add external libraries and update stm version
[mTask.git] / int / nucleo-f767-blinky / src / main.c
1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #ifdef STM32F767xx
7 #include "stm32f7xx_hal.h"
8 #include "gpio.h"
9 #include "usart.h"
10 #else
11 #include <stdio.h>
12 #include <netdb.h>
13 #include <netinet/in.h>
14 #include <signal.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <sys/types.h>
18 #include <unistd.h>
19 #endif
20
21 #include "interpret.h"
22 #include "mTaskSymbols.h"
23 #include "sds.h"
24 #include "task.h"
25 #include "interface.h"
26
27 #define MSG_GET_TASK 't'
28 #define MSG_DEL_TASK 'd'
29 #define MSG_SDS_SPEC 's'
30 #define MSG_SDS_UPD 'u'
31
32 void read_message()
33 {
34 //Find next task
35 uint8_t c = read_byte();
36 debug("Receiving input: %c\n", c);
37 switch(c){
38 case MSG_SDS_SPEC:
39 debug("Receiving an sds\n");
40 sds_register();
41 break;
42 case MSG_SDS_UPD:
43 debug("Receiving an sds\n");
44 //TODO do something with the return value
45 sds_update();
46 break;
47 case MSG_DEL_TASK:
48 debug("Receiving a delete task request\n");
49 task_delete();
50 break;
51 case MSG_GET_TASK:
52 debug("Receiving a task\n");
53 c = task_register();
54 break;
55 case '\n':
56 break;
57 default:
58 debug("Unknown message: %X\n", c);
59 }
60 }
61
62 void loop()
63 {
64 int ct;
65 long cyclestart;
66 struct task *curtask;
67
68 if(input_available())
69 read_message();
70
71 //Run tasks
72 cyclestart = millis();
73 for(ct = 0; ct<MAXTASKS; ct++){
74 //See whether the task is even in use
75 if((curtask = task_get(ct)) == NULL){
76 // debug("Task %d not implemented\n", ct);
77 continue;
78 }
79 //See whether the task interval has passed
80 if(cyclestart-curtask->lastrun < curtask->interval){
81 // debug("Task %d not scheduled\n", ct);
82 continue;
83 }
84 debug("Current task to run: %d\n", ct);
85 run_task(curtask);
86 curtask->lastrun = cyclestart;
87 write_byte('\n');
88 }
89 }
90
91 #ifdef STM32F767xx
92 char s[128] = "";
93 int main1(void){
94 #else
95 int main(int argc, char *argv[]){
96 gargc = argc;
97 gargv = argv;
98 #endif
99 debug("booting up\r\n");
100
101 //Initialize systems
102 setup();
103 sds_init();
104 task_init();
105
106 write_byte('\n');
107
108 while(true){
109 //Check for new tasks
110 debug("loop\r\n");
111 loop();
112 delay(100);
113 }
114 return 0;
115 }