UAVX Multicopter Flight Controller.

Dependencies:   mbed

Committer:
gke
Date:
Tue Apr 26 12:12:29 2011 +0000
Revision:
2:90292f8bd179
Parent:
0:62a1c91a859a
Not flightworthy. Posted for others to make use of the I2C SW code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gke 0:62a1c91a859a 1 /*
gke 0:62a1c91a859a 2 Copyright (c) 2010 Andy Kirkham
gke 0:62a1c91a859a 3
gke 0:62a1c91a859a 4 Permission is hereby granted, free of charge, to any person obtaining a copy
gke 0:62a1c91a859a 5 of this software and associated documentation files (the "Software"), to deal
gke 0:62a1c91a859a 6 in the Software without restriction, including without limitation the rights
gke 0:62a1c91a859a 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gke 0:62a1c91a859a 8 copies of the Software, and to permit persons to whom the Software is
gke 0:62a1c91a859a 9 furnished to do so, subject to the following conditions:
gke 0:62a1c91a859a 10
gke 0:62a1c91a859a 11 The above copyright notice and this permission notice shall be included in
gke 0:62a1c91a859a 12 all copies or substantial portions of the Software.
gke 0:62a1c91a859a 13
gke 0:62a1c91a859a 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gke 0:62a1c91a859a 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gke 0:62a1c91a859a 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gke 0:62a1c91a859a 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gke 0:62a1c91a859a 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gke 0:62a1c91a859a 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gke 0:62a1c91a859a 20 THE SOFTWARE.
gke 0:62a1c91a859a 21 */
gke 0:62a1c91a859a 22
gke 0:62a1c91a859a 23 #include "../SerialBuffered.h"
gke 0:62a1c91a859a 24 #include "../sb_globals.h"
gke 0:62a1c91a859a 25
gke 0:62a1c91a859a 26 extern "C" void SerialBuffered_ISR(unsigned long, int);
gke 0:62a1c91a859a 27
gke 0:62a1c91a859a 28 extern "C" static void SerialBuffered_ISR_0(void) __irq { SerialBuffered_ISR(LPC_UART0_BASE, 0); }
gke 0:62a1c91a859a 29
gke 0:62a1c91a859a 30 void SerialBuffered::set_uart0(PinName tx, PinName rx) {
gke 0:62a1c91a859a 31 unsigned ier = 0;
gke 0:62a1c91a859a 32
gke 0:62a1c91a859a 33 if (tx == NC && rx == NC) return; // Eh, why would one?
gke 0:62a1c91a859a 34
gke 0:62a1c91a859a 35 LPC_SC->PCONP |= (1UL << 3);
gke 0:62a1c91a859a 36 LPC_SC->PCLKSEL0 &= ~(3UL << 6);
gke 0:62a1c91a859a 37 LPC_SC->PCLKSEL0 |= (1UL << 6);
gke 0:62a1c91a859a 38
gke 0:62a1c91a859a 39 if (tx == USBTX) {
gke 0:62a1c91a859a 40 set_tx_buffer_size(SERIALBUFFERED_BUFFER_SIZE);
gke 0:62a1c91a859a 41 LPC_PINCON->PINSEL0 &= ~(1UL << 4);
gke 0:62a1c91a859a 42 LPC_PINCON->PINSEL0 |= (1UL << 4);
gke 0:62a1c91a859a 43 ier |= 1;
gke 0:62a1c91a859a 44 }
gke 0:62a1c91a859a 45 else { reset_uart_tx(0); }
gke 0:62a1c91a859a 46
gke 0:62a1c91a859a 47 if (rx == USBRX) {
gke 0:62a1c91a859a 48 set_rx_buffer_size(SERIALBUFFERED_BUFFER_SIZE);
gke 0:62a1c91a859a 49 LPC_PINCON->PINSEL0 &= ~(1UL << 6);
gke 0:62a1c91a859a 50 LPC_PINCON->PINSEL0 |= (1UL << 6);
gke 0:62a1c91a859a 51 ier |= 2;
gke 0:62a1c91a859a 52 }
gke 0:62a1c91a859a 53 else { reset_uart_rx(0); }
gke 0:62a1c91a859a 54
gke 0:62a1c91a859a 55 if (ier) {
gke 0:62a1c91a859a 56 baud(9600);
gke 0:62a1c91a859a 57 format(SerialBuffered::WordLength8, SerialBuffered::NoParity, SerialBuffered::StopBit1);
gke 0:62a1c91a859a 58 LPC_UART0->FCR = 0x7;
gke 0:62a1c91a859a 59 NVIC_SetVector(UART0_IRQn, (uint32_t)SerialBuffered_ISR_0);
gke 0:62a1c91a859a 60 NVIC_EnableIRQ(UART0_IRQn);
gke 0:62a1c91a859a 61 LPC_UART0->IER = ier;
gke 0:62a1c91a859a 62 }
gke 0:62a1c91a859a 63 }