Changeset dafe675 in mainline for uspace/srv/drivers/serial/serial.c


Ignore:
Timestamp:
2010-04-30T08:54:55Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
25a7e11d
Parents:
2300b9d
Message:

serial port driver reads the input data and puts them into the input buffer when interrupted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/drivers/serial/serial.c

    r2300b9d rdafe675  
    121121}
    122122
     123static bool serial_received(ioport8_t *port)
     124{
     125   return (pio_read_8(port + 5) & 1) != 0;
     126}
     127
     128static uint8_t serial_read_8(ioport8_t *port)
     129{
     130        return pio_read_8(port);
     131}
     132
     133static bool is_transmit_empty(ioport8_t *port)
     134{
     135   return (pio_read_8(port + 5) & 0x20) != 0;
     136}
     137
     138static void serial_write_8(ioport8_t *port, uint8_t c)
     139{
     140        while (!is_transmit_empty(port))
     141                ;
     142       
     143        pio_write_8(port, c);
     144}
     145
    123146static bool serial_pio_enable(device_t *dev)
    124147{
     
    219242                        ioport = true;
    220243                        printf(NAME ": the %s device was asigned i/o address = 0x%x.\n", dev->name, data->io_addr);
    221                         break;                 
     244                        break; 
     245                default:
     246                        break;
    222247                }
    223248        }
     
    273298static void serial_read_from_device(device_t *dev)
    274299{
    275         // TODO
     300        serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     301        ioport8_t *port = data->port;
     302        bool cont = true;
     303       
     304        while (cont) { 
     305                if (cont = serial_received(port)) {
     306                        uint8_t val = serial_read_8(port);
     307                        printf(NAME ": character %c read from %s.\n", val, dev->name);
     308                       
     309                        fibril_mutex_lock(&data->mutex);
     310                        if (data->client_connected) {
     311                                if (!buf_push_back(&(data->input_buffer), val)) {
     312                                        printf(NAME ": buffer overflow on %s.\n", dev->name);
     313                                } else {
     314                                        printf(NAME ": the character %c saved to the buffer of %s.\n", val, dev->name);
     315                                }
     316                        } else {
     317                                printf(NAME ": no client is connected to %s, discarding the character which was read.\n", dev->name);
     318                        }
     319                        fibril_mutex_unlock(&data->mutex);
     320                }
     321               
     322        }       
    276323}
    277324
    278325static inline void serial_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    279326{
    280         printf(NAME ": interrupt received.\n");
    281327        serial_read_from_device(dev);
    282328}
Note: See TracChangeset for help on using the changeset viewer.