tux-droid-svn Mailing List for Tux Droid CE (Page 193)
Status: Beta
Brought to you by:
ks156
You can subscribe to this list here.
2007 |
Jan
|
Feb
(32) |
Mar
(108) |
Apr
(71) |
May
(38) |
Jun
(128) |
Jul
(1) |
Aug
(14) |
Sep
(77) |
Oct
(104) |
Nov
(90) |
Dec
(71) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(81) |
Feb
(18) |
Mar
(40) |
Apr
(102) |
May
(151) |
Jun
(74) |
Jul
(151) |
Aug
(257) |
Sep
(447) |
Oct
(379) |
Nov
(404) |
Dec
(430) |
2009 |
Jan
(173) |
Feb
(236) |
Mar
(519) |
Apr
(300) |
May
(112) |
Jun
(232) |
Jul
(314) |
Aug
(58) |
Sep
(203) |
Oct
(293) |
Nov
(26) |
Dec
(109) |
2010 |
Jan
(19) |
Feb
(25) |
Mar
(33) |
Apr
(1) |
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Paul_R <c2m...@c2...> - 2008-05-30 14:04:33
|
Author: Paul_R Date: 2008-05-30 16:04:36 +0200 (Fri, 30 May 2008) New Revision: 1207 Modified: firmware/tuxup/trunk/bootloader.c firmware/tuxup/trunk/main.c Log: * Changed the way to control the bootloading process with a counter. The counter is incremented in fuxusb and tuxup to keep the synchro. With HID, the driver is non-blockant. When we read the statuses, the driver return the content of a buffer, and don't request a read on the bus. That's the reason why a synchro is needed. * Added a 'true' progress bar. Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2008-05-30 13:37:01 UTC (rev 1206) +++ firmware/tuxup/trunk/bootloader.c 2008-05-30 14:04:36 UTC (rev 1207) @@ -40,6 +40,9 @@ extern int verbose; bool HID; +static float line_nb; +static float step; +static float progress = 0; /* Debug commands */ //#define keybreak() {puts("Press return to read feedback"); getchar();} @@ -51,8 +54,8 @@ #define FALSE 0 #define USB_TIMEOUT 5 -#define BOOT_INIT_ACK 10 -#define BOOT_EXIT_ACK 2 +#define BOOT_INIT_ACK 255 +#define BOOT_EXIT_ACK 254 /* USB bootloader commands */ #define BOOT_INIT 1 @@ -60,6 +63,7 @@ #define BOOT_EXIT 3 static bool wait_status(uint8_t value, int timeout); +static void compute_progress_bar(float line_nb); typedef uint32_t FILE_Addr_t; typedef uint32_t FILE_SegmentLen_t; @@ -359,13 +363,13 @@ */ if (HID) { - ret = (wait_status(counter, USB_TIMEOUT)); + ret = (wait_status(++counter, USB_TIMEOUT)); tux_hid_read(5, data_buffer); - counter ++; } else { ret = usb_get_commands(parser->dev_handle, data_buffer, 5); + counter ++; } #if (PRINT_DATA) printf("Status of feedback from bootloader: %x\n", ret); @@ -374,14 +378,18 @@ { if ((ret) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) { - printf("."); + while ((counter >= progress)) + { + printf("#"); + progress += step; + } fflush (stdout); return TRUE; } else { fprintf(stderr, - "Bootloading failed, program aborted at dongle reply.\n"); + "\nBootloading failed, program aborted at dongle reply.\n"); exit(1); } } @@ -389,14 +397,18 @@ { if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) { - printf("."); + while ((counter >= progress)) + { + printf("#"); + progress += step; + } fflush (stdout); return TRUE; } else { fprintf(stderr, - "Bootloading failed, program aborted at dongle reply.\n"); + "\nBootloading failed, program aborted at dongle reply.\n"); exit(1); } } @@ -612,7 +624,6 @@ Parser_t parser; char line[100]; int rc = FALSE; - memset(&parser, 0, sizeof(parser)); /* clear all parser elements */ /* TODO get this value from either the file or the main program. @@ -634,7 +645,15 @@ goto cleanup; } + /* Nb of line */ + line_nb = 0; while (fgets(line, sizeof(line), fs) != NULL) + line_nb++; + + compute_progress_bar(line_nb); + fs = fopen(fileName, "rt"); + + while (fgets(line, sizeof(line), fs) != NULL) { parser.lineNum++; if (!parseIHexLine(&parser, line)) @@ -671,9 +690,14 @@ uint8_t packet_total = 2; /* XXX should depend on CPU type */ int ret; + /* Set global variable mem_type to the memory type */ mem_type = mem_t; + if (mem_type == EEPROM) + printf("EEPROM [\033[s\033[61C]\033[u\033[1B"); + else + printf("FLASH [\033[s\033[61C]\033[u\033[1B"); /* Bootloader initialization */ data_buffer[0] = LIBUSB_I2C_HEADER; data_buffer[1] = BOOT_INIT; @@ -682,9 +706,11 @@ data_buffer[4] = packet_total; counter = 0; - + progress = 0; + if (HID) { + sleep(0.5); ret = tux_hid_write(5, data_buffer); sleep(1); } @@ -697,7 +723,7 @@ { if (!wait_status(BOOT_INIT_ACK, USB_TIMEOUT) || !ret) { - fprintf(stderr, "Initialization failed\n"); + fprintf(stderr, "\nInitialization failed\n"); return FALSE; } } @@ -721,13 +747,15 @@ data_buffer[3] = 0; data_buffer[4] = 0; + progress = 0; + if (HID) - { + { tux_hid_write(5, data_buffer); tux_hid_read(5, data_buffer); if (!wait_status(BOOT_EXIT_ACK, USB_TIMEOUT)) { - fprintf(stderr, "Bootloader exit failed \n"); + fprintf(stderr, "\nBootloader exit failed \n"); return FALSE; } } @@ -762,3 +790,11 @@ } return 1; } + +static void compute_progress_bar(float line_nb) +{ + line_nb = (line_nb / 4); + if (line_nb<1) + line_nb = 1; + step = (line_nb / 60); +} Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2008-05-30 13:37:01 UTC (rev 1206) +++ firmware/tuxup/trunk/main.c 2008-05-30 14:04:36 UTC (rev 1207) @@ -292,12 +292,12 @@ return 0; if (bootload(dev_h, cpu_i2c_addr, FLASH, filename)) - { - printf(" [OK]\n"); + { + printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); return 0; } else - printf(" [FAIL]\n"); + printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); return 1; } @@ -331,11 +331,11 @@ if (bootload(dev_h, cpu_i2c_addr, EEPROM, filename)) { - printf(" [OK]\n"); + printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); return 0; } else - printf(" [FAIL]\n"); + printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); return 1; } |
From: Paul_R <c2m...@c2...> - 2008-05-28 12:05:03
|
Author: Paul_R Date: 2008-05-28 14:05:06 +0200 (Wed, 28 May 2008) New Revision: 1205 Added: firmware/tuxup/trunk/tux_hid_unix.c firmware/tuxup/trunk/tux_hid_unix.h firmware/tuxup/trunk/tux_misc.c firmware/tuxup/trunk/tux_misc.h Log: * Oups, forget to add some modules ... Added: firmware/tuxup/trunk/tux_hid_unix.c =================================================================== --- firmware/tuxup/trunk/tux_hid_unix.c (rev 0) +++ firmware/tuxup/trunk/tux_hid_unix.c 2008-05-28 12:05:06 UTC (rev 1205) @@ -0,0 +1,192 @@ +/* + * Tux Droid - Hid interface (only for unix) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <asm/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <linux/hiddev.h> + +#include <string.h> +#include <dirent.h> + +#include "tux_hid_unix.h" +#include "tux_misc.h" + +static int tux_device_hdl = -1; +static char tux_device_path[256] = ""; +static struct hiddev_usage_ref uref_out; +static struct hiddev_report_info rinfo_out; + +static bool +find_dongle_from_path(const char *path, int vendor_id, int product_id) +{ + DIR* dir; + struct dirent *dinfo; + int fd = -1; + char device_path[256] = ""; + struct hiddev_devinfo device_info; + int err; + + dir = opendir(path); + if (dir != NULL) + { + while ((dinfo = readdir(dir)) != NULL) + { + if (strncmp(dinfo->d_name, "hiddev", 6) == 0) + { + sprintf(device_path, "%s/%s", path, dinfo->d_name); + + if ((fd = open(device_path, O_RDONLY)) >= 0) + { + err = ioctl(fd, HIDIOCGDEVINFO, &device_info); + if ((device_info.vendor == vendor_id) && + ((device_info.product & 0xFFFF) == product_id)) + { + sprintf(tux_device_path, "%s", device_path); + tux_device_hdl = fd; + + closedir(dir); + + return true; + } + else + { + close(fd); + } + } + } + } + + closedir(dir); + } + + return false; +} + +bool LIBLOCAL +tux_hid_capture(int vendor_id, int product_id) +{ + /* Normal path to scan is /dev/usb */ + if (find_dongle_from_path("/dev/usb", vendor_id, product_id)) + { + return true; + } + + /* Other possible path to scan is /dev/usb */ + if (find_dongle_from_path("/dev", vendor_id, product_id)) + { + return true; + } + + /* dongle not found */ + return false; +} + +void LIBLOCAL +tux_hid_release(void) +{ + if (tux_device_hdl != -1) + { + close(tux_device_hdl); + tux_device_hdl = -1; + } +} + +bool LIBLOCAL +tux_hid_write(int size, const unsigned char *buffer) +{ + int i; + int err; + + rinfo_out.report_type = HID_REPORT_TYPE_OUTPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORTINFO, &rinfo_out); + if (err < 0) + { + return false; + } + + for(i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_OUTPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + uref_out.value = (unsigned char)buffer[i]; + + err = ioctl(tux_device_hdl,HIDIOCSUSAGE, &uref_out); + if (err < 0) + { + return false; + } + } + + err = ioctl(tux_device_hdl,HIDIOCSREPORT,&rinfo_out); + if (err < 0) + { + return false; + } + + return true; +} + +bool LIBLOCAL +tux_hid_read(int size, unsigned char *buffer) +{ + int i; + int err; + + rinfo_out.report_type = HID_REPORT_TYPE_INPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORT, &rinfo_out); + if (err < 0) + { + return false; + } + + for (i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_INPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + + err = ioctl(tux_device_hdl, HIDIOCGUCODE, &uref_out); + if (err < 0) + { + return false; + } + + err = ioctl(tux_device_hdl, HIDIOCGUSAGE, &uref_out); + if (err < 0) + { + return false; + } + buffer[i] = uref_out.value; + } + return true; +} + Property changes on: firmware/tuxup/trunk/tux_hid_unix.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxup/trunk/tux_hid_unix.h =================================================================== --- firmware/tuxup/trunk/tux_hid_unix.h (rev 0) +++ firmware/tuxup/trunk/tux_hid_unix.h 2008-05-28 12:05:06 UTC (rev 1205) @@ -0,0 +1,39 @@ +/* + * Tux Droid - Hid interface (only for unix) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef WIN32 + +#ifndef _TUX_HID_H_ +#define _TUX_HID_H_ + +#include <stdbool.h> +#include <stdio.h> + +#define HID_RW_TIMEOUT 1000 + +extern bool tux_hid_capture(int vendor_id, int product_id); +extern void tux_hid_release(void); +extern bool tux_hid_write(int size, const unsigned char *buffer); +extern bool tux_hid_read(int size, unsigned char *buffer); + +#endif /* _TUX_HID_H_ */ + +#endif /* Not WIN32 */ + Property changes on: firmware/tuxup/trunk/tux_hid_unix.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxup/trunk/tux_misc.c =================================================================== --- firmware/tuxup/trunk/tux_misc.c (rev 0) +++ firmware/tuxup/trunk/tux_misc.c 2008-05-28 12:05:06 UTC (rev 1205) @@ -0,0 +1,211 @@ +/* + * Tux Droid - Misc + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <stdio.h> +#include <string.h> + +#include "tux_misc.h" + +#ifdef WIN32 +# include <time.h> +# include <windows.h> +#else +# include <sys/time.h> +#endif + +#ifdef WIN32 +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +/** + * + */ +static int +gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tmpres /= 10; /*convert into microseconds*/ + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} +#endif /* WIN32 */ + +/** + * + */ +LIBEXPORT double +get_time(void) +{ + double result; + struct timeval tv; + struct timezone tz; + + gettimeofday(&tv, &tz); + result = ((double)tv.tv_usec / 1000000) + (double)tv.tv_sec; + + return result; +} + +LIBLOCAL bool +str_to_uint8(const char *str, unsigned char *dest) +{ + int r, val; + + r = sscanf(str, "%d", &val); + + if (r == 1) + { + if ((val >= 0) && (val <= 255)) + { + *dest = val; + return true; + } + } + + return false; +} + +LIBLOCAL bool +str_to_int8(const char *str, char *dest) +{ + int r, val; + + r = sscanf(str, "%d", &val); + + if (r == 1) + { + if ((val >= -128) && (val <= 127)) + { + *dest = val; + return true; + } + } + + return false; +} + +LIBLOCAL bool +str_to_int(const char *str, int *dest) +{ + int r, val; + + r = sscanf(str, "%d", &val); + + if (r == 1) + { + *dest = val; + return true; + } + + return false; +} + +LIBLOCAL bool +str_to_bool(const char *str, bool *dest) +{ + if (!strcmp(str, "True")) + { + *dest = true; + return true; + } + else + { + if (!strcmp(str, "False")) + { + *dest = false; + return true; + } + } + + return false; +} + +LIBLOCAL bool +str_to_float(const char *str, float *dest) +{ + int r; + float val; + + r = sscanf(str, "%f", &val); + + if (r == 1) + { + *dest = val; + return true; + } + + return false; +} + +LIBLOCAL bool +hex_to_uint8(const char *str, unsigned char *dest) +{ + int r; + int val; + + r = sscanf(str, "0x%2x", &val); + + if (r == 1) + { + if ((val >= 0) && (val <= 255)) + { + *dest = val; + return true; + } + } + + return false; +} Property changes on: firmware/tuxup/trunk/tux_misc.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxup/trunk/tux_misc.h =================================================================== --- firmware/tuxup/trunk/tux_misc.h (rev 0) +++ firmware/tuxup/trunk/tux_misc.h 2008-05-28 12:05:06 UTC (rev 1205) @@ -0,0 +1,57 @@ +/* + * Tux Droid - Misc + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _TUX_MISC_H_ +#define _TUX_MISC_H_ + +#include <stdbool.h> +#include <stdint.h> + +#define FW_MAIN_LOOP_DELAY 0.004 + +#define TUX_VID 0x03eb // Atmel VID +#define TUX_PID 0xFF07 // Tux PID + +#ifdef WIN32 +# include <windows.h> +# include <mmsystem.h> +# define sleep(sec) Sleep(sec * 1000) +# define usleep(usec) Sleep(usec / 1000) +# define LIBEXPORT __declspec(dllexport) +# define LIBLOCAL +#else +# define LIBEXPORT __attribute__ ((visibility ("default"))) +# define LIBLOCAL __attribute__ ((visibility ("hidden"))) +#endif + + +/** + * Callback function prototype for simple event + */ +typedef void(*simple_callback_t)(void); + +extern double get_time(void); +extern bool str_to_uint8(const char *str, unsigned char *dest); +extern bool str_to_int8(const char *str, char *dest); +extern bool str_to_int(const char *str, int *dest); +extern bool str_to_bool(const char *str, bool *dest); +extern bool str_to_float(const char *str, float *dest); +extern bool hex_to_uint8(const char *str, unsigned char *dest); +#endif /* _TUX_MISC_H_ */ Property changes on: firmware/tuxup/trunk/tux_misc.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native |
From: Paul_R <c2m...@c2...> - 2008-05-28 11:01:17
|
Author: Paul_R Date: 2008-05-28 13:01:17 +0200 (Wed, 28 May 2008) New Revision: 1204 Modified: firmware/tuxup/trunk/Makefile firmware/tuxup/trunk/bootloader.c firmware/tuxup/trunk/bootloader.h firmware/tuxup/trunk/main.c Log: * Added the compatibility with the HID interface. Modified: firmware/tuxup/trunk/Makefile =================================================================== --- firmware/tuxup/trunk/Makefile 2008-05-28 11:00:43 UTC (rev 1203) +++ firmware/tuxup/trunk/Makefile 2008-05-28 11:01:17 UTC (rev 1204) @@ -11,14 +11,15 @@ LIB = -lusb ## Objects that must be built in order to link -FILES = main.c usb-connection.c bootloader.c +FILES = main.c usb-connection.c bootloader.c tux_hid_unix.c tux_misc.c ## Build all: $(TARGET) ## Compile and link -tuxup: main.c bootloader.c bootloader.h usb-connection.c usb-connection.h tux-api.h version.h common/commands.h - ${CC} ${LIB} ${CFLAGS} -o tuxup main.c bootloader.c usb-connection.c +tuxup: main.c bootloader.c bootloader.h usb-connection.c usb-connection.h tux_hid_unix.c tux_hid_unix.h tux_misc.c tux_misc.h tux-api.h version.h common/commands.h + ${CC} ${LIB} ${CFLAGS} -o tuxup main.c bootloader.c usb-connection.c \ + tux_hid_unix.c tux_misc.c clean : -rm -f $(TARGET) *.o Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2008-05-28 11:00:43 UTC (rev 1203) +++ firmware/tuxup/trunk/bootloader.c 2008-05-28 11:01:17 UTC (rev 1204) @@ -26,22 +26,21 @@ * @brief Boot loader that sends data to the dongle which forwards it on I2C * to reprogram all CPU's. */ - #include <stdio.h> #include <stdint.h> #include <unistd.h> -//#include <stdlib.h> -//#include <errno.h> +#include <stdlib.h> +#include <time.h> #include <string.h> -//#include <fcntl.h> -//#include <sys/types.h> - #include "usb-connection.h" +#include "tux_hid_unix.h" #include "tux-api.h" /* Whether to display verbose messages. */ extern int verbose; +bool HID; + /* Debug commands */ //#define keybreak() {puts("Press return to read feedback"); getchar();} //#define keybreak() {usleep(5000);} @@ -51,16 +50,24 @@ #define TRUE 1 #define FALSE 0 +#define USB_TIMEOUT 5 +#define BOOT_INIT_ACK 10 +#define BOOT_EXIT_ACK 2 + /* USB bootloader commands */ #define BOOT_INIT 1 #define BOOT_FILLPAGE 2 #define BOOT_EXIT 3 +static bool wait_status(uint8_t value, int timeout); + typedef uint32_t FILE_Addr_t; typedef uint32_t FILE_SegmentLen_t; typedef unsigned FILE_LineNum_t; typedef uint8_t FILE_ParsedLen_t; +static uint8_t counter; + static enum mem_type_t mem_type; typedef struct @@ -295,12 +302,27 @@ /* set the last bit to 1 to indicate eeprom type to the bootloader */ data_buffer[2] |= 0x80; } - ret = usb_send_commands(parser->dev_handle, data_buffer, 36); + if (HID) + { + ret = tux_hid_write(36, data_buffer); + } + else + { + ret = usb_send_commands(parser->dev_handle, data_buffer, 36); + } #if (PRINT_DATA) printf("Status of the first packet sent: %d\n", ret); #endif - if (ret != 36) - return FALSE; + if (HID) + { + if (!ret) + return FALSE; + } + else + { + if (ret != 36) + return FALSE; + } /* * Send second packet @@ -308,33 +330,75 @@ for (i = 2; i < 34; i++) data_buffer[i] = parser->segmentData[idx++]; keybreak(); - ret = usb_send_commands(parser->dev_handle, data_buffer, 34); + if (HID) + { + ret = tux_hid_write(34, data_buffer); + } + else + { + ret = usb_send_commands(parser->dev_handle, data_buffer, 34); + } #if (PRINT_DATA) printf("Status of the second packet sent: %d\n", ret); #endif - if (ret != 34) - return FALSE; + if (HID) + { + if (!ret) + return FALSE; + } + else + { + if (ret != 34) + return FALSE; + } keybreak(); /* * Bootlader status command and result */ - ret = usb_get_commands(parser->dev_handle, data_buffer, 5); + if (HID) + { + ret = (wait_status(counter, USB_TIMEOUT)); + tux_hid_read(5, data_buffer); + counter ++; + } + else + { + ret = usb_get_commands(parser->dev_handle, data_buffer, 5); + } #if (PRINT_DATA) printf("Status of feedback from bootloader: %x\n", ret); #endif - if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) + if (HID) { - printf("."); - fflush (stdout); - return TRUE; + if ((ret) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) + { + printf("."); + fflush (stdout); + return TRUE; + } + else + { + fprintf(stderr, + "Bootloading failed, program aborted at dongle reply.\n"); + exit(1); + } } else { - fprintf(stderr, - "Bootloading failed, program aborted at dongle reply.\n"); - exit(1); + if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) + { + printf("."); + fflush (stdout); + return TRUE; + } + else + { + fprintf(stderr, + "Bootloading failed, program aborted at dongle reply.\n"); + exit(1); + } } } @@ -616,13 +680,35 @@ data_buffer[2] = cpu_address; data_buffer[3] = page_size; data_buffer[4] = packet_total; + + counter = 0; + + if (HID) + { + ret = tux_hid_write(5, data_buffer); + sleep(1); + } + else + { + ret = usb_send_commands(dev_h, data_buffer, 5); + } - ret = usb_send_commands(dev_h, data_buffer, 5); + if (HID) + { + if (!wait_status(BOOT_INIT_ACK, USB_TIMEOUT) || !ret) + { + fprintf(stderr, "Initialization failed\n"); + return FALSE; + } + } + else + { #if (PRINT_DATA) - printf("Boot init status: %x\n", ret); + printf("Boot init status: %x\n", ret); #endif - if (ret != 5) - return FALSE; /* initialization failed */ + if (ret != 5) + return FALSE; /* initialization failed */ + } /* Bootloader: parse hex file and send data */ if (FILE_ParseFile(dev_h, filename)) @@ -635,7 +721,44 @@ data_buffer[3] = 0; data_buffer[4] = 0; - ret = usb_send_commands(dev_h, data_buffer, 5); - ret = usb_get_commands(dev_h, data_buffer, 5); + if (HID) + { + tux_hid_write(5, data_buffer); + tux_hid_read(5, data_buffer); + if (!wait_status(BOOT_EXIT_ACK, USB_TIMEOUT)) + { + fprintf(stderr, "Bootloader exit failed \n"); + return FALSE; + } + } + else + { + ret = usb_send_commands(dev_h, data_buffer, 5); + ret = usb_get_commands(dev_h, data_buffer, 5); + } return rc; } +/* + * Wait a specific ACK. + * This function wait for a specific value of the second parameter of the + * bootloader ACK. + */ +static bool wait_status(uint8_t value, int timeout) +{ + uint8_t data_buffer[5]; + uint8_t sttime = time(NULL); + uint8_t edtime = 0; + + tux_hid_read(5, data_buffer); + while (data_buffer[2] != value || data_buffer[0] != 0xF0) + { + edtime = time(NULL); + if (difftime(edtime, sttime) > timeout) + { + return 0; + } + tux_hid_read(5, data_buffer); + usleep(5000); + } + return 1; +} Modified: firmware/tuxup/trunk/bootloader.h =================================================================== --- firmware/tuxup/trunk/bootloader.h 2008-05-28 11:00:43 UTC (rev 1203) +++ firmware/tuxup/trunk/bootloader.h 2008-05-28 11:01:17 UTC (rev 1204) @@ -21,6 +21,8 @@ #ifndef bootloader_h #define bootloader_h +#include <stdbool.h> +extern bool HID; int bootload(usb_dev_handle * dev_h, uint8_t cpu_address, uint8_t mem_type, const char *filename); Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2008-05-28 11:00:43 UTC (rev 1203) +++ firmware/tuxup/trunk/main.c 2008-05-28 11:01:17 UTC (rev 1204) @@ -19,18 +19,22 @@ /* $Id$ */ +#include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <getopt.h> +#include <unistd.h> #include <time.h> #include <string.h> #include <linux/limits.h> #include "tux-api.h" #include "usb-connection.h" +#include "tux_hid_unix.h" #include "bootloader.h" #include "version.h" #include "common/defines.h" +#include "tux_misc.h" #define countof(X) ( (size_t) ( sizeof(X)/sizeof*(X) ) ) @@ -110,21 +114,38 @@ if (usb_connected) return; - /* detect Tux on USB */ - for (;;) + /* First, try to found a HID device */ + if (!(tux_hid_capture(TUX_VID, TUX_PID))) { - device = usb_find_tux(); - if (device != NULL || wait == 0) - break; + /* Unable to capture the device : + * Try with the libusb */ + for (;;) + { + device = usb_find_tux(); + if (device != NULL || wait == 0) + break; - sleep(1); - wait--; + sleep(1); + wait--; + } + + if (device == NULL) + { + fprintf(stderr, "The dongle was not found, now exiting.\n"); + exit(1); + } + else + { + printf("Dongle found, using LibUSB \n"); + /* The dongle is a libusb device */ + HID = 0; + } } - - if (device == NULL) + else { - fprintf(stderr, "The dongle was not found, now exiting.\n"); - exit(1); + printf("HID Dongle found \n"); + /* The dongle is a HID device */ + HID = 1; } if (verbose) @@ -133,18 +154,21 @@ /* Check if we have the old firmware that requires entering * bootloader mode manually, exits with a message that explains what * to do in such a case. */ - if (device->descriptor.bcdDevice < 0x030) + if (!HID) { - fprintf(stderr, msg_old_firmware); - exit(1); + if (device->descriptor.bcdDevice < 0x030) + { + fprintf(stderr, msg_old_firmware); + exit(1); + } + + /* open USB device */ + if ((dev_h = usb_open_tux(device)) == NULL) + { + fprintf(stderr, "USB DEVICE INIT ERROR \n"); + exit(1); + } } - - /* open USB device */ - if ((dev_h = usb_open_tux(device)) == NULL) - { - fprintf(stderr, "USB DEVICE INIT ERROR \n"); - exit(1); - } if (verbose) printf("Interface configured \n\n"); usb_connected = 1; @@ -156,8 +180,15 @@ return; if (verbose) printf("Closing interface ...\n"); - usb_release_interface(dev_h, USB_COMMAND); - usb_close(dev_h); + if (HID) + { + tux_hid_release(); + } + else + { + usb_release_interface(dev_h, USB_COMMAND); + usb_close(dev_h); + } if (verbose) printf(" ... interface closed \n"); usb_connected = 0; @@ -369,20 +400,28 @@ } fux_connect(); /* Enter bootloader mode. */ - ret = usb_send_commands(dev_h, send_data, 5); - if (ret == 5) + if (HID) { - if (verbose) - fprintf(stdout, "Switched to bootloader mode.\n"); + tux_hid_write(5, send_data); sleep(1); } else { - fprintf(stderr, "Switching to bootloader mode failed.\n"); - return 1; + ret = usb_send_commands(dev_h, send_data, 5); + if (ret == 5) + { + if (verbose) + fprintf(stdout, "Switched to bootloader mode.\n"); + sleep(1); + } + + else + { + fprintf(stderr, "Switching to bootloader mode failed.\n"); + return 1; + } } } - ret = system("dfu-programmer at89c5130 erase"); if (ret) { @@ -635,14 +674,17 @@ if (!pretend) { uint8_t send_data[5] = { 0x01, 0x01, 0x00, 0x00, 0xFE }; - ret = usb_send_commands(dev_h, send_data, 5); + if (HID) + { + tux_hid_write(5, send_data); + } + else + { + ret = usb_send_commands(dev_h, send_data, 5); + } fux_disconnect(); } - /* In case of error of some sort, we return it. */ - if (ret) - return ret; - /* Print time elapsed for programming. */ end_time = time(NULL); if (!pretend) |
From: Paul_R <c2m...@c2...> - 2008-05-28 11:00:43
|
Author: Paul_R Date: 2008-05-28 13:00:43 +0200 (Wed, 28 May 2008) New Revision: 1203 Modified: firmware/fuxusb/trunk/fuxusb.Opt firmware/fuxusb/trunk/src/bootloader.c firmware/fuxusb/trunk/src/config.h firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_ep.c Log: * Adapted the bootloader mode to be compatible with HID tuxup : - Added BOOT_INIT ack. - Added a counter for the synchronisation with tuxup. The value is sent with the i2c ack. Modified: firmware/fuxusb/trunk/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/trunk/src/bootloader.c =================================================================== --- firmware/fuxusb/trunk/src/bootloader.c 2008-05-23 15:27:06 UTC (rev 1202) +++ firmware/fuxusb/trunk/src/bootloader.c 2008-05-28 11:00:43 UTC (rev 1203) @@ -27,11 +27,15 @@ #include "config.h" #include "global.h" #include "usb_commands.h" +#include "usb_desc.h" +#include "usb_ep.h" #include "bootloader.h" #include "i2c.h" #include "spi_task.h" #include "rf.h" +#include "lib_mcu\usb\usb_drv.h" +static uint8_t counter = 0; /* Externs defs */ bit i2c_bootloading_Flag; @@ -131,7 +135,7 @@ /* Wait 20ms before next I2C */ i2c_wait_counter = 20; /* ACK or NACK and exit I2C task */ - bl_acknowledge(i2cFlags.s_val, 0, 0, 0); + bl_acknowledge(i2cFlags.s_val, counter ++, 0, 0); i2c_task_on_Flag = 0; } } @@ -166,13 +170,13 @@ else if (((blHeader.page_address & ~0x8000) != address_tracking && \ blHeader.page_address != 0x1DC0 && \ - blHeader.page_address != 0x0EC0) || Command_Ctr != 35) + blHeader.page_address != 0x0EC0)) { bl_acknowledge(False, 3, 0, 0); bl_exit(); } - for(i = 3; i < Command_Ctr; i++) + for(i = 3; i < 35; i++) { blHeader.blData[address_idx++] = command_received[i]; } @@ -180,16 +184,8 @@ else { - /* Check if we got the right number of - * data */ - if (Command_Ctr != 33) - { - /* Exit bootloader mode */ - bl_acknowledge(False, 4, 0, 0); - bl_exit(); - } - for(i = 1; i < Command_Ctr; i++) + for(i = 1; i < 33; i++) { blHeader.blData[address_idx++] = command_received[i]; } @@ -223,10 +219,18 @@ address_idx = 0; packet_idx = 0; + counter = 0; + i2c_bootloading_Flag = True; EX0 = 0; /* Disable INT0 interrupt */ + CMD_IN_Bank_Nb = 0; + usb_reset_endpoint(EP_CMD_IN); + +#ifdef HID_DEVICE + bl_acknowledge(True, 10, 0, 0); +#endif } /** Modified: firmware/fuxusb/trunk/src/config.h =================================================================== --- firmware/fuxusb/trunk/src/config.h 2008-05-23 15:27:06 UTC (rev 1202) +++ firmware/fuxusb/trunk/src/config.h 2008-05-28 11:00:43 UTC (rev 1203) @@ -28,6 +28,7 @@ */ #include <stdint.h> +#include <stdio.h> #include "lib_mcu/compiler.h" #include "lib_mcu/reg_5131.h" #include "lib_mcu/ext_5131.h" @@ -38,6 +39,7 @@ * @{ */ #undef MAIN_DEBUG #undef USB_ENUM_DEBUG +#undef BL_DEBUG /* @} */ /** \name MCU config Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 15:27:06 UTC (rev 1202) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-28 11:00:43 UTC (rev 1203) @@ -30,7 +30,7 @@ #include "version.h" /** Enable / Disable the HID interface */ -#undef HID_DEVICE +#define HID_DEVICE /** \name Descriptors type * @{ */ Modified: firmware/fuxusb/trunk/src/usb_ep.c =================================================================== --- firmware/fuxusb/trunk/src/usb_ep.c 2008-05-23 15:27:06 UTC (rev 1202) +++ firmware/fuxusb/trunk/src/usb_ep.c 2008-05-28 11:00:43 UTC (rev 1203) @@ -89,6 +89,11 @@ read_tts_ep(); } + /* EP4 : Command in EP (dongle -> PC) */ + if (Usb_test_it_ep(EP_CMD_IN)) + { + clear_cmdin_ep(); + } /* EP5 : Command out EP (PC -> dongle) */ if(Usb_test_it_ep(EP_CMD_OUT)) @@ -99,12 +104,6 @@ clear_cmdout_ep(); } } - - /* EP4 : Command in EP (dongle -> PC) */ - if (Usb_test_it_ep(EP_CMD_IN)) - { - clear_cmdin_ep(); - } } /** |
From: Paul_R <c2m...@c2...> - 2008-05-23 15:27:10
|
Author: Paul_R Date: 2008-05-23 17:27:06 +0200 (Fri, 23 May 2008) New Revision: 1202 Modified: firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_enum.c Log: * Splitted and cleaned the get_descriptor function. * Added attribute 'code' on the descriptors structures. (see C51 reference manual). Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 14:20:56 UTC (rev 1201) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 15:27:06 UTC (rev 1202) @@ -217,7 +217,7 @@ /* @} */ /* @} */ -struct usb_st_device_descriptor +code struct usb_st_device_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes. */ uint8_t bDescriptorType; /**< DEVICE descriptor type */ @@ -235,7 +235,7 @@ uint8_t bNumConfigurations; /**< Number of possible configurations */ }; -struct usb_st_configuration_descriptor +code struct usb_st_configuration_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< CONFIGURATION descriptor type */ @@ -247,7 +247,7 @@ uint8_t MaxPower; /**< maximum power consumption */ }; -struct usb_st_interface_descriptor +code struct usb_st_interface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -260,7 +260,7 @@ uint8_t iInterface; /**< Index of string descriptor */ }; -struct usb_st_endpoint_descriptor +code struct usb_st_endpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -271,7 +271,7 @@ }; /* HID specific */ -struct usb_hid_descriptor +code struct usb_hid_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -283,7 +283,7 @@ }; /* Audio Class specific */ -struct usb_Audio_st_ACinterface_descriptor +code struct usb_Audio_st_ACinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -296,7 +296,7 @@ uint8_t iInterface; /**< Index of string descriptor */ }; -struct usb_Audio_cs_ACinterface_descriptor +code struct usb_Audio_cs_ACinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -307,7 +307,7 @@ uint8_t baInterfaceNr[2]; /**< Class code assigned by the USB */ }; -struct usb_Audio_cs_ACinterface_descriptor_NbCol1 +code struct usb_Audio_cs_ACinterface_descriptor_NbCol1 { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -319,7 +319,7 @@ }; /* Audio input terminal */ -struct usb_Audio_InputTerminal_descriptor +code struct usb_Audio_InputTerminal_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -334,7 +334,7 @@ }; /* Audio output terminal */ -struct usb_Audio_OutputTerminal_descriptor +code struct usb_Audio_OutputTerminal_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -347,7 +347,7 @@ }; /* Audio feature unit */ -struct usb_Audio_FeatureUnit_descriptor +code struct usb_Audio_FeatureUnit_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -360,7 +360,7 @@ }; /* Audio stream */ -struct usb_Audio_st_ASinterface_descriptor +code struct usb_Audio_st_ASinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -374,7 +374,7 @@ }; /* Audio class specific */ -struct usb_Audio_cs_ASinterface_descriptor +code struct usb_Audio_cs_ASinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -385,7 +385,7 @@ }; /* Audio EP */ -struct usb_Audio_st_endpoint_descriptor +code struct usb_Audio_st_endpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -398,7 +398,7 @@ }; /* Audio stream */ -struct usb_Audio_cs_ASendpoint_descriptor +code struct usb_Audio_cs_ASendpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -409,7 +409,7 @@ }; /* Audio endpoint */ -struct usb_Audio_TYPEI_FormatType_descriptor +code struct usb_Audio_TYPEI_FormatType_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -425,7 +425,7 @@ /** \name General structure * This structure contain all the descriptors. * @{ */ -struct usb_configuration_s +code struct usb_configuration_s { /*! Configuration descriptor */ struct usb_st_configuration_descriptor cfg; @@ -532,56 +532,56 @@ /** \name String descriptors * @{ */ -struct usb_st_language_descriptor +code struct usb_st_language_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_CONFIG_LENGTH]; /**< language id */ }; -struct usb_st_manufacturer +code struct usb_st_manufacturer { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_MN_LENGTH];/**< unicode characters */ }; -struct usb_st_product +code struct usb_st_product { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_PN_LENGTH];/**< unicode characters */ }; -struct usb_st_serial_number +code struct usb_st_serial_number { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_SN_LENGTH];/**< unicode characters */ }; -struct usb_st_config +code struct usb_st_config { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_CONFIG_LENGTH];/**< unicode characters */ }; -struct usb_st_speaker_descriptor +code struct usb_st_speaker_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[AUDIO_SPEAKER_LENGTH]; /**< language id */ }; -struct usb_st_micro_descriptor +code struct usb_st_micro_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[AUDIO_MICRO_LENGTH]; /**< language id */ }; -struct usb_st_tts_descriptor +code struct usb_st_tts_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ @@ -589,7 +589,7 @@ }; -struct usb_st_audio_descriptor +code struct usb_st_audio_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ @@ -600,7 +600,7 @@ /** \name String structure * This structure contain all the descriptors. * @{ */ -struct string_s +code struct string_s { /*! Language string descriptor */ struct usb_st_language_descriptor st_language; Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 14:20:56 UTC (rev 1201) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 15:27:06 UTC (rev 1202) @@ -54,6 +54,8 @@ * \ingroup usb_enum */ uint8_t usb_configuration_nb = 0; /*! @} */ +/** Number of data to transfert during a get_descriptor process. */ +uint16_t data_to_transfer; /** \name Standard enumeration functions * @{ */ @@ -90,6 +92,7 @@ /** \name Misc functions * @{ */ +static bit send_descriptor(uint8_t *buffer, uint8_t size); static void stall_request(void); static void send_zlp(void); /* @} */ @@ -391,8 +394,8 @@ */ static void usb_get_descriptor (void) { - uint16_t data_to_transfer; - uint16_t wLength; + + uint16_t wLength; uint8_t descriptor_type; uint8_t string_type; @@ -401,25 +404,18 @@ string_type = Usb_read_byte(); descriptor_type = Usb_read_byte(); -#ifdef USB_ENUM_DEBUG - printf("GET_DESCRIPTOR %BX %BX ",descriptor_type,string_type); -#endif + + /* Parse the request, and prepare data */ switch (descriptor_type) { case DEVICE: data_to_transfer = sizeof (usb_device_descriptor); pbuffer = &(usb_device_descriptor.bLength); -#ifdef USB_ENUM_DEBUG - printf("DEVICE "); -#endif break; case CONFIGURATION: data_to_transfer = sizeof (usb_configuration); pbuffer = &(usb_configuration.cfg.bLength); -#ifdef USB_ENUM_DEBUG - printf("CONFIGURATION "); -#endif break; #ifdef HID_DEVICE @@ -435,9 +431,6 @@ #endif case STRING: -#ifdef USB_ENUM_DEBUG - printf("STRING %BX", string_type); -#endif switch (string_type) { case LANG_ID: @@ -493,95 +486,64 @@ } break; default: -#ifdef USB_ENUM_DEBUG - printf("UNKNOWN"); -#endif + Usb_clear_rx_setup(); stall_request(); Usb_clear_DIR(); -#ifdef USB_ENUM_DEBUG - printf("1"); -#endif return; } - ACC = Usb_read_byte(); /* don't care of wIndex field */ + /* Pop 2 bytes from the usb fifo. We don't need them. */ ACC = Usb_read_byte(); + ACC = Usb_read_byte(); - ((uint8_t *)&wLength)[1] = Usb_read_byte(); /* read wLength */ + /* Read the wLength value */ + ((uint8_t *)&wLength)[1] = Usb_read_byte(); ((uint8_t *)&wLength)[0] = Usb_read_byte(); + /* Determine if the last paket will be complete or not */ if (wLength > data_to_transfer) { - if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) - { - zlp = True; - } - else - { - zlp = False; - } /* no need of zero length packet */ + zlp = (data_to_transfer % EP_CONTROL_LENGTH) ? False : True; } else { data_to_transfer = wLength; /* send only requested number of data */ } - Usb_clear_rx_setup(); /* clear the receive setup flag */ - Usb_set_DIR(); /* set out on EP0 */ + /* Clear setup bit, prepare EP to send data */ + Usb_clear_rx_setup(); + Usb_set_DIR(); + + /* Send data on the bus */ while (data_to_transfer > EP_CONTROL_LENGTH) { - pbuffer = usb_send_ep0_packet(pbuffer, EP_CONTROL_LENGTH); - data_to_transfer -= EP_CONTROL_LENGTH; - - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + if (!send_descriptor(pbuffer, EP_CONTROL_LENGTH)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("2"); -#endif return; } } - /* send last data packet */ - pbuffer = usb_send_ep0_packet(pbuffer, data_to_transfer); - data_to_transfer = 0; - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + + /* Send last packet */ + if (!send_descriptor(pbuffer, data_to_transfer)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("3"); -#endif return; } + + /* The last packet was smaller than the EP size : send a ZLP. */ if (zlp == True) { - usb_send_ep0_packet(pbuffer, 0); - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + if (!send_descriptor(pbuffer, 0)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("4"); -#endif return; } - } + + /* Wait until the last packet has not be sent */ while ((!(Usb_rx_complete())) && (!(Usb_setup_received()))); + if (Usb_setup_received()) { -#ifdef USB_ENUM_DEBUG - printf("5"); -#endif return; } @@ -590,10 +552,33 @@ Usb_clear_DIR(); /* set in on EP0 */ Usb_clear_rx(); } -#ifdef USB_ENUM_DEBUG - printf("6"); -#endif +} +/** + * \brief This function send the descriptor to the host. + * \param *buffer Pointer on a buffer wich contain data to send. + * \param size The number of data to send. + * \return True is the host as acknoledged the packet. + */ +static bit send_descriptor(uint8_t *buffer, uint8_t size) +{ + pbuffer = usb_send_ep0_packet(buffer, size); + data_to_transfer -= size; + + /* Wait until the EP isn't ready */ + while (!Usb_rx_complete() && !Usb_tx_complete()); + + /* Clear TX complete flag */ + Usb_clear_tx_complete(); + + /* Cancelled by host, abort */ + if ((Usb_rx_complete())) + { + Usb_clear_tx_ready(); + Usb_clear_rx(); + return False; + } + return True; } /** |
From: Paul_R <c2m...@c2...> - 2008-05-23 14:20:54
|
Author: Paul_R Date: 2008-05-23 16:20:56 +0200 (Fri, 23 May 2008) New Revision: 1201 Modified: firmware/fuxusb/trunk/src/usb_desc.c firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_enum.c Log: * Reorganized the strings descriptors Modified: firmware/fuxusb/trunk/src/usb_desc.c =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.c 2008-05-23 13:07:11 UTC (rev 1200) +++ firmware/fuxusb/trunk/src/usb_desc.c 2008-05-23 14:20:56 UTC (rev 1201) @@ -32,89 +32,98 @@ */ code struct usb_st_device_descriptor usb_device_descriptor = { - sizeof(usb_device_descriptor), DEVICE, USB_SPECIFICATION, DEVICE_CLASS, - DEVICE_SUB_CLASS, DEVICE_PROTOCOL, EP_CONTROL_LENGTH, VENDOR_ID, PRODUCT_ID, - ((uint16_t)RELEASE_NUMBER), MAN_STRING_INDEX, PROD_STRING_INDEX, - SN_STRING_INDEX, NB_CONFIGURATION + sizeof(usb_device_descriptor), // bLength + DEVICE, // bDescriptorType + USB_SPECIFICATION, // bcdUSB + DEVICE_CLASS, // bDeviceClass + DEVICE_SUB_CLASS, // bDeviceSubClass + DEVICE_PROTOCOL, // bDeviceProtocol + EP_CONTROL_LENGTH, // bMaxPacketSize0 + VENDOR_ID, // idVendor + PRODUCT_ID, // idProduct + ((uint16_t)RELEASE_NUMBER), // bcdDevice + MAN_STRING_INDEX, // iManufacturer + PROD_STRING_INDEX, // iProduct + SN_STRING_INDEX, // iSerial + NB_CONFIGURATION // bNumConfiguration }; -/** \brief Manufactrer string. - * Contain the manufacturer string - * string : KYSOH - * size : 5 +/** \brief String structure. + * This structure contain all the strings descriptors. */ -code struct usb_st_manufacturer usb_manufacturer = -{ sizeof(usb_manufacturer), STRING, USB_MANUFACTURER_NAME }; +code struct string_s string = +{ + { // Language ID string descriptor + sizeof(string.st_language), // bLength + STRING, // bDescriptorType + LANGUAGE_ID // + }, -/** \brief Product string. - * Contain the product string - * string : TuxDroid - * size : 8 - */ -code struct usb_st_product usb_product = -{ sizeof(usb_product), STRING, USB_PRODUCT_NAME }; + { // Manufacturer string descriptor + sizeof(string.st_manufacturer), // bLength + STRING, // bDescriptorType + USB_MANUFACTURER_NAME // + }, -/** \brief Serial number. - * string : 10001 - * size : 5 - */ -code struct usb_st_serial_number usb_serial_number = -{ sizeof(usb_serial_number), STRING, USB_SERIAL_NUMBER }; + { // Product string descriptor + sizeof(string.st_product), // bLength + STRING, // bDescriptorType + USB_PRODUCT_NAME // + }, + { // Serial number string descriptor + sizeof(string.st_serial_number),// bLength + STRING, // bDescriptorType + USB_SERIAL_NUMBER // + }, -/** \brief Language code. - * Define the language - * string : 0x0904 - */ -code struct usb_st_language_descriptor usb_language = -{ sizeof(usb_language), STRING, LANGUAGE_ID }; + { // Configuration string descriptor + sizeof(string.st_config), // bLength + STRING, // bDescriptorType + USB_CONFIG_NAME // + }, + + { // Speaker interface string descriptor + sizeof(string.st_speaker), // bLength + STRING, // bDescriptorType + AUDIO_SPEAKER_NAME // + }, + { // Micro interface string descriptor + sizeof(string.st_micro), // bLength + STRING, // bDescriptorType + AUDIO_MICRO_NAME // + }, + + { // TTS string descriptor + sizeof(string.st_tts), // bLength + STRING, // bDescriptorType + AUDIO_TTS_NAME // + }, -/** \brief Configuration string. - * Contain the configuration name - * string : TuxDroid - * size : 8 - */ -code struct usb_st_config usb_config = -{ sizeof(usb_config), STRING, USB_CONFIG_NAME }; + { // Audio interface string descriptor + sizeof(string.st_audio), // bLength + STRING, // bDescriptorType + AUDIO_NORMAL_NAME // + } +}; -/** \brief Microphone interface. - * Contain microphone interface string - * string : TuxDroid - Micro - */ -code struct usb_st_micro_descriptor usb_audio_micro = -{ sizeof(usb_audio_micro), STRING, AUDIO_MICRO_NAME }; - -/** \brief Speaker interface. - * Contain speaker interface string - * string : TuxDroid - Speaker - */ -code struct usb_st_speaker_descriptor usb_audio_speaker = -{ sizeof(usb_audio_speaker), STRING, AUDIO_SPEAKER_NAME }; - -/** \brief TTS interface. - * Contain tts interface string - * string : TuxDroid - TTS - */ -code struct usb_st_tts_descriptor usb_audio_tts = -{ sizeof(usb_audio_tts), STRING, AUDIO_TTS_NAME }; - -/** \brief Audio interface 1. - * Contain the first audio interface name (micro and speaker) - * string : TuxDroid - Audio - */ -code struct usb_st_audio_descriptor usb_audio_normal = -{ sizeof(usb_audio_normal), STRING, AUDIO_NORMAL_NAME }; - - /** \brief General structure. * This structure contain all the descriptors. */ code struct usb_configuration_s usb_configuration = { - { 9, CONFIGURATION, CONF_LENGTH, NB_INTERFACE, CONF_NB, - CONFIG_STRING_INDEX, CONF_ATTRIBUTES, MAX_POWER}, + { + 9, // bLength + CONFIGURATION, // bDescriptorType + CONF_LENGTH, // wTotalLength + NB_INTERFACE, // bNumInterfaces + CONF_NB, // bConfigurationValue + CONFIG_STRING_INDEX,// iConfiguration + CONF_ATTRIBUTES, // bmAttributes + MAX_POWER // MaxPower + }, //------------------------------------------------------------------------- // Audio Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 13:07:11 UTC (rev 1200) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 14:20:56 UTC (rev 1201) @@ -270,70 +270,6 @@ uint8_t bInterval; /**< Interval for polling EP in ms */ }; -struct usb_st_manufacturer -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[USB_MN_LENGTH];/**< unicode characters */ -}; - -struct usb_st_product -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[USB_PN_LENGTH];/**< unicode characters */ -}; - -struct usb_st_serial_number -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[USB_SN_LENGTH];/**< unicode characters */ -}; - -struct usb_st_config -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[USB_CONFIG_LENGTH];/**< unicode characters */ -}; - -struct usb_st_language_descriptor -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[USB_CONFIG_LENGTH]; /**< language id */ -}; - -struct usb_st_speaker_descriptor -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[AUDIO_SPEAKER_LENGTH]; /**< language id */ -}; - -struct usb_st_micro_descriptor -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[AUDIO_MICRO_LENGTH]; /**< language id */ -}; - -struct usb_st_tts_descriptor -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[AUDIO_TTS_LENGTH]; /**< language id */ -}; - - -struct usb_st_audio_descriptor -{ - uint8_t bLength; /**< size of this descriptor in bytes */ - uint8_t bDescriptorType; /**< STRING descriptor type */ - uint16_t wstring[AUDIO_NORMAL_LENGTH]; /**< language id */ -}; - /* HID specific */ struct usb_hid_descriptor { @@ -594,18 +530,100 @@ }; /* @} */ +/** \name String descriptors + * @{ */ +struct usb_st_language_descriptor +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[USB_CONFIG_LENGTH]; /**< language id */ +}; +struct usb_st_manufacturer +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[USB_MN_LENGTH];/**< unicode characters */ +}; + +struct usb_st_product +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[USB_PN_LENGTH];/**< unicode characters */ +}; + +struct usb_st_serial_number +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[USB_SN_LENGTH];/**< unicode characters */ +}; + +struct usb_st_config +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[USB_CONFIG_LENGTH];/**< unicode characters */ +}; + +struct usb_st_speaker_descriptor +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[AUDIO_SPEAKER_LENGTH]; /**< language id */ +}; + +struct usb_st_micro_descriptor +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[AUDIO_MICRO_LENGTH]; /**< language id */ +}; + +struct usb_st_tts_descriptor +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[AUDIO_TTS_LENGTH]; /**< language id */ +}; + + +struct usb_st_audio_descriptor +{ + uint8_t bLength; /**< size of this descriptor in bytes */ + uint8_t bDescriptorType; /**< STRING descriptor type */ + uint16_t wstring[AUDIO_NORMAL_LENGTH]; /**< language id */ +}; +/* @} */ + +/** \name String structure + * This structure contain all the descriptors. + * @{ */ +struct string_s +{ + /*! Language string descriptor */ + struct usb_st_language_descriptor st_language; + /*! Manufacturer string descriptor */ + struct usb_st_manufacturer st_manufacturer; + /*! Product string descriptor */ + struct usb_st_product st_product; + /*! Serial number string descriptor */ + struct usb_st_serial_number st_serial_number; + /*! Configuration string descriptor */ + struct usb_st_config st_config; + /*! Speaker interface string descriptor */ + struct usb_st_speaker_descriptor st_speaker; + /*! Micro interface string descriptor */ + struct usb_st_micro_descriptor st_micro; + /*! TTS Interface string descriptor */ + struct usb_st_tts_descriptor st_tts; + /*! Audio control interface string descriptor */ + struct usb_st_audio_descriptor st_audio; +}; +/* @} */ extern code struct usb_st_device_descriptor usb_device_descriptor; extern code struct usb_configuration_s usb_configuration; +extern code struct string_s string; -extern code struct usb_st_manufacturer usb_manufacturer; -extern code struct usb_st_product usb_product; -extern code struct usb_st_serial_number usb_serial_number; -extern code struct usb_st_language_descriptor usb_language; -extern code struct usb_st_config usb_config; -extern code struct usb_st_micro_descriptor usb_audio_micro; -extern code struct usb_st_speaker_descriptor usb_audio_speaker; -extern code struct usb_st_tts_descriptor usb_audio_tts; -extern code struct usb_st_audio_descriptor usb_audio_normal; - #endif // _USB_DESC_H_ Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 13:07:11 UTC (rev 1200) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 14:20:56 UTC (rev 1201) @@ -436,73 +436,56 @@ #endif case STRING: #ifdef USB_ENUM_DEBUG - printf("STRING "); + printf("STRING %BX", string_type); #endif switch (string_type) - { + { case LANG_ID: - data_to_transfer = sizeof (usb_language); - pbuffer = &(usb_language.bLength); -#ifdef USB_ENUM_DEBUG - printf("LANG_ID "); -#endif + data_to_transfer = sizeof (string.st_language); + pbuffer = &(string.st_language.bLength); break; + case MAN_STRING_INDEX: - data_to_transfer = sizeof (usb_manufacturer); - pbuffer = &(usb_manufacturer.bLength); -#ifdef USB_ENUM_DEBUG - printf("MAN_STRING_INDEX "); -#endif + data_to_transfer = sizeof (string.st_manufacturer); + pbuffer = &(string.st_manufacturer.bLength); break; case PROD_STRING_INDEX: - data_to_transfer = sizeof (usb_product); - pbuffer = &(usb_product.bLength); -#ifdef USB_ENUM_DEBUG - printf("PROD_STRING_INDEX "); -#endif + data_to_transfer = sizeof (string.st_product); + pbuffer = &(string.st_product.bLength); break; case SN_STRING_INDEX: - data_to_transfer = sizeof (usb_serial_number); - pbuffer = &(usb_serial_number.bLength); -#ifdef USB_ENUM_DEBUG - printf("SN_STRING_INDEX "); -#endif + data_to_transfer = sizeof (string.st_serial_number); + pbuffer = &(string.st_serial_number.bLength); break; case CONFIG_STRING_INDEX: - data_to_transfer = sizeof (usb_config); - pbuffer = &(usb_config.bLength); -#ifdef USB_ENUM_DEBUG - printf("CONFIG_STRING_INDEX "); -#endif + data_to_transfer = sizeof (string.st_config); + pbuffer = &(string.st_config.bLength); break; case AUDIO_MICRO_INDEX: - data_to_transfer = sizeof (usb_audio_micro); - pbuffer = &(usb_audio_micro.bLength); + data_to_transfer = sizeof (string.st_micro); + pbuffer = &(string.st_micro.bLength); break; case AUDIO_SPEAKER_INDEX: - data_to_transfer = sizeof (usb_audio_speaker); - pbuffer = &(usb_audio_speaker.bLength); + data_to_transfer = sizeof (string.st_speaker); + pbuffer = &(string.st_speaker.bLength); break; case AUDIO_TTS_INDEX: - data_to_transfer = sizeof (usb_audio_tts); - pbuffer = &(usb_audio_tts.bLength); + data_to_transfer = sizeof (string.st_tts); + pbuffer = &(string.st_tts.bLength); break; case AUDIO_NORMAL_INDEX: - data_to_transfer = sizeof (usb_audio_normal); - pbuffer = &(usb_audio_normal.bLength); + data_to_transfer = sizeof (string.st_audio); + pbuffer = &(string.st_audio.bLength); break; default: -#ifdef USB_ENUM_DEBUG - printf("UNKNOWN_STRING_INDEX "); -#endif Usb_clear_rx_setup(); stall_request(); Usb_clear_DIR(); |
From: Paul_R <c2m...@c2...> - 2008-05-23 13:08:20
|
Author: Paul_R Date: 2008-05-23 15:07:11 +0200 (Fri, 23 May 2008) New Revision: 1200 Modified: firmware/fuxusb/trunk/src/fifo_mic.c firmware/fuxusb/trunk/src/fifo_mic.h Log: * Added const attribute to the parameter of FIFO_MIC_put_n Modified: firmware/fuxusb/trunk/src/fifo_mic.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 13:05:05 UTC (rev 1199) +++ firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 13:07:11 UTC (rev 1200) @@ -78,7 +78,7 @@ * be previously selected. * \ingroup fifo_mic */ -void FIFO_MIC_put_n(uint8_t n) +void FIFO_MIC_put_n(uint8_t const n) { uint8_t data i; Modified: firmware/fuxusb/trunk/src/fifo_mic.h =================================================================== --- firmware/fuxusb/trunk/src/fifo_mic.h 2008-05-23 13:05:05 UTC (rev 1199) +++ firmware/fuxusb/trunk/src/fifo_mic.h 2008-05-23 13:07:11 UTC (rev 1200) @@ -31,7 +31,7 @@ extern bit Fifoready_MIC; extern void FIFO_MIC_init (void); -extern void FIFO_MIC_put_n (uint8_t n); +extern void FIFO_MIC_put_n (uint8_t const n); extern uint8_t FIFO_MIC_get (void); #endif /*_FIFO_MIC_H_*/ |
From: Paul_R <c2m...@c2...> - 2008-05-23 13:05:04
|
Author: Paul_R Date: 2008-05-23 15:05:05 +0200 (Fri, 23 May 2008) New Revision: 1199 Modified: firmware/fuxusb/trunk/src/fifo_stt.c firmware/fuxusb/trunk/src/fifo_stt.h Log: * Optimized fifoSTT functions Modified: firmware/fuxusb/trunk/src/fifo_stt.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-23 12:02:12 UTC (rev 1198) +++ firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-23 13:05:05 UTC (rev 1199) @@ -71,14 +71,15 @@ * \param Data The data to push. * \ingroup fifo_stt */ -void FIFO_STT_put (uint8_t Data) +void FIFO_STT_put (uint8_t const data Data) { if(FifoOverLoad_STT) { FIFO_STT_flush(); - } - FifoTbl_STT[FifoIn_STT_Idx] = Data; // Put data into the FIFO - FifoIn_STT_Idx++; // Update FIFO in index + } + + FifoTbl_STT[FifoIn_STT_Idx ++] = Data; // Put data into the FIFO + if (FifoIn_STT_Idx == FIFO_STT_OVERLOAD) // FIFO Overload { FifoOverLoad_STT = 1; @@ -90,12 +91,7 @@ * \return The popped byte. * \ingroup fifo_stt */ -uint8_t FIFO_STT_get (void) +uint8_t FIFO_STT_get(void) { - uint8_t Data; - - Data = FifoTbl_STT[FifoOut_STT_Idx]; - FifoOut_STT_Idx++; - - return (Data); + return FifoTbl_STT[FifoOut_STT_Idx ++]; } Modified: firmware/fuxusb/trunk/src/fifo_stt.h =================================================================== --- firmware/fuxusb/trunk/src/fifo_stt.h 2008-05-23 12:02:12 UTC (rev 1198) +++ firmware/fuxusb/trunk/src/fifo_stt.h 2008-05-23 13:05:05 UTC (rev 1199) @@ -32,9 +32,9 @@ extern data uint8_t FifoIn_STT_Idx; extern void FIFO_STT_init (void); -extern void FIFO_STT_put (uint8_t Data); +extern void FIFO_STT_put (uint8_t const data Data); extern uint8_t FIFO_STT_get (void); -#define FIFO_STT_flush() FIFO_STT_init() +#define FIFO_STT_flush() FIFO_STT_init() #endif /*_FIFO_STT_H_*/ |
From: Paul_R <c2m...@c2...> - 2008-05-23 12:10:28
|
Author: Paul_R Date: 2008-05-23 14:02:12 +0200 (Fri, 23 May 2008) New Revision: 1198 Modified: firmware/fuxusb/trunk/src/fifo_mic.c firmware/fuxusb/trunk/src/fifo_spk.c firmware/fuxusb/trunk/src/global.c firmware/fuxusb/trunk/src/global.h Log: * Improved the mic and speaker FIFOs Modified: firmware/fuxusb/trunk/src/fifo_mic.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 10:36:07 UTC (rev 1197) +++ firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 12:02:12 UTC (rev 1198) @@ -32,7 +32,7 @@ /** \name Fifo's constants * @{ */ /** Buffer size */ -#define FIFOTBL_MIC_MAX 52 +#define FIFOTBL_MIC_MAX 64 /** Overload value */ #define FIFO_MIC_OVERLOAD FIFOTBL_MIC_MAX - 1 /** Ready threshold. This value allow to fill the fifo */ @@ -44,7 +44,7 @@ * access time. * @{ */ /** Fifo buffer */ -uint8_t FifoTbl_MIC[FIFOTBL_MIC_MAX]; +uint8_t idata FifoTbl_MIC[FIFOTBL_MIC_MAX]; /** In index */ uint8_t data FifoIn_MIC_Idx; /** Out index */ @@ -83,27 +83,25 @@ uint8_t data i; i = n; - do { - FifoOut_MIC_cmpt++; - if (FifoOut_MIC_cmpt >= FIFO_MIC_READY_VALUE) + do + { + if (++ FifoOut_MIC_cmpt >= FIFO_MIC_READY_VALUE) { - Fifoready_MIC = 1; + Fifoready_MIC = 1; + + if (FifoOut_MIC_cmpt == FIFO_MIC_OVERLOAD) + { + FifoOut_MIC_cmpt --; + return; + } } - if (FifoOut_MIC_cmpt == FIFO_MIC_OVERLOAD) - { - FifoOut_MIC_cmpt--; - return; - } + FifoTbl_MIC[FifoIn_MIC_Idx ++] = received_rf_data[n - i]; - FifoTbl_MIC[FifoIn_MIC_Idx] = received_rf_data[n - i]; - FifoIn_MIC_Idx++; // Update FIFO in index if (FifoIn_MIC_Idx == FIFOTBL_MIC_MAX) { FifoIn_MIC_Idx = 0; } - - i--; - } while(i); + } while (-- i); } /** @@ -113,36 +111,19 @@ */ uint8_t FIFO_MIC_get (void) { - uint8_t data Data; - - if (FifoOut_MIC_cmpt == 0) + if (!FifoOut_MIC_cmpt) { Fifoready_MIC = 0; + return (FifoOut_MIC_Idx) ? FifoTbl_MIC[FifoOut_MIC_Idx-1] \ + : FifoTbl_MIC[FIFOTBL_MIC_MAX-1]; } - if (FifoOut_MIC_cmpt == 0) - { - if (FifoOut_MIC_Idx == 0) - { - Data = FifoTbl_MIC[FIFOTBL_MIC_MAX-1]; - } - else - { - Data = FifoTbl_MIC[FifoOut_MIC_Idx-1]; - } - return Data; - } - else - { - FifoOut_MIC_cmpt--; - } + FifoOut_MIC_cmpt--; - Data = FifoTbl_MIC[FifoOut_MIC_Idx]; - FifoOut_MIC_Idx++; - if (FifoOut_MIC_Idx == FIFOTBL_MIC_MAX) + if (++ FifoOut_MIC_Idx == FIFOTBL_MIC_MAX) { FifoOut_MIC_Idx = 0; } - return (Data); + return FifoTbl_MIC[FifoOut_MIC_Idx]; } Modified: firmware/fuxusb/trunk/src/fifo_spk.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_spk.c 2008-05-23 10:36:07 UTC (rev 1197) +++ firmware/fuxusb/trunk/src/fifo_spk.c 2008-05-23 12:02:12 UTC (rev 1198) @@ -32,7 +32,7 @@ /** \name Fifo's constants * @{ */ /** Buffer size */ -#define FIFOTBL_SPK_MAX 52 +#define FIFOTBL_SPK_MAX 64 /** Overload value */ #define FIFO_SPK_OVERLOAD FIFOTBL_SPK_MAX /** Ready threshold. This value allow to empty the fifo */ @@ -81,38 +81,27 @@ */ void FIFO_SPK_put_n (uint8_t const n) { - uint8_t i = n; - uint8_t FilterByte; + uint8_t data i = n; + do - { - FifoOut_SPK_cmpt++; - if (FifoOut_SPK_cmpt >= FIFO_SPK_READY_VALUE_MAX) + { + if (++ FifoOut_SPK_cmpt >= FIFO_SPK_READY_VALUE_MAX) { Fifoready_SPK = 1; // FIFO ready to be empty - } - if (FifoOut_SPK_cmpt == FIFO_SPK_OVERLOAD) // FIFO Overload - { - FifoOut_SPK_cmpt--; - return; - } - FilterByte = Usb_read_byte(); // Put data into the FIFO - if(!FilterByte) - { - FifoTbl_SPK[FifoIn_SPK_Idx] = 0x01; + if (FifoOut_SPK_cmpt == FIFO_SPK_OVERLOAD) + { + FifoOut_SPK_cmpt --; + return; + } } - else - { - FifoTbl_SPK[FifoIn_SPK_Idx] = FilterByte; - } + FifoTbl_SPK[FifoIn_SPK_Idx ++] = Usb_read_byte(); - FifoIn_SPK_Idx++; // Update FIFO in index if (FifoIn_SPK_Idx == FIFOTBL_SPK_MAX) { FifoIn_SPK_Idx = 0; } - i--; - } while (i); + } while (-- i); } /** @@ -122,36 +111,22 @@ */ uint8_t FIFO_SPK_get(void) { - uint8_t Data; - if (FifoOut_SPK_cmpt < FIFO_SPK_READY_VALUE_MIN) { Fifoready_SPK = 0; // FIFO empty - } - - if (FifoOut_SPK_cmpt == 0) // FIFO Underload - { - if (FifoOut_SPK_Idx == 0) + if (FifoOut_SPK_cmpt == 0) // FIFO Underload { - Data = FifoTbl_SPK[FIFOTBL_SPK_MAX-1]; + return FifoOut_SPK_Idx ? FifoTbl_SPK[FifoOut_SPK_Idx-1] \ + : FifoTbl_SPK[FIFOTBL_SPK_MAX-1]; } - else - { - Data = FifoTbl_SPK[FifoOut_SPK_Idx-1]; - } - return Data; } - else - { - FifoOut_SPK_cmpt--; - } - Data = FifoTbl_SPK[FifoOut_SPK_Idx]; - FifoOut_SPK_Idx++; - if (FifoOut_SPK_Idx == FIFOTBL_SPK_MAX) + FifoOut_SPK_cmpt--; + + if (++ FifoOut_SPK_Idx == FIFOTBL_SPK_MAX) { FifoOut_SPK_Idx = 0; } - return (Data); + return FifoTbl_SPK[FifoOut_SPK_Idx]; } Modified: firmware/fuxusb/trunk/src/global.c =================================================================== --- firmware/fuxusb/trunk/src/global.c 2008-05-23 10:36:07 UTC (rev 1197) +++ firmware/fuxusb/trunk/src/global.c 2008-05-23 12:02:12 UTC (rev 1198) @@ -37,7 +37,7 @@ /* \name Buffers * @{ */ /** Commands received on the CMD_OUT EP. The EP size is 64 */ -uint8_t idata command_received[64]; +uint8_t command_received[64]; /** Data received from the RF. The maximum byte in a frame is 34 */ uint8_t received_rf_data[34]; /** Commands received from USB for the RF. */ Modified: firmware/fuxusb/trunk/src/global.h =================================================================== --- firmware/fuxusb/trunk/src/global.h 2008-05-23 10:36:07 UTC (rev 1197) +++ firmware/fuxusb/trunk/src/global.h 2008-05-23 12:02:12 UTC (rev 1198) @@ -218,7 +218,7 @@ extern uint8_t i2c_wait_counter; /* USB buffers */ -extern uint8_t idata command_received[]; +extern uint8_t command_received[]; extern uint8_t received_rf_data[]; extern uint8_t idata rf_commands[]; |
From: Paul_R <c2m...@c2...> - 2008-05-23 10:36:12
|
Author: Paul_R Date: 2008-05-23 12:36:07 +0200 (Fri, 23 May 2008) New Revision: 1197 Modified: firmware/fuxusb/trunk/fuxusb.Opt firmware/fuxusb/trunk/src/fifo_mic.c firmware/fuxusb/trunk/src/fifo_spk.c firmware/fuxusb/trunk/src/fifo_stt.c firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_enum.c firmware/fuxusb/trunk/src/usb_ep.c firmware/fuxusb/trunk/src/usb_task.c Log: * Typo. Modified: firmware/fuxusb/trunk/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/trunk/src/fifo_mic.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -86,7 +86,9 @@ do { FifoOut_MIC_cmpt++; if (FifoOut_MIC_cmpt >= FIFO_MIC_READY_VALUE) + { Fifoready_MIC = 1; + } if (FifoOut_MIC_cmpt == FIFO_MIC_OVERLOAD) { FifoOut_MIC_cmpt--; @@ -95,8 +97,10 @@ FifoTbl_MIC[FifoIn_MIC_Idx] = received_rf_data[n - i]; FifoIn_MIC_Idx++; // Update FIFO in index - if (FifoIn_MIC_Idx == FIFOTBL_MIC_MAX) + if (FifoIn_MIC_Idx == FIFOTBL_MIC_MAX) + { FifoIn_MIC_Idx = 0; + } i--; } while(i); @@ -112,13 +116,19 @@ uint8_t data Data; if (FifoOut_MIC_cmpt == 0) + { Fifoready_MIC = 0; + } if (FifoOut_MIC_cmpt == 0) { if (FifoOut_MIC_Idx == 0) + { Data = FifoTbl_MIC[FIFOTBL_MIC_MAX-1]; + } else - Data = FifoTbl_MIC[FifoOut_MIC_Idx-1]; + { + Data = FifoTbl_MIC[FifoOut_MIC_Idx-1]; + } return Data; } @@ -130,7 +140,9 @@ Data = FifoTbl_MIC[FifoOut_MIC_Idx]; FifoOut_MIC_Idx++; if (FifoOut_MIC_Idx == FIFOTBL_MIC_MAX) - FifoOut_MIC_Idx = 0; + { + FifoOut_MIC_Idx = 0; + } return (Data); } Modified: firmware/fuxusb/trunk/src/fifo_spk.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_spk.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/fifo_spk.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -87,7 +87,9 @@ { FifoOut_SPK_cmpt++; if (FifoOut_SPK_cmpt >= FIFO_SPK_READY_VALUE_MAX) + { Fifoready_SPK = 1; // FIFO ready to be empty + } if (FifoOut_SPK_cmpt == FIFO_SPK_OVERLOAD) // FIFO Overload { FifoOut_SPK_cmpt--; @@ -96,15 +98,21 @@ FilterByte = Usb_read_byte(); // Put data into the FIFO if(!FilterByte) + { FifoTbl_SPK[FifoIn_SPK_Idx] = 0x01; + } else + { FifoTbl_SPK[FifoIn_SPK_Idx] = FilterByte; + } FifoIn_SPK_Idx++; // Update FIFO in index - if (FifoIn_SPK_Idx == FIFOTBL_SPK_MAX) + if (FifoIn_SPK_Idx == FIFOTBL_SPK_MAX) + { FifoIn_SPK_Idx = 0; + } i--; - }while(i); + } while (i); } /** @@ -117,14 +125,20 @@ uint8_t Data; if (FifoOut_SPK_cmpt < FIFO_SPK_READY_VALUE_MIN) + { Fifoready_SPK = 0; // FIFO empty + } if (FifoOut_SPK_cmpt == 0) // FIFO Underload { if (FifoOut_SPK_Idx == 0) + { Data = FifoTbl_SPK[FIFOTBL_SPK_MAX-1]; + } else - Data = FifoTbl_SPK[FifoOut_SPK_Idx-1]; + { + Data = FifoTbl_SPK[FifoOut_SPK_Idx-1]; + } return Data; } else @@ -133,8 +147,11 @@ } Data = FifoTbl_SPK[FifoOut_SPK_Idx]; FifoOut_SPK_Idx++; + if (FifoOut_SPK_Idx == FIFOTBL_SPK_MAX) - FifoOut_SPK_Idx = 0; + { + FifoOut_SPK_Idx = 0; + } return (Data); } Modified: firmware/fuxusb/trunk/src/fifo_stt.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -80,9 +80,9 @@ FifoTbl_STT[FifoIn_STT_Idx] = Data; // Put data into the FIFO FifoIn_STT_Idx++; // Update FIFO in index if (FifoIn_STT_Idx == FIFO_STT_OVERLOAD) // FIFO Overload - FifoOverLoad_STT = 1; - - + { + FifoOverLoad_STT = 1; + } } /** Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 10:36:07 UTC (rev 1197) @@ -30,7 +30,7 @@ #include "version.h" /** Enable / Disable the HID interface */ -#define HID_DEVICE +#undef HID_DEVICE /** \name Descriptors type * @{ */ Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -207,7 +207,6 @@ case SET_DESCRIPTOR: case SYNCH_FRAME: default: - #ifdef USB_ENUM_DEBUG printf("Unknown Request "); #endif @@ -307,7 +306,9 @@ #endif } else + { stall_request(); + } } /** @@ -406,141 +407,119 @@ switch (descriptor_type) { case DEVICE: - { - data_to_transfer = sizeof (usb_device_descriptor); - pbuffer = &(usb_device_descriptor.bLength); + data_to_transfer = sizeof (usb_device_descriptor); + pbuffer = &(usb_device_descriptor.bLength); #ifdef USB_ENUM_DEBUG - printf("DEVICE "); + printf("DEVICE "); #endif - break; - } + break; + case CONFIGURATION: - { - data_to_transfer = sizeof (usb_configuration); - pbuffer = &(usb_configuration.cfg.bLength); + data_to_transfer = sizeof (usb_configuration); + pbuffer = &(usb_configuration.cfg.bLength); #ifdef USB_ENUM_DEBUG - printf("CONFIGURATION "); + printf("CONFIGURATION "); #endif - break; - } + break; + #ifdef HID_DEVICE case REPORT: - { data_to_transfer = SIZE_OF_REPORT; pbuffer = &(usb_configuration.rep[0]); break; - } + case HID: - { data_to_transfer = sizeof(usb_configuration.HIDStandardDescriptor); pbuffer = &(usb_configuration.HIDStandardDescriptor.bLength); break; - } + #endif case STRING: - { #ifdef USB_ENUM_DEBUG - printf("STRING "); + printf("STRING "); #endif - switch (string_type) - { - case LANG_ID: - { - data_to_transfer = sizeof (usb_language); - pbuffer = &(usb_language.bLength); + switch (string_type) + { + case LANG_ID: + data_to_transfer = sizeof (usb_language); + pbuffer = &(usb_language.bLength); #ifdef USB_ENUM_DEBUG - printf("LANG_ID "); + printf("LANG_ID "); #endif - break; - } - case MAN_STRING_INDEX: - { - data_to_transfer = sizeof (usb_manufacturer); - pbuffer = &(usb_manufacturer.bLength); + break; + case MAN_STRING_INDEX: + data_to_transfer = sizeof (usb_manufacturer); + pbuffer = &(usb_manufacturer.bLength); #ifdef USB_ENUM_DEBUG - printf("MAN_STRING_INDEX "); + printf("MAN_STRING_INDEX "); #endif - break; - } - case PROD_STRING_INDEX: - { - data_to_transfer = sizeof (usb_product); - pbuffer = &(usb_product.bLength); + break; + + case PROD_STRING_INDEX: + data_to_transfer = sizeof (usb_product); + pbuffer = &(usb_product.bLength); #ifdef USB_ENUM_DEBUG - printf("PROD_STRING_INDEX "); + printf("PROD_STRING_INDEX "); #endif - break; - } - case SN_STRING_INDEX: - { - data_to_transfer = sizeof (usb_serial_number); - pbuffer = &(usb_serial_number.bLength); + break; + + case SN_STRING_INDEX: + data_to_transfer = sizeof (usb_serial_number); + pbuffer = &(usb_serial_number.bLength); #ifdef USB_ENUM_DEBUG - printf("SN_STRING_INDEX "); + printf("SN_STRING_INDEX "); #endif - break; + break; - } - case CONFIG_STRING_INDEX: - { - data_to_transfer = sizeof (usb_config); - pbuffer = &(usb_config.bLength); + case CONFIG_STRING_INDEX: + data_to_transfer = sizeof (usb_config); + pbuffer = &(usb_config.bLength); #ifdef USB_ENUM_DEBUG - printf("CONFIG_STRING_INDEX "); + printf("CONFIG_STRING_INDEX "); #endif - break; + break; - } - case AUDIO_MICRO_INDEX: - { - data_to_transfer = sizeof (usb_audio_micro); - pbuffer = &(usb_audio_micro.bLength); - break; - } - case AUDIO_SPEAKER_INDEX: - { - data_to_transfer = sizeof (usb_audio_speaker); - pbuffer = &(usb_audio_speaker.bLength); - break; - } - case AUDIO_TTS_INDEX: - { - data_to_transfer = sizeof (usb_audio_tts); - pbuffer = &(usb_audio_tts.bLength); - break; - } - case AUDIO_NORMAL_INDEX: - { - data_to_transfer = sizeof (usb_audio_normal); - pbuffer = &(usb_audio_normal.bLength); - break; - } - default: - { -#ifdef USB_ENUM_DEBUG - printf("UNKNOWN_STRING_INDEX "); -#endif - Usb_clear_rx_setup(); - stall_request(); - Usb_clear_DIR(); - return; - } - } + case AUDIO_MICRO_INDEX: + data_to_transfer = sizeof (usb_audio_micro); + pbuffer = &(usb_audio_micro.bLength); break; - } - default: - { + + case AUDIO_SPEAKER_INDEX: + data_to_transfer = sizeof (usb_audio_speaker); + pbuffer = &(usb_audio_speaker.bLength); + break; + + case AUDIO_TTS_INDEX: + data_to_transfer = sizeof (usb_audio_tts); + pbuffer = &(usb_audio_tts.bLength); + break; + + case AUDIO_NORMAL_INDEX: + data_to_transfer = sizeof (usb_audio_normal); + pbuffer = &(usb_audio_normal.bLength); + break; + + default: #ifdef USB_ENUM_DEBUG - printf("UNKNOWN"); + printf("UNKNOWN_STRING_INDEX "); #endif Usb_clear_rx_setup(); stall_request(); Usb_clear_DIR(); -#ifdef USB_ENUM_DEBUG - printf("1"); -#endif return; } + break; + default: +#ifdef USB_ENUM_DEBUG + printf("UNKNOWN"); +#endif + Usb_clear_rx_setup(); + stall_request(); + Usb_clear_DIR(); +#ifdef USB_ENUM_DEBUG + printf("1"); +#endif + return; } ACC = Usb_read_byte(); /* don't care of wIndex field */ @@ -551,8 +530,14 @@ if (wLength > data_to_transfer) { - if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = True; } - else { zlp = False; } /* no need of zero length packet */ + if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) + { + zlp = True; + } + else + { + zlp = False; + } /* no need of zero length packet */ } else { @@ -711,12 +696,12 @@ Usb_clear_rx_setup(); stall_request(); } - if (bmRequestType == INTERFACE_TYPE) + else if (bmRequestType == INTERFACE_TYPE) { Usb_clear_rx_setup(); stall_request(); } - if (bmRequestType == ENDPOINT_TYPE) + else if (bmRequestType == ENDPOINT_TYPE) { if (Usb_read_byte() == 0x00) { @@ -724,23 +709,20 @@ switch (Usb_read_byte()) /* check wIndex */ { case ENDPOINT_1: - { - Usb_select_ep(EP_IN); - Usb_set_stall_request(); - Usb_select_ep(EP_CONTROL); - endpoint_status[EP_IN] = 0x01; - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } + Usb_select_ep(EP_IN); + Usb_set_stall_request(); + Usb_select_ep(EP_CONTROL); + endpoint_status[EP_IN] = 0x01; + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + default: - { - Usb_clear_rx_setup(); - stall_request(); - break; - } + Usb_clear_rx_setup(); + stall_request(); + break; } } } @@ -757,12 +739,12 @@ Usb_clear_rx_setup(); stall_request(); } - if (bmRequestType == INTERFACE_TYPE) + else if (bmRequestType == INTERFACE_TYPE) { Usb_clear_rx_setup(); stall_request(); } - if (bmRequestType == ENDPOINT_TYPE) + else if (bmRequestType == ENDPOINT_TYPE) { if (Usb_read_byte() == 0x00) { @@ -770,32 +752,28 @@ switch (Usb_read_byte()) /* check wIndex */ { case ENDPOINT_1: - { - Usb_select_ep(EP_IN); - Usb_clear_stall_request(); - usb_reset_endpoint(EP_IN); - Usb_select_ep(EP_CONTROL); - endpoint_status[EP_IN] = 0x00; - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } + Usb_select_ep(EP_IN); + Usb_clear_stall_request(); + usb_reset_endpoint(EP_IN); + Usb_select_ep(EP_CONTROL); + endpoint_status[EP_IN] = 0x00; + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + case ENDPOINT_0: - { - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + default: - { - Usb_clear_rx_setup(); - stall_request(); - break; - } + Usb_clear_rx_setup(); + stall_request(); + break; } } } Modified: firmware/fuxusb/trunk/src/usb_ep.c =================================================================== --- firmware/fuxusb/trunk/src/usb_ep.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/usb_ep.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -66,7 +66,9 @@ { Usb_select_ep(EP_CONTROL); if (Usb_setup_received()) - usb_enumeration_process(); + { + usb_enumeration_process(); + } } /* EP1 : Microphone EP */ @@ -174,7 +176,9 @@ if (tts_pipe_selected) { if(usb_get_nb_byte()) + { FIFO_SPK_put_n(8); + } } Usb_clear_rx(); } @@ -190,7 +194,9 @@ if (!tts_pipe_selected) { if(usb_get_nb_byte()) + { FIFO_SPK_put_n(8); + } } Usb_clear_rx(); } Modified: firmware/fuxusb/trunk/src/usb_task.c =================================================================== --- firmware/fuxusb/trunk/src/usb_task.c 2008-05-23 09:53:58 UTC (rev 1196) +++ firmware/fuxusb/trunk/src/usb_task.c 2008-05-23 10:36:07 UTC (rev 1197) @@ -66,13 +66,19 @@ void usb_task(void) { if (Usb_resume()) + { resume_usb(); + } else if (Usb_reset()) + { reset_usb(); + } else if (Usb_suspend()) + { suspend_usb(); + } /* * When the SOF is detected, manage the LEDs. @@ -83,15 +89,17 @@ led_behavior(); /* This counter is used to temporise the i2c task. */ - if (i2c_wait_counter) + if (i2c_wait_counter) + { i2c_wait_counter--; + } } /* * Load the microphone EP if it's not already loaded and if the micro * fifo is ready. */ + fill_mic_ep(); - fill_mic_ep(); /* * Prepare the statuses when a request has been received */ @@ -101,5 +109,7 @@ * Parse all endpoints when an EP interrupt has been trigged */ if(Usb_endpoint_interrupt()) + { endpoints_parser(); + } } |
From: Paul_R <c2m...@c2...> - 2008-05-23 09:53:54
|
Author: Paul_R Date: 2008-05-23 11:53:58 +0200 (Fri, 23 May 2008) New Revision: 1196 Modified: firmware/fuxusb/trunk/src/misc.c firmware/fuxusb/trunk/src/rf.c Log: * Added comments on is_rf_online function. * Improved the LED behavior function. Added a new LED behavior for the bootloader mode. Modified: firmware/fuxusb/trunk/src/misc.c =================================================================== --- firmware/fuxusb/trunk/src/misc.c 2008-05-23 09:30:15 UTC (rev 1195) +++ firmware/fuxusb/trunk/src/misc.c 2008-05-23 09:53:58 UTC (rev 1196) @@ -28,10 +28,31 @@ #include "config.h" #include "global.h" #include "misc.h" +#include "bootloader.h" -/** Start of frame counter */ -static uint16_t usb_sof_counter = 0; +/** \name LED ON/OFF values + * @{ */ +/** \name RF online + * @{ */ +#define ONLINE_LED_ON 0x10 +#define ONLINE_LED_OFF 0x20 +/* @} */ +/** \name RF offline + * @{ */ +#define OFFLINE_LED_ON 0x300 +#define OFFLINE_LED_OFF 0x400 +/* @} */ + +/** \name Bootloader active + * @{ */ +#define BL_LED_ON 0x100 +#define BL_LED_OFF 0x120 +/* @} */ +/* @} */ + +static void blink_led(uint16_t const on_value, uint16_t const off_value); + /** * \brief Control the LED behavior. * The LED blink slowly when the RF is disconnected, and fast when Tux is @@ -40,31 +61,43 @@ * \ingroup misc */ void led_behavior(void) -{ +{ + /* Bootloader mode is activated */ + if (i2c_bootloading_Flag) + { + blink_led(BL_LED_ON, BL_LED_OFF); + } + /* RF is online */ + else if (!RF_OFFLINE) + { + blink_led(ONLINE_LED_ON, ONLINE_LED_OFF); + } + /* RF is offline */ + else + { + blink_led(OFFLINE_LED_ON, OFFLINE_LED_OFF); + } +} + +/** + * \brief Switch on/off the LED depending of the condition. + * \param on_value The SOF value to switch on the LED. + * \param off_value The SOF value to switch off the LED. + */ +static void blink_led(uint16_t const on_value, uint16_t const off_value) +{ + /** Start of frame counter */ + static uint16_t usb_sof_counter = 0; + usb_sof_counter ++; - if(RF_OFFLINE) + if (usb_sof_counter == on_value) { - if (usb_sof_counter == 0x01) - Led_0_off(); - else if (usb_sof_counter == 0x300) - Led_0_on(); - else if (usb_sof_counter == 0x400) - usb_sof_counter = 0x00; + Led_0_on(); } - else + else if (usb_sof_counter >= off_value) { - if (usb_sof_counter == 0x01) - Led_0_off(); - else if (usb_sof_counter == 0x10) - Led_0_on(); - else if (usb_sof_counter == 0x20) - usb_sof_counter = 0x00; - /* - * When the RF is connected, the counter can be greater than 0x20. - * If it's greater than the maximum, clear it - */ - else if (usb_sof_counter > 0x20) - usb_sof_counter = 0; - } + Led_0_off(); + usb_sof_counter = 0x00; + } } Modified: firmware/fuxusb/trunk/src/rf.c =================================================================== --- firmware/fuxusb/trunk/src/rf.c 2008-05-23 09:30:15 UTC (rev 1195) +++ firmware/fuxusb/trunk/src/rf.c 2008-05-23 09:53:58 UTC (rev 1196) @@ -58,6 +58,12 @@ rf_reset_signal = 1; } +/** + * \brief Control if the RF is online. + * \return True if the RF is online. + * If the RF is online, this function return True. + * \ingroup rf + */ bit is_rf_online(void) { /* |
From: Paul_R <c2m...@c2...> - 2008-05-23 09:30:14
|
Author: Paul_R Date: 2008-05-23 11:30:15 +0200 (Fri, 23 May 2008) New Revision: 1195 Modified: firmware/fuxusb/trunk/src/main.c firmware/fuxusb/trunk/src/rf.c firmware/fuxusb/trunk/src/rf.h Log: * Added a function to check if the RF is connected, and try to reconnect it if it's disconnected. (rf.c) * Created an init function in main.c Modified: firmware/fuxusb/trunk/src/main.c =================================================================== --- firmware/fuxusb/trunk/src/main.c 2008-05-23 09:14:14 UTC (rev 1194) +++ firmware/fuxusb/trunk/src/main.c 2008-05-23 09:30:15 UTC (rev 1195) @@ -35,6 +35,8 @@ #include "lib_mcu\uart\uart_lib.h" #endif +static void init(void); + /** * The mainloop is divided in three major tasks : * - USB task which parse and control the USB bus This function is always executed, event if the RF is disconnected @@ -44,13 +46,34 @@ */ void main (void) { - /* - * This flag indicate if rf is running or not. - * It's used to restart the RF communication if it has been lost. - */ - static bit rf_is_running = False; + /* init */ + init(); - /* Set X2 mode -> 1 instr. = 6 clock cycles */ + /* Main loop */ + while(1) + { + usb_task(); + + /* Bootloader active */ + if (i2c_bootloading_Flag) + { + i2c_task(); + } + /* Bootloader inactive : if RF is online, process spi_task. */ + else if (is_rf_online()) + { + spi_task(); + } + } +} + +/** + * This function init the dongle. + * \ingroup main + */ +static void init(void) +{ + /* Set X2 mode -> 1 instr. = 6 clock cycles */ Set_x2_mode(); /* Reset the RF card while the USB isn't configured */ @@ -68,33 +91,5 @@ uart_init(); printf("\n== TUX started ==\n"); #endif - - /* Main loop */ - while(1) - { - usb_task(); - - /* Bootloader active */ - if (i2c_bootloading_Flag) - { - i2c_task(); - } - else - { - /* If RF is online, goto spi_task */ - if (!RF_OFFLINE) - { - rf_is_running = True; - spi_task(); - } - /* else, check if the RF must be restarted */ - else - { - if (rf_is_running) - reset_rf(); - new_cmd_enabled = True; - rf_is_running = False; - } - } - } -} \ No newline at end of file +} + Modified: firmware/fuxusb/trunk/src/rf.c =================================================================== --- firmware/fuxusb/trunk/src/rf.c 2008-05-23 09:14:14 UTC (rev 1194) +++ firmware/fuxusb/trunk/src/rf.c 2008-05-23 09:30:15 UTC (rev 1195) @@ -27,6 +27,7 @@ #include "global.h" #include "spi_lib.h" #include "rf.h" +#include "spi_task.h" /** * \brief Restart the RF. @@ -56,3 +57,29 @@ for (i=0; i<64000; i++); rf_reset_signal = 1; } + +bit is_rf_online(void) +{ + /* + * This flag indicate if rf is running or not. + * It's used to restart the RF communication if it has been lost. + */ + static bit rf_is_running = False; + + if (!RF_OFFLINE) + { + rf_is_running = True; + return True; + } + else + { + if (rf_is_running) + { + reset_rf(); + } + new_cmd_enabled = True; + rf_is_running = False; + return False; + } +} + Modified: firmware/fuxusb/trunk/src/rf.h =================================================================== --- firmware/fuxusb/trunk/src/rf.h 2008-05-23 09:14:14 UTC (rev 1194) +++ firmware/fuxusb/trunk/src/rf.h 2008-05-23 09:30:15 UTC (rev 1195) @@ -30,5 +30,6 @@ void reset_rf(void); void rf_start_bootloader(void); +bit is_rf_online(void); #endif // _RF_H_ |
From: Paul_R <c2m...@c2...> - 2008-05-23 09:14:13
|
Author: Paul_R Date: 2008-05-23 11:14:14 +0200 (Fri, 23 May 2008) New Revision: 1194 Modified: firmware/fuxusb/trunk/lib_c/stdint.h Log: * Added stdint to group mcu (doxygen). Modified: firmware/fuxusb/trunk/lib_c/stdint.h =================================================================== --- firmware/fuxusb/trunk/lib_c/stdint.h 2008-05-22 15:24:51 UTC (rev 1193) +++ firmware/fuxusb/trunk/lib_c/stdint.h 2008-05-23 09:14:14 UTC (rev 1194) @@ -11,7 +11,9 @@ Use [u]intN_t if you need exactly N bits. Since these typedefs are mandated by the C99 standard, they are preferred - over rolling your own typedefs. */ + over rolling your own typedefs. + + \ingroup mcu */ /* Integer types */ |
From: Paul_R <c2m...@c2...> - 2008-05-22 15:24:54
|
Author: Paul_R Date: 2008-05-22 17:24:51 +0200 (Thu, 22 May 2008) New Revision: 1193 Modified: firmware/fuxusb/trunk/src/global.h Log: * doc Modified: firmware/fuxusb/trunk/src/global.h =================================================================== --- firmware/fuxusb/trunk/src/global.h 2008-05-22 15:24:30 UTC (rev 1192) +++ firmware/fuxusb/trunk/src/global.h 2008-05-22 15:24:51 UTC (rev 1193) @@ -22,8 +22,26 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -/** \mainpage Fuxusb firmware documentation of the Tux Droid open source robot +/** \mainpage Fuxusb documentation. * + * Firmware for the USB dongle of TuxDroid. + * + * The functionnalities are : + * - A bi-directionnal audio interface with a IN data pipe (microphone) and a + * OUT data pipe (speaker). + * - A bi-directionnal interface to receive commands from the PC and send back + * the statuses. + * + * The audio interfaces are detected by the hosts as audio cards, with the + * following specifications : + * - PCM8 + * - 8kHz / 8bits + * - Isochronous EPs @1ms. + * + * The command interface is detected as a HID device with these specifications: + * - OUT EP - Interrupt - EP size : 64 bytes - polling interval : 1ms + * - IN EP - Interrupt - EP size : 64 bytes - polling interval : 1ms + * * \section SVN SVN repository * http://svn.tuxisalive.com/firmware/fuxusb/trunk */ @@ -31,108 +49,144 @@ /** \defgroup fuxusb USB Dongle for TuxDroid. */ - /** \defgroup main Main function - * \brief Fuxusb main function - * \ingroup fuxusb +/** \defgroup main Main function + * \brief Main function of fuxusb. + * The main loop is organized like this : + * - usb_task -> main usb function + * - i2c_task -> communication function for the bootloader + * - spi_task -> communication function for the RF + * + * The usb_task is always active. spi_task is enabled only if the bootloader + * mode is inactive and if the RF is connected. + * \ingroup fuxusb */ /** * \defgroup usb_task USB Task - \brief Main functions to control the USB bus. - - \ingroup fuxusb + * \brief Main functions to control the USB bus. + * + * From this module, all USB functionnalities are controlled and (if + * necessary) executed. + * The majors tasks are : + * - endpoint parser + * - prepare the status + * - fill the microphone fifo + * - manage the bus (suspend / resume / reset) + * - misc functionnalities (like LED behavior) + * \ingroup fuxusb */ /** - * \defgroup usb_enum USB enumeration process - \brief This module analyze the enumeration requests and send back required - informations. - - \ingroup fuxusb + * \defgroup usb_enum USB enumeration + * \brief This function proceed the enumeration. + * + * When a setup packet is received on the EP0 (control EP), the request is + * analyzed. The requested information is sent back to the host. + * \ingroup fuxusb */ /** * \defgroup usb_desc USB descriptor - \brief This module contain the descriptors structures. - - \ingroup fuxusb + * \brief This module contain the descriptors structures. + * + * The general descriptor is defined in a structure of sub-structure. + * Each sub-structure represents a specific descriptor. + * \ingroup fuxusb */ /** \defgroup usb_ep USB Endpoints * \brief Endpoints control. + * + * This module controls the endpoints. The main function parses all EPs and + * treats the requests. * \ingroup fuxusb */ /** \defgroup usb_cmd USB commands - * \brief Functions to prepare status and parse received commands. + * \brief Specifics function to parse the received commands. + * + * Three types of commands can be received : + * - dongle commands : Commands for the dongle. (ISP mode, reset, etc.). + * - commands for Tux : These commands must be sent by RF for Tux. + * - bootloader commands : Commands for the bootloading process. * \ingroup fuxusb */ /** \defgroup usb_misc USB misc functions * \brief USB misc functions. + * + * Maintenance functions are grouped in this module. * \ingroup fuxusb */ /** \defgroup spi_task SPI task * \brief SPI communication. + * + * This function send/receive commands/statuses on the SPI bus for/from the RF. * \ingroup fuxusb */ /** \defgroup bootloader Bootloader * \brief Bootloader functions. + * + * Functions for the bootloader. In bootloader mode, datas are sent to tux by + * I2C. I2C_task becomes active, and the RF is disabled. * \ingroup fuxusb */ /** \defgroup i2c I2C * \brief I2C functions. + * + * Specifics functions to access and manage the I2C bus. * \ingroup fuxusb */ /** * \defgroup fifo_spk Speaker FIFO - \brief FIFO_SPK is used for the speaker data, received from the USB and sent - to the RF. - - This FIFO are specific for this application and the context. - It's optimized for speed. It's not circular, and the access to the - buffer are direct. - - \ingroup fuxusb + * \brief FIFO_SPK is used for the speaker data, received from the USB and sent + * to the RF. + * + * This FIFO are specific for this application and the context. + * It's optimized for speed. It's not circular, and the access to the + * buffer are direct. + * \ingroup fuxusb */ /** * \defgroup fifo_mic Microphone FIFO - \brief FIFO_MIC used for the microphone data, received from the RF and sent - to the computer. - This FIFO is specific for this application and the context. - It's optimized for speed. It's not circular, and the access to the - buffer are direct. - - \ingroup fuxusb + * \brief FIFO_MIC used for the microphone data, received from the RF and sent + * to the computer. + * This FIFO is specific for this application and the context. + * It's optimized for speed. It's not circular, and the access to the + * buffer are direct. + * \ingroup fuxusb */ /** * \defgroup fifo_stt Status FIFO - \brief FIFO_STT is used for the status data, received from the RF and sent - to the computer. - - This FIFO are specific for this application and the context. - It's optimized for speed. It's not circular, and the access to the - buffer are direct. - - \ingroup fuxusb + * \brief FIFO_STT is used for the status data, received from the RF and sent + * to the computer. + * + * This FIFO are specific for this application and the context. + * It's optimized for speed. It's not circular, and the access to the + * buffer are direct. + * \ingroup fuxusb */ /** \defgroup rf RF * \brief RF functions. + * + * This module contain the specifics functions to manage the RF. * \ingroup fuxusb */ /** \defgroup misc Misc * \brief Misc functions. + * + * This module contain misc. functions. * \ingroup fuxusb */ |
From: Paul_R <c2m...@c2...> - 2008-05-22 15:24:36
|
Author: Paul_R Date: 2008-05-22 17:24:30 +0200 (Thu, 22 May 2008) New Revision: 1192 Modified: firmware/fuxusb/trunk/src/fifo_stt.c firmware/fuxusb/trunk/src/fifo_stt.h Log: * Removed FIFO_STT_flush and created an alias on FIFO_STT_init. Modified: firmware/fuxusb/trunk/src/fifo_stt.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-22 14:00:43 UTC (rev 1191) +++ firmware/fuxusb/trunk/src/fifo_stt.c 2008-05-22 15:24:30 UTC (rev 1192) @@ -67,18 +67,6 @@ } /** - * This function reset all indexes and the byte counter. - * \ingroup fifo_stt - */ -void FIFO_STT_flush (void) -{ - FifoOut_STT_cmpt = 0; - FifoOut_STT_Idx = 0; - FifoIn_STT_Idx = 0; - FifoOverLoad_STT = 0; -} - -/** * \brief Push one byte in the FIFO. * \param Data The data to push. * \ingroup fifo_stt Modified: firmware/fuxusb/trunk/src/fifo_stt.h =================================================================== --- firmware/fuxusb/trunk/src/fifo_stt.h 2008-05-22 14:00:43 UTC (rev 1191) +++ firmware/fuxusb/trunk/src/fifo_stt.h 2008-05-22 15:24:30 UTC (rev 1192) @@ -31,9 +31,10 @@ extern data uint8_t FifoIn_STT_Idx; -extern void FIFO_STT_flush (void); extern void FIFO_STT_init (void); extern void FIFO_STT_put (uint8_t Data); extern uint8_t FIFO_STT_get (void); +#define FIFO_STT_flush() FIFO_STT_init() + #endif /*_FIFO_STT_H_*/ |
From: Paul_R <c2m...@c2...> - 2008-05-22 14:00:42
|
Author: Paul_R Date: 2008-05-22 16:00:43 +0200 (Thu, 22 May 2008) New Revision: 1191 Modified: firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c Log: * Added the motor state status : Status_Position2 frame, last byte. - xxxxxxx1 : Spin left on - xxxxxx1x : Spin right on - xxxxx1xx : Eyes on - xxxx1xxx : Mouth on - xxx1xxxx : Wings on Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2008-05-22 13:40:54 UTC (rev 1190) +++ firmware/tuxcore/trunk/global.h 2008-05-22 14:00:43 UTC (rev 1191) @@ -103,19 +103,23 @@ * gStatus.mot: Motors Status */ -/* gStatus.mot:[0] Spin motor - * xxxxxxx0 === Spin off - * xxxxxxx1 === Spin on */ -#define GSTATUS_MOT_SPIN 0x01 -/* gStatus.mot:[1] Eyes/Mouth motor - * xxxxxx0x === motor off - * xxxxxx1x === motor on */ -#define GSTATUS_MOT_EYES 0x02 -#define GSTATUS_MOT_MOUTH 0x02 -/* gStatus.mot:[2] Wings motor - * xxxxx0xx === Wings off - * xxxxx1xx === Wings on */ -#define GSTATUS_MOT_WINGS 0x04 +/* gStatus.mot:[0:1] Spin motor + * xxxxxx00 === Spin off + * xxxxxx01 === Spin right on + * xxxxxx10 === Spin left on + * xxxxxx11 === undef / impossible */ +#define GSTATUS_MOT_SPINL 0x01 +#define GSTATUS_MOT_SPINR 0x02 +#define GSTATUS_MOT_SPIN_MK 0x03 +/* gStatus.mot:[2] Eyes/Mouth motor + * xxxxx0xx === motor off + * xxxxx1xx === motor on */ +#define GSTATUS_MOT_EYES 0x04 +#define GSTATUS_MOT_MOUTH 0x08 +/* gStatus.mot:[3] Wings motor + * xxxx0xxx === Wings off + * xxxx1xxx === Wings on */ +#define GSTATUS_MOT_WINGS 0x10 /* * gStatus.ir: IR Status @@ -166,7 +170,7 @@ uint8_t batteryS; /* Battery level status */ uint8_t ir; /* IR RC5 code received from tux's remote */ uint8_t pos; /* Poitionning */ - uint8_t mot; + uint8_t mot; /* Motors states */ uint8_t audio_play; uint8_t audio_status; } Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2008-05-22 13:40:54 UTC (rev 1190) +++ firmware/tuxcore/trunk/main.c 2008-05-22 14:00:43 UTC (rev 1191) @@ -258,7 +258,8 @@ queue_cmd_p(STATUS_PORTS_CMD, PINB, PINC, PIND); queue_cmd_p(STATUS_POSITION1_CMD, eyes_move_counter, mouth_move_counter, flippers_move_counter); - queue_cmd_p(STATUS_POSITION2_CMD, spin_move_counter, gStatus.pos, 0); + queue_cmd_p(STATUS_POSITION2_CMD, spin_move_counter, gStatus.pos, + gStatus.mot); if (led_f) { led_f = false; Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2008-05-22 13:40:54 UTC (rev 1190) +++ firmware/tuxcore/trunk/motors.c 2008-05-22 14:00:43 UTC (rev 1191) @@ -820,7 +820,7 @@ */ void stop_spinning(void) { - gStatus.mot &= ~GSTATUS_MOT_SPIN; + gStatus.mot &= ~GSTATUS_MOT_SPIN_MK; spin_move_counter = 0; stop_spin_motor(); } @@ -833,7 +833,7 @@ */ void spin_left(uint8_t const angle, uint8_t const pwm) { - gStatus.mot |= GSTATUS_MOT_SPIN; + gStatus.mot |= GSTATUS_MOT_SPINL; spin_move_counter = angle; /* If the rotation direction is changing and we are not stopped exactly on * the switch (position switch not pressed), we need to increment the angle @@ -857,7 +857,7 @@ */ void spin_right(uint8_t const angle, uint8_t const pwm) { - gStatus.mot |= GSTATUS_MOT_SPIN; + gStatus.mot |= GSTATUS_MOT_SPINR; spin_move_counter = angle; /* If the rotation direction is changing and we are not stopped exactly on * the switch (position switch not pressed), we need to increment the angle |
From: Paul_R <c2m...@c2...> - 2008-05-22 13:40:56
|
Author: Paul_R Date: 2008-05-22 15:40:54 +0200 (Thu, 22 May 2008) New Revision: 1190 Modified: firmware/tuxcore/trunk/motors.c Log: * Clear the movement counters when a stop command is received. Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2008-05-22 12:50:02 UTC (rev 1189) +++ firmware/tuxcore/trunk/motors.c 2008-05-22 13:40:54 UTC (rev 1190) @@ -330,6 +330,7 @@ void stop_eyes(void) { gStatus.mot &= ~GSTATUS_MOT_EYES; + eyes_move_counter = 0; stop_eyes_motor(); } @@ -490,6 +491,7 @@ void stop_mouth(void) { gStatus.mot &= ~GSTATUS_MOT_MOUTH; + mouth_move_counter = 0; stop_mouth_motor(); } @@ -635,6 +637,7 @@ void stop_flippers(void) { gStatus.mot &= ~GSTATUS_MOT_WINGS; + flippers_move_counter = 0; stop_flippers_motor(); } @@ -818,6 +821,7 @@ void stop_spinning(void) { gStatus.mot &= ~GSTATUS_MOT_SPIN; + spin_move_counter = 0; stop_spin_motor(); } |
From: Paul_R <c2m...@c2...> - 2008-05-22 12:50:14
|
Author: Paul_R Date: 2008-05-22 14:50:02 +0200 (Thu, 22 May 2008) New Revision: 1189 Modified: firmware/fuxusb/trunk/src/config.h firmware/fuxusb/trunk/src/global.c firmware/fuxusb/trunk/src/global.h firmware/fuxusb/trunk/src/i2c.c firmware/fuxusb/trunk/src/i2c.h firmware/fuxusb/trunk/src/misc.c firmware/fuxusb/trunk/src/misc.h firmware/fuxusb/trunk/src/rf.c firmware/fuxusb/trunk/src/rf.h firmware/fuxusb/trunk/src/usb_desc.h Log: * Doc. Modified: firmware/fuxusb/trunk/src/config.h =================================================================== --- firmware/fuxusb/trunk/src/config.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/config.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -22,15 +22,23 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ +/** \file config.h + * \brief Global config. + * \ingroup fuxusb + */ + #include <stdint.h> #include "lib_mcu/compiler.h" #include "lib_mcu/reg_5131.h" #include "lib_mcu/ext_5131.h" #include "lib_mcu/5131_drv.h" -/* Debug modes : Don't forget to define MAIN_DEBUG to be able to use printf */ -//#define MAIN_DEBUG -//#define USB_ENUM_DEBUG +/** \name Debug modes + * Don't forget to define MAIN_DEBUG to be able to use printf + * @{ */ +#undef MAIN_DEBUG +#undef USB_ENUM_DEBUG +/* @} */ /** \name MCU config * @{ */ @@ -44,9 +52,11 @@ #define BDR_GENERATOR BRG_TIMER2 /* @} */ -/* Misc */ +/** \name Misc + * @{ */ #define False 0 #define True 1 +/* @} */ /** \name Endpoints * @{ */ Modified: firmware/fuxusb/trunk/src/global.c =================================================================== --- firmware/fuxusb/trunk/src/global.c 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/global.c 2008-05-22 12:50:02 UTC (rev 1189) @@ -19,6 +19,11 @@ /* $Id$ */ +/** \file global.c + * \brief Global variables. + * \ingroup fuxusb + */ + #include "global.h" #include "config.h" #include "version.h" Modified: firmware/fuxusb/trunk/src/global.h =================================================================== --- firmware/fuxusb/trunk/src/global.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/global.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -70,6 +70,7 @@ */ /** \defgroup usb_misc USB misc functions + * \brief USB misc functions. * \ingroup fuxusb */ @@ -133,12 +134,17 @@ /** \defgroup misc Misc * \brief Misc functions. * \ingroup fuxusb - */ - + */ + /** * \defgroup mcu MCU libs */ +/** \file global.h + * \brief Global variables - header. + * \ingroup fuxusb + */ + #include "common\api.h" #include "common\defines.h" Modified: firmware/fuxusb/trunk/src/i2c.c =================================================================== --- firmware/fuxusb/trunk/src/i2c.c 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/i2c.c 2008-05-22 12:50:02 UTC (rev 1189) @@ -20,6 +20,7 @@ /* $Id$ */ /** \file i2c.c + * \brief I2C communication functions. \ingroup i2c */ Modified: firmware/fuxusb/trunk/src/i2c.h =================================================================== --- firmware/fuxusb/trunk/src/i2c.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/i2c.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -20,6 +20,7 @@ /* $Id$ */ /** \file i2c.h + * \brief I2C communication. \ingroup i2c */ Modified: firmware/fuxusb/trunk/src/misc.c =================================================================== --- firmware/fuxusb/trunk/src/misc.c 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/misc.c 2008-05-22 12:50:02 UTC (rev 1189) @@ -21,6 +21,7 @@ /** \file misc.c + * \brief Misc functions. \ingroup misc */ Modified: firmware/fuxusb/trunk/src/misc.h =================================================================== --- firmware/fuxusb/trunk/src/misc.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/misc.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -21,6 +21,7 @@ /** \file misc.h + * \brief Misc. module declaration. \ingroup misc */ Modified: firmware/fuxusb/trunk/src/rf.c =================================================================== --- firmware/fuxusb/trunk/src/rf.c 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/rf.c 2008-05-22 12:50:02 UTC (rev 1189) @@ -20,6 +20,7 @@ /* $Id$ */ /** \file rf.c + * \brief Functions to control the RF. \ingroup rf */ #include "config.h" Modified: firmware/fuxusb/trunk/src/rf.h =================================================================== --- firmware/fuxusb/trunk/src/rf.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/rf.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -21,6 +21,7 @@ /** \file rf.h + * \brief RF module declaration. \ingroup rf */ Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-22 09:48:32 UTC (rev 1188) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-22 12:50:02 UTC (rev 1189) @@ -30,7 +30,7 @@ #include "version.h" /** Enable / Disable the HID interface */ -#undef HID_DEVICE +#define HID_DEVICE /** \name Descriptors type * @{ */ |
From: Paul_R <c2m...@c2...> - 2008-05-22 09:48:28
|
Author: Paul_R Date: 2008-05-22 11:48:32 +0200 (Thu, 22 May 2008) New Revision: 1188 Modified: firmware/fuxusb/trunk/fuxusb.Opt firmware/fuxusb/trunk/src/bootloader.c firmware/fuxusb/trunk/src/spi_task.c firmware/fuxusb/trunk/src/spi_task.h Log: * Removed spi_task_on_Flag : flag with no effect. Modified: firmware/fuxusb/trunk/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/trunk/src/bootloader.c =================================================================== --- firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 09:41:39 UTC (rev 1187) +++ firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 09:48:32 UTC (rev 1188) @@ -68,9 +68,6 @@ */ void bootloader_cmd_parser(void) { - /* Disable spi_task */ - spi_task_on_Flag = False; - if (command_received[0] == BOOT_INIT) { init_bootloader(); @@ -242,7 +239,6 @@ i2c_bootloading_Flag = False; reset_rf(); spi_task_reset(); - spi_task_on_Flag = True; } Modified: firmware/fuxusb/trunk/src/spi_task.c =================================================================== --- firmware/fuxusb/trunk/src/spi_task.c 2008-05-22 09:41:39 UTC (rev 1187) +++ firmware/fuxusb/trunk/src/spi_task.c 2008-05-22 09:48:32 UTC (rev 1188) @@ -66,10 +66,6 @@ * RF that a command must be included in the frame. */ bit new_command_received; -/** This flag allow to process the SPI task. It's cleared when the bootloader mode - * is activated. - */ -bit spi_task_on_Flag = True; /* Static defs */ static uint8_t spi_slave_config; @@ -161,209 +157,206 @@ uint8_t Spi_Overflow_Ctr; uint8_t i; uint8_t received_status[4]; - - if(spi_task_on_Flag) + + //-------------------------------------------------------------------------- + // + // Wait the START Event + // + //-------------------------------------------------------------------------- + if (SPI_START) { - //-------------------------------------------------------------------------- - // - // Wait the START Event - // - //-------------------------------------------------------------------------- - if (SPI_START) - { - spi_ready = 0; - spi_count = 0; // Reset spi counter - spi_slave = HEADERS; // Set state machine - spi_master = HEADERM; - spi_enable = 0; // Communication in progress + spi_ready = 0; + spi_count = 0; // Reset spi counter + spi_slave = HEADERS; // Set state machine + spi_master = HEADERM; + spi_enable = 0; // Communication in progress - SPI_CSn = 0; // Chip select - spi_Start_Flag = 1; - } + SPI_CSn = 0; // Chip select + spi_Start_Flag = 1; + } + //-------------------------------------------------------------------------- + // + // SPI Streaming Analyze + // + //-------------------------------------------------------------------------- + if(spi_Start_Flag) + { //-------------------------------------------------------------------------- // - // SPI Streaming Analyze + // Excecute When RF Module is Ready // + // Falling Edge on spi_ready + // //-------------------------------------------------------------------------- - if(spi_Start_Flag) - { - //-------------------------------------------------------------------------- - // - // Excecute When RF Module is Ready - // - // Falling Edge on spi_ready - // - //-------------------------------------------------------------------------- - if(spi_ready) + if(spi_ready) + { + Spi_Overflow_Ctr = 0; + do { - Spi_Overflow_Ctr = 0; - do + spi_ready = 0; + //-------------------------------------------------------------------------- + // Prepare the Byte to Send + //-------------------------------------------------------------------------- + if (spi_slave == HEADERS) { - spi_ready = 0; - //-------------------------------------------------------------------------- - // Prepare the Byte to Send - //-------------------------------------------------------------------------- - if (spi_slave == HEADERS) + if (Fifoready_SPK) // FIFO ready to be empty { - if (Fifoready_SPK) // FIFO ready to be empty + if (new_command_received) // { - if (new_command_received) // - { - spi_slave_config = RF_AUDIO_HDR | - RF_CMD_HDR; // Config byte - SPDAT = spi_slave_config; // Header byte - } - else - { - // Config byte - spi_slave_config = RF_AUDIO_HDR; - // Header byte - SPDAT = spi_slave_config; - } + spi_slave_config = RF_AUDIO_HDR | + RF_CMD_HDR; // Config byte + SPDAT = spi_slave_config; // Header byte } else { - if (new_command_received) - { - // Config byte - spi_slave_config = RF_CMD_HDR; - // Header byte - SPDAT = spi_slave_config; - } - else - { - spi_slave_config = 0x00; // Config byte - SPDAT = spi_slave_config; // Header byte - } + // Config byte + spi_slave_config = RF_AUDIO_HDR; + // Header byte + SPDAT = spi_slave_config; } - spi_slave = GET_SOUND_FIFO; // Next state } - else if (spi_slave == GET_SOUND_FIFO) + else { - if (spi_count == 17) - spi_slave = PUT_COMMAND; // Next state - if (spi_slave_config & RF_AUDIO_HDR) - { - SPDAT = FIFO_SPK_get(); // Get data from FIFO + if (new_command_received) + { + // Config byte + spi_slave_config = RF_CMD_HDR; + // Header byte + SPDAT = spi_slave_config; } else - SPDAT = 0x00; // No data to transmit - + { + spi_slave_config = 0x00; // Config byte + SPDAT = spi_slave_config; // Header byte + } } - else if (spi_slave == PUT_COMMAND) + spi_slave = GET_SOUND_FIFO; // Next state + } + else if (spi_slave == GET_SOUND_FIFO) + { + if (spi_count == 17) + spi_slave = PUT_COMMAND; // Next state + if (spi_slave_config & RF_AUDIO_HDR) + { + SPDAT = FIFO_SPK_get(); // Get data from FIFO + } + else + SPDAT = 0x00; // No data to transmit + + } + else if (spi_slave == PUT_COMMAND) + { + if (spi_count == 21) { - if (spi_count == 21) + if(spi_slave_config & RF_CMD_HDR) { - if(spi_slave_config & RF_CMD_HDR) - { - new_command_received = False; - } - spi_slave = DUMMY; // Next state + new_command_received = False; } - if (spi_slave_config & RF_CMD_HDR) - { - SPDAT = rf_commands[spi_count-18]; - } - else - SPDAT = 0x00; // No command to transmit + spi_slave = DUMMY; // Next state } - else if (spi_slave == DUMMY) + if (spi_slave_config & RF_CMD_HDR) { - SPDAT = 0x00; // Dummy byte in case of big frame + SPDAT = rf_commands[spi_count-18]; } + else + SPDAT = 0x00; // No command to transmit + } + else if (spi_slave == DUMMY) + { + SPDAT = 0x00; // Dummy byte in case of big frame + } - spi_count++; - //-------------------------------------------------------------------------- - // Analyze the byte received - //-------------------------------------------------------------------------- - if (spi_master == HEADERM) - { - while (!(SPSTA == 0x80)); // Wait SPI response - if(RF_OFFLINE) - return; + spi_count++; + //-------------------------------------------------------------------------- + // Analyze the byte received + //-------------------------------------------------------------------------- + if (spi_master == HEADERM) + { + while (!(SPSTA == 0x80)); // Wait SPI response + if(RF_OFFLINE) + return; - spi_master_config = SPDAT; + spi_master_config = SPDAT; - if (SPDAT & RF_2FRAMES_HDR) // Double frame - spi_lenght_data = 34; - else - spi_lenght_data = 17; - spi_master = PUT_SOUND_FIFO; // Go to the next state + if (SPDAT & RF_2FRAMES_HDR) // Double frame + spi_lenght_data = 34; + else + spi_lenght_data = 17; + spi_master = PUT_SOUND_FIFO; // Go to the next state + } + else if (spi_master == PUT_SOUND_FIFO) + { + while (!(SPSTA == 0x80)); // Wait SPI response + if(RF_OFFLINE) + return; + + if (spi_master_config & RF_AUDIO_HDR) + { + P1_0 = 1; + received_rf_data[spi_count-2] = SPDAT; } - else if (spi_master == PUT_SOUND_FIFO) + if (spi_count == (spi_lenght_data + 1)) + // Go to the next state + spi_master = READ_COMMAND; + } + else if (spi_master == READ_COMMAND) + { + while (!(SPSTA == 0x80)); // Wait SPI response + if(RF_OFFLINE) + return; + + if (spi_master_config & RF_CMD_HDR) { - while (!(SPSTA == 0x80)); // Wait SPI response - if(RF_OFFLINE) - return; + if (spi_count <= spi_lenght_data + 5) + received_status[spi_count - \ + spi_lenght_data - 2] = SPDAT; - if (spi_master_config & RF_AUDIO_HDR) + if (spi_count == spi_lenght_data + 6) { - P1_0 = 1; - received_rf_data[spi_count-2] = SPDAT; + RF_Status_Temp = SPDAT; + if(RF_Status < RF_Status_Temp) + RF_Status = RF_Status_Temp; } - if (spi_count == (spi_lenght_data + 1)) - // Go to the next state - spi_master = READ_COMMAND; } - else if (spi_master == READ_COMMAND) + if (spi_count == spi_lenght_data + 6) { - while (!(SPSTA == 0x80)); // Wait SPI response - if(RF_OFFLINE) - return; + new_cmd_enabled = True; - if (spi_master_config & RF_CMD_HDR) - { - if (spi_count <= spi_lenght_data + 5) - received_status[spi_count - \ - spi_lenght_data - 2] = SPDAT; + spi_Start_Flag = 0; + SPI_CSn = 1; // Chip deselect + spi_enable = 1; - if (spi_count == spi_lenght_data + 6) - { - RF_Status_Temp = SPDAT; - if(RF_Status < RF_Status_Temp) - RF_Status = RF_Status_Temp; - } - } - if (spi_count == spi_lenght_data + 6) + // + // Store Sound Data in the FIFO MIC + // + // Double frame + if (spi_master_config & (RF_2FRAMES_HDR | \ + RF_AUDIO_HDR)) { - new_cmd_enabled = True; - - spi_Start_Flag = 0; - SPI_CSn = 1; // Chip deselect - spi_enable = 1; - - // - // Store Sound Data in the FIFO MIC - // - // Double frame - if (spi_master_config & (RF_2FRAMES_HDR | \ - RF_AUDIO_HDR)) + FIFO_MIC_put_n(spi_lenght_data); + } + // + // Store STATUS in the FIFO + // + if (spi_master_config & RF_CMD_HDR) + { + if(received_status[0]) { - FIFO_MIC_put_n(spi_lenght_data); - } - // - // Store STATUS in the FIFO - // - if (spi_master_config & RF_CMD_HDR) - { - if(received_status[0]) - { - i = 0; - do{ - FIFO_STT_put(received_status[i]); - i++; - } while (i<4); - } - } - //if (spi_slave_config & RF_CMD_HDR) - //printf("\n"); - return; - } + i = 0; + do{ + FIFO_STT_put(received_status[i]); + i++; + } while (i<4); + } + } + //if (spi_slave_config & RF_CMD_HDR) + //printf("\n"); + return; } - Spi_Overflow_Ctr++; - } while (spi_ready&&(Spi_Overflow_Ctr<5)); - } - } + } + Spi_Overflow_Ctr++; + } while (spi_ready&&(Spi_Overflow_Ctr<5)); + } } } Modified: firmware/fuxusb/trunk/src/spi_task.h =================================================================== --- firmware/fuxusb/trunk/src/spi_task.h 2008-05-22 09:41:39 UTC (rev 1187) +++ firmware/fuxusb/trunk/src/spi_task.h 2008-05-22 09:48:32 UTC (rev 1188) @@ -34,7 +34,6 @@ extern uint8_t RF_Status; extern bit new_cmd_enabled; extern bit new_command_received; -extern bit spi_task_on_Flag; /* Functions */ void spi_task_init(void); |
From: Paul_R <c2m...@c2...> - 2008-05-22 09:41:35
|
Author: Paul_R Date: 2008-05-22 11:41:39 +0200 (Thu, 22 May 2008) New Revision: 1187 Modified: firmware/fuxusb/trunk/src/bootloader.c firmware/fuxusb/trunk/src/fifo_mic.c firmware/fuxusb/trunk/src/global.c firmware/fuxusb/trunk/src/global.h firmware/fuxusb/trunk/src/i2c.c firmware/fuxusb/trunk/src/main.c firmware/fuxusb/trunk/src/misc.c firmware/fuxusb/trunk/src/spi_task.c firmware/fuxusb/trunk/src/usb_commands.c firmware/fuxusb/trunk/src/usb_enum.c firmware/fuxusb/trunk/src/usb_ep.c Log: * Comments, typo and cleanup. Modified: firmware/fuxusb/trunk/src/bootloader.c =================================================================== --- firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -36,13 +36,24 @@ bit i2c_bootloading_Flag; /* Statics defs */ +/** This flag indicate if the bootloader is activated or not. + * It's used in the main loop to switch between the SPI task and the i2c task. + */ bit i2c_task_on_Flag; +/** \name Data control + * @{ */ +/** Page size */ uint8_t page_size; +/** Number of packets per page */ uint8_t packets_per_page; +/** Adress number */ uint8_t address_idx; +/** Packet number */ uint8_t packet_idx; +/** Address tracking */ uint16_t address_tracking; blHeader_t blHeader; +/* @} */ static void bl_init(void); static void bl_exit(void); Modified: firmware/fuxusb/trunk/src/fifo_mic.c =================================================================== --- firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/fifo_mic.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -93,7 +93,7 @@ return; } - FifoTbl_MIC[FifoIn_MIC_Idx] = received_data[n - i]; + FifoTbl_MIC[FifoIn_MIC_Idx] = received_rf_data[n - i]; FifoIn_MIC_Idx++; // Update FIFO in index if (FifoIn_MIC_Idx == FIFOTBL_MIC_MAX) FifoIn_MIC_Idx = 0; Modified: firmware/fuxusb/trunk/src/global.c =================================================================== --- firmware/fuxusb/trunk/src/global.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/global.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -23,19 +23,27 @@ #include "config.h" #include "version.h" +/** Command_Ctr contain the number of bytes received in the CMD_OUT EP. */ uint8_t Command_Ctr; -/* Counters */ +/** This counter is used to wait before sending data on the i2c bus */ uint8_t i2c_wait_counter; -/* Buffers */ +/* \name Buffers + * @{ */ +/** Commands received on the CMD_OUT EP. The EP size is 64 */ uint8_t idata command_received[64]; -uint8_t received_data[34]; +/** Data received from the RF. The maximum byte in a frame is 34 */ +uint8_t received_rf_data[34]; +/** Commands received from USB for the RF. */ uint8_t idata rf_commands[4]; +/* @} */ -/* Dongle infos */ +/** \name Dongle infos + * @{ */ code version_t info_version ={VERSION_CMD, CPU_VER_JOIN(FUXUSB_CPU_NUM, VER_MAJOR), VER_MINOR, VER_UPDATE}; code revision_t info_revision={REVISION_CMD, REVISION_NUMBER, RELEASE_TYPE}; code author_t info_author={AUTHOR_CMD, AUTHOR_ID, VARIATION}; +/* @} */ Modified: firmware/fuxusb/trunk/src/global.h =================================================================== --- firmware/fuxusb/trunk/src/global.h 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/global.h 2008-05-22 09:41:39 UTC (rev 1187) @@ -159,7 +159,7 @@ /* USB buffers */ extern uint8_t idata command_received[]; -extern uint8_t received_data[]; +extern uint8_t received_rf_data[]; extern uint8_t idata rf_commands[]; /* Dongle infos */ Modified: firmware/fuxusb/trunk/src/i2c.c =================================================================== --- firmware/fuxusb/trunk/src/i2c.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/i2c.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -25,18 +25,26 @@ #include "i2c.h" -/* I2C status and address variables */ +/** \name I2C status and address variables + * @{ */ uint8_t i2cDeviceAddrRW; volatile I2C_FLAGS i2cFlags; -/* send/transmit buffer (outgoing data) */ +/* @} */ + +/** \name send/transmit buffer (outgoing data) + * @} */ uint8_t xdata i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; uint8_t *i2cDataToSend; uint8_t i2cSendDataIndex; uint8_t i2cSendDataLength; -/* receive buffer (incoming data) */ +/* @} */ + +/** \name receive buffer (incoming data) + * @{ */ uint8_t xdata i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; uint8_t i2cReceiveDataIndex; uint8_t i2cReceiveDataLength; +/* @} */ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for Modified: firmware/fuxusb/trunk/src/main.c =================================================================== --- firmware/fuxusb/trunk/src/main.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/main.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -19,9 +19,6 @@ /* $Id$ */ - - - /** \file main.c * \brief Fuxusb main function * \ingroup main Modified: firmware/fuxusb/trunk/src/misc.c =================================================================== --- firmware/fuxusb/trunk/src/misc.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/misc.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -28,6 +28,7 @@ #include "global.h" #include "misc.h" +/** Start of frame counter */ static uint16_t usb_sof_counter = 0; /** Modified: firmware/fuxusb/trunk/src/spi_task.c =================================================================== --- firmware/fuxusb/trunk/src/spi_task.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/spi_task.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -54,9 +54,21 @@ } spi_master; /* Externs defs */ +/** Indicate the RF state. + */ uint8_t RF_Status; +/** This flag is set when a new command can be received from the USB. + * When a command for tux is received, this flag = False. When the commands has + * been sent to the RF, this flag is set. + */ bit new_cmd_enabled; +/** This flag is set when a command for tux is received. It indicate the + * RF that a command must be included in the frame. + */ bit new_command_received; +/** This flag allow to process the SPI task. It's cleared when the bootloader mode + * is activated. + */ bit spi_task_on_Flag = True; /* Static defs */ @@ -288,7 +300,7 @@ if (spi_master_config & RF_AUDIO_HDR) { P1_0 = 1; - received_data[spi_count-2] = SPDAT; + received_rf_data[spi_count-2] = SPDAT; } if (spi_count == (spi_lenght_data + 1)) // Go to the next state @@ -316,8 +328,7 @@ if (spi_count == spi_lenght_data + 6) { new_cmd_enabled = True; - //new_cmd_enabled = True; -// USB_StatusProcess_Permit_Flag = True; + spi_Start_Flag = 0; SPI_CSn = 1; // Chip deselect spi_enable = 1; Modified: firmware/fuxusb/trunk/src/usb_commands.c =================================================================== --- firmware/fuxusb/trunk/src/usb_commands.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/usb_commands.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -71,6 +71,7 @@ case DONGLE_CMD_HDR: dongle_cmd_parser(); break; + /* Commands for Tux */ case TUX_CMD_HDR: new_cmd_enabled = False; @@ -79,6 +80,7 @@ for(i=0;i < 4;i++) rf_commands[i] = command_received[i]; break; + /* Bootloader commands */ case BOOTLOADER_CMD_HDR: bootloader_cmd_parser(); @@ -95,7 +97,6 @@ void prepare_status(void) { uint8_t data i; - if((status_requested) && (CMD_IN_Bank_Nb < 2)) { @@ -167,12 +168,15 @@ 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; @@ -250,6 +254,7 @@ SPCON = 0x14; /* Switch off the LED */ Led_0_off(); + /* * Set bootloader fuse, detach and attach usb, and active * bootloader mode. Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -55,7 +55,8 @@ uint8_t usb_configuration_nb = 0; /*! @} */ - +/** \name Standard enumeration functions + * @{ */ static void usb_get_descriptor(void); static void usb_read_request(void); static void usb_set_address(void); @@ -66,8 +67,10 @@ static void usb_get_configuration(void); static void usb_get_interface(void); static void usb_set_interface(void); +/* @} */ -/* AUDIO SPECIFIC REQUESTS */ +/** \name Audio enumeration functions + * @{ */ static void usb_get_current(void); static void usb_get_min(void); static void usb_get_max(void); @@ -76,15 +79,20 @@ static void usb_set_min(void); static void usb_set_max(void); static void usb_set_res(void); +/* @} */ -/* HID SPECIFIC REQUESTS */ +/** \name HID enumeration function + * @{ */ static void usb_hid_set_report(void); static void usb_hid_set_idle(void); static void usb_hid_get_idle(void); +/* @} */ -/* MISC COMMANDS */ +/** \name Misc functions + * @{ */ static void stall_request(void); static void send_zlp(void); +/* @} */ /** \name Init functions * @{ */ Modified: firmware/fuxusb/trunk/src/usb_ep.c =================================================================== --- firmware/fuxusb/trunk/src/usb_ep.c 2008-05-22 08:53:29 UTC (rev 1186) +++ firmware/fuxusb/trunk/src/usb_ep.c 2008-05-22 09:41:39 UTC (rev 1187) @@ -34,9 +34,16 @@ #include "lib_mcu\usb\usb_drv.h" /* Externs defs */ +/** \name Banks control. + * EP 4 and 5 uses ping-pong mode. The banks number must be controlled by + * firmware. + * @{ */ uint8_t CMD_OUT_Bank_Nb; uint8_t CMD_IN_Bank_Nb; +/* @} */ +/** Flag to switch between the normal speaker pipe and the tts pipe */ bit tts_pipe_selected = False; +/** Flag to indicate that the statuses must be sent to the PC */ bit status_requested = False; /* Statics defs */ @@ -54,7 +61,7 @@ */ void endpoints_parser(void) { - + /* EP0 : enumeration EP */ if (Usb_test_it_ep(0)) { Usb_select_ep(EP_CONTROL); @@ -62,15 +69,26 @@ usb_enumeration_process(); } - if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) - read_tts_ep(); + /* EP1 : Microphone EP */ + if(Usb_test_it_ep(EP_AUDIO_IN)) + { + clear_mic_ep(); + } + /* EP2 : Speaker EP */ if(Usb_test_it_ep(EP_AUDIO_OUT)) + { read_spk_ep(); + } - if(Usb_test_it_ep(EP_AUDIO_IN)) - clear_mic_ep(); + /* EP3 : TTS EP */ + if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) + { + read_tts_ep(); + } + + /* EP5 : Command out EP (PC -> dongle) */ if(Usb_test_it_ep(EP_CMD_OUT)) { if (new_cmd_enabled) @@ -79,8 +97,12 @@ clear_cmdout_ep(); } } + + /* EP4 : Command in EP (dongle -> PC) */ if (Usb_test_it_ep(EP_CMD_IN)) + { clear_cmdin_ep(); + } } /** |
From: Paul_R <c2m...@c2...> - 2008-05-22 08:53:27
|
Author: Paul_R Date: 2008-05-22 10:53:29 +0200 (Thu, 22 May 2008) New Revision: 1186 Modified: firmware/fuxusb/trunk/fuxusb.Opt firmware/fuxusb/trunk/src/bootloader.c firmware/fuxusb/trunk/src/config.h firmware/fuxusb/trunk/src/usb_commands.c firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_ep.c Log: * Cleanup debugs messages. Modified: firmware/fuxusb/trunk/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/trunk/src/bootloader.c =================================================================== --- firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 07:43:15 UTC (rev 1185) +++ firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 08:53:29 UTC (rev 1186) @@ -59,49 +59,27 @@ { /* Disable spi_task */ spi_task_on_Flag = False; -#ifdef BL_DEBUG - printf("BOOT CMD :: %bx - ", command_received[0]); -#endif if (command_received[0] == BOOT_INIT) { -#ifdef BL_DEBUG - printf("BOOT INIT \n"); -#endif init_bootloader(); } else if (!i2c_bootloading_Flag) { -#ifdef BL_DEBUG - printf("INIT FAIL \n"); -#endif bl_acknowledge(False, 1, 0, 0); bl_exit(); } else if (command_received[0] == BOOT_EXIT) { -#ifdef BL_DEBUG - printf("BOOT EXIT \n"); -#endif - bl_exit(); -#ifdef BL_DEBUG - printf("FLAG :: %BX \n", (uint8_t)(i2c_bootloading_Flag)); -#endif + bl_exit(); bl_acknowledge(True, 2, 0, 0); } else if (command_received[0] == BOOT_FILLPAGE) { -#ifdef BL_DEBUG - printf("BOOT FILLPAGE \n"); -#endif bl_fill_page(); } -#ifdef BL_DEBUG - else - printf("UNKNOWN CMD \n"); -#endif /* All data received */ if ((packet_idx == packets_per_page) && (address_idx == page_size)) @@ -137,9 +115,6 @@ else if (i2c_task_on_Flag) { -#ifdef BL_DEBUG - printf("I2C TASK PROCESS\n"); -#endif /* Send data through I2C */ bl_senddata(blHeader, 64); @@ -157,7 +132,7 @@ /** * \brief Fill page * A new page has been received. Check if the page is good, control the indexes - * and adresses, and put the data on the i2c. + * and adresses, and put the data on the i2c buffer. */ static void bl_fill_page(void) { @@ -189,7 +164,6 @@ bl_exit(); } - for(i = 3; i < Command_Ctr; i++) { blHeader.blData[address_idx++] = command_received[i]; @@ -217,6 +191,8 @@ /** * \brief Init bootloader mode. + * This function init the i2c communication, restart the dongle rf in bootloader + * mode, reset all bootloader variables and disable the INT0 interrupt (spi ready). */ static void init_bootloader(void) { @@ -247,6 +223,7 @@ /** *\brief Exit bootloader mode. + * When the bootloader mode exit, the spi and rf functions are re-initialized. */ static void bl_exit(void) { @@ -260,6 +237,8 @@ /* * Initialize i2c interface. + * This function set the I2C bitrate, init the interface and connect the + * bootloader pointer to the i2c buffer. */ static void bl_init(void) { @@ -287,15 +266,7 @@ i2cSendData[0] = blHeader.page_address >> 8; /* the first 2 bytes of the i2c frame are the page address */ i2cSendData[1] = blHeader.page_address; i2cSendDataLength = dataLength + 2; -#ifdef BOOTLOAD_DEBUG - { - uint8_t i; - printf("I2C: Page 0x%BX%BX:\n", i2cSendData[0], i2cSendData[1]); - for (i=2; i<i2cSendDataLength; i++) - printf("%BX", i2cSendData[i]); - printf("\n"); - } -#endif + i2cMasterStart(); } Modified: firmware/fuxusb/trunk/src/config.h =================================================================== --- firmware/fuxusb/trunk/src/config.h 2008-05-22 07:43:15 UTC (rev 1185) +++ firmware/fuxusb/trunk/src/config.h 2008-05-22 08:53:29 UTC (rev 1186) @@ -28,17 +28,12 @@ #include "lib_mcu/ext_5131.h" #include "lib_mcu/5131_drv.h" - - /* Debug modes : Don't forget to define MAIN_DEBUG to be able to use printf */ //#define MAIN_DEBUG -//#define BL_EP_DEBUG -//#define BL_DEBUG -//#define CMD_DEBUG -//#define FIFO_DEBUG //#define USB_ENUM_DEBUG -/* MCU config */ +/** \name MCU config + * @{ */ #define FOSC 24000 #define CPUB_VERSION #define X2_MODE @@ -47,6 +42,7 @@ #define BAUDRATE 115200 #define BDR_GENERATOR BRG_TIMER2 +/* @} */ /* Misc */ #define False 0 Modified: firmware/fuxusb/trunk/src/usb_commands.c =================================================================== --- firmware/fuxusb/trunk/src/usb_commands.c 2008-05-22 07:43:15 UTC (rev 1185) +++ firmware/fuxusb/trunk/src/usb_commands.c 2008-05-22 08:53:29 UTC (rev 1186) @@ -140,10 +140,6 @@ { 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); Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-22 07:43:15 UTC (rev 1185) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-22 08:53:29 UTC (rev 1186) @@ -29,7 +29,7 @@ #include "version.h" -/** Enable the HID interface */ +/** Enable / Disable the HID interface */ #undef HID_DEVICE /** \name Descriptors type Modified: firmware/fuxusb/trunk/src/usb_ep.c =================================================================== --- firmware/fuxusb/trunk/src/usb_ep.c 2008-05-22 07:43:15 UTC (rev 1185) +++ firmware/fuxusb/trunk/src/usb_ep.c 2008-05-22 08:53:29 UTC (rev 1186) @@ -72,22 +72,12 @@ clear_mic_ep(); if(Usb_test_it_ep(EP_CMD_OUT)) - { -#ifdef BL_EP_DEBUG - printf("CMD OUT RECEIVED ... "); -#endif + { if (new_cmd_enabled) { -#ifdef BL_EP_DEBUG - printf("PROCESS\n"); -#endif commands_parser(); clear_cmdout_ep(); } -#ifdef BL_EP_DEBUG - else - printf("ERROR\n"); -#endif } if (Usb_test_it_ep(EP_CMD_IN)) clear_cmdin_ep(); @@ -190,52 +180,30 @@ static void clear_cmdout_ep(void) { Usb_select_ep(EP_CMD_OUT); -#ifdef BL_EP_DEBUG - printf("Clear EP OUT:: %BX -> ", CMD_OUT_Bank_Nb); -#endif + // Release the EP fifo if (CMD_OUT_Bank_Nb == 0 && Usb_rx_bank0_complete()) { -#ifdef BL_EP_DEBUG - printf("BANK0 -> "); -#endif Usb_clear_rx_bank0(); CMD_OUT_Bank_Nb = 1; } else if(CMD_OUT_Bank_Nb == 1 && Usb_rx_bank1_complete()) { -#ifdef BL_EP_DEBUG - printf("BANK1 -> "); -#endif Usb_clear_rx_bank1(); CMD_OUT_Bank_Nb = 0; } else { -#ifdef BL_EP_DEBUG - printf("ERR : "); -#endif // Bad synchronisation : try to resynchronise if (Usb_rx_bank1_complete()) { -#ifdef BL_EP_DEBUG - printf("B1 -> "); - while(1); -#endif Usb_clear_rx_bank1(); } else { -#ifdef BL_EP_DEBUG - printf("B0 -> "); - while(1); -#endif Usb_clear_rx_bank0(); } } -#ifdef BL_EP_DEBUG - printf("%BX \n ", CMD_OUT_Bank_Nb); -#endif } /** @@ -246,36 +214,19 @@ static void clear_cmdin_ep(void) { Usb_select_ep(EP_CMD_IN); -#ifdef BL_EP_DEBUG - printf("Clear EP IN:: %BX -> ", CMD_IN_Bank_Nb); -#endif + if(Usb_tx_complete()) { Usb_clear_tx_complete(); CMD_IN_Bank_Nb--; -#ifdef BL_EP_DEBUG - printf("%BX -> ", CMD_IN_Bank_Nb); -#endif + if (CMD_IN_Bank_Nb<0) - { -#ifdef BL_EP_DEBUG - printf("RESET BANK "); -#endif + { CMD_IN_Bank_Nb = 0; } if (CMD_IN_Bank_Nb != 0) { -#ifdef BL_EP_DEBUG - printf("SET TX READY "); -#endif Usb_set_tx_ready(); } -#ifdef BL_EP_DEBUG - else - printf("NOTHING TO DO"); -#endif } -#ifdef BL_EP_DEBUG - printf("\n"); -#endif } |
From: Paul_R <c2m...@c2...> - 2008-05-22 07:43:15
|
Author: Paul_R Date: 2008-05-22 09:43:15 +0200 (Thu, 22 May 2008) New Revision: 1185 Modified: firmware/fuxusb/trunk/src/bootloader.c Log: * Removed the bootinit acknoledge. This acknoledge is not read by tuxup, and isn't not needed. Modified: firmware/fuxusb/trunk/src/bootloader.c =================================================================== --- firmware/fuxusb/trunk/src/bootloader.c 2008-05-21 14:54:04 UTC (rev 1184) +++ firmware/fuxusb/trunk/src/bootloader.c 2008-05-22 07:43:15 UTC (rev 1185) @@ -243,8 +243,6 @@ EX0 = 0; /* Disable INT0 interrupt */ - /* Acknoledge the boot init */ - bl_acknowledge(True, 1, 0, 0); } /** |
From: Paul_R <c2m...@c2...> - 2008-05-21 21:47:34
|
Author: Paul_R Date: 2008-05-21 16:54:04 +0200 (Wed, 21 May 2008) New Revision: 1184 Modified: firmware/hex_dev/fuxusb.hex Log: * Current dongle firmware, from trunk at rev 1182 (compiled to work with tuxd). Modified: firmware/hex_dev/fuxusb.hex =================================================================== (Binary files differ) |
From: Paul_R <c2m...@c2...> - 2008-05-21 14:46:33
|
Author: Paul_R Date: 2008-05-21 16:46:36 +0200 (Wed, 21 May 2008) New Revision: 1183 Modified: firmware/tuxup/trunk/main.c Log: * Reset the dongle at the end of the update process. With this change, after the update, the dongle don't needs to be unplugged/plugged. The daemon restarts correctly, and all is working. * Minor change : replace a sleep(2) by sleep(1). Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2008-05-21 14:07:04 UTC (rev 1182) +++ firmware/tuxup/trunk/main.c 2008-05-21 14:46:36 UTC (rev 1183) @@ -374,7 +374,7 @@ { if (verbose) fprintf(stdout, "Switched to bootloader mode.\n"); - sleep(2); + sleep(1); } else { @@ -633,7 +633,11 @@ } if (!pretend) + { + uint8_t send_data[5] = { 0x01, 0x01, 0x00, 0x00, 0xFE }; + ret = usb_send_commands(dev_h, send_data, 5); fux_disconnect(); + } /* In case of error of some sort, we return it. */ if (ret) |
From: Paul_R <c2m...@c2...> - 2008-05-21 14:07:03
|
Author: Paul_R Date: 2008-05-21 16:07:04 +0200 (Wed, 21 May 2008) New Revision: 1182 Modified: firmware/fuxusb/trunk/src/usb_enum.c Log: * Bug : usb_enum.c -> set_interface When the interface 3 (HID interface) is set, the banks and the eps have to be cleared. Otherwise, the EPs are corrupted. The result is that the command is often ignored. This problem occurs especially with tuxup, when the dongle has to be flashed. Tuxup uses the set_interface function, even if the interface is already set. I've also added code to reset the audio EPs when the actives interfaces (alternates interfaces 1) are set. Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-21 10:02:01 UTC (rev 1181) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-21 14:07:04 UTC (rev 1182) @@ -322,6 +322,53 @@ Usb_clear_DIR(); Usb_clear_rx_setup(); + /* HID interface : + * When this interface is set, reset the endpoints and the banks + */ + if(Linterface_number == 3) + { + if(LAlternateSetting == 0) + { + CMD_IN_Bank_Nb = 0; + CMD_OUT_Bank_Nb = 0; + usb_reset_endpoint(EP_CMD_IN); + usb_reset_endpoint(EP_CMD_OUT); + } + } + + /* Microphone interface : + * Reset the endpount when the active interface is set + */ + if(Linterface_number == 1) + { + if(LAlternateSetting == 1) + { + usb_reset_endpoint(IN_ENDPOINT1); + } + } + + /* Speaker interface : + * Reset the endpount when the active interface is set + */ + if(Linterface_number == 2) + { + if(LAlternateSetting == 1) + { + usb_reset_endpoint(OUT_ENDPOINT2); + } + } + + /* Speaker interface : + * Reset the endpount when the active interface is set + */ + if(Linterface_number == 5) + { + if(LAlternateSetting == 1) + { + usb_reset_endpoint(OUT_ENDPOINT3); + } + } + send_zlp(); #ifdef USB_ENUM_DEBUG |