void evaluate_ret_code(uint8_t ret_code)
{
if ((ret_code == SHA204_PARSE_ERROR)
|| (ret_code == SHA204_CMD_FAIL)
|| (ret_code == SHA204_RX_FAIL))
// We got some kind of response. Return codes of
// SHA204_PARSE_ERROR and SHA204_CMD_FAIL indicate
// a consistent response whereas SHA204_RX_FAIL
// just indicates that we received some bytes,
// possibly garbled. In all these cases we put
// the device to sleep.
(void) sha204p_sleep();
}
/** \brief This function serves as an example for
* the SHA204 MAC command.
*
* In an infinite loop, it issues the same command
* sequence using the Command Marshaling layer of
* the SHA204 library.
* \return exit status of application
*/
int main()
{
volatile unsigned int i;
volatile unsigned no_exit = 1;
unsigned int loop_counter = 0;
// declared as "volatile" for easier debugging
volatile uint8_t ret_code;
// Make the command buffer the size of the MAC command.
static uint8_t command[MAC_COUNT_LONG];
// Make the response buffer the size of a MAC response.
static uint8_t response[MAC_RSP_SIZE];
// Initialize the hardware interface.
sha204p_init();
while (no_exit)
{
// The following code sequence wakes up the device,
// issues a MAC command in mode 0
// using the Command Marshaling layer, and puts
// the device to sleep.
for (i = 0; i < sizeof(response); i++)
response[i] = 0;
// Wake up the device.
printf("\nLoop counter: %u\nWakeup\n", loop_counter++);
ret_code = sha204c_wakeup(&response[0]);
if (ret_code != SHA204_SUCCESS)
{
fputs("No response\n", stdout);
continue;
}
fputs("Response: ", stdout);
TRACE_DumpFrame(&response[0], response[SHA204_COUNT_IDX]);
// Put device to sleep.
ret_code = sha204p_sleep();
fputs("Sleep\n", stdout);
// Compare returned MAC with expected one.
ret_code = SHA204_SUCCESS;
for (i = 0; i < SHA204_RSP_SIZE_MAX; i++)
{
if (response[i] != mac_mode0_response_expected[i])
{
fputs("Response does not match expected response: ", stdout);
TRACE_DumpFrame((uint8_t *) &mac_mode0_response_expected[0], mac_mode0_response_expected[SHA204_COUNT_IDX]);
ret_code = SHA204_GEN_FAIL;
}
}
// Wait for some time so trace data are not just flying by.
for (i = 0; i < 4; i++)
delay_ms(250);
}
return (int) ret_code;
}