flinklib
flinklib: flink C library for Linux
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 
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 
72 
80 int flink_pwm_get_period(flink_subdev* subdev, uint32_t channel, uint32_t* period) {
81  uint32_t offset;
82 
83  dbg_print("Reading period value from pwm %d of subdevice %d\n", channel, subdev->id);
84 
86  dbg_print(" --> calculated offset is 0x%x!\n", offset);
87 
88  if(flink_read(subdev, offset, REGISTER_WITH, period) != REGISTER_WITH) {
89  libc_error();
90  return EXIT_ERROR;
91  }
92  return EXIT_SUCCESS;
93 }
94 
95 
96 
104 int flink_pwm_set_hightime(flink_subdev* subdev, uint32_t channel, uint32_t hightime) {
105  uint32_t offset;
106 
107  dbg_print("Setting PWM hight time for channel %d on subdevice %d\n", subdev->id, channel);
108 
110  dbg_print(" --> calculated offset is 0x%x!\n", offset);
111 
112  if(flink_write(subdev, offset, REGISTER_WITH, &hightime) != REGISTER_WITH) {
113  libc_error();
114  return EXIT_ERROR;
115  }
116  return EXIT_SUCCESS;
117 }
118 
126 int flink_pwm_get_hightime(flink_subdev* subdev, uint32_t channel, uint32_t* hightime) {
127  uint32_t offset;
128 
129  dbg_print("Reading hightime value from pwm %d of subdevice %d\n", channel, subdev->id);
130 
132  dbg_print(" --> calculated offset is 0x%x!\n", offset);
133 
134  if(flink_read(subdev, offset, REGISTER_WITH, hightime) != REGISTER_WITH) {
135  libc_error();
136  return EXIT_ERROR;
137  }
138  return EXIT_SUCCESS;
139 }
140 
141 
142 
143 
144 
145 
Data structures for flink devices and subdevices.
int flink_pwm_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Gets the PWM hightime.
Definition: pwm.c:126
uint32_t frequency
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
Definition: pwm.c:104
#define EXIT_ERROR
Definition: flinklib.h:129
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:50
#define HEADER_SIZE
Definition: flinklib.h:51
#define EXIT_SUCCESS
Definition: flinklib.h:128
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:52
void libc_error(void)
Definition: error.c:56
Debug utilities.
#define PWM_FIRSTPWM_OFFSET
Definition: flinklib.h:57
int flink_pwm_get_period(flink_subdev *subdev, uint32_t channel, uint32_t *period)
Gets the PWM period.
Definition: pwm.c:80
ssize_t flink_write(flink_subdev *subdev, uint32_t offset, uint8_t size, void *wdata)
Write to a flink subdevice.
Definition: lowlevel.c:110
#define dbg_print(fmt,...)
Definition: log.h:29