flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
flinklib.h File Reference
#include <stdint.h>
#include <sys/types.h>
Include dependency graph for flinklib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define REGISTER_WITH   4
 
#define HEADER_SIZE   16
 
#define SUBHEADER_SIZE   16
 
#define STATUS_OFFSET   0x0010
 
#define CONFIG_OFFSET   0x0014
 
#define INFO_DESC_SIZE   28
 
#define PWM_BASECLK_OFFSET   0x0000
 
#define PWM_FIRSTPWM_OFFSET   0x0004
 
#define ANALOG_INPUT_FIRST_VALUE_OFFSET   0x0004
 
#define ANALOG_OUTPUT_FIRST_VALUE_OFFSET   0x0004
 
#define WD_FIRST_COUNTER_OFFSET   0x0004
 
#define RESET_BIT   0
 
#define NONEXCL_ACCESS   0
 
#define EXCL_ACCESS   1
 
#define FLINK_OUTPUT   1
 
#define FLINK_INPUT   0
 
#define EXIT_SUCCESS   0
 
#define EXIT_ERROR   -1
 

Typedefs

typedef struct _flink_dev flink_dev
 
typedef struct _flink_subdev flink_subdev
 

Functions

flink_devflink_open (const char *file_name)
 Opens a flink device file. More...
 
int flink_close (flink_dev *dev)
 Close an open flink device. More...
 
int flink_ioctl (flink_dev *dev, int cmd, void *arg)
 IOCTL operation for a flink device. More...
 
ssize_t flink_read (flink_subdev *subdev, uint32_t offset, uint8_t size, void *rdata)
 Read from a flink subdevice. More...
 
ssize_t flink_write (flink_subdev *subdev, uint32_t offset, uint8_t size, void *wdata)
 Write to a flink subdevice. More...
 
int flink_read_bit (flink_subdev *subdev, uint32_t offset, uint8_t bit, void *rdata)
 Read a single bit from a flink subdevice. More...
 
int flink_write_bit (flink_subdev *subdev, uint32_t offset, uint8_t bit, void *wdata)
 Write a single bit to a flink subdevice. More...
 
int flink_get_nof_subdevices (flink_dev *dev)
 Returns the number of subdevices of a fink device. More...
 
flink_subdevflink_get_subdevice_by_id (flink_dev *dev, uint8_t subdev_id)
 Find subdevice of a device with a given id. More...
 
flink_subdevflink_get_subdevice_by_unique_id (flink_dev *dev, uint8_t unique_id)
 Find subdevice of a device with a given unique id. More...
 
uint8_t flink_subdevice_get_id (flink_subdev *subdev)
 Get the id of a subdevice. More...
 
uint16_t flink_subdevice_get_function (flink_subdev *subdev)
 Get the function of a subdevice. More...
 
uint8_t flink_subdevice_get_subfunction (flink_subdev *subdev)
 Get the subfunction of a subdevice. More...
 
uint8_t flink_subdevice_get_function_version (flink_subdev *subdev)
 Get the function version of a subdevice. More...
 
uint32_t flink_subdevice_get_baseaddr (flink_subdev *subdev)
 Get the base address of a subdevice. More...
 
uint32_t flink_subdevice_get_memsize (flink_subdev *subdev)
 Get the memory size of a subdevice. More...
 
uint32_t flink_subdevice_get_nofchannels (flink_subdev *subdev)
 Get the number of channels of a subdevice. More...
 
uint32_t flink_subdevice_get_unique_id (flink_subdev *subdev)
 Get the unique id of a subdevice. More...
 
int flink_subdevice_select (flink_subdev *subdev, uint8_t exclusive)
 Select a flink subdevice for further operations. More...
 
int flink_subdevice_reset (flink_subdev *subdev)
 Reset a flink subdevice. More...
 
const char * flink_subdevice_id2str (uint8_t subdev_id)
 
int flink_info_get_description (flink_subdev *subdev, char *value)
 Reads the description field of an info subdevice. More...
 
int flink_analog_in_get_resolution (flink_subdev *subdev, uint32_t *resolution)
 Reads the resolution of a analog input subdevice. More...
 
int flink_analog_in_get_value (flink_subdev *subdev, uint32_t channel, uint32_t *value)
 Reads an analog input channel. More...
 
int flink_analog_out_get_resolution (flink_subdev *subdev, uint32_t *resolution)
 Reads the resolution of a analog output subdevice. More...
 
