industrialNETworXnetx

| 14.10.2008 | 11:26 | 11 replies

2 Task Example

Hallo,
i try to write an example for 2 Tasks.

TLR_RESULT TaskProcess_LedDemo(LEDDEMO_RSC_T FAR* ptRsc)
{
  TLR_RESULT  eRslt;        /* result */
  UINT        uiInput, uSysTim;
  int         iIndex,count;

count=0;

while(1)
{

Drv_PioGetInputs(ptRsc->tRem.hPioInOut, &uiInput); // Read the States of Switch S30

for(iIndex = 8; iIndex < 16; iIndex++ )
{
//check each bit and turn on/off the corresponding LED
if( (uiInput & (1< {
Drv_PioClearOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8)); // turn off the corresponding LED
}
else // switch is on
{
Drv_PioSetOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8)); // turn on the corresponding LED
}
}
count++;
if (count >= 1000)
{
count = 0;
rX_SysSleepTask(10);
}
};

rX_SysBlockTask("LedDemo");
return eRslt;
}
.......
TLR_RESULT TaskProcess_LedDemo2(LEDDEMO2_RSC_T FAR* ptRsc)
{
TLR_RESULT eRslt, erXRes; /* result */
UINT uiInput;
int iIndex,count2;
UINT systicks;
count2=0;

while(1)
{
Drv_PioGetInputs(ptRsc->tRem.hPioInOut, &uiInput); // Read the States of Switch S30
systicks = rX_SysGetSystemTicks();
for(iIndex = 8; iIndex < 16; iIndex++ )
{
//check each bit and turn on/off the corresponding LED
if( (uiInput & (1< {
Drv_PioClearOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8)); // turn off the corresponding LED
}
else // switch is on
{
Drv_PioSetOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8)); // turn on the corresponding LED
}
}

count2++;

};

rX_SysBlockTask("LedDemo2");
return eRslt;

}
......



But it does not work.



The function rX_SysGetSystemTicks() return always the value 0 .

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 14.10.2008 | 13:21

Hi,

strange. I made a test and it was working on my side.
Which rcX version are you using?

The first time, when I reach my breakpoint on the "systicks = rX_SysGetSystemTicks();" call, is the value "0". When I call this the 2nd time I have some numbers in it.

| 14.10.2008 | 13:29

OK it works now. I hade the error in the declaration from the interrupt.
Now i have another problem. how kan i call the function "rX_SysWakeupTask(Task1)" from Task2 .
Abslimo

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 14.10.2008 | 13:34

Call "rX_SysWakeupTask( RX_HANDLE hTsk )" in your 2nd Task and use the needed Handle from the 1st one.

| 14.10.2008 | 14:42

I have writen:

TLR_RESULT TaskProcess_LedDemo(LEDDEMO_RSC_T FAR* ptRsc)
{
  TLR_RESULT  eRslt;        /* result */
  UINT        uiInput, uSysTim;
  int         iIndex,count;
  UINT systicks;
  
  count=0;
  
  while(1) 
  {    
    
    Drv_PioGetInputs(ptRsc->tRem.hPioInOut, &uiInput);              // Read the States of Switch S30 
    systicks = rX_SysGetSystemTicks();
    for(iIndex = 8; iIndex < 16; iIndex++ )
    {
      //check each bit and turn on/off the corresponding LED 
      if( (uiInput & (1<tRem.hPioInOut, 1<<(iIndex+8));  // turn off the corresponding LED 
      } 
      else                                                          // switch is on  
      {
        Drv_PioSetOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8));    // turn on the corresponding LED 
      }
    }
    count++;
    if (count >= 100000)
    {
        count = 0;
        rX_SysSleepTask(100000);
    }        
  };
  rX_SysBlockTask("LedDemo");   //Man kann statt den Name des Tasks:( ptRsc->tLoc.hTsk ) schreiben.
  return eRslt;
}
.........
TLR_RESULT TaskProcess_LedDemo2(LEDDEMO2_RSC_T FAR* ptRsc)
{
  TLR_RESULT  eRslt, erXRes;        /* result */
  UINT        uiInput;
  int         iIndex,count2;
  UINT systicks2;
  
  count2=0;
  
  while(1) 
  {    
    Drv_PioGetInputs(ptRsc->tRem.hPioInOut, &uiInput);              // Read the States of Switch S30 
    systicks2 = rX_SysGetSystemTicks();
    for(iIndex = 8; iIndex < 16; iIndex++ )
    {
      //check each bit and turn on/off the corresponding LED 
      if( (uiInput & (1<tRem.hPioInOut, 1<<(iIndex+8));  // turn off the corresponding LED 
      } 
      else                                                          // switch is on  
      {
        Drv_PioSetOutputs(ptRsc->tRem.hPioInOut, 1<<(iIndex+8));    // turn on the corresponding LED 
      }
    }
    
    count2++;
    
     if (count2 >= 10000)
    {
        //rX_SysSleepTask(1);
        
        count2 = 0;
        
        erXRes = rX_SysWakeupTask(LedDemo);

}
};

rX_SysBlockTask("LedDemo2"); //Man kann statt den Name des Tasks:( ptRsc->tLoc.hTsk ) schreiben.
return eRslt;

}



But i get an Error:

arm-hitex-elf-ld.exe  -T.\netx_sdram.ld.tmp -static -( -lrcx -lc -lm -lgcc -) -o .\output\LedDemo.elf 
arm-hitex-elf-ld: cannot find .\output\LedDemo2_Process.o


If i instead

erXRes = rX_SysWakeupTask(LedDemo);

erXRes = rX_SysWakeupTask("LedDemo"); write, then the function does not work properly.

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 14.10.2008 | 14:48

Try

erXRes = rX_SysWakeupTask(ptRsc->tLoc.hTsk);

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 14.10.2008 | 15:07

  rX_SysBlockTask("LedDemo");   //Man kann statt den Name des Tasks:( ptRsc->tLoc.hTsk ) schreiben.

I am asking myself how this should work. Did you ever evaluate the return code? If you want to access the other task you will need the handle for this task, as you can see from the prototype of this function:

AP_Task.h

    RX_RESULT FAR   rX_SysBlockTask               (RX_HANDLE                    hTask); 

You can retrieve the handle of the other task by name via the function "rX_SysIdentifyTask" and use this handle for your wakeup call.

Regards

MT

| 14.10.2008 | 15:14

But i get an Error:

arm-hitex-elf-ld.exe  -T.\netx_sdram.ld.tmp -static -( -lrcx -lc -lm -lgcc -) -o .\output\LedDemo.elf 
arm-hitex-elf-ld: cannot find .\output\LedDemo2_Process.o

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 14.10.2008 | 15:15

Probably because your "LedDemo2_Process.c" does not compile?

Ever looked into the build window for errors?

Regards

MT

| 14.10.2008 | 16:06

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_   -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo2_Process.o .\Sources\LedDemo2_Process.c 
.\Sources\LedDemo2_Process.c: In function 'TaskProcess_LedDemo2':
.\Sources\LedDemo2_Process.c:106: error: 'ptRsc' undeclared (first use in this function)
.\Sources\LedDemo2_Process.c:106: error: (Each undeclared identifier is reported only once
.\Sources\LedDemo2_Process.c:106: error: for each function it appears in.)

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_ -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo2_Resources.o .\Sources\LedDemo2_Resources.c

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_ -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo_Body.o .\Sources\LedDemo_Body.c

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_ -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo_Functions.o .\Sources\LedDemo_Functions.c

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_ -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo_Process.o .\Sources\LedDemo_Process.c
.\Sources\LedDemo_Process.c: In function 'TaskProcess_LedDemo':
.\Sources\LedDemo_Process.c:72: warning: unused variable 'uSysTim'

arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_ -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo_Resources.o .\Sources\LedDemo_Resources.c

arm-hitex-elf-ld.exe -T.\netx_sdram.ld.tmp -static -( -lrcx -lc -lm -lgcc -) -o .\output\LedDemo.elf
arm-hitex-elf-ld: cannot find .\output\LedDemo2_Process.o

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 14.10.2008 | 16:32

Ok, now that you've learned how to copy and paste, we will start with lesson 2: "Reading".

The lines below show the error that has happened (I kindly stripped all lines, that did not show errors). ":106" tells you the line number where the compiler failed.

I assume you don't have a variable called "ptRsc", do you?

But now it's up to you for lesson 3. "Starting C programming"

Abslimo wrote:
arm-hitex-elf-gcc.exe -c -mlong-calls -mcpu=arm926ej-s -fshort-enums -gdwarf-2 -Wall -O0 -mapcs -mthumb-interwork -D_NETX_HITOP_ -D__RCX__ -D_NXSB100_ -D_RX_NO_HW_QUEUE_   -I.\Includes\ -I.\Includes\API\ -I.\Includes\Configuration\ -I.\Includes\CpunetX\ -I.\Includes\TLR\ -o .\output\LedDemo2_Process.o .\Sources\LedDemo2_Process.c 
.\Sources\LedDemo2_Process.c: In function 'TaskProcess_LedDemo2':
.\Sources\LedDemo2_Process.c:106: error: 'ptRsc' undeclared (first use in this function)
.\Sources\LedDemo2_Process.c:106: error: (Each undeclared identifier is reported only once
.\Sources\LedDemo2_Process.c:106: error: for each function it appears in.)

Regards

MT

| 14.10.2008 | 17:03

Thank's for your lessons.....
The problem is now solved. I should the variable "LEDDEMO_RSC_T* ptRsc" global define.
Regards
Abslimo

Login