Hint crc (void * list_ptr, Huint size, Huint * done) {

    // done variable not used for slave accelerator calls
    
    Hint result = SUCCESS;
    
    // Get VHWTI
    Huint vhwti_base = 0;
    
    // Get VHWTI from PVRs 
    getpvr(1,&vhwti_base);
    
    // Increment SW counter 
    Huint sw_counter = _hwti_get_accelerator_sw_counter( vhwti_base );
    _hwti_set_accelerator_sw_counter( vhwti_base, ++sw_counter);


    // if the size is more than 4k words,
    // grab the amount of iterations you
    // need to perform.
    Huint iterations = size / BRAM_SIZE;
    
    // If there is a remainder in this 
    // division, round up.
    if ((size % BRAM_SIZE) != 0) {
        iterations++;
    }

    Huint i = 0;
    Huint new_size = 0;
    Huint * new_list_ptr = 0;
    for (i = 0; i < iterations; i++) {

        // Calculate the size for this iteration
        new_size = (size < (BRAM_SIZE*(i+1))) ? size-(BRAM_SIZE*i) : BRAM_SIZE; 

        // Calculate the starting pointer for this iteration. Typcasting
        // may be repetitive here.
        new_list_ptr = (Huint *) ((Huint *)list_ptr + BRAM_SIZE*i);

        // Run crc in software
        result =  (sw_crc((void *) new_list_ptr, new_size));

        if (result != SUCCESS) break;
    } /* end of iterations loop */

    return result;
}
Example #2
0
Hint poly_crc (void * list_ptr, Huint size) 
{
   Hint result = SUCCESS;
   
   // Use Accelerator?
   Hbool use_accelerator = poly_init(CRC, size);

   // Start transferring data to BRAM
   if(transfer_dma( (void *) list_ptr, (void *) ACC_BRAMC, size *4))
      return FAILURE;

   if (use_accelerator) {
     int e = 0;
     putfslx( size, 0, FSL_DEFAULT);//send end address
     putfslx( 0, 0, FSL_DEFAULT); //send start address
     getfslx(e, 0, FSL_DEFAULT);
     if (e != 1) return FAILURE;
   } else {
      Huint vhwti_base = 0;
   
      // Get VHWTI from PVRs 
      getpvr(1,vhwti_base);
      hthread_time_t start = hthread_time_get();
      // Run crc in software
      result =  (sw_crc((void *) ACC_BRAMC, size));
      hthread_time_t stop = hthread_time_get();
      hthread_time_t diff;
      hthread_time_diff(diff, stop,start);
      volatile hthread_time_t * ptr = (hthread_time_t *) (vhwti_base + 0x100);
      *ptr += diff;

   }

   // Start transferring data from BRAM
   if(transfer_dma( (void *) ACC_BRAMC, (void *) list_ptr, size *4))
      return FAILURE;

   return result;
}