Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 848e3d15 in mainline


Ignore:
Timestamp:
2010-10-21T20:22:56Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
032e0bb
Parents:
7a252ec8
Message:

Cstyle fixes and cleanup of test_serial.

File:
1 edited

Legend:

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

    r7a252ec8 r848e3d15  
    3030 * @brief       test the serial port driver - read from the serial port
    3131 * @{
    32  */ 
     32 */
    3333/**
    3434 * @file
     
    5151
    5252
    53 static void print_usage()
     53static void print_usage(void)
    5454{
    55         printf("Usage: \n test_serial count \n where count is the number of characters to be read\n"); 
     55        printf("Usage: \n test_serial count \n where count is the number of "
     56            "characters to be read\n");
    5657}
    5758
     
    6162                printf(NAME ": incorrect number of arguments.\n");
    6263                print_usage();
    63                 return 0;               
     64                return 0;
    6465        }
    6566       
     
    7071        device_handle_t handle;
    7172       
    72         if (EOK != (res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, IPC_FLAG_BLOCKING))) {
    73                 printf(NAME ": could not get the device handle, errno = %d.\n", -res);
     73        res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle,
     74            IPC_FLAG_BLOCKING);
     75        if (EOK != res) {
     76                printf(NAME ": could not get the device handle, errno = %d.\n",
     77                    -res);
    7478                return 1;
    7579        }
    7680       
    77         printf(NAME ": trying to read %d characters from device with handle %d.\n", cnt, handle);       
     81        printf(NAME ": trying to read %d characters from device with handle "
     82            "%d.\n", cnt, handle);
    7883       
    79         int phone;
    80         if (0 >= (phone = devman_device_connect(handle, IPC_FLAG_BLOCKING))) {
    81                 printf(NAME ": could not connect to the device, errno = %d.\n", -res);
    82                 devman_hangup_phone(DEVMAN_CLIENT);             
     84        int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING);
     85        if (0 > phone) {
     86                printf(NAME ": could not connect to the device, errno = %d.\n",
     87                    -res);
     88                devman_hangup_phone(DEVMAN_CLIENT);
    8389                return 2;
    8490        }
    8591       
    86         char *buf = (char *)malloc(cnt+1);
     92        char *buf = (char *) malloc(cnt + 1);
    8793        if (NULL == buf) {
    8894                printf(NAME ": failed to allocate the input buffer\n");
     
    94100        ipcarg_t old_baud, old_par, old_stop, old_word_size;
    95101       
    96         res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, &old_par, &old_word_size, &old_stop);   
     102        res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud,
     103            &old_par, &old_word_size, &old_stop);
    97104        if (EOK != res) {
    98                 printf(NAME ": failed to get old communication parameters, errno = %d.\n", -res);
     105                printf(NAME ": failed to get old communication parameters, "
     106                    "errno = %d.\n", -res);
    99107                devman_hangup_phone(DEVMAN_CLIENT);
    100108                ipc_hangup(phone);
     
    103111        }
    104112       
    105         res = ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, 1200, SERIAL_NO_PARITY, 8, 1);     
     113        res = ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, 1200,
     114            SERIAL_NO_PARITY, 8, 1);
    106115        if (EOK != res) {
    107                 printf(NAME ": failed to set communication parameters, errno = %d.\n", -res);
     116                printf(NAME ": failed to set communication parameters, errno = "
     117                    "%d.\n", -res);
    108118                devman_hangup_phone(DEVMAN_CLIENT);
    109119                ipc_hangup(phone);
     
    112122        }
    113123       
    114        
    115124        int total = 0;
    116125        int read = 0;
    117         while (total < cnt) {           
     126        while (total < cnt) {
    118127                read = read_dev(phone, buf, cnt - total);
    119128                if (0 > read) {
    120                         printf(NAME ": failed read from device, errno = %d.\n", -read);
    121                         ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, old_word_size, old_stop);     
     129                        printf(NAME ": failed read from device, errno = %d.\n",
     130                            -read);
     131                        ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     132                            old_par, old_word_size, old_stop);
    122133                        ipc_hangup(phone);
    123134                        devman_hangup_phone(DEVMAN_CLIENT);
    124135                        free(buf);
    125136                        return 5;
    126                 }               
     137                }
    127138                total += read;
    128                 if (read > 0) {                 
     139                if (read > 0) {
    129140                        buf[read] = 0;
    130                         printf(buf);   
    131                         // write data back to the device to test the opposite direction of data transfer
     141                        printf(buf);
     142                        /*
     143                         * Write data back to the device to test the opposite
     144                         * direction of data transfer.
     145                         */
    132146                        write_dev(phone, buf, read);
    133                 } else {       
    134                         usleep(100000);                 
     147                } else {
     148                        usleep(100000);
    135149                }       
    136150        }
     
    139153        write_dev(phone, (void *)the_end, str_size(the_end));
    140154       
    141         // restore original communication settings
    142         ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, old_word_size, old_stop);     
     155        /* restore original communication settings */
     156        ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par,
     157            old_word_size, old_stop);
    143158        devman_hangup_phone(DEVMAN_CLIENT);
    144159        ipc_hangup(phone);
     
    148163}
    149164
    150 
    151165/** @}
    152166 */
Note: See TracChangeset for help on using the changeset viewer.