PMSIS API
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Data Structures

struct  pi_pwm_conf
 PWM configuration structure. More...
 
struct  pi_pwm_ioctl_ch_config
 PWM ioctl channel config arg struct. More...
 
struct  pi_pwm_ioctl_evt
 PWM ioctl event output arg struct. More...
 

Macros

#define PI_PWM_CONFIG_INSEL_OFFSET
 
#define PI_PWM_CONFIG_EVT_OFFSET
 
#define PI_PWM_CONFIG_CLKSEL_OFFSET
 
#define PI_PWM_CONFIG_UPDOWNSEL_OFFSET
 
#define PI_PWM_CONFIG_PRESCALER_OFFSET
 
#define PI_PWM_EVENT_OUTPUT(pwm, channel)
 

Enumerations

enum  pi_pwm_cmd_e
 PWM timer commands. More...
 
enum  pi_pwm_timer_conf_e
 PWM timer config. More...
 
enum  pi_pwm_ch_config_e
 PWM channel configuration. More...
 
enum  pi_pwm_channel_e
 PWM channels. More...
 
enum  pi_pwm_evt_sel_e
 Event output selection. More...
 
enum  pi_pwm_output_evt_e
 Output event source selection. More...
 
enum  pi_pwm_ioctl_cmd_e
 PWM ioctl commands. More...
 

Functions

void pi_pwm_conf_init (struct pi_pwm_conf *conf)
 Initialize a PWM configuration structure. More...
 
int32_t pi_pwm_open (struct pi_device *device)
 Open a PWM device. More...
 
void pi_pwm_close (struct pi_device *device)
 Close a PWM device. More...
 
int32_t pi_pwm_ioctl (struct pi_device *device, pi_pwm_ioctl_cmd_e cmd, void *arg)
 PWM ioctl command. More...
 
uint32_t pi_pwm_counter_get (struct pi_device *device)
 Get PWM timer value. More...
 
static void pi_pwm_timer_start (struct pi_device *device)
 Start PWM timer. More...
 
static void pi_pwm_timer_stop (struct pi_device *device)
 Stop PWM timer. More...
 
int32_t pi_pwm_duty_cycle_set (struct pi_device *device, uint32_t frequency, uint8_t duty_cycle)
 Set PWM frequency and duty_cycle. More...
 

Description

Macro Definition Documentation

#define PI_PWM_CONFIG_CLKSEL_OFFSET

PWM timer clock source selection offset.

#define PI_PWM_CONFIG_EVT_OFFSET

PWM timer event trigger offset.

#define PI_PWM_CONFIG_INSEL_OFFSET

PWM timer input source selection offset.

#define PI_PWM_CONFIG_PRESCALER_OFFSET

PWM timer prescaler value offset.

#define PI_PWM_CONFIG_UPDOWNSEL_OFFSET

PWM timer counting method offset.

#define PI_PWM_EVENT_OUTPUT (   pwm,
  channel 
)

PWM output event source selection.

Enumeration Type Documentation

Action to perform when a PWM channel's threshold match.

Enumerator
PI_PWM_SET 

Set. Output is high.

PI_PWM_TOGGLE_CLEAR 

Toggle, next threshold action match is Clear. Output is toggled then next match low.

PI_PWM_SET_CLEAR 

Set, next threshold action match is Clear. Output is high then next match low.

PI_PWM_TOGGLE 

Toggle. Output is toggled at each match.

PI_PWM_CLEAR 

Clear. Output is low.

PI_PWM_TOGGLE_SET 

Toggle, next threshold action match is Set. Output is toggled then next match high.

PI_PWM_CLEAR_SET 

Clear, next threshold action match is Set. Output is low then next match high.

PWM device channel selection.

Enumerator
PI_PWM_CHANNEL0 

PWM module channel 0.

PI_PWM_CHANNEL1 

PWM module channel 1.

PI_PWM_CHANNEL2 

PWM module channel 2.

PI_PWM_CHANNEL3 

PWM module channel 3.

PWM module timer commands.

Enumerator
PI_PWM_CMD_START 

PWM module timer START command.

PI_PWM_CMD_STOP 

PWM module timer STOP command.

PI_PWM_CMD_UPDATE 

PWM module timer UPDATE command.

PI_PWM_CMD_RESET 

PWM module timer RESET command.

PI_PWM_CMD_ARM 

PWM module timer ARM command.

Output event selection(channel).

Enumerator
PI_PWM_EVENT_SEL0 

PWM output event 0.

PI_PWM_EVENT_SEL1 

PWM output event 1.

PI_PWM_EVENT_SEL2 

PWM output event 2.

PI_PWM_EVENT_SEL3 

PWM output event 3.

PWM ioctl commands to set timer threshold, change channel configuration,...

Enumerator
PI_PWM_TIMER_COMMAND 

Timer execution command.

PI_PWM_TIMER_CONFIG 

Timer config command.

PI_PWM_TIMER_THRESH 

Timer threshold setting command.

PI_PWM_CH_CONFIG 

PWM channel config command.

PI_PWM_EVENT_SET 

PWM output event set command.

PI_PWM_EVENT_CLEAR 

PWM output event clear command.

PI_PWM_RESET_FREQ 

Stop PWM timer and zero frequency. This is to be used when reconfiguring timer frequency that has been set with pi_pwm_duty_cycle_set().

PI_PWM_ATTACH_CB 

Attach user callback to an IRQ.

Ouput event source selection(actual event).

