RTEMS 6.1-rc5
Loading...
Searching...
No Matches
tx-support.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2021 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _TX_SUPPORT_H
38#define _TX_SUPPORT_H
39
40#include <rtems.h>
41#include <rtems/irq-extension.h>
42#include <rtems/score/atomic.h>
43#include <rtems/score/threadq.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
55typedef enum {
56 PRIO_PSEUDO_ISR,
57 PRIO_VERY_ULTRA_HIGH,
58 PRIO_ULTRA_HIGH,
59 PRIO_VERY_HIGH,
60 PRIO_HIGH,
61 PRIO_NORMAL,
62 PRIO_LOW,
63 PRIO_VERY_LOW,
64 PRIO_ULTRA_LOW
65} Priority;
66
70#define PRIO_DEFAULT 1
71
78#define PRIO_INVALID 0xfffffffe
79
87#define PRIO_NEARLY_IDLE 126
88
96#define PRIO_FLEXIBLE 64
97
101#define INVALID_ID 0xfffffffd
102
106#define OBJECT_NAME rtems_build_name( 'T', 'E', 'S', 'T' )
107
108#define CreateTask( name, priority ) \
109 DoCreateTask( \
110 rtems_build_name( name[ 0 ], name[ 1 ], name[ 2 ], name[ 3 ] ), \
111 priority \
112 )
113
114#define SCHEDULER_A_ID 0xf010001
115
116#define SCHEDULER_B_ID 0xf010002
117
118#define SCHEDULER_C_ID 0xf010003
119
120#define SCHEDULER_D_ID 0xf010004
121
122rtems_id DoCreateTask( rtems_name name, rtems_task_priority priority );
123
124void StartTask( rtems_id id, rtems_task_entry entry, void *arg );
125
126void DeleteTask( rtems_id id );
127
128void SuspendTask( rtems_id id );
129
130void SuspendSelf( void );
131
132void ResumeTask( rtems_id id );
133
134bool IsTaskSuspended( rtems_id id );
135
136rtems_event_set QueryPendingEvents( void );
137
138rtems_event_set PollAnyEvents( void );
139
140rtems_event_set ReceiveAnyEvents( void );
141
142rtems_event_set ReceiveAnyEventsTimed( rtems_interval ticks );
143
144void ReceiveAllEvents( rtems_event_set events );
145
146void SendEvents( rtems_id id, rtems_event_set events );
147
148rtems_mode GetMode( void );
149
150rtems_mode SetMode( rtems_mode set, rtems_mode mask );
151
152rtems_task_priority GetPriority( rtems_id id );
153
154rtems_task_priority GetPriorityByScheduler(
155 rtems_id task_id,
156 rtems_id scheduler_id
157);
158
159rtems_task_priority SetPriority( rtems_id id, rtems_task_priority priority );
160
161rtems_task_priority GetSelfPriority( void );
162
163rtems_task_priority SetSelfPriority( rtems_task_priority priority );
164
165rtems_task_priority SetSelfPriorityNoYield( rtems_task_priority priority );
166
167rtems_id GetScheduler( rtems_id id );
168
169rtems_id GetSelfScheduler( void );
170
171void SetScheduler(
172 rtems_id task_id,
173 rtems_id scheduler_id,
174 rtems_task_priority priority
175);
176
177void SetSelfScheduler( rtems_id scheduler_id, rtems_task_priority priority );
178
179void GetAffinity( rtems_id id, cpu_set_t *set );
180
181void GetSelfAffinity( cpu_set_t *set );
182
183void SetAffinity( rtems_id id, const cpu_set_t *set );
184
185void SetSelfAffinity( const cpu_set_t *set );
186
187void SetAffinityOne( rtems_id id, uint32_t cpu_index );
188
189void SetSelfAffinityOne( uint32_t cpu_index );
190
191void SetAffinityAll( rtems_id id );
192
193void SetSelfAffinityAll( void );
194
195void Yield( void );
196
197void YieldTask( rtems_id id );
198
199void AddProcessor( rtems_id scheduler_id, uint32_t cpu_index );
200
201void RemoveProcessor( rtems_id scheduler_id, uint32_t cpu_index );
202
203rtems_id CreateMutex( void );
204
205rtems_id CreateMutexNoProtocol( void );
206
207rtems_id CreateMutexFIFO( void );
208
209bool IsMutexOwner( rtems_id id );
210
211void DeleteMutex( rtems_id id );
212
213void ObtainMutex( rtems_id id );
214
215void ObtainMutexTimed( rtems_id id, rtems_interval ticks );
216
217void ObtainMutexDeadlock( rtems_id id );
218
219void ReleaseMutex( rtems_id id );
220
221struct Thread_queue_Queue;
222
223struct Thread_queue_Queue *GetMutexThreadQueue( rtems_id id );
224
225void RestoreRunnerASR( void );
226
227void RestoreRunnerMode( void );
228
229void RestoreRunnerPriority( void );
230
231void RestoreRunnerScheduler( void );
232
233struct _Thread_Control;
234
235struct _Thread_Control *GetThread( rtems_id id );
236
237struct _Thread_Control *GetExecuting( void );
238
239void KillZombies( void );
240
241void WaitForExecutionStop( rtems_id task_id );
242
243void WaitForIntendToBlock( rtems_id task_id );
244
245void WaitForHeir( uint32_t cpu_index, rtems_id task_id );
246
247void WaitForNextTask( uint32_t cpu_index, rtems_id task_id );
248
249typedef enum {
250 TASK_TIMER_INVALID,
251 TASK_TIMER_INACTIVE,
252 TASK_TIMER_TICKS,
253 TASK_TIMER_REALTIME,
254 TASK_TIMER_MONOTONIC
255} TaskTimerState;
256
257typedef struct {
258 TaskTimerState state;
259 uint64_t expire_ticks;
260 struct timespec expire_timespec;
262
263void GetTaskTimerInfo( rtems_id id, TaskTimerInfo *info );
264
265void GetTaskTimerInfoByThread(
266 struct _Thread_Control *thread,
267 TaskTimerInfo *info
268);
269
270void ClockTick( void );
271
278void FinalClockTick( void );
279
288void TimecounterTick( void );
289
290typedef uint32_t ( *GetTimecountHandler )( void );
291
299GetTimecountHandler SetGetTimecountHandler( GetTimecountHandler handler );
300
305#define SOFTWARE_TIMECOUNTER_FREQUENCY 1000000
306
312uint32_t GetTimecountCounter( void );
313
321uint32_t SetTimecountCounter( uint32_t counter );
322
335
353bool DeleteTimerServer( void );
354
355typedef struct {
356 struct {
357 const void *begin;
358 void *free_begin;
359 const void *end;
360 } areas[ 2 ];
361 size_t count;
363
364void MemorySave( MemoryContext *ctx );
365
366void MemoryRestore( const MemoryContext *ctx );
367
378void MemoryAllocationFailWhen( uint32_t counter );
379
380typedef struct {
381 Chain_Node node;
382 void ( *handler )( void * );
383 void *arg;
384 Atomic_Uint done;
386
387void CallWithinISR( void ( *handler )( void * ), void *arg );
388
389void CallWithinISRSubmit( CallWithinISRRequest *request );
390
391void CallWithinISRWait( const CallWithinISRRequest *request );
392
393void CallWithinISRRaise( void );
394
395void CallWithinISRClear( void );
396
397rtems_vector_number CallWithinISRGetVector( void );
398
399rtems_vector_number GetSoftwareInterruptVector( void );
400
401typedef struct {
403 const Thread_queue_Operations *wrapped_ops;
404 Thread_queue_Control thread_queue;
405 CallWithinISRRequest isr_request;
407
408void WrapThreadQueueInitialize(
410 void ( *handler )( void * ),
411 void *arg
412);
413
414void WrapThreadQueueExtract(
416 struct _Thread_Control *thread
417);
418
419void WrapThreadQueueExtractDirect(
421 Thread_Control *thread
422);
423
424void WrapThreadQueueDestroy( WrapThreadQueueContext *ctx );
425
426struct Per_CPU_Control;
427
428void SetPreemptionIntervention(
429 struct Per_CPU_Control *cpu,
430 void ( *handler )( void * ),
431 void *arg
432);
433
434rtems_vector_number GetValidInterruptVectorNumber(
435 const rtems_interrupt_attributes *required
436);
437
438rtems_vector_number GetTestableInterruptVector(
439 const rtems_interrupt_attributes *required
440);
441
442rtems_status_code RaiseSoftwareInterrupt( rtems_vector_number vector );
443
444rtems_status_code ClearSoftwareInterrupt( rtems_vector_number vector );
445
446bool HasInterruptVectorEntriesInstalled( rtems_vector_number vector );
447
466
471typedef struct {
486
496 rtems_id id,
498);
499
503typedef enum {
504 TIMER_INVALID,
505 TIMER_INACTIVE,
506 TIMER_SCHEDULED,
507 TIMER_PENDING
509
522
530void UnsetClock( void );
531
532void FatalInitialExtension(
533 rtems_fatal_source source,
534 bool always_set_to_false,
536);
537
538typedef void ( *FatalHandler )(
539 rtems_fatal_source source,
541 void *arg
542);
543
544void SetFatalHandler( FatalHandler fatal, void *arg );
545
546void SetTaskSwitchExtension( rtems_task_switch_extension task_switch );
547
548typedef struct {
549 uint32_t fatal;
550 uint32_t thread_begin;
551 uint32_t thread_create;
552 uint32_t thread_delete;
553 uint32_t thread_exitted;
554 uint32_t thread_restart;
555 uint32_t thread_start;
556 uint32_t thread_switch;
557 uint32_t thread_terminate;
559
560void ClearExtensionCalls( ExtensionCalls *calls );
561
562void CopyExtensionCalls( const ExtensionCalls *from, ExtensionCalls *to );
563
564void SetIORelaxHandler( void ( *handler )( void * ), void *arg );
565
566void StartDelayThreadDispatch( uint32_t cpu_index );
567
568void StopDelayThreadDispatch( uint32_t cpu_index );
569
570bool AreInterruptsEnabled( void );
571
572bool IsWhiteSpaceOnly( const char *s );
573
574bool IsEqualIgnoreWhiteSpace( const char *a, const char *b );
575
576#if defined(RTEMS_SMP)
577bool TicketLockIsAvailable( const SMP_ticket_lock_Control *lock );
578
579void TicketLockWaitForOwned( const SMP_ticket_lock_Control *lock );
580
581void TicketLockWaitForOthers(
582 const SMP_ticket_lock_Control *lock,
583 unsigned int others
584);
585
586typedef struct {
587 const SMP_ticket_lock_Control *lock;
588 unsigned int next_ticket;
589} TicketLockState;
590
591void TicketLockGetState(
592 const SMP_ticket_lock_Control *lock,
593 TicketLockState *state
594);
595
596void TicketLockWaitForAcquires(
597 const TicketLockState *state,
598 unsigned int acquire_count
599);
600
601void TicketLockWaitForReleases(
602 const TicketLockState *state,
603 unsigned int release_count
604);
605
606static inline bool ISRLockIsAvailable( const ISR_lock_Control *lock )
607{
608 return TicketLockIsAvailable( &lock->Lock.Ticket_lock );
609}
610
611static inline void ISRLockWaitForOwned( const ISR_lock_Control *lock )
612{
613 TicketLockWaitForOwned( &lock->Lock.Ticket_lock );
614}
615
616static inline void ISRLockWaitForOthers(
617 const ISR_lock_Control *lock,
618 unsigned int others
619)
620{
621 TicketLockWaitForOthers( &lock->Lock.Ticket_lock, others );
622}
623#endif
624
625void *IdleBody( uintptr_t ignored );
626
635
638#ifdef __cplusplus
639}
640#endif
641
642#endif /* _TX_SUPPORT_H */
uint32_t rtems_event_set
This integer type represents a bit field which can hold exactly 32 individual events.
Definition: event.h:436
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
uint32_t rtems_mode
This type represents a Classic API task mode set.
Definition: modes.h:174
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
rtems_task(* rtems_task_entry)(rtems_task_argument)
This type defines the task entry point of an RTEMS task.
Definition: tasks.h:239
rtems_timer_service_routine(* rtems_timer_service_routine_entry)(rtems_id, void *)
This type defines the prototype of routines which can be fired by directives of the Timer Manager.
Definition: timer.h:259
Timer_Classes
The timer class indicates how the timer was most recently fired.
Definition: timer.h:114
uint32_t rtems_name
This type represents Classic API object names.
Definition: types.h:226
uint32_t rtems_task_priority
This integer type represents task priorities of the Classic API.
Definition: types.h:257
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Watchdog_Interval rtems_interval
This type represents clock tick intervals.
Definition: types.h:114
User_extensions_thread_switch_extension rtems_task_switch_extension
Task switch extensions are invoked when a thread switch from an executing thread to a heir thread tak...
Definition: extension.h:608
Internal_errors_t rtems_fatal_code
This integer type represents system termination codes.
Definition: extension.h:162
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:63
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdogticks.h:59
Timer_States GetTimerState(rtems_id id)
Get the state of a timer from RTEMS internal data.
Definition: tx-timer-server.c:114
bool DeleteTimerServer(void)
Undo the effects of rtems_timer_initiate_server()
Definition: tx-timer-server.c:54
Timer_States
The various states of a timer.
Definition: tx-support.h:503
uint32_t GetTimecountCounter(void)
Gets the software timecount counter value.
Definition: tx-timecounter.c:67
void GetTimerSchedulingData(rtems_id id, Timer_Scheduling_Data *data)
Get data related to scheduling a timer service routine from RTEMS internal structures.
Definition: tx-timer-server.c:90
void MemoryAllocationFailWhen(uint32_t counter)
Fails a dynamic memory allocation when the counter reaches zero.
Definition: tx-memory-alloc.c:49
void TimecounterTick(void)
Simulates a single clock tick using the software timecounter.
Definition: tx-timecounter.c:126
const rtems_task_config DefaultTaskConfig
This task configurations may be used to construct a task during tests.
Definition: tx-default-task-config.c:53
uint32_t SetTimecountCounter(uint32_t counter)
Sets and gets the software timecount counter value.
Definition: tx-timecounter.c:75
Timer_Classes GetTimerClass(rtems_id id)
Get the clock and context of a timer from RTEMS internal data.
Definition: tx-timer-server.c:72
void FinalClockTick(void)
Simulates a clock tick with the final expire time point of UINT64_MAX for all clocks.
Definition: tx-support.c:796
void UnsetClock(void)
Mark the realtime clock as never set.
Definition: tx-timer-server.c:147
rtems_id GetTimerServerTaskId(void)
Return the task id of the timer server task.
Definition: tx-timer-server.c:46
GetTimecountHandler SetGetTimecountHandler(GetTimecountHandler handler)
Sets the get timecount handler.
Definition: tx-timecounter.c:58
This header file provides the interfaces of the Atomic Operations.
This header file is provided for backward compatiblility.
This header file defines the RTEMS Classic API.
Definition: tx-support.h:380
This structure represents a chain node.
Definition: chain.h:78
Definition: tx-support.h:548
Definition: tx-support.h:355
Per CPU Core Structure.
Definition: percpu.h:384
Definition: tx-support.h:257
Definition: threadq.h:609
The thread queue operations are used to manage the threads of a thread queue.
Definition: threadq.h:554
Definition: threadq.h:427
This structure provides data used by RTEMS to schedule a timer service routine.
Definition: tx-support.h:471
void * user_data
This member contains a reference to the user data to be provided to the timer service routine.
Definition: tx-support.h:480
Watchdog_Interval interval
This member contains the timer interval in ticks or seconds.
Definition: tx-support.h:484
rtems_timer_service_routine_entry routine
This member contains a reference to the timer service routine.
Definition: tx-support.h:475
Definition: tx-support.h:401
Definition: thread.h:837
Definition: inftrees.h:24
Definition: mmu-config.c:53
This structure provides the attributes of an interrupt vector.
Definition: intr.h:2076
This structure defines the configuration of a task constructed by rtems_task_construct().
Definition: tasks.h:110
This header file provides interfaces of the Thread Queue Handler which are used by the implementation...