Main Page   Modules   Data Structures   File List   Globals  

message.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2002, 2003, Oliver Tscherwitschke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009    this list of conditions and the following disclaimer.
00010 2. Redistributions in binary form must reproduce the above copyright notice,
00011    this list of conditions and the following disclaimer in the documentation
00012    and/or other materials provided with the distribution.
00013 3. The name of the author may not be used to endorse or promote products
00014    derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00017 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00019 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00022 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00023 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00024 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00034 #ifndef MESSAGE_H
00035 #define MESSAGE_H
00036 
00037 
00038 #include "types.h"
00039 
00040 
00041 /* return values */
00042 #define MESSAGE_SUCCESS         0
00043 #define MESSAGE_TIMEOUT         1
00044 #define MESSAGE_QUEUE_EMPTY     2
00045 #define MESSAGE_QUEUE_FULL      3
00046 
00047 
00048 
00053 typedef union
00054 {
00055     uint8_t     byte[4];
00056     uint16_t    word[2];
00057     uint32_t    dword;
00058 }
00059 OtosMessage;
00060 
00061 
00062 /* structure for an otOS message queue */
00063 typedef struct
00064 {
00065     uint8_t         size;       /* size of the message queue        */
00066     uint8_t         in;         /* index to next message to insert  */
00067     uint8_t         out;        /* index to next message to read    */
00068     uint8_t         count;      /* number of messages in queue      */
00069     OtosMessage     msg[];      /* flexible size array of messages  */
00070 }
00071 OtosMessageQueue;
00072 
00073 
00074 /* function prototypes */
00075 OtosMessageQueue*       otosCreateMessageQueue(uint8_t Size);
00076 uint8_t                 otosSendMessage(OtosMessageQueue* pQueue, OtosMessage* pMsg);
00077 uint8_t                 otosReceiveMessage(OtosMessageQueue* pQueue, OtosMessage* pMsg, uint32_t Timeout);
00078 
00079 
00080 
00081 /*
00082  * These definitions are only intended for otOS-internal use
00083  */
00084 #ifdef COMPILE_OTOS
00085 
00086 /* macros */
00087 
00088 /* inc out index and dec message count */
00089 #define MQUEUE_INC_OUT(pQ)                  \
00090     ++pQ->out;                              \
00091     if (pQ->out == pQ->size) pQ->out = 0;   \
00092     --pQ->count;
00093 
00094 /* inc in index and inc message count */
00095 #define MQUEUE_INC_IN(pQ)                   \
00096     ++pQ->in;                               \
00097     if (pQ->in == pQ->size) pQ->in = 0;     \
00098     ++pQ->count;
00099 
00100 #endif /* #ifdef COMPILE_OTOS */
00101 
00102 #endif

Generated on Sat Jan 25 18:41:43 2003 for otOS by doxygen1.3-rc2