CRpi
A library for rpi with intefaces to: gpio, pwm, dma
Functions
pwm.cpp File Reference

Interface to the PWM peripheral. More...

#include <peripherals/clockManager.h>
#include <memoryManagement/physMemoryManagement.h>
#include <peripherals/pwm.h>
#include <memoryManagement/addressing.h>
#include <CCRCodingUtils/include/errorManagement.h>
#include <stdlib.h>
#include <unistd.h>
#include "pwm_internal.h"

Functions

int pwm_init ()
 Initializes this peripheral interface, to use before any other function in this file. More...
 
int pwm_isInit ()
 true if pwm_init has been called with success
 
int pwm_setClock (int clkSrc, int divisorInt, int divisorFrac)
 sets the clock divisor for the pwm (the base frequency is 19.2 MHz) More...
 
int pwm_resetChannel (int channel)
 Resets the specified channel to: disabled, pwm mode, don't repeat last, silence=0, normal polarity, don't use fifo, don't use M/S Warning: the pwm peripheral likes to ignore the CTL_RPTL1_MASK and repeat the last word even if you say it not to. More...
 
int pwm_setRepeatLastWord (int channel, unsigned int value)
 Sets the repetition of the last word in the fifo on serializer mode Warning: the pwm peripheral likes to ignore this setting and repeat the last word even if you say it not to. More...
 
int pwm_clearFifo ()
 clears the fifo More...
 
int pwm_setEnable (int channel, unsigned int value)
 Sets the enabled status of the specified channel. After the dma completes a transfer (a chain of control blocks) and 0 gets loaded as control block this is resetted to 0. More...
 
int pwm_setMode (int channel, unsigned int mode)
 Sets the mode of the specified channel to PWM or Serializer. More...
 
int pwm_setSerializerMode (int channel, unsigned int mode)
 Set the serialized mode to use the fifo or the data register. More...
 
int pwm_setMSenable (int channel, unsigned int mode)
 Sets the pwm mode: M/S or the algorithm (see datasheet pag 139) More...
 
int pwm_setRange (int channel, uint32_t range)
 Sets the range of the specified channel counter. More...
 
int pwm_setData (int channel, uint32_t data)
 Sets the data for the specified channel: in Serializer mode (if not using fifo) it will be sent as pulses, in PWM mode it's the number of pulses in a period. More...
 
int pwm_writeToFifo (unsigned int data)
 Write the provided data word to the fifo. More...
 
int pwm_setDreqThreshold (unsigned int threshold)
 Sets the threshold under which the dreq signal is raised. More...
 
int pwm_setDmaEnable (unsigned int value)
 Enables or disables the generation of the dma signals DREQ and PANIC. More...
 

Detailed Description

Interface to the PWM peripheral.

If you haven't already, see pwm.h See documentation at "BCM2835 ARM peripherals" pag 138d

Function Documentation

int pwm_clearFifo ( )

clears the fifo

Returns
negative in case of error
int pwm_init ( )

Initializes this peripheral interface, to use before any other function in this file.

Returns
negative in case of error
int pwm_resetChannel ( int  channel)

Resets the specified channel to: disabled, pwm mode, don't repeat last, silence=0, normal polarity, don't use fifo, don't use M/S Warning: the pwm peripheral likes to ignore the CTL_RPTL1_MASK and repeat the last word even if you say it not to.

Parameters
channelThe channel
Returns
negative in case of error
int pwm_setClock ( int  clkSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock divisor for the pwm (the base frequency is 19.2 MHz)

Parameters
clkSrcClock source, see the macros in clockManager. Normally you want CLK_SRC_OSCILLATOR (19.2MHz)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
int pwm_setData ( int  channel,
uint32_t  data 
)

Sets the data for the specified channel: in Serializer mode (if not using fifo) it will be sent as pulses, in PWM mode it's the number of pulses in a period.

Parameters
channelThe channel: 1 or 2
dataThe data value
Returns
negative in case of error
int pwm_setDmaEnable ( unsigned int  value)

Enables or disables the generation of the dma signals DREQ and PANIC.

Parameters
value0=disabled, any other value=enabled
int pwm_setDreqThreshold ( unsigned int  threshold)

Sets the threshold under which the dreq signal is raised.

Parameters
thresholdThe threshold
Returns
negative in case of error
int pwm_setEnable ( int  channel,
unsigned int  value 
)

Sets the enabled status of the specified channel. After the dma completes a transfer (a chain of control blocks) and 0 gets loaded as control block this is resetted to 0.

Parameters
channelThe channel: 1 or 2
valueIt's a boolean: 0=disabled, 1=enabled
Returns
negative in case of error
int pwm_setMode ( int  channel,
unsigned int  mode 
)

Sets the mode of the specified channel to PWM or Serializer.

Parameters
channelThe channel: 1 or 2
modeThe mode: 0=PWM, 1=Serializer
Returns
negative in case of error
int pwm_setMSenable ( int  channel,
unsigned int  mode 
)

Sets the pwm mode: M/S or the algorithm (see datasheet pag 139)

Parameters
channelThe channel: 1 or 2
modeThe mode: 0=algorithm, 1=M/S
Returns
negative in case of error
int pwm_setRange ( int  channel,
uint32_t  range 
)

Sets the range of the specified channel counter.

Parameters
channelThe channel: 1 or 2
rangeRange, it's the number of possible pulses in a period.
Returns
negative in case of error
int pwm_setRepeatLastWord ( int  channel,
unsigned int  value 
)

Sets the repetition of the last word in the fifo on serializer mode Warning: the pwm peripheral likes to ignore this setting and repeat the last word even if you say it not to.

Parameters
channelThe channel to configure
value0=don't repeat, 1=repeat
Returns
negative in case of error
int pwm_setSerializerMode ( int  channel,
unsigned int  mode 
)

Set the serialized mode to use the fifo or the data register.

Parameters
channelThe channel: 1 or 2
modeThe mode: 0=use data register, 1=use fifo
Returns
negative in case of error
int pwm_writeToFifo ( unsigned int  data)

Write the provided data word to the fifo.

Parameters
dataThe data
Returns
negative in case of error