mtkernel_3/kernel/tkernel/messagebuf.h | bare source | permlink (0.00 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * micro T-Kernel 3.00.00 4: * 5: * Copyright (C) 2006-2019 by Ken Sakamura. 6: * This software is distributed under the T-License 2.1. 7: *---------------------------------------------------------------------- 8: * 9: * Released by TRON Forum(http://www.tron.org) at 2019/12/11. 10: * 11: *---------------------------------------------------------------------- 12: */ 13: 14: /* 15: * messagebuf.h 16: * Message Buffer 17: */ 18: 19: #ifndef _MESSAGEBUF_H_ 20: #define _MESSAGEBUF_H_ 21: 22: /* 23: * Message buffer control block 24: * 25: * Because Receive wait task (TTW_MBF) and Send wait task (TTW_SMBF) 26: * do not co-exist for one message buffer, the wait queue may be 27: * allowed to share. 28: * However, when the size of message buffer is 0, it is difficult 29: * to judge the wait queue if it is for receive or send, 30: * therefore do not use this method. 31: */ 32: typedef struct messagebuffer_control_block { 33: QUEUE send_queue; /* Message buffer send wait queue */ 34: ID mbfid; /* message buffer ID */ 35: void *exinf; /* Extended information */ 36: ATR mbfatr; /* Message buffer attribute */ 37: QUEUE recv_queue; /* Message buffer receive wait queue */ 38: W bufsz; /* Message buffer size */ 39: INT maxmsz; /* Maximum length of message */ 40: W frbufsz; /* Free buffer size */ 41: W head; /* First message store address */ 42: W tail; /* Next to the last message store address */ 43: VB *buffer; /* Message buffer address */ 44: #if USE_OBJECT_NAME 45: UB name[OBJECT_NAME_LENGTH]; /* name */ 46: #endif 47: } MBFCB; 48: 49: IMPORT MBFCB knl_mbfcb_table[]; /* Message buffer control block */ 50: IMPORT QUEUE knl_free_mbfcb; /* FreeQue */ 51: 52: #define get_mbfcb(id) ( &knl_mbfcb_table[INDEX_MBF(id)] ) 53: 54: 55: /* 56: * Message header format 57: */ 58: typedef INT HEADER; 59: #define HEADERSZ (sizeof(HEADER)) 60: 61: #define ROUNDSIZE (sizeof(HEADER)) 62: #define ROUNDSZ(sz) (((UW)(sz) + (UW)(ROUNDSIZE-1)) & ~(UW)(ROUNDSIZE-1)) 63: 64: /* 65: * Check message buffer free space 66: * If 'msgsz' message is able to be stored, return TRUE. 67: */ 68: Inline BOOL knl_mbf_free( MBFCB *mbfcb, INT msgsz ) 69: { 70: return ( HEADERSZ + (UW)msgsz <= (UW)mbfcb->frbufsz ); 71: } 72: 73: /* 74: * If message buffer is empty, return TRUE. 75: */ 76: Inline BOOL knl_mbf_empty( MBFCB *mbfcb ) 77: { 78: return ( mbfcb->frbufsz == mbfcb->bufsz ); 79: } 80: 81: #endif /* _MESSAGEBUF_H_ */