Skip to content

Commit 785e3fb

Browse files
author
Jamie Smith
authored
Improve usability and documentation of the SPI API (ARMmbed#165)
* Make TRANSACTION_QUEUE_SIZE_SPI a proper option instead of a weird macro * Document DMAUsage constant * Copy over reworked SPI header * Spelling -_- * Document SPI event flags
1 parent 626b492 commit 785e3fb

File tree

15 files changed

+401
-81
lines changed

15 files changed

+401
-81
lines changed

drivers/include/drivers/I2C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class I2C : private NonCopyable<I2C> {
396396
* @param tx_length The length of TX buffer in bytes. If 0, no transmission is done.
397397
* @param rx_buffer The RX buffer, which is used for received data. May be nullptr if tx_length is 0.
398398
* @param rx_length The length of RX buffer in bytes If 0, no reception is done.
399-
* @param event The logical OR of events to modify. May be I2C_EVENT_ALL, or some combination
399+
* @param event The logical OR of events to subscribe to. May be I2C_EVENT_ALL, or some combination
400400
* of the flags I2C_EVENT_ERROR, I2C_EVENT_ERROR_NO_SLAVE, I2C_EVENT_TRANSFER_COMPLETE, or I2C_EVENT_TRANSFER_EARLY_NACK
401401
* @param callback The event callback function
402402
* @param repeated Set up for a repeated start. If true, the Mbed processor does not relinquish the bus after

drivers/include/drivers/SPI.h

Lines changed: 314 additions & 48 deletions
Large diffs are not rendered by default.

drivers/mbed_lib.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"help": "The maximum number of SPI peripherals used at the same time. Determines RAM allocated for SPI peripheral management. If null, limit determined by hardware.",
1919
"value": null
2020
},
21+
"spi_transaction_queue_len": {
22+
"help": "Size of the asynchronous transaction queue for each SPI peripheral on the processor. 0 means no queueing support. Only takes effect if the mbed target supports async SPI.",
23+
"value": 2
24+
},
2125
"qspi_io0": {
2226
"help": "QSPI data I/O 0 pin",
2327
"value": "QSPI_FLASH1_IO0"
@@ -86,5 +90,34 @@
8690
"help": "OSPI dqs pin",
8791
"value": "OSPI_FLASH1_DQS"
8892
}
93+
},
94+
"target_overrides": {
95+
"EFM32GG990F1024":{
96+
"spi_transaction_queue_len": 4
97+
},
98+
"EFR32MG12P332F1024GL125":{
99+
"spi_transaction_queue_len": 4
100+
},
101+
"EFM32GG11B820F2048GL192": {
102+
"spi_transaction_queue_len": 4
103+
},
104+
"RZ_A1XX":{
105+
"spi_transaction_queue_len": 16
106+
},
107+
"RZ_A2XX":{
108+
"spi_transaction_queue_len": 16
109+
},
110+
"TMPM46B":{
111+
"spi_transaction_queue_len": 4
112+
},
113+
"TMPM4G9":{
114+
"spi_transaction_queue_len": 4
115+
},
116+
"TMPM4GR":{
117+
"spi_transaction_queue_len": 4
118+
},
119+
"TMPM4NR":{
120+
"spi_transaction_queue_len": 4
121+
}
89122
}
90123
}

drivers/source/SPI.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void SPI::_do_construct()
137137
}
138138
core_util_critical_section_exit();
139139

140-
#if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI
140+
#if DEVICE_SPI_ASYNCH && MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
141141
// prime the SingletonPtr, so we don't have a problem trying to
142142
// construct the buffer if asynch operation initiated from IRQ
143143
_peripheral->transaction_buffer.get();
@@ -291,14 +291,14 @@ void SPI::abort_transfer()
291291
{
292292
spi_abort_asynch(&_peripheral->spi);
293293
unlock_deep_sleep();
294-
#if TRANSACTION_QUEUE_SIZE_SPI
294+
#if MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
295295
dequeue_transaction();
296296
#endif
297297
}
298298

299299
void SPI::clear_transfer_buffer()
300300
{
301-
#if TRANSACTION_QUEUE_SIZE_SPI
301+
#if MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
302302
_peripheral->transaction_buffer->reset();
303303
#endif
304304
}
@@ -320,7 +320,7 @@ int SPI::set_dma_usage(DMAUsage usage)
320320

321321
int SPI::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event)
322322
{
323-
#if TRANSACTION_QUEUE_SIZE_SPI
323+
#if MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
324324
transaction_t t;
325325

326326
t.tx_buffer = const_cast<void *>(tx_buffer);
@@ -373,7 +373,7 @@ void SPI::unlock_deep_sleep()
373373
}
374374
}
375375

376-
#if TRANSACTION_QUEUE_SIZE_SPI
376+
#if MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
377377

