Skip to content

Commit 5473b22

Browse files
ananglcfriedt
authored andcommitted
drivers: i2s_nrfx: Fix a few minor fixes
- correct the names of buffers used by message queues so that it is possible to have multiple instances of the driver (in case such need appears in the future) - make `stop` and `discard_rx` normal structure members, not bit fields, as they are modified in the interrupt handler and that could lead to overwriting of other bit fields located in the same memory unit - add a log message providing the actual frame clock (WS) frequency (i.e. PCM rate) that the driver was able to configure (due to hardware limitations, it is not always possible to achieve the exact requested frequency and the driver selects the closest one available, so make it more visible to users Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 953f35f commit 5473b22

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/i2s/i2s_nrfx.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ struct i2s_nrfx_drv_data {
2727
const uint32_t *last_tx_buffer;
2828
enum i2s_state state;
2929
enum i2s_dir active_dir;
30+
bool stop; /* stop after the current (TX or RX) block */
31+
bool discard_rx; /* discard further RX blocks */
32+
volatile bool next_tx_buffer_needed;
3033
bool tx_configured : 1;
3134
bool rx_configured : 1;
32-
bool stop : 1; /* stop after the current (TX or RX) block */
33-
bool discard_rx : 1; /* discard further RX blocks */
3435
bool request_clock : 1;
35-
volatile bool next_tx_buffer_needed;
3636
};
3737

3838
struct i2s_nrfx_drv_cfg {
@@ -81,6 +81,7 @@ static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
8181
uint32_t best_diff = UINT32_MAX;
8282
uint8_t r, best_r = 0;
8383
nrf_i2s_mck_t best_mck_cfg = 0;
84+
uint32_t best_mck = 0;
8485

8586
for (r = 0; r < ARRAY_SIZE(ratios); ++r) {
8687
/* Only multiples of the frame width can be used as ratios. */
@@ -110,6 +111,7 @@ static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
110111

111112
if (diff < best_diff) {
112113
best_mck_cfg = mck_factor * 4096;
114+
best_mck = actual_mck;
113115
best_r = r;
114116
/* Stop if an exact match is found. */
115117
if (diff == 0) {
@@ -150,6 +152,7 @@ static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
150152

151153
if (diff < best_diff) {
152154
best_mck_cfg = dividers[d].divider_enum;
155+
best_mck = mck_freq;
153156
best_r = r;
154157
/* Stop if an exact match is found. */
155158
if (diff == 0) {
@@ -173,6 +176,8 @@ static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
173176

174177
config->mck_setup = best_mck_cfg;
175178
config->ratio = ratios[best_r].ratio_enum;
179+
LOG_INF("I2S MCK frequency: %u, actual PCM rate: %u",
180+
best_mck, best_mck / ratios[best_r].ratio_val);
176181
}
177182

178183
static bool get_next_tx_buffer(struct i2s_nrfx_drv_data *drv_data,
@@ -876,8 +881,8 @@ static const struct i2s_driver_api i2s_nrf_drv_api = {
876881
#define I2S_CLK_SRC(idx) DT_STRING_TOKEN(I2S(idx), clock_source)
877882

878883
#define I2S_NRFX_DEVICE(idx) \
879-
static void *tx_msgs[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \
880-
static void *rx_msgs[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \
884+
static void *tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \
885+
static void *rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \
881886
static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \
882887
.state = I2S_STATE_READY, \
883888
}; \
@@ -887,11 +892,11 @@ static const struct i2s_driver_api i2s_nrf_drv_api = {
887892
nrfx_isr, nrfx_i2s_irq_handler, 0); \
888893
irq_enable(DT_IRQN(I2S(idx))); \
889894
k_msgq_init(&i2s_nrfx_data##idx.tx_queue, \
890-
(char *)tx_msgs, sizeof(void *), \
891-
CONFIG_I2S_NRFX_TX_BLOCK_COUNT); \
895+
(char *)tx_msgs##idx, sizeof(void *), \
896+
ARRAY_SIZE(tx_msgs##idx)); \
892897
k_msgq_init(&i2s_nrfx_data##idx.rx_queue, \
893-
(char *)rx_msgs, sizeof(void *), \
894-
CONFIG_I2S_NRFX_RX_BLOCK_COUNT); \
898+
(char *)rx_msgs##idx, sizeof(void *), \
899+
ARRAY_SIZE(rx_msgs##idx)); \
895900
init_clock_manager(dev); \
896901
return 0; \
897902
} \

0 commit comments

Comments
 (0)