EBST_CAM
Loading...
Searching...
No Matches
Board_ll.c File Reference

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 LSCPCIEJ_STRESING_DRIVER_NAME   "lscpciej"
 
#define DIV   1024
 
#define WIDTH   7
 

Functions

es_status_codes CleanupDma (uint32_t drvno)
 
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 DLLCALLCONV interrupt_handler0 ()
 
void DLLCALLCONV interrupt_handler1 ()
 
void DLLCALLCONV interrupt_handler2 ()
 
void DLLCALLCONV interrupt_handler3 ()
 
void DLLCALLCONV interrupt_handler4 ()
 
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)
 
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 ()
 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.
 
void FreeMemInfo (uint64_t *pmemory_all, uint64_t *pmemory_free)
 Get the free and installed memory info.
 
es_status_codes StartCopyDataToUserBufferThread (uint32_t drvno)
 
es_status_codes InitMutex (uint32_t drvno)
 
void initPerformanceCounter ()
 
int64_t GetTimestampInTicks ()
 Reads system timer.
 
int64_t GetTimestampInMicroseconds ()
 
int64_t GetTimestampInMilliseconds ()
 
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 ()
 
uint16_t checkSpaceKeyState ()
 
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)
 
uint32_t getDmaBufferSizeInBytes (uint32_t drvno)
 
int64_t getCurrentInterruptCounter (uint32_t drvno)
 
es_status_codes SaveMeasurementDataToFileBIN (const char *filename)
 Export the measurement data to a binary file.
 
es_status_codes CopyFromFileToUserBufferBIN (const char *filename)
 
void openFile (uint32_t drvno)
 
void closeFile (uint32_t drvno)
 
void setTimestamp ()
 
void writeFileHeaderToFile (uint32_t drvno)
 Creates a file at filename_full and writes struct file_header to it.
 
void writeToDisc (uint32_t *drvno_ptr)
 
void startWriteToDiscThead (uint32_t drvno)
 
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 ()
 
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)
 
es_status_codes AboutMeasurementSettings ()
 
es_status_codes AboutCameraSettings (uint32_t drvno)
 
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)
 
void UnlockHighLevelMutex (uint32_t drvno)
 

Variables

WDC_DEVICE_HANDLE hDev_tmp [MAXPCIECARDS]
 
WDC_DEVICE_HANDLE * hDev = (WDC_DEVICE_HANDLE *)&hDev_tmp
 
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 }
 
WD_DMA * dmaBufferInfos [MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }
 
WDC_PCI_SCAN_RESULT scanResult
 
WD_PCI_CARD_INFO deviceInfo [MAXPCIECARDS]
 
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
 
void(* interrupt_handler_array [MAXPCIECARDS])() = { &interrupt_handler0, &interrupt_handler1, &interrupt_handler2, &interrupt_handler3, &interrupt_handler4 }
 

Detailed Description

All the low level platform specific implementations for interacting with the Stresing PCIe board.

Author
Florian Hahn
Date
23.10.2020

Macro Definition Documentation

◆ DIV

#define DIV   1024

◆ LSCPCIEJ_STRESING_DRIVER_NAME

#define LSCPCIEJ_STRESING_DRIVER_NAME   "lscpciej"

◆ WIDTH

#define WIDTH   7

Function Documentation

◆ _ExitDriver()

es_status_codes _ExitDriver ( )

Exit driver. Call this after Cleanup driver.

Returns
es_status_codes

◆ _InitBoard()

es_status_codes _InitBoard ( uint32_t drvno)

Initializes PCIe board on a platform specific way.

Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ _InitDriver()

es_status_codes _InitDriver ( )

Windows specific function for initializing driver.

Returns
es_status_codes

◆ About()

es_status_codes About ( uint32_t board_sel)

Display information about registers and settings in pop up windows.

Returns
es_status_codes

◆ AboutCameraSettings()

es_status_codes AboutCameraSettings ( uint32_t drvno)

◆ AboutDrv()

es_status_codes AboutDrv ( uint32_t drvno)

Shows window with infos about the PCIe board.

  • version of driver
  • ID = 53xx
  • length of space0 BAR =0x3f
  • vendor ID = EBST
  • PCI board version (same as label on PCI board)
    Parameters
    drvnoboard number (=1 if one PCI board)
    Returns
    es_status_codes

