#72 BricxCC internal compiler NBC/NXC error

compiler
closed-invalid
BricxCC (17)
5
2009-09-05
2009-09-05
Anonymous
No

BricxCC (build 3.3.7.20)
internal NBC/NXC compiler with options: Use internal compiler, Enhanced firmware, NXT 2.0 compatible firmware, Opt level 1

when I compiled following code 3 problems happens:

1) if you start raw code, NXT motor on port B doesn't work.
2) if you add inline to bool function "program_was_stopped" then program doesn't work correctly after you activate TOUCH sensor 1 and then press button CENTER. The TextOut "The End" doesn't appear.
3) if you add inline to scan_head function too then all works perfectly.

I think that this means some bug or bugs in compiler.

#define HEAD_SPEED 30
#define SCAN_ANGLE 60

bool program_stopped = false;
mutex stopMutex;

bool program_was_stopped ()
{
Acquire(stopMutex);
bool state = program_stopped;
Release(stopMutex);
return state;
}

safecall void move_head (int abs_angle)
{
int a = GetOutput(OUT_B,RotationCount);
RotateMotor(OUT_B, HEAD_SPEED, abs_angle-a);
}

void scan_head ()
{
move_head(-SCAN_ANGLE);
move_head(SCAN_ANGLE);
move_head(0);
}

task ultrasonic_moving_head ()
{
until (program_was_stopped()) {
move_head(-SCAN_ANGLE/10);
move_head(SCAN_ANGLE/10);
}

TextOut(0,LCD_LINE1,"The END",true);
Wait(1000);
move_head(0);
}

task button_test ()
{
until (ButtonPressed(BTNCENTER,true)) {
Wait(100);
}
Acquire(stopMutex);
program_stopped = true;
Release(stopMutex);
}

task motion_control()
{
until (program_was_stopped()) {
if (SENSOR_1 > 0) {
scan_head();
}
}
}

task main()
{
SetSensor(IN_1,SENSOR_TOUCH);
SetSensorMode(IN_1, SENSOR_MODE_BOOL);
Precedes(ultrasonic_moving_head,
button_test,
motion_control);
}

Discussion

  • John Hansen

    John Hansen - 2009-09-05

    Subroutines that are called by more than one task must be mared as safecall or inline or your program will not run correctly. Writing multi-threaded code that works correctly can be tricky. This is definitely not a compiler bug.

     
  • John Hansen

    John Hansen - 2009-09-05
    • status: open --> closed-invalid
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks