kb_pwm.c File Reference

This module provides useful basic facilities to use the KoreBot PWM and configure them. More...

Include dependency graph for kb_pwm.c:

Go to the source code of this file.

Defines

#define MAP_SIZE   4096UL
#define MAP_MASK   (MAP_SIZE - 1)
#define MEMDEV   "/dev/mem"
#define MAXPWM   2
#define PWM0   16
#define PWM1   17
#define reg_val(reg)   *((unsigned long *)reg)

Functions

static void bit_set_pwm0 (unsigned long addr, unsigned gpio)
static void bit_clear_pwm0 (unsigned long addr, unsigned gpio)
static int bit_test_pwm0 (unsigned long addr, unsigned gpio)
static void reg_set_pwm0 (unsigned long addr, unsigned long value)
static long int get_reg_pwm0 (unsigned long addr)
static void bit_set_pwm1 (unsigned long addr, unsigned gpio)
static void bit_clear_pwm1 (unsigned long addr, unsigned gpio)
static int bit_test_pwm1 (unsigned long addr, unsigned gpio)
static void reg_set_pwm1 (unsigned long addr, unsigned long value)
static long int get_reg_pwm1 (unsigned long addr)
static void bit_set_clk (unsigned long addr, unsigned gpio)
static void bit_clear_clk (unsigned long addr, unsigned gpio)
int kb_clk_init ()
int kb_pwm0_init ()
int kb_pwm1_init ()
int kb_pwm_init ()
int kb_pwm_cleanup ()
int kb_pwm_activate (unsigned pwm)
int kb_pwm_desactivate (unsigned pwm)
int kb_pwm_config (unsigned pwm, unsigned pwm_sd, unsigned prescale)
int kb_pwm_duty (unsigned pwm, unsigned FDcycle, unsigned Dcycle)
int kb_pwm_period (unsigned pwm, unsigned pwm_period)

Variables

static void * map_base_pwm0
static void * map_base_pwm1
static void * map_base_clk
static int fd_pwm0
static int fd_pwm1
static int fd_clk


Detailed Description

This module provides useful basic facilities to use the KoreBot PWM and configure them.

Support for KoreBot General Purpose IO.

Author:
Frederic Lambercy (K-Team SA)
Note:
Copyright (C) 2004 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file kb_pwm.c.


Define Documentation

#define MAP_MASK   (MAP_SIZE - 1)

Definition at line 32 of file kb_pwm.c.

#define MAP_SIZE   4096UL

Definition at line 31 of file kb_pwm.c.

#define MAXPWM   2

Definition at line 35 of file kb_pwm.c.

#define MEMDEV   "/dev/mem"

Definition at line 34 of file kb_pwm.c.

#define PWM0   16

Definition at line 37 of file kb_pwm.c.

Referenced by kb_pwm_activate().

#define PWM1   17

Definition at line 38 of file kb_pwm.c.

Referenced by kb_pwm_activate().

#define reg_val ( reg   )     *((unsigned long *)reg)

Definition at line 40 of file kb_pwm.c.


Function Documentation

static void bit_clear_clk ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 180 of file kb_pwm.c.

References map_base_clk, MAP_MASK, and reg_val.

Referenced by kb_pwm_desactivate().

static void bit_clear_pwm0 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 64 of file kb_pwm.c.

References map_base_pwm0, MAP_MASK, and reg_val.

static void bit_clear_pwm1 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 122 of file kb_pwm.c.

References map_base_pwm1, MAP_MASK, and reg_val.

static void bit_set_clk ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 168 of file kb_pwm.c.

References map_base_clk, MAP_MASK, and reg_val.

Referenced by kb_pwm_activate().

static void bit_set_pwm0 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 52 of file kb_pwm.c.

References map_base_pwm0, MAP_MASK, and reg_val.

static void bit_set_pwm1 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 110 of file kb_pwm.c.

References map_base_pwm1, MAP_MASK, and reg_val.

static int bit_test_pwm0 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 75 of file kb_pwm.c.

References map_base_pwm0, MAP_MASK, and reg_val.

static int bit_test_pwm1 ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 133 of file kb_pwm.c.

References map_base_pwm1, MAP_MASK, and reg_val.

static long int get_reg_pwm0 ( unsigned long  addr  )  [static]

Definition at line 98 of file kb_pwm.c.

References map_base_pwm0, MAP_MASK, and reg_val.

static long int get_reg_pwm1 ( unsigned long  addr  )  [static]

Definition at line 156 of file kb_pwm.c.

References map_base_pwm1, MAP_MASK, and reg_val.

int kb_clk_init (  ) 

Initialize the CLK module. This function must be called before any other call the pwm functions.

Returns:
  • 0 on success
  • a negative error code on failure

Definition at line 199 of file kb_pwm.c.

References CLK_BASE, fd_clk, KB_ERROR, KB_ERROR_FILEOPEN, KB_ERROR_MMAP, map_base_clk, MAP_MASK, MAP_SIZE, and MEMDEV.

Referenced by kb_pwm_init().

int kb_pwm0_init (  ) 

Initialize the PWM0 module. This function must be called before any other call the pwm functions.

Returns:
  • 0 on success
  • a negative error code on failure

Definition at line 230 of file kb_pwm.c.

References fd_pwm0, KB_ERROR, KB_ERROR_FILEOPEN, KB_ERROR_MMAP, map_base_pwm0, MAP_MASK, MAP_SIZE, MEMDEV, and PWM0_BASE.

