cmsis_os2.h 34.1 KB
Newer Older
Y
y00580916 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
/*
 * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ----------------------------------------------------------------------
 *
 * $Date:        18. June 2018
 * $Revision:    V2.1.3
 *
 * Project:      CMSIS-RTOS2 API
 * Title:        cmsis_os2.h header file
 *
 * Version 2.1.3
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osThreadGetId
 * Version 2.1.2
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osKernelGetInfo, osKernelGetState
 * Version 2.1.1
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osKernelGetTickCount, osKernelGetTickFreq
 *    Changed Kernel Tick type to uint32_t:
 *    - updated: osKernelGetTickCount, osDelayUntil
 * Version 2.1.0
 *    Support for critical and uncritical sections (nesting safe):
 *    - updated: osKernelLock, osKernelUnlock
 *    - added: osKernelRestoreLock
 *    Updated Thread and Event Flags:
 *    - changed flags parameter and return type from int32_t to uint32_t
 * Version 2.0.0
 *    Initial Release
 *---------------------------------------------------------------------------*/

/**
 * @addtogroup CMSIS
 * @{
 *
 * @brief Provides standard, universal real-time operating system (RTOS) APIs.
 *
 * CMSIS Module may contain portions from ARM Cortex Microcontroller Software Interface Standard (CMSIS) licensed under Apache License v2.0.
 *
 * @since 1.0
 * @version 1.0
 */

#ifndef CMSIS_OS2_H_
#define CMSIS_OS2_H_

#ifndef __NO_RETURN
#if   defined(__CC_ARM)
#define __NO_RETURN __declspec(noreturn)
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__GNUC__)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__ICCARM__)
#define __NO_RETURN __noreturn
#else
#define __NO_RETURN
#endif
#endif

#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif


//  ==== Enumerations, structures, defines ====

/**
* @brief Describes the system version.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** API version */
  uint32_t                       api;
  /** Kernel version */
  uint32_t                    kernel;
} osVersion_t;

/**
* @brief Enumerates kernel states.
*
*/
typedef enum {
  /** The kernel is inactive. */
  osKernelInactive        =  0,
  /** The kernel is ready. */
  osKernelReady           =  1,
  /** The kernel is running. */
  osKernelRunning         =  2,
  /** The kernel is locked. */
  osKernelLocked          =  3,
  /** The kernel is suspended. */
  osKernelSuspended       =  4,
  /** The kernel is abnormal. */
  osKernelError           = -1,
  /** Reserved */
  osKernelReserved        = 0x7FFFFFFFU
} osKernelState_t;

/**
* @brief Enumerates thread states.
*
*/
typedef enum {
  /** The thread is inactive. */
  osThreadInactive        =  0,
  /** The thread is ready. */
  osThreadReady           =  1,
  /** The thread is running. */
  osThreadRunning         =  2,
  /** The thread is blocked. */
  osThreadBlocked         =  3,
  /** The thread is terminated. */
  osThreadTerminated      =  4,
  /** The thread is abnormal. */
  osThreadError           = -1,
  /** Reserved */
  osThreadReserved        = 0x7FFFFFFF
} osThreadState_t;

/**
* @brief Enumerates thread priorities.
*
*/
typedef enum {
  /** Undefined */
  osPriorityNone          =  0,
  /** Reserved for idle threads */
  osPriorityIdle          =  1,
W
w00562794 已提交
150
  /** Low (unsupported) */
Y
y00580916 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  osPriorityLow           =  8,
  /** Low + 1 */
  osPriorityLow1          =  8+1,
  /** Low + 2 */
  osPriorityLow2          =  8+2,
  /** Low + 3 */
  osPriorityLow3          =  8+3,
  /** Low + 4 */
  osPriorityLow4          =  8+4,
  /** Low + 5 */
  osPriorityLow5          =  8+5,
  /** Low + 6 */
  osPriorityLow6          =  8+6,
  /** Low + 7 */
  osPriorityLow7          =  8+7,
  /** Below normal */
  osPriorityBelowNormal   = 16,
  /** Below normal + 1 */
  osPriorityBelowNormal1  = 16+1,
  /** Below normal + 2 */
  osPriorityBelowNormal2  = 16+2,
  /** Below normal + 3 */
  osPriorityBelowNormal3  = 16+3,
  /** Below normal + 4 */
  osPriorityBelowNormal4  = 16+4,
  /** Below normal + 5 */
  osPriorityBelowNormal5  = 16+5,
  /** Below normal + 6 */
  osPriorityBelowNormal6  = 16+6,
  /** Below normal + 7 */
  osPriorityBelowNormal7  = 16+7,
  /** Normal */
  osPriorityNormal        = 24,
  /** Normal + 1 */
  osPriorityNormal1       = 24+1,
  /** Normal + 2 */
  osPriorityNormal2       = 24+2,
  /** Normal + 3 */
  osPriorityNormal3       = 24+3,
  /** Normal + 4 */
  osPriorityNormal4       = 24+4,
  /** Normal + 5 */
  osPriorityNormal5       = 24+5,
  /** Normal + 6 */
  osPriorityNormal6       = 24+6,
  /** Normal + 7 */
  osPriorityNormal7       = 24+7,
  /** Above normal */
  osPriorityAboveNormal   = 32,
  /** Above normal + 1 */
  osPriorityAboveNormal1  = 32+1,
  /** Above normal + 2 */
  osPriorityAboveNormal2  = 32+2,
  /** Above normal + 3 */
  osPriorityAboveNormal3  = 32+3,
  /** Above normal + 4 */
  osPriorityAboveNormal4  = 32+4,
  /** Above normal + 5 */
  osPriorityAboveNormal5  = 32+5,
  /** Above normal + 6 */
  osPriorityAboveNormal6  = 32+6,
W
w00562794 已提交
212
  /** Above normal + 7 (unsupported) */
Y
y00580916 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
  osPriorityAboveNormal7  = 32+7,
  /** High (unsupported) */
  osPriorityHigh          = 40,
  /** High + 1 (unsupported) */
  osPriorityHigh1         = 40+1,
  /** High + 2 (unsupported)  */
  osPriorityHigh2         = 40+2,
  /** High + 3 (unsupported)  */
  osPriorityHigh3         = 40+3,
  /** High + 4 (unsupported)  */
  osPriorityHigh4         = 40+4,
  /** High + 5 (unsupported)  */
  osPriorityHigh5         = 40+5,
  /** High + 6 (unsupported)  */
  osPriorityHigh6         = 40+6,
  /** High + 7 (unsupported)  */
  osPriorityHigh7         = 40+7,
  /** Real-time (unsupported)  */
  osPriorityRealtime      = 48,
  /** Real-time + 1 (unsupported) */
  osPriorityRealtime1     = 48+1,
  /** Real-time + 2 (unsupported) */
  osPriorityRealtime2     = 48+2,
  /** Real-time + 3 (unsupported) */
  osPriorityRealtime3     = 48+3,
  /** Real-time + 4 (unsupported) */
  osPriorityRealtime4     = 48+4,
  /** Real-time + 5 (unsupported) */
  osPriorityRealtime5     = 48+5,
  /** Real-time + 6 (unsupported) */
  osPriorityRealtime6     = 48+6,
  /** Real-time + 7 (unsupported) */
  osPriorityRealtime7     = 48+7,
  /** Reserved for ISR deferred threads (unsupported) */
  osPriorityISR           = 56,
  /** Invalid */
  osPriorityError         = -1,
  /** Reserved. It enables the compiler to identify enumeration variables as 32-bit numbers and prevents the enumeration variables from being optimized. */
  osPriorityReserved      = 0x7FFFFFFF
} osPriority_t;

/**
* @brief Callback for thread scheduling
*
*/
typedef void (*osThreadFunc_t) (void *argument);

/**
* @brief Callback for timer triggering
*
*/
typedef void (*osTimerFunc_t) (void *argument);

/**
* @brief Enumerates timer types.
*
*/
typedef enum {
  /** One-shot timer */
  osTimerOnce               = 0,
  /** Repeating timer */
  osTimerPeriodic           = 1
} osTimerType_t;

/**
* @brief Indicates that the RTOS waits forever unless an event flag is received.
*
*/
#define osWaitForever         0xFFFFFFFFU

/**
* @brief Indicates that the RTOS does not wait.
*
*/
#define osNoWait              0x0U

/**
* @brief Indicates that the RTOS waits until any event flag is triggered.
*
*/
#define osFlagsWaitAny        0x00000000U

/**
* @brief Indicates that the system waits until all event flags are triggered.
*
*/
#define osFlagsWaitAll        0x00000001U

/**
* @brief Indicates that defined flags are not cleared.
*
*/
#define osFlagsNoClear        0x00000002U

/**
* @brief Indicates a flag error.
*
*/
#define osFlagsError          0x80000000U

/**
* @brief Indicates an unknown error.
*
*/
#define osFlagsErrorUnknown   0xFFFFFFFFU

/**
* @brief Indicates a timeout.
*
*/
#define osFlagsErrorTimeout   0xFFFFFFFEU

/**
* @brief Indicates a resource error.
*
*/
#define osFlagsErrorResource  0xFFFFFFFDU

/**
* @brief Indicates an incorrect parameter.
*
*/
#define osFlagsErrorParameter 0xFFFFFFFCU
#define osFlagsErrorISR       0xFFFFFFFAU

// Thread attributes (attr_bits in \ref osThreadAttr_t).
#define osThreadDetached      0x00000000U
#define osThreadJoinable      0x00000001U

// Mutex attributes (attr_bits in \ref osMutexAttr_t).
#define osMutexRecursive      0x00000001U
#define osMutexPrioInherit    0x00000002U
#define osMutexRobust         0x00000008U

/**
* @brief Enumerates return values of CMSIS-RTOS.
*
*/
typedef enum {
  /** Operation completed successfully */
  osOK                      =  0,
  /** Unspecified error */
  osError                   = -1,
  /** Timeout */
  osErrorTimeout            = -2,
  /** Resource error */
  osErrorResource           = -3,
  /** Incorrect parameter */
  osErrorParameter          = -4,
  /** Insufficient memory */
  osErrorNoMemory           = -5,
  /** Service interruption */
  osErrorISR                = -6,
  /** Reserved. It is used to prevent the compiler from optimizing enumerations. */
  osStatusReserved          = 0x7FFFFFFF
} osStatus_t;

/**
* @brief Identifies a thread.
*
*/
typedef void *osThreadId_t;

/**
* @brief Identifies a timer.
*
*/
typedef void *osTimerId_t;

/**
* @brief Identifies an event flag.
*
*/
typedef void *osEventFlagsId_t;

/**
* @brief Identifies a mutex.
*
*/
typedef void *osMutexId_t;

/**
* @brief Identifies a semaphore object.
*
*/
typedef void *osSemaphoreId_t;


typedef void *osMemoryPoolId_t;

/**
* @brief Identifies a message queue.
*
*/
typedef void *osMessageQueueId_t;


#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T

/**
* @brief Identifies a TrustZone module call process.
*
*/
typedef uint32_t TZ_ModuleId_t;
#endif

/**
* @brief Describes thread attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Thread name */
  const char                   *name;
  /** Thread attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the thread control block */
  void                      *cb_mem;
  /** Size of the memory for the thread control block */
  uint32_t                   cb_size;
  /** Memory for the thread stack */
  void                   *stack_mem;
  /** Size of the thread stack */
  uint32_t                stack_size;
  /** Thread priority */
  osPriority_t              priority;
  /** TrustZone module of the thread */
  TZ_ModuleId_t            tz_module;
  /** Reserved */
  uint32_t                  reserved;
} osThreadAttr_t;

/**
* @brief Describes timer attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Timer name */
  const char                   *name;
  /** Reserved attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the timer control block */
  void                      *cb_mem;
  /** Size of the memory for the timer control block */
  uint32_t                   cb_size;
} osTimerAttr_t;

/**
* @brief Describes event attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Event name */
  const char                   *name;
  /** Reserved attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the event control block */
  void                      *cb_mem;
  /** Size of the memory for the event control block */
  uint32_t                   cb_size;
} osEventFlagsAttr_t;

/**
* @brief Describes mutex attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Mutex name */
  const char                   *name;
  /** Reserved attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the mutex control block */
  void                      *cb_mem;
  /** Size of the memory for the mutex control block */
  uint32_t                   cb_size;
} osMutexAttr_t;

