Skip to content

Commit

Permalink
Merge pull request #329 from TG9541/release2.2.25
Browse files Browse the repository at this point in the history
fixes #328: release 2.2.25 - bug-fix and INTRX
  • Loading branch information
TG9541 authored Jul 10, 2020
2 parents 98ccbd3 + 86fd82b commit db67ed8
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
4 changes: 2 additions & 2 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ COLD:
.endif
MOV BG_TIM_PSCR,#3 ; prescaler 1/(2^3) = 1/8
.endif
LDW X,#BG_TIM_REL ; "BGTIMREL" timer reload for BG task
LDW BG_TIM_ARRH,X ; timer not yet started - use 16bit transfer
MOV BG_TIM_ARRH,#(BG_TIM_REL/256) ; reload H
MOV BG_TIM_ARRL,#(BG_TIM_REL%256) ; L
MOV BG_TIM_CR1,#0x01 ; enable background timer
MOV BG_TIM_IER,#0x01 ; enable background timer interrupt
.endif
Expand Down
2 changes: 1 addition & 1 deletion inc/defconf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; Default settings for all kinds of options
;--------------------------------------------------------
RELVER1 = 2 ; Revision digit 1
RELVER0 = 4 ; Revision digit 0
RELVER0 = 5 ; Revision digit 0

TERM_LINUX = 1 ; LF terminates line

Expand Down
92 changes: 92 additions & 0 deletions lib/INTRX
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
\ STM8 eForth buffered UART receive
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md

\ The code assumes target CPU resource definitions and that
\ RX buffer length are defined prior to loading!
\ More in the example at the end of the file

#require WIPE
#require :NVM
#require ALIAS
#require ]B!
#require '?KEY

5 CONSTANT #RIEN

NVM
VARIABLE rxbuf RBLEN 2- ALLOT
VARIABLE rxp \ UART RX ISR buffer write pointer
VARIABLE rrp \ ?RXB buffer read pointer

\ increment buffer pointer w/ wrap around
:NVM ( a -- )
DUP @ 1+ ( a ab1 ) [ rxbuf RBLEN + 1- ] LITERAL OVER < IF
( a n1 ) DROP rxbuf ( a n0 )
THEN
( a n ) SWAP !
;RAM ALIAS rpi

\ RX ISR handler
:NVM
SAVEC
UART1_DR C@ rxp @ C! rxp rpi
IRET
[ OVERT INT_UARTRX !

\ like ?RX only buffered
: ?RXB ( -- c T | F )
rrp @ rxp @ = IF
0
ELSE
rrp @ C@ -1 rrp rpi
THEN
;

\ Interrupt RX UART handler
: INTRX ( -- )
[ ' ?RXB ] LITERAL '?KEY !
rxbuf DUP rxp ! rrp !
[ 1 UART1_CR2 #RIEN ]B!
;

WIPE RAM

\\ Example

\ select the generic STM8S controller first

\ alternatively specify STM8S103, STM8S105 or STM8S207
\res MCU: STM8S103

\ load (or define) device independent constants
\res export INT_UARTRX UART_DR UART_CR2

\ define the UART buffer length
8 CONSTANT RBLEN

\ then load the controller independent code
#require INTRX

\ put it to work
#require WIPE
#require :NVM
#require OSCFREQ
#require UART_DIV
#require UARTBRR

NVM
'BOOT ( xt )
:NVM
INTRX
( xt ) LITERAL EXECUTE
;NVM 'BOOT !

\ calculate UART_DIV settings for 3840*10 = 38400 baud @ CPU clock rate
3840 OSCFREQ UART_DIV UARTBRR !
WIPE RAM

\ make it survive a RESET command
#require PERSIST
PERSIST

\ remember to set your terminal program (e.g. e4thcom) to 38400 baud!

0 comments on commit db67ed8

Please sign in to comment.