@@ -44,6 +44,10 @@ struct spi_context {
44
44
size_t tx_len ;
45
45
u8_t * rx_buf ;
46
46
size_t rx_len ;
47
+
48
+ #ifdef CONFIG_SPI_SLAVE
49
+ int recv_frames ;
50
+ #endif /* CONFIG_SPI_SLAVE */
47
51
};
48
52
49
53
#define SPI_CONTEXT_INIT_LOCK (_data , _ctx_name ) \
@@ -77,10 +81,12 @@ static inline void spi_context_lock(struct spi_context *ctx,
77
81
78
82
static inline void spi_context_release (struct spi_context * ctx , int status )
79
83
{
80
- if (!status &&
84
+ #ifdef CONFIG_SPI_SLAVE
85
+ if (status >= 0 &&
81
86
(ctx -> config -> operation & (SPI_LOCK_ON | SPI_OP_MODE_SLAVE ))) {
82
87
return ;
83
88
}
89
+ #endif /* CONFIG_SPI_SLAVE */
84
90
85
91
#ifdef CONFIG_SPI_ASYNC
86
92
if (!ctx -> asynchronous || status ) {
@@ -110,6 +116,13 @@ static inline int spi_context_wait_for_completion(struct spi_context *ctx)
110
116
k_sem_take (& ctx -> sync , K_FOREVER );
111
117
status = ctx -> sync_status ;
112
118
#endif /* CONFIG_SPI_ASYNC */
119
+
120
+ #ifdef CONFIG_SPI_SLAVE
121
+ if (spi_context_is_slave (ctx ) && !status ) {
122
+ return ctx -> recv_frames ;
123
+ }
124
+ #endif /* CONFIG_SPI_SLAVE */
125
+
113
126
return status ;
114
127
}
115
128
@@ -221,6 +234,10 @@ void spi_context_buffers_setup(struct spi_context *ctx,
221
234
222
235
ctx -> sync_status = 0 ;
223
236
237
+ #ifdef CONFIG_SPI_SLAVE
238
+ ctx -> recv_frames = 0 ;
239
+ #endif /* CONFIG_SPI_SLAVE */
240
+
224
241
SYS_LOG_DBG ("current_tx %p (%zu), current_rx %p (%zu),"
225
242
" tx buf/len %p/%zu, rx buf/len %p/%zu" ,
226
243
ctx -> current_tx , ctx -> tx_count ,
@@ -272,6 +289,13 @@ bool spi_context_tx_buf_on(struct spi_context *ctx)
272
289
static ALWAYS_INLINE
273
290
void spi_context_update_rx (struct spi_context * ctx , u8_t dfs , u32_t len )
274
291
{
292
+ #ifdef CONFIG_SPI_SLAVE
293
+ if (spi_context_is_slave (ctx )) {
294
+ ctx -> recv_frames += len ;
295
+ }
296
+
297
+ #endif /* CONFIG_SPI_SLAVE */
298
+
275
299
if (!ctx -> rx_len ) {
276
300
return ;
277
301
}
0 commit comments