Changeset ac307b2 in mainline for uspace/lib/c
- Timestamp:
- 2017-11-25T11:12:23Z (8 years ago)
- 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. - Location:
- uspace/lib/c
- Files:
-
- 1 added
- 6 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
rf571ca49 rac307b2 143 143 generic/getopt.c \ 144 144 generic/adt/checksum.c \ 145 generic/adt/circ_buf.c \ 145 146 generic/adt/list.c \ 146 147 generic/adt/hash_table.c \ … … 181 182 182 183 TEST_SOURCES = \ 184 test/adt/circ_buf.c \ 183 185 test/fibril/timer.c \ 184 186 test/main.c \ -
uspace/lib/c/generic/io/chardev_srv.c
rf571ca49 rac307b2 169 169 break; 170 170 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); 172 175 } 173 176 } -
uspace/lib/c/include/adt/circ_buf.h
rf571ca49 rac307b2 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc ipc29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 /** @file 33 * @brief Character device interface. 32 /** @file Circular buffer 34 33 */ 35 34 36 #ifndef LIBC_ IPC_CHAR_H_37 #define LIBC_ IPC_CHAR_H_35 #ifndef LIBC_CIRC_BUF_H_ 36 #define LIBC_CIRC_BUF_H_ 38 37 39 #include < ipc/common.h>38 #include <stddef.h> 40 39 41 typedef enum { 42 CHAR_WRITE_BYTE = IPC_FIRST_USER_METHOD 43 } char_request_t; 40 /** Circular buffer */ 41 typedef 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; 44 55 45 typedef enum { 46 CHAR_NOTIF_BYTE = IPC_FIRST_USER_METHOD 47 } char_notif_t; 56 extern void circ_buf_init(circ_buf_t *, void *, size_t, size_t); 57 extern size_t circ_buf_nfree(circ_buf_t *); 58 extern size_t circ_buf_nused(circ_buf_t *); 59 extern int circ_buf_push(circ_buf_t *, const void *); 60 extern int circ_buf_pop(circ_buf_t *, void *); 48 61 49 62 #endif -
uspace/lib/c/include/io/chardev_srv.h
rf571ca49 rac307b2 61 61 int (*read)(chardev_srv_t *, void *, size_t, size_t *); 62 62 int (*write)(chardev_srv_t *, const void *, size_t, size_t *); 63 void (*def_handler)(chardev_srv_t *, ipc_callid_t, ipc_call_t *); 63 64 }; 64 65 -
uspace/lib/c/include/ipc/chardev.h
rf571ca49 rac307b2 41 41 typedef enum { 42 42 CHARDEV_READ = IPC_FIRST_USER_METHOD, 43 CHARDEV_WRITE 43 CHARDEV_WRITE, 44 44 } chardev_request_t; 45 46 enum { 47 CHARDEV_LIMIT = CHARDEV_WRITE + 1 48 }; 45 49 46 50 #endif -
uspace/lib/c/include/ipc/serial_ctl.h
rf571ca49 rac307b2 30 30 #define LIBC_IPC_SERIAL_CTL_H_ 31 31 32 #include <ipc/ dev_iface.h>32 #include <ipc/chardev.h> 33 33 34 34 /** IPC methods for getting/setting serial communication properties … … 41 41 */ 42 42 typedef enum { 43 SERIAL_GET_COM_PROPS = DEV_FIRST_CUSTOM_METHOD,43 SERIAL_GET_COM_PROPS = CHARDEV_LIMIT, 44 44 SERIAL_SET_COM_PROPS 45 45 } serial_ctl_t; -
uspace/lib/c/test/adt/circ_buf.c
rf571ca49 rac307b2 1 1 /* 2 * Copyright (c) 201 0 Vojtech Horky2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @file 29 #include <adt/circ_buf.h> 30 #include <pcut/pcut.h> 31 32 PCUT_INIT 33 34 PCUT_TEST_SUITE(circ_buf); 35 36 enum { 37 buffer_size = 16 38 }; 39 40 static 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. 30 46 */ 47 PCUT_TEST(push_pop) 48 { 49 circ_buf_t cbuf; 50 int i; 51 int j; 52 int rc; 31 53 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)); 36 55 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 } 38 62 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); 42 79 } 43 80 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 81 PCUT_EXPORT(circ_buf); -
uspace/lib/c/test/main.c
rf571ca49 rac307b2 32 32 PCUT_INIT 33 33 34 PCUT_IMPORT(circ_buf); 34 35 PCUT_IMPORT(fibril_timer); 35 36 PCUT_IMPORT(odict);
Note:
See TracChangeset
for help on using the changeset viewer.