139 lines
4.6 KiB
C
139 lines
4.6 KiB
C
/****************************************************************/
|
|
/* TMS320C32 */
|
|
/* ====== BIOS, ÊËÀÈÍ, ÊËÂÑÏ ====== */
|
|
/* ÖÍÈÈ ÑÝÒ (ñ) 1998-2000 ã. */
|
|
/****************************************************************
|
|
RS485.h
|
|
****************************************************************
|
|
* Ïðîöåäóðû ðàáîòû ñ UART *
|
|
****************************************************************/
|
|
#ifndef _RS485
|
|
#define _RS485
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
//#include "DSP2833x_Device.h" // DSP281x Headerfile Include File
|
|
//#include "DSP2833x_Sci.h"
|
|
//#include "cntrl_adr.h"
|
|
//#include "params.h"
|
|
|
|
#define COM_1 1
|
|
#define COM_2 2
|
|
|
|
#define MAX_RECEIVE_LENGTH 400 // 80 //150
|
|
#define MAX_SEND_LENGTH 400 //150
|
|
|
|
#define TIME_WAIT_RS_BYTE_OUT 1000
|
|
#define TIME_WAIT_RS_LOST_BYTE 100
|
|
#define RS_TIME_OUT (SECOND*10)
|
|
|
|
#define Rec_Bloc_Begin 0x200000
|
|
#define Rec_Bloc_End 0x2F0000
|
|
#define Rec_Bloc_Length (Rec_Bloc_End-Rec_Bloc_Begin)
|
|
|
|
/* Message RS declaration */
|
|
typedef struct
|
|
{
|
|
volatile struct SCI_REGS *SciRegs;
|
|
|
|
unsigned int commnumber; // Íîìåð ïîðòà
|
|
unsigned long RS_Length; // Äëèíà ïàêåòà
|
|
|
|
unsigned int *pRS_RecvPtr; // Áóôåð ïðèåìà
|
|
unsigned int *pRS_SendPtr; // Áóôåð ïîñûëêè
|
|
unsigned int *pRecvPtr;
|
|
|
|
unsigned int RS_PrevCmd; // Ïðåäûäóùàà êîììàíäà
|
|
unsigned int RS_Cmd; // Òåêóùàà êîììàíäà
|
|
unsigned int RS_Header[MAX_RECEIVE_LENGTH]; // Çàãîëîâîê
|
|
unsigned int flag_TIMEOUT_to_Send; // Ôëàã îæèäàíèà òàéìàóòà íà îòñûëêó
|
|
unsigned int flag_TIMEOUT_to_Receive; // Ôëàã îæèäàíèà òàéìàóòà íà ïðèåì
|
|
unsigned int RS_DataReady; // Ôëàã ãîòîâíîñòè RS äàííûõ
|
|
unsigned int buffer[MAX_SEND_LENGTH]; // Áóôåð äëà îòñûëêè ïî RS
|
|
|
|
unsigned int addr_answer; // àäðåñ êóäà îòâå÷àòü â ðåæèìå âåäóùåãî
|
|
unsigned int addr_recive; // àäðåñ ïî êîòîðîìó íàñ çàïðîñèëè
|
|
unsigned int flag_LEADING; // Ôëàã ðåæèìà êîíòðîëëåðà (ïî óìîë÷àíèþ âåäîìûé)
|
|
unsigned long RS_RecvLen;
|
|
unsigned long RS_SLength; // Äëèíà ïàêåòà äëà ïîñûëêè
|
|
unsigned long RS_SendLen; // Êîëè÷åñòâî áàéò óæå ïåðåäàëè
|
|
char RS_SendBlockMode; // Ðåæèì ïåðåäà÷è
|
|
char RS_Flag9bit; // äëà RS485????????
|
|
int BS_LoadOK; // Ôëàã óñïåøíîñòè ïðèåìà áëîêà
|
|
int RS_FlagBegin;
|
|
int RS_HeaderCnt;
|
|
int RS_FlagSkiping;
|
|
unsigned long curr_baud;
|
|
unsigned long time_wait_rs_out;
|
|
|
|
} RS_DATA;
|
|
|
|
extern RS_DATA rs_a,rs_b;
|
|
|
|
extern unsigned int
|
|
RS_Len[70]; /* Äåéñòâèòåëüíàà äëèíà êîìàíäû (îòëàäî÷íîé) + 1 */
|
|
|
|
interrupt void RSA_RX_Handler(void);
|
|
interrupt void RSA_TX_Handler(void);
|
|
interrupt void RSB_RX_Handler(void);
|
|
interrupt void RSB_TX_Handler(void);
|
|
|
|
/* èíèöèëèçàöèà ïåðåìåííûõ rs_a,rs_b*/
|
|
void create_uart_vars(char size_cmd15);
|
|
|
|
/** Ïîâòîðíàà èíèöèàëèçàöèà ïîñëåäîâàòåëüíîãî ïîðòà, èñïîëüçóåòñà ïîñëå ïîäâèñà */
|
|
/** Íàñòðîéêà ðåæèìà ïðèåìà/ïåðåäà÷è */
|
|
void RS_SetBitMode(RS_DATA *rs_arr, int n);
|
|
|
|
/** Ïîñûëêà áëîêà áàéòîâ.
|
|
Ïîñûëàåò ìàññèâà 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);
|
|
|
|
/** Ïîñûëêà áëîêà óïàêîâàííûõ áàéòîâ.
|
|
@precondition Ðàáîòà ô-öèè çàâèñèò îò ìàêðî RS_TRANSMIT_INTR
|
|
@param buf àäðåñ ìàññèâà
|
|
@param len êîëè÷åñòâî 8-áèòíûõ áàéò
|
|
@see RS_Send, RS_TRANSMIT_INTR
|
|
*/
|
|
int RS_BSend(RS_DATA *rs_arr,unsigned int *pBuf, unsigned long len);
|
|
|
|
/** Èíèöèàëèçàöèà ïîñëåäîâàòåëüíîãî ïîðòà */
|
|
void setup_uart(char commnumber,unsigned long speed_baud); /* speed_baud - ñêîðîñòü ëèíèè â áîäàõ */
|
|
|
|
void RS_SetLineMode(RS_DATA *rs_arr, int bit, char parity, int stop);
|
|
void RS_SetLineSpeed(RS_DATA *rs_arr, unsigned long speed);
|
|
|
|
// Transmit a character from the SCI'
|
|
#define SCI_send(x,y) x->SciRegs->SCITXBUF=(unsigned char)(y)
|
|
|
|
// Îæèäàíèå çàâåðøåíèà ïåðåäà÷è UART
|
|
// wait for TRDY =1 for empty state
|
|
#define RS_Wait4OK(x) while(!(x->SciRegs->SCICTL2.bit.TXEMPTY))
|
|
|
|
/** Ïåðåêëþ÷åíèå ëèíèè íà ïðèåì */
|
|
#define RS_Line_to_receive(x) if(x->commnumber==COM_2) GpioDataRegs.GPBDAT.bit.GPIO34 = 1;
|
|
|
|
/** Ïåðåêëþ÷åíèå ëèíèè íà ïåðåäà÷ó */
|
|
#define RS_Line_to_send(x) if(x->commnumber==COM_2) GpioDataRegs.GPBDAT.bit.GPIO34 = 0;
|
|
|
|
/** Ðàçðåøåíèå ïðåðûâàíèé ïî ïîëó÷åíèþ ñèìâîëà è îøèáêàì îò UART */
|
|
#define enableUARTInt(x) x->SciRegs->SCICTL2.all=2
|
|
#define enableUARTIntW(x) x->SciRegs->SCICTL2.all=1
|
|
|
|
void clear_timer_rs_live(RS_DATA *rs_arr);
|
|
void test_rs_live(RS_DATA *rs_arr);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _RS485 */
|
|
|