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

Changeset 923b2eba in mainline


Ignore:
Timestamp:
2012-04-03T08:10:43Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
2a5171db
Parents:
8d2963d
Message:

rtc: add the rtc_open() callback

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    r8d2963d r923b2eba  
    4949
    5050#define REG_COUNT 2
     51
     52#define RTC_FROM_FNODE(fnode)  ((rtc_t *) ((fnode)->dev->driver_data))
    5153
    5254typedef struct rtc {
     
    6163        /** The I/O port used to access the CMOS registers */
    6264        ioport8_t *port;
     65        /** true if a client is connected to the device */
     66        bool client_connected;
    6367} rtc_t;
    6468
     
    8185static void
    8286rtc_dev_cleanup(rtc_t *rtc);
     87
     88static int
     89rtc_open(ddf_fun_t *fun);
    8390
    8491
     
    109116        ddf_log_init(NAME, LVL_ERROR);
    110117
    111         rtc_dev_ops.open = NULL; /* XXX */
     118        rtc_dev_ops.open = rtc_open;
    112119        rtc_dev_ops.close = NULL; /* XXX */
    113120
     
    302309        ddf_fun_add_to_category(fun, "clock");
    303310
     311        rtc->client_connected = false;
     312
    304313        ddf_msg(LVL_NOTE, "Device %s successfully initialized",
    305314            dev->name);
     
    315324}
    316325
     326/** Open the device
     327 *
     328 * @param fun   The function node
     329 *
     330 * @return  EOK on success or a negative error code
     331 */
     332static int
     333rtc_open(ddf_fun_t *fun)
     334{
     335        int rc;
     336        rtc_t *rtc = RTC_FROM_FNODE(fun);
     337
     338        fibril_mutex_lock(&rtc->mutex);
     339
     340        if (rtc->client_connected)
     341                rc = EBUSY;
     342        else {
     343                rc = EOK;
     344                rtc->client_connected = true;
     345        }
     346
     347        fibril_mutex_unlock(&rtc->mutex);
     348        return rc;
     349}
     350
    317351int
    318352main(int argc, char **argv)
Note: See TracChangeset for help on using the changeset viewer.