关于CC1310的例rfwsnconcentrator程
我将rfwsnNode中的 sendDmPacket()移植到rfwsnconcentrator中,并用按键控制,本意是想按一次键发一次数据,可是每次按键都会发送失败,显示[Cortex_M3_0] EasyLink_transmit failed 。并且我试过用sendack发送,也是失败。请问这是什么有原因呢?
void buttonCallback(PIN_Handle handle, PIN_Id pinId) { /* Debounce logic, only toggle if the button is still pushed (low) */ // CPUdelay(8000*50); if (PIN_getInputValue(Board_BUTTON0) == 0) { //Semaphore_pend(radioAccessSemHandle, BIOS_WAIT_FOREVER); txdata++; nodeaddress=knownSensorNodes[txdata].address; PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1)); /* Send ack packet */ sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS); //Semaphore_post(radioAccessSemHandle); }
贴出完整代码
/* * Copyright (c) 2015-2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***** Includes *****/ #include <xdc/std.h> #include <xdc/runtime/System.h> #include "ConcentratorRadioTask.h" #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Event.h> /* Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> /* Board Header files */ #include "Board.h" #include "easylink/EasyLink.h" #include "RadioProtocol.h" /***** Defines *****/ #define CONCENTRATORRADIO_TASK_STACK_SIZE 1024 #define CONCENTRATORRADIO_TASK_PRIORITY 3 #define RADIO_EVENT_ALL 0xFFFFFFFF #define RADIO_EVENT_VALID_PACKET_RECEIVED (uint32_t)(1 << 0) #define RADIO_EVENT_INVALID_PACKET_RECEIVED (uint32_t)(1 << 1) #define CONCENTRATORRADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) #define CONCENTRATOR_ACTIVITY_LED Board_LED0 /***** Type declarations *****/ //add by me--begin enum NodeRadioOperationStatus { NodeRadioStatus_Success, NodeRadioStatus_Failed, NodeRadioStatus_FailedNotConnected, }; struct RadioOperation { EasyLink_TxPacket easyLinkTxPacket; uint8_t retriesDone; uint8_t maxNumberOfRetries; uint32_t ackTimeoutMs; enum NodeRadioOperationStatus result; }; //add by me --end /***** Variable declarations *****/ static Task_Params concentratorRadioTaskParams; Task_Struct concentratorRadioTask; /* not static so you can see in ROV */ static uint8_t concentratorRadioTaskStack[CONCENTRATORRADIO_TASK_STACK_SIZE]; Event_Struct radioOperationEvent; /* not static so you can see in ROV */ static Event_Handle radioOperationEventHandle; //add by me--begin static struct DualModeSensorPacket dmSensorPacket; static struct RadioOperation currentRadioOperation; Event_Struct OperationEvent; /* not static so you can see in ROV */ static Event_Handle OperationEventHandle; //add by me --end static ConcentratorRadio_PacketReceivedCallback packetReceivedCallback; static union ConcentratorPacket latestRxPacket; static EasyLink_TxPacket txPacket; static struct AckPacket ackPacket; static uint8_t concentratorAddress; static int8_t latestRssi; /***** Prototypes *****/ static void concentratorRadioTaskFunction(UArg arg0, UArg arg1); static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status); static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket); static void sendAck(uint8_t latestSourceAddress); static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs); void buttonCallback(PIN_Handle handle, PIN_Id pinId); /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; //add by me--begin #define NODERADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; //static uint8_t txevents= 0; //add by me--end /* Configure LED Pin */ PIN_Config ledPinTable[] = { CONCENTRATOR_ACTIVITY_LED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me PIN_TERMINATE }; //add by me --begin PIN_Config buttonPinTable[] = { Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON3 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON4 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE }; //add by me--end /***** Function definitions *****/ void ConcentratorRadioTask_init(void) { /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if (!ledPinHandle) { System_abort("Error initializing board 3.3V domain pins\n"); } buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable); if (!buttonPinHandle) { System_abort("Error initializing button pins\n"); } /* Create event used internally for state changes */ Event_Params eventParam; Event_Params_init(&eventParam); Event_construct(&radioOperationEvent, &eventParam); radioOperationEventHandle = Event_handle(&radioOperationEvent); Event_construct(&OperationEvent, &eventParam); OperationEventHandle = Event_handle(&OperationEvent); /* Create the concentrator radio protocol task */ Task_Params_init(&concentratorRadioTaskParams); concentratorRadioTaskParams.stackSize = CONCENTRATORRADIO_TASK_STACK_SIZE; concentratorRadioTaskParams.priority = CONCENTRATORRADIO_TASK_PRIORITY; concentratorRadioTaskParams.stack = &concentratorRadioTaskStack; Task_construct(&concentratorRadioTask, concentratorRadioTaskFunction, &concentratorRadioTaskParams, NULL); } void ConcentratorRadioTask_registerPacketReceivedCallback(ConcentratorRadio_PacketReceivedCallback callback) { packetReceivedCallback = callback; } static void concentratorRadioTaskFunction(UArg arg0, UArg arg1) { /* Initialize EasyLink */ if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) { System_abort("EasyLink_init failed"); } /* Set frequency */ if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) { System_abort("EasyLink_setFrequency failed"); } /* Set concentrator address */; concentratorAddress = RADIO_CONCENTRATOR_ADDRESS; EasyLink_enableRxAddrFilter(&concentratorAddress, 1, 1); /* Set up Ack packet */ ackPacket.header.sourceAddress = concentratorAddress; ackPacket.header.packetType = RADIO_PACKET_TYPE_ACK_PACKET; if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0) { System_abort("Error registering button callback function"); } /* Enter receive */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } while (1) { uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); uint32_t txevents = Event_pend(OperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); if(txevents & RADIO_EVENT_VALID_PACKET_RECEIVED) { sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS); /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); //txevents=0; } /* If valid packet received */ if(events & RADIO_EVENT_VALID_PACKET_RECEIVED) { /* Send ack packet */ sendAck(latestRxPacket.header.sourceAddress); /* Call packet received callback */ notifyPacketReceived(&latestRxPacket); /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); } /* If invalid packet received */ if(events & RADIO_EVENT_INVALID_PACKET_RECEIVED) { /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } } } } static void sendAck(uint8_t latestSourceAddress) { /* Set destinationAdress, but use EasyLink layers destination adress capability */ txPacket.dstAddr[0] = latestSourceAddress; /* Copy ACK packet to payload, skipping the destination adress byte. * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(txPacket.payload, &ackPacket.header, sizeof(ackPacket)); txPacket.len = sizeof(ackPacket); /* Send packet */ if (EasyLink_transmit(&txPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } } static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket) { if (packetReceivedCallback) { packetReceivedCallback(latestRxPacket, latestRssi); } } static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status) { union ConcentratorPacket* tmpRxPacket; /* If we received a packet successfully */ if (status == EasyLink_Status_Success) { /* Save the latest RSSI, which is later sent to the receive callback */ latestRssi = (int8_t)rxPacket->rssi; /* Check that this is a valid packet */ tmpRxPacket = (union ConcentratorPacket*)(rxPacket->payload); /* If this is a known packet */ if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_ADC_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct AdcSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_DM_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct DualModeSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } void buttonCallback(PIN_Handle handle, PIN_Id pinId) { /* Debounce logic, only toggle if the button is still pushed (low) */ // CPUdelay(8000*50); if (PIN_getInputValue(Board_BUTTON0) == 0) { Event_post(OperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); // txevents=1; PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1)); } if (PIN_getInputValue(Board_BUTTON1) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2)); } if (PIN_getInputValue(Board_BUTTON2) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON3) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON4) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } } static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) { /* Set destination address in EasyLink API */ currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0; /* Copy ADC packet to payload * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket)); currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket); /* Setup retries */ currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries; currentRadioOperation.ackTimeoutMs = ackTimeoutMs; currentRadioOperation.retriesDone = 0; EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs)); /* Send packet */ if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } /* Enter RX */ if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } }
我觉得我加入的这个事件可能有些问题,请大神指导
/* * Copyright (c) 2015-2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***** Includes *****/ #include <xdc/std.h> #include <xdc/runtime/System.h> #include "ConcentratorRadioTask.h" #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Event.h> #include <driverlib/aon_batmon.h> /* Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> /* Board Header files */ #include "Board.h" #include "easylink/EasyLink.h" #include "RadioProtocol.h" /***** Defines *****/ #define CONCENTRATORRADIO_TASK_STACK_SIZE 1024 #define CONCENTRATORRADIO_TASK_PRIORITY 3 #define RADIO_EVENT_ALL 0xFFFFFFFF #define RADIO_EVENT_VALID_PACKET_RECEIVED (uint32_t)(1 << 0) #define RADIO_EVENT_INVALID_PACKET_RECEIVED (uint32_t)(1 << 1) #define CONCENTRATORRADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) #define CONCENTRATOR_ACTIVITY_LED Board_LED0 /***** Type declarations *****/ //add by me--begin enum NodeRadioOperationStatus { NodeRadioStatus_Success, NodeRadioStatus_Failed, NodeRadioStatus_FailedNotConnected, }; struct RadioOperation { EasyLink_TxPacket easyLinkTxPacket; uint8_t retriesDone; uint8_t maxNumberOfRetries; uint32_t ackTimeoutMs; enum NodeRadioOperationStatus result; }; //add by me --end /***** Variable declarations *****/ static Task_Params concentratorRadioTaskParams; Task_Struct concentratorRadioTask; /* not static so you can see in ROV */ static uint8_t concentratorRadioTaskStack[CONCENTRATORRADIO_TASK_STACK_SIZE]; Event_Struct radioOperationEvent; /* not static so you can see in ROV */ static Event_Handle radioOperationEventHandle; //add by me--begin static struct DualModeSensorPacket dmSensorPacket; static struct RadioOperation currentRadioOperation; Event_Struct OperationEvent; /* not static so you can see in ROV */ static Event_Handle OperationEventHandle; //add by me --end static ConcentratorRadio_PacketReceivedCallback packetReceivedCallback; static union ConcentratorPacket latestRxPacket; static EasyLink_TxPacket txPacket; static struct AckPacket ackPacket; static uint8_t concentratorAddress; static int8_t latestRssi; /***** Prototypes *****/ static void concentratorRadioTaskFunction(UArg arg0, UArg arg1); static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status); static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket); static void sendAck(uint8_t latestSourceAddress); static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs); void buttonCallback(PIN_Handle handle, PIN_Id pinId); static void TxcontrolTaskFunction(UArg arg0, UArg arg1); /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; //add by me--begin /***** Defines *****/ #define TXCONTROL_TASK_STACK_SIZE 1024 #define TXCONTROL_TASK_PRIORITY 2 static Task_Params TxcontrolTaskParams; Task_Struct TxcontrolTask; /* not static so you can see in ROV */ static uint8_t TxcontrolTaskStack[TXCONTROL_TASK_STACK_SIZE]; #define NODERADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; static uint32_t prevTicks; //static uint8_t txevents= 0; //add by me--end /* Configure LED Pin */ PIN_Config ledPinTable[] = { CONCENTRATOR_ACTIVITY_LED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me PIN_TERMINATE }; //add by me --begin PIN_Config buttonPinTable[] = { Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON3 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON4 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE }; //add by me--end /***** Function definitions *****/ void ConcentratorRadioTask_init(void) { /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if (!ledPinHandle) { System_abort("Error initializing board 3.3V domain pins\n"); } buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable); if (!buttonPinHandle) { System_abort("Error initializing button pins\n"); } /* Create event used internally for state changes */ Event_Params eventParam; Event_Params_init(&eventParam); Event_construct(&radioOperationEvent, &eventParam); radioOperationEventHandle = Event_handle(&radioOperationEvent); Event_construct(&OperationEvent, &eventParam); OperationEventHandle = Event_handle(&OperationEvent); /* Create the concentrator radio protocol task */ Task_Params_init(&concentratorRadioTaskParams); concentratorRadioTaskParams.stackSize = CONCENTRATORRADIO_TASK_STACK_SIZE; concentratorRadioTaskParams.priority = CONCENTRATORRADIO_TASK_PRIORITY; concentratorRadioTaskParams.stack = &concentratorRadioTaskStack; Task_construct(&concentratorRadioTask, concentratorRadioTaskFunction, &concentratorRadioTaskParams, NULL); /* Create the concentrator radio protocol task */ Task_Params_init(&TxcontrolTaskParams); TxcontrolTaskParams.stackSize = TXCONTROL_TASK_STACK_SIZE; TxcontrolTaskParams.priority = TXCONTROL_TASK_PRIORITY; TxcontrolTaskParams.stack = &TxcontrolTaskStack; Task_construct(&TxcontrolTask, TxcontrolTaskFunction, &TxcontrolTaskParams, NULL); } void ConcentratorRadioTask_registerPacketReceivedCallback(ConcentratorRadio_PacketReceivedCallback callback) { packetReceivedCallback = callback; } static void concentratorRadioTaskFunction(UArg arg0, UArg arg1) { /* Initialize EasyLink */ if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) { System_abort("EasyLink_init failed"); } /* Set frequency */ if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) { System_abort("EasyLink_setFrequency failed"); } /* Set concentrator address */; concentratorAddress = RADIO_CONCENTRATOR_ADDRESS; EasyLink_enableRxAddrFilter(&concentratorAddress, 1, 1); /* Set up Ack packet */ ackPacket.header.sourceAddress = concentratorAddress; ackPacket.header.packetType = RADIO_PACKET_TYPE_ACK_PACKET; /* Enter receive */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } while (1) { uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); /* If valid packet received */ if(events & RADIO_EVENT_VALID_PACKET_RECEIVED) { /* Send ack packet */ sendAck(latestRxPacket.header.sourceAddress); /* Call packet received callback */ notifyPacketReceived(&latestRxPacket); /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); } /* If invalid packet received */ if(events & RADIO_EVENT_INVALID_PACKET_RECEIVED) { /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } } } } static void TxcontrolTaskFunction(UArg arg0, UArg arg1){ /* Setup ADC sensor packet */ // dmSensorPacket.header.sourceAddress = RADIO_CONCENTRATOR_ADDRESS; dmSensorPacket.header.sourceAddress =1; dmSensorPacket.header.packetType = RADIO_PACKET_TYPE_DM_SENSOR_PACKET; /* Initialise previous Tick count used to calculate uptime for the TLM beacon */ prevTicks = Clock_getTicks(); dmSensorPacket.batt = AONBatMonBatteryVoltageGet(); dmSensorPacket.button = !PIN_getInputValue(Board_BUTTON0); dmSensorPacket.time100MiliSec=prevTicks; /* Setup callback for button pins */ if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0) { System_abort("Error registering button callback function"); } while(1) { uint32_t txevents = Event_pend(OperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); if(txevents & RADIO_EVENT_VALID_PACKET_RECEIVED) { sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS); /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); //txevents=0; } } } static void sendAck(uint8_t latestSourceAddress) { /* Set destinationAdress, but use EasyLink layers destination adress capability */ txPacket.dstAddr[0] = latestSourceAddress; /* Copy ACK packet to payload, skipping the destination adress byte. * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(txPacket.payload, &ackPacket.header, sizeof(ackPacket)); txPacket.len = sizeof(ackPacket); /* Send packet */ if (EasyLink_transmit(&txPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } } static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket) { if (packetReceivedCallback) { packetReceivedCallback(latestRxPacket, latestRssi); } } static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status) { union ConcentratorPacket* tmpRxPacket; /* If we received a packet successfully */ if (status == EasyLink_Status_Success) { /* Save the latest RSSI, which is later sent to the receive callback */ latestRssi = (int8_t)rxPacket->rssi; /* Check that this is a valid packet */ tmpRxPacket = (union ConcentratorPacket*)(rxPacket->payload); /* If this is a known packet */ if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_ADC_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct AdcSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_DM_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct DualModeSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } void buttonCallback(PIN_Handle handle, PIN_Id pinId) { /* Debounce logic, only toggle if the button is still pushed (low) */ // CPUdelay(8000*50); if (PIN_getInputValue(Board_BUTTON0) == 0) { Event_post(OperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); // txevents=1; PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1)); } if (PIN_getInputValue(Board_BUTTON1) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2)); } if (PIN_getInputValue(Board_BUTTON2) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON3) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON4) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } } static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) { /* Set destination address in EasyLink API */ currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0; /* Copy ADC packet to payload * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket)); currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket); /* Setup retries */ currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries; currentRadioOperation.ackTimeoutMs = ackTimeoutMs; currentRadioOperation.retriesDone = 0; EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs)); /* Send packet */ if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } /* Enter RX */ if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } }
是这一个,上一个是无法接收信号,已改
问题解决了?
没有解决,第二个上传的程序是我现在的问题,按键操作发送信号,会有发送失败EasyLink_transmit failed弹出在窗口,是天线冲突的问题吗?怎么解决呢?
收发不可同步
我试过用互斥信号量来解决,没有作用,还有什么方式来解决同步问题呢?
你问下技术支持,回复快点。
怎么问技术支持啊,求指导
你用这个芯片,应该有供应商与你们公司合作吧。供应商那边一般有技术支持的,打电话问问。
哦哦,好吧谢谢
请问你发送函数有没有中断?因为你按键一次就代表进入中断了,如果在发送函数也进入另外一种中断,会有不明确的事情发送。通过按键发送,这个功能是比较简单久可以实现的,提供我的思路:用even事件来触发,按键一次,进入按键中断,标志even事件,在task函数里检测是否有even事件发生,有的话,就在task函数里写发送函数。
您好:
我用的是按键发送一个OperationEventHandle事件,并且也进入了sendDmPacket()函数(这个函数是从rfWSNnode里面移植过来的),然后窗口中即出现了发送失败[Cortex_M3_0] EasyLink_transmit failed,我觉得可能是收发同时所以出现了问题,所以加了semHandle用来作为互斥信号量,可是依然发送失败,怎么解决呢?求指导,谢谢
源代码如下所示:
/* * Copyright (c) 2015-2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***** Includes *****/ #include <xdc/std.h> #include <xdc/runtime/System.h> #include "ConcentratorRadioTask.h" #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Event.h> #include <driverlib/aon_batmon.h> /* Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> /* Board Header files */ #include "Board.h" #include "easylink/EasyLink.h" #include "RadioProtocol.h" /***** Defines *****/ #define CONCENTRATORRADIO_TASK_STACK_SIZE 1024 #define CONCENTRATORRADIO_TASK_PRIORITY 3 #define RADIO_EVENT_ALL 0xFFFFFFFF #define RADIO_EVENT_VALID_PACKET_RECEIVED (uint32_t)(1 << 0) #define RADIO_EVENT_INVALID_PACKET_RECEIVED (uint32_t)(1 << 1) #define CONCENTRATORRADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) #define CONCENTRATOR_ACTIVITY_LED Board_LED0 /***** Type declarations *****/ //add by me--begin enum NodeRadioOperationStatus { NodeRadioStatus_Success, NodeRadioStatus_Failed, NodeRadioStatus_FailedNotConnected, }; struct RadioOperation { EasyLink_TxPacket easyLinkTxPacket; uint8_t retriesDone; uint8_t maxNumberOfRetries; uint32_t ackTimeoutMs; enum NodeRadioOperationStatus result; }; //add by me --end /***** Variable declarations *****/ static Task_Params concentratorRadioTaskParams; Task_Struct concentratorRadioTask; /* not static so you can see in ROV */ static uint8_t concentratorRadioTaskStack[CONCENTRATORRADIO_TASK_STACK_SIZE]; Event_Struct radioOperationEvent; /* not static so you can see in ROV */ static Event_Handle radioOperationEventHandle; //add by me--begin static struct DualModeSensorPacket dmSensorPacket; static struct RadioOperation currentRadioOperation; Event_Struct OperationEvent; /* not static so you can see in ROV */ static Event_Handle OperationEventHandle; //add by me --end static ConcentratorRadio_PacketReceivedCallback packetReceivedCallback; static union ConcentratorPacket latestRxPacket; static EasyLink_TxPacket txPacket; static struct AckPacket ackPacket; static uint8_t concentratorAddress; static int8_t latestRssi; /***** Prototypes *****/ static void concentratorRadioTaskFunction(UArg arg0, UArg arg1); static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status); static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket); static void sendAck(uint8_t latestSourceAddress); static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs); void buttonCallback(PIN_Handle handle, PIN_Id pinId); static void TxcontrolTaskFunction(UArg arg0, UArg arg1); /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; //add by me--begin /***** Defines *****/ #define TXCONTROL_TASK_STACK_SIZE 1024 #define TXCONTROL_TASK_PRIORITY 3 static Task_Params TxcontrolTaskParams; Task_Struct TxcontrolTask; /* not static so you can see in ROV */ static uint8_t TxcontrolTaskStack[TXCONTROL_TASK_STACK_SIZE]; #define NODERADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; static uint32_t prevTicks; //static uint8_t txevents= 0; Semaphore_Struct semStruct; Semaphore_Handle semHandle; //add by me--end /* Configure LED Pin */ PIN_Config ledPinTable[] = { CONCENTRATOR_ACTIVITY_LED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me Board_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by me PIN_TERMINATE }; //add by me --begin PIN_Config buttonPinTable[] = { Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON3 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, Board_BUTTON4 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE }; //add by me--end /***** Function definitions *****/ void ConcentratorRadioTask_init(void) { /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if (!ledPinHandle) { System_abort("Error initializing board 3.3V domain pins\n"); } buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable); if (!buttonPinHandle) { System_abort("Error initializing button pins\n"); } Semaphore_Params semParams; /* Construct a Semaphore object to be use as a resource lock, inital count 1 */ Semaphore_Params_init(&semParams); Semaphore_construct(&semStruct, 1, &semParams); /* Obtain instance handle */ semHandle = Semaphore_handle(&semStruct); /* Create event used internally for state changes */ Event_Params eventParam; Event_Params_init(&eventParam); Event_construct(&radioOperationEvent, &eventParam); radioOperationEventHandle = Event_handle(&radioOperationEvent); Event_construct(&OperationEvent, &eventParam); OperationEventHandle = Event_handle(&OperationEvent); /* Create the concentrator radio protocol task */ Task_Params_init(&concentratorRadioTaskParams); concentratorRadioTaskParams.stackSize = CONCENTRATORRADIO_TASK_STACK_SIZE; concentratorRadioTaskParams.priority = CONCENTRATORRADIO_TASK_PRIORITY; concentratorRadioTaskParams.stack = &concentratorRadioTaskStack; Task_construct(&concentratorRadioTask, concentratorRadioTaskFunction, &concentratorRadioTaskParams, NULL); /* Create the concentrator radio protocol task */ Task_Params_init(&TxcontrolTaskParams); TxcontrolTaskParams.stackSize = TXCONTROL_TASK_STACK_SIZE; TxcontrolTaskParams.priority = TXCONTROL_TASK_PRIORITY; TxcontrolTaskParams.stack = &TxcontrolTaskStack; Task_construct(&TxcontrolTask, TxcontrolTaskFunction, &TxcontrolTaskParams, NULL); } void ConcentratorRadioTask_registerPacketReceivedCallback(ConcentratorRadio_PacketReceivedCallback callback) { packetReceivedCallback = callback; } static void concentratorRadioTaskFunction(UArg arg0, UArg arg1) { /* Initialize EasyLink */ if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) { System_abort("EasyLink_init failed"); } /* Set frequency */ if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) { System_abort("EasyLink_setFrequency failed"); } /* Set concentrator address */; concentratorAddress = RADIO_CONCENTRATOR_ADDRESS; EasyLink_enableRxAddrFilter(&concentratorAddress, 1, 1); /* Set up Ack packet */ ackPacket.header.sourceAddress = concentratorAddress; ackPacket.header.packetType = RADIO_PACKET_TYPE_ACK_PACKET; /* Enter receive */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } while (1) { uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); /* If valid packet received */ if(events & RADIO_EVENT_VALID_PACKET_RECEIVED) { /* Send ack packet */ sendAck(latestRxPacket.header.sourceAddress); /* Call packet received callback */ notifyPacketReceived(&latestRxPacket); Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); } /* If invalid packet received */ if(events & RADIO_EVENT_INVALID_PACKET_RECEIVED) { /* Go back to RX */ if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } } Semaphore_post(semHandle); } } static void TxcontrolTaskFunction(UArg arg0, UArg arg1){ /* Setup ADC sensor packet */ // dmSensorPacket.header.sourceAddress = RADIO_CONCENTRATOR_ADDRESS; dmSensorPacket.header.sourceAddress =1; dmSensorPacket.header.packetType = RADIO_PACKET_TYPE_DM_SENSOR_PACKET; /* Initialise previous Tick count used to calculate uptime for the TLM beacon */ prevTicks = Clock_getTicks(); dmSensorPacket.batt = AONBatMonBatteryVoltageGet(); dmSensorPacket.button = !PIN_getInputValue(Board_BUTTON0); dmSensorPacket.time100MiliSec=prevTicks; /* Setup callback for button pins */ if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0) { System_abort("Error registering button callback function"); } while(1) { uint32_t txevents = Event_pend(OperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); if(txevents & RADIO_EVENT_VALID_PACKET_RECEIVED) { sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS); /* toggle Activity LED */ PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED, !PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED)); //txevents=0; } Semaphore_post(semHandle); } } static void sendAck(uint8_t latestSourceAddress) { /* Set destinationAdress, but use EasyLink layers destination adress capability */ txPacket.dstAddr[0] = latestSourceAddress; /* Copy ACK packet to payload, skipping the destination adress byte. * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(txPacket.payload, &ackPacket.header, sizeof(ackPacket)); txPacket.len = sizeof(ackPacket); /* Send packet */ if (EasyLink_transmit(&txPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } } static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket) { if (packetReceivedCallback) { packetReceivedCallback(latestRxPacket, latestRssi); } } static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status) { union ConcentratorPacket* tmpRxPacket; /* If we received a packet successfully */ if (status == EasyLink_Status_Success) { /* Save the latest RSSI, which is later sent to the receive callback */ latestRssi = (int8_t)rxPacket->rssi; /* Check that this is a valid packet */ tmpRxPacket = (union ConcentratorPacket*)(rxPacket->payload); /* If this is a known packet */ if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_ADC_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct AdcSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_DM_SENSOR_PACKET) { /* Save packet */ memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct DualModeSensorPacket)); /* Signal packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } else { /* Signal invalid packet received */ Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED); } } void buttonCallback(PIN_Handle handle, PIN_Id pinId) { /* Debounce logic, only toggle if the button is still pushed (low) */ // CPUdelay(8000*50); if (PIN_getInputValue(Board_BUTTON0) == 0) { CPUdelay(8000*50); Event_post(OperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED); // txevents=1; PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1)); } if (PIN_getInputValue(Board_BUTTON1) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2)); } if (PIN_getInputValue(Board_BUTTON2) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON3) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } if (PIN_getInputValue(Board_BUTTON4) == 0) { PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3)); } } static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) { /* Set destination address in EasyLink API */ currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0; /* Copy ADC packet to payload * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket)); currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket); /* Setup retries */ currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries; currentRadioOperation.ackTimeoutMs = ackTimeoutMs; currentRadioOperation.retriesDone = 0; EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs)); /* Send packet */ if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } /* Enter RX */ if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) { System_abort("EasyLink_receiveAsync failed"); } }
static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs)
{
/* Set destination address in EasyLink API */
currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0;
/* Copy ADC packet to payload
* Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */
memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket));
currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket);
/* Setup retries */
currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries;
currentRadioOperation.ackTimeoutMs = ackTimeoutMs;
currentRadioOperation.retriesDone = 0;
EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs));
/* Send packet */
if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success)
{
System_abort("EasyLink_transmit failed");
}
/* Enter RX */
if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success)
{
System_abort("EasyLink_receiveAsync failed");
}
}
把红色的去掉应该可以了
您好:
我刚刚试了一下,还是出现[Cortex_M3_0] EasyLink_transmit failed发送失败,我觉得还是发送的原因吧?
你不添加任何东西,就纯TI例程,用这个函数是发送成功的对吗?
您好:
在移植之前(在RFWSNnode)是可以成功的,这个函数是我从RFWSNnode里面移植过来的,加到了rfWSNconcentrator中,在一直保持接收的基础上,利用按键发送控制信息,我加了一个事件和一个信号量,在rfWSNconcentrator里就没有发送成功过了。
那断点调试卡在哪里?之前好像我有碰过的问题是卡在中断里,单步调试结果可以发过来看看嘛?
static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) { /* Set destination address in EasyLink API */ currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0; /* Copy ADC packet to payload * Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */ memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket)); currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket); /* Setup retries */ currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries; currentRadioOperation.ackTimeoutMs = ackTimeoutMs; currentRadioOperation.retriesDone = 0; EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs)); /* Send packet */ if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success) { System_abort("EasyLink_transmit failed"); } }
卡在加黑的字体那里,就中断了,除非重启设备不然就卡死了。单步调试因为要按键控制,所以没有用这个
会运行到加黑的地方,是因为EasyLink_transmit这个函数返回错误,不等于EasyLink_Status_Success,我意思就是:运用单步调试,进入到EasyLink_transmit这个函数里,看看它运行到哪里,返回什么错误类型
您好:
我通过单步调试,程序运行到下面加黑的程序 if ( (!configured) || suspended) { return EasyLink_Status_Config_Error; },就不运行后面的if语句了;就说是配置有误!我觉得这里应该是缺少了EasyLink_init,可是我加上了这个以后,程序就无法接收信号了,因为我在接收任务里已经用到了EasyLink_init这个函数。
EasyLink_Status EasyLink_transmitAsync(EasyLink_TxPacket *txPacket, EasyLink_TxDoneCb cb) { EasyLink_Status status = EasyLink_Status_Tx_Error; //Check if not configure or already an Async command being performed if ( (!configured) || suspended) { return EasyLink_Status_Config_Error; } //Check and take the busyMutex if ( (Semaphore_pend(busyMutex, 0) == FALSE) || (EasyLink_CmdHandle_isValid(asyncCmdHndl)) ) { return EasyLink_Status_Busy_Error; } if (txPacket->len > EASYLINK_MAX_DATA_LENGTH) { return EasyLink_Status_Param_Error; } //store application callback txCb = cb; memcpy(txBuffer, txPacket->dstAddr, addrSize); memcpy(txBuffer + addrSize, txPacket->payload, txPacket->len); //packet length to Tx includes address EasyLink_cmdPropTx.pktLen = txPacket->len + addrSize; EasyLink_cmdPropTx.pPkt = txBuffer; if (txPacket->absTime != 0) { EasyLink_cmdPropTx.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropTx.startTrigger.pastTrig = 1; EasyLink_cmdPropTx.startTime = txPacket->absTime; } else { EasyLink_cmdPropTx.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropTx.startTrigger.pastTrig = 1; EasyLink_cmdPropTx.startTime = 0; } /* Send packet */ asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropTx, RF_PriorityNormal, txDoneCallback, EASYLINK_RF_EVENT_MASK); if (EasyLink_CmdHandle_isValid(asyncCmdHndl)) { status = EasyLink_Status_Success; } //busyMutex will be released by the callback return status; }
EasyLink_init只需要掉用一次就行了,它会初始化收和发,现在能正常发了吗?
是这样的,我不加EasyLink_init,还是会出现发送失败,加上了以后就无法再接收信号,并且发送也没有信号
默认是在Task一开始就加EasyLink_init的,我看到你之前用发送函数是EasyLink_transmit,现在你用的是EasyLink_transmitAsync了,现在先解决发的问题,把收的函数功能都先屏蔽,看看什么效果
您好,
我将接收功能屏蔽掉了,现在的问题是这样的,如果将
if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) {
System_abort("EasyLink_init failed");
}
/* Set frequency */
if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) {
System_abort("EasyLink_setFrequency failed");
}
放在发送函数里面,是可以发送成功的,反之,将上面的初始化函数放在主函数或者其他初始化函数里面就不成功了,这是什么原因呢?
从现在分析看,我个人觉得EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs));这个函数可能是问题的关键,这个函数对asyncRxTimeOut = ui32Value;赋值,然后 EasyLink_init(EasyLink_PhyType ui32ModType)这个函数对asyncRxTimeOut = 0;,我现在不确定,你可以从asyncRxTimeOut 这个全局变量下手试试看。
您好:我一直用的都是EasyLink_transmit(),没有用异步的,之前那个是复制错了;这样和asyncRxTimeOut还有关系吗?
另外我将例程rfWSNnode的
if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) {
System_abort("EasyLink_init failed");
}
/* Set frequency */
if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) {
System_abort("EasyLink_setFrequency failed");
}
放到了初始化函数里,也是无法发送信号;这是不是说要想切换收发必须改变一些配置呢?