Optimization doubts with USB driver

Report here problems in any of ChibiOS components. This forum is NOT for support.
Ceco
Posts: 40
Joined: Tue Nov 27, 2012 12:16 pm
Been thanked: 3 times

Re: Optimization doubts with USB driver

Post by Ceco »

Hello Giovanni, and Happy New Year!

Currently I'm using the following code for the FIFO reading at it works well for my needs. As I mentioned before - it is optimized for huge data blocks transfers like MSD implementation and probably is not the best in other particular cases.

Code: Select all

static inline void otg_fifo_read_to_buffer(volatile uint32_t *fifop,
                                    uint8_t *buf,
                                    size_t n,
                                    size_t max) {
   uint32_t w;
   size_t cnt = n;

   while(cnt)
   {
      w = *fifop;
      if(cnt <= 4)
      {
         /* Slower but it happens just once! */
         while(cnt)
         {
            *buf++ = (uint8_t)w;
            w >>= 8;
            cnt--;
         }
         if(n > max)
         {
            /* When this happens??? */
            n -= max;
            while(n)
            {
               w = *fifop;
               if(n <= 4)
                  break;
               else
                  n -= 4;
            }
         }
      }
      else
      {
         *((uint32_t *)buf) = w;
         cnt -= 4;
         buf += 4;
      }
   }
}
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization doubts with USB driver

Post by Giovanni »

Bump. I need to review that code.

Probably M3/m4 unaligned writes could be used to speed-up the data copy operations.

Giovanni
Post Reply