Changeset 132ab5d1 in mainline for uspace/app/sportdmp/sportdmp.c


Ignore:
Timestamp:
2018-01-30T03:20:45Z (8 years ago)
Author:
Jenda <jenda.jzqk73@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a6cc679
Parents:
8bfb163 (diff), 6a5d05b (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 commit '6a5d05bd2551e64111bea4f9332dd7448c26ce84' into forwardport

Separate return value from error code in gen_irq_code*().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sportdmp/sportdmp.c

    r8bfb163 r132ab5d1  
    2727 */
    2828
    29 #include <char_dev_iface.h>
    3029#include <errno.h>
    31 #include <ipc/serial_ctl.h>
     30#include <io/chardev.h>
     31#include <io/serial.h>
    3232#include <loc.h>
    3333#include <stdio.h>
     34#include <stdlib.h>
    3435
    3536#define BUF_SIZE 1
     
    4445        sysarg_t baud = 9600;
    4546        service_id_t svc_id;
     47        chardev_t *chardev;
     48        serial_t *serial;
     49        size_t nread;
    4650
    4751        int arg = 1;
     
    113117        async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
    114118            IPC_FLAG_BLOCKING);
    115         if (!sess) {
     119        if (sess == NULL) {
    116120                fprintf(stderr, "Failed connecting to service\n");
     121                return 2;
    117122        }
    118123
    119         async_exch_t *exch = async_exchange_begin(sess);
    120         rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud,
    121             SERIAL_NO_PARITY, 8, 1);
    122         async_exchange_end(exch);
     124        rc = chardev_open(sess, &chardev);
     125        if (rc != EOK) {
     126                fprintf(stderr, "Failed opening character device\n");
     127                return 2;
     128        }
    123129
     130        rc = serial_open(sess, &serial);
     131        if (rc != EOK) {
     132                fprintf(stderr, "Failed opening serial port\n");
     133                return 2;
     134        }
     135
     136        rc = serial_set_comm_props(serial, baud, SERIAL_NO_PARITY, 8, 1);
    124137        if (rc != EOK) {
    125138                fprintf(stderr, "Failed setting serial properties\n");
     
    134147
    135148        while (true) {
    136                 ssize_t read = char_dev_read(sess, buf, BUF_SIZE);
    137                 if (read < 0) {
    138                         fprintf(stderr, "Failed reading from serial device\n");
     149                rc = chardev_read(chardev, buf, BUF_SIZE, &nread);
     150                for (size_t i = 0; i < nread; i++) {
     151                        printf("%02hhx ", buf[i]);
     152                }
     153                if (rc != EOK) {
     154                        fprintf(stderr, "\nFailed reading from serial device\n");
    139155                        break;
    140                 }
    141                 ssize_t i;
    142                 for (i = 0; i < read; i++) {
    143                         printf("%02hhx ", buf[i]);
    144156                }
    145157                fflush(stdout);
     
    147159
    148160        free(buf);
     161        serial_close(serial);
     162        chardev_close(chardev);
     163        async_hangup(sess);
    149164        return 0;
    150165}
Note: See TracChangeset for help on using the changeset viewer.