source: rtems/c/src/lib/libbsp/arm/beagle/include/bbb-pwm.h @ 55bde66

5
Last change on this file since 55bde66 was 55bde66, checked in by Punit Vara <punitvara@…>, on 07/17/16 at 13:40:30

beagle: pwm polishing

. added a README to pwm
. added select_pwmss() to select pwmss-generic registers, as opposed

to PWM-specific registers

. added pwmss_clock_en_status(), beagle_pwmss_is_running() and pwmss_tb_clock_check()
. other API improvements
. style improvements

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief BeagleBone Black PWM support definitions.
7 */
8
9/**
10 * Copyright (c) 2016 Punit Vara <punitvara@gmail.com>
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17/** Some constants are taken from
18 * https://github.com/VegetableAvenger/BBBIOlib/blob/master/BBBio_lib/BBBiolib_PWMSS.h
19 */
20
21#ifndef LIBBSP_ARM_BEAGLE_BBB_PWM_H
22#define LIBBSP_ARM_BEAGLE_BBB_PWM_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif /* __cplusplus */
27
28/**
29 * @brief  BeagleBone Black PWM Macros.
30 */
31#define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
32#define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
33
34/**
35 * @brief The set of possible PWM subsystem module
36 *
37 * Enumerated type to define various instance of pwm module.
38 */
39typedef enum{
40  BBB_PWMSS0 = 0,
41  BBB_PWMSS1,
42  BBB_PWMSS2,
43  BBB_PWMSS_COUNT
44}BBB_PWMSS;
45
46typedef enum{
47  BBB_P8_13_2B = 3,
48  BBB_P8_19_2A,
49  BBB_P8_45_2A,
50  BBB_P8_46_2B,
51  BBB_P8_34_1B,
52  BBB_P8_36_1A,
53  BBB_P9_14_1A,
54  BBB_P9_16_1B,
55  BBB_P9_21_0B,
56  BBB_P9_22_0A,
57  BBB_P9_29_0B,
58  BBB_P9_31_0A
59}bbb_pwm_pin_t;
60
61#define BBB_P8_13_MUX_PWM 4
62#define BBB_P8_19_MUX_PWM 4
63#define BBB_P8_45_MUX_PWM 3
64#define BBB_P8_46_MUX_PWM 3
65#define BBB_P8_34_MUX_PWM 2
66#define BBB_P8_36_MUX_PWM 2
67#define BBB_P9_14_MUX_PWM 6
68#define BBB_P9_16_MUX_PWM 6
69#define BBB_P9_21_MUX_PWM 3
70#define BBB_P9_22_MUX_PWM 3
71#define BBB_P9_29_MUX_PWM 1
72#define BBB_P9_31_MUX_PWM 1
73#define BBB_PWM_FREQ_THRESHOLD 0.5f
74
75/**
76 * @brief  BeagleBone Black PWM API.
77 */
78
79/**
80 * @brief This function intilizes clock for pwm sub system.
81 *
82 * @param PWMSS_ID It is the instance number of EPWM of pwm sub system.
83 *
84 * @return true if successful
85 * @return false if not successful
86 *
87 **/
88bool beagle_pwm_init(BBB_PWMSS pwmss_id);
89
90/* PWMSS setting
91 *      set pulse argument of epwm module
92 *
93 *      @param pwm_id    : EPWMSS number , 0~2
94 *      @param pwm_freq : frequency to be generated
95 *      @param dutyA    : Duty Cycle(in percentage) in PWM channel A
96 *      @param dutyB    : Duty Cycle(in percentage) in PWM channel B
97 *
98 *      @return         : 1 for success
99 *      @return         : 0 for failed
100 *
101 *      @example        :  beagle_pwm_configure(0 , 50.0f , 50.0f , 25.0f);      // Generate 50HZ pwm in PWM0 ,
102 *                                                                              // duty cycle is 50% for ePWM0A , 25% for ePWM0B
103 *
104 *      @Note :
105 *              find an number nearst 65535 for TBPRD , to improve duty precision,
106 *
107 *              Using big TBPRD can increase the range of CMPA and CMPB ,
108 *              and it means we can get better precision on duty cycle.
109 *
110 *              EX : 20.25% duty cycle
111 *                  on TBPRD = 62500 , CMPA = 12656.25 ( .25 rejection) , real duty : 20.2496% (12656 /62500)
112 *                  on TBPRD = 6250  , CMPA = 1265.625 ( .625 rejection), real duty : 20.24%   (1265 6250)
113 *                  on TBPRD = 500   , CMPA = 101.25   ( .25 rejection) , real duty : 20.2%    (101/500)
114 *
115 *              Divisor = CLKDIV * HSPCLKDIV
116 *                      1 TBPRD : 10 ns (default)
117 *                      65535 TBPRD : 655350 ns
118 *                      65535 TBPRD : 655350 * Divisor ns  = X TBPRD : Cycle
119 *
120 *              accrooding to that , we must find a Divisor value , let X nearest 65535 .
121 *              so , Divisor must  Nearest Cycle/655350
122 */
123int beagle_pwm_configure(BBB_PWMSS pwm_id, float pwm_freq, float duty_a, float duty_b);
124
125/**
126 * @brief   This API enables the particular PWM module.
127 *
128 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
129 *
130 * @return  true if successful
131 * @return  false if fail
132 *
133 **/
134bool beagle_pwm_enable(BBB_PWMSS pwmid);
135
136/**
137 * @brief   This API disables the particular PWM module.
138 *
139 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
140 *
141 * @return  true if successful
142 * @return  false if fail
143 *
144 **/
145bool beagle_pwm_disable(BBB_PWMSS pwmid);
146
147/**
148 * @brief   This function enables pinmuxing for PWM module.
149 *
150 * @param   pin_no  It is individual pin at which freuqency need to be generated.
151 *                  It should be according to pwm sub system.
152 *
153 * @param   pwm_id  It is the instance number of EPWM of pwmsubsystem.
154 *
155 * @return  true if successful
156 * @return  false if fail
157 *
158 **/
159bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, BBB_PWMSS pwm_id);
160
161/**
162 * @brief   This function determines whether PWMSS-wide clocks enabled or not.
163 *
164 * @param   pwmss_id  It is the instance number of PWMSS which clocks need to be
165 *                    checked.
166 *
167 * @return  true if successful
168 * @return  false if fail
169 *
170 **/
171bool beagle_pwmss_is_running(unsigned int pwmss_id);
172
173
174#ifdef __cplusplus
175}
176#endif /* __cplusplus */
177
178#endif /* LIBBSP_ARM_BEAGLE_BBB_PWM_H */
Note: See TracBrowser for help on using the repository browser.