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

Interface to the clock manager peripheral. More...

#include <memoryManagement/addressing.h>
#include <memoryManagement/physMemoryManagement.h>
#include <CCRCodingUtils/include/errorManagement.h>
#include <peripherals/clockManager.h>
#include <CCRCodingUtils/include/utils.h>
#include <unistd.h>

Macros

#define CLOCK_MANAGER_BASE_ADDR_PHYS   (peripheralsBaseAddressPhys + 0x101000)
 Physical base address of the clock manager peripheral.
 
#define CLOCK_MANAGER_AREA_LEN   0x100
 Length in bytes of the memory area dedicated to the clock manager.
 
#define REG_CM_GP0CTL_OFF   (0x70)
 Offset to the general purpose clock 0 control register.
 
#define REG_CM_GP1CTL_OFF   (0x78)
 Offset to the general purpose clock 1 control register.
 
#define REG_CM_GP2CTL_OFF   (0x80)
 Offset to the general purpose clock 2 control register.
 
#define REG_CM_PCMCTL_OFF   (0x98)
 Offset to the PCM clock control register.
 
#define REG_CM_PWMCTL_OFF   (0xa0)
 Offset to the PWM clock control register.
 
#define REG_CM_GP0DIV_OFF   (0x74)
 Offset to the general purpose clock 0 divisor register.
 
#define REG_CM_GP1DIV_OFF   (0x7c)
 Offset to the general purpose clock 1 divisor register.
 
#define REG_CM_GP2DIV_OFF   (0x84)
 Offset to the general purpose clock 2 divisor register.
 
#define REG_CM_PCMDIV_OFF   (0x9c)
 Offset to the PCM clock divisor register.
 
#define REG_CM_PWMDIV_OFF   (0xa4)
 Offset to the PWM clock divisor register.
 
#define CM_PASSWORD   (0x5a<<24)
 clock manager password. You must OR this to every write you make to the clock manager registers
 
#define CM_CTL_MASH_MASK   (3<<9)
 Control register mask: mash filter level.
 
#define CM_CTL_FLIP_MASK   (1<<8)
 Control register mask: Invert the clock output.
 
#define CM_CTL_BUSY_MASK   (1<<7)
 Control register mask: Clock generator is running.
 
#define CM_CTL_KILL_MASK   (1<<6)
 Control register mask: Kill the clock.
 
#define CM_CTL_ENAB_MASK   (1<<4)
 Control register mask: Enable the clock generator.
 
#define CM_CTL_SRC_MASK   (0xf)
 Control register mask: Clock source.
 

Functions

int clkMan_init ()
 Initializes this peripheral interface, to use before any other function in this file. More...
 
int clkMan_isInit ()
 true if clkMan_init has been called with success
 
int clkMan_setClock_gp0 (int clockSrc, int divisorInt, int divisorFrac)
 sets the clock for the general purpouse clock 0 More...
 
int clkMan_setClock_gp1 (int clockSrc, int divisorInt, int divisorFrac)
 sets the clock for the general purpouse clock 1 More...
 
int clkMan_setClock_gp2 (int clockSrc, int divisorInt, int divisorFrac)
 sets the clock for the general purpouse clock 2 More...
 
int clkMan_setClock_pcm (int clockSrc, int divisorInt, int divisorFrac)
 sets the clock for the pcm peripheral More...
 
int clkMan_setClock_pwm (int clockSrc, int divisorInt, int divisorFrac)
 sets the clock for the pwm peripheral More...
 

Detailed Description

Interface to the clock manager peripheral.

If you haven't already, see clockManager.h You can find the documentation on the BCM2835 at page 105. The documentation about pwm and pcm clocks is missing in the official doc, there's a pdf by G.J Van Loo with the missing info at https://www.scribd.com/doc/127599939/BCM2835-Audio-clocks

Function Documentation

int clkMan_init ( )

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

Returns
negative in case of error
int clkMan_setClock_gp0 ( int  clockSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock for the general purpouse clock 0

Parameters
clockSrcThe desired clock source (use the CLK_SRC_* macros)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
Returns
negative in case of error
int clkMan_setClock_gp1 ( int  clockSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock for the general purpouse clock 1

Parameters
clockSrcThe desired clock source (use the CLK_SRC_* macros)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
Returns
negative in case of error
int clkMan_setClock_gp2 ( int  clockSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock for the general purpouse clock 2

Parameters
clockSrcThe desired clock source (use the CLK_SRC_* macros)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
Returns
negative in case of error
int clkMan_setClock_pcm ( int  clockSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock for the pcm peripheral

Parameters
clockSrcThe desired clock source (use the CLK_SRC_* macros)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
Returns
negative in case of error
int clkMan_setClock_pwm ( int  clockSrc,
int  divisorInt,
int  divisorFrac 
)

sets the clock for the pwm peripheral

Parameters
clockSrcThe desired clock source (use the CLK_SRC_* macros)
divisorIntInteger part of the divisor
divisorFracFractional part of the divisor
Returns
negative in case of error