]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MB91460_Softune/SRC/utility/taskutility.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / MB91460_Softune / SRC / utility / taskutility.c
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
6   taskutility.C\r
7   - \r
8 -------------------------------------------------------------------------*/\r
9 #include "mb91467d.h"\r
10 #include "vectors.h"\r
11 #include "FreeRTOS.h"\r
12 #include "task.h"\r
13 #include "queue.h"\r
14 \r
15 static void vUART5Task( void *pvParameters );\r
16 \r
17 const char                      ASCII[] = "0123456789ABCDEF";\r
18 \r
19 void                            vInitUart5( void );\r
20 \r
21 \r
22 static xQueueHandle xQueue;\r
23 \r
24 void vInitUart5( void )\r
25 {\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
33 \r
34         //EPFR19 = 0x00;   // enable UART\r
35         SSR05_RIE = 1;\r
36 }\r
37 \r
38 void Putch5( char ch )  /* sends a char */\r
39 {\r
40         while( SSR05_TDRE == 0 );\r
41 \r
42         /* wait for transmit buffer empty */\r
43         TDR05 = ch; /* put ch into buffer */\r
44 }\r
45 \r
46 char Getch5( void ) /* waits for and returns incomming char */\r
47 {\r
48         volatile unsigned       ch;\r
49 \r
50         while( SSR05_RDRF == 0 );\r
51 \r
52         /* wait for data received */\r
53         if( SSR05_ORE )                 /* overrun error */\r
54         {\r
55                 ch = RDR05;                     /* reset error flags */\r
56                 return ( char ) ( -1 );\r
57         }\r
58         else\r
59         {\r
60                 return( RDR05 );        /* return char */\r
61         }\r
62 }\r
63 \r
64 void Puts5( const char *Name5 ) /* Puts a String to UART */\r
65 {\r
66         volatile portSHORT      i, len;\r
67         len = strlen( Name5 );\r
68 \r
69         for( i = 0; i < len; i++ )      /* go through string */\r
70         {\r
71                 if( Name5[i] == 10 )\r
72                 {\r
73                         Putch5( 13 );\r
74                 }\r
75 \r
76                 Putch5( Name5[i] );                                     /* send it out */\r
77         }\r
78 }\r
79 \r
80 void Puthex5( unsigned long n, unsigned char digits )\r
81 {\r
82         unsigned portCHAR       digit = 0, div = 0, i;\r
83 \r
84         div = ( 4 * (digits - 1) );                             /* init shift divisor */\r
85         for( i = 0; i < digits; i++ )\r
86         {\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
90         }\r
91 }\r
92 \r
93 void Putdec5( unsigned long x, int digits )\r
94 {\r
95         portSHORT       i;\r
96         portCHAR        buf[10], sign = 1;\r
97 \r
98         if( digits < 0 )\r
99         {                                       /* should be print of zero? */\r
100                 digits *= ( -1 );\r
101                 sign = 1;\r
102         }\r
103 \r
104         buf[digits] = '\0'; /* end sign of string */\r
105 \r
106         for( i = digits; i > 0; i-- )\r
107         {\r
108                 buf[i - 1] = ASCII[x % 10];\r
109                 x = x / 10;\r
110         }\r
111 \r
112         if( sign )\r
113         {\r
114                 for( i = 0; buf[i] == '0'; i++ )\r
115                 {                               /* no print of zero */\r
116                         if( i < digits - 1 )\r
117                         {\r
118                                 buf[i] = ' ';\r
119                         }\r
120                 }\r
121         }\r
122 \r
123         Puts5( buf );           /* send string */\r
124 }\r
125 \r
126 void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )\r
127 {\r
128         xQueue = xQueueCreate( 5, sizeof( char ) );\r
129 \r
130         if( xQueue != NULL )\r
131         {\r
132                 portENTER_CRITICAL();\r
133                 vInitUart5();\r
134                 portENTER_CRITICAL();\r
135 \r
136                 xTaskCreate( vUART5Task, (signed portCHAR *) "UART5", configMINIMAL_STACK_SIZE * 2, ( void * ) NULL, uxPriority, NULL );\r
137         }\r
138 }\r
139 \r
140 static void vUART5Task( void *pvParameters )\r
141 {\r
142         static portCHAR buff[ 900 ] = { 0 };\r
143         unsigned portLONG       trace_len, j;\r
144 \r
145         unsigned portCHAR       ch;\r
146 \r
147         SSR05_RIE = 1;\r
148         Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );\r
149 \r
150         for( ;; )\r
151         {\r
152                 Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );\r
153 \r
154                 Puts5( "\n\r1: To call vTaskList() and display current task status " );\r
155 \r
156                 Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );\r
157 \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
161 \r
162                 switch( ch )\r
163                 {\r
164                         case '1':\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
170                                 Puts5( buff );\r
171                                 Puts5( "\r----------------------------------------------" );\r
172                                 break;\r
173 \r
174                         case '2':\r
175                                 vTaskStartTrace( (signed char *) buff, sizeof( buff ) );\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
185                                 {\r
186                                         Puthex5( buff[j], 2 );\r
187                                         if( j % 4 == 3 )\r
188                                         {\r
189                                                 Puts5( "   |   " );\r
190                                         }\r
191 \r
192                                         if( j % 16 == 15 )\r
193                                         {\r
194                                                 Puts5( "\n" );\r
195                                         }\r
196                                 }\r
197 \r
198                                 Puts5( "\r--------------------------------------------------------" );\r
199                                 break;\r
200 \r
201                         default:\r
202                                 break;\r
203                 }\r
204 \r
205                 Puts5( "\n" );\r
206         }\r
207 }\r
208 \r
209 __interrupt void UART5_RxISR( void )\r
210 {\r
211 unsigned portCHAR ch;\r
212 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
213 \r
214         ch = RDR05;\r
215         xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );\r
216 }\r