flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 // ############ Device handles ############
26 
27 typedef struct _flink_dev flink_dev;
28 typedef struct _flink_subdev flink_subdev;
29 
30 
31 // ############ Base operations ############
32 
33 flink_dev* flink_open(const char* file_name);
34 int flink_close(flink_dev* dev);
35 
36 
37 // ############ Low level operations ############
38 
39 int flink_ioctl(flink_dev* dev, int cmd, void* arg);
40 ssize_t flink_read(flink_subdev* subdev, uint32_t offset, uint8_t size, void* rdata);
41 ssize_t flink_write(flink_subdev* subdev, uint32_t offset, uint8_t size, void* wdata);
42 int flink_read_bit(flink_subdev* subdev, uint32_t offset, uint8_t bit, void* rdata);
43 int flink_write_bit(flink_subdev* subdev, uint32_t offset, uint8_t bit, void* wdata);
44 
45 
46 // ############ Subdevice operations ############
47 
48 #define REGISTER_WITH 4 // byte
49 #define HEADER_SIZE 16 // byte
50 #define SUBHEADER_SIZE 16 // byte
51 #define STATUS_OFFSET 0x0010 // byte
52 #define CONFIG_OFFSET 0x0014 // byte
53 #define INFO_DESC_SIZE 28 // byte
54 #define PWM_BASECLK_OFFSET 0x0000 // byte
55 #define PWM_FIRSTPWM_OFFSET 0x0004 // byte
56 #define ANALOG_INPUT_FIRST_VALUE_OFFSET 0x0004 // byte
57 #define ANALOG_OUTPUT_FIRST_VALUE_OFFSET 0x0004 // byte
58 #define WD_FIRST_COUNTER_OFFSET 0x0004 // byte
59 #define RESET_BIT 0
60 
61 #define NONEXCL_ACCESS 0
62 #define EXCL_ACCESS 1
63 
64 // General
66 flink_subdev* flink_get_subdevice_by_id(flink_dev* dev, uint8_t subdev_id);
68 
69 uint8_t flink_subdevice_get_id(flink_subdev* subdev);
77 int flink_subdevice_select(flink_subdev* subdev, uint8_t exclusive);
79 const char* flink_subdevice_id2str(uint8_t subdev_id);
80 
81 // Info
82 int flink_info_get_description(flink_subdev* subdev, char* value);
83 
84 // Analog input
85 int flink_analog_in_get_resolution(flink_subdev* subdev, uint32_t* resolution);
86 int flink_analog_in_get_value(flink_subdev* subdev, uint32_t channel, uint32_t* value);
87 
88 // Analog output
89 int flink_analog_out_get_resolution(flink_subdev* subdev, uint32_t* resolution);
90 int flink_analog_out_set_value(flink_subdev* subdev, uint32_t channel, uint32_t value);
91 
92 // Digital in-/output
93 #define FLINK_OUTPUT 1
94 #define FLINK_INPUT 0
95 int flink_dio_set_direction(flink_subdev* subdev, uint32_t channel, uint8_t output);
96 int flink_dio_set_value(flink_subdev* subdev, uint32_t channel, uint8_t high);
97 int flink_dio_get_value(flink_subdev* subdev, uint32_t channel, uint8_t* value);
98 
99 // Counter
100 int flink_counter_set_mode(flink_subdev* subdev, uint8_t mode);
101 int flink_counter_get_count(flink_subdev* subdev, uint32_t channel, uint32_t* data);
102 
103 // PWM
104 int flink_pwm_get_baseclock(flink_subdev* subdev, uint32_t* frequency);
105 int flink_pwm_set_period(flink_subdev* subdev, uint32_t channel, uint32_t period);
106 int flink_pwm_set_hightime(flink_subdev* subdev, uint32_t channel, uint32_t hightime);
107 
108 // Watchdog
109 int flink_wd_get_baseclock(flink_subdev* subdev, uint32_t* base_clk);
110 int flink_wd_get_status(flink_subdev* subdev, uint8_t* status);
111 int flink_wd_set_counter(flink_subdev* subdev, uint32_t value);
112 int flink_wd_arm(flink_subdev* subdev);
113 
114 
115 // ############ Exit states ############
116 
117 #define EXIT_SUCCESS 0
118 #define EXIT_ERROR -1
119 
120 #ifdef __cplusplus
121 } // end extern "C"
122 #endif
123 
124 #endif // FLINKLIB_H_
uint8_t flink_subdevice_get_function_version(flink_subdev *subdev)
Get the function version of a subdevice.
Definition: base.c:298
flink_dev * flink_open(const char *file_name)
Opens a flink device file.
Definition: base.c:112
uint8_t flink_subdevice_get_id(flink_subdev *subdev)
Get the id of a subdevice.
Definition: base.c:271
int flink_pwm_set_hightime(flink_subdev *subdev, uint32_t channel, uint32_t hightime)
Sets the PWM hightime.
Definition: pwm.c:79
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:145
int flink_get_nof_subdevices(flink_dev *dev)
Returns the number of subdevices of a fink device.
Definition: base.c:169
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_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:334
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:307
uint8_t flink_subdevice_get_subfunction(flink_subdev *subdev)
Get the subfunction of a subdevice.
Definition: base.c:289
int flink_subdevice_reset(flink_subdev *subdev)
Reset a flink subdevice.
Definition: base.c:185
int flink_dio_get_value(flink_subdev *subdev, uint32_t channel, uint8_t *value)
Reads an input channel.
Definition: dio.c:92
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:189
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_unique_id(flink_dev *dev, uint8_t unique_id)
Find subdevice of a device with a given unique id.
Definition: base.c:248
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:225
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:151
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
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:316
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:208
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:280
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:325
ssize_t flink_write(flink_subdev *subdev, uint32_t offset, uint8_t size, void *wdata)
Write to a flink subdevice.
Definition: lowlevel.c:111
int flink_analog_out_set_value(flink_subdev *subdev, uint32_t channel, uint32_t value)
Writes an analog output channel.
Definition: aout.c:55