Skip to content

Commit 2eee130

Browse files
committed
allow specifying the address for reg_rd and reg_wr in 32-bit words
This change allows specifying the address in 32-bit words (i.e. the address as seen from the ULP), in addition to the existing mode of specifying a register's full address on the DPORT bus. If an address is between 0 and DR_REG_MAX_DIRECT (0x3ff), treat it as a word offset (ULP address), otherwise treat it as a full address on the DPORT bus as before.
1 parent 5169996 commit 2eee130

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

esp32_ulp/opcodes.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
OPCODE_WR_REG = 1
1717
OPCODE_RD_REG = 2
1818

19+
DR_REG_MAX_DIRECT = 0x3ff
1920
RD_REG_PERIPH_RTC_CNTL = 0
2021
RD_REG_PERIPH_RTC_IO = 1
2122
RD_REG_PERIPH_SENS = 2
@@ -353,8 +354,9 @@ def get_cond(arg):
353354

354355
def _soc_reg_to_ulp_periph_sel(reg):
355356
# Map SoC peripheral register to periph_sel field of RD_REG and WR_REG instructions.
356-
ret = 3
357-
if reg < DR_REG_RTCCNTL_BASE:
357+
if reg < DR_REG_MAX_DIRECT:
358+
ret = RD_REG_PERIPH_RTC_CNTL
359+
elif reg < DR_REG_RTCCNTL_BASE:
358360
raise ValueError("invalid register base")
359361
elif reg < DR_REG_RTCIO_BASE:
360362
ret = RD_REG_PERIPH_RTC_CNTL
@@ -371,7 +373,10 @@ def _soc_reg_to_ulp_periph_sel(reg):
371373

372374
def i_reg_wr(reg, high_bit, low_bit, val):
373375
reg = get_imm(reg)
374-
_wr_reg.addr = (reg & 0xff) >> 2
376+
if reg < DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
377+
_wr_reg.addr = reg
378+
else:
379+
_wr_reg.addr = (reg & 0xff) >> 2
375380
_wr_reg.periph_sel = _soc_reg_to_ulp_periph_sel(reg)
376381
_wr_reg.data = get_imm(val)
377382
_wr_reg.low = get_imm(low_bit)
@@ -382,7 +387,10 @@ def i_reg_wr(reg, high_bit, low_bit, val):
382387

383388
def i_reg_rd(reg, high_bit, low_bit):
384389
reg = get_imm(reg)
385-
_rd_reg.addr = (reg & 0xff) >> 2
390+
if reg < DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
391+
_rd_reg.addr = reg
392+
else:
393+
_rd_reg.addr = (reg & 0xff) >> 2
386394
_rd_reg.periph_sel = _soc_reg_to_ulp_periph_sel(reg)
387395
_rd_reg.unused = 0
388396
_rd_reg.low = get_imm(low_bit)

tests/compat/fixes.S

+5
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ counter:
1717
entry:
1818
MOVE R1, gpio
1919
WAIT 42
20+
21+
# reg_rd/reg_wr with "short" and "long" address notation
22+
reg_rd 12, 7, 0
23+
reg_rd 0x3ff48000, 7, 0
24+
2025
halt

0 commit comments

Comments
 (0)