⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binsem.h

📁 FreeRTOS 是一个源码公开的免费的嵌入式实时操作系统
💻 H
字号:
/*
  ----------------------------------------------------------
  BINARY SEMAPHORE LIBRARY FOR LEANSLICE MULTITASKING

  Copyright (c) B Knudsen Data, Trondheim, Norway, 1999-2002
  ----------------------------------------------------------

  ==> Binary semaphores are used for protecting critical common data
      or regions. This ensures that only one task is granted access
      at the same time.

  Required definitions in the application program:

   enum {BinSemaphore1, BS2};
   #define NoOfBinSemaphores 2
   #define BINSEM_TYPE       1
   #include "binsem.h"

  Initialization:

   initBinSemaphores();  // initialize in main()

  Using binary semaphores:

   getBinSemaphore(BS2);  // get semaphore (wait until free)
   //.. process protected region
   freeBinSemaphore(BS2);  // release semaphore

  The single binary semaphore type available allows up
  to 8, 16, 24 or 32 binary semaphores.
*/

#ifndef BINSEM_TYPE
 #error The BINSEM_TYPE have to be defined (1,..)
#endif


// -------------------------------------------
#if BINSEM_TYPE == 1

#if NoOfBinSemaphores <= 8
 char BinSemaphore;
#elif NoOfBinSemaphores <= 16
 uns16 BinSemaphore;
#elif NoOfBinSemaphores <= 24
 uns24 BinSemaphore;
#else
 uns32 BinSemaphore;
#endif

#define initBinSemaphores()  BinSemaphore = 0

#define freeBinSemaphore(BSemNo)  BinSemaphore.BSemNo = 0

#define getBinSemaphore(BSemNo) \
{ \
   while (BinSemaphore.BSemNo == 1) \
       waitState(); \
   BinSemaphore.BSemNo = 1; \
}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -