mirror of
https://github.com/dougg3/mac-rom-simm-programmer.git
synced 2024-11-26 02:49:16 +00:00
Enable timer, use for delay functions
This commit is contained in:
parent
6a9b75d01b
commit
9df4cd0c84
@ -51,6 +51,12 @@ void Board_Init(void)
|
||||
// Enable USB device controller
|
||||
CLK->APBCLK0 |= CLK_APBCLK0_USBDCKEN_Msk;
|
||||
|
||||
// Enable timer 0
|
||||
CLK->APBCLK0 |= CLK_APBCLK0_TMR0CKEN_Msk;
|
||||
|
||||
// Timer 0 clock source = 48 MHz HIRC
|
||||
CLK->CLKSEL1 = (CLK->CLKSEL1 & (~(CLK_CLKSEL1_TMR0SEL_Msk))) | (7UL << CLK_CLKSEL1_TMR0SEL_Pos);
|
||||
|
||||
// Enable all GPIO
|
||||
CLK->AHBCLK |=
|
||||
CLK_AHBCLK_GPACKEN_Msk |
|
||||
@ -59,6 +65,9 @@ void Board_Init(void)
|
||||
CLK_AHBCLK_GPDCKEN_Msk |
|
||||
CLK_AHBCLK_GPECKEN_Msk |
|
||||
CLK_AHBCLK_GPFCKEN_Msk;
|
||||
|
||||
// Start the timer, prescaler = 48, so 1 MHz
|
||||
TIMER0->CTL = TIMER_CTL_CNTEN_Msk | (3UL << TIMER_CTL_OPMODE_Pos) | 47;
|
||||
}
|
||||
|
||||
/** Determines if a brownout was detected at startup
|
||||
|
@ -44,22 +44,27 @@ static inline void EnableInterrupts(void)
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
/** Blocks for the specified number of milliseconds
|
||||
*
|
||||
* @param ms The number of milliseconds to wait
|
||||
*/
|
||||
static inline void DelayMS(uint32_t ms)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** Blocks for the specified number of microseconds
|
||||
*
|
||||
* @param us The number of microseconds to wait
|
||||
*/
|
||||
static inline void DelayUS(uint32_t us)
|
||||
{
|
||||
const uint32_t startTime = TIMER0->CNT & 0xFFFFFFUL;
|
||||
uint32_t nowTime;
|
||||
do
|
||||
{
|
||||
nowTime = TIMER0->CNT & 0xFFFFFFUL;
|
||||
} while (((nowTime - startTime) & 0xFFFFFFUL) < us);
|
||||
}
|
||||
|
||||
/** Blocks for the specified number of milliseconds
|
||||
*
|
||||
* @param ms The number of milliseconds to wait
|
||||
*/
|
||||
static inline void DelayMS(uint32_t ms)
|
||||
{
|
||||
DelayUS(ms * 1000UL);
|
||||
}
|
||||
|
||||
#endif /* HAL_M258KE_HARDWARE_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user