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
/*
 * 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 <vxworks/errnoLib.h>
#include "tickLib.h"
#include "taskLib.h"
 
/**
 * @defgroup vxworks VxWorks&reg; emulator
 *
 * A VxWorks&reg; emulation library on top of Xenomai.
 *
 * The emulator mimicks the behavior described in the public
 * documentation of the WIND 5.x API for the following class of
 * services:
 *
 * - taskLib, taskInfoLib, taskHookLib,
 * - semLib, msgQLib, wdLib, memPartLib
 * - intLib, tickLib, sysLib (partial)
 * - errnoLib, lstLib, kernelLib (partial)
 */
 
static unsigned int clock_resolution = 1000000; /* 1ms */
 
static const struct option vxworks_options[] = {
   {
#define clock_resolution_opt    0
       .name = "vxworks-clock-resolution",
       .has_arg = required_argument,
   },
   { /* Sentinel */ }
};
 
static int vxworks_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 vxworks_help(void)
{
        fprintf(stderr, "--vxworks-clock-resolution=<ns> tick value (default 1ms)\n");
}
 
static int vxworks_init(void)
{
   int ret;
 
   registry_add_dir("/vxworks");
   registry_add_dir("/vxworks/tasks");
   registry_add_dir("/vxworks/semaphores");
   registry_add_dir("/vxworks/queues");
   registry_add_dir("/vxworks/watchdogs");
 
   cluster_init(&wind_task_table, "vxworks.task");
 
   ret = clockobj_init(&wind_clock, clock_resolution);
   if (ret) {
       warning("%s: failed to initialize VxWorks clock (res=%u ns)",
           __FUNCTION__, clock_resolution);
       return __bt(ret);
   }
 
   __RT(pthread_mutex_init(&wind_task_lock, NULL));
 
   return 0;
}
 
static struct setup_descriptor vxworks_skin = {
   .name = "vxworks",
   .init = vxworks_init,
   .options = vxworks_options,
   .parse_option = vxworks_parse_option,
   .help = vxworks_help,
};
 
interface_setup_call(vxworks_skin);