GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_system_timer_start.c Lines: 29 29 100.0 %
Date: 2026-03-06 19:21:09 Branches: 12 12 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   System Management (System)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_system_timer_start                              PORTABLE C      */
36
/*                                                           6.1.7        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service starts a timer for the specified widget.               */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    owner                                 Pointer to widget control     */
48
/*                                            block                       */
49
/*    timer_id                              ID of timer                   */
50
/*    initial ticks                         Initial expiration ticks      */
51
/*    reschedule_ticks                      Periodic expiration ticks     */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    status                                Completion status             */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*   tx_timer_activate                      start the ThreadX timer       */
60
/*   GX_ENTER_CRITICAL                      lock system mutex             */
61
/*   GX_EXIT_CRITICAL                       unlock system mutex           */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    GUIX Application                                                    */
66
/*    GUIX Internal Code                                                  */
67
/*                                                                        */
68
/**************************************************************************/
69
839
UINT  _gx_system_timer_start(GX_WIDGET *owner, UINT timer_id, UINT initial_ticks, UINT reschedule_ticks)
70
{
71
GX_TIMER *found;
72
73
#ifdef GX_THREADX_BINDING
74
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE
75
UINT tx_timer_active;
76
#endif
77
#endif
78
79
    /* check for bad widget pointer */
80
839
    if (!owner)
81
    {
82
1
        return GX_PTR_ERROR;
83
    }
84
85
    /* lock entering critical section */
86
838
    GX_ENTER_CRITICAL
87
88
    /* check for already having this timer */
89
838
    found = _gx_system_active_timer_list;
90
91
1128
    while (found)
92
    {
93
331
        if (found -> gx_timer_id == timer_id &&
94
284
            found -> gx_timer_owner == owner)
95
        {
96
            /* yes, this timer is already running */
97
            /* reset the existing timer value and return */
98
41
            found -> gx_timer_initial_ticks = initial_ticks;
99
41
            found -> gx_timer_reschedule_ticks = reschedule_ticks;
100
41
            GX_EXIT_CRITICAL
101
41
            return GX_SUCCESS;
102
        }
103
290
        found = found -> gx_timer_next;
104
    }
105
106
    /* check for having timer available */
107
797
    if (!_gx_system_free_timer_list)
108
    {
109
        /* no timers available, unlock and return error */
110
1
        GX_EXIT_CRITICAL
111
1
        return GX_OUT_OF_TIMERS;
112
    }
113
114
    /* we have a free timer, remove from free list */
115
796
    found = _gx_system_free_timer_list;
116
796
    _gx_system_free_timer_list = found -> gx_timer_next;
117
118
    /* initialize new timer */
119
796
    found -> gx_timer_initial_ticks = initial_ticks;
120
796
    found -> gx_timer_reschedule_ticks = reschedule_ticks;
121
796
    found -> gx_timer_id = timer_id;
122
796
    found -> gx_timer_owner = owner;
123
124
    /* link this timer at the head of the active list */
125
796
    found -> gx_timer_next = _gx_system_active_timer_list;
126
796
    _gx_system_active_timer_list = found;
127
128
#ifdef GX_THREADX_BINDING
129
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE
130
    /* if the low-level timer is not active, start it */
131
796
    tx_timer_info_get(&_gx_system_timer, (CHAR **)TX_NULL, &tx_timer_active,
132
                      (ULONG *)TX_NULL, (ULONG *)TX_NULL, (TX_TIMER **)TX_NULL);
133
134
796
    if (!tx_timer_active)
135
    {
136
438
        tx_timer_activate(&_gx_system_timer);
137
    }
138
#endif
139
#else
140
    GX_TIMER_START;
141
#endif
142
143
    /* release our lock */
144
796
    GX_EXIT_CRITICAL
145
796
    return GX_SUCCESS;
146
}
147