| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #include "Timer.h"
- #include "boardinit.h"
- #include "../App/public.h"
- #include "../App/xspDataOpt.h"
- uint32_t g_iDelayfinish;
- volatile uint32_t gTimer_tickt = 0;
- TimerInfo g_timeInfo;
- void TIMER5_IRQHandler(void)
- {
- if(timer_flag_get(TIMER5,TIMER_FLAG_UP) != RESET){
- g_iDelayfinish = 1;
- timer_disable(TIMER5);
- timer_flag_clear(TIMER5,TIMER_FLAG_UP);/* 定时器更新中断的标识位需要手动清除 */
- }
- }
- void timer5_init(void)
- {
- timer_parameter_struct timer_initpara;
- rcu_periph_clock_enable(RCU_TIMER5);/* 使能TIMER5时钟 */
- /* TIMER5 初始化配置 */
- timer_deinit(TIMER5);
- timer_initpara.prescaler = 7200-1;/* 时钟预分频系数 10KHz*/
- timer_initpara.period = 1000-1;/* 自动重装载值 500-500us 1000-1ms */
- timer_initpara.counterdirection = TIMER_COUNTER_UP; /* 向上计数模式 */
- timer_init(TIMER5,&timer_initpara);
- timer_single_pulse_mode_config(TIMER5,TIMER_SP_MODE_SINGLE);
- //timer_enable(TIMER5);
- nvic_irq_enable(TIMER5_IRQn, 3, 3);/* TIMER5中断设置,抢占优先级3,子优先级3 */
- //timer_interrupt_enable(TIMER5,TIMER_INT_UP);/* 使能更新中断 */
- timer_flag_clear(TIMER5,TIMER_FLAG_UP);/* 定时器更新中断的标识位需要手动清除 */
- timer_interrupt_disable(TIMER5,TIMER_INT_UP);
- timer_counter_value_config(TIMER5,0);
- timer_disable(TIMER5);
- }
- void start_delay_ms(uint32_t delayms)
- {
- g_iDelayfinish = 0;
- //timer_prescaler_config(TIMER5,10800-1);
- timer_autoreload_value_config(TIMER5,delayms*10-1);
- timer_counter_value_config(TIMER5,0);
- timer_enable(TIMER5);
- timer_interrupt_enable(TIMER5,TIMER_INT_UP);/* 使能更新中断 */
- }
- void stop_delay_ms(void)
- {
- timer_disable(TIMER5);
- timer_flag_clear(TIMER5,TIMER_FLAG_UP);/* 定时器更新中断的标识位需要手动清除 */
- }
- static void display_led_status(uint32_t tickt)
- {
- static volatile uint8_t ledgreen = 0, ledred=0;
- static volatile uint8_t num = 0;
- if(0 == g_devMsg.ledgreen) { // 绿灯状态不亮
- gpio_bit_set(GPIOC, GPIO_PIN_13);
- }
- else if(1 == g_devMsg.ledgreen){ // 绿灯慢闪
- if(tickt%50000==0) {
- if(ledgreen==0) gpio_bit_set(GPIOC, GPIO_PIN_13);
- else gpio_bit_reset(GPIOC, GPIO_PIN_13);
- ledgreen = !ledgreen;
- }
- }
- else if(2 == g_devMsg.ledgreen) { // 绿灯快闪
- if(tickt%20000==0) {
- if(ledgreen==0) gpio_bit_set(GPIOC, GPIO_PIN_13);
- else gpio_bit_reset(GPIOC, GPIO_PIN_13);
- ledgreen = !ledgreen;
- }
- }
- else if(3 == g_devMsg.ledgreen) { // 绿灯常亮
- gpio_bit_reset(GPIOC, GPIO_PIN_13);
- }
- else if((4 == g_devMsg.ledgreen) ||(5 == g_devMsg.ledgreen)){
- if( g_devMsg.ledgreen == 5){
- if((tickt%30002) == 0){
- g_devMsg.ledgreen = 6;
- return;
- }
- }
- if(tickt%20000==0) {
- if(ledgreen==0) {
- gpio_bit_set(GPIOC, GPIO_PIN_13);
- gpio_bit_set(GPIOA, GPIO_PIN_0);
- }
- else {
- gpio_bit_reset(GPIOC, GPIO_PIN_13);
- gpio_bit_reset(GPIOA, GPIO_PIN_0);
- num++;
- if(num>g_devMsg.ledred){
- g_devMsg.ledgreen = 5;// 上电显示灯已经结束
- gpio_bit_set(GPIOC, GPIO_PIN_13);
- gpio_bit_set(GPIOA, GPIO_PIN_0);
- ledgreen = 1;
- }
- }
- ledgreen = !ledgreen;
- }
- return;
- }
- if(0 == g_devMsg.ledred) { // 红灯状态不亮
- gpio_bit_set(GPIOA, GPIO_PIN_0);
- }
- else if(1 == g_devMsg.ledred){ // 红灯慢闪
- if(tickt%50000==0) {
- if(ledred==0) gpio_bit_set(GPIOA, GPIO_PIN_0);
- else gpio_bit_reset(GPIOA, GPIO_PIN_0);
- ledred = !ledred;
- }
- }
- else if(2 == g_devMsg.ledred) { // 红灯快闪
- if(tickt%20000==0) {
- if(ledred==0) gpio_bit_set(GPIOA, GPIO_PIN_0);
- else gpio_bit_reset(GPIOA, GPIO_PIN_0);
- ledred = !ledred;
- }
- }
- else if(3 == g_devMsg.ledred) { // 红灯常亮
- gpio_bit_reset(GPIOA, GPIO_PIN_0);
- }
- }
- void TIMER4_IRQHandler(void)
- {
- volatile uint8_t status = 0,i = 0,j=0;
- volatile uint16_t status1 = 0,data;
- if(RESET != timer_flag_get(TIMER4,TIMER_FLAG_UP)){
- gTimer_tickt++;
- display_led_status(gTimer_tickt);
- // deal_gun_status(gTimer_tickt);
- #if (SEL_74CH165)
- // if((g_timeInfo.bExit == 1) &&((gTimer_tickt-g_timeInfo.exitTick)>=g_timeInfo.delay) ){
- // if((0 == g_timeInfo.bRead) && (RESET == gpio_input_bit_get(g_extimsg.csGroup,g_extimsg.extiPin))){
- // //exti_interrupt_disable(g_extimsg.extiLine); // 关闭外部中断
- // reset_port_pin(PLNALL,USE_PORT_ID);
- // delay_ms(3);//延时
- // set_port_pin(PLNALL,USE_PORT_ID);
- // g_timeInfo.bExit = 0;
- // g_timeInfo.bRead = 1;
- // }
- // }
- #else
- if((g_timeInfo.bExit == 1) &&((gTimer_tickt-g_timeInfo.exitTick)>=g_timeInfo.delay) ){
- status = gpio_input_bit_get(GPIOE,g_extimsg.extiPin);
- exti_interrupt_disable(g_extimsg.extiLine); // 关闭外部中断
- status1 = (status == 1 ? 0xFFFF : 0x0000);
- gpio_bit_set(GPIOD,GPIO_PIN_ALL);
- for(j=0;j<10;j++);
- for(i=0;i<8;i++){
- gpio_bit_reset(GPIOD,1<<i);
- gpio_bit_reset(GPIOD,1<<(i+8));
- for(j=0;j<10;j++);
- data = (status1^ gpio_input_port_get(GPIOE));//
- g_timeInfo.srcDa[i] = data&0xFF;
- g_timeInfo.srcDa[i+8] = (data>>8)&0xFF;
- gpio_bit_set(GPIOD,GPIO_PIN_ALL);// CS
- for(j=0;j<10;j++);
- }
- g_timeInfo.bExit = 0;
- g_timeInfo.bRead = 1;
- }
- #endif
- timer_flag_clear(TIMER4,TIMER_FLAG_UP);/* 定时器更新中断的标识位需要手动清除 */
- }
- }
- /*-------------------------------------------------------------------------
- * 初始化定时器4
- * 10us中断一次
- * ------------------------------------------------------------------------*/
- void timer4_init(void)
- {
- timer_parameter_struct timer_initpara;
- rcu_periph_clock_enable(RCU_TIMER4);/* 使能TIMER5时钟 */
- /* TIMER5 初始化配置 */
- timer_deinit(TIMER4);
- timer_initpara.prescaler = 71;/* 时钟预分频系数 */
- timer_initpara.period = 9;/* 自动重装载值 500-500us 1000-1ms */
- timer_init(TIMER4,&timer_initpara);
- timer_enable(TIMER4);
- nvic_irq_enable(TIMER4_IRQn, 3, 2);/* TIMER5中断设置,抢占优先级3,子优先级3 */
- timer_interrupt_enable(TIMER4,TIMER_INT_UP);/* 使能更新中断 */
- }
|