LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Macros | Functions | Variables
uart.h File Reference
Include dependency graph for uart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HOST_BAUD   9600
 
#define HOST_UBRR   (F_CPU/16/HOST_BAUD-1)
 
#define SENSOR_BAUD   9600
 
#define SENSOR_UBRR   (F_CPU/16/SENSOR_BAUD-1)
 
#define UART0_BUFSIZE   40
 Size of the UART0 Buffers. More...
 
#define UART0_DE_MASK   0x04
 
#define UART0_PORT   PORTE
 
#define UART1_BUFSIZE   200
 UART1 really communicates, so a little more. More...
 
#define UART1_CTS_MASK   0x20
 
#define UART1_DE_MASK   0x02
 
#define UART1_PIN   PIND
 
#define UART1_PORT   PORTD
 
#define UART1_RTS_MASK   0x10
 
#define USE_RTS
 

Functions

static void AssertRTS (void)
 Asserts RTS to the Host Line, i.e. allows the Host to send Data. More...
 
int hprintf_P (const char *fmt,...)
 printf_P for Communication with the Host More...
 
void InitUart (void)
 Initialize USART Hardware and Pointers. More...
 
void putc0 (char)
 Sends a Command Char (bit9=1) over USART0. More...
 
int putchar_uart1 (char, FILE *)
 The Putchar-Routine for USART1 (Host-Interface) More...
 
void putd0 (char)
 Sends a Data Char (bit9=0) over USART0. More...
 
static void ReleaseRTS (void)
 Releases RTS to the Host Line, i.e. stops the Host from sending Data. More...
 
bool Tbub1IsEmpty (void)
 Tell if Transmit Buffer 1 is empty. More...
 
static void Uart0DisableLineDriver (void)
 Disables the RS485 Line Driver on Uart0. More...
 
static void Uart0EnableLineDriver (void)
 Enables the RS485 Line Driver on Uart0. More...
 
static void Uart1DisableLineDriver (void)
 Disables the RS485 Line Driver on Uart1. More...
 
static void Uart1EnableLineDriver (void)
 Enables the RS485 Line Driver on Uart1. More...
 
void usart1FlushRx (void)
 
static void UsartTimerCallback (void)
 Timer Callback. Checks for CTS from the Host to resume Communication. More...
 

Variables

volatile uint8_t byteFromHost
 Contains the last byte received from the host. More...
 
uint8_t charsInRbuf0
 
volatile char cksum0
 Keeps track of the Checksum for USART0. It is automatically reset by command bytes. More...
 
uint8_t computedChecksum
 
volatile uint8_t hostCommandsLost
 Counts the number of commands lost due to buffer overrun. More...
 
volatile char rbuf0 []
 Receive Buffer for UART0. More...
 
volatile uint8_t tbuf1_head
 
volatile uint8_t tbuf1_tail
 
FILE uart0
 
FILE uart1
 

Macro Definition Documentation

◆ HOST_BAUD

#define HOST_BAUD   9600

◆ HOST_UBRR

#define HOST_UBRR   (F_CPU/16/HOST_BAUD-1)

◆ SENSOR_BAUD

#define SENSOR_BAUD   9600

◆ SENSOR_UBRR

#define SENSOR_UBRR   (F_CPU/16/SENSOR_BAUD-1)

◆ UART0_BUFSIZE

#define UART0_BUFSIZE   40

Size of the UART0 Buffers.

◆ UART0_DE_MASK

#define UART0_DE_MASK   0x04

◆ UART0_PORT

#define UART0_PORT   PORTE

◆ UART1_BUFSIZE

#define UART1_BUFSIZE   200

UART1 really communicates, so a little more.

◆ UART1_CTS_MASK

#define UART1_CTS_MASK   0x20

◆ UART1_DE_MASK

#define UART1_DE_MASK   0x02

◆ UART1_PIN

#define UART1_PIN   PIND

◆ UART1_PORT

#define UART1_PORT   PORTD

◆ UART1_RTS_MASK

#define UART1_RTS_MASK   0x10

◆ USE_RTS

#define USE_RTS

Function Documentation

◆ AssertRTS()

static void AssertRTS ( void  )
inlinestatic

Asserts RTS to the Host Line, i.e. allows the Host to send Data.

References config, UART1_PORT, UART1_RTS_MASK, and confStruct_t::useRts.

Referenced by CmdCalibrate(), CmdDistance(), DoCflags(), EnterDouble(), InitUart(), and ReadIntelHex().

Here is the caller graph for this function:

◆ hprintf_P()

int hprintf_P ( const char *  fmt,
  ... 
)

◆ InitUart()

void InitUart ( void  )

Initialize USART Hardware and Pointers.

