Jump to content
Sign in to follow this  
Shree

Serious Compiler Warnings

Recommended Posts

Hello Wizards,

I wrote a code for a timer, which counts from 0-999 secs/mins. This timer if interrupted by power failure would complete its count after the supply resumes. I had to detect the power failure and write the current count in EEPROM. I deployed RB0 external interrupt to detect power failure and tried to write eeprom in the ISR. The code compiled successfully but gave serious warnings:

 

Building...

BoostC Optimizing C Compiler Version 6.97 (for PIC16 architecture)

success

BoostLink Optimizing Linker Version 6.97

 

Building CASM file

Serious Warning: Possible sw stack corruption, function '__div_16_16' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

Serious Warning: Possible sw stack corruption, function '__rem_16_16' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

Serious Warning: Possible sw stack corruption, function 'write_eeprom' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

Memory Usage Report

===================

RAM available:368 bytes, used:66 bytes (18.0%), free:302 bytes (82.0%),

Heap size:110 bytes, Heap max single alloc:94 bytes

ROM available:8192 words, used:695 words (8.5%), free:7497 words (91.5%)

 

success

Done

When I removed the below mentioned part in the code, the code did compile fine without warnings

void interrupt()
{
   if(intcon.T0IF==1)
   {
	  some time counting code
	  intcon.T0if=0;
	}

	if(intcon.INTF==1)
	{
			  DISPEN=0; //Display Off
			  RELAY=0; //O/P relay off
			  POWER=0; //Power On LED off
			  if(counter!=check)//Checking whether the supply failed before the counting started
			 {
			write_eeprom(0x12,0x00);   //Starting from here is the code which generates warnings
				   disp2=counter/100;			 //A header file is created for writing and reading eeprom.
				   write_eeprom(0x11,disp2); //The counter is an integer so I have to divide it in 2 parts to store it in eeprom
				   disp1=counter%100;
					write_eeprom(0x10,disp1);
			  }		
			  intcon.INTF=0;
	 }
}

 

I think I am making some mistake or maybe there is a bug. Can somebody please help me?

Thanks in Advance

Regards

Shree

Share this post


Link to post
Share on other sites

The error is caused by you using divide, modulo and write_eeprom in the interrupt. You can get rid of the problem by setting a flag in the ISR and doing the write in your main code. Alternatively, do all writes to EEPROM in the ISR and change the divide and modulo to counter&255 and counter>>8 to split the int into two bytes.

 

Mike.

BTW, why is flood control set to 3 minutes. That is a very long time. I can read and reply to posts far quicker than that.

Share this post


Link to post
Share on other sites
BTW, why is flood control set to 3 minutes. That is a very long time. I can read and reply to posts far quicker than that.
Did not realise that was a limation. Now set to 30 seconds.

 

Regards

Dave

Share this post


Link to post
Share on other sites

As this is your power fail interrupt, you may not be able to avoid the need to write to the EEPROM in both this and the main code.

 

A alternative solution to the write_eeprom() warning would be to make a second copy of the function, write_eeprom_i() stripping out any GIE disable and enable code from it. just for use in the ISR. It will take a few more words of FLASH, but the write_eeprom() function isn't that big and other work-arounds may take more.

 

I'd go with Pommie's suggestion of using &255 and >>8 to avoid divides.

 

Ian

Share this post


Link to post
Share on other sites

When getting the high byte or low byte of an unsigned int x,

 

Is it more efficient to do x >> 8 instead of x / 256 ?

 

Similarly, to do x & 255 instead of x % 256 ?

Does aggressive optimization (-O a) treat these as one and the same?.

 

Will switching all my division and modulo operators in the main and interrupt threads eliminate the following warning?

Serious Warning: Possible sw stack corruption, function '__rem_8_8' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

 

Thanks,

-g reddy

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...