1
6
7
8
15
16
17
18
19
20
24
25
26
27
28
29
30
31
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
242
243
244
245
246
247
248
249
250
251
252
253
254
260
261
267
268
275
276
277
278
279
280
283
287
288
289
290
291
292
293
294
295
296
299
300
307
325
326
332
333
334
335
336
337
338
339
340
346
353
354
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
384
385
386
387
388
389
390
391
392
393
394
395
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
417
418
424
429
430
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
473
480
481
487
494
495
501
508
509
515
516
517
518
519
520
521
522
523
524
529
530
531
532
533
534
535
536
537
538
544
545
546
547
548
549
550
551
552
553
558
559
560
561
562
563
564
565
566
567
573
574
575
576
577
578
579
580
581
582
587
588
589
590
591
592
593
594
595
596
599
600
601
602
603
604
605
606
607
608
611
612
613
614
615
616
617
618
619
620
623
624
625
626
627
628
629
630
631
632
635
636
637
638
639
640
641
642
643
644
647
648
649
650
651
652
653
654
655
656
659
660
661
662
663
664
665
666
667
668
671
672
673
674
675
676
677
678
679
680
683
684
685
686
687
688
689
690
691
692
695
696
697
698
699
700
701
702
703
704
707
708
709
710
711
712
713
714
715
716
719
720
721
722
723
724
725
726
727
728
731
732
733
734
735
736
737
738
739
740
743
744
745
746
747
748
749
750
751
752
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
778
779
782
788
789
792
798
799
800
801
802
803
804
805
806
807
808
811
812
813
814
815
816
817
818
819
820
823
824
825
826
827
828
829
830
831
832
835
836
837
838
839
840
841
842
843
844
847
848
849
850
851
852
853
854
855
856
859
860
861
862
863
864
865
866
867
868
871
872
875
882
883
886
893
894
897
904
905
906
907
908
909
910
911
912
913
916
917
918
919
920
921
922
923
924
925
928
929
930
931
932
933
934
935
936
937
940
941
942
943
944
945
946
947
948
949
950
951
952
956
957
958
959
960
961
962
963
964
965
966
967
968
972
973
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1012
1013
1014
1019
1020
1021
1022
1023
/* ... */
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "esp_err.h"
#include "ulp_common.h"
#include "ulp_fsm_common.h"
#include "soc/reg_base.h"7 includes
#ifdef __cplusplus
extern "C" {
#endif
/* ... */
#define R0 0
#define R1 1
#define R2 2
#define R3 3
/* ... */
#define OPCODE_WR_REG 1
#define OPCODE_RD_REG 2
#define RD_REG_PERIPH_RTC_CNTL 0
#define RD_REG_PERIPH_RTC_IO 1
#define RD_REG_PERIPH_SENS 2
#define RD_REG_PERIPH_RTC_I2C 3
#define OPCODE_I2C 3
#define SUB_OPCODE_I2C_RD 0
#define SUB_OPCODE_I2C_WR 1
#define OPCODE_DELAY 4
#define OPCODE_ADC 5
#define OPCODE_ST 6
#define SUB_OPCODE_ST 4
#define OPCODE_ALU 7
#define SUB_OPCODE_ALU_REG 0
#define SUB_OPCODE_ALU_IMM 1
#define SUB_OPCODE_ALU_CNT 2
#define ALU_SEL_ADD 0
#define ALU_SEL_SUB 1
#define ALU_SEL_AND 2
#define ALU_SEL_OR 3
#define ALU_SEL_MOV 4
#define ALU_SEL_LSH 5
#define ALU_SEL_RSH 6
#define ALU_SEL_SINC 0
#define ALU_SEL_SDEC 1
#define ALU_SEL_SRST 2
#define OPCODE_BRANCH 8
#define SUB_OPCODE_BX 0
#define SUB_OPCODE_BR 1
#define SUB_OPCODE_BS 2
#define BX_JUMP_TYPE_DIRECT 0
#define BX_JUMP_TYPE_ZERO 1
#define BX_JUMP_TYPE_OVF 2
#define SUB_OPCODE_B 1
#define B_CMP_L 0
#define B_CMP_GE 1
#define JUMPS_LT 0
#define JUMPS_GE 1
#define JUMPS_LE 2
#define OPCODE_END 9
#define SUB_OPCODE_END 0
#define SUB_OPCODE_SLEEP 1
#define OPCODE_TSENS 10
#define OPCODE_HALT 11
#define OPCODE_LD 13
#define OPCODE_MACRO 15
#define SUB_OPCODE_MACRO_LABEL 0
#define SUB_OPCODE_MACRO_BRANCH 1
#define SUB_OPCODE_MACRO_LABELPC 2 54 defines
/* ... */
union ulp_insn {
struct {
uint32_t cycles : 16;
uint32_t unused : 12;
uint32_t opcode : 4;
}{ ... } delay;
struct {
uint32_t dreg : 2;
uint32_t sreg : 2;
uint32_t unused1 : 6;
uint32_t offset : 11;
uint32_t unused2 : 4;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } st;
struct {
uint32_t dreg : 2;
uint32_t sreg : 2;
uint32_t unused1 : 6;
uint32_t offset : 11;
uint32_t unused2 : 7;
uint32_t opcode : 4;
}{ ... } ld;
struct {
uint32_t unused : 28;
uint32_t opcode : 4;
}{ ... } halt;
struct {
uint32_t dreg : 2;
uint32_t addr : 11;
uint32_t unused : 8;
uint32_t reg : 1;
uint32_t type : 3;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } bx;
struct {
uint32_t imm : 16;
uint32_t cmp : 1;
uint32_t offset : 7;
uint32_t sign : 1;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } b;
struct {
uint32_t imm : 8;
uint32_t unused : 7;
uint32_t cmp : 2;
uint32_t offset : 7;
uint32_t sign : 1;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } bs;
struct {
uint32_t dreg : 2;
uint32_t sreg : 2;
uint32_t treg : 2;
uint32_t unused : 15;
uint32_t sel : 4;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } alu_reg;
struct {
uint32_t unused1 : 4;
uint32_t imm : 8;
uint32_t unused2 : 9;
uint32_t sel : 4;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } alu_reg_s;
struct {
uint32_t dreg : 2;
uint32_t sreg : 2;
uint32_t imm : 16;
uint32_t unused : 1;
uint32_t sel : 4;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } alu_imm;
struct {
uint32_t addr : 8;
uint32_t periph_sel : 2;
uint32_t data : 8;
uint32_t low : 5;
uint32_t high : 5;
uint32_t opcode : 4;
}{ ... } wr_reg;
struct {
uint32_t addr : 8;
uint32_t periph_sel : 2;
uint32_t unused : 8;
uint32_t low : 5;
uint32_t high : 5;
uint32_t opcode : 4;
}{ ... } rd_reg;
struct {
uint32_t dreg : 2;
uint32_t mux : 4;
uint32_t sar_sel : 1;
uint32_t unused1 : 1;
uint32_t cycles : 16;
uint32_t unused2 : 4;
uint32_t opcode: 4;
}{ ... } adc;
struct {
uint32_t dreg : 2;
uint32_t wait_delay: 14;
uint32_t reserved: 12;
uint32_t opcode: 4;
}{ ... } tsens;
struct {
uint32_t i2c_addr : 8;
uint32_t data : 8;
uint32_t low_bits : 3;
uint32_t high_bits : 3;
uint32_t i2c_sel : 4;
uint32_t unused : 1;
uint32_t rw : 1;
uint32_t opcode : 4;
}{ ... } i2c;
struct {
uint32_t wakeup : 1;
uint32_t unused : 24;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } end;
struct {
uint32_t cycle_sel : 4;
uint32_t unused : 21;
uint32_t sub_opcode : 3;
uint32_t opcode : 4;
}{ ... } sleep;
struct {
uint32_t dreg : 2;
uint32_t label : 16;
uint32_t unused : 6;
uint32_t sub_opcode : 4;
uint32_t opcode: 4;
}{ ... } macro;
uint32_t instruction;
}{ ... };
/* ... */
#define I_DELAY(cycles_) { .delay = {\
.cycles = cycles_, \
.unused = 0, \
.opcode = OPCODE_DELAY }{...} }{...}
/* ... */
#define I_HALT() { .halt = {\
.unused = 0, \
.opcode = OPCODE_HALT }{...} }{...}
/* ... */
static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
{
uint32_t ret = 3;
if (reg < DR_REG_RTCCNTL_BASE) {
assert(0 && "invalid register base");
}{...} else if (reg < DR_REG_RTCIO_BASE) {
ret = RD_REG_PERIPH_RTC_CNTL;
}{...} else if (reg < DR_REG_SENS_BASE) {
ret = RD_REG_PERIPH_RTC_IO;
}{...} else if (reg < DR_REG_RTC_I2C_BASE) {
ret = RD_REG_PERIPH_SENS;
}{...} else if (reg < DR_REG_IO_MUX_BASE) {
ret = RD_REG_PERIPH_RTC_I2C;
}{...} else {
assert(0 && "invalid register base");
}{...}
return ret;
}{ ... }
/* ... */
#define I_WR_REG(reg, low_bit, high_bit, val) {.wr_reg = {\
.addr = ((reg) / sizeof(uint32_t)) & 0xff, \
.periph_sel = SOC_REG_TO_ULP_PERIPH_SEL(reg), \
.data = val, \
.low = low_bit, \
.high = high_bit, \
.opcode = OPCODE_WR_REG }{...} }{...}
/* ... */
#define I_RD_REG(reg, low_bit, high_bit) {.rd_reg = {\
.addr = ((reg) / sizeof(uint32_t)) & 0xff, \
.periph_sel = SOC_REG_TO_ULP_PERIPH_SEL(reg), \
.unused = 0, \
.low = low_bit, \
.high = high_bit, \
.opcode = OPCODE_RD_REG }{...} }{...}
/* ... */
#define I_WR_REG_BIT(reg, shift, val) I_WR_REG(reg, shift, shift, val)
/* ... */
#define I_WAKE() { .end = { \
.wakeup = 1, \
.unused = 0, \
.sub_opcode = SUB_OPCODE_END, \
.opcode = OPCODE_END }{...} }{...}
/* ... */
#define I_END() \
I_WR_REG_BIT(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)...
/* ... */
#define I_SLEEP_CYCLE_SEL(timer_idx) { .sleep = { \
.cycle_sel = timer_idx, \
.unused = 0, \
.sub_opcode = SUB_OPCODE_SLEEP, \
.opcode = OPCODE_END }{...} }{...}
/* ... */
#define I_TSENS(reg_dest, delay) { .tsens = { \
.dreg = reg_dest, \
.wait_delay = delay, \
.reserved = 0, \
.opcode = OPCODE_TSENS }{...} }{...}
/* ... */
#define I_ADC(reg_dest, adc_idx, pad_idx) { .adc = {\
.dreg = reg_dest, \
.mux = pad_idx + 1, \
.sar_sel = adc_idx, \
.unused1 = 0, \
.cycles = 0, \
.unused2 = 0, \
.opcode = OPCODE_ADC }{...} }{...}
/* ... */
#define I_ST(reg_val, reg_addr, offset_) { .st = { \
.dreg = reg_val, \
.sreg = reg_addr, \
.unused1 = 0, \
.offset = offset_, \
.unused2 = 0, \
.sub_opcode = SUB_OPCODE_ST, \
.opcode = OPCODE_ST }{...} }{...}
/* ... */
#define I_LD(reg_dest, reg_addr, offset_) { .ld = { \
.dreg = reg_dest, \
.sreg = reg_addr, \
.unused1 = 0, \
.offset = offset_, \
.unused2 = 0, \
.opcode = OPCODE_LD }{...} }{...}
/* ... */
#define I_BL(pc_offset, imm_value) { .b = { \
.imm = imm_value, \
.cmp = B_CMP_L, \
.offset = abs(pc_offset), \
.sign = (pc_offset >= 0) ? 0 : 1, \
.sub_opcode = SUB_OPCODE_B, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BGE(pc_offset, imm_value) { .b = { \
.imm = imm_value, \
.cmp = B_CMP_GE, \
.offset = abs(pc_offset), \
.sign = (pc_offset >= 0) ? 0 : 1, \
.sub_opcode = SUB_OPCODE_B, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXR(reg_pc) { .bx = { \
.dreg = reg_pc, \
.addr = 0, \
.unused = 0, \
.reg = 1, \
.type = BX_JUMP_TYPE_DIRECT, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXI(imm_pc) { .bx = { \
.dreg = 0, \
.addr = imm_pc, \
.unused = 0, \
.reg = 0, \
.type = BX_JUMP_TYPE_DIRECT, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXZR(reg_pc) { .bx = { \
.dreg = reg_pc, \
.addr = 0, \
.unused = 0, \
.reg = 1, \
.type = BX_JUMP_TYPE_ZERO, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXZI(imm_pc) { .bx = { \
.dreg = 0, \
.addr = imm_pc, \
.unused = 0, \
.reg = 0, \
.type = BX_JUMP_TYPE_ZERO, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXFR(reg_pc) { .bx = { \
.dreg = reg_pc, \
.addr = 0, \
.unused = 0, \
.reg = 1, \
.type = BX_JUMP_TYPE_OVF, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_BXFI(imm_pc) { .bx = { \
.dreg = 0, \
.addr = imm_pc, \
.unused = 0, \
.reg = 0, \
.type = BX_JUMP_TYPE_OVF, \
.sub_opcode = SUB_OPCODE_BX, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_ADDR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src1, \
.treg = reg_src2, \
.unused = 0, \
.sel = ALU_SEL_ADD, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_SUBR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src1, \
.treg = reg_src2, \
.unused = 0, \
.sel = ALU_SEL_SUB, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_ANDR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src1, \
.treg = reg_src2, \
.unused = 0, \
.sel = ALU_SEL_AND, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_ORR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src1, \
.treg = reg_src2, \
.unused = 0, \
.sel = ALU_SEL_OR, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_MOVR(reg_dest, reg_src) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.treg = 0, \
.unused = 0, \
.sel = ALU_SEL_MOV, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_LSHR(reg_dest, reg_src, reg_shift) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.treg = reg_shift, \
.unused = 0, \
.sel = ALU_SEL_LSH, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_RSHR(reg_dest, reg_src, reg_shift) { .alu_reg = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.treg = reg_shift, \
.unused = 0, \
.sel = ALU_SEL_RSH, \
.sub_opcode = SUB_OPCODE_ALU_REG, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_ADDI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_ADD, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_SUBI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_SUB, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_ANDI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_AND, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_ORI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_OR, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_MOVI(reg_dest, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = 0, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_MOV, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_LSHI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_LSH, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_RSHI(reg_dest, reg_src, imm_) { .alu_imm = { \
.dreg = reg_dest, \
.sreg = reg_src, \
.imm = imm_, \
.unused = 0, \
.sel = ALU_SEL_RSH, \
.sub_opcode = SUB_OPCODE_ALU_IMM, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define M_LABEL(label_num) { .macro = { \
.dreg = 0, \
.label = label_num, \
.unused = 0, \
.sub_opcode = SUB_OPCODE_MACRO_LABEL, \
.opcode = OPCODE_MACRO }{...} }{...}
/* ... */
#define M_BRANCH(label_num) { .macro = { \
.dreg = 0, \
.label = label_num, \
.unused = 0, \
.sub_opcode = SUB_OPCODE_MACRO_BRANCH, \
.opcode = OPCODE_MACRO }{...} }{...}
/* ... */
#define M_LABELPC(label_num) { .macro = { \
.dreg = 0, \
.label = label_num, \
.unused = 0, \
.sub_opcode = SUB_OPCODE_MACRO_LABELPC, \
.opcode = OPCODE_MACRO }{...} }{...}
/* ... */
#define M_MOVL(reg_dest, label_num) \
M_LABELPC(label_num), \
I_MOVI(reg_dest, 0)...
/* ... */
#define M_BL(label_num, imm_value) \
M_BRANCH(label_num), \
I_BL(0, imm_value)...
/* ... */
#define M_BGE(label_num, imm_value) \
M_BRANCH(label_num), \
I_BGE(0, imm_value)...
/* ... */
#define M_BX(label_num) \
M_BRANCH(label_num), \
I_BXI(0)...
/* ... */
#define M_BXZ(label_num) \
M_BRANCH(label_num), \
I_BXZI(0)...
/* ... */
#define M_BXF(label_num) \
M_BRANCH(label_num), \
I_BXFI(0)...
/* ... */
#define I_STAGE_INC(imm_) { .alu_reg_s = { \
.unused1 = 0, \
.imm = imm_, \
.unused2 = 0, \
.sel = ALU_SEL_SINC, \
.sub_opcode = SUB_OPCODE_ALU_CNT, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_STAGE_DEC(imm_) { .alu_reg_s = { \
.unused1 = 0, \
.imm = imm_, \
.unused2 = 0, \
.sel = ALU_SEL_SDEC, \
.sub_opcode = SUB_OPCODE_ALU_CNT, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define I_STAGE_RST() { .alu_reg_s = { \
.unused1 = 0, \
.imm = 0, \
.unused2 = 0, \
.sel = ALU_SEL_SRST, \
.sub_opcode = SUB_OPCODE_ALU_CNT, \
.opcode = OPCODE_ALU }{...} }{...}
/* ... */
#define M_BSLT(label_num, imm_value) \
M_BRANCH(label_num), \
I_JUMPS(0, imm_value, JUMPS_LT)...
/* ... */
#define M_BSGE(label_num, imm_value) \
M_BRANCH(label_num), \
I_JUMPS(0, imm_value, JUMPS_GE)...
/* ... */
#define M_BSLE(label_num, imm_value) \
M_BRANCH(label_num), \
I_JUMPS(0, imm_value, JUMPS_LE)...
/* ... */
#define M_BSEQ(label_num, imm_value) \
I_JUMPS(2, imm_value, JUMPS_LT), \
M_BRANCH(label_num), \
I_JUMPS(0, imm_value, JUMPS_LE)...
/* ... */
#define M_BSGT(label_num, imm_value) \
I_JUMPS(2, imm_value, JUMPS_LE), \
M_BRANCH(label_num), \
I_JUMPS(0, imm_value, JUMPS_GE)...
/* ... */
#define I_JUMPS(pc_offset, imm_value, comp_type) { .bs = { \
.imm = imm_value, \
.unused = 0, \
.cmp = comp_type, \
.offset = abs(pc_offset), \
.sign = (pc_offset >= 0) ? 0 : 1, \
.sub_opcode = SUB_OPCODE_BS, \
.opcode = OPCODE_BRANCH }{...} }{...}
/* ... */
#define I_I2C_RW(sub_addr, val, low_bit, high_bit, slave_sel, rw_bit) { .i2c = {\
.i2c_addr = sub_addr, \
.data = val, \
.low_bits = low_bit, \
.high_bits = high_bit, \
.i2c_sel = slave_sel, \
.unused = 0, \
.rw = rw_bit, \
.opcode = OPCODE_I2C }{...} }{...}
/* ... */
#define I_I2C_READ(slave_sel, sub_addr) I_I2C_RW(sub_addr, 0, 0, 0, slave_sel, SUB_OPCODE_I2C_RD)
/* ... */
#define I_I2C_WRITE(slave_sel, sub_addr, val) I_I2C_RW(sub_addr, val, 0, 7, slave_sel, SUB_OPCODE_I2C_WR)53 defines
#ifdef __cplusplus
}{...}
#endif