Event Recorder  Version 1.0.0
MDK Debugger Views for Status and Event Information
 All Files Functions Macros Groups Pages
Expressions

Provide memory usage information

The SCVD interpreter has built-in evaluation for expressions that are used in various XML elements and attributes. An expression is a combination of operands and Operators that evaluate to a resulting value where the type of the result is derived from the expression.

An operand may be a numeric constant, a variable, a built-in function, a predefined variable, or an expression. Operators are used to combine and compare operands.

Operators

Operators combine and compare operands. Operators may be unary (requiring one operand) or binary (requiring two operands). The combination of an operator and its operands is an expression. Parentheses can be used in expressions with multiple operators to specify the order of evaluation. If no parentheses are used in an expression, then the operator precedence determines the evaluation order.

Operators Precedence Description
( ) 1 Parentheses can be used to specify the order of evaluation
.member 2 Type member
typedef_name:member:enum 2 Enumerator value; refer to enum
typedef_name:member 2 Type-member selector for use in __Offset_of intrinsic; refer to member
Unary +, Unary — 3 Unary plus or minus applied to the following operand
* / % 4 Multiplication, Division, or Modulo
+ — 5 Addition, Subtraction
<< >> 6 Shift left, Shift right
& | ^ 7 Binary AND, OR, XOR
== != > >= < <= 8 Comparisons
&& || 9 Logical AND, OR
e ? e : e 10 Conditional operator
= |= &= ^= += -= *= /= %= 11 Assignment operators
Todo:
Typedef references are weak
Note
Todo:
& and " require replacements....
  • Since the character & is reserved in XML, it is required to use &amp instead of &. for logical operations
  • use literally &quot; whenever this quote is not part of an XML structure

Examples:

<item property="Wait" cond="TCB[i].p_blnk &amp;&amp; TCB[i].State == Thread_CB:State:WaitingSemaphore" value="%S[TCB[i].p_blnk]" />
<item property="Round Robin Timeout" value="%T[((float) (rrobin &amp; 0xFFFF) * (float) clockrate / 1000)] mSec" />
<item property="__Symbol_exists (&quot;os_active_TCB&quot;)"
value="%t[__Symbol_exists (&quot;os_active_TCB&quot;) ? &quot;Yes&quot; : &quot;No&quot;]" />

Variables

Todo:
add info

Predefined Variables

Predefined variables can be used without a declaration or definition.

Predefined Variable Description
__Running Indicates program execution at target: 1=run, 0=stop
_count Counts the number of items in readlist and read elements.
_addr Returns the memory adress of a readlist member.

 

Built-in Functions

The SCVD has built-in mechanisms to evaluate Expressions in various XML elements and attributes for calculations.

The table lists the predefined functions:

Function Name Description
__CalcMemUsed Provide memory usage information
__FindSymbol Get numeric value of symbol
__GetRegVal Read CPU register value
__Symbol_exists Search for symbol
__Offset_of Get offset of type member

__CalcMemUsed

uint32_t __CalcMemUsed (uint32_t StackAddress, uint32_t StackSize, uint32_t FillPattern, uint32_t MagicValue)
Parameters
StackAddressStart address of memory area
StackSizeSize of memory area in Bytes
FillPatternInitial value of memory area, used to identify memory usage
MagicValueInitial value at end of memory area, used to identify memory (stack) overflow
Note
If MagicValue is not used, then supply the FillPattern value
Returns
A packed integer that indicates memory usage in bytes and percent and stack overflow:
  • Bit 0..19 Used memory in Bytes (FillPattern is overwritten)
  • Bit 20..28 Used memory in percent
  • Bit 31 Memory overflow (MagicValue is overwritten)

The function provides information about the memory usages and is typically applied for the stack memory of RTOS threads.

Example:

<!-- Stack Watermarking Check: __CalcMemUsed (stack_address, stackSize, FillPattern, MagicPattern at Stack-bottom) -->
<!-- Note: for the idle_tcb (the last tcb in TCB[]), no watermarking is available -->
<calc cond="TCB[i].ShowStackInfo && ((i != (TCB._count - 1)) && ((stackinfo >> 28) & 0x01))" >
StkUse = __CalcMemUsed (TCB[i].Stack, TCB[i].StackSize, 0xCCCCCCCC, 0xE25A2EA5);
TCB[i].StkOverflow = (StkUse & 0x80000000) ? 1 : 0;
TCB[i].StkUse &= ~0x80000000;
TCB[i].BytesUsed = (StkUse & 0xFFFFF);
TCB[i].Percentage = (StkUse >> 20) & 0xFF;
TCB[i].bSimpleStk = 0;
</calc>

__FindSymbol

int32_t __FindSymbol (char *symbol_name)

Get numeric value of symbol

Parameters
symbol_namePointer to the name of a public symbol (examples: "main", "os_active_TCB", ...).
Returns
  • runtime error When the symbol was not found.
  • symbol value Numeric value of the public symbol when the symbol was found.

The function searches for a public symbol and returns the numeric value of the symbol. If the symbol cannot be found, then a runtime error is thrown.


__GetRegVal

uint32_t __GetRegVal (char * RegisterName)

Read CPU register value

Parameters
RegisterNamePointer to the name of a CPU register: "PSP", "MSP", ....
Returns
Value of the CPU register

The function reads the value of a CPU register.


__Symbol_exists

int32_t __Symbol_exists (char *symbol_name)

Search for symbol

Parameters
symbol_namePointer to the name of a public symbol (examples: "main", "os_active_TCB", ...).
Returns
  • 1 for true - symbol found
  • 0 for false - symbol not found

The function searchs for a symbol in the application and returns 1 ehn the symblo was found, otherwise 0 for false.


__Offset_of

uint32_t __Offset_of (type typedef_mem_name)

Get offset of type member

Parameters
typedef_mem_nameIs the member name of a specified type and has the form typedef_name:typedef_member_name.
Returns
The offset value of the specified typedef member.

The function returns the offset value of the specified typedef member.

Example:

__Offset_of (Thread_CB:Task_ID)