OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF5282_Eclipse/] [RTOSDemo/] [serial/] [serial.c] - Blame information for rev 578

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_OUTPUT            ( ( unsigned portCHAR ) 0x04 )
78
#define serRX_INPUT                     ( ( unsigned portCHAR ) 0x08 )
79
#define serTX_ENABLE            ( ( unsigned portCHAR ) 0x04 )
80
#define serRX_ENABLE            ( ( unsigned portCHAR ) 0x01 )
81
#define serTX_INT                       ( ( unsigned portCHAR ) 0x01 )
82
#define serRX_INT                       ( ( unsigned portCHAR ) 0x02 )
83
 
84
 
85
/* The queues used to communicate between tasks and ISR's. */
86
static xQueueHandle xRxedChars;
87
static xQueueHandle xCharsForTx;
88
 
89
/* Flag used to indicate the tx status. */
90
static portBASE_TYPE xTxHasEnded = pdTRUE;
91
 
92
/*-----------------------------------------------------------*/
93
 
94
/* The UART interrupt handler. */
95
void __attribute__( ( interrupt ) ) __cs3_isr_interrupt_78( void );
96
 
97
/*-----------------------------------------------------------*/
98
 
99
xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
100
{
101
const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32UL * ulWantedBaud ) );
102
 
103
        /* Create the queues used by the com test task. */
104
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
105
        xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
106
 
107
        xTxHasEnded = pdTRUE;
108
 
109
        /* Set the pins to UART mode. */
110
        MCF_PAD_PUAPAR |= ( serTX_OUTPUT | serRX_INPUT );
111
 
112
        /* Reset the peripheral. */
113
        MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;
114
        MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;
115
        MCF_UART1_UCR = MCF_UART_UCR_RESET_ERROR;
116
        MCF_UART1_UCR = MCF_UART_UCR_RESET_BKCHGINT;
117
        MCF_UART1_UCR = MCF_UART_UCR_RESET_MR | MCF_UART_UCR_RX_DISABLED | MCF_UART_UCR_TX_DISABLED;
118
 
119
        /* Configure the UART. */
120
        MCF_UART1_UMR1 = serNO_PARITY | ser8DATA_BITS;
121
        MCF_UART1_UMR2 = ser1STOP_BIT;
122
        MCF_UART1_UCSR = serSYSTEM_CLOCK;
123
 
124
        MCF_UART1_UBG1 = ( unsigned portCHAR ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );
125
        MCF_UART1_UBG2 = ( unsigned portCHAR ) ( ulBaudRateDivisor & 0xffUL );
126
 
127
        /* Turn it on. */
128
        MCF_UART1_UCR = serTX_ENABLE | serRX_ENABLE;
129
 
130
        /* Configure the interrupt controller.  Run the UARTs above the kernel
131
        interrupt priority for demo purposes. */
132
    MCF_INTC0_ICR14 = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 2  ) << 3 );
133
    MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK14 | 0x01 );
134
 
135
        /* The Tx interrupt is not enabled until there is data to send. */
136
        MCF_UART1_UIMR = serRX_INT;
137
 
138
        /* Only a single port is implemented so we don't need to return anything. */
139
        return NULL;
140
}
141
/*-----------------------------------------------------------*/
142
 
143
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
144
{
145
        /* Only one port is supported. */
146
        ( void ) pxPort;
147
 
148
        /* Get the next character from the buffer.  Return false if no characters
149
        are available or arrive before xBlockTime expires. */
150
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
151
        {
152
                return pdTRUE;
153
        }
154
        else
155
        {
156
                return pdFALSE;
157
        }
158
}
159
/*-----------------------------------------------------------*/
160
 
161
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
162
{
163
        /* Only one port is supported. */
164
        ( void ) pxPort;
165
 
166
        /* Return false if after the block time there is no room on the Tx queue. */
167
        if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
168
        {
169
                return pdFAIL;
170
        }
171
 
172
        /* A critical section should not be required as xTxHasEnded will not be
173
        written to by the ISR if it is already 0 (is this correct?). */
174
        if( xTxHasEnded != pdFALSE )
175
        {
176
                xTxHasEnded = pdFALSE;
177
                MCF_UART1_UIMR = serRX_INT | serTX_INT;
178
        }
179
 
180
        return pdPASS;
181
}
182
/*-----------------------------------------------------------*/
183
 
184
void vSerialClose( xComPortHandle xPort )
185
{
186
        ( void ) xPort;
187
}
188
/*-----------------------------------------------------------*/
189
 
190
void __cs3_isr_interrupt_78( void )
191
{
192
unsigned portCHAR ucChar;
193
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xDoneSomething = pdTRUE;
194
 
195
        while( xDoneSomething != pdFALSE )
196
        {
197
                xDoneSomething = pdFALSE;
198
 
199
                /* Does the tx buffer contain space? */
200
                if( ( MCF_UART1_USR & MCF_UART_USR_TXRDY ) != 0x00 )
201
                {
202
                        /* Are there any characters queued to be sent? */
203
                        if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )
204
                        {
205
                                /* Send the next char. */
206
                                MCF_UART1_UTB = ucChar;
207
                                xDoneSomething = pdTRUE;
208
                        }
209
                        else
210
                        {
211
                                /* Turn off the Tx interrupt until such time as another character
212
                                is being transmitted. */
213
                                MCF_UART1_UIMR = serRX_INT;
214
                                xTxHasEnded = pdTRUE;
215
                        }
216
                }
217
 
218
                if( MCF_UART1_USR & MCF_UART_USR_RXRDY )
219
                {
220
                        ucChar = MCF_UART1_URB;
221
                        xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );
222
                        xDoneSomething = pdTRUE;
223
                }
224
        }
225
 
226
    portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
227
}
228
 
229
 
230
 
231
 
232
 
233
 
234
 

powered by: WebSVN 2.1.0

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