summaryrefslogtreecommitdiff
path: root/nuttx/arch/pjrc-8051/src/up_irqtest.c
blob: 944e705940892c1a21e67cfd390d4bfabe2f4f2a (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
/************************************************************
 * up_putc.c
 *
 *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
 *
 * 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 Gregory Nutt 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 <sys/types.h>
#include <nuttx/arch.h>
#include <8052.h>
#include "up_internal.h"

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

#define up_extint0 ((vector_t)PM2_VECTOR_EXTINT0)
#define up_timer0  ((vector_t)PM2_VECTOR_TIMER0)
#define up_extint1 ((vector_t)PM2_VECTOR_EXTINT1)
#define up_timer1  ((vector_t)PM2_VECTOR_TIMER1)
#define up_uart    ((vector_t)PM2_VECTOR_UART)
#define up_timer2  ((vector_t)PM2_VECTOR_TIMER2)

/************************************************************
 * Private Types
 ************************************************************/

typedef void (*vector_t)(void);

/************************************************************
 * Public Variables
 ************************************************************/

boolean g_irqtest;
ubyte g_irqtos;
ubyte g_irqregs[REGS_SIZE];
int g_nirqs;
FAR struct xcptcontext *g_irqcontext; 

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

/************************************************************
 * Name: utility functions
 ************************************************************/

static void _up_putc(ubyte ch) __naked
{
  ch; /* To avoid unreferenced argument warning */
  _asm
        mov     a, dpl
        ljmp    PM2_ENTRY_COUT
  _endasm;
}

void _up_puthex(ubyte hex) __naked
{
  hex; /* To avoid unreferenced argument warning */
  _asm
        mov     a, dpl
        ljmp    PM2_ENTRY_PHEX
  _endasm;
}

void _up_puthex16(int hex) __naked
{
  hex; /* To avoid unreferenced argument warning */
  _asm
        ljmp    PM2_ENTRY_PHEX16
  _endasm;
}

void _up_putnl(void) __naked
{
  _asm
	ljmp	PM2_ENTRY_NEWLINE
  _endasm;
}

void _up_puts(__code char *ptr)
{
  for (; *ptr; ptr++)
    {
       _up_putc(*ptr);
    }
}

void _up_delay(ubyte milliseconds) __naked
{
  _asm
	mov	r0, dpl
00001$: mov	r1, #230
00002$: nop
	nop
	nop
	nop
	nop
	nop
	djnz	r1, 00002$
	djnz	r0, 00001$
	ret
  _endasm;
}

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

/************************************************************
 * Name: os_start
 *
 * Description:
 *   "Fake" OS entry point.
 *
 ************************************************************/

void os_start(void)
{
  int i;

  /* Disable all interrupts */

  IE = 0;

  /* Then verify all of the interrupt */

  g_irqtest = FALSE;

  up_extint0();
  up_timer0();
#ifndef CONFIG_8052_TIMER2
  up_timer0();
#endif
  up_extint1();
  up_timer1();
  up_uart();
  up_timer2();

  /* Now a real interrupt ... */

  /* Configure timer 0 */

  TR0   = 0;     /* Make sure timer 0 is stopped */
  TF0   = 0;     /* Clear the overflow flag */
  TMOD &= 0xF0;  /* Set to mode 0 (without changing timer1) */
  TL0   = 0;     /* Clear timer 0 value */
  TH0   = 0;
  TR0    = 1;    /* Start the timer */

  /* Start timer interrupts */

  g_irqtest = TRUE;
  g_nirqs   = 0;
  IE        = 0x82;    /* Enable interrupts */

  /* Wait a about 500 MS */

  _up_delay(500);

  /* Disable the timer */

  TR0 = 0;     /* Stop timer 0 */
  IE  = 0;     /* Disable interrupts */

  _up_puts("IRQs in 500 MS=");
  _up_puthex16(g_nirqs);
  _up_putnl();

  /* end of test */

  _up_puts("Test complete");
  _up_putnl();
  for(;;);
}

/************************************************************
 * Name: irq_dispatch
 *
 * Description:
 *   "Fake" IRQ dispatcher
 *
 ***********************************************************/

void irq_dispatch(int irq, FAR void *context)
{
  context;
  if (g_irqtest)
    {
      g_nirqs++;
    }
  else
    {
      _up_puts("Dispatch IRQ=");
      _up_puthex(irq);
      _up_putnl();
    }
}

/************************************************************
 * Name: up_dumpstack / up_dumpframe
 *
 * Description:
 *   "Fake" debug routines if needed.
 *
 ************************************************************/

void up_dumpstack(void)
{
}

void up_dumpframe(FAR struct xcptcontext *context)
{
}

/************************************************************
 * Name: up_ledinit, up_ledon, up_ledoff
 *
 * Description:
 *   "Fake" LED routines if needed
 *
 ************************************************************/

void up_ledinit(void)
{
}

void up_ledon(ubyte led)
{
  led;
}

void up_ledoff(ubyte led)
{
  led;
}