Advertisement
Guest User

Untitled

a guest
Jul 16th, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1. diff --git a/apps/plugin.c b/apps/plugin.c
  2. index b47dd95..dd470d5 100644
  3. --- a/apps/plugin.c
  4. +++ b/apps/plugin.c
  5. @@ -790,6 +790,8 @@ static const struct plugin_api rockbox_api = {
  6.      system_sound_play,
  7.      keyclick_click,
  8.  #endif
  9. +    usb_serial_send,
  10. +    usb_serial_recv,
  11.  };
  12.  
  13.  int plugin_load(const char* plugin, const void* parameter)
  14. diff --git a/apps/plugin.h b/apps/plugin.h
  15. index e9c0c64..de2d011 100644
  16. --- a/apps/plugin.h
  17. +++ b/apps/plugin.h
  18. @@ -924,6 +924,8 @@ struct plugin_api {
  19.      void (*system_sound_play)(enum system_sound sound);
  20.      void (*keyclick_click)(int button);
  21.  #endif
  22. +    void (*usb_serial_send)(const unsigned char *buf, int length);
  23. +    int (*usb_serial_recv)(unsigned char *buf, int length);
  24.  };
  25.  
  26.  /* plugin header */
  27. diff --git a/firmware/usbstack/usb_serial.c b/firmware/usbstack/usb_serial.c
  28. index e715909..be52e81 100644
  29. --- a/firmware/usbstack/usb_serial.c
  30. +++ b/firmware/usbstack/usb_serial.c
  31. @@ -73,6 +73,10 @@ static bool active = false;
  32.  static int ep_in, ep_out;
  33.  static int usb_interface;
  34.  
  35. +struct semaphore recv_sema;
  36. +struct mutex recv_mutex;
  37. +int recv_len;
  38. +
  39.  int usb_serial_request_endpoints(struct usb_class_driver *drv)
  40.  {
  41.      ep_in = usb_core_request_endpoint(USB_ENDPOINT_XFER_BULK, USB_DIR_IN, drv);
  42. @@ -128,8 +132,8 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
  43.  
  44.  void usb_serial_init_connection(void)
  45.  {
  46. -    /* prime rx endpoint */
  47. -    usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer);
  48. +    semaphore_init(&recv_sema, 1, 0);
  49. +    mutex_init(&recv_mutex);
  50.  
  51.      /* we come here too after a bus reset, so reset some data */
  52.      buffer_transitlength = 0;
  53. @@ -218,11 +222,8 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length)
  54.  
  55.      switch (dir) {
  56.          case USB_DIR_OUT:
  57. -            logf("serial: %s", receive_buffer);
  58. -            /* Data received. TODO : Do something with it ? */
  59. -
  60. -            /* Get the next bit */
  61. -            usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer);
  62. +            recv_len = status == 0 ? -1 : length;
  63. +            semaphore_release(&recv_sema);
  64.              break;
  65.  
  66.          case USB_DIR_IN:
  67. @@ -240,3 +241,13 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length)
  68.              break;
  69.      }
  70.  }
  71. +
  72. +void usb_serial_recv(unsigned char *data, int length)
  73. +{
  74. +    mutex_lock(&recv_mutex);
  75. +    usb_drv_recv(ep_out, data, length);
  76. +    semaphore_wait(&recv_sema);
  77. +    int len = recv_len;
  78. +    mutex_unlock(&recv_mutex);
  79. +    return len;
  80. +}
  81. diff --git a/firmware/usbstack/usb_serial.h b/firmware/usbstack/usb_serial.h
  82. index f1a603c..f664481 100644
  83. --- a/firmware/usbstack/usb_serial.h
  84. +++ b/firmware/usbstack/usb_serial.h
  85. @@ -33,6 +33,7 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length);
  86.  bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char *dest);
  87.  
  88.  void usb_serial_send(const unsigned char *data, int length);
  89. +int usb_serial_recv(unsigned char *data, int length); /* return length or -1 */
  90.  
  91.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement