CC1310 rfPacketRX 加入UART功能问题
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 <stdlib.h>
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* Drivers */
#include <ti/drivers/rf/RF.h>
#include <ti/drivers/PIN.h>
#include <driverlib/rf_prop_mailbox.h>
/* Board Header files */
#include "Board.h"
#include "RFQueue.h"
#include "smartrf_settings/smartrf_settings.h"
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
#include <stdlib.h>
#include <stdio.h>
/* 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:\r\n";
// 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, "hello\n", sizeof("hello\n"));
}
}
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 pins\n");
}
/* 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 pins\n");
}
Semaphore_Params_init(&semParams);
Semaphore_construct(&semRxStruct, 0, &semParams);
semRxHandle = Semaphore_handle(&semRxStruct);
RxTask_init(ledPinHandle);
/* Start BIOS */
BIOS_start();
return (0);
}
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:\r\n";
// 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, "hello\n", sizeof("hello\n"));
UART_close(uart);//加上这一句就可以了
}
}
程序有好几处while(1);
为啥一直循环啊
谢谢前面两位朋友提供的信息