ATmega644 Smart-Card
Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
Logger Class Reference

Logger class that outputs logs over USART. More...

#include <logger.h>

Collaboration diagram for Logger:
Collaboration graph

Public Member Functions

 Logger ()=default
 Construct a new Logger object.
 
void init ()
 Initialize USART. More...
 
void operator() (const char *str) const
 Functor to log a string. More...
 
void operator() (const uint8_t *arr, const uint8_t len) const
 Functor to log an array of hex-values. More...
 

Private Member Functions

void sendChar (const char c) const
 Transmit a single character over USART. More...
 
void sendStr (const char *str) const
 Transmit a string over USART. More...
 

Static Private Attributes

static constexpr uint16_t UBRR0_VALUE = F_CPU/(8*BAUD)-1
 UBRR0 value for initializing USART. More...
 

Detailed Description

Logger class that outputs logs over USART.

Authors
Philipp Karg (phili.nosp@m.pp.k.nosp@m.arg@t.nosp@m.um.d.nosp@m.e)
Date
02.06.2022

Member Function Documentation

◆ init()

void Logger::init ( )

Initialize USART.

  1. Enable double speed.
  2. Set baud-rate in both UBRR registers with UBRR0_VALUE.
  3. Enable the transmitter.
  4. Set the data frame (8 data-bits, 1 stop-bit).

◆ operator()() [1/2]

void Logger::operator() ( const char *  str) const
inline

Functor to log a string.

Parameters
[in]str(const char*): String to log.

◆ operator()() [2/2]

void Logger::operator() ( const uint8_t *  arr,
const uint8_t  len 
) const

Functor to log an array of hex-values.

Parameters
[in]arr(const uint8_t*): Array of hex values to log.
[in]len(const uint8_t): Length of the array.

◆ sendChar()

void Logger::sendChar ( const char  c) const
private

Transmit a single character over USART.

  1. Wait for an empty transmit buffer.
  2. Write c into the buffer.
Parameters
[in]c(const char): Character to send.

◆ sendStr()

void Logger::sendStr ( const char *  str) const
private

Transmit a string over USART.

Continuously call sendChar() and send each character of str.

Parameters
[in]str(const char*): String to send.

Member Data Documentation

◆ UBRR0_VALUE

constexpr uint16_t Logger::UBRR0_VALUE = F_CPU/(8*BAUD)-1
staticconstexprprivate

UBRR0 value for initializing USART.

This value was found through trial and error. According to the data-sheet, this value should be calculated as the following: UBRR0 = f_clk/(16*BAUD) - 1 However this did not work with the provided clock-frequency of 3276800 in the manual.


The documentation for this class was generated from the following file: