Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Reentrancy problem in mikroC PRO V 2.50 compiler (using PIC 18F452)

Status
Not open for further replies.

BRL6

New Member
Hi,everybody.I have reentrancy problem in my program.My compiler
mikroC PRO V2.50,give me these error messages;


184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 10 May 2010, 17:39:42 t4x.mcppi


I read about reentrancy solution and derictive #pragma funcall... but I do not know how I must modified and used that for my program.

Somebody please help me to apply that directive ,if that is a good way,and write that to solve my problem.

Thanks,

Here are my code firmware and program;

Code:

#define stepsize 98
int t4=0,index;
char *tc;
int adcvalmax[8];
int interb0=0;

void Display_AdcX(int adcvalmax[8] ) {
int i=0,m=0;
char ch[8];
extern int adcvalmax[8];// 16 1504 Initialization of extern object 'adcvalmax' t1x.c //
memset(adcvalmax,0,8*sizeof(int));
memset(ch,0,8*sizeof(int));

for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************

ch = adcvalmax[m] /1000; //prepare value for display in A
Lcd_Chr(2, 1, 48 + ch); //write ASCII at 2nd row,1st column
Lcd_Chr_Cp('.');

ch = (adcvalmax[m] /100) % 10;
Lcd_Chr_Cp(48 + ch);

ch = (adcvalmax[m] /10) % 10;
Lcd_Chr_Cp(48 + ch);

ch = adcvalmax[m] % 10;
Lcd_Chr_Cp(48 + ch);
Lcd_Chr_Cp('A');

}

}//~


void MR_CHNS(int adcvalmax[8]){

long longadc=0;
extern int adcvalmax[8];// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//
int ch[8];//declares a array of 8 integers
int m=0,i=0;
int Px=0,P1st=0,P2nd=0;

memset(adcvalmax,0,8*sizeof(int));
memset(ch,0,8*sizeof(int));

for(i=0;i<8;i++){

for(m=0;m<8;m++){

do{
ch=ADC_Read(i);
Px=ch;
}while(Px!=0);

P1st=ADC_Read(m);
Delay_ms(10);//10 ms pause
P2nd=ADC_Read(m);

while(P1st<=P2nd){
P1st=P2nd;
P2nd=0;
P2nd=ADC_Read(m);
}

adcvalmax[m] = P1st;// if (vf>vn)
index = (stepsize);
ADRESH = (ADRESH)&&(0b00000011);
longadc = ADRESH + ADRESL;
adcvalmax[m] = longadc * index;//in mA or mv

}
}

}//~



void update_pwm(unsigned short int rp2val){
rp2val=0;

t4 = Adc_Read(4);
rp2val = ADRESL;


PWM1_Set_Duty(rp2val);//Set & change duty ratio due to the VRP2 value
//from 0 -255;(ADRESL)


LCD_Out(2,14,&rp2val);// 96 1508 Implicit conversion of int to ptr t1x.c //

//(127: 50% duty ratio)
if(rp2val == 127) PORTC.F5=1;//Turn the LED on (RC5/pin24)

}//~



void interrupt() {

static int interb0;
//Turn off charger interrupt via INTO/RB0
INTCON.INT0IF=0;//Clear INT0(INTCON)external interrupt Flag bit to detect
//next inter.
interb0++;//interb0 = interb0+1

while(interb0 ==1){

PWM1_Stop();//Stop PWM


LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "STAND BY!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column

PORTC.F3=1;//Turn the LED on (RC3/pin18):LED stand by state indicator
Delay_ms(1000);//One second pause
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

if(interb0!=1){
PWM1_Start();//Start PWM ,(interb0!=1)
interb0 = 0;
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

}//~


// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


void main() {

PORTA=0;//Clear port A
TRISA=0XFF;//Port A is input
PORTD=0;//Clear port D
TRISD=0;//Port D is output
PORTC=0;//Clear port C
TRISC=0;//port C is output
PORTB=0;//Clear port B
TRISB=0XFF;//port B is input
PORTE=0;//Clear port E
TRISE=0XFF;//Port E is input
TRISC = PORTC = 0;

INTCON.GIEH = 1; // When IPEN = 1,enables all high priority interrupts
INTCON.GIEL=1;//When IPEN = 1,enables all low priority peripheral interrupts
RCON.IPEN = 1;//Enable priority levels on interrupts
INTCON.INT0IE=1;//Enables the INT0 external interrupt
INTCON2.INTEDG0 = 0;// Interrupt on falling edge


LCD_Init();// initialize(4-bit interface connection)
LCD_Cmd(_LCD_CURSOR_OFF);// send command to LCD (cursor off)
LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "Hi!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column



PWM1_Init(500);//500HZ but should Initialize PWM module at 50HZ ;
//using frequency divider with D-Flip_Flop IC.
PWM1_Set_Duty(127);//Set duty ratio to 50%



update_pwm(t4);
PWM1_Start();//Start PWM


//Not required to determine ADCON0;it is asked by uC compiler on NEW Project
// icon bar at the top at first automatically &done via:Adc_Read() Library

ADCON1=0x80;//configure VDD=Vref+,Vss=Vref-,8-analog channels&Right justified
//A/D Result Format
Delay_ms(2000);


MR_CHNS(adcvalmax);
Display_AdcX(adcvalmax);



}//~!






0 1 mikroCPIC1618.exe -MSF -DBG -pP18F452 -DL -O11111114 -fo8 -N"E:\XT1\t4x.mcppi" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\defs\" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\uses\P18\" -SP"E:\XT1\" "t4x.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w8_e64.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl"
0 125 All files Preprocessed in 15 ms
0 121 Compilation Started t4x.c
223 122 Compiled Successfully t4x.c
0 126 All files Compiled in 157 ms
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 10 May 2010, 17:39:42 t4x.mcppi






Thanks & Regards,
 
Just change it so your interrupt routine sets a flag (or variable) and your main code calls the LCD routines.

Mike.
 
The reason you shouldn't do that is because code calling the function may be interrupted as it executes. This isn't good as variables and other special registers could be corrupted.

As Pommie says, the solution is to remove any "real" code from your interrupt service routine and put it in the main function instead.
 
Reentrancy & #pragma funcall... directive problem

Hi.Thanks for your answers; prommie & edecca.But I can not use interrupt
to solve my reentrancy problem.Would you please write for my program
the directive; #pragma funcall....Because I do not know how I used
it exactly for my program to solve the reentrancy problem.

Thanks,
 
Status
Not open for further replies.

Latest threads

Back
Top