hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
 
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <xenomai/init.h>
#include "timer.h"
#include "task.h"
#include "sem.h"
#include "event.h"
#include "cond.h"
#include "mutex.h"
#include "queue.h"
#include "buffer.h"
#include "heap.h"
#include "alarm.h"
#include "pipe.h"
 
/**
 * @defgroup alchemy Alchemy API
 *
 * A programming interface reminiscent from traditional RTOS APIs
 *
 * This interface is an evolution of the former @a native API
 * available with the Xenomai 2.x series.
 */
 
static unsigned int clock_resolution = 1; /* nanosecond. */
 
static const struct option alchemy_options[] = {
   {
#define clock_resolution_opt    0
       .name = "alchemy-clock-resolution",
       .has_arg = required_argument,
   },
   { /* Sentinel */ }
};
 
static int alchemy_parse_option(int optnum, const char *optarg)
{
   switch (optnum) {
   case clock_resolution_opt:
       clock_resolution = atoi(optarg);
       break;
   default:
       /* Paranoid, can't happen. */
       return -EINVAL;
   }
 
   return 0;
}
 
static void alchemy_help(void)
{
        fprintf(stderr, "--alchemy-clock-resolution=<ns> tick value (default 1ns, tickless)\n");
}
 
#ifdef CONFIG_XENO_COBALT
 
static inline void init_corespec(void)
{
   syncluster_init(&alchemy_pipe_table, "alchemy.pipe");
   registry_add_dir("/alchemy/pipes");
}
 
#else
 
static inline void init_corespec(void) { }
 
#endif
 
static int alchemy_init(void)
{
   int ret;
 
   syncluster_init(&alchemy_task_table, "alchemy.task");
   syncluster_init(&alchemy_sem_table, "alchemy.sem");
   syncluster_init(&alchemy_event_table, "alchemy.event");
   syncluster_init(&alchemy_cond_table, "alchemy.cond");
   syncluster_init(&alchemy_mutex_table, "alchemy.mutex");
   syncluster_init(&alchemy_queue_table, "alchemy.queue");
   syncluster_init(&alchemy_buffer_table, "alchemy.buffer");
   syncluster_init(&alchemy_heap_table, "alchemy.heap");
   pvcluster_init(&alchemy_alarm_table, "alchemy.alarm");
 
   ret = clockobj_init(&alchemy_clock, clock_resolution);
   if (ret) {
       warning("%s: failed to initialize Alchemy clock (res=%u ns)",
           __FUNCTION__, clock_resolution);
       return __bt(ret);
   }
 
   registry_add_dir("/alchemy");
   registry_add_dir("/alchemy/tasks");
   registry_add_dir("/alchemy/semaphores");
   registry_add_dir("/alchemy/events");
   registry_add_dir("/alchemy/condvars");
   registry_add_dir("/alchemy/mutexes");
   registry_add_dir("/alchemy/queues");
   registry_add_dir("/alchemy/buffers");
   registry_add_dir("/alchemy/heaps");
   registry_add_dir("/alchemy/alarms");
 
   init_corespec();
 
   return 0;
}
 
static struct setup_descriptor alchemy_skin = {
   .name = "alchemy",
   .init = alchemy_init,
   .options = alchemy_options,
   .parse_option = alchemy_parse_option,
   .help = alchemy_help,
};
 
interface_setup_call(alchemy_skin);