19 void init_transmission_buffers_master(
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 tx_pattern[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE };
23 uint8_t rx_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_rx1_pattern[3],
sizeof(T), 0x00);
35 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0x00);
38 if (config->master_tx_cnt < config->master_rx_cnt) {
39 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xF5);
40 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xF5);
44 if (config->slave_tx_cnt > config->slave_rx_cnt) {
45 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0x00);
46 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0x00);
49 if (config->slave_tx_cnt < config->slave_rx_cnt) {
50 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xF5);
51 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xF5);
55 if (!config->master_tx_defined) {
56 set_buffer(&p_rx2_pattern[0],
sizeof(T), 0xF5);
57 set_buffer(&p_rx2_pattern[1],
sizeof(T), 0xF5);
58 set_buffer(&p_rx2_pattern[2],
sizeof(T), 0xF5);
59 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0xF5);
60 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0xF5);
64 if (!config->master_rx_defined) {
65 set_buffer(&p_rx1_pattern[0],
sizeof(T), 0xAA);
66 set_buffer(&p_rx1_pattern[1],
sizeof(T), 0xBB);
67 set_buffer(&p_rx1_pattern[2],
sizeof(T), 0xCC);
68 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xDD);
69 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xEE);
73 if (!config->slave_tx_defined) {
74 set_buffer(&p_rx1_pattern[0],
sizeof(T), 0xF5);
75 set_buffer(&p_rx1_pattern[1],
sizeof(T), 0xF5);
76 set_buffer(&p_rx1_pattern[2],
sizeof(T), 0xF5);
77 set_buffer(&p_rx1_pattern[3],
sizeof(T), 0xF5);
78 set_buffer(&p_rx1_pattern[4],
sizeof(T), 0xF5);
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_rx2_pattern[0],
sizeof(T), 0x11);
90 set_buffer(&p_rx2_pattern[1],
sizeof(T), 0x22);
91 set_buffer(&p_rx2_pattern[2],
sizeof(T), 0x33);
92 set_buffer(&p_rx2_pattern[3],
sizeof(T), 0x44);
93 set_buffer(&p_rx2_pattern[4],
sizeof(T), 0x55);
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);
114 PinName ss_pin = MASTER_SPI_SS;
115 PinName miso = MASTER_SPI_MISO;
116 PinName mosi = MASTER_SPI_MOSI;
123 if (config->duplex == HALF_DUPLEX) {
124 if (MASTER_SPI_HF_DATA == MASTER_SPI_MOSI) {
126 }
else if (MASTER_SPI_HF_DATA == MASTER_SPI_MISO) {
129 printf(
"ERROR: Master init in half duplex mode. \r\n ");
134 switch (config->freq_hz) {
148 if (!config->auto_ss) {
150 *ss =
new DigitalOut(MASTER_SPI_SS);
154 spi_init(obj,
false, mosi, miso, MASTER_SPI_CLK, ss_pin);
156 spi_format(obj, config->symbol_size, config->mode, config->bit_ordering);
166 Timeout transm_thread_timeout;
167 Thread transm_thread(osPriorityNormal);
173 transm_thread_timeout.attach_us(transm_timeout_handler, 5 * US_PER_S + 2 * MASTER_TRANSMISSION_DELAY_MS * US_PER_MS);
175 transfer_finished =
false;
177 transm_thread.start(
callback(transfer_thread, (
void *) &trans_thread_params));
181 if (!transfer_finished) {
182 transm_thread.terminate();
183 printf(
"ERROR: Master 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.
uint32_t minimum_frequency
Minimum frequency supported must be set by target device and it will be assessed during testing...
uint32_t maximum_frequency
Maximum frequency supported must be set by target device and it will be assessed during testing...
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.
uint32_t spi_frequency(spi_t *obj, uint32_t hz)
Set the frequency target.
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.