aboutsummaryrefslogtreecommitdiff
path: root/common/mbed
diff options
context:
space:
mode:
Diffstat (limited to 'common/mbed')
-rw-r--r--common/mbed/bootloader.c4
-rw-r--r--common/mbed/suspend.c6
-rw-r--r--common/mbed/xprintf.cpp46
-rw-r--r--common/mbed/xprintf.h17
4 files changed, 73 insertions, 0 deletions
diff --git a/common/mbed/bootloader.c b/common/mbed/bootloader.c
new file mode 100644
index 000000000..b51e83943
--- /dev/null
+++ b/common/mbed/bootloader.c
@@ -0,0 +1,4 @@
1#include "bootloader.h"
2
3
4void bootloader_jump(void) {}
diff --git a/common/mbed/suspend.c b/common/mbed/suspend.c
new file mode 100644
index 000000000..32651574f
--- /dev/null
+++ b/common/mbed/suspend.c
@@ -0,0 +1,6 @@
1#include <stdbool.h>
2
3
4void suspend_power_down(void) {}
5bool suspend_wakeup_condition(void) { return true; }
6void suspend_wakeup_init(void) {}
diff --git a/common/mbed/xprintf.cpp b/common/mbed/xprintf.cpp
new file mode 100644
index 000000000..4342b79f8
--- /dev/null
+++ b/common/mbed/xprintf.cpp
@@ -0,0 +1,46 @@
1#include <cstdarg>
2//#include <stdarg.h>
3#include "mbed.h"
4#include "mbed/xprintf.h"
5
6
7#define STRING_STACK_LIMIT 120
8
9/* mbed Serial */
10Serial ser(UART_TX, UART_RX);
11
12/* TODO: Need small implementation for embedded */
13int xprintf(const char* format, ...)
14{
15 /* copy from mbed/common/RawSerial.cpp */
16 std::va_list arg;
17 va_start(arg, format);
18 int len = vsnprintf(NULL, 0, format, arg);
19 if (len < STRING_STACK_LIMIT) {
20 char temp[STRING_STACK_LIMIT];
21 vsprintf(temp, format, arg);
22 ser.puts(temp);
23 } else {
24 char *temp = new char[len + 1];
25 vsprintf(temp, format, arg);
26 ser.puts(temp);
27 delete[] temp;
28 }
29 va_end(arg);
30 return len;
31
32/* Fail: __builtin_va_arg_pack?
33 * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
34 void *arg = __builtin_apply_args();
35 void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
36 __builtin_return(ret)
37*/
38/* Fail: varargs can not be passed to printf
39 //int r = ser.printf("test %i\r\n", 123);
40 va_list arg;
41 va_start(arg, format);
42 int r = ser.printf(format, arg);
43 va_end(arg);
44 return r;
45*/
46}
diff --git a/common/mbed/xprintf.h b/common/mbed/xprintf.h
new file mode 100644
index 000000000..26bc529e5
--- /dev/null
+++ b/common/mbed/xprintf.h
@@ -0,0 +1,17 @@
1#ifndef XPRINTF_H
2#define XPRINTF_H
3
4//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10int xprintf(const char *format, ...);
11
12#ifdef __cplusplus
13}
14#endif
15
16
17#endif