2 Stop-bits are used, USART0 connects to the sensor, uses 9-bit mode and parity, USART1 connects to the Host at 9600 baud, 8 bits and no parity.

References AssertRTS(), HOST_UBRR, and SENSOR_UBRR.

Referenced by Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putc0()

void putc0 ( char  c)

Sends a Command Char (bit9=1) over USART0.

Parameters
cThe Character

References cksum0, and put0().

Referenced by BootldRead(), BootldWrite(), UpdateSensorFirmware(), and VerifySensorFirmware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putchar_uart1()

int putchar_uart1 ( char  c,
FILE *  stream 
)

The Putchar-Routine for USART1 (Host-Interface)

Note
This routine blocks when the transmit buffer is full.
Parameters
cThe Character
streamA Pointer to the File (unused)
Returns
Always 0

References putc1().

Here is the call graph for this function:

◆ putd0()

void putd0 ( char  c)

Sends a Data Char (bit9=0) over USART0.

Parameters
cThe Character

References put0().

Referenced by BootldRead(), and BootldWrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReleaseRTS()

static void ReleaseRTS ( void  )
inlinestatic

Releases RTS to the Host Line, i.e. stops the Host from sending Data.

References config, UART1_PORT, UART1_RTS_MASK, and confStruct_t::useRts.

Referenced by ISR().

Here is the caller graph for this function:

◆ Tbub1IsEmpty()

bool Tbub1IsEmpty ( void  )

Tell if Transmit Buffer 1 is empty.

Returns
True if empty, False if not

References tbuf1_head, and tbuf1_tail.

Referenced by DoTflags().

Here is the caller graph for this function:

◆ Uart0DisableLineDriver()

static void Uart0DisableLineDriver ( void  )
inlinestatic

Disables the RS485 Line Driver on Uart0.

References UART0_DE_MASK, and UART0_PORT.

Referenced by FTest485GetConnects(), and ISR().

Here is the caller graph for this function:

◆ Uart0EnableLineDriver()

static void Uart0EnableLineDriver ( void  )
inlinestatic

Enables the RS485 Line Driver on Uart0.

References UART0_DE_MASK, and UART0_PORT.

Referenced by FTest485GetConnects(), and put0().

Here is the caller graph for this function:

◆ Uart1DisableLineDriver()

static void Uart1DisableLineDriver ( void  )
inlinestatic

Disables the RS485 Line Driver on Uart1.

References UART1_DE_MASK, and UART1_PORT.

Referenced by FTest485GetConnects(), and ISR().

Here is the caller graph for this function:

◆ Uart1EnableLineDriver()

static void Uart1EnableLineDriver ( void  )
inlinestatic

Enables the RS485 Line Driver on Uart1.

References UART1_DE_MASK, and UART1_PORT.

Referenced by FTest485GetConnects(), and ISR().

Here is the caller graph for this function:

◆ usart1FlushRx()

void usart1FlushRx ( void  )

References CFLAG_BTRECEIVED, CFLAG_BYTERECEIVED, CFLAG_CMDRECEIVED, cFlags, and rbuf1_ptr.

Referenced by CmdCalibrate().

Here is the caller graph for this function:

◆ UsartTimerCallback()

static void UsartTimerCallback ( void  )
inlinestatic

Timer Callback. Checks for CTS from the Host to resume Communication.

This function re-enables interrupts after CTS becomes true again and must be called periodically e.g. from timer interrupt.

References config, tbuf1_head, tbuf1_tail, UART1_CTS_MASK, UART1_PIN, and confStruct_t::useRts.

Referenced by ISR().

Here is the caller graph for this function:

Variable Documentation

◆ byteFromHost

volatile uint8_t byteFromHost

Contains the last byte received from the host.

Referenced by CmdCalibrate(), and ISR().

◆ charsInRbuf0

uint8_t charsInRbuf0

Referenced by DoCflags(), and ISR().

◆ cksum0

volatile char cksum0

Keeps track of the Checksum for USART0. It is automatically reset by command bytes.

Referenced by BootldRead(), BootldWrite(), put0(), and putc0().

◆ computedChecksum

uint8_t computedChecksum

Referenced by DoCflags(), and ISR().

◆ hostCommandsLost

volatile uint8_t hostCommandsLost

Counts the number of commands lost due to buffer overrun.

Referenced by CmdStat(), and ISR().

◆ rbuf0

volatile char rbuf0[]

Receive Buffer for UART0.

Referenced by DoCflags(), and ISR().

◆ tbuf1_head

volatile uint8_t tbuf1_head

◆ tbuf1_tail

volatile uint8_t tbuf1_tail

◆ uart0

FILE uart0

◆ uart1

FILE uart1

Referenced by hprintf_P().