@@ -29,13 +29,15 @@ struct spi_context {
2929 struct k_poll_signal * signal ;
3030 bool asynchronous ;
3131#endif
32- const struct spi_buf * * current_tx ;
33- struct spi_buf * * current_rx ;
32+ const struct spi_buf * current_tx ;
33+ size_t tx_count ;
34+ struct spi_buf * current_rx ;
35+ size_t rx_count ;
3436
3537 void * tx_buf ;
36- u32_t tx_len ;
38+ size_t tx_len ;
3739 void * rx_buf ;
38- u32_t rx_len ;
40+ size_t rx_len ;
3941};
4042
4143#define SPI_CONTEXT_INIT_LOCK (_data , _ctx_name ) \
@@ -144,36 +146,40 @@ static inline void spi_context_cs_control(struct spi_context *ctx, bool on)
144146}
145147
146148static inline void spi_context_buffers_setup (struct spi_context * ctx ,
147- const struct spi_buf * * tx_bufs ,
148- struct spi_buf * * rx_bufs ,
149+ const struct spi_buf * tx_bufs ,
150+ size_t tx_count ,
151+ struct spi_buf * rx_bufs ,
152+ size_t rx_count ,
149153 uint8_t dfs )
150154{
151- SYS_LOG_DBG ("tx_bufs %p (%p) - rx_bufs %p (%p) - %u" ,
152- tx_bufs , tx_bufs ? * tx_bufs : NULL ,
153- rx_bufs , rx_bufs ? * rx_bufs : NULL , dfs );
155+ SYS_LOG_DBG ("tx_bufs %p (%zu) - rx_bufs %p (%zu) - %u" ,
156+ tx_bufs , tx_count , rx_bufs , rx_count , dfs );
154157
155158 ctx -> current_tx = tx_bufs ;
159+ ctx -> tx_count = tx_count ;
156160 ctx -> current_rx = rx_bufs ;
161+ ctx -> rx_count = rx_count ;
157162
158- if (* tx_bufs ) {
159- ctx -> tx_buf = ( * tx_bufs ) -> buf ;
160- ctx -> tx_len = ( * tx_bufs ) -> len / dfs ;
163+ if (tx_bufs ) {
164+ ctx -> tx_buf = tx_bufs -> buf ;
165+ ctx -> tx_len = tx_bufs -> len / dfs ;
161166 } else {
162167 ctx -> tx_buf = NULL ;
163168 ctx -> tx_len = 0 ;
164169 }
165170
166- if (* rx_bufs ) {
167- ctx -> rx_buf = ( * rx_bufs ) -> buf ;
168- ctx -> rx_len = ( * rx_bufs ) -> len / dfs ;
171+ if (rx_bufs ) {
172+ ctx -> rx_buf = rx_bufs -> buf ;
173+ ctx -> rx_len = rx_bufs -> len / dfs ;
169174 } else {
170175 ctx -> rx_buf = NULL ;
171176 ctx -> rx_len = 0 ;
172177 }
173178
174- SYS_LOG_DBG ("current_tx %p, current_rx %p,"
175- " tx buf/len %p/%u, rx buf/len %p/%u" ,
176- ctx -> current_tx , ctx -> current_rx ,
179+ SYS_LOG_DBG ("current_tx %p (%zu), current_rx %p (%zu),"
180+ " tx buf/len %p/%zu, rx buf/len %p/%zu" ,
181+ ctx -> current_tx , ctx -> tx_count ,
182+ ctx -> current_rx , ctx -> rx_count ,
177183 ctx -> tx_buf , ctx -> tx_len , ctx -> rx_buf , ctx -> rx_len );
178184}
179185
@@ -187,17 +193,19 @@ void spi_context_update_tx(struct spi_context *ctx, uint8_t dfs)
187193 ctx -> tx_len -- ;
188194 if (!ctx -> tx_len ) {
189195 ctx -> current_tx ++ ;
190- if (* ctx -> current_tx ) {
191- ctx -> tx_buf = (* ctx -> current_tx )-> buf ;
192- ctx -> tx_len = (* ctx -> current_tx )-> len /dfs ;
196+ ctx -> tx_count -- ;
197+
198+ if (ctx -> tx_count ) {
199+ ctx -> tx_buf = ctx -> current_tx -> buf ;
200+ ctx -> tx_len = ctx -> current_tx -> len / dfs ;
193201 } else {
194202 ctx -> tx_buf = NULL ;
195203 }
196204 } else if (ctx -> tx_buf ) {
197205 ctx -> tx_buf += dfs ;
198206 }
199207
200- SYS_LOG_DBG ("tx buf/len %p/%u " , ctx -> tx_buf , ctx -> tx_len );
208+ SYS_LOG_DBG ("tx buf/len %p/%zu " , ctx -> tx_buf , ctx -> tx_len );
201209}
202210
203211static ALWAYS_INLINE
@@ -216,17 +224,19 @@ void spi_context_update_rx(struct spi_context *ctx, uint8_t dfs)
216224 ctx -> rx_len -- ;
217225 if (!ctx -> rx_len ) {
218226 ctx -> current_rx ++ ;
219- if (* ctx -> current_rx ) {
220- ctx -> rx_buf = (* ctx -> current_rx )-> buf ;
221- ctx -> rx_len = (* ctx -> current_rx )-> len /dfs ;
227+ ctx -> rx_count -- ;
228+
229+ if (ctx -> rx_count ) {
230+ ctx -> rx_buf = ctx -> current_rx -> buf ;
231+ ctx -> rx_len = ctx -> current_rx -> len / dfs ;
222232 } else {
223233 ctx -> rx_buf = NULL ;
224234 }
225235 } else if (ctx -> rx_buf ) {
226236 ctx -> rx_buf += dfs ;
227237 }
228238
229- SYS_LOG_DBG ("rx buf/len %p/%u " , ctx -> rx_buf , ctx -> rx_len );
239+ SYS_LOG_DBG ("rx buf/len %p/%zu " , ctx -> rx_buf , ctx -> rx_len );
230240}
231241
232242static ALWAYS_INLINE
0 commit comments