blob: 208ced67cb510c9cd9526662019afc2fc7c70b86 [file] [log] [blame]
/* --COPYRIGHT--,ESD
* Copyright (c) 2008 Texas Instruments. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License
* v. 1.0 which accompanies this distribution. The Eclipse Public License is
* available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
* Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Texas Instruments - initial implementation
* --/COPYRIGHT--*/
/*
* ======== SysMin.c ========
*/
#include <xdc/runtime/Startup.h>
#include <xdc/runtime/Gate.h>
#include <string.h>
#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);
}
return (Startup_DONE);
}
/*
* ======== SysMin_abort ========
*/
Void SysMin_abort(CString 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_putch ========
*/
Void SysMin_putch(Char ch)
{
IArg key;
if (SysMin_bufSize != 0) {
key = Gate_enterSystem();
module->outbuf[module->outidx++] = ch;
if (module->outidx == SysMin_bufSize) {
module->outidx = 0;
module->wrapped = TRUE;
}
Gate_leaveSystem(key);
}
}
/*
* ======== SysMin_ready ========
*/
Bool SysMin_ready(Void)
{
return (SysMin_bufSize != 0);
}
/*
* ======== SysMin_flush ========
* Called during SysMin_exit, System_exit or System_flush.
*/
Void SysMin_flush(Void)
{
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);
}