Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers template.c Source File

template.c

00001 int stackUsage_Template()
00002 {
00003     char* stackArr = NULL;
00004     int i = 0;
00005     int stackUsageCounter = 0;
00006     bool detectChange = false;
00007     char borderArr[BORDER_ARRAY_SIZE]; //Used to mark the border of a stack frame.
00008     for(i=0; i < BORDER_ARRAY_SIZE; ++i)
00009     {
00010         borderArr[i] = INIT_VALUE;
00011     }
00012     stackArr = paintStack();
00013     Template_Func();
00014     // The size of the second array is: 3*STACK_UNIT_SIZE.
00015     // so we need to run over the array to detect the first changed byte.
00016     // once we detect this byte, we can calculate the maximum stack usage.
00017     for (i = 0 ; i < STACK_UNIT_NUM*STACK_UNIT_SIZE && !detectChange; ++i)
00018     {
00019         if(stackArr[i] != ((memPattern[i%PATTERN_SIZE]) ^ (i%MAX_CHAR_VALUE)))
00020         {
00021             detectChange = true;
00022         }
00023     }
00024     stackUsageCounter = STACK_UNIT_NUM*STACK_UNIT_SIZE - i;
00025     stackArr = stackArr + STACK_UNIT_NUM * STACK_UNIT_SIZE;
00026     for (; stackArr != borderArr; ++stackArr)
00027     {
00028         ++stackUsageCounter;
00029     }
00030     return stackUsageCounter;
00031 }