Contiki-NG
Loading...
Searching...
No Matches
dbg-arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
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 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \addtogroup nrf
33 * @{
34 *
35 * \addtogroup nrf-os OS drivers
36 * @{
37 *
38 * \addtogroup nrf-dbg Debug driver
39 * @{
40 *
41 * \file
42 * Debug driver for the nRF.
43 * \author
44 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
45 *
46 */
47/*---------------------------------------------------------------------------*/
48#include "contiki.h"
49
50#include "uarte-arch.h"
51#include "usb.h"
52/*---------------------------------------------------------------------------*/
53#if PLATFORM_DBG_CONF_USB
54#define write_byte(b) usb_write((uint8_t *)&b, sizeof(uint8_t))
55#define flush() usb_flush()
56#else /* PLATFORM_DBG_CONF_USB */
57#define write_byte(b) uarte_write(b)
58#define flush()
59#endif /* PLATFORM_DBG_CONF_USB */
60/*---------------------------------------------------------------------------*/
61#if TRUSTZONE_NONSECURE
62#include "trustzone/tz-api.h"
63
64#define DBG_BUF_SIZE 256
65static char dbg_buf[DBG_BUF_SIZE];
66static uint16_t dbg_pos;
67/*---------------------------------------------------------------------------*/
68int
69dbg_putchar(int c)
70{
71 if(dbg_pos < DBG_BUF_SIZE) {
72 dbg_buf[dbg_pos++] = c;
73 }
74
75 if(c == '\n' || dbg_pos >= DBG_BUF_SIZE - 1) {
76 dbg_buf[MIN(dbg_pos - 1, DBG_BUF_SIZE - 1)] = '\0';
77 tz_api_println(dbg_buf);
78 dbg_pos = 0;
79 }
80
81 return c;
82}
83#else
84int
86{
87 write_byte(c);
88
89 if(c == '\n') {
90 flush();
91 }
92
93 return c;
94}
95#endif /* TRUSTZONE_NONSECURE */
96/*---------------------------------------------------------------------------*/
97unsigned int
98dbg_send_bytes(const unsigned char *s, unsigned int len)
99{
100 unsigned int i = 0;
101
102 while(s && *s != 0) {
103 if(i >= len) {
104 break;
105 }
106 dbg_putchar(*s++);
107 i++;
108 }
109
110 flush();
111
112 return i;
113}
114/*---------------------------------------------------------------------------*/
115/**
116 * @}
117 * @}
118 * @}
119 */
unsigned int dbg_send_bytes(const unsigned char *s, unsigned int len)
Print a stream of bytes.
Definition dbg-arch.c:53
int dbg_putchar(int c)
Print a character to debug output.
Definition dbg-arch.c:61
CC_TRUSTZONE_SECURE_CALL void tz_api_println(const char *text)
Print the specified message via the secure world.
Definition tz-api.c:118
UARTE header file for the nRF.