Beispiel #1
0
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
			   unsigned long abstime) {
    waitqueue_t entry;
    timer_t timer = { 0,  (void (*)(void*)) make_running, ctid };
    tid_t owner;
    int result = 0;
    // check if mutex is available, if not, go to sleep
    grab_kernel_lock();

    entry.thread = ctid;
    add_to_waitqueue(&cond->waiters, &entry);
    pthread_mutex_unlock(mutex);
    if (abstime)
	add_timer(abstime - get_system_up_time(), &timer);

    wait();
    if (abstime) {
	if (get_timer_count(timer))
	    remove_timer(&timer);
	else
	    result = ETIMEDOUT;
    }
    remove_from_waitqueue(&entry);
    pthread_mutex_lock(mutex);
    return 0;
}
Beispiel #2
0
/* read from fd */
ssize_t DEVICE::read(void *buf, size_t len)
{
   ssize_t read_len ;

   get_timer_count();

   read_len = d_read(m_fd, buf, len);

   last_tick = get_timer_count();

   DevReadTime += last_tick;
   VolCatInfo.VolReadTime += last_tick;

   if (read_len > 0) {          /* skip error */
      DevReadBytes += read_len;
   }

   return read_len;
}
Beispiel #3
0
/* write to fd */
ssize_t DEVICE::write(const void *buf, size_t len)
{
   ssize_t write_len ;

   get_timer_count();

   write_len = d_write(m_fd, buf, len);

   last_tick = get_timer_count();

   DevWriteTime += last_tick;
   VolCatInfo.VolWriteTime += last_tick;

   if (write_len > 0) {         /* skip error */
      DevWriteBytes += write_len;
   }

   return write_len;
}
Beispiel #4
0
void main(void){
//------------------------------------------------------------------------------
// Main Program
// This is the main routine for the program. Execution of code starts here.
// The operating system is Back Ground Fore Ground.
// 
//------------------------------------------------------------------------------
  
  init_ports();                            
  Init_Clocks();                            
  Init_Conditions();                     
  init_timers();                            
  five_msec_delay(QUARTER_SECOND);                      
  Init_LCD();  
  setup_sw_debounce();
  init_adc();
  P1OUT |= IR_LED;
  init_serial_uart();
  
  WDTCTL = WDTPW + WDTHOLD;
  
  setup_pwm();
  
  set_motor_speed(R_FORWARD, PWM_RES);
  set_motor_speed(L_FORWARD, PWM_RES);

  unsigned int time_sequence  = START_VAL;      // counter for switch loop
  unsigned int previous_count = START_VAL;      // automatic variable for
                                                // comparing timer_count
  unsigned int display_count = START_VAL;
  
  is_follow_running = FALSE;
  
//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run

    if(get_timer_count() > display_count + QUARTER_SECOND)
    {
      display_count = get_timer_count();
      Display_Process();
      time_sequence = START_VAL;
    }
    
    update_switches();                 // Check for switch state change
    update_menu();

    if(is_follow_running)
      run_follow();
    
    if(uca0_is_message_received())
    {
      BufferString message = uca0_read_buffer(TRUE);
      receive_command(message.head + message.offset);
    }
    
    if(uca1_is_message_received())
    {
      update_menu();
      BufferString message = uca1_read_buffer(TRUE);
      uca0_transmit_message(message.head, message.offset);
      if(find(WIFI_COMMAND_SYMBOL, message))
      {
        receive_command(message.head + message.offset);
      }
      if(find(LOST_WIFI_COMMAND_SYMBOL, message))
      {
        receive_command(CONNECT_NCSU);
      }
    }
    
    if(time_sequence > SECOND_AND_A_QUARTER)
      time_sequence = START_VAL;
    
    unsigned int current_timer_count = get_timer_count();
    
    if(current_timer_count > previous_count)
    {
      previous_count = current_timer_count % UINT_16_MAX;
      time_sequence++;
    } 
   }
//------------------------------------------------------------------------------
}