微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > 哪位大神有CC1310收发独立TASK的例程

哪位大神有CC1310收发独立TASK的例程

时间:12-23 整理:3721RD 点击:

哪位大神有CC1310收发独立TASK的例程参考一下,,,搞了好久了,,,始终没理解easylink下同时收发怎么搞。。。

在线等。。。多谢。。。

下面是我自己的代码。、、

/*
* 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.
*/

/*
* ======== rfEasyLinkTx.c ========
*/
/* XDCtools Header files */
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>

/* Board Header files */
#include "Board.h"

/* EasyLink API Header files */
#include "easylink/EasyLink.h"

/* Undefine to not use async mode */
#define RFEASYLINKTX_ASYNC

#define RFEASYLINKTX_TASK_STACK_SIZE 1024
#define RFEASYLINKTX_TASK_PRIORITY 2

#define RFEASYLINKTX_BURST_SIZE 10
#define RFEASYLINKTXPAYLOAD_LENGTH 30

Task_Struct txTask; /* not static so you can see in ROV */
static Task_Params txTaskParams;
static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

/* Pin driver handle */
static PIN_Handle pinHandle;
static PIN_State pinState;

/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config pinTable[] = {
Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};

static uint16_t seqNumber;

#ifdef RFEASYLINKTX_ASYNC
static Semaphore_Handle txDoneSem;
#endif //RFEASYLINKTX_ASYNC

#ifdef RFEASYLINKTX_ASYNC
void txDoneCb(EasyLink_Status status)
{
if (status == EasyLink_Status_Success)
{
/* Toggle LED1 to indicate TX */
PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
}
else if(status == EasyLink_Status_Aborted)
{
/* Toggle LED2 to indicate command aborted */
PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
}

Semaphore_post(txDoneSem);
}
#endif //RFEASYLINKTX_ASYNC

static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
{
uint8_t txBurstSize = 0;

#ifdef RFEASYLINKTX_ASYNC
/* Create a semaphore for Async */
Semaphore_Params params;
Error_Block eb;

/* Init params */
Semaphore_Params_init(&params);
Error_init(&eb);

/* Create semaphore instance */
txDoneSem = Semaphore_create(0, &params, &eb);
#endif //TX_ASYNC

EasyLink_init(EasyLink_Phy_Custom);

/*
* If you wish to use a frequency other than the default, use
* the following API:
* EasyLink_setFrequency(868000000);
*/

/* Set output power to 12dBm */
EasyLink_setRfPwr(12);

while(1) {
EasyLink_TxPacket txPacket = { {0}, 0, 0, {0} };

/* Create packet with incrementing sequence number and random payload */
txPacket.payload[0] = (uint8_t)(seqNumber >> 8);
txPacket.payload[1] = (uint8_t)(seqNumber++);
uint8_t i;
for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
{
txPacket.payload[i] = rand();
}

txPacket.len = RFEASYLINKTXPAYLOAD_LENGTH;
txPacket.dstAddr[0] = 0xaa;

/* Add a Tx delay for > 500ms, so that the abort kicks in and brakes the burst */
if(txBurstSize++ >= RFEASYLINKTX_BURST_SIZE)
{
/* Set Tx absolute time to current time + 1s */
txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1000);
txBurstSize = 0;
}
/* Else set the next packet in burst to Tx in 100ms */
else
{
/* Set Tx absolute time to current time + 100ms */
txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(100);
}

#ifdef RFEASYLINKTX_ASYNC
EasyLink_transmitAsync(&txPacket, txDoneCb);
/* Wait 300ms for Tx to complete */
if(Semaphore_pend(txDoneSem, (300000 / Clock_tickPeriod)) == FALSE)
{
/* TX timed out, abort */
if(EasyLink_abort() == EasyLink_Status_Success)
{
/*
* Abort will cause the txDoneCb to be called and the txDoneSem
* to be released, so we must consume the txDoneSem
*/
Semaphore_pend(txDoneSem, BIOS_WAIT_FOREVER);
}
}
#else
EasyLink_Status result = EasyLink_transmit(&txPacket);

if (result == EasyLink_Status_Success)
{
/* Toggle LED1 to indicate TX */
PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
}
#endif //RFEASYLINKTX_ASYNC
}
}

void txTask_init(PIN_Handle inPinHandle) {
pinHandle = inPinHandle;

Task_Params_init(&txTaskParams);
txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
txTaskParams.stack = &txTaskStack;
txTaskParams.arg0 = (UInt)1000000;

Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);
}

/*
* ======== main ========
*/
int main(void)
{
/* Call driver init functions. */
Board_initGeneral();

/* Open LED pins */
pinHandle = PIN_open(&pinState, pinTable);
if(!pinHandle) {
System_abort("Error initializing board LED pins\n");
}

/* Clear LED pins */
PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);
PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);

txTask_init(pinHandle);

/* Start BIOS */
BIOS_start();

return (0);
}

如果我的理解没错的话,你是希望在一套代码里既有发送功能又有接收功能,是吗?

需要明确的一点是,射频在某个时刻不能同时既接收又发送。

你可以参考examples\rtos\CC1310_LAUNCHXL\easylink\rfWsnConcentrator示例工程,系统在成功接收到数据后会转入发送状态发送ACK。

多谢工程师。。。就是我想要的

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top