1 /*
2  * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _HARDWARE_TICKS_H
8 #define _HARDWARE_TICKS_H
9 
10 /** \file hardware/tick.h
11  *  \defgroup hardware_ticks hardware_ticks
12  *
13  * \brief Hardware Tick API
14  *
15  * \if rp2040_specific
16  * RP2040 only has one tick generator, and it is part of the watchdog hardware.
17  * \endif
18  *
19  * \if rp2350_specific
20  * The RP2350 has a dedicated Tick block that is used to supply ticks to TIMER0, TIMER1,
21  * RISC-V platform timer, Arm Cortex-M33 0 timer, Arm Cortex-M33 1 timer and the WATCHDOG block.
22  * \endif
23  */
24 
25 #include "pico.h"
26 #if !PICO_RP2040
27 #include "hardware/structs/ticks.h"
28 #else
29 #include "hardware/watchdog.h"
30 /*! \brief Tick generator numbers on RP2040 (used as typedef \ref tick_gen_num_t)
31  *  \ingroup hardware_ticks
32  *
33  * RP2040 only has one tick generator, and it is part of the watchdog hardware
34  */
35 typedef enum tick_gen_num_rp2040 {
36     TICK_WATCHDOG = 0,
37     TICK_COUNT
38 } tick_gen_num_t;
39 #endif
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 // PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_TICKS, Enable/disable assertions in the hardware_ticks module, type=bool, default=0, group=hardware_ticks
46 #ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_TICKS
47 #define PARAM_ASSERTIONS_ENABLED_HARDWARE_TICKS 0
48 #endif
49 
50 /*! \brief Start a tick generator
51  *  \ingroup hardware_ticks
52  *
53  * \param tick The tick generator number
54  * \param cycles The number of clock cycles per tick
55  */
56 void tick_start(tick_gen_num_t tick, uint cycles);
57 
58 
59 /*! \brief Stop a tick generator
60  *  \ingroup hardware_ticks
61  *
62  * \param tick The tick generator number
63  */
64 void tick_stop(tick_gen_num_t tick);
65 
66 /*! \brief Check if a tick genererator is currently running
67  *  \ingroup hardware_ticks
68  *
69  * \param tick The tick generator number
70  * \return true if the specific ticker is running.
71  */
72 bool tick_is_running(tick_gen_num_t tick);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
79