|
|
#include <windows.h>
#include <iostream>
#include <set>
#include "logger.hpp"
#include "zcsv.hpp"
using namespace iflytop; using namespace std; #define TAG "Main"
#if 0
/**
* @brief * * * FPGA_PIN, DIRECTION, NAME * B5 INPUT ex_clk * E2 OUTPUT core_board_debug_led * * * 输入引脚模板 * define_attribute {p:ex_clk} {PAP_IO_DIRECTION} {INPUT} * define_attribute {p:ex_clk} {PAP_IO_LOC} {B5} * define_attribute {p:ex_clk} {PAP_IO_VCCIO} {3.3} * define_attribute {p:ex_clk} {PAP_IO_STANDARD} {LVTTL33} * 输出引脚模板 * define_attribute{p : core_board_debug_led } { PAP_IO_DIRECTION } { OUTPUT } * define_attribute{p : core_board_debug_led } {PAP_IO_LOC } {E2 } * define_attribute{p : core_board_debug_led } {PAP_IO_VCCIO } {3.3 } * define_attribute{p : core_board_debug_led } {PAP_IO_STANDARD } {LVCMOS33 } * define_attribute{p : core_board_debug_led } {PAP_IO_DRIVE } {4 } * define_attribute{p : core_board_debug_led } {PAP_IO_SLEW } {SLOW } * * */ int _main() { shared_ptr<ZCSV> zcsv = make_shared<ZCSV>(); bool suc = zcsv->parseCSV("pin.csv"); if (!suc) { ZLOGE(TAG, "parse csv failed"); return -1; }
// string pinnum;
int maxRow = zcsv->maxRowNum();
string outputfilename; outputfilename = zcsv->getdata(1, 1);
ofstream file; file.open(outputfilename, ios::out | ios::trunc);
set<string> pins; for (uint32_t i = 1; i < maxRow; i++) { string pin = zcsv->getdata(i + 1, 1); string name = zcsv->getdata(i + 1, 2); string direction = zcsv->getdata(i + 1, 3); if (pin.empty() || pin == "N/A") { ZLOGI(TAG, "line %d pin name is empty, skip", i + 1); continue; }
if (pins.find(pin) != pins.end()) { ZLOGE(TAG, "parse pin.csv fail, pin repeat, line num:%d,%s", i + 1, pin.c_str()); return -1; } pins.insert(pin);
if (direction == "INPUT") { file << "define_attribute {p:" << name << "} {PAP_IO_DIRECTION} {INPUT}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_LOC} {" << pin << "}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_VCCIO} {3.3}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_STANDARD} {LVTTL33}" << endl; } else if (direction == "OUTPUT") { file << "define_attribute {p:" << name << "} {PAP_IO_DIRECTION} {OUTPUT}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_LOC} {" << pin << "}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_VCCIO} {3.3}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_STANDARD} {LVCMOS33}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_DRIVE} {4}" << endl; file << "define_attribute {p:" << name << "} {PAP_IO_SLEW} {SLOW}" << endl; } else { ZLOGE(TAG, "parse pin.csv fail, direction error, line num:%d,%s", i + 1, direction.c_str()); return -1; } } file.close();
ZLOGI(TAG, "generator %s success", outputfilename.c_str()); return 0; }
int main(int argc, char const *argv[]) { _main(); while (true) { Sleep(5000); } } #endif
#define TRY_INSERT_DEFALUT_VALUE(key, value) \
if (zcsv->getData(key, i).empty() || zcsv->getData(key, i) == "NA") { \ file << "define_attribute {p:" << name << "} {" << key << "} {" << value << "}" << endl; \ }
char inputfile[128] = {0};
int domain(int argc, char const* argv[]) { if (argc < 2) { // 请输入文件名
cout << "please input file name" << endl; cin >> inputfile; } else { strcpy(inputfile, argv[1]); }
ZLOGI(TAG, "input file:%s", inputfile); shared_ptr<ZCSV> zcsv = make_shared<ZCSV>(); bool suc = zcsv->parseCSV(inputfile); if (!suc) { ZLOGE(TAG, "parse csv failed"); return -1; }
// 去掉.,获取文件名
string outputfilename; string inputfilename = inputfile; size_t pos = inputfilename.find_last_of("."); if (pos == string::npos) { outputfilename = inputfilename; } else { outputfilename = inputfilename.substr(0, pos); }
outputfilename += ".fdc"; map<string, int> colNum;
auto keys = zcsv->getRowKeys();
ofstream file; file.open(outputfilename, ios::out | ios::trunc); int maxRow = zcsv->maxRowNum();
for (uint32_t i = 1; i <= maxRow; i++) { // 检查必要数值
string name = zcsv->getData("NAME", i); string PAP_IO_LOC = zcsv->getData("PAP_IO_LOC", i); string PAP_IO_DIRECTION = zcsv->getData("PAP_IO_DIRECTION", i);
if (name.empty() || name == "NA") { ZLOGE(TAG, "line %d name is empty, skip", i + 1); continue; } if (PAP_IO_LOC.empty() || PAP_IO_LOC == "NA") { ZLOGE(TAG, "line %d PAP_IO_LOC is empty, skip", i + 1); continue; }
if (PAP_IO_DIRECTION.empty()) { ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION is empty", i + 1); return -1; }
// 插入数值
vector<string> keys = zcsv->getRowKeys(); for (auto& key : keys) { if (key == "NAME") continue; if (zcsv->getData(key, i).empty()) continue; if (zcsv->getData(key, i) == "NA") continue; file << "define_attribute {p:" << name << "} {" << key << "} {" << zcsv->getData(key, i) << "}" << endl; }
// // 尝试插入默认值
if (PAP_IO_DIRECTION == "INPUT") { TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3"); TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVTTL33"); } else if (PAP_IO_DIRECTION == "OUTPUT") { TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3"); TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33"); TRY_INSERT_DEFALUT_VALUE("PAP_IO_DRIVE", "4"); TRY_INSERT_DEFALUT_VALUE("PAP_IO_SLEW", "SLOW"); } else { ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION (%s) is error", i + 1, PAP_IO_DIRECTION.c_str()); return -1; } } file.close(); ZLOGI(TAG, "generator %s success", outputfilename.c_str()); return 0; }
int main(int argc, char const* argv[]) { domain(argc, argv); while (true) { Sleep(5000); } }
|