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