Slave program – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual

Page 72

Advertising
background image

62

Parallel I/O Models

unsigned int i;
when (reset) {
outData.length = OUT_LEN; // assign output length
for(i=0; i<OUT_LEN; ++i) {
// fill output buffer with 1s
outData.buffer[i] = TEST_DATA;
}
io_out_request(parallelBus); // request to output buffer
}

when (io_out_ready(parallelBus)) {
// output buffer when slave is ready
io_out(parallelBus, &outData);
}

when (io_in_ready(parallelBus)) {
// declare the maximum input buffer acceptable
inData.length = MAX_IN;
io_in(parallelBus, &inData); // store input in buffer
}

Slave Program

/*
* This is the slave program. After reset, the output
* buffer is filled with data and then the slave reads from
* the master. The slave then writes to the master. The
* slave’s input buffer should contain [5,1,1,1,1,1]; the
* output buffer should contain
* [7,1,2,3,4,5,6,7,0,0,0,0,0,0].
*/

IO_0 parallel slave parallelBus;

// maximum length of input data expected
#define MAX_IN 5

// output length can be equal to or less than the max
#define OUT_LEN 7

// maximum array length
#define MAX_OUT 13

// output structure
struct parallel_out {
// actual length of data to be output
unsigned int length;
// array setup for max length of data to be output
unsigned int buffer[MAX_OUT];
} outData;

// input structure
struct parallel_in {
// actual length of buffer to be input
unsigned int length;
// maximum input array

Advertising