Page 1 of 1

PIC Mask and acknowledge

Posted: Wed Feb 12, 2003 4:16 am
by DarylD
I think I may have a ickle bug in my PIC mask and acknowledge code.

Basically, could I have a sneaky-peak at others implementations to compare.

Thanks.

Daryl.

Re:PIC Mask and acknowledge

Posted: Thu Feb 13, 2003 10:35 am
by Slasher
I know what you mean. Initially mine worked, i had a master and slave mask for both master and slave pic.
I was saving the states in the inverse bits ie the way the pic excepts them, 0 - irq line enabled or 1 - irq line disabled.
but this was causing problems after i call the funtion to enable an irq level, say level 1. If call it again to enable say level 0, the system goes off the WALL.
so this is how i did it,

unsigned char master_mask,slave_mask;

void set_level(unsigned char level) /*levels from 0 to 15*/
{
if (level >=0 && level < 8) /*master pic*/
{
master=master|level;
mask_pic_master(~master);
}
else
if(level >= 8 && level <16)/* slave pic*/
{
level=level - 8;
slave=slave|level;
mask_pic_slave(~slave);
}
return;
}

the masks are stored in absolute form but inverted when sent to the pic.
Hope this helps;