1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** ThreadX Component                                                     */
17 /**                                                                       */
18 /**   Timer                                                               */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define TX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "tx_api.h"
29 #include "tx_initialize.h"
30 #include "tx_thread.h"
31 #include "tx_timer.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _txe_timer_change                                   PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    William E. Lamie, Microsoft Corporation                             */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks for errors in the application timer change     */
47 /*    function call.                                                      */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    timer_ptr                         Pointer to timer control block    */
52 /*    initial_ticks                     Initial expiration ticks          */
53 /*    reschedule_ticks                  Reschedule ticks                  */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    TX_TIMER_ERROR                    Invalid application timer pointer */
58 /*    TX_TICK_ERROR                     Invalid initial tick value of 0   */
59 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
60 /*    status                            Actual completion status          */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _tx_timer_change                  Actual timer change function      */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
75 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_txe_timer_change(TX_TIMER * timer_ptr,ULONG initial_ticks,ULONG reschedule_ticks)79 UINT  _txe_timer_change(TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG reschedule_ticks)
80 {
81 
82 UINT    status;
83 
84 
85     /* Check for an invalid timer pointer.  */
86     if (timer_ptr == TX_NULL)
87     {
88 
89         /* Timer pointer is invalid, return appropriate error code.  */
90         status =  TX_TIMER_ERROR;
91     }
92 
93     /* Now check for invalid timer ID.  */
94     else if (timer_ptr -> tx_timer_id != TX_TIMER_ID)
95     {
96 
97         /* Timer pointer is invalid, return appropriate error code.  */
98         status =  TX_TIMER_ERROR;
99     }
100 
101     /* Check for an illegal initial tick value.  */
102     else if (initial_ticks == ((ULONG) 0))
103     {
104 
105         /* Invalid initial tick value, return appropriate error code.  */
106         status =  TX_TICK_ERROR;
107     }
108 
109     /* Check for invalid caller of this function.  */
110     else if (TX_THREAD_GET_SYSTEM_STATE() >= TX_INITIALIZE_IN_PROGRESS)
111     {
112 
113         /* Invalid caller of this function, return appropriate error code.  */
114         status =  TX_CALLER_ERROR;
115     }
116     else
117     {
118 
119         /* Call actual application timer function.  */
120         status =  _tx_timer_change(timer_ptr, initial_ticks, reschedule_ticks);
121     }
122 
123     /* Return completion status.  */
124     return(status);
125 }
126 
127