41049605fdd06a5259cc12c0869667aa6b75fb47
[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 mem_pool_t kheap_pool;
35
36 void main()
37 {
38
39         /* Initialize the clock system, */
40         clock_init();
41
42         /* Setup the interrupt vector table */
43         ivt_init();
44
45         /* Initialze basic input and output over serial */
46         uart_init();
47
48         /* TFT screen */
49         // tft_init();
50         
51         /* Cortex M* integrated systick, can be replaced
52          * by the more accurate RTC.
53         systick_init();
54         */
55         
56         /* Set up a very small libc library */
57         init_printf(NULL, putc);
58
59         /* Display some basic info at startup */
60         sysinfo();
61
62         /* On board LEDs*/
63         led_init();
64
65         /* Real time clock */
66         rtc_init();
67
68         extern uint32_t * _beginofheap;
69         //printf("%p", &_beginofheap);
70         kpool_init(&kheap_pool, 0x10, 10, (uint32_t *) &_beginofheap);
71
72 //      printf("%p\n", &kheap_pool);
73
74         char * string = (char *) kalloc(&kheap_pool);
75         char * string2 = (char *) kalloc(&kheap_pool);
76         char * string3 = (char *) kalloc(&kheap_pool);
77
78
79         memset(string, 0xFF, 0x10);
80         memset(string2, 0xEE, 0x10);
81         memset(string3, 0xDD, 0x10);
82
83         printf("%p\n", string);
84         printf("%p\n", string2);
85         printf("%p\n", string3);
86
87         kfree(&kheap_pool, string);
88
89         char * string6 = (char *) kalloc(&kheap_pool);
90
91
92         memset(string6, 0xCC, 0x10);
93 //      char * string7 = (char *) kalloc(&kheap_pool);
94         printf("%p\n", string6);
95 //      printf("%p\n", string7);
96
97
98         kfree(&kheap_pool, string2);
99
100         char * string7 = (char *) kalloc(&kheap_pool);
101         memset(string7, 0xBB, 0x10);
102
103
104         char * string8 = (char *) kalloc(&kheap_pool);
105         memset(string8, 0xAA, 0x10);
106
107         char * string9 = (char *) kalloc(&kheap_pool);
108         memset(string9, 0x99, 0x10);
109         //free(string);
110
111         kfree(&kheap_pool, string3);
112
113         //char * string2 = (char *) alloc();
114         
115         //string2 = "taalb";
116
117         /* Eeprom Driver
118         eeprom_at24c_init();
119         eeprom_test();
120         */
121         
122         /* LED Segment Driver */
123         //tm1637_init();
124
125         /* ASM Blocking routine */
126         //for (int i = 0; i < 1000; i++)
127         //      _block(10000);
128
129         /* TEMP SENSOR 
130         tsensor_printid();
131         uint16_t temp = tsensor_get_temp();
132         printf("Current temperature: %d °C\n", temp); */
133
134         /* ADC Joystick module */
135         // mk450_init();        
136
137
138         /* Start up terminal */
139         terminal();
140         
141         /* Should not be here, endless loop */
142         for(;;) {
143
144         }
145 }