benoitdes wrote on Tuesday, April 15, 2014:
Thanks for your answers,
Well, my code is like this.
In the main :
xQueueHandle xQueueMidiMessages;
xQueueHandle xQueueScreenMessages;
/* Declare a variable of type xSemaphoreHandle. This is used to reference the
semaphore that is used to synchronize a task with an interrupt. */
xSemaphoreHandle xBinarySemaphoreCoreLoop;
int main(void)
{
/* System Initialization. */
SystemInit();
SystemCoreClockUpdate();
/* Before a semaphore is used it must be explicitly created */
xBinarySemaphoreCoreLoop = xSemaphoreCreateCounting(3,0);
// We need to know the size of an internal midi message ! 20 messages of uint32_t they said.
xQueueMidiMessages = xQueueGenericCreate(20, 32, (unsigned char)0);
xQueueScreenMessages = xQueueGenericCreate(5, 32, (unsigned char)0);
GPIO_Config(); // Config des E/S et des RCC
Reset_all_high_luminosity_step();
Update_leds_registers(0,0,0);
Display_Led_Startup();
Interrupt_Config(); // BPM & Encoders 1, 2, 4, 5, 6 interrupt config
SPI2_Config(); // Config SPI pour l'ecran
DAC_Config();
USART_Config(); // Config du midi in, midi out et de l'interruption sur midi in
Interrupt_Config(); // BPM & Encoders 1, 2, 4, 5, 6 interrupt config
i2C_Config(); // Config i2C pour le touchpad
ADC_Config(); // Config des 4 entrees analogiques
screen_init();
tab_screen_init();
set_zone_white(0,0,127,63);
//USB_Stop();
USB_Config();
// Force analog outputs at 0V
GPIO_ResetBits(GPIOB, GPIO_Pin_11); //GATE
Set_DAC_Ch1_Voltage(0); // CV
Set_DAC_Ch2_Voltage(0); // ANALOG
// All note off (MIDI + USB)
Send_All_Note_Off();
if (xBinarySemaphoreCoreLoop != NULL && xQueueMidiMessages != NULL && xQueueScreenMessages != NULL) {
// Allumage de la led de debug SWD
Switch_Leds(LED_SWD_OFF);
// This is the timer for the core loop (accuracy => us) TIM2
TIM_Config();
// Interrupt triggered by the timer TIM2
EnableTimerInterrupt();
//vTrack_Loop needs a stack size in bytes after the task name
xTaskCreate(vTrack_Loop, (signed char *)"Core_Loop", 512, NULL, 4, NULL);
// vIHM_Checker is launched every 5 ms, can you believe it ?
xTaskCreate(vIHM_Checker, (signed char *)"IHM_Loop", 128, NULL, 3, NULL);
// vDisplay_Led is launched every 1 ms
xTaskCreate(vDisplay_Led, (signed char *)"Led_Loop", 128, NULL, 2, NULL);
// vUpdate_Screen is launched every 30 ms
xTaskCreate(vUpdate_Screen, (signed char *)"Screen_Loop", 128, NULL, 1, NULL);
// vCheck_Slowly is launched every 2 seconds
// xTaskCreate(vCheck_Slowly, (signed char *)"Slow_Loop", 1024, NULL, 1, NULL);
uint16_t prio = configKERNEL_INTERRUPT_PRIORITY;
vTaskStartScheduler();
}
for(;;);
while(1);
}
From Core_loop, the Sender :
extern xQueueHandle xQueueScreenMessages;
void Send_To_Screen(uint8_t message_type, uint16_t content){
uint32_t mess_to_send = (message_type << 16) | content;
xQueueGenericSend(xQueueScreenMessages, &mess_to_send, 0, pdFALSE);
}
In Screen_Loop, the receiver :
/*
* The purpose of this task is to update the screen
*/
void vUpdate_Screen( void *pvParameters )
{
uint32_t uxHighWaterMark;
/* Inspect our own high water mark on entering the task. */
uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL );
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
/* This task is launched every 30ms */
portTickType currentPortTick = 30/(portTICK_RATE_MS);
portBASE_TYPE xStatus = pdFALSE;
const uint32_t message_from_core;
/* Variables */
static uint8_t Count = 0;
static uint8_t Logo_OFF = FALSE;
/* Start of the task vSystem_Timer */
TASK_LOOP
{
// DEBUG
if (uxHighWaterMark < 10){while(1);}
xStatus = xQueueReceive(xQueueScreenMessages, &message_from_core, 0);
if (xStatus == pdPASS) {ReadAndDecodeFromCore(message_from_core);}
/* Delay */
vTaskDelayUntil( &xLastWakeTime, currentPortTick);
}
}
The first time i receive something through the queue, when returning from xQueueReceive, xLastWakeTime and currentPortTick seemed corrupted.
I have this kind of assert defined :
define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
The new types of assert are in version 8.0.0 of FreeRTOS ?
Regards,
Benoit