/* ******************* ******************************* C SOURCE FILE ******************************* ** ******************* ** ** ** ** project : The C Kernel ** ** filename : CKMSG.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 _CKMSG_C_SRC /****************************************************************************/ /** **/ /** MODULES USED **/ /** **/ /****************************************************************************/ #include "ckmsg.h" /****************************************************************************/ /** **/ /** DEFINITIONS AND MACROS **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** TYPEDEFS AND STRUCTURES **/ /** **/ /****************************************************************************/ /****************************************************************************/ /** **/ /** PROTOTYPES OF LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ #if NR_OF_MBOXS > 0 && NR_OF_MSGS > 0 static void init (int8u id); /****************************************************************************/ /** **/ /** EXPORTED VARIABLES **/ /** **/ /****************************************************************************/ MsgType Msg[NR_OF_MSGS]; /****************************************************************************/ /** **/ /** GLOBAL VARIABLES **/ /** **/ /****************************************************************************/ static bool Req[NR_OF_MSGS]; /****************************************************************************/ /** **/ /** EXPORTED FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ void MsgInit (void) /****************************************************************************/ { int8u id; /**** Initialize all id's ****/ for (id = 0; id < NR_OF_MSGS; id++) init (id); } /****************************************************************************/ int8u MsgAlloc (void) /****************************************************************************/ { int8u id; for (id = 0; id < NR_OF_MSGS; id++) { /**** Search for a free Id ****/ if (!Req[id]) { /**** If found mark id as allocated ****/ Req[id] = TRUE; break; } } return (id); } /****************************************************************************/ void MsgFree (int8u id) /****************************************************************************/ { /**** Cannot free illegal id ****/ if (id >= NR_OF_MSGS) return; /**** Initialize freed Id again ****/ init (id); } /****************************************************************************/ void SetMsg (int8u id, int32u msg) /****************************************************************************/ { if (id < NR_OF_MSGS) Msg[id].msg = msg; } /****************************************************************************/ int32u GetMsg (int8u id) /****************************************************************************/ { if (id < NR_OF_MSGS) return (Msg[id].msg); else return ((int32u) 0); } /****************************************************************************/ /** **/ /** LOCAL FUNCTIONS **/ /** **/ /****************************************************************************/ /****************************************************************************/ static void init (int8u id) /****************************************************************************/ { Req[id] = FALSE; Msg[id].next = NR_OF_MSGS; Msg[id].msg = 0; } #endif /****************************************************************************/ /** **/ /** EOF **/ /** **/ /****************************************************************************/