OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MB91460_Softune/] [SRC/] [utility/] [taskutility.c] - Blame information for rev 584

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 jeremybenn
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
2
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
3
/* ELIGIBILITY FOR ANY PURPOSES.                                                                                         */
4
/*                               (C) Fujitsu Microelectronics Europe GmbH                                        */
5
/*------------------------------------------------------------------------
6
  taskutility.C
7
  -
8
-------------------------------------------------------------------------*/
9
#include "mb91467d.h"
10
#include "vectors.h"
11
#include "FreeRTOS.h"
12
#include "task.h"
13
#include "queue.h"
14
 
15
static void vUART5Task( void *pvParameters );
16
 
17
const char                      ASCII[] = "0123456789ABCDEF";
18
 
19
void                            vInitUart5( void );
20
 
21
 
22
static xQueueHandle xQueue;
23
 
24
void vInitUart5( void )
25
{
26
        //Initialize UART asynchronous mode
27
        BGR05 = 1666;   //  9600 Baud @ 16MHz
28
        SCR05 = 0x17;   // 7N2
29
        SMR05 = 0x0d;   // enable SOT3, Reset, normal mode
30
        SSR05 = 0x00;   // LSB first
31
        PFR19_D4 = 1;   // enable UART
32
        PFR19_D5 = 1;   // enable UART
33
 
34
        //EPFR19 = 0x00;   // enable UART
35
        SSR05_RIE = 1;
36
}
37
 
38
void Putch5( char ch )  /* sends a char */
39
{
40
        while( SSR05_TDRE == 0 );
41
 
42
        /* wait for transmit buffer empty */
43
        TDR05 = ch; /* put ch into buffer */
44
}
45
 
46
char Getch5( void ) /* waits for and returns incomming char */
47
{
48
        volatile unsigned       ch;
49
 
50
        while( SSR05_RDRF == 0 );
51
 
52
        /* wait for data received */
53
        if( SSR05_ORE )                 /* overrun error */
54
        {
55
                ch = RDR05;                     /* reset error flags */
56
                return ( char ) ( -1 );
57
        }
58
        else
59
        {
60
                return( RDR05 );        /* return char */
61
        }
62
}
63
 
64
void Puts5( const char *Name5 ) /* Puts a String to UART */
65
{
66
        volatile portSHORT      i, len;
67
        len = strlen( Name5 );
68
 
69
        for( i = 0; i < len; i++ )       /* go through string */
70
        {
71
                if( Name5[i] == 10 )
72
                {
73
                        Putch5( 13 );
74
                }
75
 
76
                Putch5( Name5[i] );                                     /* send it out */
77
        }
78
}
79
 
80
void Puthex5( unsigned long n, unsigned char digits )
81
{
82
        unsigned portCHAR       digit = 0, div = 0, i;
83
 
84
        div = ( 4 * (digits - 1) );                             /* init shift divisor */
85
        for( i = 0; i < digits; i++ )
86
        {
87
                digit = ( (n >> div) & 0xF );           /* get hex-digit value */
88
                Putch5( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
89
                div -= 4;               /* next digit shift */
90
        }
91
}
92
 
93
void Putdec5( unsigned long x, int digits )
94
{
95
        portSHORT       i;
96
        portCHAR        buf[10], sign = 1;
97
 
98
        if( digits < 0 )
99
        {                                       /* should be print of zero? */
100
                digits *= ( -1 );
101
                sign = 1;
102
        }
103
 
104
        buf[digits] = '\0'; /* end sign of string */
105
 
106
        for( i = digits; i > 0; i-- )
107
        {
108
                buf[i - 1] = ASCII[x % 10];
109
                x = x / 10;
110
        }
111
 
112
        if( sign )
113
        {
114
                for( i = 0; buf[i] == '0'; i++ )
115
                {                               /* no print of zero */
116
                        if( i < digits - 1 )
117
                        {
118
                                buf[i] = ' ';
119
                        }
120
                }
121
        }
122
 
123
        Puts5( buf );           /* send string */
124
}
125
 
126
void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
127
{
128
        xQueue = xQueueCreate( 5, sizeof( char ) );
129
 
130
        if( xQueue != NULL )
131
        {
132
                portENTER_CRITICAL();
133
                vInitUart5();
134
                portENTER_CRITICAL();
135
 
136
                xTaskCreate( vUART5Task, (signed portCHAR *) "UART5", configMINIMAL_STACK_SIZE * 2, ( void * ) NULL, uxPriority, NULL );
137
        }
138
}
139
 
140
static void vUART5Task( void *pvParameters )
141
{
142
        static portCHAR buff[ 900 ] = { 0 };
143
        unsigned portLONG       trace_len, j;
144
 
145
        unsigned portCHAR       ch;
146
 
147
        SSR05_RIE = 1;
148
        Puts5( "\n -------------MB91467D FreeRTOS DEMO Task List and Trace Utility----------- \n" );
149
 
150
        for( ;; )
151
        {
152
                Puts5( "\n\rPress any of the following keys for the corresponding functionality: " );
153
 
154
                Puts5( "\n\r1: To call vTaskList() and display current task status " );
155
 
156
                Puts5( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );
157
 
158
                /* Block on the semaphore.  The UART interrupt will use the semaphore to
159
                wake this task when required. */
160
                xQueueReceive( xQueue, &ch, portMAX_DELAY );
161
 
162
                switch( ch )
163
                {
164
                        case '1':
165
                                vTaskList( (signed char *) buff );
166
                                Puts5( "\n\rThe current task list is as follows...." );
167
                                Puts5( "\n\r----------------------------------------------" );
168
                                Puts5( "\n\rName                  State  Priority  Stack   Number" );
169
                                Puts5( "\n\r----------------------------------------------" );
170
                                Puts5( buff );
171
                                Puts5( "\r----------------------------------------------" );
172
                                break;
173
 
174
                        case '2':
175
                                vTaskStartTrace( (signed char *) buff, sizeof( buff ) );
176
                                Puts5( "\n\rThe trace started!!" );
177
                                vTaskDelay( (portTickType) 450 );
178
                                trace_len = ulTaskEndTrace();
179
                                Puts5( "\n\rThe trace ended!!" );
180
                                Puts5( "\n\rThe trace is as follows...." );
181
                                Puts5( "\n\r--------------------------------------------------------" );
182
                                Puts5( "\n\r  Tick       | Task Number  |        Tick    | Task Number  |" );
183
                                Puts5( "\n\r--------------------------------------------------------\n\r" );
184
                                for( j = 0; j < trace_len; j++ )
185
                                {
186
                                        Puthex5( buff[j], 2 );
187
                                        if( j % 4 == 3 )
188
                                        {
189
                                                Puts5( "   |   " );
190
                                        }
191
 
192
                                        if( j % 16 == 15 )
193
                                        {
194
                                                Puts5( "\n" );
195
                                        }
196
                                }
197
 
198
                                Puts5( "\r--------------------------------------------------------" );
199
                                break;
200
 
201
                        default:
202
                                break;
203
                }
204
 
205
                Puts5( "\n" );
206
        }
207
}
208
 
209
__interrupt void UART5_RxISR( void )
210
{
211
unsigned portCHAR ch;
212
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
213
 
214
        ch = RDR05;
215
        xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );
216
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.