00001 /* 00002 Object Oriented Mobile Robot Model (OOMRM) C++ Library Copyright (C) 2002-2007 Derek Jones 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Lesser General Public 00006 License as published by the Free Software Foundation; either 00007 version 2.1 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this library; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 $Id: ouart.h,v 1.5 2007/09/26 05:12:58 derek Exp $ 00019 */ 00020 #ifndef _OOMRM_UART_H 00021 #define _OOMRM_UART_H 00022 #include <hardware/oomrm.h> 00023 #include <shared.h> 00024 00026 00028 // For eb500 Uart buffer size. 00029 #define EBBUFF_SIZE 1024 00030 // Optimization for eb500 00031 #define EB500_RX_CHANNEL 10 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 // Provide an alternative UART receive callback function 00036 void set_uart_callback(fooshort f); 00037 } 00038 #endif 00039 00040 extern volatile word* _uart_RTX_buffer[]; // pointer to buffer for each channel (starts as NULL). [UART_IN_BUFF_SIZE]; 00041 extern volatile word *ptrRTXCharHead[]; // pointer to head of input buffer on channel n. 00042 extern volatile word *ptrRTXCharTail[]; // pinter to tail of input buffer on channel n. 00043 extern uint16 RTX_buffer_max[]; // = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // maximum number of characters in buffer for this channel (65K max) 00044 00045 /* Macros for moving character buffer pointers */ 00046 #define INC_CIRC_BUFFER_PTR(ptr, Addr, Length) ((ptr >= Addr + Length - 1) ? Addr : ptr+1) 00047 00051 enum UART_MODE { UART_NONE0=0, UART_NONE1=1, UART_RECEIVER=2, UART_TRANSMITTER=3 }; 00053 //enum UART_DEVICE { UART_GENERIC_DEVICE=0, UART_KEYPAD, UART_EB500 }; 00054 // This defines when to signal (semaphore/mailbox if RTOS) otherwise flag that a complete packet has been received. 00059 enum UART_SIGNAL { UART_GENERIC_SIGNAL, UART_ESCAPE_SIGNAL, UART_PACKETLENGTH_SIGNAL, UART_JAUSLENGTH_SIGNAL }; 00060 00062 enum PARITY_TYPE { OOMRM_PARITY_NONE=0, OOMRM_PARITY_EVEN=2, OOMRM_PARITY_ODD=3 }; // DO NOT CHANGE (UART HSQR) 00063 00064 #ifdef __cplusplus 00065 00067 00083 class oUART : public virtual OOMRM 00084 { 00085 public: 00086 oUART(); 00087 oUART(IOLINE channel, UART_MODE imode, int dsize, PARITY_TYPE parity, int BAUD_RATE); 00088 // friend void uart_handler(void); 00090 void init(IOLINE channel, UART_MODE mode, int dsize, PARITY_TYPE parity, int BAUD_RATE); 00094 void priority(PRIORITY p); 00098 bool havebyte();// { return (ptrRTXCharHead[_uart_channel] != ptrRTXCharTail[_uart_channel]); } 00100 word inbyte(void); 00101 /* 00102 { 00103 static word ReturnVal; 00104 ReturnVal = *ptrRTXCharTail[_uart_channel]; 00105 // Move pointer to next character 00106 ptrRTXCharTail[_uart_channel] = INC_CIRC_BUFFER_PTR(ptrRTXCharTail[_uart_channel], _uart_RTX_buffer[_uart_channel], RTX_buffer_max[_uart_channel]); 00107 return ReturnVal; 00108 } 00109 */ 00111 void outbyte(word txbyte); 00113 int sendingbyte(void); 00115 int send(const char* const buf, int nbytes); 00117 void buffer(volatile word* inbuffer, uint16 ilen); 00118 // The OS_Event has "C" declaration and causes all sorts of pain by putting it into a class structure--thus using void*. 00119 void config(uint8 isig, uint16 imod, void* semaphore, WSIM_IO_ID ihw); 00120 // Allows dynamically reconfiguring size of receive buffer before semaphore posts. 00121 void reconfig(uint16 imod); 00123 bool active(uint8 r = FALSE); 00125 void dump(void); 00127 uint16 byte_count(void); 00129 void baud_rate(int dsize, PARITY_TYPE parity, int BAUD_RATE); 00130 protected: 00131 IOLINE _uart_channel; // should be private--fix later. FLTK callback needs this. 00132 private: 00133 void ioline(IOLINE channel, UART_MODE mode, int dsize, PARITY_TYPE parity, int BAUD_RATE); 00134 UART_MODE _mode; 00135 // NOTE: most data had to be outside class for uart_handler 00136 }; 00137 #endif 00138 #endif
1.3