1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
\r
3 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
\r
5 /* ELIGIBILITY FOR ANY PURPOSES. */
\r
7 /* (C) Fujitsu Microelectronics Europe GmbH */
\r
9 /*------------------------------------------------------------------------
\r
12 -------------------------------------------------------------------------*/
\r
14 /*************************@INCLUDE_START************************/
\r
15 #include "mb96348hs.h"
\r
16 #include "FreeRTOS.h"
\r
20 static void vUART0Task( void *pvParameters );
\r
22 /**************************@INCLUDE_END*************************/
\r
24 /*********************@GLOBAL_VARIABLES_START*******************/
\r
25 const char ASCII[] = "0123456789ABCDEF";
\r
27 xTaskHandle UART_TaskHandle;
\r
29 static xQueueHandle xQueue;
\r
30 void InitUart0( void )
\r
32 /* Initialize UART asynchronous mode */
\r
33 BGR0 = configCLKP1_CLOCK_HZ / 9600; /* 9600 Baud @ CLKP1 - 56 MHz */
\r
35 SCR0 = 0x17; /* 8N1 */
\r
36 SMR0 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
37 SSR0 = 0x02; /* LSB first, enable receive interrupts */
\r
39 PIER08_IE2 = 1; /* enable input */
\r
40 DDR08_D2 = 0; /* switch P08_2 to input */
\r
41 DDR08_D3 = 1; /* switch P08_3 to output */
\r
44 void Putch0( char ch ) /* sends a char */
\r
46 while( SSR0_TDRE == 0 );
\r
48 /* wait for transmit buffer empty */
\r
49 TDR0 = ch; /* put ch into buffer */
\r
52 char Getch0( void ) /* waits for and returns incomming char */
\r
54 volatile unsigned ch;
\r
56 while( SSR0_RDRF == 0 );
\r
58 /* wait for data received */
\r
59 if( SSR0_ORE ) /* overrun error */
\r
61 ch = RDR0; /* reset error flags */
\r
62 return ( char ) ( -1 );
\r
66 return( RDR0 ); /* return char */
\r
70 void Puts0( const char *Name1 ) /* Puts a String to UART */
\r
72 volatile portSHORT i, len;
\r
73 len = strlen( Name1 );
\r
75 for( i = 0; i < len; i++ ) /* go through string */
\r
77 if( Name1[i] == 10 )
\r
82 Putch0( Name1[i] ); /* send it out */
\r
86 void Puthex0( unsigned long n, unsigned char digits )
\r
88 unsigned portCHAR digit = 0, div = 0, i;
\r
90 div = ( 4 * (digits - 1) ); /* init shift divisor */
\r
91 for( i = 0; i < digits; i++ )
\r
93 digit = ( (n >> div) & 0xF ); /* get hex-digit value */
\r
94 Putch0( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
\r
95 div -= 4; /* next digit shift */
\r
99 void Putdec0( unsigned long x, int digits )
\r
102 portCHAR buf[10], sign = 1;
\r
105 { /* should be print of zero? */
\r
110 buf[digits] = '\0'; /* end sign of string */
\r
112 for( i = digits; i > 0; i-- )
\r
114 buf[i - 1] = ASCII[x % 10];
\r
120 for( i = 0; buf[i] == '0'; i++ )
\r
121 { /* no print of zero */
\r
122 if( i < digits - 1 )
\r
129 Puts0( buf ); /* send string */
\r
132 void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
\r
134 xQueue = xQueueCreate( 5, sizeof( char ) );
\r
136 if( xQueue != NULL )
\r
138 portENTER_CRITICAL();
\r
140 portENTER_CRITICAL();
\r
141 xTaskCreate( vUART0Task, (signed portCHAR *) "UART1", configMINIMAL_STACK_SIZE * 3, ( void * ) NULL, uxPriority, &UART_TaskHandle );
\r
145 static void vUART0Task( void *pvParameters )
\r
147 static portCHAR buff[ 800 ] = { 0 };
\r
148 unsigned portLONG trace_len;
\r
149 signed portLONG i, j, l = 0;
\r
151 unsigned portCHAR ch;
\r
152 ( void ) pvParameters;
\r
156 Puts0( "\n -------------MB96348 FreeRTOS DEMO Task List and Trace Utility----------- \n" );
\r
160 Puts0( "\n\rPress any of the following keys for the corresponding functionality: " );
\r
162 Puts0( "\n\r1: To call vTaskList() and display current task status " );
\r
164 Puts0( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );
\r
166 /* Block on the semaphore. The UART interrupt will use the semaphore to
\r
167 wake this task when required. */
\r
168 xQueueReceive( xQueue, &ch, portMAX_DELAY );
\r
173 vTaskList( (signed char *) buff );
\r
174 Puts0( "\n\rThe current task list is as follows...." );
\r
175 Puts0( "\n\r----------------------------------------------" );
\r
176 Puts0( "\n\rName State Priority Stack Number" );
\r
177 Puts0( "\n\r----------------------------------------------" );
\r
179 Puts0( "\r----------------------------------------------" );
\r
183 vTaskStartTrace( (signed char *) buff, sizeof( buff ) );
\r
184 Puts0( "\n\rThe trace started!!" );
\r
185 vTaskDelay( (portTickType) 500 );
\r
186 trace_len = ulTaskEndTrace();
\r
187 Puts0( "\n\rThe trace ended!!" );
\r
188 Puts0( "\n\rThe trace is as follows...." );
\r
189 Puts0( "\n\r--------------------------------------------------------" );
\r
190 Puts0( "\n\r Tick | Task Number | Tick | Task Number |" );
\r
191 Puts0( "\n\r--------------------------------------------------------\n\r" );
\r
193 for( i = 0; i < trace_len; i += 4 )
\r
195 for( j = i + 3; j >= i; j-- )
\r
197 Puthex0( buff[j], 2 );
\r
209 Puts0( "\r--------------------------------------------------------" );
\r
220 __interrupt void UART0_TraceRxISR( void )
\r
222 unsigned portCHAR ch;
\r
223 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
226 xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );
\r