您尚未登录。

楼主 #1 2018-01-11 15:54:44

LAQ
会员
注册时间: 2017-09-20
已发帖子: 38
积分: 38

关于ESP32的idf里面的freerots的系统文件

今天想调用idf里面的task.c文件里面的taskENTER_CRITICAL(mux);    /*进入临界区*/
但是不知道入口参数mux这个是什么来的,哪位大神可以指导下吗

离线

#2 2018-01-11 16:06:05

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,244
积分: 9197

Re: 关于ESP32的idf里面的freerots的系统文件

相当于Win32的这个
http://www.cnblogs.com/zhidao-chen/p/3853138.html

2:进入 EnterCriticalSection(&g_section);

....................需要保护的共享资源代码

3: 退出 LeaveCriticalSection(&g_section);

用于在多线程中保护这部分代码, 不能让两个线程同时进入这部分代码,
只有持有钥匙的线程才能进入。否则只能等别的线程把钥匙放弃(taskEXIT_CRITICAL),你拿到钥匙(taskENTER_CRITICAL)才能进入.





离线

楼主 #3 2018-01-11 16:59:39

LAQ
会员
注册时间: 2017-09-20
已发帖子: 38
积分: 38

Re: 关于ESP32的idf里面的freerots的系统文件

请问有没有关于ESP32的taskENTER_CRITICAL的用法例程提供下

离线

#4 2018-01-11 20:43:14

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,244
积分: 9197

Re: 关于ESP32的idf里面的freerots的系统文件

我全文搜过esp-idf的examples目录, 没有这个接口的调用。
都是在 freertos的实现里面调用。





离线

#5 2018-01-11 20:46:55

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,244
积分: 9197

Re: 关于ESP32的idf里面的freerots的系统文件

终于找到一个 taskEXIT_CRITICAL 的调用 demo: how-to-use-binary-semaphore-mutex-counting-semaphore-resource-management.html, 估计要科学上网了。

#include "esp_task_wdt.h"

int count = 0;
portMUX_TYPE mmux = portMUX_INITIALIZER_UNLOCKED;

void setup() {
  Serial.begin(112500);
  /* create Mutex */
  xTaskCreate(
      lowPriorityTask,           /* Task function. */
      "lowPriorityTask",        /* name of task. */
      10000,                    /* Stack size of task */
      NULL,                     /* parameter of the task */
      1,                        /* priority of the task */
      NULL);                    /* Task handle to keep track of created task */
  /* let lowPriorityTask run first */
  delay(500);
  /* let lowPriorityTask run first then create highPriorityTask */
  xTaskCreate(
      highPriorityTask,           /* Task function. */
      "highPriorityTask",        /* name of task. */
      10000,                    /* Stack size of task */
      NULL,                     /* parameter of the task */
      4,                        /* priority of the task */
      NULL);                    /* Task handle to keep track of created task */
}

void loop() {

}
void lowPriorityTask( void * parameter )
{
  for(;;){

    Serial.println("lowPriorityTask lock section");
    /* if using shceduler stopping way then
    un-comment/comments lines below accordingly */
    //vTaskSuspendAll();
    taskENTER_CRITICAL(&mmux);
    /* stop scheduler until this loop is finished */
    for(count=0; count<1000; count++){
      /* in general the watch dog timer willl be feed by RTOS
      but we disable scheduler so we have to feed it */
      esp_task_wdt_feed();
    }
    /* we resume the scheduler so highPriorityTask will run again */
   // xTaskResumeAll();
   taskEXIT_CRITICAL(&mmux);
    Serial.println("lowPriorityTask leave section");

  }
  vTaskDelete( NULL );
}

void highPriorityTask( void * parameter )
{
  for(;;){
    /* highPriorityTask is resumed, we will check the counter should be 1000 */
    Serial.print("highPriorityTask is running and count is ");
    Serial.println(count);
    /* delay so that lowPriorityTask has chance to run */
    delay(50);
  }
  vTaskDelete( NULL );
}





离线

#6 2018-01-11 21:42:12

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,244
积分: 9197

Re: 关于ESP32的idf里面的freerots的系统文件

2.4 Critical section
- A critical section is a region of code that need to be protected from any concurrent accesses to change it. The critical section must keep be short because in the critical section most of operations are suspended. If this section is long the suspension time is long too. It affect the behavior of the system.
- In order to implement critical section, there are 2 ways:
+ Call taskENTER_CRITICAL() before enter critical section and call taskEXIT_CRITICAL() after leaving it. Using these function we will disable most of interrupts.
+ Call vTaskSuspendAll() before enter critical section and call xTaskResumeAll() after leaving it. Using these functions we still keep interrupts.
Note: in general the watch dog timer willl be feed by RTOS but we disable scheduler so we have to feed it.
2.4.1 Demo
- In this demo, we create 2 tasks: low priority task and high priority task. The low priority task will go to the critical section and increase a counter by 1 until it reaches 1000. When low priority task leave critical section, we check the counter is 1000 from high priority task. It proves that high priority task is suspended.


google自动翻译:

2.4关键部分
- 关键部分是需要从任何并发访问保护来改变它的代码区域。关键部分必须保持短暂,因为在关键部分大多数操作被暂停。如果这部分时间太长,中止时间也很长。它影响系统的行为。
- 为了实现临界区,有两种方法:
+在进入临界区之前调用taskENTER_CRITICAL()并在离开之后调用taskEXIT_CRITICAL()。使用这些函数,我们将禁用大部分的中断。
+在进入临界区之前调用vTaskSuspendAll(),并在离开它之后调用xTaskResumeAll()。使用这些函数我们仍然保持中断。
注意:一般来说,看门狗定时器将由RTOS馈送,但是我们禁用调度器,所以我们必须喂它。
2.4.1演示
- 在这个演示中,我们创建了2个任务:低优先级任务和高优先级任务。低优先级任务将进入关键部分,并将计数器增加1,直到达到1000.当低优先级任务离开关键部分时,我们检查高优先级任务的计数器是1000。证明优先级高的任务暂停。





离线

楼主 #7 2018-01-12 09:32:15

LAQ
会员
注册时间: 2017-09-20
已发帖子: 38
积分: 38

Re: 关于ESP32的idf里面的freerots的系统文件

非常感谢

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn