flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pwm.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, subdevice function "pwm" *
12  * *
13  *******************************************************************/
14 
24 #include "flinklib.h"
25 #include "types.h"
26 #include "error.h"
27 #include "log.h"
28 
35 int flink_pwm_get_baseclock(flink_subdev* subdev, uint32_t* frequency) {
36  uint32_t offset;
37 
38  dbg_print("Reading base clock from PWM subdevice %d\n", subdev->id);
39 
40  offset = HEADER_SIZE + SUBHEADER_SIZE;
41  dbg_print(" --> calculated offset is 0x%x!\n", offset);
42 
43  if(flink_read(subdev, offset, REGISTER_WITH, frequency) != REGISTER_WITH) {
44  libc_error();
45  return EXIT_ERROR;
46  }
47  return EXIT_SUCCESS;
48 }
49 
57 int flink_pwm_set_period(flink_subdev* subdev, uint32_t channel, uint32_t period) {
58  uint32_t offset;
59 
60  dbg_print("Setting PWM period for channel %d on subdevice %d\n", subdev->id, channel);
61 
63  dbg_print(" --> calculated offset is 0x%x!\n", offset);
64 
65  if(flink_write(subdev, offset, REGISTER_WITH, &period) != REGISTER_WITH) {
66  libc_error();
67  return EXIT_ERROR;
68  }
69  return EXIT_SUCCESS;
70 }
71 
79 int flink_pwm_set_hightime(flink_subdev* subdev, uint32_t channel, uint32_t hightime) {
80  uint32_t offset;
81 
82  dbg_print("Setting PWM hight time for channel %d on subdevice %d\n", subdev->id, channel);
83 
85  dbg_print(" --> calculated offset is 0x%x!\n", offset);
86 
87  if(flink_write(subdev, offset, REGISTER_WITH, &hightime) != REGISTER_WITH) {
88  libc_error();
89  return EXIT_ERROR;
90  }
91  return EXIT_SUCCESS;
92 }
Data structures for flink devices and subdevices.
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
Definition: pwm.c:79
#define EXIT_ERROR
Definition: flinklib.h:118
ssize_t flink_read(flink_subdev *subdev, uint32_t offset, uint8_t size, void *rdata)
Read from a flink subdevice.
Definition: lowlevel.c:71
Error handling.
#define REGISTER_WITH
Definition: flinklib.h:48
#define HEADER_SIZE
Definition: flinklib.h:49
#define EXIT_SUCCESS
Definition: flinklib.h:117
int flink_pwm_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PWM subdevice.
Definition: pwm.c:35
int flink_pwm_set_period(flink_subdev *subdev, uint32_t channel, uint32_t period)
Sets the PWM period.
Definition: pwm.c:57
#define SUBHEADER_SIZE
Definition: flinklib.h:50
void libc_error(void)
Definition: error.c:56
Debug utilities.
#define PWM_FIRSTPWM_OFFSET
Definition: flinklib.h:55
ssize_t flink_write(flink_subdev *subdev, uint32_t offset, uint8_t size, void *wdata)
Write to a flink subdevice.
Definition: lowlevel.c:111
#define dbg_print(fmt,...)
Definition: log.h:29