]> Vexing Labs - forthdeck.git/commitdiff
Further work with timers and interrupts.
authorAdam Shamblin <adam@vexingworkshop.com>
Tue, 31 May 2022 22:22:43 +0000 (16:22 -0600)
committerAdam Shamblin <adam@vexingworkshop.com>
Tue, 31 May 2022 22:22:43 +0000 (16:22 -0600)
gpio.fs
timer.fs

diff --git a/gpio.fs b/gpio.fs
index dbf58b4f0b5f7b578ce27aa9cbf53e6e859a4215..65ab7b896474376ff74dd110abced625340e2402 100644 (file)
--- a/gpio.fs
+++ b/gpio.fs
@@ -69,7 +69,8 @@ SIO_BASE $02c + constant GPIO_OE_XOR
     output? IF ." High" ELSE ." Low" THEN
   cr LOOP ;
 
-\ TODO I haven't read much about reading inputs yet, this will require fleshing out.
+\ TODO I haven't read much about reading inputs yet;
+\ this will require fleshing out.
 : input@ ( n -- ? ) 1 swap lshift GPIO_IN @ ;
 
 : inputs. ( -- )
index f738c9552413e3a6d534ae6116878b52d278057b..7355d39fd89524081522b4029be17d43f3b71dc7 100644 (file)
--- a/timer.fs
+++ b/timer.fs
@@ -1,16 +1,39 @@
 \ Words for dealing with the system timer peripheral
 
+$e0000000 constant PPB_BASE
+PPB_BASE $e100 + constant NVIC_ISER \ Interrupt set-enable register
+PPB_BASE $e180 + constant NVIC_ICER \ Interrupt clear-enable register
+
+: interrupt-enable ( n -- ) 1 swap lshift NVIC_ISER @ or NVIC_ISER ! ;
+: interrupt-disable ( n -- ) 1 swap lshift NVIC_ICER @ and NVIC_ICER ! ;
+
+\ Check if an interrupt is enabled.
+\ example: 12 interrupt-enabled?
+: interrupt-enabled? ( n -- flag ) 1 swap lshift NVIC_ISER @ and 0 > ;
+
+\ Display a list of interrupts and their enabled status.
+: interrupts-enabled. ( -- )
+  cr 32 0 DO I dup ." IRQ-" u.
+    interrupt-enabled? IF ." 1" ELSE ." 0" THEN
+  cr LOOP ;
+
 $40054000 constant TIMER_BASE
-TIMER_BASE $00 + constant TIMEHW
+TIMER_BASE $00 + constant TIMEHW \ High/Low Write
 TIMER_BASE $04 + constant TIMELW
-TIMER_BASE $08 + constant TIMEHR
+TIMER_BASE $08 + constant TIMEHR \ High/Low Read
 TIMER_BASE $0c + constant TIMELR
+TIMER_BASE $10 + constant ALARM0
+TIMER_BASE $14 + constant ALARM1
+TIMER_BASE $18 + constant ALARM2
+TIMER_BASE $1c + constant ALARM3
+TIMER_BASE $24 + constant TIMERAWH \ Timer, raw read, no side effects (latch)
+TIMER_BASE $28 + constant TIMERAWL
 
-TIMER_BASE $38 + constant TIMER_INTE
+TIMER_BASE $38 + constant TIMER_INTE \ Interrupt enable
 
 
 \ Display the current system timer. "counter print"
-: counter. ( -- ) TIMELR @ TIMEHR @ swap D. ; 
+: counter. ( -- ) TIMELR @ TIMEHR @ swap UD. ; 
 
 \ Enable or disable a specific alarm.
 \ example: 2 alarm-enable
@@ -20,3 +43,9 @@ TIMER_BASE $38 + constant TIMER_INTE
 \ Check if an alarm is enabled.
 \ example: 2 alarm-enabled?
 : alarm-enabled? ( n -- flag ) 1 swap lshift TIMER_INTE @ and 0 > ;
+
+: ms ( n -- )
+  0 dup alarm-enable interrupt-enable
+  1000 *      \ convert milliseconds to microseconds
+  TIMERAWL +  \ add raw time, lower 32 bits
+  ALARM0 !    \ write time to ALARM0