[tuxdroid-svn] r1164 - firmware/fuxusb/trunk/src
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-16 08:48:46
|
Author: Paul_R Date: 2008-05-16 10:48:51 +0200 (Fri, 16 May 2008) New Revision: 1164 Modified: firmware/fuxusb/trunk/src/usb_commands.c firmware/fuxusb/trunk/src/usb_misc.c firmware/fuxusb/trunk/src/usb_task.c Log: * Added comments in usb_misc.c * Typo on usb_task.c * Reorganized functions in usb_commands.c Modified: firmware/fuxusb/trunk/src/usb_commands.c =================================================================== --- firmware/fuxusb/trunk/src/usb_commands.c 2008-05-16 08:12:21 UTC (rev 1163) +++ firmware/fuxusb/trunk/src/usb_commands.c 2008-05-16 08:48:51 UTC (rev 1164) @@ -81,7 +81,73 @@ } } +/** + *\brief Fill the USB EP Fifo with statuses. + * This function prepare the USB EP Fifo with the lasts statuses received. + */ +void prepare_status(void) +{ + uint8_t data i; + + + if((status_requested) && (CMD_IN_Bank_Nb < 2)) + { + Usb_select_ep(EP_CMD_IN); + + /* Write header */ + Usb_write_byte(0); + Usb_write_byte(RF_OFFLINE ? 0 : 1); + Usb_write_byte(RF_Status); + Usb_write_byte(FifoIn_STT_Idx ? (FifoIn_STT_Idx / 4) : 0); + + /* Write statuses */ + for(i=0;i<FifoIn_STT_Idx;i++) + { + Usb_write_byte(FIFO_STT_get()); + } + /* And finish with 0 to completly fill the EP fifo */ + for(i=FifoIn_STT_Idx;i<60;i++) + { + Usb_write_byte(0); + } + + /* Clear the status fifo */ + FIFO_STT_flush(); + /* Increase the bank number */ + CMD_IN_Bank_Nb ++; + /* Put the statuses on the USB bus */ + send_status(); + /* Clear flags */ + RF_Status = 0; + status_requested = False; + } +} + /* + * Acknowledge or not a bootloader command. + * \param ack Send an ACK if ack is set, NACK otherwise + * \param p1, p2, p3: optional paramaters + */ +void bl_acknowledge(uint8_t ack, uint8_t p1, uint8_t p2, uint8_t p3) +{ + Usb_select_ep(EP_CMD_IN); + +#ifdef BL_EP_DEBUG + printf("SEND ACK \n"); +#endif + + Usb_write_byte(BOOTLOADER_CMD); + Usb_write_byte(ack ? B_ACK : B_NACK); + Usb_write_byte(p1); + Usb_write_byte(p2); + Usb_write_byte(p3); + + CMD_IN_Bank_Nb ++; + + send_status(); +} + +/* * \brief Parse commands for dongle. */ static void dongle_cmd_parser(void) @@ -96,15 +162,12 @@ case STATUS_REQUEST: status_requested = True; break; - case RF_RESET: reset_rf(); break; - case USB_RESET: reset_dongle(); break; - case ISP_MODE: jump_bootloader(); break; @@ -151,72 +214,6 @@ } /** - *\brief Fill the USB EP Fifo with statuses. - * This function prepare the USB EP Fifo with the lasts statuses received. - */ -void prepare_status(void) -{ - uint8_t data i; - - - if((status_requested) && (CMD_IN_Bank_Nb < 2)) - { - Usb_select_ep(EP_CMD_IN); - - /* Write header */ - Usb_write_byte(0); - Usb_write_byte(RF_OFFLINE ? 0 : 1); - Usb_write_byte(RF_Status); - Usb_write_byte(FifoIn_STT_Idx ? (FifoIn_STT_Idx / 4) : 0); - - /* Write statuses */ - for(i=0;i<FifoIn_STT_Idx;i++) - { - Usb_write_byte(FIFO_STT_get()); - } - /* And finish with 0 to completly fill the EP fifo */ - for(i=FifoIn_STT_Idx;i<60;i++) - { - Usb_write_byte(0); - } - - /* Clear the status fifo */ - FIFO_STT_flush(); - /* Increase the bank number */ - CMD_IN_Bank_Nb ++; - /* Put the statuses on the USB bus */ - send_status(); - /* Clear flags */ - RF_Status = 0; - status_requested = False; - } -} - -/* - * Acknowledge or not a bootloader command. - * \param ack Send an ACK if ack is set, NACK otherwise - * \param p1, p2, p3: optional paramaters - */ -#define B_ACK 0 -#define B_NACK 1 -void bl_acknowledge(uint8_t ack, uint8_t p1, uint8_t p2, uint8_t p3) -{ - Usb_select_ep(EP_CMD_IN); -#ifdef BL_EP_DEBUG - printf("SEND ACK \n"); -#endif - Usb_write_byte(BOOTLOADER_CMD); - Usb_write_byte(ack ? B_ACK : B_NACK); - Usb_write_byte(p1); - Usb_write_byte(p2); - Usb_write_byte(p3); - - CMD_IN_Bank_Nb ++; - - send_status(); -} - -/** *\brief Perform a complete reset. */ static void reset_dongle(void) Modified: firmware/fuxusb/trunk/src/usb_misc.c =================================================================== --- firmware/fuxusb/trunk/src/usb_misc.c 2008-05-16 08:12:21 UTC (rev 1163) +++ firmware/fuxusb/trunk/src/usb_misc.c 2008-05-16 08:48:51 UTC (rev 1164) @@ -27,7 +27,10 @@ #include "rf.h" #include "lib_mcu\usb\usb_drv.h" - +/** + * \brief Suspend the USB bus. + * This function suspend the bus and keep the rf board on reset state. + */ void suspend_usb(void) { Usb_clear_suspend(); @@ -35,6 +38,10 @@ rf_reset_signal = 0; } +/** + * \brief Resume the USB bus. + * This function resume the bus afetr a suspend state. + */ void resume_usb(void) { Usb_clear_suspend_clock(); @@ -43,6 +50,10 @@ Usb_clear_sof(); } +/** + * \brief Reset the bus. + * This function reset the usb bus. + */ void reset_usb(void) { Usb_clear_reset(); @@ -50,11 +61,15 @@ FIFO_STT_init(); } +/** + * \brief reattach USB. + * This function simulate a disconnexion/connexion of the USB device. + * This is used when the device has to be re-enumerated (ISP mode for example). + */ void reattach_usb(void) { long tc; - /* Detach and attach usb */ tc=10000; Usb_detach(); while(tc) tc --; Modified: firmware/fuxusb/trunk/src/usb_task.c =================================================================== --- firmware/fuxusb/trunk/src/usb_task.c 2008-05-16 08:12:21 UTC (rev 1163) +++ firmware/fuxusb/trunk/src/usb_task.c 2008-05-16 08:48:51 UTC (rev 1164) @@ -31,7 +31,6 @@ void usb_task_init(void) { - uint16_t timer=10000; configure_usb_clock(); Usb_enable(); @@ -59,11 +58,15 @@ else if (Usb_suspend()) suspend_usb(); + /* + * When the SOF is detected, manage the LEDs. + */ if (Usb_sof()) { Usb_clear_sof(); led_behavior(); + /* This counter is used to temporise the i2c task. */ if (i2c_wait_counter) i2c_wait_counter--; } @@ -71,6 +74,7 @@ * Load the microphone EP if it's not already loaded and if the micro * fifo is ready. */ + fill_mic_ep(); /* * Prepare the statuses when a request has been received |