]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/msp430_GCC/ParTest/ParTest.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / msp430_GCC / ParTest / ParTest.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /*-----------------------------------------------------------\r
30  * Characters on the LCD are used to simulate LED's.  In this case the 'ParTest'\r
31  * is really operating on the LCD display.\r
32  *-----------------------------------------------------------*/\r
33 \r
34 /*\r
35  * This demo is configured to execute on the ES449 prototyping board from\r
36  * SoftBaugh. The ES449 has a built in LCD display and a single built in user\r
37  * LED.  Therefore, in place of flashing an LED, the 'flash' and 'check' tasks\r
38  * toggle '*' characters on the LCD.  The left most '*' represents LED 0, the\r
39  * next LED 1, etc.\r
40  *\r
41  * There is a single genuine on board LED referenced as LED 10.\r
42  */\r
43 \r
44 /* Standard includes. */\r
45 #include <signal.h>\r
46 \r
47 /* Scheduler includes. */\r
48 #include "FreeRTOS.h"\r
49 #include "task.h"\r
50 \r
51 /* Demo application includes. */\r
52 #include "partest.h"\r
53 \r
54 /* Constants required to setup the LCD. */\r
55 #define LCD_DIV_64 5\r
56 \r
57 /* Constants required to access the "LED's".  The LED segments are turned on\r
58 and off to generate '*' characters. */\r
59 #define partstNUM_LEDS                  ( ( unsigned char ) 6 )\r
60 #define partstSEGMENTS_ON               ( ( unsigned char ) 0x0f )\r
61 #define partstSEGMENTS_OFF              ( ( unsigned char ) 0x00 )\r
62 \r
63 /* The LED number of the real on board LED, rather than a simulated LED. */\r
64 #define partstON_BOARD_LED              ( ( unsigned portBASE_TYPE ) 10 )\r
65 #define mainON_BOARD_LED_BIT    ( ( unsigned char ) 0x01 )\r
66 \r
67 /* The LCD segments used to generate the '*' characters for LED's 0 to 5. */\r
68 unsigned char * const ucRHSSegments[ partstNUM_LEDS ] = {       ( unsigned char * )0xa4, \r
69                                                                                                                                 ( unsigned char * )0xa2, \r
70                                                                                                                                 ( unsigned char * )0xa0, \r
71                                                                                                                                 ( unsigned char * )0x9e,\r
72                                                                                                                                 ( unsigned char * )0x9c,\r
73                                                                                                                                 ( unsigned char * )0x9a };\r
74 \r
75 unsigned char * const ucLHSSegments[ partstNUM_LEDS ] = {       ( unsigned char * )0xa3, \r
76                                                                                                                                 ( unsigned char * )0xa1, \r
77                                                                                                                                 ( unsigned char * )0x9f, \r
78                                                                                                                                 ( unsigned char * )0x9d,\r
79                                                                                                                                 ( unsigned char * )0x9b,\r
80                                                                                                                                 ( unsigned char * )0x99 };\r
81 \r
82 /*\r
83  * Toggle the single genuine built in LED.\r
84  */\r
85 static void prvToggleOnBoardLED( void );\r
86 \r
87 /*-----------------------------------------------------------*/\r
88 \r
89 void vParTestInitialise( void )\r
90 {\r
91         /* Initialise the LCD hardware. */\r
92 \r
93         /* Used for the onboard LED. */\r
94         P1DIR = 0x01;\r
95 \r
96         // Setup Basic Timer for LCD operation\r
97         BTCTL = (LCD_DIV_64+0x23);\r
98 \r
99         // Setup port functions\r
100         P1SEL = 0x32;\r
101         P2SEL = 0x00;\r
102         P3SEL = 0x00;\r
103         P4SEL = 0xFC;\r
104         P5SEL = 0xFF;\r
105         \r
106         /* Initialise all segments to off. */\r
107         LCDM1 = partstSEGMENTS_OFF;     \r
108         LCDM2 = partstSEGMENTS_OFF;     \r
109         LCDM3 = partstSEGMENTS_OFF;     \r
110         LCDM4 = partstSEGMENTS_OFF;     \r
111         LCDM5 = partstSEGMENTS_OFF;     \r
112         LCDM6 = partstSEGMENTS_OFF;     \r
113         LCDM7 = partstSEGMENTS_OFF;     \r
114         LCDM8 = partstSEGMENTS_OFF;     \r
115         LCDM9 = partstSEGMENTS_OFF;     \r
116         LCDM10 = partstSEGMENTS_OFF;    \r
117         LCDM11 = partstSEGMENTS_OFF;    \r
118         LCDM12 = partstSEGMENTS_OFF;    \r
119         LCDM13 = partstSEGMENTS_OFF;    \r
120         LCDM14 = partstSEGMENTS_OFF;    \r
121         LCDM15 = partstSEGMENTS_OFF;    \r
122         LCDM16 = partstSEGMENTS_OFF;    \r
123         LCDM17 = partstSEGMENTS_OFF;    \r
124         LCDM18 = partstSEGMENTS_OFF;    \r
125         LCDM19 = partstSEGMENTS_OFF;    \r
126         LCDM20 = partstSEGMENTS_OFF;    \r
127 \r
128         /* Setup LCD control. */\r
129         LCDCTL = (LCDSG0_7|LCD4MUX|LCDON);\r
130 }\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
134 {\r
135         /* Set or clear the output [in this case show or hide the '*' character. */\r
136         if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )\r
137         {\r
138                 vTaskSuspendAll();\r
139                 {\r
140                         if( xValue )\r
141                         {\r
142                                 /* Turn on the segments required to show the '*'. */\r
143                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
144                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
145                         }\r
146                         else\r
147                         {\r
148                                 /* Turn off all the segments. */\r
149                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
150                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
151                         }\r
152                 }\r
153                 xTaskResumeAll();\r
154         }\r
155 }\r
156 /*-----------------------------------------------------------*/\r
157 \r
158 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
159 {\r
160         if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )\r
161         {\r
162                 vTaskSuspendAll();\r
163                 {\r
164                         /* If the '*' is already showing - hide it.  If it is not already\r
165                         showing then show it. */\r
166                         if( *( ucRHSSegments[ uxLED ] ) )\r
167                         {\r
168                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
169                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
170                         }\r
171                         else\r
172                         {\r
173                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
174                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
175                         }\r
176                 }\r
177                 xTaskResumeAll();\r
178         }\r
179         else\r
180         {\r
181                 if( uxLED == partstON_BOARD_LED )\r
182                 {\r
183                         /* The request related to the genuine on board LED. */\r
184                         prvToggleOnBoardLED();\r
185                 }\r
186         }       \r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 static void prvToggleOnBoardLED( void )\r
191 {\r
192 static unsigned short sState = pdFALSE;\r
193 \r
194         /* Toggle the state of the single genuine on board LED. */\r
195         if( sState )    \r
196         {\r
197                 P1OUT |= mainON_BOARD_LED_BIT;\r
198         }\r
199         else\r
200         {\r
201                 P1OUT &= ~mainON_BOARD_LED_BIT;\r
202         }\r
203 \r
204         sState = !sState;\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 \r