* @brief Put a byte into the ring buffer. If ring buffer is full, this operation will fail. * * @param rb A pointer to the ring buffer object. * @param ch A byte put into the ring buffer. * * @return Return the data size we put into the ring buffer. The ring buffer is full if returns 0. Otherwise, it will return 1. */
| 270 | * @return Return the data size we put into the ring buffer. The ring buffer is full if returns 0. Otherwise, it will return 1. |
| 271 | */ |
| 272 | rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) |
| 273 | { |
| 274 | RT_ASSERT(rb != RT_NULL); |
| 275 | |
| 276 | /* whether has enough space */ |
| 277 | if (!rt_ringbuffer_space_len(rb)) |
| 278 | return 0; |
| 279 | |
| 280 | rb->buffer_ptr[rb->write_index] = ch; |
| 281 | |
| 282 | /* flip mirror */ |
| 283 | if (rb->write_index == rb->buffer_size - 1) |
| 284 | { |
| 285 | rb->write_mirror = ~rb->write_mirror; |
| 286 | rb->write_index = 0; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | rb->write_index++; |
| 291 | } |
| 292 | |
| 293 | return 1; |
| 294 | } |
| 295 | RTM_EXPORT(rt_ringbuffer_putchar); |
| 296 | |
| 297 | /** |
no outgoing calls