Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 155 lines (135 sloc) 4.57 kb
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
1 /*
2 * Copyright (c) 2010, Kelvin Lawson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. No personal names or organizations' names associated with the
14 * Atomthreads project may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
8de1462 @kelvinlawson Remove unnecessary mods from the MIPS pull request (kernel and tests fol...
authored
30
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
31 #include "atom.h"
32 #include "atomtimer.h"
33 #include "atomtests.h"
34
35
36 /* Test OS objects */
37 static ATOM_TIMER timer_cb[4];
38
39
40 /* Global test data */
41 static int callback_ran_flag[4];
42
43
44 /* Forward declarations */
45 static void testCallback (POINTER cb_data);
46
47
48 /**
49 * \b test_start
50 *
51 * Start timer test.
52 *
53 * This test exercises the atomTimerCancel() API, particularly its
54 * behaviour when there are several timers registered. Four timers
55 * are registered, two of which are cancelled, and the test confirms
56 * that only the two which are not cancelled are called back.
57 *
58 * @retval Number of failures
59 */
60 uint32_t test_start (void)
61 {
62 int failures;
63 int i;
64
65 /* Default to zero failures */
66 failures = 0;
67
68 /* Clear down the ran flag for all four timers */
69 for (i = 0; i < 4; i++)
70 {
71 callback_ran_flag[i] = FALSE;
72 }
73
74 /*
75 * Fill out four timer request structures. Callbacks are
76 * requested starting in one second, with the others
77 * at 1 tick intervals thereafter.
78 */
79 for (i = 0; i < 4; i++)
80 {
81 /*
82 * testCallback() is passed a pointer to the flag it
83 * should set to notify that it has run.
84 */
85 timer_cb[i].cb_ticks = SYSTEM_TICKS_PER_SEC + i;
86 timer_cb[i].cb_func = testCallback;
87 timer_cb[i].cb_data = &callback_ran_flag[i];
88 }
89
90 /* Register all four timers */
91 for (i = 0; i < 4; i++)
92 {
93 if (atomTimerRegister (&timer_cb[i]) != ATOM_OK)
94 {
95 ATOMLOG (_STR("TimerReg\n"));
96 failures++;
97 }
98 }
99
100 /* Check timers were successfully created */
101 if (failures == 0)
102 {
103 /* Cancel two of the callbacks */
104 if (atomTimerCancel (&timer_cb[1]) != ATOM_OK)
105 {
106 ATOMLOG (_STR("Cancel1\n"));
107 failures++;
108 }
109 if (atomTimerCancel (&timer_cb[2]) != ATOM_OK)
110 {
111 ATOMLOG (_STR("Cancel2\n"));
112 failures++;
113 }
114
115 /* Wait two seconds for callbacks to complete */
116 if (atomTimerDelay(2 * SYSTEM_TICKS_PER_SEC) != ATOM_OK)
117 {
118 ATOMLOG (_STR("Wait\n"));
119 failures++;
120 }
121 else
122 {
123 /*
124 * We should now find that timer callbacks 0 and 3
125 * have run, but 1 and 2 did not (due to cancellation).
126 */
127 if ((callback_ran_flag[0] != TRUE) || (callback_ran_flag[3] != TRUE)
128 || (callback_ran_flag[1] != FALSE) || (callback_ran_flag[2] != FALSE))
129 {
130 ATOMLOG (_STR("Cancellations\n"));
131 failures++;
132 }
133 }
134 }
135
136 /* Quit */
137 return failures;
138
139 }
140
141
142 /**
143 * \b testCallback
144 *
145 * Set a flag to say we ran. Some of the callbacks are
146 * expected to execute this, while those that are
147 * cancelled should not.
148 *
149 * @param[in] cb_data Not used
150 */
151 static void testCallback (POINTER cb_data)
152 {
153 /* Callback was called */
154 *(int *)cb_data = TRUE;
8de1462 @kelvinlawson Remove unnecessary mods from the MIPS pull request (kernel and tests fol...
authored
155 }
Something went wrong with that request. Please try again.