how to don't allow interruptions in a piece of code in VC++
-
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??
-
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??
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.
-
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.
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?
-
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?
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.
-
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.
-
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?
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.
-
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.
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??
-
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??
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.
-
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??
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.
-
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??
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!