Plant Monitor SAM3X8E
Loading...
Searching...
No Matches
tc.c
Go to the documentation of this file.
1
9
10#include "hal/tc.h"
11
12void tc_init(void)
13{
14 /* Enable clock for TC0 & configure
15 * TC0->Channel0 to use internal MCK/2 */
16 PMC->PMC_PCER0 |= (1u << ID_TC0);
17 TC0->TC_CHANNEL[0].TC_CMR |= TC_CMR_TCCLKS_TIMER_CLOCK1;
18
19 /* Reset & start clock for TC0->Channel0 */
20 TC0->TC_CHANNEL[0].TC_CCR = (TC_CCR_CLKEN | TC_CCR_SWTRG);
21}
22
23void tc_delay_us(uint32_t us)
24{
25 uint32_t start = TC0->TC_CHANNEL[0].TC_CV;
26 uint32_t end = us * 42u;
27
28 /* Spin until enough ticks have elapsed */
29 while ((uint32_t)(TC0->TC_CHANNEL[0].TC_CV - start) < end);
30}
31
32void tc_delay_ms(uint32_t ms)
33{
34 uint32_t start = TC0->TC_CHANNEL[0].TC_CV;
35 uint32_t end = ms * 42000u;
36
37 /* Spin until enough ticks have elapsed */
38 while ((uint32_t)(TC0->TC_CHANNEL[0].TC_CV - start) < end);
39}
40
41void wdt_disable(void)
42{
43 WDT->WDT_MR |= WDT_MR_WDDIS;
44}
void tc_delay_ms(uint32_t ms)
Creates a hardware delay in milliseconds.
Definition tc.c:32
void tc_delay_us(uint32_t us)
Creates a hardware delay in microseconds.
Definition tc.c:23
void tc_init(void)
Initializes TC0->Channel0.
Definition tc.c:12
void wdt_disable(void)
Disables SAM3X8E watchdog timer.
Definition tc.c:41
HAL interface for timer counter of SAM3X8E.