In MikroPascal for DSPIC, when variables of type record are declared in separate Unit, program behavior :
Code: Select all
unit unit_pt;
const
CacheLength : byte = 5;
PingCacheLength : byte = 5;
type IpHeader = array[4] of byte;
type MacHeader = array[6] of byte;
type TPingCache = Record
IpP : IpHeader;
MacP : MacHeader;
Time : word;
UserTime : word;
T : word;
TTL : byte;
UserTTL : byte;
end;
type TArpCache = Record
Valid : Boolean;
tmr : longint;
Ip : IpHeader;
Mac : MacHeader;
end;
type TNtp = Record
Rfc : dWord;
Unix : dWord;
Year : word;
Month : byte;
Day : byte;
Hour : byte;
Min : byte;
Sec : byte;
Str : string[32];
end;
var
ArpCache : array[CacheLength] of TArpCache;
PingCache : array[PingCacheLength] of TPingCache;
TTime : TNtp;
implementation
end.
Code: Select all
program Test_Pt;
uses unit_pt;
procedure EraseArpCache;
var j,g : word;
begin
j := 0;
while j < CacheLength do
begin
g := 0;
while g < 4 do
begin
ArpCache[j].Ip[g] := $FF; // erase Ip Cache value
inc(g);
end;
g := 0;
while g < 6 do
begin
ArpCache[j].Mac[g] := $FF; // erase Mac Cache value
inc(g);
end;
ArpCache[j].Valid := False;
ArpCache[j].Tmr := $FFFFFFFF;
inc(j);
end;
end;
procedure ErasePingCache;
var j,g : word;
begin
j := 0;
while j < PingCacheLength do
begin
g := 0;
while g < 4 do
begin
PingCache[j].IpP[g] := 0; // erase Ip Cache value
inc(g);
end;
g := 0;
while g < 6 do
begin
PingCache[j].MacP[g] := 0; // erase Mac Cache value
inc(g);
end;
PingCache[j].Time := 0;
PingCache[j].UserTime := 0;
PingCache[j].T := 0;
PingCache[j].TTL := 0;
PingCache[j].UserTTL := 0;
inc(j);
end;
end;
begin
EraseArpCache;
ErasePingCache;
WordToStr(1000,TTime.Str);
end.