仓库迁移

This commit is contained in:
andy
2023-06-10 11:52:00 +08:00
parent e4616bfae5
commit 077c27f2bb
499 changed files with 199745 additions and 92 deletions

View File

@@ -0,0 +1,17 @@
#ifndef compiler_info__
#define compiler_info__
#define BUILD_DATE "2023-06-09 18:00:05"
#endif

497
source/main/main.c Normal file
View File

@@ -0,0 +1,497 @@
#ifdef RT_THREAD
#include "stdio.h"
#include "rtthread.h"
#include "board.h"
#include "mystdlib.h"
#include "list.h"
#include "mystring.h"
#include "signal.h"
#include "prot_mcu.h"
#include "debug.h"
#include "handle.h"
#include "prot_uc.h"
#include "transmit.h"
#include "tcp.h"
#include "netconf.h"
#include "stm32f4x7_eth_bsp.h"
#include "commend.h"
#include "dev_flash.h"
#include "mymisc.h"
#include "dev_backup.h"
#include "compiler_info.h"
#include "udp.h"
#include "moter.h"
int main()
{
const sys_param_def *par=sys_param();
ETH_BSP_Config();
LwIP_Init();
debug_init();
app_init();
protu_def *protu=app_variable("protu",0,0);
tran_def *tran=app_variable("tran",0,0);
void *cmd=app_variable("cmd",0,0);
void *udp=app_variable("udp",0,0);
connect(protu,protu_recv_signal,0,tran,tran_recv_slot);
connect(tran,tran_reply_signal,0,protu,protu_reply_call);
connect(tran,tran_send_signal,0,protu,protu_send_call);
connect(udp,udp_recv_signal,0,cmd,cmd_recv_slot);
connect(cmd,cmd_reply_signal,0,udp,udp_reply_call);
connect(protu,protu_recv_signal,0,cmd,cmd_recv_slot);
connect(cmd,cmd_reply_signal,0,protu,protu_send_call);
//DBG_LOG("询预压");
//DBG_LOG("我知道");
//--diag_suppress=550,177
while(1)
{
rt_thread_mdelay(5000);
}
}
int init_wdog(void)
{
if(bk_wdog_fun())
{
rt_thread_idle_sethook((void (*)(void))bk_wdog_fun());
}
return 0;
}
app_init_export(init_wdog)
static int test(list_def *argv)
{
if(list_length(argv)<2){
cmd_print("param num too less.");
return -1;
}
int num=str_atoi(list_get_str(argv,1));
cmd_print("test num=%d,hex=%x",num,num);
return 0;
}
commend_export(test,test,"cmd test")
static int scheme_info(list_def *argv)
{
const scheme_def *s=check_scheme();
if(s->plan_id==0xffffffff){
cmd_print("scheme is empty.");
return -1;
}
cmd_print("plan id: %d",s->plan_id);
cmd_print("timeout_m: %d",s->timeout_m);
cmd_print("range num: %d",s->range_num);
for(int i=0;i<s->range_num;i++)
{
cmd_print(" max:%5d, min:%5d %s",s->range[i].max,s->range[i].min,
s->range[i].max<s->range[i].min?"err":"ok");
}
return 0;
}
commend_export(scheme,scheme_info,"print scheme info")
static int updata_slave(list_def *argv)
{
void *ptr=flash_get_slave();
tran_def *tran=app_variable("tran",0,0);
uint8_t *data=ptr;
data+=FLASH_FILE_HEAD_SIZE;
flash_file *file=ptr;
if(tran==0){
DBG_WARN("can not fond variable \"tran\"");
return -1;
}
if(list_length(argv)<2){
cmd_print("param num too less.");
return -1;
}
list_def *addrs=str_atod_list(list_get_str(argv,1),',');
for(int i=0;i<list_length(addrs);i++)
{
int addr=list_get_int(addrs,i);
port_mcu *mcu=tran_get_portm(tran,addr-1);
if(mcu)
port_start(mcu,updata_creat(data,file->file_size));
}
cmd_print("start updata,addr=%s",str_temp(list_string(addrs)));
return 0;
}
commend_export(updatas,updata_slave,"updata slave")
static int memused(list_def *argv)
{
uint32_t used,total,max_used;
rt_memory_info(&total,&used,&max_used);
cmd_print("mem total=%d,used=%d,max_used=%d",total,used,max_used);
used=mem_perused();
cmd_print("mem used=%d.",used);
return 0;
}
commend_export(memused,memused,"print the mem use info")
static int reboot(list_def *argv)
{
cmd_print("mcu will reboot later");
later_execute((void (*)(void *))bk_reboot_app,0,50);
return 0;
}
commend_export(reboot,reboot,"reboot mcu")
static int moter(list_def *argv)
{
const sys_param_def *par=sys_param();
cmd_print("moter ctl");
if(list_length(argv)<3){
cmd_print("param num too less.");
return -1;
}
int fre=str_atoi(list_get_str(argv,1));
int count=str_atoi(list_get_str(argv,2));
moter_start(fre,count);
cmd_print("moter start,fre=%d,count=%d",fre,count);
return 0;
}
commend_export(moter,moter,"control moter up or down|use:moter [frequency] [count]")
static void print_sys_param(const sys_param_def *par)
{
cmd_print(" - - - - - - - - - - - - - - ");
cmd_print("pack time: %s",par->pack_time);
cmd_print("host if: %s",par->host_if);
cmd_print("device type: %s",par->device_type);
cmd_print("mac addr: %02x.%02x.%02x.%02x.%02x.%02x",
par->mac[0],par->mac[1],par->mac[2],par->mac[3],par->mac[4],par->mac[5]);
cmd_print("local ip: %d.%d.%d.%d",
par->local_ip[0],par->local_ip[1],par->local_ip[2],par->local_ip[3]);
cmd_print("host ip: %d.%d.%d.%d",
par->host_ip[0],par->host_ip[1],par->host_ip[2],par->host_ip[3]);
cmd_print("host port: %d",par->host_port);
cmd_print("local cmd port: %d",par->local_cmd_port);
cmd_print("host log port: %d",par->host_log_port);
cmd_print("local id: %d",par->local_id);
}
static int sysinfo(list_def *argv)
{
const sys_param_def *par=sys_param();
cmd_print("build time: %s",BUILD_DATE);
cmd_print("soft version: 0.01");
cmd_print("run time: %d",rt_tick_get()/1000);
cmd_print("startup: %s",bk_get_currtype());
cmd_print("watch dog: %s",bk_wdog_fun()?"on":"off");
cmd_print("reboot times: %d",bk_reboot_times());
print_sys_param(par);
return 0;
}
commend_export(sysinfo,sysinfo,"print the sortware info")
static void print_sys_help(void)
{
cmd_print("example for how to set system params:");
cmd_print("set hostif uart4/utcp");
cmd_print("set devicetype checker/coder");
cmd_print("set localip 192.168.80.10");
cmd_print("set hostip 192.168.80.100");
cmd_print("set hostport 7777");
cmd_print("set localcmdport 7777");
cmd_print("set hostlogport 12345");
cmd_print("set localid 1");
cmd_print("set save");
}
static int sys_set(list_def *argv)
{
static sys_param_def *spar=0;
if(spar==0){
spar=calloc(1,sizeof(sys_param_def));
memcpy(spar,sys_param(),sizeof(sys_param_def));
}
if(list_length(argv)<2){
cmd_print(" - - - -SET TEMP- - - - ");
print_sys_param(spar);
return 0;
}
if(strcmp(list_get_str(argv,1),"help")==0)
{
print_sys_help();
return 0;
}
else if(strcmp(list_get_str(argv,1),"save")==0)
{
cmd_print(" - - - -SET TEMP- - - - ");
print_sys_param(spar);
flash_save_param(spar);
cmd_print("param saved,device will reboot later.");
later_execute((void (*)(void *))bk_reboot_app,0,100);
return 0;
}else{
if(list_length(argv)<3){
cmd_print("param num too less.");
print_sys_help();
return -1;
}
}
if(strcmp(list_get_str(argv,1),"hostif")==0)
{
char *str=list_get_str(argv,2);
memcpy(spar->host_if,str,strlen(str)+1);
cmd_print("host if: %s",spar->host_if);
}
else if(strcmp(list_get_str(argv,1),"devicetype")==0)
{
char *str=list_get_str(argv,2);
memcpy(spar->device_type,str,strlen(str)+1);
cmd_print("device type: %s",spar->device_type);
}
else if(strcmp(list_get_str(argv,1),"localip")==0)
{
char *str=list_get_str(argv,2);
list_def *ip=str_atod_list(str,'.');
spar->local_ip[0]=list_get_int(ip,0);
spar->local_ip[1]=list_get_int(ip,1);
spar->local_ip[2]=list_get_int(ip,2);
spar->local_ip[3]=list_get_int(ip,3);
cmd_print("local ip: %d.%d.%d.%d",
spar->local_ip[0],spar->local_ip[1],spar->local_ip[2],spar->local_ip[3]);
}
else if(strcmp(list_get_str(argv,1),"hostip")==0)
{
char *str=list_get_str(argv,2);
list_def *ip=str_atod_list(str,'.');
spar->host_ip[0]=list_get_int(ip,0);
spar->host_ip[1]=list_get_int(ip,1);
spar->host_ip[2]=list_get_int(ip,2);
spar->host_ip[3]=list_get_int(ip,3);
cmd_print("host ip: %d.%d.%d.%d",
spar->host_ip[0],spar->host_ip[1],spar->host_ip[2],spar->host_ip[3]);
}
else if(strcmp(list_get_str(argv,1),"hostport")==0)
{
char *str=list_get_str(argv,2);
spar->host_port=str_atoi(str);
cmd_print("host port: %d",spar->host_port);
}
else if(strcmp(list_get_str(argv,1),"localcmdport")==0)
{
char *str=list_get_str(argv,2);
spar->local_cmd_port=str_atoi(str);
cmd_print("local cmd port: %d",spar->local_cmd_port);
}
else if(strcmp(list_get_str(argv,1),"hostlogport")==0)
{
char *str=list_get_str(argv,2);
spar->host_log_port=str_atoi(str);
cmd_print("local log port: %d",spar->host_log_port);
}
else if(strcmp(list_get_str(argv,1),"localid")==0)
{
char *str=list_get_str(argv,2);
spar->local_id=str_atoi(str);
cmd_print("local id: %d",spar->local_id);
}
else{
cmd_print("unknown cmd for sysset.");
print_sys_help();
return -1;
}
return 0;
}
commend_export(set,sys_set,"set the system params")
#else
#include "board.h"
#include "dev_flash.h"
#include "dev_backup.h"
#include "crc.h"
#include "dev_watchdog.h"
#include "string.h"
#define APP_ADDR 0x08020000
void __set_msp(uint32_t addr);
typedef void (*app)(void);
void app_run(void)
{
app app_fun;
if(((*(volatile uint32_t*)APP_ADDR)&0x2FFE0000)==0x20000000)
{
// wdog_start();
// bk_set_wdog_fun(wdog_refresh);
app_fun=(app)*(volatile uint32_t*)(APP_ADDR+4);
__set_msp(*(volatile uint32_t*)APP_ADDR);
app_fun();
}
}
void param_init(rom_head *h);
void app_updata(void);
int main()
{
uint32_t boot_type=bk_get_boottype();
bk_init();
switch(boot_type){
// 重启并升级
case REBOOT_APP_TO_BOOT:
{
uint8_t *rom;
rom_head *head;
rom=flash_get_rom(&head);
param_init(head);
if(rom)
{
if(head->crc==crc_crc32(rom,head->size))
{
flash_updata_app(rom,head->size);
}
}
bk_reboot_guide();
break;
}
// 重新运行boot
case REBOOT_BOOT_TO_BOOT:
break;
// 重启app
case REBOOT_APP_TO_APP:
// 引导至app
case REBOOT_BOOT_TO_APP:
// 断言失败重启
case REBOOT_PARAM_ERR:
// 硬件错误重启
case REBOOT_HARD_ERR:
// 看门狗重启
case REBOOT_INIT:
// 上电启动
default:
param_init(0);
app_run();
break;
}
while(1)
{
}
}
// 初始化mac地址
void mac_init(uint8_t *mac)
{
const uint8_t *mcu_id=(const uint8_t *)0x1FFF7A10;
for(int i=0;i<6;i++)
{
mac[i]=mcu_id[i*2]^((mcu_id[i*2+1]<<4)|(mcu_id[i*2+1]>>4));
}
}
// 参数初始化
void param_init(rom_head *h)
{
static sys_param_def pars={0};
memcpy(&pars,sys_param(),sizeof(sys_param_def));
memcpy(pars.pack_time,h->pack_time,20);
if(pars.local_id==0xffffffff){
if(h){
memcpy(pars.host_if,h->host_if,8);
memcpy(pars.device_type,"checker",8);
mac_init(pars.mac);
memcpy(pars.local_ip,h->local_ip,4);
memcpy(pars.host_ip,h->host_ip,4);
pars.host_port=h->host_port;
pars.local_cmd_port=7777;
pars.host_log_port=12345;
pars.local_id=1;
}
else{
// 填充默认配置
memcpy(pars.host_if,"uart4",6);
memcpy(pars.device_type,"coder",6);
mac_init(pars.mac);
memcpy(pars.local_ip,(uint8_t []){192,168,80,10},4);
memcpy(pars.host_ip,(uint8_t []){192,168,80,80},4);
pars.host_port=9527;
pars.local_cmd_port=7777;
pars.host_log_port=12345;
pars.local_id=1;
}
}
flash_save_param(&pars);
}
#endif

9175
source/main/stm32f4xx.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
/**
******************************************************************************
* @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_conf.h
* @author MCD Application Team
* @version V1.4.0
* @date 04-August-2014
* @brief Library configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F4xx_CONF_H
#define __STM32F4xx_CONF_H
/* Includes ------------------------------------------------------------------*/
/* Uncomment the line below to enable peripheral header file inclusion */
#include "stm32f4xx_adc.h"
#include "stm32f4xx_crc.h"
#include "stm32f4xx_dbgmcu.h"
#include "stm32f4xx_dma.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_flash.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_iwdg.h"
#include "stm32f4xx_pwr.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_rtc.h"
#include "stm32f4xx_sdio.h"
#include "stm32f4xx_spi.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_wwdg.h"
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
#if defined (STM32F429_439xx)
#include "stm32f4xx_cryp.h"
#include "stm32f4xx_hash.h"
#include "stm32f4xx_rng.h"
#include "stm32f4xx_can.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_dcmi.h"
#include "stm32f4xx_dma2d.h"
#include "stm32f4xx_fmc.h"
#include "stm32f4xx_ltdc.h"
#include "stm32f4xx_sai.h"
#endif /* STM32F429_439xx */
#if defined (STM32F427_437xx)
#include "stm32f4xx_cryp.h"
#include "stm32f4xx_hash.h"
#include "stm32f4xx_rng.h"
#include "stm32f4xx_can.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_dcmi.h"
#include "stm32f4xx_dma2d.h"
#include "stm32f4xx_fmc.h"
#include "stm32f4xx_sai.h"
#endif /* STM32F427_437xx */
#if defined (STM32F40_41xxx)
#include "stm32f4xx_cryp.h"
#include "stm32f4xx_hash.h"
#include "stm32f4xx_rng.h"
#include "stm32f4xx_can.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_dcmi.h"
#include "stm32f4xx_fsmc.h"
#endif /* STM32F40_41xxx */
#if defined (STM32F411xE)
#include "stm32f4xx_flash_ramfunc.h"
#endif /* STM32F411xE */
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* If an external clock source is used, then the value of the following define
should be set to the value of the external clock source, else, if no external
clock is used, keep this define commented */
/*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT 1 */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
#endif /* __STM32F4xx_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
/**
******************************************************************************
* @file system_stm32f4xx.h
* @author MCD Application Team
* @version V1.4.0
* @date 04-August-2014
* @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f4xx_system
* @{
*/
/**
* @brief Define to prevent recursive inclusion
*/
#ifndef __SYSTEM_STM32F4XX_H
#define __SYSTEM_STM32F4XX_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup STM32F4xx_System_Includes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F4xx_System_Exported_types
* @{
*/
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
/**
* @}
*/
/** @addtogroup STM32F4xx_System_Exported_Constants
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F4xx_System_Exported_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F4xx_System_Exported_Functions
* @{
*/
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /*__SYSTEM_STM32F4XX_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/