Skip to content

Commit cc95328

Browse files
committed
MCUXpresso: Use SDK API for spi_master_block_write
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 7ed5b81 commit cc95328

File tree

8 files changed

+94
-62
lines changed

8 files changed

+94
-62
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,21 @@ int spi_master_write(spi_t *obj, int value)
119119
}
120120

121121
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
122-
char *rx_buffer, int rx_length, char write_fill) {
122+
char *rx_buffer, int rx_length, char write_fill)
123+
{
123124
int total = (tx_length > rx_length) ? tx_length : rx_length;
124125

125-
for (int i = 0; i < total; i++) {
126-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
127-
char in = spi_master_write(obj, out);
128-
if (i < rx_length) {
129-
rx_buffer[i] = in;
130-
}
131-
}
126+
// Default write is done in each and every call, in future can create HAL API instead
127+
DSPI_SetDummyData(spi_address[obj->instance], write_fill);
128+
129+
DSPI_MasterTransferBlocking(spi_address[obj->instance], &(dspi_transfer_t) {
130+
.txData = (uint8_t *)tx_buffer,
131+
.rxData = (uint8_t *)rx_buffer,
132+
.dataSize = total,
133+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
134+
});
135+
136+
DSPI_ClearStatusFlags(spi_address[obj->instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
132137

133138
return total;
134139
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ int spi_master_write(spi_t *obj, int value)
116116
}
117117

118118
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
119-
char *rx_buffer, int rx_length, char write_fill) {
119+
char *rx_buffer, int rx_length, char write_fill)
120+
{
120121
int total = (tx_length > rx_length) ? tx_length : rx_length;
121122

122-
for (int i = 0; i < total; i++) {
123-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
124-
char in = spi_master_write(obj, out);
125-
if (i < rx_length) {
126-
rx_buffer[i] = in;
127-
}
128-
}
123+
// Default write is done in each and every call, in future can create HAL API instead
124+
SPI_SetDummyData(spi_address[obj->instance], write_fill);
125+
126+
SPI_MasterTransferBlocking(spi_address[obj->instance], &(spi_transfer_t) {
127+
.txData = (uint8_t *)tx_buffer,
128+
.rxData = (uint8_t *)rx_buffer,
129+
.dataSize = total
130+
});
129131

130132
return total;
131133
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ int spi_master_write(spi_t *obj, int value)
116116
}
117117

118118
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
119-
char *rx_buffer, int rx_length, char write_fill) {
119+
char *rx_buffer, int rx_length, char write_fill)
120+
{
120121
int total = (tx_length > rx_length) ? tx_length : rx_length;
121122

122-
for (int i = 0; i < total; i++) {
123-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
124-
char in = spi_master_write(obj, out);
125-
if (i < rx_length) {
126-
rx_buffer[i] = in;
127-
}
128-
}
123+
// Default write is done in each and every call, in future can create HAL API instead
124+
SPI_SetDummyData(spi_address[obj->instance], write_fill);
125+
126+
SPI_MasterTransferBlocking(spi_address[obj->instance], &(spi_transfer_t) {
127+
.txData = (uint8_t *)tx_buffer,
128+
.rxData = (uint8_t *)rx_buffer,
129+
.dataSize = total
130+
});
129131

130132
return total;
131133
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,21 @@ int spi_master_write(spi_t *obj, int value)
118118
}
119119

