Changeset 207 for soft/giet_vm/libs


Ignore:
Timestamp:
Aug 16, 2012, 6:36:16 PM (12 years ago)
Author:
alain
Message:

Several bugs have been fixed to support TSAR multi-cluster architecture
such as the "tsarv4-generic_mmu" platform.

File:
1 edited

Legend:

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

    r200 r207  
    6262            :"$2", "$3", "$4");
    6363}
     64//////////////////////////////////////////////////////////////////////////////
     65//         nb_mwmr_write()
     66// This is a non-blocking function.
     67// The nitems parameter is the number of items to be transfered.
     68// The requested transfer is therefore (nitems * width) words.
     69// It takes the lock for exclusive access before testing the channel state.
     70// If there is not enough data in mwmr channel to read nitems,
     71// it reads as many items as possible, releases the lock, and returns
     72// the number of read items (it can be 0).
     73//////////////////////////////////////////////////////////////////////////////
     74unsigned int nb_mwmr_write( mwmr_channel_t*     mwmr,
     75                            unsigned int*               buffer,
     76                            unsigned int                nitems )
     77{
     78    unsigned int        x;
     79    unsigned int        spaces;         // number of empty slots (in words)
     80    unsigned int        nwords;         // requested transfer length (in words)
     81    unsigned int    depth;              // channel depth (in words)
     82    unsigned int    width;              // channel width (in words)
     83    unsigned int    sts;        // channel sts
     84    unsigned int    ptw;        // channel ptw
     85
     86    if(nitems == 0) return 0;
     87
     88    // get the lock
     89    mwmr_lock_acquire( &mwmr->lock );
     90
     91    // access fifo status
     92    depth  = mwmr->depth;
     93    width  = mwmr->width;
     94    sts    = mwmr->sts;
     95    ptw    = mwmr->ptw;
     96    spaces = depth - sts;
     97    nwords = width * nitems;
     98
     99    if( spaces >= nwords )      // transfer nitems, release lock and return
     100    {
     101        for ( x = 0 ; x < nwords ; x++ ) 
     102        {
     103            mwmr->data[ptw] = buffer[x];
     104            if ( (ptw + 1) == depth ) ptw = 0;
     105            else                      ptw = ptw + 1;
     106        }
     107        mwmr->sts  = mwmr->sts + nwords;
     108        mwmr->ptw  = ptw;
     109        mwmr->lock = 0;
     110        return nitems;
     111    }
     112   
     113    else if ( spaces < width )  // release lock and return
     114    {
     115        mwmr->lock = 0;
     116        return 0;
     117    }
     118    else        // transfer as many items as possible, release lock and return
     119    {
     120        nwords = (spaces/width) * width;        // integer number of items
     121        for ( x = 0 ; x < nwords ; x++ ) 
     122        {
     123            mwmr->data[ptw] = buffer[x];
     124            if ( (ptw + 1) == depth ) ptw = 0;
     125            else                      ptw = ptw + 1;
     126        }
     127        mwmr->sts  = sts + nwords;
     128        mwmr->ptw  = ptw;
     129        mwmr->lock = 0;
     130        return (nwords/width);
     131    }
     132} // end nb_mwmr_write()
    64133
    65134//////////////////////////////////////////////////////////////////////////////
     
    136205        for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
    137206    }
    138 }
     207} // end mwmr_write()
     208
     209//////////////////////////////////////////////////////////////////////////////
     210//         nb_mwmr_read()
     211// This is a non-blocking function.
     212// The nitems parameter is the number of items to be transfered.
     213// The requested transfer is therefore (nitems * width) words.
     214// It takes the lock for exclusive access before testing the channel state.
     215// If there is not enough data in mwmr channel to read nitems,
     216// it reads as many items as possible, releases the lock, and returns
     217// the number of read items (it can be 0).
     218//////////////////////////////////////////////////////////////////////////////
     219unsigned int nb_mwmr_read( mwmr_channel_t*      mwmr,
     220                           unsigned int*                buffer,
     221                           unsigned int                 nitems )
     222{
     223    unsigned int        x;
     224    unsigned int        nwords;         // requested transfer length (in words)
     225    unsigned int    depth;              // channel depth (in words)
     226    unsigned int    width;              // channel width (in words)
     227    unsigned int    sts;        // channel sts
     228    unsigned int    ptr;        // channel ptr
     229
     230    if(nitems == 0) return 0;
     231
     232    // get the lock
     233    mwmr_lock_acquire( &mwmr->lock );
     234
     235    // access fifo status
     236    depth  = mwmr->depth;
     237    width  = mwmr->width;
     238    sts    = mwmr->sts;
     239    ptr    = mwmr->ptr;
     240    nwords = width * nitems;
     241
     242    if( sts >= nwords )         // transfer nitems, release lock and return
     243    {
     244        for ( x = 0 ; x < nwords ; x++ ) 
     245        {
     246            buffer[x] = mwmr->data[ptr];
     247            if ( (ptr + 1) == depth ) ptr = 0;
     248            else                      ptr = ptr + 1;
     249        }
     250        mwmr->sts  = mwmr->sts - nwords;
     251        mwmr->ptr  = ptr;
     252        mwmr->lock = 0;
     253        return nitems;
     254    }
     255   
     256    else if ( sts < width )     // release lock and return
     257    {
     258        mwmr->lock = 0;
     259        return 0;
     260    }
     261    else        // transfer as many items as possible, release lock and return
     262    {
     263        nwords = (sts/width) * width;   // integer number of items
     264        for ( x = 0 ; x < nwords ; x++ ) 
     265        {
     266            buffer[x] = mwmr->data[ptr];
     267            if ( (ptr + 1) == depth ) ptr = 0;
     268            else                      ptr = ptr + 1;
     269        }
     270        mwmr->sts  = sts - nwords;
     271        mwmr->ptr  = ptr;
     272        mwmr->lock = 0;
     273        return (nwords/width);
     274    }
     275} // nb_mwmr_read()
    139276
    140277//////////////////////////////////////////////////////////////////////////////
     
    157294    unsigned int    width;              // channel width (in words)
    158295    unsigned int    sts;        // channel sts
    159     unsigned int    ptr;        // channel ptw
     296    unsigned int    ptr;        // channel ptr
    160297
    161298    if(nitems == 0) return;
     
    209346        for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
    210347    }
    211 }
    212 
     348} // end mwmr_read()
     349
     350
Note: See TracChangeset for help on using the changeset viewer.