Преглед на файлове

modbus 库去掉assert 导致系统复位。新增单相总检测板

liyi преди 1 година
родител
ревизия
7eef3608b9

+ 5 - 0
truing_control/PDU-AC_ADA_NEW_6/common/common.c

@@ -60,13 +60,18 @@ void read_config_from_eeprom(void)
 			{
 				for(int i =0 ;i < RelaySlaveChaNum;i++)
 				{
+#ifndef SUPPORT_MON
 					if(board->relay_staging_staus[i])
 					{
 						SET_RL_ON_DELAY_FLAG(board->relay_staging_staus[i]);
 						CLEAR_RL_OFF_DELAY_FLAG(board->relay_staging_staus[i]);
 						SET_RL_ORDER_FLAG(board->relay_staging_staus[i]);
 					}
+#else
+					board->md_data.r_data.state.state[i].state = 1;
+#endif
 				}
+
 			}
 			board->read_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.open.delay_open[0],sizeof(ac_rw_data_t));
 

+ 3 - 0
truing_control/PDU-AC_ADA_NEW_6/common/common.h

@@ -511,6 +511,9 @@ typedef struct {
 
 
 
+
+
+
 typedef struct{
 	elect_info_t info[3];
 }elect_3_info_t;

+ 6 - 1
truing_control/PDU-AC_ADA_NEW_6/modbus/BARE/port/port.c

@@ -239,6 +239,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							w_eeprom_data_t data = {0};
 							if((usAddress >= SET_STATE) && (usAddress <=(SET_STATE +SET_STATE_LEN)))
 							{
+#ifndef SUPPORT_MON
 								start = usAddress - SET_STATE;
 								async_data da = {0};
 								da.fire_or_zero = _FIRE;
@@ -344,9 +345,10 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 										}										
 									}
 #endif								
-								
+#endif	
 							}else if((usAddress >= OPEN_DELAY) && (usAddress <=(OPEN_DELAY+OPEN_DELAY_LEN)))
 							{
+#ifndef SUPPORT_MON
 								start = usAddress - OPEN_DELAY;
 								base = (uint16_t*)(&board->md_data.rw_data.open.delay_open[0]);
 								base += start;
@@ -356,8 +358,10 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 								memcpy(&data.data,&usRegHoldBuf[WiRegIndex],2*WusNRegs);		
 								data.start_addr = (EEPROM_OTHER_ADDR+(start*2));
 								board->q_cache.en_queue(&data);
+#endif
 							}else if((usAddress >= CLOSE_DELAY) && (usAddress <=(CLOSE_DELAY+CLOSE_DELAY_LEN)))
 							{
+#ifndef SUPPORT_MON
 								start = usAddress - CLOSE_DELAY;
 								base = (uint16_t*)(&board->md_data.rw_data.close.delay_close[0]);
 								base += start;
@@ -366,6 +370,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 								memcpy(&data.data,&usRegHoldBuf[WiRegIndex],2*WusNRegs);
 								data.start_addr = (EEPROM_OTHER_ADDR+(sizeof(ac_delay_open_t))+(start*2));
 								board->q_cache.en_queue(&data);
+#endif
 							}else if((usAddress >= VALUE_THR) && (usAddress <=(VALUE_THR+VALUE_THR_LEN)))				//yu zhi she zhi
 							{
 								start = usAddress - VALUE_THR;

+ 8 - 0
truing_control/PDU-AC_ADA_NEW_6/modbus/BARE/port/portserial.c

@@ -40,6 +40,14 @@ vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
     /* If xRXEnable enable serial receive interrupts. If xTxENable enable
      * transmitter empty interrupts.
      */
+		if(FALSE == xRxEnable && xTxEnable == FALSE)
+		{
+			usart_interrupt_disable(USART0,USART_INT_RBNE);
+			usart_interrupt_disable(USART0,USART_INT_TC);
+			gpio_bit_reset(GPIOA, GPIO_PIN_8);
+			return;
+		}
+	
 	  if(TRUE == xRxEnable)
     {
         usart_interrupt_enable(USART0,USART_INT_RBNE);//ʹÄܽÓÊÕÖжÏ

+ 4 - 0
truing_control/PDU-AC_ADA_NEW_6/modbus/include/mb.h

@@ -409,6 +409,10 @@ eMBErrorCode    eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
  */
 eMBErrorCode    eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
                                   USHORT usNDiscrete );
+																	
+																	
+																	
+uint8_t eMBCheck(void);
 
 #ifdef __cplusplus
 PR_END_EXTERN_C

+ 14 - 0
truing_control/PDU-AC_ADA_NEW_6/modbus/mb.c

@@ -327,6 +327,20 @@ eMBDisable( void )
     return eStatus;
 }
 