Referenced by kb_pwm_init().

int kb_pwm1_init (  ) 

Initialize the PWM1 module. This function must be called before any other call the pwm functions.

Returns:
  • 0 on success
  • a negative error code on failure

Definition at line 258 of file kb_pwm.c.

References fd_pwm1, KB_ERROR, KB_ERROR_FILEOPEN, KB_ERROR_MMAP, map_base_pwm1, MAP_MASK, MAP_SIZE, MEMDEV, and PWM1_BASE.

Referenced by kb_pwm_init().

int kb_pwm_activate ( unsigned  pwm  ) 

Configure the given IO as an PWM. The GPIO will be configure as an output.

Parameters:
pwm A pwm number between 0 and 1

Definition at line 317 of file kb_pwm.c.

References bit_set_clk(), CKEN, KB_ERROR, KB_ERROR_INVALID, kb_gpio_dir(), kb_gpio_function(), MAXPWM, PWM0, and PWM1.

Referenced by main(), and pwm_on().

Here is the call graph for this function:

int kb_pwm_cleanup (  ) 

Cleanup the PWM module. Must be called to free the module ressources.

Definition at line 301 of file kb_pwm.c.

References fd_pwm0, fd_pwm1, KB_ERROR, KB_ERROR_MMAP, map_base_pwm0, map_base_pwm1, and MAP_SIZE.

int kb_pwm_config ( unsigned  pwm,
unsigned  pwm_sd,
unsigned  prescale 
)

Configure the control register of the given PWM.

Parameters:
pwm A pwm number between 0 and 1
pwm_sd Choose the shutdown method
prescale Determines the frequency of the PWM module clock (old PSCLK_PWMn = 3.6864 MHz / (PWM_CTRL[PRESCALE] + 1)) (PSCLK_PWMn = 13.0 MHz / (PWM_CTRL[PRESCALE] + 1))

Definition at line 390 of file kb_pwm.c.

References KB_ERROR, KB_ERROR_INVALID, MAXPWM, PWM_CTRL0, PWM_CTRL1, reg_set_pwm0(), and reg_set_pwm1().

Referenced by pwm_config().

Here is the call graph for this function:

int kb_pwm_desactivate ( unsigned  pwm  ) 

Desactivate the PWM.

Parameters:
pwm A pwm number between 0 and 1

Definition at line 363 of file kb_pwm.c.

References bit_clear_clk(), CKEN, KB_ERROR, KB_ERROR_INVALID, and MAXPWM.

Referenced by pwm_off().

Here is the call graph for this function:

int kb_pwm_duty ( unsigned  pwm,
unsigned  FDcycle,
unsigned  Dcycle 
)

Configure the duty cycle of the given PWM.

Parameters:
pwm A pwm number between 0 and 1
FDcycle Full Duty Cycle
Dcycle Duty Cycle of PWMn clock

Definition at line 429 of file kb_pwm.c.

References KB_ERROR, KB_ERROR_INVALID, MAXPWM, PWM_PWDUTY0, PWM_PWDUTY1, reg_set_pwm0(), and reg_set_pwm1().

Referenced by main(), and pwm_ratio().

Here is the call graph for this function:

int kb_pwm_init (  ) 

Initialize the two PWM module. This function must be called before any other call the pwm functions.

Returns:
  • 0 on success
  • a negative error code on failure

Definition at line 289 of file kb_pwm.c.

References kb_clk_init(), kb_gpio_init(), kb_pwm0_init(), and kb_pwm1_init().

Referenced by main().

Here is the call graph for this function:

int kb_pwm_period ( unsigned  pwm,
unsigned  pwm_period 
)

Configure the frequency of the given PWM.

Parameters:
pwm A pwm number between 0 and 1
pwm_period Period of given PWM

Definition at line 468 of file kb_pwm.c.

References KB_ERROR, KB_ERROR_INVALID, MAXPWM, PWM_PERVAL0, PWM_PERVAL1, reg_set_pwm0(), and reg_set_pwm1().

Referenced by main(), and pwm_freq().

Here is the call graph for this function:

static void reg_set_pwm0 ( unsigned long  addr,
unsigned long  value 
) [static]

Definition at line 89 of file kb_pwm.c.

References map_base_pwm0, MAP_MASK, and reg_val.

Referenced by kb_pwm_config(), kb_pwm_duty(), and kb_pwm_period().

static void reg_set_pwm1 ( unsigned long  addr,
unsigned long  value 
) [static]

Definition at line 147 of file kb_pwm.c.

References map_base_pwm1, MAP_MASK, and reg_val.

Referenced by kb_pwm_config(), kb_pwm_duty(), and kb_pwm_period().


Variable Documentation

int fd_clk [static]

Definition at line 48 of file kb_pwm.c.

Referenced by kb_clk_init().

int fd_pwm0 [static]

Definition at line 46 of file kb_pwm.c.

Referenced by kb_pwm0_init(), and kb_pwm_cleanup().

int fd_pwm1 [static]

Definition at line 47 of file kb_pwm.c.

Referenced by kb_pwm1_init(), and kb_pwm_cleanup().

void* map_base_clk [static]

Definition at line 45 of file kb_pwm.c.

Referenced by bit_clear_clk(), bit_set_clk(), and kb_clk_init().

void* map_base_pwm0 [static]

void* map_base_pwm1 [static]


Generated on Wed Dec 15 11:49:28 2010 for KoreBot Library by  doxygen 1.5.5