Skip to content

Timer

Timer Driver.

Functions for using a hardware timer

Sysprops

syspropdescription
modethe timer mode as per TIMER_MODE_XX define (optional, defaults to TIMER_MODE_COUNT
gpiothe gpio to be used in TIMER_MODE_CC_xx modes
channelthe timer channel (optional, driver dependent)

Types

Name
typedef void(*)(uint32_t value)timer_callback_f

Functions Overview

Name
CW_DRIVER_FUNCtimer_start(int hDev, const uint8_t type, const uint32_t freq, timer_callback_f cb)
CW_DRIVER_FUNCtimer_stop(int hDev)
CW_DRIVER_FUNCtimer_config(int hDev, const uint8_t mode, const uint8_t channel, const uint32_t gpio)

Defines

Name
TIMER_TYPE_PERIODIC
TIMER_TYPE_ONCE
TIMER_MODE_COUNT
TIMER_MODE_CC_RISINGcapture timer on input rising edge
TIMER_MODE_CC_FALLINGcapture timer on input falling edge
TIMER_MODE_CC_OUTPUTtoggle output at timer frequency

Types Documentation

typedef timer_callback_f

cpp
typedef void(* timer_callback_f) (uint32_t value);

Function Details

function timer_start

cpp
CW_DRIVER_FUNC timer_start(
    int hDev,
    const uint8_t type,
    const uint32_t freq,
    timer_callback_f cb
)

Parameters:

  • hDev
  • type
  • freq
  • cb callback for input capture or counting mode. set to NULL in CC_OUTPUT mode.

Return:

function timer_stop

cpp
CW_DRIVER_FUNC timer_stop(
    int hDev
)

Parameters:

  • hDev

Return:

function timer_config

cpp
CW_DRIVER_FUNC timer_config(
    int hDev,
    const uint8_t mode,
    const uint8_t channel,
    const uint32_t gpio
)

Parameters:

  • hDev
  • mode
  • channel
  • gpio

Return:

Macros Documentation

define TIMER_TYPE_PERIODIC

cpp
#define TIMER_TYPE_PERIODIC (0)

define TIMER_TYPE_ONCE

cpp
#define TIMER_TYPE_ONCE (1)

define TIMER_MODE_COUNT

cpp
#define TIMER_MODE_COUNT (0)

define TIMER_MODE_CC_RISING

cpp
#define TIMER_MODE_CC_RISING (1)

capture timer on input rising edge

define TIMER_MODE_CC_FALLING

cpp
#define TIMER_MODE_CC_FALLING (2)

capture timer on input falling edge

define TIMER_MODE_CC_OUTPUT

cpp
#define TIMER_MODE_CC_OUTPUT (3)

toggle output at timer frequency