Accessing Your Cluster from a CPU

Top  Previous  Next

The Diamond library includes functions to allow you to communicate with your cluster. These correspond directly to the functions in the server’s presentation-level interface, P. Note that the full Diamond library automatically does the equivalent of the host’s push operation when it detects you switching from writing (put…) to reading (get…).

 

Also note that you must ensure that no other threads attempt to access the presentation layer during a complete put…get sequence. This can be done by protecting the sequence with the par_sema.

 

#include <filer.h>

typedef int ps1_integer;

typedef unsigned int ps1_bits;

typedef double ps1_double;

 

These are the functions that you can use to communicate with your cluster:

 

_ps1_get_integer

ps1_integer _ps1_get_integer();

 

Read a single 32-bit integer from the input buffer.

_ps1_put_integer

void _ps1_put_integer(ps1_integer value);

 

Put a 32-bit integer to the output data buffer.

_ps1_get_bits

ps1_bits _ps1_get_bits();

 

Read a single 32-bit uninterpreted value from the input buffer. This is the same as _ps1_get_integer when the host and CPU integer formats are equivalent.

_ps1_put_bits

void _ps1_put_bits(ps1_bits value);

 

Put a 32-bit uninterpreted value to the output data buffer.This is the same as _ps1_put_integer when the host and CPU integer formats are equivalent.

_ps1_get_double

ps1_double _ps1_get_double(void);

 

Get a floating-point double value from the input data buffer.

_ps1_put_double

void _ps1_put_double(ps1_double value);

 

Send a floating-point double value to the output data buffer.

_ps1_get_record

size_t _ps1_get_record(void *buf);

 

Get a record from the input data buffer. A record is transmitted as an array of octet values, rounded up to a multiple of 4. The values are placed in the object pointed at by buf, and the function returns the number of octets received.

_ps1_put_record

void _ps1_put_record(size_t len, void *buf);

 

Send a record to the output data buffer. A record is transmitted as an array of octet values, rounded up to a multiple of 4. The first parameter gives the number of values and the second parameter locates the object containing them.

_get_bits

ps1_bits _get_bits(void);

 

Get an uninterpreted 32-bit value from the input data buffer.

_put_bits

void _put_bits(ps1_bits b);

 

Send an uninterpreted 32-bit value to the output data buffer. This is often equivalent to _put_int when the host and DSP integer formats are equivalent.

 

The following is an example of how the CPU would call service 1 in the example cluster (12).

 

int reply;

#define COMMAND ((12<<8) | 1)

char text[] = "This is a message";

sema_wait(&par_sema);

   _put_bits(COMMAND);                // the service word

   _put_record(sizeof(text)+1, text); // +1 for terminating 0

   reply = _ps1_get_integer();        // send and read reply

sema_signal(&par_sema);