BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:30 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Source Code Posting: HSERIN reimplementation, w/o dead-locks
PostPosted: Sun Jun 27, 2004 10:00 pm 
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


Top
  
 
 Post subject: Re: Source Code Posting: HSERIN reimplementation, w/o dead-l
PostPosted: Thu Jul 14, 2011 1:57 pm 
Offline
New User

Joined: Thu Jul 14, 2011 1:27 pm
Posts: 1
How can I get access to the code for the hserin re-implementation?
Thanks
Manlio


Top
 Profile  
 
 Post subject: Re: Source Code Posting: HSERIN reimplementation, w/o dead-l
PostPosted: Fri Jul 15, 2011 10:34 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Thanks for the post. If you can't post the code email me a copy and I'll psot it for you.

Just a couple nit picks. HSERIN timeouts work. However if you are using the wait modifier(or waitstr) and you continue to receive data, even if it doesn't match, the timeout will never trigger.

Also hserin/hserout do work in interrupts although if send to much data at once they may block in the interrupt because the send has to wait for the buffer to get room for more data which can cause issues(resets if you are doing something that would allow multiple interrupts to cascade and you blow out the stack).

Same applies to serin/serout which take time and block the interrupt from exiting. Cascading interrupts can cause stack overflow very quickly.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Source Code Posting: HSERIN reimplementation, w/o dead-l
PostPosted: Fri Jul 15, 2011 10:58 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
If I am reading this right, the code is from 2004? So to me I wonder if you tried the current code and what issues you were running into?

Kurt


Top
 Profile  
 
 Post subject: Re: Source Code Posting: HSERIN reimplementation, w/o dead-l
PostPosted: Sun Jul 17, 2011 12:32 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
My mistake. I should always look at the posted date. I expect hserin/hserout currently fixes all the problems that existed in 2004. :)

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO