protect_source/标准版4.0/prot_digital_v30_Core1.c

228 lines
5.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************************
* PROT_digital_v30_Core1.c
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ccblkfn.h>
#include "adi_initialize.h"
#include "PROT_digital_v30_Core1.h"
#include "sys/drivers.h"
//#include "cgu.h"
#include "rtdb.h"
#include "digit_protect\inc\digit_commonapi.h"
#include "adi_osal.h"
/**
* Place program arguments in the following string.
*/
extern void timer_interrupt(void);
extern void pulseAjustClock(); //秒脉冲中断处理函数
extern int progStart(int ErrCode);
extern void KaiChuChannelReset(); //开出通道复位
extern void maintask(void);
extern int spi_flash_init(void);
extern void gse_handle( void );
extern int goosesmv_init( void );
//int inf_shm_printf_write( const char *forms, ... );
extern void adi_gpio_init();
double sGetMsTime ( void );
extern void adi_qpio_wd_set();
extern void adi_qpio_wd_clear();
extern int driver_can_adi_open_can0( int baudRate );
extern int driver_can_adi_handle( void );
static double restartTime=0;
/* 设定过多少毫秒后,重启系统(停止喂狗) **/
int set_boottime( int millSecs )
{
restartTime = sGetMsTime() + millSecs + 10.0;
return 0;
}
static int feed_watch_dog( void )
{
if( restartTime < 10 || sGetMsTime()<restartTime )
{
WD_FEED();
}
return 0;
}
int main(void)
{
int i;
unsigned int *ptr;
double kk1,kk2,kk3;
/* Initialize managed drivers and/or services */
adi_initComponents();
i = 1;
//cgu_init();
ptr =(unsigned int *)(RTDB_BUFFER_PROTECT_INIT);
*ptr = 1;
rtdb_init();
//printf("%d",i);
//printf("time = %d,time1 = %d\n",k,*((int *)(RTDB_BUFFER_INIT_TIME)));
SYS_TRACE("protect system init start \n");
//spiflash初始化
spi_flash_init();
(*ptr)++;
SYS_TRACE("spi_flash_init finished \n");
adi_gpio_init();
//int *pddd;
//inf_shm_get_addr_printf( &pddd );
//SYS_TRACE("addr = %X\n",pddd);
//保护初始化
progStart(0);
(*ptr)++;
SYS_TRACE("progStart finished \n");
//goose sv初始化
goosesmv_init( );
(*ptr)++;
//打开can
driver_can_adi_open_can0( 500 );
//driver_can_adi_open_can0( 1000 );
(*ptr)++;
//开出通道复位
KaiChuChannelReset();
(*ptr)++;
//打开定时器
//gpio初始化毫秒中断、秒脉冲中断、看门狗
#ifdef MS_INT_EXTERNAL //毫秒中断为外部中断
drv_gpio_init(timer_interrupt,pulseAjustClock);
#else //毫秒中断采用内部定时器
//打开定时器
drv_tmr_open(timer_interrupt);
//gpio初始化秒脉冲中断、看门狗
drv_gpio_init(NULL,pulseAjustClock);
#endif
SYS_TRACE("drv_tmr_open() finished \n");
ptr =(unsigned int *)(RTDB_BUFFER_PROTECT_INIT);
*ptr = SHM_BUFF_INIT_FLAG;
ptr =(unsigned int *)(RTDB_BUFFER_PROTECT_COUNT);
*ptr = 0;
//printf("v = %X\n",*(unsigned int *)(RTDB_BUFFER_PROTECT_INIT));
//为了使网口发送成功第一帧GOOSE必须如下延迟
//sMsSleep(3500);
//gsemv_goose_check_send();
while(1)
{
//continue;
#ifdef CCES_ADI
//execute_as_subscriber();
#endif
#if 1
//kk1 = sGetMsTime();
feed_watch_dog( ); //20180426
(*ptr) ++;
//can收发
driver_can_adi_handle();
//WD_FEED();
gse_handle();
//driver_can_adi_handle();
//喂狗
//WD_FEED();
maintask();
//adi_gpio_wd_feed();
//D_OUT(0, 2);
if( *ptr%200000 == 0 )
{
#if 0
static int subNum=0;
subNum++;
if( subNum > 0 )
{
int gsv_clnp_recv_submit_buffer( int eth_index );
subNum = gsv_clnp_recv_submit_buffer( 2 );
if( 0 != subNum )
{
inf_shm_printf_write("gsv_clnp_recv_submit_buffer failed.\n");
}
subNum = 0;
}
#endif
#if 0
int gsv_clnp_send( int eth_index, unsigned char *msg, int msg_len );
unsigned char buff[128]={00,00,00,00,00,00,11,22,33,44,55,66,0x81,00,00,00,
0x88,0xb8,0x30,0x08,0x00,0x37,0x00,0x00,0x00,0x00,0x61,0x2d,0x80,0x01,0x62,0x81,
};
static unsigned char dd=0,iLoop;
for( iLoop=48; iLoop<49; iLoop++ )
buff[iLoop]=(unsigned char)(iLoop+dd);
dd++;
gsv_clnp_send(3, buff, sizeof(buff) );
buff[iLoop]=(unsigned char)(iLoop+dd);
gsv_clnp_send(3, buff, sizeof(buff) );
//gsv_clnp_send(3, buff, sizeof(buff) );
#endif
#if 0
static unsigned char status=0;
status = !status;
gw61850gse_data_value_change(1,NULL,2041, (void *)&status);
gw61850gse_data_value_change(1,NULL,2054, (void *)&status);
gw61850gse_check_and_send();
#endif
#if 0
int addr;
unsigned char buf[1024]={0x55};
addr = 64*1024 * (3 + 2);
//在spi_flash_write中已经将该快擦除
memset(buf, 0x55, 1024 );
spi_flash_write(addr, buf, 1024 );
#endif
#if 0
static int tmp=0;
tmp++;
if( tmp > 4 )
{
tmp = 0;
gsv_clnp_linkport_reable_rx(2);
SYS_TRACE("\n \t>>Now reset LinkPort.\n" );
}
#endif
//SYS_TRACE(">>Now protect circle is %d, time is %0.3f.\n",
// *ptr/1000, sGetMsTime()/1000 );
}
//kk2 = sGetMsTime();
/*
if((kk3 = kk2 - kk1)>= 8)
{
SYS_TRACE("the circle %d time is longer than 8ms and the circle time is %f\n",*ptr,kk3);
}
*/
#endif
}
/* Begin adding your custom code here */
}