|
Hi,
below you find a "reimplementation" of the HSERIN/HSEROUT stuff. Nothing fancy, especially the setup-function only supports 8N1, but with variable baud-rate (up to 38400, more is not functional with the AtomPRO's SCI3 port).
Features: - unlike HSERIN _my_ stuff has a working time-out feature. I have used Timer A for this stuff. The timeout unit is about 0.5ms.
- unlike ordirnary SERIN/SEROUT it is _safe_ to call this stuff from an interrupt routine. Ordinary SERIN/SEROUT will just yield a reset when called from an ISR.
Theory: add "hserialdefs.bas" at the front of your basic project and "hserial.bas" just somewhere (best BELOW the main entry point of your program).
hserial.bas implements three "functions":
HSerialInit HSerialIn HSerialOut
You probably guess what these are for. "Arguments" are passed via global variables (well, all variables are global ...)
There is quite some documentation contained in the source. Comments and improvements are welcome.
One final note: reception of data is enabled all the time (of course not inside HSerialOut ...). I need this to monitor the output of a servo controller. Idially one would want to use the RDRF (RIE) interrupt for this. ATM I mis-use a "transmit enable" signal of the servo controller which is wired to IRQ1 and brought low by the servo-controller prior to sending any data. It wastes one IO-port and needs much care because the IRQ is triggerred by each character (unless disabled). Could try to use it as a RIE replacement, but the real solution would be access to the SCI3 interrupt. BTW: NONE of the SCI3 interrupts is accessible by an application program. Tried everything. The interrupts are not let through.
Have fun
Claus
########################### start of hserialdefs.bas ################################### ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Add this file to the project list before any other code using this HSerial ;; reimplementation ;; HSerIOMaxLen CON 8 ; maximal IO-length. Adjust as needed HSerIOBuf VAR Byte(HSerIOMaxLen) ; deblock-buffer HSerIOLen VAR Byte ; length to receive or transmit HSerIOTo VAR Byte ; timeout units are 1/2048 sec. HSerIOStat VAR Byte ; status, one of HSER_{OK,TIMEOUT,BUSY} HSerIOCnt VAR Byte ; now much was actually transferred HSerIORate VAR Word ; 2400, 4800, 9600, 19200, 38400, ; more just will not work ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Error codes, returned in the global variable HSerIOStat ;; HSER_OK CON 0 ; no error has occurred HSER_BUSY CON 1 ; receive attempt while transmit not finished HSER_TIMEOUT CON 2 ; timeout during receive or transmit ####################### end of hserialdefs.bas
####################### start of hserial.bas ########################################## ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; why did I wrote the stuff below? Because HSERIN _sucks_, the timeout is not ;; implemented. So we do it ourselves. ;; ;; Entry points: ;; HSerialInit, HSerialOut, HSerialIn ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; SCR3 bit constants ;; SCR3_TIE CON $80 SCR3_RIE CON S40 SCR3_TE CON $20 SCR3_RE CON $10 SCR3_MPIE CON $08 SCR3_TEIE CON $04 SCR3_CKE1 CON $02 SCR3_CKE0 CON $01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; SSR bit constants ;; SSR_TDRE CON $80 SSR_RDRF CON $40 SSR_OER CON $20 SSR_FER CON $10 SSR_PER CON $08 SSR_TEND CON $04 SSR_MPBR CON $02 SSR_MPBT CON $01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; SMR bit constants ;; SMR_COM CON $80 SMR_CHR CON $40 SMR_PE CON $20 SMR_PM CON $10 SMR_STOP CON $08 SMR_MP CON $04 SMR_CKS1 CON $02 SMR_CKS0 CON $01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; SYSCR2 bit constants ;; SYSCR2_SMSEL
|