void trxWriteFrameBuffer(MacPacket packet) {

    unsigned int i;
    unsigned char phy_len;
    Payload pld;

    // Linearize contents in buffer
    i = 0;
    phy_len = packet->payload_length + MAC_HEADER_LENGTH + CRC_LENGTH;

    frame_buffer[i++] = phy_len; //packet->payload_length + MAC_HEADER_LENGTH + CRC_LENGTH;
    frame_buffer[i++] = packet->frame_ctrl.val.byte.LB;
    frame_buffer[i++] = packet->frame_ctrl.val.byte.HB;
    frame_buffer[i++] = packet->seq_num;
    frame_buffer[i++] = packet->dest_pan_id.byte.LB;
    frame_buffer[i++] = packet->dest_pan_id.byte.HB;
    frame_buffer[i++] = packet->dest_addr.byte.LB;
    frame_buffer[i++] = packet->dest_addr.byte.HB;
    frame_buffer[i++] = packet->src_addr.byte.LB;
    frame_buffer[i++] = packet->src_addr.byte.HB;

    pld = macGetPayload(packet);
    if(pld == NULL) { return; }

    memcpy(frame_buffer + i, payToString(pld), payGetPayloadLength(pld));

    spic1BeginTransaction();
    spic1Transmit(TRX_CMD_FW);
    spic1MassTransmit(phy_len, frame_buffer, phy_len*3); // 3*length microseconds timeout seems to work well

}
Esempio n. 2
0
//Recieved radio packet, send over UART
void xbeeHandleRx(MacPacket packet) {

    int i;
    unsigned char checksum;
    unsigned char pld_len = payGetPayloadLength(packet->payload);
    unsigned char* pld_str = payToString(packet->payload);
    unsigned char xb_frame_len = pld_len + XB_OVERHEAD_LENGTH;
    WordVal src_addr = packet->src_addr;

    dmaTxReady = 0;
    checksum = XB_API_ID;
    checksum += src_addr.byte.HB;
    checksum += src_addr.byte.LB;

    //CRITICAL_SECTION_START
        txBufferA[0] = XB_RX_START;     //Start Byte
        txBufferA[1] = 0x00; 	        //Length High Byte
        txBufferA[2] = xb_frame_len;	//Length Low Byte
        txBufferA[3] = XB_API_ID;       //API Identifier - Currently only support the RX type
        txBufferA[4] = src_addr.byte.HB;    //Source Address High byte
        txBufferA[5] = src_addr.byte.LB;    //Source Address Low Byte
        txBufferA[6] = radioGetLastRSSI();	        //'RSSI' Not currently implemented
        txBufferA[7] = 0x00;            //'Options' Not currently implemented

        for(i = 0; i < pld_len; i++) {
            checksum += pld_str[i];
            txBufferA[RX_FRAME_OFFSET + i] = pld_str[i];
        }

        txBufferA[RX_FRAME_OFFSET + pld_len] = 0xFF - checksum;	//set Checksum byte
    //CRITICAL_SECTION_END

    // pld_len + RX_FRAME_OFFSET + length(CHKSUM) - 1
    DMA6CNT = pld_len + RX_FRAME_OFFSET;
    DMA6CONbits.CHEN = 1;
    DMA6REQbits.FORCE = 1;

}