00001 /* 00002 * Copyright Droids Corporation, Microb Technology, Eirbot (2005) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program 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 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Revision : $Id: uart_private.h,v 1.4 2009-03-15 21:51:18 zer0 Exp $ 00019 * 00020 */ 00021 00022 /* Olivier MATZ, Droids-corp 2004 - 2009 */ 00023 00024 #ifndef _UART_PRIVATE_H_ 00025 #define _UART_PRIVATE_H_ 00026 00027 #include <aversive.h> 00028 #include <aversive/list.h> 00029 00030 #include <uart.h> 00031 #include <uart_defs.h> 00032 #include <uart_config.h> 00033 00034 typedef volatile uint8_t *uart_reg_t; 00035 00036 struct regs { 00037 uart_reg_t udr; 00038 uart_reg_t ucsra; 00039 uart_reg_t ucsrb; 00040 uart_reg_t ucsrc; 00041 uart_reg_t ubrrl; 00042 uart_reg_t ubrrh; 00043 }; 00044 00045 const struct regs uart_regs[UART_HW_NUM]; 00046 00047 typedef void (event)(char); 00048 typedef void (event_9bits)(int); 00049 00051 extern struct cirbuf g_tx_fifo[UART_HW_NUM]; 00052 00054 extern struct cirbuf g_rx_fifo[UART_HW_NUM]; 00055 00056 extern event *rx_event[UART_HW_NUM]; 00057 extern event *tx_event[UART_HW_NUM]; 00058 00059 void uart_send_next_char(uint8_t num); 00060 int8_t uart_setconf(uint8_t num, struct uart_config *u); 00061 00062 static inline char uart_get_udr(uint8_t num) 00063 { 00064 return *uart_regs[num].udr; 00065 } 00066 00067 static inline void uart_set_udr(uint8_t num, char c) 00068 { 00069 *uart_regs[num].udr = c; 00070 /* tx event function. We suppose interrupts are already 00071 * locked, so no pb with tx_event pointer */ 00072 if (tx_event[num]) 00073 tx_event[num](c); 00074 } 00075 00076 #ifdef CONFIG_MODULE_UART_9BITS 00077 static inline int uart_get_udr_9bits(uint8_t num) 00078 { 00079 int val = *uart_regs[num].udr; 00080 val |= (*uart_regs[num].ucsrb & ((1 << RXB8) ? 0x100 : 0)); 00081 return val; 00082 } 00083 00084 static inline void uart_set_udr_9bits(uint8_t num, int c) 00085 { 00086 if (c & 0x100 ) 00087 *uart_regs[num].ucsrb |= (1 << RXB8); 00088 else 00089 *uart_regs[num].ucsrb &= ~(1 << RXB8); 00090 *uart_regs[num].udr = c; 00091 00092 /* tx event function. We suppose interrupts are already 00093 * locked, so no pb with tx_event pointer */ 00094 if (tx_event[num]) 00095 ((event_9bits *)tx_event[num])(c); 00096 } 00097 #endif /* CONFIG_MODULE_UART_9BITS */ 00098 00099 #endif /* _UART_PRIVATE_H_ */