no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ade7880.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __ADE7880_H__
34#define __ADE7880_H__
35
36#include <stdbool.h>
37#include <stdint.h>
38#include <string.h>
39#include "no_os_util.h"
40#include "no_os_spi.h"
41#include "no_os_gpio.h"
42#include "no_os_print_log.h"
43
44/* SPI commands */
45#define ADE7880_SPI_READ_CMD 0x01
46#define ADE7880_SPI_WRITE_CMD 0x00
47
48#define ENABLE 0x0001
49#define DISABLE 0x0000
50
51/* ADE7880 Register Map */
52#define ADE7880_REG_AIGAIN 0x4380
53#define ADE7880_REG_AVGAIN 0x4381
54#define ADE7880_REG_BIGAIN 0x4382
55#define ADE7880_REG_BVGAIN 0x4383
56#define ADE7880_REG_CIGAIN 0x4384
57#define ADE7880_REG_CVGAIN 0x4385
58#define ADE7880_REG_NIGAIN 0x4386
59#define ADE7880_REG_DICOEFF 0x4388
60#define ADE7880_REG_APGAIN 0x4389
61#define ADE7880_REG_AWATTOS 0x438A
62#define ADE7880_REG_BPGAIN 0x438B
63#define ADE7880_REG_BWATTOS 0x438C
64#define ADE7880_REG_CPGAIN 0x438D
65#define ADE7880_REG_CWATTOS 0x438E
66#define ADE7880_REG_AIRMSOS 0x438F
67#define ADE7880_REG_AVRMSOS 0x4390
68#define ADE7880_REG_BIRMSOS 0x4391
69#define ADE7880_REG_BVRMSOS 0x4392
70#define ADE7880_REG_CIRMSOS 0x4393
71#define ADE7880_REG_CVRMSOS 0x4394
72#define ADE7880_REG_NIRMSOS 0x4395
73#define ADE7880_REG_HPGAIN 0x4398
74#define ADE7880_REG_ISUMLVL 0x4399
75#define ADE7880_REG_VLEVEL 0x439F
76#define ADE7880_REG_AFWATTOS 0x43A2
77#define ADE7880_REG_BFWATTOS 0x43A3
78#define ADE7880_REG_CFWATTOS 0x43A4
79#define ADE7880_REG_AFVAROS 0x43A5
80#define ADE7880_REG_BFVAROS 0x43A6
81#define ADE7880_REG_CFVAROS 0x43A7
82#define ADE7880_REG_AFIRMSOS 0x43A8
83#define ADE7880_REG_BFIRMSOS 0x43A9
84#define ADE7880_REG_CFIRMSOS 0x43AA
85#define ADE7880_REG_AFVRMSOS 0x43AB
86#define ADE7880_REG_BFVRMSOS 0x43AC
87#define ADE7880_REG_CFVRMSOS 0x43AD
88#define ADE7880_REG_HXWATTOS 0x43AE
89#define ADE7880_REG_HYWATTOS 0x43AF
90#define ADE7880_REG_HZWATTOS 0x43B0
91#define ADE7880_REG_HXVAROS 0x43B1
92#define ADE7880_REG_HYVAROS 0x43B2
93#define ADE7880_REG_HZVAROS 0x43B3
94#define ADE7880_REG_HXIRMSOS 0x43B4
95#define ADE7880_REG_HYIRMSOS 0x43B5
96#define ADE7880_REG_HZIRMSOS 0x43B6
97#define ADE7880_REG_HXVRMSOS 0x43B7
98#define ADE7880_REG_HYVRMSOS 0x43B8
99#define ADE7880_REG_HZVRMSOS 0x43B9
100#define ADE7880_REG_AIRMS 0x43C0
101#define ADE7880_REG_AVRMS 0x43C1
102#define ADE7880_REG_BIRMS 0x43C2
103#define ADE7880_REG_BVRMS 0x43C3
104#define ADE7880_REG_CIRMS 0x43C4
105#define ADE7880_REG_CVRMS 0x43C5
106#define ADE7880_REG_NIRMS 0x43C6
107#define ADE7880_REG_ISUM 0x43C7
108
109/* Internal DSP memory RAM registers*/
110#define ADE7880_REG_RUN 0xE228
111
112/* Billable registers*/
113#define ADE7880_REG_AWATTHR 0xE400
114#define ADE7880_REG_BWATTHR 0xE401
115#define ADE7880_REG_CWATTHR 0xE402
116#define ADE7880_REG_AFWATTHR 0xE403
117#define ADE7880_REG_BFWATTHR 0xE404
118#define ADE7880_REG_CFWATTHR 0xE405
119#define ADE7880_REG_AFVARHR 0xE409
120#define ADE7880_REG_BFVARHR 0xE40A
121#define ADE7880_REG_CFVARHR 0xE40B
122#define ADE7880_REG_AVAHR 0xE40C
123#define ADE7880_REG_BVAHR 0xE40D
124#define ADE7880_REG_CVAHR 0xE40E
125
126/* Configuration and PQ registers */
127#define ADE7880_REG_IPEAK 0xE500
128#define ADE7880_REG_VPEAK 0xE501
129#define ADE7880_REG_STATUS0 0xE502
130#define ADE7880_REG_STATUS1 0xE503
131#define ADE7880_REG_AIMAV 0xE504
132#define ADE7880_REG_BIMAV 0xE505
133#define ADE7880_REG_CIMAV 0xE506
134#define ADE7880_REG_OILVL 0xE507
135#define ADE7880_REG_OVLVL 0xE508
136#define ADE7880_REG_SAGLVL 0xE509
137#define ADE7880_REG_MASK0 0xE50A
138#define ADE7880_REG_MASK1 0xE50B
139#define ADE7880_REG_IAWV 0xE50C
140#define ADE7880_REG_IBWV 0xE50D
141#define ADE7880_REG_ICWV 0xE50E
142#define ADE7880_REG_INWV 0xE50F
143#define ADE7880_REG_VAWV 0xE510
144#define ADE7880_REG_VBWV 0xE511
145#define ADE7880_REG_VCWV 0xE512
146#define ADE7880_REG_AWATT 0xE513
147#define ADE7880_REG_BWATT 0xE514
148#define ADE7880_REG_CWATT 0xE515
149#define ADE7880_REG_AVA 0xE519
150#define ADE7880_REG_BVA 0xE51A
151#define ADE7880_REG_CVA 0xE51B
152#define ADE7880_REG_CHECKSUM 0xE51F
153#define ADE7880_REG_VNOM 0xE520
154#define ADE7880_REG_LAST_RWDATA32 0xE5FF
155#define ADE7880_REG_PHSTATUS 0xE600
156#define ADE7880_REG_ANGLE0 0xE601
157#define ADE7880_REG_ANGLE1 0xE602
158#define ADE7880_REG_ANGLE2 0xE603
159#define ADE7880_REG_PHNOLOAD 0xE608
160#define ADE7880_REG_LINECYC 0xE60C
161#define ADE7880_REG_ZXTOUT 0xE60D
162#define ADE7880_REG_COMPMODE 0xE60E
163#define ADE7880_REG_GAIN 0xE60F
164#define ADE7880_REG_CFMODE 0xE610
165#define ADE7880_REG_CF1DEN 0xE611
166#define ADE7880_REG_CF2DEN 0xE612
167#define ADE7880_REG_CF3DEN 0xE613
168#define ADE7880_REG_APHCAL 0xE614
169#define ADE7880_REG_BPHCAL 0xE615
170#define ADE7880_REG_CPHCAL 0xE616
171#define ADE7880_REG_PHSIGN 0xE617
172#define ADE7880_REG_CONFIG 0xE618
173#define ADE7880_REG_MMODE 0xE700
174#define ADE7880_REG_ACCMODE 0xE701
175#define ADE7880_REG_LCYCMODE 0xE702
176#define ADE7880_REG_PEAKCYC 0xE703
177#define ADE7880_REG_SAGCYC 0xE704
178#define ADE7880_REG_CFCYC 0xE705
179#define ADE7880_REG_HSDC_CFG 0xE706
180#define ADE7880_REG_VERSION 0xE707
181#define ADE7880_REG_RESERVED 0xE7E4
182#define ADE7880_REG_LAST_RWDATA8 0xE7FD
183#define ADE7880_REG_FVRMS 0xE880
184#define ADE7880_REG_FIRMS 0xE881
185#define ADE7880_REG_FWATT 0xE882
186#define ADE7880_REG_FVAR 0xE883
187#define ADE7880_REG_FVA 0xE884
188#define ADE7880_REG_FPF 0xE885
189#define ADE7880_REG_VTHD 0xE886
190#define ADE7880_REG_ITHD 0xE887
191#define ADE7880_REG_HXVRMS 0xE888
192#define ADE7880_REG_HXIRMS 0xE889
193#define ADE7880_REG_HXWATT 0xE88A
194#define ADE7880_REG_HXVAR 0xE88B
195#define ADE7880_REG_HXVA 0xE88C
196#define ADE7880_REG_HXPF 0xE88D
197#define ADE7880_REG_HXVHD 0xE88E
198#define ADE7880_REG_HXIHD 0xE88F
199#define ADE7880_REG_HYVRMS 0xE890
200#define ADE7880_REG_HYIRMS 0xE891
201#define ADE7880_REG_HYWATT 0xE892
202#define ADE7880_REG_HFVAR 0xE893
203#define ADE7880_REG_HYVA 0xE894
204#define ADE7880_REG_HYPF 0xE895
205#define ADE7880_REG_HYVHD 0xE896
206#define ADE7880_REG_HYIHD 0xE897
207#define ADE7880_REG_HZVRMS 0xE898
208#define ADE7880_REG_HZIRMS 0xE899
209#define ADE7880_REG_HZWATT 0xE89A
210#define ADE7880_REG_HZVAR 0xE89B
211#define ADE7880_REG_HZVA 0xE89C
212#define ADE7880_REG_HZPF 0xE89D
213#define ADE7880_REG_HZVHD 0xE89E
214#define ADE7880_REG_HZIHD 0xE89F
215#define ADE7880_REG_HCONFIG 0xE900
216#define ADE7880_REG_APF 0xE902
217#define ADE7880_REG_BPF 0xE903
218#define ADE7880_REG_CPF 0xE904
219#define ADE7880_REG_APERIOD 0xE905
220#define ADE7880_REG_BPERIOD 0xE906
221#define ADE7880_REG_CPERIOD 0xE907
222#define ADE7880_REG_APNOLOAD 0xE908
223#define ADE7880_REG_VARNOLOAD 0xE909
224#define ADE7880_REG_VANOLOAD 0xE90A
225#define ADE7880_REG_LAST_ADD 0xE9FE
226#define ADE7880_REG_LAST_RWDATA16 0xE9FF
227#define ADE7880_REG_CONFIG3 0xEA00
228#define ADE7880_REG_LAST_OP 0xEA01
229#define ADE7880_REG_WTHR 0xEA02
230#define ADE7880_REG_VARTHR 0xEA03
231#define ADE7880_REG_VATHR 0xEA04
232#define ADE7880_REG_HX 0xEA08
233#define ADE7880_REG_HY 0xEA09
234#define ADE7880_REG_HZ 0xEA0A
235#define ADE7880_REG_LPOILVL 0xEC00
236#define ADE7880_REG_CONFIG2 0xEC01
237
238/* ADE7880_REG_IPEAK Bit Definition */
239#define ADE7880_IPPHASE2 NO_OS_BIT(26)
240#define ADE7880_IPPHASE1 NO_OS_BIT(25)
241#define ADE7880_IPPHASE0 NO_OS_BIT(24)
242#define ADE7880_IPEAKVAL NO_OS_GENMASK(23, 0)
243
244/* ADE7880_REG_VPEAK Bit Definition */
245#define ADE7880_VPPHASE2 NO_OS_BIT(26)
246#define ADE7880_VPPHASE1 NO_OS_BIT(25)
247#define ADE7880_VPPHASE0 NO_OS_BIT(24)
248#define ADE7880_VPEAKVAL NO_OS_GENMASK(23, 0)
249
250/* ADE7880_REG_STATUS0 Bit Definition */
251#define ADE7880_STATUS0_HREADY NO_OS_BIT(19)
252#define ADE7880_STATUS0_REVPSUM3 NO_OS_BIT(18)
253#define ADE7880_STATUS0_DREADY NO_OS_BIT(17)
254#define ADE7880_STATUS0_CF3 NO_OS_BIT(16)
255#define ADE7880_STATUS0_CF2 NO_OS_BIT(15)
256#define ADE7880_STATUS0_CF1 NO_OS_BIT(14)
257#define ADE7880_STATUS0_REVPSUM2 NO_OS_BIT(13)
258#define ADE7880_STATUS0_REVFRPC NO_OS_BIT(12)
259#define ADE7880_STATUS0_REVFRPB NO_OS_BIT(11)
260#define ADE7880_STATUS0_REVFRPA NO_OS_BIT(10)
261#define ADE7880_STATUS0_REVPSUM1 NO_OS_BIT(9)
262#define ADE7880_STATUS0_REVAPC NO_OS_BIT(8)
263#define ADE7880_STATUS0_REVAPB NO_OS_BIT(7)
264#define ADE7880_STATUS0_REVAPA NO_OS_BIT(6)
265#define ADE7880_STATUS0_LENERGY NO_OS_BIT(5)
266#define ADE7880_STATUS0_VAEHF NO_OS_BIT(4)
267#define ADE7880_STATUS0_FREHF NO_OS_BIT(3)
268#define ADE7880_STATUS0_FAEHF NO_OS_BIT(1)
269#define ADE7880_STATUS0_AEHF NO_OS_BIT(0)
270
271/* ADE7880_REG_STATUS1 Bit Definition */
272#define ADE7880_STATUS1_CRC NO_OS_BIT(25)
273#define ADE7880_STATUS1_PKV NO_OS_BIT(24)
274#define ADE7880_STATUS1_PKI NO_OS_BIT(23)
275#define ADE7880_STATUS1_MISMTCH NO_OS_BIT(20)
276#define ADE7880_STATUS1_SEQERR NO_OS_BIT(19)
277#define ADE7880_STATUS1_OV NO_OS_BIT(18)
278#define ADE7880_STATUS1_OI NO_OS_BIT(17)
279#define ADE7880_STATUS1_SAG NO_OS_BIT(16)
280#define ADE7880_STATUS1_RSTDONE NO_OS_BIT(15)
281#define ADE7880_STATUS1_ZXIC NO_OS_BIT(14)
282#define ADE7880_STATUS1_ZXIB NO_OS_BIT(13)
283#define ADE7880_STATUS1_ZXIA NO_OS_BIT(12)
284#define ADE7880_STATUS1_ZXVC NO_OS_BIT(11)
285#define ADE7880_STATUS1_ZXVB NO_OS_BIT(10)
286#define ADE7880_STATUS1_ZXVA NO_OS_BIT(9)
287#define ADE7880_STATUS1_ZXTOIC NO_OS_BIT(8)
288#define ADE7880_STATUS1_ZXTOIB NO_OS_BIT(7)
289#define ADE7880_STATUS1_ZXTOIA NO_OS_BIT(6)
290#define ADE7880_STATUS1_ZXTOVC NO_OS_BIT(5)
291#define ADE7880_STATUS1_ZXTOVB NO_OS_BIT(4)
292#define ADE7880_STATUS1_ZXTOVA NO_OS_BIT(3)
293#define ADE7880_STATUS1_VANLOAD NO_OS_BIT(2)
294#define ADE7880_STATUS1_FNLOAD NO_OS_BIT(1)
295#define ADE7880_STATUS1_NLOAD NO_OS_BIT(0)
296
297/* ADE7880_REG_MASK0 Bit Definition */
298#define ADE7880_MASK0_HREADY NO_OS_BIT(19)
299#define ADE7880_MASK0_REVPSUM3 NO_OS_BIT(18)
300#define ADE7880_MASK0_DREADY NO_OS_BIT(17)
301#define ADE7880_MASK0_CF3 NO_OS_BIT(16)
302#define ADE7880_MASK0_CF2 NO_OS_BIT(15)
303#define ADE7880_MASK0_CF1 NO_OS_BIT(14)
304#define ADE7880_MASK0_REVPSUM2 NO_OS_BIT(13)
305#define ADE7880_MASK0_REVFRPC NO_OS_BIT(12)
306#define ADE7880_MASK0_REVFRPB NO_OS_BIT(11)
307#define ADE7880_MASK0_REVFRPA NO_OS_BIT(10)
308#define ADE7880_MASK0_REVPSUM1 NO_OS_BIT(9)
309#define ADE7880_MASK0_REVAPC NO_OS_BIT(8)
310#define ADE7880_MASK0_REVAPB NO_OS_BIT(7)
311#define ADE7880_MASK0_REVAPA NO_OS_BIT(6)
312#define ADE7880_MASK0_LENERGY NO_OS_BIT(5)
313#define ADE7880_MASK0_VAEHF NO_OS_BIT(4)
314#define ADE7880_MASK0_FREHF NO_OS_BIT(3)
315#define ADE7880_MASK0_FAEHF NO_OS_BIT(1)
316#define ADE7880_MASK0_AEHF NO_OS_BIT(0)
317
318/* ADE7880_REG_MASK1 Bit Definition */
319#define ADE7880_MASK1_CRC NO_OS_BIT(25)
320#define ADE7880_MASK1_PKV NO_OS_BIT(24)
321#define ADE7880_MASK1_PKI NO_OS_BIT(23)
322#define ADE7880_MASK1_MISMTCH NO_OS_BIT(20)
323#define ADE7880_MASK1_SEQERR NO_OS_BIT(19)
324#define ADE7880_MASK1_OV NO_OS_BIT(18)
325#define ADE7880_MASK1_OI NO_OS_BIT(17)
326#define ADE7880_MASK1_SAG NO_OS_BIT(16)
327#define ADE7880_MASK1_RSTDONE NO_OS_BIT(15)
328#define ADE7880_MASK1_ZXIC NO_OS_BIT(14)
329#define ADE7880_MASK1_ZXIB NO_OS_BIT(13)
330#define ADE7880_MASK1_ZXIA NO_OS_BIT(12)
331#define ADE7880_MASK1_ZXVC NO_OS_BIT(11)
332#define ADE7880_MASK1_ZXVB NO_OS_BIT(10)
333#define ADE7880_MASK1_ZXVA NO_OS_BIT(9)
334#define ADE7880_MASK1_ZXTOIC NO_OS_BIT(8)
335#define ADE7880_MASK1_ZXTOIB NO_OS_BIT(7)
336#define ADE7880_MASK1_ZXTOIA NO_OS_BIT(6)
337#define ADE7880_MASK1_ZXTOVC NO_OS_BIT(5)
338#define ADE7880_MASK1_ZXTOVB NO_OS_BIT(4)
339#define ADE7880_MASK1_ZXTOVA NO_OS_BIT(3)
340#define ADE7880_MASK1_VANLOAD NO_OS_BIT(2)
341#define ADE7880_MASK1_FNLOAD NO_OS_BIT(1)
342#define ADE7880_MASK1_NLOAD NO_OS_BIT(0)
343
344/* ADE7880_REG_PHSTATUS Bit Definition */
345#define ADE7880_VSPHASE2 NO_OS_BIT(14)
346#define ADE7880_VSPHASE1 NO_OS_BIT(13)
347#define ADE7880_VSPHASE0 NO_OS_BIT(12)
348#define ADE7880_OVPHASE2 NO_OS_BIT(11)
349#define ADE7880_OVPHASE1 NO_OS_BIT(10)
350#define ADE7880_OVPHASE0 NO_OS_BIT(9)
351#define ADE7880_OIPHASE2 NO_OS_BIT(5)
352#define ADE7880_OIPHASE1 NO_OS_BIT(4)
353#define ADE7880_OIPHASE0 NO_OS_BIT(3)
354
355/* ADE7880_REG_PHNOLOAD Bit Definition */
356#define ADE7880_VANLPHASE2 NO_OS_BIT(8)
357#define ADE7880_VANLPHASE1 NO_OS_BIT(7)
358#define ADE7880_VANLPHASE0 NO_OS_BIT(6)
359#define ADE7880_FNLPHASE2 NO_OS_BIT(5)
360#define ADE7880_FNLPHASE1 NO_OS_BIT(4)
361#define ADE7880_FNLPHASE0 NO_OS_BIT(3)
362#define ADE7880_NLPHASE2 NO_OS_BIT(2)
363#define ADE7880_NLPHASE1 NO_OS_BIT(1)
364#define ADE7880_NLPHASE0 NO_OS_BIT(0)
365
366/* ADE7880_REG_COMPMODE Bit Definition */
367#define ADE7880_SELFREQ NO_OS_BIT(14)
368#define ADE7880_VNOMCEN NO_OS_BIT(13)
369#define ADE7880_VNOMBEN NO_OS_BIT(12)
370#define ADE7880_VNOMAEN NO_OS_BIT(11)
371#define ADE7880_ANGLESEL NO_OS_GENMASK(10, 9)
372#define ADE7880_TERMSEL3_2 NO_OS_BIT(8)
373#define ADE7880_TERMSEL3_1 NO_OS_BIT(7)
374#define ADE7880_TERMSEL3_0 NO_OS_BIT(6)
375#define ADE7880_TERMSEL2_2 NO_OS_BIT(5)
376#define ADE7880_TERMSEL2_1 NO_OS_BIT(4)
377#define ADE7880_TERMSEL2_0 NO_OS_BIT(3)
378#define ADE7880_TERMSEL1_2 NO_OS_BIT(2)
379#define ADE7880_TERMSEL1_1 NO_OS_BIT(1)
380#define ADE7880_TERMSEL1_0 NO_OS_BIT(0)
381
382/* ADE7880_REG_GAIN Bit Definition */
383#define ADE7880_PGA3 NO_OS_GENMASK(8, 6)
384#define ADE7880_PGA2 NO_OS_GENMASK(5, 3)
385#define ADE7880_PGA1 NO_OS_GENMASK(2, 0)
386
387/* ADE7880_REG_CFMODE Bit Definition */
388#define ADE7880_CF3LATCH NO_OS_BIT(14)
389#define ADE7880_CF2LATCH NO_OS_BIT(13)
390#define ADE7880_CF1LATCH NO_OS_BIT(12)
391#define ADE7880_CF3DIS NO_OS_BIT(11)
392#define ADE7880_CF2DIS NO_OS_BIT(10)
393#define ADE7880_CF1DIS NO_OS_BIT(9)
394#define ADE7880_CF3SEL NO_OS_GENMASK(8, 6)
395#define ADE7880_CF2SEL NO_OS_GENMASK(5, 3)
396#define ADE7880_CF1SEL NO_OS_GENMASK(2, 0)
397
398/* ADE7880_REG_APHCAL, ADE7880_REG_BPHCAL,
399ADE7880_REG_CPHCAL, Bit Definition */
400#define ADE7880_PHCALVAL NO_OS_GENMASK(9, 0)
401
402/* ADE7880_REG_PHSIGN Bit Definition */
403#define ADE7880_SUM3SIGN NO_OS_BIT(8)
404#define ADE7880_SUM2SIGN NO_OS_BIT(7)
405#define ADE7880_CFVARSIGN NO_OS_BIT(6)
406#define ADE7880_BFVARSIGN NO_OS_BIT(5)
407#define ADE7880_AFVARSIGN NO_OS_BIT(4)
408#define ADE7880_SUM1SIGN NO_OS_BIT(3)
409#define ADE7880_CWSIGN NO_OS_BIT(2)
410#define ADE7880_BWSIGN NO_OS_BIT(1)
411#define ADE7880_AWSIGN NO_OS_BIT(0)
412
413/* ADE7880_REG_CONFIG Bit Definition */
414#define ADE7880_VTOIC NO_OS_GENMASK(13, 12)
415#define ADE7880_VTOIB NO_OS_GENMASK(11, 10)
416#define ADE7880_VTOIA NO_OS_GENMASK(9, 8)
417#define ADE7880_SWRST NO_OS_BIT(7)
418#define ADE7880_HSDCEN NO_OS_BIT(6)
419#define ADE7880_MOD2SHORT NO_OS_BIT(5)
420#define ADE7880_MOD1SHORT NO_OS_BIT(4)
421#define ADE7880_SWAP NO_OS_BIT(3)
422#define ADE7880_CF2DIS NO_OS_BIT(2)
423#define ADE7880_INTEN NO_OS_BIT(0)
424
425/* ADE7880_REG_MMODE Bit Definition */
426#define ADE7880_PEAKSEL2 NO_OS_BIT(4)
427#define ADE7880_PEAKSEL1 NO_OS_BIT(3)
428#define ADE7880_PEAKSEL0 NO_OS_BIT(2)
429
430/* ADE7880_REG_ACCMODE Bit Definition */
431#define ADE7880_REVAPSEL NO_OS_BIT(6)
432#define ADE7880_CONSEL NO_OS_GENMASK(5, 4)
433#define ADE7880_VARACC NO_OS_GENMASK(3, 2)
434#define ADE7880_WATTACC NO_OS_GENMASK(1, 0)
435
436/* ADE7880_REG_LCYCMODE Bit Definition */
437#define ADE7880_PFMODE NO_OS_BIT(7)
438#define ADE7880_RSTREAD NO_OS_BIT(6)
439#define ADE7880_ZXSEL2 NO_OS_BIT(5)
440#define ADE7880_ZXSEL1 NO_OS_BIT(4)
441#define ADE7880_ZXSEL0 NO_OS_BIT(3)
442#define ADE7880_LVA NO_OS_BIT(2)
443#define ADE7880_LVAR NO_OS_BIT(1)
444#define ADE7880_LWATT NO_OS_BIT(0)
445
446/* ADE7880_REG_HSDC_CFG Bit Definition */
447#define ADE7880_HSAPOL NO_OS_BIT(5)
448#define ADE7880_HXFER NO_OS_GENMASK(4, 3)
449#define ADE7880_HGAP NO_OS_BIT(2)
450#define ADE7880_HSIZE NO_OS_BIT(1)
451#define ADE7880_HCLK NO_OS_BIT(0)
452
453/* ADE7880_REG_CONFIG3 Bit Definition */
454#define ADE7880_ININTEN NO_OS_BIT(3)
455#define ADE7880_INSEL NO_OS_BIT(2)
456#define ADE7880_LPFSEL NO_OS_BIT(1)
457#define ADE7880_HPFEN NO_OS_BIT(0)
458
459/* ADE7880_REG_HCONFIG Bit Definition */
460#define ADE7880_ACTPHSEL NO_OS_GENMASK(9, 8)
461#define ADE7880_HRATE NO_OS_GENMASK(7, 5)
462#define ADE7880_HSTIME NO_OS_GENMASK(4, 3)
463#define ADE7880_HPHASE NO_OS_GENMASK(2, 1)
464#define ADE7880_HRCFG NO_OS_BIT(0)
465
466/* ADE7880_REG_LPOILVL Bit Definition */
467#define ADE7880_LPLINE NO_OS_GENMASK(7, 3)
468#define ADE7880_LPOIL NO_OS_GENMASK(2, 0)
469
470/* ADE7880_REG_CONFIG2 Bit Definition */
471#define ADE7880_I2C_LOCK NO_OS_BIT(1)
472#define ADE7880_EXTREFEN NO_OS_BIT(0)
473
474/* Miscellaneous Definitions */
475#define ADE7880_CHIP_ID 0x0EA0
476#define ADE7880_RESET_RECOVER 100
477#define ADE7880_RAM_PROTECTION1 0xE7FE
478#define ADE7880_RAM_PROTECTION2 0xE7E3
479#define ADE7880_RAM_PROT_VAL1 0xAD
480#define ADE7880_RAM_PROT_VAL2 0x80
481#define ADE7880_SET_SPI_ADDR 0xEBFF
482#define ADE7880_DUMB_VAL 0x01
483
484
485/*Configuration registers*/
486/* Set DICOEFF= 0xFFFF8000 when integrator is enabled*/
487#define ADE7880_DICOEFF 0x00000000
488#define ADE7880_VLEVEL_VAL 0x007A1200
489/*Constant Definitions***/
490/*DSP ON*/
491#define ADE7880_RUN_ON 0x0001
492// /*Full scale Codes (FS) referred from Datasheet.*/
493// /*Respective digital codes are produced when ADC inputs*/
494// /*are at full scale. Do not Change. */
495#define ADE7880_RMS_FS_CODES 5326737
496
497/* Assuming a transformer ratio of 1000:1 and 10 ohms burden resistance value */
498#define ADE7880_BURDEN_RES 10
499#define ADE7880_CURRENT_TR_RATIO 1000
500#define ADE7880_CURRENT_TR_FCN (ADE7880_CURRENT_TR_RATIO / ADE7880_BURDEN_RES)
501/* Assuming a voltage divider with Rlow 1k and Rup 1MEG */
502#define ADE7880_UP_RES 1000000
503#define ADE7880_DOWN_RES 1000
504#define ADE7880_VOLTAGE_TR_FCN ((ADE7880_DOWN_RES + ADE7880_UP_RES) / ADE7880_DOWN_RES)
505
506// 0.5V full scale * 0.707 * 10000 for mili units
507#define ADE7880_FS_VOLTAGE 3535
508
514 /* The angles between phase voltages and phase currents are measured. */
516 /* The angles between phase voltages are measured */
518 /* The angles between phase currents are measured. */
520 /* no angles are measured. */
522};
523
530 /* gain 1 */
532 /* gain 2 */
534 /* gain 4 */
536 /* gain 8 */
538 /* gain 16 */
540};
541
548 /* the CFx frequency is proportional to the sum of total active powers on
549 each phase */
551 /* the CFx frequency is proportional to the sum of apparent powers on
552 each phase */
554 /* the CFx frequency is proportional to the sum of fundamental active
555 powers on each phase */
557 /* the CFx frequency is proportional to the sum of fundamental reactive
558 powers on each phase */
560};
561
568 /* Phase A voltage */
570 /* Phase B voltage */
572 /* Phase C voltage */
574};
575
582 /* Phase B voltage */
584 /* Phase C voltage */
586 /* Phase A voltage */
588};
589
596 /* Phase C voltage */
598 /* Phase A voltage */
600 /* Phase B voltage */
602};
603
609 /* Signed accumulation mode of the total and fundamental active powers */
611 /* Positive only accumulation mode of the total and fundamental active powers */
613 /* Reserved. When set, the device behaves like WATTACC[1:0] = 00. */
615 /* Absolute accumulation mode of the total and fundamental active powers */
617};
618
624 /* Signed accumulation mode of the fundamental reactive powers */
626 /* reserved. When set, the device behaves like VARACC[1:0] = 00. */
628 /* The fundamental reactive power is accumulated, depending on the sign of the
629 fundamental active power */
631 /* Absolute accumulation mode of the fundamental reactive powers */
633};
634
641 /* 3-phase four wires with three voltage sensors */
643 /* 3-phase three wires delta connection. In this mode, BVRMS register contains the rms
644 value of VA-VC */
646 /* 3-phase four wires with two voltage sensors. */
648 /* 3-phase four wires delta connection. */
650};
651
657 /* HSDC transmits sixteen 32-bit words in the following order: IAWV, VAWV, IBWV, VBWV, ICWV,
658 VCWV, INWV, AVA, BVA, CVA, AWATT, BWATT, CWATT, AFVAR, BFVAR, and CFVAR. */
660 /* HSDC transmits seven instantaneous values of currents and voltages: IAWV, VAWV,
661 IBWV, VBWV, ICWV, VCWV, and INWV. */
663 /* HSDC transmits nine instantaneous values of phase powers: AVA, BVA, CVA, AWATT,
664 BWATT, CWATT, AFVAR, BFVAR, and CFVAR. */
666 /* 11 = reserved. If set, the ADE7880 behaves as if HXFER[1:0] = 00. */
668};
669
675 /* Phase A voltage and current */
677 /* Phase B voltage and current */
679 /* Phase C voltage and current */
681 /* Neutral current */
683};
684
691 /* 500 ms */
693 /* 750 ms */
695 /* 1000 ms */
697 /* 1250 ms */
699};
700
706 /* 125 µs (8 kHz rate) */
708 /* 250 µs (4 kHz rate) */
710 /* 1 ms (1 kHz rate) */
712 /* 16 ms (62.5 Hz rate) */
714 /* 128 ms (7.8125 Hz rate) */
716 /* 512 ms (1.953125 Hz rate) */
718 /* 1.024 sec (0.9765625 Hz rate) */
720 /* harmonic calculations disabled */
722};
723
729 /* Phase A voltage */
731 /* Phase B voltage */
733 /* Phase C voltage */
735 /* reserved. If selected, phase C voltage is used */
737};
738
744 /* 50 Hz */
746 /* 60 Hz */
748};
749
759
765 /* SPI is not available in PSM2 & PSM3*/
766 /* PSM0 normal mode */
768 /* PSM1 measure the mean absolute values (mav)
769 of the 3-phase currents */
771 /* PSM2 Current peak detect mode */
773 /* PSM3 Sleep mode */
775};
776
784 /* psm0 descriptor */
786 /* psm1 descriptor */
788 /* reset descriptor */
790 /* Variable for mode selection */
791 uint8_t power_mode;
792};
793
801 /* psm0 descriptor */
803 /* psm1 descriptor */
805 /* reset descriptor */
807 /* Variable storing the IRMS value */
808 uint32_t irms_val;
809 /* Variable storing the VRMS value */
810 uint32_t vrms_val;
811 /* Variable for mode selection */
812 uint8_t power_mode;
813};
814
815/* Read device register. */
816int ade7880_read(struct ade7880_dev *dev, uint16_t reg_addr,
817 uint32_t *reg_data);
818
819/* Write device register. */
820int ade7880_write(struct ade7880_dev *dev, uint16_t reg_addr,
821 uint32_t reg_data);
822
823/* Set power mode */
824int ade7880_set_power_mode(struct ade7880_dev *dev);
825
826/* Update specific register bits. */
827int ade7880_update_bits(struct ade7880_dev *dev, uint16_t reg_addr,
828 uint32_t mask, uint32_t reg_data);
829
830/* Read Energy/Power for specific phase */
831int ade7880_read_data_ph(struct ade7880_dev *dev, enum ade7880_phase phase);
832
833/* Initialize the device. */
834int ade7880_init(struct ade7880_dev **device,
836
837/* Setup the device */
838int ade7880_setup(struct ade7880_dev *dev);
839
840/* Remove the device and release resources. */
841int ade7880_remove(struct ade7880_dev *dev);
842
843/* Get interrupt indicator from STATUS0 register. */
844int ade7880_get_int_status0(struct ade7880_dev *dev, uint32_t msk,
845 uint8_t *status);
846
847#endif // __ADE7880_H__
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
ade7880_varacc_e
ADE7880 These bits decide the accumulation mode of funamental reactive powers.
Definition ade7880.h:623
@ ADE7880_VARACC_RESERVED
Definition ade7880.h:627
@ ADE7880_VARACC_SIGN_WATTACC
Definition ade7880.h:630
@ ADE7880_VARACC_ABSOLUTE_ACC
Definition ade7880.h:632
@ ADE7880_VARACC_SIGNED_ACC
Definition ade7880.h:625
int ade7880_set_power_mode(struct ade7880_dev *dev)
Set power mode.
Definition ade7880.c:141
int ade7880_read_data_ph(struct ade7880_dev *dev, enum ade7880_phase phase)
Read the power/energy for specific phase.
Definition ade7880.c:254
ade7880_hxfer_e
ADE7880 These bits select the data transmitted on HSDC.
Definition ade7880.h:656
@ ADE7880_HXFER_RESERVED
Definition ade7880.h:667
@ ADE7880_HXFER_9
Definition ade7880.h:665
@ ADE7880_HXFER_7
Definition ade7880.h:662
@ ADE7880_HXFER_16
Definition ade7880.h:659
int ade7880_update_bits(struct ade7880_dev *dev, uint16_t reg_addr, uint32_t mask, uint32_t reg_data)
Update specific register bits.
Definition ade7880.c:200
ade7880_actphsel_e
ADE7880 These bits select the phase voltage used as time base for harmonic calculations.
Definition ade7880.h:728
@ ADE7880_ACTPHSEL_RESERVED
Definition ade7880.h:736
@ ADE7880_ACTPHSEL_B
Definition ade7880.h:732
@ ADE7880_ACTPHSEL_C
Definition ade7880.h:734
@ ADE7880_ACTPHSEL_A
Definition ade7880.h:730
ade7880_wattacc_e
ADE7880 These bits decide the accumulation mode of fundamental active powers.
Definition ade7880.h:608
@ ADE7880_WATTACC_ABSOLUTE_ACC
Definition ade7880.h:616
@ ADE7880_WATTACC_POSITIVE_ACC
Definition ade7880.h:612
@ ADE7880_WATTACC_RESERVED
Definition ade7880.h:614
@ ADE7880_WATTACC_SIGNED_ACC
Definition ade7880.h:610
ade7880_cfxsel_e
ADE7880 These bits indicate the value the CFx frequency is proportional to.
Definition ade7880.h:547
@ ADE7880_CFXSEL_3
Definition ade7880.h:559
@ ADE7880_CFXSEL_1
Definition ade7880.h:553
@ ADE7880_CFXSEL_0
Definition ade7880.h:550
@ ADE7880_CFXSEL_2
Definition ade7880.h:556
ade7880_vtoia_e
ADE7880 These bits decide what phase voltage is considered together with Phase A current in the power...
Definition ade7880.h:567
@ ADE7880_VTOIA_C
Definition ade7880.h:573
@ ADE7880_VTOIA_A
Definition ade7880.h:569
@ ADE7880_VTOIA_B
Definition ade7880.h:571
ade7880_pga_gain_e
ADE7880 phase currents/neutral current/phase voltages gain selection is currently being used.
Definition ade7880.h:529
@ ADE7880_PGAGAIN_16
Definition ade7880.h:539
@ ADE7880_PGAGAIN_8
Definition ade7880.h:537
@ ADE7880_PGAGAIN_2
Definition ade7880.h:533
@ ADE7880_PGAGAIN_4
Definition ade7880.h:535
@ ADE7880_PGAGAIN_1
Definition ade7880.h:531
ade7880_hstime_e
ADE7880 These bits decide the delay period after which, if HRCFG bit is set to 0, Bit 19 (HREADY) in ...
Definition ade7880.h:690
@ ADE7880_HSTIM_500
Definition ade7880.h:692
@ ADE7880_HSTIM_1250
Definition ade7880.h:698
@ ADE7880_HSTIM_700
Definition ade7880.h:694
@ ADE7880_HSTIM_1000
Definition ade7880.h:696
ade7880_consel_e
ADE7880 These bits select the inputs to the energy accumulation registers. IA’, IB’,...
Definition ade7880.h:640
@ ADE7880_CONSEL_3P_3W_DELTA
Definition ade7880.h:645
@ ADE7880_CONSEL_3P_4W_DELTA
Definition ade7880.h:649
@ ADE7880_CONSEL_3P_4W
Definition ade7880.h:647
@ ADE7880_CONSEL_3P_3W
Definition ade7880.h:642
int ade7880_get_int_status0(struct ade7880_dev *dev, uint32_t msk, uint8_t *status)
Get interrupt indicator from STATUS0 register.
Definition ade7880.c:227
int ade7880_remove(struct ade7880_dev *dev)
Remove the device and release resources.
Definition ade7880.c:460
ade7880_phase
ADE7880 available phases.
Definition ade7880.h:754
@ ADE7880_PHASE_C
Definition ade7880.h:757
@ ADE7880_PHASE_A
Definition ade7880.h:755
@ ADE7880_PHASE_B
Definition ade7880.h:756
ade7880_freq_sel_e
ADE7880 Freq value.
Definition ade7880.h:743
@ ADE7880_SELFREQ_60
Definition ade7880.h:747
@ ADE7880_SELFREQ_50
Definition ade7880.h:745
ade7880_power_mode_e
ADE7880 Power mode selection.
Definition ade7880.h:764
@ REDUCED_POWER_MODE
Definition ade7880.h:770
@ NORMAL_MODE
Definition ade7880.h:767
@ LOW_POWER_MODE
Definition ade7880.h:772
@ SLEEP_MODE
Definition ade7880.h:774
int ade7880_setup(struct ade7880_dev *dev)
Setup the device.
Definition ade7880.c:403
ade7880_hrate_e
ADE7880 These bits manage the update rate of the harmonic registers.
Definition ade7880.h:705
@ ADE7880_HRATE_1K
Definition ade7880.h:711
@ ADE7880_HRATE_8K
Definition ade7880.h:707
@ ADE7880_HRATE_DISABLED
Definition ade7880.h:721
@ ADE7880_HRATE_0_9765625
Definition ade7880.h:719
@ ADE7880_HRATE_7_8125
Definition ade7880.h:715
@ ADE7880_HRATE_4K
Definition ade7880.h:709
@ ADE7880_HRATE_62_5
Definition ade7880.h:713
@ ADE7880_HRATE_1_953125
Definition ade7880.h:717
int ade7880_write(struct ade7880_dev *dev, uint16_t reg_addr, uint32_t reg_data)
Write device register.
Definition ade7880.c:101
int ade7880_init(struct ade7880_dev **device, struct ade7880_init_param init_param)
Initialize the device.
Definition ade7880.c:315
ade7880_vtoib_e
ADE7880 These bits decide what phase voltage is considered together with Phase B current in the power...
Definition ade7880.h:581
@ ADE7880_VTOIB_C
Definition ade7880.h:585
@ ADE7880_VTOIB_A
Definition ade7880.h:587
@ ADE7880_VTOIB_B
Definition ade7880.h:583
ade7880_hphase_e
ADE7880 These bits decide what phase or neutral is analyzed by the harmonic calculations block.
Definition ade7880.h:674
@ ADE7880_HPHASE_N
Definition ade7880.h:682
@ ADE7880_HPHASE_A
Definition ade7880.h:676
@ ADE7880_HPHASE_B
Definition ade7880.h:678
@ ADE7880_HPHASE_C
Definition ade7880.h:680
ade7880_anglesel_e
ADE7880 angles measurement.
Definition ade7880.h:513
@ ADE7880_ANGLESEL_V_I
Definition ade7880.h:515
@ ADE7880_ANGLESEL_I
Definition ade7880.h:519
@ ADE7880_NO_ANGLESEL
Definition ade7880.h:521
@ ADE7880_ANGLESEL_V
Definition ade7880.h:517
int ade7880_read(struct ade7880_dev *dev, uint16_t reg_addr, uint32_t *reg_data)
Read device register.
Definition ade7880.c:48
ade7880_vtoic_e
ADE7880 These bits decide what phase voltage is considered together with Phase C current in the power...
Definition ade7880.h:595
@ ADE7880_VTOIC_C
Definition ade7880.h:597
@ ADE7880_VTOIC_B
Definition ade7880.h:601
@ ADE7880_VTOIC_A
Definition ade7880.h:599
Header file of GPIO Interface.
Print messages helpers.
Header file of SPI Interface.
Header file of utility functions.
ADE7880 Device structure.
Definition ade7880.h:798
struct no_os_spi_desc * spi_desc
Definition ade7880.h:800
uint8_t power_mode
Definition ade7880.h:812
struct no_os_gpio_desc * psm0_desc
Definition ade7880.h:802
uint32_t irms_val
Definition ade7880.h:808
uint32_t vrms_val
Definition ade7880.h:810
struct no_os_gpio_desc * psm1_desc
Definition ade7880.h:804
struct no_os_gpio_desc * reset_desc
Definition ade7880.h:806
ADE7880 Device initialization parameters.
Definition ade7880.h:781
struct no_os_gpio_desc * psm1_desc
Definition ade7880.h:787
struct no_os_spi_init_param * spi_init
Definition ade7880.h:783
struct no_os_gpio_desc * psm0_desc
Definition ade7880.h:785
struct no_os_gpio_desc * reset_desc
Definition ade7880.h:789
uint8_t power_mode
Definition ade7880.h:791
Definition ad9361_util.h:63
Structure holding the GPIO descriptor.
Definition no_os_gpio.h:84
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128