source: mainline/uspace/app/sportdmp/sportdmp.c@ 3a11f17

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3a11f17 was c0e53ff, checked in by Martin Sucha <sucha14@…>, 14 years ago

Add simple serial port dumping program

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Sucha
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
30#include <stdio.h>
31#include <devman.h>
32#include <ipc/devman.h>
33#include <device/char_dev.h>
34#include <ipc/serial_ctl.h>
35
36#define BUF_SIZE 1
37
38int main(int argc, char **argv)
39{
40 devman_handle_t device;
41 int rc = devman_fun_get_handle("/hw/pci0/00:01.0/com1/a",
42 &device, IPC_FLAG_BLOCKING);
43 if (rc != EOK) {
44 fprintf(stderr, "Cannot open device\n");
45 return 1;
46 }
47
48 async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE, device,
49 IPC_FLAG_BLOCKING);
50 if (!sess) {
51 fprintf(stderr, "Cannot connect device\n");
52 }
53
54 async_exch_t *exch = async_exchange_begin(sess);
55 rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, 9600,
56 SERIAL_NO_PARITY, 8, 1);
57 async_exchange_end(exch);
58
59 if (rc != EOK) {
60 fprintf(stderr, "Cannot set serial properties\n");
61 return 2;
62 }
63
64 uint8_t *buf = (uint8_t *) malloc(BUF_SIZE);
65 if (buf == NULL) {
66 fprintf(stderr, "Cannot allocate buffer\n");
67 return 3;
68 }
69
70 while (true) {
71 ssize_t read = char_dev_read(sess, buf, BUF_SIZE);
72 if (read < 0) {
73 fprintf(stderr, "Failed reading from serial device\n");
74 break;
75 }
76 ssize_t i;
77 for (i = 0; i < read; i++) {
78 if (buf[i] >= 32 && buf[i] < 128)
79 putchar((wchar_t) buf[i]);
80 else
81 putchar('.');
82 fflush(stdout);
83 }
84 }
85
86 free(buf);
87 return 0;
88}
Note: See TracBrowser for help on using the repository browser.