This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/DK-TM4C129X: TI-RTOS Multithreading

Part Number: DK-TM4C129X

Tool/software: TI-RTOS

Hey guys im new to CCS and im using Ti-RTOS. I want to synchronize my code in multi threading as im calling two functions in main.In one im using ADC and in other i want to use Usb mouse host example of rtos but i cant understand how to use it here im posting my current code maybe u guys can help thanks. 

/*
* ======== spiloopback.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <stdio.h>
#include <string.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"


/*Tiva Rc headers */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "C:\ti\TivaWare_C_Series-2.1.3.156\driverlib\adc.h"
#include "inc/hw_ints.h"
#include "C:\ti\TivaWare_C_Series-2.1.3.156\driverlib\sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/systick.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"

#define SPI_MSG_LENGTH 4 //length of one bytes in one registers
#define TASKSTACKSIZE 768 //Size of one task

/* Allocate buffers in .dma section of memory for concerto devices */
#ifdef MWARE
#pragma DATA_SECTION(masterRxBuffer, ".dma");
#pragma DATA_SECTION(masterTxBuffer, ".dma");
#pragma DATA_SECTION(slaveRxBuffer, ".dma");
#pragma DATA_SECTION(slaveTxBuffer, ".dma");
#endif

Task_Struct task0Struct; //task structure
Char task0Stack[TASKSTACKSIZE];

char masterRxBuffer[SPI_MSG_LENGTH]; //Buffer in which received data will save
char masterTxBuffer[SPI_MSG_LENGTH]; //The data is saved in this buffer for sending


void masterTaskFxn (UArg arg0, UArg arg1)
{


unsigned long ulADC0Value[1];
unsigned long ulADC0Value1[14];
volatile unsigned long ulTempAvg;
volatile unsigned long ulTempAvg1;
volatile unsigned long ulTempValueC;
volatile unsigned long ulTempValueF;
// SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_25MHZ);
// SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_25MHZ);
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//Enabling ADC0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);//enabling port E
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);//defining pin PE1

ADCSequenceDisable(ADC0_BASE, 3);
ADCSequenceDisable(ADC0_BASE, 2);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
//Channel 2 PE1
ADCSequenceStepConfigure(ADC0_BASE, 2,0, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);
//Channel TS
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
ADCSequenceEnable(ADC0_BASE, 2);
// **********
ADCProcessorTrigger(ADC0_BASE, 3);
ADCProcessorTrigger(ADC0_BASE, 2);
//waiting for conversion
while(!ADCIntStatus(ADC0_BASE, 3, false)){}
while(!ADCIntStatus(ADC0_BASE, 2, false)){}
//Getting values
ADCSequenceDataGet(ADC0_BASE, 3, ulADC0Value);
ADCSequenceDataGet(ADC0_BASE, 2, ulADC0Value1);
ulTempAvg = (ulADC0Value[0] );
ulTempAvg1 = (ulADC0Value1[0] +ulADC0Value1[1]+ulADC0Value1[2]+ulADC0Value1[3])/4;
ulTempValueC = (1475 - ((2475 * ulTempAvg)) / 4096)/10;
ADCIntClear(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 2);
//*********
}

void maasterTaskFxn (UArg arg0, UArg arg1)
{
System_printf("-------------------------------------new ---------------------------------------");

}

/*
* ======== main ========
*/
void main(void)
{
Task_Params taskParams;
Board_initGeneral();
Board_initGPIO();
Board_initSPI();
GPIO_write(Board_LED0, Board_LED_ON); //new chip select set to High at pin number PQ7
Task_Params_init(&taskParams); //initlization the task
taskParams.priority = 1; //task parameters
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)masterTaskFxn, &taskParams, NULL);


Task_Params_init(&taskParams); //initlization the task
taskParams.priority = 2; //task parameters
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)maasterTaskFxn, &taskParams, NULL);

//GPIO_write(Board_LED0, Board_LED_OFF);
System_flush();
System_printf("-------------------------------------new ---------------------------------------");
System_flush();
/* Start BIOS */
BIOS_start(); //starting the tasks in bios.
//return (0);
while(1);
}