Simplify adc_bridge, also removing excess white space.

This commit is contained in:
Giles Atkinson 2024-10-07 09:54:03 +01:00 committed by Holger Vogt
parent 62f0b2d8cc
commit 37b6fda497
1 changed files with 77 additions and 240 deletions

View File

@ -8,28 +8,21 @@ Public Domain
Georgia Tech Research Corporation Georgia Tech Research Corporation
Atlanta, Georgia 30332 Atlanta, Georgia 30332
PROJECT A-8503-405 PROJECT A-8503-405
AUTHORS
AUTHORS
6 June 1991 Jeffrey P. Murray 6 June 1991 Jeffrey P. Murray
MODIFICATIONS
MODIFICATIONS
26 Sept 1991 Jeffrey P. Murray 26 Sept 1991 Jeffrey P. Murray
SUMMARY SUMMARY
This file contains the functional description of the adc_bridge This file contains the functional description of the adc_bridge code model.
code model.
INTERFACES
INTERFACES FILE ROUTINE CALLED
FILE ROUTINE CALLED
CM.c void *cm_analog_alloc() CM.c void *cm_analog_alloc()
void *cm_analog_get_ptr() void *cm_analog_get_ptr()
@ -37,67 +30,40 @@ INTERFACES
void *cm_event_get_ptr() void *cm_event_get_ptr()
int cm_event_queue() int cm_event_queue()
REFERENCED FILES REFERENCED FILES
Inputs from and outputs to ARGS structure. Inputs from and outputs to ARGS structure.
NON-STANDARD FEATURES NON-STANDARD FEATURES
NONE NONE
===============================================================================*/ ===============================================================================*/
/*=== INCLUDE FILES ====================*/ /*=== INCLUDE FILES ====================*/
/*=== CONSTANTS ========================*/ /*=== CONSTANTS ========================*/
/*=== MACROS ===========================*/ /*=== MACROS ===========================*/
/*=== LOCAL VARIABLES & TYPEDEFS =======*/ /*=== LOCAL VARIABLES & TYPEDEFS =======*/
/*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/
/*============================================================================== /*==============================================================================
FUNCTION cm_adc_bridge() FUNCTION cm_adc_bridge()
AUTHORS AUTHORS
6 June 1991 Jeffrey P. Murray 6 June 1991 Jeffrey P. Murray
MODIFICATIONS MODIFICATIONS
26 Sept 1991 Jeffrey P. Murray 26 Sept 1991 Jeffrey P. Murray
SUMMARY SUMMARY
This function implements the adc_bridge code model. This function implements the adc_bridge code model.
INTERFACES INTERFACES
FILE ROUTINE CALLED FILE ROUTINE CALLED
CM.c void *cm_analog_alloc() CM.c void *cm_analog_alloc()
void *cm_analog_get_ptr() void *cm_analog_get_ptr()
@ -107,15 +73,12 @@ INTERFACES
int cm_event_queue() int cm_event_queue()
RETURNED VALUE RETURNED VALUE
Returns inputs and outputs via ARGS structure. Returns inputs and outputs via ARGS structure.
GLOBAL VARIABLES GLOBAL VARIABLES
NONE NONE
NON-STANDARD FEATURES NON-STANDARD FEATURES
NONE NONE
==============================================================================*/ ==============================================================================*/
@ -131,231 +94,105 @@ NON-STANDARD FEATURES
* Last Modified 7/26/91 J.P.Murray * * Last Modified 7/26/91 J.P.Murray *
************************************************/ ************************************************/
static Digital_State_t get_out_value(double in, double low, double high)
void cm_adc_bridge(ARGS)
{ {
double in_low, /* analog output value corresponding to '0' if (in >= high)
return ONE;
else if (in <= low)
return ZERO;
return UNKNOWN;
}
void cm_adc_bridge(ARGS)
{
double in_low, /* analog output value corresponding to '0'
digital input */ digital input */
in_high, /* analog output value corresponding to '1' in_high; /* analog output value corresponding to '1'
digital input */ digital input */
current_time, /* the current time value */ int i, /* generic loop counter index */
*in, /* base address of array holding all digital output size; /* number of input & output ports */
values plus their previous values */
*in_old; /* base address of array holding previous
output values */
Digital_State_t *out, /* base address of array holding all output
int i, /* generic loop counter index */
size; /* number of input & output ports */
Digital_State_t *out, /* base address of array holding all input
values plus their previous values */ values plus their previous values */
*out_old, /* base address of array holding previous
input values */
test; /* temp holding variable for digital states */ test; /* temp holding variable for digital states */
/* determine "width" of the node bridge... */ /* determine "width" of the node bridge... */
size = PORT_SIZE(in); size = PORT_SIZE(in);
in_high = PARAM(in_high); in_high = PARAM(in_high);
in_low = PARAM(in_low); in_low = PARAM(in_low);
if (INIT) { /*** Test for INIT == TRUE. If so, allocate storage, etc. ***/ if (INIT) { /*** Test for INIT == TRUE. If so, allocate storage, etc. ***/
/* Allocate storage for inputs */
cm_analog_alloc(0, size * (int) sizeof(double));
/* Allocate storage for outputs */ /* Allocate storage for outputs */
cm_event_alloc(1, size * (int) sizeof(Digital_State_t));
/* Get analog addresses */ cm_event_alloc(0, size * (int) sizeof(Digital_State_t));
in = in_old = (double *) cm_analog_get_ptr(0,0);
/* Get discrete addresses */ /* Get discrete addresses */
out = out_old = (Digital_State_t *) cm_event_get_ptr(1,0);
out = (Digital_State_t *) cm_event_get_ptr(0,0);
/* Ensure output on first call. */
for (i = 0; i < size; i++)
out[i] = UNKNOWN + 1;
return;
} }
else { /*** This is not an initialization pass...retrieve storage /*** This is not an initialization pass...retrieve storage
addresses and calculate new outputs, if required. ***/ addresses and calculate new outputs, if required. ***/
out = (Digital_State_t *) cm_event_get_ptr(0, 0);
/** Retrieve previous values... **/ switch (CALL_TYPE) {
/* assign discrete addresses */
in = (double *) cm_analog_get_ptr(0,0);
in_old = (double *) cm_analog_get_ptr(0,1);
/* assign analog addresses */
out = (Digital_State_t *) cm_event_get_ptr(1,0);
out_old = (Digital_State_t *) cm_event_get_ptr(1,1);
}
/* read current input values */
for (i=0; i<size; i++) {
in[i] = INPUT(in[i]);
}
/*** If TIME == 0.0, bypass calculations ***/
if (0.0 != TIME) {
switch (CALL_TYPE) {
case ANALOG: /** analog call...check for breakpoint calls. **/ case ANALOG: /** analog call...check for breakpoint calls. **/
/* loop through all inputs... */ /* loop through all inputs... */
for (i=0; i<size; i++) {
for (i = 0; i < size; i++) {
if (in[i] <= in_low) { /* low output required */ test = get_out_value(INPUT(in[i]), in_low, in_high);
if (test != out[i]) {
test = ZERO; /* call for event breakpoint... */
if ( test != out_old[i] ) { cm_event_queue(TIME);
/* call for event breakpoint... */ break;
current_time = TIME;
cm_event_queue(current_time);
}
else {
/* no change since last time */
}
} }
else { }
if (in[i] >= in_high) { /* high output required */
test = ONE;
if ( test != out_old[i] ) {
/* call for event breakpoint... */
current_time = TIME;
cm_event_queue(current_time);
}
else {
/* no change since last time */
}
}
else { /* unknown output required */
if ( UNKNOWN != out_old[i] ) {
/* call for event breakpoint... */
current_time = TIME;
cm_event_queue(current_time);
}
else {
/* no change since last time */
}
}
}
}
break; break;
case EVENT: /** discrete call...lots to do **/ case EVENT: /** discrete call...lots to do **/
/* loop through all inputs... */ /* loop through all inputs... */
for (i=0; i<size; i++) {
for (i = 0; i < size; i++) {
if (in[i] <= in_low) { /* low output required */ test = get_out_value(INPUT(in[i]), in_low, in_high);
if (test != out[i]) {
out[i] = ZERO; /* Post changed value. */
if ( out[i] != out_old[i] ) { OUTPUT_STATE(out[i]) = test;
/* post changed value */ switch (test) {
OUTPUT_STATE(out[i]) = ZERO; case ZERO:
OUTPUT_DELAY(out[i]) = PARAM(fall_delay); OUTPUT_DELAY(out[i]) = PARAM(fall_delay);
} break;
else { case ONE:
/* no change since last time */ OUTPUT_DELAY(out[i]) = PARAM(rise_delay);
OUTPUT_CHANGED(out[i]) = FALSE; break;
default:
if (out[i] == ZERO)
OUTPUT_DELAY(out[i]) = PARAM(rise_delay);
else
OUTPUT_DELAY(out[i]) = PARAM(fall_delay);
break;
} }
out[i] = test;
/* Regardless, output the strength */
OUTPUT_STRENGTH(out[i]) = STRONG;
} else {
/* no change since last time */
OUTPUT_CHANGED(out[i]) = FALSE;
} }
else { }
if (in[i] >= in_high) { /* high output required */
out[i] = ONE;
if ( out[i] != out_old[i] ) {
/* post changed value */
OUTPUT_STATE(out[i]) = ONE;
OUTPUT_DELAY(out[i]) = PARAM(rise_delay);
}
else {
/* no change since last time */
OUTPUT_CHANGED(out[i]) = FALSE;
}
}
else { /* unknown output required */
out[i] = UNKNOWN;
if ( UNKNOWN != out_old[i] ) {
/* post changed value */
OUTPUT_STATE(out[i]) = UNKNOWN;
switch (out_old[i]) {
case ONE:
OUTPUT_DELAY(out[i]) = PARAM(fall_delay);
break;
case ZERO:
OUTPUT_DELAY(out[i]) = PARAM(rise_delay);
break;
case UNKNOWN: /* should never get here! */
break;
}
}
else {
/* no change since last time */
OUTPUT_CHANGED(out[i]) = FALSE;
}
}
}
/* regardless, output the strength */
OUTPUT_STRENGTH(out[i]) = STRONG;
}
break; break;
default: default:
break; break;
}
}
else { /*** TIME == 0.0 => set outputs to input value... ***/
/* loop through all inputs... */
for (i=0; i<size; i++) {
if (in[i] <= in_low) { /* low output required */
OUTPUT_STATE(out[i]) = out[i] = ZERO;
}
else
if (in[i] >= in_high) { /* high output required */
OUTPUT_STATE(out[i]) = out[i] = ONE;
}
else {
OUTPUT_STATE(out[i]) = out[i] = UNKNOWN;
}
OUTPUT_STRENGTH(out[i]) = STRONG;
}
} }
} }