📄 scatter_sample.c
字号:
/**********************************************************************/
/* */
/* Copyright (C) 2032 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ML675001 series */
/* Module Name : scatter loading sample main routine */
/* File Name : scatter_sample.c */
/* Revision : 01.00 */
/* Date : 2003/08/19 initial version */
/* */
/**********************************************************************/
#include "ml675001.h"
#include "common.h"
#include "irq.h"
#include "scatter.h"
/* constants */
#define MHz (1000000UL)
#define TMRCYC (10UL) /* 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))
#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 */
int rom_count(void); /* count up variable at external rom */
int ram_count(void); /* count up variable at internal ram */
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 */
/* variables */
volatile int timer_flag; /* 0:timer interrupt not occurred, 1:occurred */
volatile int counter_ram; /* */
volatile int counter_rom; /* */
/**********************************************************************/
/* 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();
for(;;){
counter_ram = ram_count();
counter_rom = rom_count();
}
led_on(LED_NORMAL_END_PATTERN); /* light LED end pattern */
return 0;
}
/**********************************************************************/
/* count up variable at external ROM */
/* Function : rom_count */
/* Parameters */
/* Input : Nothing */
/* Output : count up value */
/**********************************************************************/
int rom_count(void)
{
int count;
timer_flag = 0;
count = 0;
set_timer();
irq_en();
put_hvalue(TMEN, TMEN_TCEN); /* enable timer */
while(timer_flag == 0)
count++;
irq_dis();
return count;
}
/**********************************************************************/
/* 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 + -