int flink_analog_out_set_value (flink_subdev *subdev, uint32_t channel, uint32_t value)
 Writes an analog output channel. More...
 
int flink_dio_set_direction (flink_subdev *subdev, uint32_t channel, uint8_t output)
 Configures a channel as input or output. More...
 
int flink_dio_set_value (flink_subdev *subdev, uint32_t channel, uint8_t high)
 Sets a output channel to a value. More...
 
int flink_dio_get_value (flink_subdev *subdev, uint32_t channel, uint8_t *value)
 Reads an input channel. More...
 
int flink_counter_set_mode (flink_subdev *subdev, uint8_t mode)
 
int flink_counter_get_count (flink_subdev *subdev, uint32_t channel, uint32_t *data)
 
int flink_pwm_get_baseclock (flink_subdev *subdev, uint32_t *frequency)
 Reads the base clock of a PWM subdevice. More...
 
int flink_pwm_set_period (flink_subdev *subdev, uint32_t channel, uint32_t period)
 Sets the PWM period. More...
 
int flink_pwm_set_hightime (flink_subdev *subdev, uint32_t channel, uint32_t hightime)
 Sets the PWM hightime. More...
 
int flink_wd_get_baseclock (flink_subdev *subdev, uint32_t *base_clk)
 Reads the base clock of a watchdog subdevice. More...
 
int flink_wd_get_status (flink_subdev *subdev, uint8_t *status)
 Reads the status word of a watchdog subdevice. More...
 
int flink_wd_set_counter (flink_subdev *subdev, uint32_t value)
 Presets the watchdog counter. More...
 
int flink_wd_arm (flink_subdev *subdev)
 Starts the watchdog counter. More...
 

Macro Definition Documentation

#define ANALOG_INPUT_FIRST_VALUE_OFFSET   0x0004

Definition at line 56 of file flinklib.h.

#define ANALOG_OUTPUT_FIRST_VALUE_OFFSET   0x0004

Definition at line 57 of file flinklib.h.

#define CONFIG_OFFSET   0x0014

Definition at line 52 of file flinklib.h.

#define EXCL_ACCESS   1

Definition at line 62 of file flinklib.h.

#define EXIT_ERROR   -1

Definition at line 118 of file flinklib.h.

#define EXIT_SUCCESS   0

Definition at line 117 of file flinklib.h.

#define FLINK_INPUT   0

Definition at line 94 of file flinklib.h.

#define FLINK_OUTPUT   1

Definition at line 93 of file flinklib.h.

#define HEADER_SIZE   16

Definition at line 49 of file flinklib.h.

#define INFO_DESC_SIZE   28

Definition at line 53 of file flinklib.h.

#define NONEXCL_ACCESS   0

Definition at line 61 of file flinklib.h.

#define PWM_BASECLK_OFFSET   0x0000

Definition at line 54 of file flinklib.h.

#define PWM_FIRSTPWM_OFFSET   0x0004

Definition at line 55 of file flinklib.h.

#define REGISTER_WITH   4

Definition at line 48 of file flinklib.h.

#define RESET_BIT   0

Definition at line 59 of file flinklib.h.

#define STATUS_OFFSET   0x0010

Definition at line 51 of file flinklib.h.

#define SUBHEADER_SIZE   16

Definition at line 50 of file flinklib.h.

#define WD_FIRST_COUNTER_OFFSET   0x0004

Definition at line 58 of file flinklib.h.

Typedef Documentation

typedef struct _flink_dev flink_dev

Definition at line 27 of file flinklib.h.

typedef struct _flink_subdev flink_subdev

Definition at line 28 of file flinklib.h.

Function Documentation

int flink_analog_in_get_resolution ( flink_subdev subdev,
uint32_t *  resolution 
)

Reads the resolution of a analog input subdevice.

Parameters
subdevSubdevice.
resolutionContains the resolution in number of resolvable steps.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 37 of file ain.c.

int flink_analog_in_get_value ( flink_subdev subdev,
uint32_t  channel,
uint32_t *  value 
)

Reads an analog input channel.

Parameters
subdevSubdevice containing the channel.
channelChannel number.
valueContains the digitized value of the channel input.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 55 of file ain.c.

int flink_analog_out_get_resolution ( flink_subdev subdev,
uint32_t *  resolution 
)

Reads the resolution of a analog output subdevice.

Parameters
subdevSubdevice.
resolutionContains the resolution in number of resolvable steps.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 37 of file aout.c.

