Skip to content

Commit 1a1819b

Browse files
Matthew MacovskyKyle Kearney
authored andcommitted
Introduce qspi_inst_t type for QSPI instructions
Encourage the usage of consistent types (there are currently a mix of `int` and `unsigned int` used for qspi instructions) QSPI commands are limited to 8 bits, to this is a typdef to uint8_t
1 parent c385e14 commit 1a1819b

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
380380
int type = 0;
381381
uint32_t offset = 0;
382382
uint32_t chunk = 4096;
383-
unsigned int cur_erase_inst = _erase_instruction;
383+
qspi_inst_t cur_erase_inst = _erase_instruction;
384384
int size = (int)in_size;
385385
bool erase_failed = false;
386386
int status = QSPIF_BD_ERROR_OK;
@@ -954,8 +954,8 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
954954
}
955955

956956
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
957-
unsigned int &erase4k_inst,
958-
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
957+
qspi_inst_t &erase4k_inst,
958+
qspi_inst_t *erase_type_inst_arr, unsigned int *erase_type_size_arr)
959959
{
960960
erase4k_inst = 0xff;
961961
bool found_4Kerase_type = false;
@@ -1008,7 +1008,7 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
10081008

10091009
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size,
10101010
bool &set_quad_enable,
1011-
bool &is_qpi_mode, unsigned int &read_inst)
1011+
bool &is_qpi_mode, qspi_inst_t &read_inst)
10121012
{
10131013
set_quad_enable = false;
10141014
is_qpi_mode = false;
@@ -1199,7 +1199,7 @@ int QSPIFBlockDevice::_set_write_enable()
11991199
int QSPIFBlockDevice::_enable_fast_mdoe()
12001200
{
12011201
char status_reg[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
1202-
unsigned int read_conf_register_inst = 0x15;
1202+
qspi_inst_t read_conf_register_inst = 0x15;
12031203
char status_reg_qer_setup[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
12041204

12051205
status_reg_qer_setup[2] = 0x2; // Bit 1 of config Reg 2
@@ -1317,7 +1317,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_set_frequency(int freq)
13171317
return _qspi.set_frequency(freq);
13181318
}
13191319

1320-
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst, void *buffer, bd_addr_t addr,
1320+
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst, void *buffer, bd_addr_t addr,
13211321
bd_size_t size)
13221322
{
13231323
// Send Read command to device driver
@@ -1332,7 +1332,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
13321332

13331333
}
13341334

1335-
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst, const void *buffer, bd_addr_t addr,
1335+
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(qspi_inst_t progInst, const void *buffer, bd_addr_t addr,
13361336
bd_size_t *size)
13371337
{
13381338
// Send Program (write) command to device driver
@@ -1346,7 +1346,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst
13461346
return result;
13471347
}
13481348

1349-
qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int erase_inst, bd_addr_t addr, bd_size_t size)
1349+
qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(qspi_inst_t erase_inst, bd_addr_t addr, bd_size_t size)
13501350
{
13511351
// Send Erase Instruction command to driver
13521352
qspi_status_t result = QSPI_STATUS_OK;
@@ -1368,7 +1368,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int erase_inst
13681368

13691369
}
13701370

1371-
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruction, bd_addr_t addr,
1371+
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(qspi_inst_t instruction, bd_addr_t addr,
13721372
const char *tx_buffer,
13731373
size_t tx_length, const char *rx_buffer, size_t rx_length)
13741374
{

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,19 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
234234
/********************************/
235235
/* Calls to QSPI Driver APIs */
236236
/********************************/
237-
// Send Program => Write command to Driver
238-
qspi_status_t _qspi_send_program_command(unsigned int prog_instruction, const void *buffer, mbed::bd_addr_t addr,
239-
mbed::bd_size_t *size);
237+
// Send Program/Write command to Driver
238+
qspi_status_t _qspi_send_program_command(mbed::qspi_inst_t prog_instruction, const void *buffer,
239+
mbed::bd_addr_t addr, mbed::bd_size_t *size);
240240

241241
// Send Read command to Driver
242-
qspi_status_t _qspi_send_read_command(unsigned int read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
242+
qspi_status_t _qspi_send_read_command(mbed::qspi_inst_t read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
243243

244244
// Send Erase Instruction using command_transfer command to Driver
245-
qspi_status_t _qspi_send_erase_command(unsigned int erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
245+
qspi_status_t _qspi_send_erase_command(mbed::qspi_inst_t erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
246246

247247
// Send Generic command_transfer command to Driver
248-
qspi_status_t _qspi_send_general_command(unsigned int instruction_int, mbed::bd_addr_t addr, const char *tx_buffer,
249-
size_t tx_length, const char *rx_buffer, size_t rx_length);
248+
qspi_status_t _qspi_send_general_command(mbed::qspi_inst_t instruction_int, mbed::bd_addr_t addr, const char *tx_buffer,
249+
mbed::bd_size_t tx_length, const char *rx_buffer, mbed::bd_size_t rx_length);
250250

251251
// Send Bus configure_format command to Driver
252252
qspi_status_t _qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
@@ -331,15 +331,15 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
331331
PlatformMutex _mutex;
332332

333333
// Command Instructions
334-
unsigned int _read_instruction;
335-
unsigned int _prog_instruction;
336-
unsigned int _erase_instruction;
337-
unsigned int _erase4k_inst; // Legacy 4K erase instruction (default 0x20h)
338-
unsigned int _write_register_inst; // Write status/config register instruction may vary between chips
339-
unsigned int _read_register_inst; // Read status/config register instruction may vary between chips
334+
mbed::qspi_inst_t _read_instruction;
335+
mbed::qspi_inst_t _prog_instruction;
336+
mbed::qspi_inst_t _erase_instruction;
337+
mbed::qspi_inst_t _erase4k_inst; // Legacy 4K erase instruction (default 0x20h)
338+
mbed::qspi_inst_t _write_register_inst; // Write status/config register instruction may vary between chips
339+
mned::qspi_inst_t _read_register_inst; // Read status/config register instruction may vary between chips
340340

341341
// Up To 4 Erase Types are supported by SFDP (each with its own command Instruction and Size)
342-
unsigned int _erase_type_inst_arr[MAX_NUM_OF_ERASE_TYPES];
342+
mbed::qspi_inst_t _erase_type_inst_arr[MAX_NUM_OF_ERASE_TYPES];
343343
unsigned int _erase_type_size_arr[MAX_NUM_OF_ERASE_TYPES];
344344

345345
// Sector Regions Map

drivers/QSPI.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#define ONE_MHZ 1000000
3030

31+
#define QSPI_NO_INST 0x00
32+
3133
namespace mbed {
3234
/** \defgroup drivers-public-api-spi SPI
3335
* \ingroup drivers-public-api
@@ -39,6 +41,10 @@ namespace mbed {
3941
* @{
4042
*/
4143

44+
/** Type representing a QSPI instruction
45+
*/
46+
typedef uint8_t qspi_inst_t;
47+
4248
/** A QSPI Driver, used for communicating with QSPI slave devices
4349
*
4450
* The default format is set to Quad-SPI(1-1-1), and a clock frequency of 1MHz
@@ -160,7 +166,7 @@ class QSPI : private NonCopyable<QSPI> {
160166
* @returns
161167
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
162168
*/
163-
qspi_status_t read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length);
169+
qspi_status_t read(qspi_inst_t instruction, int alt, int address, char *rx_buffer, size_t *rx_length);
164170

165171
/** Write to QSPI peripheral using custom write instruction, alt values
166172
*
@@ -173,7 +179,7 @@ class QSPI : private NonCopyable<QSPI> {
173179
* @returns
174180
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
175181
*/
176-
qspi_status_t write(int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length);
182+
qspi_status_t write(qspi_inst_t instruction, int alt, int address, const char *tx_buffer, size_t *tx_length);
177183

178184
/** Perform a transaction to write to an address(a control register) and get the status results
179185
*
@@ -187,7 +193,7 @@ class QSPI : private NonCopyable<QSPI> {
187193
* @returns
188194
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
189195
*/
190-
qspi_status_t command_transfer(int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length);
196+
qspi_status_t command_transfer(qspi_inst_t instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length);
191197

192198
#if !defined(DOXYGEN_ONLY)
193199
protected:
@@ -227,7 +233,7 @@ class QSPI : private NonCopyable<QSPI> {
227233
/*
228234
* This function builds the qspi command struct to be send to Hal
229235
*/
230-
inline void _build_qspi_command(int instruction, int address, int alt);
236+
inline void _build_qspi_command(qspi_inst_t instruction, int address, int alt);
231237
#endif
232238
};
233239

drivers/source/QSPI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
140140
return ret_status;
141141
}
142142

143-
qspi_status_t QSPI::read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
143+
qspi_status_t QSPI::read(qspi_inst_t instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
144144
{
145145
qspi_status_t ret_status = QSPI_STATUS_ERROR;
146146

@@ -164,7 +164,7 @@ qspi_status_t QSPI::read(int instruction, int alt, int address, char *rx_buffer,
164164
return ret_status;
165165
}
166166

167-
qspi_status_t QSPI::write(int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
167+
qspi_status_t QSPI::write(qspi_inst_t instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
168168
{
169169
qspi_status_t ret_status = QSPI_STATUS_ERROR;
170170

@@ -188,7 +188,7 @@ qspi_status_t QSPI::write(int instruction, int alt, int address, const char *tx_
188188
return ret_status;
189189
}
190190

191-
qspi_status_t QSPI::command_transfer(int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length)
191+
qspi_status_t QSPI::command_transfer(qspi_inst_t instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length)
192192
{
193193
qspi_status_t ret_status = QSPI_STATUS_ERROR;
194194

@@ -246,12 +246,12 @@ bool QSPI::_acquire()
246246
return _initialized;
247247
}
248248

249-
void QSPI::_build_qspi_command(int instruction, int address, int alt)
249+
void QSPI::_build_qspi_command(qspi_inst_t instruction, int address, int alt)
250250
{
251251
memset(&_qspi_command, 0, sizeof(qspi_command_t));
252252
//Set up instruction phase parameters
253253
_qspi_command.instruction.bus_width = _inst_width;
254-
if (instruction != -1) {
254+
if (instruction != QSPI_NO_INST) {
255255
_qspi_command.instruction.value = instruction;
256256
_qspi_command.instruction.disabled = false;
257257
} else {

0 commit comments

Comments
 (0)