/***************************************************************************** * file lib/process/process.c * author YuLiang * version 1.0.0 * date 26-Sep-2021 * brief This file provides all the process related operation functions. ****************************************************************************** * Attention * *

© COPYRIGHT(c) 2021 LandPower

* * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of LandPower nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ /* Includes ------------------------------------------------------------------*/ #ifdef HAVE_CONFIG_H #include "config.h" #endif /* 标准C库头文件. */ #include #include #include #include #include #include #include #include #include #include #include "cmd.h" #include "mtimer.h" #include "process.h" #include "hwgpio.h" #include "fifo.h" #include "pd_main.h" #include "pd_dau.h" #include "pd_cpld.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ int32_t recv_qid; uint16_t version_hex; uint32_t start_time; /* Private function prototypes -----------------------------------------------*/ /* Internal functions --------------------------------------------------------*/ /* 信号处理函数 */ void _signal_handler(int sig) { if (SIGSEGV == sig) { log_backtrace(LOG_LVL_ERR); } //else if(SIGINT == sig // || SIGTSTP == sig) //{ /* 屏蔽信号 */ // return; //} exit(-1); } /* 看门狗初始化. */ void _wdg_init(void) { uint16_t temp = 0; /* 初始化看门狗计数器, 单位 ms. */ temp = 0xffff; cpld_write(CPLD_REG_WDG_TM, 1, &temp); temp = 0x01; cpld_write(CPLD_REG_WDG_EN, 1, &temp); cpld_write(CPLD_REG_WDG_CLR, 1, &temp); } /* 喂狗. */ void _wdg_clr(void) { uint16_t temp = 0; /* 喂狗, 1 - 喂狗. */ temp = 0x01; cpld_write(CPLD_REG_WDG_CLR, 1, &temp); } /* Interface functions -------------------------------------------------------*/ /* description: 数据处理初始化. param: return: (E_NONE)成功,(其他)失败 */ int32_t process_init(void) { #if 0 /* 创建消息队列. */ if ((recv_qid = msgget(0x4321, IPC_CREAT | 0666)) == -1) { log_err(LOG_DEFAULT, "message ERROR at msgget return %s!", safe_strerror(errno)); } /* 清空消息队列. */ msgctl(recv_qid, IPC_RMID, NULL); if ((recv_qid = msgget(0x4321, IPC_CREAT | 0666)) == -1) { log_err(LOG_DEFAULT, "message ERROR at msgget return %s!", safe_strerror(errno)); } #endif /* 初始化局放应用. */ pd_main(); return E_NONE; } /* description: 程序入口函数. param: return: */ int32_t main(int32_t argc, char **argv) { struct sigaction act; uint32_t cnt = 0; /* 设置本地化信息为默认值. */ setlocale(LC_ALL, ""); /* 必须最前面, 初始化内存管理模块的基本参数. */ mtype_init_befor(); /* log初始化 */ //log_open(); /* 初始化时定量清除 log */ //log_clean(); //log_out(LOG_DEFAULT, LOG_LVL_WARN, "System start!"); /* 设置信号处理的回调函数 */ act.sa_handler = _signal_handler; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); sigaction(SIGSEGV, &act, NULL); sigaction(SIGTSTP, &act, NULL); /* 初始化cli等公共模块. */ cmd_init(); thread_m_init(); mtype_init(); dbg_init(); mtimer_init(); vtysh_init(); gpio_init(); fifo_init(); /* 初始化 DAU 复位, 并不采集数据. 这里必须等待, 不然 gpio 模拟 spi 会失败. */ cpld_handle_init(); //_wdg_init(); //dau_shutdown(); /* 主处理函数初始化 */ process_init(); /* 配置恢复命令行启动 */ //vtysh_config_recovery(); //dau_start(); /* 启动命令行 */ vtysh_shell_init(); /* 初始化完成 */ version_hex = version_str_to_int(); is_system_init = TRUE; start_time = time(NULL); //GPIO_ERR1_LED(1); /* 启动ssh命令行 */ vtycmd_init(); /* 主循环, 点灯喂狗. */ for(;;) { sleep(1); #if 0 /* 获取同步状态, 更新收报计数. */ if (0 == (cnt & 0x7)) { pd_sync_state_get(); GPIO_SYNC_LED(!pd_state.sync); if (dau_ctrl.recv_cnt > 2000) { printh("ERROR recv_cnt %d\r\n", dau_ctrl.recv_cnt); } dau_ctrl.recv_cnt_old = dau_ctrl.recv_cnt; dau_ctrl.recv_cnt = 0; } /* 点 RUN 灯. */ if (cnt & 0x1) { GPIO_RUN_LED(0); } else { GPIO_RUN_LED(1); } sleep(1); cnt++; /* 更新数据处理计数. */ if (0 == (cnt & 0x3f)) { dau_ctrl.recv_err_cnt_old = dau_ctrl.recv_err_cnt; dau_ctrl.recv_err_cnt = 0; dau_ctrl.data_err_cnt_old = dau_ctrl.data_err_cnt; dau_ctrl.data_err_cnt = 0; dau_ctrl.send_err_cnt_old = dau_ctrl.send_err_cnt; dau_ctrl.send_err_cnt = 0; } /* 喂狗. */ if (0 == (cnt & 0x1f)) { _wdg_clr(); } #endif } return 0; } /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/