From f17bf2633163ab479c1dd3e741c80cc853b02a8d Mon Sep 17 00:00:00 2001 From: G Anthony Date: Tue, 26 Feb 2013 18:52:21 -0800 Subject: [PATCH] trace: Merged omapzoom sysbios-rpmsg version of SysMin for SMP OMAP5. This clobbers the SysMin from the BIOS tools, for OMAP5 SMP. Signed-off-by: G Anthony --- packages/ti/trace/SysMin.c | 277 ++++++++++++++++++++++++++++++++++ packages/ti/trace/SysMin.xdc | 229 ++++++++++++++++++++++++++++ packages/ti/trace/SysMin.xdt | 42 ++++++ packages/ti/trace/SysMin.xs | 222 +++++++++++++++++++++++++++ packages/ti/trace/package.bld | 149 ++++++++++++++++++ packages/ti/trace/package.xdc | 41 +++++ packages/ti/trace/package.xs | 80 ++++++++++ 7 files changed, 1040 insertions(+) create mode 100644 packages/ti/trace/SysMin.c create mode 100644 packages/ti/trace/SysMin.xdc create mode 100644 packages/ti/trace/SysMin.xdt create mode 100644 packages/ti/trace/SysMin.xs create mode 100644 packages/ti/trace/package.bld create mode 100644 packages/ti/trace/package.xdc create mode 100644 packages/ti/trace/package.xs diff --git a/packages/ti/trace/SysMin.c b/packages/ti/trace/SysMin.c new file mode 100644 index 0000000..d7ed81c --- /dev/null +++ b/packages/ti/trace/SysMin.c @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + */ +/* + * ======== SysMin.c ======== + */ + +#include +#include + +#ifdef SMP +#include +#include +#include +#endif +#include + +#include +#include +#include + +#include "package/internal/SysMin.xdc.h" + +/* + * ======== SysMin_Module_startup ======== + */ +Int SysMin_Module_startup(Int phase) +{ + if (SysMin_bufSize != 0) { + memset(module->outbuf, 0, SysMin_bufSize); + } + +#ifndef SMP + /* Initialize to TRUE so the first line get the timestamp */ + module->getTime = TRUE; +#endif + + return (Startup_DONE); +} + +/* + * ======== SysMin_abort ======== + */ +Void SysMin_abort(String str) +{ + Char ch; + + if (SysMin_bufSize != 0) { + if (str != NULL) { + while ((ch = *str++) != '\0') { + SysMin_putch(ch); + } + } + + /* Only flush if configured to do so */ + if (SysMin_flushAtExit) { + SysMin_flush(); + } + } +} + +/* + * ======== SysMin_exit ======== + */ +Void SysMin_exit(Int stat) +{ + if ((SysMin_flushAtExit) && (SysMin_bufSize != 0)) { + SysMin_flush(); + } +} + +/* + * ======== SysMin_output ======== + * Common output function to write a character + * into the circular buffer + */ +static inline Void SysMin_output(Char ch) +{ + module->outbuf[module->outidx++] = ch; + /* Last 8 bytes are used for writeIdx/readIdx fields */ + if (module->outidx == SysMin_bufSize - 8) { + module->outidx = 0; + } +} + +/* + * ======== SysMin_putch ======== + * Custom implementation for using circular + * buffer without using flush + */ +Void SysMin_putch(Char ch) +{ + IArg key; + UInt i; +#ifndef SMP + static UInt coreId = 0; +#else + UInt coreId; +#endif + UInt lineIdx; + Char *lineBuf; + Int index; + UInt64 uSec; + static Bool configure = FALSE; + static UInt startIdx; + static UInt endIdx; + static UInt timeStampSecCharLen; + const UInt minSecCharLen = 4; /* for 1 us tick period */ + const UInt maxuSecCharLen = 6; /* for 1 us tick period */ + /* Max characters for seconds would be 10 assuming 1 sec tick period, + * so decimal point index will be 11, and maximum time stamp buffer + * length would be 18 accounting maxuSecCharLen and a trailing NULL */ + const UInt decPtIdx = 11; + const UInt timeStampBufLen = 18; + const UInt leftSpaceIdx = 10; + Char timeStamp[18] = {" \0"}; + + /* Configure the trace timestamp format */ + if (!configure) { + Int i = 0, mod = 10; + + /* Find number of characters needes for seconds and sub-seconds, + * tick periods are specified in microseconds */ + for (; i < maxuSecCharLen; i++) { + if (Clock_tickPeriod % mod) { + break; + } + mod = mod * 10; + } + timeStampSecCharLen = minSecCharLen + i; + startIdx = decPtIdx - timeStampSecCharLen; + endIdx = timeStampBufLen - (i + 1); /* Account for null character too */ + configure = TRUE; + } + + if (SysMin_bufSize != 0) { + +#ifndef SMP + key = Gate_enterSystem(); +#else + /* Disable only local interrupts to place chars in local line buffer */ + key = (IArg)Core_hwiDisable(); + coreId = Core_getId(); +#endif + + lineIdx = module->lineBuffers[coreId].lineidx; + lineBuf = module->lineBuffers[coreId].linebuf; + lineBuf[lineIdx++] = ch; + module->lineBuffers[coreId].lineidx = lineIdx; + +#ifdef SMP + /* Copy line buffer to shared output buffer at EOL or when filled up */ + if ((ch == '\n') || (lineIdx >= SysMin_LINEBUFSIZE)) { + Gate_enterSystem(); + + /* Tag core number */ + SysMin_output('['); + SysMin_output(0x30 + coreId); + SysMin_output(']'); +#else + if (module->getTime == TRUE) { +#endif + uSec = Clock_getTicks() * Clock_tickPeriod; + SysMin_output('['); + if (uSec) { + sprintf(timeStamp, "%17llu\0", uSec); + } + for (index = startIdx; index < endIdx; index++) { + if (index == decPtIdx) { + SysMin_output('.'); + } + if (timeStamp[index] == ' ' && index >= leftSpaceIdx) { + SysMin_output('0'); + } + else { + SysMin_output(timeStamp[index]); + } + } + SysMin_output(']'); + SysMin_output(' '); +#ifdef SMP + for (i = 0; i < lineIdx; i++) { + SysMin_output(lineBuf[i]); + } + module->writeidx[0] = module->outidx; + module->lineBuffers[coreId].lineidx = 0; + + Gate_leaveSystem(key); + } + else { + /* restore local interrupts */ + Core_hwiRestore((UInt)key); + } +#else + module->getTime = FALSE; + } + + /* Copy line buffer to shared output buffer at EOL or when filled up */ + if ((ch == '\n') || (lineIdx >= SysMin_LINEBUFSIZE)) { + for (i = 0; i < lineIdx; i++) { + SysMin_output(lineBuf[i]); + } + module->lineBuffers[coreId].lineidx = 0; + module->getTime = TRUE; + module->writeidx[0] = module->outidx; + } + + Gate_leaveSystem(key); +#endif + + } +} + +/* + * ======== SysMin_ready ======== + */ +Bool SysMin_ready() +{ + return (SysMin_bufSize != 0); +} + +/* + * ======== SysMin_flush ======== + * Called during SysMin_exit, System_exit or System_flush. + */ +Void SysMin_flush() +{ +/* Using custom circular buffer implementation without resetting write ptr */ +#if 0 + IArg key; + + key = Gate_enterSystem(); + + /* + * If a wrap occured, we need to flush the "end" of the internal buffer + * first to maintain fifo character output order. + */ + if (module->wrapped == TRUE) { + SysMin_outputFunc(module->outbuf + module->outidx, + SysMin_bufSize - module->outidx); + } + + SysMin_outputFunc(module->outbuf, module->outidx); + module->outidx = 0; + module->wrapped = FALSE; + + Gate_leaveSystem(key); +#endif +} diff --git a/packages/ti/trace/SysMin.xdc b/packages/ti/trace/SysMin.xdc new file mode 100644 index 0000000..d3adb87 --- /dev/null +++ b/packages/ti/trace/SysMin.xdc @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + */ +/* + * ======== SysMin.xdc ======== + */ + +/*! + * ======== SysMin ======== + * + * Minimal implementation of `{@link ISystemSupport}`. + * + * This implementation provides a fully functional implementation of + * all methods specified by `ISystemSupport`. + * + * The module maintains an internal buffer (with a configurable size) + * that stores on the "output". When full, the data is over-written. When + * `System_flush()` is called the characters in the internal buffer are + * "output" using the user configuratble `{@link #outputFxn}`. + * + * As with all `ISystemSupport` modules, this module is the back-end for the + * `{@link System}` module; application code does not directly call these + * functions. + */ +@Template("./SysMin.xdt") +@ModuleStartup +module SysMin inherits xdc.runtime.ISystemSupport { + + metaonly struct ModuleView { + Ptr outBuf; + UInt outBufIndex; + Bool getTime; /* set to true for each new trace */ + Bool wrapped; /* has the buffer wrapped */ + }; + + metaonly struct BufferEntryView { + String entry; + } + + /*! + * ======== rovViewInfo ======== + * @_nodoc + */ + @Facet + metaonly config xdc.rov.ViewInfo.Instance rovViewInfo = + xdc.rov.ViewInfo.create({ + viewMap: [ + ['Module', + { + type: xdc.rov.ViewInfo.MODULE, + viewInitFxn: 'viewInitModule', + structName: 'ModuleView' + } + ], + ['OutputBuffer', + { + type: xdc.rov.ViewInfo.MODULE_DATA, + viewInitFxn: 'viewInitOutputBuffer', + structName: 'BufferEntryView' + } + ] + ] + }); + + /*! + * ======== LINEBUFSIZE ======== + * Size (in MAUs) of the line buffer + * + * An internal line buffer of this size is allocated. All output is stored + * in this internal buffer until a new line is output. + */ + const SizeT LINEBUFSIZE = 0x100; + + /*! + * ======== bufSize ======== + * Size (in MAUs) of the output. + * + * An internal buffer of this size is allocated. All output is stored + * in this internal buffer. + * + * If 0 is specified for the size, no buffer is created and ALL + * tracing is disabled. + */ + config SizeT bufSize = 0x1000; + + /*! + * ======== sectionName ======== + * Section where the internal character output buffer is placed + * + * The default is to have no explicit placement; i.e., the linker is + * free to place it anywhere in the memory map. + */ + metaonly config String sectionName = null; + + /*! + * ======== flushAtExit ======== + * Flush the internal buffer during `{@link #exit}` or `{@link #abort}`. + * + * If the application's target is a TI target, the internal buffer is + * flushed via the `HOSTwrite` function in the TI C Run Time Support + * (RTS) library. + * + * If the application's target is not a TI target, the internal buffer + * is flushed to `stdout` via `fwrite(..., stdout)`. + * + * Setting this parameter to `false` reduces the footprint of the + * application at the expense of not getting output when the application + * ends via a `System_exit()`, `System_abort()`, `exit()` or `abort()`. + */ + config Bool flushAtExit = true; + + /*! + * ======== abort ======== + * Backend for `{@link System#abort()}` + * + * This abort function writes the string to the internal + * output buffer and then gives all internal output to the + * `{@link #outputFxn}` function if the `{@link #flushAtExit}` + * configuration parameter is true. + * + * @param(str) message to output just prior to aborting + * + * If non-`NULL`, this string should be output just prior to + * terminating. + * + * @see ISystemSupport#abort + */ + override Void abort(String str); + + /*! + * ======== exit ======== + * Backend for `{@link System#exit()}` + * + * This exit function gives all internal output to the + * `{@link #outputFxn}` function if the `{@link #flushAtExit}` + * configuration parameter is true. + * + * @see ISystemSupport#exit + */ + override Void exit(Int stat); + + /*! + * ======== flush ======== + * Backend for `{@link System#flush()}` + * + * The `flush` writes the contents of the internal character buffer + * via the `{@link #outputFxn}` function. + * + * @a(Warning) + * The `{@link System}` gate is used for thread safety during the + * entire flush operation, so care must be taken when flushing with + * this `ISystemSupport` module. Depending on the nature of the + * `System` gate, your application's interrupt latency + * may become a function of the `bufSize` parameter! + * + * @see ISystemSupport#flush + */ + override Void flush(); + + /*! + * ======== putch ======== + * Backend for `{@link System#printf()}` and `{@link System#putch()}` + * + * Places the character into an internal buffer. The `{@link #flush}` + * sends the internal buffer to the `{@link #outputFxn}` function. + * The internal buffer is also sent to the `SysMin_outputFxn` + * function by `{@link #exit}` and `{@link #abort}` if the + * `{@link #flushAtExit}` configuration parameter is true. + * + * @see ISystemSupport#putch + */ + override Void putch(Char ch); + + /*! + * ======== ready ======== + * Test if character output can proceed + * + * This function returns true if the internal buffer is non-zero. + * + * @see ISystemSupport#ready + */ + override Bool ready(); + +internal: + + struct LineBuffer { + UInt lineidx; /* index within linebuf to write next Char */ + Char linebuf[LINEBUFSIZE]; /* local line buffer */ + } + + struct Module_State { + LineBuffer lineBuffers[]; /* internal line buffers */ + Char outbuf[]; /* the output buffer */ + UInt outidx; /* index within outbuf to next Char to write */ + Bool getTime; /* set to true for each new trace */ + Bool wrapped; /* has the index (outidx) wrapped */ + UInt writeidx[]; /* index to the last "\n" char */ + UInt readidx[]; /* index to the last char read by external + * observer */ + } +} diff --git a/packages/ti/trace/SysMin.xdt b/packages/ti/trace/SysMin.xdt new file mode 100644 index 0000000..7e456a8 --- /dev/null +++ b/packages/ti/trace/SysMin.xdt @@ -0,0 +1,42 @@ +%%{ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + * +*/ +%%} +%var SysMin = xdc.module("ti.trace.SysMin"); +%if (SysMin.bufSize != 0) { + +#pragma DATA_SECTION(ti_trace_SysMin_Module_State_0_outbuf__A, ".tracebuf"); +#pragma DATA_SECTION(ti_trace_SysMin_Module_State_0_readidx__A, ".tracebuf"); +#pragma DATA_SECTION(ti_trace_SysMin_Module_State_0_writeidx__A, ".tracebuf"); + +%} /* bufSize != 0 */ diff --git a/packages/ti/trace/SysMin.xs b/packages/ti/trace/SysMin.xs new file mode 100644 index 0000000..60ce92b --- /dev/null +++ b/packages/ti/trace/SysMin.xs @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2008-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + */ +/* + * ======== SysMin.xs ======== + */ + +var SysMin = this; +var Core = null; + +/* + * ======== module$static$init ======== + */ +function module$static$init(obj, params) +{ + var segname = Program.sectMap[".tracebuf"]; + var segment = Program.cpu.memoryMap[segname]; + + if (params.bufSize > segment.len) { + this.$logError("bufSize 0x" + Number(params.bufSize).toString(16) + + " configured is too large, maximum bufSize allowed is " + + "0x" + Number(segment.len).toString(16) + ". Decrement" + + " the bufSize appropriately.", this); + } + + if (params.bufSize - 8 < this.LINEBUFSIZE) { + this.$logError("Buffer Size need to be larger than line buffer of size" + + " = 0x" + Number(this.LINEBUFSIZE).toString(16), this); + } + + if (Program.platformName.match(/ipu/)) { + obj.lineBuffers.length = Core.numCores; + } + else { + obj.lineBuffers.length = 1; + } + for (var i = 0; i < obj.lineBuffers.length; i++) { + obj.lineBuffers[i].lineidx = 0; + for (var j = 0; j < this.LINEBUFSIZE; j++) { + obj.lineBuffers[i].linebuf[j] = 0; + } + } + + obj.outbuf.length = params.bufSize - 8; + obj.writeidx.length = 0x1; + obj.readidx.length = 0x1; + if (params.bufSize != 0) { + var Memory = xdc.module('xdc.runtime.Memory'); + Memory.staticPlace(obj.outbuf, 0x1000, params.sectionName); + Memory.staticPlace(obj.writeidx, 0x4, params.sectionName); + Memory.staticPlace(obj.readidx, 0x4, params.sectionName); + } + + obj.outidx = 0; + obj.getTime = false; + obj.wrapped = false; +} + +/* + * ======== module$use ======== + */ +function module$use(obj, params) +{ + if (Program.platformName.match(/ipu/)) { + Core = xdc.module("ti.sysbios.hal.Core"); + } +} + +/* + * ======== viewInitModule ======== + * + */ +function viewInitModule(view, mod) +{ + view.outBuf = mod.outbuf; + view.outBufIndex = mod.outidx; + view.wrapped = mod.wrapped; +} + +/* + * ======== viewInitOutputBuffer ======== + * Displays the contents of SysMin's output buffer in ROV. + */ +function viewInitOutputBuffer(view) +{ + var Program = xdc.useModule('xdc.rov.Program'); + + /* + * Retrieve the module's state. + * If this throws an exception, just allow it to propogate up. + */ + var rawView = Program.scanRawView('ti.trace.SysMin'); + + /* + * If the buffer has not wrapped and the index of the next character to + * write is 0, then the buffer is empty, and we can just return. + */ + if (!rawView.modState.wrapped && (rawView.modState.outidx == 0)) { + view.elements = new Array(); + return; + } + + /* Get the buffer size from the configuration. */ + var bufSize = Program.getModuleConfig('ti.trace.SysMin').bufSize; + + /* Read in the outbuf */ + var outbuf = null; + try { + outbuf = Program.fetchArray(rawView.modState.outbuf$fetchDesc, + rawView.modState.outbuf, bufSize); + } + /* If there's a problem, just re-throw the exception. */ + catch (e) { + throw ("Problem reading output buffer: " + e.toString()); + } + + /* + * We will create a new view element for each string terminated in a + * newline. + */ + var elements = new Array(); + + /* Leftover characters from each read which did not end in a newline. */ + var leftover = ""; + + /* If the output buffer has wrapped... */ + if (rawView.modState.wrapped) { + /* Read from outidx to the end of the buffer. */ + var leftover = readChars("", outbuf, rawView.modState.outidx, + outbuf.length - 1, elements); + } + + /* Read from the beginning of the buffer to outidx */ + leftover = readChars(leftover, outbuf, 0, rawView.modState.outidx - 1, + elements); + + /* + * If there are any leftover characters not terminated in a newline, + * create an element for these and display them. + */ + if (leftover != "") { + var elem = Program.newViewStruct('ti.trace.SysMin', + 'OutputBuffer'); + elem.entry = leftover; + elements[elements.length] = elem; + } + + view.elements = elements; +} + +/* + * ======== readChars ======== + * Reads characters from 'buffer' from index 'begin' to 'end' and adds + * any newline-terminated strings as elements to the 'elements' array. + * If the last character is not a newline, this function returns what it's + * read from the "incomplete" string. + * The string 'leftover', the leftover incomplete string from the previous + * call, is prepended to the first string read. + */ +function readChars(leftover, buffer, begin, end, elements) +{ + /* Start with the previous incomplete string. */ + var str = leftover; + + /* For each of the specified characters... */ + for (var i = begin; i <= end; i++) { + + /* Convert the target values to characters. */ + var ch = String.fromCharCode(buffer[i]); + + /* Add the character to the current string. */ + str += ch; + + /* + * If a string ends in a newline, create a separate table entry for it. + */ + if (ch == '\n') { + /* + * Create a view structure to display the string, and add + * it to the table. + */ + var elem = Program.newViewStruct('ti.trace.SysMin', + 'OutputBuffer'); + elem.entry = str; + elements[elements.length] = elem; + + /* Reset the string */ + str = ""; + } + } + + /* Return any unfinished string characters. */ + return (str); +} diff --git a/packages/ti/trace/package.bld b/packages/ti/trace/package.bld new file mode 100644 index 0000000..cc20599 --- /dev/null +++ b/packages/ti/trace/package.bld @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + */ + +/* + * ======== package.bld ======== + * + */ + +/* explicit references to global objects */ +var Build = xdc.useModule('xdc.bld.BuildEnvironment'); +var Pkg = xdc.useModule('xdc.bld.PackageContents'); +var smpBuild = java.lang.System.getenv("BUILD_SMP"); + +/* clean lib folder */ +Pkg.generatedFiles.$add("lib/"); +Pkg.libDir = "package/"; + +/* add custom files to all releases */ +Pkg.attrs.exportSrc = false; +Pkg.attrs.exportCfg = true; +Pkg.otherFiles = [ + "SysMin.h", +]; + +/* list of libraries to build */ +var libArray = new Array(); +if (smpBuild == "1") { + /* trace library for IPU SMP target */ + libArray.push( + { + name: "ti.trace_smp", + sources: [ + "SysMin.c", + ], + libAttrs: { + defs: " -DSMP" + }, + isas: [ "v7M" ], + } + ); +} +else { + /* trace library for regular targets */ + libArray.push( + { + name: "ti.trace", + sources: [ + "SysMin.c", + ], + } + ); +} + +/* generate the package libraries */ +/* check if profile specified in XDCARGS */ +/* XDCARGS="... profile=debug ..." */ +var cmdlProf = (" " + arguments.join(" ") + " ").match(/ profile=([^ ]+) /); +cmdlProf = cmdlProf != null ? cmdlProf[1] : null; + +/* ==== loop over array of libraries ==== */ +for (var i = 0; i < libArray.length; i++) { + var lib = libArray[i]; + + /* ==== loop over all targets in build array ==== */ + for (var j = 0; j < Build.targets.length; j++) { + var targ = Build.targets[j]; + + /* invoke user supplied target predicate function */ + if (this.skipTarget != undefined) { + continue; + } + + /* skip target if not compatible with source code */ + if ("icw" in lib) { + var skipTarget = true; + var targIsaChain = "/" + targ.getISAChain().join("/") + "/"; + for (var k = 0; k < lib.icw.length; k++) { + if (targIsaChain.match("/" + lib.icw[k] + "/")) { + skipTarget = false; + break; + } + } + if (skipTarget) continue; + } + + /* skip target if it does not generate code for the given isa */ + if ("isas" in lib) { + var skipTarget = true; + var list = "/" + lib.isas.join("/") + "/"; + if (list.match("/" + targ.isa + "/")) { + skipTarget = false; + } + if (skipTarget) continue; + } + + /* ==== loop over all profiles ==== */ + for (var profile in targ.profiles) { + + /* skip profile if different than specified on command line */ + if ((cmdlProf != null) && (profile != cmdlProf)) { + continue; + } + + /* name = lib/profile/name.a+suffix */ + var name = "lib/" + profile + "/" + lib.name; + + /* pass along library attributes specified in library array */ + var libAttrs = "libAttrs" in lib ? lib.libAttrs : {}; + + /* must set profile explicitly */ + libAttrs.profile = profile; + + /* build the library */ + var library = Pkg.addLibrary(name, targ, libAttrs); + + /* add the source files */ + library.addObjects(lib.sources); + } + } +} diff --git a/packages/ti/trace/package.xdc b/packages/ti/trace/package.xdc new file mode 100644 index 0000000..42bbe27 --- /dev/null +++ b/packages/ti/trace/package.xdc @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + * + */ + +/* + * ======== package.xdc ======== + * + */ + +package ti.trace [0,0,0] { + module SysMin; +}; diff --git a/packages/ti/trace/package.xs b/packages/ti/trace/package.xs new file mode 100644 index 0000000..ef39be8 --- /dev/null +++ b/packages/ti/trace/package.xs @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011-2013, Texas Instruments Incorporated + * 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 Texas Instruments Incorporated 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. + */ + +/* + * ======== package.xs ======== + * + */ + +/* + * ======== getLibs ======== + */ +function getLibs(prog) +{ + var suffix; + var file; + var libAry = []; + var profile = this.profile; + var smp = ""; + + suffix = prog.build.target.findSuffix(this); + if (suffix == null) { + return ""; /* nothing to contribute */ + } + + if (prog.platformName.match(/ipu/)) { + smp = "_smp"; + } + + /* make sure the library exists, else fallback to a built library */ + file = "lib/" + profile + "/ti.trace" + smp + ".a" + suffix; + if (java.io.File(this.packageBase + file).exists()) { + libAry.push(file); + } + else { + file = "lib/release/ti.trace" + smp + ".a" + suffix; + if (java.io.File(this.packageBase + file).exists()) { + libAry.push(file); + } + else { + /* fallback to a compatible library built by this package */ + for (var p in this.build.libDesc) { + if (suffix == this.build.libDesc[p].suffix) { + libAry.push(p); + break; + } + } + } + } + + return libAry.join(";"); +} -- 2.39.2