应用程序计时器
應(yīng)用程序計(jì)時(shí)器
Application timers
應(yīng)用程序計(jì)時(shí)器是內(nèi)核對(duì)象,為任務(wù)提供簡單的方法來計(jì)時(shí)事件,或者更常見的是,定期執(zhí)行活動(dòng)。介紹了Nucleus SE中計(jì)時(shí)功能的所有細(xì)節(jié)——準(zhǔn)確性、中斷處理等。
Using Timers
應(yīng)用程序計(jì)時(shí)器可以配置為一次性的-即,它們被啟動(dòng),然后,在指定的時(shí)間段之后,它們只是終止。或者,可以將計(jì)時(shí)器配置為重復(fù),即當(dāng)計(jì)時(shí)器過期時(shí),它會(huì)自動(dòng)重新啟動(dòng);重新啟動(dòng)周期的時(shí)間間隔可能與初始時(shí)間不同。定時(shí)器也可以選擇性地配置為在定時(shí)器過期(或每次)時(shí)運(yùn)行特定的功能-過期例程。
Configuring Timers
Number
of Timers
與Nucleus SE的大多數(shù)方面一樣,計(jì)時(shí)器的配置主要由nuse_config.h中的#define語句控制。鍵設(shè)置是NUSE_TIMER_NUMBER,它確定為應(yīng)用程序配置了多少計(jì)時(shí)器。默認(rèn)設(shè)置為0(即不使用計(jì)時(shí)器),您可以將其設(shè)置為16以內(nèi)的任何值。錯(cuò)誤的值將導(dǎo)致編譯時(shí)錯(cuò)誤,該錯(cuò)誤由nuse_config_check.h中的測(cè)試生成(此錯(cuò)誤包含在nuse_config.c中,因此使用此模塊進(jìn)行編譯),從而導(dǎo)致編譯一個(gè)#錯(cuò)誤語句。
選擇非零值是計(jì)時(shí)器的“主啟用”。這將導(dǎo)致一些數(shù)據(jù)結(jié)構(gòu)被相應(yīng)地定義和調(diào)整大小,本文稍后將對(duì)此進(jìn)行詳細(xì)介紹。它還激活A(yù)PI啟用設(shè)置。
Expiration Routine Enable
過期例程啟用
在Nucleus SE中,我尋找機(jī)會(huì)使功能成為可選的,這樣可以節(jié)省內(nèi)存。一個(gè)很好的例子就是對(duì)計(jì)時(shí)器過期例程的支持。除了對(duì)每個(gè)單獨(dú)的計(jì)時(shí)器是可選的之外,還可以通過NUSE_config.h中的NUSE_timer_EXPIRATION_ROUTINE_SUPPORT設(shè)置為整個(gè)應(yīng)用程序啟用(或不啟用)。將其設(shè)置為FALSE將禁止定義兩個(gè)ROM數(shù)據(jù)結(jié)構(gòu),本文稍后將介紹這兩個(gè)數(shù)據(jù)結(jié)構(gòu)。
API Enables
Nucleus SE中的每個(gè)API函數(shù)(服務(wù)調(diào)用)在nuse_config.h中都有一個(gè)啟用的#define符號(hào)。對(duì)于計(jì)時(shí)器,這些是:
NUSE_TIMER_CONTROL
NUSE_TIMER_GET_REMAINING
NUSE_TIMER_RESET
NUSE_TIMER_INFORMATION
NUSE_TIMER_COUNT
默認(rèn)情況下,所有這些都設(shè)置為FALSE,從而禁用每個(gè)服務(wù)調(diào)用并禁止包含任何實(shí)現(xiàn)代碼。要為應(yīng)用程序配置計(jì)時(shí)器,需要選擇要使用的API調(diào)用并將其啟用符號(hào)設(shè)置為TRUE。
默認(rèn)情況下,從配置文件nuse_config.h中提取。
#define NUSE_TIMER_NUMBER 0 /* Number of application timers in
the system – 0-16 */
/* Service call enablers */
#define NUSE_TIMER_CONTROL FALSE
#define NUSE_TIMER_GET_REMAINING FALSE
#define NUSE_TIMER_RESET FALSE
#define NUSE_TIMER_INFORMATION FALSE
#define NUSE_TIMER_COUNT FALSE
如果啟用計(jì)時(shí)器API函數(shù)且未配置計(jì)時(shí)器(除非始終允許使用NUSE_timer_Count()),則會(huì)導(dǎo)致編譯時(shí)錯(cuò)誤。如果您的代碼使用尚未啟用的API調(diào)用,則會(huì)導(dǎo)致鏈接時(shí)間錯(cuò)誤,因?yàn)閼?yīng)用程序中不會(huì)包含任何實(shí)現(xiàn)代碼。
Timer Service Calls
Nucleus RTOS支持八個(gè)與計(jì)時(shí)器相關(guān)的服務(wù)調(diào)用,它們提供以下功能:
控制(啟動(dòng)/停止)計(jì)時(shí)器。由Nucleus SE中的NUSE_Timer_Control()實(shí)現(xiàn)。
從計(jì)時(shí)器獲取剩余時(shí)間。由Nucleus SE中的NUSE_Timer_Get_Remaining()實(shí)現(xiàn)。
將計(jì)時(shí)器恢復(fù)到未使用狀態(tài)(重置)。由Nucleus SE中的NUSE_Timer_Reset()實(shí)現(xiàn)。
提供有關(guān)指定計(jì)時(shí)器的信息。由Nucleus SE中的NUSE_Timer_Information()實(shí)現(xiàn)。
返回(當(dāng)前)為應(yīng)用程序配置的計(jì)時(shí)器數(shù)。由Nucleus SE中的NUSE_Timer_Count()實(shí)現(xiàn)。
向應(yīng)用程序添加新計(jì)時(shí)器(創(chuàng)建)。未在Nucleus SE中實(shí)現(xiàn)。
從應(yīng)用程序中刪除計(jì)時(shí)器(刪除)。未在Nucleus SE中實(shí)現(xiàn)。
返回指向應(yīng)用程序中所有計(jì)時(shí)器(當(dāng)前)的指針。未在Nucleus SE中實(shí)現(xiàn)。
將詳細(xì)檢查每個(gè)服務(wù)調(diào)用的實(shí)現(xiàn)。
Timer Services
可以在計(jì)時(shí)器上執(zhí)行的基本操作是控制計(jì)時(shí)器-啟動(dòng)和停止-并讀取其當(dāng)前值。Nucleus RTOS和Nucleus SE各自為這些操作提供了兩個(gè)基本的API調(diào)用,這里將對(duì)此進(jìn)行討論。
Controlling a Timer
The Nucleus RTOS API call for controlling a timer simply permits the timer to be enabled or disabled (i.e. started or stopped). Nucleus SE provides the same service.
Nucleus RTOS API Call for Controlling a Timer
Service call prototype:
STATUS NU_Control_Timer(NU_TIMER *timer, OPTION enable);
Parameters:
timer – pointer to the user-supplied timer control block
enable – required function; may be NU_ENABLE_TIMER or NU_DISABLE_TIMER
Returns:
NU_SUCCESS – the call was completed successfully
NU_INVALID_TIMER – the timer pointer is invalid
NU_INVALID_ENABLE – the specified function is invalid
Nucleus SE API Call for Controlling a Timer
This API call supports the full functionality of the Nucleus RTOS API.
Service call prototype:
STATUS NUSE_Timer_Control(NUSE_TIMER timer, OPTION enable);
Parameters:
timer – the index (ID) of the timer to be utilized
enable – required function; may be NUSE_ENABLE_TIMER or NUSE_DISABLE_TIMER
Returns:
NUSE_SUCCESS – the call was completed successfully
NUSE_INVALID_TIMER – the timer index is invalid
NUSE_INVALID_ENABLE – the specified function is invalid
Nucleus SE Implementation of Timer Control
The code of the NUSE_Timer_Control() API function – after parameter checking – is reasonably straightforward:
NUSE_CS_Enter();if (enable == NUSE_ENABLE_TIMER){ NUSE_Timer_Status[timer] = TRUE; if (NUSE_Timer_Expirations_Counter[timer] == 0) { NUSE_Timer_Value[timer] = NUSE_Timer_Initial_Time[timer]; } else { NUSE_Timer_Value[timer] = NUSE_Timer_Reschedule_Time[timer]; }}else /* enable == NUSE_DISABLE_TIMER */{ NUSE_Timer_Status[timer] = FALSE;}NUSE_CS_Exit();
如果指定的函數(shù)是NUSE_DISABLE_TIMER,則計(jì)時(shí)器的狀態(tài)(NUSE_TIMER_status[]項(xiàng))設(shè)置為FALSE,這將導(dǎo)致時(shí)鐘ISR忽略它。
如果指定了NUSE_ENABLE_TIMER,則計(jì)時(shí)器計(jì)數(shù)器(NUSE_TIMER_Value[])設(shè)置為NUSE_TIMER_Initial_Time[],前提是計(jì)時(shí)器自上次重置后從未過期。否則,它將被設(shè)置為“使用計(jì)時(shí)器”“重新計(jì)劃”“時(shí)間[]”。然后計(jì)時(shí)器的狀態(tài)(NUSE_timer_status[]項(xiàng))設(shè)置為TRUE,這將導(dǎo)致時(shí)鐘ISR對(duì)其進(jìn)行處理。
讀取計(jì)時(shí)器
Nucleus RTOS API調(diào)用從計(jì)時(shí)器獲取剩余時(shí)間就是這樣做的——返回過期前的計(jì)時(shí)點(diǎn)數(shù)。Nucleus SE提供相同的服務(wù)。
Nucleus RTOS API Call for Getting Remaining Time
Service call prototype:
STATUS NU_Get_Remaining_Time (NU_TIMER *timer,
UNSIGNED *remaining_time);
Parameters:
timer – pointer to the user-supplied timer control block.
remaining_time – a pointer to storage for the remaining time value, which is a single variable of type UNSIGNED
Returns:
NU_SUCCESS – the call was completed successfully
NU_INVALID_TIMER – the timer pointer is invalid
Nucleus SE API Call for Getting Remaining Time
This API call supports the full functionality of the Nucleus RTOS API.
Service call prototype:
STATUS NUSE_Timer_Get_Remaining(NUSE_TIMER timer,
U16 *remaining_time);
Parameters:
timer – the index (ID) of the timer to be utilized
remaining_time – a pointer to storage for the remaining time value, which is a single variable of type U16
Returns:
NUSE_SUCCESS – the call was completed successfully
NUSE_INVALID_TIMER – the timer index is invalid
NUSE_INVALID_POINTER – the remaining time pointer is NULL
Nucleus SE Implementation of Timer Read
The bulk of the code of the NUSE_Timer_Get_Remaining() API function – after parameter checking – is almost trivially simple. The value of NUSE_Timer_Value[] is obtained and returned within a critical section.
計(jì)時(shí)器實(shí)用程序服務(wù)
Nucleus RTOS有四個(gè)API調(diào)用,它們提供與計(jì)時(shí)器相關(guān)的實(shí)用函數(shù):重置計(jì)時(shí)器、返回有關(guān)計(jì)時(shí)器的信息、返回應(yīng)用程序中計(jì)時(shí)器的數(shù)量以及返回指向應(yīng)用程序中所有計(jì)時(shí)器的指針。前三個(gè)在Nucleus SE中實(shí)現(xiàn)。
重置計(jì)時(shí)器
此API調(diào)用將計(jì)時(shí)器恢復(fù)到其未使用的初始狀態(tài)。在完成此調(diào)用后,可以啟用或禁用計(jì)時(shí)器。只有在禁用計(jì)時(shí)器后才允許(使用NUSE_timer_Control())。下一次啟用計(jì)時(shí)器時(shí),將使用NUSE_timer_Initial_Time[]中的條目初始化計(jì)時(shí)器。Nucleus
RTOS允許在重置計(jì)時(shí)器時(shí)提供新的初始和重新計(jì)劃時(shí)間,并指定過期例程;在Nucleus SE中,這些值在配置時(shí)設(shè)置,不能更改,因?yàn)樗鼈兛赡艽鎯?chǔ)在ROM中。
Nucleus RTOS API Call for Resetting a Timer
Service call prototype:
STATUS NU_Reset_Timer(NU_TIMER *timer,
VOID (*expiration_routine)(UNSIGNED), UNSIGNED initial_time,
UNSIGNED reschedule_time, OPTION enable);
Parameters:
timer – pointer to the timer to be reset
expiration_routine – specifies the application routine to execute when the timer expires
initial_time – the initial number of timer ticks for timer expiration
reschedule_time – the number of timer ticks for expiration after the first expiration
enable – required state after reset; may be NU_ENABLE_TIMER or NU_DISABLE_TIMER
Returns:
NU_SUCCESS – the call was completed successfully
NU_INVALID_TIMER – the timer control block pointer is not valid
NU_INVALID_FUNCTION – the expiration function pointer is NULL
NU_INVALID_ENABLE – the specified state is invalid
NU_NOT_DISABLED – the time is currently enabled (disable required before reset)
Nucleus SE API Call for Resetting a Timer
This API call supports a simplified version of the key functionality of the Nucleus RTOS API.
Service call prototype:
STATUS NUSE_Timer_Reset(NUSE_TIMER timer, OPTION enable);
Parameters:
timer – the index (ID) of the timer to be reset
enable – required state after reset; may be NUSE_ENABLE_TIMER or NUSE_DISABLE_TIMER
Returns:
NUSE_SUCCESS – the call was completed successfully
NUSE_INVALID_TIMER – the timer index is not valid
NUSE_INVALID_ENABLE – the specified state is invalid
NUSE_NOT_DISABLED – the time is currently enabled (disable required before reset)
Nucleus SE Implementation of Timer Reset
The bulk of the code of the NUSE_Timer_Reset() API function – after parameter and current status checking – is quite
straightforward:
NUSE_CS_Enter();NUSE_Init_Timer(timer);if (enable == NUSE_ENABLE_TIMER){ NUSE_Timer_Status[timer] = TRUE;}/* else enable == NUSE_DISABLE_TIMER and status remains FALSE */NUSE_CS_Exit();
調(diào)用NUSE_Init_Timer()初始化時(shí)間值并清除過期計(jì)數(shù)器。然后檢查所需狀態(tài)并啟用計(jì)時(shí)器(如果需要)。
定時(shí)器信息
此服務(wù)調(diào)用獲取有關(guān)計(jì)時(shí)器的信息選擇。Nucleus SE實(shí)現(xiàn)與Nucleus RTOS的不同之處在于它返回的信息較少,因?yàn)椴恢С謱?duì)象命名。
對(duì)計(jì)時(shí)器信息的Nucleus RTOS API調(diào)用
Service call prototype:
STATUS NU_Timer_Information(NU_TIMER *timer, CHAR *name,
OPTION *enable, UNSIGNED *expirations, UNSIGNED *id,
UNSIGNED *initial_time, UNSIGNED *reschedule_time);
Parameters:
timer – pointer to the timer about which information is being requested
name – pointer to an 8-character destination area for the timer’s name.
enable – a pointer to a variable, which will receive the timer’s current enable state: NU_ENABLE_TIMER or NU_DISABLE_TIMER
expirations – a pointer to a variable of type which will receive the count of the number of times the timer has expired since it was last reset
id – a pointer to a variable which will receive the value of the parameter passed to the timer’s expiration routine
initial_time – a pointer to a variable which will receive the value to which the timer is initialized on reset
reschedule_time – a pointer to a variable which will receive the value to which the timer is initialized on expiration
Returns:
NU_SUCCESS – the call was completed successfully
NU_INVALID_TIMER – the timer pointer is not valid
Nucleus SE API Call for Timer Information
This API call supports the key functionality of the Nucleus RTOS API.
Service call prototype:
STATUS NUSE_Timer_Information(NUSE_TIMER timer, OPTION *enable,
U8 expirations, U8 *id, U16 *initial_time, U16 *reschedule_time);
Parameters:
timer – the index of the timer about which information is being requested
enable – a pointer to a variable, which will receive a value of TRUE or FALSE depending on whether the timer is enabled or not
expirations – a pointer to a variable of type U8 which will receive the count of the number of times the timer has expired since it was last reset
id – a pointer to a variable of type U8 which will receive the value of the parameter passed to the timer’s expiration routine (nothing returned if expiration routines are disabled)
initial_time – a pointer to a variable of type U16 which will receive the value to which the timer is initialized on reset
reschedule_time – a pointer to a variable of type U16 which will receive the value to which the timer is initialized on expiration
Returns:
NUSE_SUCCESS – the call was completed successfully
NUSE_INVALID_TIMER – the timer index is not valid
NUSE_INVALID_POINTER – one or more of the pointer parameters is invalid
Nucleus SE Implementation of Timer Information
The implementation of this API call is quite straightforward:
NUSE_CS_Enter();if (NUSE_Timer_Status[timer]){ *enable = NUSE_ENABLE_TIMER;}else{ *enable = NUSE_DISABLE_TIMER;}*expirations = NUSE_Timer_Expirations_Counter[timer];#if NUSE_TIMER_EXPIRATION_ROUTINE_SUPPORT id = NUSE_Timer_Expiration_Routine_Parameter[timer];#endifinitial_time = NUSE_Timer_Initial_Time[timer];*reschedule_time = NUSE_Timer_Reschedule_Time[timer];NUSE_CS_Exit();
函數(shù)返回計(jì)時(shí)器狀態(tài)。只有在應(yīng)用程序中啟用了過期例程時(shí),才會(huì)返回expiration例程參數(shù)的值。
獲取計(jì)時(shí)器的數(shù)量
此服務(wù)調(diào)用返回應(yīng)用程序中配置的計(jì)時(shí)器數(shù)。在Nucleus RTOS中,這將隨時(shí)間而變化,返回的值將表示當(dāng)前的計(jì)時(shí)器數(shù)量,而在Nucleus SE中,返回的值在構(gòu)建時(shí)設(shè)置,不能更改。
用于計(jì)時(shí)器計(jì)數(shù)的Nucleus RTOS API調(diào)用
Service call prototype:
UNSIGNED NU_Established_Timers(VOID);
Parameters:
None
Returns:
The number of created timers in the system.
Nucleus SE API Call for Timer Count
This API call supports the key functionality of the Nucleus RTOS API.
Service call prototype:
U8 NUSE_Timer_Count(void);
Parameters:
None
Returns:
The number of configured timers in the application.
定時(shí)器計(jì)數(shù)的實(shí)現(xiàn)
這個(gè)API調(diào)用的實(shí)現(xiàn)非常簡單:返回#define symbol NUSE_TIMER_NUMBER的值。
數(shù)據(jù)結(jié)構(gòu)
定時(shí)器使用五到七個(gè)數(shù)據(jù)結(jié)構(gòu)——在RAM和ROM中——與其他Nucleus SE對(duì)象一樣,這些數(shù)據(jù)結(jié)構(gòu)是一系列表,根據(jù)配置的計(jì)時(shí)器數(shù)量和選擇的選項(xiàng)進(jìn)行標(biāo)注。
我強(qiáng)烈建議應(yīng)用程序代碼不要直接訪問這些數(shù)據(jù)結(jié)構(gòu),而是使用提供的API函數(shù)。這避免了與Nucleus SE未來版本的不兼容和不必要的副作用,并簡化了將應(yīng)用程序移植到Nucleus RTOS的過程。這里包含數(shù)據(jù)結(jié)構(gòu)的詳細(xì)信息,以便更容易地理解服務(wù)調(diào)用代碼的工作方式和調(diào)試。
RAM數(shù)據(jù)
這些數(shù)據(jù)結(jié)構(gòu)包括:
NUSE_Timer_Status[]–這是一個(gè)U8類型的數(shù)組,每個(gè)配置的計(jì)時(shí)器都有一個(gè)條目,是存儲(chǔ)計(jì)時(shí)器狀態(tài)(運(yùn)行或停止:TRUE或FALSE)的位置。
其中一個(gè)定時(shí)器的值uUse是一個(gè)定時(shí)器值,它是一個(gè)定時(shí)器值。
NUSE_Timer_Expirations_Counter[]–此類型的U8數(shù)組包含計(jì)時(shí)器自上次重置后達(dá)到過期的次數(shù)的計(jì)數(shù)。
當(dāng)Nucleus SE啟動(dòng)時(shí),這些數(shù)據(jù)結(jié)構(gòu)都由NUSE_Init_Timer()初始化。未來的文章將全面描述Nucleus SE的啟動(dòng)過程。
以下是nuse_init.c文件中這些數(shù)據(jù)結(jié)構(gòu)的定義:
RAM U8 NUSE_Timer_Status[NUSE_TIMER_NUMBER];
RAM U16 NUSE_Timer_Value[NUSE_TIMER_NUMBER];
RAM U8 NUSE_Timer_Expirations_Counter[NUSE_TIMER_NUMBER];
ROM Data
這些數(shù)據(jù)結(jié)構(gòu)包括:
NUSE_Timer_Initial_Time[]–這是一個(gè)U16類型的數(shù)組,每個(gè)配置的計(jì)時(shí)器有一個(gè)條目,是存儲(chǔ)每個(gè)計(jì)時(shí)器計(jì)數(shù)器的初始值的地方。
NUSE_Timer_Reschedule_Time[]–這是一個(gè)U16類型的數(shù)組,每個(gè)配置的計(jì)時(shí)器都有一個(gè)條目,其中包含過期時(shí)每個(gè)計(jì)時(shí)器的計(jì)數(shù)器應(yīng)設(shè)置的值。值為零表示計(jì)時(shí)器是“一次性”的,不應(yīng)自動(dòng)重新啟動(dòng)。
NUSE_Timer_Expiration_Routine_Address[]–此類型的ADDR數(shù)組包含計(jì)時(shí)器過期例程的地址。此數(shù)組僅在啟用計(jì)時(shí)器過期例程支持時(shí)存在。
NUSE_Timer_Expiration_Routine_Parameter[]–此類型的U8數(shù)組包含將傳遞給計(jì)時(shí)器的過期例程的參數(shù)值。此數(shù)組僅在啟用計(jì)時(shí)器過期例程支持時(shí)存在。
這些數(shù)據(jù)結(jié)構(gòu)都在nuse_config.c中聲明和初始化(當(dāng)然是靜態(tài)的),因此:
ROM U16 NUSE_Timer_Initial_Time[NUSE_TIMER_NUMBER] ={ /* timer initial times ------ /};ROM U16 NUSE_Timer_Reschedule_Time[NUSE_TIMER_NUMBER] ={ / timer reschedule times ------ /};#if NUSE_TIMER_EXPIRATION_ROUTINE_SUPPORT || NUSE_INCLUDE_EVERYTHING / need prototypes of expiration routines here / ROM ADDR NUSE_Timer_Expiration_Routine_Address[NUSE_TIMER_NUMBER] = { / addresses of timer expiration routines ------ / / can be NULL / }; ROM U8 NUSE_Timer_Expiration_Routine_Parameter[NUSE_TIMER_NUMBER] = { / timer expiration routine parameters ------ */ };#endif
Timer Data Footprint
Like all kernel objects in Nucleus SE, the amount of data memory
required for timers is readily predictable.
The RAM data footprint (in bytes) for all the timers in an application may be computed thus:
NUSE_TIMER_NUMBER * 4
The ROM data footprint (in bytes) for all the timers in an application, if expiration routines are not supported, may be computed thus:
NUSE_TIMER_NUMBER * 4
Otherwise, it is:
NUSE_TIMER_NUMBER * (sizeof(ADDR) + 5)
Unimplemented API Calls
Three timer API calls found in Nucleus RTOS are not implemented in Nucleus SE:
Create Timer
This API call creates a timer. It is not needed with Nucleus SE, as timers are created statically.
Service call prototype:
STATUS NU_Create_Timer(NU_TIMER *timer, CHAR *name,
VOID (*expiration_routine)(UNSIGNED), UNSIGNED id,
UNSIGNED initial_time, UNSIGNED reschedule_time, OPTION enable);
Parameters:
timer – pointer to a user-supplied timer control block; this will be used as a “handle” for the timer in other API calls
name – pointers to a 7-character, null-terminated name for the timer
expiration_routine – s pecifies the application
routine to execute when the timer expires
id – a n UNSIGNED data element supplied to the expiration routine; the parameter may be used to help identify timers that use the same expiration routine
initial_time – specifies the initial number of timer ticks for timer expiration
reschedule_time – specifies the number of timer ticks for expiration after the first expiration; if this parameter is zero, the timer only expires once
enable – valid options for this parameter are NU_ENABLE_TIMER and NU_DISABLE_TIMER; NU_ENABLE_TIMER activates the timer after it is created; NU_DISABLE_TIMER leaves the timer disabled; timers created with the NU_DISABLE_TIMER must be enabled by a call to NU_Control_Timer later
Returns:
NU_SUCCESS – indicates successful completion of the service
NU_INVALID_TIMER – indicates the timer control block pointer is NULL or already in use
NU_INVALID_FUNCTION – indicates the expiration function pointer is NULL
NU_INVALID_ENABLE – indicates that the enable parameter is invalid
NU_INVALID_OPERATION – indicates that initial_time parameter was zero
Delete Timer
This API call deletes a previously created timer. It is not needed with Nucleus SE, as timers are created statically and cannot be deleted.
Service call prototype:
STATUS NU_Delete_Timer(NU_TIMER *timer);
Parameters:
timer – pointer to timer control block
Returns:
NU_SUCCESS – indicates successful completion of the service
NU_INVALID_TIMER – indicates the timer pointer is invalid
NU_NOT_DISABLED – indicates the specified timer is not disabled
Timer Pointers
This API call builds a sequential list of pointers to all timers in the system. It is not needed with Nucleus SE, as timers are identified by a
simple index, not a pointer, and it would be redundant.
Service call prototype:
UNSIGNED NU_Timer_Pointers(NU_TIMER **pointer_list,
UNSIGNED maximum_pointers);
Parameters:
pointer_list – pointer to an array of NU_TIMER pointers;
this array will be filled with pointers to established timers in the system
maximum_pointers – the maximum number of pointers to place in the array
Returns:
The number of NU_TIMER pointers
placed into the array
與Nucleus RTOS的兼容性
對(duì)于Nucleus SE的各個(gè)方面,我的目標(biāo)是盡可能保持與Nucleus RTOS的高級(jí)別應(yīng)用程序代碼兼容性。計(jì)時(shí)器也不例外,從用戶的角度來看,它們的實(shí)現(xiàn)方式與Nucleus RTOS中的實(shí)現(xiàn)方式大致相同。有一些不兼容的地方,我認(rèn)為這樣的不兼容是可以接受的,因?yàn)樯傻拇a更容易理解,或者更有可能提高內(nèi)存效率。否則,Nucleus RTOS API調(diào)用幾乎可以直接映射到Nucleus SE調(diào)用上。未來的一篇文章將進(jìn)一步介紹如何為Nucleus RTOS用戶使用Nucleus SE。
對(duì)象標(biāo)識(shí)符
在Nucleus RTOS中,所有對(duì)象都由具有特定數(shù)據(jù)類型的數(shù)據(jù)結(jié)構(gòu)(控制塊)來描述。指向此控制塊的指針用作計(jì)時(shí)器的標(biāo)識(shí)符。在Nucleus SE中,我決定需要一種不同的方法來提高內(nèi)存效率,所有的內(nèi)核對(duì)象都由RAM和/或ROM中的許多表來描述,這些表的大小由配置的每個(gè)對(duì)象類型的數(shù)量決定。特定對(duì)象的標(biāo)識(shí)符只是這些表的索引。因此,我將NUSE_TIMER定義為等同于U8;這種類型的變量(而不是指針)將充當(dāng)計(jì)時(shí)器標(biāo)識(shí)符。這是一個(gè)小的不兼容性,如果代碼被移植到Nucleus RTOS或從Nucleus RTOS移植過來,就很容易處理這個(gè)問題。對(duì)象標(biāo)識(shí)符通常只是存儲(chǔ)和傳遞,而不是以任何方式操作。
Nucleus RTOS還支持計(jì)時(shí)器的命名。這些名稱僅用于基于目標(biāo)的調(diào)試工具。為了節(jié)省內(nèi)存,我把它們從Nucleus SE中省略了。
計(jì)時(shí)器大小
在Nucleus RTOS中,定時(shí)器是用32位計(jì)數(shù)器實(shí)現(xiàn)的。我決定把這個(gè)減少到16位。這種改變顯著提高了內(nèi)存和執(zhí)行時(shí)間效率。如果需要更長的時(shí)間,Nucleus-SE可以很容易地被修飾。
過期例程
Nucleus SE實(shí)現(xiàn)過期例程的方式與Nucleus rto中的方法基本相同,只是它們可能被完全禁用(這可以節(jié)省一些內(nèi)存),并且它們是靜態(tài)定義的。當(dāng)定時(shí)器復(fù)位時(shí),不可能改變過期程序。
未實(shí)現(xiàn)的API調(diào)用
Nucleus RTOS支持8個(gè)服務(wù)調(diào)用來使用計(jì)時(shí)器。其中三個(gè)在Nucleus SE中沒有實(shí)現(xiàn)。在本文前面的未實(shí)現(xiàn)的API調(diào)用中可以找到這些調(diào)用以及省略它們的決定的詳細(xì)信息。
RTOS的下一篇文章將討論中斷。
總結(jié)
- 上一篇: 一种新的高级抖动分离解析方法
- 下一篇: 系统时间