[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 |
---|
| 17 | // an integer number of unsigned int (32 bits words). |
---|
| 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" |
---|
| 31 | |
---|
[258] | 32 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | // MWMR channel structure |
---|
[450] | 34 | // The data buffer size is defined to obtain sizeof(mwmr_channel_t) = 4096 bytes. |
---|
| 35 | // The actual buffer size cannot be larger than 4072 bytes (1018 words). |
---|
[258] | 36 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 37 | |
---|
| 38 | typedef struct mwmr_channel_s |
---|
| 39 | { |
---|
[461] | 40 | user_lock_t lock; // exclusive access lock |
---|
| 41 | unsigned int ptr; // index of the first valid data word |
---|
| 42 | unsigned int ptw; // index of the first empty slot |
---|
| 43 | unsigned int sts; // number of words available |
---|
| 44 | unsigned int depth; // max number of words in the channel |
---|
| 45 | unsigned int width; // number of words in an item |
---|
| 46 | unsigned int* data; // circular buffer base address |
---|
[258] | 47 | } mwmr_channel_t; |
---|
| 48 | |
---|
| 49 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 50 | // MWMR access functions |
---|
| 51 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 52 | |
---|
[450] | 53 | void mwmr_init( mwmr_channel_t* mwmr, |
---|
[461] | 54 | unsigned int* buffer, // data buffer base address |
---|
[450] | 55 | unsigned int width, // number of words per item |
---|
[461] | 56 | unsigned int nitems ); // max number of items |
---|
[450] | 57 | |
---|
[461] | 58 | void mwmr_read( mwmr_channel_t* mwmr, |
---|
| 59 | unsigned int* buffer, |
---|
| 60 | unsigned int items ); |
---|
[258] | 61 | |
---|
[461] | 62 | void mwmr_write( mwmr_channel_t* mwmr, |
---|
| 63 | unsigned int* buffer, |
---|
| 64 | unsigned int items ); |
---|
[258] | 65 | |
---|
[278] | 66 | unsigned int nb_mwmr_read ( mwmr_channel_t * mwmr, |
---|
| 67 | unsigned int * buffer, |
---|
[461] | 68 | unsigned int items ); |
---|
[278] | 69 | |
---|
| 70 | unsigned int nb_mwmr_write( mwmr_channel_t * mwmr, |
---|
| 71 | unsigned int * buffer, |
---|
[461] | 72 | unsigned int items ); |
---|
[278] | 73 | |
---|
[258] | 74 | #endif |
---|
| 75 | |
---|
| 76 | // Local Variables: |
---|
| 77 | // tab-width: 4 |
---|
| 78 | // c-basic-offset: 4 |
---|
| 79 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 80 | // indent-tabs-mode: nil |
---|
| 81 | // End: |
---|
| 82 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 83 | |
---|