📄 dp_user.c
字号:
/************************** Filename: dp_user.c ****************************/
/* ========================================================================= */
/* */
/* 0000 000 000 00000 0 000 0 0 0 0000 */
/* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
/* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Einsteinstra遝 6 */
/* 0000 000 0 0 000 0 0 00000 0 0000 91074 Herzogenaurach */
/* 0 00 0 0 0 0 0 0 0 0 0 */
/* 0 0 0 0 0 0 0 0 0 0 0 0 0 Tel: ++49-9132-744-200 */
/* 0 0 0 000 0 0 000 0 0 0 0 GmbH Fax: ++49-9132-744-204 */
/* */
/* ========================================================================= */
/* */
/* Function: Demo for PROFICHIP Extension Board AT89C5132 */
/* This example simulates a modular profibus device */
/* with 20 modules (0..244 Byte Input, 0..244 Byte Output). */
/* */
/* ------------------------------------------------------------------------- */
/* */
/* Hardware requirements: ProfiChip Evaluation Board AT89C5132 (PA006101) */
/* ProfiChip Evaluation Board VPC3+/C (PA006103) */
/* */
/* ------------------------------------------------------------------------- */
/* memory: 0000H ... 7FFFH: RAM */
/* 8000H ... 8FFFH: VPC3+ */
/* 9000H ... 9FFFH: Reserved */
/* A000H ... AFFFH: FPGA */
/* B000H ... BFFFH: RTC */
/* C000H ... CFFFH: LCD */
/* D000H ... DFFFH: I/O Port 0 */
/* E000H ... EFFFH: I/O Port 1 */
/* F000H ... FFFFH: I/O Port 2 */
/* */
/* ------------------------------------------------------------------------- */
/* */
/* Technical support: P. Fredehorst */
/* Tel. : ++49-9132/744-214 */
/* Fax. : -204 */
/* eMail: pfredehorst@profichip.com */
/* */
/*****************************************************************************/
/*****************************************************************************/
/* contents:
- function prototypes
- data structures
- internal functions
*/
/*****************************************************************************/
/* include hierarchy */
#include "..\..\dp_inc\platform.h"
#include "..\..\dp_inc\dp_inc.h"
/*---------------------------------------------------------------------------*/
/* defines, structures */
/*---------------------------------------------------------------------------*/
// -- defines for user state
#define USER_STATE_CLEAR ((UBYTE)0x00)
#define USER_STATE_RUN ((UBYTE)0x01)
// -- defines for diagnostics
#define USER_TYPE_DPV0 ((UBYTE)0xFA)
#define USER_TYPE_PRM_OK ((UBYTE)0xFB)
#define USER_TYPE_PRM_NOK ((UBYTE)0xFC)
#define USER_TYPE_CFG_OK ((UBYTE)0xFD)
#define USER_TYPE_CFG_NOK ((UBYTE)0xFE)
#define USER_TYPE_APPL_RDY ((UBYTE)0xFF)
typedef struct
{
UBYTE state;
UBYTE user_diag_active;
UWORD old_diag;
UBYTE user_diag[DIAG_BUFSIZE];
UWORD event;
UBYTE application_ready;
CFG_STRUCT real_cfg;
UBYTE input[244];
UBYTE output[244];
}USER_STRUC;
/*---------------------------------------------------------------------------*/
/* global user data definitions */
/*---------------------------------------------------------------------------*/
VPC3_STRUC_ERRCB vpc3_errcb; // error structure
USER_STRUC user; // user system structure
/*---------------------------------------------------------------------------*/
/* defines, structures and variables for our demo application */
/*---------------------------------------------------------------------------*/
ROMCONST__ UBYTE NAME[8] = { 0x45, 0x41, 0x53, 0x59, 0x41, 0x44, 0x41, 0x43 }; //EASYADAC
//default configuration data for startup
#define AllCfgDataLength ((UBYTE)0x0F)
ROMCONST__ UBYTE AllCfgBytes[AllCfgDataLength] = { 0x10, 0x11, 0x13, 0x17, 0x1F, 0x20, 0x21, 0x23, 0x27, 0x2F, 0x30, 0x31, 0x33, 0x37, 0x3F };
//default configuration data for startup
#define UserCfgDataLength ((UBYTE)0x02)
ROMCONST__ UBYTE DefCfg[UserCfgDataLength] = { 0x10, 0x20 };
/*---------------------------------------------------------------------------*/
/* function prototypes */
/*---------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* function: read_input_data */
/*--------------------------------------------------------------------------*/
void read_input_data( void )
{
VPC3_UNSIGNED8_PTR input_buf_ptr; // pointer to input buffer
// write DIN data to VPC3
if(input_buf_ptr = vpc3_get_dinbufptr ()) // get pointer to DIN data
{
//todo:
//handle here data (slave --> master)
memcpy( input_buf_ptr, &user.input[0], dp_sys.inp_data_len );
// the user makes a new Din-Buffer available in the state N
dp_sys.vpc3_con = VPC3_INPUT_UPDATE();
}//if(input_buf_ptr = vpc3_get_dinbufptr ())
}//void read_input_data( void )
/*---------------------------------------------------------------------------*/
/* function: user_alarm ( is also called from alarm state machine !!!! ) */
/*---------------------------------------------------------------------------*/
UBYTE user_alarm( UBYTE alarm_type, UBYTE check_diag_flag )
{
VPC3_UNION_DIAG_PTR tmp_diag;
UBYTE ret_value;
UBYTE ext_diag;
UBYTE len_diag;
UBYTE error;
UWORD diag;
ret_value = 0x00;
diag = (UWORD)alarm_type;
//don't send diagnostic twice!
if( ( diag != user.old_diag )
&& ( FALSE == user.user_diag_active )
)
{
memset( &user.user_diag[0], 0x00, sizeof( user.user_diag ) );
tmp_diag.byte_ptr = user.user_diag;
ext_diag = 0x00;
len_diag = 0x00;
switch( alarm_type )
{
case USER_TYPE_CFG_OK:
{
ext_diag = STAT_DIAG_SET;
break;
}//case USER_TYPE_CFG_OK:
case USER_TYPE_APPL_RDY:
case USER_TYPE_PRM_NOK:
case USER_TYPE_PRM_OK:
default:
{
ext_diag = 0x00;
len_diag = 0x00;
break;
}//default:
}//switch(user[vpc3_channel].diag_byte)
user.user_diag_active = TRUE;
error = set_diagnosis( tmp_diag, len_diag, ext_diag, check_diag_flag );
if( error == DP_OK )
{
user.old_diag = diag;
if( alarm_type >= USER_TYPE_PRM_OK )
{
user.user_diag_active = FALSE;
}//if( alarm_type >= USER_TYPE_PRM_OK )
ret_value = DP_OK;
}//if( error == DP_OK )
else
{
user.user_diag_active = FALSE;
#ifdef RS232_SERIO
print_string("DIAG_DP_Error: ");
print_hexbyte(error);
print_hexbyte(alarm_type);
#endif//#ifdef RS232_SERIO
ret_value = error;
}//else of if( error == DP_OK )
}//if( ( diag != user.old_diag ) ...
return ret_value;
}//UBYTE user_alarm( UBYTE alarm_type, UBYTE check_diag_flag )
/*--------------------------------------------------------------------------*/
/* function: application_ready */
/*--------------------------------------------------------------------------*/
void application_ready( void )
{
//todo
//make here your own initialization
user.input[0] = *READ_PORT1;
user.input[1] = *READ_PORT2;
//read input data
read_input_data();
//reset Diag.Stat
user_alarm( USER_TYPE_APPL_RDY, FALSE );
user.application_ready = TRUE;
}//void application_ready( void )
/*---------------------------------------------------------------------------*/
/* function: user_main */
/*---------------------------------------------------------------------------*/
void user_main( void )
{
VPC3_UNSIGNED8_PTR output_buf_ptr; // pointer to output buffer
DP_ERROR_CODE error;
UBYTE outp_state; // state of output data
/*-----------------------------------------------------------------------*/
/* init user data */
/*-----------------------------------------------------------------------*/
memset( &user, 0, sizeof(user) );
/* TRUE deactivates diagnosis handling ! */
/* FALSE activates diagnosis handling ! */
user.user_diag_active = FALSE;
user.application_ready = FALSE;
user.state = USER_STATE_CLEAR;
/*-----------------------------------------------------------------------*/
/* initialize VPC3 */
/*-----------------------------------------------------------------------*/
//todo:
//insert your real configuration data here
user.real_cfg.length = UserCfgDataLength; // length of configuration data
memcpy( &user.real_cfg.cfg_data[0], &DefCfg[0], user.real_cfg.length );
#ifdef EvaBoard_AT89C5132
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -