ata8520e.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
25 #ifndef ATA8520E_H
26 #define ATA8520E_H
27 
28 #include <stdint.h>
29 #include <inttypes.h>
30 #include "xtimer.h"
31 #include "periph/gpio.h"
32 #include "periph/spi.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
42 #define SIGFOX_PAC_LENGTH (16U)
43 #define SIGFOX_ID_LENGTH (8U)
44 #define SIGFOX_MAX_TX_LENGTH (12U)
45 #define SIGFOX_RX_LENGTH (8U)
51 enum {
58 };
59 
63 enum {
68 };
69 
73 typedef enum {
78 
84 typedef enum {
94 
100 typedef enum {
118 
122 typedef struct {
125  gpio_t cs_pin;
126  gpio_t int_pin;
127  gpio_t power_pin;
128  gpio_t reset_pin;
130 
134 typedef struct {
136  uint8_t internal_state;
137  uint8_t event_received;
139 } ata8520e_t;
140 
156 int ata8520e_init(ata8520e_t *dev, const ata8520e_params_t *params);
157 
163 void ata8520e_system_reset(const ata8520e_t *dev);
164 
172 void ata8520e_read_atmel_version(const ata8520e_t *dev, uint8_t *version);
173 
181 void ata8520e_read_sigfox_version(const ata8520e_t *dev, char *version);
182 
190 void ata8520e_read_pac(const ata8520e_t *dev, char *pac);
191 
199 void ata8520e_read_id(const ata8520e_t *dev, char *id);
200 
211 int ata8520e_send_frame(ata8520e_t *dev, uint8_t *payload, uint8_t payload_len);
212 
224 int ata8520e_send_receive_frame(ata8520e_t *dev, uint8_t *payload,
225  uint8_t payload_len, uint8_t *rx_payload);
226 
236 int ata8520e_send_bit(ata8520e_t *dev, bool bit);
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #endif /* ATA8520E_H */
243 
ata8520e_status_type_t
ata8520e_status_type_t
device module status
Definition: ata8520e.h:73
ATA8520E_ATMEL_SEND_ERROR
@ ATA8520E_ATMEL_SEND_ERROR
Send error.
Definition: ata8520e.h:92
ata8520e_params_t::power_pin
gpio_t power_pin
Power pin.
Definition: ata8520e.h:127
ata8520e_params_t::spi
spi_t spi
SPI device.
Definition: ata8520e.h:123
ATA8520E_ERR_EVENT_TIMEOUT
@ ATA8520E_ERR_EVENT_TIMEOUT
An expected event never happened.
Definition: ata8520e.h:57
ATA8520E_ATMEL_USAGE_ERROR
@ ATA8520E_ATMEL_USAGE_ERROR
Usage error.
Definition: ata8520e.h:89
ata8520e_read_atmel_version
void ata8520e_read_atmel_version(const ata8520e_t *dev, uint8_t *version)
Return the Atmel version of the device.
ATA8520E_STATE_RX
@ ATA8520E_STATE_RX
Device is in RX mode, just after TX.
Definition: ata8520e.h:67
ata8520e_t
device descriptor
Definition: ata8520e.h:134
ATA8520E_ATMEL_CLOSING_ERROR
@ ATA8520E_ATMEL_CLOSING_ERROR
Closing error.
Definition: ata8520e.h:91
ata8520e_t::event_lock
mutex_t event_lock
mutex for waiting for event
Definition: ata8520e.h:138
ATA8520E_SIGFOX_MANUFACTURER_SEND_ERROR
@ ATA8520E_SIGFOX_MANUFACTURER_SEND_ERROR
Manufacturer send error.
Definition: ata8520e.h:106
ata8520e_params_t
Initialization parameters.
Definition: ata8520e.h:122
ATA8520E_SIGFOX_ID_OR_KEY_ERROR
@ ATA8520E_SIGFOX_ID_OR_KEY_ERROR
ID or key error.
Definition: ata8520e.h:103
spi.h
Low-level SPI peripheral driver interface definition.
ATA8520E_STATE_TX
@ ATA8520E_STATE_TX
Device is in TX mode.
Definition: ata8520e.h:66
ATA8520E_OK
@ ATA8520E_OK
Everything is fine.
Definition: ata8520e.h:52
ata8520e_t::internal_state
uint8_t internal_state
current state of the device
Definition: ata8520e.h:136
ATA8520E_SIGFOX_FRAME_SIZE_ERROR
@ ATA8520E_SIGFOX_FRAME_SIZE_ERROR
Frame size error.
Definition: ata8520e.h:105
ATA8520E_ERR_GPIO_INT
@ ATA8520E_ERR_GPIO_INT
An error occurred with interrupt pin.
Definition: ata8520e.h:54
ata8520e_send_frame
int ata8520e_send_frame(ata8520e_t *dev, uint8_t *payload, uint8_t payload_len)
Send a frame.
ATA8520E_SIGFOX_GET_FREQUENCY_ERROR
@ ATA8520E_SIGFOX_GET_FREQUENCY_ERROR
Error getting frequency.
Definition: ata8520e.h:111
ATA8520E_SIGFOX_API_ERROR
@ ATA8520E_SIGFOX_API_ERROR
API error indication.
Definition: ata8520e.h:109
ATA8520E_SIGFOX
@ ATA8520E_SIGFOX
Sigfox status.
Definition: ata8520e.h:76
ATA8520E_STATE_INIT
@ ATA8520E_STATE_INIT
Device is in initialization phase.
Definition: ata8520e.h:65
ata8520e_params_t::reset_pin
gpio_t reset_pin
Reset pin.
Definition: ata8520e.h:128
ata8520e_params_t::cs_pin
gpio_t cs_pin
Chip select pin.
Definition: ata8520e.h:125
ata8520e_init
int ata8520e_init(ata8520e_t *dev, const ata8520e_params_t *params)
Initialize the device.
ATA8520E_SIGFOX_CLOSE_ERROR
@ ATA8520E_SIGFOX_CLOSE_ERROR
Close issues encountered.
Definition: ata8520e.h:108
ata8520e_t::params
ata8520e_params_t params
Device parameters.
Definition: ata8520e.h:135
ATA8520E_ATMEL_GENERIC_ERROR
@ ATA8520E_ATMEL_GENERIC_ERROR
Generic error.
Definition: ata8520e.h:87
ATA8520E_SIGFOX_FREQUENCY_ERROR
@ ATA8520E_SIGFOX_FREQUENCY_ERROR
Frequency error.
Definition: ata8520e.h:116
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
ATA8520E_SIGFOX_MANUFACTURER_ERROR
@ ATA8520E_SIGFOX_MANUFACTURER_ERROR
Manufacturer error.
Definition: ata8520e.h:102
ATA8520E_ATMEL_COMMAND_ERROR
@ ATA8520E_ATMEL_COMMAND_ERROR
Command error / not supported.
Definition: ata8520e.h:86
ATA8520E_SIGFOX_DELAY_ROUTINE_ERROR
@ ATA8520E_SIGFOX_DELAY_ROUTINE_ERROR
Error in delay routine.
Definition: ata8520e.h:113
ata8520e_read_id
void ata8520e_read_id(const ata8520e_t *dev, char *id)
Return the ID of the device.
ATA8520E_ATMEL_OK
@ ATA8520E_ATMEL_OK
No error.
Definition: ata8520e.h:85
ata8520e_params_t::spi_clk
spi_clk_t spi_clk
SPI clock speed.
Definition: ata8520e.h:124
ATA8520E_SIGFOX_CALLBACK_ERROR
@ ATA8520E_SIGFOX_CALLBACK_ERROR
Callback causes error.
Definition: ata8520e.h:114
ata8520e_read_pac
void ata8520e_read_pac(const ata8520e_t *dev, char *pac)
Return the porting authorization code (PAC) available in the device.
ATA8520E_SIGFOX_STATE_MACHINE_ERROR
@ ATA8520E_SIGFOX_STATE_MACHINE_ERROR
State machine error.
Definition: ata8520e.h:104
ATA8520E_SIGFOX_GET_VOLTAGE_TEMP_ERROR
@ ATA8520E_SIGFOX_GET_VOLTAGE_TEMP_ERROR
Get voltage/temperature error.
Definition: ata8520e.h:107
ata8520e_read_sigfox_version
void ata8520e_read_sigfox_version(const ata8520e_t *dev, char *version)
Return the Atmel version of the device.
ata8520e_atmel_status_t
ata8520e_atmel_status_t
Sigfox statuses.
Definition: ata8520e.h:84
ATA8520E_SIGFOX_OK
@ ATA8520E_SIGFOX_OK
No error.
Definition: ata8520e.h:101
ata8520e_send_bit
int ata8520e_send_bit(ata8520e_t *dev, bool bit)
Send a bit.
ATA8520E_ATMEL
@ ATA8520E_ATMEL
Atmel status.
Definition: ata8520e.h:75
gpio.h
Low-level GPIO peripheral driver interface definitions.
ata8520e_send_receive_frame
int ata8520e_send_receive_frame(ata8520e_t *dev, uint8_t *payload, uint8_t payload_len, uint8_t *rx_payload)
Send a frame and wait for a RX packet.
ATA8520E_ERR_GPIO_RESET
@ ATA8520E_ERR_GPIO_RESET
An error occurred with reset pin.
Definition: ata8520e.h:55
ata8520e_t::event_received
uint8_t event_received
check if an event was received
Definition: ata8520e.h:137
ATA8520E_SIGFOX_BUILDING_FRAME_ERROR
@ ATA8520E_SIGFOX_BUILDING_FRAME_ERROR
Error building frame.
Definition: ata8520e.h:112
ATA8520E_SIGFOX_TIMING_ERROR
@ ATA8520E_SIGFOX_TIMING_ERROR
Timing error.
Definition: ata8520e.h:115
ATA8520E_ATMEL_OPENING_ERROR
@ ATA8520E_ATMEL_OPENING_ERROR
Opening error.
Definition: ata8520e.h:90
ATA8520E_SIGFOX_GET_PN9_ERROR
@ ATA8520E_SIGFOX_GET_PN9_ERROR
Error getting PN9.
Definition: ata8520e.h:110
ata8520e_params_t::int_pin
gpio_t int_pin
IRQ pin.
Definition: ata8520e.h:126
ATA8520E_ATMEL_FREQUENCY_ERROR
@ ATA8520E_ATMEL_FREQUENCY_ERROR
Frequency error.
Definition: ata8520e.h:88
ATA8520E_SSM
@ ATA8520E_SSM
SoC System Management status.
Definition: ata8520e.h:74
ATA8520E_ERR_GPIO_POWER
@ ATA8520E_ERR_GPIO_POWER
An error occurred with power pin.
Definition: ata8520e.h:56
ATA8520E_STATE_IDLE
@ ATA8520E_STATE_IDLE
Device is in idle state.
Definition: ata8520e.h:64
inttypes.h
Adds include for missing inttype definitions.
ata8520e_system_reset
void ata8520e_system_reset(const ata8520e_t *dev)
Perform a complete reset of the device.
ATA8520E_ERR_SPI
@ ATA8520E_ERR_SPI
An error occurred with SPI.
Definition: ata8520e.h:53
xtimer.h
xtimer interface definitions
mutex_t
Mutex structure.
Definition: mutex.h:120
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
ata8520e_sigfox_status_t
ata8520e_sigfox_status_t
Sigfox statuses.
Definition: ata8520e.h:100