USB-BDI
M:/USB-BDI/USB-BDI/Firmware/MPC555-USB-BDI/include/uart.h
Go to the documentation of this file.
00001 /*      USB-BDI Used for programming and debugging a MPC555 over USB
00002  * 
00003  *  Copyright 2005 NTB Interstate University of Applied Sciences of Technology Buchs
00004  *
00005  *  This program is free software: you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation, either version 3 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  */
00015 
00024 #ifndef UART_H_
00025 #define UART_H_
00026 
00027 #include "fx2regs.h"
00028 
00029 // PORT
00030 
00031 // USB buffers
00033 #define usbOutBufferUart EP4FIFOBUF
00034 
00035 #define usbInBufferUart EP8FIFOBUF
00036 
00037 #define NUMBER_OF_STD_VALUES 7
00038 
00039 // UART buffers
00041 #define UART_BUF_LEN 512
00042 
00043 extern __xdata volatile unsigned char uart0OutBuffer[UART_BUF_LEN];
00044 extern __xdata volatile unsigned char uart0InBuffer[UART_BUF_LEN];
00045 
00046 extern volatile unsigned short uart0OutBufferStart;
00047 extern volatile unsigned short uart0OutBufferEnd;
00048 extern volatile unsigned short uart0InBufferStart;
00049 extern volatile unsigned short uart0InBufferEnd;
00050 extern unsigned short uart0InBufferLen;
00051 
00053 #define Uart0Insert(char)\
00054 {\
00055         uart0InBuffer[uart0InBufferEnd] = char;\
00056         uart0InBufferEnd = (uart0InBufferEnd + 1) % UART_BUF_LEN;\
00057         /* used to overwrite the oldest char if buffer full*/\
00058         if (uart0InBufferEnd == uart0InBufferStart) {\
00059                 uart0InBufferStart = (uart0InBufferStart + 1) % UART_BUF_LEN;\
00060         }\
00061 }
00062 
00063 #define Uart0TriggerSend()\
00064 {\
00065         uart0InBufferLen = ((uart0InBufferEnd - uart0InBufferStart) + UART_BUF_LEN) % UART_BUF_LEN;\
00066         if (uart0InBufferLen > 0) {\
00067                 SBUF0 = uart0InBuffer[uart0InBufferStart];\
00068                 uart0InBufferStart = (uart0InBufferStart + 1) % UART_BUF_LEN;\
00069         }\
00070 }
00071 
00072 void initUART();
00073 void changeBaudRate(unsigned long bitRate);
00074 
00075 #endif /*UART_H_*/
 All Files Functions Variables Defines