📄 remap_sample.c
字号:
/**********************************************************************/
/* */
/* Copyright (C) 2003 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ML675001 series CPU BOARD */
/* Module Name : remap sample main routine */
/* File Name : remap_sample.c */
/* Revision : 01.00 */
/* Date : 2003/08/18 */
/* */
/**********************************************************************/
#include "ml675001.h"
#include "common.h"
#include "irq.h"
#include "scatter.h"
/* constants */
#define MHz (1000000UL)
#define TMRCYC (15UL) /* interval of TIMER interrupt (ms) */
#define CCLK (60UL*(MHz)) /* frequency of CCLK */
#define VALUE_OF_TMRLR /* reload value of timer */\
((0x10000UL*(16UL*1000UL)-((TMRCYC)*(CCLK))+(8UL*1000UL))/(16UL*1000UL))
#define BANK10_BASE 0x50000000 /* base address of Bank10 */
#if ((0xFFFFFFFFUL/(TMRCYC)) < (CCLK))
#error Invalid value : TMRCYC
#endif
#if ((0x10000L*(16*1000)+(8*1000)) < ((TMRCYC)*(CCLK)))
#error Invalid value : TMRCYC
#endif
#if (0x10000 <= (VALUE_OF_TMRLR))
#error Invalid value : TMRCYC
#endif
/* functions */
int main(void); /* main routine */
void remap_bank10(void); /* remap bank10 */
int count(void); /* count up variable */
void init_irq(void); /* initialize IRQ */
void reg_irq_handler(void); /* registration of IRQ handler */
void set_timer(void); /* setup TIMER */
void timer_handler(void); /* TIMER handler */
void copy_code(void); /* copy code region from bank0 to bank2 */
/* variables */
volatile int timer_flag; /* 0:timer interrupt not occurred, 1:occurred */
volatile int counter_ram;
/* symbols defined by linker */
extern UWORD Image$$BANK0$$Base;
extern UWORD Image$$BANK0$$Limit;
#define image_bank0_base ((UWORD)(&Image$$BANK0$$Base))
#define image_bank0_limit ((UWORD)(&Image$$BANK0$$Limit))
/**********************************************************************/
/* Entry point */
/* Function : main */
/* Parameters */
/* Input : Nothing */
/* Output : 0 */
/**********************************************************************/
int main(void)
{
/* initialize LED */
init_led();
led_on(LED_START_PATTERN); /* light LED start pattern */
init_irq();
reg_irq_handler();
copy_code();
remap_bank10();
counter_ram = count();
led_on(LED_NORMAL_END_PATTERN); /* light LED end pattern */
return 0;
}
/**********************************************************************/
/* copy code region from bank0 to bank2 */
/* Function : copy code */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/**********************************************************************/
void copy_code(void)
{
UWORD i;
UWORD data;
for(i=image_bank0_base; i<image_bank0_limit; i+=4){
data = get_wvalue(i);
put_wvalue(BANK10_BASE+(UWORD)i, data);
}
return;
}
/**********************************************************************/
/* remap bank10 */
/* Function : remap_bank10 */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/**********************************************************************/
void remap_bank10(void)
{
volatile UWORD dummy_read;
put_wvalue(RMPCON, 0x3C);
put_wvalue(RMPCON, 0x0A);
dummy_read = get_wvalue(RMPCON); /* dummy read */
return;
}
/**********************************************************************/
/* Setup of timer */
/* Function : set_timer */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/**********************************************************************/
void set_timer(void)
{
put_hvalue(TMEN, 0x0000); /* disable timer */
put_hvalue(TMOVF, TMOVF_OVF); /* clear overflow register */
put_hvalue(TMRLR, VALUE_OF_TMRLR); /* set timer reload value */
return;
}
/**********************************************************************/
/* Timer handler */
/* Function : timer_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/**********************************************************************/
void timer_handler(void)
{
timer_flag = 1;
put_hvalue(TMOVF, TMOVF_OVF); /* clear TMOVF register */
put_hvalue(TMEN, 0x0000); /* disable timer */
return;
}
/**********************************************************************/
/* Registration of IRQ Handler */
/* Function : reg_irq_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/**********************************************************************/
void reg_irq_handler(void)
{
IRQ_HANDLER_TABLE[INT_SYSTEM_TIMER] = timer_handler; /* set IRQ handler table */
set_wbit(ILC0, ILC0_ILR0 & ILC0_INT_LV1); /* set IRQ level */
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -