Changeset 8b863a62 in mainline for uspace/drv/char/grlib_uart/cyclic_buffer.h
- Timestamp:
- 2014-04-16T17:14:06Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f857e8b
- Parents:
- dba3e2c (diff), 70b570c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/grlib_uart/cyclic_buffer.h
rdba3e2c r8b863a62 1 1 /* 2 * Copyright (c) 201 1 Jiri Michalec2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc29 /** @addtogroup ns8250 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef LIBC_DEVICE_PCI_H_36 #define LIBC_DEVICE_PCI_H_35 #ifndef CYCLIC_BUFFER_H_ 36 #define CYCLIC_BUFFER_H_ 37 37 38 # include <async.h>38 #define BUF_LEN 4096 39 39 40 #define PCI_DEVICE_ID 0x02 40 typedef struct cyclic_buffer { 41 uint8_t buf[BUF_LEN]; 42 int start; 43 int cnt; 44 } cyclic_buffer_t; 41 45 42 typedef enum { 43 IPC_M_CONFIG_SPACE_READ_8, 44 IPC_M_CONFIG_SPACE_READ_16, 45 IPC_M_CONFIG_SPACE_READ_32, 46 /* 47 * @return False if the buffer is full. 48 */ 49 static inline bool buf_push_back(cyclic_buffer_t *buf, uint8_t item) 50 { 51 if (buf->cnt >= BUF_LEN) 52 return false; 46 53 47 IPC_M_CONFIG_SPACE_WRITE_8, 48 IPC_M_CONFIG_SPACE_WRITE_16, 49 IPC_M_CONFIG_SPACE_WRITE_32 50 } pci_dev_iface_funcs_t; 54 int pos = (buf->start + buf->cnt) % BUF_LEN; 55 buf->buf[pos] = item; 56 buf->cnt++; 57 return true; 58 } 51 59 52 extern int pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *); 53 extern int pci_config_space_read_16(async_sess_t *, uint32_t, uint16_t *); 54 extern int pci_config_space_read_32(async_sess_t *, uint32_t, uint32_t *); 60 static inline bool buf_is_empty(cyclic_buffer_t *buf) 61 { 62 return buf->cnt == 0; 63 } 55 64 56 extern int pci_config_space_write_8(async_sess_t *, uint32_t, uint8_t); 57 extern int pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t); 58 extern int pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t); 65 static inline uint8_t buf_pop_front(cyclic_buffer_t *buf) 66 { 67 assert(!buf_is_empty(buf)); 68 69 uint8_t res = buf->buf[buf->start]; 70 buf->start = (buf->start + 1) % BUF_LEN; 71 buf->cnt--; 72 return res; 73 } 74 75 static inline void buf_clear(cyclic_buffer_t *buf) 76 { 77 buf->cnt = 0; 78 } 59 79 60 80 #endif 61 81 62 /** @} 82 /** 83 * @} 63 84 */
Note:
See TracChangeset
for help on using the changeset viewer.