flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
counter.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, subdevice type "counter" *
12  * *
13  *******************************************************************/
14 
24 #include "flinklib.h"
25 #include "types.h"
26 #include "error.h"
27 #include "log.h"
28 
29 int flink_counter_set_mode(flink_subdev* subdev, uint8_t mode) {
30  // TODO
31  dbg_print("Not yet implemented!");
32  return EXIT_ERROR;
33 }
34 
35 int flink_counter_get_count(flink_subdev* subdev, uint32_t channel, uint32_t* data) {
36  uint32_t offset;
37 
38  dbg_print("Reading counter value from counter %d of subdevice %d\n", channel, subdev->id);
39 
40  offset = HEADER_SIZE + SUBHEADER_SIZE + REGISTER_WITH * channel;
41  dbg_print(" --> calculated offset is 0x%x!\n", offset);
42 
43  if(flink_read(subdev, offset, REGISTER_WITH, data) != REGISTER_WITH) {
44  libc_error();
45  return EXIT_ERROR;
46  }
47  return EXIT_SUCCESS;
48 }
int flink_counter_get_count(flink_subdev *subdev, uint32_t channel, uint32_t *data)
Definition: counter.c:35
Data structures for flink devices and subdevices.
#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
#define SUBHEADER_SIZE
Definition: flinklib.h:50
int flink_counter_set_mode(flink_subdev *subdev, uint8_t mode)
Definition: counter.c:29
void libc_error(void)
Definition: error.c:56
Debug utilities.
#define dbg_print(fmt,...)
Definition: log.h:29