www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 公眾號精選 > 技術(shù)讓夢想更偉大
[導(dǎo)讀]STM32CubeIDE在stm32開發(fā)者起著最基礎(chǔ)的作用,在STM32CubeIDE中配置FreeRTOS中間層時需要選擇interface,其中有三個選項:Disable、CMSIS_V1和CMSIS_V2

STM32CubeIDE在stm32開發(fā)者起著最基礎(chǔ)的作用,在STM32CubeIDE中配置FreeRTOS中間層時需要選擇interface,其中有三個選項:Disable、CMSIS_V1和CMSIS_V2

CMSIS定義了通用工具接口,并提供一致的設(shè)備支持,那么CMSIS_V1和CMSIS_V2有什么區(qū)別呢,該怎選擇呢?

微控制器軟件接口標(biāo)準(zhǔn)CMSIS

CMSIS ARM官方定義如下:

Cortex微控制器軟件接口標(biāo)準(zhǔn)(CMSIS)是獨(dú)立于供應(yīng)商的硬件抽象層,用于基于Arm Cortex處理器的微控制器,并且CMSIS提供了到處理器和外圍設(shè)備,實(shí)時操作系統(tǒng)以及中間件組件的接口,可以說非常實(shí)用。

CMSIS軟件接口簡化了軟件重用,減少了開發(fā)周期,而且也不受限操作系統(tǒng)的類型,去耦。

不同之處

  • RTOS v1使得軟件能夠在不同的實(shí)時操作系統(tǒng)下運(yùn)行(屏蔽不同RTOS提供的API的差別)

  • 而RTOS v2則是拓展了RTOS v1,兼容更多的CPU架構(gòu)和實(shí)時操作系統(tǒng)。

RTOS v1創(chuàng)建任務(wù)函數(shù)如下:

/*********************** Thread Management *****************************/
/**
* @brief  Create a thread and add it to Active Threads and set it to state READY.
* @param  thread_def    thread definition referenced with \ref osThread.
* @param  argument      pointer that is passed to the thread function as start argument.
* @retval thread ID for reference by other functions or NULL in case of error.
* @note   MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
*/
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
{
  TaskHandle_t handle; #if( configSUPPORT_STATIC_ALLOCATION == 1 ) &&  ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) {
    handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
              thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
              thread_def->buffer, thread_def->controlblock);
  } else { if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
              thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
              &handle) != pdPASS)  { return NULL;
    } 
  } #elif( configSUPPORT_STATIC_ALLOCATION == 1 ) handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
              thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
              thread_def->buffer, thread_def->controlblock); #else if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
                   thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
                   &handle) != pdPASS)  { return NULL;
  } #endif return handle;
}

RTOS v2創(chuàng)建任務(wù)函數(shù)如下:

osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
  const char *name;
  uint32_t stack;
  TaskHandle_t hTask;
  UBaseType_t prio;
  int32_t mem;

  hTask = NULL; if (!IS_IRQ() && (func != NULL)) {
    stack = configMINIMAL_STACK_SIZE;
    prio  = (UBaseType_t)osPriorityNormal;

    name = NULL;
    mem  = -1; if (attr != NULL) { if (attr->name != NULL) {
        name = attr->name;
      } if (attr->priority != osPriorityNone) {
        prio = (UBaseType_t)attr->priority;
      } if ((prio < osPriorityIdle) || (prio > osPriorityISR) || ((attr->attr_bits & osThreadJoinable) == osThreadJoinable)) { return (NULL);
      } if (attr->stack_size > 0U) {
        /* In FreeRTOS stack is not in bytes, but in sizeof(StackType_t) which is 4 on ARM ports.       */
        /* Stack size should be therefore 4 byte aligned in order to avoid division caused side effects */
        stack = attr->stack_size / sizeof(StackType_t);
      } if ((attr->cb_mem    != NULL) && (attr->cb_size    >= sizeof(StaticTask_t)) &&
          (attr->stack_mem != NULL) && (attr->stack_size >  0U)) {
        mem = 1;
      } else { if ((attr->cb_mem == NULL) && (attr->cb_size == 0U) && (attr->stack_mem == NULL)) {
          mem = 0;
        }
      }
    } else {
      mem = 0;
    } if (mem == 1) { #if (configSUPPORT_STATIC_ALLOCATION == 1) hTask = xTaskCreateStatic ((TaskFunction_t)func, name, stack, argument, prio, (StackType_t  *)attr->stack_mem,
                                                                                      (StaticTask_t *)attr->cb_mem); #endif } else { if (mem == 0) { #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) if (xTaskCreate ((TaskFunction_t)func, name, (uint16_t)stack, argument, prio, &hTask) != pdPASS) {
            hTask = NULL;
          } #endif }
    }
  } return ((osThreadId_t)hTask);
}

正常V1夠用了,普通功能選V1,高級功能選擇V2:

我分別選擇CMSIS_V1和CMSIS_V2編譯了兩次進(jìn)行對比,CMSIS_V2都要大一些。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀
關(guān)閉