Beispiel #1
0
void GUI_X_WaitEventTimed(int Period) {
  static OS_TIMER Timer;
  static int Initialized;
  
  if (Period > 0) {
    if (Initialized != 0) {
      OS_DeleteTimer(&Timer);
    }
    Initialized = 1;
    OS_CreateTimer(&Timer, GUI_X_SignalEvent, Period);
    OS_StartTimer(&Timer);
    GUI_X_WaitEvent();
  }
}
/*-------------------------------------------
| Name       :dev_at91sam9261_uart_dbg_x_load
| Description: Load device
| Parameters : p_board_inf_uart : info uart pointer
| Return Type: integer -> devive loaded (=0)
| Comments   : -
| See        : -
---------------------------------------------*/
int dev_at91sam9261_uart_dbg_x_load (board_inf_uart_t *p_board_inf_uart)
{
   pthread_mutexattr_t mutex_attr=0;

   //already loaded?
   if (p_board_inf_uart->loaded)
      return 0;  //yes

   p_board_inf_uart->desc_rd = -1;
   p_board_inf_uart->desc_wr = -1;

   cfmakeraw   (&ttys_termios);
   cfsetispeed (&ttys_termios,B9600);
   cfsetospeed (&ttys_termios,B9600);

   ttys_termios.c_iflag &= ~(IXOFF|IXON); // xon/xoff disable
   ttys_termios.c_cc[VTIME]   = 0;        // no timeout, blocking call

   //VTIME timer in units of 0.1 seconds (posix specification)
#if defined (__KERNEL_UCORE_EMBOS)
   OS_CreateTimer (&p_board_inf_uart->timer,
                   p_board_inf_uart->f_timer_call_back,
                   100);  // 100ms
#elif defined(__KERNEL_UCORE_ECOS)
   p_board_inf_uart->timer_attr.tm_msec = 100;
   p_board_inf_uart->timer_attr.func = dev_at91sam9261_uart_dbg_x_timer_callback;

   p_board_inf_uart->timer_attr.data = (cyg_addrword_t)p_board_inf_uart;
   rttmr_create(&p_board_inf_uart->timer,&p_board_inf_uart->timer_attr);
#endif

   // Device loaded flag
   p_board_inf_uart->loaded = 1;
   p_board_inf_uart->o_flag = 0;

   // initializations
   p_board_inf_uart->XMIT             = 0;  // transmission flag
   p_board_inf_uart->inter_char_timer = 0;

   // Disable all USART Debug interrupts.
   *((AT91_REG *)AT91C_DBGU_CR+US_IDR) = 0xffffffff;

   kernel_pthread_mutex_init(&p_board_inf_uart->mutex, &mutex_attr);

   return 0;
}
/*--------------------------------------------
| Name:        kernel_timer_settime
| Description:
| Parameters:  none
| Return Type: none
| Comments:
| See:
----------------------------------------------*/
int kernel_timer_settime(kernel_timer_t* p_kernel_timer, int flags, const struct itimerspec* value,struct itimerspec* ovalue){

   switch(flags) {
   case 0:   //relative time
      break;
   //
   case TIMER_ABSTIME:
   default:
      return -1;
   }

   //
#ifdef __KERNEL_UCORE_EMBOS
   if(ovalue) {
      int elsapse_time_ms = OS_GetTimerValue((OS_TIMER*)p_kernel_timer);
      ovalue->it_value.tv_sec= elsapse_time_ms/1000;
      ovalue->it_value.tv_nsec=__timer_ms_to_ns( (elsapse_time_ms%1000)  );
   }

   //
   p_kernel_timer->interval=KERNEL_TIMER_VALUE_PERIOD;
   //
   p_kernel_timer->itimerspec.it_value.tv_sec=value->it_value.tv_sec;
   p_kernel_timer->itimerspec.it_value.tv_nsec=value->it_value.tv_nsec;
   p_kernel_timer->itimerspec.it_interval.tv_sec=value->it_interval.tv_sec;
   p_kernel_timer->itimerspec.it_interval.tv_nsec=value->it_interval.tv_nsec;

   //
   if(!p_kernel_timer->created) {
      p_kernel_timer->created=KERNEL_TIMER_CREATED;
      OS_CreateTimer((OS_TIMER*)p_kernel_timer,kernel_timer_generic_callback,(__timer_s_to_ms(value->it_value.tv_sec)+__timer_ns_to_ms(value->it_value.tv_nsec)));
   }else{
      OS_StopTimer((OS_TIMER*)p_kernel_timer); //disarm timer
   }
   //
   OS_SetTimerPeriod((OS_TIMER*)p_kernel_timer,(__timer_s_to_ms(value->it_value.tv_sec)+__timer_ns_to_ms(value->it_value.tv_nsec)));
   //
   if(p_kernel_timer->itimerspec.it_value.tv_nsec!=0 || p_kernel_timer->itimerspec.it_value.tv_sec!=0)
//      OS_StartTimer((OS_TIMER*)p_kernel_timer);//arm timer
      OS_RetriggerTimer((OS_TIMER*)p_kernel_timer);  //RETRIGGER timer // PATCH $BM

#endif

   return 0;
}
/*-------------------------------------------
| Name       :dev_at91sam7s_spi_load
| Description:
| Parameters :
| Return Type:
| Comments   :
| See        :
---------------------------------------------*/
int dev_at91sam7s_spi_load (void)
{
   int cpt;

   pthread_mutexattr_t mutex_attr=0;

   if(s_spi_io_init)
      return 0;

   s_spi_io_init++;

   kernel_pthread_mutex_init(&s_spi_mutex, &mutex_attr);
//pthread_mutex_init(&s_spi_mutex, &mutex_attr);

   //already loaded?
   if (dev_at91sam7s_spi_loaded)
      return 0;  //yes

   // initialization
   for (cpt=0; cpt < SDCARD_BLOCK_SIZE; cpt++)
   {
      dummy_ff_block[cpt]=0xff;
   }

   // to remove...
   cfmakeraw   (&ttys_termios);
   cfsetispeed (&ttys_termios, B9600);
   cfsetospeed (&ttys_termios, B9600);

   dev_at91sam7s_spi_loaded = 1; // loaded

   OS_CreateTimer (&dev_at91sam7s_spi_timer,
                   dev_at91sam7s_spi_timer_callback,
                   10);  // delay * ms
   return 0;
}