-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
70 lines (59 loc) · 2.02 KB
/
Copy pathmain.c
File metadata and controls
70 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*----------------------------------------------------------------------------
* CMSIS-RTOS 'main' function template
*---------------------------------------------------------------------------*/
#include "RTE_Components.h"
#include CMSIS_device_header
#include "cmsis_os2.h"
#include "uart.h"
#include "motor.h"
#include "buffer.h"
#include "green_led.h"
#include "audio.h"
int isMoving = 0;
int isFinish = 0;
/*----------------------------------------------------------------------------
* MOTOR
*---------------------------------------------------------------------------*/
int forward_speed = 0;
int left_speed = 0;
/*----------------------------------------------------------------------------
* ESP32 Packet Parsing Thread
*---------------------------------------------------------------------------*/
void parse_command_thread(void *argument){
for(;;){
serialData b;
osStatus_t status = osMessageQueueGet(tParserMessageQueue, &b, NULL, osWaitForever);
if (status == osOK) {
decodeMessage(&b, &forward_speed, &left_speed);
}
osDelay(1);
}
}
/*----------------------------------------------------------------------------
* Motor Control Thread
*---------------------------------------------------------------------------*/
void motor_thread (void *argument) {
for (;;) {
move(forward_speed, left_speed);
osDelay(1);
}
}
/*----------------------------------------------------------------------------
* MAIN
*---------------------------------------------------------------------------*/
int main (void) {
// System Initialization
SystemCoreClockUpdate();
initMotor();
Init_UART2(BAUD_RATE);
osKernelInitialize(); // Initialize CMSIS-RTOS
tParserMessageQueue = Init_Serial_MsgQueue();
osThreadNew(motor_thread, NULL, NULL);
osThreadNew(parse_command_thread, NULL, NULL);
osThreadNew(green_led_thread, NULL, NULL);
osThreadNew(red_led_thread, NULL, NULL);
osThreadNew(audio_thread, NULL, NULL);
osKernelStart(); // Start thread execution
for (;;) {
}
}