hirtos_1.0.0_e7372ec1/src/hirtos-thread.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--
--  Copyright (c) 2022-2023, German Rivera
--
--
--  SPDX-License-Identifier: Apache-2.0
--

with HiRTOS.Memory_Protection;
with System.Storage_Elements;

package HiRTOS.Thread
   with SPARK_Mode => On
is
   use type System.Storage_Elements.Integer_Address;

   --
   --  NOTE: Lower value means higher priority
   --
   Lowest_Thread_Prioritiy :
      constant Thread_Priority_Type := Thread_Priority_Type'Last;

   Highest_Thread_Prioritiy :
      constant Thread_Priority_Type := Thread_Priority_Type'First;

   type Thread_Entry_Point_Type is access procedure (Arg : System.Address)
          with Convention => C;

   --
   --  Create new thread
   --
   procedure Create_Thread (Entry_Point : Thread_Entry_Point_Type;
                            Thread_Arg : System.Address;
                            Priority : Valid_Thread_Priority_Type;
                            Stack_Base_Address : System.Address;
                            Stack_Size_In_Bytes :  System.Storage_Elements.Integer_Address;
                            Thread_Id : out Valid_Thread_Id_Type)
      with Pre => HiRTOS.Memory_Protection.Valid_Code_Address (Entry_Point.all'Address) and then
                  HiRTOS.Memory_Protection.Valid_Stack_Address (Stack_Base_Address) and then
                  Stack_Size_In_Bytes /= 0 and then
                  Stack_Size_In_Bytes mod
                     (HiRTOS_Cpu_Arch_Interface.Cpu_Register_Type'Size / System.Storage_Unit) = 0,
           Export,
           Convention => C,
           External_Name => "hirtos_create_thread";

   --
   --  Return the Id of the current thread executing on the current CPU core,
   --  if that core is running in thread context, or the Id of the last thread
   --  prempted by an interrupt handler, if running in interrupt context.
   --
   function Get_Current_Thread_Id return Thread_Id_Type
      with Export,
           Convention => C,
           External_Name => "hirtos_get_current_thread_id";

   --
   --  Return the priority of the current thread executing on the current CPU core,
   --  if that core is running in thread context, or the priority of the last thread
   --  prempted by an interrupt handler, if running in interrupt context.
   --
   function Get_Current_Thread_Priority return Thread_Priority_Type
      with Export,
           Convention => C,
           External_Name => "hirtos_get_current_thread_priority";

   --
   --  Put the calling thread to sleep until the current time matches
   --  the specified wakeup time.
   --
   function Thread_Delay_Until (Wakeup_Time_Us : Absolute_Time_Us_Type) return Absolute_Time_Us_Type
      with Pre => Wakeup_Time_Us mod HiRTOS_Config_Parameters.Tick_Timer_Period_Us = 0,
           Export,
           Convention => C,
           External_Name => "hirtos_thread_delay_until";

   --
   --  Suspend Calling Thread
   --
   procedure Suspend_Current_Thread
      with Export,
           Convention => C,
           External_Name => "hirtos_suspend_current_thread";

   --
   --  Resume a suspended Thread
   --
   procedure Resume_Thread (Suspended_Thread_Id : Valid_Thread_Id_Type)
      with Export,
           Convention => C,
           External_Name => "hirtos_resume_thread";

end HiRTOS.Thread;