Freertos代码之互斥信号量

2023-05-16

信号量用于限制对共享资源的访问和多任务之间的同步。三个信号量API函数都是宏,使用现有的队列实现。

使用例子:

typedef void * QueueHandle_t;
typedef QueueHandle_t SemaphoreHandle_t;

SemaphoreHandle_t mutex_sema;
mutex_sema = xSemaphoreCreateMutex();

 

xSemaphoreTake(mutex_sema, portMAX_DELAY);

/* 对共享资源的操作 */

xSemaphoreGive(mutex_sema);

 

代码:

/*

 * xSemaphoreCreateMutex

 */

#define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )

    QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )
    {
    Queue_t *pxNewQueue;
    const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;

        pxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType ); // 创建队列,注意参数.
        prvInitialiseMutex( pxNewQueue );  // 初始化刚创建的普通队列为互斥体

        return pxNewQueue;
    }

    static void prvInitialiseMutex( Queue_t *pxNewQueue )
    {
        if( pxNewQueue != NULL )
        {
            /* The queue create function will set all the queue structure members
            correctly for a generic queue, but this function is creating a
            mutex.  Overwrite those members that need to be set differently -
            in particular the information required for priority inheritance. */
            /* 队列创建函数将为通用队列正确设置所有队列结构成员,但此函数正在创建互斥体。
               覆盖那些需要以不同方式设置的成员-特别是优先级继承所需的信息 */

            // #define pxMutexHolder                pcTail
            // #define uxQueueType                    pcHead

            pxNewQueue->pxMutexHolder = NULL;
            pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;

            /* In case this is a recursive mutex. */
            pxNewQueue->u.uxRecursiveCallCount = 0;

            traceCREATE_MUTEX( pxNewQueue );

            /* Start with the semaphore in the expected state. */
            /* 从处于预期状态的信号量开始 */
            ( void ) xQueueGenericSend( pxNewQueue, NULL, ( TickType_t ) 0U, queueSEND_TO_BACK );
        }
        else
        {
            traceCREATE_MUTEX_FAILED();
        }
    }

 

/*

 * xSemaphoreTake

 */

#define xSemaphoreTake( xSemaphore, xBlockTime )        xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )

BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )
{
BaseType_t xEntryTimeSet = pdFALSE;
TimeOut_t xTimeOut;
Queue_t * const pxQueue = ( Queue_t * ) xQueue;

#if( configUSE_MUTEXES == 1 )
    BaseType_t xInheritanceOccurred = pdFALSE;
#endif

    /* Check the queue pointer is not NULL. */
    configASSERT( ( pxQueue ) );

    /* Check this really is a semaphore, in which case the item size will be
    0. 检查这是否是一个信号量,在这种情况下,项目大小将为0 */
    configASSERT( pxQueue->uxItemSize == 0 );

    /* Cannot block if the scheduler is suspended. 如果计划程序已挂起,则无法阻止 */
    #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
    {
        configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
    }
    #endif


    /* This function relaxes the coding standard somewhat to allow return
    statements within the function itself.  This is done in the interest
    of execution time efficiency. */
    /* 这个函数在一定程度上放宽了编码标准,允许函数本身内部有返回语句。这是为了提高执行时间效率 */

    for( ;; )
    {
        taskENTER_CRITICAL();
        {
            /* Semaphores are queues with an item size of 0, and where the
            number of messages in the queue is the semaphore's count value. */
            /* 信号量是项目大小为0的队列,其中队列中的消息数是信号量的计数值 */
            const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;

            /* Is there data in the queue now?  To be running the calling task
            must be the highest priority task wanting to access the queue. */
            /* 队列中现在有数据吗?要运行调用任务,必须是要访问队列的最高优先级任务 */
            if( uxSemaphoreCount > ( UBaseType_t ) 0 )
            {
                traceQUEUE_RECEIVE( pxQueue );

                /* Semaphores are queues with a data size of zero and where the
                messages waiting is the semaphore's count.  Reduce the count. */
                /* 信号量是数据大小为零的队列,其中等待的消息是信号量的计数。减少计数 */
                pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;

                #if ( configUSE_MUTEXES == 1 )
                {
                    if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
                    {
                        /* Record the information required to implement
                        priority inheritance should it become necessary. */
                        /* 如果有必要,记录实现优先级继承所需的信息 */
                        pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */
                    }
                    else
                    {
                        mtCOVERAGE_TEST_MARKER();
                    }
                }
                #endif /* configUSE_MUTEXES */

                /* Check to see if other tasks are blocked waiting to give the
                semaphore, and if so, unblock the highest priority such task. */
                /* 检查是否有其他任务在等待发出信号量时被阻塞,如果是,请取消阻止优先级最高的任务 */
                if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
                {
                    if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
                    {
                        queueYIELD_IF_USING_PREEMPTION();
                    }
                    else
                    {
                        mtCOVERAGE_TEST_MARKER();
                    }
                }
                else
                {
                    mtCOVERAGE_TEST_MARKER();
                }

                taskEXIT_CRITICAL();
                return pdPASS;
            }
            else
            {
                if( xTicksToWait == ( TickType_t ) 0 )
                {
                    /* For inheritance to have occurred there must have been an
                    initial timeout, and an adjusted timeout cannot become 0, as
                    if it were 0 the function would have exited. */
                    /* 要使继承发生,必须有一个初始超时,并且调整后的超时不能变为0,如果它为0,函数将退出 */
                    #if( configUSE_MUTEXES == 1 )
                    {
                        configASSERT( xInheritanceOccurred == pdFALSE );
                    }
                    #endif /* configUSE_MUTEXES */

                    /* The semaphore count was 0 and no block time is specified
                    (or the block time has expired) so exit now. */
                    /* 信号量计数为0,并且未指定块时间(或块时间已过期),因此请立即退出 */
                    taskEXIT_CRITICAL();
                    traceQUEUE_RECEIVE_FAILED( pxQueue );
                    return errQUEUE_EMPTY;
                }
                else if( xEntryTimeSet == pdFALSE )
                {
                    /* The semaphore count was 0 and a block time was specified
                    so configure the timeout structure ready to block. */
                    /* 信号量计数为0,并且指定了阻塞时间,因此请配置超时结构以准备阻塞 */
                    vTaskInternalSetTimeOutState( &xTimeOut );
                    xEntryTimeSet = pdTRUE;
                }
                else
                {
                    /* Entry time was already set. */
                    /* 已设置进入时间 */
                    mtCOVERAGE_TEST_MARKER();
                }
            }
        }
        taskEXIT_CRITICAL();

        /* Interrupts and other tasks can give to and take from the semaphore
        now the critical section has been exited. */
        /* 中断和其他任务可以对信号量进行交换,现在关键部分已经退出 */

        vTaskSuspendAll();
        prvLockQueue( pxQueue );

        /* Update the timeout state to see if it has expired yet. */
        /* 更新超时状态以查看它是否已过期 */
        if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
        {
            /* A block time is specified and not expired.  If the semaphore
            count is 0 then enter the Blocked state to wait for a semaphore to
            become available.  As semaphores are implemented with queues the
            queue being empty is equivalent to the semaphore count being 0. */
            /* 块时间已指定且未过期。如果信号量计数为0,则进入阻塞状态,等待信号量变为可用。
               由于信号量是用队列实现的,因此队列为空相当于信号量计数为0 */
            if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
            {
                traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );

                #if ( configUSE_MUTEXES == 1 )
                {
                    if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
                    {
                        taskENTER_CRITICAL();
                        {
                            xInheritanceOccurred = xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
                        }
                        taskEXIT_CRITICAL();
                    }
                    else
                    {
                        mtCOVERAGE_TEST_MARKER();
                    }
                }
                #endif

                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
                prvUnlockQueue( pxQueue );
                if( xTaskResumeAll() == pdFALSE )
                {
                    portYIELD_WITHIN_API();
                }
                else
                {
                    mtCOVERAGE_TEST_MARKER();
                }
            }
            else
            {
                /* There was no timeout and the semaphore count was not 0, so
                attempt to take the semaphore again. */
                /* 没有超时,信号量计数不为0,因此请尝试再次获取该信号量 */
                prvUnlockQueue( pxQueue );
                ( void ) xTaskResumeAll();
            }
        }
        else
        {
            /* Timed out. */
            prvUnlockQueue( pxQueue );
            ( void ) xTaskResumeAll();

            /* If the semaphore count is 0 exit now as the timeout has
            expired.  Otherwise return to attempt to take the semaphore that is
            known to be available.  As semaphores are implemented by queues the
            queue being empty is equivalent to the semaphore count being 0. */
            /* 如果信号量计数为0,则立即退出,因为超时已过期。否则返回尝试获取已知可用的信号量。
               由于信号量是由队列实现的,因此队列为空就等于信号量计数为0 */
            if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
            {
                #if ( configUSE_MUTEXES == 1 )
                {
                    /* xInheritanceOccurred could only have be set if
                    pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to
                    test the mutex type again to check it is actually a mutex. */
                    /* 只有当pxQueue->uxQueueType==queueQUEUE_IS_MUTEX时,才能设置xinHeritanceOccurrence,
                       因此无需再次测试互斥体类型以检查它是否是互斥体 */
                    if( xInheritanceOccurred != pdFALSE )
                    {
                        taskENTER_CRITICAL();
                        {
                            UBaseType_t uxHighestWaitingPriority;

                            /* This task blocking on the mutex caused another
                            task to inherit this task's priority.  Now this task
                            has timed out the priority should be disinherited
                            again, but only as low as the next highest priority
                            task that is waiting for the same mutex. */
                            /* 互斥体上的此任务阻塞导致另一个任务继承此任务的优先级。现在这个任务已经超时了,
                               应该再次取消优先级继承,但只能低到等待同一互斥锁的下一个最高优先级任务 */
                            uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );
                            vTaskPriorityDisinheritAfterTimeout( ( void * ) pxQueue->pxMutexHolder, uxHighestWaitingPriority );
                        }
                        taskEXIT_CRITICAL();
                    }
                }
                #endif /* configUSE_MUTEXES */

                traceQUEUE_RECEIVE_FAILED( pxQueue );
                return errQUEUE_EMPTY;
            }
            else
            {
                mtCOVERAGE_TEST_MARKER();
            }
        }
    }
}

/*

 * xSemaphoreGive

 */

#define xSemaphoreGive( xSemaphore )        xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )

BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition )
{
BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired;
TimeOut_t xTimeOut;
Queue_t * const pxQueue = ( Queue_t * ) xQueue;

    configASSERT( pxQueue );
    configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
    configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
    #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
    {
        configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
    }
    #endif


    /* This function relaxes the coding standard somewhat to allow return
    statements within the function itself.  This is done in the interest
    of execution time efficiency. */
    /* 这个函数在一定程度上放宽了编码标准,允许函数本身内部有返回语句。这是为了提高执行时间效率 */
    for( ;; )
    {
        taskENTER_CRITICAL();
        {
            /* Is there room on the queue now?  The running task must be the
            highest priority task wanting to access the queue.  If the head item
            in the queue is to be overwritten then it does not matter if the
            queue is full. */
            /* 现在排队还有空吗?正在运行的任务必须是要访问队列的最高优先级任务。如果要覆盖队列中的头项,那么队列是否已满并不重要 */
            if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
            {
                traceQUEUE_SEND( pxQueue );
                xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );

                #if ( configUSE_QUEUE_SETS == 1 )
                {
                    if( pxQueue->pxQueueSetContainer != NULL )
                    {
                        if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )
                        {
                            /* The queue is a member of a queue set, and posting
                            to the queue set caused a higher priority task to
                            unblock. A context switch is required. */
                            /* 队列是队列集的成员,投递到队列集中会导致优先级较高的任务取消阻止。需要上下文切换 */
                            queueYIELD_IF_USING_PREEMPTION();
                        }
                        else
                        {
                            mtCOVERAGE_TEST_MARKER();
                        }
                    }
                    else
                    {
                        /* If there was a task waiting for data to arrive on the
                        queue then unblock it now. */
                        /* 如果有一个任务正在等待数据到达队列,请立即取消阻止它 */
                        if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
                        {
                            if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
                            {
                                /* The unblocked task has a priority higher than
                                our own so yield immediately.  Yes it is ok to
                                do this from within the critical section - the
                                kernel takes care of that. */
                                /* 解除封锁的任务比我们的任务有更高的优先级,所以立刻让步。是的,在临界区内这样做是可以的-内核负责处理这个问题 */
                                queueYIELD_IF_USING_PREEMPTION();
                            }
                            else
                            {
                                mtCOVERAGE_TEST_MARKER();
                            }
                        }
                        else if( xYieldRequired != pdFALSE )
                        {
                            /* This path is a special case that will only get
                            executed if the task was holding multiple mutexes
                            and the mutexes were given back in an order that is
                            different to that in which they were taken. */
                            /* 此路径是一种特殊情况,只有当任务持有多个互斥锁,并且互斥锁的返回顺序与它们的获取顺序不同时,才会执行该路径 */
                            queueYIELD_IF_USING_PREEMPTION();
                        }
                        else
                        {
                            mtCOVERAGE_TEST_MARKER();
                        }
                    }
                }
                #else /* configUSE_QUEUE_SETS */
                {
                    /* If there was a task waiting for data to arrive on the
                    queue then unblock it now. */
                    /* 如果有一个任务正在等待数据到达队列,请立即取消阻止它 */
                    if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
                    {
                        if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
                        {
                            /* The unblocked task has a priority higher than
                            our own so yield immediately.  Yes it is ok to do
                            this from within the critical section - the kernel
                            takes care of that. */
                            /* 解除封锁的任务比我们的任务有更高的优先级,所以立刻让步。是的,在临界区内这样做是可以的-内核负责处理这个问题 */
                            queueYIELD_IF_USING_PREEMPTION();
                        }
                        else
                        {
                            mtCOVERAGE_TEST_MARKER();
                        }
                    }
                    else if( xYieldRequired != pdFALSE )
                    {
                        /* This path is a special case that will only get
                        executed if the task was holding multiple mutexes and
                        the mutexes were given back in an order that is
                        different to that in which they were taken. */
                        /* 此路径是一种特殊情况,只有当任务持有多个互斥锁,并且互斥锁的返回顺序与它们的获取顺序不同时,才会执行该路径 */
                        queueYIELD_IF_USING_PREEMPTION();
                    }
                    else
                    {
                        mtCOVERAGE_TEST_MARKER();
                    }
                }
                #endif /* configUSE_QUEUE_SETS */

                taskEXIT_CRITICAL();
                return pdPASS;
            }
            else
            {
                if( xTicksToWait == ( TickType_t ) 0 )
                {
                    /* The queue was full and no block time is specified (or
                    the block time has expired) so leave now. */
                    /* 队列已满,未指定块时间(或块时间已过期),请立即离开 */
                    taskEXIT_CRITICAL();

                    /* Return to the original privilege level before exiting
                    the function. */
                    /* 在退出函数之前返回到原始权限级别 */
                    traceQUEUE_SEND_FAILED( pxQueue );
                    return errQUEUE_FULL;
                }
                else if( xEntryTimeSet == pdFALSE )
                {
                    /* The queue was full and a block time was specified so
                    configure the timeout structure. */
                    /* 队列已满,并且指定了块时间,因此请配置超时结构 */
                    vTaskInternalSetTimeOutState( &xTimeOut );
                    xEntryTimeSet = pdTRUE;
                }
                else
                {
                    /* Entry time was already set. */
                    /* 已设置进入时间 */
                    mtCOVERAGE_TEST_MARKER();
                }
            }
        }
        taskEXIT_CRITICAL();

        /* Interrupts and other tasks can send to and receive from the queue
        now the critical section has been exited. */
        /* 中断和其他任务可以发送到队列或从队列接收,现在关键部分已经退出 */

        vTaskSuspendAll();
        prvLockQueue( pxQueue );

        /* Update the timeout state to see if it has expired yet. */
        /* 更新超时状态以查看它是否已过期 */
        if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
        {
            if( prvIsQueueFull( pxQueue ) != pdFALSE )
            {
                traceBLOCKING_ON_QUEUE_SEND( pxQueue );
                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );

                /* Unlocking the queue means queue events can effect the
                event list.  It is possible that interrupts occurring now
                remove this task from the event list again - but as the
                scheduler is suspended the task will go onto the pending
                ready last instead of the actual ready list. */
                /* 解锁队列意味着队列事件可以影响事件列表。现在发生的中断可能会再次将此任务从事件列表中删除-但是由于调度程序被挂起,
                   任务将转到挂起的就绪最后一个,而不是实际的就绪列表 */
                prvUnlockQueue( pxQueue );

                /* Resuming the scheduler will move tasks from the pending
                ready list into the ready list - so it is feasible that this
                task is already in a ready list before it yields - in which
                case the yield will not cause a context switch unless there
                is also a higher priority task in the pending ready list. */
                /* 恢复调度程序会将任务从挂起的就绪列表移动到就绪列表中—因此,此任务在其生成之前已经在就绪列表中是可行的—在这种情况下,
                   除非挂起的就绪列表中还有更高优先级的任务,否则产生的结果不会导致上下文切换 */
                if( xTaskResumeAll() == pdFALSE )
                {
                    portYIELD_WITHIN_API();
                }
            }
            else
            {
                /* Try again. */
                prvUnlockQueue( pxQueue );
                ( void ) xTaskResumeAll();
            }
        }
        else
        {
            /* The timeout has expired. */
            /* 超时已过期 */
            prvUnlockQueue( pxQueue );
            ( void ) xTaskResumeAll();

            traceQUEUE_SEND_FAILED( pxQueue );
            return errQUEUE_FULL;
        }
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Freertos代码之互斥信号量 的相关文章

  • FreeRTOS例程4-串口DMA收发不定长数据

    FreeRTOS例程4 串口DMA收发不定长数据 知乎 zhihu com
  • FreeRTOS内核配置说明---FreeRTOS Kernel V10.2.1

    FreeRTOS内核是高度可定制的 使用配置文件FreeRTOSConfig h进行定制 每个FreeRTOS应用都必须包含这个头文件 用户根据实际应用来裁剪定制FreeRTOS内核 这个配置文件是针对用户程序的 而非内核 因此配置文件一般
  • FreeRTOS-内核控制函数

    FreeRTOS 内核控制函数 FreeRTOS中有一些内核函数 一般来说这些内核函数在应用层不会使用 但是内核控制函数是理解FreeRTOS中断的基础 接下来我们逐一分析这些内核函数 taskYIELD 该函数的作用是进行任务切换 这是一
  • FreeRTOS软件定时器创建、复位、开始和停止(备忘)

    目录 一 简介 1 1 开发环境 1 2 摘要 二 STM32CubeIDE配置 三 创建定时器 3 1 头文件声明 3 2 工程文件定义 3 3 创建定时器 3 4 开启 复位 和关闭定时器 四 定时器回调函数 一 简介 1 1 开发环境
  • 【FreeRTOS】多任务创建

    作者主页 凉开水白菜 作者简介 共同学习 互相监督 热于分享 多加讨论 一起进步 专栏资料 https pan baidu com s 1nc1rfyLiMyw6ZhxiZ1Cumg pwd free 点赞 收藏 再看 养成习惯 订阅的粉丝
  • 【FreeRTOS开发问题】FreeRTOS内存溢出

    FreeRTOS内存溢出 如下图所示 FreeRTOS编译完成后可以看到 系统提示无法分配内存到堆 Objects Template axf Error L6406E No space in execution regions with A
  • FreeRTOS ------- 任务(task)

    在学习RTOS的时候 个人觉得带着问题去学习 会了解到更多 1 什么是任务 在FreeRTOS中 每个执行线程都被称为 任务 每个任务都是在自己权限范围内的一个小程序 其具有程序入口每个任务都是在自己权限范围内的一个小程序 其具有程序入口通
  • 基于HAL库的FREERTOS----------一.任务

    FreeROTS 就是一个免费的 RTOS 类系统 这里要注意 RTOS 不是指某一个确定的系统 而是指一类系统 比如 UCOS FreeRTOS RTX RT Thread 等这些都是 RTOS 类操作系统 FreeRTOS 是 RTOS
  • Error: L6218E: Undefined symbol vApplicationGetIdleTaskMemory (referred from tasks.o).

    我用的是F103ZET6的板子 移植成功后 编译出现两个错误是关于stm32f10x it c 里 void SVC Handler void void PendSV Handler void 两个函数的占用问题 随后编译出现以下两个问题
  • FreeRTOS基础五:软件定时器

    软件定时器简介 软件定时器的作用 在指定的时间到来时执行指定的函数 或者以某个频率周期性地执行某个函数 被执行的函数叫做软件定时器回调函数 软件定时器由FreeRTOS内核实现 不需要硬件支持 软件定时器只有在软件定时器回调函数被调用时才需
  • FreeRTOS之事件

    FreeRTOS之事件 声明 本人按照正点原子的FreeRTOS例程进行学习的 欢迎各位大佬指责和批评 谢谢 一 事件定义 事件 事件集 与高数上的集合意义差不多 事件啊 其实是实现任务间通信的机制 主要用于实现多任务间的同步 但是事件类型
  • 啊哈C的简单使用

    打开啊哈C 新建一个程序输出hello world include
  • 【FreeRTOS 事件】任务通知事件

    普通任务通知事件创建创建及运行 参阅安富莱电子demo define BIT 0 1 lt lt 0 define BIT 1 1 lt lt 1 static TaskHandle t xHandleTaskUserIF NULL sta
  • STM32 Freertos 添加 外部sram heap_5.c

    1 添加外部SRAM 初始化 2 添加heap 5 c 3 初始化heap 5 c 外部堆栈 Define the start address and size of the two RAM regions not used by the
  • 使用 GCC 编译器的 ARM 内核的堆栈回溯(当存在 MSP 到 PSP 切换时)

    核心 ARM Cortex M4 编译器 GCC 5 3 0 ARM EABI 操作系统 免费 RTOS 我正在使用 gcc 库函数 Unwind Reason Code Unwind Backtrace Unwind Trace Fn v
  • 如何更改 FreeRTOS 中任务的最大可用堆大小?

    我通过以下方式在任务中创建元素列表 l dllist pvPortMalloc sizeof dllist dlllist 有 32 字节大 我的嵌入式系统有 60kB SRAM 所以我希望系统可以轻松处理我的 200 个元素列表 我发现在
  • C++ freeRTOS任务,非静态成员函数的无效使用

    哪里有问题 void MyClass task void pvParameter while 1 this gt update void MyClass startTask xTaskCreate this gt task Task 204
  • 哪些变量类型/大小在 STM32 微控制器上是原子的?

    以下是 STM32 微控制器上的数据类型 http www keil com support man docs armcc armcc chr1359125009502 htm http www keil com support man d
  • 有关 CMake 错误的问题:没有为目标提供源

    我正在尝试使用 cmake 和 eclipse 将 FreeRtos 添加到我的项目中 但出现错误 我运行的是 debian 10 我的 cmake 版本是 3 13 4 cmake 的文件可以在以下位置找到这个 git 仓库 https
  • 当 Cortex-M3 出现硬故障时如何保留堆栈跟踪?

    使用以下设置 基于 Cortex M3 的 C gcc arm 交叉工具链 https launchpad net gcc arm embedded 使用 C 和 C FreeRtos 7 5 3 日食月神 Segger Jlink 与 J

