From 6b80a743d44d73d8af9cc12fbffe9548904b3b62 Mon Sep 17 00:00:00 2001 From: tcsadmin Date: Fri, 21 Jan 2011 22:08:04 +0000 Subject: Addressable hi-speed RS485 port changes (first byte is the device address) git-svn-id: https://mindboards.svn.sourceforge.net/svnroot/mindboards/lms_nbcnxc/branches/version_131@31 c9361245-7fe8-9947-84e8-057757c4e366 --- AT91SAM7S256/Source/c_comm.c | 54 +++++++++++++++++++++++++----------------- AT91SAM7S256/Source/c_comm.iom | 13 +++++++++- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/AT91SAM7S256/Source/c_comm.c b/AT91SAM7S256/Source/c_comm.c index 5b5292d..c760b84 100644 --- a/AT91SAM7S256/Source/c_comm.c +++ b/AT91SAM7S256/Source/c_comm.c @@ -161,6 +161,7 @@ void cCommInit(void* pHeader) IOMapComm.BtDeviceCnt = 0; IOMapComm.BrickData.BtStateStatus = 0; IOMapComm.HsSpeed = HS_BAUD_921600; + IOMapComm.HsAddress = HS_ADDRESS_ALL; IOMapComm.HsMode = HS_MODE_8N1; IOMapComm.BtDataMode = DATA_MODE_NXT; IOMapComm.HsDataMode = DATA_MODE_RAW; @@ -1508,7 +1509,8 @@ void cCommReceivedHiSpeedData(void) { UWORD NumberOfBytes; UWORD Tmp; - + UBYTE Address; + dHiSpeedReceivedData(&NumberOfBytes); if (NumberOfBytes != 0) @@ -1532,29 +1534,37 @@ void cCommReceivedHiSpeedData(void) else { // receiving hi-speed data in NXT mode - /* Copy the bytes into the IOMapBuffer */ if (NumberOfBytes > SIZE_OF_HSBUF) NumberOfBytes = SIZE_OF_HSBUF; - memcpy((PSZ)IOMapComm.HsInBuf.Buf, (PSZ)VarsComm.HsModuleInBuf.Buf, NumberOfBytes); - memset((PSZ)VarsComm.HsModuleInBuf.Buf, 0, 256); - - /* Move the inptr ahead */ - IOMapComm.HsInBuf.InPtr = NumberOfBytes; - IOMapComm.HsInBuf.OutPtr = 0; - - /* using the outbuf inptr in order to get the number of bytes in the return answer at the right place*/ - IOMapComm.HsOutBuf.InPtr = NumberOfBytes; - - /* call the data stream interpreter */ - cCommInterprete(IOMapComm.HsInBuf.Buf, IOMapComm.HsOutBuf.Buf, &(IOMapComm.HsOutBuf.InPtr), (UBYTE) HS_CMD_READY, NumberOfBytes); - - /* if there is a reply to be sent then send it */ - if (IOMapComm.HsOutBuf.InPtr) - { - cCommSendHiSpeedData(); -// dHiSpeedSendData(IOMapComm.HsOutBuf.Buf, IOMapComm.HsOutBuf.InPtr); - IOMapComm.HsOutBuf.InPtr = 0; - IOMapComm.HsOutBuf.OutPtr = 0; + Address = VarsComm.HsModuleInBuf.Buf[0]; + NumberOfBytes--; + if ((IOMapComm.HsAddress == Address) || + (HS_ADDRESS_ALL == Address) || + (HS_ADDRESS_ALL == IOMapComm.HsAddress)) + { + /* Copy the bytes into the IOMapBuffer */ + memcpy((PSZ)IOMapComm.HsInBuf.Buf, (PSZ)(VarsComm.HsModuleInBuf.Buf+1), NumberOfBytes); + memset((PSZ)VarsComm.HsModuleInBuf.Buf, 0, 256); + + /* Move the inptr ahead */ + IOMapComm.HsInBuf.InPtr = NumberOfBytes; + IOMapComm.HsInBuf.OutPtr = 0; + + /* using the outbuf inptr in order to get the number of bytes in the return answer at the right place*/ + IOMapComm.HsOutBuf.InPtr = NumberOfBytes; + + /* call the data stream interpreter */ + cCommInterprete(IOMapComm.HsInBuf.Buf, (UBYTE *)(IOMapComm.HsOutBuf.Buf+1), &(IOMapComm.HsOutBuf.InPtr), (UBYTE) HS_CMD_READY, NumberOfBytes); + + /* if there is a reply to be sent then send it */ + if (IOMapComm.HsOutBuf.InPtr) + { + IOMapComm.HsOutBuf.Buf[0] = HS_ADDRESS_ALL; // reply is sent to "all" + IOMapComm.HsOutBuf.InPtr++; + cCommSendHiSpeedData(); + IOMapComm.HsOutBuf.InPtr = 0; + IOMapComm.HsOutBuf.OutPtr = 0; + } } } } diff --git a/AT91SAM7S256/Source/c_comm.iom b/AT91SAM7S256/Source/c_comm.iom index 367a0db..7f11837 100644 --- a/AT91SAM7S256/Source/c_comm.iom +++ b/AT91SAM7S256/Source/c_comm.iom @@ -127,6 +127,17 @@ enum #define HS_MODE_8N1 (HS_MODE_8_DATA|HS_MODE_N_PARITY|HS_MODE_10_STOP) #define HS_MODE_7E1 (HS_MODE_7_DATA|HS_MODE_E_PARITY|HS_MODE_10_STOP) +// constants referring to HsAddress +#define HS_ADDRESS_ALL 0 +#define HS_ADDRESS_1 1 +#define HS_ADDRESS_2 2 +#define HS_ADDRESS_3 3 +#define HS_ADDRESS_4 4 +#define HS_ADDRESS_5 5 +#define HS_ADDRESS_6 6 +#define HS_ADDRESS_7 7 +#define HS_ADDRESS_8 8 + //Constants refering to DeviceStatus within DeviceTable enum { @@ -273,7 +284,7 @@ typedef struct UBYTE HsState; UBYTE UsbState; - UBYTE Spare1; // fill the vacant byte that would otherwise be here + UBYTE HsAddress; // make RS485 addressible for up to 8 bricks UWORD HsMode; -- cgit v1.2.3