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
21 xSemaphoreHandle xSemaphore;
\r
23 void vInitUart5( void )
\r
25 //Initialize UART asynchronous mode
\r
26 BGR05 = 1666; // 9600 Baud @ 16MHz
\r
27 SCR05 = 0x17; // 7N2
\r
28 SMR05 = 0x0d; // enable SOT3, Reset, normal mode
\r
29 SSR05 = 0x00; // LSB first
\r
30 PFR19_D4 = 1; // enable UART
\r
31 PFR19_D5 = 1; // enable UART
\r
33 //EPFR19 = 0x00; // enable UART
\r
37 void Putch5( char ch ) /* sends a char */
\r
39 while( SSR05_TDRE == 0 );
\r
41 /* wait for transmit buffer empty */
\r
42 TDR05 = ch; /* put ch into buffer */
\r
45 char Getch5( void ) /* waits for and returns incomming char */
\r
47 volatile unsigned ch;
\r
49 while( SSR05_RDRF == 0 );
\r
51 /* wait for data received */
\r
52 if( SSR05_ORE ) /* overrun error */
\r
54 ch = RDR05; /* reset error flags */
\r
55 return ( char ) ( -1 );
\r
59 return( RDR05 ); /* return char */
\r
63 void Puts5( const char *Name5 ) /* Puts a String to UART */
\r
65 volatile portSHORT i, len;
\r
66 len = strlen( Name5 );
\r
68 for( i = 0; i < strlen(Name5); i++ ) /* go through string */
\r
70 if( Name5[i] == 10 )
\r
75 Putch5( Name5[i] ); /* send it out */
\r
79 void Puthex5( unsigned long n, unsigned char digits )
\r
81 unsigned portCHAR digit = 0, div = 0, i;
\r
83 div = ( 4 * (digits - 1) ); /* init shift divisor */
\r
84 for( i = 0; i < digits; i++ )
\r
86 digit = ( (n >> div) & 0xF ); /* get hex-digit value */
\r
87 Putch5( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
\r
88 div -= 4; /* next digit shift */
\r
92 void Putdec5( unsigned long x, int digits )
\r
95 portCHAR buf[10], sign = 1;
\r
98 { /* should be print of zero? */
\r
103 buf[digits] = '\0'; /* end sign of string */
\r
105 for( i = digits; i > 0; i-- )
\r
107 buf[i - 1] = ASCII[x % 10];
\r
113 for( i = 0; buf[i] == '0'; i++ )
\r
114 { /* no print of zero */
\r
115 if( i < digits - 1 )
\r
122 Puts5( buf ); /* send string */
\r
125 void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
\r
127 portENTER_CRITICAL();
\r
129 portENTER_CRITICAL();
\r
131 vSemaphoreCreateBinary( xSemaphore );
\r
133 if( xSemaphore != NULL )
\r
135 xTaskCreate( vUART5Task, (signed portCHAR *) "UART4", ( unsigned portSHORT ) 2048, ( void * ) NULL, uxPriority, NULL );
\r
139 static void vUART5Task( void *pvParameters )
\r
141 portCHAR tasklist_buff[512], trace_buff[512];
\r
142 unsigned portLONG trace_len, j;
\r
144 unsigned portCHAR ch;
\r
146 Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );
\r
150 Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );
\r
152 Puts5( "\n\r1: To call vTaskList() and display current task status " );
\r
154 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 xSemaphoreTake( xSemaphore, portMAX_DELAY );
\r
167 vTaskList( (signed char *) tasklist_buff );
\r
168 Puts5( "\n\rThe current task list is as follows...." );
\r
169 Puts5( "\n\r----------------------------------------------" );
\r
170 Puts5( "\n\rName State Priority Stack Number" );
\r
171 Puts5( "\n\r----------------------------------------------" );
\r
172 Puts5( tasklist_buff );
\r
173 Puts5( "\r----------------------------------------------" );
\r
177 vTaskStartTrace( (signed char *) trace_buff, 512 );
\r
178 Puts5( "\n\rThe trace started!!" );
\r
179 vTaskDelay( (portTickType) 450 );
\r
180 trace_len = ulTaskEndTrace();
\r
181 Puts5( "\n\rThe trace ended!!" );
\r
182 Puts5( "\n\rThe trace is as follows...." );
\r
183 Puts5( "\n\r--------------------------------------------------------" );
\r
184 Puts5( "\n\r Tick | Task Number | Tick | Task Number |" );
\r
185 Puts5( "\n\r--------------------------------------------------------\n\r" );
\r
186 for( j = 0; j < trace_len; j++ )
\r
188 Puthex5( trace_buff[j], 2 );
\r
200 Puts5( "\r--------------------------------------------------------" );
\r
211 __interrupt void UART5_RxISR( void )
\r
214 xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
\r