MOODSERIAL personal fork

Dependents:   rosserial_mbed_lib

Fork of MODSERIAL by Andy K

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers INIT.cpp Source File

INIT.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 "MODSERIAL.h"
00024 #include "MACROS.h"
00025 
00026 
00027 namespace AjK {
00028 
00029 void
00030 MODSERIAL::init( int txSize, int rxSize, PinName rx )
00031 {
00032     disableIrq();
00033     
00034     callbackInfo.setSerial(this);
00035 
00036 #ifdef __LPC11UXX_H__
00037 
00038     _base = LPC_USART;
00039     
00040 #elif defined MKL25Z4_H_
00041     switch( _serial.index ) {
00042         case 0: _base = UART0; break;
00043         case 1: _base = UART1; break;
00044         case 2: _base = UART2; break;
00045         default: _base = NULL;      break;
00046     }
00047 #else    
00048     switch( _serial.index ) {
00049         case 0: _base = LPC_UART0; break;
00050         case 1: _base = LPC_UART1; break;
00051         case 2: _base = LPC_UART2; break;
00052         case 3: _base = LPC_UART3; break;
00053         default: _base = NULL;      break;
00054     }
00055 #endif
00056     
00057     dmaSendChannel  = -1;
00058     moddma_p        = (void *)NULL;
00059     
00060     if ( _base != NULL ) {
00061         buffer_size[RxIrq]     = rxSize;
00062         buffer[RxIrq]          = rxSize > 0 ? (char *)malloc(buffer_size[RxIrq]) : (char *)NULL;
00063         buffer_in[RxIrq]       = 0;
00064         buffer_out[RxIrq]      = 0;
00065         buffer_count[RxIrq]    = 0;
00066         buffer_overflow[RxIrq] = 0;
00067         Serial::attach( this, &MODSERIAL::isr_rx, Serial::RxIrq );        
00068         
00069         buffer_size[TxIrq]     = txSize;
00070         buffer[TxIrq]          = txSize > 0 ? (char *)malloc(buffer_size[TxIrq]) : (char *)NULL;
00071         buffer_in[TxIrq]       = 0;
00072         buffer_out[TxIrq]      = 0;
00073         buffer_count[TxIrq]    = 0;
00074         buffer_overflow[TxIrq] = 0;
00075         Serial::attach( this, &MODSERIAL::isr_tx, Serial::TxIrq );
00076     }
00077     else {
00078         error("MODSERIAL must have a defined UART to function.");
00079     }
00080     
00081     _FCR = MODSERIAL_FIFO_ENABLE | MODSERIAL_FIFO_RX_RESET | MODSERIAL_FIFO_TX_RESET;
00082     
00083     auto_detect_char = 0;
00084     
00085     enableIrq();
00086 }
00087 
00088 }; // namespace AjK ends