◆ AboutGPX()

es_status_codes AboutGPX ( uint32_t drvno)

Reads registers 0 to 12 of TDC-GPX chip. Time delay counter option.

Parameters
drvnoPCIe board identifier
Returns
es_status_codes

◆ AboutMeasurementSettings()

es_status_codes AboutMeasurementSettings ( )

◆ AboutPCI()

es_status_codes AboutPCI ( uint32_t drvno)
Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ AboutS0()

es_status_codes AboutS0 ( uint32_t drvno)

Read registers of space0. Space0 are the control registers of the PCIe board.

Parameters
drvnoPCIe board identifier
Returns
es_status_codes

◆ AboutTLPs()

es_status_codes AboutTLPs ( uint32_t drvno)
Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ checkDriverHandle()

es_status_codes checkDriverHandle ( uint32_t drvno)

Check drvno for being legit

Parameters
drvnodriver number
Returns
es_status_codes

◆ checkEscapeKeyState()

uint16_t checkEscapeKeyState ( )

◆ checkSpaceKeyState()

uint16_t checkSpaceKeyState ( )

◆ CleanupDma()

es_status_codes CleanupDma ( uint32_t drvno)
Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ CleanupDriver()

es_status_codes CleanupDriver ( uint32_t drvno)

Cleanup driver. Call this before Exit driver.

Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ closeFile()

void closeFile ( uint32_t drvno)

◆ ConvertTicksToMicroseconds()

int64_t ConvertTicksToMicroseconds ( int64_t ticks)

Translate ticks to microseconds.

Parameters
ticksticks of system timer
Returns
microseconds of ticks

◆ CopyFromFileToUserBufferBIN()

es_status_codes CopyFromFileToUserBufferBIN ( const char * filename)

◆ copyRestData()

void copyRestData ( uint32_t drvno,
size_t rest_in_bytes )

DMA copies in blocks of dmaBufferSizeInWords/DMA_BUFFER_PARTS - the rest is copied here.

Parameters
drvnoPCIe board identifier.
rest_in_bytesbytes which were not copied by INTR.

◆ Deinit2dViewer()

void Deinit2dViewer ( )

Call when closing 2d viewer or at least before opening a new 2d viewer.

◆ disableInterrupt()

es_status_codes disableInterrupt ( uint32_t drvno)

Disable interrupt.

Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ enableInterrupt()

es_status_codes enableInterrupt ( uint32_t drvno)

◆ ErrMsgBoxOff()

void ErrMsgBoxOff ( )

Disable error message boxes, if not needed.

◆ ErrMsgBoxOn()

void ErrMsgBoxOn ( )

Switch on error message boxes of our software. Default is On.

◆ ErrorMsg()

void ErrorMsg ( char ErrMsg[100])

Display error message. If ErrMsgBoxOn is set.

Parameters
[in]ErrMsgMessage. Buffer size: 100.

◆ FreeMemInfo()

void FreeMemInfo ( uint64_t * pmemory_all,
uint64_t * pmemory_free )

Get the free and installed memory info.

Parameters
[out]pmemory_allhow much is installed
[out]pmemory_freehow much is free

◆ getCurrentInterruptCounter()

int64_t getCurrentInterruptCounter ( uint32_t drvno)

◆ getDmaBufferSizeInBytes()

uint32_t getDmaBufferSizeInBytes ( uint32_t drvno)

◆ getFileHeaderFromFile()

void getFileHeaderFromFile ( struct file_header * fh,
const char * filename_full )

Open the file at filename_full and write the header to fh.

Parameters
fhstruct file_header*
filename_fullPath and file name to the file.

◆ GetGammaBlack()

uint16_t GetGammaBlack ( )

return gamma value black

◆ GetGammaWhite()

uint16_t GetGammaWhite ( )

return gamma value white

◆ getPhysicalDmaAddress()

uint64_t getPhysicalDmaAddress ( uint32_t drvno)

◆ GetTimestampInMicroseconds()

int64_t GetTimestampInMicroseconds ( )

◆ GetTimestampInMilliseconds()

