Added CStack check to project by putting it into the device object as property 512. The compile shows 648 bytes of RAM used, and the device has 1024 bytes of RAM, leaving 376 for the CStack. Property 512 index 0 returns 376. So, my understanding is that the RAM that is not allocated to the variables is used for the CStack, something to keep in mind when developing. After some exercising, the stack shows 159 CStack bytes free, meaning that 216 bytes of CStack are used. Note that 0xC5 (197) was used to paint the CStack.

This commit is contained in:
skarg
2008-03-28 02:47:33 +00:00
parent 19910c90ce
commit 69e7992cd1
2 changed files with 41 additions and 26 deletions
+41
View File
@@ -160,6 +160,11 @@ bool Device_Object_List_Identifier(
return status;
}
#if defined(__GNUC__)
extern uint8_t _end;
extern uint8_t __stack;
#endif
/* return the length of the apdu encoded or -1 for error */
int Device_Encode_Property_APDU(
uint8_t * apdu,
@@ -321,6 +326,42 @@ int Device_Encode_Property_APDU(
apdu_len =
encode_application_unsigned(&apdu[0], RS485_Get_Baud_Rate());
break;
#if defined(__GNUC__)
case 512:
count = 1 + (&__stack) - (&_end);
if (array_index == 0) {
/* Array element zero is the number of bytes of stack */
apdu_len = encode_application_unsigned(&apdu[0], count);
} else if (array_index == BACNET_ARRAY_ALL) {
/* if no index was specified, then try to encode the entire list */
/* into one packet. Note that more than likely you will have */
/* to return an error if the number of encoded objects exceeds */
/* your maximum APDU size. */
for (i = 1; i <= count; i++) {
len =
encode_application_unsigned(&apdu[0], *(&_end+i));
apdu_len += len;
/* assume next one is the same size as this one */
/* can we all fit into the APDU? */
if ((apdu_len + len) >= MAX_APDU) {
*error_class = ERROR_CLASS_SERVICES;
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = -1;
break;
}
}
} else if (array_index <= count) {
apdu_len = encode_application_unsigned(&apdu[0], *(&_end+array_index));
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = -1;
}
break;
case 513:
apdu_len = encode_application_unsigned(&apdu[0], __stack);
break;
#endif
default:
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_UNKNOWN_PROPERTY;
-26
View File
@@ -139,7 +139,6 @@ static void input_switch_read(
}
/* stack checking */
#if STACK_CHECK_ENABLED
#if defined(__GNUC__)
extern uint8_t _end;
extern uint8_t __stack;
@@ -171,28 +170,6 @@ void StackPaint(void)
" breq .loop"::);
#endif
}
static uint16_t StackCount(void)
{
const uint8_t *p = &_end;
uint16_t c = 0;
while(*p == STACK_CANARY && p <= &__stack)
{
p++;
c++;
}
return c;
}
static void Analog_Value_Task(void)
{
extern float AV_Present_Value[MAX_ANALOG_VALUES];
AV_Present_Value[0] = (float)StackCount();
}
#endif
#endif
static uint8_t PDUBuffer[MAX_MPDU];
@@ -216,9 +193,6 @@ int main(
/* BACnet handling */
pdu_len = datalink_receive(&src, &PDUBuffer[0], sizeof(PDUBuffer), 0);
if (pdu_len) {
#if STACK_CHECK_ENABLED
Analog_Value_Task();
#endif
LED_NPDU_ON();
npdu_handler(&src, &PDUBuffer[0], pdu_len);
LED_NPDU_OFF();