Ignore:
Timestamp:
2014-04-16T17:14:06Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
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.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/grlib_uart/cyclic_buffer.h

    rdba3e2c r8b863a62  
    11/*
    2  * Copyright (c) 2011 Jiri Michalec
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup ns8250
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef LIBC_DEVICE_PCI_H_
    36 #define LIBC_DEVICE_PCI_H_
     35#ifndef CYCLIC_BUFFER_H_
     36#define CYCLIC_BUFFER_H_
    3737
    38 #include <async.h>
     38#define BUF_LEN 4096
    3939
    40 #define PCI_DEVICE_ID  0x02
     40typedef struct cyclic_buffer {
     41        uint8_t buf[BUF_LEN];
     42        int start;
     43        int cnt;
     44}  cyclic_buffer_t;
    4145
    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 */
     49static inline bool buf_push_back(cyclic_buffer_t *buf, uint8_t item)
     50{
     51        if (buf->cnt >= BUF_LEN)
     52                return false;
    4653       
    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}
    5159
    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 *);
     60static inline bool buf_is_empty(cyclic_buffer_t *buf)
     61{
     62        return buf->cnt == 0;
     63}
    5564
    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);
     65static 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
     75static inline void buf_clear(cyclic_buffer_t *buf)
     76{
     77        buf->cnt = 0;
     78}
    5979
    6080#endif
    6181
    62 /** @}
     82/**
     83 * @}
    6384 */
Note: See TracChangeset for help on using the changeset viewer.