2

I've been working on some RTOS MicroC project and whenever I've implemented some function it works just fine outside the task, but whenever I put in the task it just wouldn't do anything. I know I might not get answer to this, but any tips where to start looking would be a big help, thanks in advance.

a_sem = OSSemCreate(1);

static void AppTask1(void *p_arg)
{
    (void) p_arg;
    INT8U perr;
    while (1)
    {
        OSSemPend(a_sem, 0, &perr);
        planeAngles();// Functon that works outside the task
        OSSemPost(a_sem);
        OSTimeDly(OS_TICKS_PER_SEC/20);
    }
}

static void AppTask2(void *p_arg)
{
    (void) p_arg;
    INT8U perr;
    while (1)
    {
        OSSemPend(a_sem, 0, &perr);
        servoTurns(); // Functon that works outside the task
        OSSemPost(a_sem);
        OSTimeDly(OS_TICKS_PER_SEC/20);
    }
}
Ženia Bogdasic
  • 117
  • 1
  • 17

2 Answers2

2

Both tasks wait on a semaphore, but it is not clear where that semaphore is initially given. It seems likely that neither task ever returns from the OSSemPend call.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 1
    What do you mean by that "where that semaphore is initially given"? – Ženia Bogdasic Aug 09 '14 at 20:12
  • 1
    I mean the code fragment does not include code that sets the semaphore initially to allow the pend to exit on the first time it is exited. – Clifford Aug 09 '14 at 21:37
  • 1
    I guess you mean this:a_sem = OSSemCreate(1); – Ženia Bogdasic Aug 09 '14 at 21:41
  • 1
    @CookieDemon : Yes! So update the question to include the necessary information. The fact that both answers so far have picked up on the possibility that this is not done should tell you that the question is deficient if in fact you have done that. The point is that it is almost certainly not that these functions do nothing, but rather than they are not called at all - your debugger will tel you that by placing a breakpoint on these calls. – Clifford Aug 10 '14 at 09:20
1

Somewhere in your code, before AppTask1 and AppTask2 are created, you should have a line of code like this:

OSSemCreate(a_sem, 1, &perr);

You are creating a semaphore, a_sem with an initial value of 1 so that the first task that calls OSSemPend will successfully acquire the semaphore.

Also, you should not block forever on OSSemPend. Wait for awhile and then check the error status:

OSSemPend(a_sem, 10, &perr);
if(perr == OS_ERR_NONE)
{
    /* You have the semaphore */
}
else
{
    /* Error! Maybe a timeout */
}
Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46