anonymous wrote on Thursday, September 05, 2013:
Yes, tick interrupt is executing but xTaskIncrementTick() only once returns pdTRUE (seen on de debbuger).
When I debug more the I get to the place in xQueueGenericSendFromISR() (marked)
....
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
{
/* The task waiting has a higher priority so record that a
context switch is required. */
if( pxHigherPriorityTaskWoken != NULL ) // ## here
{
*pxHigherPriorityTaskWoken = pdTRUE;
}
}
...
but in Idle task:
if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( unsigned portBASE_TYPE ) 1 )
{
taskYIELD(); // ## never get here
}
Here is my FreeRTOSConfig.h file.
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#ifdef __ICCARM__
#include <stdint.h>
uint32_t SystemCoreClock(void);
//extern uint32_t SystemCoreClock;
#endif
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configCPU_CLOCK_HZ ( SystemCoreClock() )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 75 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 10 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_NEWLIB_REENTRANT 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* 15 priority levels */
#endif
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ( (1<<configPRIO_BITS) - 1)
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#include <assert.h>
#define configASSERT( x ) assert( x )
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#endif /* FREERTOS_CONFIG_H */
Task Creation functionons
portTASK_FUNCTION(test, param)
{
void __sinit( struct _reent *s );
__sinit(_REENT);
char stdout_buf[32];
setbuf(stdin, NULL); // _IOLBF
setvbuf(stdout, stdout_buf, _IOLBF, sizeof_array(stdout_buf));
setbuf(stderr, NULL);
int cnt = 0;
char buf[32];
while( 1 )
{
board_led_togle(LED3);
board_led_togle(LED4);
printf("%d:\r", cnt++);
}
}
portTASK_FUNCTION(test2, param)
{
//vTaskSuspend
while(1)
vTaskDelay(portTICK_RATE_MS);
}
int main( void )
{
extern void SystemInit();
SystemInit();
xTaskCreate(test, (signed char *)"Test", configMINIMAL_STACK_SIZE < 512 ? 512 : configMINIMAL_STACK_SIZE, NULL, 2, NULL);
// xTaskCreate(test2, (signed char *)"Test2", 256, NULL, 2, NULL);
vTaskStartScheduler();
abort();
}
And Problematic code
int stm32f4_uart_dma_tc_isr( struct stm32f4_uart *u )
{
assert(u->tx_dma->NDTR == 0);
assert( (u->tx_dma->CR & DMA_SxCR_EN) == 0);
assert( !xQueueIsQueueEmptyFromISR(u->tx_free_queue) || !xQueueIsQueueEmptyFromISR(u->tx_ready_queue) );
signed portBASE_TYPE woken = 0;
int res;
DMA_ClearITPendingBit(u->tx_dma, DMA_IT_TCIFx);
if( u->current_rx_buf_isr )
{
res = xQueueSendFromISR(u->tx_free_queue, &u->current_rx_buf_isr, &woken);
assert(res == pdTRUE );
u->current_rx_buf_isr = NULL;
}
struct stm32f4_uart_buffer * b = NULL;
res = xQueueReceiveFromISR(u->tx_ready_queue, &b, NULL);
u->current_rx_buf_isr = b;
if( res == pdTRUE )
{
assert(b);
u->tx_dma->M0AR = (uint32_t)b->data;
u->tx_dma->NDTR = b->size;
//DMA_ITConfig(u->tx_dma, DMA_IT_TC, ENABLE);
DMA_Cmd(u->tx_dma, ENABLE);
}
else
{
assert(!b);
//DMA_ITConfig(u->tx_dma, DMA_IT_TC, DISABLE);
}
return 0;
return woken;
}
ssize_t stm32f4_uart_dma_write(void *__cookie, const char *__buf, size_t __n)
{
size_t left = __n;
struct stm32f4_uart *u = __cookie;
struct stm32f4_uart_buffer *buf;
while( left )
{
int res = xQueueReceive(u->tx_free_queue, &buf, portMAX_DELAY);
assert(res == pdTRUE);
buf->size = left > sizeof_array(buf->data) ? sizeof_array(buf->data) : left;
memcpy(buf->data, __buf, buf->size);
left -= buf->size;
portENTER_CRITICAL();
{
res = xQueueSendToBackFromISR(u->tx_ready_queue, &buf, NULL);
assert(res);
if( u->tx_dma->NDTR == 0 )
{
stm32f4_uart_dma_tc_isr(u);
}
}
portEXIT_CRITICAL();
}
return __n;
}