/* ******************* ******************************* C SOURCE FILE ******************************* ** ******************* ** ** ** ** project : The C Kernel ** ** filename : CKREGION.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 _CKREGION_C_SRC /****************************************************************************/ /** **/ /** MODULES USED **/ /** **/ /****************************************************************************/ #include "ckqueue.h" #include "ckregion.h" /****************************************************************************/ /** **/ /** DEFINITIONS AND MACROS **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** TYPEDEFS AND STRUCTURES **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** PROTOTYPES OF LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ #if NR_OF_REGIONS > 0 static void init (int8u id); /****************************************************************************/ /** **/ /** EXPORTED VARIABLES **/ /** **/ /****************************************************************************/ RegionType Region[NR_OF_REGIONS]; /****************************************************************************/ /** **/ /** GLOBAL VARIABLES **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** EXPORTED FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ void RegionInit (void) /****************************************************************************/ { int8u id; /**** Initialize all id's ****/ for (id = 0; id < NR_OF_REGIONS; id++) init (id); } /****************************************************************************/ int8u RegionAlloc (void) /****************************************************************************/ { int8u id; for (id = 0; id < NR_OF_REGIONS; id++) { /**** Search for a free Id ****/ if (!Region[id].req) { /**** Allocate associated queue ****/ Region[id].qid = QueueAlloc (); /**** Check if OK ****/ if (Region[id].qid == NR_OF_QUEUES) return (NR_OF_REGIONS); break; } } /**** If found mark id as allocated ****/ if (id < NR_OF_REGIONS) Region[id].req = TRUE; return (id); } /****************************************************************************/ void RegionFree (int8u id) /****************************************************************************/ { /**** Cannot free illegal id ****/ if (id >= NR_OF_REGIONS) return; /**** Free the associated queue ****/ QueueFree (Region[id].qid); init (id); } /****************************************************************************/ /** **/ /** LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ static void init (int8u id) /****************************************************************************/ { Region[id].req = FALSE; Region[id].lock = FALSE; Region[id].tid = NR_OF_TASKS; Region[id].qid = NR_OF_QUEUES; } #endif /****************************************************************************/ /** **/ /** EOF **/ /** **/ /****************************************************************************/