1 /*
2  * \file
3  *
4  * \brief ATSHA204 header file for the communication layer for the device
5  *
6  *
7  * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
8  *
9  * \asf_license_start
10  *
11  * \page License
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  *    this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright notice,
20  *    this list of conditions and the following disclaimer in the documentation
21  *    and/or other materials provided with the distribution.
22  *
23  * 3. The name of Atmel may not be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * 4. This software may only be redistributed and used in connection with an
27  *    Atmel microcontroller product.
28  *
29  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
30  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
32  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
33  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  *
41  * \asf_license_stop
42  *
43  */
44 /*
45  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
46  */
47 
48 #ifndef SHA204_COMM_H
49 #   define SHA204_COMM_H
50 
51 #include <compiler.h>               //!< compiler dependent definitions
52 
53 #include "sha204_physical.h"        //!< declarations that are common to all interface implementations
54 
55 //! maximum command delay
56 #define SHA204_COMMAND_EXEC_MAX      (69)
57 
58 //! minimum number of bytes in command (from count byte to second CRC byte)
59 #define SHA204_CMD_SIZE_MIN          ((uint8_t)  7)
60 
61 //! maximum size of command packet (CheckMac)
62 #define SHA204_CMD_SIZE_MAX          ((uint8_t) 84)
63 
64 //! number of CRC bytes
65 #define SHA204_CRC_SIZE              ((uint8_t)  2)
66 
67 //! buffer index of status byte in status response
68 #define SHA204_BUFFER_POS_STATUS     (1)
69 
70 //! buffer index of first data byte in data response
71 #define SHA204_BUFFER_POS_DATA       (1)
72 
73 //! status byte after wake-up
74 #define SHA204_STATUS_BYTE_WAKEUP    ((uint8_t) 0x11)
75 
76 //! command parse error
77 #define SHA204_STATUS_BYTE_PARSE     ((uint8_t) 0x03)
78 
79 //! command execution error
80 #define SHA204_STATUS_BYTE_EXEC      ((uint8_t) 0x0F)
81 
82 //! communication error
83 #define SHA204_STATUS_BYTE_COMM      ((uint8_t) 0xFF)
84 
85 /**
86  * \brief This structure contains the parameters for the \ref sha204c_send_and_receive function.
87  */
88 struct sha204_send_and_receive_parameters {
89 	uint8_t *tx_buffer;         //!< pointer to send buffer
90 	uint8_t rx_size;            //!< size of receive buffer
91 	uint8_t *rx_buffer;         //!< pointer to receive buffer
92 	uint8_t poll_delay;         //!< how long to wait before polling for response-ready
93 	uint8_t poll_timeout;       //!< how long to poll before timing out
94 };
95 
96 /**
97  * \defgroup sha204_communication_group SHA204 Service - hardware independent communication functions
98  * @{
99  */
100 void sha204c_calculate_crc(uint8_t length, uint8_t *data, uint8_t *crc);
101 uint8_t sha204c_wakeup(uint8_t *response);
102 uint8_t sha204c_send_and_receive(struct sha204_send_and_receive_parameters *args);
103 //! @}
104 
105 #endif
106