Ejemplo n.º 1
0
static void chb_frame_read()
{
    U8 i, len, data;

    CHB_ENTER_CRIT();
    CHB_SPI_ENABLE();

    /*Send frame read command and read the length.*/
    chb_xfer_byte(CHB_SPI_CMD_FR);
    len = chb_xfer_byte(0);

    /*Check for correct frame length.*/

    // TODO: CHECK FOR THE CRC VALID BIT TO QUALIFY THE FRAME
    // check the length of the frame to make sure the incoming frame
    // doesn't overflow the buffer
    if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH))
    {
        chb_buf_write(len);
        
        for (i=0; i<len; i++)
        {
            data = chb_xfer_byte(0);
            chb_buf_write(data);
        }
    }

    CHB_SPI_DISABLE();
    CHB_LEAVE_CRIT();
}
Ejemplo n.º 2
0
static void chb_frame_read()
{
    U8 i, len, data;

    CHB_ENTER_CRIT();
    RadioCS(TRUE);

    /*Send frame read command and read the length.*/
    SPID_write(CHB_SPI_CMD_FR);
    len = SPID_write(0);

    /*Check for correct frame length.*/
    if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH))
    {
        // check to see if there is room to write the frame in the buffer. if not, then drop it
        if (len < (CHB_BUF_SZ - chb_buf_get_len()))
        {
            chb_buf_write(len);
            
            for (i=0; i<len; i++)
            {
                data = SPID_write(0);
                chb_buf_write(data);
            }
			//generate message received event here
			//EVSYS.STROBE = 0x04;  //generate event on channel 3
			//generate interrupt on port E by toggling pin 2
			//PORTE.OUTSET = PIN2_bm;
			//PORTE.OUTCLR = PIN2_bm;
        }
        else
        {
            // we've overflowed the buffer. toss the data and do some housekeeping
            pcb_t *pcb = chb_get_pcb();
            //char buf[50];

            // read out the data and throw it away
            for (i=0; i<len; i++)
            {
                data = SPID_write(0);
            }

            // Increment the overflow stat
            pcb->overflow++;

            // grab the message from flash & print it out
            //strcpy_P(buf, chb_err_overflow);
            //printf(buf);
        }
    }

    RadioCS(FALSE);
    CHB_LEAVE_CRIT();
}
Ejemplo n.º 3
0
static void chb_frame_read()
{
    U8 i, len, data;

    CHB_ENTER_CRIT();
    CHB_SPI_ENABLE();

    /*Send frame read command and read the length.*/
    chb_xfer_byte(CHB_SPI_CMD_FR);
    len = chb_xfer_byte(0);

    // check the length of the frame to make sure its within the correct size limits
    if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH))
    {
        // check to see if there is room to write the frame in the buffer. if not, then drop it
        if (len < (CHB_BUF_SZ - chb_buf_get_len()))
        {
            chb_buf_write(len);

            for (i=0; i<len; i++)
            {
                data = chb_xfer_byte(0);
                chb_buf_write(data);
            }
        }
        else
        {
            // this frame will overflow the buffer. toss the data and do some housekeeping
            pcb_t *pcb = chb_get_pcb();
            char buf[50];

            // read out the data and throw it away
            for (i=0; i<len; i++)
            {
                data = chb_xfer_byte(0);
            }

            // Increment the overflow stat, and print a message.
            pcb->overflow++;

            // grab the message from flash & print it out
            strcpy_P(buf, chb_err_overflow);
            Serial.print(buf);
        }
    }

    CHB_SPI_DISABLE();
    CHB_LEAVE_CRIT();
}
Ejemplo n.º 4
0
static void chb_frame_read()
{
    U8 i, len, data;

    // CHB_ENTER_CRIT();
    CHB_SPI_ENABLE();

    /*Send frame read command and read the length.*/
    chb_xfer_byte(CHB_SPI_CMD_FR);
    len = chb_xfer_byte(0);

    /*Check for correct frame length.*/
    if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH))
    {
        // check to see if there is room to write the frame in the buffer. if not, then drop it
        if (len < (CFG_CHIBI_BUFFERSIZE - chb_buf_get_len()))
        {
            chb_buf_write(len);
            
            for (i=0; i<len; i++)
            {
                data = chb_xfer_byte(0);
                chb_buf_write(data);
            }
        }
        else
        {
            // we've overflowed the buffer. toss the data and do some housekeeping
            chb_pcb_t *pcb = chb_get_pcb();

            // read out the data and throw it away
            for (i=0; i<len; i++)
            {
                data = chb_xfer_byte(0);
            }

            // Increment the overflow stat
            pcb->overflow++;

            // print the error message
            printf(chb_err_overflow);
        }
    }

    CHB_SPI_DISABLE();
    CHB_LEAVE_CRIT();
}