This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using Bit variable in saftey critical application

Hi, I have doubt regarding bit fields in Keil C. Suppose I am having variable alaram:

bit Alaram=0;

Alaram=P0^1;

if(Alaram==1)
{
 produceAlaram();
}


whether there is any chance of bit toggling in the software....
whether the alaram bit will changed to 1 even the P0^1 is 0...is there any possiblility?

so I change the code as.

unsigned char Alrm=P0^1;

if(Alrm)
{
 Alaram=0xA5;
}
else
{
 Alaram=0xAA;
}
if(Alaram=0xA5)
{
 produceAlaram();
}


Alaram is changed to unsigned char so one bit change cant produce alarm erroneously...whether this approach is correct...if any mistake kindly tell me and give me some guidelines for programming safety critical application........

with regards,
G.Karthik Ragunath

Parents
  • Thanks for u r suggestion...Here P0^1 doesn't indicates XOR operation it is to take the first bit of the Port 0 in keil....

    My question is whether there is a chance of one bit change in internal variables....
    the example I mentioned is that alarm is dependent to Port1's first bit,but whether there is any chance of producing alarm by one bit internal variable toggling erroneously even though the P1.1 bit is 0...

    is it possible in micro controllers....in some application we don't use bit 1 and 0..instead we use 0xAA-code for 0 and 0xA5 code for 1...so that one bit toggling doesn't lead to erroneous operations....is it needed???Plz provide any suggestion for writing code for safety critical applications......

    With thanks and Regards,
    G.Karthik Ragunath

Reply
  • Thanks for u r suggestion...Here P0^1 doesn't indicates XOR operation it is to take the first bit of the Port 0 in keil....

    My question is whether there is a chance of one bit change in internal variables....
    the example I mentioned is that alarm is dependent to Port1's first bit,but whether there is any chance of producing alarm by one bit internal variable toggling erroneously even though the P1.1 bit is 0...

    is it possible in micro controllers....in some application we don't use bit 1 and 0..instead we use 0xAA-code for 0 and 0xA5 code for 1...so that one bit toggling doesn't lead to erroneous operations....is it needed???Plz provide any suggestion for writing code for safety critical applications......

    With thanks and Regards,
    G.Karthik Ragunath

Children
  • see here:

    iapetus.neab.net/.../hardening.html

    despite Ashley's nagging, this is a very good resource indeed!

  • Thanks for u r suggestion...Here P0^1 doesn't indicates XOR operation it is to take the first bit of the Port 0 in keil....

    No, it does not. Outside of an sbit declaration, the compiler will consider the caret ^ an XOR operation, just like a C compiler should.

    My question is whether there is a chance of one bit change in internal variables....

    But you're never reading an internal variable, you're reading the status of a port pin. Only in your second example you're setting an internal variable, and then read it again.

    Port pins can show an erroneous state if there is noise on the port pin (which depends on the environment and the external circuitry).

    Internal variables in RAM can be corrupted e.g. by cosmic rays, other forms of ionizing radiation, exceeding the specified temperature range of the chip, etc. Some of these need to be excluded by design, others (like the very, very rare cosmic ray) need to be considered in a hazard analysis.

    is it possible in micro controllers....in some application we don't use bit 1 and 0..instead we use 0xAA-code for 0 and 0xA5 code for 1...so that one bit toggling doesn't lead to erroneous operations....is it needed???

    If you toggle one bit in 0xAA or 0xA5, you're still getting an erroneous operation. In your example, you will end up with a false negative alarm, which is usually worse than a false positive alarm.

    False positive alarms destroy money/work.
    False negative alarms kill people.