Example code for banked memory model

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Example code for banked memory model

跳至解决方案
4,058 次查看
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
标签 (1)
标记 (1)
0 项奖励
1 解答
924 次查看
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 项奖励
3 回复数
924 次查看
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

924 次查看
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 项奖励
925 次查看
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 项奖励