/**
* @brief Describes semaphore attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Semaphore name */
  const char                   *name;
  /** Reserved attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the semaphore control block */
  void                      *cb_mem;
  /** Size of the memory for the semaphore control block */
  uint32_t                   cb_size;
} osSemaphoreAttr_t;
M
mamingshuai 已提交
514

Y
y00580916 已提交
515 516 517 518

typedef struct {
  const char                   *name;
  uint32_t                 attr_bits;
M
mamingshuai 已提交
519
  void                      *cb_mem;
Y
y00580916 已提交
520
  uint32_t                   cb_size;
M
mamingshuai 已提交
521
  void                      *mp_mem;
Y
y00580916 已提交
522 523
  uint32_t                   mp_size;
} osMemoryPoolAttr_t;
M
mamingshuai 已提交
524

Y
y00580916 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
/**
* @brief Describes message queue attributes.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
  /** Message queue name */
  const char                   *name;
  /** Reserved attribute bits */
  uint32_t                 attr_bits;
  /** Memory for the message queue control block */
  void                      *cb_mem;
  /** Size of the memory for the message queue control block */
  uint32_t                   cb_size;
  /** Memory for storing data in the message queue */
  void                      *mq_mem;
  /** Size of the memory for storing data in the message queue */
  uint32_t                   mq_size;
} osMessageQueueAttr_t;
M
mamingshuai 已提交
545 546


Y
y00580916 已提交
547
//  ==== Kernel Management Functions ====
M
mamingshuai 已提交
548

Y
y00580916 已提交
549 550 551 552 553 554 555 556
/**
* @brief Initializes the RTOS kernel.
*
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osKernelInitialize (void);
M
mamingshuai 已提交
557

Y
y00580916 已提交
558 559 560 561 562 563 564 565 566 567 568
/**
* @brief Obtains the system version and name.
*
* @param version Indicates the pointer to the buffer for storing the version.
* @param id_buf Indicates the pointer to the buffer for storing the kernel ID.
* @param id_size Indicates the size of the buffer for storing the kernel ID.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
M
mamingshuai 已提交
569

Y
y00580916 已提交
570 571 572 573 574 575 576 577
/**
* @brief Obtains the kernel state.
*
* @return Returns the kernel state.
* @since 1.0
* @version 1.0
*/
osKernelState_t osKernelGetState (void);
M
mamingshuai 已提交
578

Y
y00580916 已提交
579 580 581 582 583 584 585 586
/**
* @brief Starts the kernel.
*
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osKernelStart (void);
M
mamingshuai 已提交
587

Y
y00580916 已提交
588 589 590 591 592 593 594 595
/**
* @brief Locks the kernel.
*
* @return Returns 1 if the kernel is locked successfully; returns 0 if the lock starts; returns a negative value in the case of an error.
* @since 1.0
* @version 1.0
*/
int32_t osKernelLock (void);
M
mamingshuai 已提交
596

Y
y00580916 已提交
597 598 599 600 601 602 603 604
/**
* @brief Unlocks the kernel.
*
* @return Returns 1 if the kernel is unlocked successfully; returns 0 if the kernel is not locked; returns a negative value in the case of an error.
* @since 1.0
* @version 1.0
*/
int32_t osKernelUnlock (void);
M
mamingshuai 已提交
605

Y
y00580916 已提交
606 607 608 609 610 611 612 613 614
/**
* @brief Restores the previous lock state of the kernel.
*
* @param lock Indicates the lock state to restore to. The value 1 indicates the locked state, and 0 indicates the unlocked state.
* @return Returns 1 if the kernel is locked; returns 0 if the kernel is not locked; returns a negative value in the case of an error.
* @since 1.0
* @version 1.0
*/
int32_t osKernelRestoreLock (int32_t lock);
M
mamingshuai 已提交
615

Y
y00580916 已提交
616
uint32_t osKernelSuspend (void);
M
mamingshuai 已提交
617

Y
y00580916 已提交
618 619 620 621 622
void osKernelResume (uint32_t sleep_ticks);

/// Get the RTOS kernel tick count.
/// \return RTOS kernel current tick count.
uint32_t osKernelGetTickCount (void);
M
mamingshuai 已提交
623

Y
y00580916 已提交
624 625 626 627 628 629 630 631 632 633


/**
* @brief Obtains the number of kernel ticks per second.
*
* @return Returns the number of kernel ticks.
* @since 1.0
* @version 1.0
*/
uint32_t osKernelGetTickFreq (void);
M
mamingshuai 已提交
634

Y
y00580916 已提交
635 636 637 638 639 640 641 642
/**
* @brief Obtains the kernel system timer.
*
* @return Returns the kernel system timer.
* @since 1.0
* @version 1.0
*/
uint32_t osKernelGetSysTimerCount (void);
M
mamingshuai 已提交
643

Y
y00580916 已提交
644 645 646 647 648 649 650 651
/**
* @brief Obtains the frequency of the system timer.
*
* @return Returns the system timer frequency.
* @since 1.0
* @version 1.0
*/
uint32_t osKernelGetSysTimerFreq (void);
M
mamingshuai 已提交
652 653


Y
y00580916 已提交
654
//  ==== Thread Management Functions ====
M
mamingshuai 已提交
655

Y
y00580916 已提交
656 657 658
/**
* @brief Creates an active thread.
*
M
mamingshuai 已提交
659 660
* The task priority ranges from 9 (highest priority) to 38 (lowest priority). {@code LOSCFG_BASE_CORE_TSK_LIMIT} declared in target_config.h specifies the
maximum number of tasks running in this system.
Y
y00580916 已提交
661 662 663 664 665 666 667 668
* @param func Indicates the entry of the thread callback function.
* @param argument Indicates the pointer to the argument passed to the thread.
* @param attr Indicates the thread attributes.
* @return Returns the thread ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
M
mamingshuai 已提交
669

Y
y00580916 已提交
670 671 672 673 674 675 676 677 678
/**
* @brief Obtains the name of a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the thread name; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
const char *osThreadGetName (osThreadId_t thread_id);
M
mamingshuai 已提交
679

Y
y00580916 已提交
680 681 682 683 684 685 686 687
/**
* @brief Obtains the ID of the currently running thread.
*
* @return Returns the thread ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osThreadId_t osThreadGetId (void);
M
mamingshuai 已提交
688

Y
y00580916 已提交
689 690 691 692 693 694 695 696 697 698

/**
* @brief Obtains the state of a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the thread state.
* @since 1.0
* @version 1.0
*/
osThreadState_t osThreadGetState (osThreadId_t thread_id);
M
mamingshuai 已提交
699

Y
y00580916 已提交
700 701 702 703 704 705 706 707 708
/**
* @brief Obtains the stack size of a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the stack size, in bytes; returns 0 in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osThreadGetStackSize (osThreadId_t thread_id);
M
mamingshuai 已提交
709

Y
y00580916 已提交
710 711 712 713 714 715 716 717 718
/**
* @brief Obtains the size of the available stack space for a thread based on the stack watermark.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the available stack size, in bytes; returns 0 in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
M
mamingshuai 已提交
719

Y
y00580916 已提交
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
/**
* @brief Changes the priority of a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @param priority Indicates the new priority.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);

/**
* @brief Gets the prority of an active thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the prority of the thread.
* @since 1.0
* @version 1.0
*/
osPriority_t osThreadGetPriority (osThreadId_t thread_id);
M
mamingshuai 已提交
740

