⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dp_user.c

📁 PROFIBUS SLAVE PROGRAMS PRO FIBUS SLAVE PROGRAMS
💻 C
📖 第 1 页 / 共 2 页
字号:

            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( user.input[0] != *READ_PORT1 )
                        {
                            user.input[0] = *READ_PORT1;
                            user.event |= VPC3_EV_NEW_INPUT_DATA;
                        }

                        if( user.input[1] != *READ_PORT2 )
                        {
                            user.input[1] = *READ_PORT2;
                            user.event |= VPC3_EV_NEW_INPUT_DATA;
                        }
                    #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( &user.output[0], output_buf_ptr, dp_sys.outp_data_len);

                /*-----------------------------------------------------------*/
                /* user application                                          */
                /*-----------------------------------------------------------*/
                #ifdef EvaBoard_AT89C5132
                    *WRITE_PORT1 = user.output[0];
                    *WRITE_PORT2 = user.output[1];
                #endif//#ifdef EvaBoard_AT89C5132
            }//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 )
{
VPC3_STRUC_PRM_PTR          prm_data;
UBYTE                       ret_value;

    ret_value = DP_OK;

    if( len == PRM_LEN_DPV1 )
    {
        prm_data = (VPC3_STRUC_PRM_PTR)prm_ptr;

        //check DPV1 Status
        if(    ( prm_data->dpv1_status_1 != 0x00 )
            || ( prm_data->dpv1_status_2 != 0x00 )
            || ( prm_data->dpv1_status_3 != 0x00 )
          )
        {
            ret_value = DP_PRM_DPV1_STATUS;
        }//if(    (( prm_data->dpv1_status_2 & 0x02 ) != 0x00 ) ...
    }//if( len >= PRM_LEN_DPV1 )
    else
    {
        ret_value = DP_PRM_LEN_ERROR;
    }//else of if( len >= PRM_LEN_DPV1 )

    if( ( VPC3_GET_DP_STATE() == DATA_EX ) && ( ret_value == DP_OK ) )
    {
        //don't send diagnostic here
    }//if( ( VPC3_GET_DP_STATE() == DATA_EX ) && ( ret_value == DP_OK ) )
    else
    {
        user_alarm( USER_TYPE_PRM_OK, FALSE );
    }//else of if( ( VPC3_GET_DP_STATE() == DATA_EX ) && ( ret_value == DP_OK ) )

    return ret_value;
}//UBYTE user_chk_new_prm_data(VPC3_UNSIGNED8_PTR prm_ptr, UBYTE len)
#endif//#if( ISR_ENABLE_VPC3_INT_NEW_PRM_DATA == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_new_cfg_data                                           */
/*                                                                           */
/* todo  : check cfg data                                                    */
/*                                                                           */
/* return:  VPC3_CFG_OK      0                                               */
/*          VPC3_CFG_FAULT   1                                               */
/*          VPC3_CFG_UPDATE  2                                               */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_NEW_CFG_DATA == 1 )
UBYTE user_chk_new_cfg_data(void)
{
VPC3_UNSIGNED8_PTR  readcfg_ptr;    // pointer read config buffer
VPC3_UNSIGNED8_PTR  cfg_ptr;        // pointer check config buffer
UBYTE               cfg_len;
UBYTE               ret_value;

    ret_value = VPC3_CFG_OK;
    cfg_len = VPC3_GET_CFG_LEN();

    if( cfg_len == VPC3_GET_READ_CFG_LEN() )
    {
        readcfg_ptr = VPC3_GET_READ_CFG_BUF_PTR();
        cfg_ptr     = VPC3_GET_CFG_BUF_PTR();

        if( memcmp( readcfg_ptr, cfg_ptr, cfg_len ) != 0 )
        {
            ret_value = VPC3_CFG_FAULT;
        }
    }//if( cfg_len == VPC3_GET_READ_CFG_LEN() )
    else
    {
        ret_value = VPC3_CFG_FAULT;
    }//if( cfg_len != real_cfg_len )

    if( ret_value == VPC3_CFG_OK )
    {
        user_alarm( USER_TYPE_CFG_OK, FALSE );
        user.event |= VPC3_EV_NEW_CFG_DATA;
    }//if( ret_value == VPC3_CFG_UPDATE )
    return ret_value;
}//UBYTE user_chk_new_cfg_data(void)
#endif//#if( ISR_ENABLE_VPC3_INT_NEW_CFG_DATA == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_go_leave_data_ex                                       */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_GO_LEAVE_DATA_EX == 1 )
void user_isr_go_leave_data_ex( void )
{
    if( VPC3_GET_DP_STATE() != DATA_EX )
    {
        user.state = USER_STATE_CLEAR;
        user.application_ready = FALSE;
    }//if( VPC3_GET_DP_STATE() != DATA_EX )
}//void user_isr_go_leave_data_ex( void )
#endif//#if( ISR_ENABLE_VPC3_INT_GO_LEAVE_DATA_EX == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_dx_out                                                 */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_DX_OUT == 1 )
void user_isr_dx_out( void )
{
    user.event |= VPC3_EV_DX_OUT;
}//void user_isr_dx_out( void )
#endif//#if( ISR_ENABLE_VPC3_INT_DX_OUT == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_diag_buf_changed                                       */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_DIAG_BUF_CHANGED == 1 )
void user_isr_diag_buf_changed( void )
{
    // diagnosis buffer has been changed
    user.user_diag_active = FALSE;
    // Fetch new diagnosis buffer
    dp_sys.diag_buf_ptr.byte_ptr = vpc3_get_diagbufptr();
}//void user_isr_diag_buf_changed( void )
#endif//#if( ISR_ENABLE_VPC3_INT_DIAG_BUF_CHANGED == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_new_wd_timeout                                         */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_WD_DP_TIMEOUT == 1 )
void user_isr_new_wd_dp_timeout( void )
{
    reset_diagnostic_buffer();
}//void user_isr_new_wd_dp_timeout( void )
#endif//#if( ISR_ENABLE_VPC3_INT_WD_DP_TIMEOUT == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_new_ext_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_EXT_PRM_DATA == 1 )
UBYTE user_chk_new_ext_prm_data( VPC3_STRUC_PRM_BLOCK_PTR prmblock_ptr, UBYTE len )
{
    //not used
    return DP_OK;
}//UBYTE user_chk_new_ext_prm_data( VPC3_STRUC_PRM_BLOCK_PTR prmblock_ptr, UBYTE len )
#endif//#if( ISR_ENABLE_VPC3_INT_NEW_EXT_PRM_DATA == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_mac_reset                                              */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_MAC_RESET == 1 )
void user_isr_mac_reset( void )
{
    //not used in our application
}//void user_isr_mac_reset( void )
#endif//#if( ISR_ENABLE_VPC3_INT_MAC_RESET == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_baudrate_detect                                        */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_BAUDRATE_DETECT == 1 )
void user_isr_baudrate_detect( void )
{
    //not used in our application
}//void user_isr_baudrate_detect( void )
#endif//#if( ISR_ENABLE_VPC3_INT_BAUDRATE_DETECT == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_new_gc_command                                         */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_NEW_GC_COMMAND == 1 )
void user_isr_new_gc_command( void )
{
    //not used in our application
}//void user_isr_new_gc_command( void )
#endif//#if( ISR_ENABLE_VPC3_INT_NEW_GC_COMMAND == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_new_ssa_data                                           */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_NEW_SSA_DATA == 1 )
void user_isr_new_ssa_data( void )
{
    //not used in our application
}//void user_isr_new_ssa_data( void )
#endif//#if( ISR_ENABLE_VPC3_INT_NEW_SSA_DATA == 1 )

/*---------------------------------------------------------------------------*/
/* function: user_isr_user_timer_clock (10ms)                                */
/*---------------------------------------------------------------------------*/
#if( ISR_ENABLE_VPC3_INT_USER_TIMER_CLOCK == 1 )
void user_isr_user_timer_clock( void )
{
    //not used
}//void user_isr_user_timer_clock( void )
#endif//#if( ISR_ENABLE_VPC3_INT_USER_TIMER_CLOCK == 1 )


/*****************************************************************************/
/*  Copyright (C) profichip GmbH 2005. Confidential.                         */
/*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -