#include "stdint.h" #include "stdio.h" #include "stdarg.h" #include "head.h" #include "rtthread.h" #define UART0_BASE (0x30000000) #define UART0_CTRL (UART0_BASE + (0x00)) #define UART0_STATUS (UART0_BASE + (0x04)) #define UART0_BAUD (UART0_BASE + (0x08)) #define UART0_TXDATA (UART0_BASE + (0x0c)) #define UART0_RXDATA (UART0_BASE + (0x10)) #define UART0_REG(addr) (*((volatile uint32_t *)addr)) // send one char to uart void my_putc(uint8_t c) { while (UART0_REG(UART0_STATUS) & 0x1); UART0_REG(UART0_TXDATA) = c; } // Block, get one char from uart. uint8_t uart_getc() { UART0_REG(UART0_STATUS) &= ~0x2; while (!(UART0_REG(UART0_STATUS) & 0x2)); return (UART0_REG(UART0_RXDATA) & 0xff); } // 115200bps, 8 N 1 void uart_init() { // enable tx and rx UART0_REG(UART0_CTRL) = 0x3; } int my_puts(const char *s,int len) { for (int i = 0;i < len;i++) { my_putc(s[i]); } return 0; } static char g_print_buff[1024]; int my_printf(const char* fmt, ...) { int len = 0; va_list args; va_start(args, fmt); len = vsnprintf(g_print_buff, 1024, fmt, args); va_end(args); my_puts(g_print_buff, len); return len; } char g_string[] = "string from ram"; void task1(void* par) { (void)par; while (1) { my_printf("task1: %s\n", g_string); rt_thread_delay(500); } } int main() { my_printf("Hello World! %s\n", "Andy"); // cpu_test(); rt_thread_t t = rt_thread_create("task1", task1, 0, 1024, 10, 10); (void)t; rt_thread_startup(t); my_printf("enter while 1\n"); while (1) { rt_size_t total, used, max_used; rt_memory_info(&total, &used, &max_used); my_printf("main: total=%d, used=%d, max_used=%d\n", total,used,max_used); rt_thread_delay(1000); } return 0; }