/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */\r
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */\r
/* ELIGIBILITY FOR ANY PURPOSES. */\r
-/* (C) Fujitsu Microelectronics Europe GmbH */\r
+/* (C) Fujitsu Microelectronics Europe GmbH */\r
/*------------------------------------------------------------------------\r
taskutility.C\r
- \r
-------------------------------------------------------------------------*/\r
-\r
- \r
-/*************************@INCLUDE_START************************/\r
#include "mb91467d.h"\r
#include "vectors.h"\r
#include "FreeRTOS.h"\r
#include "task.h"\r
-\r
+#include "semphr.h"\r
\r
static void vUART5Task( void *pvParameters );\r
\r
-/**************************@INCLUDE_END*************************/\r
-/*********************@GLOBAL_VARIABLES_START*******************/\r
-const char ASCII[] = "0123456789ABCDEF";\r
+const char ASCII[] = "0123456789ABCDEF";\r
+\r
+void vInitUart5( void );\r
\r
-xTaskHandle UART_TaskHandle;\r
+xSemaphoreHandle xSemaphore;\r
\r
-void InitUart5(void)\r
+void vInitUart5( void )\r
{\r
//Initialize UART asynchronous mode\r
- BGR05 = 1666; // 9600 Baud @ 16MHz\r
- \r
+ BGR05 = 1666; // 9600 Baud @ 16MHz\r
SCR05 = 0x17; // 7N2\r
SMR05 = 0x0d; // enable SOT3, Reset, normal mode\r
SSR05 = 0x00; // LSB first\r
- \r
PFR19_D4 = 1; // enable UART\r
PFR19_D5 = 1; // enable UART\r
\r
//EPFR19 = 0x00; // enable UART\r
- \r
SSR05_RIE = 1;\r
}\r
\r
-void Putch5(char ch) /* sends a char */\r
+void Putch5( char ch ) /* sends a char */\r
{\r
- while (SSR05_TDRE == 0); /* wait for transmit buffer empty */\r
- TDR05 = ch; /* put ch into buffer */\r
+ while( SSR05_TDRE == 0 );\r
+\r
+ /* wait for transmit buffer empty */\r
+ TDR05 = ch; /* put ch into buffer */\r
}\r
\r
-char Getch5(void) /* waits for and returns incomming char */\r
+char Getch5( void ) /* waits for and returns incomming char */\r
{\r
- volatile unsigned ch;\r
- \r
- while(SSR05_RDRF == 0); /* wait for data received */\r
- if (SSR05_ORE) /* overrun error */\r
- {\r
- ch = RDR05; /* reset error flags */\r
- return (char)(-1);\r
- }\r
- else\r
- return (RDR05); /* return char */\r
+ volatile unsigned ch;\r
+\r
+ while( SSR05_RDRF == 0 );\r
+\r
+ /* wait for data received */\r
+ if( SSR05_ORE ) /* overrun error */\r
+ {\r
+ ch = RDR05; /* reset error flags */\r
+ return ( char ) ( -1 );\r
+ }\r
+ else\r
+ {\r
+ return( RDR05 ); /* return char */\r
+ }\r
}\r
\r
-void Puts5(const char *Name5) /* Puts a String to UART */\r
+void Puts5( const char *Name5 ) /* Puts a String to UART */\r
{\r
- volatile portSHORT i,len;\r
- len = strlen(Name5);\r
- \r
- for (i=0; i<strlen(Name5); i++) /* go through string */\r
- {\r
- if (Name5[i] == 10)\r
- Putch5(13);\r
- Putch5(Name5[i]); /* send it out */\r
- }\r
+ volatile portSHORT i, len;\r
+ len = strlen( Name5 );\r
+\r
+ for( i = 0; i < strlen(Name5); i++ ) /* go through string */\r
+ {\r
+ if( Name5[i] == 10 )\r
+ {\r
+ Putch5( 13 );\r
+ }\r
+\r
+ Putch5( Name5[i] ); /* send it out */\r
+ }\r
}\r
\r
-void Puthex5(unsigned long n, unsigned char digits)\r
+void Puthex5( unsigned long n, unsigned char digits )\r
{\r
- unsigned portCHAR digit=0,div=0,i;\r
-\r
- div=(4*(digits-1)); /* init shift divisor */\r
- for (i=0;i<digits;i++)\r
- {\r
- digit = ((n >> div)&0xF); /* get hex-digit value */\r
- Putch5(digit + ((digit < 0xA) ? '0' : 'A' - 0xA));\r
- div-=4; /* next digit shift */\r
- }\r
+ unsigned portCHAR digit = 0, div = 0, i;\r
+\r
+ div = ( 4 * (digits - 1) ); /* init shift divisor */\r
+ for( i = 0; i < digits; i++ )\r
+ {\r
+ digit = ( (n >> div) & 0xF ); /* get hex-digit value */\r
+ Putch5( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );\r
+ div -= 4; /* next digit shift */\r
+ }\r
}\r
\r
-void Putdec5(unsigned long x, int digits)\r
+void Putdec5( unsigned long x, int digits )\r
{\r
- portSHORT i;\r
- portCHAR buf[10],sign=1;\r
- \r
- if (digits < 0) { /* should be print of zero? */\r
- digits *= (-1);\r
- sign =1;\r
- } \r
- buf[digits]='\0'; /* end sign of string */\r
- \r
- for (i=digits; i>0; i--) {\r
- buf[i-1] = ASCII[x % 10];\r
- x = x/10;\r
+ portSHORT i;\r
+ portCHAR buf[10], sign = 1;\r
+\r
+ if( digits < 0 )\r
+ { /* should be print of zero? */\r
+ digits *= ( -1 );\r
+ sign = 1;\r
}\r
\r
- if ( sign )\r
+ buf[digits] = '\0'; /* end sign of string */\r
+\r
+ for( i = digits; i > 0; i-- )\r
{\r
- for (i=0; buf[i]=='0'; i++) { /* no print of zero */\r
- if ( i<digits-1)\r
- buf[i] = ' ';\r
- } \r
+ buf[i - 1] = ASCII[x % 10];\r
+ x = x / 10;\r
}\r
- \r
- Puts5(buf); /* send string */\r
+\r
+ if( sign )\r
+ {\r
+ for( i = 0; buf[i] == '0'; i++ )\r
+ { /* no print of zero */\r
+ if( i < digits - 1 )\r
+ {\r
+ buf[i] = ' ';\r
+ }\r
+ }\r
+ }\r
+\r
+ Puts5( buf ); /* send string */\r
}\r
\r
void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )\r
{\r
portENTER_CRITICAL();\r
- InitUart5();\r
+ vInitUart5();\r
portENTER_CRITICAL();\r
- xTaskCreate( vUART5Task , ( signed portCHAR * ) "UART4", ( unsigned portSHORT ) 2048, ( void * ) NULL, uxPriority, &UART_TaskHandle );\r
+\r
+ vSemaphoreCreateBinary( xSemaphore );\r
+\r
+ if( xSemaphore != NULL )\r
+ {\r
+ xTaskCreate( vUART5Task, (signed portCHAR *) "UART4", ( unsigned portSHORT ) 2048, ( void * ) NULL, uxPriority, NULL );\r
+ }\r
}\r
\r
static void vUART5Task( void *pvParameters )\r
{\r
- portCHAR tasklist_buff[512], trace_buff[512];\r
- unsigned portLONG trace_len, j;\r
- \r
- unsigned portCHAR ch; \r
- \r
- Puts5("\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n");\r
-\r
- for(;;)\r
+ portCHAR tasklist_buff[512], trace_buff[512];\r
+ unsigned portLONG trace_len, j;\r
+\r
+ unsigned portCHAR ch;\r
+\r
+ Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );\r
+\r
+ for( ;; )\r
{\r
- Puts5("\n\rPress any of the following keys for the corresponding functionality: ");\r
+ Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );\r
\r
- Puts5("\n\r1: To call vTaskList() and display current task status ");\r
+ Puts5( "\n\r1: To call vTaskList() and display current task status " );\r
\r
- Puts5("\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends");\r
+ Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );\r
\r
- SSR05_RIE=1;\r
+ SSR05_RIE = 1;\r
\r
- vTaskSuspend(NULL);\r
+ /* Block on the semaphore. The UART interrupt will use the semaphore to\r
+ wake this task when required. */\r
+ xSemaphoreTake( xSemaphore, portMAX_DELAY );\r
\r
- ch=Getch5();\r
+ ch = Getch5();\r
\r
- switch ( ch ) \r
+ switch( ch )\r
{\r
case '1':\r
- vTaskList( ( signed char * ) tasklist_buff );\r
- Puts5("\n\rThe current task list is as follows....");\r
- Puts5("\n\r----------------------------------------------");\r
- Puts5("\n\rName State Priority Stack Number");\r
- Puts5("\n\r----------------------------------------------");\r
- Puts5(tasklist_buff);\r
- Puts5("\r----------------------------------------------");\r
+ vTaskList( (signed char *) tasklist_buff );\r
+ Puts5( "\n\rThe current task list is as follows...." );\r
+ Puts5( "\n\r----------------------------------------------" );\r
+ Puts5( "\n\rName State Priority Stack Number" );\r
+ Puts5( "\n\r----------------------------------------------" );\r
+ Puts5( tasklist_buff );\r
+ Puts5( "\r----------------------------------------------" );\r
break;\r
\r
case '2':\r
- vTaskStartTrace(( signed char * ) trace_buff, 512);\r
- Puts5("\n\rThe trace started!!");\r
- vTaskDelay( ( portTickType ) 450);\r
+ vTaskStartTrace( (signed char *) trace_buff, 512 );\r
+ Puts5( "\n\rThe trace started!!" );\r
+ vTaskDelay( (portTickType) 450 );\r
trace_len = ulTaskEndTrace();\r
- Puts5("\n\rThe trace ended!!");\r
- Puts5("\n\rThe trace is as follows....");\r
- Puts5("\n\r--------------------------------------------------------");\r
- Puts5("\n\r Tick | Task Number | Tick | Task Number |");\r
- Puts5("\n\r--------------------------------------------------------\n\r");\r
- for( j = 0 ; j < trace_len ; j++ )\r
+ Puts5( "\n\rThe trace ended!!" );\r
+ Puts5( "\n\rThe trace is as follows...." );\r
+ Puts5( "\n\r--------------------------------------------------------" );\r
+ Puts5( "\n\r Tick | Task Number | Tick | Task Number |" );\r
+ Puts5( "\n\r--------------------------------------------------------\n\r" );\r
+ for( j = 0; j < trace_len; j++ )\r
{\r
- Puthex5(trace_buff[j],2);\r
- if(j%4==3) Puts5(" | ");\r
- if(j%16==15) Puts5("\n");\r
+ Puthex5( trace_buff[j], 2 );\r
+ if( j % 4 == 3 )\r
+ {\r
+ Puts5( " | " );\r
+ }\r
+\r
+ if( j % 16 == 15 )\r
+ {\r
+ Puts5( "\n" );\r
+ }\r
}\r
- Puts5("\r--------------------------------------------------------");\r
+\r
+ Puts5( "\r--------------------------------------------------------" );\r
break;\r
- \r
+\r
default:\r
break;\r
}\r
- Puts5("\n");\r
+\r
+ Puts5( "\n" );\r
}\r
}\r
\r
-__interrupt void UART5_RxISR ( void )\r
+__interrupt void UART5_RxISR( void )\r
{\r
- SSR05_RIE=0;\r
- vTaskResume( UART_TaskHandle );\r
+ SSR05_RIE = 0;\r
+ xSemaphoreGiveFromISR( xSemaphore, pdFALSE );\r
}\r