SYSCALL naked assembly working
[cortex-from-scratch] / main.c
1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
2  * 
3  * $LOG$
4  * 2019/7/20 - ROBIN KRENS      
5  * Initial version 
6  * 
7  * $DESCRIPTION$
8  * Main initialize basic components of the board
9  * and jumps to a terminal
10  *
11  * */
12
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16
17 #include <sys/robsys.h> 
18 #include <sys/mmap.h>
19
20 #include <lib/regfunc.h>
21 #include <lib/pool.h>
22 #include <lib/stdio.h>
23 #include <lib/string.h>
24 #include <lib/tinyprintf.h>
25
26 #include <drivers/uart.h>
27 #include <drivers/led.h>
28 //#include <drivers/tm1637.h>
29 //#include <drivers/at24c.h>
30 //#include <drivers/tsensor.h>
31 //#include <drivers/mk450_joystick.h>
32 #include <drivers/st7735s.h>
33
34
35 #include <lib/syscall.h>
36
37 int test3(int i, int j) {
38
39         volatile uint32_t * sp = get_msp();
40         
41         /* asm volatile (
42         "tst lr, #4" "\n\t" 
43         "ite eq" "\n\t"
44         "mrseq %0, msp" "\n\t" 
45         "mrsne r0, psp" : "=r" (sp) ); */
46
47         for (int i = 0; (sp + i) < 0x20010000; i++) {
48                 printf("ADDRESS: %p, VALUE: %x\n", (sp + i), *(sp + i));
49         }
50
51         for(;;);
52         return 0xCC;
53
54 }
55 int test2(int i, int j) {
56
57         int x = i * j;
58         test3(0x3A, 0x3B); 
59         
60
61 }
62 int test(int i, int j) {
63
64         test2(0x2A, 0x2B);
65         
66         return 0xAA;
67 }
68
69 void main()
70 {
71
72         /* Initialize the clock system, */
73         clock_init();
74
75         /* Setup the interrupt vector table */
76         ivt_init();
77
78         /* Initialze basic input and output over serial */
79         uart_init();
80
81         /* TFT screen */
82         // tft_init();
83         
84         /* Cortex M* integrated systick, can be replaced
85          * by the more accurate RTC.
86         systick_init();
87         */
88         
89         /* Set up a very small libc library */
90         init_printf(NULL, putc);
91
92         /* Heap init */
93         //kheap_init();
94         //printf("%p\n", get_kheap());
95         
96         /* Display some basic info at startup */
97         sysinfo();
98
99         /* On board LEDs*/
100         led_init();
101
102         /* Real time clock */
103         //rtc_init();
104
105 //      printf("press any key to start\n");
106 //      asm volatile ("wfi");
107
108         syscall_init();
109         theos_test(0xA1, 0xA2);
110
111         /* Eeprom Driver
112         eeprom_at24c_init();
113         eeprom_test();
114         */
115         
116         /* LED Segment Driver */
117         //tm1637_init();
118
119         /* ASM Blocking routine */
120         //for (int i = 0; i < 1000; i++)
121         //      _block(10000);
122
123         /* TEMP SENSOR 
124         tsensor_printid();
125         uint16_t temp = tsensor_get_temp();
126         printf("Current temperature: %d °C\n", temp); */
127
128         /* ADC Joystick module */
129         // mk450_init();        
130
131
132         /* Start up terminal */
133         terminal();
134         
135         /* Should not be here, endless loop */
136         for(;;) {
137
138         }
139 }