spcm_core.spcm_tools
1from ctypes import * 2 3# load registers for easier access 4from .regs import * 5 6 7# 8# ************************************************************************** 9# pvAllocMemPageAligned: creates a buffer for DMA that's page-aligned 10# ************************************************************************** 11# 12def pvAllocMemPageAligned (qwBytes): 13 dwAlignment = 4096 14 dwMask = dwAlignment - 1 15 16 # allocate non-aligned, slightly larger buffer 17 qwRequiredNonAlignedBytes = qwBytes * sizeof (c_char) + dwMask 18 pvNonAlignedBuf = (c_char * qwRequiredNonAlignedBytes)() 19 20 # get offset of next aligned address in non-aligned buffer 21 misalignment = addressof (pvNonAlignedBuf) & dwMask 22 if misalignment: 23 dwOffset = dwAlignment - misalignment 24 else: 25 dwOffset = 0 26 return(c_char * qwBytes).from_buffer(pvNonAlignedBuf, dwOffset)
def
pvAllocMemPageAligned(qwBytes):
13def pvAllocMemPageAligned (qwBytes): 14 dwAlignment = 4096 15 dwMask = dwAlignment - 1 16 17 # allocate non-aligned, slightly larger buffer 18 qwRequiredNonAlignedBytes = qwBytes * sizeof (c_char) + dwMask 19 pvNonAlignedBuf = (c_char * qwRequiredNonAlignedBytes)() 20 21 # get offset of next aligned address in non-aligned buffer 22 misalignment = addressof (pvNonAlignedBuf) & dwMask 23 if misalignment: 24 dwOffset = dwAlignment - misalignment 25 else: 26 dwOffset = 0 27 return(c_char * qwBytes).from_buffer(pvNonAlignedBuf, dwOffset)