Modulo Buffer Examples

The following listing is a modulo buffer example.

Listing: Modulo Buffer Example 1
#pragma define_section DATA_INT_MODULO ".data_int_modulo"





/* Place the buffer object in a unique section so the it can be aligned properly in the linker control file. */



#pragma section DATA_INT_MODULO begin

int int_buf[10];

#pragma section DATA_INT_MODULO end





          /* Convenient defines for modulo descriptors */



#define M0 0

#define M1 1



int main ( void )

{

          int i;



/*   Modulo buffer will be initialized. R0 will be the modulo pointer register. The buffer size is 10 units. The unit size is ‘sizeof(int)’. */



  __mod_init(M0, (void *)&int_buf[0], 10, sizeof(int));



/* Write the modulo control register */



  __mod_start();



/* Write int_buf[0] through int_buf[9]. R0 initially points at int_buf[0] and wraps when the pointer value exceeds int_buf[9]. The pointer is updated by 1 unit each time through the loop */



          for ( i=0; i<100; i++ )

          {



          *((int *)__mod_access(M0)) = i;

          __mod_update(M0, 1);



          }



/* Reset modulo control register to linear addressing mode */

          __mod_stop();



}

The following listing is an another modulo buffer example.

Listing: Modulo Buffer Example 2
/* Set up a static location to save error codes */

if ( ! __mod_error(&err_codes)) {



printf (“__mod_error set up failed\n”);

}



/* Initialize a modulo buffer pointer, pointing to an array of 10 ints. */



__mod_initint16(M0, &int_buf[9], 10);



/* Check for success of previous call */



          if ( err_code ) { printf ( “__mod_initint16 failed\n” ) };



          __mod_start();





/* Write modulo buffer with the result of the expression “i”. 

Decrement the buffer pointer for each execution of the loop. 

The modulo buffer wraps from index 0 to 9 through the entire execution of the loop. */



          for ( i=100; i>0; i-- ) {



          __mod_setint16(M0, i, -1);



          }

          __mod_stop();