📄 main_entry.c
字号:
/*****************************************************************************
*Name:led_test.c
*Brief:Test Pioc
*****************************************************************************/
/* 定义32位寄存器的写操作函数 */
#define HAL_WRITE_UINT32( _register_, _value_ ) (*((volatile unsigned int *)(_register_)) = (_value_))
#define EP9312_CLKSET1 0x80930020 /* 时钟速率控制寄存器1 */
#define EP9312_CLKSET2 0x80930024 /* 时钟速率控制寄存器2 */
#define EP9312_CLKSET1_NBYP 0x00800000
#define EP9312_CLKSET1_HCLKDIV_SHIFT 20
#define EP9312_CLKSET1_FCLKDIV_SHIFT 25
#define EP9312_CLKSET1_PCLKDIV_SHIFT 18
#define Timer1Load ((volatile unsigned int *) 0x80810000) /* 定时器1的加载寄存器 */
#define Timer1Clear ((volatile unsigned int *) 0x8081000C) /* 定时器1的中断清除寄存器 */
#define Timer1Control ((volatile unsigned int *) 0x80810008) /* 定时器1的控制寄存器 */
#define VIC1IntSelect ((volatile unsigned int *) 0x800B000C) /* 向量中断控制器1的中断选择寄存器 */
#define VIC1IntEnable ((volatile unsigned int *) 0x800B0010) /* 向量中断控制器1的中断使能寄存器 */
#define VIC1VectAddr0 ((volatile unsigned int *) 0x800B0100) /* 向量中断控制器1的向量地址寄存器0 */
#define VIC1VectCntl0 ((volatile unsigned int *) 0x800B0200) /* 向量中断控制器1的向量控制寄存器0 */
#define VIC1VectAddr ((volatile unsigned int *) 0x800B0030) /* 向量中断控制器1的向量地址寄存器 */
#define PBDR ((volatile unsigned int *) 0x80840004) /* GPIOB的数据寄存器 */
#define PBDDR ((volatile unsigned int *) 0x80840014) /* GPIOB的方向寄存器 */
/**************************************************************************/
/* ep9301的底层初始化函数,配置ep9301的所有时钟 */
void AT91F_LowLevelInit(void)
{
unsigned int ClkSet1;
unsigned int ClkSet2;
/* Set the output of PLL2 to 192Mhz */
ClkSet2 = 0x300dc317;
/* Set the output of the PLL to 332Mhz */
ClkSet1 = EP9312_CLKSET1_NBYP | 0x00fa5a;
/* Set the FCLKDIV value to divide by 2 (166Mhz). */
ClkSet1 |= (1 << EP9312_CLKSET1_FCLKDIV_SHIFT);
/* Set the HCLKDIV value to divide by 5 (66Mhz). */
ClkSet1 |= (3 << EP9312_CLKSET1_HCLKDIV_SHIFT);
/* Set PCLKDIV so that PCLK = HCLK / 2 */
ClkSet1 |= (1 << EP9312_CLKSET1_PCLKDIV_SHIFT);
/* Write out the value to ClkSet 1 */
HAL_WRITE_UINT32(EP9312_CLKSET1, ClkSet1);
/* Do the five required nops to flush the ARM920T instruction pipeline. */
__asm
{ nop }
__asm
{ nop }
__asm
{ nop }
__asm
{ nop }
__asm
{ nop }
/* Write out the value to ClkSet 2 */
HAL_WRITE_UINT32(EP9312_CLKSET2, ClkSet2);
/* Go to Async mode */
__asm
{ mrc p15, 0, r0, c1, c0, 0 }
__asm
{ orr r0, r0, #0xc0000000 }
__asm
{ mcr p15, 0, r0, c1, c0, 0 }
/* TODO remove this hack. This is to set the wait states to max for Flash.*/
HAL_WRITE_UINT32(0x80080018, 0x1000FFFF);
}
/* IRQ中断的C处理函数 */
void Irq_C_Handler(void)
{
typedef void (*lpFunction)(); /* 定义一个void型函数指针 */
lpFunction isr = (lpFunction)(*(VIC1VectAddr)); /* 读出VIC1VectAddr寄存器中的中断服务程序函数地址 */
isr(); /* 执行中断服务程序 */
*(VIC1VectAddr)=0x1; /* 写VIC1VectAddr寄存器,表示中断已响应 */
}
/* 定时器1的中断服务函数 */
int flag;
void time1_handler(void)
{
*Timer1Clear=0x1; /* 清除定时器1中断 */
flag++;
if(flag==8) flag=0;
*(PBDR)=0x1<<flag; /* 循环点亮LED */
}
/* 主函数C_Entry */
extern void C_Entry(void)
{
flag =0;
*(PBDDR)=0xff; /* 设置GPIOB的为输出模式 */
*(PBDR)=0x01; /* 设置GPIOB输出为0x01 */
*VIC1IntSelect = 0x0; /* 设置所有中断为IRQ中断 */
*VIC1VectAddr0 = (unsigned long) time1_handler; /* 将定时器1的中断服务函数地址写入向量中断控制器1的向量地址寄存器0 */
*VIC1IntEnable = 0x10; /* 使能定时器1中断 */
*VIC1VectCntl0 = 0x24; /* 选择定时器1中断为向量中断,并使能向量中断 */
*Timer1Load = 0x2ff; /* 加载定时器1的加载寄存器 */
*Timer1Control = 0xc0; /* 设置定时器1的时钟源:2kHz,模式:预加载模式,并使能定时器1 */
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -