source: rtems/bsps/arm/beagle/include/bsp/bbb-pwm.h @ 320cb42

Last change on this file since 320cb42 was 320cb42, checked in by James Fitzsimons <james.fitzsimons@…>, on 02/23/21 at 08:18:40

bsps/beagle: Updating licences to latest BSD 2 clause

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief BeagleBone Black PWM support definitions.
7 */
8
9/*
10 * SPDX-License-Identifier: BSD-2-Clause
11 *
12 * Copyright (c) 2016 Punit Vara <punitvara@gmail.com>
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37/** Some constants are taken from
38 * https://github.com/VegetableAvenger/BBBIOlib/blob/master/BBBio_lib/BBBiolib_PWMSS.h
39 */
40
41#ifndef LIBBSP_ARM_BEAGLE_BBB_PWM_H
42#define LIBBSP_ARM_BEAGLE_BBB_PWM_H
43
44#ifdef __cplusplus
45extern "C" {
46#endif /* __cplusplus */
47
48/**
49 * @brief  BeagleBone Black PWM Macros.
50 */
51#define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
52#define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
53
54
55typedef enum{
56  BBB_P8_13_2B = 3,
57  BBB_P8_19_2A,
58  BBB_P8_45_2A,
59  BBB_P8_46_2B,
60  BBB_P8_34_1B,
61  BBB_P8_36_1A,
62  BBB_P9_14_1A,
63  BBB_P9_16_1B,
64  BBB_P9_21_0B,
65  BBB_P9_22_0A,
66  BBB_P9_29_0B,
67  BBB_P9_31_0A
68}bbb_pwm_pin_t;
69
70#define BBB_P8_13_MUX_PWM 4
71#define BBB_P8_19_MUX_PWM 4
72#define BBB_P8_45_MUX_PWM 3
73#define BBB_P8_46_MUX_PWM 3
74#define BBB_P8_34_MUX_PWM 2
75#define BBB_P8_36_MUX_PWM 2
76#define BBB_P9_14_MUX_PWM 6
77#define BBB_P9_16_MUX_PWM 6
78#define BBB_P9_21_MUX_PWM 3
79#define BBB_P9_22_MUX_PWM 3
80#define BBB_P9_29_MUX_PWM 1
81#define BBB_P9_31_MUX_PWM 1
82#define BBB_PWM_FREQ_THRESHOLD 0.5f
83
84/**
85 * @brief  BeagleBone Black PWM API.
86 */
87
88/**
89 * @brief This function intilizes clock for pwm sub system.
90 *
91 * @param PWMSS_ID It is the instance number of EPWM of pwm sub system.
92 *
93 * @return true if successful
94 * @return false if not successful
95 *
96 **/
97bool beagle_pwm_init(BBB_PWMSS pwmss_id);
98
99/* PWMSS setting
100 *      set pulse argument of epwm module
101 *
102 *      @param pwm_id    : EPWMSS number , 0~2
103 *      @param pwm_freq : frequency to be generated
104 *      @param dutyA    : Duty Cycle(in percentage) in PWM channel A
105 *      @param dutyB    : Duty Cycle(in percentage) in PWM channel B
106 *
107 *      @return         : 1 for success
108 *      @return         : 0 for failed
109 *
110 *      @example        :  beagle_pwm_configure(0 , 50.0f , 50.0f , 25.0f);      // Generate 50HZ pwm in PWM0 ,
111 *                                                                              // duty cycle is 50% for ePWM0A , 25% for ePWM0B
112 *
113 *      @Note :
114 *              find an number nearst 65535 for TBPRD , to improve duty precision,
115 *
116 *              Using big TBPRD can increase the range of CMPA and CMPB ,
117 *              and it means we can get better precision on duty cycle.
118 *
119 *              EX : 20.25% duty cycle
120 *                  on TBPRD = 62500 , CMPA = 12656.25 ( .25 rejection) , real duty : 20.2496% (12656 /62500)
121 *                  on TBPRD = 6250  , CMPA = 1265.625 ( .625 rejection), real duty : 20.24%   (1265 6250)
122 *                  on TBPRD = 500   , CMPA = 101.25   ( .25 rejection) , real duty : 20.2%    (101/500)
123 *
124 *              Divisor = CLKDIV * HSPCLKDIV
125 *                      1 TBPRD : 10 ns (default)
126 *                      65535 TBPRD : 655350 ns
127 *                      65535 TBPRD : 655350 * Divisor ns  = X TBPRD : Cycle
128 *
129 *              accrooding to that , we must find a Divisor value , let X nearest 65535 .
130 *              so , Divisor must  Nearest Cycle/655350
131 */
132int beagle_pwm_configure(BBB_PWMSS pwm_id, float pwm_freq, float duty_a, float duty_b);
133
134/**
135 * @brief   This API enables the particular PWM module.
136 *
137 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
138 *
139 * @return  true if successful
140 * @return  false if fail
141 *
142 **/
143bool beagle_pwm_enable(BBB_PWMSS pwmid);
144
145/**
146 * @brief   This API disables the particular PWM module.
147 *
148 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
149 *
150 * @return  true if successful
151 * @return  false if fail
152 *
153 **/
154bool beagle_pwm_disable(BBB_PWMSS pwmid);
155
156/**
157 * @brief   This function enables pinmuxing for PWM module.
158 *
159 * @param   pin_no  It is individual pin at which freuqency need to be generated.
160 *                  It should be according to pwm sub system.
161 *
162 * @param   pwm_id  It is the instance number of EPWM of pwmsubsystem.
163 *
164 * @return  true if successful
165 * @return  false if fail
166 *
167 **/
168bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, BBB_PWMSS pwm_id);
169
170/**
171 * @brief   This function determines whether PWMSS-wide clocks enabled or not.
172 *
173 * @param   pwmss_id  It is the instance number of PWMSS which clocks need to be
174 *                    checked.
175 *
176 * @return  true if successful
177 * @return  false if fail
178 *
179 **/
180bool beagle_pwmss_is_running(unsigned int pwmss_id);
181
182
183#ifdef __cplusplus
184}
185#endif /* __cplusplus */
186
187#endif /* LIBBSP_ARM_BEAGLE_BBB_PWM_H */
Note: See TracBrowser for help on using the repository browser.