Ignore:
Timestamp:
Jul 4, 2016, 6:05:43 PM (6 years ago)
Author:
Punit Vara <punitvara@…>
Branches:
5, master
Children:
c3058473
Parents:
6dc5c03f
git-author:
Punit Vara <punitvara@…> (07/04/16 18:05:43)
git-committer:
Martin Galvan <martin.galvan@…> (07/04/16 18:09:06)
Message:

Beaglebone: Update PWM driver imported from BBBIO

This patch adapts the previously added Beaglebone PWM code from BBBIO to RTEMS.
This work was done in the context of the Google Summer of Code 2016, and further
patches will follow to improve the code quality and documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/beagle/include/bbb-pwm.h

    r6dc5c03f r5e3096db  
     1/**
     2 * @file
     3 *
     4 * @ingroup arm_beagle
     5 *
     6 * @brief BeagleBone Black BSP definitions.
     7 */
     8
     9/**
     10 * Copyright (c) 2016 Punit Vara <punitvara at 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
    121#ifndef LIBBSP_ARM_BEAGLE_BBB_PWM_H
    222#define LIBBSP_ARM_BEAGLE_BBB_PWM_H
     
    929 * @brief  BeagleBone Black PWM Macros.
    1030 */
    11 #define BBBIO_PWMSS_COUNT       3
    12 #define BBBIO_PWMSS0           0
    13 #define BBBIO_PWMSS1           1
    14 #define BBBIO_PWMSS2           2
     31#define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
     32#define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
    1533
    16 #define MUXMODE0               0
    17 #define MUXMODE1                1
    18 #define MUXMODE2               2
    19 #define MUXMODE3               3
    20 #define MUXMODE4               4
    21 #define MUXMODE5               5
    22 #define MUXMODE6               6
    23 #define MUXMODE7               7
     34#define BBB_PWMSS_COUNT       3
     35#define BBB_PWMSS0  0
     36#define BBB_PWMSS1  1 
     37#define BBB_PWMSS2  2
    2438
    25 #define EPWM_GROUP1    1
    26 #define EPWM_GROUP2    2
    27 #define EPWM_GROUP0    0
     39#define BBB_P8_13_2B  3
     40#define BBB_P8_19_2A  4
     41#define BBB_P8_45_2A  5
     42#define BBB_P8_46_2B  6
     43#define BBB_P8_34_1B  7
     44#define BBB_P8_36_1A  8
     45#define BBB_P9_14_1A  9
     46#define BBB_P9_16_1B  10
     47#define BBB_P9_21_0B  11
     48#define BBB_P9_22_0A  12
     49#define BBB_P9_29_0B  13
     50#define BBB_P9_31_0A  14
    2851
    29 int BBBIO_PWMSS_Setting(unsigned int PWMID , float HZ ,float dutyA ,float dutyB);
    30 int BBBIO_PWM_Init();
    31 void BBBIO_PWM_Release();
    32 int BBBIO_PWMSS_Status(unsigned int PWMID);
    33 void BBBIO_ehrPWM_Enable(unsigned int PWMSS_ID);
    34 void BBBIO_ehrPWM_Disable(unsigned int PWMSS_ID);
     52#define BBB_MUX0      0
     53#define BBB_MUX1      1
     54#define BBB_MUX2      2
     55#define BBB_MUX3      3
     56#define BBB_MUX4      4
     57#define BBB_MUX5      5
     58#define BBB_MUX6      6
     59#define BBB_MUX7      7
    3560
     61#define BBB_EPWM1     1
     62#define BBB_EPWM2     2
     63#define BBB_EPWM0     0
     64
     65/**
     66 * @brief  BeagleBone Black PWM API.
     67 */
     68
     69/**
     70 * @brief This function intilize clock and pinmuxing for pwm sub system.
     71 *
     72 * @param PWMSS_ID It is the instance number of EPWM of pwm sub system.
     73 *
     74 * @return true if successful
     75 * @return false if not successful
     76 *
     77 **/
     78bool beagle_pwm_init(uint32_t pwmss_id);
     79
     80/* PWMSS setting
     81 *      set pulse argument of epwm module
     82 *
     83 *      @param pwm_id    : EPWMSS number , 0~2
     84 *      @param pwm_freq : frequency to be generated
     85 *      @param dutyA    : Duty Cycle in ePWM A
     86 *      @param dutyB    : Duty Cycle in ePWM B
     87 *
     88 *      @return         : 1 for success
     89 *      @return         : 0 for failed
     90 *
     91 *      @example        :  PWMSS_Setting(0 , 50.0f , 50.0f , 25.0f);      // Generate 50HZ pwm in PWM0 ,
     92 *                                                                              // duty cycle is 50% for ePWM0A , 25% for ePWM0B
     93 *
     94 *      @Note :
     95 *              find an number nearst 65535 for TBPRD , to improve duty precision,
     96 *
     97 *              Using big TBPRD can increase the range of CMPA and CMPB ,
     98 *              and it means we can get better precision on duty cycle.
     99 *
     100 *              EX : 20.25% duty cycle
     101 *                  on TBPRD = 62500 , CMPA = 12656.25 ( .25 rejection) , real duty : 20.2496% (12656 /62500)
     102 *                  on TBPRD = 6250  , CMPA = 1265.625 ( .625 rejection), real duty : 20.24%   (1265 6250)
     103 *                  on TBPRD = 500   , CMPA = 101.25   ( .25 rejection) , real duty : 20.2%    (101/500)
     104 *
     105 *              Divisor = CLKDIV * HSPCLKDIV
     106 *                      1 TBPRD : 10 ns (default)
     107 *                      65535 TBPRD : 655350 ns
     108 *                      65535 TBPRD : 655350 * Divisor ns  = X TBPRD : Cyclens
     109 *
     110 *              accrooding to that , we must find a Divisor value , let X nearest 65535 .
     111 *              so , Divisor must  Nearest Cyclens/655350
     112 */
     113int beagle_pwmss_setting(uint32_t pwm_id, float pwm_freq, float dutyA, float dutyB);
     114
     115/**
     116 * @brief   This API enables the particular PWM module.
     117 *
     118 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
     119 *
     120 * @return  true if successful
     121 * @return  false if fail
     122 *
     123 **/
     124bool beagle_ehrpwm_enable(uint32_t pwmid);
     125
     126/**
     127 * @brief   This API disables the HR sub-module.
     128 *
     129 * @param   pwmid  It is the instance number of EPWM of pwm sub system.
     130 *
     131 * @return  true if successful
     132 * @return  false if fail
     133 *
     134 **/
     135bool beagle_ehrpwm_disable(uint32_t pwmid);
     136
     137/**
     138 * @brief   This function Enables pinmuxing for PWM module.
     139 *
     140 * @param   pin_no  It is individual pin at which freuqency need to be generated.
     141 *                  It should be according to pwm sub system.
     142 *
     143 * @param   pwm_id  It is the instance number of EPWM of pwmsubsystem.
     144 *
     145 * @return  true if successful
     146 * @return  false if fail
     147 *
     148 **/
     149bool beagle_epwm_pinmux_setup(uint32_t pin_no, uint32_t pwm_id);
    36150
    37151#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.