EBST_CAM
|
All the low level platform specific implementations for interacting with the Stresing PCIe board. More...
#include "../Board_ll.h"
#include <stdint.h>
#include "../Board.h"
#include <process.h>
#include <io.h>
#include "../../version.h"
#include "../Direct2dViewer_c.h"
Macros | |
#define | DIV 1024 |
#define | WIDTH 7 |
Functions | |
es_status_codes | CleanupDma (uint32_t drvno) |
Cleanup DMA buffer. | |
void | isr (uint32_t drvno) |
This interrupt routine copies data from the DMA buffer to the user buffer. If write to disk is true, the data is also written to disc. | |
void __stdcall | interrupt_handler0 (void) |
void __stdcall | interrupt_handler1 (void) |
void __stdcall | interrupt_handler2 (void) |
void __stdcall | interrupt_handler3 (void) |
void __stdcall | interrupt_handler4 (void) |
es_status_codes | readRegister_32 (uint32_t drvno, uint32_t *data, uint32_t address) |
Reads 4 bytes on DMA area. | |
es_status_codes | readRegister_16 (uint32_t drvno, uint16_t *data, uint32_t address) |
Reads long on DMA area. | |
es_status_codes | readRegister_8 (uint32_t drvno, uint8_t *data, uint32_t address) |
Read byte (8 bit) from register of PCIe board, except r10-r1f. | |
es_status_codes | writeRegister_32 (uint32_t drvno, uint32_t data, uint32_t address) |
Writes 32 bits (4 bytes) to register. | |
es_status_codes | writeRegister_16 (uint32_t drvno, uint16_t data, uint32_t address) |
Writes 16 bits (2 bytes) to register. | |
es_status_codes | writeRegister_8 (uint32_t drvno, uint8_t data, uint32_t address) |
Write byte (8 bit) to register in space0 of PCIe board, except r10-r1f. | |
es_status_codes | checkDriverHandle (uint32_t drvno) |
uint64_t | getPhysicalDmaAddress (uint32_t drvno) |
es_status_codes | SetupDma (uint32_t drvno) |
Allocate DMA buffer - should only be called once. | |
es_status_codes | enableInterrupt (uint32_t drvno) |
Enable interrupt. | |
es_status_codes | disableInterrupt (uint32_t drvno) |
Disable interrupt. | |
void | ResetBufferWritePos (uint32_t drvno) |
Reset the buffer write pointers and software ISR counter. | |
void | copyRestData (uint32_t drvno, size_t rest_in_bytes) |
DMA copies in blocks of dmaBufferSizeInWords/DMA_BUFFER_PARTS - the rest is copied here. | |
es_status_codes | _InitBoard (uint32_t drvno) |
Initializes PCIe board on a platform specific way. | |
es_status_codes | _InitDriver (uint8_t *_number_of_boards) |
Windows specific function for initializing driver. | |
es_status_codes | CleanupDriver (uint32_t drvno) |
Cleanup driver. Call this before Exit driver. | |
es_status_codes | _ExitDriver () |
Exit driver. Call this after Cleanup driver. | |
es_status_codes | readConfig_32 (uint32_t drvno, uint32_t *data, uint32_t address) |
Read long (32 bit) from runtime register of PCIe board. | |
es_status_codes | writeConfig_32 (uint32_t drvno, uint32_t data, uint32_t address) |
Write long (32 bit) to register in space0 of PCIe board. | |
es_status_codes | FreeMemInfo (uint64_t *pmemory_all, uint64_t *pmemory_free) |
Get the free and installed memory info. | |
es_status_codes | StartCopyDataToUserBufferThread (uint32_t drvno) |
Start thread which polls DMA buffer to user buffer when software polling is used. | |
es_status_codes | InitMutex (uint32_t drvno) |
Initialize mutexes for register read/write. | |
void | initPerformanceCounter () |
Initialize performance counter for high resolution timing. | |
int64_t | GetTimestampInTicks () |
Get the current timestamp in ticks. | |
int64_t | GetTimestampInMicroseconds () |
Get the current timestamp in microseconds. | |
int64_t | GetTimestampInMilliseconds () |
Get the current timestamp in milliseconds. | |
int64_t | ConvertTicksToMicroseconds (int64_t ticks) |
Translate ticks to microseconds. | |
uint8_t | WaitforTelapsed (int64_t microseconds) |
This functions returns after a time given in microseconds. The time is measured in CPU ticks. The function is escapable by pressing ESC. | |
uint16_t | checkEscapeKeyState () |
Check if escape key was pressed. | |
uint16_t | checkSpaceKeyState () |
Check if space key was pressed. | |
es_status_codes | SetPriority () |
Set thread to high priority level. | |
es_status_codes | ResetPriority () |
Reset thread priority to normal. | |
uint16_t * | getVirtualDmaAddress (uint32_t drvno) |
Get the virtual address of the DMA buffer. | |
uint32_t | getDmaBufferSizeInBytes (uint32_t drvno) |
Get the size of the DMA buffer in bytes. | |
int64_t | getCurrentInterruptCounter (uint32_t drvno) |
Get the current interrupt counter. | |
es_status_codes | SaveMeasurementDataToFileBIN (const char *filename) |
Export the measurement data to a binary file. | |
es_status_codes | CopyFromFileToUserBufferBIN (const char *filename) |
Import measurement data from binary file to user buffer. | |
void | openFile (uint32_t drvno) |
Open a file or create it for writing measurement data. | |
void | closeFile (uint32_t drvno) |
Close the file. | |
void | setTimestamp () |
Set the start timestamp that is used for file name and file header. | |
void | writeFileHeaderToFile (uint32_t drvno) |
Creates a file at filename_full and writes struct file_header to it. | |
void | writeToDisc (uint32_t *drvno_ptr) |
Thread function which writes data from user buffer to disc. | |
void | startWriteToDiscThead (uint32_t drvno) |
Start thread which writes data from user buffer to disc. | |
void | VerifyData (struct verify_data_parameter *vd) |
Check a file for its data consistency. | |
void | getFileHeaderFromFile (struct file_header *fh, const char *filename_full) |
Open the file at filename_full and write the header to fh. | |
void | WaitForAllInterruptsDone () |
Wait until all interrupts are done or timeout occurs. | |
es_status_codes | About (uint32_t board_sel) |
Display information about registers and settings in pop up windows. | |
es_status_codes | AboutDrv (uint32_t drvno) |
Shows window with infos about the PCIe board. | |
es_status_codes | AboutGPX (uint32_t drvno) |
Reads registers 0 to 12 of TDC-GPX chip. Time delay counter option. | |
es_status_codes | AboutS0 (uint32_t drvno) |
Read registers of space0. Space0 are the control registers of the PCIe board. | |
es_status_codes | AboutTLPs (uint32_t drvno) |
es_status_codes | AboutPCI (uint32_t drvno) |
Read registers of PCIe config space. | |
es_status_codes | AboutMeasurementSettings () |
Show measurement settings in a message box. | |
es_status_codes | AboutCameraSettings (uint32_t drvno) |
Show camera settings in a message box. | |
void | ErrMsgBoxOn () |
Switch on error message boxes of our software. Default is On. | |
void | ErrMsgBoxOff () |
Disable error message boxes, if not needed. | |
void | ErrorMsg (char ErrMsg[100]) |
Display error message. If ErrMsgBoxOn is set. | |
void | ValMsg (uint64_t val) |
Simple display of unsigned integer as error message for test purpose. | |
void | Start2dViewer (uint32_t drvno, uint32_t block, uint16_t camera, uint16_t pixel, uint32_t nos) |
Start 2d viewer. | |
void | ShowNewBitmap (uint32_t drvno, uint32_t block, uint16_t camera, uint16_t pixel, uint32_t nos) |
Update the displayed bitmap. | |
void | Deinit2dViewer () |
Call when closing 2d viewer or at least before opening a new 2d viewer. | |
void | SetGammaValue (uint16_t white, uint16_t black) |
Set gamma value. | |
uint16_t | GetGammaWhite () |
return gamma value white | |
uint16_t | GetGammaBlack () |
return gamma value black | |
void | LockHighLevelMutex (uint32_t drvno) |
Lock the mutex for register read/write. | |
void | UnlockHighLevelMutex (uint32_t drvno) |
Unlock the mutex for register read/write. | |
Variables | |
volatile DWORD | dmaBufferSizeInBytes [MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
uint16_t * | dmaBuffer [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
volatile uint64_t | IsrCounter [MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
volatile UINT8 | dmaBufferPartReadPos [MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
bool | _SHOW_MSG = TRUE |
HANDLE | ghMutex [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
HANDLE | registerReadWriteMutex [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
HANDLE | registerReadWriteMutexHighLevel [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
HANDLE | mutexUserBuffer [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
FILE * | file_stream [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
void * | Direct2dViewer = NULL |
uint16_t * | greyscale_data = NULL |
LARGE_INTEGER | freq |
LSCPCIEJ_INT_HANDLER_STUB | interrupt_handler_array [MAXPCIECARDS] = { &interrupt_handler0, &interrupt_handler1, &interrupt_handler2, &interrupt_handler3, &interrupt_handler4 } |
All the low level platform specific implementations for interacting with the Stresing PCIe board.
#define DIV 1024 |
#define WIDTH 7 |
es_status_codes _ExitDriver | ( | ) |
Exit driver. Call this after Cleanup driver.
es_status_codes _InitBoard | ( | uint32_t | drvno | ) |
Initializes PCIe board on a platform specific way.
[in] | drvno | PCIe board identifier. |
es_status_codes _InitDriver | ( | uint8_t * | _number_of_boards | ) |
Windows specific function for initializing driver.
[out] | _number_of_boards | Pointer to number of boards found. |
es_status_codes About | ( | uint32_t | board_sel | ) |
Display information about registers and settings in pop up windows.
es_status_codes AboutCameraSettings | ( | uint32_t | drvno | ) |
Show camera settings in a message box.
[in] | drvno | PCIe board identifier. |
es_status_codes AboutDrv | ( | uint32_t | drvno | ) |
Shows window with infos about the PCIe board.
drvno | board number (=1 if one PCI board) |
es_status_codes AboutGPX | ( | uint32_t | drvno | ) |
Reads registers 0 to 12 of TDC-GPX chip. Time delay counter option.
drvno | PCIe board identifier |
es_status_codes AboutMeasurementSettings | ( | ) |
Show measurement settings in a message box.
es_status_codes AboutPCI | ( | uint32_t | drvno | ) |
Read registers of PCIe config space.
[in] | drvno | PCIe board identifier. |
es_status_codes AboutS0 | ( | uint32_t | drvno | ) |
Read registers of space0. Space0 are the control registers of the PCIe board.
drvno | PCIe board identifier |
es_status_codes AboutTLPs | ( | uint32_t | drvno | ) |
[in] | drvno | PCIe board identifier. |
es_status_codes checkDriverHandle | ( | uint32_t | drvno | ) |
uint16_t checkEscapeKeyState | ( | ) |
Check if escape key was pressed.
uint16_t checkSpaceKeyState | ( | ) |
Check if space key was pressed.
es_status_codes CleanupDma | ( | uint32_t | drvno | ) |
es_status_codes CleanupDriver | ( | uint32_t | drvno | ) |
Cleanup driver. Call this before Exit driver.
[in] | drvno | PCIe board identifier. |
void closeFile | ( | uint32_t | drvno | ) |
Close the file.
[in] | drvno | PCIe board identifier. |
int64_t ConvertTicksToMicroseconds | ( | int64_t | ticks | ) |
Translate ticks to microseconds.
[in] | ticks | ticks of system timer |
es_status_codes CopyFromFileToUserBufferBIN | ( | const char * | filename | ) |
Import measurement data from binary file to user buffer.
[in] | filename | Filename with complete absolute path. |
void copyRestData | ( | uint32_t | drvno, |
size_t | rest_in_bytes ) |
DMA copies in blocks of dmaBufferSizeInWords/DMA_BUFFER_PARTS - the rest is copied here.
[in] | drvno | PCIe board identifier. |
rest_in_bytes | bytes which were not copied by INTR. |
void Deinit2dViewer | ( | ) |
Call when closing 2d viewer or at least before opening a new 2d viewer.
es_status_codes disableInterrupt | ( | uint32_t | drvno | ) |
es_status_codes enableInterrupt | ( | uint32_t | drvno | ) |
void ErrMsgBoxOff | ( | ) |
Disable error message boxes, if not needed.
void ErrMsgBoxOn | ( | ) |
Switch on error message boxes of our software. Default is On.
void ErrorMsg | ( | char | ErrMsg[100] | ) |
Display error message. If ErrMsgBoxOn is set.
[in] | ErrMsg | Message. Buffer size: 100. |
es_status_codes FreeMemInfo | ( | uint64_t * | pmemory_all, |
uint64_t * | pmemory_free ) |
Get the free and installed memory info.
[out] | pmemory_all | how much is installed |
[out] | pmemory_free | how much is free |
int64_t getCurrentInterruptCounter | ( | uint32_t | drvno | ) |
Get the current interrupt counter.
When measurement_cnt is greater than 1, that means measurement is running in a loop, return number of interrupts, because the last interrupt was the maximum number of interrupts, when the IsrCounter is 0.
[in] | drvno | PCIe board identifier. |
uint32_t getDmaBufferSizeInBytes | ( | uint32_t | drvno | ) |
Get the size of the DMA buffer in bytes.
[in] | drvno | PCIe board identifier. |
void getFileHeaderFromFile | ( | struct file_header * | fh, |
const char * | filename_full ) |
Open the file at filename_full and write the header to fh.
fh | struct file_header* |
filename_full | Path and file name to the file. |
uint16_t GetGammaBlack | ( | ) |
return gamma value black
uint16_t GetGammaWhite | ( | ) |
return gamma value white
uint64_t getPhysicalDmaAddress | ( | uint32_t | drvno | ) |
int64_t GetTimestampInMicroseconds | ( | ) |
Get the current timestamp in microseconds.
int64_t GetTimestampInMilliseconds | ( | ) |
Get the current timestamp in milliseconds.
int64_t GetTimestampInTicks | ( | ) |
Get the current timestamp in ticks.
uint16_t * getVirtualDmaAddress | ( | uint32_t | drvno | ) |
Get the virtual address of the DMA buffer.
[in] | drvno | PCIe board identifier. |
es_status_codes InitMutex | ( | uint32_t | drvno | ) |
Initialize mutexes for register read/write.
[in] | drvno | PCIe board identifier. |
void initPerformanceCounter | ( | ) |
Initialize performance counter for high resolution timing.
This function must be called once before using GetTimestampInTicks.
void __stdcall interrupt_handler0 | ( | void | ) |
void __stdcall interrupt_handler1 | ( | void | ) |
void __stdcall interrupt_handler2 | ( | void | ) |
void __stdcall interrupt_handler3 | ( | void | ) |
void __stdcall interrupt_handler4 | ( | void | ) |
void isr | ( | uint32_t | drvno | ) |
This interrupt routine copies data from the DMA buffer to the user buffer. If write to disk is true, the data is also written to disc.
This routine is called every DMASPERINTR=500 scans. The size of a drivers contiguous memory is limited, so we must copy the data from a small buffer to a bigger buffer. The copy process is split in lower/upper half blocks.
[in] | drvno | PCIe board identifier. |
void LockHighLevelMutex | ( | uint32_t | drvno | ) |
Lock the mutex for register read/write.
[in] | drvno | PCIe board identifier. |
void openFile | ( | uint32_t | drvno | ) |
Open a file or create it for writing measurement data.
[in] | drvno | PCIe board identifier. |
es_status_codes readConfig_32 | ( | uint32_t | drvno, |
uint32_t * | data, | ||
uint32_t | address ) |
Read long (32 bit) from runtime register of PCIe board.
This function reads the memory mapped data , not the I/O Data. Reads data from PCIe config space.
[in] | drvno | board number (=1 if one PCI board) |
[out] | data | pointer to where data is stored |
[in] | address | offset of register (count in bytes) |
es_status_codes readRegister_16 | ( | uint32_t | drvno, |
uint16_t * | data, | ||
uint32_t | address ) |
Reads long on DMA area.
[in] | drvno | PCIe board identifier |
[out] | data | buffer for data |
[in] | address | Offset from BaseAdress - in Bytes ! 0..3= Regs of Board. |
es_status_codes readRegister_32 | ( | uint32_t | drvno, |
uint32_t * | data, | ||
uint32_t | address ) |
Reads 4 bytes on DMA area.
[in] | drvno | PCIe board identifier |
[out] | data | buffer for data |
[in] | address | Offset from BaseAdress - in Bytes ! 0..3= Regs of Board. |
es_status_codes readRegister_8 | ( | uint32_t | drvno, |
uint8_t * | data, | ||
uint32_t | address ) |
Read byte (8 bit) from register of PCIe board, except r10-r1f.
[in] | drvno | board number (=0 if one PCI board) |
[out] | data | pointer to where data is stored |
[in] | address | offset of register from base address (count in bytes) |
void ResetBufferWritePos | ( | uint32_t | drvno | ) |
Reset the buffer write pointers and software ISR counter.
[in] | drvno | PCIe board identifier. |
es_status_codes ResetPriority | ( | ) |
Reset thread priority to normal.
es_status_codes SaveMeasurementDataToFileBIN | ( | const char * | filename | ) |
Export the measurement data to a binary file.
[in] | filename | Filename with complete absolute path. |
void SetGammaValue | ( | uint16_t | white, |
uint16_t | black ) |
Set gamma value.
[in] | white | set value for maximum brightness. Default: 0xFFFF (16 bit), 0x3FFF (14 bit) |
[in] | black | set value for minimum brightness. Default: 0 |
es_status_codes SetPriority | ( | ) |
Set thread to high priority level.
void setTimestamp | ( | ) |
Set the start timestamp that is used for file name and file header.
es_status_codes SetupDma | ( | uint32_t | drvno | ) |
Allocate DMA buffer - should only be called once.
Gets address of DMASubBuf from driver and copy it later to our pDMABigBuf.
[in] | drvno | PCIe board identifier. |
void ShowNewBitmap | ( | uint32_t | drvno, |
uint32_t | block, | ||
uint16_t | camera, | ||
uint16_t | pixel, | ||
uint32_t | nos ) |
Update the displayed bitmap.
[in] | drvno | board number |
[in] | block | current number of blocks |
[in] | camera | which camera to display (when camcnt is >1) |
[in] | pixel | count of pixel of one line |
[in] | nos | samples in one block |
void Start2dViewer | ( | uint32_t | drvno, |
uint32_t | block, | ||
uint16_t | camera, | ||
uint16_t | pixel, | ||
uint32_t | nos ) |
Start 2d viewer.
[in] | drvno | board number |
[in] | block | current number of block |
[in] | camera | which camera to display (when camcnt is >1) |
[in] | pixel | count of pixel of one line |
[in] | nos | samples in one block |
es_status_codes StartCopyDataToUserBufferThread | ( | uint32_t | drvno | ) |
Start thread which polls DMA buffer to user buffer when software polling is used.
[in] | drvno | PCIe board identifier. |
void startWriteToDiscThead | ( | uint32_t | drvno | ) |
Start thread which writes data from user buffer to disc.
[in] | drvno | PCIe board identifier. |
void UnlockHighLevelMutex | ( | uint32_t | drvno | ) |
Unlock the mutex for register read/write.
[in] | drvno | PCIe board identifier. |
void ValMsg | ( | uint64_t | val | ) |
Simple display of unsigned integer as error message for test purpose.
[in] | val | unsigned integer 64 bit |
void VerifyData | ( | struct verify_data_parameter * | vd | ) |
Check a file for its data consistency.
vd | see struct verify_data_parameter in globals.h for details |
void WaitForAllInterruptsDone | ( | ) |
Wait until all interrupts are done or timeout occurs.
uint8_t WaitforTelapsed | ( | int64_t | microseconds | ) |
This functions returns after a time given in microseconds. The time is measured in CPU ticks. The function is escapable by pressing ESC.
[in] | microseconds | Time to wait in microseconds. |
es_status_codes writeConfig_32 | ( | uint32_t | drvno, |
uint32_t | data, | ||
uint32_t | address ) |
Write long (32 bit) to register in space0 of PCIe board.
[in] | drvno | board number (=1 if one PCI board) |
[in] | data | long value to write |
[in] | address | offset from base address of register (count in bytes) |
void writeFileHeaderToFile | ( | uint32_t | drvno | ) |
Creates a file at filename_full and writes struct file_header to it.
[in] | drvno | PCIe board identifier. |
es_status_codes writeRegister_16 | ( | uint32_t | drvno, |
uint16_t | data, | ||
uint32_t | address ) |
Writes 16 bits (2 bytes) to register.
[in] | drvno | PCIe board identifier. |
[in] | data | data to write |
[in] | address | Register offset from BaseAdress - in bytes |
es_status_codes writeRegister_32 | ( | uint32_t | drvno, |
uint32_t | data, | ||
uint32_t | address ) |
Writes 32 bits (4 bytes) to register.
[in] | drvno | PCIe board identifier. |
[in] | data | data to write |
[in] | address | Register offset from BaseAdress - in bytes |
es_status_codes writeRegister_8 | ( | uint32_t | drvno, |
uint8_t | data, | ||
uint32_t | address ) |
Write byte (8 bit) to register in space0 of PCIe board, except r10-r1f.
[in] | drvno | board number (=1 if one PCI board) |
[in] | data | byte value to write |
[in] | address | Offset from BaseAdress of register (count in bytes) |
void writeToDisc | ( | uint32_t * | drvno_ptr | ) |
Thread function which writes data from user buffer to disc.
[in] | drvno_ptr | Pointer to PCIe board identifier. |
bool _SHOW_MSG = TRUE |
void* Direct2dViewer = NULL |
uint16_t* dmaBuffer[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
volatile UINT8 dmaBufferPartReadPos[MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
volatile DWORD dmaBufferSizeInBytes[MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
FILE* file_stream[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
LARGE_INTEGER freq |
HANDLE ghMutex[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
uint16_t* greyscale_data = NULL |
LSCPCIEJ_INT_HANDLER_STUB interrupt_handler_array[MAXPCIECARDS] = { &interrupt_handler0, &interrupt_handler1, &interrupt_handler2, &interrupt_handler3, &interrupt_handler4 } |
volatile uint64_t IsrCounter[MAXPCIECARDS] = { 0, 0, 0, 0, 0 } |
HANDLE mutexUserBuffer[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
HANDLE registerReadWriteMutex[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |
HANDLE registerReadWriteMutexHighLevel[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL } |