开源鸿蒙 CMSIS Support

2022-08-09 浏览 (1003)

CMSIS Support

Basic Concepts

The Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for microcontrollers based on Arm Cortex processors. Of the CMSIS components, the Real Time Operating System (RTOS) defines a set of universal and standardized APIs to reduce the dependency of application developers on specific RTOS and facilitate software porting and reuse. The CMSIS provides CMSIS-RTOS v1 and CMSIS-RTOS v2. The OpenHarmony LiteOS-M supports only the implementation of CMSIS-RTOS v2.

Development Guidelines

Available APIs

The following table describes CMSIS-RTOS v2 APIs. For more details about the APIs, see the API reference.

Table 1 CMSIS-RTOS v2 APIs

CategoryAPIDescription
Kernel information and controlosKernelGetInfoObtains RTOS kernel information.
osKernelGetStateObtains the current RTOS kernel status.
osKernelGetSysTimerCountObtains the RTOS kernel system timer count.
osKernelGetSysTimerFreqObtains the RTOS kernel system timer frequency.
osKernelInitializeInitializes the RTOS kernel.
osKernelLockLocks the RTOS kernel scheduler.
osKernelUnlockUnlocks the RTOS kernel scheduler.
osKernelRestoreLockRestores the RTOS kernel scheduler to the locked state.
osKernelResumeRestores the RTOS kernel scheduler (not implemented yet).
osKernelStartStarts the RTOS kernel scheduler.
osKernelSuspendSuspends the RTOS kernel scheduler (not implemented yet).
osKernelGetTickCountObtains the RTOS kernel tick count.
osKernelGetTickFreqObtains the RTOS kernel tick frequency.
Thread managementosThreadDetachDetaches a thread (to reclaim the thread storage when the thread terminates).
osThreadEnumerateEnumerates active threads (not been implemented yet).
osThreadExitTerminates a running thread.
osThreadGetCountObtains the number of active threads.
osThreadGetIdObtains the ID of the running thread.
osThreadGetNameObtains the thread name.
osThreadGetPriorityObtains the current thread priority.
osThreadGetStackSizeObtains the thread stack size.
osThreadGetStackSpaceObtains the available stack space for a thread based on the stack waterline record during execution.
osThreadGetStateObtains the current thread status.
osThreadJoinWaits for the specified thread to terminate.
osThreadNewCreates a thread and adds it to active threads.
osThreadResumeResumes the execution of a thread.
osThreadSetPriorityChanges the priority of a thread.
osThreadSuspendSuspends a thread.
osThreadTerminateTerminates a thread.
osThreadYieldPasses control to the next thread in the ready state.
Thread flagosThreadFlagsSetSets flags for a thread.
osThreadFlagsClearClears the specified flags for the running thread.
osThreadFlagsGetObtains the current flags of the running thread.
osThreadFlagsWaitWaits for one or more thread flags of the running thread to signal.
Event flagosEventFlagsGetNameObtains the names of the event flags (not implemented yet).
osEventFlagsNewCreates and initializes event flags.
osEventFlagsDeleteDeletes event flags.
osEventFlagsSetSets event flags.
osEventFlagsClearClears event flags.
osEventFlagsGetObtains the current event flags.
osEventFlagsWaitWaits for one or more event flags to be signaled.
General waiting functionsosDelayWaits for timeout (time delay).
osDelayUntilWaits until the specified time.
Timer managementosTimerDeleteDeletes a timer.
osTimerGetNameObtains the timer name (not implemented yet).
osTimerIsRunningChecks whether a timer is running.
osTimerNewCreates and initializes a timer.
osTimerStartStarts or restarts a timer.
osTimerStopStops a timer.
Mutex managementosMutexAcquireAcquires a mutex or times out (if locked).
osMutexDeleteDeletes a mutex.
osMutexGetNameObtains the mutex name (not implemented yet).
osMutexGetOwnerObtains the thread that acquires the mutex.
osMutexNewCreates and initializes a mutex.
osMutexReleaseReleases the mutex obtained using osMutexAcquire.
SemaphoreosSemaphoreAcquireObtains the semaphore token or times out if no token is available.
osSemaphoreDeleteDeletes a semaphore.
osSemaphoreGetCountObtains the token count of the current semaphore.
osSemaphoreGetNameObtains the name of a semaphore (not implemented yet).
osSemaphoreNewCreates and initializes a semaphore.
osSemaphoreReleaseReleases semaphore tokens till the initial maximum count.
Memory poolosMemoryPoolAllocAllocates a memory block from the memory pool.
osMemoryPoolDeleteDeletes a memory pool object.
osMemoryPoolFreeReleases the allocated memory block to the memory pool.
osMemoryPoolGetBlockSizeObtains the memory block size in the memory pool.
osMemoryPoolGetCapacityObtains the maximum number of memory blocks in the memory pool.
osMemoryPoolGetCountObtains the number of used memory blocks in the memory pool.
osMemoryPoolGetNameObtains the memory pool name.
osMemoryPoolGetSpaceObtains the number of available memory blocks in the memory pool.
osMemoryPoolNewCreates and initializes a memory pool.
Message queueosMessageQueueDeleteDeletes a message queue.
osMessageQueueGetObtain a message from the queue or times out if the queue is empty.
osMessageQueueGetCapacityObtains the maximum number of messages in the message queue.
osMessageQueueGetCountObtains the number of queued messages in the message queue.
osMessageQueueGetMsgSizeObtains the maximum message size in the memory pool.
osMessageQueueGetNameObtains the message queue name (not implemented yet).
osMessageQueueGetSpaceObtains the number of slots available for messages in the message queue.
osMessageQueueNewCreates and initializes a message queue.
osMessageQueuePutPuts the message into the queue or times out if the queue is full.
osMessageQueueResetInitialized the message queue to the empty state (not implemented yet).

How to Develop

The CMSIS-RTOS v2 component can be provided as a library (shown in the figure) or source code. By adding the CMSIS-RTOS v2 component (typically configuration files), you can implement RTOS capabilities on CMSIS-based applications. You only need to include the cmsis_os2.h header file. RTOS APIs can then be called to process RTOS kernel-related events. You do not need to recompile the source code when the kernel is replaced.

The RTOS object control block definition needs to be called for static object allocation. The implementation-specific header file (os_xx.h in the following figure) provides access to such control block definitions. In the OpenHarmony LiteOS-M kernel, the header files whose names start with los_ provide the definitions of the kernel.

Development Example

#include ...
#include "cmsis_os2.h"

/*----------------------------------------------------------------------------
 * Application main thread
 *---------------------------------------------------------------------------*/
void app_main (void *argument) {
  // ...
  for (;;) {}
}

int main (void) {
 // Initialize the system.
  MySystemInit();
  // ...

  osKernelInitialize();                // Initialize CMSIS-RTOS.
  osThreadNew(app_main, NULL, NULL);    // Create the main thread of the application.
  osKernelStart();                     // Start to execute the thread.
  for (;;) {}
}

你可能感兴趣的文章

开源鸿蒙 Kernel

开源鸿蒙 Time Management

开源鸿蒙 Appendix

开源鸿蒙 Kernel Coding Specification

开源鸿蒙 Doubly Linked List

开源鸿蒙 Basic Data Structure

开源鸿蒙 POSIX Support

开源鸿蒙 Standard Libraries

开源鸿蒙 Interrupt Management

开源鸿蒙 Event

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/91fecbbe0b41415592c0e25ac8500e67