mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 03:40:04 +02:00
eiger: locking for local link access in shared memory
This commit is contained in:
parent
a7e24717a9
commit
092b3fa8b9
@ -151,7 +151,7 @@ void Beb_Beb(int id) {
|
||||
Beb_bit_mode = 4;
|
||||
|
||||
// ll_beb = &ll_beb_local;
|
||||
// Local_LocalLinkInterface1(ll_beb,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
|
||||
// Local_LocalLinkInterface(ll_beb,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
|
||||
|
||||
// Beb_SetByteOrder();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ void Feb_Interface_FebInterface() {
|
||||
malloc((Feb_Interface_recv_buffer_size + 1) * sizeof(unsigned int));
|
||||
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
|
||||
|
||||
Local_LocalLinkInterface1(
|
||||
Local_LocalLinkInterface(
|
||||
ll, XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
#include "LocalLinkInterface.h"
|
||||
#include "HardwareMMappingDefs.h"
|
||||
#include "clogger.h"
|
||||
#include "sharedMemory.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
|
||||
unsigned int ll_fifo_badr) {
|
||||
void Local_LocalLinkInterface(struct LocalLinkInterface *ll,
|
||||
unsigned int ll_fifo_badr) {
|
||||
sharedMemory_lockLocalLink();
|
||||
|
||||
LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
|
||||
ll->ll_fifo_base = 0;
|
||||
ll->ll_fifo_ctrl_reg = 0;
|
||||
@ -18,10 +21,8 @@ void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
|
||||
} else
|
||||
LOG(logERROR,
|
||||
("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
|
||||
}
|
||||
|
||||
void Local_LocalLinkInterface(struct LocalLinkInterface *ll) {
|
||||
LOG(logDEBUG1, ("Initializing new memory\n"));
|
||||
sharedMemory_unlockLocalLink();
|
||||
}
|
||||
|
||||
int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr) {
|
||||
@ -29,7 +30,7 @@ int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr) {
|
||||
void *plb_ll_fifo_ptr;
|
||||
|
||||
if ((fd = open("/dev/mem", O_RDWR)) < 0) {
|
||||
fprintf(stderr, "Could not open /dev/mem\n");
|
||||
LOG(logERROR, ("Could not open /dev/mem for local link\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -38,7 +39,7 @@ int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr) {
|
||||
close(fd);
|
||||
|
||||
if (plb_ll_fifo_ptr == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
LOG(logERROR, ("mmap error for local link\n")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -78,6 +79,8 @@ unsigned int Local_StatusVector(struct LocalLinkInterface *ll) {
|
||||
|
||||
int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
void *buffer) {
|
||||
sharedMemory_lockLocalLink();
|
||||
|
||||
// note: buffer must be word (4 byte) aligned
|
||||
// frame_len in byte
|
||||
int vacancy = 0;
|
||||
@ -87,8 +90,10 @@ int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
unsigned int fifo_ctrl;
|
||||
xfs_u32 status;
|
||||
|
||||
if (buffer_len < 1)
|
||||
if (buffer_len < 1) {
|
||||
sharedMemory_unlockLocalLink();
|
||||
return -1;
|
||||
}
|
||||
|
||||
last_word = (buffer_len - 1) / 4;
|
||||
word_ptr = (unsigned int *)buffer;
|
||||
@ -131,11 +136,16 @@ int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
word_ptr[words_send++]);
|
||||
}
|
||||
}
|
||||
|
||||
sharedMemory_unlockLocalLink();
|
||||
|
||||
return buffer_len;
|
||||
}
|
||||
|
||||
int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
void *buffer) {
|
||||
sharedMemory_lockLocalLink();
|
||||
|
||||
static unsigned int buffer_ptr = 0;
|
||||
// note: buffer must be word (4 byte) aligned
|
||||
// frame_len in byte
|
||||
@ -155,6 +165,7 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
if (status & PLB_LL_FIFO_STATUS_LL_SOF) {
|
||||
if (buffer_ptr) {
|
||||
buffer_ptr = 0;
|
||||
sharedMemory_unlockLocalLink();
|
||||
return -1; // buffer overflow
|
||||
}
|
||||
buffer_ptr = 0;
|
||||
@ -170,6 +181,7 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
word_ptr[buffer_ptr++] = fifo_val; // write to buffer
|
||||
} else {
|
||||
buffer_ptr = 0;
|
||||
sharedMemory_unlockLocalLink();
|
||||
return -2; // buffer overflow
|
||||
}
|
||||
|
||||
@ -179,12 +191,15 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
PLB_LL_FIFO_STATUS_LL_REM_SHIFT);
|
||||
LOG(logDEBUG1, ("Len: %d\n", len));
|
||||
buffer_ptr = 0;
|
||||
sharedMemory_unlockLocalLink();
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!(status & PLB_LL_FIFO_STATUS_EMPTY));
|
||||
|
||||
sharedMemory_unlockLocalLink();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr);
|
||||
int Local_Reset1(struct LocalLinkInterface *ll, unsigned int rst_mask);
|
||||
int Local_ctrl_reg_write_mask(struct LocalLinkInterface *ll, unsigned int mask,
|
||||
unsigned int val);
|
||||
void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
|
||||
unsigned int ll_fifo_badr);
|
||||
void Local_LocalLinkInterface(struct LocalLinkInterface *ll,
|
||||
unsigned int ll_fifo_badr);
|
||||
unsigned int Local_StatusVector(struct LocalLinkInterface *ll);
|
||||
int Local_Reset(struct LocalLinkInterface *ll);
|
||||
int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
@ -21,4 +21,3 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
void *buffer);
|
||||
int Local_Test(struct LocalLinkInterface *ll, unsigned int buffer_len,
|
||||
void *buffer);
|
||||
void Local_LocalLinkInterface(struct LocalLinkInterface *ll);
|
||||
|
@ -8,8 +8,8 @@ int sharedMemory_open(int port);
|
||||
int sharedMemory_attach();
|
||||
int sharedMemory_detach();
|
||||
int sharedMemory_remove();
|
||||
void sharedMemory_lock();
|
||||
void sharedMemory_unlock();
|
||||
void sharedMemory_lockStatus();
|
||||
void sharedMemory_unlockStatus();
|
||||
#ifdef VIRTUAL
|
||||
void sharedMemory_setStatus(enum runStatus s);
|
||||
enum runStatus sharedMemory_getStatus();
|
||||
@ -20,3 +20,7 @@ void sharedMemory_setScanStatus(enum runStatus s);
|
||||
enum runStatus sharedMemory_getScanStatus();
|
||||
void sharedMemory_setScanStop(int s);
|
||||
int sharedMemory_getScanStop();
|
||||
#ifdef EIGERD
|
||||
void sharedMemory_lockLocalLink();
|
||||
void sharedMemory_unlockLocalLink();
|
||||
#endif
|
@ -8,14 +8,21 @@
|
||||
#include <sys/shm.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SHM_NAME "sls_server_shared_memory"
|
||||
#define SHM_NAME "sls_server_shared_memory"
|
||||
#ifdef EIGERD
|
||||
#define SHM_VERSION 0x200915
|
||||
#else
|
||||
#define SHM_VERSION 0x200625
|
||||
#define SHM_KEY 5678
|
||||
#define MEM_SIZE 128
|
||||
#endif
|
||||
#define SHM_KEY 5678
|
||||
#define MEM_SIZE 128
|
||||
|
||||
typedef struct Memory {
|
||||
int version;
|
||||
pthread_mutex_t lock;
|
||||
pthread_mutex_t lockStatus;
|
||||
#ifdef EIGERD
|
||||
pthread_mutex_t lockLocalLink;
|
||||
#endif
|
||||
enum runStatus scanStatus; // idle, running or error
|
||||
int scanStop;
|
||||
#ifdef VIRTUAL
|
||||
@ -80,11 +87,18 @@ int sharedMemory_create(int port) {
|
||||
|
||||
int sharedMemory_initialize() {
|
||||
shm->version = SHM_VERSION;
|
||||
if (pthread_mutex_init(&(shm->lock), NULL) != 0) {
|
||||
LOG(logERROR,
|
||||
("Failed to initialize pthread lock for shared memory\n"));
|
||||
if (pthread_mutex_init(&(shm->lockStatus), NULL) != 0) {
|
||||
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockStatus for "
|
||||
"shared memory\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef EIGERD
|
||||
if (pthread_mutex_init(&(shm->lockLocalLink), NULL) != 0) {
|
||||
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockLocalLink for "
|
||||
"shared memory\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#endif
|
||||
shm->scanStatus = IDLE;
|
||||
shm->scanStop = 0;
|
||||
#ifdef VIRTUAL
|
||||
@ -141,64 +155,72 @@ int sharedMemory_remove() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void sharedMemory_lock() { pthread_mutex_lock(&(shm->lock)); }
|
||||
void sharedMemory_lockStatus() { pthread_mutex_lock(&(shm->lockStatus)); }
|
||||
|
||||
void sharedMemory_unlock() { pthread_mutex_unlock(&(shm->lock)); }
|
||||
void sharedMemory_unlockStatus() { pthread_mutex_unlock(&(shm->lockStatus)); }
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void sharedMemory_setStatus(enum runStatus s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->status = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
enum runStatus sharedMemory_getStatus() {
|
||||
enum runStatus s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->status;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
|
||||
void sharedMemory_setStop(int s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->stop = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
int sharedMemory_getStop() {
|
||||
int s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->stop;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sharedMemory_setScanStatus(enum runStatus s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->scanStatus = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
enum runStatus sharedMemory_getScanStatus() {
|
||||
enum runStatus s = IDLE;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->scanStatus;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
|
||||
void sharedMemory_setScanStop(int s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->scanStop = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
int sharedMemory_getScanStop() {
|
||||
int s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->scanStop;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef EIGERD
|
||||
void sharedMemory_lockLocalLink() { pthread_mutex_lock(&(shm->lockLocalLink)); }
|
||||
|
||||
void sharedMemory_unlockLocalLink() {
|
||||
pthread_mutex_unlock(&(shm->lockLocalLink));
|
||||
}
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user