]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MSP430X_MSP430FR5969_LaunchPad_IAR_CCS/main.c
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS / Demo / MSP430X_MSP430FR5969_LaunchPad_IAR_CCS / main.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup and standard FreeRTOS hook functions.\r
38  *\r
39  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
40  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
41  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
42  *\r
43  */\r
44 \r
45 /* Scheduler include files. */\r
46 #include "FreeRTOS.h"\r
47 #include "task.h"\r
48 #include "semphr.h"\r
49 \r
50 /* Standard demo includes, used so the tick hook can exercise some FreeRTOS\r
51 functionality in an interrupt. */\r
52 #include "EventGroupsDemo.h"\r
53 #include "TaskNotify.h"\r
54 #include "ParTest.h" /* LEDs - a historic name for "Parallel Port". */\r
55 \r
56 /* TI includes. */\r
57 #include "driverlib.h"\r
58 \r
59 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
60 or 0 to run the more comprehensive test and demo application. */\r
61 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 \r
65 /*\r
66  * Configure the hardware as necessary to run this demo.\r
67  */\r
68 static void prvSetupHardware( void );\r
69 \r
70 /*\r
71  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
72  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
73  */\r
74 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
75         extern void main_blinky( void );\r
76 #else\r
77         extern void main_full( void );\r
78 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
79 \r
80 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
81 within this file. */\r
82 void vApplicationMallocFailedHook( void );\r
83 void vApplicationIdleHook( void );\r
84 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
85 void vApplicationTickHook( void );\r
86 \r
87 /* The heap is allocated here so the "persistent" qualifier can be used.  This\r
88 requires configAPPLICATION_ALLOCATED_HEAP to be set to 1 in FreeRTOSConfig.h.\r
89 See http://www.freertos.org/a00111.html for more information. */\r
90 #ifdef __ICC430__\r
91         __persistent                                    /* IAR version. */\r
92 #else\r
93         #pragma PERSISTENT( ucHeap )    /* CCS version. */\r
94 #endif\r
95 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] = { 0 };\r
96 \r
97 /*-----------------------------------------------------------*/\r
98 \r
99 int main( void )\r
100 {\r
101         /* See http://www.FreeRTOS.org/MSP430FR5969_Free_RTOS_Demo.html */\r
102 \r
103         /* Configure the hardware ready to run the demo. */\r
104         prvSetupHardware();\r
105 \r
106         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
107         of this file. */\r
108         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
109         {\r
110                 main_blinky();\r
111         }\r
112         #else\r
113         {\r
114                 main_full();\r
115         }\r
116         #endif\r
117 \r
118         return 0;\r
119 }\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 void vApplicationMallocFailedHook( void )\r
123 {\r
124         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
125         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
126         internally by FreeRTOS API functions that create tasks, queues, software\r
127         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
128         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
129 \r
130         /* Force an assert. */\r
131         configASSERT( ( volatile void * ) NULL );\r
132 }\r
133 /*-----------------------------------------------------------*/\r
134 \r
135 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
136 {\r
137         ( void ) pcTaskName;\r
138         ( void ) pxTask;\r
139 \r
140         /* Run time stack overflow checking is performed if\r
141         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
142         function is called if a stack overflow is detected.\r
143         See http://www.freertos.org/Stacks-and-stack-overflow-checking.html */\r
144 \r
145         /* Force an assert. */\r
146         configASSERT( ( volatile void * ) NULL );\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 void vApplicationIdleHook( void )\r
151 {\r
152     __bis_SR_register( LPM4_bits + GIE );\r
153     __no_operation();\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 void vApplicationTickHook( void )\r
158 {\r
159         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
160         {\r
161                 /* Call the periodic event group from ISR demo. */\r
162                 vPeriodicEventGroupsProcessing();\r
163 \r
164                 /* Call the code that 'gives' a task notification from an ISR. */\r
165                 xNotifyTaskFromISR();\r
166         }\r
167         #endif\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 /* The MSP430X port uses this callback function to configure its tick interrupt.\r
172 This allows the application to choose the tick interrupt source.\r
173 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct\r
174 interrupt vector for the chosen tick interrupt source.  This implementation of\r
175 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this\r
176 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */\r
177 void vApplicationSetupTimerInterrupt( void )\r
178 {\r
179 const unsigned short usACLK_Frequency_Hz = 32768;\r
180 \r
181         /* Ensure the timer is stopped. */\r
182         TA0CTL = 0;\r
183 \r
184         /* Run the timer from the ACLK. */\r
185         TA0CTL = TASSEL_1;\r
186 \r
187         /* Clear everything to start with. */\r
188         TA0CTL |= TACLR;\r
189 \r
190         /* Set the compare match value according to the tick rate we want. */\r
191         TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;\r
192 \r
193         /* Enable the interrupts. */\r
194         TA0CCTL0 = CCIE;\r
195 \r
196         /* Start up clean. */\r
197         TA0CTL |= TACLR;\r
198 \r
199         /* Up mode. */\r
200         TA0CTL |= MC_1;\r
201 }\r
202 /*-----------------------------------------------------------*/\r
203 \r
204 static void prvSetupHardware( void )\r
205 {\r
206     /* Stop Watchdog timer. */\r
207     WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ );\r
208 \r
209         /* Set all GPIO pins to output and low. */\r
210         GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
211         GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
212         GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
213         GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
214         GPIO_setOutputLowOnPin( GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15 );\r
215         GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
216         GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
217         GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
218         GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 );\r
219         GPIO_setAsOutputPin( GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15 );\r
220 \r
221         /* Configure P2.0 - UCA0TXD and P2.1 - UCA0RXD. */\r
222         GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 );\r
223         GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 );\r
224         GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P2, GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION );\r
225         GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P2, GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION );\r
226 \r
227         /* Set PJ.4 and PJ.5 for LFXT. */\r
228         GPIO_setAsPeripheralModuleFunctionInputPin(  GPIO_PORT_PJ, GPIO_PIN4 + GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION  );\r
229 \r
230         /* Set DCO frequency to 8 MHz. */\r
231         CS_setDCOFreq( CS_DCORSEL_0, CS_DCOFSEL_6 );\r
232 \r
233         /* Set external clock frequency to 32.768 KHz. */\r
234         CS_setExternalClockSource( 32768, 0 );\r
235 \r
236         /* Set ACLK = LFXT. */\r
237         CS_initClockSignal( CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1 );\r
238 \r
239         /* Set SMCLK = DCO with frequency divider of 1. */\r
240         CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );\r
241 \r
242         /* Set MCLK = DCO with frequency divider of 1. */\r
243         CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );\r
244 \r
245         /* Start XT1 with no time out. */\r
246         CS_turnOnLFXT( CS_LFXT_DRIVE_0 );\r
247 \r
248         /* Disable the GPIO power-on default high-impedance mode. */\r
249         PMM_unlockLPM5();\r
250 }\r
251 /*-----------------------------------------------------------*/\r
252 \r
253 int _system_pre_init( void )\r
254 {\r
255     /* Stop Watchdog timer. */\r
256     WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ );\r
257 \r
258     /* Return 1 for segments to be initialised. */\r
259     return 1;\r
260 }\r
261 \r
262 \r