From b038c3b87564e9f4acac0019b18fd6d20692ac38 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Fri, 16 May 2014 16:41:30 +0800 Subject: Tangential change --- rs422lib/precomp.h | 2 +- rs422lib/rsbus.c | 16 ++++++++++------ rs422lib/rsbus.h | 16 +++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/rs422lib/precomp.h b/rs422lib/precomp.h index 3c7c016..11f64be 100644 --- a/rs422lib/precomp.h +++ b/rs422lib/precomp.h @@ -19,7 +19,7 @@ #define RSADDR (1) -#define MACTYPE (TYPE0) +#define MACTYPE (0x00) //TYPE 0 is a dummy used for debug // Change it in real implementation //define delay func diff --git a/rs422lib/rsbus.c b/rs422lib/rsbus.c index 4c0fcb2..2b548a6 100644 --- a/rs422lib/rsbus.c +++ b/rs422lib/rsbus.c @@ -10,6 +10,11 @@ #define SYSRET (0xF0) #define INSREP (0x0F) +// Maximum size of receive buffer +#define RSMAX (20) + +#define CODE_LEN (6) + unsigned char rs_rxbuf[RSMAX]; unsigned char len; unsigned char pch; @@ -17,7 +22,7 @@ rshdlr rxhdlr; enum rs_stat{REST,ST,ADDR,READ,DISCARD,ED,DED}; enum rs_stat rs_st=REST; -unsigned char rs_tx[20]={STBIT1,0,RSADDR,MACTYPE}; +unsigned char rs_tx[CODE_LEN+RS_MAX]={STBIT1,0,RSADDR,MACTYPE}; volatile unsigned char tx_len; volatile unsigned char tx_pos=255; @@ -36,6 +41,7 @@ __interrupt void USCI0TX_ISR(void) UCA0TXBUF = rs_tx[tx_pos++]; // TX next character } +// Inline send for ISR #pragma FUNC_ALWAYS_INLINE(rsbus_w_irq) static __inline void rsbus_w_irq(unsigned char* buf,unsigned int len) { @@ -46,8 +52,6 @@ static __inline void rsbus_w_irq(unsigned char* buf,unsigned int len) tx_len=len+7; unsigned int parity=MACTYPE^RSADDR; rs_tx[1]=0; // Useless addr spec - rs_tx[2]=RSADDR; - rs_tx[3]=MACTYPE; for (i=0;i wait unsigned int i; - if (len>14) + if (len>RS_MAX) return; RSOUT |= RSPIN; tx_len=len+7; unsigned int parity=addr^MACTYPE^RSADDR; rs_tx[1]=addr; // Useless addr spec - rs_tx[2]=RSADDR; - rs_tx[3]=MACTYPE; for (i=0;i #include"precomp.h" +// MAXIMUM length to be send +#define RS_MAX (14) + #define ST_BUSY (0x04) #define ST_RUN (0x02) #define ST_RES (0x01) #define ST_REST (0x00) +// Switch the machine to a new state specified above +// This will shown on the network -> must call #define SWITCH_STATE(STATE) (mac_stat[0]=STATE) +// Changing the state value (unsigned char) -> +// Available indices 0,1,2 #define STATE(X) (mac_stat[X+1]) -#define TYPE0 (0x00) //TYPE 0 is a dummy used for debug - -#define TYPE1 (0x01) -#define TYPE2 (0x02) - #define STBIT0 (0x5B) #define STBIT1 (0xAD) #define EDBIT0 (0xA4) #define EDBIT1 (0x52) -#define TXLEN (4) - -#define RSMAX (20) - typedef void (*rshdlr)(unsigned char*,int); void rsbus_init(rshdlr); -- cgit v1.2.3-70-g09d2