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