Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to don't allow interruptions in a piece of code in VC++

how to don't allow interruptions in a piece of code in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    timbk
    wrote on last edited by
    #1

    hello, my application reads data from LPT port , by data register (wich is the data for my app) and by status register( wich decribes the origin of data).I am using intruccions Inp32(Register), this is a piece of code in wich i do the adquisition: <pre> aux2=Inp32(Status); aux=Inp32(Data); </pre> It's working but , this is performed between 30useconds intervals , and in some cases it seems that the O.S. (embeded Win98SE) is doing another thing between this two instructions, and when the O.S. come back to execute the second instruction , the data don't belong anymore to the origin indicated by the first instruction, so , is there any way to deny to the O.S. do another thing between this two instructions??

    L S 2 Replies Last reply
    0
    • T timbk

      hello, my application reads data from LPT port , by data register (wich is the data for my app) and by status register( wich decribes the origin of data).I am using intruccions Inp32(Register), this is a piece of code in wich i do the adquisition: <pre> aux2=Inp32(Status); aux=Inp32(Data); </pre> It's working but , this is performed between 30useconds intervals , and in some cases it seems that the O.S. (embeded Win98SE) is doing another thing between this two instructions, and when the O.S. come back to execute the second instruction , the data don't belong anymore to the origin indicated by the first instruction, so , is there any way to deny to the O.S. do another thing between this two instructions??

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, AFAIK you can make a piece of code almost atomic by temporarily raising the thread priority to REALTIME, then restore it (don't run REALTIME for more than a few dozen microseconds!). That would be fine most of the time, however a high-priority interrupt, a DMA operation, or another REALTIME operation, may steal the CPU from you for a short period. Warning: I doubt changing the priority twice will reliably be handled in 30 microseconds, so it may not be good enough. If that is insufficient, the official approach is to write a driver. Is your PC generating the 30 usec tacting, or is your peripheral? how do you that? If it isn't a potential data overrun problem you are facing, the system-level approach would be to use two-way handshake, i.e. the PC reporting back it has read the data, so the peripheral is allowed to present the next data. Doing so, the communication could slow down temporarily while maintaining good overall bandwidth. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, AFAIK you can make a piece of code almost atomic by temporarily raising the thread priority to REALTIME, then restore it (don't run REALTIME for more than a few dozen microseconds!). That would be fine most of the time, however a high-priority interrupt, a DMA operation, or another REALTIME operation, may steal the CPU from you for a short period. Warning: I doubt changing the priority twice will reliably be handled in 30 microseconds, so it may not be good enough. If that is insufficient, the official approach is to write a driver. Is your PC generating the 30 usec tacting, or is your peripheral? how do you that? If it isn't a potential data overrun problem you are facing, the system-level approach would be to use two-way handshake, i.e. the PC reporting back it has read the data, so the peripheral is allowed to present the next data. Doing so, the communication could slow down temporarily while maintaining good overall bandwidth. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


        T Offline
        T Offline
        timbk
        wrote on last edited by
        #3

        Thnaks for your reply, answering to your question , is the periferal who generates the 30usec clock. Handshake, good idea, but that decrease speed data adquisition, and i need to perform a "real time" adquisition lets say. So it's interesant the idea that you refer in the first paragraph, increase the priority , how can i do that?

        L 2 Replies Last reply
        0
        • T timbk

          Thnaks for your reply, answering to your question , is the periferal who generates the 30usec clock. Handshake, good idea, but that decrease speed data adquisition, and i need to perform a "real time" adquisition lets say. So it's interesant the idea that you refer in the first paragraph, increase the priority , how can i do that?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          probably using this[^]. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


          T 1 Reply Last reply
          0
          • L Luc Pattyn

            probably using this[^]. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


            T Offline
            T Offline
            timbk
            wrote on last edited by
            #5

            Thanks LUC , i will work on that , but tomorrow , here in Argentina is 0:55 AM , so im going to bed now.

            1 Reply Last reply
            0
            • T timbk

              Thnaks for your reply, answering to your question , is the periferal who generates the 30usec clock. Handshake, good idea, but that decrease speed data adquisition, and i need to perform a "real time" adquisition lets say. So it's interesant the idea that you refer in the first paragraph, increase the priority , how can i do that?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              timbk wrote:

              s the periferal who generates the 30usec clock

              and is your code getting a signal (interrupt, event) every 30 usec, or are you just sitting in a polling loop? if so, you would need to turn the entire piece of code into a REALTIME section, not a good idea. How long does your acquisition take? milliseconds? longer? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


              T 1 Reply Last reply
              0
              • L Luc Pattyn

                timbk wrote:

                s the periferal who generates the 30usec clock

                and is your code getting a signal (interrupt, event) every 30 usec, or are you just sitting in a polling loop? if so, you would need to turn the entire piece of code into a REALTIME section, not a good idea. How long does your acquisition take? milliseconds? longer? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


                T Offline
                T Offline
                timbk
                wrote on last edited by
                #7

                there is a thread running in at the same time the main thread, this new thread created for the acquisition is always checking the state of a bit in status register to know when there is a valid data present in data register, so do you think that is not a good idea to set a realtime priority to whole thread? I'm not using interuptions, i dont know how to do this in Win98 , it's possible handling interuptions in Win98??

                L 2 Replies Last reply
                0
                • T timbk

                  there is a thread running in at the same time the main thread, this new thread created for the acquisition is always checking the state of a bit in status register to know when there is a valid data present in data register, so do you think that is not a good idea to set a realtime priority to whole thread? I'm not using interuptions, i dont know how to do this in Win98 , it's possible handling interuptions in Win98??

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  When I was using Win98 (that is 10 years ago), PC hardware wasn't powerful enough to make floppy drives work reliably with interrupts, so each floppy access caused the entire system to temporarily freeze. The realtime thread performing its polling loop will monopolize a CPU core. If your system has a single-core CPU and you will set realtime priorities, the same will happen as on old systems with floppy activity; if you are running on dual-core or better, you might be all right with one thread at realtime, so other threads can still be swapped in and out to serve the user. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


                  1 Reply Last reply
                  0
                  • T timbk

                    there is a thread running in at the same time the main thread, this new thread created for the acquisition is always checking the state of a bit in status register to know when there is a valid data present in data register, so do you think that is not a good idea to set a realtime priority to whole thread? I'm not using interuptions, i dont know how to do this in Win98 , it's possible handling interuptions in Win98??

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    if you can't live with the consequences, the one good way out is to add a sufficiently large memory to your peripheral, so the communication no longer poses a real-time requirement. That is what I did consistently when interfacing with image capture devices and feeding the images (up to 100MB) to a Windows PC, even when using modern PCs, operating systems, and buses. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


                    1 Reply Last reply
                    0
                    • T timbk

                      hello, my application reads data from LPT port , by data register (wich is the data for my app) and by status register( wich decribes the origin of data).I am using intruccions Inp32(Register), this is a piece of code in wich i do the adquisition: <pre> aux2=Inp32(Status); aux=Inp32(Data); </pre> It's working but , this is performed between 30useconds intervals , and in some cases it seems that the O.S. (embeded Win98SE) is doing another thing between this two instructions, and when the O.S. come back to execute the second instruction , the data don't belong anymore to the origin indicated by the first instruction, so , is there any way to deny to the O.S. do another thing between this two instructions??

                      S Offline
                      S Offline
                      Stuart Dootson
                      wrote on last edited by
                      #10

                      Use a proper real-time operating system if you want that sort of access to the hardware - Windows really doesn't cut it for real-timer operations...

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups