Changeset 722


Ignore:
Timestamp:
Nov 21, 2015, 1:57:51 PM (9 years ago)
Author:
alain
Message:

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.

Location:
soft/giet_vm/giet_libs
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_libs/mwmr_channel.c

    r693 r722  
    99#include "giet_config.h"
    1010#include "stdio.h"
     11#include "stdint.h"
    1112#include "user_lock.h"
    1213
    1314//////////////////////////////////////
    1415void mwmr_init( mwmr_channel_t*  mwmr,
    15                 unsigned int*    buffer,     // buffer base address
    16                 unsigned int     width,      // number of words per item
    17                 unsigned int     nitems )    // max number of items
    18 {
    19 
    20 #if GIET_DEBUG_USER_MWMR
    21 unsigned int    x;
    22 unsigned int    y;
    23 unsigned int    lpid;
     16                uint32_t*        buffer,     // buffer base address
     17                uint32_t         width,      // number of words per item
     18                uint32_t         nitems )    // max number of items
     19{
     20
     21#if GIET_DEBUG_USER_MWMR
     22uint32_t    x;
     23uint32_t    y;
     24uint32_t    lpid;
    2425giet_proc_xyp( &x, &y, &lpid );
    25 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] initialises fifo %x / "
    26                 " buffer = %x / width = %d / nitems = %d\n",
    27                 x, y, lpid, (unsigned int)mwmr, (unsigned int)buffer, width, nitems );
     26giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] initialises mwmr channel %x"
     27                "\n buffer = %x / width = %d / nitems = %d\n",
     28                x, y, lpid, (uint32_t)mwmr, (uint32_t)buffer, width, nitems );
    2829#endif
    2930
     
    3940
    4041
    41 ///////////////////////////////////////////////////
    42 unsigned int nb_mwmr_write( mwmr_channel_t * mwmr,
    43                             unsigned int *   buffer,
    44                             unsigned int     items)
    45 {
    46 
    47 #if GIET_DEBUG_USER_MWMR
    48 unsigned int    x;
    49 unsigned int    y;
    50 unsigned int    lpid;
     42///////////////////////////////////////
     43void mwmr_dump( mwmr_channel_t*  mwmr )
     44{
     45    // get the lock
     46    lock_acquire( &mwmr->lock );
     47
     48    giet_tty_printf("\n[DEBUG MWMR] &fifo = %x / width = %d / depth = %d"
     49                    "\n             sts = %d / ptr = %d / ptw = %d\n",
     50                    (uint32_t)mwmr, mwmr->width, mwmr->depth,
     51                     mwmr->sts, mwmr->ptr, mwmr->ptw );
     52    uint32_t line, word, value;
     53    for ( line = 0 ; line < ((mwmr->depth)>>2) ; line++ )
     54    {
     55        giet_tty_printf(" line %d :  ", line );
     56        for ( word = 0 ; word < 4 ; word++ )
     57        {
     58            value = mwmr->data[line*4+word];
     59            giet_tty_printf(" %x %x %x %x",
     60                            (value    ) & 0xFF,
     61                            (value>>8 ) & 0xFF,
     62                            (value>>16) & 0xFF,
     63                            (value>>24) & 0xFF );
     64        }
     65        giet_tty_printf("\n");
     66    }
     67
     68    // release the lock
     69    lock_release( &mwmr->lock );
     70
     71}
     72
     73
     74//////////////////////////////////////////////
     75uint32_t nb_mwmr_write( mwmr_channel_t*  mwmr,
     76                        uint32_t*        buffer,
     77                        uint32_t         items)
     78{
     79
     80#if GIET_DEBUG_USER_MWMR
     81uint32_t    x;
     82uint32_t    y;
     83uint32_t    lpid;
    5184giet_proc_xyp( &x, &y, &lpid );
    52 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] enters nb_mwmr_write()"
    53                 " : mwmr = %x / buffer = %x / items =  %d\n",
    54                 x, y, lpid, (unsigned int)mwmr, (unsigned int)buffer, items );
    55 #endif
    56 
    57     unsigned int n;
    58     unsigned int spaces; // number of empty slots (in words)
    59     unsigned int nwords; // requested transfer length (in words)
    60     unsigned int depth;  // channel depth (in words)
    61     unsigned int width;  // channel width (in words)
    62     unsigned int sts;    // channel sts
    63     unsigned int ptw;    // channel ptw
     85#endif
     86
     87    uint32_t n;
     88    uint32_t spaces; // number of empty slots (in words)
     89    uint32_t nwords; // requested transfer length (in words)
     90    uint32_t depth;  // channel depth (in words)
     91    uint32_t width;  // channel width (in words)
     92    uint32_t sts;    // channel sts
     93    uint32_t ptw;    // channel ptw
    6494
    6595    if (items == 0) return 0;
     
    88118
    89119#if GIET_DEBUG_USER_MWMR
    90 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] writes %d words in fifo %x : sts = %d\n",
    91                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     120giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] nb_mwmr_write() for %d words"
     121                "\n %d words written / fifo %x / sts = %d\n",
     122                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    92123#endif
    93124
     
    113144
    114145#if GIET_DEBUG_USER_MWMR
    115 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] writes %d words in fifo %x : sts = %d\n",
    116                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     146giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] nb_mwmr_write() for %d words"
     147                "\n %d words written / fifo %x / sts = %d\n",
     148                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    117149#endif
    118150
     
    125157
    126158//////////////////////////////////////////////////
    127 unsigned int nb_mwmr_read( mwmr_channel_t * mwmr,
    128                            unsigned int *   buffer,
    129                            unsigned int     items)
    130 {
    131 
    132 #if GIET_DEBUG_USER_MWMR
    133 unsigned int    x;
    134 unsigned int    y;
    135 unsigned int    lpid;
     159uint32_t nb_mwmr_read( mwmr_channel_t* mwmr,
     160                       uint32_t*        buffer,
     161                       uint32_t         items)
     162{
     163
     164#if GIET_DEBUG_USER_MWMR
     165uint32_t    x;
     166uint32_t    y;
     167uint32_t    lpid;
    136168giet_proc_xyp( &x, &y, &lpid );
    137 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] enters nb_mwmr_read()"
    138                 " : mwmr = %x / buffer = %x / items =  %d\n",
    139                 x, y, lpid, (unsigned int)mwmr, (unsigned int)buffer, items );
    140 #endif
    141 
    142     unsigned int n;
    143     unsigned int nwords; // requested transfer length (words)
    144     unsigned int depth;  // channel depth (words)
    145     unsigned int width;  // channel width (words)
    146     unsigned int sts;    // channel sts   (words)
    147     unsigned int ptr;    // channel ptr   (words)
     169#endif
     170
     171    uint32_t n;
     172    uint32_t nwords; // requested transfer length (words)
     173    uint32_t depth;  // channel depth (words)
     174    uint32_t width;  // channel width (words)
     175    uint32_t sts;    // channel sts   (words)
     176    uint32_t ptr;    // channel ptr   (words)
    148177
    149178    if (items == 0) return 0;
     
    171200
    172201#if GIET_DEBUG_USER_MWMR
    173 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] read %d words in fifo %x : sts = %d\n",
    174                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     202giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] nb_mwmr_read() for %d words"
     203                "\n %d words read / fifo %x / sts = %d\n",
     204                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    175205#endif
    176206
     
    180210    else if (sts < width) // release lock and return
    181211    {
    182 
    183 #if GIET_DEBUG_USER_MWMR
    184 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] read nothing in fifo %x : sts = %d\n",
    185                 x, y, lpid, (unsigned int)mwmr, mwmr->sts );
    186 #endif
    187 
    188212        lock_release( &mwmr->lock );
    189213        return 0;
     
    202226
    203227#if GIET_DEBUG_USER_MWMR
    204 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] read %d words in fifo %x : sts = %d\n",
    205                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     228giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] nb_mwmr_read() for %d words"
     229                "\n %d words read / fifo %x / sts = %d\n",
     230                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    206231#endif
    207232
     
    214239
    215240////////////////////////////////////////
    216 void mwmr_write( mwmr_channel_t * mwmr,
    217                  unsigned int *   buffer,
    218                  unsigned int     items )
    219 {
    220 
    221 #if GIET_DEBUG_USER_MWMR
    222 unsigned int    x;
    223 unsigned int    y;
    224 unsigned int    lpid;
     241void mwmr_write( mwmr_channel_t* mwmr,
     242                 uint32_t *       buffer,
     243                 uint32_t         items )
     244{
     245
     246#if GIET_DEBUG_USER_MWMR
     247uint32_t    x;
     248uint32_t    y;
     249uint32_t    lpid;
    225250giet_proc_xyp( &x, &y, &lpid );
    226 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] enters mwmr_write()"
    227                 " : mwmr = %x / buffer = %x / items =  %d\n",
    228                 x, y, lpid, (unsigned int)mwmr, (unsigned int)buffer, items );
    229 #endif
    230 
    231     unsigned int n;
    232     unsigned int spaces; // number of empty slots (in words)
    233     unsigned int nwords; // requested transfer length (in words)
    234     unsigned int depth;  // channel depth (in words)
    235     unsigned int width;  // channel width (in words)
    236     unsigned int sts;    // channel sts
    237     unsigned int ptw;    // channel ptw
     251#endif
     252
     253    uint32_t n;
     254    uint32_t spaces; // number of empty slots (in words)
     255    uint32_t nwords; // requested transfer length (in words)
     256    uint32_t depth;  // channel depth (in words)
     257    uint32_t width;  // channel width (in words)
     258    uint32_t sts;    // channel sts
     259    uint32_t ptw;    // channel ptw
    238260
    239261    if (items == 0)  return;
     
    264286
    265287#if GIET_DEBUG_USER_MWMR
    266 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] writes %d words in fifo %x : sts = %d\n",
    267                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     288giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] mwmr_write() for %d words"
     289                "\n %d words written / fifo %x / sts = %d\n",
     290                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    268291#endif
    269292
     
    290313
    291314#if GIET_DEBUG_USER_MWMR
    292 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] writes %d words in fifo %x : sts = %d\n",
    293                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     315giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] mwmr_write() for %d words"
     316                "\n %d words written / fifo %x / sts = %d\n",
     317                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    294318#endif
    295319
     
    304328
    305329//////////////////////////////////////
    306 void mwmr_read( mwmr_channel_t * mwmr,
    307                 unsigned int *   buffer,
    308                 unsigned int     items)
    309 {
    310 
    311 #if GIET_DEBUG_USER_MWMR
    312 unsigned int    x;
    313 unsigned int    y;
    314 unsigned int    lpid;
     330void mwmr_read( mwmr_channel_t* mwmr,
     331                uint32_t*        buffer,
     332                uint32_t         items)
     333{
     334
     335#if GIET_DEBUG_USER_MWMR
     336uint32_t    x;
     337uint32_t    y;
     338uint32_t    lpid;
    315339giet_proc_xyp( &x, &y, &lpid );
    316 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] enters mwmr_read()"
    317                 " : mwmr = %x / buffer = %x / items =  %d\n",
    318                 x, y, lpid, (unsigned int)mwmr, (unsigned int)buffer, items );
    319 #endif
    320 
    321     unsigned int n;
    322     unsigned int nwords; // requested transfer length (in words)
    323     unsigned int depth;  // channel depth (in words)
    324     unsigned int width;  // channel width (in words)
    325     unsigned int sts;    // channel sts
    326     unsigned int ptr;    // channel ptr
     340#endif
     341
     342    uint32_t n;
     343    uint32_t nwords; // requested transfer length (in words)
     344    uint32_t depth;  // channel depth (in words)
     345    uint32_t width;  // channel width (in words)
     346    uint32_t sts;    // channel sts
     347    uint32_t ptr;    // channel ptr
    327348
    328349    if (items == 0) return;
     
    352373
    353374#if GIET_DEBUG_USER_MWMR
    354 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] read %d words in fifo %x : sts = %d\n",
    355                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     375giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] mwmr_read() for %d words"
     376                "\n %d words read / fifo %x / sts = %d\n",
     377                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    356378#endif
    357379
     
    378400
    379401#if GIET_DEBUG_USER_MWMR
    380 giet_tty_printf("\n[MWMR DEBUG] Proc[%d,%d,%d] read %d words in fifo %x : sts = %d\n",
    381                 x, y, lpid, nwords, (unsigned int)mwmr, mwmr->sts );
     402giet_tty_printf("\n[DEBUG MWMR] P[%d,%d,%d] mwmr_read() for %d words"
     403                "\n %d words read / fifo %x / sts = %d\n",
     404                x, y, lpid, items*width , nwords, (uint32_t)mwmr, mwmr->sts );
    382405#endif
    383406
     
    391414
    392415
     416
     417
     418
     419
     420
     421
     422/////////////////////////////////////////////
     423void mwmr_bufio_init( mwmr_bufio_t*    bufio,       
     424                      uint8_t*         buffer,
     425                      uint32_t         size,       // number of bytes
     426                      uint32_t         is_input,
     427                      mwmr_channel_t*  mwmr )
     428{
     429    uint32_t bytes_per_item = (mwmr->width)<<2;
     430
     431    giet_pthread_assert( ((size % bytes_per_item) == 0) ,
     432    "ERROR in mwmr_bufio_init() : BUFIO size must be multiple of MWMR item size\n");
     433
     434    bufio->mwmr     = mwmr;
     435    bufio->is_input = is_input;
     436    bufio->base     = buffer;
     437    bufio->ptr      = 0;
     438    bufio->max      = 0;
     439    bufio->nitems   = size / bytes_per_item;
     440    bufio->nbytes   = size;
     441}  // end mwmr_bufio_init()
     442
     443////////////////////////////////////////////
     444void mwmr_bufio_dump( mwmr_bufio_t*  bufio )
     445{
     446    giet_tty_printf("\n[DEBUG MWMR] &bufio = %x / &mwmr = %x / &buffer = %x"
     447                    "\n             is_input = %d / nbytes = %d / ptr = %d / max = %d\n",
     448                    bufio , bufio->mwmr , bufio->base,
     449                    bufio->is_input , bufio->nbytes , bufio->ptr , bufio->max );
     450    uint32_t i = 0;
     451    while ( i < bufio->nbytes )
     452    {
     453        giet_tty_printf(" %x", bufio->base[i] );
     454        if ( (i & 0xF) == 0xF ) giet_tty_printf("\n");
     455        i++;
     456    }
     457    giet_tty_printf("\n");
     458}  // end mwmr_bufio_dump()
     459   
     460////////////////////////////////////////////////////
     461uint8_t mwmr_bufio_read_byte( mwmr_bufio_t*  bufio )
     462{
     463    giet_pthread_assert( ( bufio->is_input ) ,
     464    "ERROR in mwmr_bufio_read_byte() : bufio not input\n");
     465
     466    uint8_t ret;
     467
     468    if ( bufio->ptr == 0 )  // refill
     469    {
     470        uint32_t items;
     471        do
     472        {
     473            items = nb_mwmr_read( bufio->mwmr , (uint32_t*)bufio->base , bufio->nitems );
     474        }
     475        while ( items == 0 );
     476        bufio->max = items * ((bufio->mwmr->width)<<2);
     477
     478#if GIET_DEBUG_USER_MWMR
     479giet_tty_printf("\n[DEBUG MWMR] mwmr_bufio_read_byte() read %d bytes from mwmr\n",
     480                bufio->max );
     481uint32_t i = 0;
     482while ( i < bufio->max )
     483{
     484    giet_tty_printf(" %x", bufio->base[i] );
     485    if ( (i & 0xF) == 0xF ) giet_tty_printf("\n");
     486    i++;
     487}
     488giet_tty_printf("\n");
     489#endif
     490
     491    }
     492
     493    ret = bufio->base[bufio->ptr];
     494    bufio->ptr++;
     495    if ( bufio->ptr == bufio->max ) bufio->ptr = 0;
     496    return ret;
     497
     498}  // end mwmr_bufio_read_byte()
     499
     500///////////////////////////////////////////
     501void mwmr_bufio_skip( mwmr_bufio_t*  bufio,
     502                      uint32_t       length )
     503{
     504    giet_pthread_assert( ( bufio->is_input ) ,
     505    "ERROR in mwmr_bufio_skip() : bufio not input\n");
     506
     507    while ( length )
     508    {
     509        if ( bufio->ptr == 0 )  // refill
     510        {
     511            uint32_t items;
     512            do
     513            {
     514                items = nb_mwmr_read( bufio->mwmr , (uint32_t*)bufio->base , bufio->nitems );
     515            }
     516            while ( items == 0 );
     517            bufio->max = items * ((bufio->mwmr->width)<<2);
     518
     519#if GIET_DEBUG_USER_MWMR
     520giet_tty_printf("\n[DEBUG MWMR] mwmr_bufio_skip() read %d bytes from mwmr\n",
     521                bufio->max );
     522uint32_t i = 0;
     523while ( i < bufio->max )
     524{
     525    giet_tty_printf(" %x", bufio->base[i] );
     526    if ( (i & 0xF) == 0xF ) giet_tty_printf("\n");
     527    i++;
     528}
     529giet_tty_printf("\n");
     530#endif
     531
     532        }
     533
     534        bufio->ptr++;
     535        if ( bufio->ptr == bufio->max ) bufio->ptr = 0;
     536        length--;
     537    }
     538}  // end mwmr_bufio_skip()
     539                     
     540/////////////////////////////////////////////
     541void mwmr_bufio_align( mwmr_bufio_t*  bufio )
     542{
     543    giet_pthread_assert( ( bufio->is_input ) ,
     544    "ERROR in mwmr_bufio_align() : bufio not input\n");
     545
     546    uint32_t bytes_per_item = (bufio->mwmr->width)<<2;
     547    uint32_t offset = bufio->ptr % bytes_per_item;
     548
     549    // align ptr on next item boundary if required
     550    if ( offset )
     551    {
     552        bufio->ptr = bufio->ptr + bytes_per_item - offset;
     553        if ( bufio-> ptr == bufio->max ) bufio->ptr = 0;
     554    }
     555}  // end mwmr_bufio_align()
     556
     557
     558/////////////////////////////////////////////////
     559void mwmr_bufio_write_byte( mwmr_bufio_t*  bufio,
     560                            uint8_t        value )
     561{
     562    giet_pthread_assert( ( !bufio->is_input ) ,
     563    "ERROR in mwmr_bufio_write_byte() : bufio not output\n");
     564
     565    bufio->base[bufio->ptr] = value;
     566
     567    bufio->ptr++;
     568    if ( bufio->ptr == bufio->nbytes )  // flush bufio
     569    {
     570        // move data to mwmr channel
     571        mwmr_write( bufio->mwmr , (uint32_t*)bufio->base , bufio->nitems );
     572
     573        // reinitialise bufio
     574        bufio->ptr = 0;
     575
     576#if GIET_DEBUG_USER_MWMR
     577giet_tty_printf("\n[DEBUG MWMR] mwmr_bufio_write_byte() write %d bytes to mwmr\n",
     578                bufio->nbytes );
     579uint32_t i = 0;
     580while ( i < bufio->nbytes )
     581{
     582    giet_tty_printf(" %x", bufio->base[i] );
     583    if ( (i & 0xF) == 0xF ) giet_tty_printf("\n");
     584    i++;
     585}
     586giet_tty_printf("\n");
     587#endif
     588    }
     589}  // end mwmr_bufio_write_byte()
     590
     591/////////////////////////////////////////////
     592void mwmr_bufio_flush( mwmr_bufio_t*  bufio )
     593{
     594    giet_pthread_assert( ( !bufio->is_input ) ,
     595    "ERROR in mwmr_bufio_flush() : bufio not output\n");
     596
     597    uint32_t i;
     598
     599    uint32_t bytes_per_item = (bufio->mwmr->width)<<2;
     600
     601    // do nothing if bufio empty
     602    if ( bufio->ptr == 0 ) return;
     603   
     604    // compute number of items and extra bytes to be moved to MWMR channel
     605    uint32_t nitems = bufio->ptr / bytes_per_item;
     606    uint32_t offset = bufio->ptr % bytes_per_item;
     607
     608    // completes last item with 0 if required
     609    if ( offset )
     610    {
     611        for( i = bufio->ptr;
     612             i < bufio->ptr + bytes_per_item - offset ;
     613             i++ ) bufio->base[i] = 0;
     614
     615        nitems++;
     616    }
     617
     618#if GIET_DEBUG_USER_MWMR
     619giet_tty_printf("\n[DEBUG MWMR] mwmr_bufio_flush() write %d bytes to mwmr\n",
     620                nitems * bytes_per_item );
     621uint32_t j = 0;
     622while ( j < (nitems * bytes_per_item) )
     623{
     624    giet_tty_printf(" %x", bufio->base[j] );
     625    if ( (j & 0xF) == 0xF ) giet_tty_printf("\n");
     626    j++;
     627}
     628giet_tty_printf("\n");
     629#endif
     630
     631    // move nitems to mwmr channel
     632    mwmr_write( bufio->mwmr , (uint32_t*)bufio->base , nitems );
     633
     634    // reinitialise bufio
     635    bufio->ptr = 0;
     636
     637}  // end mwmr_bufio_flush()
     638
     639
     640   
    393641// Local Variables:
    394642// tab-width: 4
  • soft/giet_vm/giet_libs/mwmr_channel.h

    r521 r722  
    1515//
    1616// An MWMR transaction transfer an integer number of items, and an item is
    17 // an integer number of unsigned int (32 bits words).
     17// an integer number of uint32_t (32 bits words).
    1818// The max number of words that can be stored in a MWMR channel is defined by the
    1919// "depth" parameter, and the "width" parameter define the minimal number of
     
    2929
    3030#include "user_lock.h"
     31#include "stdint.h"
    3132
    3233///////////////////////////////////////////////////////////////////////////////////
    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.
    3437///////////////////////////////////////////////////////////////////////////////////
    3538
    3639typedef struct mwmr_channel_s
    3740{
    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
    4648} mwmr_channel_t;
    4749
     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
    4872//////////////////////////////////////////////////////////////////////////////
    49 //  MWMR access functions
     73//  MWMR channel access functions
    5074//////////////////////////////////////////////////////////////////////////////
    5175
    5276void 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
     81void mwmr_dump( mwmr_channel_t* mwmr );
    5682
    5783void mwmr_read(  mwmr_channel_t* mwmr,
    58                  unsigned int*   buffer,
    59                  unsigned int    items );
     84                 uint32_t*       buffer,
     85                 uint32_t        items );
    6086
    6187void mwmr_write( mwmr_channel_t* mwmr,
    62                  unsigned int*   buffer,
    63                  unsigned int    items );
     88                 uint32_t*       buffer,
     89                 uint32_t        items );
    6490
    65 unsigned int nb_mwmr_read ( mwmr_channel_t * mwmr,
    66                             unsigned int * buffer,
    67                             unsigned int items );
     91uint32_t nb_mwmr_read ( mwmr_channel_t* mwmr,
     92                        uint32_t*        buffer,
     93                        uint32_t        items );
    6894
    69 unsigned int nb_mwmr_write( mwmr_channel_t * mwmr,
    70                             unsigned int * buffer,
    71                             unsigned int items );
     95uint32_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
     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 );
    72122
    73123#endif
  • soft/giet_vm/giet_libs/stdio.c

    r713 r722  
    817817}
    818818
     819////////////////////////////////////////////
     820void giet_fbf_cma_alloc( unsigned int nbufs )
     821{
     822    if ( sys_call( SYSCALL_FBF_CMA_ALLOC,
     823                   nbufs,
     824                   0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_ALLOC");
     825}
     826
     827///////////////////////////////////////////////
     828void giet_fbf_cma_init_buf( unsigned int index,
     829                            void*        buf_vaddr,
     830                            void*        sts_vaddr )
     831{
     832    if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
     833                   index,
     834                   (unsigned int)buf_vaddr,
     835                   (unsigned int)sts_vaddr,
     836                   0 ) )         giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF");
     837}
     838
    819839/////////////////////////
    820 void giet_fbf_cma_alloc()
    821 {
    822     if ( sys_call( SYSCALL_FBF_CMA_ALLOC,
    823                    0, 0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_ALLOC");
    824 }
    825 
    826 ///////////////////////////////////////////
    827 void giet_fbf_cma_init_buf( void* buf0_vbase,
    828                             void* buf1_vbase,
    829                             void* sts0_vaddr,
    830                             void* sts1_vaddr )
    831 {
    832     if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF,
    833                    (unsigned int)buf0_vbase,
    834                    (unsigned int)buf1_vbase,
    835                    (unsigned int)sts0_vaddr,
    836                    (unsigned int)sts1_vaddr ) ) giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF");
    837 }
    838 
    839 ///////////////////////////////////////////
    840 void giet_fbf_cma_start( unsigned int length )
     840void giet_fbf_cma_start()
    841841{
    842842    if ( sys_call( SYSCALL_FBF_CMA_START,
    843                    length,
    844                    0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_START");
    845 }
    846 
    847 ////////////////////////////////////////////////
    848 void giet_fbf_cma_display( unsigned int buffer )
     843                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_START");
     844}
     845
     846///////////////////////////////////////////////
     847void giet_fbf_cma_display( unsigned int index )
    849848{
    850849    if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
    851                    buffer,
     850                   index,
    852851                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_DISPLAY");
     852}
     853
     854/////////////////////////////////////////////
     855void giet_fbf_cma_check( unsigned int index )
     856{
     857    if ( sys_call( SYSCALL_FBF_CMA_CHECK,
     858                   index,
     859                   0, 0, 0 ) )   giet_pthread_exit("ERROR in FBF_CMA_CHECK");
    853860}
    854861
     
    857864{
    858865    if ( sys_call( SYSCALL_FBF_CMA_STOP,
    859                    0, 0, 0, 0 ) )    giet_pthread_exit("ERROR in FBF_CMA_STOP");
     866                   0, 0, 0, 0 ) )  giet_pthread_exit("ERROR in FBF_CMA_STOP");
    860867}
    861868
  • soft/giet_vm/giet_libs/stdio.h

    r713 r722  
    3434#define SYSCALL_FBF_CMA_DISPLAY      0x0D
    3535#define SYSCALL_FBF_CMA_STOP         0x0E
    36 //                                   0x0F
     36#define SYSCALL_FBF_CMA_CHECK        0x0F
    3737
    3838#define SYSCALL_APPS_STATUS          0x10
     
    292292extern void giet_fbf_alloc();
    293293
    294 extern void giet_fbf_cma_alloc();
    295 
    296 extern void giet_fbf_cma_init_buf( void* buf0_vbase,
    297                                    void* buf1_vbase,
    298                                    void* sts0_vaddr,
    299                                    void* sts1_vaddr );
    300 
    301 extern void giet_fbf_cma_start( unsigned int length );
     294extern void giet_fbf_cma_alloc( unsigned int nbufs );
     295
     296extern void giet_fbf_cma_init_buf( unsigned int index,
     297                                   void*        buf_vbase,
     298                                   void*        sts_vaddr );
     299
     300extern void giet_fbf_cma_start();
     301
     302extern void giet_fbf_cma_check( unsigned int buffer );
    302303
    303304extern void giet_fbf_cma_display( unsigned int buffer );
Note: See TracChangeset for help on using the changeset viewer.