void comm_cc2520_init(void) { tx_slot_read = 0; tx_slot_write = 0; // rf halAssyInit(); basicRfConfig.panId = CC2520_PAN_ID; basicRfConfig.channel = CC2520_RF_CHANNEL; basicRfConfig.ackRequest = FALSE; basicRfConfig.myAddr = CC2520_NODE_ADDRESS; #ifdef SECURITY_CCM basicRfConfig.securityKey = rf_security_key; #endif if(basicRfInit(&basicRfConfig) == FAILED) { for(;;) {} } basicRfReceiveOn(); chThdCreateStatic(rx_thread_wa, sizeof(rx_thread_wa), NORMALPRIO, rx_thread, NULL); chThdCreateStatic(tx_thread_wa, sizeof(tx_thread_wa), NORMALPRIO, tx_thread, NULL); }
void rfRecvData(void) { uint8 pRxData[128]; int rlen; basicRfReceiveOn(); // Main loop while (TRUE) { while(!basicRfPacketIsReady()); rlen = basicRfReceive(pRxData, sizeof pRxData, NULL); if(rlen > 0) { pRxData[rlen] = 0; printf("%s rssi: %d\r\n", (char *)pRxData, basicRfGetRssi()); } } }
void rfRecvData(void) { uint8 pRxData[128]; int rlen; basicRfReceiveOn(); printf("recv msg start...\r\n"); // Main loop while (TRUE) { while(!basicRfPacketIsReady()); rlen = basicRfReceive(pRxData, sizeof pRxData, NULL); if(rlen > 0) { printf("recv msg ok...\r\n"); pRxData[rlen] = 0; printf((char *)pRxData); } } }
/*********************************************************************************** * @fn main */ void main(void) { // Initalise board peripherals halBoardInit(); basicRfSetUp(); // Initalise hal_rf if(halRfInit()==FAILED) { HAL_ASSERT(FALSE); } // Indicate that device is powered halLedSet(1); halMcuWaitMs(350); configureUSART0forUART_ALT1(); uartStartRxForIsr(); while(TRUE) { //---------------------- // INITIALIZE //---------------------- if(initFlag) { while(!start); //waiting for 'a' key from PC //respond to PC -- going to try to start up WRS start=0; pTxData[0] = INIT_COMM_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { state=1; } basicRfReceiveOn(); //wait for ACK from WRS pTxData[0] = INIT_COEF_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { basicRfReceiveOn(); //WAIT FOR COEFFICIENTS FROM WRS while(!basicRfPacketIsReady());//wait to receive acknowledgement if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) { if(pRxData[0] == 'C') { //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } //finished sending coefficients to PC basicRfReceiveOn(); initFlag=0; } if(turnOnMotorFlag){ if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS { turnOnMotorFlag=0; } } if(sendInitFlag){ if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS { initFlag=1; sendInitFlag=0; //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { pRxData[0] == 'R'; U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } //Receive package from WRS if(basicRfPacketIsReady()) { if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) { getRSSI = basicRfGetRssi(); pRxData[104]=getRSSI; if(pRxData[0] == 'D')//||(pRxData[0] == 'I')) { //SEND DATA TO PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } } }
/*********************************************************************************** * @fn main */ void main(void) { // Initalise board peripherals halBoardInit(); basicRfSetUp(); // Initalise hal_rf if(halRfInit()==FAILED) { HAL_ASSERT(FALSE); } // Indicate that device is powered halLedSet(1); halMcuWaitMs(350); configureUSART0forUART_ALT1(); uartStartRxForIsr(); while(!start); //waiting for 'a' key from PC //respond to PC -- going to try to start up WRS pTxData[0] = INIT_COMM_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { state=1; } basicRfReceiveOn(); //wait for ACK from WRS pTxData[0] = INIT_COEF_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { basicRfReceiveOn(); state=2;//continuous? //WAIT FOR COEFFICIENTS FROM WRS while(!basicRfPacketIsReady());//wait to receive acknowledgement if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) { if(pRxData[0] == 'C') { //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } // while(!ACK);//waiting for acknowledgement } } } //finished sending coefficients to PC basicRfReceiveOn(); while(TRUE) { //Receive package from WRS if(basicRfPacketIsReady()) { if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) { getRSSI = basicRfGetRssi(); pRxData[104]=getRSSI; if((pRxData[0] == 'P')||(pRxData[0] == 'A')) { //SEND DATA TO PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } //Receive CMD from PC if(changePWMflag)//have this be set in interrupt { //basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS { changePWMflag=0; } //basicRfReceiveOn(); // while(changePWMflag)//Keep receiving until PWM acknowledge is sent // { // while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think // // if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) // { // if(pRxData[0] == 'Z') // { // //receive current duty cycle and send back to PC // for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) // { // U0CSR &= ~0x02; //SET U0TX_BYTE to 0 // U0DBUF = pRxData[uartTxIndex]; // while (!(U0CSR&0x02)); // } // changePWMflag = 0; // } // //else send pressure? // } // } // } } }//END OF MAIN WHILE LOOP }