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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_STR75x_IAR/] [serial/] [serial.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/*
55
        BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0.
56
*/
57
 
58
/* Library includes. */
59
#include "75x_uart.h"
60
#include "75x_gpio.h"
61
#include "75x_eic.h"
62
#include "75x_mrcc.h"
63
 
64
/* Scheduler includes. */
65
#include "FreeRTOS.h"
66
#include "queue.h"
67
 
68
/* Demo application includes. */
69
#include "serial.h"
70
 
71
#define serINVALID_QUEUE                                ( ( xQueueHandle ) 0 )
72
#define serNO_BLOCK                                             ( ( portTickType ) 0 )
73
 
74
/*-----------------------------------------------------------*/
75
 
76
/* Queues used to hold received characters, and characters waiting to be
77
transmitted. */
78
static xQueueHandle xRxedChars;
79
static xQueueHandle xCharsForTx;
80
 
81
static volatile portBASE_TYPE xQueueEmpty = pdTRUE;
82
 
83
/*-----------------------------------------------------------*/
84
 
85
/* The interrupt service routine - called from the assembly entry point. */
86
__arm void vSerialISR( void );
87
 
88
/*-----------------------------------------------------------*/
89
 
90
/*
91
 * See the serial2.h header file.
92
 */
93
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
94
{
95
xComPortHandle xReturn;
96
UART_InitTypeDef UART_InitStructure;
97
GPIO_InitTypeDef GPIO_InitStructure;
98
EIC_IRQInitTypeDef  EIC_IRQInitStructure;
99
 
100
        /* Create the queues used to hold Rx and Tx characters. */
101
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
102
        xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
103
 
104
        /* If the queues were created correctly then setup the serial port
105
        hardware. */
106
        if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
107
        {
108
                portENTER_CRITICAL();
109
                {
110
                        /* Enable the UART0 Clock. */
111
                        MRCC_PeripheralClockConfig( MRCC_Peripheral_UART0, ENABLE );
112
 
113
                        /* Configure the UART0_Tx as alternate function */
114
                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
115
                        GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11;
116
                        GPIO_Init(GPIO0, &GPIO_InitStructure);
117
 
118
                        /* Configure the UART0_Rx as input floating */
119
                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
120
                        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
121
                        GPIO_Init(GPIO0, &GPIO_InitStructure);
122
 
123
                        /* Configure UART0. */
124
                        UART_InitStructure.UART_WordLength = UART_WordLength_8D;
125
                        UART_InitStructure.UART_StopBits = UART_StopBits_1;
126
                        UART_InitStructure.UART_Parity = UART_Parity_No;
127
                        UART_InitStructure.UART_BaudRate = ulWantedBaud;
128
                        UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
129
                        UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
130
                        UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
131
                        UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
132
                        UART_Init(UART0, &UART_InitStructure);
133
 
134
                        /* Enable the UART0 */
135
                        UART_Cmd(UART0, ENABLE);
136
 
137
                        /* Configure the IEC for the UART interrupts. */
138
                        EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
139
                        EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel;
140
                        EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
141
                        EIC_IRQInit(&EIC_IRQInitStructure);
142
 
143
                        xQueueEmpty = pdTRUE;
144
                        UART_ITConfig( UART0, UART_IT_Transmit | UART_IT_Receive, ENABLE );
145
                }
146
                portEXIT_CRITICAL();
147
        }
148
        else
149
        {
150
                xReturn = ( xComPortHandle ) 0;
151
        }
152
 
153
        /* This demo file only supports a single port but we have to return
154
        something to comply with the standard demo header file. */
155
        return xReturn;
156
}
157
/*-----------------------------------------------------------*/
158
 
159
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
160
{
161
        /* The port handle is not required as this driver only supports one port. */
162
        ( void ) pxPort;
163
 
164
        /* Get the next character from the buffer.  Return false if no characters
165
        are available, or arrive before xBlockTime expires. */
166
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
167
        {
168
                return pdTRUE;
169
        }
170
        else
171
        {
172
                return pdFALSE;
173
        }
174
}
175
/*-----------------------------------------------------------*/
176
 
177
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
178
{
179
signed char *pxNext;
180
 
181
        /* A couple of parameters that this port does not use. */
182
        ( void ) usStringLength;
183
        ( void ) pxPort;
184
 
185
        /* NOTE: This implementation does not handle the queue being full as no
186
        block time is used! */
187
 
188
        /* The port handle is not required as this driver only supports UART0. */
189
        ( void ) pxPort;
190
 
191
        /* Send each character in the string, one at a time. */
192
        pxNext = ( signed char * ) pcString;
193
        while( *pxNext )
194
        {
195
                xSerialPutChar( pxPort, *pxNext, serNO_BLOCK );
196
                pxNext++;
197
        }
198
}
199
/*-----------------------------------------------------------*/
200
 
201
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
202
{
203
portBASE_TYPE xReturn;
204
 
205
        /* Place the character in the queue of characters to be transmitted. */
206
        portENTER_CRITICAL();
207
        {
208
                if( xQueueEmpty == pdTRUE )
209
                {
210
                        UART0->DR = cOutChar;
211
                        xReturn = pdPASS;
212
                }
213
                else
214
                {
215
                        if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
216
                        {
217
                                xReturn = pdFAIL;
218
                        }
219
                        else
220
                        {
221
                                xReturn = pdPASS;
222
                        }
223
                }
224
 
225
                xQueueEmpty = pdFALSE;
226
        }
227
        portEXIT_CRITICAL();
228
 
229
        return xReturn;
230
}
231
/*-----------------------------------------------------------*/
232
 
233
void vSerialClose( xComPortHandle xPort )
234
{
235
        /* Not supported as not required by the demo application. */
236
}
237
/*-----------------------------------------------------------*/
238
 
239
__arm void vSerialISR( void )
240
{
241
signed char cChar;
242
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
243
 
244
        do
245
        {
246
                if( UART0->MIS & UART_IT_Transmit )
247
                {
248
                        /* The interrupt was caused by the THR becoming empty.  Are there any
249
                        more characters to transmit? */
250
                        if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
251
                        {
252
                                /* A character was retrieved from the queue so can be sent to the
253
                                THR now. */
254
                                UART0->DR = cChar;
255
                        }
256
                        else
257
                        {
258
                                xQueueEmpty = pdTRUE;
259
                        }
260
 
261
                        UART_ClearITPendingBit( UART0, UART_IT_Transmit );
262
                }
263
 
264
                if( UART0->MIS & UART_IT_Receive )
265
                {
266
                        /* The interrupt was caused by a character being received.  Grab the
267
                        character from the RHR and place it in the queue of received
268
                        characters. */
269
                        cChar = UART0->DR;
270
                        xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
271
                        UART_ClearITPendingBit( UART0, UART_IT_Receive );
272
                }
273
        } while( UART0->MIS );
274
 
275
        /* If a task was woken by either a character being received or a character
276
        being transmitted then we may need to switch to another task. */
277
        portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
278
}
279
 
280
 
281
 
282
 
283
 
284
 

powered by: WebSVN 2.1.0

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