TABLE OF CONTENTS
- /IO_Serial
- IO_Serial/Baud_calculation
- IO_Serial/Settings
- IO_Serial/Os_serial_session_open
- IO_Serial/Os_serial_close
- IO_Serial/Os_serial_init
- IO_Serial/Os_serial_ioctl
- IO_Serial/Os_serial_open
- IO_Serial/Os_serial_read
- IO_Serial/Os_serial_read_byte
- IO_Serial/Os_serial_udre_isr
- IO_Serial/Os_serial_urxc_isr
- IO_Serial/Os_serial_write
/IO_Serial [ Modules ]
DESCRIPTION
Serial communication IO subsystem. Session-based, only one session at time.
IO_Serial/Baud_calculation [ Constants ]
[ Top ] [ IO_Serial ] [ Constants ]
DESCRIPTION
Calculates the baud rate register value and the resulting real baud rate and the error.
DECLARATION
Const Os_serial_ubrr_val =((_xtal + Os_serial_baud * 8) /(os_serial_baud * 16) - 1) Const Os_serial_baud_real =(_xtal /(16 *(os_serial_ubrr_val + 1))) Const Os_serial_baud_error =((os_serial_baud_real * 1000) / Os_serial_baud - 1000)
IO_Serial/Settings [ Constants ]
[ Top ] [ IO_Serial ] [ Constants ]
DESCRIPTION
Set the baudrate.
DECLARATION
#if Varexist( "Os_serial_baud") = False Const Os_serial_baud = 9600 #endif
IO_Serial/Os_serial_session_open [ Variables ]
[ Top ] [ IO_Serial ] [ Variables ]
DESCRIPTION
Bit is set while a Task uses the serial IO subsystem, other tasks trying to open it are put on a waiting list and suspended until its Free.
DECLARATION
Dim Os_serial_session_open As Bit
IO_Serial/Os_serial_close [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Closes the session to let other tasks use the serial IO.
DECLARATION
Sub Os_serial_close() Disable Urxc Os_semaphore_release Os_serial_session_semaphore End Sub
SEE ALSO
IO_Serial/Os_serial_open
IO_Serial/Os_serial_init [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Initializes the serial IO subsystem
DECLARATION
Sub Os_serial_init()
SOURCE
Os_serial_session_semaphore = Os_semaphore_create(1) Os_serial_session_open = True End Sub
IO_Serial/Os_serial_ioctl [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
T
DECLARATION
Sub Os_serial_ioctl() End Sub
SEE ALSO
a
IO_Serial/Os_serial_open [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Prior to send/receive, a Task has to open the session. When another Task is using the serial IO, either an error is returned to the calling Task or it gets blocked until the serial IO is Free again.
DECLARATION
Function Os_serial_open(byval Queuemode As Word , Byref Receivebuffer As Word , Byval Buffersize As Word) As Byte Os_serial_session_open = Os_semaphore_aquire Os_serial_session_semaphore , Queuemode Os_serial_open = Os_serial_session_open Os_serial_tx_complete = Os_serial_session_open If Receivebuffer <> 0 Then Os_serial_rxbuffer_start = Receivebuffer Os_serial_rxbuffer_w_ptr = Receivebuffer Os_serial_rxbuffer_r_ptr = Receivebuffer Os_serial_rxbuffer_end = Receivebuffer + Buffersize End If Ubrr = Os_serial_ubrr_val Enable Urxc End Function
SEE ALSO
IO_Serial/Os_serial_close
IO_Serial/Os_serial_read [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Reads a given count of bytes to a memory location, initiates the Interrupt-driven receive loop
DECLARATION
Function Os_serial_read(byref Datapointer As Word , Byref Datalength As Word) As Word Local Bytesread As Word Local Databyte As Byte Bytesread = 0 If Os_serial_session_open = True Then For Bytesread = 1 To Datalength If Os_serial_rxbuffer_w_ptr <> Os_serial_rxbuffer_r_ptr Then Databyte = Inp(os_serial_rxbuffer_r_ptr) If Os_serial_rxbuffer_r_ptr = Os_serial_rxbuffer_end Then Os_serial_rxbuffer_r_ptr = Os_serial_rxbuffer_start Else Incr Os_serial_rxbuffer_r_ptr End If Else Exit For End If Out Datapointer , Databyte Incr Datapointer Next End If Return Bytesread End Sub
SEE ALSO
IO_Serial/Os_serial_read_byte
IO_Serial/Os_serial_read_byte [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Reads one byte from the serial IO, returns 0 if nothing to receive.
DECLARATION
Function Os_serial_read_byte() As Byte Local Databyte As Byte If Os_serial_session_open = True And Os_serial_rxbuffer_w_ptr <> Os_serial_rxbuffer_r_ptr Then Databyte = Inp(os_serial_rxbuffer_r_ptr) If Os_serial_rxbuffer_r_ptr = Os_serial_rxbuffer_end Then Os_serial_rxbuffer_r_ptr = Os_serial_rxbuffer_start Else Incr Os_serial_rxbuffer_r_ptr End If Else Databyte = 0 End If Return Databyte End Function
SEE ALSO
IO_Serial/Os_serial_read
IO_Serial/Os_serial_udre_isr [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Interrupt routine transmitting the contents of a buffer
DECLARATION
Os_serial_udre_isr: Udr = Inp(os_serial_txbuffer_ptr) ' send byte ' Incr Os_serial_txbuffer_ptr ' update buffer pointer ' Decr Os_serial_txbuffer_index If Os_serial_txbuffer_index = 0 Then Disable Udre ' buffer empty: disable UDRE ' Os_serial_tx_complete = True End If Return
SEE ALSO
IO_Serial/Os_serial_urxc_isr
IO_Serial/Os_serial_urxc_isr [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Interrupt routine receiving data to a ring buffer
DECLARATION
Os_serial_urxc_isr ___r16 = Inp(udr) Out Os_serial_rxbuffer_w_ptr , ___r16 Incr Os_serial_rxbuffer_w_ptr If Os_serial_rxbuffer_w_ptr = Os_serial_rxbuffer_end Then Os_serial_rxbuffer_w_ptr = Os_serial_rxbuffer_start End If Return
SEE ALSO
IO_Serial/Os_serial_udre_isr
IO_Serial/Os_serial_write [ Functions ]
[ Top ] [ IO_Serial ] [ Functions ]
DESCRIPTION
Sends a desired count of bytes from the given memory location, initiates the Interrupt-driven transmit loop
DECLARATION
Sub Os_serial_write(byref Datapointer As Word , Byval Datalength As Word) If Os_serial_session_open = True Then While Os_serial_tx_complete = False : Wend ' wait for previous message to transmit if neccessary ' Os_serial_tx_complete = False Os_serial_txbuffer_ptr = Datapointer ' set internal buffer pointer ' Os_serial_txbuffer_index = Datalength Os_serial_tx_ready_loop: ' wait until tx buffer is ready ' sbis UCSRA, UDRE rjmp Os_serial_tx_ready_loop Udr = Inp(os_serial_txbuffer_ptr) ' send first byte ' Incr Os_serial_txbuffer_ptr ' update buffer pointer ' Decr Os_serial_txbuffer_index If 0 < Os_serial_txbuffer_index Then Enable Udre ' tx buffer not empty: enable Interrupt driven transmission ' Else Os_serial_tx_complete = True End If End If End Sub