Example code for banked memory model

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Example code for banked memory model

Jump to solution
4,390 Views
ThomasH
Contributor II
Hi,
 
Where can I find example code or documents about programming in banked memory model? How do I have to declare functions,..... I can´t find any examples in the compiler documentation.
 
Thanks!
Thomas
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,256 Views
CrasyCat
Specialist III

Hello

Function should be declared as __near function as follows
/* prototype */
void __near Test_Func(void);
 
It should be defined in segment NON_BANKED as follows:
/* function code */
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void Test_Func(void)
{
  ....
  ....
}
#pragma CODE_SEG DEFAULT
 
That should be fine

CrasyCat

View solution in original post

0 Kudos
Reply
3 Replies
1,256 Views
CrasyCat
Specialist III

Hello

There is nothing special to do in respect of function definition when you are building in BANKED memory model.

Just rebuild everything with -Mb and the compiler will care about invoking the function with CALL instead of JSR.

Only think you have to really take care of is you HAVE TO place your interrupt function in NON BANKED flash. Entry within the vector table are 16-bit wide. So you need to make sure interrupt functions are placed in NON-BANKED memory.

I am usually recommending to define the interrupt function in the section NON_BANKED as follows:

#ifndef __SMALL__
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#endif
interrupt void INCcount(void) {
    /* Insert Code here */
}
#ifndef __SMALL__
#pragma CODE_SEG DEFAULT
#endif

I hope this helps.

CrasyCat

1,256 Views
ThomasH
Contributor II
Hello,
 
Thanks for your answer.
 
For example I have the function Test_Func. How do I have to declare this function that this function will be linked into the non banked section?
 
/* prototype */
void __near Test_Func(void);
 
/* function code */
void __near Test_Func(void)
{
  ....
  ....
}

Is the above declaration right or do I also have to use #pragma?

/* prototype */
void __near Test_Func(void);
 
/* function code */
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void __near Test_Func(void)
{
  ....
  ....
}
#pragma CODE_SEG DEFAULT
 
 
I´m sorry for my (stupid) questions - I´m a newbie in programming CodeWarrior.
 
Many thanks!
Thomas 

 

 


0 Kudos
Reply
1,257 Views
CrasyCat
Specialist III

Hello

Function should be declared as __near function as follows
/* prototype */
void __near Test_Func(void);
 
It should be defined in segment NON_BANKED as follows:
/* function code */
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void Test_Func(void)
{
  ....
  ....
}
#pragma CODE_SEG DEFAULT
 
That should be fine

CrasyCat

0 Kudos
Reply