Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __UART_H
00033 #define __UART_H
00034
00035 #include <inttypes.h>
00036
00037 extern void UARTInitialize(unsigned int);
00038 extern void UARTWriteChar(unsigned char);
00039 extern unsigned char UARTReadChar(void);
00040 extern void __putchar(int);
00041 extern void UART_send(char *, unsigned char);
00042 extern void UART_send_ringbuffer(void);
00043 extern int ringbuffer(unsigned char, unsigned char*, unsigned int);
00044
00045 void startAutoBaud(void);
00046 volatile extern char autobaud_in_progress;
00047
00048 int writePacket2Ringbuffer(uint8_t descriptor, void * data, uint8_t length);
00049 extern void uart0ISR(void);
00050
00051 inline uint16_t crc16(void *, uint16_t count, uint16_t prev_crc);
00052 inline uint16_t crc_update(uint16_t, uint8_t);
00053
00054 #define RBREAD 0
00055 #define RBWRITE 1
00056 #define RBFREE 2
00057 #define RINGBUFFERSIZE 384
00058
00059 int UART0_txEmpty(void);
00060 void UART0_rxFlush(void);
00061 void UART0_txFlush(void);
00062 uint8_t UART0_writeFifo(void * data, uint32_t length);
00063
00064
00065 #define UART0_RX_BUFFERSIZE 512
00066 #define UART0_TX_BUFFERSIZE 512
00067
00068
00069 #define PACKET_INFO_SIZE 64
00070
00071 typedef struct
00072 {
00073 uint8_t descriptor;
00074 void * data;
00075 uint8_t updated;
00076 } PacketInfo;
00077
00078 extern volatile unsigned int UART_rxPacketCount;
00079 extern volatile unsigned int UART_rxGoodPacketCount;
00080
00081 typedef struct
00082 {
00083 volatile uint8_t *buffer;
00084 uint8_t inUse;
00085 uint32_t bufferSize;
00086 uint32_t readIdx;
00087 uint32_t writeIdx;
00088 uint32_t tmp;
00089 uint32_t mask;
00090 }volatile Fifo;
00091
00092 extern volatile short uart0_min_tx_buffer;
00093 extern volatile short uart0_min_rx_buffer;
00094
00095 void Fifo_initialize(Fifo * fifo, volatile uint8_t * buffer, uint32_t bufferSize);
00096 inline uint8_t Fifo_writeByte(Fifo * fifo, uint8_t byte);
00097 inline uint8_t Fifo_writeBlock(Fifo * fifo, void *data, uint32_t length);
00098 inline uint8_t Fifo_readByte(Fifo * fifo, uint8_t * byte);
00099 inline uint16_t Fifo_availableMemory(Fifo * fifo);
00100 inline void Fifo_reset(Fifo * fifo);
00101
00102 void parseRxFifo(void);
00103
00104 PacketInfo* registerPacket(uint8_t descriptor, void * data);
00105
00106 #endif //__UART_H