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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF52221_CodeWarrior/] [sources/] [serial/] [serial.c] - Blame information for rev 867

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

Line No. Rev Author Line
1 578 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.
56
 
57
NOTE:  This driver is primarily to test the scheduler functionality.  It does
58
not effectively use the buffers or DMA and is therefore not intended to be
59
an example of an efficient driver. */
60
 
61
/* Standard include file. */
62
#include <stdlib.h>
63
 
64
/* Scheduler include files. */
65
#include "FreeRTOS.h"
66
#include "queue.h"
67
#include "task.h"
68
 
69
/* Demo app include files. */
70
#include "serial.h"
71
 
72
/* Hardware definitions. */
73
#define serNO_PARITY            ( ( unsigned portCHAR ) 0x02 << 3 )
74
#define ser8DATA_BITS           ( ( unsigned portCHAR ) 0x03 )
75
#define ser1STOP_BIT            ( ( unsigned portCHAR ) 0x07 )
76
#define serSYSTEM_CLOCK         ( ( unsigned portCHAR ) 0xdd )
77
#define serTX_ENABLE            ( ( unsigned portCHAR ) 0x04 )
78
#define serRX_ENABLE            ( ( unsigned portCHAR ) 0x01 )
79
#define serTX_INT                       ( ( unsigned portCHAR ) 0x01 )
80
#define serRX_INT                       ( ( unsigned portCHAR ) 0x02 )
81
 
82
 
83
/* The queues used to communicate between tasks and ISR's. */
84
static xQueueHandle xRxedChars;
85
static xQueueHandle xCharsForTx;
86
 
87
/* Flag used to indicate the tx status. */
88
static portBASE_TYPE xTxHasEnded = pdTRUE;
89
 
90
/*-----------------------------------------------------------*/
91
 
92
xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
93
{
94
const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32UL * ulWantedBaud ) );
95
 
96
        /* Create the queues used by the com test task. */
97
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
98
        xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
99
 
100
        xTxHasEnded = pdTRUE;
101
 
102
        /* Set the pins to UART mode. */
103
        MCF_GPIO_PUAPAR |= MCF_GPIO_PUAPAR_UTXD0_UTXD0;
104
        MCF_GPIO_PUAPAR |= MCF_GPIO_PUAPAR_URXD0_URXD0;
105
 
106
        /* Reset the peripheral. */
107
        MCF_UART0_UCR = MCF_UART_UCR_RESET_RX;
108
        MCF_UART0_UCR = MCF_UART_UCR_RESET_TX;
109
        MCF_UART0_UCR = MCF_UART_UCR_RESET_ERROR;
110
        MCF_UART0_UCR = MCF_UART_UCR_RESET_BKCHGINT;
111
        MCF_UART0_UCR = MCF_UART_UCR_RESET_MR | MCF_UART_UCR_RX_DISABLED | MCF_UART_UCR_TX_DISABLED;
112
 
113
        /* Configure the UART. */
114
        MCF_UART0_UMR1 = serNO_PARITY | ser8DATA_BITS;
115
        MCF_UART0_UMR2 = ser1STOP_BIT;
116
        MCF_UART0_UCSR = serSYSTEM_CLOCK;
117
 
118
        MCF_UART0_UBG1 = ( unsigned portCHAR ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );
119
        MCF_UART0_UBG2 = ( unsigned portCHAR ) ( ulBaudRateDivisor & 0xffUL );
120
 
121
        /* Turn it on. */
122
        MCF_UART0_UCR = serTX_ENABLE | serRX_ENABLE;
123
 
124
        /* Configure the interrupt controller.  Run the UARTs above the kernel
125
        interrupt priority for demo purposes. */
126
    MCF_INTC0_ICR13 = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 1  ) << 3 );
127
    MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK13 | 0x01 );
128
 
129
        /* The Tx interrupt is not enabled until there is data to send. */
130
        MCF_UART0_UIMR = serRX_INT;
131
 
132
        /* Only a single port is implemented so we don't need to return anything. */
133
        return NULL;
134
}
135
/*-----------------------------------------------------------*/
136
 
137
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
138
{
139
        /* Only one port is supported. */
140
        ( void ) pxPort;
141
 
142
        /* Get the next character from the buffer.  Return false if no characters
143
        are available or arrive before xBlockTime expires. */
144
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
145
        {
146
                return pdTRUE;
147
        }
148
        else
149
        {
150
                return pdFALSE;
151
        }
152
}
153
/*-----------------------------------------------------------*/
154
 
155
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
156
{
157
        /* Only one port is supported. */
158
        ( void ) pxPort;
159
 
160
        /* Return false if after the block time there is no room on the Tx queue. */
161
        if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
162
        {
163
                return pdFAIL;
164
        }
165
 
166
        /* A critical section should not be required as xTxHasEnded will not be
167
        written to by the ISR if it is already 0 (is this correct?). */
168
        if( xTxHasEnded != pdFALSE )
169
        {
170
                xTxHasEnded = pdFALSE;
171
                MCF_UART0_UIMR = serRX_INT | serTX_INT;
172
        }
173
 
174
        return pdPASS;
175
}
176
/*-----------------------------------------------------------*/
177
 
178
void vSerialClose( xComPortHandle xPort )
179
{
180
        ( void ) xPort;
181
}
182
/*-----------------------------------------------------------*/
183
 
184
__declspec(interrupt:0) void vUART0InterruptHandler( void )
185
{
186
unsigned portCHAR ucChar;
187
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xDoneSomething = pdTRUE;
188
 
189
        while( xDoneSomething != pdFALSE )
190
        {
191
                xDoneSomething = pdFALSE;
192
 
193
                /* Does the tx buffer contain space? */
194
                if( ( MCF_UART0_USR & MCF_UART_USR_TXRDY ) != 0x00 )
195
                {
196
                        /* Are there any characters queued to be sent? */
197
                        if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )
198
                        {
199
                                /* Send the next char. */
200
                                MCF_UART0_UTB = ucChar;
201
                                xDoneSomething = pdTRUE;
202
                        }
203
                        else
204
                        {
205
                                /* Turn off the Tx interrupt until such time as another character
206
                                is being transmitted. */
207
                                MCF_UART0_UIMR = serRX_INT;
208
                                xTxHasEnded = pdTRUE;
209
                        }
210
                }
211
 
212
                if( MCF_UART0_USR & MCF_UART_USR_RXRDY )
213
                {
214
                        ucChar = MCF_UART0_URB;
215
                        xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );
216
                        xDoneSomething = pdTRUE;
217
                }
218
        }
219
 
220
    portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
221
}
222
 
223
 
224
 
225
 
226
 
227
 
228
 

powered by: WebSVN 2.1.0

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