This what I did
Code: Select all
unit Test
// fuction to allow user access to the received UART data
TAsyncUARTReceiveNextMessage = function(): PAsyncUARTReceiveMessage;
PAsyncUARTReceiveNextMessage = ^TAsyncUARTReceiveNextMessage;
TAsyncUARTReceiveReleaseNextMessage = procedure();
PAsyncUARTReceiveReleaseNextMessage = ^TAsyncUARTReceiveReleaseNextMessage;
TAsyncUARTReceiveRec = record
// Stuff removed for clarity
NextMessage: PAsyncUARTReceiveNextMessage; // Call to return the next received message queued in the structure, return nil if no data is available
ReleaseNextMessage: PAsyncUARTReceiveReleaseNextMessage; // Call to release slot locked by NextMessage above
Callback: PAsyncUARTReceiveCallback;
end;
var
Rx1Buffer:TAsyncUARTReceiveRec;
implementation
function DummyRxCallback(ReceivedChar: Char; var ReceiveComplete: Boolean): Boolean;
begin
...
end;
function NextMessageUART1: PAsyncUARTReceiveMessage;
begin
....
end;
procedure ReleaseNextMessageUART1;
begin
...
end;
procedure InitializeUARTInterrupts;
begin
....
Rx1Buffer.Callback := @DummyRxCallback;
Rx1Buffer.NextMessage := @NextMessageUART1;
Rx1Buffer.ReleaseNextMessage := @ReleaseNextMessageUART1;
end;
end.
Code: Select all
program MainTest;
uses
Test;
implementation
var
UARTMessage: PAsyncUARTReceiveMessage;
begin
InitializeUARTInterrupts
UARTMessage := Rx1Buffer.NextMessage();
if UARTMessage <> 0 then
begin
Rx1Buffer.ReleaseNextMessage()
end;
end.
Jim0 1 mPDsPic.exe -DBG -pP30F4013 -MSF -Y -DL -O11111110 -fo80 -N"C:\Users\Jim\Desktop\NMRA DCC\dsPIC Code\Command Station\DCC_CommandStation.mppds" -SP"C:\Program Files\Mikroelektronika\mikroPascal PRO for dsPIC\defs\" -SP"C:\Program Files\Mikroelektronika\mik
0 132 Compilation Started C:\Users\Jim\Desktop\NMRA DCC\dsPIC Code\Command Station\DCC_CommandStation_Main.mpas
1 1015 Hint: Compiling unit "C:\Users\Jim\Desktop\NMRA DCC\dsPIC Code\Command Station\DCC_CommandStation_Main.mpas" DCC_CommandStation_Main.mpas
122 1022 Hint: interrupt handler (MainLine_DCC_Signal_Int at 0x0020) DCC_CommandStation_Main.mpas
189 1022 Hint: interrupt handler (Timer3Int at 0x0022) DCC_CommandStation_Main.mpas
212 1022 Hint: interrupt handler (UART_RX_Int at 0x0026) DCC_CommandStation_Main.mpas
488 1019 Warning: Source size may exceed destination size DCC_CommandStation_Main.mpas
489 1019 Warning: Source size may exceed destination size DCC_CommandStation_Main.mpas
746 1010 Hint: Unit "DCC_CommandStation_Main.mpas" has been recompiled DCC_CommandStation_Main.mpas
0 133 Compiled Successfully C:\Users\Jim\Desktop\NMRA DCC\dsPIC Code\Command Station\DCC_CommandStation_Main.mpas
0 138 All files Compiled in 1469 ms
0 1143 Used RX (bytes): 32 (100%) Free RX (bytes): 0 (0%) Used RX (bytes): 32 (100%) Free RX (bytes): 0 (0%)
0 1143 Static RAM (bytes): 1133 Dynamic RAM (bytes): 946 Static RAM (bytes): 1133 Dynamic RAM (bytes): 946
0 1143 Used ROM (bytes): 5558 (17%) Free ROM (bytes): 27210 (83%) Used ROM (bytes): 5558 (17%) Free ROM (bytes): 27210 (83%)
0 144 Project Linked Successfully DCC_CommandStation.mppds
0 0
0 102 Finished (with errors): 20 Mar 2010, 19:17:53 DCC_CommandStation.mppds
Update: Submitted a ticket with example