void gpio_ir_recv_handler(uint32_t id, uint32_t event) { uint32_t current_timestamp; IRSendRev *pIR; pIR = (IRSendRev *)id; gpio_irq_disable((gpio_irq_t *)(pIR->pGpioIrqRecv)); current_timestamp = micros(); switch(pIR->rcvstate) { case STATE_IDLE: if ((pIR->recv_wait_int) == IRQ_LOW) { pIR->rcvstate = STATE_MARK; pIR->prev_timestamp = current_timestamp; } break; case STATE_MARK: if ((pIR->recv_wait_int) == IRQ_HIGH) { // mark transition to space pIR->recv_buf[(pIR->recv_len)++] = current_timestamp - (pIR->prev_timestamp); pIR->prev_timestamp = current_timestamp; pIR->rcvstate = STATE_SPACE; gtimer_reload((gtimer_t *)(pIR->pTimerRecv), GAP); gtimer_start((gtimer_t *)(pIR->pTimerRecv)); } break; case STATE_SPACE: if ((pIR->recv_wait_int) == IRQ_LOW) { // space transition to mark gtimer_stop((gtimer_t *)(pIR->pTimerRecv)); pIR->recv_buf[(pIR->recv_len)++] = current_timestamp - (pIR->prev_timestamp); pIR->prev_timestamp = current_timestamp; pIR->rcvstate = STATE_MARK; } break; case STATE_STOP: break; } if ((pIR->recv_wait_int) == IRQ_LOW ) { // Change to listen to high level event (pIR->recv_wait_int) = IRQ_HIGH; gpio_irq_set((gpio_irq_t *)(pIR->pGpioIrqRecv), (gpio_irq_event)IRQ_HIGH, 1); gpio_irq_enable((gpio_irq_t *)(pIR->pGpioIrqRecv)); } else if ((pIR->recv_wait_int) == IRQ_HIGH) { // Change to listen to low level event (pIR->recv_wait_int) = IRQ_LOW; gpio_irq_set((gpio_irq_t *)(pIR->pGpioIrqRecv), (gpio_irq_event)IRQ_LOW, 1); gpio_irq_enable((gpio_irq_t *)(pIR->pGpioIrqRecv)); } }
void IRSendRev::Init(int revPin) { gpio_irq_init((gpio_irq_t *)pGpioIrqRecv, (PinName)(g_APinDescription[revPin].pinname), (gpio_irq_handler)gpio_ir_recv_handler, (uint32_t)this); gpio_irq_set((gpio_irq_t *)pGpioIrqRecv, (gpio_irq_event)IRQ_LOW, 1); gpio_irq_enable((gpio_irq_t *)pGpioIrqRecv); gtimer_init((gtimer_t *)pTimerRecv, TIMER4); gtimer_start_one_shout((gtimer_t *)pTimerRecv, GAP, (void *)ir_recv_timer_handler, (uint32_t)this); gtimer_stop((gtimer_t *)pTimerRecv); Clear(); }
static void rtc_set_time(uint32_t year, uint8_t mon, uint8_t mday, uint8_t wday, uint8_t hour, uint8_t min, uint8_t sec) { int i; gtimer_stop(&sw_rtc); rtc_timeinfo.tm_sec = sec; rtc_timeinfo.tm_min = min; rtc_timeinfo.tm_hour = hour; rtc_timeinfo.tm_mday = mday-1; rtc_timeinfo.tm_wday = wday-1; rtc_timeinfo.tm_yday = 0; for (i=0;i<(mon-1);i++) { rtc_timeinfo.tm_yday += days_in_month(i,year); } rtc_timeinfo.tm_yday += (mday-1); rtc_timeinfo.tm_mon = mon-1; rtc_timeinfo.tm_year = year; gtimer_start(&sw_rtc); }
static void gtimer_timeout_handler (uint32_t tid) { gtimer_t *obj = (gtimer_t *)tid; gtimer_irq_handler handler; u8 timer_id = obj->hal_gtimer_adp.TimerId; if (obj->handler != NULL) { handler = (gtimer_irq_handler)obj->handler; handler(obj->hid); } if (!obj->is_periodcal) { gtimer_stop(obj); } if(timer_id < 2) { // Timer0 | Timer1: clear ISR here // Timer 2~7 ISR will be cleared in HAL HalTimerClearIsr(timer_id); } }
static void rtc_deinit(void) { gtimer_stop(&sw_rtc); gtimer_deinit(&sw_rtc); }