I am running FreeRTOS in a emulated LM3S811 board via QEMU and I’m trying to get temperature info (I am using this project (the keil one)… you can find the vanilla source code here ).
Currently, this is the code:
// ...
// include and define stuff
// ...
int main(void)
{
prvSetupHardware();
// other stuff
xTaskCreate( vMyTask, "MyTask", configMINIMAL_STACK_SIZE+300, NULL, mainCHECK_TASK_PRIORITY , NULL );
vTaskStartScheduler();
}
static void prvSetupHardware( void )
{
/* Setup the PLL. */
SysCtlClockSet( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ );
// ...
// other gpu and uart stuff
// ...
// Enable ADC Peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
//Allow the ADC12 to run at its default rate of 1Msps.
ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
//our code will average all four samples of temperature sensor data ta on sequencer 1 to calculate the temperature, so all four sequencer steps will measure the temperature sensor
ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
//enable ADC sequencer 1.
ADCSequenceEnable(ADC_BASE, 1);
IntMasterEnable();
}
// ...
// other stuff for uart and gpio
// ...
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
volatile uint32_t ui32TempSet;
static void vMyTask( void *pvParameter )
{
uint32_t ui32ADC0Value[4];
ui32TempSet = 25;
while (1)
{
//indication that the ADC conversion process is complete
ADCIntClear(ADC_BASE, 1);
//trigger the ADC conversion with software
ADCProcessorTrigger(ADC_BASE, 1);
//wait for the conversion to complete
while(!ADCIntStatus(ADC_BASE, 1, false));
//read the ADC value from the ADC Sample Sequencer 1 FIFO
ADCSequenceDataGet(ADC_BASE, 1, ui32ADC0Value);
ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
char valchartemper[10];
sprintf(valchartemper, "%d", ui32TempValueC);
char *valchartemperPtr = valchartemper;
while( *valchartemperPtr != NULL ){
UARTCharPut(UART0_BASE,*valchartemperPtr); // this prints via uart the temperature value
valchartemperPtr++ ;
}
SysCtlDelay(SysCtlClockGet() / 3); //delay ~1 sec
}
vTaskDelete( NULL );
}
Now, inside the “vMyTask” code there is while(!ADCIntStatus(ADC_BASE, 1, false)) which allows to exit from it just when the conversion is complete.
But since it NEVER exit from it, the code below it can’t be executed.
So just for curiosity I commented it so to execute the code below anyway, and what I get is always the same value. It’s also an impossible value: 429452990 celsius degrees. so impossibile.
Questions:
-
What is that value? Is it just a random uninitialized one?
-
Since it’s obvious that I must be miss something (it’s not normal that while(!ADCIntStatus(ADC_BASE, 1, false)) never exits), I want to know what I’m missing. Am I missing an ISR code for ADC that I have to MANUALLY write? Am I missing some interrupt handling or peripherals handling in qemu? What am I doing wrong?
-
Does qemu simulate the behavior of temperature or does it ALWAYS give the same temperature regardless of the cpu usage for example?