flinklib
flinklib: flink C library for Linux
flinklib.h
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, public header file *
12  * *
13  *******************************************************************/
14 
15 #ifndef FLINKLIB_H_
16 #define FLINKLIB_H_
17 
18 #include <stdint.h>
19 #include <sys/types.h>
20 
21 #include "flink_funcid.h" // "flink_funcid.h" is created by: flinkinterface/func_id/create_flink_funcid.sh
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 // ############ Device handles ############
28 
29 typedef struct _flink_dev flink_dev;
30 typedef struct _flink_subdev flink_subdev;
31 
32 
33 // ############ Base operations ############
34 
35 flink_dev* flink_open(const char* file_name);
37 
38 
39 // ############ Low level operations ############
40 
41 int flink_ioctl(flink_dev* dev, int cmd, void* arg);
42 ssize_t flink_read(flink_subdev* subdev, uint32_t offset, uint8_t size, void* rdata);
43 ssize_t flink_write(flink_subdev* subdev, uint32_t offset, uint8_t size, void* wdata);
44 int flink_read_bit(flink_subdev* subdev, uint32_t offset, uint8_t bit, void* rdata);
45 int flink_write_bit(flink_subdev* subdev, uint32_t offset, uint8_t bit, void* wdata);
46 
47 
48 // ############ Subdevice operations ############
49 
50 #define REGISTER_WITH 4 // byte
51 #define HEADER_SIZE 16 // byte
52 #define SUBHEADER_SIZE 16 // byte
53 #define STATUS_OFFSET 0x0010 // byte
54 #define CONFIG_OFFSET 0x0014 // byte
55 #define INFO_DESC_SIZE 28 // byte
56 #define PWM_BASECLK_OFFSET 0x0000 // byte
57 #define PWM_FIRSTPWM_OFFSET 0x0004 // byte
58 #define PPWA_BASECLK_OFFSET 0x0000 // byte
59 #define PPWA_FIRSTPPWA_OFFSET 0x0004 // byte
60 #define ANALOG_INPUT_FIRST_VALUE_OFFSET 0x0004 // byte
61 #define ANALOG_OUTPUT_FIRST_VALUE_OFFSET 0x0004 // byte
62 #define WD_FIRST_COUNTER_OFFSET 0x0004 // byte
63 #define RESET_BIT 0
64 
65 #define NONEXCL_ACCESS 0
66 #define EXCL_ACCESS 1
67 
68 // General
72 
73 uint8_t flink_subdevice_get_id(flink_subdev* subdev);
81 int flink_subdevice_select(flink_subdev* subdev, uint8_t exclusive);
83 const char* flink_subdevice_id2str(uint8_t subdev_id);
84 
85 // Info
86 int flink_info_get_description(flink_subdev* subdev, char* value);
87 
88 // Analog input
89 int flink_analog_in_get_resolution(flink_subdev* subdev, uint32_t* resolution);
90 int flink_analog_in_get_value(flink_subdev* subdev, uint32_t channel, uint32_t* value);
91 
92 // Analog output
93 int flink_analog_out_get_resolution(flink_subdev* subdev, uint32_t* resolution);
94 int flink_analog_out_set_value(flink_subdev* subdev, uint32_t channel, uint32_t value);
95 
96 // Digital in-/output
97 #define FLINK_OUTPUT 1
98 #define FLINK_INPUT 0
99 int flink_dio_set_direction(flink_subdev* subdev, uint32_t channel, uint8_t output);
100 int flink_dio_set_value(flink_subdev* subdev, uint32_t channel, uint8_t high);
101 int flink_dio_get_value(flink_subdev* subdev, uint32_t channel, uint8_t* value);
102 
103 // Counter
104 int flink_counter_set_mode(flink_subdev* subdev, uint8_t mode);
105 int flink_counter_get_count(flink_subdev* subdev, uint32_t channel, uint32_t* data);
106 
107 // PWM
108 int flink_pwm_get_baseclock(flink_subdev* subdev, uint32_t* frequency);
109 int flink_pwm_set_period(flink_subdev* subdev, uint32_t channel, uint32_t period);
110 int flink_pwm_get_period(flink_subdev* subdev, uint32_t channel, uint32_t* period);
111 int flink_pwm_set_hightime(flink_subdev* subdev, uint32_t channel, uint32_t hightime);
112 int flink_pwm_get_hightime(flink_subdev* subdev, uint32_t channel, uint32_t* hightime);
113 
114 // PPWA
115 int flink_ppwa_get_baseclock(flink_subdev* subdev, uint32_t* frequency);
116 int flink_ppwa_get_period(flink_subdev* subdev, uint32_t channel, uint32_t* period);
117 int flink_ppwa_get_hightime(flink_subdev* subdev, uint32_t channel, uint32_t* hightime);
118 
119 // Watchdog
120 int flink_wd_get_baseclock(flink_subdev* subdev, uint32_t* base_clk);
121 int flink_wd_get_status(flink_subdev* subdev, uint8_t* status);
122 int flink_wd_set_counter(flink_subdev* subdev, uint32_t value);
123 int flink_wd_arm(flink_subdev* subdev);
124 
125 
126 // ############ Exit states ############
127 
128 #define EXIT_SUCCESS 0
129 #define EXIT_ERROR -1
130 
131 #ifdef __cplusplus
132 } // end extern "C"
133 #endif
134 
135 #endif // FLINKLIB_H_
int flink_ppwa_get_period(flink_subdev *subdev, uint32_t channel, uint32_t *period)
Reads the PPWA period.
Definition: ppwa.c:57
uint32_t frequency
uint8_t flink_subdevice_get_function_version(flink_subdev *subdev)
Get the function version of a subdevice.
Definition: base.c:297
flink_dev * flink_open(const char *file_name)
Opens a flink device file.
Definition: base.c:113
uint8_t flink_subdevice_get_id(flink_subdev *subdev)
Get the id of a subdevice.
Definition: base.c:270
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
Definition: pwm.c:104
int flink_dio_set_value(flink_subdev *subdev, uint32_t channel, uint8_t high)
Sets a output channel to a value.
Definition: dio.c:64
int flink_close(flink_dev *dev)
Close an open flink device.
Definition: base.c:146
int flink_get_nof_subdevices(flink_dev *dev)
Returns the number of subdevices of a fink device.
Definition: base.c:167
int flink_wd_set_counter(flink_subdev *subdev, uint32_t value)
Presets the watchdog counter.
Definition: wd.c:79
int flink_analog_in_get_value(flink_subdev *subdev, uint32_t channel, uint32_t *value)
Reads an analog input channel.
Definition: ain.c:55
int flink_pwm_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Gets the PWM hightime.
Definition: pwm.c:126
int flink_wd_arm(flink_subdev *subdev)
Starts the watchdog counter.
Definition: wd.c:100
int flink_analog_out_get_resolution(flink_subdev *subdev, uint32_t *resolution)
Reads the resolution of a analog output subdevice.
Definition: aout.c:37
uint32_t flink_subdevice_get_unique_id(flink_subdev *subdev)
Get the unique id of a subdevice.
Definition: base.c:333
ssize_t flink_read(flink_subdev *subdev, uint32_t offset, uint8_t size, void *rdata)
Read from a flink subdevice.
Definition: lowlevel.c:71
uint32_t flink_subdevice_get_baseaddr(flink_subdev *subdev)
Get the base address of a subdevice.
Definition: base.c:306
uint8_t flink_subdevice_get_subfunction(flink_subdev *subdev)
Get the subfunction of a subdevice.
Definition: base.c:288
int flink_ppwa_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PPWA subdevice.
Definition: ppwa.c:35
int flink_subdevice_reset(flink_subdev *subdev)
Reset a flink subdevice.
Definition: base.c:183
int flink_dio_get_value(flink_subdev *subdev, uint32_t channel, uint8_t *value)
Reads an input channel.
Definition: dio.c:93
int flink_write_bit(flink_subdev *subdev, uint32_t offset, uint8_t bit, void *wdata)
Write a single bit to a flink subdevice.
Definition: lowlevel.c:187
int flink_ioctl(flink_dev *dev, int cmd, void *arg)
IOCTL operation for a flink device.
Definition: lowlevel.c:44
flink_subdev * flink_get_subdevice_by_id(flink_dev *dev, uint8_t subdev_id)
Find subdevice of a device with a given id.
Definition: base.c:223
int flink_info_get_description(flink_subdev *subdev, char *value)
Reads the description field of an info subdevice.
Definition: info.c:37
const char * flink_subdevice_id2str(uint8_t subdev_id)
int flink_read_bit(flink_subdev *subdev, uint32_t offset, uint8_t bit, void *rdata)
Read a single bit from a flink subdevice.
Definition: lowlevel.c:149
int flink_counter_set_mode(flink_subdev *subdev, uint8_t mode)
Definition: counter.c:29
int flink_counter_get_count(flink_subdev *subdev, uint32_t channel, uint32_t *data)
Definition: counter.c:35
int flink_pwm_set_period(flink_subdev *subdev, uint32_t channel, uint32_t period)
Sets the PWM period.
Definition: pwm.c:57
flink_dev * dev
int flink_pwm_get_baseclock(flink_subdev *subdev, uint32_t *frequency)
Reads the base clock of a PWM subdevice.
Definition: pwm.c:35
uint32_t flink_subdevice_get_memsize(flink_subdev *subdev)
Get the memory size of a subdevice.
Definition: base.c:315
int flink_dio_set_direction(flink_subdev *subdev, uint32_t channel, uint8_t output)
Configures a channel as input or output.
Definition: dio.c:38
int flink_subdevice_select(flink_subdev *subdev, uint8_t exclusive)
Select a flink subdevice for further operations.
Definition: base.c:206
int flink_wd_get_status(flink_subdev *subdev, uint8_t *status)
Reads the status word of a watchdog subdevice.
Definition: wd.c:57
int flink_analog_in_get_resolution(flink_subdev *subdev, uint32_t *resolution)
Reads the resolution of a analog input subdevice.
Definition: ain.c:37
uint16_t flink_subdevice_get_function(flink_subdev *subdev)
Get the function of a subdevice.
Definition: base.c:279
int flink_ppwa_get_hightime(flink_subdev *subdev, uint32_t channel, uint32_t *hightime)
Reads the PPWA hightime.
Definition: ppwa.c:79
int flink_wd_get_baseclock(flink_subdev *subdev, uint32_t *base_clk)
Reads the base clock of a watchdog subdevice.
Definition: wd.c:35
uint32_t flink_subdevice_get_nofchannels(flink_subdev *subdev)
Get the number of channels of a subdevice.
Definition: base.c:324
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
int flink_analog_out_set_value(flink_subdev *subdev, uint32_t channel, uint32_t value)
Writes an analog output channel.
Definition: aout.c:55
flink_subdev * flink_get_subdevice_by_unique_id(flink_dev *dev, uint32_t unique_id)
Find subdevice of a device with a given unique id.
Definition: base.c:246