随机推荐

  • 二重积分和雅可比行列式

    我们以二重积分为例进行说明 xff0c 首先说结论 xff1a 一 结论 若x 61 x u v y 61 y u v 存在偏导数 xff0c 则二阶雅可比行列式为 61 61 dxdy 61 J2 dudv J2的绝对值 且 其中积分区域
  • 雅可比行列式和雅可比矩阵

    接触雅可比行列式是在二重积分的变量变换中 xff0c 参见我的另一篇文章https blog csdn net xiaoyink article details 88432372 下面我们来详细说明一下雅可比行列式和雅可比矩阵 雅可比矩阵
  • jlink-v8 固件修复

    一 先说 jlink v8 v9 v10区别 v8基本价格在40左右 xff0c 芯片是atml的 xff0c 但是很多反应是掉固件和提示盗版问题 v9现在主流 xff0c 盗版价100左右 xff0c 主控芯片stm32 做的比较成熟 x
  • kubernetes学习-快速上手速查手册

    目录 使用k3s快速搭建k8s安装k8s dashboard使用Helm部署K8S资源k8s核心命令一切推倒重来资源创建方式NamespacePodDeploymentServiceIngress解决官网Ingress安装不了问题使用方式
  • 作为一个4年程序员至少需要掌握的专业技能

    一名3年工作经验的程序员应该具备的技能 xff0c 在机缘巧合之中 xff0c 看了这篇博客 感觉自己真的是很差 xff0c 一直想着会写if else 就已经是一名程序员了 xff0c 在工作之余也很少学习 于是 xff0c 自己的cod
  • C语言与C++的区别

    一 C 43 43 简介 本贾尼 斯特劳斯特鲁普 于1979年4月在贝尔实验室负责分析UNIX系统的内核的流量情况 于1979年10月开始着手开发一种新的编程语言 在C语言的基础上增加了面向对象机制 这就是C 43 43 的来历 在1983
  • 我的2011-当梦想照进现实

    我的2011年 xff0c 之所以是现在的样子 xff0c 始缘于我三年前的一个决定 离职考研 对于工作了两年的我来说 xff0c 离职考研是人生的一场博弈 我的2011年 xff0c 结束了研究生期间对三维骨骼动画渲染的相关研究 xff0
  • Dockerfile RUN 同时执行多条命令

    Dockerfile RUN 同时执行多条命令 Dokcerfile中的命令每执行一条即产生一个新的镜像 xff0c 当前命令总是在最新的镜像上执行 如下Dockerfile xff1a RUN span class hljs built
  • HC-SR04超声波模块使用记录

    文章目录 HC SR04超声波模块使用记录轮询测量方式一 模块使用中的问题二 应对方法三 注意 分时测量利用输入捕获测量利用输入捕获测量 HC SR04超声波模块使用记录 具体使用方法见HC SR04使用手册 xff0c 本文重点记录该模块
  • 【C语言冒泡排序、选择排序和快速排序】

    文章目录 前言一 冒泡排序二 选择排序三 快速排序四 代码设计与实现代码设计代码实现 调试结果冒泡排序改良 延伸思考总结 前言 本文简单介绍了C语言的冒泡排序 选择排序 快速排序 xff0c 结合本人的理解与使用做一下记录 一 冒泡排序 思
  • 平衡车制作---原理篇

    平衡车制作 原理篇 文章目录 平衡车制作 原理篇前言直立控制直观感受内部机理 速度控制方向控制总结 前言 本篇教程内容主要来自于 直立平衡车模参考设计方案 xff0c 且这里是从概念层面讲述的并没有具体的控制理论方面的内容 有了这些概念方面
  • FreeRTOS使用注意

    FreeRTOS使用注意 xff1a 中断中必须使用带FromISR结尾的API函数只有中断优先级处于FreeRTOS可管理的范围内时 xff0c 才能使用FreeRTOS提供的API函数中断中不要使用FreeRTOS提供的内存申请和释放函
  • 现代控制理论基础总结

    现代控制理论基础总结 xff08 线性部分 xff09 学习现代控制理论也有两个月的时间了 xff0c 里面涉及的基础内容和公式十分之多 xff0c 所以现在对各部分基础知识作一个总结 1 控制系统的状态表达式 在现代控制理论中 xff0c
  • 题库(关于c++的网站都盘了)大盘点(好多没盘到)

    1 keda ac 2 hydro ac 3 luogu com cn 4 cplusplus com 5 leetcode cn 6 https loj ac 7 noi cn 8 ybt ssoier cn 8088 9 learncp
  • 利用MapReduce进行二次排序--附例子

    首先先来明确几个概念 xff1a 1 分区 partition 1 xff09 分区 xff08 partition xff09 xff1a 默认采取散列值进行分区 xff0c 但此方法容易造成 数据倾斜 xff08 大部分数据分到同一个r
  • MapReduce之单表关联Join输出祖父母、孙子---(附例子)

    需求 xff1a 一个文件 xff0c 有子女和对应的父母 xff0c 要求输出 祖父母 孙子 xff0c 文件如下 xff1a 单表关联 结果 xff1a child parent grand child Tom Lucy Alice T
  • 如何把 ubuntu 16.04.7 命令行界面下的系统语言更改为中文?

    如果你的 ubuntu 16 04 7 系统在命令行下的默认语言是英文 xff0c 比如下面这样 xff1a 怎么更改才能让某些输出单词显示成中文呢 xff1f 可以修改 etc default locale 这个文件 xff0c 先看一下
  • 小程序云开发实现订阅消息

    链接 简书博主示例 xff1a https www jianshu com p d90f22dac001 官方文档 xff1a 官方文档1 文档2 云调用 使用方法demo 假如这是一个点餐系统 xff0c 想让顾客下单以后 xff0c 派
  • ue4 常见问题解答

    1 如何让客户端自动连接服务器 span style color 0000aa MyGame span span style color 000066 span span style color 000066 exe span span s
  • Freertos代码之互斥信号量

    信号量用于限制对共享资源的访问和多任务之间的同步 三个信号量API函数都是宏 xff0c 使用现有的队列实现 使用例子 typedef void QueueHandle t typedef QueueHandle t SemaphoreHa