Example #1
0
/*! \brief  This function will download a frame to the radio transceiver's frame
 *          buffer.
 *
 *  \param  write_buffer    Pointer to data that is to be written to frame buffer.
 *  \param  length          Length of data. The maximum length is 127 bytes.
 *
 */
void hal_frame_write(u8 *write_buffer, u8 length)
{
#ifdef SINGLE_CHIP
   volatile uint8_t *pDst = (volatile uint8_t *)0x180;

   AVR_ENTER_CRITICAL_REGION();

   //Toggle the SLP_TR pin to initiate the frame transmission.
   hal_set_slptr_high();
   hal_set_slptr_low();

   *pDst = length;
   pDst++;
   memcpy((void *)pDst, write_buffer, length);

   AVR_LEAVE_CRITICAL_REGION();
#else

   length &= HAL_TRX_CMD_RADDRM; //Truncate length to maximum frame length.

   AVR_ENTER_CRITICAL_REGION();

   //Toggle the SLP_TR pin to initiate the frame transmission.
   hal_set_slptr_high();
   hal_set_slptr_low();

   HAL_SS_LOW(); //Initiate the SPI transaction.

   /*SEND FRAME WRITE COMMAND AND FRAME LENGTH.*/
   SPDR = HAL_TRX_CMD_FW;
   while ((SPSR & (1 << SPIF)) == 0) {;}
   SPDR; // Dummy read of SPDR

   SPDR = length;
   while ((SPSR & (1 << SPIF)) == 0) {;}
   SPDR;  // Dummy read of SPDR

   // Download to the Frame Buffer.
   do
   {
      SPDR = *write_buffer++;
      --length;

      while ((SPSR & (1 << SPIF)) == 0)
         ;

      SPDR;  // Dummy read of SPDR
   } while (length > 0);

   HAL_SS_HIGH(); //Terminate SPI transaction.

   AVR_LEAVE_CRITICAL_REGION();

#endif //SINGLE_CHIP
}
U8 drvr_tx(const buffer_t *buf)
{
    U8 state = drvr_get_trx_state();

    if ((state == BUSY_TX) || (state == BUSY_TX_ARET))
    {
        return RADIO_WRONG_STATE;
    }

    // TODO: check why we need to transition to the off state before we go to tx_aret_on
    drvr_set_trx_state(TRX_OFF);
    drvr_set_trx_state(TX_ARET_ON);

    // TODO: try and start the frame transmission by writing TX_START command instead of toggling
    // sleep pin...i just feel like it's kind of weird...

    // write frame to buffer
    hal_frame_write(buf->dptr, buf->len);

    // TEST - check data in buffer
    //{
    //    U8 tmp[30];
    //
    //    hal_sram_read(0, buf->len, tmp);
    //    debug_dump_buf(tmp, buf->len);
    //}
    // TEST

    //Do frame transmission. Toggle the SLP_TR pin to initiate the frame transmission.
    hal_set_slptr_high();
    hal_set_slptr_low();

    // TODO: if we're in extended operating mode, check for ACK or NO_ACK return codes...
    return RADIO_SUCCESS;
}
Example #3
0
/*! \brief  This function will download a frame to the radio transceiver's frame
 *          buffer.
 *
 *  \param  write_buffer    Pointer to data that is to be written to frame buffer.
 *  \param  length          Length of data. The maximum length is 127 bytes.
 *
 */
void radio_frame_write(u8 *write_buffer, u8 length)
{
    length &= HAL_TRX_CMD_RADDRM; //Truncate length to maximum frame length.

    AVR_ENTER_CRITICAL_REGION();

    //Toggle the SLP_TR pin to initiate the frame transmission.
    hal_set_slptr_high();
    hal_set_slptr_low();

    RADIO_DEVSEL_L(); //Initiate the SPI transaction.

    /*SEND FRAME WRITE COMMAND AND FRAME LENGTH.*/
    SPDR = HAL_TRX_CMD_FW;
    while ((SPSR & (1 << SPIF)) == 0) {;}
    SPDR; // Dummy read of SPDR

    SPDR = length;
    while ((SPSR & (1 << SPIF)) == 0) {;}
    SPDR;  // Dummy read of SPDR

    // Download to the Frame Buffer.
    do
    {
        SPDR = *write_buffer++;
        --length;

        while ((SPSR & (1 << SPIF)) == 0)
            ;

        SPDR;  // Dummy read of SPDR
    } while (length > 0);

    RADIO_DEVSEL_H(); //Terminate SPI transaction.

    AVR_LEAVE_CRITICAL_REGION();
}