1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
4 * 2019/7/20 - ROBIN KRENS
8 * Main initialize basic components of the board
9 * and jumps to a terminal
17 #include <sys/robsys.h>
19 #include <sys/process.h>
21 #include <lib/regfunc.h>
23 #include <lib/stdio.h>
24 #include <lib/string.h>
25 #include <lib/tinyprintf.h>
27 #include <drivers/uart.h>
28 #include <drivers/led.h>
29 //#include <drivers/tm1637.h>
30 //#include <drivers/at24c.h>
31 //#include <drivers/tsensor.h>
32 //#include <drivers/mk450_joystick.h>
33 #include <drivers/st7735s.h>
35 #include <lib/syscall.h>
41 uint32_t stackp1[500];
42 uint32_t stackp2[500];
46 void switch_usermode() {
49 //asm volatile ("mov r0, 0x1" "\n\t"
50 //"msr control, r0" "\n\t"
60 //uint32_t control = 0xFFFFFFFF;
61 printf("process 1\n");
62 //asm volatile("msr control, %0" "\n\t"
63 // "dsb" : : "r" (control));
64 //printf("control: %x", control);
67 theos_switch(&p1, &p2);
73 printf("process 2\n");
75 theos_switch(&p2, &p1);
80 int test_data_segment = 99;
85 /* Load .data segment into SRAM */
86 extern uint32_t * data_lma, data_vma, data_end;
87 int size = (&data_end - &data_vma) * 4;
88 memcpy(&data_vma, &data_lma, size);
90 /* Initialize the clock system, */
93 /* Setup the interrupt vector table */
96 /* Initialze basic input and output over serial */
102 /* Set up a very small libc library */
103 init_printf(NULL, putc);
107 //printf("%p\n", get_kheap());
109 /* Display some basic info at startup */
116 /* Real time clock */
120 // printf("press any key to start\n");
121 // asm volatile ("cpsid f"); // doesn't work in qemu
126 //ret = theos_test(0x1, 0x2, 0x3);
127 //ret = theos_uptime();
129 //printf("ret: %d\n", ret);
131 int size_stack = sizeof(stackp1);
133 p1.stackptr = ((unsigned int) stackp1) + size_stack - 0x1C;
134 p1.stackptr[6] = (uint32_t) process1;
135 p1.stackptr[7] = 0x01000000;
136 p2.stackptr = ((unsigned int) stackp2) + size_stack - 0x1C;
137 p2.stackptr[6] = (uint32_t) process2;
138 p2.stackptr[7] = 0x01000000;
142 /* Cortex M* integrated systick, can be replaced
143 * by the more accurate RTC. */
147 // switch_usermode();
149 //printf("without system call");
150 // theos_test(0xA1, 0xA2);
157 /* LED Segment Driver */
160 /* ASM Blocking routine */
161 //for (int i = 0; i < 1000; i++)
166 uint16_t temp = tsensor_get_temp();
167 printf("Current temperature: %d °C\n", temp); */
169 /* ADC Joystick module */
173 /* Start up terminal */
176 /* Should not be here, endless loop */