Changeset ca97cad in mainline for uspace/lib/libc


Ignore:
Timestamp:
2010-05-06T11:42:55Z (15 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab1aa871
Parents:
ba95e8f
Message:

writing to serial port using character interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/device/char.c

    rba95e8f rca97cad  
    4040#include <stdio.h>
    4141
    42 
    43 int read_dev(int dev_phone, void *buf, size_t len)
    44 {       
     42/** Read to or write from the device using its character interface.
     43 *
     44 * Helper function.
     45 *
     46 * @param dev_phone phone to the device.
     47 * @param buf the buffer for the data read from or written to the device.
     48 * @param len the maximum length of the data to be read or written.
     49 * @param read read from the device if true, write to it otherwise.
     50 *
     51 * @return non-negative number of bytes actually read from or written to the device on success,
     52 * negative error number otherwise.
     53 *
     54 */
     55static int rw_dev(int dev_phone, void *buf, size_t len, bool read)
     56{
    4557        ipc_call_t answer;
    4658       
    4759        async_serialize_start();
    4860       
    49         aid_t req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer);
     61        aid_t req;
     62        int rc;
    5063       
    51         int rc = async_data_read_start(dev_phone, buf, len);
     64        if (read) {
     65                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer);
     66                rc = async_data_read_start(dev_phone, buf, len);               
     67        } else {
     68                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_WRITE_DEV, &answer);
     69                rc = async_data_write_start(dev_phone, buf, len);
     70        }
    5271       
    5372        if (rc != EOK) {
     
    7089        }
    7190       
    72         return IPC_GET_ARG1(answer);
     91        return IPC_GET_ARG1(answer);   
    7392}
    7493
     94/** Read from the device using its character interface.
     95 *
     96 * @param dev_phone phone to the device.
     97 * @param buf the output buffer for the data read from the device.
     98 * @param len the maximum length of the data to be read.
     99 *
     100 * @return non-negative number of bytes actually read from the device on success, negative error number otherwise.
     101 */
     102int read_dev(int dev_phone, void *buf, size_t len)
     103{       
     104        return rw_dev(dev_phone, buf, len, true);
     105}
     106
     107/** Write to the device using its character interface.
     108 *
     109 * @param dev_phone phone to the device.
     110 * @param buf the input buffer containg the data to be written to the device.
     111 * @param len the maximum length of the data to be written.
     112 *
     113 * @return non-negative number of bytes actually written to the device on success, negative error number otherwise.
     114 */
    75115int write_dev(int dev_phone, void *buf, size_t len)
    76116{
    77         // TODO
    78         return 0;
     117        return rw_dev(dev_phone, buf, len, false);
    79118}
    80119
Note: See TracChangeset for help on using the changeset viewer.