-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredpitaya_converters_12_conf.c
80 lines (69 loc) · 2.32 KB
/
redpitaya_converters_12_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
/*
* Copyright (c) 2019 OscillatorIMP Digital
*/
#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 <redpitaya_converters_12_core/redpitaya_converters_12_config.h>
#include <redpitaya_converters_12_conf.h>
int redpitaya_converters_12_spi_conf(const char *filename,
const int8_t adc_dac_sel_val, unsigned char conf_addr_val, unsigned char config_val,
int8_t conf_en_val)
{
//const int32_t conf_val = (conf_addr_val<<8) | (config_val);
unsigned long conf_val = (conf_addr_val<<8) | (config_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;
}
/* configure spi address */
if (ioctl(fd, REDPITAYA_CONVERTERS_12_SET(REG_REDPITAYA_CONVERTERS_12_CONF), &conf_val) < 0)
goto fd_close;
/* configure select adc/dac */
if (ioctl(fd, REDPITAYA_CONVERTERS_12_SET(REG_REDPITAYA_CONVERTERS_12_ADC_DAC_SEL), &adc_dac_sel_val) < 0)
goto fd_close;
/* configure enable configuration */
if (ioctl(fd, REDPITAYA_CONVERTERS_12_SET(REG_REDPITAYA_CONVERTERS_12_CONF_EN), &conf_en_val) < 0)
goto fd_close;
retval = EXIT_SUCCESS;
fd_close:
close(fd);
return retval;
}
int redpitaya_converters_12_ext_ref_enable(const char *filename, int8_t pll_en_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;
}
/* enable external reference clock*/
ioctl(fd, REDPITAYA_CONVERTERS_12_SET(REG_REDPITAYA_CONVERTERS_12_PLL_EN), &pll_en_val);
retval = EXIT_SUCCESS;
close(fd);
return retval;
}
int redpitaya_converters_12_get_ref_status(const char *filename, int8_t *pll_ref_status)
{
int retval = EXIT_SUCCESS;
int fd = open(filename, O_RDWR);
if (fd < 0) {
printf("erreur d'ouverture de %s\n", filename);
return EXIT_FAILURE;
}
retval = EXIT_SUCCESS;
if (ioctl(fd, REDPITAYA_CONVERTERS_12_GET(REG_REDPITAYA_CONVERTERS_12_PLL_OK), pll_ref_status) < 0)
retval = EXIT_FAILURE;
close(fd);
return retval;
}