-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.c
243 lines (193 loc) · 4.99 KB
/
tasks.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "brtos/includes/BRTOS.h"
#include "includes/drivers.h"
#include "includes/tasks.h"
#include "drivers/serial.h"
#include "drivers/lcd.h"
#include "drivers/adc.h"
//#include "BRTOS.h"
//#include "drivers.h"
//#include "tasks.h"
//#include "serial.h"
//#include "lcd.h"
//#include "debug_stack.h"
//#include <adc.h>
extern BRTOS_Sem *SemTeste;
extern BRTOS_Queue *QSerialRX;
CHAR8 BufferLCD[17];
void System_Time(void)
{
// task setup
INT8U i = 0;
OSResetTime(&Hora);
OSResetDate(&Data);
/* task main loop */
for (;;)
{
#if (WATCHDOG == 1)
__asm
CLRWDT
__endasm;
#endif
(void)DelayTask(10);
i++;
if (i >= 100)
{
OSUpdateUptime(&Hora,&Data);
i = 0;
}
}
}
void Task_2(void)
{
/* task setup */
INT8U cont = 0;
/* task main loop */
for (;;)
{
cont++;
(void)DelayTask(35);
//Acorda a tarefa 3
(void)OSSemPost(SemTeste);
}
}
void Task_3(void)
{
/* task setup */
INT8U seq1 = 0x08;
INT8U sent1 = 0;
LATB = 0;
TRISB = 0;
/* task main loop */
for (;;)
{
LATB=seq1;
//Se sentido de P2.0 a P2.7 transla��o para esquerda
if(sent1==0){ seq1<<=1;
//Se o �ltimo Led ficar� aceso, inverte sentido
if(seq1==0x80) sent1=1;
}
//Caso contr�rio rota��o para direita
else{ seq1>>=1;
//Se o primeiro Led ficar� aceso, inverte sentido oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
if(seq1==0x01) sent1=0;
}
(void)OSSemPend(SemTeste,0);
//(void)DelayTask(30);
}
}
void Task_Serial(void)
{
/* task setup */
volatile INT8U pedido = 0;
// task main loop
for (;;)
{
/*
if(!OSQueuePend(QSerialRX, (INT8U*)&pedido, 0))
{
switch(pedido)
{
#if (COMPUTES_CPU_LOAD == 1)
case '1':
acquireUART();
Transmite_CPU_Load();
releaseUART();
break;
#endif
case '2':
acquireUART();
Transmite_Uptime();
releaseUART();
break;
case '3':
acquireUART();
//Serial_Envia_Frase((CHAR8*)version);
//strcpypgm2ram (BufferText, (const rom far CHAR8*)version);
Serial_Envia_Frase(BufferText);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
releaseUART();
break;
case '4':
acquireUART();
Transmite_RAM_Ocupada();
releaseUART();
break;
case '5':
acquireUART();
Transmite_Task_Stacks();
releaseUART();
break;
case '6':
acquireUART();
//strcpypgm2ram (BufferText, (const rom char far *)"CPU: PIC18F Core");
Serial_Envia_Frase(BufferText);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
releaseUART();
break;
/ *
#if (OSTRACE == 1)
case '6':
Send_OSTrace();
Serial_Envia_Caracter(LF);
Serial_Envia_Caracter(CR);
break;
#endif
* /
default:
acquireUART();
Serial_Envia_Caracter(pedido);
releaseUART();
break;
}
}
*/
}
}
void Task_LCD(void)
{
/* task setup */
INT16U uiValorAD = 0;
init_lcd();
//strcpypgm2ram (BufferLCD, (const rom char far *)"ugenios + BRTOS");
BufferLCD[0] = 0xE4;
write_lcd(BufferLCD);
posiciona(2, 1);
//strcpypgm2ram (BufferLCD, (const rom char far *)"Temp: ");
write_lcd(BufferLCD);
TRISA = 0xFF;
InicializaAD();
// Liga resistencia de aquecimento
LATCbits.LATC5 = 1;
TRISCbits.TRISC5 = 0;
// Liga ventilador
LATCbits.LATC2 = 0;
TRISCbits.TRISC2 = 0;
uiValorAD = LeValorAD();
// task main loop
for (;;)
{
uiValorAD = LeValorAD();
if (uiValorAD >= 30)
{
// Liga ventilador
LATCbits.LATC2 = 1;
// Desliga resist�ncia
LATCbits.LATC5 = 0;
}else
{
// Desliga ventilador
LATCbits.LATC2 = 0;
// Liga resist�ncia
LATCbits.LATC5 = 1;
}
posiciona(2, 7);
write_numero(uiValorAD);
BufferLCD[0]=0xDF;
BufferLCD[1]='C';
BufferLCD[2]=0;
write_lcd(BufferLCD);
DelayTask(1000);
}
}