scd_hal.c - SCD hardware abstraction layer source file for AT90USB1287 More...
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include "scd_hal.h"
#include "scd_io.h"
#include "scd_values.h"
#include "utils.h"
Go to the source code of this file.
Defines | |
#define | DEBUG 1 |
Functions | |
void | EnableTerminalResetInterrupt () |
Enable the terminal reset interrupt. | |
void | DisableTerminalResetInterrupt () |
Disable the terminal reset interrupt. | |
uint8_t | GetTerminalIOLine () |
Returns the status of the terminal I/O line. | |
uint8_t | GetTerminalResetLine () |
Retrieves the state of the reset line from the terminal. | |
void | EnableWDT (uint16_t ms) |
Enables the Watch Dog Timer. | |
void | DisableWDT () |
Disables the Watch Dog Timer. | |
void | ResetWDT () |
Resets the Watch Dog Timer. | |
uint8_t | WaitTerminalResetIOLow (uint32_t max_wait) |
Loops until the IO or reset line from the terminal become low. | |
uint16_t | GetTerminalFreq () |
Returns the frequency of the terminal clock in khz, zero if there is no clock. | |
uint8_t | ReadTimerT2 () |
Reads the value of the timer T2. | |
void | StartTimerT2 () |
Starts the T2 timer. | |
void | StopTimerT2 () |
Stops the T2 timer. | |
uint16_t | ReadCounterTerminal () |
Reads the value of the terminal counter. | |
void | StartCounterTerminal () |
Starts the counter for the external clock given by the terminal. | |
void | StopCounterTerminal () |
Stops the terminal clock counter. | |
void | PauseCounterTerminal () |
Pauses the terminal clock counter. | |
void | LoopTerminalETU (uint8_t nEtus) |
Waits (loops) for a number of nEtus based on the Terminal clock. | |
void | SendByteTerminalNoParity (uint8_t byte, uint8_t inverse_convention) |
Sends a byte to the terminal without parity check. | |
uint8_t | SendByteTerminalParity (uint8_t byte, uint8_t inverse_convention) |
Sends a byte to the terminal with parity check. | |
uint8_t | WaitForTerminalData (uint16_t max_cycles) |
uint8_t | GetByteTerminalNoParity (uint8_t inverse_convention, uint8_t *r_byte, uint32_t max_wait) |
Receives a byte from the terminal without parity check. | |
uint8_t | GetByteTerminalParity (uint8_t inverse_convention, uint8_t *r_byte, uint32_t max_wait) |
Receives a byte from the terminal with parity check. | |
uint8_t | IsICCInserted () |
Returns non-zero if ICC is inserted, zero otherwise. | |
uint8_t | IsICCPowered () |
Returns non-zero if ICC is powered up. | |
uint8_t | PowerUpICC () |
void | PowerDownICC () |
Powers down the ICC. | |
void | LoopICCETU (uint8_t nEtus) |
Waits (loops) for a number of nEtus based on the ICC clock. | |
uint8_t | WaitForICCData (uint32_t max_cycles) |
Loops for max_cycles or until the I/O line from ICC becomes low. | |
uint8_t | GetByteICCNoParity (uint8_t inverse_convention, uint8_t *r_byte) |
Receives a byte from the ICC without parity checking. | |
uint8_t | GetByteICCParity (uint8_t inverse_convention, uint8_t *r_byte) |
Receives a byte from the ICC with parity checking. | |
void | SendByteICCNoParity (uint8_t byte, uint8_t inverse_convention) |
Sends a byte to the ICC without parity check. | |
uint8_t | SendByteICCParity (uint8_t byte, uint8_t inverse_convention) |
Sends a byte to the ICC with parity check. | |
void | SetICCResetLine (uint8_t high) |
Sets the reset line of the ICC to the desired value. | |
uint8_t | ActivateICC (uint8_t warm) |
Starts the activation sequence for the ICC. | |
void | DeactivateICC () |
Starts the deactivation sequence for the ICC. | |
void | EnableICCInsertInterrupt () |
Enable the ICC insert interrupt. | |
void | DisableICCInsertInterrupt () |
Disable the ICC insert interrupt. | |
Variables | |
volatile uint32_t | syncCounter |
scd_hal.c - SCD hardware abstraction layer source file for AT90USB1287
This file implements the hardware abstraction layer functions
This functions are implemented specifically for each microcontroller but the function names should be the same for any microcontroller. Thus the definition halSCD.h should be the same, while only the implementation should differ.
Copyright (C) 2012 Omar Choudary (omar.choudary@cl.cam.ac.uk)
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file scd_hal.c.
uint8_t ActivateICC | ( | uint8_t | warm | ) |
void DeactivateICC | ( | ) |
void DisableICCInsertInterrupt | ( | ) |
void DisableTerminalResetInterrupt | ( | ) |
void DisableWDT | ( | ) |
void EnableICCInsertInterrupt | ( | ) |
void EnableTerminalResetInterrupt | ( | ) |
Enable the terminal reset interrupt.
Enable the terminal reset interrupt. This interrupt should fire when the terminal reset line goes low (0).
Enable INT0 on falling edge. This is the recommended procedure, as in the data sheet. First disable the interrupt, then change the mode, then clear the interrupt flag and finally enable the interrupt
void EnableWDT | ( | uint16_t | ms | ) |
Enables the Watch Dog Timer.
Enable the Watch Dog Timer. This function will also enable the WDT interrupt.
ms | the number of miliseconds to wait. This is an estimate since each hardware platform might provide just a limited set of possible values. For the AT90USB1287 (this uC) the possible values are 15ms, 30ms, 60ms, 120ms, 250 ms, 500 ms, 1s, 2s, 4s and 8s. Therefore this function simply approximates the closest larger value. For example sending a value of 14 will actually use 15ms, sending 25 will use 30ms, sending 100 will use 120ms and sending 1000 will use 1s. |
uint8_t GetByteICCNoParity | ( | uint8_t | inverse_convention, | |
uint8_t * | r_byte | |||
) |
Receives a byte from the ICC without parity checking.
Receives a byte from the ICC without parity checking
inverse_convention | different than 0 if inverse convention is to be used * | |
r_byte | contains the byte read on return |
ICC clock counter must be already enabled
uint8_t GetByteICCParity | ( | uint8_t | inverse_convention, | |
uint8_t * | r_byte | |||
) |
Receives a byte from the ICC with parity checking.
Receives a byte from the ICC with parity checking
inverse_convention | different than 0 if inverse convention is to be used * | |
r_byte | contains the byte read on return |
ICC clock counter must be already enabled
uint8_t GetByteTerminalNoParity | ( | uint8_t | inverse_convention, | |
uint8_t * | r_byte, | |||
uint32_t | max_wait | |||
) |
Receives a byte from the terminal without parity check.
Receives a byte from the terminal without parity checking. This function also checks if the terminal reset line is low.
inverse_convention | different than 0 if inverse convention is to be used | |
r_byte | contains the byte read on return | |
max_wait | the maximum number of cycles to wait for the reset or the IO line to become low. Give 0 to wait indefinitely. |
Terminal clock counter must be already enabled
uint8_t GetByteTerminalParity | ( | uint8_t | inverse_convention, | |
uint8_t * | r_byte, | |||
uint32_t | max_wait | |||
) |
Receives a byte from the terminal with parity check.
Receives a byte from the terminal with parity checking
inverse_convention | different than 0 if inverse convention is to be used | |
r_byte | contains the byte read on return | |
max_wait | the maximum number of cycles to wait for the reset or the IO line to become low. Give 0 to wait indefinitely. |
Terminal clock counter must be enabled before calling this function
uint16_t GetTerminalFreq | ( | ) |
uint8_t GetTerminalIOLine | ( | ) |
uint8_t GetTerminalResetLine | ( | ) |
uint8_t IsICCInserted | ( | ) |
uint8_t IsICCPowered | ( | ) |
void LoopICCETU | ( | uint8_t | nEtus | ) |
void LoopTerminalETU | ( | uint8_t | nEtus | ) |
void PauseCounterTerminal | ( | ) |
void PowerDownICC | ( | ) |
uint8_t PowerUpICC | ( | ) |
uint16_t ReadCounterTerminal | ( | ) |
Reads the value of the terminal counter.
This method increments the synchronization counter. The sync counter can be used as a synchronization mechanism. It is a 32-bit value, which should be updated regularly, e.g. by the timer T2.
uint8_t ReadTimerT2 | ( | ) |
Reads the value of the timer T2.
The timer T2 can be used for event management. It is an 8-bit counter.
void ResetWDT | ( | ) |
void SendByteICCNoParity | ( | uint8_t | byte, | |
uint8_t | inverse_convention | |||
) |
Sends a byte to the ICC without parity check.
Sends a byte to the ICC without parity error retransmission
byte | byte to be sent | |
inverse_convention | different than 0 if inverse convention is to be used |
The ICC clock counter must be started before calling this function
uint8_t SendByteICCParity | ( | uint8_t | byte, | |
uint8_t | inverse_convention | |||
) |
Sends a byte to the ICC with parity check.
Sends a byte to the ICC with parity error retransmission
byte | byte to be sent | |
inverse_convention | different than 0 if inverse convention is to be used |
As in the No Parity version, this function relies on counter started
void SendByteTerminalNoParity | ( | uint8_t | byte, | |
uint8_t | inverse_convention | |||
) |
Sends a byte to the terminal without parity check.
Sends a byte to the terminal without parity error retransmission
byte | byte to be sent | |
inverse_convention | different than 0 if inverse convention is to be used |
The terminal clock counter must be started before calling this function
uint8_t SendByteTerminalParity | ( | uint8_t | byte, | |
uint8_t | inverse_convention | |||
) |
Sends a byte to the terminal with parity check.
Sends a byte to the terminal with parity error retransmission
byte | byte to be sent | |
inverse_convention | different than 0 if inverse convention is to be used |
As in the NoParity version, this function relies on counter started
void SetICCResetLine | ( | uint8_t | high | ) |
void StartCounterTerminal | ( | ) |
Starts the counter for the external clock given by the terminal.
Starts the counter for the external clock given by the terminal
From hardware tests it seems that it is better to just leave the counter running all the time and just modify the register values as needed
void StartTimerT2 | ( | ) |
Starts the T2 timer.
Starts the timer T2 using the internal clock CLK_IO. The current setup is for an interrupt frequency f_t2_int = 976.5625 Hz. That means that each value of the udpated counter represents 1.024 ms.
void StopCounterTerminal | ( | ) |
void StopTimerT2 | ( | ) |
uint8_t WaitForICCData | ( | uint32_t | max_cycles | ) |
Loops for max_cycles or until the I/O line from ICC becomes low.
Loops until the I/O line from ICC becomes low
max_cycles | the maximum number of clocks to wait for the I/O line to become low. Loops forever if this is 0 |
uint8_t WaitForTerminalData | ( | uint16_t | max_cycles | ) |
uint8_t WaitTerminalResetIOLow | ( | uint32_t | max_wait | ) |
Loops until the IO or reset line from the terminal become low.
Loops until the IO or reset line from the terminal become low.
max_wait | the maximum number of cycles to wait for the reset or the IO line to become low. Give 0 to wait indefinitely. |
volatile uint32_t syncCounter |