| ??? 01/13/01 20:01 Read: times |
#8202 - RE: does anyone know the reason |
Tom wrote: ---------------------------
The fear of using global variables is from the possibility of an interrupt routine modifying an int, long, or other multi-byte global variable while a foreground task is reading it. ------------------------------------- You can temporary disable interrupts and after reading the variable, enable it again as: EA = 0; do something... EA = 1; For the function, you can also use another way (this is bad if interrupts are enabled an disabled in timing sequences in an application) Leaving the function with EA = 1 will leave the interrupts enabled. old_en = EA; EA = 0; do something... EA = old_en; Here we store the EA in the bit variable. If interrupts enabled old_en is set to 1 othervise it is cleared. We can use this function when interrupts enabled or disabled. Another option is to write two functions: void Enable_interrupts () { if (DisableCount == 0x00) EA = 1; if (DisableCount != 0xFF) DisableCount++; } void Disable_interrupts () { if (DisableCount == 0x00) EA = 0; if (DisableCount != 0xFF) DisableCount++; } Each sequential call to Disable_interrupts () will increment DisableCount counter. Only the first call will disable interrupts. Then so many Enable_interrupts () must be called to decrement DisableCount counter back to zero when interrupts will be enabled again. I use the latest on my ISDN project where frames are received in interrupt mode (must allocate a memory from the memory pool, decode the frame type and pass the information to the MFC task). Many function calls to do that. System task scheduler (messager) must disable interrupts poping the message and seting the global parameter variables, then the interrupts are enabled again. |
| Topic | Author | Date |
| does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
| RE: does anyone know the reason | 01/01/70 00:00 | |
RE: does anyone know the reason | 01/01/70 00:00 |



