Skip to content

Commit

Permalink
randomTest() added
Browse files Browse the repository at this point in the history
randomtest.ini is completed and tested
  • Loading branch information
Vasileios Bimpikas committed Apr 3, 2015
1 parent 6b2a0ec commit bd60d0d
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lab_env_Target 1.dep
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ I (.\STM32F10xFWLib\inc\stm32f10x_type.h)(0x4D3B2BDE)
I (.\STM32F10xFWLib\inc\cortexm3_macro.h)(0x4D3B2BDE)
I (.\STM32F10xFWLib\inc\stm32f10x_rcc.h)(0x4D3B2BDE)
F (.\STM32F10xFWLib\src\cortexm3_macro_rvds.s)(0x4D3B2BDE)(--cpu Cortex-M3 --pd "__EVAL SETA 1" -g --apcs=interwork --pd "__MICROLIB SETA 1"-I C:\Keil_v5\ARM\RV31\INC-I C:\Keil_v5\ARM\CMSIS\Include-I C:\Keil_v5\ARM\Inc\ST\STM32F10x--pd "__UVISION_VERSION SETA 513"--list .\cortexm3_macro_rvds.lst --xref -o .\cortexm3_macro_rvds.o --depend .\cortexm3_macro_rvds.d)
F (.\main.c)(0x551AA5C4)(-c --cpu Cortex-M3 -D__EVAL -D__MICROLIB -g -O0 --apcs=interwork -I..\CORTEX_STM32F103_Keil -I.\STM32F10xFWLib\inc -I.\FreeRTOS\inc -I.-I C:\Keil_v5\ARM\RV31\INC-I C:\Keil_v5\ARM\CMSIS\Include-I C:\Keil_v5\ARM\Inc\ST\STM32F10x-D__UVISION_VERSION="513" -DRVDS_ARMCM3_LM3S102-o .\main.o --omf_browse .\main.crf --depend .\main.d)
F (.\main.c)(0x551E8BD7)(-c --cpu Cortex-M3 -D__EVAL -D__MICROLIB -g -O0 --apcs=interwork -I..\CORTEX_STM32F103_Keil -I.\STM32F10xFWLib\inc -I.\FreeRTOS\inc -I.-I C:\Keil_v5\ARM\RV31\INC-I C:\Keil_v5\ARM\CMSIS\Include-I C:\Keil_v5\ARM\Inc\ST\STM32F10x-D__UVISION_VERSION="513" -DRVDS_ARMCM3_LM3S102-o .\main.o --omf_browse .\main.crf --depend .\main.d)
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x54766380)
I (.\FreeRTOS\inc\FreeRTOS.h)(0x4D3B2BDE)
I (C:\Keil_v5\ARM\ARMCC\include\stddef.h)(0x54766380)
Expand Down
Binary file modified main.crf
Binary file not shown.
Binary file modified main.o
Binary file not shown.
119 changes: 119 additions & 0 deletions randomtest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// randomTest(); simulateCarMotor();

SIGNAL void randomTest()
{
int pos;
int i, j;
int lastPulsePinValue;
int reached1, reached2, reached3;
int requested1, requested2, requested3; // 1 if a call has been made to this floor
int at_floor;

// Random variables
int randButton, initFeed, random, count, delay;

reached1 = 0;
reached2 = 0;
reached3 = 0;
requested1 = 0;
requested2 = 0;
requested3 = 0;
pos = 0;
count = 0;
at_floor = 0;

// Initially feed the random variable
initFeed = rand(0xAB21);
printf("initFeed: %d\n", initFeed);
random = rand(initFeed);

printf("randomTest() is running\n");
while(1) // run forever
{
// Get a random value at every iteration depending on counter
random = rand(count + random); // counter's number is arbitary (because we're starting with random delay)
delay = random % 5; // 0 to 5 sec (maximum) delay

// call from random floor
randButton = rand(count + random) % 3;
PORTC |= 1 << randButton;

// register that a call to this floor has been made
if(randButton == 0)
requested1 = 1;
else if(randButton == 1)
requested2 = 1;
else
requested3 = 1;

// close the doors
PORTC |= 1 << 8;

swatch(0.0025);
// reset the pin (button)
PORTC ^= 1 << randButton;


// delay for the generated amount of time
while(j < delay)
j++;
j = 0;
at_floor = 0;
// every second, check whether we are at a floor
if ((PORTC & (1 << 7)) && !TIM3_CCR1 && !TIM3_CCR2)
{
if (pos >= -1 && pos <= 1 && !reached1) {
// reached floor 1
printf("arrived at floor 1\n");
reached1 = 1;
if(!requested1)
printf("Unnecessary stop!\n");
requested1 = 0; // served
at_floor = 1;
}
if (pos >= 399 && pos <= 401 && !reached2) {
// reached floor 2
printf("arrived at floor 2\n");
reached2 = 1;
if(!requested2)
printf("Unnecessary stop!\n");
requested2 = 0; // served
at_floor = 1;
}
if (pos >= 799 && pos <= 801 && !reached3) {
// reached floor 3
printf("arrived at floor 3\n");
reached3 = 1;
if(!requested3)
printf("Unnecessary stop!\n");
requested3 = 0; // served
at_floor = 1;
}
}


if (TIM3_CCR1 || TIM3_CCR2) // if the elevator is moving, nothing has been reached
{
reached1 = 0;
reached2 = 0;
reached3 = 0;
}

// if we have stopped at a floor, we open the doors for 1s
if (at_floor)
PORTC ^= 1 << 8;

// wait 1s
for (i = 0; i < 400; ++i) {
if (lastPulsePinValue < (PORTC & (1 << 9)))
pos += TIM3_CCR1 ? 1 : -1;
lastPulsePinValue = PORTC & (1 << 9);
swatch(0.0025);
}

// close the doors
PORTC |= 1 << 8;

count++; // increment the counter. Used as rand() feed. Overflow of this counter is desired (more random values)
}
}
3 changes: 3 additions & 0 deletions stm32_exec.build_log.htm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h2>Project:</h2>

<h2>Output:</h2>
Build target 'Target 1'
compiling main.c...
linking...
Program Size: Code=16192 RO-data=304 RW-data=240 ZI-data=18208
".\stm32_exec.axf" - 0 Error(s), 0 Warning(s).
</pre>
</body>
Expand Down
2 changes: 1 addition & 1 deletion stm32_exec.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>Static Call Graph - [.\stm32_exec.axf]</title></head>
<body><HR>
<H1>Static Call Graph for image .\stm32_exec.axf</H1><HR>
<BR><P>#&#060CALLGRAPH&#062# ARM Linker, 5050106: Last Updated: Fri Apr 03 11:49:52 2015
<BR><P>#&#060CALLGRAPH&#062# ARM Linker, 5050106: Last Updated: Fri Apr 03 14:47:20 2015
<BR><P>
<H3>Maximum Stack Usage = 216 bytes + Unknown(Functions without stacksize, Cycles, Untraceable Function Pointers)</H3><H3>
Call chain for Maximum Stack Depth:</H3>
Expand Down

0 comments on commit bd60d0d

Please sign in to comment.