flinklib
flinklib: flink C library for Linux
ppwa.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, subdevice function "ppwa" *
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 PPWA 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_ppwa_get_period(flink_subdev* subdev, uint32_t channel, uint32_t* period) {
58  uint32_t offset;
59 
60  dbg_print("Reading PPWA 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_read(subdev, offset, REGISTER_WITH, period) != REGISTER_WITH) {
66  libc_error();
67  return EXIT_ERROR;
68  }
69  return EXIT_SUCCESS;
70 }
71 
79 int flink_ppwa_get_hightime(flink_subdev* subdev, uint32_t channel, uint32_t* hightime) {
80  uint32_t offset;
81 
82  dbg_print("Reading PPWA hightime 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_read(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_ppwa_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PPWA subdevice.
Definition: ppwa.c:35
uint32_t frequency
#define PPWA_FIRSTPPWA_OFFSET
Definition: flinklib.h:59
#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
#define SUBHEADER_SIZE
Definition: flinklib.h:52
int flink_ppwa_get_period(flink_subdev *subdev, uint32_t channel, uint32_t *period)
Reads the PPWA period.
Definition: ppwa.c:57
int flink_ppwa_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Reads the PPWA hightime.
Definition: ppwa.c:79
void libc_error(void)
Definition: error.c:56
Debug utilities.
#define dbg_print(fmt,...)
Definition: log.h:29