RTEMS
tc-modes.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
9 /*
10  * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Do not manually edit this file. It is part of the RTEMS quality process
36  * and was automatically generated.
37  *
38  * If you find something that needs to be fixed or worded better please
39  * post a report to an RTEMS mailing list or raise a bug report:
40  *
41  * https://docs.rtems.org/branches/master/user/support/bugs.html
42  *
43  * For information on updating and regenerating please refer to:
44  *
45  * https://docs.rtems.org/branches/master/eng/req/howto.html
46  */
47 
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51 
52 #include <rtems.h>
53 
54 #include <rtems/test.h>
55 
124 static bool IsPowerOfTwo( rtems_mode mode )
125 {
126  return mode != 0 && ( mode & ( mode - 1 ) ) == 0;
127 }
128 
129 static int PopCount( rtems_mode modes )
130 {
131  int count;
132 
133  count = 0;
134 
135  while ( modes != 0 ) {
136  ++count;
137  modes &= modes - 1;
138  }
139 
140  return count;
141 }
142 
146 T_TEST_CASE( RtemsModeValModes )
147 {
148  rtems_mode modes;
149 
150  T_plan(15);
151 
152  /* No action */
153  T_step_true( 0, IsPowerOfTwo( RTEMS_NO_ASR ) );
154  T_step_true( 1, IsPowerOfTwo( RTEMS_NO_PREEMPT ) );
155  T_step_true( 2, IsPowerOfTwo( RTEMS_TIMESLICE ) );
156 
157  /* No action */
158  T_step_eq_u32( 3, RTEMS_ASR, 0 );
159  T_step_eq_u32( 4, RTEMS_DEFAULT_MODES, 0 );
160  T_step_eq_u32( 5, RTEMS_NO_TIMESLICE, 0 );
161  T_step_eq_u32( 6, RTEMS_PREEMPT, 0 );
162 
163  /* No action */
164  T_step_eq_u32(
165  7,
168  );
169  T_step_eq_u32(
170  8,
173  );
174  T_step_eq_u32(
175  9,
178  );
179  T_step_eq_u32(
180  10,
183  );
184 
185  /* No action */
186  T_step_true( 11, IsPowerOfTwo( RTEMS_ASR_MASK ) );
187  T_step_true( 12, IsPowerOfTwo( RTEMS_PREEMPT_MASK ) );
188  T_step_true( 13, IsPowerOfTwo( RTEMS_TIMESLICE_MASK ) );
189 
190  modes = 0;
191  modes |= 0xff;
192  modes |= RTEMS_ASR_MASK;
193  modes |= RTEMS_PREEMPT_MASK;
194  modes |= RTEMS_TIMESLICE_MASK;
195  T_step_eq_int( 14, PopCount( modes ), 11 );
196 }
197 
#define RTEMS_NO_TIMESLICE
This task mode constant is used to indicate timeslicing is disabled.
Definition: modes.h:211
#define RTEMS_INTERRUPT_MASK
This task mode constant corresponds to the interrupt enable/disable bits.
Definition: modes.h:81
#define RTEMS_ASR
This task mode constant is used to indicate signal processing is disabled.
Definition: modes.h:109
#define RTEMS_TIMESLICE
This task mode constant is used to indicate timeslicing is enabled.
Definition: modes.h:239
#define RTEMS_TIMESLICE_MASK
This task mode constant corresponds to the timeslice enable/disable bit.
Definition: modes.h:249
#define RTEMS_ASR_MASK
This mode constant corresponds to the signal enable/disable bit.
Definition: modes.h:118
#define RTEMS_PREEMPT
This task mode constant is used to indicate preemption is enabled.
Definition: modes.h:220
#define RTEMS_NO_ASR
This task mode constant is used to indicate signal processing is disabled.
Definition: modes.h:193
This header file defines the RTEMS Classic API.
uint32_t rtems_mode
This type is used to represent a task mode set.
Definition: modes.h:90
#define RTEMS_PREEMPT_MASK
This task mode constant corresponds to the preemption enable/disable bit.
Definition: modes.h:230
#define RTEMS_ALL_MODE_MASKS
This task mode constant is a mask with all mode bits set.
Definition: modes.h:99
#define RTEMS_DEFAULT_MODES
This task mode constant represents the default mode set.
Definition: modes.h:137
#define RTEMS_NO_PREEMPT
This task mode constant is used to indicate preemption is disabled.
Definition: modes.h:202