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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MB96340_Softune/] [FreeRTOS_96348hs_SK16FX100PMC/] [Src/] [utility/] [taskutility.c] - Blame information for rev 636

Go to most recent revision | 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
 
3
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
4
 
5
/* ELIGIBILITY FOR ANY PURPOSES.                                             */
6
 
7
/*                 (C) Fujitsu Microelectronics Europe GmbH                  */
8
 
9
/*------------------------------------------------------------------------
10
  taskutility.C
11
  -
12
-------------------------------------------------------------------------*/
13
 
14
/*************************@INCLUDE_START************************/
15
#include "mb96348hs.h"
16
#include "FreeRTOS.h"
17
#include "task.h"
18
#include "queue.h"
19
 
20
static void vUART0Task( void *pvParameters );
21
 
22
/**************************@INCLUDE_END*************************/
23
 
24
/*********************@GLOBAL_VARIABLES_START*******************/
25
const char      ASCII[] = "0123456789ABCDEF";
26
 
27
xTaskHandle UART_TaskHandle;
28
 
29
static xQueueHandle xQueue;
30
void InitUart0( void )
31
{
32
        /* Initialize UART asynchronous mode */
33
        BGR0 = configCLKP1_CLOCK_HZ / 9600; /* 9600 Baud @ CLKP1 - 56 MHz */
34
 
35
        SCR0 = 0x17;                                            /* 8N1 */
36
        SMR0 = 0x0d;                                            /* enable SOT3, Reset, normal mode */
37
        SSR0 = 0x02;                                            /* LSB first, enable receive interrupts */
38
 
39
        PIER08_IE2 = 1; /* enable input */
40
        DDR08_D2 = 0;    /* switch P08_2 to input */
41
        DDR08_D3 = 1;   /* switch P08_3 to output */
42
}
43
 
44
void Putch0( char ch )  /* sends a char */
45
{
46
        while( SSR0_TDRE == 0 );
47
 
48
        /* wait for transmit buffer empty       */
49
        TDR0 = ch;      /* put ch into buffer                   */
50
}
51
 
52
char Getch0( void ) /* waits for and returns incomming char     */
53
{
54
        volatile unsigned       ch;
55
 
56
        while( SSR0_RDRF == 0 );
57
 
58
        /* wait for data received       */
59
        if( SSR0_ORE )          /* overrun error                */
60
        {
61
                ch = RDR0;              /* reset error flags            */
62
                return ( char ) ( -1 );
63
        }
64
        else
65
        {
66
                return( RDR0 ); /* return char                  */
67
        }
68
}
69
 
70
void Puts0( const char *Name1 ) /* Puts a String to UART */
71
{
72
        volatile portSHORT      i, len;
73
        len = strlen( Name1 );
74
 
75
        for( i = 0; i < len; i++ )       /* go through string */
76
        {
77
                if( Name1[i] == 10 )
78
                {
79
                        Putch0( 13 );
80
                }
81
 
82
                Putch0( Name1[i] );                                     /* send it out                           */
83
        }
84
}
85
 
86
void Puthex0( unsigned long n, unsigned char digits )
87
{
88
        unsigned portCHAR       digit = 0, div = 0, i;
89
 
90
        div = ( 4 * (digits - 1) );                             /* init shift divisor */
91
        for( i = 0; i < digits; i++ )
92
        {
93
                digit = ( (n >> div) & 0xF );           /* get hex-digit value */
94
                Putch0( digit + ((digit < 0xA) ? '0' : 'A' - 0xA) );
95
                div -= 4;               /* next digit shift */
96
        }
97
}
98
 
99
void Putdec0( unsigned long x, int digits )
100
{
101
        portSHORT       i;
102
        portCHAR        buf[10], sign = 1;
103
 
104
        if( digits < 0 )
105
        {                                       /* should be print of zero? */
106
                digits *= ( -1 );
107
                sign = 1;
108
        }
109
 
110
        buf[digits] = '\0'; /* end sign of string */
111
 
112
        for( i = digits; i > 0; i-- )
113
        {
114
                buf[i - 1] = ASCII[x % 10];
115
                x = x / 10;
116
        }
117
 
118
        if( sign )
119
        {
120
                for( i = 0; buf[i] == '0'; i++ )
121
                {                               /* no print of zero */
122
                        if( i < digits - 1 )
123
                        {
124
                                buf[i] = ' ';
125
                        }
126
                }
127
        }
128
 
129
        Puts0( buf );           /* send string */
130
}
131
 
132
void vUtilityStartTraceTask( unsigned portBASE_TYPE uxPriority )
133
{
134
        xQueue = xQueueCreate( 5, sizeof( char ) );
135
 
136
        if( xQueue != NULL )
137
        {
138
                portENTER_CRITICAL();
139
                InitUart0();
140
                portENTER_CRITICAL();
141
                xTaskCreate( vUART0Task, (signed portCHAR *) "UART1", configMINIMAL_STACK_SIZE * 3, ( void * ) NULL, uxPriority, &UART_TaskHandle );
142
        }
143
}
144
 
145
static void vUART0Task( void *pvParameters )
146
{
147
        static portCHAR buff[ 800 ] = { 0 };
148
        unsigned portLONG       trace_len;
149
        signed portLONG         i, j, l = 0;
150
 
151
        unsigned portCHAR       ch;
152
        ( void ) pvParameters;
153
 
154
        SSR0_RIE = 1;
155
 
156
        Puts0( "\n -------------MB96348 FreeRTOS DEMO Task List and Trace Utility----------- \n" );
157
 
158
        for( ;; )
159
        {
160
                Puts0( "\n\rPress any of the following keys for the corresponding functionality: " );
161
 
162
                Puts0( "\n\r1: To call vTaskList() and display current task status " );
163
 
164
                Puts0( "\n\r2: To call vTaskStartTrace() and to display trace results once the trace ends" );
165
 
166
                /* Block on the semaphore.  The UART interrupt will use the semaphore to
167
                wake this task when required. */
168
                xQueueReceive( xQueue, &ch, portMAX_DELAY );
169
 
170
                switch( ch )
171
                {
172
                        case '1':
173
                                vTaskList( (signed char *) buff );
174
                                Puts0( "\n\rThe current task list is as follows...." );
175
                                Puts0( "\n\r----------------------------------------------" );
176
                                Puts0( "\n\rName          State  Priority  Stack   Number" );
177
                                Puts0( "\n\r----------------------------------------------" );
178
                                Puts0( buff );
179
                                Puts0( "\r----------------------------------------------" );
180
                                break;
181
 
182
                        case '2':
183
                                vTaskStartTrace( (signed char *) buff, sizeof( buff ) );
184
                                Puts0( "\n\rThe trace started!!" );
185
                                vTaskDelay( (portTickType) 500 );
186
                                trace_len = ulTaskEndTrace();
187
                                Puts0( "\n\rThe trace ended!!" );
188
                                Puts0( "\n\rThe trace is as follows...." );
189
                                Puts0( "\n\r--------------------------------------------------------" );
190
                                Puts0( "\n\r  Tick     | Task Number  |     Tick     | Task Number  |" );
191
                                Puts0( "\n\r--------------------------------------------------------\n\r" );
192
 
193
                                for( i = 0; i < trace_len; i += 4 )
194
                                {
195
                                        for( j = i + 3; j >= i; j-- )
196
                                        {
197
                                                Puthex0( buff[j], 2 );
198
                                        }
199
 
200
                                        Puts0( "   |   " );
201
                                        l++;
202
                                        if( l == 4 )
203
                                        {
204
                                                Puts0( "\n" );
205
                                                l = 0;
206
                                        }
207
                                }
208
 
209
                                Puts0( "\r--------------------------------------------------------" );
210
                                break;
211
 
212
                        default:
213
                                break;
214
                }
215
 
216
                Puts0( "\n" );
217
        }
218
}
219
 
220
__interrupt void UART0_TraceRxISR( void )
221
{
222
unsigned portCHAR ch;
223
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
224
 
225
        ch = RDR0;
226
        xQueueSendFromISR( xQueue, &ch, &xHigherPriorityTaskWoken );
227
}

powered by: WebSVN 2.1.0

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