int flink_analog_out_set_value ( flink_subdev subdev,
uint32_t  channel,
uint32_t  value 
)

Writes an analog output channel.

Parameters
subdevSubdevice containing the channel.
channelChannel number.
valueContains the digitized value of the channel output.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 55 of file aout.c.

int flink_close ( flink_dev dev)

Close an open flink device.

Parameters
devdevice to close.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 145 of file base.c.

Here is the caller graph for this function:

int flink_counter_get_count ( flink_subdev subdev,
uint32_t  channel,
uint32_t *  data 
)

Definition at line 35 of file counter.c.

int flink_counter_set_mode ( flink_subdev subdev,
uint8_t  mode 
)

Definition at line 29 of file counter.c.

int flink_dio_get_value ( flink_subdev subdev,
uint32_t  channel,
uint8_t *  value 
)

Reads an input channel.

Parameters
subdevSubdevice containing the channel.
channelChannel number.
valueContains a value of nonzero if the input is set.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 92 of file dio.c.

int flink_dio_set_direction ( flink_subdev subdev,
uint32_t  channel,
uint8_t  output 
)

Configures a channel as input or output.

Parameters
subdevSubdevice containing the channel.
channelChannel number.
outputValue, a value of nonzero configures the channel as output.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 38 of file dio.c.

int flink_dio_set_value ( flink_subdev subdev,
uint32_t  channel,
uint8_t  value 
)

Sets a output channel to a value.

Parameters
subdevSubdevice containing the channel.
channelChannel number.
outputA value of nonzero sets the channel.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 64 of file dio.c.

int flink_get_nof_subdevices ( flink_dev dev)

Returns the number of subdevices of a fink device.

Parameters
devDevice to read
Returns
int: Number of flink devices or -1 in case of error.

Definition at line 169 of file base.c.

flink_subdev* flink_get_subdevice_by_id ( flink_dev dev,
uint8_t  subdev_id 
)

Find subdevice of a device with a given id.

Parameters
devDevice to search.
subdev_idId of subdevice.
Returns
flink_subdev*: Pointer to the subdevice or NULL in case of error.

Definition at line 225 of file base.c.

Here is the caller graph for this function:

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.

Parameters
devDevice to search.
unique_idUnique id of subdevice.
Returns
flink_subdev*: Pointer to the subdevice or NULL in case of error.

Definition at line 248 of file base.c.

int flink_info_get_description ( flink_subdev subdev,
char *  desc 
)

Reads the description field of an info subdevice.

Parameters
subdevSubdevice.
descString containing the description.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 37 of file info.c.

int flink_ioctl ( flink_dev dev,
int  cmd,
void *  arg 
)

IOCTL operation for a flink device.

Parameters
devFlink device handle.
cmdIOCTL command.
argIOCTL arguments.
Returns
int: IOCTL return value or -1 in case of failure.

Definition at line 44 of file lowlevel.c.

Here is the caller graph for this function:

flink_dev* flink_open ( const char *  file_name)

Opens a flink device file.

Parameters
file_nameDevice file (null terminated array).
Returns
flink_dev*: Pointer to the opened flink device or NULL in case of error.

Definition at line 112 of file base.c.

Here is the caller graph for this function:

int flink_pwm_get_baseclock ( flink_subdev subdev,
uint32_t *  frequency 
)

Reads the base clock of a PWM subdevice.

Parameters
subdevSubdevice.
frequencyContains the base clock in Hz.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 35 of file pwm.c.

int flink_pwm_set_hightime ( flink_subdev subdev,
uint32_t  channel,
uint32_t  hightime 
)

Sets the PWM hightime.

Parameters
subdevSubdevice.
channelChannel number.
hightimeHightime of the PWM signal in multiples of the base clock.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 79 of file pwm.c.

int flink_pwm_set_period ( flink_subdev subdev,
uint32_t  channel,
uint32_t  period 
)

Sets the PWM period.

Parameters
subdevSubdevice.
channelChannel number.
periodPeriod of the PWM signal in multiples of the base clock.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 57 of file pwm.c.

ssize_t flink_read ( flink_subdev subdev,
uint32_t  offset,
uint8_t  size,
void *  rdata 
)

Read from a flink subdevice.

Parameters
subdevSubdevice to read from.
offsetRead offset, relative to the subdevice base address.
sizeNof bytes to read.
rdataPointer to a buffer where the read bytes are written to.
Returns
ssize_t: Nof bytes read from the subdevcie or a negative error code.