120120
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
121-
char *rx_buffer, int rx_length, char write_fill) {
121+
char *rx_buffer, int rx_length, char write_fill)
122+
{
122123
int total = (tx_length > rx_length) ? tx_length : rx_length;
123124

124-
for (int i = 0; i < total; i++) {
125-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
126-
char in = spi_master_write(obj, out);
127-
if (i < rx_length) {
128-
rx_buffer[i] = in;
129-
}
130-
}
125+
// Default write is done in each and every call, in future can create HAL API instead
126+
DSPI_SetDummyData(spi_address[obj->instance], write_fill);
127+
128+
DSPI_MasterTransferBlocking(spi_address[obj->instance], &(dspi_transfer_t) {
129+
.txData = (uint8_t *)tx_buffer,
130+
.rxData = (uint8_t *)rx_buffer,
131+
.dataSize = total,
132+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
133+
});
134+
135+
DSPI_ClearStatusFlags(spi_address[obj->instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
131136

132137
return total;
133138
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
141141
{
142142
int total = (tx_length > rx_length) ? tx_length : rx_length;
143143

144-
for (int i = 0; i < total; i++) {
145-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
146-
char in = spi_master_write(obj, out);
147-
if (i < rx_length) {
148-
rx_buffer[i] = in;
149-
}
150-
}
144+
// Default write is done in each and every call, in future can create HAL API instead
145+
DSPI_SetDummyData(spi_address[obj->instance], write_fill);
146+
147+
DSPI_MasterTransferBlocking(spi_address[obj->instance], &(dspi_transfer_t) {
148+
.txData = (uint8_t *)tx_buffer,
149+
.rxData = (uint8_t *)rx_buffer,
150+
.dataSize = total,
151+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
152+
});
153+
154+
DSPI_ClearStatusFlags(spi_address[obj->instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
151155

152156
return total;
153157
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
141141
{
142142
int total = (tx_length > rx_length) ? tx_length : rx_length;
143143

144-
for (int i = 0; i < total; i++) {
145-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
146-
char in = spi_master_write(obj, out);
147-
if (i < rx_length) {
148-
rx_buffer[i] = in;
149-
}
150-
}
144+
// Default write is done in each and every call, in future can create HAL API instead
145+
DSPI_SetDummyData(spi_address[obj->instance], write_fill);
146+
147+
DSPI_MasterTransferBlocking(spi_address[obj->instance], &(dspi_transfer_t) {
148+
.txData = (uint8_t *)tx_buffer,
149+
.rxData = (uint8_t *)rx_buffer,
150+
.dataSize = total,
151+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
152+
});
153+
154+
DSPI_ClearStatusFlags(spi_address[obj->instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
151155

152156
return total;
153157
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,21 @@ int spi_master_write(spi_t *obj, int value)
118118
}
119119

120120
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
121-
char *rx_buffer, int rx_length, char write_fill) {
121+
char *rx_buffer, int rx_length, char write_fill)
122+
{
122123
int total = (tx_length > rx_length) ? tx_length : rx_length;
123124

124-
for (int i = 0; i < total; i++) {
125-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
126-
char in = spi_master_write(obj, out);
127-
if (i < rx_length) {
128-
rx_buffer[i] = in;
129-
}
130-
}
125+
// Default write is done in each and every call, in future can create HAL API instead
126+
DSPI_SetDummyData(spi_address[obj->instance], write_fill);
127+
128+
DSPI_MasterTransferBlocking(spi_address[obj->instance], &(dspi_transfer_t) {
129+
.txData = (uint8_t *)tx_buffer,
130+
.rxData = (uint8_t *)rx_buffer,
131+
.dataSize = total,
132+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
133+
});
134+
135+
DSPI_ClearStatusFlags(spi_address[obj->instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
131136

132137
return total;
133138
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,21 @@ int spi_master_write(spi_t *obj, int value)
128128
}
129129

130130
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
131-
char *rx_buffer, int rx_length, char write_fill) {
131+
char *rx_buffer, int rx_length, char write_fill)
132+
{
132133
int total = (tx_length > rx_length) ? tx_length : rx_length;
133134

134-
for (int i = 0; i < total; i++) {
135-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
136-
char in = spi_master_write(obj, out);
137-
if (i < rx_length) {
138-
rx_buffer[i] = in;
139-
}
140-
}
135+
// Default write is done in each and every call, in future can create HAL API instead
136+
DSPI_SetDummyData(spi_address[obj->spi.instance], write_fill);
137+
138+
DSPI_MasterTransferBlocking(spi_address[obj->spi.instance], &(dspi_transfer_t) {
139+
.txData = (uint8_t *)tx_buffer,
140+
.rxData = (uint8_t *)rx_buffer,
141+
.dataSize = total,
142+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
143+
});
144+
145+
DSPI_ClearStatusFlags(spi_address[obj->spi.instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
141146

142147
return total;
143148
}

0 commit comments

Comments
 (0)