/* * ======== SysMin_putch ======== */ Void SysMin_putch(Char ch) { UInt coreId; UInt outidx; UInt i; Char *outbuf; IArg key; if (SysMin_bufSize != 0) { /* * only disable local interrupts to place chars in * local line buffer */ key = (IArg)Core_hwiDisable(); coreId = Core_getId(); outidx = module->lineBuffers[coreId].outidx; outbuf = module->lineBuffers[coreId].outbuf; outbuf[outidx++] = ch; SysMin_module->lineBuffers[coreId].outidx = outidx; /* At EOL, copy core's line buffer to shared outbuf */ if ((ch == '\n') || (outidx >= 256)) { /* * disable interrupts globally to transfer lines * to the shared output buffer */ Gate_enterSystem(); for (i = 0; i < outidx; i++) { module->outbuf[module->outidx++] = outbuf[i]; if (module->outidx == SysMin_bufSize) { module->outidx = 0; module->wrapped = TRUE; } } SysMin_module->lineBuffers[coreId].outidx = 0; Gate_leaveSystem(key); } else { /* restore local interrupts */ Core_hwiRestore((UInt)key); } } }
/* * ======== Swi_disable ======== */ UInt Swi_disable() { UInt key, hwiKey; hwiKey = Hwi_disable(); key = Swi_module->locked; Swi_module->locked = TRUE; Core_hwiRestore(hwiKey); return (key); }
/* * ======== 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() * (UInt64)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 } }