Enumerator
PI_PWM_EVT_PWM_0_CH_0 

Output event source : PWM_0 CH_0.

PI_PWM_EVT_PWM_0_CH_1 

Output event source : PWM_0 CH_1.

PI_PWM_EVT_PWM_0_CH_2 

Output event source : PWM_0 CH_2.

PI_PWM_EVT_PWM_0_CH_3 

Output event source : PWM_0 CH_3.

PI_PWM_EVT_PWM_1_CH_0 

Output event source : PWM_1 CH_0.

PI_PWM_EVT_PWM_1_CH_1 

Output event source : PWM_1 CH_1.

PI_PWM_EVT_PWM_1_CH_2 

Output event source : PWM_1 CH_2.

PI_PWM_EVT_PWM_1_CH_3 

Output event source : PWM_1 CH_3.

PI_PWM_EVT_PWM_2_CH_0 

Output event source : PWM_2 CH_0.

PI_PWM_EVT_PWM_2_CH_1 

Output event source : PWM_2 CH_1.

PI_PWM_EVT_PWM_2_CH_2 

Output event source : PWM_2 CH_2.

PI_PWM_EVT_PWM_2_CH_3 

Output event source : PWM_2 CH_3.

PI_PWM_EVT_PWM_3_CH_0 

Output event source : PWM_3 CH_0.

PI_PWM_EVT_PWM_3_CH_1 

Output event source : PWM_3 CH_1.

PI_PWM_EVT_PWM_3_CH_2 

Output event source : PWM_3 CH_2.

PI_PWM_EVT_PWM_3_CH_3 

Output event source : PWM_3 CH_3.

PWM timer configuration.

Enumerator
PI_PWM_EVT_EACH_CLK_CYCLE 

Trigger each clock cycle.

PI_PWM_EVT_SOURCE_0 

Trigger if input source = '0'.

PI_PWM_EVT_SOURCE_1 

Trigger if input source = '1'.

PI_PWM_EVT_RISE 

Trigger on input source rising edge.

PI_PWM_EVT_FALL 

Trigger on input source falling edge.

PI_PWM_EVT_EDGE 

Trigger on input source rising or falling edge.

PI_PWM_EVT_RISE_ARMED 

Trigger : on input source rising edge when armed.

PI_PWM_EVT_FALL_ARMED 

Trigger : on input source falling edge when armed.

PI_PWM_CLKSEL_FLL 

FLL : configurable frequency.

PI_PWM_CLKSEL_REFCLK_32K 

32kHz Ref Clock.

PI_PWM_UPDOWNSEL_ALT 

Mountain shape : Count up then down alternatively. /\/\/\

PI_PWM_UPDOWNSEL_RESET 

Saw shape : Count up then reset to 0. /|/|/|.

Function Documentation

void pi_pwm_close ( struct pi_device *  device)

This function closes a PWM device. It enables PWM device clock gating and disable events of the selected PWM device.

Parameters
deviceDevice structure.
void pi_pwm_conf_init ( struct pi_pwm_conf conf)

This function initializes a PWM configuration structure with default values.

Parameters
confPWM configuration structure.
uint32_t pi_pwm_counter_get ( struct pi_device *  device)

This function returns current timer value of a PWM device.

Parameters
deviceDevice structure.
Return values
ValuePWM timer counter.
int32_t pi_pwm_duty_cycle_set ( struct pi_device *  device,
uint32_t  frequency,
uint8_t  duty_cycle 
)

This function sets PWM frequency and duty cycle(also referred to pulse width measured in seconds).

Parameters
deviceDevice structure.
frequencyFrequency of PWM.
duty_cycleOutput high ratio.
Return values
0If operation is successful.
ERRNOOtherwise error code.
Note
Frequency is given in Hz, duty cycle in percentage * 100.
int32_t pi_pwm_ioctl ( struct pi_device *  device,
pi_pwm_ioctl_cmd_e  cmd,
void *  arg 
)

This function allows to send different commands to PWM device. The commands are listed above in pi_pwm_ioctl_cmd_e.

Please note that some functions need arguments such as :

  • PI_PWM_TIMER_COMMAND -> pi_pwm_cmd_e.
  • PI_PWM_TIMER_CONFIG -> struct pi_pwm_conf.
  • PI_PWM_TIMER_THRESH -> an uint32_t with :
    • high 16 bits = counter end
    • low 16 bits = counter start
  • PI_PWM_CH_CONFIG -> struct pi_pwm_ioctl_ch_config.
  • PI_PWM_EVENT_SET -> struct pi_pwm_ioctl_evt.
  • PI_PWM_EVENT_CLEAR -> struct pi_pwm_ioctl_evt.
  • PI_PWM_ATTACH_CB -> struct pi_task.
Parameters
deviceDevice structure.
cmdIoctl command.
argIoctl command args.
Return values
-1If wrong ioctl command.
ValueOtherwise return value depending on ioctl command.
int32_t pi_pwm_open ( struct pi_device *  device)

This function opens a PWM device. It disables PWM device clock gating, sets up the PWM with given value and enables events of the selected PWM device.

Parameters
deviceDevice structure.
Return values
0If operation is successful.
ERR_CODEOtherwise.
static void pi_pwm_timer_start ( struct pi_device *  device)
inlinestatic

This function starts a PWM timer.

Parameters
deviceDevice structure.
static void pi_pwm_timer_stop ( struct pi_device *  device)
inlinestatic

This function stops a PWM timer.

Parameters
deviceDevice structure.