UKSS_ICE/RS485.c
nelolik b8a0477c5c init commit.
Проект каким он достался от Димы.
2021-02-15 09:56:27 +03:00

554 lines
16 KiB
C

/****************************************************************/
/* TMS320C32 */
/* ====== BIOS, ÊËÀÈÍ, ÊËÂÑÏ ====== */
/* ÖÍÈÈ ÑÝÒ (ñ) 1998-2000 ã. */
/****************************************************************
RS485.ñ
****************************************************************
* Ïðîöåäóðû ðàáîòû ñ UART *
****************************************************************/
//#include "big_dsp_module.h"
#include "DSP2833x_Device.h"
#include "DSP2833x_SWPrioritizedIsrLevels.h"
#include "RS485.h"
#include "bios_dsp.h"
#include "cntrl_adr.h"
#include "tools.h"
//#include "flash_tools.h"
RS_DATA rs_a,rs_b;
unsigned int RS_Len[70]={0};
static char size_cmd15=1;
void RS_RX_Handler(RS_DATA *rs_arr);
void RS_TX_Handler(RS_DATA *rs_arr);
/** Îáðàáîò÷èê ïðåðûâàíèé UART - ïðèíàòî */
interrupt void RSA_RX_Handler(void)
{
// Set interrupt priority:
volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all;
IER |= M_INT9;
IER &= MINT9; // Set "global" priority
PieCtrlRegs.PIEIER9.all &= MG91; // Set "group" priority
PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts
EINT;
clear_timer_rs_live(&rs_a);
RS_RX_Handler(&rs_a);
// Restore registers saved:
DINT;
PieCtrlRegs.PIEIER9.all = TempPIEIER;
}
interrupt void RSB_RX_Handler(void)
{
// Set interrupt priority:
volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all;
IER |= M_INT9;
IER &= MINT9; // Set "global" priority
PieCtrlRegs.PIEIER9.all &= MG93; // Set "group" priority
PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts
EINT;
clear_timer_rs_live(&rs_b);
RS_RX_Handler(&rs_b);
// Restore registers saved:
DINT;
PieCtrlRegs.PIEIER9.all = TempPIEIER;
}
interrupt void RSA_TX_Handler(void)
{
// Set interrupt priority:
volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all;
IER |= M_INT9;
IER &= MINT9; // Set "global" priority
PieCtrlRegs.PIEIER9.all &= MG92; // Set "group" priority
PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts
EINT;
clear_timer_rs_live(&rs_a);
RS_TX_Handler(&rs_a);
// Restore registers saved:
DINT;
PieCtrlRegs.PIEIER9.all = TempPIEIER;
}
interrupt void RSB_TX_Handler(void)
{
// Set interrupt priority:
volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all;
IER |= M_INT9;
IER &= MINT9; // Set "global" priority
PieCtrlRegs.PIEIER9.all &= MG94; // Set "group" priority
PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts
EINT;
clear_timer_rs_live(&rs_b);
RS_TX_Handler(&rs_b);
// Restore registers saved:
DINT;
PieCtrlRegs.PIEIER9.all = TempPIEIER;
}
/** Îáðàáîò÷èê ïðåðûâàíèé UART - ïðèíàòî */
void RS_RX_Handler(RS_DATA *rs_arr)
{
char Rc;
char RS_BytePtr;
// led1_on();
for(;;) // 'goto' ýòî íå îïåðàòîð àçûêà Ñ
{
if(!rs_arr->SciRegs->SCIRXST.bit.RXRDY) // Receiver ready flag
{
PieCtrlRegs.PIEACK.bit.ACK9 |= 1;
rs_arr->SciRegs->SCIFFRX.bit.RXFFINTCLR=1; // Clear INT flag
return; // êñòàòè ýòî åäèíñòâåííûé âûõîä èç ïðåðûâàíèà
}
Rc = rs_arr->SciRegs->SCIRXBUF.bit.RXDT; // ×èòàåì ñèìâîë â ëþáîì ñëó÷àå
if(rs_arr->SciRegs->SCIRXST.bit.RXERROR) // Receiver error flag
{
rs_arr->SciRegs->SCICTL1.bit.SWRESET=0; // Reset SCI
rs_arr->SciRegs->SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset
continue;
}
if(rs_arr->RS_DataReady) continue; // Íå çàáðàëè äàííûå
if (rs_arr->RS_Flag9bit==1) // äëà RS485????????
{
// Èíèöèàëèçèðóåì ïåðåìåííûå è ôëàãè
rs_arr->RS_FlagBegin = true; // Æäåì çàãîëîâîê
rs_arr->RS_RecvLen = 0;
rs_arr->RS_FlagSkiping = false;
rs_arr->RS_HeaderCnt = 0;
rs_arr->RS_Cmd = 0;
}
if(rs_arr->RS_FlagSkiping) continue; // Íå íàì
if (rs_arr->RS_FlagBegin) // Çàãîëîâîê
{
if (rs_arr->RS_HeaderCnt==0) // Àäðåñ êîíòðîëëåðà èëè ñòàíäàðòíàà êîìàíäà
{
if( (Rc == CNTRL_ADDR_UNIVERSAL) || (Rc == CNTRL_ADDR && CNTRL_ADDR!=0) || ((Rc == rs_arr->addr_answer) && rs_arr->flag_LEADING)
|| ((Rc == ADDR_FOR_ALL && ADDR_FOR_ALL!=0) && !rs_arr->flag_LEADING))
{
rs_arr->addr_recive=Rc; // çàïîìíèëè àäðåñ ïî êîòîðîìó íàñ çàïðîñèëè
rs_arr->RS_Header[rs_arr->RS_HeaderCnt++] = Rc; // Ïåðâûé áàéò
RS_SetBitMode(rs_arr,8); // ïåðåñòðîèëèñü â 8-áèò ðåæèì
}
else
{
rs_arr->RS_FlagSkiping = true; // Íå íàøåìó êîíòðîëëåðó
rs_arr->RS_FlagBegin = false; // îñòàëèñü â 9-áèò ðåæèìå
// led1_off();
}
}
else
{
rs_arr->RS_Header[rs_arr->RS_HeaderCnt++] = Rc; // Âòîðîé áàéò è ò.ä.
if (rs_arr->RS_HeaderCnt == 7 && rs_arr->RS_Cmd==CMD_MODBUS_16 && !rs_arr->flag_LEADING)
{
RS_Len[CMD_MODBUS_16] = (10+Rc);
}
// åñëè âòîðîé áàéò - ýòî êîìàíäà
if (rs_arr->RS_HeaderCnt == 2)
{
rs_arr->RS_Cmd = Rc;
// Ïðîâåðêà äëèíû ïîñûëêè
// CMD_LOAD - ìëàäøàà íà äàííûé ìîìåíò
// CMD_STD_ANS - ñòàðøàà íà äàííûé ìîìåíò
if ((rs_arr->RS_Cmd < CMD_MODBUS_3) || (rs_arr->RS_Cmd > CMD_STD_ANS) || (RS_Len[rs_arr->RS_Cmd]<3)
|| ((rs_arr->RS_Cmd == CMD_LOAD)&&(rs_arr->RS_PrevCmd != CMD_INITLOAD))
)
{
RS_SetBitMode(rs_arr,9); // Ïîëó÷èëè âñå ïåðåñòðîèëèñü â 9-áèò äëà RS485?
rs_arr->RS_HeaderCnt = 0; // Ïîòîìó ÷òî êîìàíäà íå òà
rs_arr->RS_FlagBegin = true;
rs_arr->RS_FlagSkiping = false;
rs_arr->RS_Cmd=0;
// led1_off();
continue;
}
if (rs_arr->RS_Cmd == CMD_LOAD) // Äëà ýòîé êîìàíäû çàãîëîâîê î÷åíü êîðîòêèé
rs_arr->RS_FlagBegin = false;// äàëüøå èäóò äàííûå
}
if( (rs_arr->RS_HeaderCnt >= RS_Len[rs_arr->RS_Cmd]) ||
(rs_arr->RS_HeaderCnt >= sizeof(rs_arr->RS_Header)))
{ // Ïîëó÷èëè çàãîëîâîê
RS_SetBitMode(rs_arr,9); // Ïîëó÷èëè âñå ïåðåñòðîèëèñü â 9-áèò äëà RS485?
rs_arr->RS_FlagBegin = false;
rs_arr->RS_FlagSkiping = true;
rs_arr->RS_DataReady = true;
rs_arr->RS_Cmd=0;
// led1_off();
} } }
else // Ïîòîê äàííûõ
{
if(rs_arr->pRS_RecvPtr<(unsigned int *)Rec_Bloc_Begin || rs_arr->pRS_RecvPtr>(unsigned int *)Rec_Bloc_End)
{
rs_arr->pRS_RecvPtr = (unsigned int *)Rec_Bloc_Begin; // Íà ïðîãðàììó íàäåéñà, à ñàì íå ïëîøàé
rs_arr->pRecvPtr = (unsigned int *)Rec_Bloc_Begin; // Íà ïðîãðàììó íàäåéñà, à ñàì íå ïëîøàé
}
if(rs_arr->RS_PrevCmd != CMD_INITLOAD) continue; // Ìû çäåñü îêàçàëèñü ïî êàêîé-òî ÷óäîâèùíîé îøèáêå
if(rs_arr->RS_DataReady) // Åñëè äàííûå â îñíîâíîì öèêëå íå çàáðàíû,
{ // òî ïðîïóñêàåì ñëåäóþùóþ ïîñûëêó
rs_arr->RS_FlagSkiping = true; // Èãíîðèðóåì äî ñëåäóþùåãî çàãîëîâêà
// led1_off();
continue;
}
RS_BytePtr = rs_arr->RS_RecvLen++ % 2;
if(RS_BytePtr) *rs_arr->pRS_RecvPtr++ |= Rc; // Ïîëó÷èëè ñëîâî
else *rs_arr->pRS_RecvPtr = Rc<<8;
if(rs_arr->RS_Length <= rs_arr->RS_RecvLen) // Êîíåö ïîñûëêè
{
rs_arr->RS_PrevCmd = rs_arr->RS_Header[1] = CMD_LOAD;
RS_SetBitMode(rs_arr,9); // Ïîëó÷èëè âñå äàííûå ïåðåñòðîèëèñü â 9-áèò äëà RS485?
rs_arr->RS_FlagSkiping = true; // Èãíîðèðóåì äî ñëåäóþùåãî çàãîëîâêà
rs_arr->RS_DataReady = true; // Ôëàã â îñíîâíîé öèêë - äàííûå ïîëó÷åíû
// led1_off();
} } } }
/** Îáðàáîò÷èê ïðåðûâàíèé UART - ïîñëàíî */
void RS_TX_Handler(RS_DATA *rs_arr)
{
char RS_BytePtr;
// unsigned int i;
if(rs_arr->RS_SendBlockMode == BM_CHAR32)
{
if(++rs_arr->RS_SendLen >= rs_arr->RS_SLength)
{
enableUARTInt(rs_arr); /* Çàïðåùàåì ïðåðûâàíèà ïî ïåðåäà÷å */
}
SCI_send(rs_arr,*(rs_arr->pRS_SendPtr++));
if(rs_arr->RS_SendLen >= rs_arr->RS_SLength)
{
RS_Wait4OK(rs_arr);
// for (i=0; i <= TIME_WAIT_RS_BYTE_OUT; i++){} /* Ïàóçà äëà PC */
RS_SetBitMode(rs_arr,9); /* Ïåðåäàëè âñå ïåðåñòðîèëèñü â 9-áèò äëà RS485?*/
RS_Line_to_receive(rs_arr); /* ðåæèì ïðèåìà RS485 */
rs_arr->flag_TIMEOUT_to_Send=false; /* ñáðîñèëè ôëàã îæèäàíèà òàéìàóòà */
}
}
else /* BM_PACKED */
{
RS_BytePtr = (rs_arr->RS_SendLen++) % 2;
if(rs_arr->RS_SendLen >= rs_arr->RS_SLength)
{
enableUARTInt(rs_arr); /* Çàïðåùàåì ïðåðûâàíèà ïî ïåðåäà÷å */
}
if(RS_BytePtr) SCI_send(rs_arr, LOBYTE( *(rs_arr->pRS_SendPtr++) ));
else SCI_send(rs_arr, HIBYTE( *rs_arr->pRS_SendPtr ));
if(rs_arr->RS_SendLen >= rs_arr->RS_SLength)
{
RS_Wait4OK(rs_arr);
// for (i=0; i <= TIME_WAIT_RS_BYTE_OUT; i++){} /* Ïàóçà äëà PC */
// RS_SetBitMode(rs_arr,9); /* Ïåðåäàëè âñå ïåðåñòðîèëèñü â 9-áèò äëà RS485?*/
// RS_Line_to_receive(); /* ðåæèì ïðèåìà RS485 */
}
}
PieCtrlRegs.PIEACK.bit.ACK9 |= 1;
// rs_arr->SciRegs->SCIFFTX.bit.TXINTCLR=1; // Clear INT flag
}
/** Èíèöèàëèçàöèà ìàññèâà äëèí êîìàíä */
void setup_arr_cmd_length()
{
int i;
for (i=0;i<70;i++) RS_Len[i]=i;
RS_Len[CMD_LOAD] = 12;
RS_Len[CMD_UPLOAD] = 12;
RS_Len[CMD_RUN] = 8;
RS_Len[CMD_XFLASH] = 9;
RS_Len[CMD_TFLASH] = 16;
RS_Len[CMD_PEEK] = 8;
RS_Len[CMD_POKE] = 12;
RS_Len[CMD_INITLOAD] = 12;
RS_Len[CMD_INIT] = 5;
RS_Len[CMD_VECTOR] = size_cmd15-2; //sizeof(CMD_TO_TMS)-2;
RS_Len[CMD_STD] = size_cmd15-1; //sizeof(CMD_TO_TMS)-1;
RS_Len[CMD_IMPULSE] = 8;
RS_Len[CMD_MODBUS_3] = 8;
RS_Len[CMD_MODBUS_6] = 8;
RS_Len[CMD_MODBUS_16] = 13;
RS_Len[CMD_MODBUS_15] = 27;
RS_Len[CMD_EXTEND] = 18;
}
/** Íàñòðîéêà ðåæèìà ïðèåìà/ïåðåäà÷è */
void RS_SetBitMode(RS_DATA *rs_arr,int n)
{
if(n == 8)
{
RS_SetLineMode(rs_arr,8,'N',1); /* ðåæèì ëèíèè */
rs_arr->RS_Flag9bit=0;
}
if(n == 9)
{
RS_SetLineMode(rs_arr,8,'N',1); /* ðåæèì ëèíèè */
rs_arr->RS_Flag9bit=1;
} }
/** Ïîñûëêà áëîêà áàéòîâ.
Ïîñûëàåò ìàññèâà 32-áèòíûõ öåëûõ ÷èñåë ñòàðøèå áèòû äîëæíû áûòü 0.
@precondition Ðàáîòà ô-öèè çàâèñèò îò ìàêðî RS_TRANSMIT_INTR
@param buf àäðåñ ìàññèâà
@param len êîëè÷åñòâî áàéò
@see RS_BSend, RS_TRANSMIT_INTR */
int RS_Send(RS_DATA *rs_arr,unsigned int *pBuf,unsigned long len)
{
unsigned int i;
for (i=0; i <= 30000; i++){} /* Ïàóçà äëà PC */
RS_Line_to_send(rs_arr); /* ðåæèì ïåðåäà÷è RS485 */
for (i=0; i <= 10000; i++){} /* Ïàóçà äëà PC */
rs_arr->RS_SLength = len; /* Íàñòðàèâàåì ïåðåìåííûå */
rs_arr->pRS_SendPtr = pBuf + 1;
rs_arr->RS_SendBlockMode = BM_CHAR32;
RS_Wait4OK(rs_arr); /* Äîæèäàåìñà óõîäà */
RS_SetBitMode(rs_arr,8); /* Îñòàëüíûå â 8-áèò ðåæèìå */
rs_arr->RS_SendLen = 1; /* Äâà áàéòà óæå ïåðåäàëè */
if(len > 1)
{
enableUARTIntW(rs_arr); /* Ðàçðåøàåì ïðåðûâàíèà ïî ïåðåäà÷å */
SCI_send(rs_arr, *pBuf); // Ïåðåäàåì âòîðîé áàéò ïî ïðåðûâàíèþ
}
else
{
SCI_send(rs_arr, *pBuf); // Ïåðåäàåì âòîðîé áàéò ïî ïðåðûâàíèþ
RS_Wait4OK(rs_arr); /* Äîæèäàåìñà óõîäà áåç ïðåðûâàíèà */
for (i=0; i <= TIME_WAIT_RS_BYTE_OUT; i++){} /* Ïàóçà äëà PC */
RS_SetBitMode(rs_arr,9); /* Îáðàòíî â 9-áèò ðåæèì */
RS_Line_to_receive(rs_arr); /* ðåæèì ïðèåìà RS485 */
}
return 0;
}
// Ïîñûëêà áëîêà óïàêîâàííûõ áàéòîâ
int RS_BSend(RS_DATA *rs_arr,unsigned int *pBuf, unsigned long len)
{
RS_Line_to_send(rs_arr); // ðåæèì ïåðåäà÷è RS485
rs_arr->RS_SLength = len; // Íàñòðàèâàåì ïåðåìåííûå
rs_arr->pRS_SendPtr = pBuf;
rs_arr->RS_SendBlockMode = BM_PACKED;
RS_Wait4OK(rs_arr); // Îæèäàåì î÷èñòêè è óõîäà ïîñëåäíåãî áàéòà
RS_SetBitMode(rs_arr,8); /* Îñòàëüíûå â 8-áèò ðåæèìå */
rs_arr->RS_SendLen = 1; // Îäèí áàéò óæå ïåðåäàëè
enableUARTIntW(rs_arr); /* Ðàçðåøàåì ïðåðûâàíèà ïî ïåðåäà÷å */
SCI_send(rs_arr,HIBYTE(*pBuf));// Ïåðåäàåì ïåðâûé áàéò
return 0;
}
/** Óñòàíàâëèâàåò ñêîðîñòü îáìåíà.
@param speed ñêîðîñòü RS â áîä */
/** Óñòàíàâëèâàåò ñêîðîñòü îáìåíà.
@param speed ñêîðîñòü RS â áîä */
void RS_SetLineSpeed(RS_DATA *rs_arr,unsigned long speed)
{
long SciBaud;
SciBaud = LSPCLK/(speed*8.0);
// if((SciBaud-(unsigned int)SciBaud)>0.5) SciBaud++;
rs_arr->SciRegs->SCIHBAUD = HIBYTE((int)SciBaud);
rs_arr->SciRegs->SCILBAUD = LOBYTE((int)SciBaud);
}
/** Èíèöèàëèçàöèà ïîñëåäîâàòåëüíîãî ïîðòà */
void create_uart_vars(char size_cmd15_set)
{
size_cmd15=size_cmd15_set;
rs_a.commnumber=COM_1;
rs_b.commnumber=COM_2;
}
/** Èíèöèàëèçàöèà ïîñëåäîâàòåëüíîãî ïîðòà */
void setup_uart(char commnumber, unsigned long speed_baud)
{
volatile struct SCI_REGS *SciRegs;
RS_DATA *rs_arr;
if(commnumber==COM_1)
{
rs_a.SciRegs = &SciaRegs;
rs_arr = &rs_a;
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1; // SCITXDA - SCI-A transmit(O)
GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1; // SCIRXDA - SCI-A receive (I)
PieVectTable.SCIRXINTA = &RSA_RX_Handler;
PieVectTable.SCITXINTA = &RSA_TX_Handler;
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1
PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2
IER |= M_INT9; // Enable CPU INT
EDIS;
}
if(commnumber==COM_2)
{
rs_b.SciRegs = &ScibRegs;
rs_arr = &rs_b;
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 2; // SCITXDB - SCI-B transmit(O)
GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 2; // SCIRXDB - SCI-B receive (I)
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO 34 - general purpose I/O 34 (default)
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // Configures the GPIO pin as an output
PieVectTable.SCIRXINTB = &RSB_RX_Handler;
PieVectTable.SCITXINTB = &RSB_TX_Handler;
PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3
PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4
IER |= M_INT9; // Enable CPU INT
EDIS;
}
rs_arr->commnumber = commnumber;
SciRegs = rs_arr->SciRegs;
RS_SetLineMode(rs_arr,8,'N',1);
// enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciRegs->SCIFFCT.bit.ABDCLR=1;
SciRegs->SCIFFCT.bit.CDC=0;
SciRegs->SCICTL1.bit.RXERRINTENA=0;
SciRegs->SCICTL1.bit.SWRESET=0;
SciRegs->SCICTL1.bit.TXWAKE=0;
SciRegs->SCICTL1.bit.SLEEP=0;
SciRegs->SCICTL1.bit.TXENA=1;
SciRegs->SCICTL1.bit.RXENA=1;
SciRegs->SCIFFTX.bit.SCIFFENA=0; // fifo off
SciRegs->SCIFFRX.bit.RXFFIL=1; // Äëèíà íàèìåíüøåé êîìàíäû
setup_arr_cmd_length();
RS_SetLineSpeed(rs_arr,speed_baud); // ñêîðîñòü ëèíèè
RS_Line_to_receive(rs_arr); // ðåæèì ïðèåìà RS485
enableUARTInt(rs_arr); // ðàçðåøåíèå ïðåðûâàíèé UART
RS_SetBitMode(rs_arr,9);
rs_arr->RS_PrevCmd = 0; // íå áûëî íèêàêèõ êîìàíä
rs_arr->flag_TIMEOUT_to_Send = 0;
rs_arr->flag_LEADING = 0;
SciRegs->SCIFFRX.bit.RXFFINTCLR=1; // Clear INT flag
SciRegs->SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset
}
/** Íàñòðîéêà ðåæèìà ëèíèè.
@param bit êîëè÷åñòâî áèò äàííûõ
@param parity ðåæèì ÷åòíîñòè (N,O,E,M,S)
@param stop êîëè÷åñòâî ñòîïîâûõ áèò */
void RS_SetLineMode(RS_DATA *rs_arr, int bit, char parity, int stop)
{
volatile struct SCI_REGS *SciRegs;
/*
SCICCR - SCI Communication Control Register
Bit Bit Name Designation Functions
2-0 SCI CHAR2-0 SCICHAR Select the character (data) length (one to eight bits).
3 ADDR/IDLE MODE ADDRIDLE_MODE The idle-line mode (0) is usually used for normal communications because the address-bit mode adds an extra bit to the frame. The idle-line mode does not add this extra bit and is compatible with RS-232 type communications.
4 LOOP BACK ENABLE LOOPBKENA This bit enables (1) the Loop Back test mode where the Tx pin is internally connected to the Rx pin.
5 PARITY ENABLE PARITYENA Enables the parity function if set to 1, or disables the parity function if cleared to 0.
6 EVEN/ODD PARITY PARITY If parity is enabled, selects odd parity if cleared to 0 or even parity if set to 1.
7 STOP BITS STOPBITS Determines the number of stop bits transmitted-one stop bit if cleared to 0 or two stop bits if set to 1.
*/
SciRegs = rs_arr->SciRegs;
if(bit>0 && bit<9) SciRegs->SCICCR.bit.SCICHAR = bit-1;
switch(parity)
{
case 'N': SciRegs->SCICCR.bit.PARITYENA = 0;
break;
case 'O': SciRegs->SCICCR.bit.PARITYENA = 1;
SciRegs->SCICCR.bit.PARITY = 0;
break;
case 'E': SciRegs->SCICCR.bit.PARITYENA = 1;
SciRegs->SCICCR.bit.PARITY = 1;
break;
}
if (stop==1) SciRegs->SCICCR.bit.STOPBITS = 0;
if (stop==2) SciRegs->SCICCR.bit.STOPBITS = 1;
SciRegs->SCICCR.bit.LOOPBKENA = 0; //0
SciRegs->SCICCR.bit.ADDRIDLE_MODE = 0;
}
void clear_timer_rs_live(RS_DATA *rs_arr)
{
rs_arr->time_wait_rs_out=0;
}
/* ïðîâåðêà íà æèâó÷åñòü RS */
void test_rs_live(RS_DATA *rs_arr)
{
/* if (rs_arr->time_wait_rs_out < RS_TIME_OUT)
rs_arr->time_wait_rs_out++;
else
{
rs_arr->time_wait_rs_out=0;
RS_Line_to_receive(rs_arr); // ðåæèì ïðèåìà RS485
RS_SetBitMode(rs_arr,9);
}*/ }