Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/i2c/device/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ int main(void)
control_init();
control_register_resources(i_control, CONTROL_INTERFACES_NUM);

/* bug 17317 - [[combine]] */
par {
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
[[distribute]]
i2c_control_client(i_i2c, i_control);
#pragma warning enable
i2c_slave(i_i2c, p_scl, p_sda, i2c_device_addr);
}
}
Expand Down
8 changes: 3 additions & 5 deletions examples/spi/device/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ on tile[PORT_SPI_SLAVE_CS_TILE_NUM]: in port p_ss = PORT_SPI_SL
on tile[PORT_SPI_SLAVE_MISO_TILE_NUM]: out buffered port:32 p_miso = PORT_SPI_SLAVE_MISO;
on tile[PORT_SPI_SLAVE_MOSI_TILE_NUM]: in buffered port:32 p_mosi = PORT_SPI_SLAVE_MOSI;

void spi_ctrl(client interface control i_control[1])
void spi_ctrl(client interface control i_control[CONTROL_INTERFACES_NUM])
{
interface spi_slave_callback_if i_spi;
control_init();
control_register_resources(i_control, 1);
control_register_resources(i_control, CONTROL_INTERFACES_NUM);
par {
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
spi_control_client(i_spi, i_control);
#pragma warning enable
spi_slave(i_spi, p_sclk, p_mosi, p_miso, p_ss, cb,
SPI_MODE_3, SPI_TRANSFER_SIZE_8);
}
Expand All @@ -34,7 +32,7 @@ void spi_ctrl(client interface control i_control[1])

int main(void)
{
interface control i_control[1];
interface control i_control[CONTROL_INTERFACES_NUM];
par {
on tile[PORT_SPI_SLAVE_SCLK_TILE_NUM]: par {
spi_ctrl(i_control);
Expand Down
4 changes: 0 additions & 4 deletions examples/usb/device/src/endpoint0.xc
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,15 @@ void Endpoint0(chanend chan_ep0_out, chanend chan_ep0_in, client interface contr
break;

case USB_BMREQ_H2D_VENDOR_DEV:
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
result = USB_H2D_VendorRequest(ep0_out, ep0_in, &sp, i_control);
#pragma warning enable
break;

case USB_BMREQ_D2H_VENDOR_DEV:
if (sp.bRequest == XUD_REQUEST_GET_MSOS_DESCRIPTOR) {
result = XUD_GetMsosDescriptor(ep0_out, ep0_in, &sp);

} else {
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
result = USB_D2H_VendorRequest(ep0_out, ep0_in, &sp, i_control);
#pragma warning enable
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/usb/device/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABL
int main(void)
{
chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
interface control i_control[1];
interface control i_control[CONTROL_INTERFACES_NUM];
par {
on USB_TILE: par {
Endpoint0(c_ep_out[0], c_ep_in[0], i_control);
Expand Down
4 changes: 1 addition & 3 deletions examples/xscope/device/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
int main(void)
{
chan c_xscope;
interface control i_control[1];
interface control i_control[CONTROL_INTERFACES_NUM];

par {
xscope_host_data(c_xscope);
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
on tile[0]: xscope_control_client(c_xscope, i_control);
#pragma warning enable
on tile[0]: app(i_control[0]);
}
return 0;
Expand Down
6 changes: 2 additions & 4 deletions lib_device_control/adapters/transport_i2c.xc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
//
// To include this file in the build, define CONTROL_USE_I2C as 1, in control_conf.h

// [[distributable]]
void i2c_control_client(server i2c_slave_callback_if i_i2c, client interface control i_control[])
[[distributable]]
void i2c_control_client(server i2c_slave_callback_if i_i2c, client interface control i_control[CONTROL_INTERFACES_NUM])
{
while (1) {
select {
case i_i2c.ack_write_request(void) -> i2c_slave_ack_t resp:
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
if (control_process_i2c_write_start(i_control) == CONTROL_SUCCESS)
resp = I2C_SLAVE_ACK;
else
Expand All @@ -47,7 +46,6 @@ void i2c_control_client(server i2c_slave_callback_if i_i2c, client interface con
case i_i2c.stop_bit(void):
control_process_i2c_stop(i_control);
break;
#pragma warning enable

}
}
Expand Down
4 changes: 1 addition & 3 deletions lib_device_control/adapters/transport_spi.xc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
//
// To include this file in the build, define CONTROL_USE_SPI as 1, in control_conf.h

void spi_control_client(server spi_slave_callback_if i_spi, client interface control i_control[])
void spi_control_client(server spi_slave_callback_if i_spi, client interface control i_control[CONTROL_INTERFACES_NUM])
{
while (1) {
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
select {
case i_spi.master_ends_transaction():
control_process_spi_master_ends_transaction(i_control);
Expand All @@ -29,7 +28,6 @@ void spi_control_client(server spi_slave_callback_if i_spi, client interface con
control_process_spi_master_supplied_data(datum, valid_bits, i_control);
break;
}
#pragma warning enable
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib_device_control/adapters/transport_usb.xc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static XUD_Result_t USB_EP0_Receive(XUD_ep ep0_out, USB_SetupPacket_t *sp, uint8
}

// case USB_BMREQ_H2D_VENDOR_DEV:
XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, client interface control i_control[]) {
XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, client interface control i_control[CONTROL_INTERFACES_NUM]) {
XUD_Result_t result = XUD_RES_ERR;
if ((sp->bRequest == CONTROL_VENDOR_REQUEST) && (sp->wLength <= EP0_MAX_REQUEST_SIZE)) {
result = USB_EP0_Receive(ep0_out, sp, request_data);
Expand All @@ -53,7 +53,7 @@ XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacke
}

// case USB_BMREQ_D2H_VENDOR_DEV:
XUD_Result_t USB_D2H_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, client interface control i_control[]) {
XUD_Result_t USB_D2H_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, client interface control i_control[CONTROL_INTERFACES_NUM]) {
XUD_Result_t result = XUD_RES_ERR;
if ((sp->bRequest == CONTROL_VENDOR_REQUEST) && (sp->wLength <= EP0_MAX_REQUEST_SIZE)) {
control_ret_t ctrl = control_process_usb_get_request(sp->wIndex, sp->wValue, sp->wLength, request_data, i_control);
Expand Down
6 changes: 2 additions & 4 deletions lib_device_control/adapters/transport_xscope.xc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#define DEBUG_UNIT TRANSPORT
#include "debug_print.h"

void xscope_control_client(chanend c_xscope, client interface control i_control[])
void xscope_control_client(chanend c_xscope, client interface control i_control[CONTROL_INTERFACES_NUM])
{
uint8_t buffer[256]; /* 256 bytes from xscope.h */
int num_bytes_read;

control_init();
control_register_resources(i_control, 1);
control_register_resources(i_control, CONTROL_INTERFACES_NUM);

xscope_connect_data_from_host(c_xscope);

Expand All @@ -32,9 +32,7 @@ void xscope_control_client(chanend c_xscope, client interface control i_control[
select {
case xscope_data_from_host(c_xscope, buffer, num_bytes_read):
unsigned return_size;
#pragma warning disable unusual-code // Suppress slice interface warning (no array size passed)
control_process_xscope_upload(buffer, sizeof(buffer), num_bytes_read, return_size, i_control);
#pragma warning enable
if (return_size > 0) {
xscope_core_bytes(0, return_size, buffer);
}
Expand Down
22 changes: 11 additions & 11 deletions lib_device_control/api/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ control_register_resources(CLIENT_INTERFACE_ARRAY(control, i, n), unsigned n);
* \returns Whether the write start was successful or not
*/
control_ret_t
control_process_i2c_write_start(CLIENT_INTERFACE(control, i[]));
control_process_i2c_write_start(CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that an I2C slave read has started. Called from I2C callback API.
*
Expand All @@ -134,7 +134,7 @@ control_process_i2c_write_start(CLIENT_INTERFACE(control, i[]));
* \returns Whether the read start was successful or not
*/
control_ret_t
control_process_i2c_read_start(CLIENT_INTERFACE(control, i[]));
control_process_i2c_read_start(CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that an I2C slave write has occurred. Called from I2C callback API.
*
Expand All @@ -145,7 +145,7 @@ control_process_i2c_read_start(CLIENT_INTERFACE(control, i[]));
*/
control_ret_t
control_process_i2c_write_data(const uint8_t data,
CLIENT_INTERFACE(control, i[]));
CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that an I2C slave read has occurred. Called from I2C callback API.
*
Expand All @@ -156,7 +156,7 @@ control_process_i2c_write_data(const uint8_t data,
*/
control_ret_t
control_process_i2c_read_data(REFERENCE_PARAM(uint8_t, data),
CLIENT_INTERFACE(control, i[]));
CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that an I2C transaction has stopped. Called from I2C callback API.
*
Expand All @@ -165,7 +165,7 @@ control_process_i2c_read_data(REFERENCE_PARAM(uint8_t, data),
* \returns Whether the stop was successful or not
*/
control_ret_t
control_process_i2c_stop(CLIENT_INTERFACE(control, i[]));
control_process_i2c_stop(CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that a USB set (write) has occurred. Called from USB EP0 handler.
*
Expand All @@ -180,7 +180,7 @@ control_process_i2c_stop(CLIENT_INTERFACE(control, i[]));
control_ret_t
control_process_usb_set_request(uint16_t windex, uint16_t wvalue, uint16_t wlength,
const uint8_t request_data[],
CLIENT_INTERFACE(control, i[]));
CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that a USB get (read) has occurred. Called from USB EP0 handler.
*
Expand All @@ -195,7 +195,7 @@ control_process_usb_set_request(uint16_t windex, uint16_t wvalue, uint16_t wleng
control_ret_t
control_process_usb_get_request(uint16_t windex, uint16_t wvalue, uint16_t wlength,
uint8_t request_data[],
CLIENT_INTERFACE(control, i[]));
CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that an xscope transfer has occurred. Called from xscope handler.
* This function both reads and writes data in a single call.
Expand All @@ -213,7 +213,7 @@ control_process_usb_get_request(uint16_t windex, uint16_t wvalue, uint16_t wleng
control_ret_t
control_process_xscope_upload(uint8_t buf[], unsigned buf_size,
unsigned length_in, REFERENCE_PARAM(unsigned, length_out),
CLIENT_INTERFACE(control, i[]));
CLIENT_INTERFACE(control, i[CONTROL_INTERFACES_NUM]));

/** Inform the control library that the SPI master has ended the transaction. If the command
* was a write, this is the point that a write command is emitted on the i_ctl interface.
Expand All @@ -223,7 +223,7 @@ control_process_xscope_upload(uint8_t buf[], unsigned buf_size,
* \returns Whether the transfer was successful or not
*/
control_ret_t
control_process_spi_master_ends_transaction(CLIENT_INTERFACE(control, i_ctl[]));
control_process_spi_master_ends_transaction(CLIENT_INTERFACE(control, i_ctl[CONTROL_INTERFACES_NUM]));

/** Inform the control library that the SPI master requires data. If the command
* was a read, then this is the point that a read command is emitted on the i_ctl interface.
Expand All @@ -236,7 +236,7 @@ control_process_spi_master_ends_transaction(CLIENT_INTERFACE(control, i_ctl[]));
* \returns Whether the transfer was successful or not
*/
control_ret_t
control_process_spi_master_requires_data(REFERENCE_PARAM(uint32_t, data), CLIENT_INTERFACE(control, i_ctl[]));
control_process_spi_master_requires_data(REFERENCE_PARAM(uint32_t, data), CLIENT_INTERFACE(control, i_ctl[CONTROL_INTERFACES_NUM]));

/** Inform the control library that the SPI master supplied data.
* NOTE: It is assumed that the datum is 8 bits wide, i.e. spi_slave(...) is set up with
Expand All @@ -249,6 +249,6 @@ control_process_spi_master_requires_data(REFERENCE_PARAM(uint32_t, data), CLIENT
* \returns Whether the transfer was successful or not
*/
control_ret_t
control_process_spi_master_supplied_data(uint32_t datum, uint32_t valid_bits, CLIENT_INTERFACE(control, i_ctl[]));
control_process_spi_master_supplied_data(uint32_t datum, uint32_t valid_bits, CLIENT_INTERFACE(control, i_ctl[CONTROL_INTERFACES_NUM]));

#endif // CONTROL_H
3 changes: 3 additions & 0 deletions lib_device_control/inc/control_default_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#ifndef CONTROL_INTERFACES_NUM
#define CONTROL_INTERFACES_NUM 1
// TODO host apps fail with this warning
// #warning "CONTROL_INTERFACES_NUM not defined in control_conf.h, defaulting to 1."
// #warning "Please define CONTROL_INTERFACES_NUM in control_conf.h to silence this warning."
#endif

#if CONTROL_INTERFACES_NUM <= 0
Expand Down
3 changes: 2 additions & 1 deletion lib_device_control/inc/transport_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* \param i_control Control interface array
*
*/
void i2c_control_client(SERVER_INTERFACE(i2c_slave_callback_if, i_i2c), CLIENT_INTERFACE(control, i_control[]));
[[distributable]]
void i2c_control_client(SERVER_INTERFACE(i2c_slave_callback_if, i_i2c), CLIENT_INTERFACE(control, i_control[CONTROL_INTERFACES_NUM]));

#endif // TRANSPORT_I2C_H
2 changes: 1 addition & 1 deletion lib_device_control/inc/transport_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* \param i_control Control interface array
*
*/
void spi_control_client(SERVER_INTERFACE(spi_slave_callback_if, i_spi), CLIENT_INTERFACE(control, i_control[]));
void spi_control_client(SERVER_INTERFACE(spi_slave_callback_if, i_spi), CLIENT_INTERFACE(control, i_control[CONTROL_INTERFACES_NUM]));

#endif // TRANSPORT_SPI_H
4 changes: 2 additions & 2 deletions lib_device_control/inc/transport_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* \return XUD_Result_t Result of the operation
*/
XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, CLIENT_INTERFACE(control, i_control[]));
XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, CLIENT_INTERFACE(control, i_control[CONTROL_INTERFACES_NUM]));

/** USB transport host read (Get) processing function
* \param ep0_out Endpoint 0 OUT endpoint
Expand All @@ -27,6 +27,6 @@ XUD_Result_t USB_H2D_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacke
*
* \return XUD_Result_t Result of the operation
*/
XUD_Result_t USB_D2H_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, CLIENT_INTERFACE(control, i_control[]));
XUD_Result_t USB_D2H_VendorRequest(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t *sp, CLIENT_INTERFACE(control, i_control[CONTROL_INTERFACES_NUM]));

#endif // TRANSPORT_USB_H
2 changes: 1 addition & 1 deletion lib_device_control/inc/transport_xscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* \param i_control Control interface array
*
*/
void xscope_control_client(chanend c_xscope, CLIENT_INTERFACE(control, i_control[]));
void xscope_control_client(chanend c_xscope, CLIENT_INTERFACE(control, i_control[CONTROL_INTERFACES_NUM]));

#endif // TRANSPORT_XSCOPE_H
Loading