Changeset 49698fa in mainline for uspace/drv/ns8250/cyclic_buffer.h
- Timestamp:
- 2010-10-23T10:25:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 663f41c4
- Parents:
- 472020fc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ns8250/cyclic_buffer.h
r472020fc r49698fa 1 1 /* 2 * Copyright (c) 2010 Lenka Trochtova 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. 4 4 * … … 32 32 /** @file 33 33 */ 34 35 #ifndef CYCLIC_BUFFER_H36 #define CYCLIC_BUFFER_H37 34 38 #define BUF_LEN 256 // the length of the buffer 35 #ifndef CYCLIC_BUFFER_H_ 36 #define CYCLIC_BUFFER_H_ 37 38 #define BUF_LEN 256 39 39 40 40 typedef struct cyclic_buffer { 41 uint8_t buf[BUF_LEN]; // the buffer41 uint8_t buf[BUF_LEN]; 42 42 int start; 43 43 int cnt; 44 } cyclic_buffer_t; 44 } cyclic_buffer_t; 45 45 46 // returns false if the buffer is full 47 static inline bool buf_push_back(cyclic_buffer_t *buf, uint8_t item) 46 /* 47 * @returns False if the buffer is full. 48 */ 49 static inline bool buf_push_back(cyclic_buffer_t *buf, uint8_t item) 48 50 { 49 if (buf->cnt >= BUF_LEN) {51 if (buf->cnt >= BUF_LEN) 50 52 return false; 51 }52 53 53 int pos = (buf->start + buf->cnt) % BUF_LEN; 54 54 buf->buf[pos] = item; … … 57 57 } 58 58 59 static inline bool buf_is_empty(cyclic_buffer_t *buf) 59 static inline bool buf_is_empty(cyclic_buffer_t *buf) 60 60 { 61 61 return buf->cnt == 0; 62 62 } 63 63 64 // call it on non empty buffer! 65 static inline uint8_t buf_pop_front(cyclic_buffer_t *buf) 64 static inline uint8_t buf_pop_front(cyclic_buffer_t *buf) 66 65 { 67 66 assert(!buf_is_empty(buf)); 68 67 69 68 uint8_t res = buf->buf[buf->start]; 70 buf->start = (buf->start + 1) % BUF_LEN; 69 buf->start = (buf->start + 1) % BUF_LEN; 71 70 buf->cnt--; 72 71 return res; 73 72 } 74 73 75 static inline void buf_clear(cyclic_buffer_t *buf) 74 static inline void buf_clear(cyclic_buffer_t *buf) 76 75 { 77 76 buf->cnt = 0;
Note:
See TracChangeset
for help on using the changeset viewer.