Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Methods/.svn/text-base/sb_uart1.cpp.svn-base@1:1e3318a30ddd, 2011-02-25 (annotated)
- Committer:
- gke
- Date:
- Fri Feb 25 01:35:24 2011 +0000
- Revision:
- 1:1e3318a30ddd
This version has broken I2C - posted for debugging involvement of Simon et al.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gke | 1:1e3318a30ddd | 1 | /* |
| gke | 1:1e3318a30ddd | 2 | Copyright (c) 2010 Andy Kirkham |
| gke | 1:1e3318a30ddd | 3 | |
| gke | 1:1e3318a30ddd | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| gke | 1:1e3318a30ddd | 5 | of this software and associated documentation files (the "Software"), to deal |
| gke | 1:1e3318a30ddd | 6 | in the Software without restriction, including without limitation the rights |
| gke | 1:1e3318a30ddd | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| gke | 1:1e3318a30ddd | 8 | copies of the Software, and to permit persons to whom the Software is |
| gke | 1:1e3318a30ddd | 9 | furnished to do so, subject to the following conditions: |
| gke | 1:1e3318a30ddd | 10 | |
| gke | 1:1e3318a30ddd | 11 | The above copyright notice and this permission notice shall be included in |
| gke | 1:1e3318a30ddd | 12 | all copies or substantial portions of the Software. |
| gke | 1:1e3318a30ddd | 13 | |
| gke | 1:1e3318a30ddd | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| gke | 1:1e3318a30ddd | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| gke | 1:1e3318a30ddd | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| gke | 1:1e3318a30ddd | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| gke | 1:1e3318a30ddd | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| gke | 1:1e3318a30ddd | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| gke | 1:1e3318a30ddd | 20 | THE SOFTWARE. |
| gke | 1:1e3318a30ddd | 21 | */ |
| gke | 1:1e3318a30ddd | 22 | |
| gke | 1:1e3318a30ddd | 23 | #include "../SerialBuffered.h" |
| gke | 1:1e3318a30ddd | 24 | #include "../sb_globals.h" |
| gke | 1:1e3318a30ddd | 25 | |
| gke | 1:1e3318a30ddd | 26 | extern "C" void SerialBuffered_ISR(unsigned long, int); |
| gke | 1:1e3318a30ddd | 27 | |
| gke | 1:1e3318a30ddd | 28 | extern "C" static void SerialBuffered_ISR_1(void) __irq { SerialBuffered_ISR(LPC_UART1_BASE, 1); } |
| gke | 1:1e3318a30ddd | 29 | |
| gke | 1:1e3318a30ddd | 30 | void SerialBuffered::set_uart1(PinName tx, PinName rx) { |
| gke | 1:1e3318a30ddd | 31 | unsigned ier = 0; |
| gke | 1:1e3318a30ddd | 32 | |
| gke | 1:1e3318a30ddd | 33 | if (tx == NC && rx == NC) return; // Eh, why would one? |
| gke | 1:1e3318a30ddd | 34 | |
| gke | 1:1e3318a30ddd | 35 | LPC_SC->PCONP |= (1UL << 4); |
| gke | 1:1e3318a30ddd | 36 | LPC_SC->PCLKSEL0 &= ~(3UL << 8); |
| gke | 1:1e3318a30ddd | 37 | LPC_SC->PCLKSEL0 |= (1UL << 8); |
| gke | 1:1e3318a30ddd | 38 | |
| gke | 1:1e3318a30ddd | 39 | if (rx == p14) { |
| gke | 1:1e3318a30ddd | 40 | set_rx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); |
| gke | 1:1e3318a30ddd | 41 | LPC_PINCON->PINSEL1 &= ~(3UL << 0); |
| gke | 1:1e3318a30ddd | 42 | LPC_PINCON->PINSEL1 |= (1UL << 0); |
| gke | 1:1e3318a30ddd | 43 | ier |= 1; |
| gke | 1:1e3318a30ddd | 44 | } |
| gke | 1:1e3318a30ddd | 45 | else if (rx == p25) { |
| gke | 1:1e3318a30ddd | 46 | set_rx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); |
| gke | 1:1e3318a30ddd | 47 | LPC_PINCON->PINSEL4 &= ~(3UL << 2); |
| gke | 1:1e3318a30ddd | 48 | LPC_PINCON->PINSEL4 |= (2UL << 2); |
| gke | 1:1e3318a30ddd | 49 | ier |= 1; |
| gke | 1:1e3318a30ddd | 50 | } |
| gke | 1:1e3318a30ddd | 51 | else { reset_uart_rx(1); } |
| gke | 1:1e3318a30ddd | 52 | |
| gke | 1:1e3318a30ddd | 53 | if (tx == p13) { |
| gke | 1:1e3318a30ddd | 54 | set_tx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); |
| gke | 1:1e3318a30ddd | 55 | LPC_PINCON->PINSEL0 &= ~(3UL << 30); |
| gke | 1:1e3318a30ddd | 56 | LPC_PINCON->PINSEL0 |= (1UL << 30); |
| gke | 1:1e3318a30ddd | 57 | ier |= 2; |
| gke | 1:1e3318a30ddd | 58 | } |
| gke | 1:1e3318a30ddd | 59 | else if (tx == p26) { |
| gke | 1:1e3318a30ddd | 60 | set_tx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); |
| gke | 1:1e3318a30ddd | 61 | LPC_PINCON->PINSEL4 &= ~(3UL << 0); |
| gke | 1:1e3318a30ddd | 62 | LPC_PINCON->PINSEL4 |= (2UL << 0); |
| gke | 1:1e3318a30ddd | 63 | ier |= 2; |
| gke | 1:1e3318a30ddd | 64 | } |
| gke | 1:1e3318a30ddd | 65 | else { reset_uart_tx(1); } |
| gke | 1:1e3318a30ddd | 66 | |
| gke | 1:1e3318a30ddd | 67 | if (ier) { |
| gke | 1:1e3318a30ddd | 68 | baud(9600); |
| gke | 1:1e3318a30ddd | 69 | format(SerialBuffered::WordLength8, SerialBuffered::NoParity, SerialBuffered::StopBit1); |
| gke | 1:1e3318a30ddd | 70 | LPC_UART1->FCR = 0x7; |
| gke | 1:1e3318a30ddd | 71 | NVIC_SetVector(UART1_IRQn, (uint32_t)SerialBuffered_ISR_1); |
| gke | 1:1e3318a30ddd | 72 | NVIC_EnableIRQ(UART1_IRQn); |
| gke | 1:1e3318a30ddd | 73 | LPC_UART1->IER = ier; |
| gke | 1:1e3318a30ddd | 74 | } |
| gke | 1:1e3318a30ddd | 75 | } |