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

Changeset 25a7e11d in mainline


Ignore:
Timestamp:
2010-04-30T14:13:41Z (11 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
f658458
Parents:
dafe675
Message:

backup (unstable)

Location:
uspace
Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/Makefile

    rdafe675 r25a7e11d  
    5555        generic/devman.c \
    5656        generic/device/hw_res.c \
     57        generic/device/char.c \
    5758        generic/event.c \
    5859        generic/errno.c \
  • uspace/lib/libc/include/ipc/dev_iface.h

    rdafe675 r25a7e11d  
    3737typedef enum { 
    3838        HW_RES_DEV_IFACE = 0,   
     39        CHAR_DEV_IFACE,
    3940        // TODO add more interfaces
    4041        DEV_IFACE_MAX
  • uspace/lib/libdrv/Makefile

    rdafe675 r25a7e11d  
    3737        generic/driver.c \
    3838        generic/dev_iface.c \
    39         generic/remote_res.h
     39        generic/remote_res.c \
     40        generic/remote_char.c
    4041
    4142include ../Makefile.common
  • uspace/lib/libdrv/generic/dev_iface.c

    rdafe675 r25a7e11d  
    3838#include "dev_iface.h"
    3939#include "remote_res.h"
     40#include "remote_char.h"
    4041 
    4142static iface_dipatch_table_t remote_ifaces = {
    4243        .ifaces = {
    43                 &remote_res_iface
     44                &remote_res_iface,
     45                &remote_char_iface
    4446        }
    4547};
  • uspace/lib/libdrv/generic/driver.c

    rdafe675 r25a7e11d  
    224224        // TODO - if the client is not a driver, check whether it is allowed to use the device
    225225
    226         // TODO open the device (introduce some callbacks for opening and closing devices registered by the driver)
    227        
    228         ipc_answer_0(iid, EOK);
     226        int ret = EOK;
     227        // open the device
     228        if (NULL != dev->class && NULL != dev->class->open) {
     229                ret = (*dev->class->open)(dev);
     230        }
     231       
     232        ipc_answer_0(iid, ret);
    229233
    230234        while (1) {
     
    236240               
    237241                switch  (method) {
    238                 case IPC_M_PHONE_HUNGUP:
    239                
    240                         // TODO close the device
    241                        
     242                case IPC_M_PHONE_HUNGUP:               
     243                        // close the device
     244                        if (NULL != dev->class && NULL != dev->class->close) {
     245                                (*dev->class->close)(dev);
     246                        }                       
    242247                        ipc_answer_0(callid, EOK);
    243248                        return;
  • uspace/lib/libdrv/include/driver.h

    rdafe675 r25a7e11d  
    4141#include <ipc/dev_iface.h>
    4242#include <device/hw_res.h>
     43#include <device/char.h>
    4344#include <assert.h>
    4445#include <ddi.h>
     
    8182        /** Unique identification of the class. */
    8283        int id;
     84        /** Optional callback function called when a client is connecting to the device. */
     85        int (*open)(device_t *dev);
     86        /** Optional callback function called when a client is disconnecting from the device. */
     87        void (*close)(device_t *dev);
    8388        /** The table of interfaces implemented by the device. */
    8489        void *interfaces[DEV_IFACE_COUNT];     
  • uspace/srv/drivers/serial/serial.c

    rdafe675 r25a7e11d  
    269269        int res;
    270270        // enable interrupt globally   
    271         printf(NAME ": call  enable_interrupt\n");
    272271        if (EOK != (res = interrupt_enable(data->irq))) {
    273272                return res;
     
    385384}
    386385
     386/** Open the device.
     387 *
     388 * This is a callback function called when a client tries to connect to the device.
     389 *
     390 * @param dev the device.
     391 */
     392static int serial_open(device_t *dev)
     393{
     394        serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     395        int res;
     396       
     397        fibril_mutex_lock(&data->mutex);       
     398       
     399        if (data->client_connected) {
     400                res = ELIMIT;
     401        } else {
     402                res = EOK;
     403                data->client_connected = true;
     404        }
     405       
     406        fibril_mutex_unlock(&data->mutex);
     407
     408        return res;
     409}
     410
     411/** Close the device.
     412 *
     413 *  This is a callback function called when a client tries to disconnect from the device.
     414 *
     415 * @param dev the device.
     416 */
     417static void serial_close(device_t *dev)
     418{
     419        serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     420       
     421        fibril_mutex_lock(&data->mutex);
     422       
     423        assert(data->client_connected);
     424       
     425        data->client_connected = false;
     426        buf_clear(&data->input_buffer);
     427       
     428        fibril_mutex_unlock(&data->mutex);       
     429}
     430
     431/** Initialize the serial port driver.
     432 *
     433 * Initialize class structures with callback methods for handling
     434 * client requests to the serial port devices.
     435 */
    387436static void serial_init()
    388437{
    389438        // TODO
    390439        serial_dev_class.id = 0;
     440        serial_dev_class.open = &serial_open;
     441        serial_dev_class.close = &serial_close;
    391442}
    392443
Note: See TracChangeset for help on using the changeset viewer.