[tuxdroid-svn] r1106 - in firmware/fuxusb/branches/usb_cleanup: . bootloader usb
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-06 06:44:58
|
Author: Paul_R Date: 2008-05-06 08:44:57 +0200 (Tue, 06 May 2008) New Revision: 1106 Added: firmware/fuxusb/branches/usb_cleanup/rf.c firmware/fuxusb/branches/usb_cleanup/rf.h Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Moved the bootloader functions into bootloading module * Created a module rf Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-05 20:04:46 UTC (rev 1105) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 06:44:57 UTC (rev 1106) @@ -5,9 +5,13 @@ * -------------------------------------------------------- * $Id$ */ - +#include "usb/usb_task.h" +#include "usb/usb_drv.h" +#include "modules/fifo_stt/fifo_stt.h" #include "bootloading.h" #include "config.h" +#include "global.h" +#include "rf.h" uint8_t Command_FromUSB_bootload_cmd; uint8_t cpu_address; @@ -16,6 +20,7 @@ uint8_t packets_per_page; uint8_t address_idx; uint8_t packet_idx; +uint16_t address_tracking; blHeader_t blHeader; /* header for bootloading */ @@ -59,3 +64,222 @@ #endif i2cMasterStart(); } + + +void usb_Bootloader_command_process_task(void) +{ + data Uchar i; + if((USB_Bootloader_NewCmd_Flag) && (CMD_IN_Bank_Nb < 2)) + { + Usb_select_ep(EP_CMD_IN); + +#ifdef BOOTLOAD_USB_DEBUG + printf ("BUSB: TX ready, UEPSTAX=0x%BX\n", UEPSTAX); +#endif + for(i=0;i<FifoIn_STT_Idx;i++) + { + Usb_write_byte(FIFO_STT_get()); + } + FIFO_STT_flush(); + CMD_IN_Bank_Nb ++; // Increase the bank number + USB_Bootloader_NewCmd_Flag = FALSE; + data_to_send(); + } +} + + + +void bootloader_exit(void) +{ + /* Restore normal mode and reset the RF. */ + i2c_bootloading_Flag = 0; + rf_reset(); +} + +/* + * 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 usb_Bootloader_acknowledge(uint8_t ack, uint8_t p1, uint8_t p2, uint8_t p3) +{ +#ifdef BOOTLOAD_DEBUG + printf ("BOOT: %s\n", ack ? "ACK" : "NACK"); +#endif + FIFO_STT_flush(); + FIFO_STT_put(BOOTLOADER_CMD); + if (ack) + FIFO_STT_put(B_ACK); + else + FIFO_STT_put(B_NACK); + FIFO_STT_put(p1); + FIFO_STT_put(p2); + FIFO_STT_put(p3); + USB_Bootloader_NewCmd_Flag = TRUE; + usb_Bootloader_command_process_task(); +} + + +void bootloader_task(void) +{ + uint8_t i; + /* Request processed */ + USBCommand_NewRequest_Flag = 0; + /* Disables the spi task and enables I2C + * bootloading */ + spi_task_on_Flag = 0; + /* First byte after the header is the + * bootloading command */ + Command_FromUSB_bootload_cmd = Usb_read_byte(); + + /* Initialize bootloading */ + if (Command_FromUSB_bootload_cmd == BOOT_INIT) + { +#ifdef BOOTLOAD_DEBUG + printf ("BOOT: BOOT_INIT "); +#endif + /* Clear pending IN data */ + /* XXX the following reset doesn't work + * correctly, we couldn't fix it yet. It + * ensures that nothing is in the IN EP + * when starting bootloading. */ + //Usb_select_ep(EP_CMD_IN); + //Usb_clear_tx_ready(); + //Usb_clear_tx_complete(); + //CMD_IN_Bank_Nb = 0; + //usb_reset_endpoint(EP_CMD_IN); + //Usb_select_ep(EP_CMD_OUT); + /* Wait 250ms before first I2C + * communication for the RF to boot */ + i2c_wait_counter = 250; + /* Initialize the bootloader */ + bl_init(); + rf_start_bootloader(); + i2c_bootloading_Flag = 1; + + /* Get SLA (LSB=0 for write mode) */ + blHeader.slave_address = \ + (Usb_read_byte() << 1); + page_size = Usb_read_byte(); + packets_per_page = Usb_read_byte(); +#ifdef BOOTLOAD_DEBUG + printf ("SLA: %BX, page size: %BX, "\ + "packets per page: %BX\n", \ + blHeader.slave_address, page_size, \ + packets_per_page); +#endif + address_tracking = 0; + address_idx = 0; + packet_idx = 0; + } + + /* INIT not done, report error */ + else if (!i2c_bootloading_Flag) + usb_Bootloader_acknowledge(FALSE, 1, 0, 0); + + /* Exit bootloading */ + else if (Command_FromUSB_bootload_cmd == + BOOT_EXIT) + { +#ifdef BOOTLOAD_DEBUG + printf ("BOOT: BOOT_EXIT\n"); +#endif + bootloader_exit(); + usb_Bootloader_acknowledge(TRUE, 2, 0, 0); + } + + /* Get bootload data */ + else if (Command_FromUSB_bootload_cmd == + BOOT_FILLPAGE) + { +#ifdef BOOTLOAD_DEBUG + printf ("BOOT: BOOT_FILLPAGE %BX", \ + packet_idx); +#endif + /* Get the address on the first packet */ + if (packet_idx == 0) + { + blHeader.page_address = \ + Usb_read_byte() << 8; + blHeader.page_address += \ + Usb_read_byte(); + /* Check if address is correct and we + * got the right number of data. + * 0x1DC0 and 0x0EC0 are the last + * segments of the flash where the + * version number is, so it's possible + * to have a gap between the end of + * code and these addresses. EEPROM + * addresses start at 0x8000 so remove + * that bit too. */ + /* Workaround for the old tuxup that + * sent BOOT_FILLPAGE instead of + * BOOT_EXIT at the end of bootloading. + */ + if (USBCommand_Ctr == 5) + bootloader_exit(); + else if (((blHeader.page_address & ~0x8000) \ + != address_tracking && + blHeader.page_address != 0x1DC0 && + blHeader.page_address != 0x0EC0) || + USBCommand_Ctr != 36) + { + usb_Bootloader_acknowledge(FALSE, + 3, 0, 0); + bootloader_exit(); + } + +#ifdef BOOTLOAD_DEBUG + printf (" page_address: 0x%X", \ + blHeader.page_address); +#endif + for(i=0; i<(USBCommand_Ctr - 4); i++) + blHeader.blData[address_idx++] = \ + Usb_read_byte(); + } + /* Other packets hold data only */ + else + { + /* Check if we got the right number of + * data */ + if (USBCommand_Ctr != 34) + { + /* Exit bootloader mode */ + usb_Bootloader_acknowledge(FALSE, + 4, 0, 0); + bootloader_exit(); + } + + for(i=0; i<(USBCommand_Ctr - 2); i++) + blHeader.blData[address_idx++] = \ + Usb_read_byte(); + } +#ifdef BOOTLOAD_DEBUG + printf ("\n"); +#endif + packet_idx++; + } + /* All data received */ + if ((packet_idx == packets_per_page) && \ + (address_idx == page_size)) + { + address_tracking += page_size; + address_idx = 0; + packet_idx = 0; + /* Execute I2C bootloading */ + i2c_task_on_Flag = 1; + } + else if (packet_idx >= packets_per_page) + { +#ifdef BOOTLOAD_DEBUG + printf ("\nBOOT: ERROR too much data\n"); +#endif + /* Exit bootloader mode */ + usb_Bootloader_acknowledge(FALSE, 5, 0, 0); + bootloader_exit(); + } + /* Request processed */ + USBCommand_NewRequest_Flag = 0; +} Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h 2008-05-05 20:04:46 UTC (rev 1105) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h 2008-05-06 06:44:57 UTC (rev 1106) @@ -2,7 +2,7 @@ * Copyright (c) 2006, C2ME S.A. * All rights reserved. * - * $Id:$ + * $Id$ */ #ifndef _BOOTLOADING_H_ @@ -41,8 +41,9 @@ */ void bl_init(void); - +void bootloader_task(void); void bl_senddata(blHeader_t blHeader, uint8_t dataLength); +void usb_Bootloader_command_process_task(void); extern uint8_t Command_FromUSB_bootload_cmd; extern uint8_t cpu_address; Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 =================================================================== --- firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-05 20:04:46 UTC (rev 1105) +++ firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 06:44:57 UTC (rev 1106) @@ -13,6 +13,7 @@ File 1,1,<.\main.c><main.c> 0x0 File 1,1,<.\global.c><global.c> 0x0 +File 1,1,<.\rf.c><rf.c> 0x0 File 2,1,<.\usb\usb_task.c><usb_task.c> 0x0 File 2,1,<.\usb\usb_enum.c><usb_enum.c> 0x0 File 2,1,<.\usb\usb_drv.c><usb_drv.c> 0x0 @@ -53,7 +54,7 @@ EnvLib () EnvReg () OrgReg () - TgStat=0 + TgStat=11 OutDir (.\obj\) OutName (fuxusb.aof) GenApp=1 Added: firmware/fuxusb/branches/usb_cleanup/rf.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/rf.c (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/rf.c 2008-05-06 06:44:57 UTC (rev 1106) @@ -0,0 +1,31 @@ +#include "config.h" +#include "global.h" +#include "spi/spi_lib.h" +#include "rf.h" + +/** + * Restart the RF in bootloader mode + */ +void rf_start_bootloader(void) +{ + uint16_t i; + /* Reset the RF module to set it in bootloader mode, SPI_CS has to be low + * at reset to enter bootloading in the RF module. */ + SPI_CSn = 0; + rf_reset_signal = 0; + for (i=0; i<32000; i++); + rf_reset_signal = 1; +} + +/** + * Reset the RF in normal mode + */ +void rf_reset(void) +{ + uint16_t i; + /* Don't forget to set SPI_CSn otherwise bootlodar mode is entered. */ + SPI_CSn = 1; + rf_reset_signal = 0; + for (i=0; i<32000; i++); + rf_reset_signal = 1; +} Property changes on: firmware/fuxusb/branches/usb_cleanup/rf.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/rf.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/rf.h (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/rf.h 2008-05-06 06:44:57 UTC (rev 1106) @@ -0,0 +1,2 @@ +void rf_reset(void); +void rf_start_bootloader(void); Property changes on: firmware/fuxusb/branches/usb_cleanup/rf.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-05 20:04:46 UTC (rev 1105) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 06:44:57 UTC (rev 1106) @@ -12,7 +12,7 @@ #include "config.h" #include "global.h" - +#include "rf.h" #include "spi\spi_lib.h" #include "usb\usb_drv.h" #include "lib_mcu\fa-usb\flash_api.h" @@ -42,8 +42,8 @@ #endif bit EP_AUDIOIN_Loaded = 0; bit i2c_bootloading_Flag = 0; /* bootloader mode */ -uint16_t address_tracking; + bit ReadStatus_USBRequest_Flag = 0; bit Cpu_reset = 0; bit Speaker_TTS_Select_Flag = 0; @@ -112,32 +112,7 @@ USB_Bootloader_NewCmd_Flag = FALSE; } -/** - * Restart the RF in bootloader mode - */ -void rf_start_bootloader(void) -{ - uint16_t i; - /* Reset the RF module to set it in bootloader mode, SPI_CS has to be low - * at reset to enter bootloading in the RF module. */ - SPI_CSn = 0; - rf_reset_signal = 0; - for (i=0; i<32000; i++); - rf_reset_signal = 1; -} -/** - * Reset the RF in normal mode - */ -void rf_reset(void) -{ - uint16_t i; - /* Don't forget to set SPI_CSn otherwise bootlodar mode is entered. */ - SPI_CSn = 1; - rf_reset_signal = 0; - for (i=0; i<32000; i++); - rf_reset_signal = 1; -} /*F************************************************************************** * NAME: usb_command_parser @@ -202,26 +177,7 @@ } } -void usb_Bootloader_command_process_task(void) -{ - data Uchar i; - if((USB_Bootloader_NewCmd_Flag) && (CMD_IN_Bank_Nb < 2)) - { - Usb_select_ep(EP_CMD_IN); -#ifdef BOOTLOAD_USB_DEBUG - printf ("BUSB: TX ready, UEPSTAX=0x%BX\n", UEPSTAX); -#endif - for(i=0;i<FifoIn_STT_Idx;i++) - { - Usb_write_byte(FIFO_STT_get()); - } - FIFO_STT_flush(); - CMD_IN_Bank_Nb ++; // Increase the bank number - USB_Bootloader_NewCmd_Flag = FALSE; - data_to_send(); - } -} void data_to_send(void) { @@ -233,37 +189,7 @@ } } -/* - * 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 usb_Bootloader_acknowledge(uint8_t ack, uint8_t p1, uint8_t p2, uint8_t p3) -{ -#ifdef BOOTLOAD_DEBUG - printf ("BOOT: %s\n", ack ? "ACK" : "NACK"); -#endif - FIFO_STT_flush(); - FIFO_STT_put(BOOTLOADER_CMD); - if (ack) - FIFO_STT_put(B_ACK); - else - FIFO_STT_put(B_NACK); - FIFO_STT_put(p1); - FIFO_STT_put(p2); - FIFO_STT_put(p3); - USB_Bootloader_NewCmd_Flag = TRUE; - usb_Bootloader_command_process_task(); -} -void bootloader_exit(void) -{ - /* Restore normal mode and reset the RF. */ - i2c_bootloading_Flag = 0; - rf_reset(); -} /*F************************************************************************** * NAME: usb_command_parser @@ -775,164 +701,9 @@ else if(USBCommand_Header == LIBUSB_BOOTLOADER_CMD_HDR) { - /* Request processed */ - USBCommand_NewRequest_Flag = 0; - /* Disables the spi task and enables I2C - * bootloading */ - spi_task_on_Flag = 0; - /* First byte after the header is the - * bootloading command */ - Command_FromUSB_bootload_cmd = Usb_read_byte(); - - /* Initialize bootloading */ - if (Command_FromUSB_bootload_cmd == BOOT_INIT) - { -#ifdef BOOTLOAD_DEBUG - printf ("BOOT: BOOT_INIT "); -#endif - /* Clear pending IN data */ - /* XXX the following reset doesn't work - * correctly, we couldn't fix it yet. It - * ensures that nothing is in the IN EP - * when starting bootloading. */ - //Usb_select_ep(EP_CMD_IN); - //Usb_clear_tx_ready(); - //Usb_clear_tx_complete(); - //CMD_IN_Bank_Nb = 0; - //usb_reset_endpoint(EP_CMD_IN); - //Usb_select_ep(EP_CMD_OUT); - /* Wait 250ms before first I2C - * communication for the RF to boot */ - i2c_wait_counter = 250; - /* Initialize the bootloader */ - bl_init(); - rf_start_bootloader(); - i2c_bootloading_Flag = 1; - - /* Get SLA (LSB=0 for write mode) */ - blHeader.slave_address = \ - (Usb_read_byte() << 1); - page_size = Usb_read_byte(); - packets_per_page = Usb_read_byte(); -#ifdef BOOTLOAD_DEBUG - printf ("SLA: %BX, page size: %BX, "\ - "packets per page: %BX\n", \ - blHeader.slave_address, page_size, \ - packets_per_page); -#endif - address_tracking = 0; - address_idx = 0; - packet_idx = 0; - } - - /* INIT not done, report error */ - else if (!i2c_bootloading_Flag) - usb_Bootloader_acknowledge(FALSE, 1, 0, 0); - - /* Exit bootloading */ - else if (Command_FromUSB_bootload_cmd == - BOOT_EXIT) - { -#ifdef BOOTLOAD_DEBUG - printf ("BOOT: BOOT_EXIT\n"); -#endif - bootloader_exit(); - usb_Bootloader_acknowledge(TRUE, 2, 0, 0); - } - - /* Get bootload data */ - else if (Command_FromUSB_bootload_cmd == - BOOT_FILLPAGE) - { -#ifdef BOOTLOAD_DEBUG - printf ("BOOT: BOOT_FILLPAGE %BX", \ - packet_idx); -#endif - /* Get the address on the first packet */ - if (packet_idx == 0) - { - blHeader.page_address = \ - Usb_read_byte() << 8; - blHeader.page_address += \ - Usb_read_byte(); - /* Check if address is correct and we - * got the right number of data. - * 0x1DC0 and 0x0EC0 are the last - * segments of the flash where the - * version number is, so it's possible - * to have a gap between the end of - * code and these addresses. EEPROM - * addresses start at 0x8000 so remove - * that bit too. */ - /* Workaround for the old tuxup that - * sent BOOT_FILLPAGE instead of - * BOOT_EXIT at the end of bootloading. - */ - if (USBCommand_Ctr == 5) - bootloader_exit(); - else if (((blHeader.page_address & ~0x8000) \ - != address_tracking && - blHeader.page_address != 0x1DC0 && - blHeader.page_address != 0x0EC0) || - USBCommand_Ctr != 36) - { - usb_Bootloader_acknowledge(FALSE, - 3, 0, 0); - bootloader_exit(); - } - -#ifdef BOOTLOAD_DEBUG - printf (" page_address: 0x%X", \ - blHeader.page_address); -#endif - for(i=0; i<(USBCommand_Ctr - 4); i++) - blHeader.blData[address_idx++] = \ - Usb_read_byte(); - } - /* Other packets hold data only */ - else - { - /* Check if we got the right number of - * data */ - if (USBCommand_Ctr != 34) - { - /* Exit bootloader mode */ - usb_Bootloader_acknowledge(FALSE, - 4, 0, 0); - bootloader_exit(); - } - - for(i=0; i<(USBCommand_Ctr - 2); i++) - blHeader.blData[address_idx++] = \ - Usb_read_byte(); - } -#ifdef BOOTLOAD_DEBUG - printf ("\n"); -#endif - packet_idx++; - } - /* All data received */ - if ((packet_idx == packets_per_page) && \ - (address_idx == page_size)) - { - address_tracking += page_size; - address_idx = 0; - packet_idx = 0; - /* Execute I2C bootloading */ - i2c_task_on_Flag = 1; - } - else if (packet_idx >= packets_per_page) - { -#ifdef BOOTLOAD_DEBUG - printf ("\nBOOT: ERROR too much data\n"); -#endif - /* Exit bootloader mode */ - usb_Bootloader_acknowledge(FALSE, 5, 0, 0); - bootloader_exit(); - } - /* Request processed */ - USBCommand_NewRequest_Flag = 0; + bootloader_task(); } + /* Clear the bank */ Usb_select_ep(EP_CMD_OUT); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-05 20:04:46 UTC (rev 1105) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 06:44:57 UTC (rev 1106) @@ -10,7 +10,7 @@ #ifndef _USB_TASK_H_ #define _USB_TASK_H_ - +#include "config.h" /*_____ I N C L U D E S ____________________________________________________*/ @@ -25,9 +25,12 @@ /*_____ D E C L A R A T I O N ______________________________________________*/ extern bit Cpu_reset; +extern bit i2c_bootloading_Flag; +void data_to_send(void); void usb_task_init (void); void usb_task (void); void usb_Satus_command_process_task(void); +void usb_Bootloader_acknowledge(uint8_t ack, uint8_t p1, uint8_t p2, uint8_t p3); #endif /* _USB_TASK_H_ */ |