/*********************************************************************************** * @fn CC2520_TXBUF8 * * @brief Write 8 bits to TX buffer * * @param uint8 data * * @return none */ void CC2520_TXBUF8(uint8 data) { CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_TXBUF); CC2520_SPI_TXRX(data); CC2520_SPI_END(); }
/*********************************************************************************** * @fn CC2520_INS_STROBE * * @brief send strobe command * * @param uint8 strobe - strobe command * * @return uint8 - status byte */ uint8 CC2520_INS_STROBE(uint8 strobe) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(strobe); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_REGWR16 * * @brief Write two register bytes * * @param uint8 addr - address * uint16 value * * @return none */ void CC2520_REGWR16(uint8 addr, uint16 value) { CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGWR | addr); CC2520_SPI_TXRX(LO_UINT16(value)); CC2520_SPI_TXRX(HI_UINT16(value)); CC2520_SPI_END(); }
/*********************************************************************************** * @fn CC2520_REGWR8 * * @brief Write one register byte * * @param uint8 addr - address * uint8 value * * @return none */ void CC2520_REGWR8(uint8 addr, uint8 value) { CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGWR | addr); CC2520_SPI_TXRX(value); CC2520_SPI_END(); return; }
/*********************************************************************************** * @fn CC2520_RXBUFCP_END * * @brief Copy RX buf to memory and read into buffer. * Call this routine after CC2520_RXBUFCP_BEGIN. * * @param uint16 addr - copy destination * uint8 count - number of bytes * uint8 *pData - data buffer * * @return uint8 - status byte */ uint8 CC2520_RXBUFCP_END(uint16 addr, uint8 count, uint8 *pData) { uint8 s; s = CC2520_SPI_TXRX(LO_UINT16(addr)); CC2520_INS_RD_ARRAY(count, pData); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_TXBUF16 * * @brief Write 16 bits to TX buffer * * @param uint16 data * * @return none */ void CC2520_TXBUF16(uint16 data) { CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_TXBUF); CC2520_SPI_TXRX(LO_UINT16(data)); CC2520_SPI_TXRX(HI_UINT16(data)); CC2520_SPI_END(); }
/*********************************************************************************** * @fn CC2520_SRES * * @brief SRES - Reset device except SPI interface * * @param none * * @return uint8 - status byte */ uint8 CC2520_SRES(void) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_SRES); CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_IBUFLD * * @brief IBUFLD - load instruction to instruction buffer * * @param uint8 i - * * @return uint8 - status byte */ uint8 CC2520_IBUFLD(uint8 i) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_IBUFLD); CC2520_SPI_TXRX(i); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_REGWR24 * * @brief Write three register bytes * * @param uint8 addr * uint32 value * * @return none */ void CC2520_REGWR24(uint8 addr, uint32 value) { CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGWR | addr); CC2520_SPI_TXRX(LO_UINT16(LO_UINT32(value))); CC2520_SPI_TXRX(HI_UINT16(LO_UINT32(value))); CC2520_SPI_TXRX(LO_UINT16(HI_UINT32(value))); CC2520_SPI_END(); }
/*********************************************************************************** * @fn CC2520_REGWR * * @brief Register write. Can only be started from addresses below 0x40 * * @param uint8 addr - address * uint8 count - number of bytes * uint8 *pValues - data buffer * * @return uint8 - status byte */ uint8 CC2520_REGWR(uint8 addr, uint8 count, uint8 *pValues) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_REGWR | addr); CC2520_INS_WR_ARRAY(count, pValues); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_TXBUF * * @brief Write data to TX buffer * * @param uint8 count - number of bytes * uint8 *pData - pointer to data buffer * * @return uint8 - status byte */ uint8 CC2520_TXBUF(uint8 count, uint8 *pData) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_TXBUF); CC2520_INS_WR_ARRAY(count, pData); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_REGRD8 * * @brief Read one register byte * * @param uint8 addr - address * * @return uint8 - result */ uint8 CC2520_REGRD8(uint8 addr) { uint8 value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGRD | addr); value = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value; }
/*********************************************************************************** * @fn CC2520_ABORT * * @brief Abort ongoing data management or security instruction * * @param uint8 c - abort mode (see datasheet) * * @return uint8 - status byte */ uint8 CC2520_ABORT(uint8 c) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_ABORT); CC2520_SPI_TXRX(c); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_RXBUF8 * * @brief Read 8 bits from RX buffer * * @param none * * @return uint8 - result */ uint8 CC2520_RXBUF8(void) { uint8 value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_RXBUF); value = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value; }
/*********************************************************************************** * @fn CC2520_BCLR * * @brief BCLR - Clear a single bit * * @param uint8 bitAddr - address * * @return uint8 - status byte */ uint8 CC2520_BCLR(uint8 bitAddr) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_BCLR); CC2520_SPI_TXRX(bitAddr); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn halRfInit * * @brief Power up, sets default tuning settings, enables autoack and configures * chip IO * * @param none * * @return HAL_RF_SUCCESS if the radio has started, FAILURE otherwise */ uint8 halRfInit(void) { regVal_t* p; DEBUG_MSG_FUNC_START; // Avoid GPIO0 interrupts during reset #if 0 // POOH halDigioIntDisable(&pinRadio_GPIO0); #else CC2520_GPIO_0_Interrupt_Setting(DISABLE); #endif // Make sure to pull the CC2520 RESETn and VREG_EN pins low CC2520_RESET_OPIN(0); CC2520_SPI_END(); CC2520_VREG_EN_OPIN(0); #if 0 // POOH halMcuWaitUs(1100); #else Delay(110); #endif // Make sure MISO is configured as output. #if 0 // POOH CC2520_MISO_DIR_OUT(); #endif // Enable the voltage regulator and wait for it (CC2520 power-up) CC2520_VREG_EN_OPIN(1); #if 0 // POOH halMcuWaitUs(CC2520_VREG_MAX_STARTUP_TIME); #else Delay(200); #endif // Release reset CC2520_RESET_OPIN(1); #if 0 // POOH // Wait for XOSC stable to be announced on the MISO pin if (halRfWaitRadioReady()==HAL_RF_FAILED) return HAL_RF_FAILED; #else Delay(200); #endif // Write non-default register values p= regval; while (p->reg!=0) { CC2520_MEMWR8(p->reg,p->val); p++; } return HAL_RF_SUCCESS; }
/*********************************************************************************** * @fn CC2520_MEMRD8 * * @brief Read memory 8 bits * * @param uint16 addr * * @return uint8 - result */ uint8 CC2520_MEMRD8(uint16 addr) { uint8 value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_MEMRD | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); value = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value; }
/*********************************************************************************** * @fn CC2520_RXMASKOR * * @brief RXMASKOR instruction - bitwise OR between RX enable mask and orMask * * @param uint16 orMask - * * @return uint8 - status byte */ uint8 CC2520_RXMASKOR(uint16 orMask) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_RXMASKOR); CC2520_SPI_TXRX(HI_UINT16(orMask)); CC2520_SPI_TXRX(LO_UINT16(orMask)); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_RXMASKAND * * @brief RXMASKAND - bitwise AND between RX enable mask and andMask * * @param uint16 andMask * * @return uint8 - status byte */ uint8 CC2520_RXMASKAND(uint16 andMask) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_RXMASKAND); CC2520_SPI_TXRX(HI_UINT16(andMask)); CC2520_SPI_TXRX(LO_UINT16(andMask)); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_REGRD16 * * @brief Read two register bytes * * @param uint8 addr - address * * @return uint16 - result */ uint16 CC2520_REGRD16(uint8 addr) { eword_t value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGRD | addr); value.b.b0 = CC2520_SPI_TXRX(0x00); value.b.b1 = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value.w; }
/*********************************************************************************** * @fn CC2520_RANDOM * * @brief Random generated bytes * * @param uint8 count * uint8 *pData * * @return uint8 - status byte */ uint8 CC2520_RANDOM(uint8 count, uint8 *pData) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_RANDOM); CC2520_SPI_TXRX(0x00); CC2520_INS_RD_ARRAY(count, pData); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_INC * * @brief INC - increment instruction. Increments 2^c byte word with least * significant byte at address. * * @param uint8 pri - priority * uint8 c - increments 2^c byte word * uint16 addr - address * * @return uint8 - status byte */ uint8 CC2520_INC(uint8 pri, uint8 c, uint16 addr) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_INC | pri); CC2520_SPI_TXRX((c << 4) | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_RXBUF16 * * @brief Read 16 bits from RX buffer * * @param none * * @return uint16 - result */ uint16 CC2520_RXBUF16(void) { eword_t value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_RXBUF); value.b.b0 = CC2520_SPI_TXRX(0x00); value.b.b1 = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value.w; }
/*********************************************************************************** * @fn CC2520_MEMWR8 * * @brief Write memory 8 bits * * @param uint16 addr * uint8 value * * @return uint8 - status byte */ uint8 CC2520_MEMWR8(uint16 addr, uint8 value) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_MEMWR | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); CC2520_SPI_TXRX(value); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_MEMWR * * @brief Write memory * * @param uint16 addr * uint16 count * uint8 *pData * * @return uint8 - status byte */ uint8 CC2520_MEMWR(uint16 addr, uint16 count, uint8 *pData) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_MEMWR | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); CC2520_INS_WR_ARRAY(count, pData); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_MEMRD16 * * @brief Read memory 16 bits * * @param uint16 addr * * @return uint16 - result */ uint16 CC2520_MEMRD16(uint16 addr) { eword_t value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_MEMRD | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); value.b.b0 = CC2520_SPI_TXRX(0x00); value.b.b1 = CC2520_SPI_TXRX(0x00); CC2520_SPI_END(); return value.w; }
/*********************************************************************************** * @fn CC2520_REGRD24 * * @brief Read three register bytes * * @param uint8 addr - address * * @return uint32 - result */ uint32 CC2520_REGRD24(uint8 addr) { edword_t value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_REGRD | addr); value.b.b0 = CC2520_SPI_TXRX(0x00); value.b.b1 = CC2520_SPI_TXRX(0x00); value.b.b2 = CC2520_SPI_TXRX(0x00); value.b.b3 = 0x00; CC2520_SPI_END(); return value.dw; }
/*********************************************************************************** * @fn CC2520_ECBX * * @brief ECB encryption and XOR * * @param uint8 pri - priority * uint8 k - address of key * uint8 c - encrypts 16-C bytes of data in a 16 byte block * uint16 src - source address * uint16 dest - destination address * * @return uint8 - status byte */ uint8 CC2520_ECBX(uint8 pri, uint8 k, uint8 c, uint16 src, uint16 dest) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(CC2520_INS_ECBX | pri); CC2520_SPI_TXRX(k); CC2520_SPI_TXRX((c << 4) | HI_UINT16(src)); CC2520_SPI_TXRX(LO_UINT16(src)); CC2520_SPI_TXRX(HI_UINT16(dest)); CC2520_SPI_TXRX(LO_UINT16(dest)); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_INS_MEMCP_COMMON * * @brief memory copy * * @param uint8 instr - * uint8 pri - * uint16 count - * uint16 src - * uint16 dest - * * @return uint8 - status byte */ static uint8 CC2520_INS_MEMCP_COMMON(uint8 instr, uint8 pri, uint16 count, \ uint16 src, uint16 dest) { uint8 s; CC2520_SPI_BEGIN(); s = CC2520_SPI_TXRX(instr | pri); CC2520_SPI_TXRX(count); CC2520_SPI_TXRX((HI_UINT16(src) << 4) | HI_UINT16(dest)); CC2520_SPI_TXRX(LO_UINT16(src)); CC2520_SPI_TXRX(LO_UINT16(dest)); CC2520_SPI_END(); return s; }
/*********************************************************************************** * @fn CC2520_MEMRD24 * * @brief Read memory 24 bits * * @param uint16 addr * * @return uint32 - result */ uint32 CC2520_MEMRD24(uint16 addr) { edword_t value; CC2520_SPI_BEGIN(); CC2520_SPI_TXRX(CC2520_INS_MEMRD | HI_UINT16(addr)); CC2520_SPI_TXRX(LO_UINT16(addr)); value.b.b0 = CC2520_SPI_TXRX(0x00); value.b.b1 = CC2520_SPI_TXRX(0x00); value.b.b2 = CC2520_SPI_TXRX(0x00); value.b.b3 = 0x00; CC2520_SPI_END(); return value.dw; }