Channels <chan.h>

Top  Previous  Next

The functions described here allow programs to access the basic communication facility of the Diamond model, which is to transfer a message across a channel.

 

The header chan.h defines the following:


type CHAN representing the channel data type;

a function to initialize a channel;

functions to send and receive messages over channels.

 

The chan.h functions must always include in their parameter list the address of a channel. This could be the address of a user-declared variable of type CHAN.

 

For example:

 

CHAN mychan;

int value;

chan_init(&mychan);

...

chan_out_word(value, &mychan);

 

Alternatively, it could be a port:

 

int main(int argc, char *argv[], char *envp[],

         CHAN * in_ports[], int ins,

         CHAN *out_ports[], int outs) {

   int value;

   ...

   chan_out_word(value, out_ports[0]);

   ...

}

 

Note that the channels passed in through the port vector arguments of main must not be initialized; all others, such as mychan above, must be initialized by calls to chan_init.

 

The functions provided in chan.h are listed below. Messages of any type and size can be transmitted by the two general-purpose functions chan_in_message and chan_out_message. The word functions are simply convenient shorthands for four-octet messages.

 

Note that most inter-processor links support only transfers that are multiples of 4 octets.

 


chan_init

initialize a local channel word; you must not initialize channels bound to ports.


chan_in_message

input a message from a channel


chan_in_word

input a 32-bit word from a channel


chan_out_message

output a message to a channel


chan_out_word

output a 32-bit word to a channel


chan_reset

reset some properties of a link attached to a channel