/* ******************* ******************************* C SOURCE FILE ******************************* ** ******************* ** ** ** ** project : The C Kernel ** ** filename : CKSEMA.C ** ** version : 2 ** ** last revised : August 22, 2004 ** ** ** ***************************************************************************** ** ** ** Copyright (c) 1998-2004, P.K. van der Vlugt ** ** All rights reserved. ** ** ** ***************************************************************************** VERSION HISTORY: ---------------- Version : 1 Date : June 01, 2003 Revised by : P.K. van der Vlugt Description : Original version. Version : 2 Date : August 22, 2004 Revised by : P.K. van der Vlugt Description : * Changed module name to comply to new kernel module naming convention. */ #define _CKSEMA_C_SRC /****************************************************************************/ /** **/ /** MODULES USED **/ /** **/ /****************************************************************************/ #include "ckqueue.h" #include "cksema.h" /****************************************************************************/ /** **/ /** DEFINITIONS AND MACROS **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** TYPEDEFS AND STRUCTURES **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** PROTOTYPES OF LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ #if NR_OF_SEMAS > 0 static void init (int8u id); /****************************************************************************/ /** **/ /** EXPORTED VARIABLES **/ /** **/ /****************************************************************************/ SemaType Sema[NR_OF_SEMAS]; /****************************************************************************/ /** **/ /** GLOBAL VARIABLES **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** EXPORTED FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ void SemaInit (void) /****************************************************************************/ { int8u id; /**** Initialize all id's ****/ for (id = 0; id < NR_OF_SEMAS; id++) init (id); } /****************************************************************************/ int8u SemaAlloc (void) /****************************************************************************/ { int8u id; for (id = 0; id < NR_OF_SEMAS; id++) { /**** Search for a free Id ****/ if (!Sema[id].req) { /**** Allocate associated queue ****/ Sema[id].qid = QueueAlloc (); /**** Check if OK ****/ if (Sema[id].qid == NR_OF_QUEUES) return (NR_OF_SEMAS); break; } } /**** If found mark id as allocated ****/ if (id < NR_OF_SEMAS) Sema[id].req = TRUE; return (id); } /****************************************************************************/ void SemaFree (int8u id) /****************************************************************************/ { /**** Cannot free illegal id ****/ if (id >= NR_OF_SEMAS) return; /**** Free the associated queue ****/ QueueFree (Sema[id].qid); init (id); } /****************************************************************************/ /** **/ /** LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ static void init (int8u id) /****************************************************************************/ { Sema[id].req = FALSE; Sema[id].count = 0; Sema[id].qid = NR_OF_QUEUES; /**** Mark Sema mode with FIFO_Q as default ****/ Sema[id].mode = 0; } #endif /****************************************************************************/ /** **/ /** EOF **/ /** **/ /****************************************************************************/