Electronic Load 1.0 Programmable Constant Current Sink

uart.h
Go to the documentation of this file.
1 // uart.h
2
3
4 #ifndef UART_H_
5 #define UART_H_
6
7 //#define USE_RTS // comment this out if your circuit does not have RTS/CTS-lines
8 #include <stdio.h>
9 #include "Config.h"
10
11 /* We don't have RTS/CTS and Driver Enable
12 #define UART0_DE_MASK 0x04
13 #define UART0_PORT PORTE
14 #define UART0_PIN PINE*/
15
16 #define HOST_BAUD 115200
17 #define HOST_UBRR (F_CPU/16/HOST_BAUD-1)
18
19 // Buffer Sizes. Must be <255 since the Poiters are only uint8_t
20 #define UART0_TXBUFSIZE 10
21 #define CMDLINE_MAX 20 // Maximum Number of characters used in a Command Line
22 extern volatile char cmdline[CMDLINE_MAX+1];
23
24 extern volatile uint8_t cFlags;
25 static const uint8_t CFLAG_PARITYERROR=4;
26 static const uint8_t CFLAG_CHECKSUMERROR=8;
27 static const uint8_t CFLAG_CMDRECEIVED=16;
28 static const uint8_t CFLAG_BYTERECEIVED=32;
29
30 extern volatile uint8_t tbuf0_tail,tbuf0_head;
31 extern volatile uint8_t byteFromHost;
32 extern volatile uint8_t hostCommandsLost;
33
34 extern FILE uart0;
35 extern void InitUart(void);
36 extern int putchar_uart0(char,FILE*);
37 extern int hprintf_P(const char *fmt, ... ) __attribute__ ((format(printf,1,2)));
38 extern void Usart0FlushRx(void);
39
40
46 static inline void UsartTimerCallback(void)
47 {
48 #ifdef USE_RTS
49 if (config.useRts)
50 {
51 if (!(UART0_PIN & UART1_CTS_MASK) && (tbuf0_head!=tbuf0_tail))
52 {
53 UCSR1B|=0b01100000; // enable UDRE and TX Complete interrupt
54 }
55 }
56 #endif
57 }
58
61 static inline void AssertRTS(void)
62 {
63 #ifdef USE_RTS // Defined out...
64 if (config.useRts) // Config'd out...
65 UART1_PORT&= ~UART1_RTS_MASK;
66 #endif
67 }
68
71 static inline void ReleaseRTS(void)
72 {
73 #ifdef USE_RTS
74 if (config.useRts)
75 UART1_PORT|=UART1_RTS_MASK;
76 #endif
77 }
78 #endif
ReleaseRTS
static void ReleaseRTS(void)
Releases RTS to the Host Line, i.e. stops the Host from sending Data.
Definition: uart.h:71
CFLAG_BYTERECEIVED
static const uint8_t CFLAG_BYTERECEIVED
Received a Byte from the host.
Definition: uart.h:28
cmdline
volatile char cmdline[CMDLINE_MAX+1]
Ready to hold CMDLINE_MAX chars plus terminating 0.
Definition: uart.c:41
CFLAG_PARITYERROR
static const uint8_t CFLAG_PARITYERROR
Parity Error in received Byte.
Definition: uart.h:25
config.h
Structures and Constants for Configuration Handling.
putchar_uart0
int putchar_uart0(char, FILE *)
The Putchar-Routine for USART0 (Host-Interface)
Definition: uart.c:107
tbuf0_tail
volatile uint8_t tbuf0_tail
Definition: uart.c:36
tbuf0_head
volatile uint8_t tbuf0_head
Definition: uart.c:36
cFlags
volatile uint8_t cFlags
Definition: uart.c:33
UsartTimerCallback
static void UsartTimerCallback(void)
Timer Callback. Checks for CTS from the Host to resume Communication.
Definition: uart.h:46
AssertRTS
static void AssertRTS(void)
Asserts RTS to the Host Line, i.e. allows the Host to send Data.
Definition: uart.h:61
CFLAG_CMDRECEIVED
static const uint8_t CFLAG_CMDRECEIVED
Received the terminating CR of a Command.
Definition: uart.h:27
Usart0FlushRx
void Usart0FlushRx(void)
Definition: uart.c:197
uart0
FILE uart0
Definition: uart.c:44
byteFromHost
volatile uint8_t byteFromHost
Contains the last byte received from the host.
Definition: uart.c:38
hprintf_P
int hprintf_P(const char *fmt,...)
printf_P for Communication with the Host
Definition: uart.c:208
CMDLINE_MAX
#define CMDLINE_MAX
Definition: uart.h:21
config
confStruct_t config
The Configuration. It is read on startup from the EEPROM.
Definition: config.c:37
hostCommandsLost
volatile uint8_t hostCommandsLost
Counts the number of commands lost due to buffer overrun.
Definition: uart.c:39
CFLAG_CHECKSUMERROR
static const uint8_t CFLAG_CHECKSUMERROR
Checksum Error in received Telegram.
Definition: uart.h:26
InitUart
void InitUart(void)
Initialize USART Hardware and Pointers.
Definition: uart.c:53