添加rtthread相关代码
This commit is contained in:
67
riscv/startup/main.c
Normal file
67
riscv/startup/main.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "stdarg.h"
|
||||
#include "head.h"
|
||||
|
||||
#define PRINT_BASE_ADDR *(uint8_t *)0x40000000
|
||||
|
||||
int my_putc(int c) {
|
||||
PRINT_BASE_ADDR = c;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int add(int a, int b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
|
||||
char g_string[] = "string from ram";
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int a=1;
|
||||
int b=2;
|
||||
typedef void (*fun_t)(void);
|
||||
fun_t fun = (fun_t)0;
|
||||
set_csr(mstatus, 0x00000008);
|
||||
set_csr(mie, (1 << 3) | (1 << 7));
|
||||
set_csr(mip, (1 << 3));
|
||||
fun();
|
||||
int c = add(a, b);
|
||||
my_printf("Hello World! %s\n", "Andy");
|
||||
my_printf("add(%d, %d)=%d\n", a, b, c);
|
||||
a = 67;b = -78;
|
||||
fun=(fun_t)0xff000000;
|
||||
fun();
|
||||
my_printf("mul(%d, %d)=%d\n", a, b, a * b);
|
||||
my_printf("ram_val test: %s\n", g_string);
|
||||
cpu_test();
|
||||
|
||||
my_printf("enter while 1\n");
|
||||
while (1) {
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user