?? userspc3.c
字號:
//WDT_INIT();
/* Enable the SPC3 interrupt in the interupt controller of the microprocessor */
// SPC3_INTERRUPT_ENABLE = I_ENABLE;
// GLOBAL_INTERRUPT_ENABLE = I_ENABLE;
for (;;)
{
Send_watchdog();
CKD_R_Data_Process();
if (OWN_ADDRESS!=T_OWN_ADDRESS)
{
OWN_ADDRESS = T_OWN_ADDRESS;
Spc3_Terminal_Ini();
}
//=== Begin of the endless loop ===/
zyk_wd_state = SPC3_GET_WD_STATE(); //for info.: the actuall WD State/
zyk_dps_state = DPS2_GET_DP_STATE(); //for info.: the actuall PROFIBUS DP State/
//WDT_RE(); ****************************************************************************
DPS2_RESET_USER_WD(); //Trigger the user watchdog of the SPC3 //
/*============ Handling of the output data =================*/
if (DPS2_POLL_IND_DX_OUT()) // are new output date available?
{
//Confirm the receiving
DPS2_CON_IND_DX_OUT();
// Get the pointer to the actual output data
user_output_buffer_ptr = DPS2_OUTPUT_UPDATE();
// Example: Copy the output data to the IO
for (i=0; i<user_io_data_len_ptr->outp_data_len; i++)
{
// (*((io_byte_ptr) + i)) = (*(((UBYTE *) user_output_buffer_ptr) + i));
Profi_R_Data[i] = (*(((UBYTE *) user_output_buffer_ptr) + i));
}
//PROFI_R_Data_Process();數據輸入函數
}
/*
i =spc3.is_reg.status[0];
if (( i & 0x40))
{
CKD_S_Data[0] |= 0x01;
}
else
{
CKD_S_Data[0] &= 0xfe;
}
*/
// CKD_S_Data[0] |= 0x01;
//============ Handling of the input data =================
// Write the input data from the periphery to the ASIC //
// test profi send data
for (i=0; i<user_io_data_len_ptr->inp_data_len; i++)
{
*((io_byte_ptr) + i) = Profi_S_Data[i];//數據上傳
*(((UBYTE *) user_input_buffer_ptr) + i) = *((io_byte_ptr) + i);
// *(((UBYTE *) user_input_buffer_ptr) + i) = Profi_S_Data[i];
}
// Give the actuall pointer / data to the SPC3/DPS2 an get a new pointer,
// where the next input data can be written //
user_input_buffer_ptr = DPS2_INPUT_UPDATE();
//== Handling of the external diagnosis and other user defined actions =====//
dps_chg_diag_srvc_byte_new = *((UBYTE*)(io_byte_ptr));
if (user_diag_flag) // is a diagnosis buffer available? //
{
// Is there a change in the service byte (1.input byte) //
if (dps_chg_diag_srvc_byte_new == dps_chg_diag_srvc_byte_old)
{
// no action //
}
else
{
//== Handling of the external diagnosis =====
// only the least significant 3 byte are used
if ((dps_chg_diag_srvc_byte_new & 0x07) !=(dps_chg_diag_srvc_byte_old & 0x07))
{
// Mask the 3 bits
diag_service_code = dps_chg_diag_srvc_byte_new & 0x07;
// Write the length of the diagnosis data to the SPC3
if (dps_chg_diag_srvc_byte_new & 0x01)
diag_len = 16; // max. value of the IM308B
else
diag_len = 6;
diag_len = DPS2_SET_DIAG_LEN(diag_len);
// Write the external diagnosis data to the SPC3
build_diag_data_blk ((struct diag_data_blk *)user_diag_buffer_ptr);
// Set the service code
// 0x01 External diagnosis
// 0x02 Static diagnosis
// 0x04 External diagnosis Overflow
i= DPS2_SET_DIAG_STATE(diag_service_code);
// Trigger the diagnosis update in the SPC3
DPS2_DIAG_UPDATE();
// Store "no diagnosis buffer available"
user_diag_flag = FALSE;
}
dps_chg_diag_srvc_byte_old = dps_chg_diag_srvc_byte_new;
}
}
//================ Check the buffers and the state =================//
// Is a new diagnosis buffer available //
if (DPS2_POLL_IND_DIAG_BUFFER_CHANGED())
{
DPS2_CON_IND_DIAG_BUFFER_CHANGED(); //Confirm the indication
user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR(); // Fetch the pointer
user_diag_flag = TRUE; // Set the Notice "Diag. buffer availble
}
} //=== endless loop ===//
return;
}
void user_dps_reset (void)
{
enum SPC3_INIT_RET dps2_init_result; /* result of the initial. */
DPS2_SET_IDENT_NUMBER_HIGH(ident_numb_high); /* Set the Identnumber */
DPS2_SET_IDENT_NUMBER_LOW(ident_numb_low);
SPC3_SET_STATION_ADDRESS(this_station); /* Set the station address*/
SPC3_SET_HW_MODE(SYNC_SUPPORTED | FREEZE_SUPPORTED | INT_POL_LOW | USER_TIMEBASE_10m);//888888888888888888888888888888888888888 /* Set div. modes of the */
/* SPC3 */
if (!real_no_add_chg)
{
DPS2_SET_ADD_CHG_ENABLE(); /* Allow or allow not the */
} /* address change */
else
{
DPS2_SET_ADD_CHG_DISABLE();
}
/* initialize the length of the buffers for DPS2_INIT() */
dps2_buf.din_dout_buf_len = 244;
dps2_buf.diag_buf_len = sizeof(struct diag_data_blk);
dps2_buf.prm_buf_len = 20;
dps2_buf.cfg_buf_len = 10;
dps2_buf.ssa_buf_len = 0; /* Suspend the address change service */
/* initialize the buffers in the SPC3
*/
//dps2_buf_init( &xxx, DPS2_IBUF_PTR, TRUE, _USE_SPEC_PRM_BUF__)
//loesch= &spc3.int_req.b[0];
dps2_init_result = dps2_buf_init(&dps2_buf, TRUE, _USE_SPEC_PRM_BUF__);
//dps2_init_result = SPC3_INIT(&dps2_buf); //
if(dps2_init_result != SPC3_INIT_OK)
{ // Failure //
for(;;)
{
error_code = INIT_ERROR;
user_error_function(error_code);
}
}
/* Get a buffer for the first configuration */
real_config_data_ptr = (UBYTE *) DPS2_GET_READ_CFG_BUF_PTR();
/* Set the length of the configuration data */
DPS2_SET_READ_CFG_LEN(CFG_LEN);
/* Write the configuration bytes in the buffer */
*(real_config_data_ptr) = CONFIG_DATA_INP; /* Example 0x13 */
*(real_config_data_ptr + 1) = CONFIG_DATA_OUTP; /* Example 0x23 */
/* Store the actuall configuration in RAM for the check in the
check_configuration sequence (see the modul intspc3.c) */
cfg_akt[0] = CONFIG_DATA_INP;
cfg_akt[1] = CONFIG_DATA_OUTP;
cfg_len_akt = 2;
/* Calculate the length of the input and output using the configuration bytes*/
user_io_data_len_ptr = dps2_calculate_inp_outp_len (real_config_data_ptr,(UWORD)CFG_LEN);
if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0)
{
/* Write the IO data length in the init block */
DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);
}
else
{
for(;;)
{
error_code =IO_LENGTH_ERROR;
user_error_function(error_code);
}
}
/* Fetch the first input buffer */
user_input_buffer_ptr = DPS2_GET_DIN_BUF_PTR();
/* Fetch the first diagnosis buffer, initialize service bytes */
dps_chg_diag_srvc_byte_new = dps_chg_diag_srvc_byte_old = 0;
user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR();
user_diag_flag = TRUE;
/* for info: get the baudrate */
user_baud_value = SPC3_GET_BAUD();
/* Set the Watchdog for the baudrate control */
SPC3_SET_BAUD_CNTRL(0x1E);
/* and finally, at last, los geht's start the SPC3 */
SPC3_START();
}
void user_error_function(enum ERRORCODES errors)
{
char ch;
/* An error has occured -> user defined actions */
/* you can check the error_code */
ch=errors;
while (1);
}
void build_diag_data_blk (struct diag_data_blk * diag_ptr)
{
diag_ptr -> header = (diag_len - 6); /* subtract the fixed */
diag_ptr -> ext_diag_0 = prm_tst_buf[0]; /* DP diagnosis */
diag_ptr -> ext_diag_1 = prm_tst_buf[1];
diag_ptr -> ext_diag_2 = prm_tst_buf[2];
diag_ptr -> ext_diag_3 = prm_tst_buf[3];
diag_ptr -> ext_diag_4 = prm_tst_buf[4];
diag_ptr -> ext_diag_5 = prm_tst_buf[5];
diag_ptr -> ext_diag_6 = prm_tst_buf[6];
diag_ptr -> ext_diag_7 = prm_tst_buf[7];
diag_ptr -> ext_diag_8 = prm_tst_buf[8];
diag_ptr -> ext_diag_9 = prm_tst_buf[9];
diag_ptr -> ext_diag_10 = prm_tst_buf[10];
diag_ptr -> ext_diag_11 = prm_tst_buf[11];
diag_ptr -> ext_diag_12 = prm_tst_buf[12];
diag_ptr -> ext_diag_13 = 0;
diag_ptr -> ext_diag_14 = 0;
diag_ptr -> ext_diag_15 = 0;
diag_ptr -> ext_diag_16 = 0;
diag_ptr -> ext_diag_17 = 0;
}
/*
void init_serial(void)
{
SCON = 0x40; //SCON: mode1(8bit UART,variable);SM1=1
T2CON=0x30; //RCLK=1; TCLK=1;
PCON |= 0x00; //SMOD=0;
switch (BR_NUM) //---------根據波特率號設置T2--------------------/
{
case 1:{TH2=0x0ff; TL2=0x0d0;RCAP2H=0x0ff;RCAP2L=0x0d0;}
break; // /---9.6K---/
case 2:{ TH2=0x0ff; TL2=0x0e8;RCAP2H=0x0ff;RCAP2L=0x0e8;}
break; // /---19.2K--/
case 3:{ TH2=0x0ff; TL2=0x0f0;RCAP2H=0x0ff;RCAP2L=0x0f0;}
break; // /---38.4K--/
case 4:{ TH2=0x0ff; TL2=0x0f8;RCAP2H=0x0ff;RCAP2L=0x0f8;}
break; // /---57.6K--/
case 5:{ TH2=0x0ff; TL2=0x0fc; RCAP2H=0x0ff;RCAP2L=0x0fc;}
break; // /---115.2K-/
case 6:{ TH2=0x0ff; TL2=0x0fe;RCAP2H=0x0ff;RCAP2L=0x0fe;}
break; // /---230.4K-/
default:
break;
}
ES=1; //enable serial port interrupt
REN=1;//enable reception
TR2=1;//enable T2
}
*/
/*
#pragma disable //disable interrupt in sending
void send(UBYTE *str,UBYTE len)
{
UBYTE k=0;
do
{
SBUF=*str;
while(TI==0);
TI=0;
k++;
str++;
} while(k<len);
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -