Skip to content

Instantly share code, notes, and snippets.

@wnienhaus
Created May 24, 2022 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnienhaus/56c534079823ed036a8f13a43ab7ddf8 to your computer and use it in GitHub Desktop.
Save wnienhaus/56c534079823ed036a8f13a43ab7ddf8 to your computer and use it in GitHub Desktop.
.set gpio2_channel, 12 ##12 is the channel no of gpio2
.set gpio4_channel, 10 ##10 is the channel no of gpio4
.set token, 0xcafe
.text
Counter: .long 0
Dummy1: .long 0
Dummy2: .long 0
State: .long 0
Magic: .long 0
.global entry
entry: //20
// load magic flag
move r0, Magic
ld r1, r0, 0
// test if we have initialised already
sub r1, r1, token
jump after_init, eq //jump if 0 (equal to token)
init:
//flag that we started running
move r1, token
st r1, r0, 0
init_led:
// set gpio2 (rtcio channel 12) to RTC
// 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module.
WRITE_RTC_REG(RTC_IO_TOUCH_PAD2_REG, RTC_IO_TOUCH_PAD2_MUX_SEL_M, 1, 1); //SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD2_REG, RTC_IO_TOUCH_PAD2_MUX_SEL_M);
// gpio_2 shall be output, not input
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio2_channel, 1, 1); //REG_SET_BIT(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio2_channel)
init_input:
// set gpio4 (rtcio channel 10) to RTC
// 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module.
WRITE_RTC_REG(RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_MUX_SEL_M, 1, 1); //SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_MUX_SEL_M);
// 1: input enabled (this gpio has a pull-down by default)
WRITE_RTC_REG(RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_FUN_IE_M, 1, 1); //SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_FUN_IE_M);
after_init:
/* read GPIO4 (rtcio 10) */
READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + gpio4_channel, 1)
add r0, r0, 0
load_last:
move r1, State
ld r2, r1, 0 //r2 = prev_State
decision:
sub r2, r0, r2 //r2=r0-r2 //00=0,01=-1,10=1,11=0
jump exit, eq //jump to exit if 0 (no diff between cur and prev level)
//else we trigger
trigger:
//enable led (set GPIO2)
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TS_REG, RTC_GPIO_ENABLE_W1TS_S + gpio2_channel, 1, 1)
move r1, State
st r0, r1, 0 //store new State
//count this event
move r1, Counter
ld r0, r1, 0
add r0, r0, 1
st r0, r1, 0
//delay
move r1, 200
move r2, off
jump delay
off:
//turn off led (clear GPIO2)
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TC_REG, RTC_GPIO_ENABLE_W1TC_S + gpio2_channel, 1, 1)
jump exit
delay:
wait 8000 //1ms at 8MHz
sub r1, r1, 1
jump r2, eq
jump delay
exit:
/* Get ULP back to sleep */
halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment