void main() { u8 time_counter_for_cycle = 4; disable_all_interrupt(); //设置输出口、中断 require_delay_init(); InitUart(); init_system_component(); //初始化端口 P33 = 0; enable_all_interrupt(); //检测当前状态 detect_current_state(); while(1) { // Feed dog reset_watch_dog(); // 驱动灯光开关 // toggle_once(); // 5ms system tick-tock if (INT_PROC & TICK_DUTY) { cycle_based_adjust(counter_for_cycle); INT_PROC &= ~TICK_DUTY; // continue; } if (INT_PROC & EXINT_PROC) { EX0 = 0; // SendData(time_counter>>8); // SendData(time_counter); if(time_counter <= 80) { if(display_mode_set == combination) { -- time_counter_for_cycle; } // 循环四次跳至下一个功能 if(!time_counter_for_cycle) { display_mode_logic++; time_counter_for_cycle = 4; } if(display_mode_logic == 13) display_mode_logic = 1; // SendData(display_mode_logic); display_mode_set_changed(); } if(display_mode_set == bi_directional_storbing) { if(time_counter >= 4000 && time_counter < 20000){ display_mode_logic ++; if(display_mode_logic == 13) display_mode_logic = 1; } if(time_counter >= 40000) display_mode_logic = 2; EEPROM_SectorErase(IAP_ADDRESS); EEPROM_write(IAP_ADDRESS, display_mode_logic); // SendData(display_mode_logic); display_mode_set_changed(); } time_counter = 0; INT_PROC &= ~EXINT_PROC; EX0 = 1; continue; } } }
void main() { u8 k = 8; // stop catching interrupt disable_all_interrupt(); // require_delay_init(); while(--k) { Delay1000ms(); } // -> sync.h sync_with_alert(); instant_effective_init(); // begin catching interrupt enable_all_interrupt(); // run forever while(1) { // Feed dog reset_watch_dog(); if (INT_PROC & UART_PROC) { signal_t signal_raw = recieve_data_from_buffer(); parse_crtl_signal(signal_raw); INT_PROC &= ~UART_PROC; continue; } // io status sampling finished if (INT_PROC & LM567_DUTY) { signal_t signal_raw; u8 signal_raw_search_index = 0, signal_raw_fall_counter = 2; if(quick_validate_signal(signal_raw_data)) { while (signal_raw_search_index < 7) { if ((signal_raw_data & (0x03 << signal_raw_search_index)) == (0x02 << signal_raw_search_index)) { ++signal_raw_search_index; ++signal_raw_fall_counter; } ++signal_raw_search_index; } if (fall_counter_whole < signal_raw_fall_counter) { signal_raw = effective_signal(signal_raw_data); parse_crtl_signal(signal_raw); } } INT_PROC &= ~LM567_DUTY; EX1 = ENABLE; continue; } // 60hz * 2 if (INT_PROC & EXINT_PROC) { // if (cycle_output && toggle_status) if (toggle_status) toggle_once(); // -> display.h prepare_next_display_params(); INT_PROC &= ~EXINT_PROC; continue; } // // 5ms system tick-tock if (INT_PROC & TICK_DUTY) { cycle_based_adjust(counter_for_cycle); INT_PROC &= ~TICK_DUTY; continue; } if (INT_PROC & MINUTE_DUTY) { // -> display.h skip_to_next_display_if_should(); INT_PROC &= ~MINUTE_DUTY; continue; } if (adc_should_sampling) { adc_sampling(); } } }
/* Testet coreinterrupt_e Die Funktion generate_coreinterrupt wird danach getestet, ob ein Interrupt tatsächlich generiert und ausgeführt wird. Danach werden die Interrupts maskiert und is_coreinterrupt und clear_coreinterrupt werden getestet. Die Funktion ispending liefert 1, wenn ein generierter Interrupt auf Ausführung wartet, d.h. die Priorität ist nicht ausreichend oder alle Interrupts wurden maskiert. Die Funktion clearpending löscht das Pending-Flag des Interrupts, so dass ispending 0 liefert und der Interrupt daher nicht mehr ausgeführt wird. */ int main(void) { uint8_t led = 0; unsigned i; enable_gpio_clockcntrl(GPIO_PORTA_BIT/*switch*/|GPIO_PORTE_BIT/*led*/); config_input_gpio(GPIO_PORTA, GPIO_PIN0, GPIO_PULL_OFF); config_output_gpio(GPIO_PORTE, GPIO_PINS(15,8)); // Teste Interrupt Ausführung for (i = 0; i <= 16; ++i) { for (unsigned p = 0; p < sizeof(pos)/sizeof(pos[0]); ++p) { pos[p] = 0; } switch (i) { case coreinterrupt_NMI: case coreinterrupt_MPUFAULT: case coreinterrupt_BUSFAULT: case coreinterrupt_USAGEFAULT: case coreinterrupt_SVCALL: case coreinterrupt_DEBUGMONITOR: case coreinterrupt_PENDSV: case coreinterrupt_SYSTICK: if (generate_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if ( i == coreinterrupt_MPUFAULT || i == coreinterrupt_BUSFAULT || i == coreinterrupt_USAGEFAULT) { if (counter != 0) goto ONERR; // pending if (enable_coreinterrupt(i) != 0) goto ONERR; if (counter != 1 || pos[i] != 1) goto ONERR; // interrupt executed if (disable_coreinterrupt(i) != 0) goto ONERR; } else { if (counter != 1 || pos[i] != 1) goto ONERR; // interrupt executed if (EINVAL != enable_coreinterrupt(i)) goto ONERR; if (EINVAL != disable_coreinterrupt(i)) goto ONERR; } if (counter != 1) goto ONERR; // no second interrupt turn_on_led(led++); for (int i = 0; i < 50000; ++i) ; counter = 0; break; default: if (generate_coreinterrupt((coreinterrupt_e)i) != EINVAL) goto ONERR; if (counter != 0) goto ONERR; break; } } // Teste Interrupt Pending for (i = 0; i <= 16; ++i) { for (unsigned p = 0; p < sizeof(pos)/sizeof(pos[0]); ++p) { pos[p] = 0; } switch (i) { case coreinterrupt_MPUFAULT: case coreinterrupt_BUSFAULT: case coreinterrupt_USAGEFAULT: case coreinterrupt_SVCALL: case coreinterrupt_DEBUGMONITOR: case coreinterrupt_PENDSV: case coreinterrupt_SYSTICK: enable_coreinterrupt(i); disable_all_interrupt(); if (generate_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if (is_coreinterrupt((coreinterrupt_e)i) != 1) goto ONERR; for (unsigned p = 0; p < 16; ++p) { if (is_coreinterrupt((coreinterrupt_e)p) != (p==i)) goto ONERR; } if (clear_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if (is_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; for (unsigned p = 0; p < 16; ++p) { if (is_coreinterrupt((coreinterrupt_e)p) != 0) goto ONERR; } enable_all_interrupt(); if (counter != 0) goto ONERR; disable_coreinterrupt(i); turn_on_led(led++); for (int i = 0; i < 50000; ++i) ; break; case coreinterrupt_NMI: // not maskable default: if (is_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if (clear_coreinterrupt((coreinterrupt_e)i) != EINVAL) goto ONERR; if (counter != 0) goto ONERR; break; } } // Teste Interrupt Priority for (i = 0; i <= 16; ++i) { switch (i) { case coreinterrupt_MPUFAULT: case coreinterrupt_BUSFAULT: case coreinterrupt_USAGEFAULT: case coreinterrupt_SVCALL: case coreinterrupt_DEBUGMONITOR: case coreinterrupt_PENDSV: case coreinterrupt_SYSTICK: enable_coreinterrupt(i); if (setpriority_coreinterrupt((coreinterrupt_e)i, 3) != 0) goto ONERR; if (getpriority_coreinterrupt((coreinterrupt_e)i) != 3) goto ONERR; setbasepriority_interrupt(3); if (generate_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if (is_coreinterrupt((coreinterrupt_e)i) != 1) goto ONERR; if (setpriority_coreinterrupt((coreinterrupt_e)i, 2) != 0) goto ONERR; if (getpriority_coreinterrupt((coreinterrupt_e)i) != 2) goto ONERR; if (is_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; if (counter != 1 || pos[i] != 1) goto ONERR; // interrupt executed counter = 0; // reset if (setpriority_coreinterrupt((coreinterrupt_e)i, 0) != 0) goto ONERR; if (getpriority_coreinterrupt((coreinterrupt_e)i) != 0) goto ONERR; disable_coreinterrupt(i); turn_on_led(led++); for (int i = 0; i < 50000; ++i) ; break; case coreinterrupt_NMI: // not maskable with priority default: break; } } // Teste disable_coreinterrupt bei MPUFAULT, BUSFAULT, USAGEFAULT generate_coreinterrupt(coreinterrupt_MPUFAULT); generate_coreinterrupt(coreinterrupt_BUSFAULT); generate_coreinterrupt(coreinterrupt_USAGEFAULT); if (is_coreinterrupt(coreinterrupt_MPUFAULT) != 1) goto ONERR; if (is_coreinterrupt(coreinterrupt_BUSFAULT) != 1) goto ONERR; if (is_coreinterrupt(coreinterrupt_USAGEFAULT) != 1) goto ONERR; clear_coreinterrupt(coreinterrupt_MPUFAULT); clear_coreinterrupt(coreinterrupt_BUSFAULT); clear_coreinterrupt(coreinterrupt_USAGEFAULT); if (is_coreinterrupt(coreinterrupt_MPUFAULT) != 0) goto ONERR; if (is_coreinterrupt(coreinterrupt_BUSFAULT) != 0) goto ONERR; if (is_coreinterrupt(coreinterrupt_USAGEFAULT) != 0) goto ONERR; if (counter != 0) goto ONERR; // 2 grüne LEDs turn_on_led(3); write1_gpio(GPIO_PORTE, GPIO_PIN11|GPIO_PIN15); while (1) ; ONERR: // 2 rote LEDs enable_all_interrupt(); enable_fault_interrupt(); write1_gpio(GPIO_PORTE, GPIO_PIN9|GPIO_PIN13); while (1) ; }