mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Continue to develop the MSP430X IAR demo project - still a work in progress.
This commit is contained in:
parent
df4e7ceba0
commit
ae6380f70b
|
@ -69,18 +69,18 @@
|
||||||
#define configUSE_PREEMPTION 1
|
#define configUSE_PREEMPTION 1
|
||||||
#define configUSE_IDLE_HOOK 1
|
#define configUSE_IDLE_HOOK 1
|
||||||
#define configUSE_TICK_HOOK 1
|
#define configUSE_TICK_HOOK 1
|
||||||
#define configCPU_CLOCK_HZ ( 16000000UL )
|
#define configCPU_CLOCK_HZ ( 8000000UL )
|
||||||
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
||||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
||||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 )
|
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 )
|
||||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 5 * 1024 ) )
|
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 10 * 1024 ) )
|
||||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||||
#define configUSE_TRACE_FACILITY 0
|
#define configUSE_TRACE_FACILITY 0
|
||||||
#define configUSE_16_BIT_TICKS 0
|
#define configUSE_16_BIT_TICKS 0
|
||||||
#define configIDLE_SHOULD_YIELD 1
|
#define configIDLE_SHOULD_YIELD 1
|
||||||
#define configUSE_MUTEXES 1
|
#define configUSE_MUTEXES 1
|
||||||
#define configQUEUE_REGISTRY_SIZE 5
|
#define configQUEUE_REGISTRY_SIZE 5
|
||||||
#define configGENERATE_RUN_TIME_STATS 0
|
#define configGENERATE_RUN_TIME_STATS 1
|
||||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||||
#define configUSE_RECURSIVE_MUTEXES 0
|
#define configUSE_RECURSIVE_MUTEXES 0
|
||||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||||
|
@ -103,6 +103,16 @@ to exclude the API function. */
|
||||||
|
|
||||||
#define configTICK_INTERRUPT_VECTOR TIMER0_A0_VECTOR
|
#define configTICK_INTERRUPT_VECTOR TIMER0_A0_VECTOR
|
||||||
|
|
||||||
|
/* Prevent the following definitions being included when FreeRTOSConfig.h
|
||||||
|
is included from an asm file. */
|
||||||
|
#ifdef __ICC430__
|
||||||
|
extern void vConfigureTimerForRunTimeStats( void );
|
||||||
|
extern inline unsigned long ulGetRunTimeStatsTime( void );
|
||||||
|
extern volatile unsigned long ulStatsOverflowCount;
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
|
||||||
|
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
|
||||||
|
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeStatsTime()
|
||||||
|
|
||||||
#endif /* FREERTOS_CONFIG_H */
|
#endif /* FREERTOS_CONFIG_H */
|
||||||
|
|
||||||
|
|
136
Demo/MSP430X_MSP430F5438_IAR/ParTest.c
Normal file
136
Demo/MSP430X_MSP430F5438_IAR/ParTest.c
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* If you are: *
|
||||||
|
* *
|
||||||
|
* + New to FreeRTOS, *
|
||||||
|
* + Wanting to learn FreeRTOS or multitasking in general quickly *
|
||||||
|
* + Looking for basic training, *
|
||||||
|
* + Wanting to improve your FreeRTOS skills and productivity *
|
||||||
|
* *
|
||||||
|
* then take a look at the FreeRTOS books - available as PDF or paperback *
|
||||||
|
* *
|
||||||
|
* "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
||||||
|
* http://www.FreeRTOS.org/Documentation *
|
||||||
|
* *
|
||||||
|
* A pdf reference manual is also available. Both are usually delivered *
|
||||||
|
* to your inbox within 20 minutes to two hours when purchased between 8am *
|
||||||
|
* and 8pm GMT (although please allow up to 24 hours in case of *
|
||||||
|
* exceptional circumstances). Thank you for your support! *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
This file is part of the FreeRTOS distribution.
|
||||||
|
|
||||||
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
|
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||||
|
***NOTE*** The exception to the GPL is included to allow you to distribute
|
||||||
|
a combined work that includes FreeRTOS without being obliged to provide the
|
||||||
|
source code for proprietary components outside of the FreeRTOS kernel.
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
more details. You should have received a copy of the GNU General Public
|
||||||
|
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
||||||
|
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
||||||
|
by writing to Richard Barry, contact details for whom are available on the
|
||||||
|
FreeRTOS WEB site.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
|
contact details.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
|
critical systems.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
|
licensing and training services.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------
|
||||||
|
* Simple parallel port IO routines to flash LEDs.
|
||||||
|
*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Kernel includes. */
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
/* Hardware includes. */
|
||||||
|
#include "msp430.h"
|
||||||
|
#include "hal_MSP-EXP430F5438.h"
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vParTestInitialise( void )
|
||||||
|
{
|
||||||
|
/* The port used by the two LEDs is configured from halBoardInit() so
|
||||||
|
nothing needs to be done here. */
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
|
||||||
|
{
|
||||||
|
taskENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
if( xValue != pdFALSE )
|
||||||
|
{
|
||||||
|
switch( uxLED )
|
||||||
|
{
|
||||||
|
case 0: LED_PORT_OUT |= LED_1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: LED_PORT_OUT |= LED_2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch( uxLED )
|
||||||
|
{
|
||||||
|
case 0: LED_PORT_OUT &= ~LED_1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: LED_PORT_OUT &= ~LED_2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
|
||||||
|
{
|
||||||
|
taskENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
switch( uxLED )
|
||||||
|
{
|
||||||
|
case 0: if( ( LED_PORT_OUT & LED_1 ) == 0 )
|
||||||
|
{
|
||||||
|
LED_PORT_OUT |= LED_1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LED_PORT_OUT &= ~LED_1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: if( ( LED_PORT_OUT & LED_2 ) == 0 )
|
||||||
|
{
|
||||||
|
LED_PORT_OUT |= LED_2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LED_PORT_OUT &= ~LED_2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>EMUVerifyDownloadP7</name>
|
<name>EMUVerifyDownloadP7</name>
|
||||||
<state>0</state>
|
<state>1</state>
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>EraseOptionSlaveP7</name>
|
<name>EraseOptionSlaveP7</name>
|
||||||
|
@ -240,7 +240,7 @@
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>TargetSettlingtime</name>
|
<name>TargetSettlingtime</name>
|
||||||
<state>0</state>
|
<state>10</state>
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>AllowAccessToBSL</name>
|
<name>AllowAccessToBSL</name>
|
||||||
|
|
|
@ -1910,6 +1910,12 @@
|
||||||
<name>$PROJ_DIR$\MSP-EXP430F5438_HAL\hal_usb.h</name>
|
<name>$PROJ_DIR$\MSP-EXP430F5438_HAL\hal_usb.h</name>
|
||||||
</file>
|
</file>
|
||||||
</group>
|
</group>
|
||||||
|
<group>
|
||||||
|
<name>Standard_Demo_Tasks</name>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\Common\Minimal\comtest.c</name>
|
||||||
|
</file>
|
||||||
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<name>UserExperienceDemo</name>
|
<name>UserExperienceDemo</name>
|
||||||
<file>
|
<file>
|
||||||
|
@ -2054,12 +2060,18 @@
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\main.c</name>
|
<name>$PROJ_DIR$\main.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\ParTest.c</name>
|
||||||
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\readme.txt</name>
|
<name>$PROJ_DIR$\readme.txt</name>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\RegTest.s43</name>
|
<name>$PROJ_DIR$\RegTest.s43</name>
|
||||||
</file>
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\serial.c</name>
|
||||||
|
</file>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -195,9 +195,9 @@
|
||||||
|
|
||||||
// *** Modified to place code in high memory and insodoing, testing the port.
|
// *** Modified to place code in high memory and insodoing, testing the port.
|
||||||
// Original code
|
// Original code
|
||||||
//-P(CODE)CODE=5C00-FF7F,10000-45BFF
|
-P(CODE)CODE=5C00-FF7F,10000-45BFF
|
||||||
// Modified code
|
// Modified code
|
||||||
-P(CODE)CODE=10000-45BFF
|
//-P(CODE)CODE=10000-45BFF
|
||||||
-Z(CODE)CODE_ID
|
-Z(CODE)CODE_ID
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
|
@ -40,9 +40,10 @@
|
||||||
int __low_level_init(void)
|
int __low_level_init(void)
|
||||||
{
|
{
|
||||||
/* Insert your low-level initializations here */
|
/* Insert your low-level initializations here */
|
||||||
|
_DINT();
|
||||||
WDTCTL = WDTPW+WDTHOLD;
|
WDTCTL = WDTPW+WDTHOLD;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return value:
|
* Return value:
|
||||||
*
|
*
|
||||||
|
|
|
@ -50,15 +50,23 @@
|
||||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
licensing and training services.
|
licensing and training services.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Standard includes. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* FreeRTOS includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
/* Hardware includes. */
|
||||||
#include "msp430.h"
|
#include "msp430.h"
|
||||||
#include "hal_MSP-EXP430F5438.h"
|
#include "hal_MSP-EXP430F5438.h"
|
||||||
|
|
||||||
|
/* Standard demo includes. */
|
||||||
|
#include "ParTest.h"
|
||||||
|
#include "comtest2.h"
|
||||||
|
|
||||||
/* Codes sent within messages to the LCD task so the LCD task can interpret
|
/* Codes sent within messages to the LCD task so the LCD task can interpret
|
||||||
exactly what the message it just received was. These are sent in the
|
exactly what the message it just received was. These are sent in the
|
||||||
cMessageID member of the message structure (defined below). */
|
cMessageID member of the message structure (defined below). */
|
||||||
|
@ -67,7 +75,7 @@ cMessageID member of the message structure (defined below). */
|
||||||
#define mainMESSAGE_STATUS ( 3 )
|
#define mainMESSAGE_STATUS ( 3 )
|
||||||
|
|
||||||
/* When the cMessageID member of the message sent to the LCD task is
|
/* When the cMessageID member of the message sent to the LCD task is
|
||||||
mainMESSAGE_STATUS then these definitions are sent in the cMessageValue member
|
mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member
|
||||||
of the same message and indicate what the status actually is. */
|
of the same message and indicate what the status actually is. */
|
||||||
#define mainERROR_DYNAMIC_TASKS ( pdPASS + 1 )
|
#define mainERROR_DYNAMIC_TASKS ( pdPASS + 1 )
|
||||||
#define mainERROR_COM_TEST ( pdPASS + 2 )
|
#define mainERROR_COM_TEST ( pdPASS + 2 )
|
||||||
|
@ -79,6 +87,13 @@ to send messages from tasks and interrupts the the LCD task. */
|
||||||
#define mainQUEUE_LENGTH ( 5 )
|
#define mainQUEUE_LENGTH ( 5 )
|
||||||
|
|
||||||
#define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
#define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||||
|
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||||
|
|
||||||
|
/* The LED used by the comtest tasks. See the comtest.c file for more
|
||||||
|
information. In this case it is deliberately out of range as there are only
|
||||||
|
two LEDs, and they are both already in use. */
|
||||||
|
#define mainCOM_TEST_LED ( 3 )
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -92,6 +107,7 @@ static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue );
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;
|
volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;
|
||||||
|
volatile unsigned long ulStatsOverflowCount = 0;
|
||||||
|
|
||||||
/* The handle of the queue used to send messages from tasks and interrupts to
|
/* The handle of the queue used to send messages from tasks and interrupts to
|
||||||
the LCD task. */
|
the LCD task. */
|
||||||
|
@ -102,31 +118,34 @@ task. */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char cMessageID; /* << States what the message is. */
|
char cMessageID; /* << States what the message is. */
|
||||||
char cMessageValue; /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID. */
|
unsigned long ulMessageValue; /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID. */
|
||||||
} xQueueMessage;
|
} xQueueMessage;
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void main( void )
|
void main( void )
|
||||||
{
|
{
|
||||||
prvSetupHardware();
|
prvSetupHardware();
|
||||||
|
|
||||||
/* Create the queue used by tasks and interrupts to send strings to the LCD
|
/* Create the queue used by tasks and interrupts to send strings to the LCD
|
||||||
task. */
|
task. */
|
||||||
xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
|
xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
|
||||||
|
|
||||||
if( xLCDQueue != NULL )
|
if( xLCDQueue != NULL )
|
||||||
{
|
{
|
||||||
/* Add the created queue to the queue registry so it can be viewed in
|
/* Add the created queue to the queue registry so it can be viewed in
|
||||||
the IAR FreeRTOS state viewer plug-in. */
|
the IAR FreeRTOS state viewer plug-in. */
|
||||||
vQueueAddToRegistry( xLCDQueue, "LCDQueue" );
|
vQueueAddToRegistry( xLCDQueue, "LCDQueue" );
|
||||||
|
|
||||||
|
/* Create the standard demo tasks. */
|
||||||
|
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, 9600, mainCOM_TEST_LED );
|
||||||
|
|
||||||
/* Create the terminal IO and button poll tasks, as described at the top
|
/* Create the terminal IO and button poll tasks, as described at the top
|
||||||
of this file. */
|
of this file. */
|
||||||
xTaskCreate( prvTerminalIOTask, ( signed char * ) "IO", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
|
xTaskCreate( prvTerminalIOTask, ( signed char * ) "IO", configMINIMAL_STACK_SIZE * 2, NULL, mainLCD_TASK_PRIORITY, NULL );
|
||||||
xTaskCreate( prvButtonPollTask, ( signed char * ) "ButPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( prvButtonPollTask, ( signed char * ) "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
|
|
||||||
xTaskCreate( vRegTest1Task, "RegTest1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
|
xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
|
||||||
xTaskCreate( vRegTest2Task, "RegTest2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
|
xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
}
|
}
|
||||||
for( ;; );
|
for( ;; );
|
||||||
|
@ -169,7 +188,7 @@ static char cBuffer[ 512 ];
|
||||||
informed this task that the up
|
informed this task that the up
|
||||||
button on the joystick input has
|
button on the joystick input has
|
||||||
been pressed or released. */
|
been pressed or released. */
|
||||||
sprintf( cBuffer, "Button up = %d", xReceivedMessage.cMessageValue );
|
sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mainMESSAGE_BUTTON_SEL : /* The select button interrupt
|
case mainMESSAGE_BUTTON_SEL : /* The select button interrupt
|
||||||
|
@ -180,7 +199,8 @@ static char cBuffer[ 512 ];
|
||||||
the terminal IO window in the IAR
|
the terminal IO window in the IAR
|
||||||
embedded workbench. */
|
embedded workbench. */
|
||||||
printf( "\nTask\t Abs Time\t %%Time\n*****************************************" );
|
printf( "\nTask\t Abs Time\t %%Time\n*****************************************" );
|
||||||
// vTaskGetRunTimeStats( ( signed char * ) cBuffer );
|
fflush( stdout );
|
||||||
|
vTaskGetRunTimeStats( ( signed char * ) cBuffer );
|
||||||
// printf( cBuffer );
|
// printf( cBuffer );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -189,7 +209,7 @@ static char cBuffer[ 512 ];
|
||||||
task of the system status.
|
task of the system status.
|
||||||
Generate a string in accordance
|
Generate a string in accordance
|
||||||
with the status value. */
|
with the status value. */
|
||||||
prvGenerateStatusMessage( cBuffer, xReceivedMessage.cMessageValue );
|
prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default : sprintf( cBuffer, "Unknown message" );
|
default : sprintf( cBuffer, "Unknown message" );
|
||||||
|
@ -214,7 +234,7 @@ static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue )
|
||||||
break;
|
break;
|
||||||
case mainERROR_DYNAMIC_TASKS : sprintf( pcBuffer, "Error: Dynamic tasks" );
|
case mainERROR_DYNAMIC_TASKS : sprintf( pcBuffer, "Error: Dynamic tasks" );
|
||||||
break;
|
break;
|
||||||
case mainERROR_COM_TEST : sprintf( pcBuffer, "Err: loop connected?" ); /* Error in COM test - is the Loopback connector connected? */
|
case mainERROR_COM_TEST : sprintf( pcBuffer, "Err: COM test" ); /* Error in COM test - is the Loopback connector connected? */
|
||||||
break;
|
break;
|
||||||
case mainERROR_GEN_QUEUE_TEST : sprintf( pcBuffer, "Error: Gen Q test" );
|
case mainERROR_GEN_QUEUE_TEST : sprintf( pcBuffer, "Error: Gen Q test" );
|
||||||
break;
|
break;
|
||||||
|
@ -247,7 +267,7 @@ xQueueMessage xMessage;
|
||||||
{
|
{
|
||||||
/* The state has changed, send a message to the LCD task. */
|
/* The state has changed, send a message to the LCD task. */
|
||||||
xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
|
xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
|
||||||
xMessage.cMessageValue = ucState;
|
xMessage.ulMessageValue = ( unsigned long ) ucState;
|
||||||
ucLastState = ucState;
|
ucLastState = ucState;
|
||||||
xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
|
xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
|
||||||
}
|
}
|
||||||
|
@ -261,11 +281,13 @@ xQueueMessage xMessage;
|
||||||
|
|
||||||
static void prvSetupHardware( void )
|
static void prvSetupHardware( void )
|
||||||
{
|
{
|
||||||
|
unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL );
|
||||||
|
|
||||||
halBoardInit();
|
halBoardInit();
|
||||||
halButtonsInit( BUTTON_ALL );
|
halButtonsInit( BUTTON_ALL );
|
||||||
halButtonsInterruptEnable( BUTTON_SELECT );
|
halButtonsInterruptEnable( BUTTON_SELECT );
|
||||||
LFXT_Start (XT1DRIVE_0);
|
LFXT_Start( XT1DRIVE_0 );
|
||||||
Init_FLL_Settle( 18000, 488 );
|
Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 );
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -276,7 +298,7 @@ const unsigned short usACLK_Frequency_Hz = 32768;
|
||||||
/* Ensure the timer is stopped. */
|
/* Ensure the timer is stopped. */
|
||||||
TA0CTL = 0;
|
TA0CTL = 0;
|
||||||
|
|
||||||
/* Run the timer of the ACLK. */
|
/* Run the timer from the ACLK. */
|
||||||
TA0CTL = TASSEL_1;
|
TA0CTL = TASSEL_1;
|
||||||
|
|
||||||
/* Clear everything to start with. */
|
/* Clear everything to start with. */
|
||||||
|
@ -344,26 +366,30 @@ static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
|
||||||
xStatusMessage.lMessageValue = mainERROR_DYNAMIC_TASKS;
|
xStatusMessage.lMessageValue = mainERROR_DYNAMIC_TASKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xAreComTestTasksStillRunning() != pdPASS )
|
|
||||||
{
|
|
||||||
xStatusMessage.lMessageValue = mainERROR_COM_TEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( xAreGenericQueueTasksStillRunning() != pdPASS )
|
if( xAreGenericQueueTasksStillRunning() != pdPASS )
|
||||||
{
|
{
|
||||||
xStatusMessage.lMessageValue = mainERROR_GEN_QUEUE_TEST;
|
xStatusMessage.lMessageValue = mainERROR_GEN_QUEUE_TEST;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/* See if the standard demo tasks are executing as expected, changing
|
||||||
|
the message that is sent to the LCD task from PASS to an error code if
|
||||||
|
any tasks set reports an error. */
|
||||||
|
if( xAreComTestTasksStillRunning() != pdPASS )
|
||||||
|
{
|
||||||
|
xStatusMessage.ulMessageValue = mainERROR_COM_TEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Check the reg test tasks are still cycling. They will stop incrementing
|
/* Check the reg test tasks are still cycling. They will stop incrementing
|
||||||
their loop counters if they encounter an error. */
|
their loop counters if they encounter an error. */
|
||||||
if( usRegTest1Counter == usLastRegTest1Counter )
|
if( usRegTest1Counter == usLastRegTest1Counter )
|
||||||
{
|
{
|
||||||
xStatusMessage.cMessageValue = mainERROR_REG_TEST;
|
xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( usRegTest2Counter == usLastRegTest2Counter )
|
if( usRegTest2Counter == usLastRegTest2Counter )
|
||||||
{
|
{
|
||||||
xStatusMessage.cMessageValue = mainERROR_REG_TEST;
|
xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
usLastRegTest1Counter = usRegTest1Counter;
|
usLastRegTest1Counter = usRegTest1Counter;
|
||||||
|
@ -391,5 +417,70 @@ static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#pragma vector=PORT2_VECTOR
|
||||||
|
__interrupt static void prvSelectButtonInterrupt(void)
|
||||||
|
{
|
||||||
|
/* Define the message sent to the LCD task from this interrupt. */
|
||||||
|
static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt!" };
|
||||||
|
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
|
/* This is the interrupt handler for the joystick select button input.
|
||||||
|
The button has been pushed, write a message to the LCD via the LCD task. */
|
||||||
|
xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
|
||||||
|
|
||||||
|
P2IFG = 0;
|
||||||
|
|
||||||
|
/* If writing to xLCDQueue caused a task to unblock, and the unblocked task
|
||||||
|
has a priority equal to or above the task that this interrupt interrupted,
|
||||||
|
then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
|
||||||
|
xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
|
||||||
|
interrupt returns directly to the higher priority unblocked task. */
|
||||||
|
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vConfigureTimerForRunTimeStats( void )
|
||||||
|
{
|
||||||
|
/* Ensure the timer is stopped. */
|
||||||
|
TA1CTL = 0;
|
||||||
|
|
||||||
|
/* Run the timer from the ACLK/4. */
|
||||||
|
TA1CTL = TASSEL_1 | ID__4;
|
||||||
|
|
||||||
|
/* Clear everything to start with. */
|
||||||
|
TA1CTL |= TACLR;
|
||||||
|
|
||||||
|
/* Enable the interrupts. */
|
||||||
|
TA1CCTL0 = CCIE;
|
||||||
|
|
||||||
|
/* Start up clean. */
|
||||||
|
TA1CTL |= TACLR;
|
||||||
|
|
||||||
|
/* Continuous mode. */
|
||||||
|
TA1CTL |= MC__CONTINOUS;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#pragma vector=TIMER1_A0_VECTOR
|
||||||
|
static __interrupt void prvRunTimeStatsOverflowISR( void )
|
||||||
|
{
|
||||||
|
ulStatsOverflowCount++;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
inline unsigned long ulGetRunTimeStatsTime( void )
|
||||||
|
{
|
||||||
|
unsigned long ulReturn;
|
||||||
|
|
||||||
|
TA1CTL &= ~MC__CONTINOUS;
|
||||||
|
ulReturn = ( ( ulStatsOverflowCount << 16UL ) | ( unsigned long ) TA1R );
|
||||||
|
TA1CTL |= MC__CONTINOUS;
|
||||||
|
|
||||||
|
return ulReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
240
Demo/MSP430X_MSP430F5438_IAR/serial.c
Normal file
240
Demo/MSP430X_MSP430F5438_IAR/serial.c
Normal file
|
@ -0,0 +1,240 @@
|
||||||
|
/*
|
||||||
|
FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* If you are: *
|
||||||
|
* *
|
||||||
|
* + New to FreeRTOS, *
|
||||||
|
* + Wanting to learn FreeRTOS or multitasking in general quickly *
|
||||||
|
* + Looking for basic training, *
|
||||||
|
* + Wanting to improve your FreeRTOS skills and productivity *
|
||||||
|
* *
|
||||||
|
* then take a look at the FreeRTOS books - available as PDF or paperback *
|
||||||
|
* *
|
||||||
|
* "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
||||||
|
* http://www.FreeRTOS.org/Documentation *
|
||||||
|
* *
|
||||||
|
* A pdf reference manual is also available. Both are usually delivered *
|
||||||
|
* to your inbox within 20 minutes to two hours when purchased between 8am *
|
||||||
|
* and 8pm GMT (although please allow up to 24 hours in case of *
|
||||||
|
* exceptional circumstances). Thank you for your support! *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
This file is part of the FreeRTOS distribution.
|
||||||
|
|
||||||
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
|
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||||
|
***NOTE*** The exception to the GPL is included to allow you to distribute
|
||||||
|
a combined work that includes FreeRTOS without being obliged to provide the
|
||||||
|
source code for proprietary components outside of the FreeRTOS kernel.
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
more details. You should have received a copy of the GNU General Public
|
||||||
|
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
||||||
|
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
||||||
|
by writing to Richard Barry, contact details for whom are available on the
|
||||||
|
FreeRTOS WEB site.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
|
contact details.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
|
critical systems.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
|
licensing and training services.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
|
||||||
|
*
|
||||||
|
* This file only supports UART A0 in loopback mode, and has not been tested
|
||||||
|
* for real UART operation (only loopback mode) so is not guaranteed to have
|
||||||
|
* a correct baud rate configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Standard includes. */
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* Scheduler includes. */
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "queue.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
/* Demo application includes. */
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
|
/* HAL includes. */
|
||||||
|
#include "hal_usb.h"
|
||||||
|
|
||||||
|
/* Constants required to setup the hardware. */
|
||||||
|
#define serTX_AND_RX ( ( unsigned portCHAR ) 0x03 )
|
||||||
|
|
||||||
|
/* Misc. constants. */
|
||||||
|
#define serNO_BLOCK ( ( portTickType ) 0 )
|
||||||
|
|
||||||
|
/* The queue used to hold received characters. */
|
||||||
|
static xQueueHandle xRxedChars;
|
||||||
|
|
||||||
|
/* The queue used to hold characters waiting transmission. */
|
||||||
|
static xQueueHandle xCharsForTx;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
|
||||||
|
{
|
||||||
|
unsigned portLONG ulBaudRateCount;
|
||||||
|
|
||||||
|
/* Initialise the hardware. */
|
||||||
|
|
||||||
|
/* Generate the baud rate constants for the wanted baud rate. */
|
||||||
|
ulBaudRateCount = configCPU_CLOCK_HZ / ulWantedBaud;
|
||||||
|
|
||||||
|
portENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
/* Create the queues used by the com test task. */
|
||||||
|
xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
|
||||||
|
xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Reset UART. */
|
||||||
|
UCA0CTL1 |= UCSWRST;
|
||||||
|
|
||||||
|
/* Use SMCLK. */
|
||||||
|
UCA0CTL1 = UCSSEL0 | UCSSEL1;
|
||||||
|
|
||||||
|
/* Setup baud rate low byte. */
|
||||||
|
UCA0BR0 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
|
||||||
|
|
||||||
|
/* Setup baud rate high byte. */
|
||||||
|
ulBaudRateCount >>= 8UL;
|
||||||
|
UCA0BR1 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
|
||||||
|
|
||||||
|
/* UCLISTEN sets loopback mode! */
|
||||||
|
UCA0STAT = UCLISTEN;
|
||||||
|
|
||||||
|
/* Clear interrupts. */
|
||||||
|
// UCA0IFG = 0;
|
||||||
|
|
||||||
|
/* Enable interrupts. */
|
||||||
|
UCA0IE |= UCRXIE;
|
||||||
|
|
||||||
|
/* Take out of reset. */
|
||||||
|
UCA0CTL1 &= ~UCSWRST;
|
||||||
|
#else
|
||||||
|
USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD;
|
||||||
|
USB_PORT_DIR |= USB_PIN_TXD;
|
||||||
|
USB_PORT_DIR &= ~USB_PIN_RXD;
|
||||||
|
|
||||||
|
UCA1CTL1 |= UCSWRST; //Reset State
|
||||||
|
UCA1CTL0 = UCMODE_0;
|
||||||
|
|
||||||
|
UCA1CTL0 &= ~UC7BIT; // 8bit char
|
||||||
|
UCA1CTL1 |= UCSSEL_2;
|
||||||
|
// UCA1BR0 = 16; // 8Mhz/57600=138
|
||||||
|
// UCA1BR1 = 1;
|
||||||
|
/* Setup baud rate low byte. */
|
||||||
|
UCA0BR0 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
|
||||||
|
|
||||||
|
/* Setup baud rate high byte. */
|
||||||
|
ulBaudRateCount >>= 8UL;
|
||||||
|
UCA0BR1 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
|
||||||
|
|
||||||
|
UCA1MCTL = 0xE;
|
||||||
|
UCA1CTL1 &= ~UCSWRST;
|
||||||
|
UCA1IE |= UCRXIE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
portEXIT_CRITICAL();
|
||||||
|
|
||||||
|
/* Unlike other ports, this serial code does not allow for more than one
|
||||||
|
com port. We therefore don't return a pointer to a port structure and can
|
||||||
|
instead just return NULL. */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
|
||||||
|
{
|
||||||
|
/* Get the next character from the buffer. Return false if no characters
|
||||||
|
are available, or arrive before xBlockTime expires. */
|
||||||
|
if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
|
||||||
|
{
|
||||||
|
return pdTRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return pdFALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
|
||||||
|
{
|
||||||
|
signed portBASE_TYPE xReturn;
|
||||||
|
|
||||||
|
xReturn = xQueueSend( xCharsForTx, &cOutChar, xBlockTime );
|
||||||
|
UCA0IE |= UCTXIE;
|
||||||
|
|
||||||
|
return xReturn;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
char cTxedBytes[ 512 ];
|
||||||
|
char cRxedBytes[ 512 ];
|
||||||
|
volatile int xIndex = 0;
|
||||||
|
volatile int xIndex2 = 0;
|
||||||
|
|
||||||
|
#pragma vector=USCI_A0_VECTOR
|
||||||
|
static __interrupt void prvUSCI_A0_ISR( void )
|
||||||
|
{
|
||||||
|
signed portCHAR cChar;
|
||||||
|
portBASE_TYPE xTaskWoken = pdFALSE;
|
||||||
|
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
|
while( UCA0IFG & UCRXIFG )
|
||||||
|
{
|
||||||
|
/* Get the character from the UART and post it on the queue of Rxed
|
||||||
|
characters. */
|
||||||
|
cChar = UCA0RXBUF;
|
||||||
|
|
||||||
|
if( xIndex2 < 500 )
|
||||||
|
{
|
||||||
|
cRxedBytes[ xIndex2++ ] = cChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( UCA0IFG & UCTXIFG )
|
||||||
|
{
|
||||||
|
/* The previous character has been transmitted. See if there are any
|
||||||
|
further characters waiting transmission. */
|
||||||
|
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWoken ) == pdTRUE )
|
||||||
|
{
|
||||||
|
if( xIndex < 500 )
|
||||||
|
{
|
||||||
|
cTxedBytes[ xIndex++ ] = cChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There was another character queued - transmit it now. */
|
||||||
|
UCA0TXBUF = cChar;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* There were no other characters to transmit - disable the Tx
|
||||||
|
interrupt. */
|
||||||
|
UCA0IE &= ~UCTXIE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );
|
||||||
|
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue