99#include "AvrModbus.h"
1010#include "crc16.h"
1111/*********************************************************************************/
12- #if (AVR_MODBUS_REVISION_DATE != 20190828 )
12+ #if (AVR_MODBUS_REVISION_DATE != 20191010 )
1313#error wrong include file. (AvrModbus.h)
1414#endif
1515/*********************************************************************************/
1818/*********************************************************************************/
1919#if (AVR_MODBUS_SLAVE == true )
2020
21- static char CheckAllOfSlaveInit (tag_AvrModbusSlaveCtrl * Slave )
21+ static tU8 CheckAllOfSlaveInit (tag_AvrModbusSlaveCtrl * Slave )
2222{
2323 /*
2424 1) 인수
@@ -35,11 +35,11 @@ static char CheckAllOfSlaveInit(tag_AvrModbusSlaveCtrl *Slave)
3535 return (Slave -> Bit .InitGeneral ) ? true : false;
3636}
3737/*********************************************************************************/
38- static void ErrorException (tag_AvrModbusSlaveCtrl * Slave , char ErrCode )
38+ static void ErrorException (tag_AvrModbusSlaveCtrl * Slave , tU8 ErrCode )
3939{
4040 tag_AvrUartRingBuf * TxQue = & Slave -> Uart -> TxQueue ;
4141 tag_AvrUartRingBuf * RxQue = & Slave -> Uart -> RxQueue ;
42- unsigned int Crc16 ;
42+ tU16 Crc16 ;
4343
4444 /*
4545 1) 인수
@@ -71,8 +71,8 @@ static void SlaveReadHolding(tag_AvrModbusSlaveCtrl *Slave)
7171{
7272 tag_AvrUartRingBuf * TxQue = & Slave -> Uart -> TxQueue ;
7373 tag_AvrUartRingBuf * RxQue = & Slave -> Uart -> RxQueue ;
74- unsigned int StartAddr , NumberOfPoint , Crc16 , i ;
75- char * BaseAddr ;
74+ tU16 StartAddr , NumberOfPoint , Crc16 , i ;
75+ tU8 * BaseAddr ;
7676
7777 /*
7878 1) 인수
@@ -85,12 +85,12 @@ static void SlaveReadHolding(tag_AvrModbusSlaveCtrl *Slave)
8585 - Master의 'ReadHolding' 명령에 대한 처리.
8686 */
8787
88- StartAddr = (int ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
89- NumberOfPoint = (int ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
88+ StartAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
89+ NumberOfPoint = (tU16 ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
9090
9191 StartAddr = (StartAddr < 200 ) ? 0 : StartAddr - 200 ;
9292 NumberOfPoint *= 2 ;
93- BaseAddr = (char * ) (((int * ) Slave -> BaseAddr ) + StartAddr );
93+ BaseAddr = (tU8 * ) (((tU16 * ) Slave -> BaseAddr ) + StartAddr );
9494
9595 AvrUartPutChar (Slave -> Uart , RxQue -> Buf [0 ]); //Slave Address
9696 AvrUartPutChar (Slave -> Uart , RxQue -> Buf [1 ]); //Function
@@ -120,8 +120,8 @@ static void SlavePresetSingle(tag_AvrModbusSlaveCtrl *Slave)
120120{
121121 tag_AvrUartRingBuf * TxQue = & Slave -> Uart -> TxQueue ;
122122 tag_AvrUartRingBuf * RxQue = & Slave -> Uart -> RxQueue ;
123- int RegisterAddr , PresetData , * BaseAddr ;
124- unsigned int Crc16 ;
123+ tU16 RegisterAddr , PresetData , * BaseAddr ;
124+ tU16 Crc16 ;
125125
126126 /*
127127 1) 인수
@@ -134,16 +134,16 @@ static void SlavePresetSingle(tag_AvrModbusSlaveCtrl *Slave)
134134 - Master의 'PresetSingle' 명령에 대한 처리.
135135 */
136136
137- RegisterAddr = (int ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
138- PresetData = (int ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
137+ RegisterAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
138+ PresetData = (tU16 ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
139139
140140 if ((Slave -> Bit .InitCheckOutRange == true) && (Slave -> CheckOutRange (RegisterAddr , 1 ) == true))
141141 {
142142 ErrorException (Slave , 2 );
143143 }
144144 else
145145 {
146- BaseAddr = ((int * ) Slave -> BaseAddr ) + ((RegisterAddr < Slave -> MapStartAddr ) ? RegisterAddr : RegisterAddr - Slave -> MapStartAddr );
146+ BaseAddr = ((tU16 * ) Slave -> BaseAddr ) + ((RegisterAddr < Slave -> MapStartAddr ) ? RegisterAddr : RegisterAddr - Slave -> MapStartAddr );
147147 * BaseAddr = PresetData ;
148148
149149 if (Slave -> Bit .InitUserException == true)
@@ -180,8 +180,8 @@ static void SlavePresetMultiple(tag_AvrModbusSlaveCtrl *Slave)
180180{
181181 tag_AvrUartRingBuf * TxQue = & Slave -> Uart -> TxQueue ;
182182 tag_AvrUartRingBuf * RxQue = & Slave -> Uart -> RxQueue ;
183- unsigned int StartAddr , NumberOfRegister , Crc16 , Length , i , j = 7 ;
184- char * BaseAddr ;
183+ tU16 StartAddr , NumberOfRegister , Crc16 , Length , i , j = 7 ;
184+ tU8 * BaseAddr ;
185185
186186 /*
187187 1) 인수
@@ -205,7 +205,7 @@ static void SlavePresetMultiple(tag_AvrModbusSlaveCtrl *Slave)
205205 {
206206 Length = NumberOfRegister * 2 ;
207207 Length = (Length > (Slave -> Uart -> RxQueue .Size - 9 )) ? (Slave -> Uart -> RxQueue .Size - 9 ) : Length ;
208- BaseAddr = (char * ) (((int * ) Slave -> BaseAddr ) + ((StartAddr < Slave -> MapStartAddr ) ? StartAddr : StartAddr - Slave -> MapStartAddr ));
208+ BaseAddr = (tU8 * ) (((tU16 * ) Slave -> BaseAddr ) + ((StartAddr < Slave -> MapStartAddr ) ? StartAddr : StartAddr - Slave -> MapStartAddr ));
209209
210210 for (i = 0 ; i < Length ; i += 2 )
211211 {
@@ -243,7 +243,7 @@ static void SlavePresetMultiple(tag_AvrModbusSlaveCtrl *Slave)
243243 }
244244}
245245/*********************************************************************************/
246- char AvrModbusSlaveGeneralInit (tag_AvrModbusSlaveCtrl * Slave , tag_AvrUartCtrl * Uart , char * BaseAddr , long SlaveProcTick_us )
246+ tU8 AvrModbusSlaveGeneralInit (tag_AvrModbusSlaveCtrl * Slave , tag_AvrUartCtrl * Uart , tU8 * BaseAddr , tU32 SlaveProcTick_us )
247247{
248248 /*
249249 1) 인수
@@ -268,6 +268,7 @@ char AvrModbusSlaveGeneralInit(tag_AvrModbusSlaveCtrl *Slave, tag_AvrUartCtrl *U
268268 Slave -> MapStartAddr = 200 ;
269269 Slave -> Uart -> ReceivingDelay = AVR_MODBUS_RECEIVING_DELAY_US / SlaveProcTick_us ;
270270 if (Slave -> Uart -> ReceivingDelay < 2 ) Slave -> Uart -> ReceivingDelay = 2 ;
271+ AvrUartSetTxEndDelay (Uart , AVR_MODBUS_SLAVE_DEFAULT_TX_END_DELAY , SlaveProcTick_us );
271272
272273 Slave -> Bit .InitGeneral = true;
273274 }
@@ -277,7 +278,7 @@ char AvrModbusSlaveGeneralInit(tag_AvrModbusSlaveCtrl *Slave, tag_AvrUartCtrl *U
277278 return Slave -> Bit .InitGeneral ;
278279}
279280/*********************************************************************************/
280- char AvrModbusSlaveLinkCheckRangeFunc (tag_AvrModbusSlaveCtrl * Slave , char (* CheckOutRange )(int StartAddr , int NumberOfRegister ))
281+ tU8 AvrModbusSlaveLinkCheckRangeFunc (tag_AvrModbusSlaveCtrl * Slave , tU8 (* CheckOutRange )(tU16 StartAddr , tU16 NumberOfRegister ))
281282{
282283 /*
283284 1) 인수
@@ -306,7 +307,7 @@ char AvrModbusSlaveLinkCheckRangeFunc(tag_AvrModbusSlaveCtrl *Slave, char (*Chec
306307 return Slave -> Bit .InitCheckOutRange ;
307308}
308309/*********************************************************************************/
309- char AvrModbusSlaveLinkUserExceptionFunc (tag_AvrModbusSlaveCtrl * Slave , void (* UserException )(int StartAddr , int NumberOfRegister ))
310+ tU8 AvrModbusSlaveLinkUserExceptionFunc (tag_AvrModbusSlaveCtrl * Slave , void (* UserException )(tU16 StartAddr , tU16 NumberOfRegister ))
310311{
311312 /*
312313 1) 인수
@@ -335,7 +336,7 @@ char AvrModbusSlaveLinkUserExceptionFunc(tag_AvrModbusSlaveCtrl *Slave, void (*U
335336 return Slave -> Bit .InitUserException ;
336337}
337338/*********************************************************************************/
338- char AvrModbusSlaveLinkPreUserExceptionFunc (tag_AvrModbusSlaveCtrl * Slave , char (* PreUserException )(struct tag_AvrModbusSlaveCtrl * Slave , unsigned char * SlaveId ))
339+ tU8 AvrModbusSlaveLinkPreUserExceptionFunc (tag_AvrModbusSlaveCtrl * Slave , tU8 (* PreUserException )(struct tag_AvrModbusSlaveCtrl * Slave , tU8 * SlaveId ))
339340{
340341 /*
341342 1) 인수
@@ -364,7 +365,7 @@ char AvrModbusSlaveLinkPreUserExceptionFunc(tag_AvrModbusSlaveCtrl *Slave, char
364365 return Slave -> Bit .InitPreUserException ;
365366}
366367/*********************************************************************************/
367- char AvrModbusSlaveSetMapStartAddr (tag_AvrModbusSlaveCtrl * Slave , unsigned int MapStartAddr )
368+ tU8 AvrModbusSlaveSetMapStartAddr (tag_AvrModbusSlaveCtrl * Slave , tU16 MapStartAddr )
368369{
369370 /*
370371 1) 인수
@@ -389,7 +390,7 @@ char AvrModbusSlaveSetMapStartAddr(tag_AvrModbusSlaveCtrl *Slave, unsigned int M
389390 return true;
390391}
391392/*********************************************************************************/
392- char AvrModbusSlaveLinkCustomFrameCheck (tag_AvrModbusSlaveCtrl * Slave , int (* CustomFrameCheck )(tag_AvrUartRingBuf * RxQue , int Ctr ))
393+ tU8 AvrModbusSlaveLinkCustomFrameCheck (tag_AvrModbusSlaveCtrl * Slave , tU16 (* CustomFrameCheck )(tag_AvrUartRingBuf * RxQue , tU16 Ctr ))
393394{
394395 /*
395396 1) 인수
@@ -415,11 +416,11 @@ char AvrModbusSlaveLinkCustomFrameCheck(tag_AvrModbusSlaveCtrl *Slave, int (*Cus
415416 return Slave -> Bit .InitCustomFrameCheck ;
416417}
417418/*********************************************************************************/
418- void AvrModbusSlaveProc (tag_AvrModbusSlaveCtrl * Slave , unsigned char SlaveId )
419+ void AvrModbusSlaveProc (tag_AvrModbusSlaveCtrl * Slave , tU8 SlaveId )
419420{
420421 tag_AvrUartRingBuf * RxQue = & Slave -> Uart -> RxQueue ;
421- unsigned int Crc16 ;
422- unsigned char PreException = false;
422+ tU16 Crc16 ;
423+ tU8 PreException = false;
423424
424425 /*
425426 1) 인수
@@ -439,8 +440,8 @@ void AvrModbusSlaveProc(tag_AvrModbusSlaveCtrl *Slave, unsigned char SlaveId)
439440 return ;
440441 }
441442
442- AvrUartFixTxEnableFloating (Slave -> Uart );
443-
443+ AvrUartControlTxEnd (Slave -> Uart );
444+
444445 if ((AvrUartCheckRx (Slave -> Uart ) >= 1 ) && (AvrUartCheckReceiving (Slave -> Uart ) == false))
445446 {
446447 if (Slave -> Bit .InitPreUserException && Slave -> PreUserException (Slave , & SlaveId )) PreException = true;
@@ -496,7 +497,7 @@ void AvrModbusSlaveProc(tag_AvrModbusSlaveCtrl *Slave, unsigned char SlaveId)
496497/*********************************************************************************/
497498#if (AVR_MODBUS_MASTER == true )
498499
499- static char CheckAllOfMasterInit (tag_AvrModbusMasterCtrl * Master )
500+ static tU8 CheckAllOfMasterInit (tag_AvrModbusMasterCtrl * Master )
500501{
501502 /*
502503 1) 인수
@@ -515,7 +516,7 @@ static char CheckAllOfMasterInit(tag_AvrModbusMasterCtrl *Master)
515516/*********************************************************************************/
516517static tag_AvrModbusMasterSlaveInfo * GetAddedSlaveInfo (tag_AvrModbusMasterCtrl * Master , tag_AvrModbusMasterSlaveInfo * Slave )
517518{
518- char i = 0 ;
519+ tU8 i = 0 ;
519520 tag_AvrModbusMasterSlaveInfo * SlaveTemp = Slave ;
520521
521522 /*
@@ -557,7 +558,7 @@ static void MasterPolling(tag_AvrModbusMasterCtrl *Master)
557558{
558559 tag_AvrUartRingBuf * TxQue = & Master -> Uart -> TxQueue ;
559560 tag_AvrModbusMasterSlavePollData * PollData ;
560- unsigned int Crc16 ;
561+ tU16 Crc16 ;
561562
562563 /*
563564 1) 인수
@@ -599,7 +600,7 @@ static void MasterPolling(tag_AvrModbusMasterCtrl *Master)
599600/*********************************************************************************/
600601static void MasterReceive (tag_AvrModbusMasterCtrl * Master )
601602{
602- unsigned int Crc16 , Length , i , j = 3 ;
603+ tU16 Crc16 , Length , i , j = 3 ;
603604 tag_AvrUartRingBuf * RxQue = & Master -> Uart -> RxQueue ;
604605 tag_AvrModbusMasterSlavePollData * PollData ;
605606 tag_AvrModbusMasterSlaveInfo * Slave ;
@@ -640,7 +641,7 @@ static void MasterReceive(tag_AvrModbusMasterCtrl *Master)
640641 }
641642}
642643/*********************************************************************************/
643- char AvrModbusMasterGeneralInit (tag_AvrModbusMasterCtrl * Master , tag_AvrUartCtrl * Uart , char MaxSlave , long MasterProcTick_us )
644+ tU8 AvrModbusMasterGeneralInit (tag_AvrModbusMasterCtrl * Master , tag_AvrUartCtrl * Uart , tU8 MaxSlave , tU32 MasterProcTick_us )
644645{
645646 /*
646647 1) 인수
@@ -677,7 +678,7 @@ char AvrModbusMasterGeneralInit(tag_AvrModbusMasterCtrl *Master, tag_AvrUartCtrl
677678 return Master -> Bit .InitGeneral ;
678679}
679680/*********************************************************************************/
680- char AvrModbusMasterSetPollingDelay (tag_AvrModbusMasterCtrl * Master , long PollDelay_us )
681+ tU8 AvrModbusMasterSetPollingDelay (tag_AvrModbusMasterCtrl * Master , tU32 PollDelay_us )
681682{
682683 /*
683684 1) 인수
@@ -701,9 +702,9 @@ char AvrModbusMasterSetPollingDelay(tag_AvrModbusMasterCtrl *Master, long PollDe
701702 return true;
702703}
703704/*********************************************************************************/
704- char AvrModbusMasterAddSlave (tag_AvrModbusMasterCtrl * Master , unsigned char Id , int StartAddr , int NumberOfRegister , char * BaseAddr )
705+ tU8 AvrModbusMasterAddSlave (tag_AvrModbusMasterCtrl * Master , tU8 Id , tU16 StartAddr , tU16 NumberOfRegister , tU8 * BaseAddr )
705706{
706- char i ;
707+ tU8 i ;
707708 tag_AvrModbusMasterSlaveInfo * Slave = Master -> SlaveArray ;
708709
709710 /*
@@ -767,9 +768,9 @@ char AvrModbusMasterAddSlave(tag_AvrModbusMasterCtrl *Master, unsigned char Id,
767768 return false;
768769}
769770/*********************************************************************************/
770- char AvrModbusMasterAddSlavePollData (tag_AvrModbusMasterCtrl * Master , unsigned char Id , int StartAddr , int NumberOfRegister , char * BaseAddr )
771+ tU8 AvrModbusMasterAddSlavePollData (tag_AvrModbusMasterCtrl * Master , tU8 Id , tU16 StartAddr , tU16 NumberOfRegister , tU8 * BaseAddr )
771772{
772- char i ;
773+ tU8 i ;
773774 tag_AvrModbusMasterSlaveInfo * Slave = Master -> SlaveArray ;
774775
775776 /*
@@ -833,7 +834,7 @@ char AvrModbusMasterAddSlavePollData(tag_AvrModbusMasterCtrl *Master, unsigned c
833834 return true;
834835}
835836/*********************************************************************************/
836- void AvrModbusMasterRemoveSlave (tag_AvrModbusMasterCtrl * Master , unsigned char Id )
837+ void AvrModbusMasterRemoveSlave (tag_AvrModbusMasterCtrl * Master , tU8 Id )
837838{
838839 tag_AvrModbusMasterSlaveInfo * Slave ;
839840
@@ -864,7 +865,7 @@ void AvrModbusMasterRemoveSlave(tag_AvrModbusMasterCtrl *Master, unsigned char I
864865 }
865866}
866867/*********************************************************************************/
867- void AvrModbusMasterSetSlaveNoResponse (tag_AvrModbusMasterCtrl * Master , unsigned char Id , unsigned char NoResponseLimit )
868+ void AvrModbusMasterSetSlaveNoResponse (tag_AvrModbusMasterCtrl * Master , tU8 Id , tU8 NoResponseLimit )
868869{
869870 tag_AvrModbusMasterSlaveInfo * Slave = null ;
870871
@@ -895,7 +896,7 @@ void AvrModbusMasterSetSlaveNoResponse(tag_AvrModbusMasterCtrl *Master, unsigned
895896 }
896897}
897898/*********************************************************************************/
898- void AvrModbusMasterSetSlavePollFunction (tag_AvrModbusMasterCtrl * Master , unsigned char Id , enum_AvrModbusFunction PollFunction )
899+ void AvrModbusMasterSetSlavePollFunction (tag_AvrModbusMasterCtrl * Master , tU8 Id , enum_AvrModbusFunction PollFunction )
899900{
900901 tag_AvrModbusMasterSlaveInfo * Slave = null ;
901902
@@ -925,7 +926,7 @@ void AvrModbusMasterSetSlavePollFunction(tag_AvrModbusMasterCtrl *Master, unsign
925926 }
926927}
927928/*********************************************************************************/
928- char AvrModbusMasterLinkUserException (tag_AvrModbusMasterCtrl * Master , void (* UserException )(unsigned char Id ))
929+ tU8 AvrModbusMasterLinkUserException (tag_AvrModbusMasterCtrl * Master , void (* UserException )(tU8 Id ))
929930{
930931 /*
931932 1) 인수
@@ -1001,9 +1002,9 @@ void AvrModbusMasterProc(tag_AvrModbusMasterCtrl *Master)
10011002 }
10021003}
10031004/*********************************************************************************/
1004- char AvrModbusMasterPresetSingle (tag_AvrModbusMasterCtrl * Master , unsigned char SlaveId , int RegAddr , int PresetData )
1005+ tU8 AvrModbusMasterPresetSingle (tag_AvrModbusMasterCtrl * Master , tU8 SlaveId , tU16 RegAddr , tU16 PresetData )
10051006{
1006- unsigned int Crc16 ;
1007+ tU16 Crc16 ;
10071008 tag_AvrUartRingBuf * TxQue = & Master -> Uart -> TxQueue ;
10081009
10091010 /*
@@ -1043,9 +1044,9 @@ char AvrModbusMasterPresetSingle(tag_AvrModbusMasterCtrl *Master, unsigned char
10431044 return true;
10441045}
10451046/*********************************************************************************/
1046- char AvrModbusMasterPresetMultiple (tag_AvrModbusMasterCtrl * Master , unsigned char SlaveId , int StartAddr , int NumberOfRegister , char * BaseAddr )
1047+ tU8 AvrModbusMasterPresetMultiple (tag_AvrModbusMasterCtrl * Master , tU8 SlaveId , tU16 StartAddr , tU16 NumberOfRegister , tU8 * BaseAddr )
10471048{
1048- unsigned int Crc16 , i ;
1049+ tU16 Crc16 , i ;
10491050 tag_AvrUartRingBuf * TxQue = & Master -> Uart -> TxQueue ;
10501051
10511052 /*
@@ -1095,7 +1096,7 @@ char AvrModbusMasterPresetMultiple(tag_AvrModbusMasterCtrl *Master, unsigned cha
10951096 return true;
10961097}
10971098/*********************************************************************************/
1098- char AvrModbusMasterCheckSlaveNoResponse (tag_AvrModbusMasterCtrl * Master , unsigned char Id )
1099+ tU8 AvrModbusMasterCheckSlaveNoResponse (tag_AvrModbusMasterCtrl * Master , tU8 Id )
10991100{
11001101 tag_AvrModbusMasterSlaveInfo * Slave ;
11011102
@@ -1129,9 +1130,9 @@ char AvrModbusMasterCheckSlaveNoResponse(tag_AvrModbusMasterCtrl *Master, unsign
11291130 }
11301131}
11311132/*********************************************************************************/
1132- tag_AvrModbusMasterSlaveInfo * AvrModbusMasterFindSlaveById (tag_AvrModbusMasterCtrl * Master , unsigned char Id )
1133+ tag_AvrModbusMasterSlaveInfo * AvrModbusMasterFindSlaveById (tag_AvrModbusMasterCtrl * Master , tU8 Id )
11331134{
1134- unsigned char i , Find = false;
1135+ tU8 i , Find = false;
11351136 tag_AvrModbusMasterSlaveInfo * Slave = Master -> SlavePoll ;
11361137
11371138 /*
0 commit comments