From f98750c13fb8425106630ad0eacbb65a204e8333 Mon Sep 17 00:00:00 2001 From: Adam Shamblin Date: Sun, 29 May 2022 18:09:34 -0600 Subject: [PATCH] Further use of timers, probe at sysinfo and rtc. --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- rtc.fs | 21 +++++++++++++++++++++ sysinfo.fs | 6 ++++++ timer.fs | 22 ++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 rtc.fs create mode 100644 sysinfo.fs create mode 100644 timer.fs diff --git a/README.md b/README.md index aa90178..2a09036 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Given a pin number, return the pin's address on the IO bank. 13 pin ``` -### funcsel@ ( addr -- n ) +### funcsel@ ( addr -- n ) *funcsel fetch* Given a pin address, leave the number of the currently selected pin function on the stack. @@ -33,7 +33,7 @@ the stack. 13 pin funcsel@ ``` -### funcsel! ( addr n -- ) +### funcsel! ( addr n -- ) *funcsel set* Given a pin address and a function number (see GPIO pin constants), set the selected pin's function. @@ -42,6 +42,40 @@ selected pin's function. 13 pin SIO funcsel! ``` +### pins ( -- ) + +Display a list of all GPIO pins and their currently selected function. + +```forth +pins +``` + +### output-enable ( n -- ), output-disable ( n -- ) + +Given a pin number, enable or disable that pin for output. + +```forth +13 output-enable +13 output-disable +``` + +### output-enabled? ( n -- flag ) + +Given a pin number, leave a flag on the stack indicating whether or not output +is enabled. + +```forth +13 output-enabled? +``` + +### output-enabled. ( -- ) + +Display a table of pins and their output status. + +```forth +output-enabled. +``` + ## Terminal *file: terminal.fs* diff --git a/rtc.fs b/rtc.fs new file mode 100644 index 0000000..bdbaaf5 --- /dev/null +++ b/rtc.fs @@ -0,0 +1,21 @@ +\ Words for interacting with RTC peripheral + +$4005c000 constant RTC_BASE +RTC_BASE $00 + constant RTC_CLKDIV_M1 +RTC_BASE $04 + constant RTC_SETUP_0 +RTC_BASE $08 + constant RTC_SETUP_1 +RTC_BASE $0c + constant RTC_CTRL +RTC_BASE $10 + constant RTC_IRC_SETUP_0 +RTC_BASE $14 + constant RTC_IRC_SETUP_1 +RTC_BASE $18 + constant RTC_1 +RTC_BASE $1c + constant RTC_0 +RTC_BASE $20 + constant RTC_INTR +RTC_BASE $24 + constant RTC_INTE +RTC_BASE $28 + constant RTC_INTF +RTC_BASE $2c + constant RTC_INTS + +( Working with the onboard RTC + It would appear the the rpiPico does have an onboard RTC.) + +: rtc-active? ( -- flag ) RTC_CTRL %10 and ; +: rtc-enable ( -- ) RTC_CTRL %1 or ; diff --git a/sysinfo.fs b/sysinfo.fs new file mode 100644 index 0000000..9189cb3 --- /dev/null +++ b/sysinfo.fs @@ -0,0 +1,6 @@ +\ Words for interacting with the sysinfo block + +$40000000 constant SYSINFO_BASE +SYSINFO_BASE $00 + constant CHIP_ID +SYSINFO_BASE $04 + constant PLATFORM +SYSINFO_BASE $40 + constant GITREF_RP2040 diff --git a/timer.fs b/timer.fs new file mode 100644 index 0000000..f738c95 --- /dev/null +++ b/timer.fs @@ -0,0 +1,22 @@ +\ Words for dealing with the system timer peripheral + +$40054000 constant TIMER_BASE +TIMER_BASE $00 + constant TIMEHW +TIMER_BASE $04 + constant TIMELW +TIMER_BASE $08 + constant TIMEHR +TIMER_BASE $0c + constant TIMELR + +TIMER_BASE $38 + constant TIMER_INTE + + +\ Display the current system timer. "counter print" +: counter. ( -- ) TIMELR @ TIMEHR @ swap D. ; + +\ Enable or disable a specific alarm. +\ example: 2 alarm-enable +: alarm-enable ( n -- ) 1 swap lshift TIMER_INTE @ or TIMER_INTE ! ; +: alarm-disable ( n -- ) 1 swap lshift TIMER_INTE @ and TIMER_INTE ! ; + +\ Check if an alarm is enabled. +\ example: 2 alarm-enabled? +: alarm-enabled? ( n -- flag ) 1 swap lshift TIMER_INTE @ and 0 > ; -- 2.39.5