4 #include "appsupport.h"
5 #include "rtems_process_wrapper.h"
6 #include "traffic_shaping.h"
8 unsigned int sink_processes;
9 void sink_end_process(rtems_task_argument argument);
10 void queue_status_process(rtems_task_argument argument);
11 void shaping_process(rtems_task_argument argument);
12 rtems_task shaping_init(rtems_task_argument argument) {
14 rtems_status_code status;
15 QUEUE_WRAPPER *queue_wrap, *sink_wrap;
19 // instatiate daemons for data transfer notices
20 queue_wrap = (QUEUE_WRAPPER *)malloc(NUMBER_OF_QUEUES *
21 sizeof(QUEUE_WRAPPER));
22 for (i=0; i < NUMBER_OF_QUEUES; i++) {
23 queue_wrap[i].q = scratch_queue_autoinit_shaper(i+1, 0, 0, 0);
24 queue_wrap[i].hasData = 0;
27 for (i=0; i< NUMBER_OF_QUEUES; i++) {
28 name = rtems_build_name('q', 's', i+1, 'c');
29 status = rtems_task_create(name,
31 RTEMS_MINIMUM_STACK_SIZE,
35 if (status != RTEMS_SUCCESSFUL) {
36 printf("[init ] Create queue process failed (status %d).\n",
38 rtems_shutdown_executive(0);
40 status = rtems_task_start(task_id, queue_status_process,
41 (rtems_task_argument)&queue_wrap[i]);
42 if (status != RTEMS_SUCCESSFUL) {
43 printf("[init ] Start queue process failed (status %d).\n",
45 rtems_shutdown_executive(0);
49 // instatiate daemons to wait for sinks finishing
50 sink_processes = NUMBER_OF_SINKS;
51 sink_wrap = (QUEUE_WRAPPER *)malloc(NUMBER_OF_SINKS *
52 sizeof(QUEUE_WRAPPER));
53 for (i=0; i<NUMBER_OF_SINKS; i++) {
54 sink_wrap[i].sem_terminate = get_sem_terminate(i+1);
56 for (i=0; i<NUMBER_OF_SINKS; i++) {
57 name = rtems_build_name('s', 't', i+1, 'c');
58 status = rtems_task_create(name,
60 RTEMS_MINIMUM_STACK_SIZE,
64 if (status != RTEMS_SUCCESSFUL) {
65 printf("[init ] Create sink process failed (status %d).\n",
67 rtems_shutdown_executive(0);
69 status = rtems_task_start(task_id, sink_end_process,
70 (rtems_task_argument)&sink_wrap[i]);
71 if (status != RTEMS_SUCCESSFUL) {
72 printf("[init ] Start sink process failed (status %d).\n",
74 rtems_shutdown_executive(0);
79 // intatiate daemon for data transfer
80 name = rtems_build_name('t', 's', NUMBER_OF_QUEUES, 'c');
81 status = rtems_task_create(name,
83 RTEMS_MINIMUM_STACK_SIZE,
87 if (status != RTEMS_SUCCESSFUL) {
88 printf("[init ] Create shaping process failed (status %d).\n",
90 rtems_shutdown_executive(0);
92 status = rtems_task_start(task_id, shaping_process,
93 (rtems_task_argument)queue_wrap);
94 if (status != RTEMS_SUCCESSFUL) {
95 printf("[init ] Start shaping process failed (status %d).\n",
97 rtems_shutdown_executive(0);
100 rtems_task_delete(RTEMS_SELF);
104 void queue_status_process(rtems_task_argument argument)
106 QUEUE_WRAPPER *wrap = (QUEUE_WRAPPER *) argument;
107 SCRATCH_QUEUE_SHAPER *queue = wrap->q;
109 /* printf("queue:%x, traffice_shaping: "
110 "\n\t sem_shaper_used:%x, "
111 "\n\t sem_shaper_left:%x, "
112 "\n\t semaphore_left:%x, "
113 "\n\t semaphore_used:%x",
115 queue->sem_shaper_used,
116 queue->sem_shaper_left,
117 queue->semaphore_left,
118 queue->semaphore_used
122 // always USEINTERRUPT
123 ss_sem_wait(queue->sem_shaper_used);
124 ss_sem_wait(queue->sem_shaper_left);
130 void sink_end_process(rtems_task_argument argument)
132 QUEUE_WRAPPER *queue_wrap = (QUEUE_WRAPPER *) argument;
134 // wait for terminating signal from sink
135 ss_sem_wait(queue_wrap->sem_terminate);
138 if (sink_processes == 0) {
139 SHOW_DEBUG("END!!!");
144 static int cur_queue; // current queue
145 QUEUE_WRAPPER * get_next_queue(QUEUE_WRAPPER * queue_wrap);
146 int canSend(QUEUE_WRAPPER * queue);
147 void shaping_process(rtems_task_argument argument)
149 QUEUE_WRAPPER *queue_wrap = (QUEUE_WRAPPER *) argument;
154 q_w = get_next_queue(queue_wrap);
158 scratch_queue_shaperRW(q_w->q);
168 QUEUE_WRAPPER * get_next_queue(QUEUE_WRAPPER * queue_wrap)
172 cur_queue = (cur_queue == 0) ? NUMBER_OF_QUEUES : cur_queue;
176 cur_queue = (cur_queue == NUMBER_OF_QUEUES) ? 0 : cur_queue;
178 return &queue_wrap[cur_queue];
183 int canSend(QUEUE_WRAPPER * queue)