This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
FreeRTOS-Kernel/FreeRTOS/Demo/MB91460_Softune/SRC/utility/taskutility.c

219 lines
5.2 KiB
C
Raw Normal View History

2008-02-07 01:27:42 +08:00
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
2008-02-10 22:44:30 +08:00
/* ELIGIBILITY FOR ANY PURPOSES. */
/* (C) Fujitsu Microelectronics Europe GmbH */
2008-02-07 01:27:42 +08:00
/*------------------------------------------------------------------------
taskutility.C
-
2008-02-07 01:27:42 +08:00
-------------------------------------------------------------------------*/
#include "mb91467d.h"
#include "vectors.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
2008-02-07 01:27:42 +08:00
static void vUART5Task( void *pvParameters );
const char ASCII[] = "0123456789ABCDEF";
void vInitUart5( void );
2008-02-07 01:27:42 +08:00
static QueueHandle_t xQueue;
2008-02-07 01:27:42 +08:00
void vInitUart5( void )
2008-02-07 01:27:42 +08:00
{
//Initialize UART asynchronous mode
BGR05 = 1666; // 9600 Baud @ 16MHz
2008-02-10 22:44:30 +08:00
SCR05 = 0x17; // 7N2
SMR05 = 0x0d; // enable SOT3, Reset, normal mode
SSR05 = 0x00; // LSB first
PFR19_D4 = 1; // enable UART
PFR19_D5 = 1; // enable UART
2008-02-07 01:27:42 +08:00
//EPFR19 = 0x00; // enable UART
SSR05_RIE = 1;
}
void Putch5( char ch ) /* sends a char */
2008-02-07 01:27:42 +08:00
{
while( SSR05_TDRE == 0 );
/* wait for transmit buffer empty */
TDR05 = ch; /* put ch into buffer */
2008-02-07 01:27:42 +08:00
}
char Getch5( void ) /* waits for and returns incomming char */
2008-02-07 01:27:42 +08:00
{
volatile unsigned ch;
while( SSR05_RDRF == 0 );
/* wait for data received */
if( SSR05_ORE ) /* overrun error */
{
ch = RDR05; /* reset error flags */
return ( char ) ( -1 );
}
else
{
return( RDR05 ); /* return char */
}
2008-02-07 01:27:42 +08:00
}
void Puts5( const char *Name5 ) /* Puts a String to UART */
2008-02-07 01:27:42 +08:00
{
volatile short i, len;
len = strlen( Name5 );
for( i = 0; i < len; i++ ) /* go through string */
{
if( Name5[i] == 10 )
{
Putch5( 13 );
}
Putch5( Name5[i] ); /* send it out */
}
2008-02-07 01:27:42 +08:00
}
void Puthex5( unsigned long n, unsigned char digits )
2008-02-07 01:27:42 +08:00
{
unsigned char digit = 0, div = 0, i;
div = ( 4 * (digits - 1) ); /* init shift divisor */
for( i = 0; i < digits; i++ )
{
digit = ( (n >> div) & 0xF ); /* get hex-digit value */
Putch5( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
div -= 4; /* next digit shift */
}
2008-02-07 01:27:42 +08:00
}
void Putdec5( unsigned long x, int digits )
2008-02-07 01:27:42 +08:00
{
short i;
char buf[10], sign = 1;
if( digits < 0 )
{ /* should be print of zero? */
digits *= ( -1 );
sign = 1;
2008-02-07 01:27:42 +08:00
}
buf[digits] = '\0'; /* end sign of string */
for( i = digits; i > 0; i-- )
2008-02-10 22:44:30 +08:00
{
buf[i - 1] = ASCII[x % 10];
x = x / 10;
2008-02-10 22:44:30 +08:00
}
if( sign )
{
for( i = 0; buf[i] == '0'; i++ )
{ /* no print of zero */
if( i < digits - 1 )
{
buf[i] = ' ';
}
}
}
Puts5( buf ); /* send string */
2008-02-07 01:27:42 +08:00
}
2008-02-10 22:44:30 +08:00
void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
2008-02-07 01:27:42 +08:00
{
xQueue = xQueueCreate( 5, sizeof( char ) );
if( xQueue != NULL )
{
portENTER_CRITICAL();
vInitUart5();
portENTER_CRITICAL();
xTaskCreate( vUART5Task, "UART5", configMINIMAL_STACK_SIZE * 2, ( void * ) NULL, uxPriority, NULL );
}
2008-02-07 01:27:42 +08:00
}
static void vUART5Task( void *pvParameters )
{
static char buff[ 900 ] = { 0 };
unsigned long trace_len, j;
unsigned char ch;
SSR05_RIE = 1;
Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );
for( ;; )
2008-02-07 01:27:42 +08:00
{
Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );
2008-02-07 01:27:42 +08:00
Puts5( "\n\r1: To call vTaskList() and display current task status " );
2008-02-07 01:27:42 +08:00
2012-08-14 20:14:48 +08:00
/* The legacy trace is no longer supported. Use FreeRTOS+Trace instead.
Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" ); */
2008-02-07 01:27:42 +08:00
/* Block on the semaphore. The UART interrupt will use the semaphore to
wake this task when required. */
xQueueReceive( xQueue, &ch, portMAX_DELAY );
2008-02-07 01:27:42 +08:00
switch( ch )
2008-02-07 01:27:42 +08:00
{
case '1':
vTaskList( buff );
Puts5( "\n\rThe current task list is as follows...." );
Puts5( "\n\r----------------------------------------------" );
Puts5( "\n\rName State Priority Stack Number" );
Puts5( "\n\r----------------------------------------------" );
Puts5( buff );
Puts5( "\r----------------------------------------------" );
2008-02-07 01:27:42 +08:00
break;
2012-08-14 20:14:48 +08:00
/* The legacy trace is no longer supported. Use FreeRTOS+Trace instead.
2008-02-07 01:27:42 +08:00
case '2':
vTaskStartTrace( (signed char *) buff, sizeof( buff ) );
Puts5( "\n\rThe trace started!!" );
vTaskDelay( (TickType_t) 450 );
2008-02-07 01:27:42 +08:00
trace_len = ulTaskEndTrace();
Puts5( "\n\rThe trace ended!!" );
Puts5( "\n\rThe trace is as follows...." );
Puts5( "\n\r--------------------------------------------------------" );
Puts5( "\n\r Tick | Task Number | Tick | Task Number |" );
Puts5( "\n\r--------------------------------------------------------\n\r" );
for( j = 0; j < trace_len; j++ )
2008-02-07 01:27:42 +08:00
{
Puthex5( buff[j], 2 );
if( j % 4 == 3 )
{
Puts5( " | " );
}
if( j % 16 == 15 )
{
Puts5( "\n" );
}
2008-02-07 01:27:42 +08:00
}
Puts5( "\r--------------------------------------------------------" );
2012-08-14 20:14:48 +08:00
break;*/
2008-02-07 01:27:42 +08:00
default:
break;
}
Puts5( "\n" );
2008-02-07 01:27:42 +08:00
}
}
__interrupt void UART5_RxISR( void )
2008-02-07 01:27:42 +08:00
{
unsigned char ch;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
ch = RDR05;
xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );
2008-02-07 01:27:42 +08:00
}