From 6e984a8b5e34ba181b0893a929af569a1faef2b6 Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Tue, 18 Dec 2018 15:21:25 -0500 Subject: Update to arm_atsam wait and timer routines Microsecond (us) delays are now handled by a busy wait loop according to MCU frequency. This replaces the system counter method which had an overhead of around 12us. TC5 device and supporting routines removed as it was the old us delay counter. wait_ms is now properly a macro to CLK_delay_ms. wait_us is now properly a macro to CLK_delay_us. Removed CLK_get_us as it has no use. All calls to CLK_get_ms() have been replaced by timer_read64() with corrected typing. All calls to CLK_delay_ms() have been replaced by wait_ms(). All calls to CLK_delay_us() have been replaced by wait_us() and timings verified or updated as needed after review on scope. Corrected typing of variables using 64bit ms timer readings if needed. --- tmk_core/protocol/arm_atsam/usb/usb2422.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/usb/usb2422.c') diff --git a/tmk_core/protocol/arm_atsam/usb/usb2422.c b/tmk_core/protocol/arm_atsam/usb/usb2422.c index ac19bf4ea..d6e192242 100644 --- a/tmk_core/protocol/arm_atsam/usb/usb2422.c +++ b/tmk_core/protocol/arm_atsam/usb/usb2422.c @@ -64,7 +64,7 @@ void USB_write2422_block(void) i2c0_transmit(USB2422_ADDR, dest, 34, 50000); SERCOM0->I2CM.CTRLB.bit.CMD = 0x03; while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP); } - CLK_delay_us(100); + wait_us(100); } DBGC(DC_USB_WRITE2422_BLOCK_COMPLETE); @@ -135,7 +135,7 @@ void USB2422_init(void) sr_exp_data.bit.HUB_RESET_N = 1; //reset high SR_EXP_WriteData(); - CLK_delay_us(100); + wait_us(100); #ifndef MD_BOOTLOADER @@ -154,10 +154,9 @@ void USB_reset(void) //pulse reset for at least 1 usec sr_exp_data.bit.HUB_RESET_N = 0; //reset low SR_EXP_WriteData(); - CLK_delay_us(1); + wait_us(2); sr_exp_data.bit.HUB_RESET_N = 1; //reset high to run SR_EXP_WriteData(); - CLK_delay_us(1); DBGC(DC_USB_RESET_COMPLETE); } @@ -247,7 +246,7 @@ void USB_set_host_by_voltage(void) SR_EXP_WriteData(); - CLK_delay_ms(250); + wait_ms(250); while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB_SET_HOST_5V_LOW_WAITING); } @@ -313,11 +312,11 @@ uint8_t USB2422_Port_Detect_Init(void) USB_set_host_by_voltage(); - port_detect_retry_ms = CLK_get_ms() + PORT_DETECT_RETRY_INTERVAL; + port_detect_retry_ms = timer_read64() + PORT_DETECT_RETRY_INTERVAL; while (!USB_active()) { - tmod = CLK_get_ms() % PORT_DETECT_RETRY_INTERVAL; + tmod = timer_read64() % PORT_DETECT_RETRY_INTERVAL; if (v_con_1 > v_con_2) //Values updated from USB_set_host_by_voltage(); { @@ -333,7 +332,7 @@ uint8_t USB2422_Port_Detect_Init(void) else { DBG_LED_OFF; } } - if (CLK_get_ms() > port_detect_retry_ms) + if (timer_read64() > port_detect_retry_ms) { DBGC(DC_PORT_DETECT_INIT_FAILED); return 0; -- cgit v1.2.3-24-g4f1b