RTEMS 6.1-rc6
Loading...
Searching...
No Matches
bestcomm.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2010, 2013 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef GEN5200_BESTCOMM_H
29#define GEN5200_BESTCOMM_H
30
31#include "bestcomm_ops.h"
32
33#include <assert.h>
34
35#include <rtems.h>
36
37#include <bsp/mpc5200.h>
39#include <bsp/bestcomm/bestcomm_glue.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
55typedef struct {
56 uint32_t *tdt_begin;
57 uint32_t *tdt_last;
58 volatile uint32_t (*var_table)[32];
59 uint32_t fdt_and_pragmas;
60 uint32_t reserved_0;
61 uint32_t reserved_1;
62 uint32_t *context_begin;
63 uint32_t reserved_2;
65
66#define BESTCOMM_TASK_ENTRY_TABLE ((volatile bestcomm_task_entry *) 0xf0008000)
67
68#define BESTCOMM_IRQ_EVENT RTEMS_EVENT_13
69
70typedef struct {
71 int task_index;
72 rtems_id event_task_id;
74
75void bestcomm_irq_create(bestcomm_irq *self, int task_index);
76
77void bestcomm_irq_destroy(const bestcomm_irq *self);
78
79static inline void bestcomm_irq_enable(const bestcomm_irq *self)
80{
81 bestcomm_glue_irq_enable(self->task_index);
82}
83
84static inline void bestcomm_irq_disable(const bestcomm_irq *self)
85{
86 bestcomm_glue_irq_disable(self->task_index);
87}
88
89static inline void bestcomm_irq_clear(const bestcomm_irq *self)
90{
91 SDMA_CLEAR_IEVENT(&mpc5200.sdma.IntPend, self->task_index);
92}
93
94static inline int bestcomm_irq_get_task_index(const bestcomm_irq *self)
95{
96 return self->task_index;
97}
98
99static inline rtems_id bestcomm_irq_get_event_task_id(const bestcomm_irq *self)
100{
101 return self->event_task_id;
102}
103
104static inline void bestcomm_irq_set_event_task_id(bestcomm_irq *self, rtems_id id)
105{
106 self->event_task_id = id;
107}
108
109static inline void bestcomm_irq_wakeup_event_task(const bestcomm_irq *self)
110{
111 rtems_status_code sc = rtems_event_send(self->event_task_id, BESTCOMM_IRQ_EVENT);
112 assert(sc == RTEMS_SUCCESSFUL);
113 (void) sc;
114}
115
116static inline void bestcomm_irq_wait(const bestcomm_irq *self)
117{
118 rtems_event_set events;
120 BESTCOMM_IRQ_EVENT,
123 &events
124 );
125 assert(sc == RTEMS_SUCCESSFUL);
126 assert(events == BESTCOMM_IRQ_EVENT);
127 (void) sc;
128}
129
130static inline bool bestcomm_irq_peek(const bestcomm_irq *self)
131{
132 rtems_event_set events;
133 rtems_status_code sc = rtems_event_receive(0, 0, 0, &events);
134 assert(sc == RTEMS_SUCCESSFUL);
135 (void) sc;
136
137 return (events & BESTCOMM_IRQ_EVENT) != 0;
138}
139
140typedef struct {
141 volatile uint16_t *task_control_register;
142
143 volatile uint32_t (*variable_table)[32];
144
145 TaskId task_index;
146
147 bestcomm_irq irq;
148
149 uint32_t *tdt_begin;
150
151 size_t tdt_opcode_count;
153
154void bestcomm_task_create(bestcomm_task *self, TaskId task_index);
155
156void bestcomm_task_create_and_load(
157 bestcomm_task *self,
158 TaskId task_index,
159 const uint32_t *tdt_source_begin,
160 size_t tdt_size
161);
162
163void bestcomm_task_destroy(bestcomm_task *self);
164
165void bestcomm_task_load(bestcomm_task *self, const uint32_t *tdt_source_begin, size_t tdt_size);
166
167static inline void bestcomm_task_set_priority(bestcomm_task *self, int priority)
168{
169 /* Allow higher priority initiator to block current initiator */
170 mpc5200.sdma.ipr[self->task_index] = SDMA_IPR_PRIOR(priority);
171}
172
173static inline void bestcomm_task_irq_enable(const bestcomm_task *self)
174{
175 bestcomm_irq_enable(&self->irq);
176}
177
178static inline void bestcomm_task_irq_disable(const bestcomm_task *self)
179{
180 bestcomm_irq_disable(&self->irq);
181}
182
183static inline void bestcomm_task_irq_clear(const bestcomm_task *self)
184{
185 bestcomm_irq_clear(&self->irq);
186}
187
188static inline rtems_id bestcomm_task_get_event_task_id(const bestcomm_task *self)
189{
190 return bestcomm_irq_get_event_task_id(&self->irq);
191}
192
193static inline void bestcomm_task_set_event_task_id(bestcomm_task *self, rtems_id id)
194{
195 bestcomm_irq_set_event_task_id(&self->irq, id);
196}
197
198static inline void bestcomm_task_associate_with_current_task(bestcomm_task *self)
199{
200 bestcomm_task_set_event_task_id(self, rtems_task_self());
201}
202
203static inline void bestcomm_task_start(const bestcomm_task *self)
204{
205 *self->task_control_register = SDMA_TCR_EN | SDMA_TCR_HIGH_EN;
206}
207
208static inline void bestcomm_task_start_with_autostart(const bestcomm_task *self)
209{
210 *self->task_control_register = (uint16_t)
211 (SDMA_TCR_EN | SDMA_TCR_HIGH_EN | SDMA_TCR_AUTO_START | SDMA_TCR_AS(self->task_index));
212}
213
214static inline void bestcomm_task_stop(const bestcomm_task *self)
215{
216 *self->task_control_register = 0;
217}
218
219static inline void bestcomm_task_wakeup_event_task(const bestcomm_task *self)
220{
221 bestcomm_irq_wakeup_event_task(&self->irq);
222}
223
224static inline void bestcomm_task_wait(const bestcomm_task *self)
225{
226 bestcomm_irq_wait(&self->irq);
227}
228
229static inline bool bestcomm_task_peek(const bestcomm_task *self)
230{
231 return bestcomm_irq_peek(&self->irq);
232}
233
234static inline bool bestcomm_task_is_running(const bestcomm_task *self)
235{
236 return (*self->task_control_register & SDMA_TCR_EN) != 0;
237}
238
239static inline uint32_t bestcomm_get_task_variable(const bestcomm_task *self, size_t index)
240{
241 assert(index < VAR_COUNT);
242 return (*self->variable_table)[index];
243}
244
245static inline volatile uint32_t *bestcomm_task_get_address_of_variable(const bestcomm_task *self, size_t index)
246{
247 assert(index < VAR_COUNT);
248 return &(*self->variable_table)[index];
249}
250
251static inline void bestcomm_task_set_variable(const bestcomm_task *self, size_t index, uint32_t value)
252{
253 assert(index < VAR_COUNT);
254 (*self->variable_table)[index] = value;
255}
256
257static inline uint32_t bestcomm_task_get_increment_and_condition(const bestcomm_task *self, size_t index)
258{
259 assert(index < INC_COUNT);
260 return (*self->variable_table)[INC(index)];
261}
262
263static inline void bestcomm_task_set_increment_and_condition_32(
264 const bestcomm_task *self,
265 size_t index,
266 uint32_t inc_and_cond
267)
268{
269 assert(index < INC_COUNT);
270 (*self->variable_table)[INC(index)] = inc_and_cond;
271}
272
273static inline void bestcomm_task_set_increment_and_condition(
274 const bestcomm_task *self,
275 size_t index,
276 int16_t inc,
277 int cond
278)
279{
280 bestcomm_task_set_increment_and_condition_32(self, index, INC_INIT(cond, inc));
281}
282
283static inline void bestcomm_task_set_increment(const bestcomm_task *self, size_t index, int16_t inc)
284{
285 bestcomm_task_set_increment_and_condition_32(self, index, INC_INIT(0, inc));
286}
287
288void bestcomm_task_clear_variables(const bestcomm_task *self);
289
290static inline uint32_t bestcomm_task_get_opcode(const bestcomm_task *self, size_t index)
291{
292 assert(index < self->tdt_opcode_count);
293 return self->tdt_begin[index];
294}
295
296static inline void bestcomm_task_set_opcode(bestcomm_task *self, size_t index, uint32_t opcode)
297{
298 assert(index < self->tdt_opcode_count);
299 self->tdt_begin[index] = opcode;
300}
301
302static inline void bestcomm_task_set_initiator(const bestcomm_task *self, int initiator)
303{
306 *self->task_control_register = BSP_BFLD16SET(*self->task_control_register, initiator, 3, 7);
308}
309
310static inline volatile bestcomm_task_entry *bestcomm_task_get_task_entry(const bestcomm_task *self)
311{
312 return &BESTCOMM_TASK_ENTRY_TABLE[self->task_index];
313}
314
315static inline void bestcomm_task_set_pragma(const bestcomm_task *self, int bit_pos, bool enable)
316{
317 volatile bestcomm_task_entry *entry = bestcomm_task_get_task_entry(self);
318 uint32_t mask = BSP_BIT32(bit_pos);
319 uint32_t bit = enable ? mask : 0;
320 entry->fdt_and_pragmas = (entry->fdt_and_pragmas & ~mask) | bit;
321}
322
323static inline void bestcomm_task_enable_precise_increment(const bestcomm_task *self, bool enable)
324{
325 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_PRECISE_INC, enable);
326}
327
328static inline void bestcomm_task_enable_error_reset(const bestcomm_task *self, bool enable)
329{
330 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_RST_ERROR_NO, !enable);
331}
332
333static inline void bestcomm_task_enable_pack_data(const bestcomm_task *self, bool enable)
334{
335 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_PACK, enable);
336}
337
338static inline void bestcomm_task_enable_integer_mode(const bestcomm_task *self, bool enable)
339{
340 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_INTEGER, enable);
341}
342
343static inline void bestcomm_task_enable_speculative_read(const bestcomm_task *self, bool enable)
344{
345 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_SPECREAD, enable);
346}
347
348static inline void bestcomm_task_enable_combined_write(const bestcomm_task *self, bool enable)
349{
350 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_CW, enable);
351}
352
353static inline void bestcomm_task_enable_read_buffer(const bestcomm_task *self, bool enable)
354{
355 bestcomm_task_set_pragma(self, SDMA_PRAGMA_BIT_RL, enable);
356}
357
358static inline volatile uint16_t *bestcomm_task_get_task_control_register(const bestcomm_task *self)
359{
360 return self->task_control_register;
361}
362
363static inline int bestcomm_task_get_task_index(const bestcomm_task *self)
364{
365 return self->task_index;
366}
367
368static inline void bestcomm_task_free_tdt(bestcomm_task *self)
369{
370 bestcomm_free(self->tdt_begin);
371 self->tdt_begin = NULL;
372}
373
374static inline void bestcomm_task_clear_pragmas(const bestcomm_task *self)
375{
376 volatile bestcomm_task_entry *entry = bestcomm_task_get_task_entry(self);
377 entry->fdt_and_pragmas &= ~0xffU;
378}
379
382#ifdef __cplusplus
383}
384#endif /* __cplusplus */
385
386#endif /* GEN5200_BESTCOMM_H */
This header file provides the interfaces of the Assert Handler.
rtems_status_code rtems_event_send(rtems_id id, rtems_event_set event_in)
Sends the event set to the task.
Definition: eventsend.c:46
rtems_status_code rtems_event_receive(rtems_event_set event_in, rtems_option option_set, rtems_interval ticks, rtems_event_set *event_out)
Receives or gets an event set from the calling task.
Definition: eventreceive.c:47
uint32_t rtems_event_set
This integer type represents a bit field which can hold exactly 32 individual events.
Definition: event.h:436
ISR_Level rtems_interrupt_level
This integer type represents interrupt levels.
Definition: intr.h:111
#define rtems_interrupt_enable(_isr_cookie)
Restores the previous interrupt level on the current processor.
Definition: intr.h:311
#define rtems_interrupt_disable(_isr_cookie)
Disables the maskable interrupts on the current processor.
Definition: intr.h:264
#define RTEMS_WAIT
This option constant indicates that the task wants to wait on the resource.
Definition: options.h:139
#define RTEMS_EVENT_ALL
This option constant indicates that the task wishes to wait until all events of interest are availabl...
Definition: options.h:93
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
@ RTEMS_SUCCESSFUL
This status code indicates successful completion of a requested operation.
Definition: status.h:90
rtems_id rtems_task_self(void)
Gets the task identifier of the calling task.
#define RTEMS_NO_TIMEOUT
This clock tick interval constant indicates that the calling task is willing to wait potentially fore...
Definition: types.h:236
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
This header file defines the RTEMS Classic API.
Definition: bestcomm.h:70
Definition: bestcomm.h:55
Definition: bestcomm.h:140
Definition: mmu-config.c:53