Electronic Load 1.0 Programmable Constant Current Sink

Functions | Variables
uart.c File Reference

Routines for serial Communication. More...

Include dependency graph for uart.c:

## Functions
void | CopyRbuf0ToCmdline (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_UDRE_vect)
| USART0 (Host-Interface) Data Register empty Interrupt. More...
| ISR (USART0_RX_vect)
| USART0 Receive-Interrupt (Host-Interface) More...
int | putc0 (char c)
| Puts a char to USART0 (Host-Interface) More...
int | putchar_uart0 (char c, FILE *stream)
| The Putchar-Routine for USART0 (Host-Interface) More...
void | Usart0FlushRx (void)

## Variables
volatile uint8_t | byteFromHost
| Contains the last byte received from the host. More...
volatile uint8_t | cFlags
volatile char | cmdline [CMDLINE_MAX+1]
| Ready to hold CMDLINE_MAX chars plus terminating 0. More...
volatile uint8_t | hostCommandsLost
| Counts the number of commands lost due to buffer overrun. More...
static volatile char | rbuf0 [CMDLINE_MAX+1]
| Receive Buffer for UART0. More...
static volatile uint8_t | rbuf0_ptr
static volatile char | tbuf0 [UART0_TXBUFSIZE]
| Transmit Buffer for UART0. More...
volatile uint8_t | tbuf0_head
volatile uint8_t | tbuf0_tail
FILE | uart0 =FDEV_SETUP_STREAM(putchar_uart0,NULL,_FDEV_SETUP_WRITE)

## Detailed Description

Routines for serial Communication.

Copyright
  Copyright (C) 2009 Robert Loos http://www.loosweb.de

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

## ◆ InitUart()

void InitUart | ( | void |  | ) |

Initialize USART Hardware and Pointers.

2 Stop-bits are used, USART0 connects to the Host at 9600 baud, 8 bits and no parity.

Here is the call graph for this function:

## ◆ putc0()

int putc0 | ( | char | c | ) |

Puts a char to USART0 (Host-Interface)

Note
  This routine blocks when the transmit buffer is full.

Parameters

  c | The Character

Returns
  Always 0

Here is the caller graph for this function:

## ◆ putchar_uart0()

int putchar_uart0 | ( | char | c,
|  | FILE * | stream
| ) |  |

The Putchar-Routine for USART0 (Host-Interface)

Note
  This routine blocks when the transmit buffer is full.

Parameters

  c | The Character
  stream | A Pointer to the File (unused)

Returns
  Always 0

Here is the call graph for this function:

## ◆ ISR() [1/2]

ISR | ( | USART0_UDRE_vect |  | ) |

USART0 (Host-Interface) Data Register empty Interrupt.

## ◆ CopyRbuf0ToCmdline()

void CopyRbuf0ToCmdline | ( | void |  | ) |

Here is the caller graph for this function:

## ◆ ISR() [2/2]

ISR | ( | USART0_RX_vect |  | ) |

USART0 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.

Here is the call graph for this function:

## ◆ Usart0FlushRx()

void Usart0FlushRx | ( | void |  | ) |

## ◆ hprintf_P()

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

printf_P for Communication with the Host

Parameters

  fmt | Format String
  ... | Additional Parameters

Returns
  The return value of the underlying vfprintf_P

## Variable Documentation

## ◆ cFlags

volatile uint8_t cFlags

## ◆ tbuf0

volatile char tbuf0[UART0_TXBUFSIZE]
| static

Transmit Buffer for UART0.

## ◆ rbuf0

volatile char rbuf0[CMDLINE_MAX+1]
| static

Receive Buffer for UART0.

## ◆ tbuf0_tail

volatile uint8_t tbuf0_tail

## ◆ tbuf0_head

volatile uint8_t tbuf0_head

## ◆ rbuf0_ptr

volatile uint8_t rbuf0_ptr
| static

## ◆ byteFromHost

volatile uint8_t byteFromHost

Contains the last byte received from the host.

## ◆ hostCommandsLost

volatile uint8_t hostCommandsLost

Counts the number of commands lost due to buffer overrun.

## ◆ cmdline

volatile char cmdline[CMDLINE_MAX+1]

Ready to hold CMDLINE_MAX chars plus terminating 0.

## ◆ uart0

FILE uart0 =FDEV_SETUP_STREAM(putchar_uart0,NULL,_FDEV_SETUP_WRITE)