📄 main.c
字号:
* Description : This function is called to initialize a periodic time source which will be used as the
* clock tick for uC/OS-II. The interrupt handler MUST point to OSTickISR (see OS_CPU_A.S).
*
*********************************************************************************************************
*/
static void AppTickInit (void)
{
OSVectSet(119, (void (*)(void))OSTickISR); /* Point the Timer 0 vector 55 to the int handler */
MCF_PIT0_PCSR = MCF_PIT_PCSR_PRE(8) | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD;
MCF_PIT0_PMR = 312500/OS_TICKS_PER_SEC;
MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF | MCF_PIT_PCSR_EN;
return;
}
/*//comment by michael chen
void led_toggle(INT8U led)
{
unsigned char i;
switch(led)
{
case 0x01:
case 0x02:
case 0x04:
case 0x08:
case 0x10:
case 0x20:
case 0x40:
case 0x80:
OS_ENTER_CRITICAL();
leds ^= led;
// printf("\nled is %02X.\n", led);
i = MCF_GPIO_PORTTC;
//printf("\ni is %02X.\n", i);
i = i & led;
if(i == 0x00)
{
MCF_GPIO_PORTTC = MCF_GPIO_PORTTC | led;
}
else
{
MCF_GPIO_CLRTC = MCF_GPIO_PORTTC & ~led;
}
OS_EXIT_CRITICAL();
(leds & led) ? led_enable(led) : led_disable(led);
default:
break;
}
}
void led_disable(INT8U led)
{
}
void led_enable(INT8U led)
{
}
unsigned char get_sw(void)
{
return 0x55;
}
void gpt_init(void)
{
}
*/
void isr_init()
{
INT16U int_no;
MCF_INTC_IMRH = 0xFF7FFFFF; // Enable PIT0 Int
MCF_INTC_IMRL = 0xFFFFFFFE; // Enable Global Ints
MCF_INTC_ICR55 = 0x08; // Int level 1, priority 0
OSVectSet(0x45, (void (*)(void))timer0_handler); /* Setup the context switch exception */
}
/*****************************************************
MENU
function:实现菜单选择功能,用户根据按钮来选择加载不同的演示程序。
扩展: 用户可以在根据需要在这里添加自己的菜单和对应的演示程序。
被static void AppStartTask (void *pdata)函数调用
******************************************************/
void menu(void)
{
/*初始化按键中断*/
MCF_GPIO_PNQPAR = 0
| MCF_GPIO_PNQPAR_IRQ1_IRQ1
| MCF_GPIO_PNQPAR_IRQ4_IRQ4
| MCF_GPIO_PNQPAR_IRQ5_IRQ5
| MCF_GPIO_PNQPAR_IRQ6_IRQ6
| MCF_GPIO_PNQPAR_IRQ7_IRQ7;
///* Set EPORT to look for level edges */
MCF_EPORT_EPPAR = 0
| MCF_EPORT_EPPAR_EPPA4_LEVEL
| MCF_EPORT_EPPAR_EPPA5_LEVEL
| MCF_EPORT_EPPAR_EPPA6_LEVEL
| MCF_EPORT_EPPAR_EPPA7_LEVEL;
/* Set EPORT to look for rising edges */
/*
MCF_EPORT_EPPAR = 0
| MCF_EPORT_EPPAR_EPPA4_RISING
| MCF_EPORT_EPPAR_EPPA5_RISING
| MCF_EPORT_EPPAR_EPPA6_RISING
| MCF_EPORT_EPPAR_EPPA7_RISING;
*/
/* Clear any currently triggered events on the EPORT */
MCF_EPORT_EPIER = 0
| MCF_EPORT_EPIER_EPIE4
| MCF_EPORT_EPIER_EPIE5
| MCF_EPORT_EPIER_EPIE6
| MCF_EPORT_EPIER_EPIE7;
/* Enable interrupts in the interrupt controller */
MCF_INTC_IMRL &= ~(0
| MCF_INTC_IMRL_MASK4
| MCF_INTC_IMRL_MASK5
| MCF_INTC_IMRL_MASK6
| MCF_INTC_IMRL_MASK7
| MCF_INTC_IMRL_MASKALL);
OSVectSet (64+4,(void (*)(void))sw2_interrupt);//安装isr
OSVectSet (64+5,(void (*)(void))sw3_interrupt);
OSVectSet (64+6,(void (*)(void))sw4_interrupt);
OSVectSet (64+7,(void (*)(void))sw5_interrupt);
MCF_EPORT_EPIER = MCF_EPORT_EPIER | 0x10;//enable IRQ4-7
/*set portDD direction to output*/
MCF_GPIO_DDRDD = 0xff;
printf("\n\nHHMCF5213EVB-KIRIN-R1!!!\n\r");
printf("this is the menu for demo:\n\r");
printf("00 (sw2 and sw2==1+1=2): play audio out!\n\r");
printf("01 (sw3 and sw2==2+1=3): play audio in and out!\n\r");
printf("02 (sw3 and sw3==2+2=4): play RS485!(115200-N-1)\n\r");
printf("03 (sw4 and sw2==4+1=5): play UART2!\n\r");
printf("04 (sw4 and sw3==4+2=6): play FlexCan\n\r");
printf("05 (sw4 and sw4==4+4=8): play RTC(use I2C)!\n\r");
printf("06 (sw5 and sw2==8+1=9): play ZigBee point to point!(audio communication)\n\r");
printf("waiting for your choice...\n\r");
button_value_current = 0;
button_flag = 0;
button_value = 0;
while(1)
{
if(button_flag ==2)
{
switch(button_value)
{
case 2:
printf("\n\nStart to play audio out demo...\r\n");
OSTaskCreate(AppTaskPwm, NULL, (void *)&AppTaskPwmStk[256], 5);
goto out_of_menu;
break;
case 3:
printf("\n\nStart to play audio in and out demo...\r\n");
OSTaskCreate(AppTaskAudioInOut,NULL,(void *)&AppTaskAudioInOutStk[256],6);
goto out_of_menu;
break;
case 4:
printf("\n\nStart to play RS485 demo ...\r\n");
printf("\nwe set RS485 port parameter as :\n");
printf("\nbaud: 115200");
printf("\ndata bits: 8");
printf("\nNo parity");
printf("\nNo flowcontrol\n");
OSTaskCreate(AppTaskRs485,NULL,(void *)&AppTaskRs485Stk[256],7);
goto out_of_menu;
break;
case 5:
printf("\n\nStart to play UART2 demo ...\r\n");
printf("\nwe set UART2 port parameter as :\n");
printf("\nbaud: 115200");
printf("\ndata bits: 8");
printf("\nNo parity");
printf("\nFlow control\n");
OSTaskCreate(AppTaskUart2,NULL,(void *)&AppTaskUart2Stk[256],8);
goto out_of_menu;
break;
case 6:
printf("\n\nStart to play FlexCan demo ...\r\n");
OSTaskCreate(AppTaskFlexCAN,NULL,(void *)&AppTaskFlexCANStk[256],9);
goto out_of_menu;
break;
case 8:
printf("\n\nStart to play RTC demo(use I2C) ...\r\n");
OSTaskCreate(AppTaskI2cIsl1208,NULL,(void *)&AppTaskI2cIsl1208Stk[256],10);
goto out_of_menu;
break;
case 9:
printf("\n\nStart to play ZigBee point to point demo ...\r\n");
OSTaskCreate(AppTaskZigbee,NULL,(void *)&AppTaskZigbeeStk[256],10);
goto out_of_menu;
break;
default:
printf("\n\nSorry!you have pressed wrong button!\nwaiting for your choice...\n");
}
button_value_current = 0;
button_flag = 0;
button_value = 0;
}
else
{
if (button_flag>2)
{
printf("\n\nSorry!You have pressed wrong button!\nwaiting for your choice...\n");
button_value_current = 0;
button_flag = 0;
button_value = 0;
}
}
}
out_of_menu:
led_display(button_value);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -