Merge commit '10d472202dc2bf1fa5c569d2a14d460e95030564' into PSI-7.0

This is before PVA is modified
This commit is contained in:
2020-11-16 17:06:22 +01:00
22 changed files with 527 additions and 447 deletions
+2 -2
View File
@@ -438,7 +438,7 @@ int htoi(unsigned char *str)
{
int result;
(void) sscanf( (char *) str, "%x", &result );
(void) sscanf( (char *) str, "%x", (unsigned *) &result );
return ( result );
}
@@ -653,7 +653,7 @@ int otoi(Char *str)
{
int result;
(void) sscanf( (char *) str, "%o", &result );
(void) sscanf( (char *) str, "%o", (unsigned *) &result );
return ( result );
}
@@ -1,250 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author W. Eric Norum
* norume@aps.anl.gov
* 630 252 4793
*/
/*
* We want to access information which is
* normally hidden from application programs.
*/
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rtems.h>
#include <rtems/error.h>
#include "epicsMessageQueue.h"
#include "errlog.h"
LIBCOM_API epicsMessageQueueId epicsStdCall
epicsMessageQueueCreate(unsigned int capacity, unsigned int maximumMessageSize)
{
rtems_status_code sc;
epicsMessageQueueId id = calloc(1, sizeof(*id));
rtems_interrupt_level level;
static char c1 = 'a';
static char c2 = 'a';
static char c3 = 'a';
if(!id)
return NULL;
sc = rtems_message_queue_create (rtems_build_name ('Q', c3, c2, c1),
capacity,
maximumMessageSize,
RTEMS_FIFO|RTEMS_LOCAL,
&id->id);
if (sc != RTEMS_SUCCESSFUL) {
free(id);
errlogPrintf ("Can't create message queue: %s\n", rtems_status_text (sc));
return NULL;
}
id->maxSize = maximumMessageSize;
id->localBuf = NULL;
rtems_interrupt_disable (level);
if (c1 == 'z') {
if (c2 == 'z') {
if (c3 == 'z') {
c3 = 'a';
}
else {
c3++;
}
c2 = 'a';
}
else {
c2++;
}
c1 = 'a';
}
else {
c1++;
}
rtems_interrupt_enable (level);
return id;
}
static rtems_status_code rtems_message_queue_send_timeout(
rtems_id id,
void *buffer,
uint32_t size,
rtems_interval timeout)
{
Message_queue_Control *the_message_queue;
Objects_Locations location;
CORE_message_queue_Status msg_status;
the_message_queue = _Message_queue_Get( id, &location );
switch ( location )
{
case OBJECTS_ERROR:
return RTEMS_INVALID_ID;
case OBJECTS_LOCAL:
msg_status = _CORE_message_queue_Send(
&the_message_queue->message_queue,
buffer,
size,
id,
NULL,
1,
timeout
);
_Thread_Enable_dispatch();
/*
* If we had to block, then this is where the task returns
* after it wakes up. The returned status is correct for
* non-blocking operations but if we blocked, then we need
* to look at the status in our TCB.
*/
if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
msg_status = _Thread_Executing->Wait.return_code;
return _Message_queue_Translate_core_message_queue_return_code( msg_status );
}
return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
}
LIBCOM_API int epicsStdCall epicsMessageQueueSend(
epicsMessageQueueId id,
void *message,
unsigned int messageSize)
{
if (rtems_message_queue_send_timeout(id->id, message, messageSize, RTEMS_NO_TIMEOUT) == RTEMS_SUCCESSFUL)
return 0;
else
return -1;
}
LIBCOM_API int epicsStdCall epicsMessageQueueSendWithTimeout(
epicsMessageQueueId id,
void *message,
unsigned int messageSize,
double timeout)
{
rtems_interval delay;
extern double rtemsTicksPerSecond_double;
/*
* Convert time to ticks
*/
if (timeout <= 0.0)
return epicsMessageQueueTrySend(id, message, messageSize);
delay = (int)(timeout * rtemsTicksPerSecond_double);
if (delay == 0)
delay++;
if (rtems_message_queue_send_timeout(id->id, message, messageSize, delay) == RTEMS_SUCCESSFUL)
return 0;
else
return -1;
}
static int receiveMessage(
epicsMessageQueueId id,
void *buffer,
uint32_t size,
uint32_t wait,
rtems_interval delay)
{
size_t rsize;
rtems_status_code sc;
if (size < id->maxSize) {
if (id->localBuf == NULL) {
id->localBuf = malloc(id->maxSize);
if (id->localBuf == NULL)
return -1;
}
rsize = receiveMessage(id, id->localBuf, id->maxSize, wait, delay);
if (rsize > size)
return -1;
memcpy(buffer, id->localBuf, rsize);
}
else {
sc = rtems_message_queue_receive(id->id, buffer, &rsize, wait, delay);
if (sc != RTEMS_SUCCESSFUL)
return -1;
}
return rsize;
}
LIBCOM_API int epicsStdCall epicsMessageQueueTryReceive(
epicsMessageQueueId id,
void *message,
unsigned int size)
{
return receiveMessage(id, message, size, RTEMS_NO_WAIT, 0);
}
LIBCOM_API int epicsStdCall epicsMessageQueueReceive(
epicsMessageQueueId id,
void *message,
unsigned int size)
{
return receiveMessage(id, message, size, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
}
LIBCOM_API int epicsStdCall epicsMessageQueueReceiveWithTimeout(
epicsMessageQueueId id,
void *message,
unsigned int size,
double timeout)
{
rtems_interval delay;
uint32_t wait;
extern double rtemsTicksPerSecond_double;
/*
* Convert time to ticks
*/
if (timeout <= 0.0) {
wait = RTEMS_NO_WAIT;
delay = 0;
}
else {
wait = RTEMS_WAIT;
delay = (int)(timeout * rtemsTicksPerSecond_double);
if (delay == 0)
delay++;
}
return receiveMessage(id, message, size, wait, delay);
}
LIBCOM_API int epicsStdCall epicsMessageQueuePending(
epicsMessageQueueId id)
{
uint32_t count;
rtems_status_code sc;
sc = rtems_message_queue_get_number_pending(id->id, &count);
if (sc != RTEMS_SUCCESSFUL) {
errlogPrintf("Message queue %x get number pending failed: %s\n",
(unsigned int)id,
rtems_status_text(sc));
return -1;
}
return count;
}
LIBCOM_API void epicsStdCall epicsMessageQueueShow(
epicsMessageQueueId id,
int level)
{
int pending = epicsMessageQueuePending(id);
if (pending >= 0)
printf ("Message queue %lx -- Pending: %d\n", (unsigned long)id, pending);
}
@@ -1,29 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author W. Eric Norum
* norume@aps.anl.gov
* 630 252 4793
*/
/*
* Very thin shims around RTEMS routines
*/
#include <rtems.h>
struct epicsMessageQueueOSD {
rtems_id id;
unsigned int maxSize;
void *localBuf;
};
#define epicsMessageQueueDestroy(q) (rtems_message_queue_delete((q)->id))
#define epicsMessageQueueTrySend(q,m,l) (rtems_message_queue_send((q)->id, (m), (l)) == RTEMS_SUCCESSFUL ? 0 : -1)
@@ -211,7 +211,7 @@ LIBCOM_API void epicsStdCall osiSockDiscoverBroadcastAddresses
pNewNode->addr.sa = pIfreqList->ifr_broadaddr;
ifDepenDebugPrintf ( ( "found broadcast addr = %x\n", ntohl ( baddr.ia.sin_addr.s_addr ) ) );
} else {
ifDepenDebugPrintf ( ( "Ignoring broadcast addr = \n", ntohl ( baddr.ia.sin_addr.s_addr ) ) );
ifDepenDebugPrintf ( ( "Ignoring broadcast addr = %x\n", ntohl ( baddr.ia.sin_addr.s_addr ) ) );
free ( pNewNode );
continue;
}
@@ -71,6 +71,7 @@ LIBCOM_API int epicsThreadHookAdd(EPICS_THREAD_HOOK_ROUTINE hook)
return 0;
}
fprintf(stderr, "epicsThreadHookAdd: Locking problem\n");
free(pHook);
return -1;
}
@@ -473,8 +473,9 @@ LIBCOM_API void epicsThreadMap ( EPICS_THREAD_HOOK_ROUTINE func )
while (noTasks == 0) {
noTasks = taskIdListGet(taskIdList, taskIdListSize);
if (noTasks == taskIdListSize) {
taskIdList = realloc(taskIdList, (taskIdListSize+ID_LIST_CHUNK)*sizeof(int));
assert(taskIdList);
int *newlist = realloc(taskIdList, (taskIdListSize+ID_LIST_CHUNK)*sizeof(int));
assert(newlist);
taskIdList = newlist;
taskIdListSize += ID_LIST_CHUNK;
noTasks = 0;
}