378378
void SPI::start_transaction(transaction_t *data)
379379
{
@@ -400,7 +400,7 @@ void SPI::irq_handler_asynch(void)
400400
unlock_deep_sleep();
401401
_callback.call(event & SPI_EVENT_ALL);
402402
}
403-
#if TRANSACTION_QUEUE_SIZE_SPI
403+
#if MBED_CONF_DRIVERS_SPI_TRANSACTION_QUEUE_LEN
404404
if (event & (SPI_EVENT_ALL | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE)) {
405405
// SPI peripheral is free (event happened), dequeue transaction
406406
dequeue_transaction();

hal/include/hal/dma_api.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
2-
/** \addtogroup hal */
3-
/** @{*/
1+
/**
2+
* @file
3+
* \addtogroup hal
4+
* @{
5+
*/
46
/* mbed Microcontroller Library
57
* Copyright (c) 2014-2015 ARM Limited
68
* SPDX-License-Identifier: Apache-2.0
@@ -24,12 +26,15 @@
2426

2527
#define DMA_ERROR_OUT_OF_CHANNELS (-1)
2628

29+
/**
30+
* @brief Enumeration of possible DMA usage hints
31+
*/
2732
typedef enum {
28-
DMA_USAGE_NEVER,
29-
DMA_USAGE_OPPORTUNISTIC,
30-
DMA_USAGE_ALWAYS,
31-
DMA_USAGE_TEMPORARY_ALLOCATED,
32-
DMA_USAGE_ALLOCATED
33+
DMA_USAGE_NEVER, ///< Never use DMA
34+
DMA_USAGE_OPPORTUNISTIC, ///< Use DMA if possible but deallocate DMA resources when not being used.
35+
DMA_USAGE_ALWAYS, ///< Always use DMA when possible
36+
DMA_USAGE_TEMPORARY_ALLOCATED, // Seems to be used as an internal state indicator for "we need to deallocate these channels."
37+
DMA_USAGE_ALLOCATED // Seems to be used as an internal state indicator for "we have allocated DMA channels."
3338
} DMAUsage;
3439

3540
#ifdef __cplusplus

hal/include/hal/spi_api.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,35 @@
2727

2828
#if DEVICE_SPI
2929

30+
/**
31+
* @defgroup hal_SPIEvents SPI Events Macros
32+
*
33+
* @{
34+
*/
35+
36+
/**
37+
* Indicates that some kind of error occurred when starting the transfer.
38+
*/
3039
#define SPI_EVENT_ERROR (1 << 1)
40+
41+
/**
42+
* Indicates that the transfer completed successfully.
43+
*/
3144
#define SPI_EVENT_COMPLETE (1 << 2)
45+
46+
/**
47+
* Indicates an Rx overflow: the interrupt system or DMA controller was not able to
48+
* keep up with the flow of bytes from the SPI peripheral and data was lost.
49+
*/
3250
#define SPI_EVENT_RX_OVERFLOW (1 << 3)
51+
52+
/**
53+
* Union of all of the above events.
54+
*/
3355
#define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW)
3456

57+
/// @}
58+
3559
#define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred
3660

3761
#define SPI_FILL_WORD (0xFFFF)

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333

3434

35-
#define TRANSACTION_QUEUE_SIZE_SPI 16
36-
3735

3836

3937

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333

3434

35-
#define TRANSACTION_QUEUE_SIZE_SPI 16
36-
3735

3836

3937

targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626

2727

28-
#define TRANSACTION_QUEUE_SIZE_SPI 16
29-
3028

3129

3230

targets/TARGET_TOSHIBA/TARGET_TMPM46B/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#ifndef MBED_DEVICE_H
1717
#define MBED_DEVICE_H
1818

19-
#define TRANSACTION_QUEUE_SIZE_SPI 4
2019
#define DEVICE_ID_LENGTH 32
2120

2221
#include "objects.h"

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifndef MBED_DEVICE_H
2020
#define MBED_DEVICE_H
2121

22-
#define TRANSACTION_QUEUE_SIZE_SPI 4
2322
#define DEVICE_ID_LENGTH 32
2423

2524
#include <stddef.h>

targets/TARGET_TOSHIBA/TARGET_TMPM4GR/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef MBED_DEVICE_H
1818
#define MBED_DEVICE_H
1919

20-
#define TRANSACTION_QUEUE_SIZE_SPI 4
2120
#define DEVICE_ID_LENGTH 32
2221

2322
#include <stddef.h>

targets/TARGET_TOSHIBA/TARGET_TMPM4NR/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef MBED_DEVICE_H
1818
#define MBED_DEVICE_H
1919

20-
#define TRANSACTION_QUEUE_SIZE_SPI 4
2120
#define DEVICE_ID_LENGTH 32
2221

2322
#include <stddef.h>

targets/targets.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,7 @@
12111211
],
12121212
"macros": [
12131213
"USE_HAL_DRIVER",
1214-
"USE_FULL_LL_DRIVER",
1215-
"TRANSACTION_QUEUE_SIZE_SPI=2"
1214+
"USE_FULL_LL_DRIVER"
12161215
],
12171216
"bootloader_supported": true,
12181217
"config": {
@@ -6573,8 +6572,7 @@
65736572
],
65746573
"core": "Cortex-M3",
65756574
"macros_add": [
6576-
"EFM32GG990F1024",
6577-
"TRANSACTION_QUEUE_SIZE_SPI=4"
6575+
"EFM32GG990F1024"
65786576
],
65796577
"supported_toolchains": [
65806578
"GCC_ARM"
@@ -6688,8 +6686,7 @@
66886686
],
66896687
"core": "Cortex-M4F",
66906688
"macros_add": [
6691-
"EFR32MG12P332F1024GL125",
6692-
"TRANSACTION_QUEUE_SIZE_SPI=4"
6689+
"EFR32MG12P332F1024GL125"
66936690
],
66946691
"supported_toolchains": [
66956692
"GCC_ARM"
@@ -6798,8 +6795,7 @@
67986795
],
67996796
"core": "Cortex-M4F",
68006797
"macros_add": [
6801-
"EFM32GG11B820F2048GL192",
6802-
"TRANSACTION_QUEUE_SIZE_SPI=4"
6798+
"EFM32GG11B820F2048GL192"
68036799
],
68046800
"supported_toolchains": [
68056801
"GCC_ARM"

tools/test/ci/doxy-spellchecker/ignore.en.pws

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ conf
126126
transactional
127127
errored
128128
natively
129+
enqueued
130+
enqueue
131+
MSBit
132+
LSBit
133+
busses
134+
STMicro

0 commit comments

Comments
 (0)