@@ -79,7 +79,7 @@ uint64_t ei_read_timer_us() {
7979EI_WEAK_FN char ei_getchar ()
8080{
8181 uint8_t rcv_char = 0 ;
82- if (uart_fifo_read (uart, &rcv_char, 1 ) == 1 ) {
82+ if (uart_fifo_read (uart, &rcv_char, 1 ) == 1 ) {
8383 return rcv_char;
8484 }
8585 else {
@@ -90,7 +90,7 @@ EI_WEAK_FN char ei_getchar()
9090/* *
9191 * Printf function uses vsnprintf and output using Arduino Serial
9292 */
93- __attribute__ ((weak)) void ei_printf(const char *format, ...) {
93+ EI_WEAK_FN void ei_printf (const char *format, ...) {
9494 static char print_buf[1024 ] = { 0 };
9595
9696 va_list args;
@@ -99,31 +99,53 @@ __attribute__((weak)) void ei_printf(const char *format, ...) {
9999 va_end (args);
100100
101101 if (r > 0 ) {
102- printf (" %s" , print_buf);
102+ printk (" %s" , print_buf);
103103 }
104104}
105105
106- __attribute__ ((weak)) void ei_printf_float(float f) {
107- printf (" %f" , f);
106+ EI_WEAK_FN void ei_printf_float (float f) {
107+ printk (" %f" , f);
108108}
109109
110- __attribute__ ((weak)) void *ei_malloc(size_t size) {
110+ #if !defined(CONFIG_EDGE_IMPULSE_HEAP_TYPE) || (CONFIG_EDGE_IMPULSE_HEAP_TYPE == 0) // malloc
111+
112+ EI_WEAK_FN void *ei_malloc (size_t size) {
111113 return malloc (size);
112114}
113115
114- __attribute__ ((weak)) void *ei_calloc(size_t nitems, size_t size) {
116+ EI_WEAK_FN void *ei_calloc (size_t nitems, size_t size) {
115117 return calloc (nitems, size);
116118}
117119
118- __attribute__ ((weak)) void ei_free(void *ptr) {
120+ EI_WEAK_FN void ei_free (void *ptr) {
119121 free (ptr);
120122}
121123
124+ #elif defined(CONFIG_EDGE_IMPULSE_HEAP_TYPE) && (CONFIG_EDGE_IMPULSE_HEAP_TYPE == 1) // k_malloc
125+
126+ #if not defined(CONFIG_HEAP_MEM_POOL_SIZE) || (CONFIG_HEAP_MEM_POOL_SIZE == 0)
127+ #error "CONFIG_HEAP_MEM_POOL_SIZE must be set to a non-zero value when using CONFIG_EDGE_IMPULSE_HEAP_TYPE=1"
128+ #endif
129+
130+ EI_WEAK_FN void *ei_malloc (size_t size) {
131+ return k_malloc (size);
132+ }
133+
134+ EI_WEAK_FN void *ei_calloc (size_t nitems, size_t size) {
135+ return k_calloc (nitems, size);
136+ }
137+
138+ EI_WEAK_FN void ei_free (void *ptr) {
139+ k_free (ptr);
140+ }
141+
142+ #endif
143+
122144#if defined(__cplusplus) && EI_C_LINKAGE == 1
123145extern " C"
124146#endif
125- __attribute__ ((weak)) void DebugLog(const char * s) {
126- printf (" %s" , s);
147+ EI_WEAK_FN void DebugLog (const char * s) {
148+ printk (" %s" , s);
127149}
128150
129- #endif // #if EI_PORTING_ZEPHYR == 1
151+ #endif // #if EI_PORTING_ZEPHYR == 1
0 commit comments