You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
6.0 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <set>
  4. #include "logger.hpp"
  5. #include "zcsv.hpp"
  6. using namespace iflytop;
  7. using namespace std;
  8. #define TAG "Main"
  9. #if 0
  10. /**
  11. * @brief
  12. *
  13. *
  14. * FPGA_PIN, DIRECTION, NAME
  15. * B5 INPUT ex_clk
  16. * E2 OUTPUT core_board_debug_led
  17. *
  18. *
  19. *
  20. * define_attribute {p:ex_clk} {PAP_IO_DIRECTION} {INPUT}
  21. * define_attribute {p:ex_clk} {PAP_IO_LOC} {B5}
  22. * define_attribute {p:ex_clk} {PAP_IO_VCCIO} {3.3}
  23. * define_attribute {p:ex_clk} {PAP_IO_STANDARD} {LVTTL33}
  24. *
  25. * define_attribute{p : core_board_debug_led } { PAP_IO_DIRECTION } { OUTPUT }
  26. * define_attribute{p : core_board_debug_led } {PAP_IO_LOC } {E2 }
  27. * define_attribute{p : core_board_debug_led } {PAP_IO_VCCIO } {3.3 }
  28. * define_attribute{p : core_board_debug_led } {PAP_IO_STANDARD } {LVCMOS33 }
  29. * define_attribute{p : core_board_debug_led } {PAP_IO_DRIVE } {4 }
  30. * define_attribute{p : core_board_debug_led } {PAP_IO_SLEW } {SLOW }
  31. *
  32. *
  33. */
  34. int _main() {
  35. shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
  36. bool suc = zcsv->parseCSV("pin.csv");
  37. if (!suc) {
  38. ZLOGE(TAG, "parse csv failed");
  39. return -1;
  40. }
  41. // string pinnum;
  42. int maxRow = zcsv->maxRowNum();
  43. string outputfilename;
  44. outputfilename = zcsv->getdata(1, 1);
  45. ofstream file;
  46. file.open(outputfilename, ios::out | ios::trunc);
  47. set<string> pins;
  48. for (uint32_t i = 1; i < maxRow; i++) {
  49. string pin = zcsv->getdata(i + 1, 1);
  50. string name = zcsv->getdata(i + 1, 2);
  51. string direction = zcsv->getdata(i + 1, 3);
  52. if (pin.empty() || pin == "N/A") {
  53. ZLOGI(TAG, "line %d pin name is empty, skip", i + 1);
  54. continue;
  55. }
  56. if (pins.find(pin) != pins.end()) {
  57. ZLOGE(TAG, "parse pin.csv fail, pin repeat, line num:%d,%s", i + 1, pin.c_str());
  58. return -1;
  59. }
  60. pins.insert(pin);
  61. if (direction == "INPUT") {
  62. file << "define_attribute {p:" << name << "} {PAP_IO_DIRECTION} {INPUT}" << endl;
  63. file << "define_attribute {p:" << name << "} {PAP_IO_LOC} {" << pin << "}" << endl;
  64. file << "define_attribute {p:" << name << "} {PAP_IO_VCCIO} {3.3}" << endl;
  65. file << "define_attribute {p:" << name << "} {PAP_IO_STANDARD} {LVTTL33}" << endl;
  66. } else if (direction == "OUTPUT") {
  67. file << "define_attribute {p:" << name << "} {PAP_IO_DIRECTION} {OUTPUT}" << endl;
  68. file << "define_attribute {p:" << name << "} {PAP_IO_LOC} {" << pin << "}" << endl;
  69. file << "define_attribute {p:" << name << "} {PAP_IO_VCCIO} {3.3}" << endl;
  70. file << "define_attribute {p:" << name << "} {PAP_IO_STANDARD} {LVCMOS33}" << endl;
  71. file << "define_attribute {p:" << name << "} {PAP_IO_DRIVE} {4}" << endl;
  72. file << "define_attribute {p:" << name << "} {PAP_IO_SLEW} {SLOW}" << endl;
  73. } else {
  74. ZLOGE(TAG, "parse pin.csv fail, direction error, line num:%d,%s", i + 1, direction.c_str());
  75. return -1;
  76. }
  77. }
  78. file.close();
  79. ZLOGI(TAG, "generator %s success", outputfilename.c_str());
  80. return 0;
  81. }
  82. int main(int argc, char const *argv[]) {
  83. _main();
  84. while (true) {
  85. Sleep(5000);
  86. }
  87. }
  88. #endif
  89. #define TRY_INSERT_DEFALUT_VALUE(key, value) \
  90. if (zcsv->getData(key, i).empty() || zcsv->getData(key, i) == "NA") { \
  91. file << "define_attribute {p:" << name << "} {" << key << "} {" << value << "}" << endl; \
  92. }
  93. char inputfile[128] = {0};
  94. int domain(int argc, char const* argv[]) {
  95. if (argc < 2) {
  96. // 请输入文件名
  97. cout << "please input file name" << endl;
  98. cin >> inputfile;
  99. } else {
  100. strcpy(inputfile, argv[1]);
  101. }
  102. ZLOGI(TAG, "input file:%s", inputfile);
  103. shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
  104. bool suc = zcsv->parseCSV(inputfile);
  105. if (!suc) {
  106. ZLOGE(TAG, "parse csv failed");
  107. return -1;
  108. }
  109. // 去掉.,获取文件名
  110. string outputfilename;
  111. string inputfilename = inputfile;
  112. size_t pos = inputfilename.find_last_of(".");
  113. if (pos == string::npos) {
  114. outputfilename = inputfilename;
  115. } else {
  116. outputfilename = inputfilename.substr(0, pos);
  117. }
  118. outputfilename += ".fdc";
  119. map<string, int> colNum;
  120. auto keys = zcsv->getRowKeys();
  121. ofstream file;
  122. file.open(outputfilename, ios::out | ios::trunc);
  123. int maxRow = zcsv->maxRowNum();
  124. for (uint32_t i = 1; i <= maxRow; i++) {
  125. // 检查必要数值
  126. string name = zcsv->getData("NAME", i);
  127. string PAP_IO_LOC = zcsv->getData("PAP_IO_LOC", i);
  128. string PAP_IO_DIRECTION = zcsv->getData("PAP_IO_DIRECTION", i);
  129. if (name.empty() || name == "NA") {
  130. ZLOGE(TAG, "line %d name is empty, skip", i + 1);
  131. continue;
  132. }
  133. if (PAP_IO_LOC.empty() || PAP_IO_LOC == "NA") {
  134. ZLOGE(TAG, "line %d PAP_IO_LOC is empty, skip", i + 1);
  135. continue;
  136. }
  137. if (PAP_IO_DIRECTION.empty()) {
  138. ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION is empty", i + 1);
  139. return -1;
  140. }
  141. // 插入数值
  142. vector<string> keys = zcsv->getRowKeys();
  143. for (auto& key : keys) {
  144. if (key == "NAME") continue;
  145. if (zcsv->getData(key, i).empty()) continue;
  146. if (zcsv->getData(key, i) == "NA") continue;
  147. file << "define_attribute {p:" << name << "} {" << key << "} {" << zcsv->getData(key, i) << "}" << endl;
  148. }
  149. // // 尝试插入默认值
  150. if (PAP_IO_DIRECTION == "INPUT") {
  151. TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
  152. TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVTTL33");
  153. } else if (PAP_IO_DIRECTION == "OUTPUT") {
  154. TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
  155. TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33");
  156. TRY_INSERT_DEFALUT_VALUE("PAP_IO_DRIVE", "4");
  157. TRY_INSERT_DEFALUT_VALUE("PAP_IO_SLEW", "SLOW");
  158. } else {
  159. ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION (%s) is error", i + 1, PAP_IO_DIRECTION.c_str());
  160. return -1;
  161. }
  162. }
  163. file.close();
  164. ZLOGI(TAG, "generator %s success", outputfilename.c_str());
  165. return 0;
  166. }
  167. int main(int argc, char const* argv[]) {
  168. domain(argc, argv);
  169. while (true) {
  170. Sleep(5000);
  171. }
  172. }