int64_t GetTimestampInMilliseconds ( )

◆ GetTimestampInTicks()

int64_t GetTimestampInTicks ( )

Reads system timer.

Read 2x ticks and calculate the difference between the calls in microseconds with DLLTickstous, init timer by calling DLLInitSysTimer before use.

Returns
act ticks

◆ getVirtualDmaAddress()

uint16_t * getVirtualDmaAddress ( uint32_t drvno)

◆ InitMutex()

es_status_codes InitMutex ( uint32_t drvno)

◆ initPerformanceCounter()

void initPerformanceCounter ( )

◆ interrupt_handler0()

void DLLCALLCONV interrupt_handler0 ( )

◆ interrupt_handler1()

void DLLCALLCONV interrupt_handler1 ( )

◆ interrupt_handler2()

void DLLCALLCONV interrupt_handler2 ( )

◆ interrupt_handler3()

void DLLCALLCONV interrupt_handler3 ( )

◆ interrupt_handler4()

void DLLCALLCONV interrupt_handler4 ( )

◆ isr()

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.

Parameters
drvnoPCIe board identifier.

◆ LockHighLevelMutex()

void LockHighLevelMutex ( uint32_t drvno)

◆ openFile()

void openFile ( uint32_t drvno)

◆ readConfig_32()

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.

Parameters
drvnoboard number (=1 if one PCI board)
datapointer to where data is stored
addressoffset of register (count in bytes)
Returns
es_status_codes

◆ readRegister_16()

es_status_codes readRegister_16 ( uint32_t drvno,
uint16_t * data,
uint32_t address )

Reads long on DMA area.

Parameters
drvnoPCIe board identifier
databuffer for data
addressOffset from BaseAdress - in Bytes ! 0..3= Regs of Board.
Returns
es_status_codes

◆ readRegister_32()

es_status_codes readRegister_32 ( uint32_t drvno,
uint32_t * data,
uint32_t address )

Reads 4 bytes on DMA area.

Parameters
drvnoPCIe board identifier
databuffer for data
addressOffset from BaseAdress - in Bytes ! 0..3= Regs of Board.
Returns
es_status_codes

◆ readRegister_8()

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.

Parameters
drvnoboard number (=1 if one PCI board)
datapointer to where data is stored
addressoffset of register from base address (count in bytes)
Returns
es_status_codes

◆ ResetBufferWritePos()

void ResetBufferWritePos ( uint32_t drvno)

Reset the buffer write pointers and software ISR counter.

Parameters
drvnoPCIe board identifier.

◆ ResetPriority()

es_status_codes ResetPriority ( )

Reset thread priority to normal.

Returns
es_status_codes

◆ SaveMeasurementDataToFileBIN()

es_status_codes SaveMeasurementDataToFileBIN ( const char * filename)

Export the measurement data to a binary file.

Parameters
filenameFilename with complete absolute path.
Returns
es_status_codes

◆ SetGammaValue()

void SetGammaValue ( uint16_t white,
uint16_t black )

Set gamma value.

Parameters
[in]whiteset value for maximum brightness. Default: 0xFFFF (16 bit), 0x3FFF (14 bit)
[in]blackset value for minimum brightness. Default: 0

◆ SetPriority()

es_status_codes SetPriority ( )

Set thread to high priority level.

Returns
es_status_codes

◆ setTimestamp()

void setTimestamp ( )

◆ SetupDma()

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.

Parameters
drvnoPCIe board identifier.
Returns
es_status_codes

◆ ShowNewBitmap()

void ShowNewBitmap ( uint32_t drvno,
uint32_t block,
uint16_t camera,
uint16_t pixel,
uint32_t nos )

Update the displayed bitmap.

Parameters
[in]drvnoboard number
[in]blockcurrent number of blocks
[in]camerawhich camera to display (when camcnt is >1)
[in]pixelcount of pixel of one line
[in]nossamples in one block

◆ Start2dViewer()

void Start2dViewer ( uint32_t drvno,
uint32_t block,
uint16_t camera,
uint16_t pixel,
uint32_t nos )

Start 2d viewer.

