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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 584 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
 * This is not a proper UART driver.  It only supports one port, uses loopback
58
 * mode, and is used to test interrupts that use the FreeRTOS API as part of
59
 * a wider test suite.  Nor is it intended to show an efficient implementation
60
 * of a UART interrupt service routine as queues are used to pass individual
61
 * characters one at a time!
62
 */
63
 
64
/* Standard includes. */
65
#include <stdlib.h>
66
 
67
/* Scheduler includes. */
68
#include "FreeRTOS.h"
69
#include "queue.h"
70
#include "task.h"
71
 
72
/* Demo application includes. */
73
#include "serial.h"
74
 
75
/* Misc. constants. */
76
#define serNO_BLOCK                             ( ( portTickType ) 0 )
77
 
78
/* The queue used to hold received characters. */
79
static xQueueHandle xRxedChars;
80
 
81
/* The queue used to hold characters waiting transmission. */
82
static xQueueHandle xCharsForTx;
83
 
84
/*-----------------------------------------------------------*/
85
 
86
xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
87
{
88
unsigned portLONG ulBaudRateCount;
89
 
90
        /* Initialise the hardware. */
91
 
92
        /* Generate the baud rate constants for the wanted baud rate. */
93
        ulBaudRateCount = configCPU_CLOCK_HZ / ulWantedBaud;
94
 
95
        portENTER_CRITICAL();
96
        {
97
                /* Create the queues used by the com test task. */
98
                xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
99
                xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
100
 
101
                /* Reset UART. */
102
                UCA1CTL1 |= UCSWRST;
103
 
104
                /* Use SMCLK. */
105
                UCA1CTL1 = UCSSEL0 | UCSSEL1;
106
 
107
                /* Setup baud rate low byte. */
108
                UCA1BR0 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
109
 
110
                /* Setup baud rate high byte. */
111
                ulBaudRateCount >>= 8UL;
112
                UCA1BR1 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
113
 
114
                /* UCLISTEN sets loopback mode! */
115
                UCA1STAT = UCLISTEN;
116
 
117
                /* Enable interrupts. */
118
                UCA1IE |= UCRXIE;
119
 
120
                /* Take out of reset. */
121
                UCA1CTL1 &= ~UCSWRST;
122
        }
123
        portEXIT_CRITICAL();
124
 
125
        /* Note the comments at the top of this file about this not being a generic
126
        UART driver. */
127
        return NULL;
128
}
129
/*-----------------------------------------------------------*/
130
 
131
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
132
{
133
        /* Get the next character from the buffer.  Return false if no characters
134
        are available, or arrive before xBlockTime expires. */
135
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
136
        {
137
                return pdTRUE;
138
        }
139
        else
140
        {
141
                return pdFALSE;
142
        }
143
}
144
/*-----------------------------------------------------------*/
145
 
146
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
147
{
148
signed portBASE_TYPE xReturn;
149
 
150
        /* Send the next character to the queue of characters waiting transmission,
151
        then enable the UART Tx interrupt, just in case UART transmission has already
152
        completed and switched itself off. */
153
        xReturn = xQueueSend( xCharsForTx, &cOutChar, xBlockTime );
154
        UCA1IE |= UCTXIE;
155
 
156
        return xReturn;
157
}
158
/*-----------------------------------------------------------*/
159
 
160
#pragma vector=USCI_A1_VECTOR
161
static __interrupt void prvUSCI_A1_ISR( void )
162
{
163
signed portCHAR cChar;
164
portBASE_TYPE xTaskWoken = pdFALSE;
165
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
166
 
167
        while( ( UCA1IFG & UCRXIFG ) != 0 )
168
        {
169
                /* Get the character from the UART and post it on the queue of Rxed
170
                characters. */
171
                cChar = UCA1RXBUF;
172
                xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
173
        }
174
 
175
        /* If there is a Tx interrupt pending and the tx interrupts are enabled. */
176
        if( ( UCA1IFG & UCTXIFG ) != 0 )
177
        {
178
                /* The previous character has been transmitted.  See if there are any
179
                further characters waiting transmission. */
180
                if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWoken ) == pdTRUE )
181
                {
182
                        /* There was another character queued - transmit it now. */
183
                        UCA1TXBUF = cChar;
184
                }
185
                else
186
                {
187
                        /* There were no other characters to transmit - disable the Tx
188
                        interrupt. */
189
                        UCA1IE &= ~UCTXIE;
190
                }
191
        }
192
 
193
        __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );
194
 
195
        /* If writing to a queue caused a task to unblock, and the unblocked task
196
        has a priority equal to or above the task that this interrupt interrupted,
197
        then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
198
        xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
199
        interrupt returns directly to the higher priority unblocked task.
200
 
201
        THIS MUST BE THE LAST THING DONE IN THE ISR. */
202
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
203
}
204
 
205
 

powered by: WebSVN 2.1.0

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