1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup rtems_bsd_rtems |
---|
5 | * |
---|
6 | * @brief TODO. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 2012. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * All rights reserved. |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions |
---|
16 | * are met: |
---|
17 | * 1. Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer in the |
---|
21 | * documentation and/or other materials provided with the distribution. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
33 | * SUCH DAMAGE. |
---|
34 | */ |
---|
35 | |
---|
36 | #include <string.h> |
---|
37 | #include <stdio.h> |
---|
38 | #include <rtems.h> |
---|
39 | #include <rtems/bsd/bsd.h> |
---|
40 | |
---|
41 | /* |
---|
42 | * Structure passed to task-start stub |
---|
43 | */ |
---|
44 | struct newtask { |
---|
45 | void (*entry)(void *); |
---|
46 | void *arg; |
---|
47 | }; |
---|
48 | |
---|
49 | /* |
---|
50 | * Task-start stub |
---|
51 | */ |
---|
52 | static void |
---|
53 | taskEntry (rtems_task_argument arg) |
---|
54 | { |
---|
55 | struct newtask t; |
---|
56 | |
---|
57 | /* |
---|
58 | * Pick up task information and free |
---|
59 | * the memory allocated to pass the |
---|
60 | * information to this task. |
---|
61 | */ |
---|
62 | t = *(struct newtask *)arg; |
---|
63 | free ((struct newtask *)arg); |
---|
64 | |
---|
65 | /* |
---|
66 | * XXX If we need a semaphore it should be added here |
---|
67 | */ |
---|
68 | |
---|
69 | /* |
---|
70 | * Enter the task |
---|
71 | */ |
---|
72 | (*t.entry)(t.arg); |
---|
73 | rtems_panic ("Network task returned!\n"); |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | * Start a network task |
---|
78 | */ |
---|
79 | rtems_id |
---|
80 | rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg) |
---|
81 | { |
---|
82 | struct newtask *t; |
---|
83 | char nm[4]; |
---|
84 | rtems_id tid; |
---|
85 | rtems_status_code sc; |
---|
86 | |
---|
87 | strncpy (nm, name, 4); |
---|
88 | sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]), |
---|
89 | rtems_bsd_get_task_priority(name), |
---|
90 | stacksize, |
---|
91 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
92 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
93 | &tid |
---|
94 | ); |
---|
95 | if (sc != RTEMS_SUCCESSFUL) |
---|
96 | rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc)); |
---|
97 | |
---|
98 | /* |
---|
99 | * Set up task arguments |
---|
100 | */ |
---|
101 | t = malloc (sizeof *t); |
---|
102 | t->entry = entry; |
---|
103 | t->arg = arg; |
---|
104 | |
---|
105 | /* |
---|
106 | * Start the task |
---|
107 | */ |
---|
108 | sc = rtems_task_start (tid, taskEntry, (rtems_task_argument)t); |
---|
109 | if (sc != RTEMS_SUCCESSFUL) |
---|
110 | rtems_panic ("Can't start network daemon `%s': `%s'\n", name, rtems_status_text (sc)); |
---|
111 | |
---|
112 | /* |
---|
113 | * Let our caller know the i.d. of the new task |
---|
114 | */ |
---|
115 | return tid; |
---|
116 | } |
---|