calling sub procedures

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
kkchunghk
Posts: 5
Joined: 16 Jul 2010 03:19

calling sub procedures

#1 Post by kkchunghk » 13 Nov 2023 11:30

I'm trying to call a sub procedure at the start of a programme as a default condition. Then send the chip to sleep. On an interrupt the same function is called. I have a error message "Reentrancy is not allowed: function 'test1' called from two threads subtest.mbas". I don't know how to resolve that apart from repeating the content of the sub procedure in the main programme. The real content for test1 is more than a few lines.

Code: Select all

program subtest
'P16f18313

dim testData as byte
' Declarations section

sub procedure test1 (dim test1Data as byte)
PORTA = test1Data 'Just dummy codes
end sub

sub procedure test2 (dim test2Data as byte)
test1(test2Data)
end sub

sub procedure interrupt
test1(testData)
end sub

main:
'   Main program
 testData = PORTA
 clearbit(INTCON,GIE) 'Disable interrupt
 test1(testData)
 
 clearbit(PIR0,INTF)
 setbit(INTCON,GIE)   'Enable interrupt
 setbit(PIE0,IOCIE)
 while TRUE
       sleep
       nop
       nop
 wend
end.

kkchunghk
Posts: 5
Joined: 16 Jul 2010 03:19

Re: calling sub procedures

#2 Post by kkchunghk » 13 Nov 2023 11:41

By the way, I can't have the same library function appeared in the sub procedures and the main programme. If I have ADC_read() in both the sub procedure and the main programme, I get the same error message.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: calling sub procedures

#3 Post by arco » 13 Nov 2023 11:54

You cannot use one sub/procedure in both main program and interrupt, because they run asynchronously.
At the least the result would be very unreliable.

Making everything re-entrant would generate a lot of extra code.
Regards,

Peter.

Post Reply

Return to “mikroBasic PRO for PIC General”