#include"TLE926x.h"
#include "plib_port.h"
unsigned long timeref;
unsigned irqSBC = 0;

void irqSBC_Handler(void){
  irqSBC = 1 ;
}

void irq_SBC_WK2_WU_Handler(uint8_t Value)
{
//  Serial.println ("WK2_WU detected");

}
void irq_SBC_WK1_WU_Handler(uint8_t Value)
{
  //Serial.println ("WK1_WU detected");

}

void Tle9263_Init(void) {
  // put your setup code here, to run once:

  sbc_init();
 
  sbc_register_callback (SBC_ISR_WK2_WU, irq_SBC_WK2_WU_Handler);
  sbc_register_callback (SBC_ISR_WK1_WU, irq_SBC_WK1_WU_Handler);
#if 0
  /* Initialize interrupts */
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), irqSBC_Handler, RISING);
#endif
  //sbc_configure_watchdog(TIME_OUT_WD, WD_STARTS_AFTER_CAN_LIN_WAKE, WD_1000MS);
}
extern uint8_t touch_reset2times_flag;
void Tle9263_MainTask(void) {
  /* Trigger Watchdog every 100ms */
  if (touch_reset2times_flag == 1)
  {
        return;
  }
  if (timeref ++ >  5) {
    sbc_wd_trigger();
    timeref = 0;
  }

  /* Handle SBC_ISR() if INTN was toggeled */
  if (irqSBC) {
    irqSBC = 0;
  }
}
