Recycle example.cydsn/Generated_Source/PSoC5/XBEE.c
uint8_t XBEE_RxBufferRecycle(XBEE_packet_t * packet) {
    uint32_t intState;
    uint16_t i;
    
    /* Check RX state */
    if(XBEE_rxState != IDLE) {
        return XBEE_RECYCLE_BUSY;
    }
    
    /* Save interrupt state */
    intState = (*XBEE_RX_INT_INTC_SET_EN & (uint32_t)XBEE_RX_INT__INTC_MASK);
    
    /* Disable RX interrupt */
    *XBEE_RX_INT_INTC_SET_EN &= ~((uint32_t) XBEE_RX_INT__INTC_MASK);
    
    /* Check for room */
    if((XBEE_RX_BUFFER_SIZE - XBEE_RxBufferSize() - 1) < (packet->length + 4)) {
        /* Restore RX interrupt */
        *XBEE_RX_INT_INTC_SET_EN |= intState;
        return XBEE_RECYCLE_NOROOM;
    }
    
    XBEE_rxBufferWrite = XBEE_rxBufferTail;
    
    /* Write START byte */
    XBEE_rxBuffer[XBEE_rxBufferWrite] = XBEE_PACKET_START;
    
    /* Increment WRITE pointer */
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    
    /* Write LENGTH_H byte */
    XBEE_rxBuffer[XBEE_rxBufferWrite] = (uint8_t) (packet->length >> 8);
        
    /* Increment WRITE pointer */
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    
    /* Write LENGTH_L byte */
    XBEE_rxBuffer[XBEE_rxBufferWrite] = (uint8_t) (0x00FF & packet->length);
        
    /* Increment WRITE pointer */
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    
    /* Copy PAYLOAD */
    for(i=0; i<packet->length; i++) {
        XBEE_rxBuffer[XBEE_rxBufferWrite] = packet->payload[i];
        /* Increment WRITE pointer */
        XBEE_rxBufferWrite++;
        if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
            XBEE_rxBufferWrite = 0;
        }
    }
    
    /* Write CHECKSUM byte */
    XBEE_rxBuffer[XBEE_rxBufferWrite] = packet->checksum;
    
    /* Increment WRITE pointer */
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    
    /* Update TAIL pointer */
    XBEE_rxBufferTail = XBEE_rxBufferWrite;
    
    /* Restore interrupt state */
    *XBEE_RX_INT_INTC_SET_EN |= intState;
    
    /* Set PACKET and clear EMPTY status bit */
    XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_PACKET;
    XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_EMPTY;
    
    return XBEE_RECYCLE_OK;
}
/**
* Enqueue a packet in the RX buffer.
* Enqueue a packet in the XBEE_rxBuffer for other part of the code to
* handle it.
* 
* @param packet Packet to be recycled.
* @return XBEE_RECYCLE_OK: Packet recycled successfully.
* @return XBEE_RECYCLE_BUSY: Buffer is busy receiving a packet.
* @return XBEE_NOROOM: There is no empty room for the packet to by recycled.
*/
Enqueue a packet in the RX buffer.
Enqueue a packet in the XBEE_rxBuffer for other part of the code to
handle it.
Enqueue a packet in the RX buffer . Enqueue a packet in the XBEE_rxBuffer for other part of the code to handle it .
uint8_t XBEE_RxBufferRecycle(XBEE_packet_t * packet) {
    uint32_t intState;
    uint16_t i;
    if(XBEE_rxState != IDLE) {
        return XBEE_RECYCLE_BUSY;
    }
    intState = (*XBEE_RX_INT_INTC_SET_EN & (uint32_t)XBEE_RX_INT__INTC_MASK);
    *XBEE_RX_INT_INTC_SET_EN &= ~((uint32_t) XBEE_RX_INT__INTC_MASK);
    if((XBEE_RX_BUFFER_SIZE - XBEE_RxBufferSize() - 1) < (packet->length + 4)) {
        *XBEE_RX_INT_INTC_SET_EN |= intState;
        return XBEE_RECYCLE_NOROOM;
    }
    XBEE_rxBufferWrite = XBEE_rxBufferTail;
    XBEE_rxBuffer[XBEE_rxBufferWrite] = XBEE_PACKET_START;
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    XBEE_rxBuffer[XBEE_rxBufferWrite] = (uint8_t) (packet->length >> 8);
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    XBEE_rxBuffer[XBEE_rxBufferWrite] = (uint8_t) (0x00FF & packet->length);
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    for(i=0; i<packet->length; i++) {
        XBEE_rxBuffer[XBEE_rxBufferWrite] = packet->payload[i];
        XBEE_rxBufferWrite++;
        if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
            XBEE_rxBufferWrite = 0;
        }
    }
    XBEE_rxBuffer[XBEE_rxBufferWrite] = packet->checksum;
    XBEE_rxBufferWrite++;
    if(XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE) {
        XBEE_rxBufferWrite = 0;
    }
    XBEE_rxBufferTail = XBEE_rxBufferWrite;
    *XBEE_RX_INT_INTC_SET_EN |= intState;
    XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_PACKET;
    XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_EMPTY;
    return XBEE_RECYCLE_OK;
}
uint8_t XBEE_RxBufferRecycle ( XBEE_packet_t * packet ) { uint32_t intState ; uint16_t i ; if ( XBEE_rxState != IDLE ) { return XBEE_RECYCLE_BUSY ; } intState = ( * XBEE_RX_INT_INTC_SET_EN & ( uint32_t ) XBEE_RX_INT__INTC_MASK ) ; * XBEE_RX_INT_INTC_SET_EN &= ~ ( ( uint32_t ) XBEE_RX_INT__INTC_MASK ) ; if ( ( XBEE_RX_BUFFER_SIZE - XBEE_RxBufferSize ( ) - 1 ) < ( packet -> length + 4 ) ) { * XBEE_RX_INT_INTC_SET_EN |= intState ; return XBEE_RECYCLE_NOROOM ; } XBEE_rxBufferWrite = XBEE_rxBufferTail ; XBEE_rxBuffer [ XBEE_rxBufferWrite ] = XBEE_PACKET_START ; XBEE_rxBufferWrite ++ ; if ( XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE ) { XBEE_rxBufferWrite = 0 ; } XBEE_rxBuffer [ XBEE_rxBufferWrite ] = ( uint8_t ) ( packet -> length >> 8 ) ; XBEE_rxBufferWrite ++ ; if ( XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE ) { XBEE_rxBufferWrite = 0 ; } XBEE_rxBuffer [ XBEE_rxBufferWrite ] = ( uint8_t ) ( 0x00FF & packet -> length ) ; XBEE_rxBufferWrite ++ ; if ( XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE ) { XBEE_rxBufferWrite = 0 ; } for ( i = 0 ; i < packet -> length ; i ++ ) { XBEE_rxBuffer [ XBEE_rxBufferWrite ] = packet -> payload [ i ] ; XBEE_rxBufferWrite ++ ; if ( XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE ) { XBEE_rxBufferWrite = 0 ; } } XBEE_rxBuffer [ XBEE_rxBufferWrite ] = packet -> checksum ; XBEE_rxBufferWrite ++ ; if ( XBEE_rxBufferWrite == XBEE_RX_BUFFER_SIZE ) { XBEE_rxBufferWrite = 0 ; } XBEE_rxBufferTail = XBEE_rxBufferWrite ; * XBEE_RX_INT_INTC_SET_EN |= intState ; XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_PACKET ; XBEE_RX_STATUS_REG &= ~ XBEE_RX_STATUS_EMPTY ; return XBEE_RECYCLE_OK ; }
Enqueue a packet in the RX buffer.
Enqueue a packet in the RX buffer .
/* Check RX state */ /* Save interrupt state */ /* Disable RX interrupt */ /* Check for room */ /* Restore RX interrupt */ /* Write START byte */ /* Increment WRITE pointer */ /* Write LENGTH_H byte */ /* Increment WRITE pointer */ /* Write LENGTH_L byte */ /* Increment WRITE pointer */ /* Copy PAYLOAD */ /* Increment WRITE pointer */ /* Write CHECKSUM byte */ /* Increment WRITE pointer */ /* Update TAIL pointer */ /* Restore interrupt state */ /* Set PACKET and clear EMPTY status bit */