Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SHA204 Service - hardware dependent communication functions

Functions

uint8_t sha204p_idle (void)
 This I2C function puts the SHA204 device into idle state. More...
 
void sha204p_init (void)
 This function initializes peripherals (timer and communication). More...
 
uint8_t sha204p_receive_response (uint8_t size, uint8_t *response)
 This I2C function receives a response from the SHA204 device. More...
 
uint8_t sha204p_reset_io (void)
 This I2C function resets the I/O buffer of the SHA204 device. More...
 
uint8_t sha204p_resync (uint8_t size, uint8_t *response)
 This I2C function resynchronizes communication. More...
 
uint8_t sha204p_send_command (uint8_t count, uint8_t *command)
 This I2C function sends a command to the device. More...
 
void sha204p_set_device_id (uint8_t id)
 This I2C function sets the I2C address. More...
 
uint8_t sha204p_sleep (void)
 This I2C function puts the SHA204 device into low-power state. More...
 
uint8_t sha204p_wakeup (void)
 This I2C function generates a Wake-up pulse and delays. More...
 

uint8_t sha204p_idle ( void  )

This I2C function puts the SHA204 device into idle state.

Returns
status of the operation

References SHA204_I2C_PACKET_FUNCTION_IDLE, and sha204p_send().

void sha204p_init ( void  )

This function initializes peripherals (timer and communication).

References cpu_irq_enable, and sha204h_timer_init().

Referenced by security_board_init().

uint8_t sha204p_receive_response ( uint8_t  size,
uint8_t *  response 
)

This I2C function receives a response from the SHA204 device.

Parameters
[in]sizesize of receive buffer
[out]responsepointer to receive buffer
Returns
status of the operation

References twi_package_t::buffer, twi_package_t::chip, device_address, ERR_TIMEOUT, twi_package_t::length, SHA204_BUFFER_POS_COUNT, SHA204_COMM_FAIL, SHA204_INVALID_SIZE, SHA204_RSP_SIZE_MAX, SHA204_RSP_SIZE_MIN, SHA204_RX_NO_RESPONSE, SHA204_SUCCESS, SHA204_TIMEOUT, STATUS_OK, and twi_master_read().

Referenced by sha204c_send_and_receive(), and sha204c_wakeup().

uint8_t sha204p_reset_io ( void  )

This I2C function resets the I/O buffer of the SHA204 device.

Returns
status of the operation

References SHA204_I2C_PACKET_FUNCTION_RESET, and sha204p_send().

Referenced by sha204p_resync().

uint8_t sha204p_resync ( uint8_t  size,
uint8_t *  response 
)

This I2C function resynchronizes communication.

Parameters are not used for I2C.
Re-synchronizing communication is done in a maximum of three steps listed below. This function implements the first step. Since steps 2 and 3 (sending a Wake-up token and reading the response) are the same for I2C and SWI, they are implemented in the communication layer (sha204c_resync). See the excerpt from the SHA204 data sheet below.

  1. To ensure an IO channel reset, the system should send the standard I2C software reset sequence, as follows:
    • a Start condition
    • nine cycles of SCL, with SDA held high
    • another Start condition
    • a Stop condition
    It should then be possible to send a read sequence and if synchronization has completed properly the ATSHA204 will acknowledge the device address. The chip may return data or may leave the bus floating (which the system will interpret as a data value of 0xFF) during the data periods.
    If the chip does acknowledge the device address, the system should reset the internal address counter to force the ATSHA204 to ignore any partial input command that may have been sent. This can be accomplished by sending a write sequence to word address 0x00 (Reset), followed by a Stop condition.
  2. If the chip does NOT respond to the device address with an ACK, then it may be asleep. In this case, the system should send a complete Wake token and wait t_whi after the rising edge. The system may then send another read sequence and if synchronization has completed the chip will acknowledge the device address.
  3. If the chip still does not respond to the device address with an acknowledge, then it may be busy executing a command. The system should wait the longest TEXEC and then send the read sequence, which will be acknowledged by the chip.
Parameters
[in]sizesize of response buffer
[out]responsepointer to response buffer
Returns
status of the operation

References twi_package_t::chip, sha204p_reset_io(), and twi_master_read().

Referenced by sha204c_resync().

uint8_t sha204p_send_command ( uint8_t  count,
uint8_t *  command 
)

This I2C function sends a command to the device.

Parameters
[in]countnumber of bytes to send
[in]commandpointer to command buffer
Returns
status of the operation

References SHA204_I2C_PACKET_FUNCTION_NORMAL, and sha204p_send().

Referenced by sha204c_send_and_receive(), and test_sha204_wakeup().

void sha204p_set_device_id ( uint8_t  id)

This I2C function sets the I2C address.

   Communication functions will use this address.
Parameters
[in]idI2C address

References device_address.

Referenced by main(), sha204_sleep_all(), and test_all_devices().

uint8_t sha204p_sleep ( void  )

This I2C function puts the SHA204 device into low-power state.

Returns
status of the operation

References SHA204_I2C_PACKET_FUNCTION_SLEEP, and sha204p_send().

Referenced by main(), sha204_sleep_all(), sha204c_resync(), test_all_devices(), and test_sha204_wakeup().