LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Functions | Variables
uart.c File Reference

Routines for serial Communication. More...

Include dependency graph for uart.c:

Functions

void CopyRbuf1ToCmdline (void)
 
int hprintf_P (const char *fmt,...)
 printf_P for Communication with the Host More...
 
void InitUart ()
 Initialize USART Hardware and Pointers. More...
 
 ISR (USART0_TX_vect)
 USART0 Transmit Complete Interrupt. More...
 
 ISR (USART1_UDRE_vect)
 USART1 (Host-Interface) Data Register empty Interrupt. More...
 
 ISR (USART1_TX_vect)
 USART1 Transmit Complete Interrupt. More...
 
 ISR (USART0_RX_vect)
 Receive Interrupt for USART0 (sensor) More...
 
 ISR (USART1_RX_vect)
 USART1 Receive-Interrupt (Host-Interface) More...
 
void put0 (char c)
 Sends a Character to USART0. More...
 
void putc0 (char c)
 Sends a Command Char (bit9=1) over USART0. More...
 
int putc1 (char c)
 Puts a char to USART1 (Host-Interface) More...
 
int putchar_uart1 (char c, FILE *stream)
 The Putchar-Routine for USART1 (Host-Interface) More...
 
void putd0 (char c)
 Sends a Data Char (bit9=0) over USART0. More...
 
bool Tbub1IsEmpty (void)
 Tell if Transmit Buffer 1 is empty. More...
 
void usart1FlushRx (void)
 

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 [UART0_BUFSIZE]
 Receive Buffer for UART0. More...
 
static volatile uint8_t rbuf0_cksum
 
static volatile uint8_t rbuf0_ptr
 
static volatile char rbuf1 [UART1_BUFSIZE]
 Receive Buffer for UART1. More...
 
static volatile uint8_t rbuf1_ptr
 
static volatile uint8_t tbuf0_head
 
static volatile uint8_t tbuf0_tail
 
static volatile char tbuf1 [UART1_BUFSIZE]
 Transmit Buffer for UART1. More...
 
volatile uint8_t tbuf1_head
 
volatile uint8_t tbuf1_tail
 
FILE uart1 =FDEV_SETUP_STREAM(putchar_uart1,NULL,_FDEV_SETUP_WRITE)
 

Detailed Description

Routines for serial Communication.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Function Documentation

◆ CopyRbuf1ToCmdline()

void CopyRbuf1ToCmdline ( void  )

References cmdline, rbuf1, and rbuf1_ptr.

Referenced by ISR().

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:

◆ ISR() [1/5]

ISR ( USART0_TX_vect  )

USART0 Transmit Complete Interrupt.

Is only used to disable the RS485 line drivers.

References Uart0DisableLineDriver().

Here is the call graph for this function:

◆ ISR() [2/5]

ISR ( USART1_UDRE_vect  )

USART1 (Host-Interface) Data Register empty Interrupt.

References config, tbuf1, tbuf1_head, tbuf1_tail, UART1_BUFSIZE, UART1_CTS_MASK, UART1_PIN, Uart1EnableLineDriver(), and confStruct_t::useRts.

Here is the call graph for this function:

◆ ISR() [3/5]

ISR ( USART1_TX_vect  )

USART1 Transmit Complete Interrupt.

Transmission has been completed so the line driver is switched off.

References Uart1DisableLineDriver().

Here is the call graph for this function:

◆ ISR() [4/5]

ISR ( USART0_RX_vect  )

Receive Interrupt for USART0 (sensor)

USART0 receives not in buffered mode like the host communication does. USART0 resets the buffer pointer upon reception of a 9-bit char other than 1+0x00 and directly evaluates the buffer content on reception of the 9-bit char 1+0x00

References blFlags, BOOTLDDATA, BOOTLDERROR, BOOTLDHELLO, BOOTLDOK, bootLdPage, BOOTLDPROTECTED, CFLAG_CHECKSUMERROR, CFLAG_PARITYERROR, CFLAG_TEMPRECEIVED, CFLAG_TIMERECEIVED, cFlags, charsInRbuf0, computedChecksum, deadTime, displayValues, pulseTimeInt, pulseTimeMult, rbuf0, rbuf0_cksum, rbuf0_ptr, tempRaw, displayValues_t::tempSemi, and UART0_BUFSIZE.

◆ ISR() [5/5]

ISR ( USART1_RX_vect  )

USART1 Receive-Interrupt (Host-Interface)

This routine collects incoming characters until a complete host- or Bluetooth-command has been received.

Note
For Bluetooth, we ignore the high-byte of the length field. We cannot handle Telegrams bigger than the cmdline for now and the do also not appear until now.

References byteFromHost, CFLAG_BTRECEIVED, CFLAG_BYTERECEIVED, CFLAG_CMDRECEIVED, cFlags, config, CopyRbuf1ToCmdline(), hostCommandsLost, rbuf1, rbuf1_ptr, ReleaseRTS(), UART1_BUFSIZE, and confStruct_t::useRts.

Here is the call graph for this function:

◆ put0()

void put0 ( char  c)

Sends a Character to USART0.

USART0 does not have a separate transmit buffer and does not use interrupts.

Parameters
cThe Character
Note
this function blocks if transmit buffer register is full.

References cksum0, and Uart0EnableLineDriver().

Referenced by putc0(), and putd0().

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:

◆ putc1()

int putc1 ( char  c)

Puts a char to USART1 (Host-Interface)

Note
This routine blocks when the transmit buffer is full.
Parameters
cThe Character
Returns
Always 0

References tbuf1, tbuf1_head, tbuf1_tail, and UART1_BUFSIZE.

Referenced by putchar_uart1().

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:

◆ 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:

◆ 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:

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[UART0_BUFSIZE]

Receive Buffer for UART0.

Referenced by DoCflags(), and ISR().

◆ rbuf0_cksum

volatile uint8_t rbuf0_cksum
static

Referenced by ISR().

◆ rbuf0_ptr

volatile uint8_t rbuf0_ptr
static

Referenced by ISR().

◆ rbuf1

volatile char rbuf1[UART1_BUFSIZE]
static

Receive Buffer for UART1.

Referenced by CopyRbuf1ToCmdline(), and ISR().

◆ rbuf1_ptr

volatile uint8_t rbuf1_ptr
static

◆ tbuf0_head

volatile uint8_t tbuf0_head
static

◆ tbuf0_tail

volatile uint8_t tbuf0_tail
static

◆ tbuf1

volatile char tbuf1[UART1_BUFSIZE]
static

Transmit Buffer for UART1.

Referenced by ISR(), and putc1().

◆ tbuf1_head

volatile uint8_t tbuf1_head

◆ tbuf1_tail

volatile uint8_t tbuf1_tail

◆ uart1

FILE uart1 =FDEV_SETUP_STREAM(putchar_uart1,NULL,_FDEV_SETUP_WRITE)

Referenced by hprintf_P().