Sylixos RTC Introduction

Source: Internet
Author: User
  • Introduction to rtc
    RTC is called real-time clock in English. The Chinese name is real-time clock. It refers to an electronic device that can output the actual time like a clock. It is generally an integrated circuit, and therefore called a clock chip. Real-time clock chips are one of the most widely used consumer electronic products in daily life. It provides accurate real-time or accurate time reference for electronic systems. Currently, most real-time clock chips use high-precision crystal oscillator as the clock source.
  • 2 sylixos RTC key struct
    2.1 RTC Device
    The RTC device struct lw_rtc_dev is used to describe the entity of the RTC device, which isRtcopen,Key parameters of the rtcclose ,__ rtcioctl function. They contain two member variables, device header and operation function set. The code description is shown in the program list 2.1.
    Procedure 2.1

    Typedef struct {lw_dev_hdr rtcdev_devhdr;/* Device header */plw_rtc_funcs restart;/* operation function */} lw_rtc_dev; typedef lw_rtc_dev * plw_rtc_dev;

    2.2 RTC function set
    The RTC function set struct plw_rtc_funcs is a hardware processing interface abstracted by the user using sylixos, which is implemented by the user. It is a key parameter for the RTC device creation function api_rtcdevcreate. It contains four function pointers pointing to the RTC initialization function interface, setting the RTC time function interface, and obtaining the RTC time interface, optional complex RTC control function interfaces (for example, setting the alarm clock interruption ). The code description is shown in the program list 2.2.
    Procedure 2.2

    Typedef struct {voidfuncptr rtc_pfuncinit;/* initialize RTC */funcptr rtc_pfuncset;/* Set hardware RTC time */funcptr rtc_pfuncget;/* read hardware RTC time */funcptr restart; /* more complex RTC control * // * For example, set the wake-up alarm interrupt and so on */} lw_rtc_funcs; typedef lw_rtc_funcs * plw_rtc_funcs;

    3 sylixos RTC local Function
    Sylixos implements a set of common operation functions for RTC without user implementation. They areRtcopen,Rtcclose,Rtcioctl.
    3.1
    Rtcopen
    This is a function that the file system must call to open the RTC device. This function is relatively simple, but only increases the number of opened files. The function implementation is shown in the program list 3.1.
    Procedure 3.1

    /*************************************** **************************************** * *************************** Function Name: _ rtcopen ** Function Description: Open the RTC device ** input: prtcdev RTC device ** pcname ** iflags mode ** imode method ** output: device ** global variable: ** call module: **************************************** **************************************** * **********************/static long _ rtcopen (plw_rtc_dev prtcdev, pchar pcname, int iflags, int imode) {lw_dev_inc_use_count (& prtcdev-> rtcdev_devhdr); Return (long) prtcdev );}

    3.2Rtcclose
    This is a function that the file system must call to disable the RTC device. Its operations and
    In contrast, rtcopen only reduces the number of opened files. The function implementation is shown in the program list 3.2.
    Procedure 3.2

    /*************************************** **************************************** * *************************** Function Name: _ rtcclose ** Function Description: Disable the RTC device ** input: prtcdev RTC device ** output: Device ** global variable: ** call module: **************************************** **************************************** * ***********************/static int _ rtcclose (plw_rtc_dev prtcdev) {If (prtcdev) {lw_dev_dec_use_count (& prtcdev-> rtcdev_devhdr); Return (error_none);} else {return (px_error );}}

    3.3 _ rtcioctl
    This function is used to control RTC devices, such as setting time, obtaining time, and obtaining file attributes. The user-implemented function set described in section 2.2 will be called here. The function implementation is shown in the program list 3.3.
    Procedure 3.3

    Static int _ rtcioctl (plw_rtc_dev prtcdev, int icmd, pvoid pvarg) {struct stat * pstat; Switch (icmd) {Case fiogettime: /* Get RTC time */If (prtcdev-> response-> rtc_pfuncget) {return prtcdev-> response-> rtc_pfuncget (prtcdev-> rtcdev_prtcfuncs, (time_t *) pvarg );} break; Case fiosettime:/* Set RTC time */If (prtcdev-> timeout-> rtc_pfuncset) {return prtcdev-> rtcdev_prtcfuncs-> rtc_pfuncset (prtcdev-> timeout, (time_t *) pvarg);} break; Case fiofstatget:/* Get file attributes */pstat = (struct stat *) pvarg; pstat-> st_dev = (dev_t) prtcdev; pstat-> st_ino = (ino_t) 0;/* equivalent to a unique node */pstat-> st_mode = 0644 | s_ifchr;/* default attribute */pstat-> st_nlink = 1; pstat-> st_uid = 0; pstat-> st_gid = 0; pstat-> st_rdev = 1; pstat-> st_size = 0; pstat-> st_blksize = 0; pstat-> st_blocks = 0; pstat-> st_atime = api_rootfstime (lw_null);/* Default Root FS reference time */pstat-> st_mtime = api_rootfstime (lw_null ); pstat-> st_ctime = api_rootfstime (lw_null); Return (error_none); default: break;} If (prtcdev-> rtcdev_prtcfuncs-> rtc_pfuncioctl) {return prtcdev-> response-> rtc_pfuncioctl (prtcdev-> rtcdev_prtcfuncs, icmd, pvarg);} else {_ errorhandle (enosys); Return (px_error );}}

    4 sylixos RTC global function

    4.1 api_rtcdrvinstall
    This function is the RTC driver installation function provided by sylixos for users.Rtcopen,Rtcclose ,__ rtcioctl is integrated into the driver control block (lw_dev_entry ). Find an idle lw_dev_entry in the global driver control block table, initialize lw_dev_entry, and return the index number of the lw_dev_entry in the table. The function flow is shown in flowchart 4.1.

    Flowchart 4.1
    4.2 api_rtcdevcreate
    This function is used to create an RTC device. It is mainly to apply for an lw_rtc_dev struct, initialize the struct, and then add an RTC device to the system. If necessary, perform hardware initialization for RTC. The function flow is shown in flowchart 4.2.

    Flowchart 4.2
    5 References
    Sylixos_driver_usermanual.

    Sylixos RTC Introduction

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.