Prof Greg Egan / Mbed 2 deprecated UAVXArm-GKE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sb_uart1.cpp Source File

sb_uart1.cpp

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 #include "../SerialBuffered.h"
00024 #include "../sb_globals.h"
00025 
00026 extern "C" void SerialBuffered_ISR(unsigned long, int);
00027 
00028 extern "C" static void SerialBuffered_ISR_1(void) __irq { SerialBuffered_ISR(LPC_UART1_BASE, 1); }
00029 
00030 void SerialBuffered::set_uart1(PinName tx, PinName rx) {
00031     unsigned ier = 0;
00032     
00033     if (tx == NC && rx == NC) return; // Eh, why would one?
00034 
00035     LPC_SC->PCONP       |=  (1UL << 4);
00036     LPC_SC->PCLKSEL0    &= ~(3UL << 8);
00037     LPC_SC->PCLKSEL0    |=  (1UL << 8);
00038     
00039     if (rx == p14) { 
00040         set_rx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); 
00041         LPC_PINCON->PINSEL1 &= ~(3UL << 0); 
00042         LPC_PINCON->PINSEL1 |=  (1UL << 0); 
00043         ier |= 1; 
00044     }
00045     else if (rx == p25) { 
00046         set_rx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); 
00047         LPC_PINCON->PINSEL4 &= ~(3UL << 2); 
00048         LPC_PINCON->PINSEL4 |=  (2UL << 2); 
00049         ier |= 1; 
00050     }
00051     else { reset_uart_rx(1); }
00052     
00053     if (tx == p13) { 
00054         set_tx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); 
00055         LPC_PINCON->PINSEL0 &= ~(3UL << 30); 
00056         LPC_PINCON->PINSEL0 |= (1UL << 30); 
00057         ier |= 2; 
00058     }
00059     else if (tx == p26) { 
00060         set_tx_buffer_size(SERIALBUFFERED_BUFFER_SIZE); 
00061         LPC_PINCON->PINSEL4 &= ~(3UL <<  0); 
00062         LPC_PINCON->PINSEL4 |= (2UL <<  0); 
00063         ier |= 2; 
00064     }
00065     else { reset_uart_tx(1); }
00066     
00067     if (ier) {
00068         baud(9600);
00069         format(SerialBuffered::WordLength8, SerialBuffered::NoParity, SerialBuffered::StopBit1);
00070         LPC_UART1->FCR = 0x7;
00071         NVIC_SetVector(UART1_IRQn, (uint32_t)SerialBuffered_ISR_1);
00072         NVIC_EnableIRQ(UART1_IRQn);    
00073         LPC_UART1->IER = ier;
00074     }
00075 }