Parameters
[in]drvnoboard number
[in]blockcurrent number of block
[in]camerawhich camera to display (when camcnt is >1)
[in]pixelcount of pixel of one line
[in]nossamples in one block

◆ StartCopyDataToUserBufferThread()

es_status_codes StartCopyDataToUserBufferThread ( uint32_t drvno)

◆ startWriteToDiscThead()

void startWriteToDiscThead ( uint32_t drvno)

◆ UnlockHighLevelMutex()

void UnlockHighLevelMutex ( uint32_t drvno)

◆ ValMsg()

void ValMsg ( uint64_t val)

Simple display of unsigned integer as error message for test purpose.

Parameters
valunsigned integer 64 bit

◆ VerifyData()

void VerifyData ( struct verify_data_parameter * vd)

Check a file for its data consistency.

Parameters
vdsee struct verify_data_parameter in globals.h for details

◆ WaitForAllInterruptsDone()

void WaitForAllInterruptsDone ( )

◆ WaitforTelapsed()

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.

Parameters
microsecondsTime to wait in microseconds.
Returns
1 when success, 0 when aborted by ESC or failure

◆ writeConfig_32()

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.

Parameters
drvnoboard number (=1 if one PCI board)
datalong value to write
addressoffset from base address of register (count in bytes)
Returns
es_status_codes

◆ writeFileHeaderToFile()

void writeFileHeaderToFile ( uint32_t drvno)

Creates a file at filename_full and writes struct file_header to it.

Parameters
drvnoPCIe board identifier.

◆ writeRegister_16()

es_status_codes writeRegister_16 ( uint32_t drvno,
uint16_t data,
uint32_t address )

Writes 16 bits (2 bytes) to register.

Parameters
drvnoPCIe board identifier.
datadata to write
addressRegister offset from BaseAdress - in bytes
Returns
es_status_codes

◆ writeRegister_32()

es_status_codes writeRegister_32 ( uint32_t drvno,
uint32_t data,
uint32_t address )

Writes 32 bits (4 bytes) to register.

Parameters
drvnoPCIe board identifier.
datadata to write
addressRegister offset from BaseAdress - in bytes
Returns
es_status_codes

◆ writeRegister_8()

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.

Parameters
drvnoboard number (=1 if one PCI board)
databyte value to write
addressOffset from BaseAdress of register (count in bytes)
Returns
es_status_codes

◆ writeToDisc()

void writeToDisc ( uint32_t * drvno_ptr)

Variable Documentation

◆ _SHOW_MSG

bool _SHOW_MSG = TRUE

◆ deviceInfo

WD_PCI_CARD_INFO deviceInfo[MAXPCIECARDS]

◆ Direct2dViewer

void* Direct2dViewer = NULL

◆ dmaBuffer

uint16_t* dmaBuffer[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ dmaBufferInfos

WD_DMA* dmaBufferInfos[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ dmaBufferPartReadPos

volatile UINT8 dmaBufferPartReadPos[MAXPCIECARDS] = { 0, 0, 0, 0, 0 }

◆ dmaBufferSizeInBytes

volatile DWORD dmaBufferSizeInBytes[MAXPCIECARDS] = { 0, 0, 0, 0, 0 }

◆ file_stream

FILE* file_stream[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ freq

LARGE_INTEGER freq

◆ ghMutex

HANDLE ghMutex[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ greyscale_data

uint16_t* greyscale_data = NULL

◆ hDev

WDC_DEVICE_HANDLE* hDev = (WDC_DEVICE_HANDLE *)&hDev_tmp

◆ hDev_tmp

WDC_DEVICE_HANDLE hDev_tmp[MAXPCIECARDS]

◆ interrupt_handler_array

◆ IsrCounter

volatile uint64_t IsrCounter[MAXPCIECARDS] = { 0, 0, 0, 0, 0 }

◆ mutexUserBuffer

HANDLE mutexUserBuffer[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ registerReadWriteMutex

HANDLE registerReadWriteMutex[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ registerReadWriteMutexHighLevel

HANDLE registerReadWriteMutexHighLevel[MAXPCIECARDS] = { NULL, NULL, NULL, NULL, NULL }

◆ scanResult

WDC_PCI_SCAN_RESULT scanResult