forked from Sepanta/pcie-driver
				
			
				 3 changed files with 104 additions and 5 deletions
			
			
		@ -0,0 +1,63 @@ | 
				
			|||
#include "api.h" | 
				
			|||
#include <sys/mman.h> | 
				
			|||
#include <sys/types.h> | 
				
			|||
#include <sys/ioctl.h> | 
				
			|||
#include <stdio.h> | 
				
			|||
#include <fcntl.h> | 
				
			|||
#include <unistd.h> | 
				
			|||
#include <time.h> | 
				
			|||
 | 
				
			|||
#include <sys/poll.h> | 
				
			|||
 | 
				
			|||
#include <pthread.h> | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
UltraSoundDevice::UltraSoundDevice() | 
				
			|||
{ | 
				
			|||
    files[0] = open("/proc/usd_reg_0", O_RDWR, 0); | 
				
			|||
    bars[0]= mmap(NULL, 64 * 1024, PROT_READ | PROT_WRITE, MAP_SHARED, files[0], 0); | 
				
			|||
 | 
				
			|||
    files[1] = open("/proc/usd_reg_1", O_RDWR, 0); | 
				
			|||
    bars[1]= mmap(NULL, 128 * 1024 * 1024, PROT_READ | PROT_WRITE, MAP_SHARED, files[1], 0); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
UltraSoundDevice::~UltraSoundDevice() | 
				
			|||
{ | 
				
			|||
	munmap(bars[0], 64 * 1024); | 
				
			|||
  munmap(bars[1], 128 * 1024 * 1024); | 
				
			|||
 | 
				
			|||
  for(int i = 0; i < BAR_NUM; i++) | 
				
			|||
  { | 
				
			|||
    close(files[i]); | 
				
			|||
  } | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
uint8_t UltraSoundDevice::readByte(uint32_t address, uint32_t bar) | 
				
			|||
{ | 
				
			|||
  uint8_t* ptr = (uint8_t*)bars[bar]; | 
				
			|||
 | 
				
			|||
  return ptr[address]; | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
uint32_t UltraSoundDevice::readWord(uint32_t address, uint32_t bar) | 
				
			|||
{ | 
				
			|||
  uint32_t* ptr = (uint32_t*)bars[bar]; | 
				
			|||
 | 
				
			|||
  return ptr[address / 4]; | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
void UltraSoundDevice::writeByte(uint32_t address, uint32_t bar, uint8_t data) | 
				
			|||
{ | 
				
			|||
    uint8_t* ptr = (uint8_t*)bars[bar]; | 
				
			|||
    ptr[address] = data; | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/*************************************************************************************************/ | 
				
			|||
void UltraSoundDevice::writeWord(uint32_t address, uint32_t bar, uint32_t data) | 
				
			|||
{ | 
				
			|||
    uint32_t* ptr = (uint32_t*)bars[bar]; | 
				
			|||
    ptr[address / 4] = data; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,21 @@ | 
				
			|||
#include "stdint.h" | 
				
			|||
 | 
				
			|||
#define BAR_NUM 2 | 
				
			|||
#define DEV_NAME  "usd_reg" | 
				
			|||
 | 
				
			|||
class UltraSoundDevice  | 
				
			|||
{ | 
				
			|||
private: | 
				
			|||
  void* bars[BAR_NUM]; | 
				
			|||
  int files[BAR_NUM]; | 
				
			|||
 | 
				
			|||
public: | 
				
			|||
  UltraSoundDevice(); | 
				
			|||
  ~UltraSoundDevice(); | 
				
			|||
 | 
				
			|||
  uint8_t readByte(uint32_t address, uint32_t bar); | 
				
			|||
  uint32_t readWord(uint32_t address, uint32_t bar); | 
				
			|||
 | 
				
			|||
  void writeByte(uint32_t address, uint32_t bar, uint8_t data); | 
				
			|||
  void writeWord(uint32_t address, uint32_t bar, uint32_t data); | 
				
			|||
}; | 
				
			|||
					Loading…
					
					
				
		Reference in new issue