Repository navigation
Expand file tree
/
Copy pathZmod.c
More file actions
138 lines (120 loc) · 4.85 KB
/
Copy pathZmod.c
File metadata and controls
138 lines (120 loc) · 4.85 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/************************************************************************/
/* */
/* Zmod.h - function implementations for Zmod identification functions */
/* */
/************************************************************************/
/* Author: Arthur Brown */
/* Copyright 2024, Digilent Inc. */
/************************************************************************/
/* Module Description: */
/* */
/* Implements functions used to identify which family a Zmod is a */
/* member of */
/* */
/************************************************************************/
/* Revision History: */
/* */
/* 02/21/2024 (ArtVVB): created */
/* */
/************************************************************************/
/* ------------------------------------------------------------ */
/* Include File Definitions */
/* ------------------------------------------------------------ */
#if defined(__linux__)
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <linux/i2c-dev.h>
#include <time.h>
#endif
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "stdtypes.h"
#include "syzygy.h"
#include "Zmod.h"
#include "ZmodADC.h"
#include "ZmodDAC.h"
#include "ZmodDigitizer.h"
/* ------------------------------------------------------------ */
/* Miscellaneous Declarations */
/* ------------------------------------------------------------ */
/* Define the start address of the Zmod PDID word
*/
#define addrZmodPdidStart 0x80fc
/* ------------------------------------------------------------ */
/* Local Type Definitions */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Global Variables */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Local Variables */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Forward Declarations */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Procedure Definitions */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/*** ZmodReadPdid
**
** Parameters:
** fdI2cDev - open file descriptor for underlying I2C device (linux only)
** addrI2cSlave - I2C bus address for the slave
** pPdid - pointer to return product ID information through
**
** Return Value:
** fTrue for success, fFalse otherwise
**
** Errors:
** none
**
** Description:
** This function reads the product ID information from Zmod DNA
*/
BOOL
FZmodReadPdid(int fdI2cDev, BYTE addrI2cSlave, DWORD *pPdid) {
WORD cbRead;
if ( ! SyzygyI2cRead(fdI2cDev, addrI2cSlave, addrZmodPdidStart, (BYTE*)pPdid, sizeof(DWORD), &cbRead) ) {
printf("Error: failed to read PDID from 0x%02X\n", addrI2cSlave);
printf("Error: received %d of %d bytes\n", cbRead, sizeof(ZMOD_DIGITIZER_CAL));
return fFalse;
}
return fTrue;
}
/* ------------------------------------------------------------ */
/*** FGetZmodFamily
**
** Parameters:
** Pdid - product ID, read with FZmodReadPdid
** pFamily - Pointer to return the Zmod family by argument
**
** Return Value:
** Bool, false if the variant is unsupported, true otherwise
**
** Errors:
** none
**
** Description:
** This function uses the product ID to identify a Zmod Family
*/
BOOL
FGetZmodFamily(DWORD Pdid, ZMOD_FAMILY *pFamily) {
if (FZmodIsADC(Pdid)) {
*pFamily = ZMOD_FAMILY_ADC;
return fTrue;
}
if (FZmodIsDAC(Pdid)) {
*pFamily = ZMOD_FAMILY_DAC;
return fTrue;
}
if (FZmodIsDigitizer(Pdid)) {
*pFamily = ZMOD_FAMILY_DIGITIZER;
return fTrue;
}
*pFamily = ZMOD_FAMILY_UNSUPPORTED;
return fTrue;
}