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

Postby Ceco » Wed Jan 02, 2019 11:19 am

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Optimization doubts with USB driver

Postby Giovanni » Sun Nov 10, 2019 10:27 am

Bump. I need to review that code.

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

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 16 guests