Mercurial > hg > Members > kono > Cerium
view TaskManager/kernel/ppe/DmaBuffer.cc @ 603:42c94f85c779
long -> memaddr (64 or 32)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Nov 2009 14:13:29 +0900 |
parents | 1733f3cbfa28 |
children | 60aa3f241b10 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "types.h" #include "DmaBuffer.h" #define ALIGN_DOWN(v, align) ((v)&(-align)) #define ALIGN_UP(v, align) ALIGN_DOWN((v)+((align)-1), align) void* new_align(int alignment, int size) { char *nonalign; char *align; nonalign = new char[size + sizeof(void*) + alignment - 1]; align = (char*)(ALIGN_UP((memaddr)nonalign+sizeof(void*),alignment)); *((void**)align - 1) = (void*)nonalign; return align; } void free_align(void *ptr) { char *real; if (ptr != NULL) { real = (char*)(*((void**)(ptr)-1)); delete real; } } DmaBuffer::DmaBuffer(int size) { buffer[0] = malloc(size); buffer[1] = malloc(size); //posix_memalign(&buffer[0], DEFAULT_ALIGNMENT, size); //posix_memalign(&buffer[1], DEFAULT_ALIGNMENT, size); //buffer[0] = new_align(DEFAULT_ALIGNMENT, size); //buffer[1] = new_align(DEFAULT_ALIGNMENT, size); flag = 0; } DmaBuffer::~DmaBuffer(void) { //free(buffer[0]); //free(buffer[1]); free_align(buffer[0]); free_align(buffer[1]); } void DmaBuffer::swap_buffer(void) { flag ^= 1; } void DmaBuffer::get_buffer(void *_dst) { void **dst = (void**)_dst; *dst = buffer[flag]; }