diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index fafadb831..9f7a31adf 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -82,7 +82,7 @@ OBJDUMP:=$(CROSS_COMPILE)-objdump ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \ slip_uart0.c clock.c micromac-radio.c int-master.c \ - node-id.c watchdog.c slip.c sprintf.c + node-id.c watchdog.c slip.c dbg.c # Default uart0 for printf and slip TARGET_WITH_UART0 ?= 1 TARGET_WITH_UART1 ?= 0 @@ -100,9 +100,11 @@ ifeq ($(WITH_UART),1) ARCH += uart-driver.c endif -CONTIKI_TARGET_DIRS = . dev lib +CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_MAIN = platform.c +MODULES += os/lib/dbg-io + ifeq ($(JN516x_WITH_DR1175),1) JN516x_WITH_DR1174 = 1 CFLAGS += -DSENSOR_BOARD_DR1175 diff --git a/arch/platform/jn516x/dbg.c b/arch/platform/jn516x/dbg.c new file mode 100644 index 000000000..ac6cc3888 --- /dev/null +++ b/arch/platform/jn516x/dbg.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, SICS Swedish ICT. + * All rights reserved. + * + * 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include +#include "dev/uart0.h" +/*---------------------------------------------------------------------------*/ +int +dbg_putchar(int c) +{ + uart0_writeb(c); + return 1; +} +/*---------------------------------------------------------------------------*/ +unsigned int +dbg_send_bytes(const unsigned char *s, unsigned int len) +{ + unsigned int i = 0; + + while(s && *s != 0) { + if(i >= len) { + break; + } + uart0_writeb(*s++); + i++; + } + return i; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/jn516x/lib/sprintf.c b/arch/platform/jn516x/lib/sprintf.c deleted file mode 100644 index dd2408090..000000000 --- a/arch/platform/jn516x/lib/sprintf.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - File: printf.c - - Copyright (c) 2004,2008 Kustaa Nyholm / SpareTimeLabs - - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list - of conditions and the following disclaimer. - - 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. - - Neither the name of the Kustaa Nyholm or SpareTimeLabs 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 HOLDER 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. - - */ - -/* - * This is BSD code obtained from http://www.sparetimelabs.com/printfrevisited/index.html - * From the web page: - * "The code is GPL and BSD lincensed, download the BSD licensed version from the link - * above or use the GPL licensed code from this page below." - * - * modified by Beshr Al Nahas and Simon Duquennoy - */ - -#include "contiki.h" -#include -#include -#include -#include -#include -#include "dev/uart0.h" - -static char *bf, buf[14], uc, zs; -static unsigned int num; - -static void -out(char c) -{ - *bf++ = c; -} -static void -outDgt(char dgt) -{ - out(dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10)); - zs = 1; -} -static void -divOut(unsigned int div) -{ - unsigned char dgt = 0; - while(num >= div) { - num -= div; - dgt++; - } - if(zs || dgt > 0) { - outDgt(dgt); - } -} -int -vsnprintf(char *str, size_t n, const char *fmt, __VALIST va) -{ - char ch, *p, *str_orig = str; - char next_ch; - - while((ch = *fmt++) && str - str_orig < n) { - if(ch != '%') { - *str++ = ch; - } else { - char lz = 0; - char w = 0; - ch = *(fmt++); - if(ch == '0') { - ch = *(fmt++); - lz = 1; - } - if(ch == '-' || (ch >= '0' && ch <= '9')) { - w = 0; - while(ch == '-' || (ch >= '0' && ch <= '9')) { - if(ch != '-') { - w = (((w << 2) + w) << 1) + ch - '0'; - } - ch = *fmt++; - } - } - bf = buf; - p = bf; - zs = 0; -start_format: - next_ch = *fmt; - switch(ch) { - case 0: - goto abort; - case 'l': - if(next_ch == 'x' - || next_ch == 'X' - || next_ch == 'u' - || next_ch == 'd') { - ch = *(fmt++); - goto start_format; - } - case 'u': - case 'd': - num = va_arg(va, unsigned int); - if(ch == 'd' && (int)num < 0) { - num = -(int)num; - out('-'); - } - divOut(1000000000); - divOut(100000000); - divOut(10000000); - divOut(1000000); - divOut(100000); - divOut(10000); - divOut(1000); - divOut(100); - divOut(10); - outDgt(num); - break; - case 'p': - case 'x': - case 'X': - uc = ch == 'X'; - num = va_arg(va, unsigned int); - /* divOut(0x100000000UL); */ - divOut(0x10000000); - divOut(0x1000000); - divOut(0x100000); - divOut(0x10000); - divOut(0x1000); - divOut(0x100); - divOut(0x10); - outDgt(num); - break; - case 'c': - out((char)(va_arg(va, int))); - break; - case 's': - p = va_arg(va, char *); - break; - case '%': - out('%'); - default: - break; - } - *bf = 0; - bf = p; - - while(*bf++ && w > 0) { - w--; - } - while(w-- > 0) { - if(str - str_orig < n) { - *str++ = lz ? '0' : ' '; - } else { - goto abort; - } - } - while((ch = *p++)) { - if(str - str_orig < n) { - *str++ = ch; - } else { - goto abort; - } - } - } - } - -abort: - if(str - str_orig < n) { - *str = '\0'; - } else { - *(--str) = '\0'; - } return str - str_orig; -} -int -sprintf(char *str, const char *fmt, ...) -{ - int m; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, 0xffffffff, fmt, va); - va_end(va); - return m; -} -int -snprintf(char *str, size_t n, const char *fmt, ...) -{ - int m; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, n, fmt, va); - va_end(va); - return m; -} -int -printf(const char *fmt, ...) -{ - int m, i; - char str[256]; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, sizeof(str), fmt, va); - va_end(va); - for(i = 0; i < m; i++) { - putchar(str[i]); - } - return m; -} -int -puts(const char *s) -{ - char c; - while((c = *s++) != '\0') { - putchar(c); - } - putchar('\n'); - return strlen(s); -} diff --git a/arch/platform/jn516x/lib/slip.c b/arch/platform/jn516x/slip.c similarity index 99% rename from arch/platform/jn516x/lib/slip.c rename to arch/platform/jn516x/slip.c index bdf3c81b5..173a14d60 100644 --- a/arch/platform/jn516x/lib/slip.c +++ b/arch/platform/jn516x/slip.c @@ -429,9 +429,3 @@ slip_input_byte(unsigned char c) return error_return_code; } /*---------------------------------------------------------------------------*/ -int -putchar(int c) -{ - uart0_writeb(c); - return 1; -}