Changeset 722 for soft/giet_vm/giet_libs/mwmr_channel.h
- Timestamp:
- Nov 21, 2015, 1:57:51 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/mwmr_channel.h
r521 r722 15 15 // 16 16 // An MWMR transaction transfer an integer number of items, and an item is 17 // an integer number of u nsigned int (32 bits words).17 // an integer number of uint32_t (32 bits words). 18 18 // The max number of words that can be stored in a MWMR channel is defined by the 19 19 // "depth" parameter, and the "width" parameter define the minimal number of … … 29 29 30 30 #include "user_lock.h" 31 #include "stdint.h" 31 32 32 33 /////////////////////////////////////////////////////////////////////////////////// 33 // MWMR channel structure 34 // MWMR channel 35 // This structure define a - shared - communication buffer between threads. 36 // It must be declared as a global variable. 34 37 /////////////////////////////////////////////////////////////////////////////////// 35 38 36 39 typedef struct mwmr_channel_s 37 40 { 38 user_lock_t lock; // exclusive access lock 39 unsigned int sts; // number of words available 40 unsigned int ptr; // index of the first valid data word 41 unsigned int ptw; // index of the first empty slot 42 unsigned int depth; // max number of words in the channel 43 unsigned int width; // number of words in an item 44 unsigned int* data; // circular buffer base address 45 unsigned int padding[10]; // for 64 bytes alignment 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 46 48 } mwmr_channel_t; 47 49 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 61 typedef 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 48 72 ////////////////////////////////////////////////////////////////////////////// 49 // MWMR access functions73 // MWMR channel access functions 50 74 ////////////////////////////////////////////////////////////////////////////// 51 75 52 76 void mwmr_init( mwmr_channel_t* mwmr, 53 unsigned int* buffer, // data buffer base address 54 unsigned int width, // number of words per item 55 unsigned int nitems ); // max number of items 77 uint32_t* buffer, 78 uint32_t width, // number of words per item 79 uint32_t nitems ); // max number of items 80 81 void mwmr_dump( mwmr_channel_t* mwmr ); 56 82 57 83 void mwmr_read( mwmr_channel_t* mwmr, 58 u nsigned int*buffer,59 u nsigned intitems );84 uint32_t* buffer, 85 uint32_t items ); 60 86 61 87 void mwmr_write( mwmr_channel_t* mwmr, 62 u nsigned int*buffer,63 u nsigned intitems );88 uint32_t* buffer, 89 uint32_t items ); 64 90 65 u nsigned int nb_mwmr_read ( mwmr_channel_t *mwmr,66 unsigned int *buffer,67 unsigned intitems );91 uint32_t nb_mwmr_read ( mwmr_channel_t* mwmr, 92 uint32_t* buffer, 93 uint32_t items ); 68 94 69 unsigned int nb_mwmr_write( mwmr_channel_t * mwmr, 70 unsigned int * buffer, 71 unsigned int items ); 95 uint32_t nb_mwmr_write( mwmr_channel_t* mwmr, 96 uint32_t* buffer, 97 uint32_t items ); 98 99 ////////////////////////////////////////////////////////////////////////////// 100 // MWMR bufio access functions 101 ////////////////////////////////////////////////////////////////////////////// 102 103 void 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 109 void mwmr_bufio_dump( mwmr_bufio_t* bufio ); 110 111 uint8_t mwmr_bufio_read_byte( mwmr_bufio_t* bufio ); 112 113 void mwmr_bufio_skip( mwmr_bufio_t* bufio, 114 uint32_t length ); 115 116 void mwmr_bufio_align( mwmr_bufio_t* bufio ); 117 118 void mwmr_bufio_write_byte( mwmr_bufio_t* bufio, 119 uint8_t value ); 120 121 void mwmr_bufio_flush( mwmr_bufio_t* bufio ); 72 122 73 123 #endif
Note: See TracChangeset
for help on using the changeset viewer.