1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Scheduler CBS Create Server |
---|
5 | * @ingroup ScoreScheduler |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (C) 2011 Petr Benes. |
---|
10 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/config.h> |
---|
23 | #include <rtems/score/scheduler.h> |
---|
24 | #include <rtems/score/schedulercbs.h> |
---|
25 | |
---|
26 | int _Scheduler_CBS_Create_server ( |
---|
27 | Scheduler_CBS_Parameters *params, |
---|
28 | Scheduler_CBS_Budget_overrun budget_overrun_callback, |
---|
29 | rtems_id *server_id |
---|
30 | ) |
---|
31 | { |
---|
32 | unsigned int i; |
---|
33 | Scheduler_CBS_Server *the_server; |
---|
34 | |
---|
35 | if ( params->budget <= 0 || |
---|
36 | params->deadline <= 0 || |
---|
37 | params->budget >= SCHEDULER_EDF_PRIO_MSB || |
---|
38 | params->deadline >= SCHEDULER_EDF_PRIO_MSB ) |
---|
39 | return SCHEDULER_CBS_ERROR_INVALID_PARAMETER; |
---|
40 | |
---|
41 | for ( i = 0; i<_Scheduler_CBS_Maximum_servers; i++ ) { |
---|
42 | if ( !_Scheduler_CBS_Server_list[i] ) |
---|
43 | break; |
---|
44 | } |
---|
45 | |
---|
46 | if ( i == _Scheduler_CBS_Maximum_servers ) |
---|
47 | return SCHEDULER_CBS_ERROR_FULL; |
---|
48 | |
---|
49 | *server_id = i; |
---|
50 | _Scheduler_CBS_Server_list[*server_id] = (Scheduler_CBS_Server *) |
---|
51 | _Workspace_Allocate( sizeof(Scheduler_CBS_Server) ); |
---|
52 | the_server = _Scheduler_CBS_Server_list[*server_id]; |
---|
53 | if ( !the_server ) |
---|
54 | return SCHEDULER_CBS_ERROR_NO_MEMORY; |
---|
55 | |
---|
56 | the_server->parameters = *params; |
---|
57 | the_server->task_id = -1; |
---|
58 | the_server->cbs_budget_overrun = budget_overrun_callback; |
---|
59 | return SCHEDULER_CBS_OK; |
---|
60 | } |
---|