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