Page 1 of 1

asynchronous usb communication

Posted: Tue Sep 23, 2014 1:16 pm
by Pask
hi, i am using usb shell implementation to get some string from board over usb. i would using asynchronous transfer from board to pc over usb because i do not want an excessive communication overhead. How can i do it?

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 1:26 pm
by Giovanni
The SERIAL_USB driver used by the shell demo includes asynchronous read and write functions as well synchronous ones. Its interface is exactly the same of a normal serial driver.

Giovanni

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 1:29 pm
by Pask
what is demo shell project so i can see. Thanks

I'm seeing that to write is performed on a usb chprintf().
how can I distinguish from synchronous to asynchronous?

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 1:40 pm
by Giovanni
Pask wrote:i am using usb shell implementation to get some string from board over usb


This is the shell demo.

Pask wrote:how can I distinguish from synchronous to asynchronous?


I/O functions with TIME_IMMEDIATE as timeout parameter are asynchronous.

Giovanni

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 1:45 pm
by Pask
where is timeout parameter? can you give me an example pls?

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 1:58 pm
by Giovanni

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 2:20 pm
by Pask
but if I set time_immediate the operation stops immediately so the data when they are sent?

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 2:46 pm
by Giovanni
The data is sent asynchronously like you asked.

BTW, there is no performance to be gained.

Giovanni

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 2:57 pm
by Pask
ok, but if i want to replace a shell command function with an asynchronous version of it how i can?
for example i have the following code:

Code: Select all


static const ShellCommand commands[] = {
  {"mem", cmd_mem},
  {"threads", cmd_threads},
  {"test", cmd_test},
  {"write", cmd_write},
  {NULL, NULL}
};

static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
  size_t n, size;

  (void)argv;
  if (argc > 0) {
    chprintf(chp, "Usage: mem\r\n");
    return;
  }
  n = chHeapStatus(NULL, &size);
  chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
  chprintf(chp, "heap fragments   : %u\r\n", n);
  chprintf(chp, "heap free total  : %u bytes\r\n", size);
}



can i replace BaseSequentialStream with BaseChannel type as required from chnWriteTimeout?
So i replace chprintf with chnWriteTimeout and that's it?

Re: asynchronous usb communication

Posted: Tue Sep 23, 2014 3:21 pm
by Giovanni
I don't understand what you are trying to do, probably we give a different meaning to the term.

Giovanni