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

Subversion Repositories openrisc

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

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
 
59
/*-----------------------------------------------------------
60
 * Components that can be compiled to either ARM or THUMB mode are
61
 * contained in this file.c  The ISR routines, which can only be compiled
62
 * to ARM mode, are contained in serialISR.c.
63
 *----------------------------------------------------------*/
64
 
65
 
66
 
67
/* Library includes. */
68
#include "75x_uart.h"
69
#include "75x_gpio.h"
70
#include "75x_eic.h"
71
#include "75x_mrcc.h"
72
 
73
/* Scheduler includes. */
74
#include "FreeRTOS.h"
75
#include "queue.h"
76
 
77
/* Demo application includes. */
78
#include "serial.h"
79
 
80
#define serINVALID_QUEUE                                ( ( xQueueHandle ) 0 )
81
#define serNO_BLOCK                                             ( ( portTickType ) 0 )
82
 
83
/*-----------------------------------------------------------*/
84
 
85
/* Queues used to hold received characters, and characters waiting to be
86
transmitted. */
87
static xQueueHandle xRxedChars;
88
static xQueueHandle xCharsForTx;
89
 
90
static volatile portBASE_TYPE xQueueEmpty = pdTRUE;
91
 
92
/*-----------------------------------------------------------*/
93
 
94
/* The interrupt service routine - called from the assembly entry point. */
95
void vSerialISR( void );
96
void vConfigureQueues( xQueueHandle xQForRx, xQueueHandle xQForTx, volatile portBASE_TYPE *pxEmptyFlag );
97
 
98
/*-----------------------------------------------------------*/
99
 
100
/*
101
 * See the serial2.h header file.
102
 */
103
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
104
{
105
xComPortHandle xReturn;
106
UART_InitTypeDef UART_InitStructure;
107
GPIO_InitTypeDef GPIO_InitStructure;
108
EIC_IRQInitTypeDef  EIC_IRQInitStructure;
109
 
110
        /* Create the queues used to hold Rx and Tx characters. */
111
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
112
        xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
113
 
114
        /* If the queues were created correctly then setup the serial port
115
        hardware. */
116
        if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
117
        {
118
 
119
                vConfigureQueues( xRxedChars, xCharsForTx, &xQueueEmpty );
120
 
121
                portENTER_CRITICAL();
122
                {
123
                        /* Enable the UART0 Clock. */
124
                        MRCC_PeripheralClockConfig( MRCC_Peripheral_UART0, ENABLE );
125
 
126
                        /* Configure the UART0_Tx as alternate function */
127
                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
128
                        GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11;
129
                        GPIO_Init(GPIO0, &GPIO_InitStructure);
130
 
131
                        /* Configure the UART0_Rx as input floating */
132
                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
133
                        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
134
                        GPIO_Init(GPIO0, &GPIO_InitStructure);
135
 
136
                        /* Configure UART0. */
137
                        UART_InitStructure.UART_WordLength = UART_WordLength_8D;
138
                        UART_InitStructure.UART_StopBits = UART_StopBits_1;
139
                        UART_InitStructure.UART_Parity = UART_Parity_No;
140
                        UART_InitStructure.UART_BaudRate = ulWantedBaud;
141
                        UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
142
                        UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
143
                        UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
144
                        UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
145
                        UART_Init(UART0, &UART_InitStructure);
146
 
147
                        /* Enable the UART0 */
148
                        UART_Cmd(UART0, ENABLE);
149
 
150
                        /* Configure the IEC for the UART interrupts. */
151
                        EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
152
                        EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel;
153
                        EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
154
                        EIC_IRQInit(&EIC_IRQInitStructure);
155
 
156
                        xQueueEmpty = pdTRUE;
157
                        UART_ITConfig( UART0, UART_IT_Transmit | UART_IT_Receive, ENABLE );
158
                }
159
                portEXIT_CRITICAL();
160
        }
161
        else
162
        {
163
                xReturn = ( xComPortHandle ) 0;
164
        }
165
 
166
        /* This demo file only supports a single port but we have to return
167
        something to comply with the standard demo header file. */
168
        return xReturn;
169
}
170
/*-----------------------------------------------------------*/
171
 
172
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
173
{
174
        /* The port handle is not required as this driver only supports one port. */
175
        ( void ) pxPort;
176
 
177
        /* Get the next character from the buffer.  Return false if no characters
178
        are available, or arrive before xBlockTime expires. */
179
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
180
        {
181
                return pdTRUE;
182
        }
183
        else
184
        {
185
                return pdFALSE;
186
        }
187
}
188
/*-----------------------------------------------------------*/
189
 
190
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
191
{
192
signed char *pxNext;
193
 
194
        /* A couple of parameters that this port does not use. */
195
        ( void ) usStringLength;
196
        ( void ) pxPort;
197
 
198
        /* NOTE: This implementation does not handle the queue being full as no
199
        block time is used! */
200
 
201
        /* The port handle is not required as this driver only supports UART0. */
202
        ( void ) pxPort;
203
 
204
        /* Send each character in the string, one at a time. */
205
        pxNext = ( signed char * ) pcString;
206
        while( *pxNext )
207
        {
208
                xSerialPutChar( pxPort, *pxNext, serNO_BLOCK );
209
                pxNext++;
210
        }
211
}
212
/*-----------------------------------------------------------*/
213
 
214
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
215
{
216
portBASE_TYPE xReturn;
217
 
218
        /* Place the character in the queue of characters to be transmitted. */
219
        portENTER_CRITICAL();
220
        {
221
                if( xQueueEmpty == pdTRUE )
222
                {
223
                        UART0->DR = cOutChar;
224
                        xReturn = pdPASS;
225
                }
226
                else
227
                {
228
                        if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
229
                        {
230
                                xReturn = pdFAIL;
231
                        }
232
                        else
233
                        {
234
                                xReturn = pdPASS;
235
                        }
236
                }
237
 
238
                xQueueEmpty = pdFALSE;
239
        }
240
        portEXIT_CRITICAL();
241
 
242
        return xReturn;
243
}
244
/*-----------------------------------------------------------*/
245
 
246
void vSerialClose( xComPortHandle xPort )
247
{
248
        /* Not supported as not required by the demo application. */
249
}
250
/*-----------------------------------------------------------*/
251
 
252
 
253
 
254
 
255
 
256
 

powered by: WebSVN 2.1.0

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