-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tank_Monitor_ECU.c
912 lines (703 loc) · 23 KB
/
Tank_Monitor_ECU.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
//*****************************************************************************
//
// freertos_demo.c - Simple FreeRTOS example.
//
// Copyright (c) 2012-2016 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.3.156 of the EK-TM4C123GXL Firmware Package.
//
//*****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_can.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/can.h"
#include "utils/uartstdio.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "cancom.h"
#include "lcdmr.h"
#include "rtc.h"
#include "btnmr.h"
#include "LCD20x04.h"
#include "apptypes.h"
#include "buttonspoll_task.h"
//*****************************************************************************
//
// A counter that keeps track of the number of times the TX interrupt has
// occurred, which should match the number of TX messages that were sent.
//
//*****************************************************************************
volatile uint32_t g_ui32MsgCount = 0;
//*****************************************************************************
//
// A flag to indicate that some transmission error occurred.
//
//*****************************************************************************
volatile bool g_bErrFlag = 0;
volatile bool g_bRXFlag = 0;
/*****************************************************************************/
void vApplicationTickHook( void );
volatile uint32_t ui32TickCounter;
/*****************************************************************************/
//
// Queue to hold the data received from the CAN Network
//
QueueHandle_t xQueueData1;
QueueHandle_t xQueueData2;
QueueHandle_t xQueueData3;
QueueHandle_t xQueueData4;
QueueHandle_t xQueueData5;
QueueHandle_t xQueueData6;
extern QueueHandle_t xQueuebtns;
QueueHandle_t xQueueCalendar;
TaskHandle_t Rx_Task_Handle = NULL;
TaskHandle_t Tx_Task_Handle = NULL;
TaskHandle_t Display_Task_Handle = NULL;
TaskHandle_t DispCal_Task_Handle = NULL;
TaskHandle_t DisplayT1_Task_Handle = NULL;
TaskHandle_t DisplayT2_Task_Handle = NULL;
TaskHandle_t DisplayT3_Task_Handle = NULL;
TaskHandle_t DisplayT4_Task_Handle = NULL;
TaskHandle_t DisplayT5_Task_Handle = NULL;
TaskHandle_t DisplayT6_Task_Handle = NULL;
TaskHandle_t SetupScreen_Task_Handle = NULL;
/*****************************************************************************/
//*****************************************************************************
//
// The mutex that protects concurrent access of UART from multiple tasks.
//
//*****************************************************************************
xSemaphoreHandle g_pLCDSemaphore;
xSemaphoreHandle g_pRTCSemaphore;
TickType_t g_xSensorTimeOut = pdMS_TO_TICKS(5000);
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// This hook is called by FreeRTOS when an stack overflow error is detected.
//
//*****************************************************************************
void
vApplicationStackOverflowHook(xTaskHandle *pxTask, char *pcTaskName)
{
//
// This function can not return, so loop forever. Interrupts are disabled
// on entry to this function, so no processor interrupts will interrupt
// this loop.
//
while(1)
{
}
}
//*****************************************************************************
void itoa_new(uint16_t val, char * str)
{
uint32_t temp_val;
temp_val = val;
str[0] = (temp_val / 10000) + 48;
temp_val = (temp_val % 10000);
str[1] = (temp_val / 1000) + 48;
temp_val = (temp_val % 1000);
str[2] = (temp_val / 100) + 48;
temp_val = (temp_val % 100);
str[3] = (temp_val / 10) + 48;
temp_val = (temp_val % 10);
str[4] = temp_val + 48;
str[5] = '\0';
}
//*****************************************************************************
//
// Configure the UART and its pins. This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
//*****************************************************************************
//
// This function is the interrupt handler for the CAN peripheral. It checks
// for the cause of the interrupt, and maintains a count of all messages that
// have been transmitted.
//
//*****************************************************************************
extern void
CANIntHandler(void)
{
uint32_t ui32Status;
BaseType_t xHigherPriorityTaskWoken;
/* xHigherPriorityTaskWoken must be initialised to pdFALSE. If calling
vTaskNotifyGiveFromISR() unblocks the handling task, and the priority of
the handling task is higher than the priority of the currently running task,
then xHigherPriorityTaskWoken will automatically get set to pdTRUE. */
xHigherPriorityTaskWoken = pdFALSE;
//
// Read the CAN interrupt status to find the cause of the interrupt
//
ui32Status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
//
// If the cause is a controller status interrupt, then get the status
//
if(ui32Status == CAN_INT_INTID_STATUS)
{
//
// Read the controller status. This will return a field of status
// error bits that can indicate various errors. Error processing
// is not done in this example for simplicity. Refer to the
// API documentation for details about the error status bits.
// The act of reading this status will clear the interrupt. If the
// CAN peripheral is not connected to a CAN bus with other CAN devices
// present, then errors will occur and will be indicated in the
// controller status.
//
ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
//
// Set a flag to indicate some errors may have occurred.
//
g_bErrFlag = 1;
//UARTprintf(" CAN status %04X\n", ui32Status);
}
//
// Check if the cause is message object 1, which what we are using for
// sending messages.
// the number indicated in ui32Status is for the message object id in case of msg RX or TX
else if(ui32Status == 1)
{
//
// Getting to this point means that the RX interrupt occurred on
// message object 1, and the message RX is complete. Clear the
// message object interrupt.
//
CANIntClear(CAN0_BASE, 1);
//
// Set flag to indicate received message is pending.
//
g_bRXFlag = 1;
//
// Since the message was sent, clear any error flags.
//
g_bErrFlag = 0;
vTaskNotifyGiveFromISR( Rx_Task_Handle, &xHigherPriorityTaskWoken );
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
The macro used to do this is dependent on the port and may be called
*/
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
//
// message object 2 is used for transmission, when the cause of interrupt is msg obj 2 it means a msg was transmitted
//
else if(ui32Status == 2)
{
CANIntClear(CAN0_BASE, 2);
}
//
// Otherwise, something unexpected caused the interrupt. This should
// never happen.
//
else
{
//
// Spurious interrupt handling can go here.
//
}
}
//*********************************************************************************
//
// Sends sync signal to all slaves on the CAN network
//
//*********************************************************************************
static void Tx_Task(void *pvParameters)
{
TickType_t xLastWakeTime;
// Initialize the xLastWakeTime variable with the current time.
xLastWakeTime = xTaskGetTickCount();
while(1)
{
// Transmit SYNC signal to sensors every Heartbeat = 2s
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( HEARTBEAT ) );
UARTprintf("Sending Sync Msg...\n");
TransmitSync();
}
}
//*********************************************************************************
//
// Receives data from sensors
//
//*********************************************************************************
static void Rx_Task(void *pvParameters)
{
const TickType_t xBlockTime = 4000; // block time set to 4 sec
Node_t node;
CANCom_Master_Init();
while(1)
{
/* As before, block to wait for a notification from the ISR. This
time however the first parameter is set to pdTRUE, clearing the task's
notification value to 0, meaning each outstanding deferred
interrupt event must be processed before ulTaskNotifyTake() is called
again. */
ulTaskNotifyTake( pdTRUE, xBlockTime );
// Wait for receiving the response from sensor
if(g_bRXFlag)
{
ReceiveData( &node );
g_bRXFlag = 0;
// Then send the msg received to the queue corresponding to the correct sensor
// Do not block if queue is full
switch(node.node_nr)
{
case 1: xQueueSend( xQueueData1, &node, ( TickType_t ) 0); break;
case 2: xQueueSend( xQueueData2, &node, ( TickType_t ) 0); break;
case 3: xQueueSend( xQueueData3, &node, ( TickType_t ) 0); break;
case 4: xQueueSend( xQueueData4, &node, ( TickType_t ) 0); break;
case 5: xQueueSend( xQueueData5, &node, ( TickType_t ) 0); break;
case 6: xQueueSend( xQueueData6, &node, ( TickType_t ) 0); break;
}
}
else if(g_bErrFlag == 1)
{
UARTprintf(" error\n");
g_bErrFlag = 0;
}
}
}
//*****************************************************************************
//
// Setup Screen Display Task
//
//*****************************************************************************
static void SetupScreen_Task( void *pvparameters )
{
SetupScreen_t DispSetupParams1;
static bool first_time_flag = TRUE;
char cHr[2];
char cMin[2];
char cSec[2];
char cDay[2];
char cMonth[2];
char cYear[2];
char cRadius_buffer[6];
char cLength_buffer[6];
while(1)
{
//
// Block for 1 second until a button is pressed and the setup display parameters are updated
// During this 1 second block, other tasks can run
//
xQueueReceive( xQueuebtns, &DispSetupParams1, (TickType_t) 1000 );
// if the setup screen is unlocked then display the setup parameters and setup screen
if(DispSetupParams1.Unlocked == TRUE )
{
// convert the edited values into ascii
strftime( cHr, 3, "%H", &DispSetupParams1.calendar );
strftime( cMin, 3, "%M", &DispSetupParams1.calendar );
strftime( cSec, 3, "%S", &DispSetupParams1.calendar );
strftime( cDay, 3, "%d", &DispSetupParams1.calendar );
strftime( cMonth, 3, "%m", &DispSetupParams1.calendar );
strftime( cYear, 3, "%y", &DispSetupParams1.calendar );
// Convert radius and length into ascii
itoa_new( DispSetupParams1.Tank.length, cLength_buffer );
itoa_new( DispSetupParams1.Tank.radius, cRadius_buffer );
// If this is the first time to run this code display all the values on the screen for the first time
if( first_time_flag == TRUE )
{
// In setup mode suspend all tasks below except for buttons poll and setup display tasks
vTaskSuspend( Rx_Task_Handle );
vTaskSuspend( Tx_Task_Handle );
vTaskSuspend( DispCal_Task_Handle );
vTaskSuspend( DisplayT1_Task_Handle );
vTaskSuspend( DisplayT2_Task_Handle );
vTaskSuspend( DisplayT3_Task_Handle );
vTaskSuspend( DisplayT4_Task_Handle );
vTaskSuspend( DisplayT5_Task_Handle );
vTaskSuspend( DisplayT6_Task_Handle );
LCD_Clear();
LcdSetupScreenBase();
LcdHr(cHr);
LcdMin(cMin);
LcdSec(cSec);
LcdDay(cDay);
LcdMonth(cMonth);
LcdYr(cYear);
LcdRadius(cRadius_buffer);
LcdLength(cLength_buffer);
LCD_DispCursor();
first_time_flag = FALSE;
}
// if this is not the first time to run this code then update only the value that we are changing using buttons
else
{
switch(DispSetupParams1.cursor)
{
case HOUR: LcdHr(cHr); break;
case MIN: LcdMin(cMin); break;
case DAY: LcdDay(cDay); break;
case MONTH: LcdMonth(cMonth); break;
case YEAR: LcdYr(cYear); break;
case RADIUS: LcdRadius(cRadius_buffer); break;
case LENGTH: LcdLength(cLength_buffer); break;
}
}
}
//
// Else if setup mode was terminated by locking back the screen, the condition below must be true
//
else if( (DispSetupParams1.Unlocked == FALSE) && ( first_time_flag == FALSE) )
{
//**************EXIT SETUP MODE PROCEDURES************//
//
// Apply changes we made in the setup mode to RTC Hardware
//
Rtc_SetDate( &DispSetupParams1.calendar );
//
// ON EXIT from the setup mode reset the flag back to TRUE
//
first_time_flag = TRUE;
//
// Hide Cursor
//
LCD_HideCursor();
//
// Clear LCD
//
LCD_Clear();
//
// Resume normal operation and run all tasks back
//
vTaskResume( Rx_Task_Handle );
vTaskResume( Tx_Task_Handle );
vTaskResume( DispCal_Task_Handle );
vTaskResume( DisplayT1_Task_Handle );
vTaskResume( DisplayT2_Task_Handle );
vTaskResume( DisplayT3_Task_Handle );
vTaskResume( DisplayT4_Task_Handle );
vTaskResume( DisplayT5_Task_Handle );
vTaskResume( DisplayT6_Task_Handle );
}
else{};
}
}
//******************************************************************************
static void DispCal_Task( void *pvparameters )
{
struct tm calendar;
char cHr[2];
char cMin[2];
char cSec[2];
char cDay[2];
char cMonth[2];
char cYear[2];
TickType_t xLastWakeTime;
// Initialize the xLastWakeTime variable with the current time.
xLastWakeTime = xTaskGetTickCount();
while(1)
{
LcdNormalScreenBase();
// Get date from register
Rtc_GetDate( &calendar );
// convert the edited values into ascii
strftime( cHr, 3, "%H", &calendar );
strftime( cMin, 3, "%M", &calendar );
strftime( cSec, 3, "%S", &calendar );
strftime( cDay, 3, "%d", &calendar );
strftime( cMonth, 3, "%m", &calendar );
strftime( cYear, 3, "%y", &calendar );
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdHr(cHr);
LcdMin(cMin);
LcdSec(cSec);
LcdMonth(cMonth);
LcdDay(cDay);
LcdYr(cYear);
xSemaphoreGive( g_pLCDSemaphore );
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS(400) );
}
}
//******************************************************************************
static void DisplayT1_Task( void *pvparameters )
{
BaseType_t xMsg1Received = pdFALSE;
Node_t node1_disp;
uint16_t ui16T1SensorData;
char t1[6];
while(1)
{
// Wait for the queue to be full
xMsg1Received = xQueueReceive( xQueueData1, &node1_disp, g_xSensorTimeOut );
if( xMsg1Received == pdTRUE )
{
ui16T1SensorData = *((uint16_t *)node1_disp.node_data_ptr);
itoa_new( ui16T1SensorData, t1);
}
else
{
strncpy(t1, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT1( t1 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//******************************************************************************
static void DisplayT2_Task( void *pvparameters )
{
BaseType_t xMsg2Received = pdFALSE;
Node_t node2_disp;
uint16_t ui16T2SensorData;
char t2[6];
while(1)
{
// Wait for the queue to be full
xMsg2Received = xQueueReceive( xQueueData2, &node2_disp, g_xSensorTimeOut );
if( xMsg2Received == pdTRUE )
{
ui16T2SensorData = *((uint16_t *)node2_disp.node_data_ptr);
itoa_new( ui16T2SensorData, t2);
}
else
{
strncpy(t2, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT2( t2 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//******************************************************************************
static void DisplayT3_Task( void *pvparameters )
{
BaseType_t xMsg3Received = pdFALSE;
Node_t node3_disp;
uint16_t ui16T3SensorData;
char t3[6];
while(1)
{
// Wait for the queue to be full
xMsg3Received = xQueueReceive( xQueueData3, &node3_disp, g_xSensorTimeOut );
if( xMsg3Received == pdTRUE )
{
ui16T3SensorData = *((uint16_t *)node3_disp.node_data_ptr);
itoa_new( ui16T3SensorData, t3);
}
else
{
strncpy(t3, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT3( t3 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//******************************************************************************
static void DisplayT4_Task( void *pvparameters )
{
BaseType_t xMsg4Received = pdFALSE;
Node_t node4_disp;
uint16_t ui16T4SensorData;
char t4[6];
while(1)
{
// Wait for the queue to be full
xMsg4Received = xQueueReceive( xQueueData4, &node4_disp, g_xSensorTimeOut );
if( xMsg4Received == pdTRUE )
{
ui16T4SensorData = *((uint16_t *)node4_disp.node_data_ptr);
itoa_new( ui16T4SensorData, t4);
}
else
{
strncpy(t4, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT4( t4 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//******************************************************************************
static void DisplayT5_Task( void *pvparameters )
{
BaseType_t xMsg5Received = pdFALSE;
Node_t node5_disp;
uint16_t ui16T5SensorData;
char t5[6];
while(1)
{
// Wait for the queue to be full
xMsg5Received = xQueueReceive( xQueueData5, &node5_disp, g_xSensorTimeOut );
if( xMsg5Received == pdTRUE )
{
ui16T5SensorData = *((uint16_t *)node5_disp.node_data_ptr);
itoa_new( ui16T5SensorData, t5);
}
else
{
strncpy(t5, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT5( t5 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//******************************************************************************
static void DisplayT6_Task( void *pvparameters )
{
BaseType_t xMsg6Received = pdFALSE;
Node_t node6_disp;
uint16_t ui16T6SensorData;
char t6[6];
while(1)
{
// Wait for the queue to be full
xMsg6Received = xQueueReceive( xQueueData6, &node6_disp, g_xSensorTimeOut );
if( xMsg6Received == pdTRUE )
{
ui16T6SensorData = *((uint16_t *)node6_disp.node_data_ptr);
itoa_new( ui16T6SensorData, t6);
}
else
{
strncpy(t6, "NA ", 6);
}
// protect the data displayed
xSemaphoreTake( g_pLCDSemaphore, portMAX_DELAY );
LcdT6( t6 );
xSemaphoreGive( g_pLCDSemaphore );
}
}
//*****************************************************************************
//
// Initialize FreeRTOS and start the initial set of tasks.
//
//*****************************************************************************
int
main(void)
{
//
// Set the clocking to run at 80 MHz from the PLL.
//
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
//
// Initialize the UART and configure it for 115,200, 8-N-1 operation.
//
ConfigureUART();
Rtc_Init();
LcdMr_Init();
//
// Print demo introduction.
//
UARTprintf("\n\nWelcome to the EK-TM4C123GXL Underground Tank Monitor!\n");
/************************************************************************/
//
// Create a mutex:
//
g_pLCDSemaphore = xSemaphoreCreateMutex();
g_pRTCSemaphore = xSemaphoreCreateMutex();
// Create a queue capable of containing 1 uint16_t values.
// this queue will be used to receive the sensor data received from the CAN Network
xQueueData1 = xQueueCreate( 1, sizeof( Node_t ) );
xQueueData2 = xQueueCreate( 1, sizeof( Node_t ) );
xQueueData3 = xQueueCreate( 1, sizeof( Node_t ) );
xQueueData4 = xQueueCreate( 1, sizeof( Node_t ) );
xQueueData5 = xQueueCreate( 1, sizeof( Node_t ) );
xQueueData6 = xQueueCreate( 1, sizeof( Node_t ) );
xTaskCreate( Tx_Task, "Tx_Task", 100, NULL, 11, &Tx_Task_Handle );
// Rx task has to be of highest priority to force the task to run after an interrupt occures
// this will be as if the interrupt did the processing of the task
xTaskCreate( Rx_Task, "Rx_Task", 100, NULL, 12, &Rx_Task_Handle );
xTaskCreate( DispCal_Task, "DispCal_Task", 100, NULL, 7, &DispCal_Task_Handle );
xTaskCreate( DisplayT1_Task, "DisplayT1_Task", 100, NULL, 6, &DisplayT1_Task_Handle );
xTaskCreate( DisplayT2_Task, "DisplayT2_Task", 100, NULL, 5, &DisplayT2_Task_Handle );
xTaskCreate( DisplayT3_Task, "DisplayT3_Task", 100, NULL, 4, &DisplayT3_Task_Handle );
xTaskCreate( DisplayT4_Task, "DisplayT4_Task", 100, NULL, 3, &DisplayT4_Task_Handle );
xTaskCreate( DisplayT5_Task, "DisplayT5_Task", 100, NULL, 2, &DisplayT5_Task_Handle );
xTaskCreate( DisplayT6_Task, "DisplayT6_Task", 100, NULL, 1, &DisplayT6_Task_Handle );
xTaskCreate( SetupScreen_Task, "SetupScreen_Task", 100, NULL, 9, &SetupScreen_Task_Handle );
// create ButtonsPoll_Task
if(ButtonsPoll_Task_Init() != TRUE)
{
while(1)
{
// Loop here if task was not created
}
}
//
// Start the scheduler. This should not return.
//
vTaskStartScheduler();
//
// In case the scheduler returns for some reason, print an error and loop
// forever.
//
while(1)
{
}
}
void vApplicationTickHook( void )
{
ui32TickCounter++;
}