RocketLogger  1.1
pwm.h File Reference
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "log.h"
#include "types.h"
+ Include dependency graph for pwm.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PWMSS0_BASE   0x48300000
 PWMSS0 register base address. More...
 
#define PWMSS1_BASE   0x48302000
 PWMSS1 register base address. More...
 
#define EPWM_OFFSET   0x0200
 EPWM module register offset. More...
 
#define PWM_SIZE   0x00000FFF
 Size of PWM register memory. More...
 
#define TBCTL   (EPWM_OFFSET + 0x0) / sizeof(uint16_t)
 Counter control register offset. More...
 
#define TBPRD   (EPWM_OFFSET + 0xA) / sizeof(uint16_t)
 Period register offset. More...
 
#define CMPA   (EPWM_OFFSET + 0x12) / sizeof(uint16_t)
 Compare register A offset. More...
 
#define CMPB   (EPWM_OFFSET + 0x14) / sizeof(uint16_t)
 Compare register B offset. More...
 
#define AQCTLA   (EPWM_OFFSET + 0x16) / sizeof(uint16_t)
 Action qualifier register offset. More...
 
#define AQCTLB   (EPWM_OFFSET + 0x18) / sizeof(uint16_t)
 Action qualifier register B offset. More...
 
#define TBCTL_DEFAULT   0xC000
 Default counter value (see AM335x_TR) More...
 
#define UP_DOWN_COUNT   0x0002
 Up-down counting. More...
 
#define PRESCALE2   0x0400
 Counter prescale 2. More...
 
#define RWC_AQ_A   0x0060
 Action qualifier A value for latch reset (see AM335x_TR) More...
 
#define RWC_AQ_B   0x0900
 Action qualifier B value for latch reset (see AM335x_TR) More...
 
#define PULSE_WIDTH   0.1
 Latch reset pulse width (part of sampling period) More...
 
#define MARGIN   0.1
 Latch reset period margin. More...
 
#define PWM_PERIOD_SCALE
 Latch reset period scaling factor. More...
 
#define ADC_CLOCK_PERIOD   48
 ADC master clock period in ns. More...
 
#define ADC_AQ   0x0025
 Action qualifier value for ADC clock (see AM335x_TR) More...
 

Functions

int pwm_setup (void)
 
void pwm_close (void)
 
void pwm_setup_range_clock (int sample_rate)
 
void pwm_setup_adc_clock (void)
 

Macro Definition Documentation

#define ADC_AQ   0x0025

Action qualifier value for ADC clock (see AM335x_TR)

Definition at line 101 of file pwm.h.

Referenced by pwm_setup_adc_clock().

#define ADC_CLOCK_PERIOD   48

ADC master clock period in ns.

Definition at line 99 of file pwm.h.

Referenced by pwm_setup_adc_clock().

#define AQCTLA   (EPWM_OFFSET + 0x16) / sizeof(uint16_t)

Action qualifier register offset.

Definition at line 68 of file pwm.h.

Referenced by pwm_setup_adc_clock(), and pwm_setup_range_clock().

#define AQCTLB   (EPWM_OFFSET + 0x18) / sizeof(uint16_t)

Action qualifier register B offset.

Definition at line 70 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define CMPA   (EPWM_OFFSET + 0x12) / sizeof(uint16_t)

Compare register A offset.

Definition at line 64 of file pwm.h.

Referenced by pwm_setup_adc_clock(), and pwm_setup_range_clock().

#define CMPB   (EPWM_OFFSET + 0x14) / sizeof(uint16_t)

Compare register B offset.

Definition at line 66 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define EPWM_OFFSET   0x0200

EPWM module register offset.

Definition at line 52 of file pwm.h.

#define MARGIN   0.1

Latch reset period margin.

Definition at line 90 of file pwm.h.

#define PRESCALE2   0x0400

Counter prescale 2.

Definition at line 78 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define PULSE_WIDTH   0.1

Latch reset pulse width (part of sampling period)

Definition at line 88 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define PWM_PERIOD_SCALE
Value:
50000000 * \
#define MARGIN
Latch reset period margin.
Definition: pwm.h:90
#define PULSE_WIDTH
Latch reset pulse width (part of sampling period)
Definition: pwm.h:88

Latch reset period scaling factor.

Definition at line 92 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define PWM_SIZE   0x00000FFF

Size of PWM register memory.

Definition at line 56 of file pwm.h.

Referenced by pwm_close(), and pwm_setup().

#define PWMSS0_BASE   0x48300000

PWMSS0 register base address.

Copyright (c) 2016-2017, Swiss Federal Institute of Technology (ETH Zurich) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 48 of file pwm.h.

Referenced by pwm_setup().

#define PWMSS1_BASE   0x48302000

PWMSS1 register base address.

Definition at line 50 of file pwm.h.

Referenced by pwm_setup().

#define RWC_AQ_A   0x0060

Action qualifier A value for latch reset (see AM335x_TR)

Definition at line 82 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define RWC_AQ_B   0x0900

Action qualifier B value for latch reset (see AM335x_TR)

Definition at line 84 of file pwm.h.

Referenced by pwm_setup_range_clock().

#define TBCTL   (EPWM_OFFSET + 0x0) / sizeof(uint16_t)

Counter control register offset.

Definition at line 60 of file pwm.h.

Referenced by pwm_setup_adc_clock(), and pwm_setup_range_clock().

#define TBCTL_DEFAULT   0xC000

Default counter value (see AM335x_TR)

Definition at line 74 of file pwm.h.

Referenced by pwm_setup_adc_clock(), and pwm_setup_range_clock().

#define TBPRD   (EPWM_OFFSET + 0xA) / sizeof(uint16_t)

Period register offset.

Definition at line 62 of file pwm.h.

Referenced by pwm_setup_adc_clock(), and pwm_setup_range_clock().

#define UP_DOWN_COUNT   0x0002

Up-down counting.

Definition at line 76 of file pwm.h.

Referenced by pwm_setup_range_clock().

Function Documentation

void pwm_close ( void  )

Unmap PWM registers from user space

Definition at line 79 of file pwm.c.

References mem_fd, PWM_SIZE, pwmss0_regs, and pwmss1_regs.

Referenced by hw_close().

int pwm_setup ( void  )

Map PWM registers into user space (on pwmss0_regs and pwmss1_regs pointer)

Returns
SUCCESS in case of success, FAILURE otherwise

Definition at line 45 of file pwm.c.

References ERROR, FAILURE, mem_fd, PWM_SIZE, PWMSS0_BASE, pwmss0_regs, PWMSS1_BASE, pwmss1_regs, rl_log(), and SUCCESS.

Referenced by hw_init().

+ Here is the call graph for this function:

void pwm_setup_adc_clock ( void  )

Setup PWMSS0 for ADC master clock

Definition at line 114 of file pwm.c.

References ADC_AQ, ADC_CLOCK_PERIOD, AQCTLA, CMPA, pwmss0_regs, TBCTL, TBCTL_DEFAULT, and TBPRD.

Referenced by hw_init().

void pwm_setup_range_clock ( int  sample_rate)

Setup PWMSS1 for range latch reset clock

Parameters
sample_rateADC sampling rate in Sps

Definition at line 93 of file pwm.c.

References AQCTLA, AQCTLB, CMPA, CMPB, PRESCALE2, PULSE_WIDTH, PWM_PERIOD_SCALE, pwmss1_regs, RWC_AQ_A, RWC_AQ_B, TBCTL, TBCTL_DEFAULT, TBPRD, and UP_DOWN_COUNT.

Referenced by hw_init().