Definition at line 71 of file lowlevel.c.

Here is the caller graph for this function:

int flink_read_bit ( flink_subdev subdev,
uint32_t  offset,
uint8_t  bit,
void *  rdata 
)

Read a single bit from a flink subdevice.

Parameters
subdevSubdevice to read from.
offsetRead offset, relative to the subdevice base address.
bitBit number to read in the byte given by offset.
rdataPointer to a buffer where the bit read should be written
Returns
int: 0 on succes, else -1.

Definition at line 151 of file lowlevel.c.

Here is the caller graph for this function:

uint32_t flink_subdevice_get_baseaddr ( flink_subdev subdev)

Get the base address of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint32_t: Returns the base address.

Definition at line 307 of file base.c.

uint16_t flink_subdevice_get_function ( flink_subdev subdev)

Get the function of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint16_t: Returns the function id.

Definition at line 280 of file base.c.

uint8_t flink_subdevice_get_function_version ( flink_subdev subdev)

Get the function version of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint8_t: Returns the function version.

Definition at line 298 of file base.c.

uint8_t flink_subdevice_get_id ( flink_subdev subdev)

Get the id of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint8_t: Id of the subdevice.

Definition at line 271 of file base.c.

uint32_t flink_subdevice_get_memsize ( flink_subdev subdev)

Get the memory size of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint32_t: Returns the memory size.

Definition at line 316 of file base.c.

uint32_t flink_subdevice_get_nofchannels ( flink_subdev subdev)

Get the number of channels of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint32_t: Returns the number of channels.

Definition at line 325 of file base.c.

uint8_t flink_subdevice_get_subfunction ( flink_subdev subdev)

Get the subfunction of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint8_t: Returns the subfunction id.

Definition at line 289 of file base.c.

uint32_t flink_subdevice_get_unique_id ( flink_subdev subdev)

Get the unique id of a subdevice.

Parameters
subdevThe subdevice.
Returns
uint32_t: Returns the unique id.

Definition at line 334 of file base.c.

const char* flink_subdevice_id2str ( uint8_t  subdev_id)
int flink_subdevice_reset ( flink_subdev subdev)

Reset a flink subdevice.

Parameters
subdevSubdevice to reset
Returns
int: 0 on success, else -1.

Definition at line 185 of file base.c.

int flink_subdevice_select ( flink_subdev subdev,
uint8_t  exclusive 
)

Select a flink subdevice for further operations.

Parameters
subdevSubdevice to select.
exclusiveBlock access to this subdevice for other processes.
Returns
int: 0 on success, else -1.

Definition at line 208 of file base.c.

int flink_wd_arm ( flink_subdev subdev)

Starts the watchdog counter.

Parameters
subdevSubdevice.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 100 of file wd.c.

int flink_wd_get_baseclock ( flink_subdev subdev,
uint32_t *  base_clk 
)

Reads the base clock of a watchdog subdevice.

Parameters
subdevSubdevice.
frequencyContains the base clock in Hz.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 35 of file wd.c.

int flink_wd_get_status ( flink_subdev subdev,
uint8_t *  status 
)

Reads the status word of a watchdog subdevice.

Parameters
subdevSubdevice.
statusContains the status word.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 57 of file wd.c.

int flink_wd_set_counter ( flink_subdev subdev,
uint32_t  counter 
)

Presets the watchdog counter.

Parameters
subdevSubdevice.
counterDesired counter value.
Returns
int: 0 on success, -1 in case of failure.

Definition at line 79 of file wd.c.

ssize_t flink_write ( flink_subdev subdev,
uint32_t  offset,
uint8_t  size,
void *  wdata 
)

Write to a flink subdevice.

Parameters
subdevSubdevice to write to.
offsetWrite offset, relative to the subdevice base address.
sizeNof bytes to write.
wdataData to write.
Returns
ssize_t: Nof bytes written or -1 in case of error.

Definition at line 111 of file lowlevel.c.

Here is the caller graph for this function:

int flink_write_bit ( flink_subdev subdev,
uint32_t  offset,
uint8_t  bit,
void *  wdata 
)

Write a single bit to a flink subdevice.

Parameters
subdevSubdevice to write to.
offsetWrite offset, relative to the subdevice base address.
bitBit number to write in the byte given by offset.
wdataBit to write, a value of nonzero sets the bit, 0 clears the bit
Returns
int

Definition at line 189 of file lowlevel.c.

Here is the caller graph for this function: