summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/arm_atsam/main_arm_atsam.c
diff options
context:
space:
mode:
authorpatrickmt <40182064+patrickmt@users.noreply.github.com>2018-12-18 21:21:25 +0100
committerDrashna Jaelre <drashna@live.com>2019-01-07 21:44:55 +0100
commit6e984a8b5e34ba181b0893a929af569a1faef2b6 (patch)
tree3648fd159ef02fe3ed7d8ae80c2755c580cd59ff /tmk_core/protocol/arm_atsam/main_arm_atsam.c
parent28986998046b4dbdbc228dbb7889836de2a3ee18 (diff)
downloadqmk_firmware-6e984a8b5e34ba181b0893a929af569a1faef2b6.tar.gz
qmk_firmware-6e984a8b5e34ba181b0893a929af569a1faef2b6.tar.xz
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.
Diffstat (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c')
-rw-r--r--tmk_core/protocol/arm_atsam/main_arm_atsam.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
index 2bda7d7c7..eaad66e9f 100644
--- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c
+++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
@@ -159,7 +159,7 @@ void send_consumer(uint16_t data)
void main_subtask_usb_state(void)
{
- static uint32_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware
+ static uint64_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware
uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; //Current state from hardware register
if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If USB SUSPENDED
@@ -188,9 +188,9 @@ void main_subtask_usb_state(void)
{
if (fsmstate_on_delay == 0) //If ON delay timer is cleared
{
- fsmstate_on_delay = CLK_get_ms() + 250; //Set ON delay timer
+ fsmstate_on_delay = timer_read64() + 250; //Set ON delay timer
}
- else if (CLK_get_ms() > fsmstate_on_delay) //Else if ON delay timer is active and timed out
+ else if (timer_read64() > fsmstate_on_delay) //Else if ON delay timer is active and timed out
{
suspend_wakeup_init(); //Run wakeup routine
g_usb_state = fsmstate_now; //Save current USB state
@@ -214,9 +214,9 @@ void main_subtask_power_check(void)
{
static uint64_t next_5v_checkup = 0;
- if (CLK_get_ms() > next_5v_checkup)
+ if (timer_read64() > next_5v_checkup)
{
- next_5v_checkup = CLK_get_ms() + 5;
+ next_5v_checkup = timer_read64() + 5;
v_5v = adc_get(ADC_5V);
v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v;
@@ -229,9 +229,9 @@ void main_subtask_usb_extra_device(void)
{
static uint64_t next_usb_checkup = 0;
- if (CLK_get_ms() > next_usb_checkup)
+ if (timer_read64() > next_usb_checkup)
{
- next_usb_checkup = CLK_get_ms() + 10;
+ next_usb_checkup = timer_read64() + 10;
USB_HandleExtraDevice();
}
@@ -325,9 +325,9 @@ int main(void)
keyboard_task();
#ifdef CONSOLE_ENABLE
- if (CLK_get_ms() > next_print)
+ if (timer_read64() > next_print)
{
- next_print = CLK_get_ms() + 250;
+ next_print = timer_read64() + 250;
//Add any debug information here that you want to see very often
//dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
}