-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
165 lines (152 loc) · 4.45 KB
/
main.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-License-Identifier: GPL-2.0-or-later
/*============================ INCLUDES ======================================*/
#include "./platform/platform.h"
#include "./platform/queue/queue.h"
#include "./utilities/compiler.h"
/*============================ MACROS ========================================*/
#define this (*ptThis)
#define TASK_CHECK_RESET_FSM() \
do { \
this.chState = START; \
} while (0)
#define TASK_RESET_FSM() \
do { \
s_tState = START; \
} while (0)
#define OUTPUT_FIFO_SIZE 100
#define FN_ENQUEUE_BYTE (&enqueue_byte)
#define FN_DEQUEUE_BYTE (&dequeue_byte)
#define FN_PEEK_BYTE_QUEUE (&peek_byte_queue)
/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/
/*============================ LOCAL VARIABLES ===============================*/
static event_t s_tPrintWorld;
static uint8_t s_chByteout[OUTPUT_FIFO_SIZE];
static byte_queue_t s_tFIFOin, s_tFIFOout;
/*============================ PROTOTYPES ====================================*/
/**
* @brief The application entry point.
*
* @retval None
*/
static fsm_rt_t task_print_world(void);
static fsm_rt_t serial_out_task(void);
static fsm_rt_t task_world(void);
int main(void)
{
platform_init();
print_str_pool_item_init();
INIT_EVENT(&s_tPrintWorld, false, false);
INIT_BYTE_QUEUE(&s_tFIFOout, s_chByteout, sizeof(s_chByteout));
LED1_OFF();
SET_EVENT(&s_tPrintWorld);
while (1) {
breath_led();
task_world();
//task_print_world();
serial_out_task();
}
}
fsm_rt_t serial_out_task(void)
{
static enum {
START,
DEQUEUE,
SEND_BYTE
} s_tState = START;
static uint8_t s_chByte;
switch (s_tState) {
case START:
s_tState = START;
//break;
case DEQUEUE:
if (!DEQUEUE_BYTE(&s_tFIFOout, &s_chByte)) {
break;
} else {
s_tState = SEND_BYTE;
}
//break;
case SEND_BYTE:
if (serial_out(s_chByte)) {
TASK_RESET_FSM();
return fsm_rt_cpl;
}
break;
default:
return fsm_rt_err;
break;
}
return fsm_rt_on_going;
}
static fsm_rt_t task_print_world(void)
{
static enum {
START,
PRINT_WORLD
} s_tState = START;
switch (s_tState) {
case START:
s_tState = START;
// break;
case PRINT_WORLD:
if (fsm_rt_cpl == task_world()) {
TASK_RESET_FSM();
return fsm_rt_cpl;
}
break;
default:
return fsm_rt_err;
break;
}
return fsm_rt_on_going;
}
static fsm_rt_t task_world(void)
{
static print_str_pool_item_t *s_ptPrintString;
static enum {
START,
INIT,
WAIT_PRINT,
PRINT_WORLD
} s_tState = START;
switch (s_tState) {
case START:
s_tState = INIT;
//break;
case INIT:
s_ptPrintString=print_str_pool_allocate();
if (s_ptPrintString==NULL)
{
TASK_RESET_FSM();
break;
}
do {
const print_str_cfg_t c_tCFG = {
"world\r\n",
&s_tFIFOout,
(&enqueue_byte)
};
print_string_init((print_str_t*)s_ptPrintString->chBuffer, &c_tCFG);
} while (0);
s_tState = WAIT_PRINT;
// break;
case WAIT_PRINT:
if (WAIT_EVENT(&s_tPrintWorld)) {
s_tState = PRINT_WORLD;
}
break;
case PRINT_WORLD:
if (fsm_rt_cpl == print_string((print_str_t*)s_ptPrintString->chBuffer)) {
print_str_pool_free(s_ptPrintString);
RESET_EVENT(&s_tPrintWorld);
TASK_RESET_FSM();
return fsm_rt_cpl;
}
break;
default:
return fsm_rt_err;
break;
}
return fsm_rt_on_going;
}