Y
y00580916 已提交
741 742 743 744 745 746 747 748
/**
* @brief Sets the currently running thread to the ready state.
*
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osThreadYield (void);
M
mamingshuai 已提交
749

Y
y00580916 已提交
750 751 752 753 754 755 756 757 758
/**
* @brief Suspends a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osThreadSuspend (osThreadId_t thread_id);
M
mamingshuai 已提交
759

Y
y00580916 已提交
760 761 762 763 764 765 766 767 768
/**
* @brief Resumes a thread from the suspended state.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osThreadResume (osThreadId_t thread_id);
M
mamingshuai 已提交
769

Y
y00580916 已提交
770
osStatus_t osThreadDetach (osThreadId_t thread_id);
M
mamingshuai 已提交
771

Y
y00580916 已提交
772
osStatus_t osThreadJoin (osThreadId_t thread_id);
M
mamingshuai 已提交
773

Y
y00580916 已提交
774
void osThreadExit (void);
M
mamingshuai 已提交
775

Y
y00580916 已提交
776 777 778 779 780 781 782 783 784
/**
* @brief Terminates a thread.
*
* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osThreadTerminate (osThreadId_t thread_id);
M
mamingshuai 已提交
785

Y
y00580916 已提交
786 787 788 789 790 791 792 793
/**
* @brief Obtains the number of active threads.
*
* @return Returns the number; returns 0 in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osThreadGetCount (void);
M
mamingshuai 已提交
794

Y
y00580916 已提交
795
uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
M
mamingshuai 已提交
796 797


Y
y00580916 已提交
798
//  ==== Thread Flags Functions ====
M
mamingshuai 已提交
799

Y
y00580916 已提交
800
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
M
mamingshuai 已提交
801

Y
y00580916 已提交
802
uint32_t osThreadFlagsClear (uint32_t flags);
M
mamingshuai 已提交
803

Y
y00580916 已提交
804
uint32_t osThreadFlagsGet (void);
M
mamingshuai 已提交
805

Y
y00580916 已提交
806
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
M
mamingshuai 已提交
807 808


Y
y00580916 已提交
809
//  ==== Generic Wait Functions ====
M
mamingshuai 已提交
810

Y
y00580916 已提交
811 812 813 814 815 816 817 818 819
/**
* @brief Waits for a period of time.
*
* @param ticks Indicates the number of ticks to wait for.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osDelay (uint32_t ticks);
M
mamingshuai 已提交
820

Y
y00580916 已提交
821 822 823
/**
* @brief Waits until a specified time arrives.
*
M
mamingshuai 已提交
824
* This function handles the overflow of the system timer. Note that the maximum value of this parameter is (2^31 - 1) ticks.
Y
y00580916 已提交
825 826 827 828 829 830
* @param ticks Indicates the number of ticks converted from the absolute time.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osDelayUntil (uint32_t ticks);
M
mamingshuai 已提交
831 832


Y
y00580916 已提交
833
//  ==== Timer Management Functions ====
M
mamingshuai 已提交
834

Y
y00580916 已提交
835 836 837
/**
* @brief Creates and initializes a timer.
*
M
mamingshuai 已提交
838 839
* This function creates a timer associated with the arguments callback function. The timer stays in the stopped state until OSTimerStart is used to start the timer.
* The timer precision is 1000 / LOSCFG_BASE_CORE_TICK_PER_SECOND ms(LOSCFG_BASE_CORE_TICK_PER_SECOND is defined in the traget_config.h).
Y
y00580916 已提交
840 841 842 843 844 845 846 847 848
* @param func Indicates the entry of the timer callback function.
* @param type Indicates the timer type.
* @param argument Indicates the pointer to the argument used in timer callback.
* @param attr Indicates the pointer to the timer attributes. This parameter is not used.
* @return Returns the timer ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
M
mamingshuai 已提交
849

Y
y00580916 已提交
850 851 852 853 854 855 856 857 858
/**
* @brief Obtains the timer name.
*
* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
* @return Returns the timer name; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
const char *osTimerGetName (osTimerId_t timer_id);
M
mamingshuai 已提交
859

Y
y00580916 已提交
860 861 862 863 864 865 866 867 868 869
/**
* @brief Starts or restarts a timer.
*
* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
* @param ticks Indicates the number of ticks since the timer starts running.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
M
mamingshuai 已提交
870

Y
y00580916 已提交
871 872 873 874 875 876 877 878 879
/**
* @brief Stops a timer.
*
* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osTimerStop (osTimerId_t timer_id);
M
mamingshuai 已提交
880

Y
y00580916 已提交
881 882 883 884 885 886 887 888 889
/**
* @brief Checks whether a timer is running.
*
* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
* @return Returns 1 if the timer is running; returns 0 otherwise.
* @since 1.0
* @version 1.0
*/
uint32_t osTimerIsRunning (osTimerId_t timer_id);
M
mamingshuai 已提交
890

Y
y00580916 已提交
891 892 893 894 895 896 897 898 899
/**
* @brief Deletes a timer.
*
* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osTimerDelete (osTimerId_t timer_id);
M
mamingshuai 已提交
900 901


Y
y00580916 已提交
902
//  ==== Event Flags Management Functions ====
M
mamingshuai 已提交
903

Y
y00580916 已提交
904 905 906 907 908 909 910 911 912
/**
* @brief Creates and initializes an event flags object.
*
* @param attr Indicates the pointer to the event flags attributes. This parameter is not used.
* @return Returns the event flags ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
M
mamingshuai 已提交
913

Y
y00580916 已提交
914 915 916 917 918 919 920 921 922
/**
* @brief Obtains the name of an event flags object.
*
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @return Returns the event flags name; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
M
mamingshuai 已提交
923

Y
y00580916 已提交
924 925 926 927 928 929 930 931 932 933
/**
* @brief Sets event flags.
*
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to set.
* @return Returns the event flags; returns osFlagsErrorParameter in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);
M
mamingshuai 已提交
934

Y
y00580916 已提交
935 936 937 938 939 940 941 942 943 944
/**
* @brief Clears event flags.
*
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to clear.
* @return Returns the event flags; returns osFlagsErrorParameter in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
M
mamingshuai 已提交
945

Y
y00580916 已提交
946 947 948 949 950 951 952 953 954
/**
* @brief Obtains event flags.
*
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @return Returns the event flags triggered.
* @since 1.0
* @version 1.0
*/
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
M
mamingshuai 已提交
955

Y
y00580916 已提交
956 957 958
/**
* @brief Waits for event flags to trigger.
*
M
mamingshuai 已提交
959
* This function is blocked if the specified event flags are not set via {@code flags}.
Y
y00580916 已提交
960 961 962 963 964 965 966 967 968
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to trigger.
* @param options Indicates the configuration of the event flags to trigger.
* @param timeout Indicates the timeout duration.
* @return Returns the triggered event flags; returns an error value in the case of an error.
* @since 1.0
* @version 1.0
*/
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
M
mamingshuai 已提交
969

Y
y00580916 已提交
970 971 972 973 974 975 976 977 978
/**
* @brief Deletes an event flags object.
*
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
M
mamingshuai 已提交
979 980


Y
y00580916 已提交
981
//  ==== Mutex Management Functions ====
M
mamingshuai 已提交
982

Y
y00580916 已提交
983 984 985 986 987 988 989 990 991
/**
* @brief Creates and initializes a mutex.
*
* @param attr Indicates the pointer to the mutex attributes. This parameter is not used.
* @return Returns the mutex ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osMutexId_t osMutexNew (const osMutexAttr_t *attr);
M
mamingshuai 已提交
992

Y
y00580916 已提交
993
const char *osMutexGetName (osMutexId_t mutex_id);
M
mamingshuai 已提交
994

Y
y00580916 已提交
995 996 997 998 999 1000 1001 1002 1003 1004
/**
* @brief Obtains a mutex.
*
* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
* @param timeout Indicates the timeout duration.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
M
mamingshuai 已提交
1005

Y
y00580916 已提交
1006 1007 1008 1009 1010 1011 1012 1013 1014
/**
* @brief Releases a mutex.
*
* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMutexRelease (osMutexId_t mutex_id);
M
mamingshuai 已提交
1015

Y
y00580916 已提交
1016 1017 1018 1019 1020 1021 1022 1023 1024
/**
* @brief Obtains the thread ID of the currently acquired mutex.
*
* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
* @return Returns the thread ID.
* @since 1.0
* @version 1.0
*/
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
M
mamingshuai 已提交
1025

Y
y00580916 已提交
1026 1027 1028 1029 1030 1031 1032 1033 1034
/**
* @brief Deletes a mutex.
*
* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMutexDelete (osMutexId_t mutex_id);
M
mamingshuai 已提交
1035 1036


Y
y00580916 已提交
1037
//  ==== Semaphore Management Functions ====
M
mamingshuai 已提交
1038

Y
y00580916 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
/**
* @brief Creates and initializes a semaphore object.
*
* @param max_count Indicates the maximum number of available tokens that can be applied for.
* @param initial_count Indicates the initial number of available tokens.
* @param attr Indicates the pointer to the semaphore attributes. This parameter is not used.
* @return Returns the semaphore ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
M
mamingshuai 已提交
1050

Y
y00580916 已提交
1051
const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
M
mamingshuai 已提交
1052

Y
y00580916 已提交
1053 1054 1055 1056
/**
* @brief Acquires a token of a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
M
mamingshuai 已提交
1057
* @param timeout Indicates the timeout duration, in ticks.
Y
y00580916 已提交
1058 1059 1060 1061 1062
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
M
mamingshuai 已提交
1063

Y
y00580916 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072
/**
* @brief Releases a token of a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
M
mamingshuai 已提交
1073

Y
y00580916 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082
/**
* @brief Obtains the number of available tokens of a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @return Returns the number of available tokens.
* @since 1.0
* @version 1.0
*/
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
M
mamingshuai 已提交
1083

Y
y00580916 已提交
1084 1085 1086 1087 1088 1089 1090 1091 1092
/**
* @brief Deletes a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
M
mamingshuai 已提交
1093 1094


Y
y00580916 已提交
1095
//  ==== Memory Pool Management Functions ====
M
mamingshuai 已提交
1096

Y
y00580916 已提交
1097
osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
M
mamingshuai 已提交
1098

Y
y00580916 已提交
1099
const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1100

Y
y00580916 已提交
1101
void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
M
mamingshuai 已提交
1102

Y
y00580916 已提交
1103
osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
M
mamingshuai 已提交
1104

Y
y00580916 已提交
1105
uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1106

Y
y00580916 已提交
1107
uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1108

Y
y00580916 已提交
1109
uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1110

Y
y00580916 已提交
1111
uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1112

Y
y00580916 已提交
1113
osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
M
mamingshuai 已提交
1114 1115


Y
y00580916 已提交
1116
//  ==== Message Queue Management Functions ====
M
mamingshuai 已提交
1117

Y
y00580916 已提交
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
/**
* @brief Creates and initializes a message queue.
*
* @param msg_count Indicates the number of messages in the message queue.
* @param msg_size Indicates the size of messages in the message queue.
* @param attr Indicates the pointer to the message queue attributes. This parameter is not used.
* @return Returns the message queue ID; returns NULL in the case of an error.
* @since 1.0
* @version 1.0
*/
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
M
mamingshuai 已提交
1129

Y
y00580916 已提交
1130
const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1131

Y
y00580916 已提交
1132 1133 1134 1135 1136
/**
* @brief Places a message in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @param msg_ptr Indicates the pointer to the buffer for storing the message to be placed in the message queue.
M
mamingshuai 已提交
1137
* @param msg_prio Indicates the priority of the message to be placed in the message queue. This parameter is not used.
Y
y00580916 已提交
1138 1139 1140 1141 1142 1143
* @param timeout Indicates the timeout duration.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
M
mamingshuai 已提交
1144

Y
y00580916 已提交
1145 1146 1147 1148 1149
/**
* @brief Obtains a message in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @param msg_ptr Indicates the pointer to the buffer for storing the message to be retrieved from the message queue.
M
mamingshuai 已提交
1150
* @param msg_prio Indicates the pointer to the buffer for storing the priority of the message to be retrieved from the message queue. This parameter is not used.
Y
y00580916 已提交
1151 1152 1153 1154 1155 1156
* @param timeout Indicates the timeout duration.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
M
mamingshuai 已提交
1157

Y
y00580916 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166
/**
* @brief Obtains the maximum number of messages that can be placed in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @return Returns the maximum number.
* @since 1.0
* @version 1.0
*/
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1167

Y
y00580916 已提交
1168 1169 1170 1171 1172 1173 1174 1175 1176
/**
* @brief Obtains the maximum size of messages that can be placed in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @return Returns the maximum message size.
* @since 1.0
* @version 1.0
*/
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1177

Y
y00580916 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186
/**
* @brief Obtains the number of queued messages in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @return Returns the number of queued messages.
* @since 1.0
* @version 1.0
*/
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1187

Y
y00580916 已提交
1188 1189 1190 1191 1192 1193 1194 1195 1196
/**
* @brief Obtains the number of available slots for messages in a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @return Returns the number of available slots for messages.
* @since 1.0
* @version 1.0
*/
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1197

Y
y00580916 已提交
1198
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1199

Y
y00580916 已提交
1200 1201 1202 1203 1204 1205 1206 1207 1208
/**
* @brief Deletes a message queue.
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
*/
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
M
mamingshuai 已提交
1209 1210


Y
y00580916 已提交
1211 1212 1213
#ifdef  __cplusplus
}
#endif
M
mamingshuai 已提交
1214

Y
y00580916 已提交
1215
#endif  // CMSIS_OS2_H_