From 8bd9398ef17fe538f77018cdc5c06eb9a96735f7 Mon Sep 17 00:00:00 2001 From: Erik von Reis <evonreis@caltech.edu> Date: Mon, 3 May 2021 16:17:23 -0700 Subject: [PATCH] awgtpman: compiles without warnings --- src/gds/awgtpman/awg.c | 2 +- src/gds/awgtpman/dtt/rmapi.h | 5 +++++ src/gds/awgtpman/shared_memory.c | 35 +++++++++++++++++++++++++++-- src/gds/awgtpman/shared_memory.h | 19 +++++++++++----- src/gds/awgtpman/testpoint.c | 6 ++--- src/gds/awgtpman/testpoint_server.c | 4 ++-- src/shmem/shmem_header.h | 10 ++++----- 7 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/gds/awgtpman/awg.c b/src/gds/awgtpman/awg.c index 941cc3b9b..a8c642a79 100644 --- a/src/gds/awgtpman/awg.c +++ b/src/gds/awgtpman/awg.c @@ -960,7 +960,7 @@ Organization of generating waveforms: /* now start transfer */ - memcpy(target_page->buf, p->page, p->pagelen * sizeof(float)); + memcpy_to_vol(target_page->buf, p->page, p->pagelen * sizeof(float)); target_page->status = 0; } diff --git a/src/gds/awgtpman/dtt/rmapi.h b/src/gds/awgtpman/dtt/rmapi.h index bad6f01a7..87d89c411 100644 --- a/src/gds/awgtpman/dtt/rmapi.h +++ b/src/gds/awgtpman/dtt/rmapi.h @@ -347,6 +347,11 @@ extern "C" { int rmWrite (short ID, char *pData, int offset, int size, int flag); + + /** + * Initialize Reflective memory + */ + void initReflectiveMemory(); /*@}*/ diff --git a/src/gds/awgtpman/shared_memory.c b/src/gds/awgtpman/shared_memory.c index 876fd7f1f..cf60a1a49 100644 --- a/src/gds/awgtpman/shared_memory.c +++ b/src/gds/awgtpman/shared_memory.c @@ -17,8 +17,39 @@ int OpenAwgDataSharedMemory(const char *model_name) char buff[256]; strncpy(buff, model_name, sizeof(buff)); buff[sizeof(buff)-1] = 0; - strncat(buff, SHMEM_AWG_SUFFIX, sizeof(buff)); + strncat(buff, SHMEM_AWG_SUFFIX, sizeof(buff)-1); + buff[sizeof(buff)-1] = 0; shmemAwgData = (volatile AWG_DATA *)shmem_open_segment(buff, SHMEM_AWG_SIZE); AWG_DATA_INIT(shmemAwgData); return (shmemAwgData!=NULL) ? -1 : 0; -} \ No newline at end of file +} + +volatile void * memcpy_to_vol(volatile void *dest, const void *src, size_t len) +{ + // source copied from gcc memcpy + volatile char *d = dest; + const char *s = src; + while (len--) + *d++ = *s++; + return dest; +} + +void * memcpy_from_vol(void *dest, const volatile void *src, size_t len) +{ + // source copied from gcc memcpy + char *d = dest; + volatile const char *s = src; + while (len--) + *d++ = *s++; + return dest; +} + +volatile void * memcpy_vol_to_vol(volatile void *dest, const volatile void *src, size_t len) +{ + // source copied from gcc memcpy + volatile char *d = dest; + volatile const char *s = src; + while (len--) + *d++ = *s++; + return dest; +} diff --git a/src/gds/awgtpman/shared_memory.h b/src/gds/awgtpman/shared_memory.h index 8fb2fe471..331561082 100644 --- a/src/gds/awgtpman/shared_memory.h +++ b/src/gds/awgtpman/shared_memory.h @@ -32,14 +32,23 @@ int OpenAwgDataSharedMemory(const char *model_name); volatile void * memcpy_to_vol(volatile void *dest, const void *src, size_t len); /** - * - * @param dest - * @param src - * @param len - * @return + * Copy to a regular pointer from a volatile pointer. + * Works the same as memcpy() + * @param dest Destination pointer. + * @param src Source pointer. Must be volatile. + * @param len Number of bytes to copy. + * @return destination pointer. */ void * memcpy_from_vol(void *dest, const volatile void *src, size_t len); +/** + * Copy to a volatile pointer from a volatile pointer. + * Works the same as memcpy() + * @param dest The destination pointer. Must be volatile. + * @param src The source pointer. Must be volatile. + * @param len Number of bytes to copy. + * @return The destination pointer. + */ volatile void * memcpy_vol_to_vol(volatile void *dest, const volatile void *src, size_t len); diff --git a/src/gds/awgtpman/testpoint.c b/src/gds/awgtpman/testpoint.c index a6c543b7d..2642c0103 100644 --- a/src/gds/awgtpman/testpoint.c +++ b/src/gds/awgtpman/testpoint.c @@ -242,7 +242,7 @@ static char *versionId = "Version $Id$" ; /* make test point list */ testpoints.TP_r_len = tplen; - testpoints.TP_r_val = (testpoint_t*) tp; + testpoints.TP_r_val = (ushort *) tp; /* make client handle */ clnt = tpMakeHandle (node); @@ -406,14 +406,14 @@ static char *versionId = "Version $Id$" ; /* make test point list */ if (tp == NULL) { testpoints.TP_r_len = 1; - testpoints.TP_r_val = &all; + testpoints.TP_r_val = (ushort *)&all; } else if (tplen == 0) { return 0; } else { testpoints.TP_r_len = tplen; - testpoints.TP_r_val = (testpoint_t*) tp; + testpoints.TP_r_val = (ushort *) tp; } /* make client handle */ diff --git a/src/gds/awgtpman/testpoint_server.c b/src/gds/awgtpman/testpoint_server.c index a64e3e0b6..12b7c0acf 100644 --- a/src/gds/awgtpman/testpoint_server.c +++ b/src/gds/awgtpman/testpoint_server.c @@ -756,7 +756,7 @@ static char *versionId = "Version $Id$" ; /* get index directly from test point client interface */ result->status = - tpGetIndexDirect (node, tpinterface, result->tp.TP_r_val, + tpGetIndexDirect (node, tpinterface, (testpoint_t *)result->tp.TP_r_val, result->tp.TP_r_len, time, epoch); if (result->status >= 0) { result->tp.TP_r_len = result->status; @@ -970,7 +970,7 @@ static char *versionId = "Version $Id$" ; while ((p != NULL) && (tp->TP_r_len < _MAX_TPNAMES)) { printf("tpName2Index checking %s\n", p); if ((gdsChannelInfo (p, &chn) == 0) && - (tpIsValid (&chn, &tp_node, tp->TP_r_val + tp->TP_r_len)) && + (tpIsValid (&chn, &tp_node, (testpoint_t *)tp->TP_r_val + tp->TP_r_len)) && (node == tp_node)) { printf ("%s is tp %i (node %i)\n", p, tp->TP_r_val[tp->TP_r_len], diff --git a/src/shmem/shmem_header.h b/src/shmem/shmem_header.h index 88f854e75..2d7282c90 100644 --- a/src/shmem/shmem_header.h +++ b/src/shmem/shmem_header.h @@ -19,7 +19,7 @@ typedef struct SHMEM_HEADER * Pass a pointer to the header, and a version number. * Sets version number and magic bytes. */ -#define SHMEM_SET_VERSION(HEADER_PTR, ID, VERSION) { SHMEM_HEADER *_h_p_ = HEADER_PTR; \ +#define SHMEM_SET_VERSION(HEADER_PTR, ID, VERSION) { volatile SHMEM_HEADER *_h_p_ = (volatile SHMEM_HEADER *)HEADER_PTR; \ _h_p_->magic_bytes = SHMEM_HEADER_MAGIC_BYTES; \ _h_p_->struct_id = ID; \ _h_p_->version = VERSION; } @@ -29,10 +29,10 @@ typedef struct SHMEM_HEADER * Returns 0 if the structure does not start with a properly intialized * SHMEM_HEADER */ -#define SHMEM_GET_VERSION(HDR_PTR) ( (((SHMEM_HEADER *)HDR_PTR)->magic_bytes == SHMEM_HEADER_MAGIC_BYTES) \ - ? ((SHMEM_HEADER *)HDR_PTR)->version : 0 ) +#define SHMEM_GET_VERSION(HDR_PTR) ( (((volatile SHMEM_HEADER *)HDR_PTR)->magic_bytes == SHMEM_HEADER_MAGIC_BYTES) \ + ? ((volatile SHMEM_HEADER *)HDR_PTR)->version : 0 ) -#define SHMEM_GET_ID(HDR_PTR) ( (((SHMEM_HEADER *)HDR_PTR)->magic_bytes == SHMEM_HEADER_MAGIC_BYTES) \ - ? ((SHMEM_HEADER *)HDR_PTR)->struct_id : 0 ) +#define SHMEM_GET_ID(HDR_PTR) ( (((volatile SHMEM_HEADER *)HDR_PTR)->magic_bytes == SHMEM_HEADER_MAGIC_BYTES) \ + ? ((volatile SHMEM_HEADER *)HDR_PTR)->struct_id : 0 ) #endif // DAQD_TRUNK_SHMEM_HEADER_H -- GitLab