source: rtems/bsps/powerpc/gen5200/bestcomm/bestcomm_glue.c @ 3fb2a815

Last change on this file since 3fb2a815 was 3fb2a815, checked in by Christian Mauderer <christian.mauderer@…>, on 03/03/22 at 08:17:22

bsps/powerpc/gen5200: Manual file header clean up

Updates #4625.

  • Property mode set to 100644
File size: 9.6 KB
Line 
1/*
2 * RTEMS generic MPC5200 BSP
3 *
4 * This file contains glue functions to the Freescale BestComm API.
5 */
6
7/*
8 * Copyright (c) 2004-2005 embedded brains GmbH. All rights reserved.
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <assert.h>
16#include <rtems.h>
17#include <bsp.h>
18#include <bsp/irq.h>
19#include <bsp/mpc5200.h>
20#include <bsp/bestcomm/include/ppctypes.h> /* uint32, et. al.              */
21#include <bsp/bestcomm/dma_image.h>
22#include <bsp/bestcomm/task_api/bestcomm_cntrl.h>
23#include <bsp/bestcomm/bestcomm_api.h>
24#include <bsp/bestcomm/bestcomm_glue.h>
25#include <bsp/bestcomm/include/mgt5200/sdma.h>
26#include <rtems/score/heapimpl.h>
27
28extern const uint32 taskTableBytes;
29
30static Heap_Control bestcomm_heap;
31
32/*=========================================================================*\
33| Function:                                                                 |
34\*-------------------------------------------------------------------------*/
35void bestcomm_glue_irq_enable
36(
37/*-------------------------------------------------------------------------*\
38| Purpose:                                                                  |
39|   enable interrupt for given task number                                  |
40+---------------------------------------------------------------------------+
41| Input Parameters:                                                         |
42\*-------------------------------------------------------------------------*/
43 int bestcomm_taskno                           /* task number to enable    */
44)
45/*-------------------------------------------------------------------------*\
46| Return Value:                                                             |
47|    none                                                                   |
48\*=========================================================================*/
49{
50  if (0 != ((1UL<<bestcomm_taskno) & SDMA_INT_BIT_IMPL)) {
51    /*
52     * valid task number
53     * enable interrupt in bestcomm mask
54     */
55    SDMA_INT_ENABLE(&mpc5200.sdma.IntMask,bestcomm_taskno);
56  }
57}
58
59/*=========================================================================*\
60| Function:                                                                 |
61\*-------------------------------------------------------------------------*/
62void bestcomm_glue_irq_disable
63(
64/*-------------------------------------------------------------------------*\
65| Purpose:                                                                  |
66|   disable interrupt for given task number                                 |
67+---------------------------------------------------------------------------+
68| Input Parameters:                                                         |
69\*-------------------------------------------------------------------------*/
70 int bestcomm_taskno                           /* task number to disable   */
71)
72/*-------------------------------------------------------------------------*\
73| Return Value:                                                             |
74|    none                                                                   |
75\*=========================================================================*/
76{
77  if (0 != ((1UL<<bestcomm_taskno) & SDMA_INT_BIT_IMPL)) {
78    /*
79     * valid task number
80     * disable interrupt in bestcomm mask
81     */
82    SDMA_INT_DISABLE(&mpc5200.sdma.IntMask,bestcomm_taskno);
83  }
84}
85
86typedef struct {
87  rtems_interrupt_handler handler;
88  void *arg;
89} bestcomm_glue_irq_handlers_t;
90
91static bestcomm_glue_irq_handlers_t bestcomm_glue_irq_handlers[32];
92
93/*=========================================================================*\
94| Function:                                                                 |
95\*-------------------------------------------------------------------------*/
96void bestcomm_glue_irq_install
97(
98/*-------------------------------------------------------------------------*\
99| Purpose:                                                                  |
100|   install given function as bestcomm interrupt handler                    |
101+---------------------------------------------------------------------------+
102| Input Parameters:                                                         |
103\*-------------------------------------------------------------------------*/
104 int bestcomm_taskno,                          /* task number for handler  */
105 rtems_interrupt_handler handler,              /* function to call         */
106 void *arg
107)
108/*-------------------------------------------------------------------------*\
109| Return Value:                                                             |
110|    none                                                                   |
111\*=========================================================================*/
112{
113  if (0 != ((1UL<<bestcomm_taskno) & SDMA_INT_BIT_IMPL)) {
114    /*
115     * valid task number
116     * install handler
117     */
118    bestcomm_glue_irq_handlers[bestcomm_taskno].handler = handler;
119    bestcomm_glue_irq_handlers[bestcomm_taskno].arg = arg;
120  }
121}
122
123/*=========================================================================*\
124| Function:                                                                 |
125\*-------------------------------------------------------------------------*/
126static void bestcomm_glue_irq_dispatcher
127(
128/*-------------------------------------------------------------------------*\
129| Purpose:                                                                  |
130|   general bestcomm interrupt handler/dispatcher                           |
131+---------------------------------------------------------------------------+
132| Input Parameters:                                                         |
133\*-------------------------------------------------------------------------*/
134 void *arg                               /* irq specific handle (not used) */
135)
136/*-------------------------------------------------------------------------*\
137| Return Value:                                                             |
138|    none                                                                   |
139\*=========================================================================*/
140{
141  uint32_t pending;
142  int curr_taskno;
143
144  pending = mpc5200.sdma.IntPend & ~mpc5200.sdma.IntMask;
145  curr_taskno = 0;
146  while (pending != 0) {
147    if ((pending & (1UL<<curr_taskno)) != 0) {
148      if (bestcomm_glue_irq_handlers[curr_taskno].handler != NULL) {
149        /*
150         * call proper handler
151         */
152        bestcomm_glue_irq_handlers[curr_taskno].handler
153          (bestcomm_glue_irq_handlers[curr_taskno].arg);
154      }
155      else {
156        /*
157         * This should never happen. we have a pending IRQ but no handler
158         * let's clear this pending bit
159         */
160        SDMA_CLEAR_IEVENT(&mpc5200.sdma.IntPend,curr_taskno);
161      }
162      /*
163       * clear this bit in our pending copy
164       * and go to next bit
165       */
166      pending &= ~(1<<curr_taskno);
167    }
168    curr_taskno++;
169  }
170}
171
172static bool bestcomm_glue_is_initialized = false;
173/*=========================================================================*\
174| Function:                                                                 |
175\*-------------------------------------------------------------------------*/
176void bestcomm_glue_init
177(
178/*-------------------------------------------------------------------------*\
179| Purpose:                                                                  |
180|   initialize the bestcomm module (if not yet done):                       |
181|   - load code                                                             |
182|   - initialize registers                                                  |
183|   - initialize bus arbiter                                                |
184|   - initialize interrupt control                                          |
185+---------------------------------------------------------------------------+
186| Input Parameters:                                                         |
187\*-------------------------------------------------------------------------*/
188 void /* none */
189)
190/*-------------------------------------------------------------------------*\
191| Return Value:                                                             |
192|    none                                                                   |
193\*=========================================================================*/
194{
195  rtems_status_code sc = RTEMS_SUCCESSFUL;
196  uintptr_t heap_status = 0;
197
198  if (!bestcomm_glue_is_initialized) {
199    bestcomm_glue_is_initialized = true;
200
201    heap_status = _Heap_Initialize(
202      &bestcomm_heap,
203      (char *) &mpc5200.sram [0] + taskTableBytes,
204      sizeof(mpc5200.sram) - taskTableBytes,
205      4
206    );
207    assert(heap_status != 0);
208
209    /*
210     * Set task bar to begin of sram
211     */
212    mpc5200.sdma.taskBar = (uint32_t)(&(mpc5200.sram[0]));
213
214#if 0
215    /*
216     * Set core and BestComm XLB priority the same.
217     */
218    mpc5200.priority_enable |= 0x5;
219    mpc5200.priority = 0x77777171;
220#endif
221
222    /*
223     * Turn off COMM bus prefetch. This affects all data movements on
224     * the COMM bus. (Yes, _PE -- prefetch enable -- should probably be
225     * named _PD.)
226     */
227    mpc5200.sdma.PtdCntrl |= SDMA_PTDCNTRL_PE;
228
229    TasksInitAPI((uint8*)&mpc5200);
230
231    TasksLoadImage( (void *)&(mpc5200.sdma.taskBar));
232
233    /*
234     * initialize interrupt dispatcher
235     */
236    sc = rtems_interrupt_handler_install(
237      BSP_SIU_IRQ_SMARTCOMM,
238      "BESTCOMM",
239      RTEMS_INTERRUPT_UNIQUE,
240      bestcomm_glue_irq_dispatcher,
241      NULL
242    );
243    assert(sc == RTEMS_SUCCESSFUL);
244  }
245}
246
247void *bestcomm_malloc(size_t size)
248{
249  return _Heap_Allocate(&bestcomm_heap, size);
250}
251
252void bestcomm_free(void *ptr)
253{
254  if (ptr != NULL) {
255    bool ok = _Heap_Free(&bestcomm_heap, ptr);
256    assert(ok);
257  }
258}
Note: See TracBrowser for help on using the repository browser.