Tool/software: Code Composer Studio
Hello,
I have defined two different tasks for two SPI outputs. I want to operate them with the buttons(USR_SW1 & USR_SW2).
Now both tasks are running once. Button control is active.
Can I run the Tasks with the buttons? Could you help with editing the program?
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
/* Example/Board Header files */
#include "Board.h"
#define SPI_MSG_LENGTH 1
#define TASKSTACKSIZE 768
/* Allocate buffers in .dma section of memory for concerto devices */
#ifdef MWARE
#pragma DATA_SECTION(masterRxBuffer, ".dma");
#pragma DATA_SECTION(masterTxBuffer, ".dma");
#endif
Task_Struct task0Struct, task1Struct;
Char task0Stack[TASKSTACKSIZE], task1Stack[TASKSTACKSIZE];
bool transferOK0;
bool transferOK1;
unsigned int masterRxBuffer0[SPI_MSG_LENGTH];
unsigned int masterTxBuffer0[SPI_MSG_LENGTH];
unsigned int masterRxBuffer1[SPI_MSG_LENGTH];
unsigned int masterTxBuffer1[SPI_MSG_LENGTH];
Void masterTaskFxn0 (UArg arg0, UArg arg1)
{
SPI_Handle masterSpi0;
SPI_Transaction masterTransaction0;
SPI_Params spiParams0;
SPI_Params_init(&spiParams0);
spiParams0.transferMode = SPI_MODE_BLOCKING;
//spiParams0.transferTimeout = SPI_WAIT_FOREVER;
spiParams0.transferCallbackFxn = NULL;
spiParams0.mode = SPI_MASTER;
spiParams0.bitRate = 2000000;
spiParams0.dataSize = 8;
spiParams0.frameFormat=SPI_POL0_PHA1;
{
masterSpi0 = SPI_open(Board_SPI0, &spiParams0);
/* Initialize master SPI transaction structure */
masterTxBuffer0[0]=0x0A; //msg
masterTransaction0.count = 1; //Numbers of frames for a transaction
masterTransaction0.txBuf = (Ptr)masterTxBuffer0;
masterTransaction0.rxBuf = (Ptr)masterRxBuffer0;
/* Initiate SPI transfer */
transferOK0 = SPI_transfer(masterSpi0, &masterTransaction0);
System_printf("Rx0 : %d \n",masterRxBuffer0[0]);
System_printf("Tx0 : %d \n",masterTxBuffer0[0]);
SPI_close(masterSpi0);
System_printf("Done_0\n\n");
System_flush();
}
}
Void masterTaskFxn1 (UArg arg2, UArg arg3)
{
SPI_Handle masterSpi1;
SPI_Transaction masterTransaction1;
SPI_Params spiParams1;
SPI_Params_init(&spiParams1);
spiParams1.transferMode = SPI_MODE_BLOCKING;
//spiParams1.transferTimeout = SPI_WAIT_FOREVER;
spiParams1.transferCallbackFxn = NULL;
spiParams1.mode = SPI_MASTER;
spiParams1.bitRate = 2000000;
spiParams1.dataSize = 8;
spiParams1.frameFormat=SPI_POL1_PHA0;
{
masterSpi1 = SPI_open(Board_SPI1, &spiParams1);
/* Initialize master SPI transaction structure */
masterTxBuffer1[0]=0x0F; //msg
masterTransaction1.count = 1; //Numbers of frames for a transaction
masterTransaction1.txBuf = (Ptr)masterTxBuffer1;
masterTransaction1.rxBuf = (Ptr)masterRxBuffer1;
/* Initiate SPI transfer */
transferOK1 = SPI_transfer(masterSpi1, &masterTransaction1);
System_printf("Rx1 : %d \n",masterRxBuffer1[0]);
System_printf("Tx1 : %d \n",masterTxBuffer1[0]);
SPI_close(masterSpi1);
System_printf("Done_1\n\n");
System_flush();
}
}
void gpioButtonFxn0(unsigned int index)
{
/* Clear the GPIO interrupt and toggle an LED */
GPIO_toggle(Board_LED0);
System_flush();
System_printf("Buton0 or LED0 OK\n");
}
void gpioButtonFxn1(unsigned int index)
{
/* Clear the GPIO interrupt and toggle an LED */
GPIO_toggle(Board_LED1);
System_flush();
System_printf("Buton1 or LED1 OK\n");
}
int main(void)
{
/* Construct BIOS objects */
Task_Params taskParams;
/* Call board init functions. */
Board_initGeneral();
Board_initGPIO();
Board_initSPI();
Board_initUART();
/* Construct master/slave Task threads */
Task_Params_init(&taskParams);
taskParams.priority = 2;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)masterTaskFxn0, &taskParams, NULL);
Task_Params_init(&taskParams);
taskParams.priority = 3;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task1Stack;
Task_construct(&task1Struct, (Task_FuncPtr)masterTaskFxn1, &taskParams, NULL);
GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);
GPIO_enableInt(Board_BUTTON0);
GPIO_setCallback(Board_BUTTON1, gpioButtonFxn1);
GPIO_enableInt(Board_BUTTON1);
BIOS_start();
return (0);
}
Regards,
