Skip to content

Commit b6266b5

Browse files
authored
Merge pull request #11604 from kyle-cypress/pr/qspi-inst-type
Introduce qspi_inst_t type for QSPI instructions
2 parents 9c82706 + 555140a commit b6266b5

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
381381
int type = 0;
382382
uint32_t offset = 0;
383383
uint32_t chunk = 4096;
384-
unsigned int cur_erase_inst = _erase_instruction;
384+
qspi_inst_t cur_erase_inst = _erase_instruction;
385385
int size = (int)in_size;
386386
bool erase_failed = false;
387387
int status = QSPIF_BD_ERROR_OK;
@@ -955,8 +955,8 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
955955
}
956956

957957
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
958-
unsigned int &erase4k_inst,
959-
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
958+
qspi_inst_t &erase4k_inst,
959+
qspi_inst_t *erase_type_inst_arr, unsigned int *erase_type_size_arr)
960960
{
961961
erase4k_inst = 0xff;
962962
bool found_4Kerase_type = false;
@@ -1009,7 +1009,7 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
10091009

10101010
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size,
10111011
bool &set_quad_enable,
1012-
bool &is_qpi_mode, unsigned int &read_inst)
1012+
bool &is_qpi_mode, qspi_inst_t &read_inst)
10131013
{
10141014
set_quad_enable = false;
10151015
is_qpi_mode = false;
@@ -1205,7 +1205,7 @@ int QSPIFBlockDevice::_set_write_enable()
12051205
int QSPIFBlockDevice::_enable_fast_mdoe()
12061206
{
12071207
char status_reg[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
1208-
unsigned int read_conf_register_inst = 0x15;
1208+
qspi_inst_t read_conf_register_inst = 0x15;
12091209
char status_reg_qer_setup[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
12101210

12111211
status_reg_qer_setup[2] = 0x2; // Bit 1 of config Reg 2
@@ -1322,7 +1322,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_set_frequency(int freq)
13221322
return _qspi.set_frequency(freq);
13231323
}
13241324

1325-
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst, void *buffer, bd_addr_t addr,
1325+
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst, void *buffer, bd_addr_t addr,
13261326
bd_size_t size)
13271327
{
13281328
// Send Read command to device driver
@@ -1337,7 +1337,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
13371337

13381338
}
13391339

1340-
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst, const void *buffer, bd_addr_t addr,
1340+
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(qspi_inst_t progInst, const void *buffer, bd_addr_t addr,
13411341
bd_size_t *size)
13421342
{
13431343
// Send Program (write) command to device driver
@@ -1351,7 +1351,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst
13511351
return result;
13521352
}
13531353

1354-
qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int erase_inst, bd_addr_t addr, bd_size_t size)
1354+
qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(qspi_inst_t erase_inst, bd_addr_t addr, bd_size_t size)
13551355
{
13561356
// Send Erase Instruction command to driver
13571357
qspi_status_t result = QSPI_STATUS_OK;
@@ -1373,9 +1373,9 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int erase_inst
13731373

13741374
}
13751375

1376-
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruction, bd_addr_t addr,
1376+
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(qspi_inst_t instruction, bd_addr_t addr,
13771377
const char *tx_buffer,
1378-
size_t tx_length, const char *rx_buffer, size_t rx_length)
1378+
mbed::bd_size_t tx_length, const char *rx_buffer, mbed::bd_size_t rx_length)
13791379
{
13801380
// Send a general command Instruction to driver
13811381
qspi_status_t status = _qspi.command_transfer(instruction, (int)addr, tx_buffer, tx_length, rx_buffer, rx_length);

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 17 additions & 17 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,
@@ -286,7 +286,7 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
286286

287287
// Detect fastest read Bus mode supported by device
288288
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool &set_quad_enable,
289-
bool &is_qpi_mode, unsigned int &read_inst);
289+
bool &is_qpi_mode, mbed::qspi_inst_t &read_inst);
290290

291291
// Enable Quad mode if supported (1-1-4, 1-4-4, 4-4-4 bus modes)
292292
int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
@@ -299,8 +299,8 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
299299

300300
// Detect all supported erase types
301301
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
302-
unsigned int &erase4k_inst,
303-
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr);
302+
mbed::qspi_inst_t &erase4k_inst,
303+
mbed::qspi_inst_t *erase_type_inst_arr, unsigned int *erase_type_size_arr);
304304

305305
/***********************/
306306
/* Utilities Functions */
@@ -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+
mbed::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 (-1)
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 int 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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ qspi_status_t QSPI::read(int address, char *rx_buffer, size_t *rx_length)
122122
if (*rx_length != 0) {
123123
lock();
124124
if (true == _acquire()) {
125-
_build_qspi_command(-1, address, -1);
125+
_build_qspi_command(QSPI_NO_INST, address, -1);
126126
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
127127
ret_status = QSPI_STATUS_OK;
128128
}
@@ -146,7 +146,7 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
146146
if (*tx_length != 0) {
147147
lock();
148148
if (true == _acquire()) {
149-
_build_qspi_command(-1, address, -1);
149+
_build_qspi_command(QSPI_NO_INST, address, -1);
150150
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
151151
ret_status = QSPI_STATUS_OK;
152152
}
@@ -161,7 +161,7 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
161161
return ret_status;
162162
}
163163

164-
qspi_status_t QSPI::read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
164+
qspi_status_t QSPI::read(qspi_inst_t instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
165165
{
166166
qspi_status_t ret_status = QSPI_STATUS_ERROR;
167167

@@ -185,7 +185,7 @@ qspi_status_t QSPI::read(int instruction, int alt, int address, char *rx_buffer,
185185
return ret_status;
186186
}
187187

188-
qspi_status_t QSPI::write(int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
188+
qspi_status_t QSPI::write(qspi_inst_t instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
189189
{
190190
qspi_status_t ret_status = QSPI_STATUS_ERROR;
191191

@@ -209,7 +209,7 @@ qspi_status_t QSPI::write(int instruction, int alt, int address, const char *tx_
209209
return ret_status;
210210
}
211211

212-
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)
212+
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)
213213
{
214214
qspi_status_t ret_status = QSPI_STATUS_ERROR;
215215

@@ -267,12 +267,12 @@ bool QSPI::_acquire()
267267
return _initialized;
268268
}
269269

270-
void QSPI::_build_qspi_command(int instruction, int address, int alt)
270+
void QSPI::_build_qspi_command(qspi_inst_t instruction, int address, int alt)
271271
{
272272
memset(&_qspi_command, 0, sizeof(qspi_command_t));
273273
//Set up instruction phase parameters
274274
_qspi_command.instruction.bus_width = _inst_width;
275-
if (instruction != -1) {
275+
if (instruction != QSPI_NO_INST) {
276276
_qspi_command.instruction.value = instruction;
277277
_qspi_command.instruction.disabled = false;
278278
} else {

0 commit comments

Comments
 (0)