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

139 lines
3.2 KiB
C
Raw Normal View History

2016-07-08 03:33:54 +02:00
/*
* Copyright (C) 2016 MUTEX NZ Ltd.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
*/
/**
* @ingroup cpu_cc2538
* @{
*
* @file
* @brief Implementation of driver internal functions
*
* @author Aaron Sowry <aaron@mutex.nz>
*
* @}
*/
2016-11-30 18:26:05 +01:00
#include "cpu.h"
2016-07-08 03:33:54 +02:00
#include "cc2538.h"
#include "cc2538_rf.h"
#include "cc2538_rf_netdev.h"
#include "cc2538_rf_internal.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
void isr_rfcoreerr(void)
{
uint_fast8_t flags;
/* Latch and clear the interrupt status */
flags = RFCORE_SFR_RFERRF;
RFCORE_SFR_RFERRF = 0;
/* These conditions shouldn't happen if the driver is working properly */
RFCORE_ASSERT(NOT(flags & RXUNDERF));
RFCORE_ASSERT(NOT(flags & TXOVERF));
RFCORE_ASSERT(NOT(flags & TXUNDERF));
/* Fail in case of miscallaneous unexpected error conditions */
RFCORE_ASSERT(NOT(flags & STROBE_ERR));
DEBUG("%s(): RFERRF=0x%02x.\n", __FUNCTION__, flags);
/* Flush the receive FIFO in case of a receive overflow */
if (flags & RXOVERF) {
DEBUG("%s(): RXOVERF detected!\n", __FUNCTION__);
RFCORE_FLUSH_RECEIVE_FIFO();
}
/* Flush the receive FIFO in case of a receive overflow */
if (flags & NLOCK) {
/* The frequency synthesizer failed to achieve lock after time-out, or
* lock is lost during reception. The receiver must be restarted to clear
* this error situation. */
DEBUG("%s(): NLOCK detected!\n", __FUNCTION__);
RFCORE_FLUSH_RECEIVE_FIFO();
}
}
void isr_rfcorerxtx(void)
{
RFCORE_SFR_RFIRQF0 = 0;
RFCORE_SFR_RFIRQF1 = 0;
_irq_handler();
2016-11-30 18:26:05 +01:00
cortexm_isr_end();
2016-07-08 03:33:54 +02:00
}
uint_fast8_t rfcore_read_byte(void)
{
RFCORE_ASSERT(RFCORE_XREG_RXFIFOCNT > 0);
return RFCORE_SFR_RFDATA;
}
uint_fast8_t rfcore_peek_rx_fifo(int idx)
{
RFCORE_ASSERT(idx >= 0 && idx < CC2538_RF_FIFO_SIZE);
return *(uint_fast8_t *)(CC2538_RX_FIFO_ADDR + 4 * idx);
}
void rfcore_read_fifo(void *buf, uint_fast8_t len)
{
uint_fast8_t n;
RFCORE_ASSERT(len <= RFCORE_XREG_RXFIFOCNT);
for (n = 0; n < len; n++) {
GET_BYTE(buf, n) = RFCORE_SFR_RFDATA;
}
}
void rfcore_strobe(uint_fast8_t instr)
{
RFCORE_SFR_RFST = instr;
}
void rfcore_write_byte(uint_fast8_t byte)
{
RFCORE_ASSERT(RFCORE_XREG_TXFIFOCNT < CC2538_RF_FIFO_SIZE);
RFCORE_SFR_RFDATA = byte;
}
void rfcore_poke_tx_fifo(int idx, uint_fast8_t byte)
{
RFCORE_ASSERT(idx >= 0 && idx < CC2538_RF_FIFO_SIZE);
*(uint_fast8_t *)(CC2538_TX_FIFO_ADDR + 4 * idx) = byte;
}
void rfcore_write_fifo(const void *buf, uint_fast8_t len)
{
uint_fast8_t n;
RFCORE_ASSERT(len <= CC2538_RF_FIFO_SIZE - RFCORE_XREG_TXFIFOCNT);
for (n = 0; n < len; n++) {
RFCORE_SFR_RFDATA = GET_BYTE(buf, n);
}
}
bool RFCORE_ASSERT_failure(const char *expr, const char *func, int line)
{
#if (DEVELHELP || ENABLE_DEBUG)
DEBUG_PRINT("RFCORE_ASSERT(%s) failed at line %u in %s()!\n", expr, line, func);
DEBUG_PRINT(" RFCORE_SFR_RFERRF = 0x%02x\n", (unsigned int)RFCORE_SFR_RFERRF);
build: fix unused parameter errors cpu, sam0_common: fix unused parameter in periph/spi cpu, kinetis_common: fix unused parameter in periph/spi cpu, cc2538: fix unused param in periph/i2c cpu, cc2538: fix unused param in periph/spi cpu, sam3: fix unused param in periph/spi cpu, stm32_common: fix unused param in periph/pm cpu, stm32f3: fix unused params in periph/i2c cpu, nrf5x_common: fix unused param in periph/gpio cpu, nrf5x_common: fix unused param in periph/spi cpu, lpc2387: fix unused params in periph/spi cpu, cc2538: fix unused params in radio/netdev cpu, cc2650: fix unused params in periph/uart cpu, lm4f120: fix unused param in periph/spi cpu, lm4f120: fix unused params in periph/timer cpu, lm4f120: fix unused params in periph/uart cpu, stm32_common: fix unused params in periph/dac cpu, stm32l0: fix unused params in periph/i2c cpu, msp430fxyz: fix unused params in periph/uart cpu, mips: fix unused params cpu, cc430: fix unused-params in periph/timer cpu, msp430fxyz: fix unused params in periph/spi drivers, cc2420: fix unused param cpu, mips32r2_common: fix unused params in periph/timer cpu, cc2538: fix unused-param in periph/i2c cpu, mips32r2_common: fix unused-param in periph/timer cpu, msp430fxyz: fix unused params in periph/timer cpu, atmega_common: fix unused params in periph/spi driver, nrfmin: fix unused params cpu, cc2538_rf: fix unused params driver, netdev_ieee802514: fix unused param cpu, mip_pic32m: fix unused params cpu, lpc2387: fix unused params in periph/pwm tests/driver_sdcard_spi: fix unused params cpu, sam3: fix unused param in periph/pwm tests/driver_dynamixel: fix unused params, and style issues cpu, cc430: fix unused param in periph/rtc cpu, atmega_common: fix unused params in periph/i2c
2017-10-31 12:09:11 +01:00
#else
(void)expr;
(void)func;
(void)line;
2016-07-08 03:33:54 +02:00
#endif
return false;
}