Dependencies: PinDetect TextLCD mbed mRotaryEncoder
MODSERIAL/INIT.cpp@0:afb2650fb49a, 2012-02-13 (annotated)
- Committer:
- cicklaus
- Date:
- Mon Feb 13 02:11:20 2012 +0000
- Revision:
- 0:afb2650fb49a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cicklaus | 0:afb2650fb49a | 1 | /* |
cicklaus | 0:afb2650fb49a | 2 | Copyright (c) 2010 Andy Kirkham |
cicklaus | 0:afb2650fb49a | 3 | |
cicklaus | 0:afb2650fb49a | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
cicklaus | 0:afb2650fb49a | 5 | of this software and associated documentation files (the "Software"), to deal |
cicklaus | 0:afb2650fb49a | 6 | in the Software without restriction, including without limitation the rights |
cicklaus | 0:afb2650fb49a | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
cicklaus | 0:afb2650fb49a | 8 | copies of the Software, and to permit persons to whom the Software is |
cicklaus | 0:afb2650fb49a | 9 | furnished to do so, subject to the following conditions: |
cicklaus | 0:afb2650fb49a | 10 | |
cicklaus | 0:afb2650fb49a | 11 | The above copyright notice and this permission notice shall be included in |
cicklaus | 0:afb2650fb49a | 12 | all copies or substantial portions of the Software. |
cicklaus | 0:afb2650fb49a | 13 | |
cicklaus | 0:afb2650fb49a | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
cicklaus | 0:afb2650fb49a | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
cicklaus | 0:afb2650fb49a | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
cicklaus | 0:afb2650fb49a | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
cicklaus | 0:afb2650fb49a | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
cicklaus | 0:afb2650fb49a | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
cicklaus | 0:afb2650fb49a | 20 | THE SOFTWARE. |
cicklaus | 0:afb2650fb49a | 21 | */ |
cicklaus | 0:afb2650fb49a | 22 | |
cicklaus | 0:afb2650fb49a | 23 | #include "MODSERIAL.h" |
cicklaus | 0:afb2650fb49a | 24 | #include "MACROS.h" |
cicklaus | 0:afb2650fb49a | 25 | |
cicklaus | 0:afb2650fb49a | 26 | namespace AjK { |
cicklaus | 0:afb2650fb49a | 27 | |
cicklaus | 0:afb2650fb49a | 28 | void |
cicklaus | 0:afb2650fb49a | 29 | MODSERIAL::init(int txSize, int rxSize) |
cicklaus | 0:afb2650fb49a | 30 | { |
cicklaus | 0:afb2650fb49a | 31 | disableIrq(); |
cicklaus | 0:afb2650fb49a | 32 | |
cicklaus | 0:afb2650fb49a | 33 | callbackInfo.setSerial(this); |
cicklaus | 0:afb2650fb49a | 34 | |
cicklaus | 0:afb2650fb49a | 35 | switch(_uidx) { |
cicklaus | 0:afb2650fb49a | 36 | case 0: _base = LPC_UART0; break; |
cicklaus | 0:afb2650fb49a | 37 | case 1: _base = LPC_UART1; break; |
cicklaus | 0:afb2650fb49a | 38 | case 2: _base = LPC_UART2; break; |
cicklaus | 0:afb2650fb49a | 39 | case 3: _base = LPC_UART3; break; |
cicklaus | 0:afb2650fb49a | 40 | default : _base = NULL; break; |
cicklaus | 0:afb2650fb49a | 41 | } |
cicklaus | 0:afb2650fb49a | 42 | |
cicklaus | 0:afb2650fb49a | 43 | dmaSendChannel = -1; |
cicklaus | 0:afb2650fb49a | 44 | moddma_p = (void *)NULL; |
cicklaus | 0:afb2650fb49a | 45 | |
cicklaus | 0:afb2650fb49a | 46 | if (_base != NULL) { |
cicklaus | 0:afb2650fb49a | 47 | buffer_size[RxIrq] = rxSize; |
cicklaus | 0:afb2650fb49a | 48 | buffer[RxIrq] = rxSize > 0 ? (char *)malloc(buffer_size[RxIrq]) : (char *)NULL; |
cicklaus | 0:afb2650fb49a | 49 | buffer_in[RxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 50 | buffer_out[RxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 51 | buffer_count[RxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 52 | buffer_overflow[RxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 53 | Serial::attach(this, &MODSERIAL::isr_rx, Serial::RxIrq); |
cicklaus | 0:afb2650fb49a | 54 | |
cicklaus | 0:afb2650fb49a | 55 | buffer_size[TxIrq] = txSize; |
cicklaus | 0:afb2650fb49a | 56 | buffer[TxIrq] = txSize > 0 ? (char *)malloc(buffer_size[TxIrq]) : (char *)NULL; |
cicklaus | 0:afb2650fb49a | 57 | buffer_in[TxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 58 | buffer_out[TxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 59 | buffer_count[TxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 60 | buffer_overflow[TxIrq] = 0; |
cicklaus | 0:afb2650fb49a | 61 | Serial::attach(this, &MODSERIAL::isr_tx, Serial::TxIrq); |
cicklaus | 0:afb2650fb49a | 62 | } |
cicklaus | 0:afb2650fb49a | 63 | else { |
cicklaus | 0:afb2650fb49a | 64 | error("MODSERIAL must have a defined UART to function."); |
cicklaus | 0:afb2650fb49a | 65 | } |
cicklaus | 0:afb2650fb49a | 66 | |
cicklaus | 0:afb2650fb49a | 67 | _FCR = MODSERIAL_FIFO_ENABLE | MODSERIAL_FIFO_RX_RESET | MODSERIAL_FIFO_TX_RESET; |
cicklaus | 0:afb2650fb49a | 68 | |
cicklaus | 0:afb2650fb49a | 69 | auto_detect_char = 0; |
cicklaus | 0:afb2650fb49a | 70 | |
cicklaus | 0:afb2650fb49a | 71 | enableIrq(); |
cicklaus | 0:afb2650fb49a | 72 | } |
cicklaus | 0:afb2650fb49a | 73 | |
cicklaus | 0:afb2650fb49a | 74 | }; // namespace AjK ends |