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

Seeking Wisdom; Func calls from interupt and Volatile

Hi Everyone,
I have 3 controllers, all using SILABS C8051F040 SOC. They perfrom various functions on there own and communicate via CAN. They are working well together (I fixed one major problem I will detail further down). The transmission of data is handled by configuring message boxes on the fly and transmitting them and works well. The reception is handled by an interupt routine activated by a message that passes the arbritation filters. When the interupt routine is called, it calls a function I named cancieve(). Here is a sample of the beggining of one conrollers cancieve function

xdata unsigned int rx_buff[4];
xdata union {
float floater;
unsigned long int longinter;
unsigned char string[4];
unsigned long int mscounter;
unsigned int interger[2];
}	float_char;
unsigned char org_msgnum;
unsigned char PRI_LEV;

org_msgnum= CAN_sep_ident(CAN_receive_data (msg_number, rx_buff), &PRI_LEV);

if ((PRI_LEV==7)&&(org_msgnum==5))
	{
		exc_noCAN_cntr=0;	//reset exciter no value counter
		float_char.interger[0]=rx_buff[0];
		float_char.interger[1]=rx_buff[1];
		EXC_STATUS1=float_char.string[0];
		EXC_STATUS2=float_char.string[1];

		return;
	}
all such code blocks are structured so that they retrieve the message with the matching PRI_LEV and org_msgnum and return to the interupt routine and exit the interupt.

The code works as intended and is not my real question (please let me know if I should elaborate on it, one note; the PRI_LEV and org_msgnum are made from the CAN identifier). The cancieve function in this controller and others may have several such blocks of code intended to handle specific incoming messages.

My first question is, is it wise to be calling such a function from an interupt routine, or should I consider other methods? The elements of any CAN message are one byte for PRI_LEV, one BYTE for msg_num, and 4 words (8 bytes) of data. I've considered using a buffered data structure to hold these messages as they come in and handle them in the main loop of the program, but I'm not sure if this method will work better than what I have now.
It all appears to work well but I wonder if I may be causing myself further problems down the line.

The only problem that developed form the above mentioned method was that one particular byte of information transfered from one controller to another was getting scrambled on occasion. This particular byte was declared in the sending and recieving controller as -
bdata unsigned char EXC_STATUS3;
sbit I_LEAD_OV		=EXC_STATUS3^0;	//current lead over voltage
sbit RECIRC_DIODE_OT=EXC_STATUS3^1;	//re-circulating diode over temp
sbit ABORT_RES_OT	=EXC_STATUS3^2;	//dump resistor over temp
sbit ABORT_IGBT_OT	=EXC_STATUS3^3;
sbit AMB_TEMP_OT	=EXC_STATUS3^5;
sbit SHNTFLT_SOFT	=EXC_STATUS3^6;
sbit SYS_HEARTBEET	=EXC_STATUS3^7;
one instance of any of these bit variables going high would cause our system (a very expensive power system) to trip offline, causing many a headache and a lot of trouble for yours truly). I looked through the database on this site and found the following -
http://www.keil.com/support/docs/1863.htm
which details a problem similar, if not exactlyas mine. I changed the definition to
volatile unsigned char bdata EXC_STATUS3;

sbit I_LEAD_OV		=EXC_STATUS3^0;	//current lead over voltage
sbit RECIRC_DIODE_OT=EXC_STATUS3^1;	//re-circulating diode over temp
sbit ABORT_RES_OT	=EXC_STATUS3^2;	//dump resistor over temp
sbit ABORT_IGBT_OT	=EXC_STATUS3^3;
sbit AMB_TEMP_OT	=EXC_STATUS3^5;
sbit SHNTFLT_SOFT	=EXC_STATUS3^6;
sbit SYS_HEARTBEET	=EXC_STATUS3^7;
and the problem appears to have gone away. I never had to declare anything as volatile before and am still looking into what it really means.

But for the experts out there, should I be declaring all bdata types as volatile? Is there a rule of thumb for this?

I did start by making any bdata type that gets changed in the interupt function cancieve as volitile. I also wait for a few consecutive occurrances of the individual bits being high before acting on them and my system is running very well for the time being (on the bench anyway).

Well that was a little longer winded than I intended. Any advice or suggestions are greatly appreciated and have a great weekend.

Andy

0