Adaptations for Renesas CCRX toolchain and Rx72N controller performed

This commit is contained in:
Wini-Buh
2021-05-29 21:23:39 +02:00
parent 4e2684f23a
commit b4f092ec74
13 changed files with 543 additions and 73 deletions

View File

@@ -48,6 +48,8 @@
#define TU_VERIFY_STATIC _Static_assert
#elif defined (__cplusplus) && __cplusplus >= 201103L
#define TU_VERIFY_STATIC static_assert
#elif defined(__CCRX__)
#define TU_VERIFY_STATIC(const_expr, _mess) typedef char TU_XSTRCAT(Line, __LINE__)[(const_expr) ? 1 : 0];
#else
#define TU_VERIFY_STATIC(const_expr, _mess) enum { TU_XSTRCAT(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) }
#endif
@@ -62,6 +64,9 @@
// Compiler porting with Attribute and Endian
//--------------------------------------------------------------------+
// define the standard definition of this macro to construct a "weak" function name
#define MAKE_WEAK_FUNC(func_name) func_name
// TODO refactor since __attribute__ is supported across many compiler
#if defined(__GNUC__)
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
@@ -73,9 +78,17 @@
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
#define TU_ATTR_USED __attribute__ ((used)) // Function/Variable is meant to be used
#define TU_PACK_STRUCT_BEGIN
#define TU_PACK_STRUCT_END
#define TU_BIT_FIELD_ORDER_BEGIN
#define TU_BIT_FIELD_ORDER_END
// Endian conversion use well-known host to network (big endian) naming
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define TU_BYTE_ORDER TU_LITTLE_ENDIAN
#define TU_ENDIAN_LITTLE_BEGIN
#define TU_ENDIAN_LITTLE_END
#else
#define TU_BYTE_ORDER TU_BIG_ENDIAN
#endif
@@ -123,6 +136,77 @@
#define TU_BSWAP16(u16) (__iar_builtin_REV16(u16))
#define TU_BSWAP32(u32) (__iar_builtin_REV(u32))
#elif defined(__CCRX__)
#define TU_ATTR_ALIGNED(Bytes)
#define TU_ATTR_SECTION(sec_name)
#define TU_ATTR_PACKED
#define TU_ATTR_WEAK
#define TU_ATTR_ALWAYS_INLINE
#define TU_ATTR_DEPRECATED(mess)
#define TU_ATTR_UNUSED
#define TU_ATTR_USED
#define TU_PACK_STRUCT_BEGIN _Pragma("pack")
#define TU_PACK_STRUCT_END _Pragma("packoption")
#define TU_BIT_FIELD_ORDER_BEGIN _Pragma("bit_order right")
#define TU_BIT_FIELD_ORDER_END _Pragma("bit_order")
// Endian conversion use well-known host to network (big endian) naming
#if defined(__LIT)
#define TU_BYTE_ORDER TU_LITTLE_ENDIAN
#define TU_ENDIAN_LITTLE_BEGIN
#define TU_ENDIAN_LITTLE_END
#else
#define TU_BYTE_ORDER TU_BIG_ENDIAN
#define TU_ENDIAN_LITTLE_BEGIN _Pragma("endian little")
#define TU_ENDIAN_LITTLE_END _Pragma("endian")
#endif
#define TU_BSWAP16(u16) ((unsigned short)_builtin_revw((unsigned long)u16))
#define TU_BSWAP32(u32) (_builtin_revl(u32))
/* activate the "aligned" emulation, because this toolchain does not know
the aligned attribute (or something similar yet) */
#define TU_HAS_NO_ATTR_ALIGNED
/* activate the "weak" function emulation, because this toolchain does not
know the weak attribute (or something similar yet) */
#define TU_HAS_NO_ATTR_WEAK
// make sure to define away the standard definition of this macro
#undef MAKE_WEAK_FUNC
// Helper macro to construct a "weak" function name
#define MAKE_WEAK_FUNC(func_name) weak_ ## func_name
#if defined(TU_HAS_NO_ATTR_WEAK)
// "Weak function" emulation defined in cdc_device.h
#define ADD_WEAK_FUNC_TUD_CDC_RX_CB 0
#define ADD_WEAK_FUNC_TUD_CDC_RX_WANTED_CB 0
#define ADD_WEAK_FUNC_TUD_CDC_TX_COMPLETE_CB 0
#define ADD_WEAK_FUNC_TUD_CDC_LINE_STATE_CB 0
#define ADD_WEAK_FUNC_TUD_CDC_LINE_CODING_CB 0
#define ADD_WEAK_FUNC_TUD_CDC_SEND_BREAK_CB 0
// "Weak function" emulation defined in usbd_pvt.h
#define ADD_WEAK_FUNC_USBD_APP_DRIVER_GET_CB 0
// "Weak function" emulation defined in usbd.h
#define ADD_WEAK_FUNC_TUD_DESCRIPTOR_BOS_CB 0
#define ADD_WEAK_FUNC_TUD_DESCRIPTOR_DEVICE_QUALIFIER_CB 0
#define ADD_WEAK_FUNC_TUD_MOUNT_CB 0
#define ADD_WEAK_FUNC_TUD_UMOUNT_CB 0
#define ADD_WEAK_FUNC_TUD_SUSPEND_CB 0
#define ADD_WEAK_FUNC_TUD_RESUME_CB 0
#define ADD_WEAK_FUNC_TUD_VENDOR_CONTROL_XFER_CB 0
// "Weak function" emulation defined in dcd.h
#define ADD_WEAK_FUNC_DCD_EDPT0_STATUS_COMPLETE 0
#define ADD_WEAK_FUNC_DCD_EDPT_CLOSE 0
#define ADD_WEAK_FUNC_DCD_EDPT_XFER_FIFO 0
#endif
#else
#error "Compiler attribute porting is required"
#endif
@@ -149,11 +233,11 @@
#define tu_htonl(u32) (u32)
#define tu_ntohl(u32) (u32)
#define tu_htole16(u16) (tu_bswap16(u16))
#define tu_le16toh(u16) (tu_bswap16(u16))
#define tu_htole16(u16) (TU_BSWAP16(u16))
#define tu_le16toh(u16) (TU_BSWAP16(u16))
#define tu_htole32(u32) (tu_bswap32(u32))
#define tu_le32toh(u32) (tu_bswap32(u32))
#define tu_htole32(u32) (TU_BSWAP32(u32))
#define tu_le32toh(u32) (TU_BSWAP32(u32))
#else
#error Byte order is undefined

