mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Complete CLI demo on SAMD20.
This commit is contained in:
parent
8ffa1b1736
commit
23fa077241
|
@ -107,10 +107,21 @@ static void prvUARTCommandConsoleTask( void *pvParameters );
|
||||||
static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength );
|
static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A UART is used for printf() output and CLI input and output. Configure the
|
* Register the 'standard' sample CLI commands with FreeRTOS+CLI.
|
||||||
* UART and register prvUARTRxNotificationHandler() to handle UART Rx events.
|
*/
|
||||||
|
extern void vRegisterSampleCLICommands( void );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the UART used for IO.and register prvUARTRxNotificationHandler()
|
||||||
|
* to handle UART Rx events.
|
||||||
*/
|
*/
|
||||||
static void prvConfigureUART( struct usart_module *pxCDCUsart );
|
static void prvConfigureUART( struct usart_module *pxCDCUsart );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callback functions registered with the Atmel UART driver. Both functions
|
||||||
|
* just 'give' a semaphore to unblock a task that may be waiting for a
|
||||||
|
* character to be received, or a transmission to complete.
|
||||||
|
*/
|
||||||
static void prvUARTTxNotificationHandler( const struct usart_module *const pxUSART );
|
static void prvUARTTxNotificationHandler( const struct usart_module *const pxUSART );
|
||||||
static void prvUARTRxNotificationHandler( const struct usart_module *const pxUSART );
|
static void prvUARTRxNotificationHandler( const struct usart_module *const pxUSART );
|
||||||
|
|
||||||
|
@ -133,6 +144,8 @@ static xSemaphoreHandle xRxCompleteSemaphore = NULL;
|
||||||
|
|
||||||
void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )
|
void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )
|
||||||
{
|
{
|
||||||
|
vRegisterSampleCLICommands();
|
||||||
|
|
||||||
/* Create that task that handles the console itself. */
|
/* Create that task that handles the console itself. */
|
||||||
xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
|
xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
|
||||||
( const int8_t * const ) "CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
|
( const int8_t * const ) "CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
|
||||||
|
@ -251,7 +264,7 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
|
||||||
|
|
||||||
static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength )
|
static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength )
|
||||||
{
|
{
|
||||||
const portTickType xBlockMax50ms = 50 / portTICK_RATE_MS;
|
const portTickType xBlockMax100ms = 100UL / portTICK_RATE_MS;
|
||||||
|
|
||||||
if( xBufferLength > 0 )
|
if( xBufferLength > 0 )
|
||||||
{
|
{
|
||||||
|
@ -259,7 +272,7 @@ const portTickType xBlockMax50ms = 50 / portTICK_RATE_MS;
|
||||||
|
|
||||||
/* Wait for the Tx to complete so the buffer can be reused without
|
/* Wait for the Tx to complete so the buffer can be reused without
|
||||||
corrupting the data that is being sent. */
|
corrupting the data that is being sent. */
|
||||||
xSemaphoreTake( xTxCompleteSemaphore, xBlockMax50ms );
|
xSemaphoreTake( xTxCompleteSemaphore, xBlockMax100ms );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -100,9 +100,15 @@ extern uint32_t SystemCoreClock;
|
||||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||||
#define configUSE_APPLICATION_TASK_TAG 0
|
#define configUSE_APPLICATION_TASK_TAG 0
|
||||||
#define configUSE_COUNTING_SEMAPHORES 1
|
#define configUSE_COUNTING_SEMAPHORES 1
|
||||||
#define configGENERATE_RUN_TIME_STATS 0
|
|
||||||
#define configUSE_QUEUE_SETS 1
|
#define configUSE_QUEUE_SETS 1
|
||||||
|
|
||||||
|
/* Run time stats related definitions. */
|
||||||
|
void vMainConfigureTimerForRunTimeStats( void );
|
||||||
|
unsigned long ulMainGetRunTimeCounterValue( void );
|
||||||
|
#define configGENERATE_RUN_TIME_STATS 1
|
||||||
|
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vMainConfigureTimerForRunTimeStats()
|
||||||
|
#define portGET_RUN_TIME_COUNTER_VALUE() ulMainGetRunTimeCounterValue()
|
||||||
|
|
||||||
/* Co-routine definitions. */
|
/* Co-routine definitions. */
|
||||||
#define configUSE_CO_ROUTINES 0
|
#define configUSE_CO_ROUTINES 0
|
||||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
||||||
|
@ -124,6 +130,12 @@ to exclude the API function. */
|
||||||
#define INCLUDE_vTaskDelay 1
|
#define INCLUDE_vTaskDelay 1
|
||||||
#define INCLUDE_eTaskGetState 1
|
#define INCLUDE_eTaskGetState 1
|
||||||
|
|
||||||
|
/* This demo makes use of one or more example stats formatting functions. These
|
||||||
|
format the raw data provided by the uxTaskGetSystemState() function in to human
|
||||||
|
readable ASCII form. See the notes in the implementation of vTaskList() within
|
||||||
|
FreeRTOS/Source/tasks.c for limitations. */
|
||||||
|
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||||
|
|
||||||
/* Normal assert() semantics without relying on the provision of an assert.h
|
/* Normal assert() semantics without relying on the provision of an assert.h
|
||||||
header file. */
|
header file. */
|
||||||
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
|
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
|
||||||
|
|
|
@ -72,12 +72,29 @@
|
||||||
/* Library includes. */
|
/* Library includes. */
|
||||||
#include <asf.h>
|
#include <asf.h>
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hardware and driver initialisation can be done in this function.
|
||||||
|
*/
|
||||||
static void prvSetupHardware( void );
|
static void prvSetupHardware( void );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prototypes for the FreeRTOS hook/callback functions. See the comments in
|
||||||
|
* the implementation of each function for more information.
|
||||||
|
*/
|
||||||
void vApplicationMallocFailedHook( void );
|
void vApplicationMallocFailedHook( void );
|
||||||
void vApplicationIdleHook( void );
|
void vApplicationIdleHook( void );
|
||||||
void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );
|
void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );
|
||||||
void vApplicationTickHook( void );
|
void vApplicationTickHook( void );
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Used in the run time stats calculations. */
|
||||||
|
static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
prvSetupHardware();
|
prvSetupHardware();
|
||||||
|
@ -153,4 +170,61 @@ void vApplicationTickHook( void )
|
||||||
code must not attempt to block, and only the interrupt safe FreeRTOS API
|
code must not attempt to block, and only the interrupt safe FreeRTOS API
|
||||||
functions can be used (those that end in FromISR()). */
|
functions can be used (those that end in FromISR()). */
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vMainConfigureTimerForRunTimeStats( void )
|
||||||
|
{
|
||||||
|
/* How many clocks are there per tenth of a millisecond? */
|
||||||
|
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
unsigned long ulMainGetRunTimeCounterValue( void )
|
||||||
|
{
|
||||||
|
unsigned long ulSysTickCounts, ulTickCount, ulReturn;
|
||||||
|
const unsigned long ulSysTickReloadValue = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
|
||||||
|
volatile unsigned long * const pulCurrentSysTickCount = ( ( volatile unsigned long *) 0xe000e018 );
|
||||||
|
volatile unsigned long * const pulInterruptCTRLState = ( ( volatile unsigned long *) 0xe000ed04 );
|
||||||
|
const unsigned long ulSysTickPendingBit = 0x04000000UL;
|
||||||
|
|
||||||
|
/* NOTE: There are potentially race conditions here. However, it is used
|
||||||
|
anyway to keep the examples simple, and to avoid reliance on a separate
|
||||||
|
timer peripheral. */
|
||||||
|
|
||||||
|
|
||||||
|
/* The SysTick is a down counter. How many clocks have passed since it was
|
||||||
|
last reloaded? */
|
||||||
|
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
|
||||||
|
|
||||||
|
/* How many times has it overflowed? */
|
||||||
|
ulTickCount = xTaskGetTickCountFromISR();
|
||||||
|
|
||||||
|
/* This is called from the context switch, so will be called from a
|
||||||
|
critical section. xTaskGetTickCountFromISR() contains its own critical
|
||||||
|
section, and the ISR safe critical sections are not designed to nest,
|
||||||
|
so reset the critical section. */
|
||||||
|
portSET_INTERRUPT_MASK_FROM_ISR();
|
||||||
|
|
||||||
|
/* Is there a SysTick interrupt pending? */
|
||||||
|
if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )
|
||||||
|
{
|
||||||
|
/* There is a SysTick interrupt pending, so the SysTick has overflowed
|
||||||
|
but the tick count not yet incremented. */
|
||||||
|
ulTickCount++;
|
||||||
|
|
||||||
|
/* Read the SysTick again, as the overflow might have occurred since
|
||||||
|
it was read last. */
|
||||||
|
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the tick count into tenths of a millisecond. THIS ASSUMES
|
||||||
|
configTICK_RATE_HZ is 1000! */
|
||||||
|
ulReturn = ( ulTickCount * 10UL ) ;
|
||||||
|
|
||||||
|
/* Add on the number of tenths of a millisecond that have passed since the
|
||||||
|
tick count last got updated. */
|
||||||
|
ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );
|
||||||
|
|
||||||
|
return ulReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue