1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
\r
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
\r
3 /* ELIGIBILITY FOR ANY PURPOSES. */
\r
4 /* (C) Fujitsu Microelectronics Europe GmbH */
\r
5 /*------------------------------------------------------------------------
\r
8 -------------------------------------------------------------------------*/
\r
9 #include "mb91467d.h"
\r
10 #include "vectors.h"
\r
11 #include "FreeRTOS.h"
\r
15 static void vUART5Task( void *pvParameters );
\r
17 const char ASCII[] = "0123456789ABCDEF";
\r
19 void vInitUart5( void );
\r
22 static xQueueHandle xQueue;
\r
24 void vInitUart5( void )
\r
26 //Initialize UART asynchronous mode
\r
27 BGR05 = 1666; // 9600 Baud @ 16MHz
\r
28 SCR05 = 0x17; // 7N2
\r
29 SMR05 = 0x0d; // enable SOT3, Reset, normal mode
\r
30 SSR05 = 0x00; // LSB first
\r
31 PFR19_D4 = 1; // enable UART
\r
32 PFR19_D5 = 1; // enable UART
\r
34 //EPFR19 = 0x00; // enable UART
\r
38 void Putch5( char ch ) /* sends a char */
\r
40 while( SSR05_TDRE == 0 );
\r
42 /* wait for transmit buffer empty */
\r
43 TDR05 = ch; /* put ch into buffer */
\r
46 char Getch5( void ) /* waits for and returns incomming char */
\r
48 volatile unsigned ch;
\r
50 while( SSR05_RDRF == 0 );
\r
52 /* wait for data received */
\r
53 if( SSR05_ORE ) /* overrun error */
\r
55 ch = RDR05; /* reset error flags */
\r
56 return ( char ) ( -1 );
\r
60 return( RDR05 ); /* return char */
\r
64 void Puts5( const char *Name5 ) /* Puts a String to UART */
\r
66 volatile portSHORT i, len;
\r
67 len = strlen( Name5 );
\r
69 for( i = 0; i < len; i++ ) /* go through string */
\r
71 if( Name5[i] == 10 )
\r
76 Putch5( Name5[i] ); /* send it out */
\r
80 void Puthex5( unsigned long n, unsigned char digits )
\r
82 unsigned portCHAR digit = 0, div = 0, i;
\r
84 div = ( 4 * (digits - 1) ); /* init shift divisor */
\r
85 for( i = 0; i < digits; i++ )
\r
87 digit = ( (n >> div) & 0xF ); /* get hex-digit value */
\r
88 Putch5( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
\r
89 div -= 4; /* next digit shift */
\r
93 void Putdec5( unsigned long x, int digits )
\r
96 portCHAR buf[10], sign = 1;
\r
99 { /* should be print of zero? */
\r
104 buf[digits] = '\0'; /* end sign of string */
\r
106 for( i = digits; i > 0; i-- )
\r
108 buf[i - 1] = ASCII[x % 10];
\r
114 for( i = 0; buf[i] == '0'; i++ )
\r
115 { /* no print of zero */
\r
116 if( i < digits - 1 )
\r
123 Puts5( buf ); /* send string */
\r
126 void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
\r
128 xQueue = xQueueCreate( 5, sizeof( char ) );
\r
130 if( xQueue != NULL )
\r
132 portENTER_CRITICAL();
\r
134 portENTER_CRITICAL();
\r
136 xTaskCreate( vUART5Task, (signed portCHAR *) "UART5", configMINIMAL_STACK_SIZE * 2, ( void * ) NULL, uxPriority, NULL );
\r
140 static void vUART5Task( void *pvParameters )
\r
142 static portCHAR buff[ 900 ] = { 0 };
\r
143 unsigned portLONG trace_len, j;
\r
145 unsigned portCHAR ch;
\r
148 Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );
\r
152 Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );
\r
154 Puts5( "\n\r1: To call vTaskList() and display current task status " );
\r
156 Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );
\r
158 /* Block on the semaphore. The UART interrupt will use the semaphore to
\r
159 wake this task when required. */
\r
160 xQueueReceive( xQueue, &ch, portMAX_DELAY );
\r
165 vTaskList( (signed char *) buff );
\r
166 Puts5( "\n\rThe current task list is as follows...." );
\r
167 Puts5( "\n\r----------------------------------------------" );
\r
168 Puts5( "\n\rName State Priority Stack Number" );
\r
169 Puts5( "\n\r----------------------------------------------" );
\r
171 Puts5( "\r----------------------------------------------" );
\r
175 vTaskStartTrace( (signed char *) buff, 512 );
\r
176 Puts5( "\n\rThe trace started!!" );
\r
177 vTaskDelay( (portTickType) 450 );
\r
178 trace_len = ulTaskEndTrace();
\r
179 Puts5( "\n\rThe trace ended!!" );
\r
180 Puts5( "\n\rThe trace is as follows...." );
\r
181 Puts5( "\n\r--------------------------------------------------------" );
\r
182 Puts5( "\n\r Tick | Task Number | Tick | Task Number |" );
\r
183 Puts5( "\n\r--------------------------------------------------------\n\r" );
\r
184 for( j = 0; j < trace_len; j++ )
\r
186 Puthex5( buff[j], 2 );
\r
198 Puts5( "\r--------------------------------------------------------" );
\r
209 __interrupt void UART5_RxISR( void )
\r
211 unsigned portCHAR ch;
\r
214 xQueueSendFromISR( xQueue, &ch, pdFALSE );
\r