no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
iio_dac_demo.c File Reference

Implementation of iio_dac_demo. More...

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "no_os_error.h"
#include "no_os_util.h"
#include "iio_dac_demo.h"
#include "iio.h"
Include dependency graph for iio_dac_demo.c:

Macros

#define DAC_DEMO_ATTR(_name, _priv)
 
#define IIO_DEMO_DAC_CHANNEL(_idx)
 

Functions

int get_dac_demo_attr (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
 get attributes for dac.
 
int32_t dac_submit_samples (struct iio_device_data *dev_data)
 function for writing samples to the device.
 
int32_t dac_demo_trigger_handler (struct iio_device_data *dev_data)
 Handles trigger: reads one data-set from iio buffer and writes it to the dac buffer.
 
int set_dac_demo_attr (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
 set attributes for dac.
 

Variables

struct scan_type dac_scan_type
 
struct iio_attribute dac_channel_attributes []
 
struct iio_attribute dac_global_attributes []
 
struct iio_device dac_demo_iio_descriptor
 

Detailed Description

Implementation of iio_dac_demo.

Author
Andrei Drimbarean (andre.nosp@m.i.dr.nosp@m.imbar.nosp@m.ean@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2021(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ DAC_DEMO_ATTR

#define DAC_DEMO_ATTR ( _name,
_priv )
Value:
{\
.name = _name,\
.priv = _priv,\
}
int get_dac_demo_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
get attributes for dac.
Definition iio_dac_demo.c:76
int set_dac_demo_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
set attributes for dac.
Definition iio_dac_demo.c:193

◆ IIO_DEMO_DAC_CHANNEL

#define IIO_DEMO_DAC_CHANNEL ( _idx)
Value:
{\
.name = "dac_out_ch" # _idx,\
.ch_type = IIO_VOLTAGE,\
.channel = _idx,\
.scan_index = _idx,\
.indexed = true,\
.scan_type = &dac_scan_type,\
.attributes = dac_channel_attributes,\
.ch_out = true,\
}
struct scan_type dac_scan_type
Definition iio_dac_demo.c:236
struct iio_attribute dac_channel_attributes[]
Definition iio_dac_demo.c:244
@ IIO_VOLTAGE
Definition iio_types.h:56

Function Documentation

◆ dac_demo_trigger_handler()

int32_t dac_demo_trigger_handler ( struct iio_device_data * dev_data)

Handles trigger: reads one data-set from iio buffer and writes it to the dac buffer.

Parameters
dev_data- The iio device data structure.
Returns
ret - Result of the handling procedure. Returns 0 in case of success and a negative code otherwise.

◆ dac_submit_samples()

int32_t dac_submit_samples ( struct iio_device_data * dev_data)

function for writing samples to the device.

Parameters
dev_data- The iio device data structure.
Returns
ret - Result of the writing procedure. Returns 0 in case of success and a negative code otherwise.

◆ get_dac_demo_attr()

int get_dac_demo_attr ( void * device,
char * buf,
uint32_t len,
const struct iio_ch_info * channel,
intptr_t attr_id )

get attributes for dac.

Parameters
device-Physical instance of a iio_demo_device.
buf- Where value is stored.
len- Maximum length of value to be stored in buf.
channel- Channel properties.
attr_id- Attribute ID
Returns
Length of chars written in buf, or negative value on failure.

◆ set_dac_demo_attr()

int set_dac_demo_attr ( void * device,
char * buf,
uint32_t len,
const struct iio_ch_info * channel,
intptr_t attr_id )

set attributes for dac.

Parameters
device- Physical instance of a iio_demo_device.
buf- Value to be written to attribute.
len- Length of the data in "buf".
channel- Channel properties.
attr_id- Attribute ID
Returns
: Number of bytes written to device, or negative value on failure.

Variable Documentation

◆ dac_channel_attributes

struct iio_attribute dac_channel_attributes[]
Initial value:
= {
DAC_DEMO_ATTR("dac_channel_attr", DAC_CHANNEL_ATTR),
}
@ DAC_CHANNEL_ATTR
Definition dac_demo.h:81
#define DAC_DEMO_ATTR(_name, _priv)
Definition iio_dac_demo.c:218
#define END_ATTRIBUTES_ARRAY
Definition iio_types.h:107

◆ dac_demo_iio_descriptor

struct iio_device dac_demo_iio_descriptor
Initial value:
= {
.num_ch = TOTAL_DAC_CHANNELS,
.channels = iio_dac_channels,
.attributes = dac_global_attributes,
.debug_attributes = NULL,
.buffer_attributes = NULL,
.pre_enable = (int32_t (*)())update_dac_channels,
.post_disable = close_dac_channels,
.trigger_handler = (int32_t (*)())dac_demo_trigger_handler,
.submit = (int32_t (*)())dac_submit_samples,
.debug_reg_read = (int32_t (*)()) dac_demo_reg_read,
.debug_reg_write = (int32_t (*)()) dac_demo_reg_write
}
int32_t close_dac_channels(void *dev)
close all channels
Definition dac_demo.c:105
int32_t dac_demo_reg_read(struct dac_demo_desc *desc, uint8_t reg_index, uint8_t *readval)
read function for the dac demo driver
Definition dac_demo.c:125
int32_t dac_demo_reg_write(struct dac_demo_desc *desc, uint8_t reg_index, uint8_t writeval)
write function for the dac demo driver
Definition dac_demo.c:143
int32_t update_dac_channels(void *dev, int32_t mask)
update number of active channels
Definition dac_demo.c:87
int32_t dac_submit_samples(struct iio_device_data *dev_data)
function for writing samples to the device.
Definition iio_dac_demo.c:104
#define TOTAL_DAC_CHANNELS
Definition dac_demo.h:43
int32_t dac_demo_trigger_handler(struct iio_device_data *dev_data)
Handles trigger: reads one data-set from iio buffer and writes it to the dac buffer.
Definition iio_dac_demo.c:147
struct iio_attribute dac_global_attributes[]
Definition iio_dac_demo.c:249
#define NULL
Definition wrapper.h:64

◆ dac_global_attributes

struct iio_attribute dac_global_attributes[]
Initial value:
= {
DAC_DEMO_ATTR("dac_global_attr", DAC_GLOBAL_ATTR),
}
@ DAC_GLOBAL_ATTR
Definition dac_demo.h:82

◆ dac_scan_type

struct scan_type dac_scan_type
Initial value:
= {
.sign = 's',
.realbits = 16,
.storagebits = 16,
.shift = 0,
.is_big_endian = false
}