/* * This file is part of the EasyFlash Library. * * Copyright (c) 2015-2019, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * 'Software'), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Function: Portable interface for each platform. * Created on: 2015-01-16 */ #include #include #include #include /* default environment variables set for user */ static const ef_env default_env_set[] = { {"iap_need_copy_app", "0"}, // 需要升级App {"iap_copy_app_size", "0"}, {"iap_need_uart_update", "0"}, // 需要通过串口升级 {"iap_app_filename", "App.bin"}, {"stop_in_bootloader", "0"}, {"boot_times", "0"}, {"jump_boot_time", "10"}, // BOOT 等待时间 10s // 基础参数设置 {"device_id", "7322070012"}, {"app_id", "220000"}, // 业务ID {"user_pass", "123456"}, {"sys_pass", "898909"}, {"mqtt_user", "admin"}, {"mqtt_pass", "admin"}, {"mqtt_addr", "mqtt.zyjzjs.cn"}, {"mqtt_port", "1883"}, {"mqtt_topic", "syksk"}, //订阅topic {"net_drv", "dtu"}, // mqtt dtu ec200 eth {"eth2_chann", "0"}, //以太网通道2 支持modbus // 传感器基础参数配置 {"di1", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 {"di2", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 {"di3", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 {"di4", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 {"di5", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 {"di6", "0"},// 0 表示未定义 1 表示 上限位,2:下限位 3: 开关4:关 5:停止 // 485 配置参数 {"u485func", "mg1000"}, // 用于一个柜子控制多台闸门 {"s4851func", "rds600"}, // 4851 接入传感器的类型 rds600 tds300 {"s4852func", "modbus"}, // 4852 接入传感器的类型 // 模拟量配置 {"ai1", "0"}, // AI1接入设备 {"ai2", "0"}, // AI2接入设备 {"ao1", "0"}, // AO1接入设备 {"ao2", "0"}, // AO2接入设备 {"key1", "0"}, // 继电器1功能 {"key2", "0"}, // 继电器2功能 {"pwm1", "0"}, // PWM1功能 {"pwm2", "0"}, // PWM2功能 {"pwm3", "0"}, // PWM3功能 {"pwm4", "0"}, // PWM4功能 // 闸门参数设置 {"max_open", "1600"}, // 最大开度 {"max_ecode", "25712"}, // 编码器最大编码 {"min_ecode", "31770"}, // 编码器最小编码 {"exec_time", "50"}, // 异常检测时间 单位100ms 50 就是 5s // 闸门参数设置 {"ctrl_mode", "0"}, // 控制模式 // 1 直接开度控制,0 反馈开度控制 {"motor_type", "mg1000"}, // 电机类型 // mg a3 b5 {"simu_flow", "0"}, // 0 未启动 1 水位流量关系表 2巴歇尔槽启动流量关系表 {"parshall", "7"}, // 巴歇尔槽规格 // 流量数据存储 {"ttflow", "0"}, // 累计流量 {"chancnt", "1"}, // 流量计通道数 {"site_type", "sluice"}, // 0,闸门站,1,流量站,2,渗流渗压站,3,自动化采集站,4,串口服务器 {"level","[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]"}, {"flow", "[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]"}, {"wsid","[1,2,3,4,5,6]"}, {"sl427ip","116.176.77.72"}, {"sl427port","6200"}, {"sl427code","0000000002"}, // 水位流量关系表 配置10 个点 }; static char log_buf[128]; /** * Flash port for hardware initialize. * * @param default_env default ENV set for user * @param default_env_size default ENV size * * @return result */ EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) { EfErrCode result = EF_NO_ERR; *default_env = default_env_set; *default_env_size = sizeof(default_env_set) / sizeof(default_env_set[0]); //xMutexElog = xSemaphoreCreateMutex(); /* 创建互斥信号量 */ // if(xMutexElog == NULL) // { // /* 没有创建成功,用户可以在这里加入创建失败的处理机制 */ // while(1); // } return result; } /** * Read data from flash. * @note This operation's units is word. * * @param addr flash address * @param buf buffer to store read data * @param size read bytes size * * @return result */ EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) { EfErrCode result = EF_NO_ERR; /* You can add your code under here. */ const sfud_flash *flash = sfud_get_device_table() + SFUD_W25Q_DEVICE_INDEX; sfud_read(flash, addr, size, (uint8_t *)buf); return result; } /** * Erase data on flash. * @note This operation is irreversible. * @note This operation's units is different which on many chips. * * @param addr flash address * @param size erase bytes size * * @return result */ EfErrCode ef_port_erase(uint32_t addr, size_t size) { EfErrCode result = EF_NO_ERR; sfud_err sfud_result = SFUD_SUCCESS; const sfud_flash *flash = sfud_get_device_table() + SFUD_W25Q_DEVICE_INDEX; /* make sure the start address is a multiple of EF_ERASE_MIN_SIZE */ EF_ASSERT(addr % EF_ERASE_MIN_SIZE == 0); /* You can add your code under here. */ sfud_result = sfud_erase(flash, addr, size); if(sfud_result != SFUD_SUCCESS) { result = EF_ERASE_ERR; } return result; } /** * Write data to flash. * @note This operation's units is word. * @note This operation must after erase. @see flash_erase. * * @param addr flash address * @param buf the write data buffer * @param size write bytes size * * @return result */ EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) { EfErrCode result = EF_NO_ERR; /* You can add your code under here. */ sfud_err sfud_result = SFUD_SUCCESS; const sfud_flash *flash = sfud_get_device_table() + SFUD_W25Q_DEVICE_INDEX; sfud_result = sfud_write(flash, addr, size, (const uint8_t *)buf); if(sfud_result != SFUD_SUCCESS) { result = EF_WRITE_ERR; } return result; } /** * lock the ENV ram cache */ void ef_port_env_lock(void) { rt_enter_critical(); // portENTER_CRITICAL(); /* You can add your code under here. */ //__disable_irq(); } /** * unlock the ENV ram cache */ void ef_port_env_unlock(void) { rt_exit_critical(); // portEXIT_CRITICAL(); /* You can add your code under here. */ // __enable_irq(); } /** * This function is print flash debug info. * * @param file the file which has call this function * @param line the line number which has call this function * @param format output format * @param ... args * */ void ef_log_debug(const char *file, const long line, const char *format, ...) { #ifdef PRINT_DEBUG va_list args; /* args point to the first variable parameter */ va_start(args, format); /* You can add your code under here. */ va_end(args); #endif } /** * This function is print flash routine info. * * @param format output format * @param ... args */ void ef_log_info(const char *format, ...) { va_list args; /* args point to the first variable parameter */ va_start(args, format); ef_print("[Flash]"); /* must use vprintf to print */ vsprintf(log_buf, format, args); ef_print("%s", log_buf); printf("\r\n"); va_end(args); } /** * This function is print flash non-package info. * * @param format output format * @param ... args */ void ef_print(const char *format, ...) { va_list args; /* args point to the first variable parameter */ va_start(args, format); /* must use vprintf to print */ vsprintf(log_buf, format, args); printf("%s", log_buf); va_end(args); }