예제 #1
0
파일: posixino.cpp 프로젝트: ern0/posixino
void Posixino::timerThread() {

    while (true) {

        usleep(1000);

        for (int n = 0; n < 3; n++) {
            if (interruptCounter[n] < 0) continue;

            interruptCounter[n] += 1000;
            if (interruptCounter[n] < interruptTiming[n]) continue;
            interruptCounter[n] -= interruptTiming[n];

            if (n == 0) {
# ifdef TIMER0
                TIMER0_COMPA_vect();
# endif
            }
            if (n == 1) {
# ifdef TIMER1
                TIMER1_COMPA_vect();
# endif
            }
            if (n == 2) {
# ifdef TIMER2
                TIMER2_COMPA_vect();
# endif
            }

        } // for interrupts
    } // forever

} // timerThread()
예제 #2
0
int test_send() {
  uint8_t* buffer = malloc(4);
  buffer[0] = 0xd;
  buffer[1] = 0x19;
  buffer[2] = 0x15;
  buffer[3] = 0;

  mock_avr_reset();
  vw_avr_setup(VW_AVR_MODE_TX);

  mu_assert_equal(vw_avr_tx_in_progress(), 0);
  vw_avr_send(buffer);
  mu_assert_equal(vw_avr_tx_in_progress(), 1);

  // each bit is transmitted on the timer interrupt

  // 0xd - 101100
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);

  // 0x19 - 100110
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);

  // 0x15 - 101010
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 1);
  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);

  // 0x0 - null terminated
  mu_assert_equal(vw_avr_tx_in_progress(), 1);

  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);
  mu_assert_equal(vw_avr_tx_in_progress(), 0);

  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);

  TIMER0_COMPA_vect();
  mu_assert_bit(VW_AVR_TX_PORT, VW_AVR_TX_PIN, 0);

  return 0;
}