Bluepill (STM32F103) + NeoPixel version of the Simon game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stm32f103-simon/User/utils/malloc_safe.c

38 lines
618 B

8 years ago
#include <common.h>
#include "handlers.h"
#include "malloc_safe.h"
static void reset_when_done(void)
{
//
HAL_NVIC_SystemReset();
}
void *malloc_safe_do(size_t size, const char* file, uint32_t line)
{
void *mem = malloc(size);
if (mem == NULL) {
// malloc failed
user_error_file_line("Malloc failed", file, line);
reset_when_done();
}
return mem;
}
void *calloc_safe_do(size_t nmemb, size_t size, const char* file, uint32_t line)
{
void *mem = calloc(nmemb, size);
if (mem == NULL) {
// malloc failed
user_error_file_line("Calloc failed", file, line);
reset_when_done();
}
return mem;
}