+
+uint8_t eMBCheck(void)
+{
+	if( eMBState != STATE_ENABLED)
+	{
+		return 1;
+	}else
+	{
+		return 0;
+	}
+}
+
+
+
 eMBErrorCode
 eMBPoll( void )
 {

+ 33 - 7
truing_control/PDU-AC_ADA_NEW_6/modbus/rtu/mbrtu.c

@@ -153,8 +153,14 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
     eMBErrorCode    eStatus = MB_ENOERR;
 
     ENTER_CRITICAL_SECTION(  );
-    assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
-
+		
+    //assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
+		if(usRcvBufferPos >= MB_SER_PDU_SIZE_MAX)
+		{
+			eMBDisable();
+			EXIT_CRITICAL_SECTION(  );
+			return eStatus;
+		}
     /* Length and CRC check */
     if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
         && ( usMBCRC16( ( UCHAR * ) ucRTUBuf, usRcvBufferPos ) == 0 ) )
@@ -237,7 +243,12 @@ xMBRTUReceiveFSM( void )
     BOOL            xTaskNeedSwitch = FALSE;
     UCHAR           ucByte;
 
-    assert( eSndState == STATE_TX_IDLE );
+    //assert( eSndState == STATE_TX_IDLE );
+		if(eSndState != STATE_TX_IDLE)
+		{
+			eMBDisable();
+			return xTaskNeedSwitch;
+		}
 
     /* Always read the character. */
     ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
@@ -296,8 +307,18 @@ xMBRTUTransmitFSM( void )
 {
     BOOL            xNeedPoll = FALSE;
 
-    assert( eRcvState == STATE_RX_IDLE );
-
+    //assert( eRcvState == STATE_RX_IDLE );
+		if(eRcvState != STATE_RX_IDLE)
+		{
+			eMBDisable();
+			return xNeedPoll;
+		}
+//		if(eRcvState != STATE_RX_IDLE)
+//		{
+//			eMBDisable();
+//			eMBRTUStart();
+//			return xNeedPoll;
+//		}
     switch ( eSndState )
     {
         /* We should not get a transmitter event if the transmitter is in
@@ -355,8 +376,13 @@ xMBRTUTimerT35Expired( void )
 
         /* Function called in an illegal state. */
     default:
-        assert( ( eRcvState == STATE_RX_INIT ) ||
-                ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
+			{
+				eMBDisable();
+				eRcvState = STATE_RX_IDLE;
+				return xNeedPoll;
+				//  assert( ( eRcvState == STATE_RX_INIT ) ||
+				//          ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
+			}
     }
 
     vMBPortTimersDisable(  );

+ 10 - 1
truing_control/PDU-AC_ADA_NEW_6/user/board_cfg.h

@@ -65,7 +65,9 @@
 #define 	PRJ_4_SELF_LOCK       	  0
 #define   PRJ_4_BASE                0
 #define   PRJ_1_BASE                0
-#define 	PRJ_1_SELF_LOCK       	  1
+#define 	PRJ_1_SELF_LOCK       	  0
+
+#define   PRJ_1_ALL_MON             1
 
 #if PRJ_8					
 	#define   POWER_TYPE                (POWER_AC)
@@ -141,6 +143,13 @@
 	#define   SUPPORT_DETECTION         1
 	#define   SUPPORT_RELAY_REMENBER		1
 	#define   SUPPORT_SELF_LOCK         1
+	
+#elif PRJ_1_ALL_MON         
+	#define 	RelaySlaveChaNum 					1
+	#define 	ACSingCurrid 							2 
+	#define   SURPPORT_2_PT             0
+	#define   PT_SUB_COUNT              (RelaySlaveChaNum)
+	#define   SUPPORT_MON               1
 #endif
 
 

+ 12 - 1
truing_control/PDU-AC_ADA_NEW_6/user/main.c

@@ -74,7 +74,7 @@ int main(){
 	strcpy((char*)&(ac_board.md_data.r_data.info.ver),VERSION);
 	
 	flash_get_infomation(&ac_board.md_data.r_data.info);
-	
+#if SUPPORT_RELAY_REMENBER
 	ac_board.handle_input_pt[0] = 1;
 	#if SURPPORT_2_PT
 		ac_board.handle_input_pt[1] = 1;
@@ -126,9 +126,14 @@ int main(){
 		}
 #endif
 	
+#endif
 	
 	while(1)
 	{
+		if(eMBCheck())
+		{
+			eMBEnable();
+		}
 		ac_board.feed_dog();
 		task_query();
 		task_100ms();
@@ -138,8 +143,10 @@ int main(){
 #if SUPPORT_SELF_LOCK
 		ac_board.opt_lock_key();
 #endif
+#ifndef SUPPORT_MON
 		ac_board.opt_detection();
 		relay_ctrl();
+#endif
 	}
 	return 0;
 }
@@ -160,7 +167,9 @@ static void task_1s(void)
 			ac_board.flag_1s = 0;
 			ac_board.md_data.r_data.info.runing_time++;
 			ac_board.led_flash();
+#ifndef SUPPORT_MON
 			ac_board.detection();
+#endif
 #if SUPPORT_SELF_LOCK
 			ac_board.get_lock_key();
 #endif
@@ -176,7 +185,9 @@ static void task_100ms(void)
 			ac_board.flag_100ms = 0;
 			ac_board.read_ele(channel);
 			ac_board.check_wanning(ELE_OUTPUT,channel);
+#ifndef SUPPORT_MON
 			ac_board.opt_overfunc(channel);		
+#endif
 			channel++;
 			if(channel == RelaySlaveChaNum)
 			{