Understanding the code in rtc_interrupt

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I need to understand the code in "Real time clock" function rtc_interrupt. Code is



rtc_irq_data += 0x100; 
rtc_irq_data &= ~0xff;
rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);


I am unable to understand why it is += 0x100 and the rest of code.










share|improve this question













migrated from unix.stackexchange.com Feb 25 at 13:45


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.






















    1















    I need to understand the code in "Real time clock" function rtc_interrupt. Code is



    rtc_irq_data += 0x100; 
    rtc_irq_data &= ~0xff;
    rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);


    I am unable to understand why it is += 0x100 and the rest of code.










    share|improve this question













    migrated from unix.stackexchange.com Feb 25 at 13:45


    This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.




















      1












      1








      1








      I need to understand the code in "Real time clock" function rtc_interrupt. Code is



      rtc_irq_data += 0x100; 
      rtc_irq_data &= ~0xff;
      rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);


      I am unable to understand why it is += 0x100 and the rest of code.










      share|improve this question














      I need to understand the code in "Real time clock" function rtc_interrupt. Code is



      rtc_irq_data += 0x100; 
      rtc_irq_data &= ~0xff;
      rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);


      I am unable to understand why it is += 0x100 and the rest of code.







      linux linux-kernel interrupt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 24 at 12:45







      Linux kernel learner











      migrated from unix.stackexchange.com Feb 25 at 13:45


      This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.









      migrated from unix.stackexchange.com Feb 25 at 13:45


      This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
























          1 Answer
          1






          active

          oldest

          votes


















          3














          From the Book "Linux kernel development", from Robert Love, that snippet of code has the following comment(s):



          /*
          * Can be an alarm interrupt, update complete interrupt,
          * or a periodic interrupt. We store the status in the
          * low byte and the number of interrupts received since
          * the last read in the remainder of rtc_irq_data.
          */


          As for rtc_irq_data += 0x100; So, we know there is a counter for the interrupts received in the high byte. Hence the 0x100. If a 16 bit hexadecimal number representation, where the highest byte is being added +1 (more one interrupt on the counter).



          As for the second line, rtc_irq_data &= ~0xff; rtc_irq_data is being logically ANDED with the negation of 0xff, eg, with possibly 0xff00. The high part of the integer is being kept, and the low part being discarded. So supposing this was the first time being called, the value would now guaranteed to be 0x0100.



          The last part rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); is doing a logical OR |= of the low byte (that is now 0 / 0x00) with as the RTC current status. Hence the comment "We store the status in the low byte".



          As for doing a logical AND with 0xF0 in (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) , consulting the original AT compatible RTC datasheet, INTR_FLAGS is REGISTER C, a register byte where only the 4 upwards bits are used. b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,



          b3 to b0




          The unused bits of Status Register 1 are read as "0s". They cannot be
          writen.




          From RTC datasheet



          Hence then as a good standard coding practice, making sure with the AND logical 0xF0 that the lower 4 bits are ignored.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54867627%2funderstanding-the-code-in-rtc-interrupt%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown
























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            From the Book "Linux kernel development", from Robert Love, that snippet of code has the following comment(s):



            /*
            * Can be an alarm interrupt, update complete interrupt,
            * or a periodic interrupt. We store the status in the
            * low byte and the number of interrupts received since
            * the last read in the remainder of rtc_irq_data.
            */


            As for rtc_irq_data += 0x100; So, we know there is a counter for the interrupts received in the high byte. Hence the 0x100. If a 16 bit hexadecimal number representation, where the highest byte is being added +1 (more one interrupt on the counter).



            As for the second line, rtc_irq_data &= ~0xff; rtc_irq_data is being logically ANDED with the negation of 0xff, eg, with possibly 0xff00. The high part of the integer is being kept, and the low part being discarded. So supposing this was the first time being called, the value would now guaranteed to be 0x0100.



            The last part rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); is doing a logical OR |= of the low byte (that is now 0 / 0x00) with as the RTC current status. Hence the comment "We store the status in the low byte".



            As for doing a logical AND with 0xF0 in (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) , consulting the original AT compatible RTC datasheet, INTR_FLAGS is REGISTER C, a register byte where only the 4 upwards bits are used. b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,



            b3 to b0




            The unused bits of Status Register 1 are read as "0s". They cannot be
            writen.




            From RTC datasheet



            Hence then as a good standard coding practice, making sure with the AND logical 0xF0 that the lower 4 bits are ignored.






            share|improve this answer



























              3














              From the Book "Linux kernel development", from Robert Love, that snippet of code has the following comment(s):



              /*
              * Can be an alarm interrupt, update complete interrupt,
              * or a periodic interrupt. We store the status in the
              * low byte and the number of interrupts received since
              * the last read in the remainder of rtc_irq_data.
              */


              As for rtc_irq_data += 0x100; So, we know there is a counter for the interrupts received in the high byte. Hence the 0x100. If a 16 bit hexadecimal number representation, where the highest byte is being added +1 (more one interrupt on the counter).



              As for the second line, rtc_irq_data &= ~0xff; rtc_irq_data is being logically ANDED with the negation of 0xff, eg, with possibly 0xff00. The high part of the integer is being kept, and the low part being discarded. So supposing this was the first time being called, the value would now guaranteed to be 0x0100.



              The last part rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); is doing a logical OR |= of the low byte (that is now 0 / 0x00) with as the RTC current status. Hence the comment "We store the status in the low byte".



              As for doing a logical AND with 0xF0 in (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) , consulting the original AT compatible RTC datasheet, INTR_FLAGS is REGISTER C, a register byte where only the 4 upwards bits are used. b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,



              b3 to b0




              The unused bits of Status Register 1 are read as "0s". They cannot be
              writen.




              From RTC datasheet



              Hence then as a good standard coding practice, making sure with the AND logical 0xF0 that the lower 4 bits are ignored.






              share|improve this answer

























                3












                3








                3







                From the Book "Linux kernel development", from Robert Love, that snippet of code has the following comment(s):



                /*
                * Can be an alarm interrupt, update complete interrupt,
                * or a periodic interrupt. We store the status in the
                * low byte and the number of interrupts received since
                * the last read in the remainder of rtc_irq_data.
                */


                As for rtc_irq_data += 0x100; So, we know there is a counter for the interrupts received in the high byte. Hence the 0x100. If a 16 bit hexadecimal number representation, where the highest byte is being added +1 (more one interrupt on the counter).



                As for the second line, rtc_irq_data &= ~0xff; rtc_irq_data is being logically ANDED with the negation of 0xff, eg, with possibly 0xff00. The high part of the integer is being kept, and the low part being discarded. So supposing this was the first time being called, the value would now guaranteed to be 0x0100.



                The last part rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); is doing a logical OR |= of the low byte (that is now 0 / 0x00) with as the RTC current status. Hence the comment "We store the status in the low byte".



                As for doing a logical AND with 0xF0 in (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) , consulting the original AT compatible RTC datasheet, INTR_FLAGS is REGISTER C, a register byte where only the 4 upwards bits are used. b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,



                b3 to b0




                The unused bits of Status Register 1 are read as "0s". They cannot be
                writen.




                From RTC datasheet



                Hence then as a good standard coding practice, making sure with the AND logical 0xF0 that the lower 4 bits are ignored.






                share|improve this answer













                From the Book "Linux kernel development", from Robert Love, that snippet of code has the following comment(s):



                /*
                * Can be an alarm interrupt, update complete interrupt,
                * or a periodic interrupt. We store the status in the
                * low byte and the number of interrupts received since
                * the last read in the remainder of rtc_irq_data.
                */


                As for rtc_irq_data += 0x100; So, we know there is a counter for the interrupts received in the high byte. Hence the 0x100. If a 16 bit hexadecimal number representation, where the highest byte is being added +1 (more one interrupt on the counter).



                As for the second line, rtc_irq_data &= ~0xff; rtc_irq_data is being logically ANDED with the negation of 0xff, eg, with possibly 0xff00. The high part of the integer is being kept, and the low part being discarded. So supposing this was the first time being called, the value would now guaranteed to be 0x0100.



                The last part rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); is doing a logical OR |= of the low byte (that is now 0 / 0x00) with as the RTC current status. Hence the comment "We store the status in the low byte".



                As for doing a logical AND with 0xF0 in (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) , consulting the original AT compatible RTC datasheet, INTR_FLAGS is REGISTER C, a register byte where only the 4 upwards bits are used. b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,



                b3 to b0




                The unused bits of Status Register 1 are read as "0s". They cannot be
                writen.




                From RTC datasheet



                Hence then as a good standard coding practice, making sure with the AND logical 0xF0 that the lower 4 bits are ignored.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 24 at 13:09









                Rui F RibeiroRui F Ribeiro

                2461414




                2461414





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54867627%2funderstanding-the-code-in-rtc-interrupt%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay