Other Parts Discussed in Thread: SYSBIOS
Hi,
I am developing a program to save data packets in the external flash memeory by combining the nvsexternal example and rfEasyLinkRx example.
But I am facing a problem when assigning the rxPacket->payload[i] in to the nvsWrite function.
The program runs separately with its threads and the syscfg file also modified as matched for the both examples.
nvsexternal.c file
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stddef.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#include "easylink/EasyLink.h"
/* Driver Header files */
#include <ti/display/Display.h>
#include <ti/drivers/NVS.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#define FOOTER "=================================================="
/* Buffer placed in RAM to hold bytes read from non-volatile storage. */
static char buffer[64];
static const char signature[] =
{"SimpleLink SDK Non-Volatile Storage (NVS) SPI Example."};
/*
* ======== mainThread ========
*/
void *NVS(void *arg0) //nvs function
{
NVS_Handle nvsHandle;
NVS_Attrs regionAttrs;
NVS_Params nvsParams;
Display_Handle displayHandle;
Display_init();
NVS_init();
displayHandle = Display_open(Display_Type_UART, NULL);
if (displayHandle == NULL) {
/* Display_open() failed */
while (1);
}
NVS_Params_init(&nvsParams);
nvsHandle = NVS_open(CONFIG_NVSEXTERNAL, &nvsParams);
if (nvsHandle == NULL) {
Display_printf(displayHandle, 0, 0, "NVS_open() failed.");
return (NULL);
}
Display_printf(displayHandle, 0, 0, "\n");
NVS_getAttrs(nvsHandle, ®ionAttrs);
size_t round_offset = 4;
NVS_write(nvsHandle, 0, 0, sizeof(signature+1), NVS_WRITE_ERASE | NVS_WRITE_POST_VERIFY);
int x;
for(x=0; x>=0; x++) //infinte counter for testing
{
NVS_read(nvsHandle, 0, (void *) buffer, sizeof(signature));
Display_printf(displayHandle, 0, 0, "%s", buffer);
memset(buffer, 0, sizeof(signature));
NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
Display_printf(displayHandle, 0, 0, "Erasing SPI flash sector...");
NVS_write(nvsHandle, round_offset, signature, sizeof(signature), NVS_WRITE_POST_VERIFY);
NVS_read(nvsHandle, round_offset, (void *) buffer, sizeof(signature));
Display_printf(displayHandle, 0, 0, "\t Round >>> %d", x);
Display_printf(displayHandle, 0, 0, "\t Read >>> %s", buffer);
NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
memset(buffer, 0, sizeof(signature));
Display_printf(displayHandle, 0, 0, "Reset the device.");
Display_printf(displayHandle, 0, 0, FOOTER);
}
NVS_close(nvsHandle);
return (NULL);
}
void *redblink(void *arg0) // led1 blinking
{
/* 1 second delay */
uint32_t time = 1;
GPIO_init();
GPIO_setConfig(CONFIG_GPIO_rd, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(CONFIG_GPIO_rd, CONFIG_GPIO_LED_ON);
while (1) {
sleep(time);
GPIO_toggle(CONFIG_GPIO_rd);
}
}
void *blueblink(void *arg0) // led2 blinking
{
uint32_t time2 = 1;
GPIO_init();
GPIO_setConfig(CONFIG_GPIO_bl, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(CONFIG_GPIO_bl, CONFIG_GPIO_LED_OFF);
while (1) {
sleep(time2);
GPIO_toggle(CONFIG_GPIO_bl);
}
}
main_tirtos.c file
/*
* ======== main_tirtos.c ========
*/
#include <stdlib.h>
#include <stdio.h>
#include <ti/sysbios/BIOS.h>
#include <ti_radio_config.h>
#include <stdint.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/Assert.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#include "easylink/EasyLink.h"
#include <ti/display/Display.h>
/* POSIX Header files */
#include <pthread.h>
/* RTOS header files */
#include <ti/sysbios/BIOS.h>
#include <ti/drivers/Board.h>
extern void *NVS(void *arg0);
extern void *redblink(void *arg0);
extern void *blueblink(void *arg0);
#define THREADSTACKSIZE 1024
////////////////////////////////
////////////////////////////////
/* Undefine to remove async mode */
#define RFEASYLINKRX_ASYNC
#define RFEASYLINKRX_TASK_STACK_SIZE 1024
#define RFEASYLINKRX_TASK_PRIORITY 2
/***** Variable declarations *****/
static Task_Params rxTaskParams;
Task_Struct rxTask; /* not static so you can see in ROV */
static uint8_t rxTaskStack[RFEASYLINKRX_TASK_STACK_SIZE];
#ifdef RFEASYLINKRX_ASYNC
static Semaphore_Handle rxDoneSem;
#endif
/***** Function definitions *****/
#ifdef RFEASYLINKRX_ASYNC
void rxDoneCb(EasyLink_RxPacket * rxPacket, EasyLink_Status status)
{
if (status == EasyLink_Status_Success)
{
/* Toggle RLED to indicate RX */
GPIO_toggle(CONFIG_GPIO_RLED);
}
else if(status == EasyLink_Status_Aborted)
{
/* Toggle GLED to indicate command aborted */
GPIO_toggle(CONFIG_GPIO_GLED);
}
else
{
/* Toggle GLED and RLED to indicate error */
GPIO_toggle(CONFIG_GPIO_GLED);
GPIO_toggle(CONFIG_GPIO_RLED);
}
Semaphore_post(rxDoneSem);
}
#endif
static void rfEasyLinkRxFnx(UArg arg0, UArg arg1)
{
#ifndef RFEASYLINKRX_ASYNC
EasyLink_RxPacket rxPacket = {0};
#endif
#ifdef RFEASYLINKRX_ASYNC
/* Create a semaphore for Async*/
Semaphore_Params params;
Error_Block eb;
/* Init params */
Semaphore_Params_init(¶ms);
Error_init(&eb);
/* Create semaphore instance */
rxDoneSem = Semaphore_create(0, ¶ms, &eb);
if(rxDoneSem == NULL)
{
System_abort("Semaphore creation failed");
}
#endif //RFEASYLINKRX_ASYNC
// Initialize the EasyLink parameters to their default values
EasyLink_Params easyLink_params;
EasyLink_Params_init(&easyLink_params);
/*
* Initialize EasyLink with the settings found in ti_easylink_config.h
* Modify EASYLINK_PARAM_CONFIG in ti_easylink_config.h to change the default
* PHY
*/
if(EasyLink_init(&easyLink_params) != EasyLink_Status_Success)
{
System_abort("EasyLink_init failed");
}
/*
* If you wish to use a frequency other than the default, use
* the following API:
* EasyLink_setFrequency(868000000);
*/
while(1) {
#ifdef RFEASYLINKRX_ASYNC
EasyLink_receiveAsync(rxDoneCb, 0);
/* Wait 300ms for Rx */
if(Semaphore_pend(rxDoneSem, (300000 / Clock_tickPeriod)) == FALSE)
{
/* RX timed out abort */
if(EasyLink_abort() == EasyLink_Status_Success)
{
/* Wait for the abort */
Semaphore_pend(rxDoneSem, BIOS_WAIT_FOREVER);
}
}
#else
rxPacket.absTime = 0;
EasyLink_Status result = EasyLink_receive(&rxPacket);
if (result == EasyLink_Status_Success)
{
/* Toggle RLED to indicate RX */
GPIO_toggle(CONFIG_GPIO_RLED);
}
else
{
/* Toggle GLED and RLED to indicate error */
GPIO_toggle(CONFIG_GPIO_GLED);
GPIO_toggle(CONFIG_GPIO_RLED);
}
#endif //RX_ASYNC
}
}
void rxTask_init() {
Task_Params_init(&rxTaskParams);
rxTaskParams.stackSize = RFEASYLINKRX_TASK_STACK_SIZE;
rxTaskParams.priority = RFEASYLINKRX_TASK_PRIORITY;
rxTaskParams.stack = &rxTaskStack;
rxTaskParams.arg0 = (UInt)1000000;
Task_construct(&rxTask, rfEasyLinkRxFnx, &rxTaskParams, NULL);
}
////////////////////////////////
///////////////////////////////
/*
* ======== main ========
*/
int main(void)
{
pthread_t thread;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
Board_init();
/* Call driver init functions */
Board_initGeneral();
GPIO_init();
GPIO_setConfig(CONFIG_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(CONFIG_GPIO_RLED, CONFIG_GPIO_LED_OFF);
GPIO_write(CONFIG_GPIO_GLED, CONFIG_GPIO_LED_OFF);
rxTask_init();
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = 1;
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
if (retc != 0) {
/* failed to set attributes */
while (1) {}
}
retc = pthread_create(&thread, &attrs, redblink, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1) {}
}
retc = pthread_create(&thread, &attrs, blueblink, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1) {}
}
retc = pthread_create(&thread, &attrs, NVS, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1) {}
}
BIOS_start();
return (0);
}
//////////////////////////////////////////
I need to do something like this:
NVS_write(nvsHandle, round_offset, rxPacket->payload[0] , sizeof(signature), NVS_WRITE_POST_VERIFY);