xref: /btstack/port/renesas-tb-s1ja-cc256x/template/btstack_example/synergy/ssp/inc/driver/instances/r_gpt.h (revision 3b5c872a8c45689e8cc17891f01530f5aa5e911c)
1 /***********************************************************************************************************************
2  * Copyright [2015-2017] Renesas Electronics Corporation and/or its licensors. All Rights Reserved.
3  *
4  * This file is part of Renesas SynergyTM Software Package (SSP)
5  *
6  * The contents of this file (the "contents") are proprietary and confidential to Renesas Electronics Corporation
7  * and/or its licensors ("Renesas") and subject to statutory and contractual protections.
8  *
9  * This file is subject to a Renesas SSP license agreement. Unless otherwise agreed in an SSP license agreement with
10  * Renesas: 1) you may not use, copy, modify, distribute, display, or perform the contents; 2) you may not use any name
11  * or mark of Renesas for advertising or publicity purposes or in connection with your use of the contents; 3) RENESAS
12  * MAKES NO WARRANTY OR REPRESENTATIONS ABOUT THE SUITABILITY OF THE CONTENTS FOR ANY PURPOSE; THE CONTENTS ARE PROVIDED
13  * "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT; AND 4) RENESAS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, OR
15  * CONSEQUENTIAL DAMAGES, INCLUDING DAMAGES RESULTING FROM LOSS OF USE, DATA, OR PROJECTS, WHETHER IN AN ACTION OF
16  * CONTRACT OR TORT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE CONTENTS. Third-party contents
17  * included in this file may be subject to different terms.
18  **********************************************************************************************************************/
19 
20 /**********************************************************************************************************************
21  * File Name    : r_gpt.h
22  * Description  : Prototypes of GPT functions used to implement various timer interfaces.
23  **********************************************************************************************************************/
24 
25 #ifndef R_GPT_H
26 #define R_GPT_H
27 
28 /*******************************************************************************************************************//**
29  * @ingroup HAL_Library
30  * @defgroup GPT GPT
31  * @brief Driver for the General PWM Timer (GPT).
32  *
33  * @section GPT_SUMMARY Summary
34  * Extends @ref TIMER_API.
35  *
36  * This module implements the @ref TIMER_API using the General PWM Timer (GPT) peripherals GPT32EH, GPT32E, GPT32.
37  * It also provides an output compare
38  * extension to output the timer signal to the GTIOC pin.
39  * @{
40  **********************************************************************************************************************/
41 
42 /***********************************************************************************************************************
43  * Includes
44  **********************************************************************************************************************/
45 #include "bsp_api.h"
46 #include "r_timer_api.h"
47 
48 /* Common macro for SSP header files. There is also a corresponding SSP_FOOTER macro at the end of this file. */
49 SSP_HEADER
50 
51 /***********************************************************************************************************************
52  * Macro definitions
53  **********************************************************************************************************************/
54 #define GPT_CODE_VERSION_MAJOR (1U)
55 #define GPT_CODE_VERSION_MINOR (13U)
56 
57 /***********************************************************************************************************************
58  * Typedef definitions
59  **********************************************************************************************************************/
60 /** Level of GPT pin */
61 typedef enum e_gpt_pin_level
62 {
63     GPT_PIN_LEVEL_LOW      = 0,     ///< Pin level low
64     GPT_PIN_LEVEL_HIGH     = 1,     ///< Pin level high
65     GPT_PIN_LEVEL_RETAINED = 2      ///< Pin level retained
66 } gpt_pin_level_t;
67 
68 /** GPT PWM shortest pin level */
69 typedef enum e_gpt_shortest_level
70 {
71     /** 1 extra PCLK in ON time. Minimum ON time will be limited to 2 PCLK raw counts. */
72     GPT_SHORTEST_LEVEL_OFF      = 0,
73     /** 1 extra PCLK in OFF time. Minimum ON time will be limited to 1 PCLK raw counts. */
74     GPT_SHORTEST_LEVEL_ON       = 1,
75 }gpt_shortest_level_t;
76 
77 /** Sources can be used to start the timer, stop the timer, count up, or count down. */
78 typedef enum e_gpt_trigger
79 {
80     /** No action performed. */
81     GPT_TRIGGER_NONE                             = 0,
82     /** Action performed when GTIOCA input rises while GTIOCB is low. **/
83     GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_LOW   = (1UL << 8),
84     /** Action performed when GTIOCA input rises while GTIOCB is high. **/
85     GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_HIGH  = (1UL << 9),
86     /** Action performed when GTIOCA input falls while GTIOCB is low. **/
87     GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_LOW  = (1UL << 10),
88     /** Action performed when GTIOCA input falls while GTIOCB is high. **/
89     GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_HIGH = (1UL << 11),
90     /** Action performed when GTIOCB input rises while GTIOCA is low. **/
91     GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_LOW   = (1UL << 12),
92     /** Action performed when GTIOCB input rises while GTIOCA is high. **/
93     GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_HIGH  = (1UL << 13),
94     /** Action performed when GTIOCB input falls while GTIOCA is low. **/
95     GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_LOW  = (1UL << 14),
96     /** Action performed when GTIOCB input falls while GTIOCA is high. **/
97     GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_HIGH = (1UL << 15),
98     /** Enables settings in the Source Select Register. **/
99     GPT_TRIGGER_SOURCE_REGISTER_ENABLE           = (1UL << 31)
100 } gpt_trigger_t;
101 
102 /** Output level used when selecting what happens at compare match or cycle end. */
103 typedef enum e_gpt_output
104 {
105     GPT_OUTPUT_RETAINED = 0,       ///< Output retained
106     GPT_OUTPUT_LOW      = 1,       ///< Output low
107     GPT_OUTPUT_HIGH     = 2,       ///< Output high
108     GPT_OUTPUT_TOGGLED  = 3        ///< Output toggled
109 } gpt_output_t;
110 
111 /** Configurations for output pins. */
112 typedef struct s_gpt_output_pin
113 {
114     bool             output_enabled; ///< Set to true to enable output, false to disable output
115     gpt_pin_level_t  stop_level;     ///< Select a stop level from ::gpt_pin_level_t
116 } gpt_output_pin_t;
117 
118 /** Channel control block. DO NOT INITIALIZE.  Initialization occurs when timer_api_t::open is called. */
119 typedef struct st_gpt_instance_ctrl
120 {
121     /** Callback provided when a timer ISR occurs.  NULL indicates no CPU interrupt. */
122     void (* p_callback)(timer_callback_args_t * p_args);
123 
124     /** Placeholder for user data.  Passed to the user callback in ::timer_callback_args_t. */
125     void const            * p_context;
126     void                  * p_reg;                  ///< Base register for this channel
127     uint32_t                open;                   ///< Whether or not channel is open
128     uint8_t                 channel;                ///< Channel number.
129     bool                    one_shot;               ///< Whether or not timer is in one shot mode
130     bool                    gtioca_output_enabled;  ///< Set to true to enable gtioca pin output
131     bool                    gtiocb_output_enabled;  ///< Set to true to enable gtiocb pin output
132     IRQn_Type               irq;                    ///< Counter overflow IRQ number
133     timer_variant_t         variant;                ///< Timer variant
134     gpt_shortest_level_t    shortest_pwm_signal;    ///< Shortest PWM signal level
135 } gpt_instance_ctrl_t;
136 
137 /** GPT extension configures the output pins for GPT. */
138 typedef struct st_timer_on_gpt_cfg
139 {
140     gpt_output_pin_t  gtioca;       ///< Configuration for GPT I/O pin A
141     gpt_output_pin_t  gtiocb;       ///< Configuration for GPT I/O pin B
142     gpt_shortest_level_t  shortest_pwm_signal;      ///< Shortest PWM signal level
143 } timer_on_gpt_cfg_t;
144 
145 /**********************************************************************************************************************
146  * Exported global variables
147  **********************************************************************************************************************/
148 /** @cond INC_HEADER_DEFS_SEC */
149 /** Filled in Interface API structure for this Instance. */
150 extern const timer_api_t g_timer_on_gpt;
151 /** @endcond */
152 
153 /*******************************************************************************************************************//**
154  * @} (end defgroup GPT)
155  **********************************************************************************************************************/
156 
157 /* Common macro for SSP header files. There is also a corresponding SSP_HEADER macro at the top of this file. */
158 SSP_FOOTER
159 
160 #endif /* R_GPT_H */
161