Rename fb_stack to fb_alloc and call init0 in main

This commit is contained in:
iabdalkader 2016-02-17 05:24:17 +02:00
parent cfa9b6e440
commit db667c061f
5 changed files with 17 additions and 11 deletions

View File

@ -99,7 +99,7 @@ OBJ += $(wildcard $(BUILD)/$(WINC1500_DIR)/src/*.o)
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \ OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \
main.o \ main.o \
xalloc.o \ xalloc.o \
fb_stack.o \ fb_alloc.o \
ff_wrapper.o \ ff_wrapper.o \
array.o \ array.o \
usbdbg.o \ usbdbg.o \

View File

@ -2,7 +2,7 @@
SRCS += $(addprefix , \ SRCS += $(addprefix , \
main.c \ main.c \
xalloc.c \ xalloc.c \
fb_stack.c \ fb_alloc.c \
ff_wrapper.c \ ff_wrapper.c \
array.c \ array.c \
usbdbg.c \ usbdbg.c \

View File

@ -8,7 +8,7 @@
*/ */
#include <mp.h> #include <mp.h>
#include "framebuffer.h" #include "framebuffer.h"
#include "fb_stack.h" #include "fb_alloc.h"
extern char _fs_cache; extern char _fs_cache;
static char *pointer = &_fs_cache; static char *pointer = &_fs_cache;
@ -18,12 +18,14 @@ NORETURN static void fb_alloc_fail()
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "Out of Memory!!!")); nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "Out of Memory!!!"));
} }
void fb_init() { void fb_alloc_init0()
{
pointer = &_fs_cache; pointer = &_fs_cache;
} }
// returns null pointer without error if size==0 // returns null pointer without error if size==0
void *fb_alloc(uint32_t size) { void *fb_alloc(uint32_t size)
{
if (!size) { if (!size) {
return NULL; return NULL;
} }
@ -45,13 +47,15 @@ void *fb_alloc(uint32_t size) {
} }
// returns null pointer without error if size==0 // returns null pointer without error if size==0
void *fb_alloc0(uint32_t size) { void *fb_alloc0(uint32_t size)
{
void *mem = fb_alloc(size); void *mem = fb_alloc(size);
memset(mem, 0, size); memset(mem, 0, size);
return mem; return mem;
} }
void fb_free() { void fb_free()
{
if (pointer < &_fs_cache) { if (pointer < &_fs_cache) {
pointer += *((uint32_t *) pointer); // Get size and pop. pointer += *((uint32_t *) pointer); // Get size and pop.
} }

View File

@ -6,11 +6,11 @@
* Interface for using extra frame buffer RAM as a stack. * Interface for using extra frame buffer RAM as a stack.
* *
*/ */
#ifndef __FB_STACK_H__ #ifndef __FB_ALLOC_H__
#define __FB_STACK_H__ #define __FB_ALLOC_H__
#include <stdint.h> #include <stdint.h>
void fb_init(); void fb_alloc_init0();
void *fb_alloc(uint32_t size); void *fb_alloc(uint32_t size);
void *fb_alloc0(uint32_t size); void *fb_alloc0(uint32_t size);
void fb_free(); void fb_free();
#endif /* __FF_WRAPPER_H__ */ #endif /* __FF_ALLOC_H__ */

View File

@ -47,6 +47,7 @@
#include "sensor.h" #include "sensor.h"
#include "usbdbg.h" #include "usbdbg.h"
#include "sdram.h" #include "sdram.h"
#include "fb_alloc.h"
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
@ -312,6 +313,7 @@ soft_reset:
uart_init0(); uart_init0();
pyb_usb_init0(); pyb_usb_init0();
sensor_init0(); sensor_init0();
fb_alloc_init0();
#if MICROPY_HW_ENABLE_RTC #if MICROPY_HW_ENABLE_RTC
if (first_soft_reset) { if (first_soft_reset) {