echo +80 > /sys/class/rtc/rtc0/wakealarm

echo +80 > /sys/class/rtc/rtc0/wakealarm

上面指令执行的函数如下:

drivers/rtc/rtc-sysfs.c

static ssize_t
wakealarm_store(struct device *dev, struct device_attribute *attr,
        const char *buf, size_t n)
{
    ssize_t retval;
    unsigned long now, alarm;
    unsigned long push = 0;
    struct rtc_wkalrm alm;
    struct rtc_device *rtc = to_rtc_device(dev);
    char *buf_ptr;
    int adjust = 0;

    /* Only request alarms that trigger in the future.  Disable them
     * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
     */
    retval = rtc_read_time(rtc, &alm.time);
    if (retval < 0)
        return retval;
    rtc_tm_to_time(&alm.time, &now);

    buf_ptr = (char *)buf;
    if (*buf_ptr == '+') {
        buf_ptr++;
        if (*buf_ptr == '=') {
            buf_ptr++;
            push = 1;
        } else
            adjust = 1;
    }
    alarm = simple_strtoul(buf_ptr, NULL, 0);
    if (adjust) {
        alarm += now;
    }
    if (alarm > now || push) {
        /* Avoid accidentally clobbering active alarms; we can't
         * entirely prevent that here, without even the minimal
         * locking from the /dev/rtcN api.
         */
        retval = rtc_read_alarm(rtc, &alm);
        if (retval < 0)
            return retval;
        if (alm.enabled) {
            if (push) {
                rtc_tm_to_time(&alm.time, &push);
                alarm += push;
            } else
                return -EBUSY;
        } else if (push)
            return -EINVAL;
        alm.enabled = 1;
    } else {
        alm.enabled = 0;

        /* Provide a valid future alarm time.  Linux isn't EFI,
         * this time won't be ignored when disabling the alarm.
         */
        alarm = now + 300;
    }
    rtc_time_to_tm(alarm, &alm.time);

    retval = rtc_set_alarm(rtc, &alm);
    return (retval < 0) ? retval : n;
}

 

posted @ 2020-08-19 15:21  aspirs  阅读(1689)  评论(0编辑  收藏  举报