source: soft/giet_vm/giet_libs/mwmr_channel.h @ 817

Last change on this file since 817 was 722, checked in by alain, 9 years ago

1) introduce the stdint.h file to define uint*_t and int*_t types.
2) introduce the bufio service in the mwmr library.
3) modify the fbf_cma system calls to support chbuf containing more than 2 buffers.

  • Property svn:executable set to *
File size: 5.5 KB
RevLine 
[258]1//////////////////////////////////////////////////////////////////////////////////
2// File     : mwmr_channel.h         
3// Date     : 01/04/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
[450]7// The mwmr_channel.c and mwmr_channel.h files are part of the GIET nano-kernel.
8// This  middleware implements a user level Multi-Writers / Multi-Readers
9// communication channel, that can be used by parallel multi-tasks applications
10// respecting the TCG (Tasks and Communications Graph) formalism.
11//
12// The mwmr_read() and mwmr_write() functions do not require a system call.
[461]13// The channel must have been allocated in a non cacheable segment,
[450]14// if the platform does not provide hardware cache coherence.
15//
16// An MWMR transaction transfer an integer number of items, and an item is
[722]17// an integer number of uint32_t (32 bits words).
[450]18// The max number of words that can be stored in a MWMR channel is defined by the
19// "depth" parameter, and the "width" parameter define the minimal number of
20// word contained in an atomic item. Therefore, the "depth" parameter must be
21// a multiple of the "width" parameter.
22//
23// Both the mwmr_read() and mwmr_write() functions are blocking functions.
[479]24// A queuing lock provides exclusive access to the MWMR channel.
[450]25///////////////////////////////////////////////////////////////////////////////////
[258]26
27#ifndef _MWMR_CHANNEL_H_
28#define _MWMR_CHANNEL_H_
29
[461]30#include "user_lock.h"
[722]31#include "stdint.h"
[461]32
[258]33///////////////////////////////////////////////////////////////////////////////////
[722]34//         MWMR channel
35// This structure define a - shared - communication buffer between threads.
36// It must be declared as a global variable.
[258]37///////////////////////////////////////////////////////////////////////////////////
38
39typedef struct mwmr_channel_s
40{
[722]41    user_lock_t lock;         // exclusive access lock
42    uint32_t    sts;          // number of words available
43    uint32_t    ptr;          // index of the first valid data word
44    uint32_t    ptw;          // index of the first empty slot
45    uint32_t    depth;        // max number of words in the channel
46    uint32_t    width;        // number of words in an item     
47    uint32_t*   data;         // circular buffer base address
[258]48} mwmr_channel_t;
49
[722]50///////////////////////////////////////////////////////////////////////////////////
51//         MWMR bufio
52// This structure define a - private - input or output buffer, that can be used
53// to move data to (or ftom a shared MWMR communication channel.
54// It is a local variable in the stack of the reader/writer thread.
55// It can be used to simplify access to a MWMR channel when the transfered
56// data have a non fixed format, and must be analysed or produced byte per byte.
57// An input buffer is automatically refill when it becomes empty.
58// An output buffer is automatically flushed when it becomes full.
59///////////////////////////////////////////////////////////////////////////////////
60
61typedef struct mwmr_bufio_s
62{
63    uint32_t         is_input;    // input buffer if non zero
64    uint32_t         ptr;         // current byte index (0 to max-1)
65    uint8_t*         base;        // data buffer base address
66    uint32_t         max;         // number of bytes after refill (only for input bufio)
67    uint32_t         nitems;      // buffer size (number of items)
68    uint32_t         nbytes;      // buffer size (number of bytes)
69    mwmr_channel_t*  mwmr;        // associated MWMR channel
70} mwmr_bufio_t;
71
[258]72//////////////////////////////////////////////////////////////////////////////
[722]73//  MWMR channel access functions
[258]74//////////////////////////////////////////////////////////////////////////////
75
[450]76void mwmr_init(  mwmr_channel_t* mwmr,
[722]77                 uint32_t*       buffer,
78                 uint32_t        width,        // number of words per item
79                 uint32_t        nitems );     // max number of items
[450]80
[722]81void mwmr_dump( mwmr_channel_t* mwmr );
82
[461]83void mwmr_read(  mwmr_channel_t* mwmr,
[722]84                 uint32_t*       buffer,
85                 uint32_t        items );
[258]86
[461]87void mwmr_write( mwmr_channel_t* mwmr,
[722]88                 uint32_t*       buffer,
89                 uint32_t        items );
[258]90
[722]91uint32_t nb_mwmr_read ( mwmr_channel_t*  mwmr,
92                        uint32_t*        buffer,
93                        uint32_t         items );
[278]94
[722]95uint32_t nb_mwmr_write( mwmr_channel_t*  mwmr,
96                        uint32_t*        buffer,
97                        uint32_t         items );
[278]98
[722]99//////////////////////////////////////////////////////////////////////////////
100//  MWMR bufio access functions
101//////////////////////////////////////////////////////////////////////////////
102
103void mwmr_bufio_init( mwmr_bufio_t*    bufio, 
104                      uint8_t*         buffer, 
105                      uint32_t         size,       // number of bytes
106                      uint32_t         is_input,
107                      mwmr_channel_t*  mwmr );
108                   
109void mwmr_bufio_dump( mwmr_bufio_t* bufio );
110
111uint8_t mwmr_bufio_read_byte( mwmr_bufio_t* bufio );
112
113void mwmr_bufio_skip( mwmr_bufio_t* bufio,
114                      uint32_t      length );
115
116void mwmr_bufio_align( mwmr_bufio_t* bufio );
117
118void mwmr_bufio_write_byte( mwmr_bufio_t* bufio,
119                            uint8_t       value );
120
121void mwmr_bufio_flush( mwmr_bufio_t* bufio );
122
[258]123#endif
124
125// Local Variables:
126// tab-width: 4
127// c-basic-offset: 4
128// c-file-offsets:((innamespace . 0)(inline-open . 0))
129// indent-tabs-mode: nil
130// End:
131// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
132
Note: See TracBrowser for help on using the repository browser.