Jump to content
Sign in to follow this  
Guest Joe

Linker Memory Allocation Error

Recommended Posts

Guest Joe

Right, i need to post all my code for this error. There are 2 files, .c and .h, and im using device 12F629.

 

.h

#ifndef _ONOFFTIMER_H_
#define _ONOFFTIMER_H_

#include <system.h>    // standard include

#pragma  CLOCK_FREQ  32768 	 // 32.768kHz clock

// config word for PIC 12F629 (code protect disabled for debug)
#pragma  DATA 0x2007,	_CPD_OFF | _CP_OFF | _BODEN_ON | _MCLRE_OFF | _PWRTE_ON | _WDT_OFF | _LP_OSC;

// config word for PIC 12F629 (code protect enabled)
//	#pragma  DATA 0x2007,	_CPD_ON  | _CP_ON  | _BODEN_ON | _MCLRE_OFF | _PWRTE_ON | _WDT_OFF | _LP_OSC;

// chip ID
#pragma  DATA 0x2000,	0x0a, 0x0b, 0x0c, 0x0d;


// processor check
#ifndef _PIC12F629
 #error "Invalid processor, please check TARGET (12F629)";
#endif


#define TRUE 	 1
#define FALSE 	 0
//	typedef unsigned char	BYTE; 	 // 1 byte
//	typedef unsigned short	WORD; 	 // 2 bytes
//	typedef bit    BOOL; 	 // 1 bit
#define BOOL 	 unsigned char	// 1 byte
#define BYTE 	 unsigned char	// 1 byte
#define WORD 	 unsigned short	// 2 bytes

//	enum DaysOfTheWeek[] = { SUN, MON, TUE, WED, THU, FRI, SAT };
#define SUN  0
#define MON  1
#define TUE  2
#define WED  3
#define THU  4
#define FRI  5
#define SAT  6

// fatal error flash codes:
#define FATAL_ERROR_BROWN_OUT  5
#define FATAL_ERROR_INVALID_TIMES	10


////////////////////////////////////////////////////////////////////////////////////////
//  SETUP I/O CONFIGURATION /////////////////////////////////////////////////////////////
//
// GPIO pin usage:
//	GPIO.0 	 (in)	PowerDetect 	 (active low)
//	GPIO.1 	 (out)	LED   	 (active high)
//	GPIO.2 	 (out)	OutputEnable  (active high)
//	GPIO.3 	 (in)	[not used]
//	GPIO.4 	 (in)	[osc]
//	GPIO.5 	 (in)	[osc]
//	GPIO.6 	 (in)	[Pin does not exist]
//	GPIO.7 	 (in)	[Pin does not exist]

#define TRISIO_SETTING 	 11111001b  // i/o config
#define INIT_GPIO_SETTING  00000000b  // initial port state

volatile bit bUsingInternalBattery  @ GPIO.0;
volatile bit bLED      @ GPIO.1;
volatile bit bOutputEnable    @ GPIO.2;


void DoFatalError(BYTE FlashCode);

#endif //_ONOFFTIMER_H_

 

.c

#include "OnOffTimer.h"

/*
 The clock frequency is 32.768 kHz. This allows the internal timers to produce interrupts every 0.5 seconds.
 The output LED should flash ON --> OFF at 1Hz, so its state must be toggled every 0.5s.
 Using the prescaller set to 64, 8-bit TMR0 will interrupt every 500ms.
 
 At pre-programmed time periods, the output transistor will be enabled or disabled.
 
 If there is an error, the LED will flash a blink code, and perminatly enable the output.
*/

// Set these values below to the time when the device is programmed (24-hr clock):
BYTE g_byHours    = 14;  // 0 --> 23  
BYTE g_byMinutes  = 57;  // 0 --> 59
BYTE g_bySeconds  = 0;  // 0 --> 59
BYTE g_byDayOfWeek  = MON;  // 0 --> 6


typedef struct sTimes
{
BYTE OnTimeHours;
BYTE OnTimeMinutes;
BYTE OffTimeHours;
BYTE OffTimeMinutes;
}TIMES;
TIMES Times[7];

void ValidateTimes()
{
Times[SUN].OnTimeHours  = 12;	Times[SUN].OffTimeHours  = 3;
Times[SUN].OnTimeMinutes = 30;	Times[SUN].OffTimeMinutes	= 45;

Times[MON].OnTimeHours  = 12;	Times[MON].OffTimeHours  = 1;
Times[MON].OnTimeMinutes = 30;	Times[MON].OffTimeMinutes	= 30;

Times[TUE].OnTimeHours  = 12;	Times[TUE].OffTimeHours  = 2;
Times[TUE].OnTimeMinutes = 30;	Times[TUE].OffTimeMinutes	= 45;

Times[WED].OnTimeHours  = 12;	Times[WED].OffTimeHours  = 3;
Times[WED].OnTimeMinutes = 30;	Times[WED].OffTimeMinutes	= 45;

Times[THU].OnTimeHours  = 12;	Times[THU].OffTimeHours  = 3;
Times[THU].OnTimeMinutes = 30;	Times[THU].OffTimeMinutes	= 45;

Times[FRI].OnTimeHours  = 12;	Times[FRI].OffTimeHours  = 3;
Times[FRI].OnTimeMinutes = 30;	Times[FRI].OffTimeMinutes	= 45;

Times[SAT].OnTimeHours  = 12;	Times[SAT].OffTimeHours  = 3;
Times[SAT].OnTimeMinutes = 30;	Times[SAT].OffTimeMinutes	= 45;


BYTE x;
for(x = 0; x < 7; x++)
{
 if(Times[x].OnTimeHours  > 23)
 {
	 DoFatalError( FATAL_ERROR_INVALID_TIMES );
 }
//  if(Times[x].OnTimeMinutes  > 59)
 {
	 DoFatalError( FATAL_ERROR_INVALID_TIMES );
 }
//  if(Times[x].OffTimeHours > 23)
 {
	 DoFatalError( FATAL_ERROR_INVALID_TIMES );
 }
//  if(Times[x].OffTimeMinutes > 59)
 {
	 DoFatalError( FATAL_ERROR_INVALID_TIMES );
 }
}
}

void interrupt()
{
//
// This is called every time an interrupt occurs.
//

static BOOL bUpdateSeconds = bLED;

if( intcon & (1 << T0IF) )     	 // interrupt was caused by the TMR0 overflow
{
 clear_bit(intcon, T0IF);      // clear interrupt flag.

 // This interrupt occurs every 500ms, we need to toggle the LED (if using external power):

 if( ! bUsingInternalBattery )   	 // high if using internal battery
 {
	 bLED ^= 1;       	 // toggle LED if using external supply
 }	
 else
 {
	 // were using the internal battery. Switch off everything!
	 bLED = 0;
	 bOutputEnable = 0;
 }
 

 bUpdateSeconds ^= 1;     	 // toggle seconds updater flag (update secs every 2 interrupts)
 if( bUpdateSeconds )     	 // 2nd interrupt?
 {
	 g_bySeconds++;        // increment seconds
	 if( g_bySeconds > 59 )      // 60 seconds passed?
	 {
   g_bySeconds = 0;      // secounds back to zero
   g_byMinutes++;     	 // increment minutes
   if( g_byMinutes > 59 )   	 // 60 minutes passed?
   {
  	 g_byMinutes = 0;   	 // minutes back to zero
  	 g_byHours++;      // increment hours
  	 if( g_byHours > 23 )    // 24 hours passed?
  	 {
     g_byHours = 0;   	 // hours back to zero
     g_byDayOfWeek++;    // increment day of week
     if( g_byDayOfWeek > 6 ) 	 // 7 days passed?
     {
    	 g_byDayOfWeek = 0; 	 // day of week back to Sunday
     }	
  	 } //if( g_byHours > 23 )
   } //if( g_byMinutes > 59 )
	 } //if( g_bySeconds > 59 )
 
 
	 // The seconds was incremented
	 if( ! bUsingInternalBattery )   	 // are we using internal power?
	 {
   // not using internal power..
   // update the on / off status
   
   if( 
     ((g_byHours   >= Times[g_byDayOfWeek].OnTimeHours  ) && (g_byHours   < Times[g_byDayOfWeek].OffTimeHours  ))
  	 &&	((g_byMinutes >= Times[g_byDayOfWeek].OnTimeMinutes) && (g_byMinutes < Times[g_byDayOfWeek].OffTimeMinutes))
   )
   {
  	 bOutputEnable = 1;
   }
   else
   {
  	 bOutputEnable = 0;
   }
	 }
 } //if( bUpdateSeconds )
}
}




void main(void)
{
gpio	= INIT_GPIO_SETTING;     	 // inital output levels
trisio	= TRISIO_SETTING;        // port data direction
cmcon  |= 0x07;         	 // change CMCON to use digital inputs
wpu  = 00000001b;       	 // enable weak pullup on GP0

option_reg = 0xff	& (0 << NOT_GPPU)   	 // enable internal weak pull-ups
     & (0 << T0CS)      // use TMR0 as a counter
     & (0 << PSA)      // use prescaller for TMR0
     & (101b << PS0)      // using prescaller 1:64
 ;
tmr0 = 0x00;         	 // reset the timer

// clear interrupt flags (must be done before enabling interrupts):
intcon &= 11111000b;       	 // clear last 3-bits (interrupt flags)

// enable required interrupts:
intcon = 0x00	| (0 << GIE)     	 // globally disable interrupts (for now)
  	 | (0 << PEIE)     	 // disable peripheral interrupts
  	 | (1 << T0IE)     	 // enable TMR0 interrupt
  	 | (0 << INTE)     	 // disable GP2 interrupt
  	 | (0 << GPIE)     	 // disable port changed interrupt
  	 | (0 << T0IF)     	 // TMR0 interrupt flag
  	 | (0 << INTF)     	 // GP2 interrupt flag
  	 | (0 << GPIF)     	 // port changed interrupt flag
;

// figure out why the device restarted:
if( pcon & (1 << NOT_BOD) )
{
 // the device reset because it browned-out, the battery needs changing.
 DoFatalError(FATAL_ERROR_BROWN_OUT);
}

ValidateTimes();          // ensure times are set correctly

set_bit(option_reg, GIE);        // globally enable interrupts
for(;;);            // loop forever (program is interrupt driven)


}// end of main



