summaryrefslogtreecommitdiff
path: root/nuttx/arch/hc/src/m9s12/m9s12_dumpgpio.c
blob: b958092b87475e7bcc20e4bcb8290d95a7c61f6d (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/****************************************************************************
 * arch/arm/src/m9s12/m9s12_dumpgpio.c
 * arch/arm/src/chip/m9s12_dumpgpio.c
 *
 *   Copyright (C) 2011 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/

/****************************************************************************
 * Included Files
 ****************************************************************************/

#include <nuttx/config.h>

#include <stdint.h>
#include <debug.h>
#include <arch/irq.h>

#include "up_arch.h"
#include "m9s12_internal.h"
#include "m9s12_pim.h"
#include "m9s12_mebi.h"

#ifdef CONFIG_DEBUG_GPIO

/****************************************************************************
 * Definitions
 ****************************************************************************/

/* PIM ports (T,S,G,H,J,L) */

#define HCS12_PIM_NPORTS 6

/* MEBI ports (A,B,E,K) */

#define HCS12_MEBI_NPORTS 4

/* Decoding helper macros */

#define HCS12_PIN(cfg)        (((cfg) & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT)
#define HCS12_PORTNDX(cfg)    (((cfg) >> GPIO_PORT_SHIFT) & 7)
#define HCS12_PIMPORT(cfg)    (((cfg) & GPIO_PORT_PIM) != 0)
#define HCS12_MEBIPORT(cfg)   (((cfg) & GPIO_PORT_PIM) == 0)

#define HCS12_PULL(cfg)       (((cfg) & GPIO_PULLUP_MASK) >> GPIO_PULLUP_SHIFT)
#  define HCS12_PULL_NONE     0
#  define HCS12_PULL_POLARITY 1
#  define HCS12_PULL_ENABLE   2
#  define HCS12_PULL_UP       2
#  define HCS12_PULL_DOWN     3

#define HCS12_INTERRUPT(cfg)  (((cfg) & GPIO_INT_MASK) >> GPIO_INT_SHIFT)
#  define HCS12_INT_NONE      0
#  define HCS12_INT_POLARITY  1
#  define HCS12_INT_ENABLE    2
#  define HCS12_INT_FALLING   2
#  define HCS12_INT_RISING    3

/* PIM ports have the following forms:
 *
 *   FORM 1: IO INPUT DDR RDR PER PS            Port T
 *   FORM 2: IO INPUT DDR RDR PER PS WOM        Port S,L
 *   FORM 3: IO INPUT DDR RDR PER PS     IE IF  Port G,H,J
 */

#define PIMPORT_FORM1 0
#define PIMPORT_FORM2 1
#define PIMPORT_FORM3 2

/* MEBI ports are pretty strange.  Most look the same, but E and K can have
 * some special attributes.
 */

#define MEBIPORT_AB  0
#define MEBIPORT_E   1
#define MEBIPORT_K   2

/****************************************************************************
 * Public Types
 ****************************************************************************/

struct gpio_piminfo_s
{
  uint16_t base;  /* PIM GPIO block base address */
  char     name;  /* Port name */
  uint8_t  form;  /* Form of the PIM GPIO block registers */
};

struct gpio_mebiinfo_s
{
  uint16_t data;  /* MEBI data register address */
  uint16_t ddr;   /* MEBI ddr register address */
  char     name;  /* Port name */
  uint8_t  form;  /* Form of the MEBI port */
};

/****************************************************************************
 * Public Data
 ****************************************************************************/

static const struct gpio_piminfo_s piminfo[HCS12_PIM_NPORTS] =
{
 {HCS12_PIM_PORTT_BASE, 'T', PIMPORT_FORM1}, /* Port T */
 {HCS12_PIM_PORTS_BASE, 'S', PIMPORT_FORM2}, /* Port S */
 {HCS12_PIM_PORTG_BASE, 'G', PIMPORT_FORM3}, /* Port G */
 {HCS12_PIM_PORTH_BASE, 'H', PIMPORT_FORM3}, /* Port H */
 {HCS12_PIM_PORTJ_BASE, 'J', PIMPORT_FORM3}, /* Port J */
 {HCS12_PIM_PORTL_BASE, 'L', PIMPORT_FORM2}  /* Port L */
};

static const struct gpio_mebiinfo_s mebiinfo[HCS12_MEBI_NPORTS] =
{
 {HCS12_MEBI_PORTA, HCS12_MEBI_DDRA, 'A', MEBIPORT_AB}, /* Port A */
 {HCS12_MEBI_PORTB, HCS12_MEBI_DDRB, 'B', MEBIPORT_AB}, /* Port B */
 {HCS12_MEBI_PORTE, HCS12_MEBI_DDRE, 'E', MEBIPORT_E},  /* Port E */
 {HCS12_MEBI_PORTK, HCS12_MEBI_DDRK, 'K', MEBIPORT_K}   /* Port K */
};

/****************************************************************************
 * Private Data
 ****************************************************************************/

/****************************************************************************
 * Private Functions
 ****************************************************************************/

/****************************************************************************
 * Name: hcs12_pimdump
 *
 * Description:
 *   PIM GPIO register block dump
 *
 ****************************************************************************/

static inline void hcs12_pimdump(uint8_t portndx)
{
  const struct gpio_piminfo_s *ptr;

  if (portndx >= HCS12_PIM_NPORTS)
    {
      lldbg("  Illegal PIM port index: %d\n", portndx);
      return;
    }

  ptr = &piminfo[portndx];
  lldbg(" PIM Port%c:\n", ptr->name);
  lldbg("   IO:%02x  INP:%02x DDR:%02x RDR:%02x\n",
        getreg8(ptr->base+HCS12_PIM_IO_OFFSET),
        getreg8(ptr->base+HCS12_PIM_INPUT_OFFSET),
        getreg8(ptr->base+HCS12_PIM_DDR_OFFSET),
        getreg8(ptr->base+HCS12_PIM_RDR_OFFSET));

  switch (ptr->form)
    {
    case PIMPORT_FORM1:
      lldbg("  PER:%02x  PS:%02x\n",
            getreg8(ptr->base+HCS12_PIM_PER_OFFSET),
            getreg8(ptr->base+HCS12_PIM_PS_OFFSET));
      break;

    case PIMPORT_FORM2:
      lldbg("  PER:%02x  PS:%02x WOM:%02x\n",
            getreg8(ptr->base+HCS12_PIM_PER_OFFSET),
            getreg8(ptr->base+HCS12_PIM_PS_OFFSET),
            getreg8(ptr->base+HCS12_PIM_WOM_OFFSET));
      break;

    case PIMPORT_FORM3:
      lldbg("  PER:%02x  PS:%02x  IE:%02x  IF:%02x\n",
            getreg8(ptr->base+HCS12_PIM_PER_OFFSET),
            getreg8(ptr->base+HCS12_PIM_PS_OFFSET),
            getreg8(ptr->base+HCS12_PIM_IE_OFFSET),
            getreg8(ptr->base+HCS12_PIM_IF_OFFSET));
      break;

    default:
      break;
    }
}

/****************************************************************************
 * Name: hcs12_mebidump
 *
 * Description:
 *   PIM GPIO register block dump
 *
 ****************************************************************************/

static inline void hcs12_mebidump(uint8_t portndx)
{
  const struct gpio_mebiinfo_s *ptr;

  if (portndx >= HCS12_MEBI_NPORTS)
    {
      lldbg("  Illegal MEBI port index: %d\n", portndx);
      return;
    }

  ptr = &mebiinfo[portndx];
  lldbg(" MEBI Port%c:\n", ptr->name);

  switch (ptr->form)
    {
    case MEBIPORT_AB:
      lldbg("   DATA:%02x DDR:%02x\n",
            getreg8(ptr->data), getreg8(ptr->ddr));
      break;

    case MEBIPORT_E:
      lldbg("   DATA:%02x DDR:%02x MODE:%02x PEAR:%02x\n",
            getreg8(ptr->data), getreg8(ptr->ddr),
            getreg8(HCS12_MEBI_MODE), getreg8(HCS12_MEBI_PEAR));
      break;

    case MEBIPORT_K:
      lldbg("   DATA:%02x DDR:%02x MODE:%02x\n",
            getreg8(ptr->data), getreg8(ptr->ddr),
            getreg8(HCS12_MEBI_MODE));
      break;

    default:
      break;
    }
}

/****************************************************************************
 * Public Functions
 ****************************************************************************/

/************************************************************************************
 * Function:  hcs12_dumpgpio
 *
 * Description:
 *   Dump all GPIO registers associated with the base address of the provided pinset.
 *
 ************************************************************************************/

int hcs12_dumpgpio(uint16_t pinset, const char *msg)
{
  uint8_t portndx = HCS12_PORTNDX(pinset);
  irqstate_t flags = irqsave();

  lldbg("pinset: %08x -- %s\n", pinset, msg);

  if (HCS12_PIMPORT(pinset))
    {
      hcs12_pimdump(portndx);
    }
  else
    {
      hcs12_mebidump(portndx);
    }

  irqrestore(flags);
  return OK;
}

#endif /* CONFIG_DEBUG_GPIO */