2 * FreeRTOS Kernel V10.2.0
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
36 * This file implements the code that is not demo specific, including the
\r
37 * hardware setup and standard FreeRTOS hook functions.
\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
45 /* Scheduler include files. */
\r
46 #include "FreeRTOS.h"
\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
57 #include "driverlib.h"
\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
63 /*-----------------------------------------------------------*/
\r
66 * Configure the hardware as necessary to run this demo.
\r
68 static void prvSetupHardware( void );
\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
74 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
75 extern void main_blinky( void );
\r
77 extern void main_full( void );
\r
78 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\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
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
91 __persistent /* IAR version. */
\r
93 #pragma PERSISTENT( ucHeap ) /* CCS version. */
\r
95 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] = { 0 };
\r
97 /*-----------------------------------------------------------*/
\r
101 /* See http://www.FreeRTOS.org/MSP430FR5969_Free_RTOS_Demo.html */
\r
103 /* Configure the hardware ready to run the demo. */
\r
104 prvSetupHardware();
\r
106 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
108 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
120 /*-----------------------------------------------------------*/
\r
122 void vApplicationMallocFailedHook( void )
\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
130 /* Force an assert. */
\r
131 configASSERT( ( volatile void * ) NULL );
\r
133 /*-----------------------------------------------------------*/
\r
135 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
137 ( void ) pcTaskName;
\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
145 /* Force an assert. */
\r
146 configASSERT( ( volatile void * ) NULL );
\r
148 /*-----------------------------------------------------------*/
\r
150 void vApplicationIdleHook( void )
\r
152 __bis_SR_register( LPM4_bits + GIE );
\r
155 /*-----------------------------------------------------------*/
\r
157 void vApplicationTickHook( void )
\r
159 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
161 /* Call the periodic event group from ISR demo. */
\r
162 vPeriodicEventGroupsProcessing();
\r
164 /* Call the code that 'gives' a task notification from an ISR. */
\r
165 xNotifyTaskFromISR();
\r
169 /*-----------------------------------------------------------*/
\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
179 const unsigned short usACLK_Frequency_Hz = 32768;
\r
181 /* Ensure the timer is stopped. */
\r
184 /* Run the timer from the ACLK. */
\r
187 /* Clear everything to start with. */
\r
190 /* Set the compare match value according to the tick rate we want. */
\r
191 TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;
\r
193 /* Enable the interrupts. */
\r
196 /* Start up clean. */
\r
202 /*-----------------------------------------------------------*/
\r
204 static void prvSetupHardware( void )
\r
206 /* Stop Watchdog timer. */
\r
207 WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ );
\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
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
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
230 /* Set DCO frequency to 8 MHz. */
\r
231 CS_setDCOFreq( CS_DCORSEL_0, CS_DCOFSEL_6 );
\r
233 /* Set external clock frequency to 32.768 KHz. */
\r
234 CS_setExternalClockSource( 32768, 0 );
\r
236 /* Set ACLK = LFXT. */
\r
237 CS_initClockSignal( CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
239 /* Set SMCLK = DCO with frequency divider of 1. */
\r
240 CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
242 /* Set MCLK = DCO with frequency divider of 1. */
\r
243 CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
245 /* Start XT1 with no time out. */
\r
246 CS_turnOnLFXT( CS_LFXT_DRIVE_0 );
\r
248 /* Disable the GPIO power-on default high-impedance mode. */
\r
251 /*-----------------------------------------------------------*/
\r
253 int _system_pre_init( void )
\r
255 /* Stop Watchdog timer. */
\r
256 WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ );
\r
258 /* Return 1 for segments to be initialised. */
\r