예제 #1
0
파일: main.c 프로젝트: AnnaTrost/cbmc
int main(void)
{
#ifdef _ENABLE_OUTPUT_
  printf("C main(void) function\n");
#endif

  struct Hardware hardware;
  struct Hardware* hw = &hardware;

  struct Firmware firmware;
  struct Firmware* fw = &firmware;

  // burn firmware on chip
  firmware.hw = hw;
  hardware.fw = fw;

  // start hardware
  turn_on(hw);

  // start firmware
#ifdef _ENABLE_POSIX_
  pthread_t firmware_thread;
  pthread_create(&firmware_thread, NULL, poll, (void *) fw);
#else
  ASYNC(poll((void *) fw));
#endif

#ifdef _EXPOSE_BUG_
  sleep(SHORT_DELAY);
#endif

  // environment stimulus
#ifdef _ENABLE_POSIX_
  pthread_t stimulus_thread;
  pthread_create(&stimulus_thread, NULL, stimulus, (void *) hw);
#else
  ASYNC(stimulus((void *) hw));
#endif

#ifdef _EXPOSE_BUG_
  sleep(SHORT_DELAY);
#endif

  // stop hardware
  turn_off(hw);

  // check verification condition:
  //
  // the firmware must have reacted to every environment
  // stimulus that triggered the hardware functionality.
  assert(hardware.regs[SIGNAL_REG_ID] == 0);

#ifdef _ENABLE_POSIX_
  pthread_join(firmware_thread, NULL);
  pthread_join(stimulus_thread, NULL);
  pthread_mutex_destroy(&hw->lock);
#endif

  return 0;
}
예제 #2
0
파일: main.c 프로젝트: AnnaTrost/cbmc
// Write data to hardware register
void* write_data_register(struct Hardware *hw, RegisterId reg_id, Register value)
{
  ATOMIC_BEGIN;
  check_data_register(reg_id);

  if (!hw->is_on)
  {
#ifdef _ENABLE_OUTPUT_
    printf("Write register [off] reg_id: %d value: %c\n", reg_id, value);
#endif
    goto SKIP;
  }

#ifdef _ENABLE_OUTPUT_
  printf("Write register [on] reg_id: %d value: %c\n", reg_id, value);
#endif

  hw->regs[reg_id] = value;
  hw->regs[SIGNAL_REG_ID] |= reg_id;

  if (hw->interrupt_handler)
#ifdef _ENABLE_POSIX_
  {
#ifdef _ENABLE_OUTPUT_
    printf("Fire interrupt\n");
#endif

#ifdef _EXPOSE_BUG_
    // delay firing of interrupt
    sleep(LONG_DELAY);
#endif

    // caution: detached thread!
    pthread_t interrupt_thread;
    pthread_create(&interrupt_thread, NULL, hw->interrupt_handler, (void *) hw->fw);
  }
#else
    ASYNC(hw->interrupt_handler((void *) hw->fw));
#endif

SKIP:
  ATOMIC_END;
  return NULL;
}
예제 #3
0
void startToneGenerator(ToneGenerator *self,int unused){
	self -> period = USEC(2145);
	//self -> deadline = USEC(100);
	PARALLEL_PORT_INIT(&portDevice,(int)(self -> direction));
	ASYNC(self,generateTone,0);
}  //public function