예제 #1
0
//  Creates an empty mailbox.
signed char _sys_mbox_new(sys_mbox_t *mbox, int size)
{
    // prarmeter "size" can be ignored in your implementation.
    u8_t       ucErr;
    PQ_DESCR    pQDesc;
    
    *mbox = SYS_MBOX_NULL;
    
    pQDesc = OSMemGet( pQueueMem, &ucErr );
    LWIP_ASSERT("OSMemGet ", ucErr == OS_ERR_NONE );
    
    if( ucErr == OS_ERR_NONE ) 
    {
        if(size > MAX_QUEUE_ENTRIES ) // 邮箱最多容纳MAX_QUEUE_ENTRIES消息数目
            size = MAX_QUEUE_ENTRIES;
        
        pQDesc->pQ = OSQCreate( &(pQDesc->pvQEntries[0]), size ); 
        LWIP_ASSERT( "OSQCreate ", pQDesc->pQ != NULL );
        
        if( pQDesc->pQ != NULL ) 
        {
            *mbox = pQDesc;
            return ERR_OK; 
        }
        else
        {
            ucErr = OSMemPut( pQueueMem, pQDesc );
            return ERR_MEM;
        }
    }
    else 
        return ERR_MEM;
}
예제 #2
0
/*********************************************************************************************************
** Function name:           zyMsgAccept
** Descriptions:            无等待获得消息
** input parameters:        ulMsg:  zyMsgCreate返回值
** output parameters:       pucMsg: 保存获得的消息
** Returned value:          ZY_OK:  成功
**                          负数:   错误,绝对值参考zy_if.h
** Created by:              Chenmingji
** Created Date:            2009-07-23
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
*********************************************************************************************************/
INT32S zyMsgAccept (unsigned long ulMsg, INT8U *pucMsgRt)
{
    __ZY_IF_MSG *pimThis;                                               /*  消息通道信息                */
    void        *pvTmp;

    pimThis = (__ZY_IF_MSG *)ulMsg;

    /*
     *  参数检查
     */
    if (ulMsg == 0) {
        return -ZY_PARAMETER_ERR;
    }
#if OS_ARG_CHK_EN == 0    
    if (pimThis->poeQ == NULL) {
        return -ZY_PARAMETER_ERR;
    }
    if (pimThis->pomMsg == NULL) {
        return -ZY_PARAMETER_ERR;
    }
#endif                                                                  /*  OS_ARG_CHK_EN               */

    pvTmp = OSQAccept(pimThis->poeQ);
    if (pvTmp == NULL) {
        return -ZY_NOT_OK;
    }

    memcpy(pucMsgRt, pvTmp, (size_t)(pimThis->ulMsgSize));              /*  拷贝数据                    */
    OSMemPut(pimThis->pomMsg, pvTmp);                                   /*  归还缓冲区                  */
    
    return ZY_OK;
}
예제 #3
0
void TaskUart(void *pdata) //send message to uart from uartQ
{
  
	INT8U *pUartMsg;
	INT8U err;
	pdata=pdata;
	
	
	Uart_Printf("taskuart\n");
	while(1)
	{
		// 进程taskuart不断地用pUart_Q里读数据,当有数据时,则进行打印。
	    pUartMsg=OSQAccept(pUart_Q,&err);//Accept the Msg from Qene; no wait 
		while(pUartMsg)
			{
				// Uart_Printf("get msg\n");
				Uart_SendString(pUartMsg);//seng str to Uart
				OSMemPut(pUartMem,pUartMsg);
				pUartMsg=OSQAccept(pUart_Q,&err);//free Mem
			}
		
		
		OSTimeDly(OS_TICKS_PER_SEC/5);

    }
}
예제 #4
0
/* Creates an empty mailbox */
sys_mbox_t
sys_mbox_new(int size)
{
	/* prarmeter "size" can be ignored in your implementation */
	u8_t       ucErr;
	PQ_DESCR    pQDesc;
	
	pQDesc = OSMemGet( pQueueMem, &ucErr );
	LWIP_ASSERT("OSMemGet ", ucErr == OS_ERR_NONE );
	
	if( ucErr == OS_ERR_NONE ) 
	{
		if( size > MAX_QUEUE_ENTRIES )  /* 邮箱最多容纳MAX_QUEUE_ENTRIES消息数目 */
		{
			size = MAX_QUEUE_ENTRIES;
		}
		pQDesc->pQ = OSQCreate( &(pQDesc->pvQEntries[0]), size ); 
		LWIP_ASSERT( "OSQCreate ", pQDesc->pQ != NULL );
	
		if( pQDesc->pQ != NULL ) 
		{
			return pQDesc; 
		}
		else
		{
			ucErr = OSMemPut( pQueueMem, pQDesc );
			return SYS_MBOX_NULL;
		}
	}
	else 
	{
		return SYS_MBOX_NULL;
	}
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MsgQPut
 * Description   : This function is used to put a message to a message queue.
 * Return kStatus_OSA_Success if the message is put successfully, otherwise
 * return kStatus_OSA_Error.
 *
 *END**************************************************************************/
osa_status_t OSA_MsgQPut(msg_queue_handler_t handler, void* pMessage)
{
    INT8U err;
    void  *localMsg;
    int32_t  *from_ptr, *to_ptr;
    uint32_t msg_size = handler->size;

    /* Get a memory to save the message. */
    localMsg = OSMemGet(handler->pMem, &err);
    if (!localMsg)
    {
        return kStatus_OSA_Error;
    }

    /* Copy msg to localMsg */
    from_ptr = (int32_t*)pMessage;
    to_ptr   = (int32_t*)localMsg;
    while (msg_size--)
    {
        *to_ptr++ = *from_ptr++;
    }

    if (OS_ERR_NONE != OSQPost(handler->pQueue, localMsg))
    {
        OSMemPut(handler->pMem, localMsg);
        return kStatus_OSA_Error;
    }

    return kStatus_OSA_Success;
}
void TaskSensores(void *pdata)
{    
#if OS_CRITICAL_METHOD == 3 
    OS_CPU_SR  cpu_sr;
#endif
    struct AdcMsg *m;
    INT16U value = 0;
    INT16U ValorTeclado = 0;
	INT8U err;
	for(;;)
	{
        
        m = (struct AdcMsg *) OSMemGet(dMemory,&err);
        if(err == OS_NO_ERR){
            OSSemPend(STeclado,0,&err);
            ValorTeclado = NumeroSensores;
            OSSemPost(STeclado);       
            m->adc0 = 0;
            m->adc1 = 0;
            m->adc2 = 0;
            switch(ValorTeclado){
                case 3:
                    Delay10TCYx(100);
                    SetChanADC(ADC_CH2);
                    ConvertADC();
                    while( BusyADC() );
                    value = ReadADC();
                    m->adc2 = Temp(value);
                case 2:
                    Delay10TCYx(100);
                    SetChanADC(ADC_CH1);
                    ConvertADC();
                    while( BusyADC() );
                    value = ReadADC();
                    m->adc1 = Temp(value);                    
                case 1:
                    Delay10TCYx(100);
                    SetChanADC(ADC_CH0);
                    ConvertADC();
                    while( BusyADC() );
                    value = ReadADC();
                    m->adc0 = Temp(value);
                default:
                    break;
            }

            err = OSQPost(QueueADC0,m);
            if(err == OS_Q_FULL){
                OSMemPut(dMemory,m);
                OSSemPost(STaskTxSerial);
            }
        }else{
            OSSemPost(STaskTxSerial);
        }
		//OSSemPost(STask2);
		OSTimeDly(1);
	}
}
예제 #7
0
void  OSTaskDelHook (OS_TCB *ptcb)   
{   
#if OS_CPU_FPU_EN > 0    
    if (ptcb->OSTCBOpt & OS_TASK_OPT_SAVE_FP) {                         /* See if task had FP support                               */   
        if (ptcb->OSTCBExtPtr != (void *)0) {                           /* Yes, OSTCBExtPtr must not be NULL                        */   
            OSMemPut(OSFPPartPtr, ptcb->OSTCBExtPtr);                   /*      Return memory block to free pool                    */   
        }   
    }   
#endif    
   
    (void)ptcb;                                                         /* Prevent compiler warning                                 */   
}   
예제 #8
0
/*********************************************************************************************************
** Function name:           zyMsgPend
** Descriptions:            等待消息
** input parameters:        ulMsg:  zyMsgCreate返回值
**                          ulDly: 最长等待时间,毫秒为单位
** output parameters:       pucMsgRt: 保存获得的消息
** Returned value:          ZY_OK: 成功
**                          负数:  错误,绝对值参考zy_if.h
** Created by:              Chenmingji
** Created Date:            2009-07-23
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
*********************************************************************************************************/
INT32S zyMsgPend (unsigned long ulMsg, INT8U *pucMsgRt, INT32U ulDly)
{
    __ZY_IF_MSG *pimThis;                                               /*  消息通道信息                */
    INT8U        ucErr;                                                 /*  错误代码                    */
    void        *pvTmp;

    pimThis = (__ZY_IF_MSG *)ulMsg;

    /*
     *  参数检查
     */
    if (ulMsg == 0) {
        return -ZY_PARAMETER_ERR;
    }
#if OS_ARG_CHK_EN == 0    
    if (pimThis->poeQ == NULL) {
        return -ZY_PARAMETER_ERR;
    }
    if (pimThis->pomMsg == NULL) {
        return -ZY_PARAMETER_ERR;
    }
#endif                                                                  /*  OS_ARG_CHK_EN               */

    pvTmp = OSQPend(pimThis->poeQ, (INT16U)((ulDly * OS_TICKS_PER_SEC + 999) / 1000), &ucErr);

    switch (ucErr) {
    
    case OS_ERR_PEVENT_NULL:
        return -ZY_PARAMETER_ERR;

    case OS_ERR_EVENT_TYPE:
        return -ZY_NO_FIND_OBJECT;

    case OS_TIMEOUT:
        return -ZY_TIME_OUT;

    case OS_NO_ERR:
        break;
    
    default:
        return -ZY_NOT_OK;
    }

    memcpy(pucMsgRt, pvTmp, (size_t)(pimThis->ulMsgSize));              /*  拷贝数据                    */
    OSMemPut(pimThis->pomMsg, pvTmp);                                   /*  归还缓冲区                  */
    
    return ZY_OK;
}
예제 #9
0
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MsgQGet
 * Description   : This function checks the queue's status, if it is not empty,
 * get message from it and return kStatus_OSA_Success, otherwise, timeout will
 * be used for wait. The parameter timeout indicates how long should wait in
 * milliseconds. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0 will return
 * kStatus_OSA_Timeout immediately if queue is empty.
 * This function returns kStatus_OSA_Success if message is got successfully,
 * returns kStatus_OSA_Timeout if message queue is empty within the specified
 * 'timeout', returns kStatus_OSA_Error if any errors occur during waiting.
 *
 *END**************************************************************************/
osa_status_t OSA_MsgQGet(msg_queue_handler_t handler,
                           void               *pMessage,
                           uint32_t            timeout)
{
    OS_ERR err;
    OS_OPT opt;
    OS_MSG_SIZE dummy;
    void* localMsg;
    int32_t  *from_ptr, *to_ptr;
    uint32_t msg_size = handler->size;

    if (0u == timeout)
    {
        opt = OS_OPT_PEND_NON_BLOCKING;
    }
    else
    {
        opt = OS_OPT_PEND_BLOCKING;
        timeout  = wait_timeout_msec_to_tick(timeout);
    }

    localMsg = OSQPend(&(handler->queue), timeout, opt, &dummy, (CPU_TS*)0, &err);

    if (OS_ERR_NONE == err)
    {
        /* Copy localMsg to msg */
        to_ptr   = (int32_t*)pMessage;
        from_ptr = (int32_t*)localMsg;
        while (msg_size--)
        {
            *to_ptr++ = *from_ptr++;
        }

        OSMemPut(&(handler->mem), localMsg, &err);

        return kStatus_OSA_Success;
    }
    else if ((OS_ERR_PEND_WOULD_BLOCK == err) ||
             (OS_ERR_TIMEOUT          == err))
    {
        return kStatus_OSA_Timeout;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
예제 #10
0
/*
  Deallocates a mailbox. If there are messages still present in the
  mailbox when the mailbox is deallocated, it is an indication of a
  programming error in lwIP and the developer should be notified.
*/
void _sys_mbox_free(sys_mbox_t *mbox)
{
    u8_t     ucErr;
    
    LWIP_ASSERT( "sys_mbox_free ", *mbox != SYS_MBOX_NULL );    
    
    //clear OSQ EVENT
    OSQFlush( (*mbox)->pQ );
    
    //del OSQ EVENT
    (void)OSQDel( (*mbox)->pQ, OS_DEL_NO_PEND, &ucErr);
    LWIP_ASSERT( "OSQDel ", ucErr == OS_ERR_NONE );
    
    //put mem back to mem queue
    ucErr = OSMemPut( pQueueMem, (*mbox) );
    LWIP_ASSERT( "OSMemPut ", ucErr == OS_ERR_NONE );  
}
예제 #11
0
/*
  Deallocates a mailbox. If there are messages still present in the
  mailbox when the mailbox is deallocated, it is an indication of a
  programming error in lwIP and the developer should be notified.
*/
void
sys_mbox_free(sys_mbox_t mbox)
{
	u8_t     ucErr;
	
	LWIP_ASSERT( "sys_mbox_free ", mbox != SYS_MBOX_NULL );      
	    
	/* clear OSQ EVENT */
	OSQFlush( mbox->pQ );
	
	/* del OSQ EVENT */
	(void)OSQDel( mbox->pQ, OS_DEL_NO_PEND, &ucErr);
	LWIP_ASSERT( "OSQDel ", ucErr == OS_ERR_NONE );
	
	/* put mem back to mem queue */
	ucErr = OSMemPut( pQueueMem, mbox );
	LWIP_ASSERT( "OSMemPut ", ucErr == OS_ERR_NONE );  
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MsgQGet
 * Description   : This function checks the queue's status, if it is not empty,
 * get message from it and return kStatus_OSA_Success, otherwise, timeout will
 * be used for wait. The parameter timeout indicates how long should wait in
 * milliseconds. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0 will return
 * kStatus_OSA_Timeout immediately if queue is empty.
 * This function returns kStatus_OSA_Success if message is got successfully,
 * returns kStatus_OSA_Timeout if message queue is empty within the specified
 * 'timeout', returns kStatus_OSA_Error if any errors occur during waiting.
 *
 *END**************************************************************************/
osa_status_t OSA_MsgQGet(msg_queue_handler_t handler,
                           void               *pMessage,
                           uint32_t            timeout)
{
    INT8U err;
    void* localMsg;
    int32_t  *from_ptr, *to_ptr;
    uint16_t msg_size = handler->size;

    if (0U != timeout)
    {
        /* If timeout is not 0, convert it to tickes. */
        timeout  = wait_timeout_msec_to_tick(timeout);
        localMsg = OSQPend(handler->pQueue, timeout, &err);
    }
    else
    {
        localMsg = OSQAccept(handler->pQueue, &err);
    }

    if (OS_ERR_NONE == err)
    {
        /* Copy localMsg to msg */
        to_ptr   = (int32_t*)(pMessage);
        from_ptr = (int32_t*)localMsg;
        while (msg_size--)
        {
            *to_ptr++ = *from_ptr++;
        }

        OSMemPut(handler->pMem, localMsg);

        return kStatus_OSA_Success;
    }
    else if ((OS_ERR_Q_EMPTY == err) ||
             (OS_ERR_TIMEOUT == err))
    {
        return kStatus_OSA_Timeout;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
예제 #13
0
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MsgQPut
 * Description   : This function is used to put a message to a message queue.
 * Return kStatus_OSA_Success if the message is put successfully, otherwise
 * return kStatus_OSA_Error.
 *
 *END**************************************************************************/
osa_status_t OSA_MsgQPut(msg_queue_handler_t handler, void* pMessage)
{
    OS_ERR err;
    void *localMsg;
    int32_t  *from_ptr, *to_ptr;
    uint32_t msg_size = handler->size;

    /* In this case, the message is saved into internal memory */
    localMsg = OSMemGet(&(handler->mem), &err);
    if (!localMsg)
    {
        return kStatus_OSA_Error;
    }

    /* Copy msg to localMsg. */
    from_ptr = (int32_t*)pMessage;
    to_ptr   = (int32_t*)localMsg;
    while (msg_size--)
    {
        *to_ptr++ = *from_ptr++;
    }

    OSQPost(&(handler->queue),
            localMsg,
            handler->size*sizeof(int32_t),
            OS_OPT_POST_FIFO,
            &err);

    if (OS_ERR_NONE != err)
    {
        OSMemPut(&(handler->mem), localMsg, &err);
        return kStatus_OSA_Error;
    }

    return kStatus_OSA_Success;
}
예제 #14
0
void TaskUart(void *pdata) //send message to uart from uartQ
{
  
	char *pUartMsg;
	INT8U err;
	pdata=pdata;
	
	
	
	while(1)
	{
	    pUartMsg=OSQAccept(pUart_Q,&err);//Accept the Msg from Qene; no wait 
		while(pUartMsg)
			{
				Uart_SendString(pUartMsg);//seng str to Uart
				OSMemPut(pUartMem,pUartMsg);
				pUartMsg=OSQAccept(pUart_Q,&err);//free Mem
			}
		
		
		OSTimeDly(OS_TICKS_PER_SEC/5);

    }
}
예제 #15
0
void gd_task_network(void *parg)
{

	INT8S 		res = 0;
	INT8U 		err;

	gd_msg_t 	*recv_msg = NULL;
	gd_network_task_t *network_task = &gd_system.network_task;

	fail_tick = 0;


	while(1)
	{
		recv_msg = (gd_msg_t *)OSQAccept(network_task->q_network, &err);

		if(recv_msg != NULL)
		{
			switch(recv_msg->type)
			{
			case GD_MSG_GM_RESET:
				network_gm_reset();
				break;
			case GD_MSG_GM_INIT:
				network_gm_init();
				break;
			case GD_MSG_TCP_INIT:
				network_tcpip_init();
				break;
			case GD_MSG_TCP_MODE_INIT:
				network_tcpip_mode();
				break;
			case GD_MSG_TCP_CONNECT:
				network_tcpip_creat();
				break;
			case GD_MSG_SEND_HEARTBEAT:
				network_heart_beat();
				break;	

			case GD_MSG_GM_NO_SIGNAL:
				network_no_signal();
				break;
			/*unrequest at command*/
			case GD_MSG_GM_TCP_LINK1_CLOSE:
				network_tcpip_state_change(GM_TCPIP_LINK1_CLOSE);	
				break;				
			case GD_MSG_GM_TCP_LINK2_CLOSE:
				network_tcpip_state_change(GM_TCPIP_LINK2_CLOSE);	
				break;	
			case GD_MSG_GM_TCP_LINK3_CLOSE:
				network_tcpip_state_change(GM_TCPIP_LINK3_CLOSE);	
				break;	
			case GD_MSG_GM_TCP_SERVER_CLOSE:
				network_tcpip_state_change(GM_TCPIP_SERVER_CLOSE);	
				break;	
			case GD_MSG_GM_TCP_CLOSE:
				network_tcpip_state_change(GM_TCPIP_CLOSE);	
				break;	
			case GD_MSG_GM_RECV_SMS:
				network_wakeup(GM_TCPIP_RECEIVED_SMS);
				break;
			case GD_MSG_GM_RECV_RING:
				network_wakeup(GM_TCPIP_RECEIVED_RING);
				break;
		
				
			default:
				break;				
			}
			
			res = OSMemPut(gd_system.gd_msg_PartitionPtr, (void*)recv_msg);

			if(res != OS_ERR_NONE)	
			{
				//...error....
			}
		}
		network_heart_beat();
		OSTimeDlyHMSM(0, 0, 0, 100);
	}
	
}
예제 #16
0
/*
*********************************************************************************************************
*                                    App_TaskNoah_Ruler()
*
* Description : Process Comminucation between Ruler module and Audio Bridge.
*               Noah protocol layer related data parsing and processing.
*               This task wait for message event from App_TaskUART_Rx(). Check if the Noah layer data is 
*               valid in the message.  
*
* Argument(s) : p_arg   Argument passed to 'App_TaskNoah_Ruler()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
void App_TaskNoah_Ruler( void *p_arg )
{ 
    (void)p_arg;
    
    NOAH_CMD   *pPcCmd ;    
    CPU_INT08U *pCmdBuf ;
    CPU_INT08U  rxID ; 
    CPU_INT08U  PcCmdRxID_Ruler[4];
    CPU_INT08U  sum ;  
    CPU_INT08U  SessionDone;
    CPU_INT08U  err ;
    CPU_INT08U *pTaskMsgIN ;  
    CPU_INT08U *pMsg ;  
    
    pTaskMsgIN  = NULL;
    pMsg        = NULL;
    SessionDone = 0 ;    
   
      
    while( DEF_TRUE ) {          
             
        pTaskMsgIN  = (INT8U *)OSQPend( EVENT_MsgQ_RulerUART2Noah, 0, &err ); 
        
        if( pTaskMsgIN != NULL && OS_ERR_NONE == err )   {
           
            pCmdBuf = pTaskMsgIN; // char point to the data buffer
            pPcCmd  = (NOAH_CMD *)pCmdBuf ; //change to NOAH_CMD type
            rxID    = GET_FRAME_ID( pPcCmd->head ) ; //get frame ID, index       
            sum     = pPcCmd->checkSum; //get check sum data  
            
            LED_Toggle(LED_DS2);           
            APP_TRACE_DBG(("\r\n<<"));
            switch( GET_FRAME_TYPE( pPcCmd->head ) ) {// GET_FRAME_TYPE(pPcCmd->head)  get frame type 
                
                case FRAM_TYPE_DATA :  
                    
                    if( (sum == 0) || ( sum == CheckSum(0,pCmdBuf, pPcCmd->DataLen + 2)) ) {   
//                        APP_TRACE_INFO(("R[%d]:[0x%2x>0x%2x][",Global_Ruler_Index,PcCmdRxID_Ruler[Global_Ruler_Index],rxID));
//                        for(unsigned int i = 0; i<pPcCmd->DataLen; i++){   
//                            APP_TRACE_INFO((" %2X", *(unsigned char*)(pPcCmd->Data+i) )); 
//                        }
//                        APP_TRACE_INFO((" ]\r\n")); 
                        pcSendDateToBuf( EVENT_MsgQ_Noah2RulerUART, SET_FRAME_HEAD(rxID,FRAM_TYPE_ACK), NULL, 0, 0, NULL, 0 ) ;  // ACK                                               
                        if( (CPU_INT08U)(PcCmdRxID_Ruler[Global_Ruler_Index]+0x40) == rxID ) { // chweck if frameID repeat  
                            PcCmdRxID_Ruler[Global_Ruler_Index] = rxID ; //save this frameID 
                         
                            err = Noah_CMD_Parse_Ruler( pPcCmd, &SessionDone); // jump to CMD parse 
                            if( (err != OS_ERR_NONE) || (SessionDone == 1) ) {
                                SessionDone = 0;
                                Ruler_CMD_Result = err ;
                                OSTimeDly(2); //wait enough time for ACK to be sent
                                APP_TRACE_DBG((" Res[0x%2x]", Ruler_CMD_Result));
                                OSSemPost( Done_Sem_RulerUART );                                     
                            }
          
                        } else {                      
                            APP_TRACE_DBG(("PcCmdRxID_Ruler[%d] Err: expect 0x%X, get 0x%X",Global_Ruler_Index,PcCmdRxID_Ruler[Global_Ruler_Index]+0x40,rxID)); 
                        }
                        
                    } else {                
                        pcSendDateToBuf( EVENT_MsgQ_Noah2RulerUART, SET_FRAME_HEAD(rxID,FRAM_TYPE_NAK), NULL, 0, 0, NULL, 0 ) ;  // NAK   
                    
                    }                 
                break ;                
          
                    
                case FRAM_TYPE_ESTA :
                  
                    PcCmdRxID_Ruler[Global_Ruler_Index] = 0xC0 ; // ? why 0x40: make sure there can be many same setup frame
                    PcCmdTxID_Ruler[Global_Ruler_Index] = 0x00 ; //  
                    
                    OSSemPost( ACK_Sem_RulerUART );                 
                    OSSemPost( Done_Sem_RulerUART ); //end the resend pending--                     
                    OSTimeDly(1); //wait for the TX buffer is empty 
                    
                    //Reset all UART CMD related buffer and release mem 
                    do{  //reset mem used by  EVENT_MsgQ_RulerUART2Noah                    
                        pMsg   = (INT8U *)OSQAccept( EVENT_MsgQ_Noah2RulerUART, &err );
                        OSMemPut( pMEM_Part_MsgUART, pMsg ); 
                    } while ( pMsg != NULL && OS_ERR_NONE == err ) ; 
                    
                    do{  //reset mem used by  EVENT_MsgQ_RulerUART2Noah                  
                        pMsg   = (INT8U *)OSQAccept( EVENT_MsgQ_RulerUART2Noah, &err );
                        OSMemPut( pMEM_Part_MsgUART, pMsg ); 
                    } while ( pMsg != NULL && OS_ERR_NONE == err ) ; 
                       
                    Queue_Flush( pUART_Send_Buf[RULER_UART] ); //clear uart send&rec data queue
                    Queue_Flush( pUART_Rece_Buf[RULER_UART] );                      
         
                    SessionDone = 0;  //init  
                    OSSemSet( ACK_Sem_RulerUART, 0, &err ); // clear the sem
                    OSSemSet( Done_Sem_RulerUART, 0, &err );
                    test_counter4++;
                    APP_TRACE_DBG(("EST/ESTA"));   
                break ;         
                        
                case FRAM_TYPE_ACK :
                  
                    if( rxID == PcCmdTxID_Ruler[Global_Ruler_Index] ) {                       
                        OSSemPost( ACK_Sem_RulerUART );                        
                        test_counter2++;
                    } else {
                        APP_TRACE_INFO_T(("\r\nACK: Got %X, Expect %X\r\n",rxID,PcCmdTxID_Ruler[Global_Ruler_Index] )); 
                    }
                    APP_TRACE_DBG(("ACK")); 
                    test_counter3++;       
                break ;
                
                case FRAM_TYPE_NAK :
                    // dismiss NAK, there will be a resend if no ACK got
                    // OSSemPost( Done_Sem_RulerUART );
                    test_counter1++;
                    APP_TRACE_DBG(("NAK")); 
                break;
                
                         
                default :    
                break ;              
            } 
            
            //release mem
            OSMemPut( pMEM_Part_MsgUART, pTaskMsgIN );  
           
        }         
        
        ////OSTimeDly(2);   //use OSQPend(), no delay needed!!! 
        
    }        
    
    
}
예제 #17
0
/*
*********************************************************************************************************
*                                    App_TaskUART_Tx()
*
* Description : Process UART Transmit related process between Audio Bridge and PC.
*               Wait for data message from other task that want to send to PC.
*
* Argument(s) : p_arg   Argument passed to 'App_TaskUART_Tx()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
void App_TaskUART_Tx( void *p_arg )
{    
    (void)p_arg;
    
    CPU_INT08U       errCode ;  
    CPU_INT08U      *pTaskMsgIN ;
    pNEW_CMD         pPcCmd ;    
    CPU_INT32U       counter ;
    CPU_INT32U       size ;
    CPU_INT32U       times ;
    CPU_INT08U       *pChar ;

    pTaskMsgIN  = NULL;
    pPcCmd      = NULL;  
    errCode     = UNKOW_ERR_RPT ;       

     
//    unsigned char tt[512];
//        for (unsigned int i = 0; i<512; i++) {
//            tt[i] = '0'+i;
//        }
////    while(1){
//
////       kfifo_put(pUART_Send_kfifo[PC_UART], (unsigned char *)&tt , 512) ;
////       UART_WriteStart( PC_UART );
////       OSTimeDly(1);
////                           
////    }
//    
//    while (DEF_TRUE) { 
//
//        // Noah to Uart transmit
//        pTaskMsgIN   = (INT8U *)OSQPend( EVENT_MsgQ_Noah2PCUART, 0, &errCode );
//        
//        if( pTaskMsgIN != NULL && OS_ERR_NONE == errCode )   {  
//          kfifo_put(pUART_Send_kfifo[PC_UART], (unsigned char *)&tt , 512) ;
//          UART_WriteStart( PC_UART );   
//        }
//    }  
//////////////////////////////////////////////////////////////////////////////      
    
    //pcSendDateToBuf( EVENT_MsgQ_Noah2PCUART, SET_FRAME_HEAD(PcCmdTxID,FRAM_TYPE_EST),  NULL, 0, 0, NULL, 0 ) ;  // send a EST package on startup   
    
    while (DEF_TRUE) { 

        // Noah to Uart transmit
        pTaskMsgIN   = (INT8U *)OSQPend( EVENT_MsgQ_Noah2PCUART, 0, &errCode );
        
        if( pTaskMsgIN != NULL && OS_ERR_NONE == errCode )   {  
//            Time_Stamp();
//            APP_TRACE_INFO(("\r\n:App_TaskUART_Tx : [%d] start ",pPcCmd->DataLen + 5));
                    
            pPcCmd   =  (pNEW_CMD)pTaskMsgIN ; 
            pChar    =  (unsigned char *)pTaskMsgIN ; 
            counter  =  (pPcCmd->data_len[0]<<16) + (pPcCmd->data_len[1]<<8) + pPcCmd->data_len[2];
            counter +=  8;
            
#if( false )            
            APP_TRACE_INFO(("\r\n############DATA==counter: %d ####################\r\n",counter)); 
            for(unsigned int i = 0; i< counter; i++ ){                            
                APP_TRACE_INFO(("%0X ", *(pChar+i) ));
                if(i%32 == 31) {
                    APP_TRACE_INFO(("\r\n"));
                }                
             }
            APP_TRACE_INFO(("\r\n##########################################\r\n"));
#endif      
            times   = counter / UART1_SEND_QUEUE_LENGTH ;
            counter = counter % UART1_SEND_QUEUE_LENGTH ;            
            if( times ) {
                for(unsigned int i = 0; i<times; i++ ) {
                    while(1) {                  
                        size = kfifo_get_free_space( pUART_Send_kfifo[PC_UART] );                    
                        if( size >= UART1_SEND_QUEUE_LENGTH ) {
                            kfifo_put(pUART_Send_kfifo[PC_UART], pChar, UART1_SEND_QUEUE_LENGTH) ;
                            pChar += UART1_SEND_QUEUE_LENGTH;
                            break;                    
                        }
                        //OSTimeDly(1);
                    }
                    UART_WriteStart( PC_UART ); //send data
                   
                }                
            }
            
            if( counter ) {                
                while(1) {                     
                    size = kfifo_get_free_space( pUART_Send_kfifo[PC_UART] );                    
                    if( size >= counter ) {
                        kfifo_put(pUART_Send_kfifo[PC_UART], pChar, counter) ;
                        break;                    
                    }
                    //OSTimeDly(1);
                }
                UART_WriteStart( PC_UART ); //send data 
             
            }            
            OSMemPut( pMEM_Part_MsgUART, pTaskMsgIN );
        }  
        
        ////OSTimeDly(5);		                                     	
	}
       
    
    
    
}
예제 #18
0
/*********************************************************************************************************
** Function name:           zyMsgPost
** Descriptions:            发送消息
** input parameters:        ulMsg:      zyMsgCreate返回值
**                          pucMsgSend: 要发送的消息
**                          ucMod:      发送模式,一般为0
** output parameters:       none
** Returned value:          ZY_OK: 成功
**                          负数:  错误,绝对值参考zy_if.h
** Created by:              Chenmingji
** Created Date:            2009-07-23
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
*********************************************************************************************************/
INT32S zyMsgPost (unsigned long ulMsg, INT8U *pucMsgSend, INT8U ucMod)
{
    __ZY_IF_MSG *pimThis;                                               /*  消息通道信息                */
    INT8U        ucErr;                                                 /*  错误代码                    */
    void        *pvTmp;

    pimThis = (__ZY_IF_MSG *)ulMsg;

    /*
     *  参数检查
     */
    if (ulMsg == 0) {
        return -ZY_PARAMETER_ERR;
    }
#if OS_ARG_CHK_EN == 0    
    if (pimThis->poeQ == NULL) {
        return -ZY_PARAMETER_ERR;
    }
    if (pimThis->pomMsg == NULL) {
        return -ZY_PARAMETER_ERR;
    }
#endif                                                                  /*  OS_ARG_CHK_EN               */

    /*
     *  申请缓冲区
     */
    pvTmp = OSMemGet(pimThis->pomMsg, &ucErr);

    switch (ucErr) {

    case OS_MEM_INVALID_PMEM:
        return -ZY_NO_FIND_OBJECT;

    case OS_MEM_NO_FREE_BLKS:
        return -ZY_NO_MEMORY;

    case OS_NO_ERR:
        break;
    
    default:
        return -ZY_NOT_OK;
    }

    /*
     *  发送消息
     */
    memcpy(pvTmp, pucMsgSend, (size_t)(pimThis->ulMsgSize));            /*  拷贝数据                    */
    ucErr = OSQPostOpt(pimThis->poeQ, pvTmp, ucMod);                    /*  保存消息存储位置            */
    
    if (ucErr == OS_NO_ERR) {
        return ZY_OK;
    }

    OSMemPut(pimThis->pomMsg, pvTmp);                                   /*  归还缓冲区                  */

    switch (ucErr) {
    
    case OS_ERR_PEVENT_NULL:
        return -ZY_PARAMETER_ERR;

    case OS_ERR_EVENT_TYPE:
        return -ZY_NO_FIND_OBJECT;

    case OS_Q_FULL:
        return -ZY_NO_MEMORY;

    default:
        return -ZY_NOT_OK;
    }
}
/*******************************************************************************
* Function Name  : psr_mgnt_cmd()
* Description    : mgnt命令的统一处理进程, 
* Input          : pt_prop分别针对额外属性数据体
* Output         : None
* Return         : 
*******************************************************************************/
STATUS psr_mgnt_cmd(u8 mgnt_cmd, u16 pipe_id, void * pt_prop, ARRAY_HANDLE return_buffer, AUTOHEAL_LEVEL autoheal_level)
{
	u32 expiring_sticks;
	PIPE_REF pipe_ref;
	STATUS result;
	ARRAY_HANDLE mpdu;
	u8 mpdu_len;
	ARRAY_HANDLE ptw;
	
	result = FAIL;

	/* check validity of pipe_id */
	pipe_ref = inquire_pipe_mnpl_db(pipe_id);
	if(!pipe_ref)
	{
#ifdef DEBUG_MGNT
		my_printf("PSR ERR: NO PIPE INFO.\r\n");
#endif
		if(return_buffer)
		{
			return_buffer[0] = NO_PIPE_INFO;
		}
		return FAIL;

	}

	mpdu = OSMemGet(MINOR);
	if(!mpdu)
	{
		if(return_buffer)
		{
			return_buffer[0] = MEM_OUT;
		}

		return result;
	}

	switch(mgnt_cmd)
	{
		case(EXP_MGNT_PING):
		{
			expiring_sticks = psr_ping_sticks(pipe_ref);
			mpdu[0] = (0x80 | EXP_MGNT_PING);
			mpdu_len = 1;
			break;
		}
		case(EXP_MGNT_DIAG):
		{
			DLL_SEND_HANDLE pds;
			
			pds = (DLL_SEND_HANDLE)(pt_prop);
			expiring_sticks = psr_diag_sticks(pipe_ref,pds);
			ptw = mpdu;
			*(ptw++) = (0x80 | EXP_MGNT_DIAG);
			mem_cpy(ptw,pds->target_uid_handle,6);
			ptw += 6;
			*(ptw++) = pds->xmode;
			*(ptw++) = pds->rmode;
			*(ptw++) = (pds->prop & BIT_DLL_SEND_PROP_SCAN)?1:0;
			mpdu_len = ptw-mpdu;
			break;
		}
		case(EXP_MGNT_EBC_BROADCAST):
		{
			EBC_BROADCAST_HANDLE ebc;

			ebc = (EBC_BROADCAST_HANDLE)(pt_prop);

			/* limit ebc window */
			switch(ebc->rmode & 0x03)
			{
				case(0x00):
				{
					if(ebc->window > CFG_EBC_MAX_BPSK_WINDOW)
					{
						ebc->window = CFG_EBC_MAX_BPSK_WINDOW;
					}
					break;
				}
				case(0x01):
				{
					if(ebc->window > CFG_EBC_MAX_DS15_WINDOW)
					{
						ebc->window = CFG_EBC_MAX_DS15_WINDOW;
					}
					break;
				}
				case(0x02):
				{
					if(ebc->window > CFG_EBC_MAX_DS63_WINDOW)
					{
						ebc->window = CFG_EBC_MAX_DS63_WINDOW;
					}
				}
			}

			expiring_sticks = psr_broadcast_sticks(pipe_ref,ebc);
			ptw = mpdu;
			*ptw++ = (0x80 | EXP_MGNT_EBC_BROADCAST);
			*ptw++ = ebc->bid;
			*ptw++ = ebc->xmode;
			*ptw++ = ebc->rmode;
			*ptw++ = ebc->scan;
			*ptw++ = ebc->window;
			*ptw++ = ebc->mask;
			mpdu_len = 7;

			/*** todo: add other conditions ***/
			if(ebc->mask & BIT_NBF_MASK_UID)
			{
				mem_cpy(ptw,ebc->uid,6);
				ptw += 6;
				mpdu_len += 6;
			}
			if(ebc->mask & BIT_NBF_MASK_METERID)
			{
				mem_cpy(ptw,ebc->mid,6);
				ptw += 6;
				mpdu_len += 6;
			}
			if(ebc->mask & BIT_NBF_MASK_BUILDID)
			{
				*ptw++ = ebc->build_id;
				mpdu_len++;
			}
			
			break;
		}
		case(EXP_MGNT_EBC_IDENTIFY):
		{
			EBC_IDENTIFY_HANDLE ebc;

			ebc = (EBC_IDENTIFY_HANDLE)(pt_prop);
			expiring_sticks = psr_identify_sticks(pipe_ref,ebc);
			ptw = mpdu;
			*ptw++ = (0x80 | EXP_MGNT_EBC_IDENTIFY);
			*ptw++ = ebc->bid;
			*ptw++ = ebc->num_bsrf;
			*ptw++ = ebc->max_identify_try;
			mpdu_len = 4;
			
			break;
		}
		case(EXP_MGNT_EBC_ACQUIRE):
		{
			EBC_ACQUIRE_HANDLE ebc;

			ebc = (EBC_ACQUIRE_HANDLE)(pt_prop);
			expiring_sticks = psr_acquire_sticks(pipe_ref,ebc);
			ptw = mpdu;
			*ptw++ = (0x80 | EXP_MGNT_EBC_ACQUIRE);
			*ptw++ = ebc->bid;
			*ptw++ = ebc->node_index;
			*ptw++ = ebc->node_num;
			mpdu_len = 4;
		
			break;
		}
		case(EXP_MGNT_SET_BUILD_ID):
		{
			expiring_sticks = psr_transaction_sticks(pipe_ref,2,9,0);
			ptw = mpdu;
			*ptw++ = (0x80 | EXP_MGNT_SET_BUILD_ID);
			*ptw++ = *(u8 *)(pt_prop);
			mpdu_len = 2;
			
			break;
		}
		default:
		{
#ifdef DEBUG_MANIPULATION
			my_printf("error mgnt cmd %bX\r\n",mgnt_cmd);
#endif
			OSMemPut(MINOR,mpdu);
			return result;
		}
	}

	// 2013-07-18 autoheal_level 作为参数传入
	// 一般地: ping命令的autoheal_level为0, ebc各个命令由于是组网过程中使用, autoheal_level为1(允许重刷pipe, 允许重试)
	// diag命令要看情况, 在组网过程中使用level1, 在诊断和修复过程中使用level1等等, 这样能保证代码的重用和最大的灵活性

	result = psr_transaction(pipe_id, mpdu, mpdu_len, expiring_sticks, return_buffer, autoheal_level);

	OSMemPut(MINOR,mpdu);
	if(!result)
	{
#ifdef DEBUG_MANIPULATION
		my_printf("mgnt psr comm fail\r\n");
#endif
		return FAIL;
	}
	if(result && ((*return_buffer & 0xF0) == 0xF0))	//2013-07-18 status为okay仅表示通信成功, return_buffer首字节为0xFX即表示mgnt层功能失败
	{
#ifdef DEBUG_MANIPULATION
		my_printf("mgnt cmd return fail\r\n");
#endif
		return FAIL;
	}
	else
	{
		return OKAY;
	}
	
}
void TaskTxSerial(void *pdata)
{
#if OS_CRITICAL_METHOD == 3
    OS_CPU_SR  cpu_sr;
#endif
	struct AdcMsg *Sensores;
	INT8U err;
    INT16S Sensor1;
    INT16S Sensor2;
    INT16S Sensor3;
    INT16U  Acumulador1;
    INT16U  Acumulador2;
    INT16U  Acumulador3;
    INT8U contador;
    INT16U ValorTeclado;
    INT8S strTx1[5];
    INT8S strTx2[5];
    INT8S strTx3[5];
	
	for(;;)
	{
		OSSemPend(STaskTxSerial,0,&err);
        Acumulador1=0;
        Acumulador2=0;
        Acumulador3=0;
        for(contador=0 ; contador<10 ; contador++) {
            Sensores = (struct AdcMsg *) OSQPend(QueueADC0, 0, &err);
            Acumulador1+=Sensores->adc0;
            Acumulador2+=Sensores->adc1;
            Acumulador3+=Sensores->adc2;
            OSMemPut(dMemory,Sensores);
        }

		OSSemPend(STeclado,0,&err);
        ValorTeclado=NumeroSensores;
        OSSemPost(STeclado);
        Sensor1=0;
        Sensor2=0;
        Sensor3=0;
		switch(ValorTeclado){
			case 3:
				Sensor3 = (INT16S) Acumulador3/10;
			case 2:
				Sensor2 = (INT16S) Acumulador2/10;
			case 1:
				Sensor1 = (INT16S) Acumulador1/10;
			default:
				break;
		}
/*
        itoa(Sensor1,strTx1);
        putsUSART(strTx1);
        putrsUSART(SPACE);
        itoa(Sensor2,strTx2);
        putsUSART(strTx2);
        putrsUSART(SPACE);
        itoa(Sensor3,strTx3);
        putsUSART(strTx3);
        putrsUSART(CRLF);
 */
		if(NumeroSensores > 0){
            itoa(Sensor1,strTx1);
            putsUSART(strTx1);
            putrsUSART(SPACE);
			if(NumeroSensores > 1){
                itoa(Sensor2,strTx2);
                putsUSART(strTx2);
                putrsUSART(SPACE);
			}
			if(NumeroSensores > 2){
                itoa(Sensor3,strTx3);
                putsUSART(strTx3);
			}
			putrsUSART(CRLF);
		}
		//OSSemPost(STask1);
        
		OSTimeDly(10);
	}
}