11#ifndef COMM_INTERFACE_H
12#define COMM_INTERFACE_H
17 #include <avr/interrupt.h>
118 static void stop() { CLR_BIT(TCCR1B, CS10); }
129 static void setMatchValue(
const uint16_t matchValue) { OCR1A = matchValue; }
141 static constexpr uint16_t
ETU = 372/1;
153 static void serviceRoutine() __asm__("__vector_13") __attribute__((__signal__, __used__, __externally_visible__));
205 static void serviceRoutine() __asm__("__vector_5") __attribute__((__signal__, __used__, __externally_visible__));
273 void sendBytes(
const byte_t *bytes,
const uint8_t len) {
for(uint8_t i=0; i<len; i++)
sendByte(bytes[i]); }
Class that provides functionality for the ATmega644's PinB6, such as an ISR.
Definition communication.h:165
static void setLevel(const bit_t bit)
Set logical level of the Pin.
static Communication * mComm
Communication object to access the class methods & attributes.
Definition communication.h:198
static void init(Communication *comm)
Initialize the IOPin class.
static void setDirection(const PinDir direction)
Set the direction of the Pin.
static void setInterrupt(const bool enabled)
Enable/disable interrupts for the Pin.
static void serviceRoutine() __asm__("__vector_5") __attribute__((__signal__
Interrupt Service Routine for the IOPin. An interrupt is triggered if the logic-level of the Pin chan...
Class that provides functionality for the ATmega644's on-board 16-bit timer, such as an ISR.
Definition communication.h:101
static void serviceRoutine() __asm__("__vector_13") __attribute__((__signal__
Interrupt Service Routine for the 16-bit timer. An interrupt is triggered if the timer hits the value...
static void init(Communication *comm)
Initialize the Timer class.
static Communication * mComm
Communication object to access the class methods & attributes.
Definition communication.h:145
static constexpr uint16_t TIMER_BOTTOM
Timer bottom value.
Definition communication.h:146
static void stop()
Stop the 16-bit timer by setting no clock source.
Definition communication.h:118
static constexpr uint16_t ETU
The counter value which the timer should match.
Definition communication.h:141
static void setMatchValue(const uint16_t matchValue)
Change the value of register OCR1A.
Definition communication.h:129
static void start()
Start the timer, by setting the counter value to TIMER_BOTTOM & setting the clock source to CS10.
Definition communication.h:123
Class that implements the communication protocol between the SmartCard & the Terminal.
Definition communication.h:46
static constexpr bit_t START_BIT
The start bit of a transfer.
Definition communication.h:212
void sendDecryptedData(const byte_t *data)
Send the decrypted data to the Terminal.
volatile bool mParityError
Whether a parity error occurred while receiving a byte.
Definition communication.h:234
byte_t receiveByte()
Receive a single byte from the Terminal.
void sendBytes(const byte_t *bytes, const uint8_t len)
Send an array of bytes byte by byte.
Definition communication.h:273
static bit_t sampleBit()
Sample the IOPin 3-times for a more reliable result.
volatile byte_t mInputByte
The currently received input byte.
Definition communication.h:230
volatile bit_t mErrorBit
Error bit that is set to 0/1 during the stop bit indicating failure/success.
Definition communication.h:233
Logger mLog
Logger.
Definition communication.h:219
Communication()
Construct a new Communication object.
volatile PinDir mDirection
Current direction of the IOPin.
Definition communication.h:223
volatile bool mCheckErrors
Whether to check for errors after sending a byte.
Definition communication.h:232
volatile bool mByteReceived
Whether a byte was received successfully.
Definition communication.h:228
void sendATR()
Send the Answer-To-Reset sequence to the Terminal.
Definition communication.h:63
volatile bool mBitSent
Whether the last bit of a transmission was sent.
Definition communication.h:225
void sendBit(const bit_t bit)
Send a single bit to the Terminal.
volatile bit_t mOutputBit
The next bit to output.
Definition communication.h:226
void receiveProtocolHeader(const byte_t *header)
Receive a protocol header, which contains 5 bytes.
volatile uint8_t mInputBitCounter
Number of input bits in the current transfer.
Definition communication.h:229
static constexpr bit_t STOP_BIT
The stop bit of a transfer.
Definition communication.h:213
void receiveDataToDecrypt(byte_t *data)
Receive data to decrypt from the Terminal.
static bit_t getParity(byte_t byte)
Calculate the parity of a byte.
void sendByte(const byte_t byte)
Send a single byte to the Terminal.
Logger class that outputs logs over USART.
Definition logger.h:27
static constexpr uint8_t ATR_LENGTH
Length of the Answer-to-reset sequence.
Definition protocol.h:41
static constexpr byte_t ATR_SEQ[]
Answer-to-reset sequence, send at the start.
Definition protocol.h:40