]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MB91460_Softune/SRC/utility/taskutility.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[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 QueueHandle_t 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 short  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 char   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         short   i;\r
96         char    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, "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 char     buff[ 900 ] = { 0 };\r
143         unsigned long   trace_len, j;\r
144 \r
145         unsigned char   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                 /* The legacy trace is no longer supported.  Use FreeRTOS+Trace instead.\r
157                 Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" ); */\r
158 \r
159                 /* Block on the semaphore.  The UART interrupt will use the semaphore to\r
160                 wake this task when required. */\r
161                 xQueueReceive( xQueue, &ch, portMAX_DELAY );\r
162 \r
163                 switch( ch )\r
164                 {\r
165                         case '1':\r
166                                 vTaskList( buff );\r
167                                 Puts5( "\n\rThe current task list is as follows...." );\r
168                                 Puts5( "\n\r----------------------------------------------" );\r
169                                 Puts5( "\n\rName                  State  Priority  Stack   Number" );\r
170                                 Puts5( "\n\r----------------------------------------------" );\r
171                                 Puts5( buff );\r
172                                 Puts5( "\r----------------------------------------------" );\r
173                                 break;\r
174 \r
175                         /* The legacy trace is no longer supported.  Use FreeRTOS+Trace instead.\r
176                         case '2':\r
177                                 vTaskStartTrace( (signed char *) buff, sizeof( buff ) );\r
178                                 Puts5( "\n\rThe trace started!!" );\r
179                                 vTaskDelay( (TickType_t) 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
187                                 {\r
188                                         Puthex5( buff[j], 2 );\r
189                                         if( j % 4 == 3 )\r
190                                         {\r
191                                                 Puts5( "   |   " );\r
192                                         }\r
193 \r
194                                         if( j % 16 == 15 )\r
195                                         {\r
196                                                 Puts5( "\n" );\r
197                                         }\r
198                                 }\r
199 \r
200                                 Puts5( "\r--------------------------------------------------------" );\r
201                                 break;*/\r
202 \r
203                         default:\r
204                                 break;\r
205                 }\r
206 \r
207                 Puts5( "\n" );\r
208         }\r
209 }\r
210 \r
211 __interrupt void UART5_RxISR( void )\r
212 {\r
213 unsigned char ch;\r
214 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
215 \r
216         ch = RDR05;\r
217         xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );\r
218 }\r