/*
 * Fetch data from a mbox.Wait for at most timeout millisecs
 * Return -1 if timed out otherwise time spent waiting.
 */
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u32_t timeout)
{
   long addr=0L;
   int end_time = 0, start_time = 0;

   if (timeout) {
      start_time = OS_GetTime();
      if(OS_GetMailTimed (mbox, &addr,timeout)) {
         *data = NULL;
         return SYS_ARCH_TIMEOUT;
      }
      end_time = OS_GetTime();

   } else {
      OS_GetMail(mbox,&addr);
   }

   if(data) {
      if (addr == (long)&dummy_msg)
         *data = NULL;
      else
         *data=(void*)addr;

      //printf("fetch mbox:0x%x = 0x%x\r\n",mbox,*data);
   }else{
      //printf("fetch mbox:0x%x\r\n",mbox);
   }



   return (end_time - start_time);

}
void
sys_mbox_fetch(sys_mbox_t mbox, void **msg){
   long addr=0L;
   OS_GetMail(mbox,&addr);
   if(addr)
      *msg=(void*)addr
            }
Exemplo n.º 3
0
/*-----------------------------------------------------------------------------------
 * Blocks the thread until a message arrives in the mailbox, but does
 * not block the thread longer than "timeout" milliseconds (similar to
 * the sys_arch_sem_wait() function). The "msg" argument is a result
 * parameter that is set by the function (i.e., by doing "*msg =
 * ptr"). The "msg" parameter maybe NULL to indicate that the message
 * should be dropped.
 *
 * The return values are the same as for the sys_arch_sem_wait() function:
 * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
 * timeout.
 *
 * Note that a function with a similar name, sys_mbox_fetch(), is
 * implemented by lwIP.
 */
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, /*@null@*/ /*@out@*/ void **msg, u32_t timeout)
{
    void *dummyptr;
    void ** tmp_ptr;
    portTickType start_time, end_time, elapsed_time;
    e_mailbox_t* embox = (e_mailbox_t*)(*mbox);

    // assuming 1 tick is 1ms which is the case for now.
    start_time = OS_GetTime32();
    /* inherited this code from freeRTOS and LWIP must be calling it in this way..*/
    if ( msg == NULL )
    {
        tmp_ptr = &dummyptr;
    }
    else
    {
        tmp_ptr = msg;
    }

    if ( timeout != 0 )
    {
        // Return values 0 means success,1 means timeout
        if (0 == OS_GetMailTimed(&embox->mbox, tmp_ptr, timeout))
        {
            end_time = OS_GetTime32();
            elapsed_time = end_time - start_time;
            if ( elapsed_time == 0 )
            {
                elapsed_time = (portTickType) 1;
            }
            return ( elapsed_time );
        }
        else /* timed out blocking for message */
        {
            if ( msg != NULL )
            {
                *msg = NULL;
            }
            return SYS_ARCH_TIMEOUT;
        }
    }
    else /* block forever for a message. */
    {
        OS_GetMail(&embox->mbox, &(*tmp_ptr));
        end_time = OS_GetTime32();
        elapsed_time = end_time - start_time;
        if ( elapsed_time == 0 )
        {
            elapsed_time = (portTickType) 1;
        }
        return ( elapsed_time ); /* return time blocked TBD test */
    }
}
/*-------------------------------------------
| Name:OS_GetMail1
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
void OS_GetMail1 (OS_MAILBOX* pMB, void* Result){
   OS_GetMail (pMB,Result);
}
Exemplo n.º 5
0
//---------------------------------------------------------------------------//
//                                                                           //
//函数:void Key_TP_Task(void)                                               //
//描述:键盘与触摸屏扫描,编辑控件光标闪烁                                   //
//		                                                             //
//---------------------------------------------------------------------------//
void Key_TP_Task(void)
{
  unsigned char flicker_cnt = 0                             ;
  char key = 0xFF,last_key = 0xFF, down_cnt = 0, tp_cnt = 0 ;
  char rx_char                                              ;
  union 
  {
    unsigned int  pos[2]                                    ;
    char byte[4]                                            ;
  }TPoint                                                   ;
  char event                                                ;
  Init_KeyPad()                                             ; 
  TP_Init()                                                 ;
  OS_CREATEMB(&MBKeyTP, 1, sizeof(MBKeyTPBuffer),
              &MBKeyTPBuffer                     )          ; // 创建键盘、触摸屏消息邮箱
  OS_CREATEMB(&MBRX,1,sizeof(MBRXBuffer),&MBRXBuffer)       ; // 创建端口接收邮箱
  for(;;)
  {
    event  = 0x00                                           ;
    if(++flicker_cnt>50)                                      // 界面闪烁元素
    {
      flicker_cnt = 0x00                                    ;
      event = EVENT_FLICKER                                 ;
    }
    key = ReadKey()                                         ; // 按键扫描
    if(key!=last_key&&key!=0xFF)
      down_cnt  =  0                                        ;
    else if(key!=last_key&&key==0xFF)
    {
      if(down_cnt>3)
        event    |= EVENT_KEY_PRESSED                       ;
    }
    else if(key==last_key&&key!=0xFF)
      if(++down_cnt>4) down_cnt = 4                         ;
    OS_Use(&SemaSPI)                                        ;
    Init_TPSPI()                                            ;
    if(!Read_TP_Twice(&TPoint.pos[0],&TPoint.pos[1]))         // 触摸屏扫描         
    {
      if(tp_cnt>3)
        event  |= EVENT_TP_PRESSED                          ;
      tp_cnt   = 0                                          ;
    }
    else 
    {
      if(++tp_cnt>8)      tp_cnt     = 8                    ;
      if(tp_cnt>4)
      {
        Convert_Pos( TPoint.pos[0], TPoint.pos[1],   
                    &TPoint.pos[0],&TPoint.pos[1] )         ;
        event  |= EVENT_TP_TOUCHED                          ;
      }
    }
    OS_Unuse(&SemaSPI)                                      ;
    
    if(OS_GetMessageCnt(&MBRX))
    {
      OS_GetMail(&MBRX,&rx_char)                            ;
      event    |= RX_RECEIVED                               ;
    }
    if(event)                                                 // 发送系统消息
    {
      if(  !OS_GetSuspendCnt(&LCD_TASK_TCB)
         ||!OS_GetSuspendCnt(&MENU_OP_TASK_TCB))
      {
        OS_PutMail1(&MBKeyTP, &event)                       ;
        OS_PutMail1(&MBKeyTP, &last_key)                    ;
        OS_PutMail1(&MBKeyTP, &rx_char)                     ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[0])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[1])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[2])              ;
        OS_PutMail1(&MBKeyTP, &TPoint.byte[3])              ; 
      }
    }
    last_key = key                                          ;
    OS_Delay(10)                                            ;
  }
}