]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/msp430_IAR/ParTest/ParTest.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / msp430_IAR / 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 \r
45 /* Scheduler includes. */\r
46 #include "FreeRTOS.h"\r
47 #include "task.h"\r
48 \r
49 /* Demo application includes. */\r
50 #include "partest.h"\r
51 \r
52 /* Constants required to setup the LCD. */\r
53 #define LCD_DIV_64 5\r
54 \r
55 /* Constants required to access the "LED's".  The LED segments are turned on\r
56 and off to generate '*' characters. */\r
57 #define partstNUM_LEDS                  ( ( unsigned char ) 6 )\r
58 #define partstSEGMENTS_ON               ( ( unsigned char ) 0x0f )\r
59 #define partstSEGMENTS_OFF              ( ( unsigned char ) 0x00 )\r
60 \r
61 /* The LED number of the real on board LED, rather than a simulated LED. */\r
62 #define partstON_BOARD_LED              ( ( unsigned portBASE_TYPE ) 10 )\r
63 #define mainON_BOARD_LED_BIT    ( ( unsigned char ) 0x01 )\r
64 \r
65 /* The LCD segments used to generate the '*' characters for LED's 0 to 5. */\r
66 unsigned char * const ucRHSSegments[ partstNUM_LEDS ] = {       ( unsigned char * )0xa4, \r
67                                                                                                                                 ( unsigned char * )0xa2, \r
68                                                                                                                                 ( unsigned char * )0xa0, \r
69                                                                                                                                 ( unsigned char * )0x9e,\r
70                                                                                                                                 ( unsigned char * )0x9c,\r
71                                                                                                                                 ( unsigned char * )0x9a };\r
72 \r
73 unsigned char * const ucLHSSegments[ partstNUM_LEDS ] = {       ( unsigned char * )0xa3, \r
74                                                                                                                                 ( unsigned char * )0xa1, \r
75                                                                                                                                 ( unsigned char * )0x9f, \r
76                                                                                                                                 ( unsigned char * )0x9d,\r
77                                                                                                                                 ( unsigned char * )0x9b,\r
78                                                                                                                                 ( unsigned char * )0x99 };\r
79 \r
80 /*\r
81  * Toggle the single genuine built in LED.\r
82  */\r
83 static void prvToggleOnBoardLED( void );\r
84 \r
85 /*-----------------------------------------------------------*/\r
86 \r
87 void vParTestInitialise( void )\r
88 {\r
89         /* Initialise the LCD hardware. */\r
90 \r
91         /* Used for the onboard LED. */\r
92         P1DIR = 0x01;\r
93 \r
94         // Setup Basic Timer for LCD operation\r
95         BTCTL = (LCD_DIV_64+0x23);\r
96 \r
97         // Setup port functions\r
98         P1SEL = 0x32;\r
99         P2SEL = 0x00;\r
100         P3SEL = 0x00;\r
101         P4SEL = 0xFC;\r
102         P5SEL = 0xFF;\r
103         \r
104         /* Initialise all segments to off. */\r
105         LCDM1 = partstSEGMENTS_OFF;     \r
106         LCDM2 = partstSEGMENTS_OFF;     \r
107         LCDM3 = partstSEGMENTS_OFF;     \r
108         LCDM4 = partstSEGMENTS_OFF;     \r
109         LCDM5 = partstSEGMENTS_OFF;     \r
110         LCDM6 = partstSEGMENTS_OFF;     \r
111         LCDM7 = partstSEGMENTS_OFF;     \r
112         LCDM8 = partstSEGMENTS_OFF;     \r
113         LCDM9 = partstSEGMENTS_OFF;     \r
114         LCDM10 = partstSEGMENTS_OFF;    \r
115         LCDM11 = partstSEGMENTS_OFF;    \r
116         LCDM12 = partstSEGMENTS_OFF;    \r
117         LCDM13 = partstSEGMENTS_OFF;    \r
118         LCDM14 = partstSEGMENTS_OFF;    \r
119         LCDM15 = partstSEGMENTS_OFF;    \r
120         LCDM16 = partstSEGMENTS_OFF;    \r
121         LCDM17 = partstSEGMENTS_OFF;    \r
122         LCDM18 = partstSEGMENTS_OFF;    \r
123         LCDM19 = partstSEGMENTS_OFF;    \r
124         LCDM20 = partstSEGMENTS_OFF;    \r
125 \r
126         /* Setup LCD control. */\r
127         LCDCTL = (LCDSG0_7|LCD4MUX|LCDON);\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
132 {\r
133         /* Set or clear the output [in this case show or hide the '*' character. */\r
134         if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )\r
135         {\r
136                 vTaskSuspendAll();\r
137                 {\r
138                         if( xValue )\r
139                         {\r
140                                 /* Turn on the segments required to show the '*'. */\r
141                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
142                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
143                         }\r
144                         else\r
145                         {\r
146                                 /* Turn off all the segments. */\r
147                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
148                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
149                         }\r
150                 }\r
151                 xTaskResumeAll();\r
152         }\r
153 }\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
157 {\r
158         if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )\r
159         {\r
160                 vTaskSuspendAll();\r
161                 {\r
162                         /* If the '*' is already showing - hide it.  If it is not already\r
163                         showing then show it. */\r
164                         if( *( ucRHSSegments[ uxLED ] ) )\r
165                         {\r
166                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
167                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;\r
168                         }\r
169                         else\r
170                         {\r
171                                 *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
172                                 *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;\r
173                         }\r
174                 }\r
175                 xTaskResumeAll();\r
176         }\r
177         else\r
178         {\r
179                 if( uxLED == partstON_BOARD_LED )\r
180                 {\r
181                         /* The request related to the genuine on board LED. */\r
182                         prvToggleOnBoardLED();\r
183                 }\r
184         }       \r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvToggleOnBoardLED( void )\r
189 {\r
190 static unsigned short sState = pdFALSE;\r
191 \r
192         /* Toggle the state of the single genuine on board LED. */\r
193         if( sState )    \r
194         {\r
195                 P1OUT |= mainON_BOARD_LED_BIT;\r
196         }\r
197         else\r
198         {\r
199                 P1OUT &= ~mainON_BOARD_LED_BIT;\r
200         }\r
201 \r
202         sState = !sState;\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 \r