From 9e1f4ed7015ac8543169fe41b74f1939a8b86f3b Mon Sep 17 00:00:00 2001 From: Anton Staaf Date: Tue, 2 Dec 2014 10:42:22 -0800 Subject: USB-SPI: Switch from task to deferred function The task based approach made sense when it looked like there would be a case closed debugging task to handle multiple bridges (SPI/I2C/USART...). I'm not convinced anymore that that task will be needed, so this simplification seems good. Signed-off-by: Anton Staaf BRANCH=None BUG=None TEST=make buildall -j Change-Id: Ic431c287c28d10252246fe9f507d9c5fcc64a077 Reviewed-on: https://chromium-review.googlesource.com/232733 Tested-by: Anton Staaf Reviewed-by: Vincent Palatin Commit-Queue: Anton Staaf --- chip/stm32/usb_spi.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'chip/stm32/usb_spi.h') diff --git a/chip/stm32/usb_spi.h b/chip/stm32/usb_spi.h index 4917c16f0b..5da35c91f6 100644 --- a/chip/stm32/usb_spi.h +++ b/chip/stm32/usb_spi.h @@ -8,6 +8,7 @@ /* STM32 USB SPI driver for Chrome EC */ #include "compile_time_macros.h" +#include "hooks.h" #include "usb.h" /* @@ -94,19 +95,17 @@ struct usb_spi_config { int interface; int endpoint; + /* + * Deferred function to call to handle SPI request. + */ + void (*deferred)(void); + /* * Pointers to USB packet RAM and bounce buffer. */ uint16_t *buffer; usb_uint *rx_ram; usb_uint *tx_ram; - - /* - * Callback to notify managing task that a new SPI request has been - * received. This should wake up a task that will eventually call - * the usb_spi_service_request function. - */ - void (*ready)(struct usb_spi_config const *config); }; /* @@ -120,16 +119,14 @@ struct usb_spi_config { * * ENDPOINT is the index of the USB bulk endpoint used for receiving and * transmitting bytes. - * - * READY callback function for command reception notification. */ #define USB_SPI_CONFIG(NAME, \ INTERFACE, \ - ENDPOINT, \ - READY) \ + ENDPOINT) \ static uint16_t CONCAT2(NAME, _buffer_)[USB_MAX_PACKET_SIZE / 2]; \ static usb_uint CONCAT2(NAME, _ep_rx_buffer_)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \ static usb_uint CONCAT2(NAME, _ep_tx_buffer_)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \ + static void CONCAT2(NAME, _deferred_)(void); \ struct usb_spi_state CONCAT2(NAME, _state_) = { \ .disabled = 1, \ .enabled = 0, \ @@ -138,10 +135,10 @@ struct usb_spi_config { .state = &CONCAT2(NAME, _state_), \ .interface = INTERFACE, \ .endpoint = ENDPOINT, \ + .deferred = CONCAT2(NAME, _deferred_), \ .buffer = CONCAT2(NAME, _buffer_), \ .rx_ram = CONCAT2(NAME, _ep_rx_buffer_), \ .tx_ram = CONCAT2(NAME, _ep_tx_buffer_), \ - .ready = READY, \ }; \ const struct usb_interface_descriptor \ USB_IFACE_DESC(INTERFACE) = { \ @@ -184,17 +181,15 @@ struct usb_spi_config { usb_uint *tx_buf) \ { return usb_spi_interface(&NAME, rx_buf, tx_buf); } \ USB_DECLARE_IFACE(INTERFACE, \ - CONCAT2(NAME, _interface_)); + CONCAT2(NAME, _interface_)); \ + static void CONCAT2(NAME, _deferred_)(void) \ + { usb_spi_deferred(&NAME); } \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); /* - * Check for a new request and process it synchronously, the SPI transaction - * will complete before this function returns. - * - * Returns: - * 1: request serviced - * 0: no request waiting + * Handle SPI request in a deferred callback. */ -int usb_spi_service_request(struct usb_spi_config const *config); +void usb_spi_deferred(struct usb_spi_config const *config); /* * Set the enable state for the USB-SPI bridge. -- cgit v1.2.1