Changeset ac307b2 in mainline for uspace/lib/c


Ignore:
Timestamp:
2017-11-25T11:12:23Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98cb5e0d
Parents:
f571ca49 (diff), 0851a3d (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 branch 'master' into callcaps

Location:
uspace/lib/c
Files:
1 added
6 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rf571ca49 rac307b2  
    143143        generic/getopt.c \
    144144        generic/adt/checksum.c \
     145        generic/adt/circ_buf.c \
    145146        generic/adt/list.c \
    146147        generic/adt/hash_table.c \
     
    181182
    182183TEST_SOURCES = \
     184        test/adt/circ_buf.c \
    183185        test/fibril/timer.c \
    184186        test/main.c \
  • uspace/lib/c/generic/io/chardev_srv.c

    rf571ca49 rac307b2  
    169169                        break;
    170170                default:
    171                         async_answer_0(callid, EINVAL);
     171                        if (srv->srvs->ops->def_handler != NULL)
     172                                srv->srvs->ops->def_handler(srv, callid, &call);
     173                        else
     174                                async_answer_0(callid, ENOTSUP);
    172175                }
    173176        }
  • uspace/lib/c/include/adt/circ_buf.h

    rf571ca49 rac307b2  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2017 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libcipc
     29/** @addtogroup libc
    3030 * @{
    3131 */
    32 /** @file
    33  * @brief Character device interface.
     32/** @file Circular buffer
    3433 */
    3534
    36 #ifndef LIBC_IPC_CHAR_H_
    37 #define LIBC_IPC_CHAR_H_
     35#ifndef LIBC_CIRC_BUF_H_
     36#define LIBC_CIRC_BUF_H_
    3837
    39 #include <ipc/common.h>
     38#include <stddef.h>
    4039
    41 typedef enum {
    42         CHAR_WRITE_BYTE = IPC_FIRST_USER_METHOD
    43 } char_request_t;
     40/** Circular buffer */
     41typedef struct {
     42        /** Buffer */
     43        void *buf;
     44        /** Number of buffer members */
     45        size_t nmemb;
     46        /** Member size */
     47        size_t size;
     48        /** Read position */
     49        size_t rp;
     50        /** Write position */
     51        size_t wp;
     52        /** Number of used entries */
     53        size_t nused;
     54} circ_buf_t;
    4455
    45 typedef enum {
    46         CHAR_NOTIF_BYTE = IPC_FIRST_USER_METHOD
    47 } char_notif_t;
     56extern void circ_buf_init(circ_buf_t *, void *, size_t, size_t);
     57extern size_t circ_buf_nfree(circ_buf_t *);
     58extern size_t circ_buf_nused(circ_buf_t *);
     59extern int circ_buf_push(circ_buf_t *, const void *);
     60extern int circ_buf_pop(circ_buf_t *, void *);
    4861
    4962#endif
  • uspace/lib/c/include/io/chardev_srv.h

    rf571ca49 rac307b2  
    6161        int (*read)(chardev_srv_t *, void *, size_t, size_t *);
    6262        int (*write)(chardev_srv_t *, const void *, size_t, size_t *);
     63        void (*def_handler)(chardev_srv_t *, ipc_callid_t, ipc_call_t *);
    6364};
    6465
  • uspace/lib/c/include/ipc/chardev.h

    rf571ca49 rac307b2  
    4141typedef enum {
    4242        CHARDEV_READ = IPC_FIRST_USER_METHOD,
    43         CHARDEV_WRITE
     43        CHARDEV_WRITE,
    4444} chardev_request_t;
     45
     46enum {
     47        CHARDEV_LIMIT = CHARDEV_WRITE + 1
     48};
    4549
    4650#endif
  • uspace/lib/c/include/ipc/serial_ctl.h

    rf571ca49 rac307b2  
    3030#define LIBC_IPC_SERIAL_CTL_H_
    3131
    32 #include <ipc/dev_iface.h>
     32#include <ipc/chardev.h>
    3333
    3434/** IPC methods for getting/setting serial communication properties
     
    4141 */
    4242typedef enum {
    43         SERIAL_GET_COM_PROPS = DEV_FIRST_CUSTOM_METHOD,
     43        SERIAL_GET_COM_PROPS = CHARDEV_LIMIT,
    4444        SERIAL_SET_COM_PROPS
    4545} serial_ctl_t;
  • uspace/lib/c/test/adt/circ_buf.c

    rf571ca49 rac307b2  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2017 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @file
     29#include <adt/circ_buf.h>
     30#include <pcut/pcut.h>
     31
     32PCUT_INIT
     33
     34PCUT_TEST_SUITE(circ_buf);
     35
     36enum {
     37        buffer_size = 16
     38};
     39
     40static int buffer[buffer_size];
     41
     42/** Basic insertion/deletion test.
     43 *
     44 * Test initialization, emptiness, pushing buffer until it is full,
     45 * then emptying it again.
    3046 */
     47PCUT_TEST(push_pop)
     48{
     49        circ_buf_t cbuf;
     50        int i;
     51        int j;
     52        int rc;
    3153
    32 #include <assert.h>
    33 #include <errno.h>
    34 #include <mem.h>
    35 #include <ops/char_dev.h>
     54        circ_buf_init(&cbuf, buffer, buffer_size, sizeof(int));
    3655
    37 #include "test1.h"
     56        for (i = 0; i < buffer_size; i++) {
     57                PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nfree(&cbuf));
     58                PCUT_ASSERT_INT_EQUALS(i, circ_buf_nused(&cbuf));
     59                rc = circ_buf_push(&cbuf, &i);
     60                PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     61        }
    3862
    39 static int impl_char_read(ddf_fun_t *fun, char *buf, size_t count) {
    40         memset(buf, 0, count);
    41         return count;
     63        rc = circ_buf_push(&cbuf, &i);
     64        PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
     65
     66        for (i = 0; i < buffer_size; i++) {
     67                PCUT_ASSERT_INT_EQUALS(i, circ_buf_nfree(&cbuf));
     68                PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nused(&cbuf));
     69                rc = circ_buf_pop(&cbuf, &j);
     70                PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     71                PCUT_ASSERT_INT_EQUALS(i, j);
     72        }
     73
     74        PCUT_ASSERT_INT_EQUALS(buffer_size, circ_buf_nfree(&cbuf));
     75        PCUT_ASSERT_INT_EQUALS(0, circ_buf_nused(&cbuf));
     76
     77        rc = circ_buf_pop(&cbuf, &j);
     78        PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
    4279}
    4380
    44 static int imp_char_write(ddf_fun_t *fun, char *buf, size_t count) {
    45         return count;
    46 }
    47 
    48 static char_dev_ops_t char_dev_ops = {
    49         .read = &impl_char_read,
    50         .write = &imp_char_write
    51 };
    52 
    53 ddf_dev_ops_t char_device_ops = {
    54         .interfaces[CHAR_DEV_IFACE] = &char_dev_ops
    55 };
    56 
     81PCUT_EXPORT(circ_buf);
  • uspace/lib/c/test/main.c

    rf571ca49 rac307b2  
    3232PCUT_INIT
    3333
     34PCUT_IMPORT(circ_buf);
    3435PCUT_IMPORT(fibril_timer);
    3536PCUT_IMPORT(odict);
Note: See TracChangeset for help on using the changeset viewer.