Question: You need to implement the following Timer APIs for the tasks that youre the kernel timer: /* ************************************************************************************************************************ * CREATE A TIMER * * Description:
You need to implement the following Timer APIs for the tasks that youre the kernel timer:
/*
************************************************************************************************************************
* CREATE A TIMER
*
* Description: This function is called by your application code to create a timer.
*
* Arguments : dly Initial delay.
* If the timer is configured for ONE-SHOT mode, this is the timeout used
* If the timer is configured for PERIODIC mode, this is the first timeout to wait for
* before the timer starts entering periodic mode
*
* period The 'period' being repeated for the timer.
* If you specified 'RTOS_TMR_OPT_PERIODIC' as an option, when the timer expires, it will
* automatically restart with the same period.
*
* opt Specifies either:
* RTOS_TMR_OPT_ONE_SHOT The timer counts down only once
* RTOS_TMR_OPT_PERIODIC The timer counts down and then reloads itself
*
* callback Is a pointer to a callback function that will be called when the timer expires. The
* callback function must be declared as follows:
*
* void MyCallback (RTOS_TMR *ptmr, void *p_arg);
*
* callback_arg Is an argument (a pointer) that is passed to the callback function when it is called.
*
* pname Is a pointer to an ASCII string that is used to name the timer. Names are useful for
* debugging.
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID_DLY you specified an invalid delay
* RTOS_ERR_TMR_INVALID_PERIOD you specified an invalid period
* RTOS_ERR_TMR_INVALID_OPT you specified an invalid option
* RTOS_ERR_TMR_NON_AVAIL if there are no free timers from the timer pool
*
* Returns : A pointer to an RTOS_TMR data structure.
* This is the 'handle' that your application will use to reference the timer created.
************************************************************************************************************************
*/
RTOS_TMR *RTOSTmrCreate (INT32U dly,
INT32U period,
INT8U opt,
RTOS_TMR_CALLBACK callback,
void *callback_arg,
INT8U *pname,
INT8U *perr)
/*
************************************************************************************************************************
* DELETE A TIMER
*
* Description: This function is called by your application code to delete a timer.
*
* Arguments : ptmr Is a pointer to the timer to stop and delete.
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE if the timer was not created
* RTOS_ERR_TMR_INVALID_STATE the timer is in an invalid state
*
* Returns : RTOS_TRUE If the call was successful
* RTOS_FALSE If not
************************************************************************************************************************
*/
BOOLEAN RTOSTmrDel (RTOS_TMR *ptmr,
INT8U *perr)
/*
************************************************************************************************************************
* GET THE NAME OF A TIMER
*
* Description: This function is called to obtain the name of a timer.
*
* Arguments : ptmr Is a pointer to the timer to obtain the name for
*
* pdest Is a pointer to pointer to where the name of the timer will be placed.
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE The call was successful
* RTOS_ERR_TMR_INVALID_DEST 'pdest' is a NULL pointer
* RTOS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
* RTOS_ERR_TMR_INVALID_STATE the timer is in an invalid state
*
* Returns : The length of the string or 0 if the timer does not exist.
************************************************************************************************************************
*/
INT8U RTOSTmrNameGet (RTOS_TMR *ptmr,
INT8U **pdest,
INT8U *perr)
/*
************************************************************************************************************************
* GET HOW MUCH TIME IS LEFT BEFORE A TIMER EXPIRES
*
* Description: This function is called to get the number of ticks before a timer times out.
*
* Arguments : ptmr Is a pointer to the timer to obtain the remaining time from.
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
* RTOS_ERR_TMR_INVALID_STATE the timer is in an invalid state
*
* Returns : The time remaining for the timer to expire. The time represents 'timer' increments. In other words, if
* RTOSTmr_Task() is signaled every 1/10 of a second then the returned value represents the number of 1/10 of
* a second remaining before the timer expires.
************************************************************************************************************************
*/
INT32U RTOSTmrRemainGet (RTOS_TMR *ptmr,
INT8U *perr)
/*
************************************************************************************************************************
* FIND OUT WHAT STATE A TIMER IS IN
*
* Description: This function is called to determine what state the timer is in:
*
* RTOS_TMR_STATE_UNUSED the timer has not been created
* RTOS_TMR_STATE_STOPPED the timer has been created but has not been started or has been stopped
* RTOS_TMR_COMPLETED the timer is in ONE-SHOT mode and has completed it's timeout
* RTOS_TMR_RUNNING the timer is currently running
*
* Arguments : ptmr Is a pointer to the desired timer
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
* RTOS_ERR_TMR_INVALID_STATE if the timer is not in a valid state
*
* Returns : The current state of the timer (see description).
************************************************************************************************************************
*/
INT8U RTOSTmrStateGet (RTOS_TMR *ptmr,
INT8U *perr)
/*
************************************************************************************************************************
* START A TIMER
*
* Description: This function is called by your application code to start a timer.
*
* Arguments : ptmr Is a pointer to an RTOS_TMR
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE if the timer was not created
* RTOS_ERR_TMR_INVALID_STATE the timer is in an invalid state
*
* Returns : RTOS_TRUE if the timer was started
* RTOS_FALSE if an error was detected
************************************************************************************************************************
*/
BOOLEAN RTOSTmrStart (RTOS_TMR *ptmr,
INT8U *perr)
/*
************************************************************************************************************************
* STOP A TIMER
*
* Description: This function is called by your application code to stop a timer.
*
* Arguments : ptmr Is a pointer to the timer to stop.
*
* opt Allows you to specify an option to this functions which can be:
*
* RTOS_TMR_OPT_NONE Do nothing special but stop the timer
* RTOS_TMR_OPT_CALLBACK Execute the callback function, pass it the callback argument
* specified when the timer was created.
* RTOS_TMR_OPT_CALLBACK_ARG Execute the callback function, pass it the callback argument
* specified in THIS function call
*
* callback_arg Is a pointer to a 'new' callback argument that can be passed to the callback function
* instead of the timer's callback argument. In other words, use 'callback_arg' passed in
* THIS function INSTEAD of ptmr->RTOSTmrCallbackArg
*
* perr Is a pointer to an error code. '*perr' will contain one of the following:
* RTOS_ERR_NONE
* RTOS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
* RTOS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an RTOS_TMR
* RTOS_ERR_TMR_INACTIVE if the timer was not created
* RTOS_ERR_TMR_INVALID_OPT if you specified an invalid option for 'opt'
* RTOS_ERR_TMR_STOPPED if the timer was already stopped
* RTOS_ERR_TMR_INVALID_STATE the timer is in an invalid state
* RTOS_ERR_TMR_NO_CALLBACK if the timer does not have a callback function defined
*
* Returns : RTOS_TRUE If we stopped the timer (if the timer is already stopped, we also return RTOS_TRUE)
* RTOS_FALSE If not
************************************************************************************************************************
*/
BOOLEAN RTOSTmrStop (RTOS_TMR *ptmr,
INT8U opt,
void *callback_arg,
INT8U *perr)
/*
************************************************************************************************************************
* SIGNAL THAT IT'S TIME TO UPDATE THE TIMERS
*
* Description: This function is typically called by the ISR that occurs at the timer tick rate and is used to signal to
* RTOSTmr_Task() that it's time to update the timers.
*
* Arguments : none
*
* Returns : RTOS_ERR_NONE The call was successful and the timer task was signaled.
*
************************************************************************************************************************
*/
INT8U RTOSTmrSignal (void)
You need to demonstrate how you implement the above mentioned APIs. That means, when implementing the above APIs, there are other internal functions which are not publicly available to the users, but nonetheless, they are required for the timer management and API implementation.
a) The timer task , RTOSTmr_Task(),
b) Any supporting functions you may need for initialization of free list RTOSTmr_init() and start of the RTOSTmr_Task(), The OS will call this timer initialization function as part of OSInit() during the start up.
c) Any supporting functions and all link list management required to support your design.
You may assume the following kernel functions available to you by the kernel. Use the Pthread library to simulate the RTOS functions as described below:
I. RTOSTaskCreate() creates a task. You may use pthread library pthreat_create().
II. RTOSSemCreate(0u) initializes a semaphore to have the value of 0. Semaphores are used when a task wants exclusive access to a resource, needs to synchronize its activities with an ISR or a task, or is waiting until an event occurs. You would use a semaphore to signal the occurrence of an event to one or multiple tasks, and use mutexes to guard share resources. However, technically, semaphores allow for both. Example:
RTOS_SEM RTOSTmrSignal;
RTOSTmrSemSignal = RTOSSemCreate(0u);
You can use pthread_mutex_init() to implement this. (If you use pthread_cond_wait() or pthread_cond_signal () to implement the RTOSSemPend and RTOSSemPost, you dont need to implement this function and can be left blank (see below).
III. RTOSSemPend (RTOS_SEM *timerSemPtr);
This is a semaphore Pend. If semaphore is taken it will wait for signal indicating time to update timers. Example:
RTOSSemPend (RTOSSemSignal , &err);
You can use either pthread_mutex_lock() or alternatively pthread_cond_wait() to implement this.
IV. RTOSSemPost (RTOS_SEM *timerSemPtr);
This is the semaphore post operation. It will send a signal to the task that is waiting (pending) indicating that semaphore is released.Example:
RTOSSemPost (RTOSSemSignal);
You can use either pthread_mutex_lock() or alternatively pthread_cond_signal () to implement this.
V. RTOSShedLock()
This is used to prevent OS from context switching. In pthread library this can be left blank. You dont need to prevent scheduling.
VI. RTOSShedUnlock()
This is used to resume the OS context switching which was previously halted by RTOSShedLock(). In pthread library this can be left blank. You dont need to prevent scheduling.
Please Zip all your files including:
- All source files (*.c and *.h files)
- All Makefiles or project files if any
- A short instruction about the platform that it needs to be compiled on (i.e. Windows/Linux) and how should it be compiled.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
