Calculating The Page And Offset Of A Buffer - Real Time Devices AD1200 User Manual

Table of Contents

Advertisement

In C:
c h a r B u f f e r [ 1 0 0 0 0 ] ;
-or-
char *Buffer,'
B u f f e r = c a l l o c ( 1 0 0 0 0 ,
In BASIC:
D I M B U F F E R ? ( 5 O O O )
/ *
s t a t i c
a l l o c a t i o n
* /
/ *
d y n a m i c a l l o c a t i o n
* /
. Calculating the Page and Offset of a Buffer
Once you have a buffer ino which to place your data, you must inform the DMA controller of the location of
this buffer. This is a little more complex than it sounds because the DMA controller uses a page:offset memory
scheme, while you are probably used to thinking about your computer's memory in terms of a segmentoffset
scheme. Paged memory is simply memory that occupies contiguous, non-overlapping blocks of memory, with each
block being 64K (one page) in length. The frst page (page 0) starts at the first byre of memory, the second page
(page 1) starts at byte 65536, the third page (page 2) atbyte I3l072,and so on. A compurer wirh 640K of memory
has l0 pages of memory.
The DMA controller can write to (or read from) only one page witlrout being reprogrammed. This means that
the DMA controller has access to only 64K of memory at a time. If you program it to use page 3, it cannot use any
other page until you reprogram it to do so.
When DMA is started, the DMA controller is programmed o place data at a specified offset into a specified
page (for example, start writing at byte 512 of page 3). Each time a byte of data is written by the controller, the
offset is automatically incremented so the next byte will be placed in the next memory location. The problem for
you when programming these values is figuring out, what the corresponding page and offset are for your buffer.
Most compilers contain macros or functions that allow you to directly determine the segment and offset of a data
structure, but not the page and offset. Therefore, you must calculate the page number and offset yourself. probably
the most intuitive way of doing this is to convert tlte segmenroffset address of your buffer to a linear address and
then convert that linear address to a page:offset address, The table below shows functions/macros for determining
the segment and offset of a buffer.
Language
Segment
Offset
c
FP-SEG
s = FP_SEG(&Bulfe0
FP_OFF
o = FP_OFF(&Buffer)
Pascal
seg
S:= Seg13u11"r,
CIs
O := O1s13utf.t;
BASIC
VARSEG
S = VARSEG(BUFFER)
VARPTR
o = VARPTR(BUFFER)
Once you've determined the segment and offset, multiply the segment by 16 and add the offset to give you the
linear address. (Make sure you store this result in a long integer, or DWORD, or the results will be meaningiess.y
The page number is the quotient of the division of the linear address by 65536 and the offset inro the page is ttre
remainder of that division. Below are some programming examples for Pascal, C, and BASIC.
4-20

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ada1200

Table of Contents