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__));
182 static void setLevel(
const bit_t bit);
188 static void setDirection(
const PinDir direction);
194 static void setInterrupt(
const bool enabled);
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]); }
309 #endif // COMM_INTERFACE_H
byte_t receiveByte()
Receive a single byte from the Terminal.
static constexpr bit_t STOP_BIT
The stop bit of a transfer.
Definition: communication.h:213
volatile bool mBitSent
Whether the last bit of a transmission was sent.
Definition: communication.h:225
Communication()
Construct a new Communication object.
volatile bool mCheckErrors
Whether to check for errors after sending a byte.
Definition: communication.h:232
volatile bool mParityError
Whether a parity error occurred while receiving a byte.
Definition: communication.h:234
volatile bit_t mErrorBit
Error bit that is set to 0/1 during the stop bit indicating failure/success.
Definition: communication.h:233
void sendDecryptedData(const byte_t *data)
Send the decrypted data to the Terminal.
volatile bit_t mOutputBit
The next bit to output.
Definition: communication.h:226
static void setMatchValue(const uint16_t matchValue)
Change the value of register OCR1A.
Definition: communication.h:129
static constexpr uint16_t ETU
The counter value which the timer should match.
Definition: communication.h:141
static constexpr uint8_t ATR_LENGTH
Length of the Answer-to-reset sequence.
Definition: protocol.h:41
Class that implements the communication protocol between the SmartCard & the Terminal.
Definition: communication.h:45
static bit_t getParity(byte_t byte)
Calculate the parity of a byte.
static void start()
Start the timer, by setting the counter value to TIMER_BOTTOM & setting the clock source to CS10.
Definition: communication.h:123
static constexpr uint16_t TIMER_BOTTOM
Timer bottom value.
Definition: communication.h:146
static Communication * mComm
Communication object to access the class methods & attributes.
Definition: communication.h:145
Class that provides functionality for the ATmega644's on-board 16-bit timer, such as an ISR.
Definition: communication.h:100
void sendBytes(const byte_t *bytes, const uint8_t len)
Send an array of bytes byte by byte.
Definition: communication.h:273
static void init(Communication *comm)
Initialize the Timer class.
static Communication * mComm
Communication object to access the class methods & attributes.
Definition: communication.h:198
volatile bool mByteReceived
Whether a byte was received successfully.
Definition: communication.h:228
volatile PinDir mDirection
Current direction of the IOPin.
Definition: communication.h:223
Logger mLog
Logger.
Definition: communication.h:219
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...
Class that provides functionality for the ATmega644's PinB6, such as an ISR.
Definition: communication.h:164
void sendBit(const bit_t bit)
Send a single bit to the Terminal.
void sendByte(const byte_t byte)
Send a single byte to the Terminal.
Logger class that outputs logs over USART.
Definition: logger.h:26
static constexpr byte_t ATR_SEQ[]
Answer-to-reset sequence, send at the start.
Definition: protocol.h:40
static void stop()
Stop the 16-bit timer by setting no clock source.
Definition: communication.h:118
void receiveDataToDecrypt(byte_t *data)
Receive data to decrypt from the Terminal.
volatile byte_t mInputByte
The currently received input byte.
Definition: communication.h:230
volatile uint8_t mInputBitCounter
Number of input bits in the current transfer.
Definition: communication.h:229
void receiveProtocolHeader(const byte_t *header)
Receive a protocol header, which contains 5 bytes.
static constexpr bit_t START_BIT
The start bit of a transfer.
Definition: communication.h:212
static bit_t sampleBit()
Sample the IOPin 3-times for a more reliable result.
void sendATR()
Send the Answer-To-Reset sequence to the Terminal.
Definition: communication.h:63