24 #include "qm_common.h"
25 #include "qm_interrupt.h"
26 #include "qm_pinmux.h"
30 #define ASSERT_STR_HEAD ("\nAssertion failed: file ")
31 #define ASSERT_STR_TRAIL (", expr: ")
33 #define PICO_PRINTF_D 1
34 #define PICO_PRINTF_U 1
35 #define PICO_PRINTF_X 1
36 #define PICO_PRINTF_S 1
37 #define PICO_PRINTF_ESC 1
38 #define FORMAT_BUF_SIZE 32
40 static __inline__
int pico_putchar(
int c)
46 #if (PICO_PRINTF_D || PICO_PRINTF_U || PICO_PRINTF_X)
47 static __inline__
char last_digit_to_char(
unsigned int n,
int base,
bool upcase)
55 return upcase ? c + (
'A' - 10) : c + (
'a' - 10);
58 static __inline__
int putuint(
unsigned int n,
int base,
bool upcase)
60 static char format_buf[FORMAT_BUF_SIZE];
66 s[i++] = last_digit_to_char(n, base, upcase);
70 for (k = i - 1; k >= 0; k--)
78 static __inline__
int pico_putchars(
const char *s)
83 len += pico_putchar(*s);
107 const char *s = format;
110 va_start(ap, format);
130 len += pico_putchar(
'-');
133 len += putuint(n, 10,
false);
140 u = va_arg(ap,
unsigned int);
141 len += putuint(u, 10,
false);
149 u = va_arg(ap,
unsigned int);
150 len += putuint(u, 16, c ==
'X');
157 str = va_arg(ap,
const char *);
158 len += pico_putchars(str);
162 #if (PICO_PRINTF_ESC)
164 len += pico_putchar(
'%');
166 len += pico_putchar(c);
173 len += pico_putchar(c);
181 #define QM_AON_GPIO ((qm_gpio_reg_t *)QM_AON_GPIO_BASE)
183 void stdout_uart_setup(uint32_t baud_divisors)
195 QM_AON_GPIO->gpio_swporta_dr |= BIT(3);
197 QM_AON_GPIO->gpio_swporta_dr &= ~BIT(3);
199 QM_AON_GPIO->gpio_swporta_ddr |= BIT(3);
225 int puts(
const char *s)
240 void __assert_func(
const char *file,
int line,
const char *func,
241 const char *failedexpr)
248 #if (PUTS_ENABLE || PRINTF_ENABLE)
251 sizeof(ASSERT_STR_HEAD));
253 for (i = 0; func[i]; i++) {
257 sizeof(ASSERT_STR_TRAIL));
258 for (i = 0; failedexpr[i]; i++) {
267 #if (ASSERT_ACTION_HALT)
271 __asm__ __volatile__(
"hlt");
273 #elif(ASSERT_ACTION_RESET)
276 #error "Undefined assert action"
300 int read(
int file,
char *buf,
int len)
313 int write(
int file,
const char *buf,
int len)
337 int lseek(
int file,
int p,
int dir)
349 int fstat(
int file,
struct stat *st)
351 if (file == 0 || file > 2) {
357 st->st_mode = S_IFCHR;
364 caddr_t sbrk(
int incr)
366 extern char __heap, __heap_end;
367 static char *prog_break = &__heap;
369 char *prev_prog_break;
371 if (prog_break + incr >= &__heap_end || prog_break + incr < &__heap) {
376 prev_prog_break = prog_break;
380 return prev_prog_break;
int clk_periph_enable(const clk_periph_t clocks)
Enable clocks for peripherals / registers.
qm_uart_lc_t line_control
Line control (enum).
void qm_irq_disable(void)
Unconditionally disable interrupt delivery on the CPU.
int pico_printf(const char *format,...)
This is an minimally useful subset of the POSIX printf() function.
int qm_pmux_select(const qm_pin_id_t pin, const qm_pmux_fn_t fn)
Set up pin muxing for a SoC pin.
int qm_uart_set_config(const qm_uart_t uart, const qm_uart_config_t *const cfg)
Set UART configuration.
uint32_t baud_divisor
Baud Divisor.
void qm_soc_reset(qm_soc_reset_t reset_type)
Reset the SoC.
int qm_uart_write(const qm_uart_t uart, const uint8_t data)
UART character data write.
UART configuration structure type.
int qm_uart_write_buffer(const qm_uart_t uart, const uint8_t *const data, const uint32_t len)
UART multi-byte data write.
8 data bits, no parity, 1 stop bit.