9 #include "NetworkCommunication/FRCComm.h"
10 #include "ChipObject.h"
14 #include <sysSymTbl.h>
17 #define DBG_DEMANGLE_PRINT_LEN 256
21 extern char * cplusDemangle (
char *source,
char *dest, int32_t n);
24 char *wpi_getLabel(UINT addr, int32_t *found)
28 char name[MAX_SYS_SYM_LEN + 1];
29 static char label[DBG_DEMANGLE_PRINT_LEN + 1 + 11];
30 bzero(label, DBG_DEMANGLE_PRINT_LEN + 1 + 11);
32 if (symFindByValue(sysSymTbl, addr, name, &pVal, &pType) == OK)
34 cplusDemangle(name, label,
sizeof(label) - 11);
35 if ((UINT)pVal != addr)
37 sprintf(&label[strlen(label)],
"+0x%04x", addr-pVal);
38 if (found) *found = 2;
42 if (found) *found = 1;
47 sprintf(label,
"0x%04x", addr);
48 if (found) *found = 0;
72 static void wpiCleanTracePrint(INSTR *caller, int32_t func, int32_t nargs, int32_t *args, int32_t taskId, BOOL isKernelAdrs)
74 char buf [MAX_SYS_SYM_LEN];
77 int32_t nameFound = 0;
79 int32_t totalnargs = nargs;
80 char *funcName = wpi_getLabel((UINT)func, &nameFound);
82 if (nameFound != 1)
return;
85 if (strncmp(funcName,
"wpi_assert", 10) == 0)
return;
86 if (strncmp(funcName,
"wpi_fatal", 9) == 0)
return;
87 if (strncmp(funcName,
"wpi_selfTrace", 13) == 0)
return;
88 if (strncmp(funcName,
"Error::Set", 10) == 0)
return;
89 if (strncmp(funcName,
"ErrorBase::SetError", 19) == 0)
return;
90 if (strncmp(funcName,
"Error::Report", 13) == 0)
return;
93 char *start = strchr(funcName,
'(');
94 char *end = strrchr(funcName,
')');
95 if (start + 1 != end && start != NULL)
100 if(strncmp(start+1,
"bool", 4) == 0 || strncmp(start+2,
"bool", 4) == 0)
104 start = strchr(start + 1,
',');
106 while(start < end && start != NULL);
108 char *funcNameEnd = strchr(funcName,
'(');
110 len += sprintf (&buf [len], funcName);
113 if (totalnargs - params == 1)
115 len += sprintf (&buf [len],
"<this=%#lx>", args [0]);
119 len += sprintf (&buf [len],
"(");
120 for (ix = totalnargs - params; ix < nargs; ix++)
122 if (ix != totalnargs - params)
123 len += sprintf (&buf [len],
", ");
124 len += sprintf (&buf [len],
"%#lx", args [ix]);
126 len += sprintf (&buf [len],
")\n");
133 extern void trcStack(REG_SET* pRegs, FUNCPTR printRtn, int32_t tid);
136 static int32_t wpiStackTask(int32_t taskId)
142 taskRegsGet(taskId, ®s);
143 trcStack(®s, (FUNCPTR) wpiCleanTracePrint, taskId);
154 taskPriorityGet(0, &priority);
156 Task traceTask(
"StackTrace", (FUNCPTR)wpiStackTask, priority + 1);
157 traceTask.Start(taskIdSelf());
163 static bool stackTraceEnabled =
false;
164 static bool suspendOnAssertEnabled =
false;
169 void wpi_stackTraceOnAssertEnable(
bool enabled)
171 stackTraceEnabled = enabled;
180 void wpi_suspendOnAssertEnabled(
bool enabled)
182 suspendOnAssertEnabled = enabled;
185 static void wpi_handleTracing()
187 if (stackTraceEnabled)
189 printf(
"\n-----------<Stack Trace>----------------\n");
200 bool wpi_assert_impl(
bool conditionValue,
201 const char *conditionText,
203 const char *fileName,
205 const char *funcName)
214 if(message != NULL) {
215 sprintf(error,
"Assertion failed: \"%s\", \"%s\" failed in %s() in %s at line %ld\n",
216 message, conditionText, funcName, fileName, lineNumber);
218 sprintf(error,
"Assertion failed: \"%s\" in %s() in %s at line %ld\n",
219 conditionText, funcName, fileName, lineNumber);
223 printf(
"\n\n>>>>%s", error);
224 setErrorData(error, strlen(error), 100);
227 if (suspendOnAssertEnabled) taskSuspend(0);
229 return conditionValue;
237 void wpi_assertEqual_common_impl(
int valueA,
239 const char *equalityType,
241 const char *fileName,
243 const char *funcName)
250 if(message != NULL) {
251 sprintf(error,
"Assertion failed: \"%s\", \"%d\" %s \"%d\" in %s() in %s at line %ld\n",
252 message, valueA, equalityType, valueB, funcName, fileName, lineNumber);
254 sprintf(error,
"Assertion failed: \"%d\" %s \"%d\" in %s() in %s at line %ld\n",
255 valueA, equalityType, valueB, funcName, fileName, lineNumber);
259 printf(
"\n\n>>>>%s", error);
260 setErrorData(error, strlen(error), 100);
263 if (suspendOnAssertEnabled) taskSuspend(0);
272 bool wpi_assertEqual_impl(
int valueA,
275 const char *fileName,
277 const char *funcName)
279 if(!(valueA == valueB))
281 wpi_assertEqual_common_impl(valueA, valueB,
"!=", message, fileName, lineNumber, funcName);
283 return valueA == valueB;
292 bool wpi_assertNotEqual_impl(
int valueA,
295 const char *fileName,
297 const char *funcName)
299 if(!(valueA != valueB))
301 wpi_assertEqual_common_impl(valueA, valueB,
"==", message, fileName, lineNumber, funcName);
303 return valueA != valueB;
312 uint16_t GetFPGAVersion()
314 tRioStatusCode status = 0;
315 tGlobal *global = tGlobal::create(&status);
316 uint16_t version = global->readVersion(&status);
318 wpi_setGlobalError(status);
330 uint32_t GetFPGARevision()
332 tRioStatusCode status = 0;
333 tGlobal *global = tGlobal::create(&status);
334 uint32_t revision = global->readRevision(&status);
336 wpi_setGlobalError(status);
345 uint32_t GetFPGATime()
347 tRioStatusCode status = 0;
348 tGlobal *global = tGlobal::create(&status);
349 uint32_t time = global->readLocalTime(&status);
351 wpi_setGlobalError(status);
358 int32_t UserSwitchInput(int32_t nSwitch);
359 int32_t LedInput(int32_t led);
360 int32_t LedOutput(int32_t led, int32_t value);
366 int32_t GetRIOUserSwitch()
368 int32_t switchValue = UserSwitchInput(0);
369 wpi_assert(switchValue >= 0);
370 return switchValue > 0;
376 void SetRIOUserLED(uint32_t state)
378 LedOutput(0, state > 0);
385 int32_t GetRIOUserLED()
394 int32_t ToggleRIOUserLED()
396 int32_t ledState = !GetRIOUserLED();
397 SetRIOUserLED(ledState);
404 void SetRIO_FPGA_LED(uint32_t state)
406 tRioStatusCode status = 0;
407 tGlobal *global = tGlobal::create(&status);
408 global->writeFPGA_LED(state, &status);
409 wpi_setGlobalError(status);
417 int32_t GetRIO_FPGA_LED()
419 tRioStatusCode status = 0;
420 tGlobal *global = tGlobal::create(&status);
421 bool ledValue = global->readFPGA_LED(&status);
422 wpi_setGlobalError(status);
431 int32_t ToggleRIO_FPGA_LED()
433 int32_t ledState = !GetRIO_FPGA_LED();
434 SetRIO_FPGA_LED(ledState);