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

📄 userspc3.c

📁 profibus TO RS485 profibus TO RS485
💻 C
📖 第 1 页 / 共 2 页
字号:
        }

 		//=== endless loop        ===
      }   /*=== endless loop        ===*/

	return;

}

/* #pragma public */






void user_dps_reset (void)
{
static uchar xa = 0;

/*初始化SPC3的内部缓存*/
enum SPC3_INIT_RET dps2_init_result;            /* result of the initial. */

/*设置从站用户标志*/
xa++;
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);
												/* 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() */
/*输入输出缓存为244*/
dps2_buf.din_dout_buf_len = 224;
/*诊断缓存长度设置*/
dps2_buf.diag_buf_len = 80;
/*参数化缓存长度为20*/
dps2_buf.prm_buf_len = 208;
/*配置缓存长度为10*/
dps2_buf.cfg_buf_len = CFG_LEN;

/* dps2_buf.ssa_buf_len = 5;    reserve buffer if address change is possible */
dps2_buf.ssa_buf_len = 0;       /* Suspend the address change service  */
								/* No storage in the IM183 is possible */


/* initialize the buffers in the SPC3                   */
/*初始化SPC内站缓存*/
//do
//      {
      dps2_init_result = SPC3_INIT(&dps2_buf);
 //     }
//while (dps2_init_result != SPC3_INIT_OK);
/*如果有错则进入死循环等看门狗复位*/
spc3_result=0xaa;
if(dps2_init_result != SPC3_INIT_OK)
        {
  //     spc3_result=0xbb;
//        }
//	{       /* Failure */
	for(;;)
		{
		error_code = INIT_ERROR;
		user_error_function(error_code);
		}
	}

/* Get a buffer for the first configuration */
/*获取配置缓存指针*/
real_config_data_ptr = (UBYTE SPC3_PTR_ATTR*) 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 */
/*自行配置为4IN 4OUT*/

/* Store the actuall configuration in RAM for the check in the
   check_configuration sequence (see the modul intspc3.c)       */
   /*保存配置文件用于主站配置后的检验*/

/* 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 */
/*根据设置波特率扫描的看门狗初始值,若波特率错了,或无数据
接收,0X1E*10MS=300MS后才开始找新的波特率*/
SPC3_SET_BAUD_CNTRL(0x1E);

/* and finally, at last, los geht's start the SPC3 */
/*启动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);

}


UBYTE get_addr(void)
{
        UBYTE own_address;
        P1 = 0xff;
      //  oe_switch = 0;
        own_address = ~P1 & 0xff;
     //   oe_switch = 1;
        return own_address;
}


void build_diag_data_blk (struct diag_data_blk * diag_ptr)
{
        UBYTE		ii;
	diag_ptr -> header                  = (diag_len - 7);       /* subtract the fixed */
	for(ii=0;ii<74;ii++)
	{
		diag_ptr -> diag_data_map[ii] = ext_diag.diag_data_map[ii];       /* DP diagnosis       */
	}
}


void init_buffer(void)
{
	UWORD   i;
    p_link_data_buf1 = &str_link_data_buf;
	p_link_data_buf1->interface_flag = LINK_ERR;//上电初始化视为profibus从站卡为错误状态
    p_link_data_buf1->p_prm_tol_ptr = prm_data_map;
	p_link_data_buf1->p_out_tol_ptr = out_data_map;
	p_link_data_buf1->p_in_tol_ptr = in_data_map;
	p_link_data_buf1->p_diag_tol_ptr = ext_diag.diag_data_map;
	for(i=0;i<=255;i++)
	{

        prm_data_map[i] = 0x0;

       	out_data_map[i] = 0x0;
       	in_data_map[i] = 0x0;
        ext_diag.diag_data_map[i] = 0x0;
	}

        glab_diag_flag = 0x0;

}




void inteface_flag_p(void)
{

        static count=0;
        static l_count=0;
        unsigned char led_count;
	if(glab_prm_flag != old_glab_prm_flag)
         {
                count++;
		p_link_data_buf1->interface_flag = PARAM_COM;
		ext_diag.diag_data_map[0] = 0x1;//告诉上位机这个LINK的输入数据为不可用状态
                 uc_system_status_flag=RESET_STATE;
                 old_glab_prm_flag = glab_prm_flag ;
                if(count==5)
                {
                count=0;

                for(;;)
		   {
	            ;//等待狗复位
		   }
                }

	}
    else
       {
	     if((zyk_wd_state != 0x02) && (zyk_dps_state != 0x03))
           {
               l_count++;
               if(l_count==5)
               {
               l_count=0;

                out_data_map[0] = STOP_COM; //进入STOP状态
   //             write_command(STOP_COM);
  //              update_sys_command(p_link_data_buf1);
                }

           }
        else
        	{
        	l_count=0;
                count=0;
        	}

       }
}































































































































⌨️ 快捷键说明

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