b2ff855c4058a71759835fe80fb55b2a5f5f1b3d
[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/tinyprintf.h>
24
25 #include <drivers/uart.h>
26 #include <drivers/led.h>
27 //#include <drivers/tm1637.h>
28 //#include <drivers/at24c.h>
29 //#include <drivers/tsensor.h>
30 //#include <drivers/mk450_joystick.h>
31 #include <drivers/st7735s.h>
32
33 mem_pool_t kheap_pool;
34
35 void main()
36 {
37
38         /* Initialize the clock system, */
39         clock_init();
40
41         /* Setup the interrupt vector table */
42         ivt_init();
43
44         /* Initialze basic input and output over serial */
45         uart_init();
46
47         /* TFT screen */
48         // tft_init();
49         
50         /* Cortex M* integrated systick, can be replaced
51          * by the more accurate RTC.
52         systick_init();
53         */
54         
55         /* Set up a very small libc library */
56         init_printf(NULL, putc);
57
58         /* Display some basic info at startup */
59         sysinfo();
60
61         /* On board LEDs*/
62         led_init();
63
64         /* Real time clock */
65         rtc_init();
66
67         extern uint32_t * _beginofheap;
68         //printf("%p", &_beginofheap);
69         kpool_init(&kheap_pool, 512, 10, (uint32_t *) &_beginofheap);
70
71 //      printf("%p\n", &kheap_pool);
72
73         char * string = (char *) kalloc(&kheap_pool);
74         char * string2 = (char *) kalloc(&kheap_pool);
75         char * string3 = (char *) kalloc(&kheap_pool);
76
77
78         printf("%p\n", string);
79         printf("%p\n", string2);
80         printf("%p\n", string3);
81
82         kfree(&kheap_pool, string);
83
84         char * string6 = (char *) kalloc(&kheap_pool);
85         char * string7 = (char *) kalloc(&kheap_pool);
86         printf("%p\n", string6);
87         printf("%p\n", string7);
88
89         //free(string);
90
91         //char * string2 = (char *) alloc();
92         
93         //string2 = "taalb";
94
95         /* Eeprom Driver
96         eeprom_at24c_init();
97         eeprom_test();
98         */
99         
100         /* LED Segment Driver */
101         //tm1637_init();
102
103         /* ASM Blocking routine */
104         //for (int i = 0; i < 1000; i++)
105         //      _block(10000);
106
107         /* TEMP SENSOR 
108         tsensor_printid();
109         uint16_t temp = tsensor_get_temp();
110         printf("Current temperature: %d °C\n", temp); */
111
112         /* ADC Joystick module */
113         // mk450_init();        
114
115
116         /* Start up terminal */
117         terminal();
118         
119         /* Should not be here, endless loop */
120         for(;;) {
121
122         }
123 }