void gtimer_start_one_shout (gtimer_t *obj, uint32_t duration_us, void* handler, uint32_t hid) { obj->is_periodcal = _FALSE; obj->handler = handler; obj->hid = hid; gtimer_reload(obj, duration_us); gtimer_start(obj); }
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 gtimer_start_periodical (gtimer_t *obj, uint32_t duration_us, void* handler, uint32_t hid) { obj->is_periodcal = _TRUE; obj->handler = handler; obj->hid = hid; if (duration_us > GTIMER_TICK_US) { // reload will takes extra 1 tick duration_us -= GTIMER_TICK_US; } gtimer_reload(obj, duration_us); gtimer_start(obj); }