www.pudn.com > r&s1.10°æ±¾£«Îĵµ.rar > ipc.h


/* 
=============================================================================== 
| Copyright (C) 2004 RuanHaiShen, All rights reserved. 
| SUMMARY:  
|   Intertask communication and synchronization (includes binary semaphore, 
|   counting semaphore, mutex, mailbox, message queue) support functions  
|   and condition variable definitions. 
| 
| DESCRIPTION: 
|   See http://www.01s.org for documentation, latest information, license  
|   and contact details. 
|   email:ruanhaishen@01s.org 
=============================================================================*/ 
#ifndef __IPC_H__ 
#define __IPC_H__ 
/*===========================================================================*/ 
 
#if CFG_MSGQ_EN > 0 
# define  MSG_FIFO           0x00 
# define  MSG_LIFO           0x01 
#endif 
 
#if CFG_IPC_EN > 0 
# define  NULL_PRIO          0xff 
# define  IPC_NOWAIT         0 
#endif 
 
/*===================================================*/ 
 
#if CFG_SEMB_EN > 0 
struct semaphorebinary_struct 
{ 
    bool    avail;         /* semb available flag */ 
    queue_t tasks; 
}; 
typedef struct semaphorebinary_struct semb_t; 
#endif 
 
#if CFG_SEM_EN > 0 
struct semaphore_struct 
{ 
    cnt_t   count; 
    queue_t tasks; 
}; 
typedef struct semaphore_struct sem_t; 
#endif 
 
#if CFG_MUTEX_EN > 0 
struct mutex_struct 
{ 
    u8      ceiling; 
    u8      hand_prio; 
    queue_t tasks; 
}; 
typedef struct mutex_struct mutex_t; 
#endif 
 
#if CFG_MBOX_EN > 0 
struct mbox_struct 
{ 
    long	value;			/* mailbox value */ 
    bool    avail;         /* mailbox available flag */ 
    queue_t tasks; 
}; 
typedef struct mbox_struct mbox_t; 
#endif 
 
#if CFG_MSGQ_EN > 0 
struct msgq_struct 
{ 
    u8*     pstart; 
    u8*     phead; 
    u8*     ptail; 
    u8*     pend; 
    u16     avail; 
    u16     msgsz; 
    u16     entries; 
    u8      opt; 
    queue_t tasks; 
}; 
typedef struct msgq_struct msgq_t; 
#endif 
 
/*===================================================*/ 
 
#if CFG_IPC_EN > 0  
/***called under critical path*/ 
void __ipc_block(queue_t* q, tick_t ticks); 
u8   __ipc_resume(queue_t* q); 
#if CFG_IPC_TIMEOUT_EN > 0 
void __ipc_timeout(queue_t* q); 
#endif 
#define __adjust_delay(prio, ticks) \ 
do { \ 
    if (ticks != 0) { \ 
        ticks = _tasks[prio].delay; \ 
        if (ticks != 0) { \ 
            _tasks[prio].delay = 0; \ 
        } else { \ 
            ticks = 1; \ 
        } \ 
    } \ 
}while (0) 
#endif 
 
 
/*===========================================================================*/ 
#endif