Contained Within
Find More Documentation
Featured Support Resources
| Download this book in PDF
FCode Memory Allocation
B
- To get general-purpose memory, use buffer: or alloc-mem. Use free-mem to de-allocate memory obtained with alloc-mem.
- To map in portions of your SBus device for ordinary access, use " map-in" $call-parent as in:
-
| my-address offset + my-space size " map-in" $call-parent ( virt ) |
| To later map out those portions of your device, use " map-out" $call-parent as in: |
-
( virt ) size " map-out" $call-parent
- To use a region of system memory for DMA (for example, for both direct CPU access and DMA access from a device), first define the following mapping and allocation routines, then follow the steps below to ensure data coherency.
-
: dma-alloc ( size -- virt ) " dma-alloc" $call-parent ;
: dma-free ( virt size -- ) " dma-free" $call-parent ;
: dma-map-in ( virt size cache? -- devaddr )
" dma-map-in" $call-parent
;
: dma-map-out ( virt devaddr size -- ) " dma-map-out" $call-parent ;
: dma-sync ( virt devaddr size -- ) \ Correct even if "dma-sync" missing
" dma-sync" ['] $call-parent catch if
2drop 3drop
then
;
|
-
-
Allocate the DMA region with:
-
-
a. dma-alloc
b. dma-map-in
-
-
CPU accesses the region using virt from dma-alloc, then perform dma-sync.
-
Start DMA operation, using devaddr from dma-map-in.
a. Wait for DMA complete status. b. Repeat DMA as needed, then perform dma-sync
-
Repeat Steps 2 and 3 as needed
-
Deallocate the region when completed, with:
-
-
a. dma-map-out
b. dma-free
|
|