Fixed IAR embedded workbench atmega168 project by allocating more CSTACK space. Simplified the iar/gcc compatibility.
This commit is contained in:
@@ -138,6 +138,63 @@ static void input_switch_read(
|
||||
}
|
||||
}
|
||||
|
||||
/* stack checking */
|
||||
#if STACK_CHECK_ENABLED
|
||||
#if defined(__GNUC__)
|
||||
extern uint8_t _end;
|
||||
extern uint8_t __stack;
|
||||
#define STACK_CANARY (0xC5)
|
||||
void StackPaint(void) __attribute__ ((naked)) __attribute__ ((section (".init1")));
|
||||
|
||||
void StackPaint(void)
|
||||
{
|
||||
#if 0
|
||||
uint8_t *p = &_end;
|
||||
|
||||
while(p <= &__stack)
|
||||
{
|
||||
*p = STACK_CANARY;
|
||||
p++;
|
||||
}
|
||||
#else
|
||||
__asm volatile (" ldi r30,lo8(_end)\n"
|
||||
" ldi r31,hi8(_end)\n"
|
||||
" ldi r24,lo8(0xc5)\n" /* STACK_CANARY = 0xc5 */
|
||||
" ldi r25,hi8(__stack)\n"
|
||||
" rjmp .cmp\n"
|
||||
".loop:\n"
|
||||
" st Z+,r24\n"
|
||||
".cmp:\n"
|
||||
" cpi r30,lo8(__stack)\n"
|
||||
" cpc r31,r25\n"
|
||||
" brlo .loop\n"
|
||||
" 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];
|
||||
int main(
|
||||
void)
|
||||
@@ -159,6 +216,9 @@ 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();
|
||||
|
||||
Reference in New Issue
Block a user