19 void init_transmission_buffers_slave(
config_test_case_t *config, T *p_tx_pattern, T *p_rx1_pattern, T *p_rx2_pattern,
20 T *p_tx_buff, T *p_rx_buff, T *p_fill_symbol)
22 uint8_t rx_pattern[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE };
23 uint8_t tx_pattern[] = { 0x11, 0x22, 0x33, 0x44, 0x55 };
26 init_buffer_with_pattern(p_tx_pattern, sym_count,
sizeof(T), tx_pattern,
sizeof(tx_pattern));
27 init_buffer_with_pattern(p_rx1_pattern, sym_count,
sizeof(T), rx_pattern,
sizeof(rx_pattern));
28 init_buffer_with_pattern(p_rx2_pattern, sym_count,
sizeof(T), tx_pattern,
sizeof(tx_pattern));
30 set_buffer(p_fill_symbol,
sizeof(T), 0xF5);
33 if (config->master_tx_cnt > config->master_rx_cnt) {
34 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0x00);
35 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0x00);
38 if (config->master_tx_cnt < config->master_rx_cnt) {
39 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xF5);
40 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xF5);
44 if (config->slave_tx_cnt > config->slave_rx_cnt) {
45 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0x00);
46 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0x00);
49 if (config->slave_tx_cnt < config->slave_rx_cnt) {
50 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xF5);
51 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xF5);
55 if (!config->master_tx_defined) {
56 set_buffer(&p_rx1_pattern[0],
sizeof(T), 0xF5);
57 set_buffer(&p_rx1_pattern[1],
sizeof(T), 0xF5);
58 set_buffer(&p_rx1_pattern[2],
sizeof(T), 0xF5);
59 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xF5);
60 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xF5);
62 set_buffer(&p_rx2_pattern[0],
sizeof(T), 0xF5);
63 set_buffer(&p_rx2_pattern[1],
sizeof(T), 0xF5);
64 set_buffer(&p_rx2_pattern[2],
sizeof(T), 0xF5);
65 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xF5);
66 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xF5);
70 if (!config->master_rx_defined) {
71 set_buffer(&p_rx2_pattern[0],
sizeof(T), 0xAA);
72 set_buffer(&p_rx2_pattern[1],
sizeof(T), 0xBB);
73 set_buffer(&p_rx2_pattern[2],
sizeof(T), 0xCC);
74 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xDD);
75 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xEE);
79 if (!config->slave_tx_defined) {
80 set_buffer(&p_rx2_pattern[0],
sizeof(T), 0xF5);
81 set_buffer(&p_rx2_pattern[1],
sizeof(T), 0xF5);
82 set_buffer(&p_rx2_pattern[2],
sizeof(T), 0xF5);
83 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xF5);
84 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xF5);
88 if (!config->slave_rx_defined) {
89 set_buffer(&p_rx1_pattern[0],
sizeof(T), 0xAA);
90 set_buffer(&p_rx1_pattern[1],
sizeof(T), 0xBB);
91 set_buffer(&p_rx1_pattern[2],
sizeof(T), 0xCC);
92 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xDD);
93 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xEE);
97 T sym_mask = ((1 << config->symbol_size) - 1);
99 for (uint32_t i = 0; i < sym_count; i++) {
100 p_tx_pattern[i] = (p_tx_pattern[i] & sym_mask);
101 p_rx1_pattern[i] = (p_rx1_pattern[i] & sym_mask);
102 p_rx2_pattern[i] = (p_rx2_pattern[i] & sym_mask);
105 memcpy(p_tx_buff, p_tx_pattern,
sizeof(T) * sym_count);
106 set_buffer(p_rx_buff,
sizeof(T) * sym_count, 0x00);
117 SLAVE_SPI_SS,
true, &capabilities);
119 PinName miso = SLAVE_SPI_MISO;
120 PinName mosi = SLAVE_SPI_MOSI;
123 if (config->duplex == HALF_DUPLEX) {
124 if (SLAVE_SPI_HF_DATA == SLAVE_SPI_MOSI) {
126 }
else if (SLAVE_SPI_HF_DATA == SLAVE_SPI_MISO) {
129 printf(
"ERROR: Slave init in half duplex mode. \r\n ");
133 spi_init(obj,
true, mosi, miso, SLAVE_SPI_CLK, SLAVE_SPI_SS);
135 spi_format(obj, config->symbol_size, config->mode, config->bit_ordering);
143 Timeout transm_thread_timeout;
144 Thread transm_thread(osPriorityNormal);
150 transm_thread_timeout.attach_us(transm_timeout_handler,
151 5 * US_PER_S + 2 * MASTER_TRANSMISSION_DELAY_MS * US_PER_MS);
153 transfer_finished =
false;
155 transm_thread.start(
callback(transfer_thread, (
void *) &trans_thread_params));
159 if (!transfer_finished) {
160 transm_thread.terminate();
161 printf(
"ERROR: Slave transmission timeout. \r\n ");
void spi_init(spi_t *obj, bool is_slave, PinName mosi, PinName miso, PinName mclk, PinName ssel)
Initialized a spi peripheral.
SPIName spi_get_module(PinName mosi, PinName miso, PinName mclk)
Returns a variant of the SPIName enum uniquely identifying a SPI peripheral of the device...
void spi_get_capabilities(SPIName name, PinName ssel, bool slave, spi_capabilities_t *cap)
Fills the given spi_capabilities_t structure with the capabilities of the given peripheral.
Describes the capabilities of a SPI peripherals.
void spi_format(spi_t *obj, uint8_t bits, spi_mode_t mode, spi_bit_ordering_t bit_ordering)
Configure the format to be used by the SPI peripheral.
#define CMDLINE_RETCODE_SUCCESS
Execution Success.