Contiki 3.x
dbg.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /** \addtogroup cc2538-char-io
32  * @{ */
33 /**
34  * \file
35  * Implementation of arch-specific functions required by the dbg_io API in
36  * cpu/arm/common/dbg-io
37  */
38 #include "contiki.h"
39 
40 #include "dbg.h"
41 #include "dev/uart.h"
42 #include "usb/usb-serial.h"
43 
44 #include <stdio.h>
45 /*---------------------------------------------------------------------------*/
46 #ifndef DBG_CONF_USB
47 #define DBG_CONF_USB 0
48 #endif
49 
50 #if DBG_CONF_USB
51 #define write_byte(b) usb_serial_writeb(b)
52 #define flush() usb_serial_flush()
53 #else
54 #define write_byte(b) uart_write_byte(DBG_CONF_UART, b)
55 #define flush()
56 #endif
57 /*---------------------------------------------------------------------------*/
58 #undef putchar
59 #undef puts
60 
61 #define SLIP_END 0300
62 /*---------------------------------------------------------------------------*/
63 int
64 putchar(int c)
65 {
66 #if DBG_CONF_SLIP_MUX
67  static char debug_frame = 0;
68 
69  if(!debug_frame) {
70  write_byte(SLIP_END);
71  write_byte('\r');
72  debug_frame = 1;
73  }
74 #endif
75 
76  write_byte(c);
77 
78  if(c == '\n') {
79 #if DBG_CONF_SLIP_MUX
80  write_byte(SLIP_END);
81  debug_frame = 0;
82 #endif
83  dbg_flush();
84  }
85  return c;
86 }
87 /*---------------------------------------------------------------------------*/
88 unsigned int
89 dbg_send_bytes(const unsigned char *s, unsigned int len)
90 {
91  unsigned int i = 0;
92 
93  while(s && *s != 0) {
94  if(i >= len) {
95  break;
96  }
97  putchar(*s++);
98  i++;
99  }
100  return i;
101 }
102 /*---------------------------------------------------------------------------*/
103 int
104 puts(const char *s)
105 {
106  unsigned int i = 0;
107 
108  while(s && *s != 0) {
109  putchar(*s++);
110  i++;
111  }
112  putchar('\n');
113  return i;
114 }
115 /*---------------------------------------------------------------------------*/
116 
117 /** @} */
#define dbg_flush()
Flushes character output.
Definition: dbg.h:83
Header file for the cc2538 Debug I/O module.
unsigned int dbg_send_bytes(const unsigned char *seq, unsigned int len)
Print a stream of bytes.
Definition: debug-uart.c:71
Header file for cc2538&#39;s UART-like I/O over USB.