From dfcbd78814b9c0ca7649f3d627b6c57fb2750db3 Mon Sep 17 00:00:00 2001 From: ethereal Date: Mon, 8 Feb 2016 23:17:49 -0800 Subject: [PATCH 1/5] usb_hal: Remove duplicate in buffer_descriptor This allows usb_hal to pass the first stage of compilation on an unmodified mipsel GCC toolchain. --- usb/src/usb_hal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/src/usb_hal.h b/usb/src/usb_hal.h index eb9a42f..984d7d1 100644 --- a/usb/src/usb_hal.h +++ b/usb/src/usb_hal.h @@ -530,7 +530,7 @@ struct buffer_descriptor { uint32_t BSTALL : 1; uint32_t DTSEN : 1; /* DTS in datasheet */ uint32_t reserved : 2; /* NINC, KEEP */ - uint32_t DTS : 1; /* DATA0/1 in datasheet */ + uint32_t /*DTS*/ : 1; /* DATA0/1 in datasheet */ uint32_t /*UOWN*/ : 1; uint32_t : 8; From 6eef515a168f89dd2a8dc63e006fad48eda90ff0 Mon Sep 17 00:00:00 2001 From: ethereal Date: Wed, 17 Feb 2016 19:56:35 -0800 Subject: [PATCH 2/5] usb, usb_cdc, usb_hid: Removed use of min() This function/macro does not exist on vanilla mipsel GCC. --- usb/src/usb.c | 4 +++- usb/src/usb_cdc.c | 14 +++++++------- usb/src/usb_hid.c | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/usb/src/usb.c b/usb/src/usb.c index ff2be5b..b207f29 100644 --- a/usb/src/usb.c +++ b/usb/src/usb.c @@ -36,6 +36,8 @@ #include #elif __XC8 #include +#elif __GNUC__ +#include #else #error "Compiler not supported" #endif @@ -1710,4 +1712,4 @@ void __attribute__((vector(_USB_1_VECTOR), interrupt(), nomips16)) _USB1Interrup #else #error Compiler not supported yet #endif -#endif \ No newline at end of file +#endif diff --git a/usb/src/usb_cdc.c b/usb/src/usb_cdc.c index 6a569db..cd0be96 100644 --- a/usb/src/usb_cdc.c +++ b/usb/src/usb_cdc.c @@ -159,7 +159,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((void*)response, - min(len, setup->wLength), + (lenwLength)? len : setup->wLength, callback, context); return 0; } @@ -227,8 +227,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) (uint16_t) data_multiplexed_state << 1; usb_send_data_stage((char*)&transfer_data.comm_feature, - min(setup->wLength, - sizeof(transfer_data.comm_feature)), + (setup->wLengthwLength : sizeof(transfer_data.comm_feature) NULL/*callback*/, NULL); return 0; } @@ -241,8 +241,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) transfer_interface = interface; usb_start_receive_ep0_data_stage( (char*)&transfer_data.line_coding, - min(setup->wLength, - sizeof(transfer_data.line_coding)), + (setup->wLengthwLength : sizeof(transfer_data.comm_feature) set_line_coding, NULL); return 0; } @@ -260,8 +260,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((char*)&transfer_data.line_coding, - min(setup->wLength, - sizeof(transfer_data.line_coding)), + (setup->wLengthwLength : sizeof(transfer_data.comm_feature) /*callback*/NULL, NULL); return 0; } diff --git a/usb/src/usb_hid.c b/usb/src/usb_hid.c index 5861515..4c85f6f 100644 --- a/usb/src/usb_hid.c +++ b/usb/src/usb_hid.c @@ -91,7 +91,8 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*) desc, min(len, setup->wLength), NULL, NULL); + usb_send_data_stage((void*)desc, + (lenwLength)? len : setup->wLength, NULL, NULL); return 0; } @@ -112,7 +113,8 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*)desc, min(len, setup->wLength), callback, context); + usb_send_data_stage((void*)desc, + (lenwLength)? len : setup->wLength, callback, context); return 0; } #endif From 32b46de5ce2e057cc4fcc6491f21f5083c3efb96 Mon Sep 17 00:00:00 2001 From: ethereal Date: Wed, 17 Feb 2016 20:17:17 -0800 Subject: [PATCH 3/5] Added checks for mips GCC where appropriate. --- usb/include/usb_cdc.h | 4 ++-- usb/include/usb_ch9.h | 4 ++-- usb/include/usb_hid.h | 4 ++-- usb/include/usb_microsoft.h | 4 ++-- usb/include/usb_msc.h | 4 ++-- usb/src/usb.c | 12 ++++++------ usb/src/usb_hal.h | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/usb/include/usb_cdc.h b/usb/include/usb_cdc.h index 0ac4213..dc79a91 100644 --- a/usb/include/usb_cdc.h +++ b/usb/include/usb_cdc.h @@ -39,7 +39,7 @@ #include #include "usb_config.h" -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(push, 1) #elif __XC8 #else @@ -488,7 +488,7 @@ extern int8_t CDC_SEND_BREAK_CALLBACK(uint8_t interface, uint16_t duration); /** @}*/ -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(pop) #elif __XC8 #else diff --git a/usb/include/usb_ch9.h b/usb/include/usb_ch9.h index 760ae16..0d80b40 100644 --- a/usb/include/usb_ch9.h +++ b/usb/include/usb_ch9.h @@ -38,7 +38,7 @@ #include -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(push, 1) #elif __XC8 #else @@ -273,7 +273,7 @@ struct interface_association_descriptor { /** @endcond */ -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(pop) #elif __XC8 #else diff --git a/usb/include/usb_hid.h b/usb/include/usb_hid.h index bf31edc..42d6f56 100644 --- a/usb/include/usb_hid.h +++ b/usb/include/usb_hid.h @@ -39,7 +39,7 @@ #include #include "usb_config.h" -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(push, 1) #elif __XC8 #else @@ -333,7 +333,7 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup); /** @}*/ -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(pop) #elif __XC8 #else diff --git a/usb/include/usb_microsoft.h b/usb/include/usb_microsoft.h index 36e0848..5dd2d1e 100644 --- a/usb/include/usb_microsoft.h +++ b/usb/include/usb_microsoft.h @@ -38,7 +38,7 @@ #include -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(push, 1) #elif __XC8 #else @@ -171,7 +171,7 @@ uint16_t MICROSOFT_CUSTOM_PROPERTY_DESCRIPTOR_FUNC(uint8_t interface, /* Doxygen end-of-group for microsoft_items */ /** @}*/ -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(pop) #elif __XC8 #else diff --git a/usb/include/usb_msc.h b/usb/include/usb_msc.h index cdd4033..0b9a1be 100644 --- a/usb/include/usb_msc.h +++ b/usb/include/usb_msc.h @@ -39,7 +39,7 @@ #include #include "usb_config.h" -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(push, 1) #elif __XC8 #else @@ -299,7 +299,7 @@ struct scsi_sense_response { /* Additional, vendor-specific sense data goes here. */ }; -#if defined(__XC16__) || defined(__XC32__) +#if defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) #pragma pack(pop) #elif __XC8 #else diff --git a/usb/src/usb.c b/usb/src/usb.c index b207f29..b7242b6 100644 --- a/usb/src/usb.c +++ b/usb/src/usb.c @@ -36,8 +36,8 @@ #include #elif __XC8 #include -#elif __GNUC__ -#include +#elif defined(__GNUC__) && __mips == 32 + /* You need to have an include in usb_config.h. */ #else #error "Compiler not supported" #endif @@ -118,7 +118,7 @@ STATIC_SIZE_CHECK_EQUAL(sizeof(struct microsoft_extended_compat_header), 16); STATIC_SIZE_CHECK_EQUAL(sizeof(struct microsoft_extended_compat_function), 24); STATIC_SIZE_CHECK_EQUAL(sizeof(struct microsoft_extended_properties_header), 10); STATIC_SIZE_CHECK_EQUAL(sizeof(struct microsoft_extended_property_section_header), 8); -#ifdef __XC32__ +#if defined(__XC32__) || (defined(__GNUC__) && __mips == 32) STATIC_SIZE_CHECK_EQUAL(sizeof(struct buffer_descriptor), 8); #else STATIC_SIZE_CHECK_EQUAL(sizeof(struct buffer_descriptor), 4); @@ -207,7 +207,7 @@ static struct buffer_descriptor bds[NUM_BD] BD_ATTR_TAG; 0x400 and 0x7FF per the datasheet.*/ /* This addr is for the PIC18F4550 */ #pragma udata usb_buffers=0x500 -#elif defined(__XC16__) || defined(__XC32__) +#elif defined(__XC16__) || defined(__XC32__) || (defined(__GNUC__) && __mips == 32) /* Buffers can go anywhere on PIC24/PIC32 parts which are supported (so far). */ #elif __XC8 @@ -625,7 +625,7 @@ void usb_init(void) SFR_BD_ADDR_REG = w.hb; -#elif __XC32__ +#elif __XC32__ || (defined(__GNUC__) && __mips == 32) union WORD { struct { uint8_t lb; @@ -1694,7 +1694,7 @@ void _ISR __attribute((auto_psv)) _USB1Interrupt() usb_service(); } -#elif __XC32__ +#elif __XC32__ || (defined(__GNUC__) && __mips == 32) /* No parameter for interrupt() means to use IPL=RIPL and to detect whether to use shadow registers or not. This is the safest option, but if a user diff --git a/usb/src/usb_hal.h b/usb/src/usb_hal.h index 984d7d1..c9addc5 100644 --- a/usb/src/usb_hal.h +++ b/usb/src/usb_hal.h @@ -437,7 +437,7 @@ struct buffer_descriptor { #define FAR #define memcpy_from_rom(x,y,z) memcpy(x,y,z) -#elif __XC32__ +#elif __XC32__ || (defined(__GNUC__) && __mips == 32) #define USB_NEEDS_POWER_ON #define USB_NEEDS_SET_BD_ADDR_REG From ba103e736a7ef052a0b910f10b14333f4af487be Mon Sep 17 00:00:00 2001 From: ethereal Date: Wed, 17 Feb 2016 23:49:43 -0800 Subject: [PATCH 4/5] Revert "usb, usb_cdc, usb_hid: Removed use of min()" This reverts commit 6eef515a168f89dd2a8dc63e006fad48eda90ff0. --- usb/src/usb_cdc.c | 14 +++++++------- usb/src/usb_hid.c | 6 ++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/usb/src/usb_cdc.c b/usb/src/usb_cdc.c index cd0be96..6a569db 100644 --- a/usb/src/usb_cdc.c +++ b/usb/src/usb_cdc.c @@ -159,7 +159,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((void*)response, - (lenwLength)? len : setup->wLength, + min(len, setup->wLength), callback, context); return 0; } @@ -227,8 +227,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) (uint16_t) data_multiplexed_state << 1; usb_send_data_stage((char*)&transfer_data.comm_feature, - (setup->wLengthwLength : sizeof(transfer_data.comm_feature) + min(setup->wLength, + sizeof(transfer_data.comm_feature)), NULL/*callback*/, NULL); return 0; } @@ -241,8 +241,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) transfer_interface = interface; usb_start_receive_ep0_data_stage( (char*)&transfer_data.line_coding, - (setup->wLengthwLength : sizeof(transfer_data.comm_feature) + min(setup->wLength, + sizeof(transfer_data.line_coding)), set_line_coding, NULL); return 0; } @@ -260,8 +260,8 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((char*)&transfer_data.line_coding, - (setup->wLengthwLength : sizeof(transfer_data.comm_feature) + min(setup->wLength, + sizeof(transfer_data.line_coding)), /*callback*/NULL, NULL); return 0; } diff --git a/usb/src/usb_hid.c b/usb/src/usb_hid.c index 4c85f6f..5861515 100644 --- a/usb/src/usb_hid.c +++ b/usb/src/usb_hid.c @@ -91,8 +91,7 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*)desc, - (lenwLength)? len : setup->wLength, NULL, NULL); + usb_send_data_stage((void*) desc, min(len, setup->wLength), NULL, NULL); return 0; } @@ -113,8 +112,7 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*)desc, - (lenwLength)? len : setup->wLength, callback, context); + usb_send_data_stage((void*)desc, min(len, setup->wLength), callback, context); return 0; } #endif From 01db26113d1313d394e799a4fe1e8048213d7fbd Mon Sep 17 00:00:00 2001 From: ethereal Date: Wed, 17 Feb 2016 23:50:38 -0800 Subject: [PATCH 5/5] usb_cdc, usb_hid: Changed uses of min into MIN This uses the locally-defined macros and makes these files compile on vanilla mipsel GCC. --- usb/src/usb_cdc.c | 8 ++++---- usb/src/usb_hid.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/usb/src/usb_cdc.c b/usb/src/usb_cdc.c index 6a569db..5b3b223 100644 --- a/usb/src/usb_cdc.c +++ b/usb/src/usb_cdc.c @@ -159,7 +159,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((void*)response, - min(len, setup->wLength), + MIN(len, setup->wLength), callback, context); return 0; } @@ -227,7 +227,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) (uint16_t) data_multiplexed_state << 1; usb_send_data_stage((char*)&transfer_data.comm_feature, - min(setup->wLength, + MIN(setup->wLength, sizeof(transfer_data.comm_feature)), NULL/*callback*/, NULL); return 0; @@ -241,7 +241,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) transfer_interface = interface; usb_start_receive_ep0_data_stage( (char*)&transfer_data.line_coding, - min(setup->wLength, + MIN(setup->wLength, sizeof(transfer_data.line_coding)), set_line_coding, NULL); return 0; @@ -260,7 +260,7 @@ uint8_t process_cdc_setup_request(const struct setup_packet *setup) return -1; usb_send_data_stage((char*)&transfer_data.line_coding, - min(setup->wLength, + MIN(setup->wLength, sizeof(transfer_data.line_coding)), /*callback*/NULL, NULL); return 0; diff --git a/usb/src/usb_hid.c b/usb/src/usb_hid.c index 5861515..76a4c6c 100644 --- a/usb/src/usb_hid.c +++ b/usb/src/usb_hid.c @@ -91,7 +91,7 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*) desc, min(len, setup->wLength), NULL, NULL); + usb_send_data_stage((void*) desc, MIN(len, setup->wLength), NULL, NULL); return 0; } @@ -112,7 +112,7 @@ uint8_t process_hid_setup_request(const struct setup_packet *setup) if (len < 0) return -1; - usb_send_data_stage((void*)desc, min(len, setup->wLength), callback, context); + usb_send_data_stage((void*)desc, MIN(len, setup->wLength), callback, context); return 0; } #endif