* @brief Get a byte from the ring buffer. * * @param rb The pointer to the ring buffer object. * @param ch A pointer to the buffer, used to store one byte. * * @return 0 The ring buffer is empty. * @return 1 Success */
| 344 | * @return 1 Success |
| 345 | */ |
| 346 | rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) |
| 347 | { |
| 348 | RT_ASSERT(rb != RT_NULL); |
| 349 | |
| 350 | /* ringbuffer is empty */ |
| 351 | if (!rt_ringbuffer_data_len(rb)) |
| 352 | return 0; |
| 353 | |
| 354 | /* put byte */ |
| 355 | *ch = rb->buffer_ptr[rb->read_index]; |
| 356 | |
| 357 | if (rb->read_index == rb->buffer_size - 1) |
| 358 | { |
| 359 | rb->read_mirror = ~rb->read_mirror; |
| 360 | rb->read_index = 0; |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | rb->read_index++; |
| 365 | } |
| 366 | |
| 367 | return 1; |
| 368 | } |
| 369 | RTM_EXPORT(rt_ringbuffer_getchar); |
| 370 | |
| 371 | /** |