ChibiOS/HAL  6.1.0
hal_queues.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_queues.c
19  * @brief I/O Queues code.
20  *
21  * @addtogroup HAL_QUEUES
22  * @details Queues are mostly used in serial-like device drivers.
23  * Serial device drivers are usually designed to have a lower side
24  * (lower driver, it is usually an interrupt service routine) and an
25  * upper side (upper driver, accessed by the application threads).<br>
26  * There are several kind of queues:<br>
27  * - <b>Input queue</b>, unidirectional queue where the writer is the
28  * lower side and the reader is the upper side.
29  * - <b>Output queue</b>, unidirectional queue where the writer is the
30  * upper side and the reader is the lower side.
31  * - <b>Full duplex queue</b>, bidirectional queue. Full duplex queues
32  * are implemented by pairing an input queue and an output queue
33  * together.
34  * .
35  * @{
36  */
37 
38 #include <string.h>
39 
40 #include "hal.h"
41 
42 /*===========================================================================*/
43 /* Driver local definitions. */
44 /*===========================================================================*/
45 
46 /**
47  * @brief Non-blocking input queue read.
48  * @details The function reads data from an input queue into a buffer. The
49  * operation completes when the specified amount of data has been
50  * transferred or when the input queue has been emptied.
51  *
52  * @param[in] iqp pointer to an @p input_queue_t structure
53  * @param[out] bp pointer to the data buffer
54  * @param[in] n the maximum amount of data to be transferred, the
55  * value 0 is reserved
56  * @return The number of bytes effectively transferred.
57  *
58  * @notapi
59  */
60 static size_t iq_read(input_queue_t *iqp, uint8_t *bp, size_t n) {
61  size_t s1, s2;
62 
63  osalDbgCheck(n > 0U);
64 
65  /* Number of bytes that can be read in a single atomic operation.*/
66  if (n > iqGetFullI(iqp)) {
67  n = iqGetFullI(iqp);
68  }
69 
70  /* Number of bytes before buffer limit.*/
71  /*lint -save -e9033 [10.8] Checked to be safe.*/
72  s1 = (size_t)(iqp->q_top - iqp->q_rdptr);
73  /*lint -restore*/
74  if (n < s1) {
75  memcpy((void *)bp, (void *)iqp->q_rdptr, n);
76  iqp->q_rdptr += n;
77  }
78  else if (n > s1) {
79  memcpy((void *)bp, (void *)iqp->q_rdptr, s1);
80  bp += s1;
81  s2 = n - s1;
82  memcpy((void *)bp, (void *)iqp->q_buffer, s2);
83  iqp->q_rdptr = iqp->q_buffer + s2;
84  }
85  else { /* n == s1 */
86  memcpy((void *)bp, (void *)iqp->q_rdptr, n);
87  iqp->q_rdptr = iqp->q_buffer;
88  }
89 
90  iqp->q_counter -= n;
91  return n;
92 }
93 
94 /**
95  * @brief Non-blocking output queue write.
96  * @details The function writes data from a buffer to an output queue. The
97  * operation completes when the specified amount of data has been
98  * transferred or when the output queue has been filled.
99  *
100  * @param[in] oqp pointer to an @p output_queue_t structure
101  * @param[in] bp pointer to the data buffer
102  * @param[in] n the maximum amount of data to be transferred, the
103  * value 0 is reserved
104  * @return The number of bytes effectively transferred.
105  *
106  * @notapi
107  */
108 static size_t oq_write(output_queue_t *oqp, const uint8_t *bp, size_t n) {
109  size_t s1, s2;
110 
111  osalDbgCheck(n > 0U);
112 
113  /* Number of bytes that can be written in a single atomic operation.*/
114  if (n > oqGetEmptyI(oqp)) {
115  n = oqGetEmptyI(oqp);
116  }
117 
118  /* Number of bytes before buffer limit.*/
119  /*lint -save -e9033 [10.8] Checked to be safe.*/
120  s1 = (size_t)(oqp->q_top - oqp->q_wrptr);
121  /*lint -restore*/
122  if (n < s1) {
123  memcpy((void *)oqp->q_wrptr, (const void *)bp, n);
124  oqp->q_wrptr += n;
125  }
126  else if (n > s1) {
127  memcpy((void *)oqp->q_wrptr, (const void *)bp, s1);
128  bp += s1;
129  s2 = n - s1;
130  memcpy((void *)oqp->q_buffer, (const void *)bp, s2);
131  oqp->q_wrptr = oqp->q_buffer + s2;
132  }
133  else { /* n == s1 */
134  memcpy((void *)oqp->q_wrptr, (const void *)bp, n);
135  oqp->q_wrptr = oqp->q_buffer;
136  }
137 
138  oqp->q_counter -= n;
139  return n;
140 }
141 
142 /*===========================================================================*/
143 /* Driver exported variables. */
144 /*===========================================================================*/
145 
146 /*===========================================================================*/
147 /* Driver local variables and types. */
148 /*===========================================================================*/
149 
150 /*===========================================================================*/
151 /* Driver local functions. */
152 /*===========================================================================*/
153 
154 /*===========================================================================*/
155 /* Driver interrupt handlers. */
156 /*===========================================================================*/
157 
158 /*===========================================================================*/
159 /* Driver exported functions. */
160 /*===========================================================================*/
161 
162 /**
163  * @brief Initializes an input queue.
164  * @details A Semaphore is internally initialized and works as a counter of
165  * the bytes contained in the queue.
166  * @note The callback is invoked from within the S-Locked system state.
167  *
168  * @param[out] iqp pointer to an @p input_queue_t structure
169  * @param[in] bp pointer to a memory area allocated as queue buffer
170  * @param[in] size size of the queue buffer
171  * @param[in] infy pointer to a callback function that is invoked when
172  * data is read from the queue. The value can be @p NULL.
173  * @param[in] link application defined pointer
174  *
175  * @init
176  */
177 void iqObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
178  qnotify_t infy, void *link) {
179 
181  iqp->q_counter = 0;
182  iqp->q_buffer = bp;
183  iqp->q_rdptr = bp;
184  iqp->q_wrptr = bp;
185  iqp->q_top = bp + size;
186  iqp->q_notify = infy;
187  iqp->q_link = link;
188 }
189 
190 /**
191  * @brief Resets an input queue.
192  * @details All the data in the input queue is erased and lost, any waiting
193  * thread is resumed with status @p MSG_RESET.
194  * @note A reset operation can be used by a low level driver in order to
195  * obtain immediate attention from the high level layers.
196  *
197  * @param[in] iqp pointer to an @p input_queue_t structure
198  *
199  * @iclass
200  */
202 
204 
205  iqp->q_rdptr = iqp->q_buffer;
206  iqp->q_wrptr = iqp->q_buffer;
207  iqp->q_counter = 0;
208  osalThreadDequeueAllI(&iqp->q_waiting, MSG_RESET);
209 }
210 
211 /**
212  * @brief Input queue write.
213  * @details A byte value is written into the low end of an input queue. The
214  * operation completes immediately.
215  *
216  * @param[in] iqp pointer to an @p input_queue_t structure
217  * @param[in] b the byte value to be written in the queue
218  * @return The operation status.
219  * @retval MSG_OK if the operation has been completed with success.
220  * @retval MSG_TIMEOUT if the queue is full.
221  *
222  * @iclass
223  */
224 msg_t iqPutI(input_queue_t *iqp, uint8_t b) {
225 
227 
228  /* Queue space check.*/
229  if (!iqIsFullI(iqp)) {
230  iqp->q_counter++;
231  *iqp->q_wrptr++ = b;
232  if (iqp->q_wrptr >= iqp->q_top) {
233  iqp->q_wrptr = iqp->q_buffer;
234  }
235 
236  osalThreadDequeueNextI(&iqp->q_waiting, MSG_OK);
237 
238  return MSG_OK;
239  }
240 
241  return MSG_TIMEOUT;
242 }
243 
244 /**
245  * @brief Input queue non-blocking read.
246  * @details This function reads a byte value from an input queue. The
247  * operation completes immediately.
248  * @note The callback is invoked after removing a character from the
249  * queue.
250  *
251  * @param[in] iqp pointer to an @p input_queue_t structure
252  * @return A byte value from the queue.
253  * @retval MSG_TIMEOUT if the queue is empty.
254  * @retval MSG_RESET if the queue has been reset.
255  *
256  * @iclass
257  */
259 
261 
262  /* Queue data check.*/
263  if (!iqIsEmptyI(iqp)) {
264  uint8_t b;
265 
266  /* Getting the character from the queue.*/
267  iqp->q_counter--;
268  b = *iqp->q_rdptr++;
269  if (iqp->q_rdptr >= iqp->q_top) {
270  iqp->q_rdptr = iqp->q_buffer;
271  }
272 
273  /* Inform the low side that the queue has at least one slot available.*/
274  if (iqp->q_notify != NULL) {
275  iqp->q_notify(iqp);
276  }
277 
278  return (msg_t)b;
279  }
280 
281  return MSG_TIMEOUT;
282 }
283 
284 /**
285  * @brief Input queue read with timeout.
286  * @details This function reads a byte value from an input queue. If the queue
287  * is empty then the calling thread is suspended until a byte arrives
288  * in the queue or a timeout occurs.
289  * @note The callback is invoked after removing a character from the
290  * queue.
291  *
292  * @param[in] iqp pointer to an @p input_queue_t structure
293  * @param[in] timeout the number of ticks before the operation timeouts,
294  * the following special values are allowed:
295  * - @a TIME_IMMEDIATE immediate timeout.
296  * - @a TIME_INFINITE no timeout.
297  * .
298  * @return A byte value from the queue.
299  * @retval MSG_TIMEOUT if the specified time expired.
300  * @retval MSG_RESET if the queue has been reset.
301  *
302  * @api
303  */
305  uint8_t b;
306 
307  osalSysLock();
308 
309  /* Waiting until there is a character available or a timeout occurs.*/
310  while (iqIsEmptyI(iqp)) {
311  msg_t msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout);
312  if (msg < MSG_OK) {
313  osalSysUnlock();
314  return msg;
315  }
316  }
317 
318  /* Getting the character from the queue.*/
319  iqp->q_counter--;
320  b = *iqp->q_rdptr++;
321  if (iqp->q_rdptr >= iqp->q_top) {
322  iqp->q_rdptr = iqp->q_buffer;
323  }
324 
325  /* Inform the low side that the queue has at least one slot available.*/
326  if (iqp->q_notify != NULL) {
327  iqp->q_notify(iqp);
328  }
329 
330  osalSysUnlock();
331 
332  return (msg_t)b;
333 }
334 
335 /**
336  * @brief Input queue non-blocking read.
337  * @details The function reads data from an input queue into a buffer. The
338  * operation completes immediately.
339  *
340  * @param[in] iqp pointer to an @p input_queue_t structure
341  * @param[out] bp pointer to the data buffer
342  * @param[in] n the maximum amount of data to be transferred, the
343  * value 0 is reserved
344  * @return The number of bytes effectively transferred.
345  *
346  * @iclass
347  */
348 size_t iqReadI(input_queue_t *iqp, uint8_t *bp, size_t n) {
349  qnotify_t nfy = iqp->q_notify;
350  size_t rd;
351 
353 
354  rd = iq_read(iqp, bp, n);
355 
356  /* Inform the low side that the queue has at least one character
357  available.*/
358  if ((rd > (size_t)0) && (nfy != NULL)) {
359  nfy(iqp);
360  }
361 
362  return rd;
363 }
364 
365 /**
366  * @brief Input queue read with timeout.
367  * @details The function reads data from an input queue into a buffer. The
368  * operation completes when the specified amount of data has been
369  * transferred or after the specified timeout or if the queue has
370  * been reset.
371  * @note The function is not atomic, if you need atomicity it is suggested
372  * to use a semaphore or a mutex for mutual exclusion.
373  * @note The callback is invoked after removing each character from the
374  * queue.
375  *
376  * @param[in] iqp pointer to an @p input_queue_t structure
377  * @param[out] bp pointer to the data buffer
378  * @param[in] n the maximum amount of data to be transferred, the
379  * value 0 is reserved
380  * @param[in] timeout the number of ticks before the operation timeouts,
381  * the following special values are allowed:
382  * - @a TIME_IMMEDIATE immediate timeout.
383  * - @a TIME_INFINITE no timeout.
384  * .
385  * @return The number of bytes effectively transferred.
386  *
387  * @api
388  */
389 size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
390  size_t n, sysinterval_t timeout) {
391  qnotify_t nfy = iqp->q_notify;
392  size_t max = n;
393 
394  osalDbgCheck(n > 0U);
395 
396  osalSysLock();
397 
398  while (n > 0U) {
399  size_t done;
400 
401  done = iq_read(iqp, bp, n);
402  if (done == (size_t)0) {
403  msg_t msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout);
404 
405  /* Anything except MSG_OK causes the operation to stop.*/
406  if (msg != MSG_OK) {
407  break;
408  }
409  }
410  else {
411  /* Inform the low side that the queue has at least one empty slot
412  available.*/
413  if (nfy != NULL) {
414  nfy(iqp);
415  }
416 
417  /* Giving a preemption chance in a controlled point.*/
418  osalSysUnlock();
419 
420  n -= done;
421  bp += done;
422 
423  osalSysLock();
424  }
425  }
426 
427  osalSysUnlock();
428  return max - n;
429 }
430 
431 /**
432  * @brief Initializes an output queue.
433  * @details A Semaphore is internally initialized and works as a counter of
434  * the free bytes in the queue.
435  * @note The callback is invoked from within the S-Locked system state.
436  *
437  * @param[out] oqp pointer to an @p output_queue_t structure
438  * @param[in] bp pointer to a memory area allocated as queue buffer
439  * @param[in] size size of the queue buffer
440  * @param[in] onfy pointer to a callback function that is invoked when
441  * data is written to the queue. The value can be @p NULL.
442  * @param[in] link application defined pointer
443  *
444  * @init
445  */
446 void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
447  qnotify_t onfy, void *link) {
448 
450  oqp->q_counter = size;
451  oqp->q_buffer = bp;
452  oqp->q_rdptr = bp;
453  oqp->q_wrptr = bp;
454  oqp->q_top = bp + size;
455  oqp->q_notify = onfy;
456  oqp->q_link = link;
457 }
458 
459 /**
460  * @brief Resets an output queue.
461  * @details All the data in the output queue is erased and lost, any waiting
462  * thread is resumed with status @p MSG_RESET.
463  * @note A reset operation can be used by a low level driver in order to
464  * obtain immediate attention from the high level layers.
465  *
466  * @param[in] oqp pointer to an @p output_queue_t structure
467  *
468  * @iclass
469  */
471 
473 
474  oqp->q_rdptr = oqp->q_buffer;
475  oqp->q_wrptr = oqp->q_buffer;
476  oqp->q_counter = qSizeX(oqp);
477  osalThreadDequeueAllI(&oqp->q_waiting, MSG_RESET);
478 }
479 
480 /**
481  * @brief Output queue non-blocking write.
482  * @details This function writes a byte value to an output queue. The
483  * operation completes immediately.
484  *
485  * @param[in] oqp pointer to an @p output_queue_t structure
486  * @param[in] b the byte value to be written in the queue
487  * @return The operation status.
488  * @retval MSG_OK if the operation succeeded.
489  * @retval MSG_TIMEOUT if the queue is full.
490  * @retval MSG_RESET if the queue has been reset.
491  *
492  * @iclass
493  */
494 msg_t oqPutI(output_queue_t *oqp, uint8_t b) {
495 
497 
498  /* Queue space check.*/
499  while (!oqIsFullI(oqp)) {
500  /* Putting the character into the queue.*/
501  oqp->q_counter--;
502  *oqp->q_wrptr++ = b;
503  if (oqp->q_wrptr >= oqp->q_top) {
504  oqp->q_wrptr = oqp->q_buffer;
505  }
506 
507  /* Inform the low side that the queue has at least one character available.*/
508  if (oqp->q_notify != NULL) {
509  oqp->q_notify(oqp);
510  }
511 
512  return MSG_OK;
513  }
514 
515  return MSG_TIMEOUT;
516 }
517 
518 /**
519  * @brief Output queue write with timeout.
520  * @details This function writes a byte value to an output queue. If the queue
521  * is full then the calling thread is suspended until there is space
522  * in the queue or a timeout occurs.
523  * @note The callback is invoked after putting the character into the
524  * queue.
525  *
526  * @param[in] oqp pointer to an @p output_queue_t structure
527  * @param[in] b the byte value to be written in the queue
528  * @param[in] timeout the number of ticks before the operation timeouts,
529  * the following special values are allowed:
530  * - @a TIME_IMMEDIATE immediate timeout.
531  * - @a TIME_INFINITE no timeout.
532  * .
533  * @return The operation status.
534  * @retval MSG_OK if the operation succeeded.
535  * @retval MSG_TIMEOUT if the specified time expired.
536  * @retval MSG_RESET if the queue has been reset.
537  *
538  * @api
539  */
540 msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout) {
541 
542  osalSysLock();
543 
544  /* Waiting until there is a slot available or a timeout occurs.*/
545  while (oqIsFullI(oqp)) {
546  msg_t msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout);
547  if (msg < MSG_OK) {
548  osalSysUnlock();
549  return msg;
550  }
551  }
552 
553  /* Putting the character into the queue.*/
554  oqp->q_counter--;
555  *oqp->q_wrptr++ = b;
556  if (oqp->q_wrptr >= oqp->q_top) {
557  oqp->q_wrptr = oqp->q_buffer;
558  }
559 
560  /* Inform the low side that the queue has at least one character available.*/
561  if (oqp->q_notify != NULL) {
562  oqp->q_notify(oqp);
563  }
564 
565  osalSysUnlock();
566 
567  return MSG_OK;
568 }
569 
570 /**
571  * @brief Output queue read.
572  * @details A byte value is read from the low end of an output queue. The
573  * operation completes immediately.
574  *
575  * @param[in] oqp pointer to an @p output_queue_t structure
576  * @return The byte value from the queue.
577  * @retval MSG_TIMEOUT if the queue is empty.
578  *
579  * @iclass
580  */
582 
584 
585  /* Queue data check.*/
586  if (!oqIsEmptyI(oqp)) {
587  uint8_t b;
588 
589  oqp->q_counter++;
590  b = *oqp->q_rdptr++;
591  if (oqp->q_rdptr >= oqp->q_top) {
592  oqp->q_rdptr = oqp->q_buffer;
593  }
594 
595  osalThreadDequeueNextI(&oqp->q_waiting, MSG_OK);
596 
597  return (msg_t)b;
598  }
599 
600  return MSG_TIMEOUT;
601 }
602 
603 
604 /**
605  * @brief Output queue non-blocking write.
606  * @details The function writes data from a buffer to an output queue. The
607  * operation completes immediately.
608  *
609  * @param[in] oqp pointer to an @p output_queue_t structure
610  * @param[in] bp pointer to the data buffer
611  * @param[in] n the maximum amount of data to be transferred, the
612  * value 0 is reserved
613  * @return The number of bytes effectively transferred.
614  *
615  * @iclass
616  */
617 size_t oqWriteI(output_queue_t *oqp, const uint8_t *bp, size_t n) {
618  qnotify_t nfy = oqp->q_notify;
619  size_t wr;
620 
622 
623  wr = oq_write(oqp, bp, n);
624 
625  /* Inform the low side that the queue has at least one character
626  available.*/
627  if ((wr > (size_t)0) && (nfy != NULL)) {
628  nfy(oqp);
629  }
630 
631  return wr;
632 }
633 
634 /**
635  * @brief Output queue write with timeout.
636  * @details The function writes data from a buffer to an output queue. The
637  * operation completes when the specified amount of data has been
638  * transferred or after the specified timeout or if the queue has
639  * been reset.
640  * @note The function is not atomic, if you need atomicity it is suggested
641  * to use a semaphore or a mutex for mutual exclusion.
642  * @note The callback is invoked after putting each character into the
643  * queue.
644  *
645  * @param[in] oqp pointer to an @p output_queue_t structure
646  * @param[in] bp pointer to the data buffer
647  * @param[in] n the maximum amount of data to be transferred, the
648  * value 0 is reserved
649  * @param[in] timeout the number of ticks before the operation timeouts,
650  * the following special values are allowed:
651  * - @a TIME_IMMEDIATE immediate timeout.
652  * - @a TIME_INFINITE no timeout.
653  * .
654  * @return The number of bytes effectively transferred.
655  *
656  * @api
657  */
658 size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
659  size_t n, sysinterval_t timeout) {
660  qnotify_t nfy = oqp->q_notify;
661  size_t max = n;
662 
663  osalDbgCheck(n > 0U);
664 
665  osalSysLock();
666 
667  while (n > 0U) {
668  size_t done;
669 
670  done = oq_write(oqp, bp, n);
671  if (done == (size_t)0) {
672  msg_t msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout);
673 
674  /* Anything except MSG_OK causes the operation to stop.*/
675  if (msg != MSG_OK) {
676  break;
677  }
678  }
679  else {
680  /* Inform the low side that the queue has at least one character
681  available.*/
682  if (nfy != NULL) {
683  nfy(oqp);
684  }
685 
686  /* Giving a preemption chance in a controlled point.*/
687  osalSysUnlock();
688 
689  n -= done;
690  bp += done;
691 
692  osalSysLock();
693  }
694  }
695 
696  osalSysUnlock();
697  return max - n;
698 }
699 
700 /** @} */
Generic I/O queue structure.
Definition: hal_queues.h:75
void iqObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size, qnotify_t infy, void *link)
Initializes an input queue.
Definition: hal_queues.c:177
msg_t iqGetTimeout(input_queue_t *iqp, sysinterval_t timeout)
Input queue read with timeout.
Definition: hal_queues.c:304
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the queue.
Definition: osal.c:309
#define oqIsEmptyI(oqp)
Evaluates to true if the specified output queue is empty.
Definition: hal_queues.h:261
void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size, qnotify_t onfy, void *link)
Initializes an output queue.
Definition: hal_queues.c:446
size_t iqReadI(input_queue_t *iqp, uint8_t *bp, size_t n)
Input queue non-blocking read.
Definition: hal_queues.c:348
uint8_t * q_wrptr
Write pointer.
Definition: hal_queues.h:81
#define iqIsEmptyI(iqp)
Evaluates to true if the specified input queue is empty.
Definition: hal_queues.h:198
void iqResetI(input_queue_t *iqp)
Resets an input queue.
Definition: hal_queues.c:201
static size_t iq_read(input_queue_t *iqp, uint8_t *bp, size_t n)
Non-blocking input queue read.
Definition: hal_queues.c:60
HAL subsystem header.
#define osalDbgCheckClassI()
I-Class state check.
Definition: osal.h:292
#define iqIsFullI(iqp)
Evaluates to true if the specified input queue is full.
Definition: hal_queues.h:210
void oqResetI(output_queue_t *oqp)
Resets an output queue.
Definition: hal_queues.c:470
#define qSizeX(qp)
Returns the queue&#39;s buffer size.
Definition: hal_queues.h:127
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:540
uint8_t * q_top
Pointer to the first location after the buffer.
Definition: hal_queues.h:79
threads_queue_t q_waiting
Queue of waiting threads.
Definition: hal_queues.h:76
#define iqGetFullI(iqp)
Returns the filled space into an input queue.
Definition: hal_queues.h:175
#define oqGetEmptyI(oqp)
Returns the empty space into an output queue.
Definition: hal_queues.h:249
int32_t msg_t
Type of a message.
Definition: osal.h:160
void(* qnotify_t)(io_queue_t *qp)
Queue notification callback type.
Definition: hal_queues.h:65
void * q_link
Application defined field.
Definition: hal_queues.h:84
size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp, size_t n, sysinterval_t timeout)
Output queue write with timeout.
Definition: hal_queues.c:658
uint8_t * q_buffer
Pointer to the queue buffer.
Definition: hal_queues.h:78
#define oqIsFullI(oqp)
Evaluates to true if the specified output queue is full.
Definition: hal_queues.h:276
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout)
Output queue write with timeout.
Definition: hal_queues.c:540
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:278
uint32_t sysinterval_t
Type of system time interval.
Definition: osal.h:170
static size_t oq_write(output_queue_t *oqp, const uint8_t *bp, size_t n)
Non-blocking output queue write.
Definition: hal_queues.c:108
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the queue, if any.
Definition: osal.c:294
msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread.
Definition: osal.c:277
msg_t oqGetI(output_queue_t *oqp)
Output queue read.
Definition: hal_queues.c:581
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:530
msg_t oqPutI(output_queue_t *oqp, uint8_t b)
Output queue non-blocking write.
Definition: hal_queues.c:494
msg_t iqPutI(input_queue_t *iqp, uint8_t b)
Input queue write.
Definition: hal_queues.c:224
volatile size_t q_counter
Resources counter.
Definition: hal_queues.h:77
uint8_t * q_rdptr
Read pointer.
Definition: hal_queues.h:82
qnotify_t q_notify
Data notification callback.
Definition: hal_queues.h:83
msg_t iqGetI(input_queue_t *iqp)
Input queue non-blocking read.
Definition: hal_queues.c:258
size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp, size_t n, sysinterval_t timeout)
Input queue read with timeout.
Definition: hal_queues.c:389
size_t oqWriteI(output_queue_t *oqp, const uint8_t *bp, size_t n)
Output queue non-blocking write.
Definition: hal_queues.c:617
static void osalThreadQueueObjectInit(threads_queue_t *tqp)
Initializes a threads queue object.
Definition: osal.h:653