diff options
| author | Diego Ismirlian <dismirlian (at) google's mail.com> | 2017-07-16 18:38:59 -0300 | 
|---|---|---|
| committer | Diego Ismirlian <dismirlian (at) google's mail.com> | 2017-07-16 18:38:59 -0300 | 
| commit | 7bf4908f231061ab909c086722ead46dd7df87f9 (patch) | |
| tree | 644fbdb77837ce44e59dea994de53a292de086fb | |
| parent | d395dde065b77506a0883918af4bd48005e5df7c (diff) | |
| download | ChibiOS-Contrib-7bf4908f231061ab909c086722ead46dd7df87f9.tar.gz ChibiOS-Contrib-7bf4908f231061ab909c086722ead46dd7df87f9.tar.bz2 ChibiOS-Contrib-7bf4908f231061ab909c086722ead46dd7df87f9.zip | |
USBH: HID: Implement synchronization
| -rw-r--r-- | os/hal/include/usbh/dev/hid.h | 2 | ||||
| -rw-r--r-- | os/hal/src/usbh/TODO.txt | 7 | ||||
| -rw-r--r-- | os/hal/src/usbh/hal_usbh_hid.c | 39 | 
3 files changed, 34 insertions, 14 deletions
| diff --git a/os/hal/include/usbh/dev/hid.h b/os/hal/include/usbh/dev/hid.h index 1dbc486..c7371ee 100644 --- a/os/hal/include/usbh/dev/hid.h +++ b/os/hal/include/usbh/dev/hid.h @@ -95,6 +95,8 @@ struct USBHHIDDriver {  	usbh_urb_t in_urb;  	const USBHHIDConfig *config; + +	semaphore_t sem;  }; diff --git a/os/hal/src/usbh/TODO.txt b/os/hal/src/usbh/TODO.txt index 4d9d1bb..c3dd4a8 100644 --- a/os/hal/src/usbh/TODO.txt +++ b/os/hal/src/usbh/TODO.txt @@ -2,6 +2,13 @@ In decreasing order of priority:  Bugs:  - Synchronization on driver unload between usbhMainLoop and driver APIs +    - MSD: ok +    - AOA: not done +    - HUB: ok +    - FTDI: not done +    - HID: ok +    - UVC: not done +  Enhancements:  - Way to return error from the load() functions in order to stop the enumeration process diff --git a/os/hal/src/usbh/hal_usbh_hid.c b/os/hal/src/usbh/hal_usbh_hid.c index 6d0e116..575b0a6 100644 --- a/os/hal/src/usbh/hal_usbh_hid.c +++ b/os/hal/src/usbh/hal_usbh_hid.c @@ -69,7 +69,7 @@  #define USBH_HID_REQ_SET_PROTOCOL	0x0B  /*===========================================================================*/ -/* USB Class driver loader for MSD								 		 	 */ +/* USB Class driver loader for HID								 		 	 */  /*===========================================================================*/  USBHHIDDriver USBHHIDD[HAL_USBHHID_MAX_INSTANCES]; @@ -77,6 +77,7 @@ USBHHIDDriver USBHHIDD[HAL_USBHHID_MAX_INSTANCES];  static void _hid_init(void);  static usbh_baseclassdriver_t *_hid_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem);  static void _hid_unload(usbh_baseclassdriver_t *drv); +static void _stop_locked(USBHHIDDriver *hidp);  static const usbh_classdriver_vmt_t class_driver_vmt = {  	_hid_init, @@ -184,7 +185,10 @@ deinit:  static void _hid_unload(usbh_baseclassdriver_t *drv) {  	USBHHIDDriver *const hidp = (USBHHIDDriver *)drv; -	(void)hidp; +	chSemWait(&hidp->sem); +	_stop_locked(hidp); +	hidp->state = USBHHID_STATE_STOP; +	chSemSignal(&hidp->sem);  }  static void _in_cb(usbh_urb_t *urb) { @@ -213,11 +217,13 @@ static void _in_cb(usbh_urb_t *urb) {  void usbhhidStart(USBHHIDDriver *hidp, const USBHHIDConfig *cfg) {  	osalDbgCheck(hidp && cfg);  	osalDbgCheck(cfg->report_buffer && (cfg->protocol <= USBHHID_PROTOCOL_REPORT)); -	osalDbgCheck((hidp->state == USBHHID_STATE_ACTIVE) -			|| (hidp->state == USBHHID_STATE_READY)); -	if (hidp->state == USBHHID_STATE_READY) +	chSemWait(&hidp->sem); +	if (hidp->state == USBHHID_STATE_READY) { +		chSemSignal(&hidp->sem);  		return; +	} +	osalDbgCheck(hidp->state == USBHHID_STATE_ACTIVE);  	hidp->config = cfg; @@ -243,24 +249,28 @@ void usbhhidStart(USBHHIDDriver *hidp, const USBHHIDConfig *cfg) {  	osalSysUnlock();  	hidp->state = USBHHID_STATE_READY; +	chSemSignal(&hidp->sem);  } -void usbhhidStop(USBHHIDDriver *hidp) { -	osalDbgCheck((hidp->state == USBHHID_STATE_ACTIVE) -			|| (hidp->state == USBHHID_STATE_READY)); - -	if (hidp->state != USBHHID_STATE_READY) +static void _stop_locked(USBHHIDDriver *hidp) { +	if (hidp->state == USBHHID_STATE_ACTIVE)  		return; -	osalSysLock(); -	usbhEPCloseS(&hidp->epin); +	osalDbgCheck(hidp->state == USBHHID_STATE_READY); + +	usbhEPClose(&hidp->epin);  #if HAL_USBHHID_USE_INTERRUPT_OUT  	if (hidp->epout.status != USBH_EPSTATUS_UNINITIALIZED) { -		usbhEPCloseS(&hidp->epout); +		usbhEPClose(&hidp->epout);  	}  #endif  	hidp->state = USBHHID_STATE_ACTIVE; -	osalSysUnlock(); +} + +void usbhhidStop(USBHHIDDriver *hidp) { +	chSemWait(&hidp->sem); +	_stop_locked(hidp); +	chSemSignal(&hidp->sem);  }  usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp, @@ -317,6 +327,7 @@ static void _hid_object_init(USBHHIDDriver *hidp) {  	memset(hidp, 0, sizeof(*hidp));  	hidp->info = &usbhhidClassDriverInfo;  	hidp->state = USBHHID_STATE_STOP; +	chSemObjectInit(&hidp->sem, 1);  }  static void _hid_init(void) { | 
