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