Teraz pozostaje napisać tylko procedurę user_gpr_callback wywoływaną przy każdym zgłoszeniu przerwania od licznika GPT. Tą procedurę możemy umieścić tylko w pliku hal_entry.c – listing9.
List. 9. Procedura obsługi przerwania
1 2 3 4 5 |
volatile bool g_timer_flag; void user_gpt_callback(timer_callback_args_t * p_args) { g_timer_flag = true; } |
Zmodyfikowana pętla cyklicznie gasząca i zapalająca diody LED na module ewaluacyjnym została pokazana na listingu 10.
List. 10. Miganie diodami ze zmodyfikowanym odliczaniem opóźnień
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
ssp_err_t err; /* Define the units to be used with the software delay function */ const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS; /* Set the blink frequency (must be <= bsp_delay_units */ const uint32_t freq_in_hz = 2; /* Calculate the delay in terms of bsp_delay_units */ const uint32_t delay = bsp_delay_units/freq_in_hz; /* LED type structure */ bsp_leds_t leds; /* LED state variable */ ioport_level_t level = IOPORT_LEVEL_HIGH; /* Get LED information for this board */ R_BSP_LedsGet(&leds); err = g_timer.p_api->open(g_timer.p_ctrl, g_timer.p_cfg); if (SSP_SUCCESS != err) { while(1); } /* If this board has no LEDs then trap here */ if (0 == leds.led_count) { while(1); // There are no LEDs on this board } while(1) { /* Determine the next state of the LEDs */ if(IOPORT_LEVEL_LOW == level) { level = IOPORT_LEVEL_HIGH; } else { level = IOPORT_LEVEL_LOW; } /* Update all board LEDs */ for(uint32_t i = 0; i < leds.led_count; i++) { g_ioport.p_api->pinWrite(leds.p_leds[i], level); } /* Delay */ while (false == g_timer_flag); g_timer_flag = false; //R_BSP_SoftwareDelay(delay, bsp_delay_units); } |
Tomasz Jabłoński