Plant Monitor SAM3X8E
Loading...
Searching...
No Matches
tc.h File Reference

HAL interface for timer counter of SAM3X8E. More...

#include <stdint.h>
#include "sam3xa.h"

Go to the source code of this file.

Functions

void tc_init (void)
 Initializes TC0->Channel0.
void tc_delay_us (uint32_t us)
 Creates a hardware delay in microseconds.
void tc_delay_ms (uint32_t ms)
 Creates a hardware delay in milliseconds.
void wdt_disable (void)
 Disables SAM3X8E watchdog timer.

Detailed Description

HAL interface for timer counter of SAM3X8E.

Contains functions associated with hardware delay using internal timer counter peripheral.

Author
Vladimir Zhelev

Definition in file tc.h.

Function Documentation

◆ tc_delay_ms()

void tc_delay_ms ( uint32_t ms)

Creates a hardware delay in milliseconds.

Parameters
msDelay duration in milliseconds.

Definition at line 32 of file tc.c.

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}

◆ tc_delay_us()

void tc_delay_us ( uint32_t us)

Creates a hardware delay in microseconds.

Parameters
usDelay duration in microseconds.

Definition at line 23 of file tc.c.

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}

◆ tc_init()

void tc_init ( void )

Initializes TC0->Channel0.

Enables peripheral clock and configures TC0->Channel0 to use internal MCK/2 clock

Definition at line 12 of file tc.c.

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}

◆ wdt_disable()

void wdt_disable ( void )

Disables SAM3X8E watchdog timer.

Disables watchdog timer, as otherwise MCU resets every ~16 seconds.

Definition at line 41 of file tc.c.

42{
43 WDT->WDT_MR |= WDT_MR_WDDIS;
44}