完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 一只耳朵怪 于 2018-6-7 09:15 编辑
Hi, 我尝试在rfPacketRx例子中加入Uart输出信息, 通过在rxTask中插入按键中断处理来实现, 程序上电后正常接收数据包, 按键一次, 能正常 输出package 数目, 但是程序就不能返回或者挂掉, 需要reset才能接受数据, 程序内容如下: /* * 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 #include #include #include #include #include /* Drivers */ #include #include #include /* Board Header files */ #include "Board.h" #include "RFQueue.h" #include "smartrf_settings/smartrf_settings.h" #include #include #include #include /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; /* * Application LED pin configuration table: * - All LEDs board LEDs are off. */ PIN_Config pinTable[] = [ Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE ]; /***** Defines *****/ #define RX_TASK_STACK_SIZE 1024 #define RX_TASK_PRIORITY 2 /* TX Configuration */ #define DATA_ENTRY_HEADER_SIZE 8 /* Constant header size of a Generic Data Entry */ #define MAX_LENGTH 30 /* Max length byte the radio will accept */ #define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */ #define NUM_APPENDED_BYTES 2 /* The Data Entries data field will contain: * 1 Header byte (RF_cmdPropRx.rxConf.bIncludeHdr = 0x1) * Max 30 payload bytes * 1 status byte (RF_cmdPropRx.rxConf.bAppendStatus = 0x1) */ Semaphore_Struct semRxStruct; Semaphore_Handle semRxHandle; uint32_t sleepTickCount; static int packet_rx_count; /* * Application button pin configuration table: * - Buttons interrupts are configured to trigger on falling edge. */ PIN_Config buttonPinTable[] = [ Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE ]; void buttonCallback(PIN_Handle handle, PIN_Id pinId); /***** Prototypes *****/ static void rxTaskFunction(UArg arg0, UArg arg1); static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ static Task_Params rxTaskParams; Task_Struct rxTask; /* not static so you can see in ROV */ static uint8_t rxTaskStack[RX_TASK_STACK_SIZE]; static RF_Object rfObject; static RF_Handle rfHandle; /* Buffer which contains all Data Entries for receiving data. * Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_ALIGN (rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment = 4 static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__GNUC__) static uint8_t rxDataEntryBuffer [RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__ ((aligned (4))); #else #error This compiler is not supported. #endif /* Receive dataQueue for RF Core to fill in data */ static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint8_t packetLength; static uint8_t* packetDataPointer; static PIN_Handle pinHandle; static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */ /***** Function definitions *****/ void RxTask_init(PIN_Handle ledPinHandle) [ pinHandle = ledPinHandle; Task_Params_init(&rxTaskParams); rxTaskParams.stackSize = RX_TASK_STACK_SIZE; rxTaskParams.priority = RX_TASK_PRIORITY; rxTaskParams.stack = &rxTaskStack; rxTaskParams.arg0 = (UInt)1000000; Task_construct(&rxTask, rxTaskFunction, &rxTaskParams, NULL); ] /* * ======== buttonCallback ======== * Pin interrupt Callback function board buttons configured in the pinTable. */ 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) [ // char input[10]; char buf[10]; // char test; UART_Handle uart; UART_Params uartParams; const char echoPrompt[] = "fEchoing characters:rn"; // test = 0; /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 115200; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) [ System_abort("Error opening the UART"); ] sprintf(buf,"%d",packet_rx_count); UART_write(uart, echoPrompt, sizeof(echoPrompt)); UART_write(uart, buf, sizeof(buf)); UART_write(uart, "n", sizeof("n")); UART_write(uart, "hellon", sizeof("hellon")); ] ] static void rxTaskFunction(UArg arg0, UArg arg1) [ RF_Params rfParams; RF_Params_init(&rfParams); buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable); if (!buttonPinHandle) [ System_abort("Error initializing button pinsn"); ] /* Setup callback for button pins */ if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0) [ System_abort("Error registering button callback function"); ] if( RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) [ /* Failed to allocate space for all data entries */ while(1); ] /* Modify CMD_PROP_RX command for application needs */ RF_cmdPropRx.pQueue = &dataQueue; /* Set the Data Entity queue for received data */ RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; /* Discard ignored packets from Rx queue */ RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1; /* Discard packets with CRC error from Rx queue */ RF_cmdPropRx.maxPktLen = MAX_LENGTH; /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */ RF_cmdPropRx.pktConf.bRepeatOk = 1; RF_cmdPropRx.pktConf.bRepeatNok = 1; /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); /* Enter RX mode and stay forever in RX */ RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &callback, IRQ_RX_ENTRY_DONE); while(1); ] void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) [ if (e & RF_EventRxEntryDone) [ /* Toggle pin to indicate RX */ PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2)); /* Get current unhandled data entry */ currentDataEntry = RFQueue_getDataEntry(); /* Handle the packet data, located at ¤tDataEntry->data: * - Length is the first byte with the current configuration * - Data starts from the second byte */ packetLength = *(uint8_t*)(¤tDataEntry->data); packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1); /* Copy the payload + the status byte to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + 1)); packet_rx_count++; RFQueue_nextEntry(); ] ] /* * ======== main ======== */ int main(void) [ Semaphore_Params semParams; // Task_Params taskParams; /* Call board init functions. */ Board_initGeneral(); Board_initUART(); packet_rx_count=0; /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, pinTable); if(!ledPinHandle) [ System_abort("Error initializing board LED pinsn"); ] Semaphore_Params_init(&semParams); Semaphore_construct(&semRxStruct, 0, &semParams); semRxHandle = Semaphore_handle(&semRxStruct); RxTask_init(ledPinHandle); /* Start BIOS */ BIOS_start(); return (0); ] |
|
相关推荐
4个回答
|
|
rf发送函数是不会返回的,建议按键程序中先abort rf程序,下次需要接受再重启
|
|
|
|
你好,问题解决如下:
/* * ======== buttonCallback ======== * Pin interrupt Callback function board buttons configured in the pinTable. */ 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) [ // char input[10]; char buf[10]; // char test; UART_Handle uart; UART_Params uartParams; const char echoPrompt[] = "fEchoing characters:rn"; // test = 0; /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 115200; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) [ System_abort("Error opening the UART"); ] sprintf(buf,"%d",packet_rx_count); UART_write(uart, echoPrompt, sizeof(echoPrompt)); UART_write(uart, buf, sizeof(buf)); UART_write(uart, "n", sizeof("n")); UART_write(uart, "hellon", sizeof("hellon")); UART_close(uart);//加上这一句就可以了 ] ] |
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
279 浏览 1 评论
494 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
730 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
630 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1096 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
212浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
168浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
41浏览 13评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
144浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
148浏览 12评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-13 03:44 , Processed in 1.332848 second(s), Total 83, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号