239
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
serial programming mode or perform some other similar task.
Sending and Receiving Data (TX and RX buffers)
The serial port sends and receives data through TX (transmit) and RX (receive)
buffers. Read on and you will know how to allocate memory for buffers, use them,
handle overruns, and perform other tasks related to sending and receiving of data.
Allocating Memory for Buffers
Each buffer has a certain size, i.e, a memory capacity. This capacity is allocated
upon request from your program. When the device initially boots, no memory is
allocated to buffers at all.
Memory for buffers is allocated in pages. A page is 256 bytes of memory.
Allocating memory for a buffer is a two-step process: First you have to request for
a specific allocation (a number of pages) and then you have to perform the actual
allocation. For the RX buffer, request memory using
, and for the TX
buffer, request it using
.
The allocation method (
) applies to all buffers previously specified,
in one fell swoop. Hence:
dim
in, out
as
byte
out = ser.txbuffrq(
10
)
' Requesting 10 pages for the TX buffer. Out will
then contain how many can actually be allocated.
in = ser.rxbuffrq(
7
)
' Requesting 7 pages for the RX buffer. Will return
number of pages which can actually be allocated.
' .... Allocation requests for buffers of other objects ....
sys.buffalloc
' Performs actual memory allocation, as per previous
requests.
Actual memory allocation takes up to 100ms, so it is usually done just once, on
boot, for all required buffers. If you do not require some buffer, you may choose
not to allocate any memory to it. In effect, it will be disabled.
You may not always get the full amount of memory you have requested. Memory is
not an infinite resource, and if you have already requested (and received)
allocations for 95% of the memory for your platform, your next request will get up
to 5% of memory, even if you requested for 10%.
There is a small overhead for each buffer. Meaning, not 100% of the memory
allocated to a buffer is actually available for use. 16 bytes of each buffer are
reserved for variables needed to administer this buffer, such as various pointers
etc.
Thus, if we requested (and received) a buffer with 2 pages (256 * 2 = 512), we
actually have 496 bytes in which to queue data (512 - 16).
You can only change the size of buffers that belong to serial ports that
are closed (
= 0) at the moment sys.buffalloc methods
executes. If the port is opened at the time the sys.buffalloc method
executes then buffer capacities for this port will remain unchanged,
even if you requested changes through ser.rxbuffrq and ser.txbuffrq.
262
265
217
251