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