📄 ml_buf.c
字号:
/*+MHDR*/
/*
# clearcase: CmicroRel2.3
+------------------------------------------------------------------------------+
| Modulname : ML_BUF.C |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| |
| Description : |
| This Module contains functions to handle different types of buffers, |
| namely : |
| |
| * Ringbuffer |
| * FIFO |
| |
| 3 functions are implemented representing the low level functions. Each |
| entry has to be of the same size, because the handling is in principle |
| similar to array. The type of each entry is not relevant. In addition, |
| the caller of the functions contained in this module defines the |
| memory for the tracebuffer as well as a control structure representing |
| all the internal data and variables necessary to administer the . |
| tracebuffer. |
| |
| Users are free to have more than 1 Instance of a buffertype. |
| |
| M1 Errormessages, which are routed to the ErrorHandler |
| -------------------------------------------------------- |
| - none - |
| |
| M2 Exported functions of this module : |
| -------------------------------------------------------- |
| ... xmk_RingInit ( ... ) |
| ... xmk_RingRead ( ... ) |
| ... xmk_RingWrite ( ... ) |
| ... xmk_RingQuery ( ... ) |
| |
| M3 Static functions of this module : |
| -------------------------------------------------------- |
| - none - |
| |
+------------------------------------------------------------------------------+
*/
/*-MHDR*/
/*
+------------------------------------------------------------------------------+
| |
| Copyright by Telelogic AB 1993 - 1998 |
| Copyright by S&P Media GmbH Germany 1993 - 1998 |
| |
| This Program is owned by Telelogic and is protected by national |
| copyright laws and international copyright treaties. Telelogic |
| grants you the right to use this Program on one computer or in |
| one local computer network at any one time. |
| Under this License you may only modify the source code for the purpose |
| of adapting it to your environment. You must reproduce and include |
| any copyright and trademark notices on all copies of the source code. |
| You may not use, copy, merge, modify or transfer the Program except as |
| provided in this License. |
| Telelogic does not warrant that the Program will meet your |
| requirements or that the operation of the Program will be |
| uninterrupted and error free. You are solely responsible that the |
| selection of the Program and the modification of the source code |
| will achieve your intended results and that the results are actually |
| obtained. |
| |
+------------------------------------------------------------------------------+
*/
#ifndef __ML_BUF_C_
#define __ML_BUF_C_
/*+IMPORT*/
/*==================== I M P O R T =========================================*/
#include "ml_typw.h"
/*============================================================================*/
/*-IMPORT*/
/*+MGG*/
/*==================== V A L U E S O F T H I S M O D U L E =============*/
#ifdef BUFFERSIZE
#undef BUFFERSIZE
#endif
#define BUFFERSIZE p_controlblock->buffersize
#ifdef ENTRYSIZE
#undef ENTRYSIZE
#endif
#define ENTRYSIZE p_controlblock->entrysize
#ifdef MAXIMUM
#undef MAXIMUM
#endif
#define MAXIMUM p_controlblock->maximumentries
#ifdef COUNTER
#undef COUNTER
#endif
#define COUNTER p_controlblock->counter
#ifdef BUFFERADR
#undef BUFFERADR
#endif
#define BUFFERADR p_controlblock->p_buffer
#ifdef WRITEPTR
#undef WRITEPTR
#endif
#define WRITEPTR p_controlblock->p_write
#ifdef READPTR
#undef READPTR
#endif
#define READPTR p_controlblock->p_read
#ifdef XMK_CTRL
#undef XMK_CTRL
#endif
#define XMK_CTRL p_controlblock->ctrl
#ifdef COPY
#undef COPY
#endif
#define COPY(p1,p2,len) \
if (len <= ENTRYSIZE) \
(void)memcpy ((void xmk_RAM_ptr) p1, (void xmk_RAM_ptr) p2, len); \
else \
(void)memcpy ((void xmk_RAM_ptr) p1, (void xmk_RAM_ptr) p2, ENTRYSIZE);
#ifdef INCR_WRITEPTR
#undef INCR_WRITEPTR
#endif
#define INCR_WRITEPTR WRITEPTR = WRITEPTR + ENTRYSIZE ;
#ifdef INCR_READPTR
#undef INCR_READPTR
#endif
#define INCR_READPTR READPTR = READPTR + ENTRYSIZE ;
/*-------------------- Constants, Macros ----------------------------------*/
/*-------------------- Typedefinitions ----------------------------------*/
/*-------------------- Functions -----------------------------------------*/
/*-------------------- Variables -----------------------------------------*/
/*============================================================================*/
/*-MGG*/
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_RingInit |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| |
| Description : |
| This function initializes a tracebuffer. The buffer is declared by the |
| caller of this function, and this module has no global data. |
| The buffer is to be declared as type xmk_T_RING by the caller. |
| The structure contains all the data necessary to manage the tracebuffer. |
| If there is enough memory, then multiple tracebuffers are possible to use. |
| The last parameter selects the mechanism which is to be used, either |
| ring buffer or fifo. |
| |
| Parameter : xmk_T_RING *p_controlblock. Pointer to the memory declared|
| as xmk_T_RING by the caller. |
| |
| char *p_buffer pointer to ringbuffer |
| int buffersize sizeof (buffer) |
| unsigned char SizeOfOneEntry Size of one entry in the |
| buffer. |
| unsigned char ctrl either XMK_FIFO or XMK_RING |
| |
| Return : void |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
/* ANSI - Style */
void xmk_RingInit (xmk_T_RING xmk_RAM_ptr p_controlblock,
char xmk_RAM_ptr p_buffer,
int buffersize,
int SizeOfOneEntry,
unsigned char ctrl )
#else
/* Kernighan-Ritchie-Style */
void xmk_RingInit (p_controlblock,
p_buffer,
buffersize,
SizeOfOneEntry,
ctrl)
xmk_T_RING xmk_RAM_ptr p_controlblock;
char xmk_RAM_ptr p_buffer;
int buffersize;
int SizeOfOneEntry;
unsigned char ctrl ;
#endif
/*-FDEF E*/
{
XMK_BEGIN_CRITICAL_PATH;
BUFFERSIZE = buffersize ;
MAXIMUM = buffersize / SizeOfOneEntry ;
ENTRYSIZE = SizeOfOneEntry ;
COUNTER = 0 ;
BUFFERADR = p_buffer ;
READPTR = p_buffer ;
WRITEPTR = p_buffer ;
if ((ctrl == XMK_FIFO) || (ctrl==XMK_RING))
{
XMK_CTRL = ctrl ;
}
else
{
XMK_CTRL = XMK_FIFO ;
}
XMK_END_CRITICAL_PATH;
} /* END OF FUNCTION */
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_RingWrite |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| |
| Description : |
| This functions puts the data into the ringbuffer. The caller has to give |
| a pointer to the tracebuffer as the first parameter. |
| |
| Parameter : xmk_T_RING * Pointer to tracebuffercontrolblock. |
| char * Pointer to data, which is to be put in |
| int len length of data to copy .... |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -