Ejemplo n.º 1
0
static signal_bv_t proc_pong_entry(os_pid_t pid, signal_bv_t signal)
{
    haddock_assert(pid == this->_pid);
    
    if (signal & SIGNAL_PONG_INITED) {
        print_log(LOG_INFO_COOL, "pong: inited, wait for ping.");
        process_sleep();
        return signal ^ SIGNAL_PONG_INITED;
    }

    if (signal & SIGNAL_DO_PONG) {
        os_ipc_set_signal(gl_proc_ping_pid, SIGNAL_PONG_IS_HERE);

        process_sleep();
        return signal ^ SIGNAL_DO_PONG;
    }

    if (signal & SIGNAL_PING_IS_HERE) {
        print_log(LOG_INFO_COOL, "pong: ping received");

        os_timer_reconfig(gl_timeout_timer, this->_pid, SIGNAL_DO_PONG, 2000);
        os_timer_start(gl_timeout_timer);

        process_sleep();
        return signal ^ SIGNAL_PING_IS_HERE;
    }

    // unkown signal? discard.
    return 0;
}
Ejemplo n.º 2
0
void dcc_can_init(int devfd) {
    os_mutex_init(&dcc_mutex);
    mostacan_fd = devfd;
    DccLoop_Init();
    dcc_timer = os_timer_create(&dcc_timer_callback, NULL, NULL);
    os_timer_start(dcc_timer, MSEC_TO_NSEC(100));
    os_thread_create(NULL, "dcc_can_rx", 0, DCC_CAN_THREAD_CAN_STACK_SIZE,
		     dcc_can_thread, NULL);
}
Ejemplo n.º 3
0
void navilnux_init(void)
{
    mem_init();
    task_init();
    msg_init();
    syscall_init();

    os_timer_init();
    gpio0_init();

    os_timer_start();
}
Ejemplo n.º 4
0
/** 
 * \fn     mcpf_timer_start
 * \brief  Timer Start
 * 
 * This function will put the 'timer start' request in a sorted list, 
 * and will start an OS timer when necessary.
 * 
 * \note
 * \param	hMcpf     - MCPF handler.
 * \param	uExpiryTime - Requested expiry time in milliseconds (duration time).
 * \param	eTaskId - Source task id.
 * \param	*fCb - Timer expiration Cb.
 * \param	hCaller - Cb's handler.
 * \return 	Pointer to the timer handler.
 * \sa     	mcpf_timer_start
 */ 
handle_t  	mcpf_timer_start (handle_t hMcpf, McpU32 uExpiryTime, EmcpTaskId eTaskId, 
							  mcpf_timer_cb fCb, handle_t hCaller)
{
	Tmcpf				*pMcpf;
    TMcpfTimer			*pMcpfTimer, *pFirstTimer;
	McpU32				uCurrentExpiryTime = 0;
	McpU32				uListCount;
	
    if (!hMcpf) 
	{
		MCPF_OS_REPORT(("Mcpf handler is NULL\n"));
		return NULL;	
	}

	pMcpf = (Tmcpf*)hMcpf;

	/* Allocate Timer */
	pMcpfTimer = (TMcpfTimer*)mcpf_mem_alloc_from_pool(pMcpf, pMcpf->hTimerPool);

	if(NULL == pMcpfTimer)
	{
		MCPF_REPORT_ERROR(hMcpf, MCPF_MODULE_LOG, ("mcpf_timer_start, No memory available in TimerPool\n"));
        return NULL;
	}	 

	MCPF_ENTER_CRIT_SEC(hMcpf);
	/* Init Timer Fields */
	pMcpfTimer->uEexpiryTime = mcpf_getAbsoluteTime(hMcpf, uExpiryTime); 
	pMcpfTimer->eSource = eTaskId;
	pMcpfTimer->tCbData.fCb =  fCb ;                                                       
	pMcpfTimer->tCbData.hCaller = hCaller;    
	pMcpfTimer->eState = TMR_STATE_ACTIVE;		

	/* if list is not empty get current expiry time(Absolute) */
	uListCount = mcpf_SLL_Size(pMcpf->hTimerList);
	if(uListCount != 0)
	{
		/* Get the first timer on the list*/
		pFirstTimer = (TMcpfTimer*) mcpf_SLL_Get(pMcpf->hTimerList);	
		uCurrentExpiryTime = pFirstTimer->uEexpiryTime;
	}

	/* Insert new Timer to the list */
	if (RES_ERROR == mcpf_SLL_Insert(pMcpf->hTimerList, pMcpfTimer))
	{
		MCPF_EXIT_CRIT_SEC(hMcpf);
		mcpf_mem_free_from_pool(hMcpf, pMcpfTimer);
		MCPF_REPORT_ERROR(hMcpf, MCPF_MODULE_LOG, ("mcpf_SLL_Insert Failed\n"));
        return NULL;
	}	        

	/* If list was empty before insertion (first timer on the list) --> Start the OS Timer */
    if (uListCount == 0)
	{
		pMcpf->uTimerId  = os_timer_start(pMcpf->hPla, mcpf_timer_callback, 
											hMcpf, uExpiryTime);
	}	
	else if ( uCurrentExpiryTime > (pMcpfTimer->uEexpiryTime))
	{
		/* The previous first timer on the list is having greater exp time 
		   than the new one. Stop this timer and start the new one.*/
      
		/* Stop the current timer */
        if (MCP_FALSE == os_timer_stop(pMcpf->hPla, pMcpf->uTimerId))
		{
			MCPF_EXIT_CRIT_SEC(hMcpf);
			mcpf_mem_free_from_pool(hMcpf, pMcpfTimer);
			MCPF_REPORT_ERROR(hMcpf, MCPF_MODULE_LOG, ("os_timer_stop Failed\n"));
		    return NULL; 		
		}

		/* Start the new timer */
		pMcpf->uTimerId  = os_timer_start(pMcpf->hPla, mcpf_timer_callback, hMcpf, uExpiryTime);
		
	} 

	MCPF_EXIT_CRIT_SEC(hMcpf);
	return ((handle_t)pMcpfTimer);
}
Ejemplo n.º 5
0
/** 
 * \fn     mcpf_timer_callback
 * \brief  General Timer Callback
 * 
 * This function will be called upon expiry time interrupt.
 * 
 * \note
 * \param	hMcpf     - MCPF handler.
 * \param	uTimerId     - The timer Id of the expired timer
 * \return 	None
 * \sa     	mcpf_timer_callback
 */  
static void 	mcpf_timer_callback(handle_t hMcpf, McpUint uTimerId)
{
	Tmcpf		*pMcpf;
    TMcpfTimer  	*pMcpfTimer;    
	McpU32		uExpiryTime;
	TMcpfTimer  	*pExpiredTimersQ[10]; 
	McpU16		i, counter = 0;

    if (!hMcpf) 
	{
		MCPF_OS_REPORT(("Mcpf handler is NULL\n"));
		return;	
	}
	pMcpf = (Tmcpf*)hMcpf;

	MCPF_ENTER_CRIT_SEC(hMcpf);

	/* Check if expired timer is already handled, and now another OS timer was alreay started */
	if(uTimerId != pMcpf->uTimerId)
	{
		MCPF_EXIT_CRIT_SEC(hMcpf);
		return;
	}
	
	do
    	{
		pMcpfTimer = (TMcpfTimer*)mcpf_SLL_Retrieve(pMcpf->hTimerList);

		/* This is added to handle race condition between 
		   this function and the 'mcpf_timer_stop()' function. 
		   This condition can only be valid in the first iteration of the loop.
		   The timer was stopped before the expiration Cb is handled, 
		   and the timer is already been removed from the timer's list. */
		if(pMcpfTimer == NULL)
		{
			MCPF_EXIT_CRIT_SEC(hMcpf);
			return;
		}
		
		/* Store a copy of the exp time of retrieved timer */
		uExpiryTime = pMcpfTimer->uEexpiryTime;

		pMcpfTimer->eState	= TMR_STATE_EXPIRED;	

		/* Save all expired timers, in order to send an 
		    experation message outside the critical section. */
		pExpiredTimersQ[counter] = pMcpfTimer;
		counter++;

		/* Get the Next Timer from the List */
		pMcpfTimer = mcpf_SLL_Get(pMcpf->hTimerList);		

    	} while( (pMcpfTimer) && (uExpiryTime == pMcpfTimer->uEexpiryTime) );
    
	if(pMcpfTimer)
	{
		/* Start the next timer request */
		uExpiryTime = mcpf_getExpiryInMilliSecs(hMcpf, pMcpfTimer->uEexpiryTime);    
		pMcpf->uTimerId = os_timer_start(pMcpf->hPla, mcpf_timer_callback, hMcpf, uExpiryTime);  
	}
	MCPF_EXIT_CRIT_SEC(hMcpf);

	for(i = 0; i < counter; i++)
	{
		pMcpfTimer = pExpiredTimersQ[i];
		mcpf_SendMsg(hMcpf, 
					pMcpfTimer->eSource,	/* Destination task is the task that started the timer */
					0,						/* Timer's Queue Id is alway 0 */
					pMcpfTimer->eSource,	/* Source task is the task that started the timer */
					0,						/* Since in timer queue there will be only
												message about the timer expiration */
					0,						/* opcode */
					sizeof(TMcpfTimer),		/* Length of the data */
					0,						/* User Defined is NOT USED*/
					pMcpfTimer);			/* The data is the timer structure */
	}
}
Ejemplo n.º 6
0
/** 
 * \fn     mcpf_timer_stop
 * \brief  Timer Stop
 * 
 * This function will remove the timer from the list
 * and will stop the OS timer when necessary.
 * 
 * \note
 * \param	hMcpf     - MCPF handler.
 * \param	hTimer - Timer's handler.
 * \return 	Result of operation: OK or ERROR
 * \sa     	mcpf_timer_stop
 */  
EMcpfRes	 	mcpf_timer_stop (handle_t hMcpf, handle_t hTimer)
{
	Tmcpf		*pMcpf;
    TMcpfTimer	*pMcpfTimer;
	McpS32		uExpiryTime;
	TMcpfTimer  	*pExpiredTimersQ[10]; 
	McpU16		i, counter = 0;
	McpBool		bIsOnlyTimer = MCP_FALSE;
	McpBool		bIsFirstTimer = MCP_FALSE;
	EMcpfRes		eRetVal = RES_OK;

    if (!hMcpf) 
	{
		MCPF_OS_REPORT(("Mcpf handler is NULL\n"));
		return RES_ERROR;
	}
        	
	pMcpf = (Tmcpf*)hMcpf;

    pMcpfTimer = (TMcpfTimer *)hTimer;

	MCPF_ENTER_CRIT_SEC(hMcpf);
	/* hTimer has already expired */
	if (pMcpfTimer->eState == TMR_STATE_EXPIRED ) 
    {
	       pMcpfTimer->eState = TMR_STATE_DELETED;
		MCPF_EXIT_CRIT_SEC(hMcpf);
		MCPF_REPORT_INFORMATION(hMcpf, MCPF_MODULE_LOG, ("mcpf_timer_stop: hTimer has already expired"));
		return RES_OK;
    }

	
	/* If it is the first/only timer on the list --> need to stop the OS timer */
	if(mcpf_SLL_Size(pMcpf->hTimerList) == 1)
	{
		bIsOnlyTimer = MCP_TRUE;
	}
	else if(mcpf_SLL_Get(pMcpf->hTimerList) == pMcpfTimer)
		bIsFirstTimer = MCP_TRUE;
	
	/* Remove Timer From the List */
	if ( (eRetVal = mcpf_SLL_Remove(pMcpf->hTimerList,hTimer)) == RES_OK)
	{
		/* If it is the only timer on the list --> need to stop the OS timer */
		if(bIsOnlyTimer)    
		{ 
			if (MCP_TRUE == os_timer_stop(pMcpf->hPla, pMcpf->uTimerId))
				eRetVal = RES_COMPLETE;
			else
				eRetVal = RES_ERROR;
			
			pMcpf->uTimerId = 0;
		}
		else if(bIsFirstTimer) /* It is the First Timer on the list */
		{
			if (MCP_TRUE == os_timer_stop(pMcpf->hPla, pMcpf->uTimerId))
			{
				pMcpf->uTimerId = 0;
				pMcpfTimer = mcpf_SLL_Get(pMcpf->hTimerList);
				
				do
				{		
					/* Get actual exp time in msecs from absolute exp time in the list */
					uExpiryTime = mcpf_getExpiryInMilliSecs(hMcpf,pMcpfTimer->uEexpiryTime);
					if(uExpiryTime <= 0)
					{
						pExpiredTimersQ[counter] = mcpf_SLL_Retrieve(pMcpf->hTimerList);
						counter++;
					}
					else
					{
						pMcpf->uTimerId = os_timer_start(pMcpf->hPla, mcpf_timer_callback, hMcpf, (McpU32)uExpiryTime);
						break;
					}
					pMcpfTimer = mcpf_SLL_Get(pMcpf->hTimerList);	
					
				} while (pMcpfTimer);
			}
			else 
			{
				pMcpf->uTimerId = 0;
				eRetVal = RES_ERROR; 
			}
		} 
	}
	MCPF_EXIT_CRIT_SEC(hMcpf);

	for(i = 0; i < counter; i++)
	{
		pMcpfTimer = pExpiredTimersQ[i];
		mcpf_SendMsg(hMcpf, 
					pMcpfTimer->eSource,	/* Destination task is the task that started the timer */
					0,						/* Timer's Queue Id is alway 0 */
					pMcpfTimer->eSource,	/* Source task is the task that started the timer */
					0,						/* Since in timer queue there will be only
												message about the timer expiration */
					0,						/* opcode */
					sizeof(TMcpfTimer),		/* Length of the data */
					0,						/* User Defined is NOT USED*/
					pMcpfTimer);			/* The data is the timer structure */
	}
	
	/* Free Timer */
	if (RES_ERROR == mcpf_mem_free_from_pool(pMcpf, (McpU8*) hTimer))
		return RES_ERROR;

	return eRetVal;
}