Verified Commit e728833c authored by Rahix's avatar Rahix
Browse files

fix(pycardium): Remove all uses of newlib malloc



Fixes #44

Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent 7a39ec76
......@@ -71,6 +71,7 @@ upy = static_library(
elf = executable(
name + '.elf',
'main.c',
'patch.c',
'mphalport.c',
frozen_source,
modsrc,
......
......@@ -8,6 +8,7 @@
#include "py/mpstate.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "py/mpprint.h"
#include "mxc_delay.h"
#include "max32665.h"
......@@ -15,6 +16,7 @@
#include "epicardium.h"
#include "api/common.h"
/******************************************************************************
* Serial Communication
*/
......@@ -36,30 +38,15 @@ int DEBUG_printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int ret = vprintf(fmt, args);
int ret = mp_vprintf(MP_PYTHON_PRINTER, fmt, args);
va_end(args);
return ret;
}
/* newlib syscall to allow printf to work */
long _write(int fd, const char *buf, size_t cnt)
void __attribute__((noreturn)) sbrk_is_not_implemented___see_issue_44(void);
intptr_t _sbrk(int incr)
{
/*
* Only print one line at a time. Insert `\r` between lines so
* they are properly displayed on the serial console.
*/
size_t i, last = 0;
for (i = 0; i < cnt; i++) {
if (buf[i] == '\n') {
epic_uart_write_str(&buf[last], i - last);
epic_uart_write_str("\r", 1);
last = i;
}
}
if (last != i) {
epic_uart_write_str(&buf[last], cnt - last);
}
return cnt;
sbrk_is_not_implemented___see_issue_44();
}
void epic_isr_ctrl_c(void)
......
#include "epicardium.h"
#include <stdarg.h>
#include <stdio.h>
#include "py/mpprint.h"
#include "py/mphal.h"
#include <string.h>
int printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = mp_vprintf(MP_PYTHON_PRINTER, fmt, ap);
va_end(ap);
return ret;
}
#ifdef putc
#undef putc
#endif /* putc */
int putc(int c, FILE *f)
{
char chr = (char)c;
mp_hal_stdout_tx_strn_cooked(&chr, 1);
return c;
}
#ifdef putchar
#undef putchar
#endif /* putchar */
int putchar(int c)
{
char chr = (char)c;
mp_hal_stdout_tx_strn_cooked(&chr, 1);
return c;
}
int puts(const char *s)
{
int length = strlen(s);
if (length) {
mp_hal_stdout_tx_strn_cooked(s, length);
}
return length;
}
/* Used by mp_hal_move_cursor_back() */
int snprintf(char *str, size_t size, const char *format, ...)
{
/* TODO: What should we do with this? */
return -EIO;
}
/* Use by assert() */
int fiprintf(FILE *f, const char *fmt, ...)
{
/* TODO: Maybe printing everything to UART isn't the correct thing? */
va_list ap;
va_start(ap, fmt);
int ret = mp_vprintf(MP_PYTHON_PRINTER, fmt, ap);
va_end(ap);
return ret;
}
int raise(int sig)
{
/* Ignore signals */
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment