Skip to content

Commit

Permalink
change dcd_init() to take rhport struct
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Oct 11, 2024
1 parent 92602b9 commit d997f00
Show file tree
Hide file tree
Showing 31 changed files with 83 additions and 58 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ repos:
pass_filenames: false
types_or: [c, header]
language: system

- id: build-fuzzer
name: build-fuzzer
files: ^(src/|test/fuzz/)
language: system
types_or: [c, header]
entry: |
export CC=clang
export CXX=clang++
fuzz_harness=$(ls -d test/fuzz/device/*/)
for h in $fuzz_harness
do
make -C $h get-deps
make -C $h all
done
2 changes: 1 addition & 1 deletion src/device/dcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W
//--------------------------------------------------------------------+

// Initialize controller to device mode
void dcd_init(uint8_t rhport);
void dcd_init(const tusb_rhport_init_t* rh_init);

// Deinitialize controller, unset device mode.
bool dcd_deinit(uint8_t rhport);
Expand Down
2 changes: 1 addition & 1 deletion src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ bool tud_rhport_init(const tusb_rhport_init_t* rh_init) {
_usbd_rhport = rh_init->rhport;

// Init device controller driver
dcd_init(rh_init->rhport);
dcd_init(rh_init);
dcd_int_enable(rh_init->rhport);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/bridgetek/ft9xx/dcd_ft9xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ static uint16_t _ft9xx_dusb_out(uint8_t ep_number, uint8_t *buffer, uint16_t len
*------------------------------------------------------------------*/

// Initialize controller to device mode
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
TU_LOG2("FT9xx initialisation\r\n");

_dcd_ft9xx_attach();
Expand Down
4 changes: 2 additions & 2 deletions src/portable/chipidea/ci_fs/dcd_ci_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

// save crystal-less setting (if available)
Expand Down
4 changes: 2 additions & 2 deletions src/portable/chipidea/ci_hs/dcd_ci_hs.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ static void bus_reset(uint8_t rhport)
dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t));
}

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
tu_memclr(&_dcd_data, sizeof(dcd_data_t));

ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
Expand Down
4 changes: 2 additions & 2 deletions src/portable/dialog/da146xx/dcd_da146xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ static void handle_ep0_nak(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

_dcd.init_called = true;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/espressif/esp32sx/dcd_esp32sx.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ static void enum_done_processing(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
ESP_LOGV(TAG, "DCD init - Start");

// A. Disconnect
Expand Down
3 changes: 2 additions & 1 deletion src/portable/mentor/musb/dcd_musb.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ void print_musb_info(musb_regs_t* musb_regs) {
}
#endif

void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
musb_regs_t* musb_regs = MUSB_REGS(rhport);

#if CFG_TUSB_DEBUG >= MUSB_DEBUG
Expand Down
4 changes: 2 additions & 2 deletions src/portable/microchip/pic/dcd_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
intr_disable(rhport);
intr_clear(rhport);

Expand Down
4 changes: 2 additions & 2 deletions src/portable/microchip/pic32mz/dcd_pic32mz.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static ep0_stage_t ep0_get_stage(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
// Disable endpoint interrupts for now
USB_REGS->INTRRXEbits.w = 0;
USB_REGS->INTRTXEbits.w = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ static void process_bus_active(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

tu_memclr(&_dcd, sizeof(_dcd));
Expand Down
3 changes: 2 additions & 1 deletion src/portable/nordic/nrf5x/dcd_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ static void xact_in_dma(uint8_t epnum) {
//--------------------------------------------------------------------+
// Controller API
//--------------------------------------------------------------------+
void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
TU_LOG2("dcd init\r\n");
(void) rhport;
}
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nuvoton/nuc120/dcd_nuc120.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS
NUC100/NUC120 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

USBD->ATTR = 0x7D0;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nuvoton/nuc121/dcd_nuc121.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ enum {
NUC121/NUC125/NUC126 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

#ifdef SUPPORT_LPM
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nuvoton/nuc505/dcd_nuc505.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \
NUC505 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

/* configure interrupts in their initial state; BUSINTEN and CEPINTEN will be subsequently and dynamically re-written as needed */
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nxp/khci/dcd_khci.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

// save crystal-less setting (if available)
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nxp/lpc17_40/dcd_lpc17_40.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ static void bus_reset(void)
tu_memclr(&_dcd, sizeof(dcd_data_t));
}

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

//------------- user manual 11.13 usb device controller initialization -------------//
Expand Down
4 changes: 2 additions & 2 deletions src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ static void edpt_reset_all(uint8_t rhport)
}
prepare_setup_packet(rhport);
}
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
edpt_reset_all(rhport);

dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
Expand Down
3 changes: 2 additions & 1 deletion src/portable/raspberrypi/rp2040/dcd_rp2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void) {
#define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff
#endif

void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
assert(rhport == 0);

TU_LOG(2, "Chip Version B%u\r\n", rp2040_chip_version());
Expand Down
4 changes: 2 additions & 2 deletions src/portable/renesas/rusb2/dcd_rusb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ static void enable_interrupt(uint32_t pswi)
}
#endif

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
rusb2_reg_t* rusb = RUSB2_REG(rhport);
rusb2_module_start(rhport, true);

Expand Down
4 changes: 2 additions & 2 deletions src/portable/sony/cxd56/dcd_cxd56.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ static void _dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbd
dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
}

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

usbdcd_driver.usbdevclass_driver.speed = USB_SPEED_HIGH;
Expand Down
3 changes: 2 additions & 1 deletion src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t *xfer_ctl_ptr(uint8_t epnum, uint
//--------------------------------------------------------------------+
// Controller API
//--------------------------------------------------------------------+
void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
// Follow the RM mentions to use a special ordering of PDWN and FRES
for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
asm("NOP");
Expand Down
4 changes: 2 additions & 2 deletions src/portable/sunxi/dcd_sunxi_musb.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ static void usb_isr_handler(void) {
dcd_int_handler(0);
}

void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
dcd_disconnect(rhport);
USBC_HardwareReset();
USBC_PhyConfig();
Expand Down
3 changes: 2 additions & 1 deletion src/portable/synopsys/dwc2/dcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,10 @@ static bool check_dwc2(dwc2_regs_t* dwc2) {
return true;
}

void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
// Programming model begins in the last section of the chapter on the USB
// peripheral in each Reference Manual.
const uint8_t rhport = rh_init->rhport;
dwc2_regs_t* dwc2 = DWC2_REG(rhport);

// Check Synopsys ID register, failed if controller clock/power is not enabled
Expand Down
12 changes: 8 additions & 4 deletions src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ static void enable_functional_reset(const bool enable)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init (uint8_t rhport)
{
(void) rhport;
void dcd_init(const tusb_rhport_init_t* rh_init) {
(void) rh_init;

USBKEYPID = USBKEY;

Expand Down Expand Up @@ -699,7 +698,12 @@ static void handle_bus_power_event(void *param) {

// A successful lock is indicated by all PLL-related interrupt flags being cleared.
if(!USBPLLIR) {
dcd_init(0); // Re-initialize the USB module.
const tusb_rhport_init_t rhport_init = {
.rhport = 0,
.role = TUSB_ROLE_DEVICE,
.speed = TUSB_SPEED_FULL
};
dcd_init(&rhport_init); // Re-initialize the USB module.
}
} else { // Event caused by removal of bus power.
USBPWRCTL |= VBONIE; // Enable bus-power-applied interrupt.
Expand Down
4 changes: 2 additions & 2 deletions src/portable/valentyusb/eptri/dcd_eptri.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ static void dcd_reset(void)
}

// Initializes the USB peripheral for device mode and enables it.
void dcd_init(uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

usb_pullup_out_write(0);
Expand Down
3 changes: 2 additions & 1 deletion src/portable/wch/dcd_ch32_usbfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) {
}

/* public functions */
void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
// init registers
USBOTG_FS->BASE_CTRL = USBFS_CTRL_SYS_CTRL | USBFS_CTRL_INT_BUSY | USBFS_CTRL_DMA_EN;
USBOTG_FS->UDEV_CTRL = USBFS_UDEV_CTRL_PD_DIS | USBFS_UDEV_CTRL_PORT_EN;
Expand Down
3 changes: 2 additions & 1 deletion src/portable/wch/dcd_ch32_usbhs.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ static void xfer_data_packet(uint8_t ep_num, tusb_dir_t ep_dir, xfer_ctl_t* xfer
ep_set_response_and_toggle(ep_num, ep_dir, USBHS_EP_R_RES_ACK);
}

void dcd_init(uint8_t rhport) {
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
(void) rhport;

memset(&xfer_status, 0, sizeof(xfer_status));
Expand Down
7 changes: 3 additions & 4 deletions test/unit-test/test/device/msc/test_msc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,14 @@ void setUp(void)
dcd_int_disable_Ignore();
dcd_int_enable_Ignore();

if ( !tud_inited() )
{
dcd_init_Expect(rhport);

if ( !tud_inited() ) {
tusb_rhport_init_t dev_init = {
.rhport = 0,
.role = TUSB_ROLE_DEVICE,
.speed = TUSB_SPEED_AUTO
};

dcd_init_Expect(&dev_init);
tusb_init(&dev_init);
}

Expand Down
10 changes: 5 additions & 5 deletions test/unit-test/test/device/usbd/test_usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ void setUp(void)
dcd_int_disable_Ignore();
dcd_int_enable_Ignore();

if ( !tud_inited() )
{
mscd_init_Expect();
dcd_init_Expect(rhport);

if ( !tud_inited() ) {
tusb_rhport_init_t dev_init = {
.rhport = 0,
.role = TUSB_ROLE_DEVICE,
.speed = TUSB_SPEED_AUTO
};

mscd_init_Expect();
dcd_init_Expect(&dev_init);

tusb_init(&dev_init);
}
}
Expand Down

0 comments on commit d997f00

Please sign in to comment.