LinkedIn YouTube Facebook
Szukaj

Wstecz
IoT

Renesas Synergy – pierwszy projekt w e2studio

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

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ń

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

Absolwent Wydziału Elektroniki Politechniki Wrocławskiej, współpracownik miesięcznika Elektronika Praktyczna, autor książek o mikrokontrolerach Microchip i wyświetlaczach graficznych, wydanych nakładem Wydawnictwa BTC. Zawodowo zajmuje się projektowaniem zaawansowanych systemów mikroprocesorowych.