alias problem

  • 1
  • 2
  • Page 1 of 2
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

alias problem

 · 
Posted: 22.06.2014 - 01:41  ·  #1
I have a shared unit with serial communication protocol process, and in it's uses section there is a project dependent unit which defines aliases like this:
Code
alias
  // Communication protocol will be on serial port 2
  SerInpComm   = SerInp2;   // serial port alias
  RxBufferComm = RxBuffer2; // serial buffer alias

In theory that should let me use communication protocol in many projects running on different ports defined in that project dependent unit.

First I had a problem which could be simplified to this code snippet:
Code
    MyStr := SerInp2 + SerInp2;                   // this works
    MyStr := SerInpComm + SerInpComm;             // doesn't compile
    MyStr := char(SerInpComm) + char(SerInpComm); // workaround
As you can see I have solved this problem with a workaround.

But then this showed up which I don't know how to solve:
Code
  if WaitPipe(RxBufferComm, COMM_TIMEOUT_TICKS) then // compilation error

Is there some workaround for using alias with WaitPipe()?
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: alias problem

 · 
Posted: 22.06.2014 - 19:37  ·  #2
Hello Avra,

Alias is only active for one, the next, statement.

rolf
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: alias problem

 · 
Posted: 22.06.2014 - 21:31  ·  #3
Quote by rh
Alias is only active for one, the next, statement.

Sorry, I think that I just don't get it since your answer confused me even more and my understanding of XMega_Alias demo and compiler documentation. Especially since in demonstration code below these two lines using aliases compile:
Code
  c := SerInpComm;
  Write(SerOutComm, c);

and this one does not compile:
Code
  WaitPipe(RxBufferComm)

Changing alias order or code order didn't make any difference. Trying to use alias RxBufferComm breaks compilation. :crybaby:

Could you please tell me what I need to change to be able to use RxBufferComm alias since that is not obvious to me and I still don't get it? :wall:

Code
program Test;

device = mega64, VCC=3.3;

import SysTick, SerPort, SerPort2;

from System import Processes;

define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  StackSize      = $0064, iData;
  FrameSize      = $0064, iData;
  Scheduler      = iData;
  SerPort        = 9600, Stop1;    {Baud, StopBits|Parity}
  RxBuffer       = 8, iData;
  TxBuffer       = 8, iData;
  SerPort2       = 9600, Stop1;    {Baud, StopBits|Parity}
  RxBuffer2      = 8, iData;
  TxBuffer2      = 8, iData;

implementation

type

{$IDATA}
var

alias
  RxBufferComm = RxBuffer; // serial port input buffer alias
  SerInpComm   = SerInp;   // serial port input alias
  SerOutComm   = SerOut;   // serial port output alias

process HcpComm($40, $100: iData);
var
  c: char;
begin
  //WaitPipe(RxBufferComm); // COMPILER ERROR: var expected
  WaitPipe(RxBuffer);       // workaround without alias works
  c := SerInpComm;
  Write(SerOutComm, c);     // echo input
end;

begin
  Start_Processes;
  WriteLn(SeroutComm, 'I will echo your typing...');
  loop
    nop;
  endloop;
end Test.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: alias problem

 · 
Posted: 22.06.2014 - 22:00  ·  #4
Hello Avra,

sorry, my mistake. Of course ALIAS is valid until the next var or const label appears.

rolf
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: alias problem

 · 
Posted: 22.06.2014 - 22:32  ·  #5
Quote by rh
sorry, my mistake. Of course ALIAS is valid until the next var or const label appears.

So why in above code this line can not compile when uncommented:
Code
//WaitPipe(RxBufferComm); // COMPILER ERROR: var expected

There is no const or var between alias and this line. I have moved procedural var into global var so there is not a single var at all between alias and this line and I still can not compile.

What do I need to change to be able to compile above code when using RxBufferComm alias?
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: alias problem

 · 
Posted: 23.06.2014 - 13:36  ·  #6
Hello Avra,

WaitPipe is a very special construction and was not intended to be
used with ALIAS. But now it is supported.

rolf
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: alias problem

 · 
Posted: 23.06.2014 - 20:05  ·  #7
Quote by rh
WaitPipe is a very special construction and was not intended to be
used with ALIAS. But now it is supported.

I have tested and... IT COMPILES, IT COMPILES IT COMPILES !!! :D
=D> :-({|= =D> :occasion7: 👋

Now I can share communication unit between different projects without tons of ugly IFDEFs covering all possible AVR serial ports combination in code.
🆒 :juggle:

THANK YOU ROLF!
:cheers: :occasion5: 👍
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: alias problem

 · 
Posted: 23.06.2014 - 20:40  ·  #8
Hello Avra,

some things are easy to implement, like this one.
Others are not, like passing bits to a function.

rolf
  • 1
  • 2
  • Page 1 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   125   139 · Page-Gen-Time: 0.029821s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI