📄 dp_user.c
字号:
//wait, for offline
}while( VPC3_GET_OFF_PASS() );
START_VPC3();
}
if( user.event & VPC3_EV_DX_OUT )
{
user.event &= ~VPC3_EV_DX_OUT; // clear event
}
break;
}//case WAIT_PRM:
case WAIT_CFG:
case DP_ERROR:
{
// set LED's
CLR_LED_YLW__;
SET_LED_RED__;
if( user.event & VPC3_EV_DX_OUT )
{
user.event &= ~VPC3_EV_DX_OUT; // clear event
}
break;
}
case DATA_EX:
{
// set LED's
SET_LED_YLW__;
CLR_LED_RED__;
if( ( user.application_ready == TRUE )
&& ( user.state == USER_STATE_RUN )
)
{
/*-------------------------------------------------------------------*/
/* user application */
/*-------------------------------------------------------------------*/
#ifdef EvaBoard_AT89C5132
if( sSystem.input.di8[0] != *READ_PORT1 )
{
sSystem.input.di8[0] = *READ_PORT1;
user.event |= VPC3_EV_NEW_INPUT_DATA;
}
if( sSystem.input.di8[1] != *READ_PORT2 )
{
sSystem.input.di8[1] = *READ_PORT2;
user.event |= VPC3_EV_NEW_INPUT_DATA;
}
//demo for diagnostic
bDipSwitch5 = *READ_PORT2;
if( bDipSwitch5 != bOldDipSwitch5 )
{
bOldDipSwitch5 = bDipSwitch5;
#ifdef RS232_SERIO
print_string("DipSwitchS5: ");
print_hexbyte(bDipSwitch5);
#endif//#ifdef RS232_SERIO
//set alarm
if( ( bDipSwitch5 & 0x10 ) && ( bDiagStateModule5 == FALSE ) )
{
bDiagStateModule5 = TRUE;
user_demo_diagnostic( 1, 5 );
}//if( ( bDipSwitch5 & 0x10 ) && ( bDiagStateModule5 == FALSE ) )
//clear alarm
if( !( bDipSwitch5 & 0x10 ) && ( bDiagStateModule5 == TRUE ) )
{
bDiagStateModule5 = FALSE;
user_demo_diagnostic( 2, 5 );
}//if( !( bDipSwitch5 & 0x10 ) && ( bDiagStateModule5 == TRUE ) )
//set alarm
if( ( bDipSwitch5 & 0x20 ) && ( bDiagStateModule6 == FALSE ) )
{
bDiagStateModule6 = TRUE;
user_demo_diagnostic( 3, 6 );
}//if( ( bDipSwitch5 & 0x20 ) && ( bDiagStateModule6 == FALSE ) )
//clear alarm
if( !( bDipSwitch5 & 0x20 ) && ( bDiagStateModule6 == TRUE ) )
{
bDiagStateModule6 = FALSE;
user_demo_diagnostic( 4, 6 );
}//if( !( bDipSwitch5 & 0x20 ) && ( bDiagStateModule6 == TRUE ) )
}//if( bDipSwitch5 != bOldDipSwitch5 )
#endif//#ifdef EvaBoard_AT89C5132
/*-------------------------------------------------------------------*/
/* profibus input */
/*-------------------------------------------------------------------*/
if( user.event & VPC3_EV_NEW_INPUT_DATA )
{
read_input_data();
user.event &= ~VPC3_EV_NEW_INPUT_DATA;
}
}//if( ( user.application_ready == TRUE ) ...
break;
}//case DATA_EX:
default:
{
vpc3_errcb.error_code = VPC3_GET_DP_STATE();
fatal_error( _DP_USER, __LINE__, &vpc3_errcb );
break;
}
}//switch(VPC3_GET_DP_STATE())
/*-------------------------------------------------------------------*/
/* profibus output */
/*-------------------------------------------------------------------*/
if( user.event & VPC3_EV_DX_OUT )
{
user.event &= ~VPC3_EV_DX_OUT; // clear event
if( output_buf_ptr = vpc3_get_doutbufptr (&outp_state) )
{
//todo:
//handle here data (master --> slave)
memcpy( &sSystem.output.do8[0], output_buf_ptr, dp_sys.outp_data_len);
/*-----------------------------------------------------------*/
/* user application */
/*-----------------------------------------------------------*/
#ifdef EvaBoard_AT89C5132
*WRITE_PORT1 = sSystem.output.do8[0];
*WRITE_PORT2 = sSystem.output.do8[1];
#endif//#ifdef EvaBoard_AT89C5132
if( ( sSystem.input.dio32[0] != sSystem.output.dio32[0] )
|| ( sSystem.input.dio32[1] != sSystem.output.dio32[1] )
|| ( sSystem.input.dio32[2] != sSystem.output.dio32[2] )
|| ( sSystem.input.dio32[3] != sSystem.output.dio32[3] )
)
{
sSystem.input.dio32[0] = sSystem.output.dio32[0];
sSystem.input.dio32[1] = sSystem.output.dio32[1];
sSystem.input.dio32[2] = sSystem.output.dio32[2];
sSystem.input.dio32[3] = sSystem.output.dio32[3];
user.event |= VPC3_EV_NEW_INPUT_DATA;
}
//counter module
//clear counter
if( sSystem.output.counter[0] & 0x02 )
{
sSystem.input.counter[0] = 0x00;
sSystem.input.counter[1] = 0x00;
counter_value = 0x0000;
user.event |= VPC3_EV_NEW_INPUT_DATA;
}
}//if( user.output_buf_ptr = vpc3_get_doutbufptr (&outp_state) )
}//if( user.event & VPC3_EV_DX_OUT )
/*-------------------------------------------------------------------*/
/* handle here profibus interrupt events */
/*-------------------------------------------------------------------*/
if( user.event & VPC3_EV_NEW_CFG_DATA )
{
application_ready();
user.event &= ~VPC3_EV_NEW_CFG_DATA; // clear event
}
}//while(1)
}//void user_main( void )
/*---------------------------------------------------------------------------*/
/* function: delay */
/*---------------------------------------------------------------------------*/
void delay( void )
{
UBYTE i,j;
for(i = 0; i < 255; i++)
{
for(j = 0; j < 255; j++);
}
}//void delay( void )
/*---------------------------------------------------------------------------*/
/* function: fatal_error */
/*---------------------------------------------------------------------------*/
void fatal_error( DP_ERROR_FILE file, UWORD line, VPC3_ERRCB_PTR errcb_ptr )
{
#ifdef RS232_SERIO
do
{
// wait!
}
while( snd_counter > 80);
print_string("\r\nFATAL_ERROR:");
print_string("\r\nFile: ");
print_hexbyte(file);
print_string("\r\nLine: ");
print_hexword(line);
print_string("\r\nFunction: ");
print_hexbyte(errcb_ptr->function);
print_string("\r\nError_Code: ");
print_hexbyte(errcb_ptr->error_code);
print_string("\r\nDetail: ");
print_hexbyte(errcb_ptr->detail);
print_string("\r\ncn_id: ");
print_hexbyte(errcb_ptr->cn_id);
#endif//#ifdef RS232_SERIO
#ifdef EvaBoard_AT89C5132
*WRITE_PORT0 = errcb_ptr->error_code;
*WRITE_PORT1 = file;
*WRITE_PORT2 = (UBYTE)line;
#endif//#ifdef EvaBoard_AT89C5132
SET_LED_YLW__;
SET_LED_RED__;
while(1)
{
#ifdef RS232_SERIO
if(rec_counter > 0)
{
print_serial_inputs();
}
#endif//#ifdef RS232_SERIO
TOGGLE_LED_RED__;
TOGGLE_LED_YLW__;
delay();
}//while(1)
}//void fatal_error( DP_ERROR_FILE file, UWORD line, VPC3_ERRCB_PTR errcb_ptr )
/*---------------------------------------------------------------------------*/
/* function: user_isr_new_prm_data */
/* */
/* todo : check the prm-data */
/* return: DP_OK - prm-data OK */
/* DP_NOK - prm-data not OK */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_NEW_PRM_DATA == 1 )
UBYTE user_chk_new_prm_data( VPC3_UNSIGNED8_PTR prm_ptr, UBYTE len )
{
typedef struct
{
UBYTE len;
UBYTE slot_nr;
UBYTE user_data;
}STRUC_MODULE_PRM_BLOCK;
#define VPC3_STRUC_MODULE_PRM_BLOCK_PTR STRUC_MODULE_PRM_BLOCK PTR_ATTR *
VPC3_STRUC_MODULE_PRM_BLOCK_PTR module_block;
VPC3_STRUC_PRM_PTR prm_data;
UBYTE ret_value;
ret_value = DP_OK;
if( len == 0x13 )
{
prm_data = (VPC3_STRUC_PRM_PTR)prm_ptr;
//DP-Mode
if( (( prm_data->dpv1_status_1 & 0x98 ) != 0x00 )
|| (( prm_data->dpv1_status_2 & 0xFF ) != 0x00 )
|| (( prm_data->dpv1_status_3 & 0xFF ) != 0x00 )
)
{
ret_value = DP_PRM_DPV1_STATUS;
}//if( (( prm_data->dpv1_status_1 & 0x18 ) != 0x00 )
if( ret_value == DP_OK )
{
//user parameter data
module_block = (VPC3_STRUC_MODULE_PRM_BLOCK_PTR)&prm_data->user_data;
if( ( module_block->len + PRM_LEN_DPV1 ) == 0x13 )
{
//copy counter parameter data
memcpy( &sSystem.prm, &module_block->user_data, module_block->len-2 );
//check parameter of counter module
if( ( sSystem.prm.alarm & 0xFC ) //check alarm
|| ( sSystem.prm.mode > 0x01 ) //check counter mode
|| ( sSystem.prm.time_base > 0x05 ) //check counter timebase
)
{
//error
ret_value = DP_PRM_ENTRY_ERROR;
}//if( ( sSystem.prm.alarm & 0xFC ) ...
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -