1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/ata8520e: small improvements

- move ata8520e_status from public interface to private implementation
- add useful references to the datasheet
This commit is contained in:
Alexandre Abadie 2018-01-29 14:56:34 +01:00
parent 2d27b32567
commit 608e92e0be
3 changed files with 66 additions and 73 deletions

View File

@ -93,7 +93,8 @@ static void _print_atmel_status(uint8_t status)
DEBUG("[ata8520e] Atmel: Send error\n");
break;
default:
DEBUG("[ata8520e] Atmel: Invalid status code\n");
DEBUG("[ata8520e] Atmel: Unknown status code '%02X'\n",
(status >> 1) & 0x0F);
break;
}
}
@ -102,56 +103,32 @@ static void _print_sigfox_status(uint8_t status)
{
DEBUG("[ata8520e] Sigfox status: %d\n", status);
switch (status) {
case ATA8520E_SIGFOX_OK:
case ATA8520E_SIGFOX_NO_ERROR:
DEBUG("[ata8520e] Sigfox: OK\n");
break;
case ATA8520E_SIGFOX_MANUFACTURER_ERROR:
DEBUG("[ata8520e] Sigfox: Manufacturer error\n");
case ATA8520E_SIGFOX_TX_LEN_TOO_LONG:
DEBUG("[ata8520e] Sigfox: TX data length exceeds 12 bytes\n");
break;
case ATA8520E_SIGFOX_ID_OR_KEY_ERROR:
DEBUG("[ata8520e] Sigfox: ID or Key error\n");
case ATA8520E_SIGFOX_RX_TIMEOUT:
DEBUG("[ata8520e] Sigfox: Timeout for downlink message\n");
break;
case ATA8520E_SIGFOX_STATE_MACHINE_ERROR:
DEBUG("[ata8520e] Sigfox: State machine error\n");
case ATA8520E_SIGFOX_RX_BIT_TIMEOUT:
DEBUG("[ata8520e] Sigfox: Timeout for bit downlink\n");
break;
case ATA8520E_SIGFOX_FRAME_SIZE_ERROR:
DEBUG("[ata8520e] Sigfox: Frame size error\n");
case ATA8520E_SIGFOX2_INIT_ERROR:
DEBUG("[ata8520e] Sigfox2: Initialization error\n");
break;
case ATA8520E_SIGFOX_MANUFACTURER_SEND_ERROR:
DEBUG("[ata8520e] Sigfox: Manufacturer send error\n");
case ATA8520E_SIGFOX2_TX_ERROR:
DEBUG("[ata8520e] Sigfox2: Error during send\n");
break;
case ATA8520E_SIGFOX_GET_VOLTAGE_TEMP_ERROR:
DEBUG("[ata8520e] Sigfox: Get voltage/temperature error\n");
case ATA8520E_SIGFOX2_RF_ERROR:
DEBUG("[ata8520e] Sigfox2: Error in RF frequency\n");
break;
case ATA8520E_SIGFOX_CLOSE_ERROR:
DEBUG("[ata8520e] Sigfox: Close issues encountered\n");
break;
case ATA8520E_SIGFOX_API_ERROR:
DEBUG("[ata8520e] Sigfox: API error indication\n");
break;
case ATA8520E_SIGFOX_GET_PN9_ERROR:
DEBUG("[ata8520e] Sigfox: Error getting PN9\n");
break;
case ATA8520E_SIGFOX_GET_FREQUENCY_ERROR:
DEBUG("[ata8520e] Sigfox: Error getting frequency\n");
break;
case ATA8520E_SIGFOX_BUILDING_FRAME_ERROR:
DEBUG("[ata8520e] Sigfox: Error building frame\n");
break;
case ATA8520E_SIGFOX_DELAY_ROUTINE_ERROR:
DEBUG("[ata8520e] Sigfox: Error in delay routine\n");
break;
case ATA8520E_SIGFOX_CALLBACK_ERROR:
DEBUG("[ata8520e] Sigfox: Callback causes error\n");
break;
case ATA8520E_SIGFOX_TIMING_ERROR:
DEBUG("[ata8520e] Sigfox: Timing error\n");
break;
case ATA8520E_SIGFOX_FREQUENCY_ERROR:
DEBUG("[ata8520e] Sigfox: Frequency error\n");
case ATA8520E_SIGFOX2_DF_WAIT_ERROR:
DEBUG("[ata8520e] Sigfox2: Error during wait for data frame\n");
break;
default:
DEBUG("[ata8520e] Sigfox: Invalid status code [%d]\n", status);
DEBUG("[ata8520e] Sigfox: Internal error '%02X'\n", status);
break;
}
}
@ -215,6 +192,26 @@ static void _send_command(const ata8520e_t *dev, uint8_t command)
spi_release(SPIDEV);
}
static void _status(const ata8520e_t *dev)
{
/* clear the event line and check the device status,
see datasheet, section 2.1.2.10, page 12 */
_getbus(dev);
_spi_transfer_byte(dev, true, ATA8520E_GET_STATUS);
_spi_transfer_byte(dev, true, 0);
_spi_transfer_byte(dev, true, 0); /* SSM unused */
uint8_t atmel = spi_transfer_byte(SPIDEV, CSPIN, true, 0);
uint8_t sigfox = spi_transfer_byte(SPIDEV, CSPIN, true, 0);
uint8_t sigfox2 = spi_transfer_byte(SPIDEV, CSPIN, false, 0);
spi_release(SPIDEV);
if (ENABLE_DEBUG) {
_print_atmel_status(atmel);
_print_sigfox_status(sigfox);
_print_sigfox_status(sigfox2);
}
}
static void _reset(const ata8520e_t *dev)
{
gpio_set(RESETPIN);
@ -226,12 +223,15 @@ static void _reset(const ata8520e_t *dev)
static void _poweron(const ata8520e_t *dev)
{
/* power up procedure, see datasheet, section 2.2.1, page 24 */
gpio_set(POWERPIN);
_reset(dev);
}
static void _poweroff(const ata8520e_t *dev)
{
/* power down procedure, see datasheet, section 2.2.2, page 24 */
_status(dev);
gpio_clear(POWERPIN);
_send_command(dev, ATA8520E_OFF_MODE);
}
@ -287,8 +287,8 @@ int ata8520e_init(ata8520e_t *dev, const ata8520e_params_t *params)
DEBUG("[ata8520e] Sigfox PAC: %s\n", sigfox_pac);
}
/* Get status and clear event line */
ata8520e_status(dev);
/* clear event line */
_status(dev);
dev->internal_state = ATA8520E_STATE_IDLE;
@ -353,24 +353,6 @@ void ata8520e_read_id(const ata8520e_t *dev, char *id)
_poweroff(dev);
}
void ata8520e_status(const ata8520e_t *dev)
{
_getbus(dev);
_spi_transfer_byte(dev, true, ATA8520E_OFF_MODE);
_spi_transfer_byte(dev, true, 0);
_spi_transfer_byte(dev, true, 0); /* SSM unused */
uint8_t atmel = spi_transfer_byte(SPIDEV, CSPIN, true, 0);
uint8_t sigfox = spi_transfer_byte(SPIDEV, CSPIN, true, 0);
_spi_transfer_byte(dev, false, 0);
spi_release(SPIDEV);
if (ENABLE_DEBUG) {
_print_atmel_status(atmel);
_print_sigfox_status(sigfox);
}
}
static void isr_event_timeout(void *arg)
{
ata8520e_t *dev = (ata8520e_t *)arg;
@ -406,7 +388,7 @@ static void _prepare_send_frame(ata8520e_t *dev, uint8_t *msg, uint8_t msg_len)
{
_poweron(dev);
xtimer_usleep(5 * US_PER_MS);
ata8520e_status(dev);
_status(dev);
/* Verify message length */
if (msg_len > SIGFOX_MAX_TX_LENGTH) {
@ -440,7 +422,7 @@ static int _wait_send(ata8520e_t *dev, uint8_t timeout)
}
/* Clear event line */
ata8520e_status(dev);
_status(dev);
/* back to idle state */
dev->internal_state = ATA8520E_STATE_IDLE;
@ -501,7 +483,7 @@ int ata8520e_send_bit(ata8520e_t *dev, bool bit)
DEBUG("[ata8520e] Sending bit '%d'\n", bit);
_poweron(dev);
xtimer_usleep(5 * US_PER_MS);
ata8520e_status(dev);
_status(dev);
dev->internal_state = ATA8520E_STATE_TX;

View File

@ -60,6 +60,26 @@ extern "C" {
#define ATA8520E_ATMEL_PA_MASK (0x01)
/** @} */
/**
* @name Sigfox errors codes
* @{
*/
#define ATA8520E_SIGFOX_NO_ERROR (0x00)
#define ATA8520E_SIGFOX_TX_LEN_TOO_LONG (0x30)
#define ATA8520E_SIGFOX_RX_TIMEOUT (0x3E)
#define ATA8520E_SIGFOX_RX_BIT_TIMEOUT (0x4E)
/** @} */
/**
* @name Sigfox2 errors codes
* @{
*/
#define ATA8520E_SIGFOX2_INIT_ERROR (0x10)
#define ATA8520E_SIGFOX2_TX_ERROR (0x18)
#define ATA8520E_SIGFOX2_RF_ERROR (0x40)
#define ATA8520E_SIGFOX2_DF_WAIT_ERROR (0x68)
/** @} */
#ifdef __cplusplus
}
#endif

View File

@ -198,15 +198,6 @@ void ata8520e_read_pac(const ata8520e_t *dev, char *pac);
*/
void ata8520e_read_id(const ata8520e_t *dev, char *id);
/**
* @brief Check the current status of the device
*
* Calling this function clears the system event line.
*
* @param[in] dev Pointer to device descriptor
*/
void ata8520e_status(const ata8520e_t *dev);
/**
* @brief Send a frame
*