source: rtems/c/src/lib/libbsp/m68k/ods68302/startup/debugport.c @ a2016b99

4.104.114.84.95
Last change on this file since a2016b99 was 0074691a, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/97 at 22:13:29

Merged very large and much appreciated patch from Chris Johns
<cjohns@…>. This patch includes the ods68302 bsp,
the RTEMS++ class library, and the rtems++ test.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*****************************************************************************/
2/*
3  High Level Debug Port Functions
4
5  $Id$
6 
7 */
8/*****************************************************************************/
9
10#include <stdio.h>
11#include <stdarg.h>
12
13#include "debugport.h"
14#include "m68302scc.h"
15#include "bsp.h"
16
17static int initialised;
18
19void debug_port_initialise(void)
20{
21  scc_initialise(CONSOLE_PORT, CONSOLE_BAUD, FALSE);
22#if defined(DEBUG_PORT)
23  scc_initialise(DEBUG_PORT, DEBUG_BAUD, FALSE);
24#endif
25}
26
27unsigned char debug_port_status(const unsigned char status)
28{
29  if (!initialised)
30  {
31    initialised = 1;   
32    debug_port_initialise();
33  }
34 
35  return scc_status(CONSOLE_PORT, status);
36}
37
38unsigned char debug_port_in(void)
39{
40  if (!initialised)
41  {
42    initialised = 1;   
43    debug_port_initialise();
44  }
45 
46  return scc_in(CONSOLE_PORT);
47}
48
49void debug_port_out(const unsigned char character)
50{
51  if (!initialised)
52  {
53    initialised = 1;   
54    debug_port_initialise();
55  }
56 
57  scc_out(CONSOLE_PORT, character);
58}
59
60void debug_port_write(const char *buffer)
61{
62   while (*buffer != '\0')
63   {
64     debug_port_out(*buffer++);
65   }
66}
67
68void debug_port_write_buffer(const char *buffer, unsigned int size)
69{
70   unsigned int count;
71   for (count = 0; count < size; count++)
72   {
73     debug_port_out(buffer[count]);
74   }
75}
76
77void debug_port_write_hex_uint(const unsigned int value)
78{
79   unsigned int bits = sizeof(value) * 8;
80   unsigned char c;
81
82   do
83   {
84     bits -= 4;
85     c = (unsigned char) ((value >> bits) & 0x0F);
86     if (c < 10)
87     {
88       c += '0';
89     }
90     else
91     {
92       c += 'a' - 10;
93     }
94     debug_port_out((char) c);
95   }
96   while (bits);
97}
98
99void debug_port_write_hex_ulong(const unsigned long value)
100{
101   unsigned int bits = sizeof(value) * 8;
102   unsigned char c;
103
104   do
105   {
106     bits -= 4;
107     c = (unsigned char) ((value >> bits) & 0x0F);
108     if (c < 10)
109     {
110       c += '0';
111     }
112     else
113     {
114       c += 'a' - 10;
115     }
116     debug_port_out((char) c);
117   }
118   while (bits);
119}
120
121#define BUFFER_SIZE (256)
122static char buffer[BUFFER_SIZE];
123
124void debug_port_printf(const char *format, ...)
125{
126  va_list args;
127  int written;
128
129  /*  gain access to the argument list */
130  va_start(args, format);
131
132  /* set the trap    */
133  buffer[BUFFER_SIZE - 2] = '\xAA';
134  buffer[BUFFER_SIZE - 1] = '\x55';
135
136  /* format the string and send to stdout */
137  written = vsprintf(buffer, format, args);
138
139  /* try an trap format buffer overflows */
140  if ((buffer[BUFFER_SIZE - 2] != '\xAA') ||
141      (buffer[BUFFER_SIZE - 1] != '\x55'))
142  {
143    debug_port_write("debug port buffer overflow, halting...");
144    DISABLE_WATCHDOG();
145    while (1 == 1);
146  }
147
148  /* see if an error occurred, if not flush the output buffer */
149  if (written != -1)
150  {
151    debug_port_write_buffer(buffer, written);
152  }
153}
154
155void debug_port_banner(void)
156{
157#define CARD_LABEL "ods68302-" #VARIANT
158 
159  debug_port_write("\n\n\r");
160  debug_port_write(_Copyright_Notice);
161  debug_port_write("\n\r  " CARD_ID "\n\r");
162}
163
Note: See TracBrowser for help on using the repository browser.