View File

@@ -263,6 +263,7 @@ enum
//--------------------------------------------------------------------+
/// USB Device Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
@@ -283,10 +284,12 @@ typedef struct TU_ATTR_PACKED
uint8_t bNumConfigurations ; ///< Number of possible configurations.
} tusb_desc_device_t;
TU_PACK_STRUCT_END
TU_VERIFY_STATIC( sizeof(tusb_desc_device_t) == 18, "size is not correct");
// USB Binary Device Object Store (BOS) Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -294,8 +297,10 @@ typedef struct TU_ATTR_PACKED
uint16_t wTotalLength ; ///< Total length of data returned for this descriptor
uint8_t bNumDeviceCaps ; ///< Number of device capability descriptors in the BOS
} tusb_desc_bos_t;
TU_PACK_STRUCT_END
/// USB Configuration Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -308,10 +313,10 @@ typedef struct TU_ATTR_PACKED
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} tusb_desc_configuration_t;
TU_VERIFY_STATIC( sizeof(tusb_desc_configuration_t) == 9, "size is not correct");
TU_PACK_STRUCT_END
/// USB Interface Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -325,8 +330,10 @@ typedef struct TU_ATTR_PACKED
uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
uint8_t iInterface ; ///< Index of string descriptor describing this interface
} tusb_desc_interface_t;
TU_PACK_STRUCT_END
/// USB Endpoint Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -334,23 +341,32 @@ typedef struct TU_ATTR_PACKED
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
TU_BIT_FIELD_ORDER_BEGIN
struct TU_ATTR_PACKED {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
uint8_t : 2;
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
TU_BIT_FIELD_ORDER_END
struct TU_ATTR_PACKED {
#if defined(__CCRX__)
//FIXME the original defined bit field has a problem with the CCRX toolchain, so only a size field is defined
uint16_t size;
#else
uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint16_t hs_period_mult : 2;
uint16_t TU_RESERVED : 3;
#endif
}wMaxPacketSize;
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} tusb_desc_endpoint_t;
TU_PACK_STRUCT_END
/// USB Other Speed Configuration Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
@@ -363,8 +379,10 @@ typedef struct TU_ATTR_PACKED
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} tusb_desc_other_speed_t;
TU_PACK_STRUCT_END
/// USB Device Qualifier Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
@@ -378,8 +396,10 @@ typedef struct TU_ATTR_PACKED
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} tusb_desc_device_qualifier_t;
TU_PACK_STRUCT_END
/// USB Interface Association Descriptor (IAD ECN)
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
@@ -394,16 +414,20 @@ typedef struct TU_ATTR_PACKED
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
} tusb_desc_interface_assoc_t;
TU_PACK_STRUCT_END
// USB String Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
uint16_t unicode_string[];
} tusb_desc_string_t;
TU_PACK_STRUCT_END
// USB Binary Device Object Store (BOS)
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength;
@@ -413,8 +437,10 @@ typedef struct TU_ATTR_PACKED
uint8_t PlatformCapabilityUUID[16];
uint8_t CapabilityData[];
} tusb_desc_bos_platform_t;
TU_PACK_STRUCT_END
// USB WebuSB URL Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength;
@@ -422,14 +448,17 @@ typedef struct TU_ATTR_PACKED
uint8_t bScheme;
char url[];
} tusb_desc_webusb_url_t;
TU_PACK_STRUCT_END
// DFU Functional Descriptor
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED
{
uint8_t bLength;
uint8_t bDescriptorType;
union {
TU_BIT_FIELD_ORDER_BEGIN
struct TU_ATTR_PACKED {
uint8_t bitCanDnload : 1;
uint8_t bitCanUpload : 1;
@@ -437,6 +466,7 @@ typedef struct TU_ATTR_PACKED
uint8_t bitWillDetach : 1;
uint8_t reserved : 4;
} bmAttributes;
TU_BIT_FIELD_ORDER_END
uint8_t bAttributes;
};
@@ -445,17 +475,21 @@ typedef struct TU_ATTR_PACKED
uint16_t wTransferSize;
uint16_t bcdDFUVersion;
} tusb_desc_dfu_functional_t;
TU_PACK_STRUCT_END
/*------------------------------------------------------------------*/
/* Types
*------------------------------------------------------------------*/
TU_PACK_STRUCT_BEGIN
typedef struct TU_ATTR_PACKED{
union {
TU_BIT_FIELD_ORDER_BEGIN
struct TU_ATTR_PACKED {
uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
uint8_t type : 2; ///< Request type tusb_request_type_t.
uint8_t direction : 1; ///< Direction type. tusb_dir_t
} bmRequestType_bit;
TU_BIT_FIELD_ORDER_END
uint8_t bmRequestType;
};
@@ -465,6 +499,7 @@ typedef struct TU_ATTR_PACKED{
uint16_t wIndex;
uint16_t wLength;
} tusb_control_request_t;
TU_PACK_STRUCT_END
TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "size is not correct");