1 // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
3 // This file is part of SCSI2SD.
5 // SCSI2SD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // SCSI2SD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
17 #pragma GCC push_options
18 #pragma GCC optimize("-flto")
23 static volatile uint32_t counter = 0;
25 CY_ISR_PROTO(TickISR);
28 // Should be atomic at 32bit word size. Limits runtime to 49 days.
34 // Interrupt 15. SysTick_IRQn is -1.
35 // The SysTick timer is integrated into the Arm Cortex M3
36 CyIntSetSysVector((SysTick_IRQn + 16), TickISR);
38 // Ensure the cycle count is < 24bit.
39 // At 50MHz bus clock, counter is 50000.
40 SysTick_Config((BCLK__BUS_CLK__HZ + 999u) / 1000u);
48 uint32_t diffTime_ms(uint32_t start, uint32_t end)
56 return (UINT_MAX - start) + end;
60 uint32_t elapsedTime_ms(uint32_t since)
62 uint32_t now = counter;
69 return (UINT_MAX - since) + now;
73 #pragma GCC pop_options