-
Notifications
You must be signed in to change notification settings - Fork 2
/
axi_to_dac_conf.c
101 lines (87 loc) · 2.34 KB
/
axi_to_dac_conf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (c) 2019 OscillatorIMP Digital
* Gwenhael Goavec-Merou <[email protected]>
*/
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
/* memory management */
#include <sys/mman.h>
#include <axi_to_dac_core/axi_to_dac_config.h>
#include <axi_to_dac_conf.h>
int axi_to_dac_full_conf(const char *filename,
const int32_t chanA_val, const int32_t chanB_val,
enum enable_high_t enable_high, uint8_t sync_chan)
{
int retval = EXIT_FAILURE;
int fd = open(filename, O_RDWR);
if (fd < 0) {
printf("erreur d'ouverture de %s\n", filename);
return EXIT_FAILURE;
}
/* configure sync */
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_SYNC_CHAN), &sync_chan) < 0)
goto fd_close;
/* configure enable */
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_EN_HIGH), &enable_high) < 0)
goto fd_close;
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_DATA_A), &chanA_val) < 0)
goto fd_close;
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_DATA_B), &chanB_val) < 0)
goto fd_close;
retval = EXIT_SUCCESS;
fd_close:
close(fd);
return retval;
}
int axi_to_dac_set_chan(const char *filename, const enum output_chan_t chan, const int32_t val)
{
int retval = EXIT_FAILURE;
int fd = open(filename, O_RDWR);
if (fd < 0) {
printf("erreur d'ouverture de %s\n", filename);
return EXIT_FAILURE;
}
int reg = (chan == CHANA) ? AXI_TO_DAC_DATA_A : AXI_TO_DAC_DATA_B;
if (ioctl(fd, AXI_TO_DAC_SET(reg), &val) < 0)
goto fd_close;
retval = EXIT_SUCCESS;
fd_close:
close(fd);
return retval;
}
int axi_to_dac_conf_enable(const char *filename, const enum enable_high_t enable_high)
{
int retval = EXIT_FAILURE;
int fd = open(filename, O_RDWR);
if (fd < 0) {
printf("erreur d'ouverture de %s\n", filename);
return EXIT_FAILURE;
}
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_EN_HIGH), &enable_high) < 0)
goto fd_close;
retval = EXIT_SUCCESS;
fd_close:
close(fd);
return retval;
}
int axi_to_dac_conf_sync(const char *filename, const uint8_t sync_chan)
{
int retval = EXIT_FAILURE;
int fd = open(filename, O_RDWR);
if (fd < 0) {
printf("erreur d'ouverture de %s\n", filename);
return EXIT_FAILURE;
}
if (ioctl(fd, AXI_TO_DAC_SET(AXI_TO_DAC_SYNC_CHAN), &sync_chan) < 0)
goto fd_close;
retval = EXIT_SUCCESS;
fd_close:
close(fd);
return retval;
}