void DoFatalError(BYTE FlashCode)
{
clear_bit(intcon, GIE);        // disable all interrupts

for(;;)            // flash the led fast forever.
{
 if( bUsingInternalBattery )      // using internal battery
 {
	 bOutputEnable = 0;     	 // no output
	 bLED = 0;       	 // LED off
	 continue;
 }

 bOutputEnable = 1;        // enable the output

 BYTE x;
 for(x = 0; x < FlashCode; x++)
 {
	 bLED = 1; delay_ms(150);
	 bLED = 0; delay_ms(150);
 }
 delay_ms(500);
}
}

 

Copy and paste that lot into the approprate files, and compile, then link:

 

Memory Usage Report
===================
RAM available:64 bytes, used:44 bytes (68.8%), free:20 bytes (31.2%)
ROM available:1024 bytes, used:333 words (32.6%), free:691 words (67.4%)

Successful
Done

 

no probmes, we have 20 bytes free in ram, great...

 

Scroll to line 60 in the .C file, and uncomment this line:

 

if(Times[x].OnTimeMinutes > 59)

 

 

This code should require 3 bytes of RAM to execute, that's ok, we've got 20 !!

 

Now compile, and link...

 

Error: Memory allocation failed -  No remaining memory block (on target) big enough for: '' size:1 bytes
Failed
Done

 

Oh dear, we appear to have ram out of memory! -- This must be a bug!

 

 

-- Here is another bug, add that coment into line 60 again, and go into the header file and uncomment lines 26, 27, 28 (typedefs)

 

then comment out lines 29, 30, 31 (defines)

so it now looks like this:

	typedef unsigned char	BYTE; 	 // 1 byte
typedef unsigned short	WORD; 	 // 2 bytes
typedef bit    BOOL; 	 // 1 bit
//	#define BOOL 	 unsigned char	// 1 byte
//	#define BYTE 	 unsigned char	// 1 byte
//	#define WORD 	 unsigned short	// 2 bytes

 

 

 

Compile (no errors) link:

Internal Error: Var:OnTimeHours Unrecognised type id:268435756
Internal Error: Var:OnTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OffTimeHours Unrecognised type id:268435756
Internal Error: Var:OffTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OnTimeHours Unrecognised type id:268435756
Internal Error: Var:OnTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OffTimeHours Unrecognised type id:268435756
Internal Error: Var:OffTimeMinutes Unrecognised type id:268435756

 

Oh dear ! -- what on earth does this mean ?! -- And afer all those internal errors, the linker is reporting SUCCESS !

 

 

Joe

Share this post


Link to post
Share on other sites
Compile (no errors) link:

Internal Error: Var:OnTimeHours Unrecognised type id:268435756
Internal Error: Var:OnTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OffTimeHours Unrecognised type id:268435756
Internal Error: Var:OffTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OnTimeHours Unrecognised type id:268435756
Internal Error: Var:OnTimeMinutes Unrecognised type id:268435756
Internal Error: Var:OffTimeHours Unrecognised type id:268435756
Internal Error: Var:OffTimeMinutes Unrecognised type id:268435756

 

 

Joe,

 

I cant reproduced this one, can you send me a project demonstrating the issue.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Joe,

 

Memory Usage Report
===================
RAM available:64 bytes, used:44 bytes (68.8%), free:20 bytes (31.2%)
ROM available:1024 bytes, used:333 words (32.6%), free:691 words (67.4%)

Successful
Done

 

no probmes, we have 20 bytes free in ram, great...

 

Scroll to line 60 in the .C file, and uncomment this line:

   

        if(Times[x].OnTimeMinutes  > 59)

 

 

This code should require 3 bytes of RAM to execute, that's ok, we've got 20 !!

 

Now compile, and link...

 

Error: Memory allocation failed -  No remaining memory block (on target) big enough for: '' size:1 bytes
Failed
Done

 

Oh dear, we appear to have ram out of memory! -- This must be a bug!

 

The problem was that the memory usage report showed the maximum used by any one thread, not the total - if you look at you interrupt routine it uses 19 bytes, hence why we runout when you add that last piece of code in.

 

This is now fixed - and will be available in the next release V1.9.

 

Regards

Dave

Share this post


Link to post
Share on other sites
- and when can i get hold of 1.9?

 

Soon. Maybe even later today.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Guest Joe

The memory report bug is fixed in BC1.9, but the internal error bug is not.

 

I have posted another bug report that gives a short code example to reproduce this error 100%

 

 

Joe

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...