No,@KlausST: you mean very small by atomic, why?
Understood, but there is no atomic variable definition in CCS C as I see. What can I do?
disable_interrupts(the interrupt that writes to global);
temp=myglobalvar;
enable_interrupts(the interrupt that writes to global);
I'm sorry but I don't understand what you are referring to by "..two level function branching...".@Aussie Susan:....What will happen, if in interrupt, two level function branching exists?
interrupt:
#INT_RDA
void rsReceiveInt()
{
disable_interrupts(GLOBAL);
incomingData = fgetc(RS485); // incomingData = RCREG; (Both same, doesnt change)
enable_interrupts(GLOBAL);
}
in main.c:
#device HIGH_INTS = TRUE
in rs485_lib.c:
#define RS485_RX_PIN PIN_C7
#define RS485_TX_PIN PIN_C6
#define RS485_ENABLE_PIN PIN_C4
#bit BIT_RS485_EN_PIN = getenv("sfr:PORTB").0
#bit RS485_CREN = getenv("bit:CREN")
#define RS485_BAUD 9600
#define RS485_RX_BUFFER_SIZE 40
#ifndef MULTI_ALL
#define MULTI_ALL 0
#endif
#define OFF 0
#define ON 1
#use rs232(BAUD=RS485_BAUD, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, errors, stream=RS485)
#bit rs485_collision = rs232_errors.6
void RcvOn()
{
while(kbhit(RS485)) {getc();}
if(addressMode == OFF) {
setup_uart(UART_DATA);
}
else // addressMode == ON {
setup_uart(UART_ADDRESS);
}
setup_uart(TRUE);
enable_interrupts(INT_RDA);
RS485_CREN = 1;
}
void RcvOff()
{
RS485_CREN = 0;
disable_interrupts(INT_RDA);
}
void Rs485Init(int1 addMode)
{
addressMode = addMode;
// RS485 veri alımını aç
RcvOn();
rs485IndexLast = 0;
rs485IndexFirst = 0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
BIT_RS485_EN_PIN = 0;
RS485_CREN = 1;
}
void Rs485SetID(int ID)
{
rs485ID = ID;
}
void Rs485SendData(int to, int length, int* data)
{
int index;
tempID = 0xE1; //0xE0 | rs485ID;
tempTo = 0xF2; //0xF0 | to;
tempAddress = 0;
if(addressMode == 0)
{
tempAddress = 0x100;
}
// veri alımını kapat
RcvOff();
//output_high(RS485_ENABLE_PIN);
//delay_ms(4);
fputc((int16)tempAddress|tempID, RS485);
while(!PIR1TXIF); //delay_ms(2);
fputc((int16)tempAddress|tempTo, RS485);
while(!PIR1TXIF); //delay_ms(2);
fputc((int16)tempAddress|length, RS485);
while(!PIR1TXIF); //delay_ms(2);
checkSumToSend = tempTo^tempID^length;
checkSumToSend ^= serialMessageTX[0];
fputc((int16)tempAddress|serialMessageTX[0], RS485);
while(!PIR1TXIF); //delay_ms(2);
checkSumToSend ^= serialMessageTX[1];
fputc((int16)tempAddress|serialMessageTX[1], RS485);
while(!PIR1TXIF); //delay_ms(2);
checkSumToSend ^= serialMessageTX[2];
fputc((int16)tempAddress|serialMessageTX[2], RS485);
while(!PIR1TXIF); //delay_ms(2);
checkSumToSend ^= serialMessageTX[3];
fputc((int16)tempAddress|serialMessageTX[3], RS485);
while(!PIR1TXIF); //delay_ms(2);
checkSumToSend ^= serialMessageTX[4];
fputc((int16)tempAddress|serialMessageTX[4], RS485);
while(!PIR1TXIF); //delay_ms(2);
fputc((int16)tempAddress|checkSumToSend, RS485);
RcvOn();
}
int1 function(); // No data change in this function
if(function())
{
if(function())
{}
else
{
// The software comes to this point for eg.
}
}
if(function()){
// the code enters here
}
if(function()){
// the code enters here
if(function()) {
// But it doesnt enter here
}
}
void rsReceiveInt()
{
disable_interrupts(GLOBAL);
var = RCREG;
enable_interrupts(GLOBAL);
}
void rsReceiveInt()
{
disable_interrupts(GLOBAL);
var = fgetc(RS485);
enable_interrupts(GLOBAL);
}
void rsReceiveInt()
{
disable_interrupts(GLOBAL);
tempVar++;
enable_interrupts(GLOBAL);
}
#INT_TIMER1
void timerInt()
{
disable_interrupts(GLOBAL);
// Jobs done here..
enable_interrupts(GLOBAL);
clear_interrupt(int_timer1);
return;
}
#INT_TIMER1
void timerInt()
{
disable_interrupts(GLOBAL);
// Jobs done here..
enable_interrupts(GLOBAL);
clear_interrupt(int_timer1);
return;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?