I would like to know how you go about adding to the SPI interface (NOT THE PERIPHERAL but the .XC extenstion interface) with in the AVB-DC application. The interface is defined and I have tried to follow the example from the programming manual and can't seem to get it right.
I would like to enable another task to communicate with the SPI task already defined in the AVB-DC application.
Any one have successe with this?
interface spi_interface { /** This function issues a single command without parameters to the SPI, * and reads up to 4 bytes status value from the device. * * \param cmd command value - listed above * * \param returnBytes The number of bytes that are to be read from the * device after the command is issued. 0 means no bytes * will be read. * * \returns the read bytes, or zero if no bytes were requested. If multiple * bytes are requested, then the last byte read is in the least-significant * byte of the return value. */ int command_status(int cmd, unsigned returnBytes); /** This function issues a single command with a 3-byte address parameter * and an optional data-set to be output to or input form the device. * * \param cmd command value - listed above * * \param address the address to send to the SPI device. Only the least * significant 24 bits are used. * * \param data an array of data that contains either data to be written to * the device, or which is used to store that that is * read from the device. * * \param returnBytes If positive, then this is the number of bytes that * are to be read from the device, into ``data``. If * negative, then this is (minus) the number of bytes to * be written to the device from ``data``. 0 means no * bytes will be read or written. * */ void command_address_status(int cmd, unsigned int address, unsigned char data[], int returnBytes); }; /** Task that implements a SPI interface to serial flash, typically the boot flash. * * Can be combined or distributed into other tasks. * * \param i_spi server interface of type ``spi_interface`` * \param spi_ports reference to a ``fl_spi_ports`` structure containing the SPI flash ports and clockblock */ [[distributable]] void spi_task(server interface spi_interface i_spi, fl_spi_ports &spi_ports); #endif #endif
Add second interface to AVB-DC SPI interface
-
- Member
- Posts: 10
- Joined: Fri Nov 07, 2014 1:30 pm
-
Verified
- XCore Legend
- Posts: 1164
- Joined: Thu May 27, 2010 10:08 am
XC has a neat mechanism for this: Arrays of interfaces.
The server is passed an array of interfaces and each elemnt of the array goes to a different client. The server selects (listens) on all at once and will take whatever comes in in order. So you get a one to many mapping.
Eg. for a multi channel servo sever the prototytpe would be:
void servo_task(server interface servo_if i_servo[n_clients], const unsigned n_clients, ..other stuff
..
In the select case of the server: (the "unsigned i" bit is key - effectively replicates this case across the whole array)
case i_servo[unsigned i].set_pos(unsigned channel, int position):
printf("Command from client %d\n", i);
and in the app:
interface servo_if i_servo[NUM_CLIENTS];
par {
on tile[0] : send_to_servo(i_servo[0]);
..
on tile[0] : send_to_servo(i_servo[NUM_CLIENTS-1]);
on tile[0] : servo_task(i_servo, NUM_CLIENTS, ...);
The server is passed an array of interfaces and each elemnt of the array goes to a different client. The server selects (listens) on all at once and will take whatever comes in in order. So you get a one to many mapping.
Eg. for a multi channel servo sever the prototytpe would be:
void servo_task(server interface servo_if i_servo[n_clients], const unsigned n_clients, ..other stuff
..
In the select case of the server: (the "unsigned i" bit is key - effectively replicates this case across the whole array)
case i_servo[unsigned i].set_pos(unsigned channel, int position):
printf("Command from client %d\n", i);
and in the app:
interface servo_if i_servo[NUM_CLIENTS];
par {
on tile[0] : send_to_servo(i_servo[0]);
..
on tile[0] : send_to_servo(i_servo[NUM_CLIENTS-1]);
on tile[0] : servo_task(i_servo, NUM_CLIENTS, ...);
Engineer at XMOS