diff --git a/mailbox.c b/mailbox.c index de44e81..a9c8eda 100644 --- a/mailbox.c +++ b/mailbox.c @@ -61,7 +61,7 @@ void *mapmem(unsigned base, unsigned size) printf("base=0x%x, mem=%p\n", base, mem); #endif if (mem == MAP_FAILED) { - printf("mmap error %d\n", (int)mem); + printf("mmap error %ld\n", (long)mem); exit (-1); } close(mem_fd); diff --git a/transmitter.cpp b/transmitter.cpp index 904085c..0671dc0 100644 --- a/transmitter.cpp +++ b/transmitter.cpp @@ -114,7 +114,7 @@ struct DMARegisters { }; struct AllocatedMemory { - uint32_t handle, size, physicalBase, virtualBase; + uintptr_t handle, size, physicalBase, virtualBase; int mBoxFd; }; @@ -169,17 +169,17 @@ float Transmitter::getSourceFreq() return (getPeripheralsVirtBaseAddress() == BCM2838_PERI_VIRT_BASE) ? BCM2838_PLLD_FREQ : BCM2835_PLLD_FREQ; } -uint32_t Transmitter::getPeripheralPhysAddress(volatile void *object) { - return PERIPHERALS_PHYS_BASE + (reinterpret_cast(object) - reinterpret_cast(peripherals)); +uintptr_t Transmitter::getPeripheralPhysAddress(volatile void *object) { + return PERIPHERALS_PHYS_BASE + (reinterpret_cast(object) - reinterpret_cast(peripherals)); } -uint32_t Transmitter::getPeripheralVirtAddress(uint32_t offset) { - return reinterpret_cast(peripherals) + offset; +uintptr_t Transmitter::getPeripheralVirtAddress(uintptr_t offset) { + return reinterpret_cast(peripherals) + offset; } -uint32_t Transmitter::getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object) +uintptr_t Transmitter::getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object) { - return memory.physicalBase + (reinterpret_cast(object) - memory.virtualBase); + return memory.physicalBase + (reinterpret_cast(object) - memory.virtualBase); } AllocatedMemory Transmitter::allocateMemory(uint32_t size) @@ -196,7 +196,7 @@ AllocatedMemory Transmitter::allocateMemory(uint32_t size) return memory; } memory.physicalBase = mem_lock(memory.mBoxFd, memory.handle); - memory.virtualBase = reinterpret_cast(mapmem(memory.physicalBase & ~0xC0000000, size)); + memory.virtualBase = reinterpret_cast(mapmem(memory.physicalBase & ~0xC0000000, size)); memory.size = size; return memory; } @@ -278,7 +278,7 @@ void Transmitter::transmit(WaveReader &reader, float frequency, float bandwidth, transmitting = true; PCMWaveHeader header = reader.getHeader(); - uint32_t bufferSize = static_cast(static_cast(header.sampleRate) * BUFFER_TIME / 1000000); + uint32_t bufferSize = static_cast(static_cast(header.sampleRate) * BUFFER_TIME / 1000000); preserveCarrier = preserveCarrierOnExit; clockDivisor = static_cast(round(getSourceFreq() * (0x01 << 12) / frequency)); @@ -382,8 +382,8 @@ void Transmitter::transmitViaDma(WaveReader &reader, uint32_t bufferSize, uint8_ #endif volatile DMAControllBlock *dmaCb = reinterpret_cast(dmaMemory.virtualBase); - volatile uint32_t *clkDiv = reinterpret_cast(reinterpret_cast(dmaCb) + 2 * sizeof(DMAControllBlock) * bufferSize); - volatile uint32_t *pwmFifoData = reinterpret_cast(reinterpret_cast(clkDiv) + sizeof(uint32_t) * bufferSize); + volatile uint32_t *clkDiv = reinterpret_cast(reinterpret_cast(dmaCb) + 2 * sizeof(DMAControllBlock) * bufferSize); + volatile uint32_t *pwmFifoData = reinterpret_cast(reinterpret_cast(clkDiv) + sizeof(uint32_t) * bufferSize); for (i = 0; i < bufferSize; i++) { float value = samples[i].getMonoValue(); #ifndef NO_PREEMP @@ -459,11 +459,11 @@ void Transmitter::transmitThread() #endif volatile TimerRegisters *timer = reinterpret_cast(getPeripheralVirtAddress(TIMER_BASE_OFFSET)); - uint64_t current = *(reinterpret_cast(&timer->low)); - uint64_t playbackStart = current; + uintptr_t current = *(reinterpret_cast(&timer->low)); + uintptr_t playbackStart = current; while (transmitting) { - uint64_t start = current; + uintptr_t start = current; bool locked = samplesMutex.try_lock(); auto unlock = [&]() { @@ -474,7 +474,7 @@ void Transmitter::transmitThread() while ((!locked || !samples.size()) && transmitting) { unlock(); std::this_thread::sleep_for(std::chrono::microseconds(1)); - current = *(reinterpret_cast(&timer->low)); + current = *(reinterpret_cast(&timer->low)); locked = samplesMutex.try_lock(); } if (!transmitting) { @@ -499,7 +499,7 @@ void Transmitter::transmitThread() output->div = (0x5A << 24) | (clockDivisor - static_cast(round(value * divisorRange))); while (offset == prevOffset) { std::this_thread::sleep_for(std::chrono::microseconds(1)); // asm("nop"); - current = *(reinterpret_cast(&timer->low));; + current = *(reinterpret_cast(&timer->low));; offset = (current - start) * sampleRate / 1000000; } } diff --git a/transmitter.hpp b/transmitter.hpp index d6eb6f9..5a9a0c6 100644 --- a/transmitter.hpp +++ b/transmitter.hpp @@ -58,9 +58,9 @@ class Transmitter uint32_t getPeripheralsVirtBaseAddress(); uint32_t getPeripheralsSize(); float getSourceFreq(); - uint32_t getPeripheralPhysAddress(volatile void *object); - static uint32_t getPeripheralVirtAddress(uint32_t offset); - uint32_t getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object); + uintptr_t getPeripheralPhysAddress(volatile void *object); + static uintptr_t getPeripheralVirtAddress(uintptr_t offset); + uintptr_t getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object); AllocatedMemory allocateMemory(uint32_t size); void freeMemory(AllocatedMemory &memory); volatile PWMRegisters *initPwmController();