From a1d635889cd7d836f6707ba84ce5572485ba93b7 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Wed, 19 Jun 2019 18:32:59 +0200 Subject: [PATCH] Clean up --- sw/kousaten/src/fpga_cell.c | 12 +++++++++++- sw/kousaten/src/fpga_global.c | 5 +++++ sw/kousaten/src/fpga_global.h | 2 ++ sw/kousaten/src/main.c | 7 ++----- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/sw/kousaten/src/fpga_cell.c b/sw/kousaten/src/fpga_cell.c index ded54cf..871d9d7 100644 --- a/sw/kousaten/src/fpga_cell.c +++ b/sw/kousaten/src/fpga_cell.c @@ -191,10 +191,19 @@ struct fpga_chain *fpga_isp_chain_new(struct fpga_cell *entry) report(LL_INFO, "Generating ISP chain..."); + if (entry->type->identifier != 'P') { + report(LL_CRITICAL, + "Entry cell must be of type P, was '%c'", + entry->type->identifier); + errno = EINVAL; + return NULL; + } + chain = calloc(sizeof (struct fpga_chain), 1); if (!chain) { report (LL_CRITICAL, "Out of memory during ISP chain generation."); + errno = ENOMEM; return NULL; } @@ -226,6 +235,7 @@ struct fpga_chain *fpga_isp_chain_new(struct fpga_cell *entry) ¤t_channel); if (current_channel == FPGA_ISP_CHANNEL_ERROR) { /* TODO: Clean up memory */ + errno = ETYPE; return NULL; } } @@ -241,7 +251,7 @@ struct fpga_chain *fpga_isp_chain_new(struct fpga_cell *entry) } report(LL_INFO, - "ISP chain generated finished."); + "ISP chain generation finished."); return chain; } diff --git a/sw/kousaten/src/fpga_global.c b/sw/kousaten/src/fpga_global.c index 18b9e1a..c580005 100644 --- a/sw/kousaten/src/fpga_global.c +++ b/sw/kousaten/src/fpga_global.c @@ -31,3 +31,8 @@ enum log_level report(enum log_level log_level, const char *format, ...) return log_level; } + +void set_log_level(enum log_level log_level) +{ + current_log_level = log_level; +} diff --git a/sw/kousaten/src/fpga_global.h b/sw/kousaten/src/fpga_global.h index b268ee5..66e8b59 100644 --- a/sw/kousaten/src/fpga_global.h +++ b/sw/kousaten/src/fpga_global.h @@ -10,8 +10,10 @@ enum log_level {LL_CRITICAL = 0, LL_DEBUG, LL_COUNT}; enum log_level report(enum log_level log_level, const char *format, ...); +void set_log_level(enum log_level log_level); /* Error codes */ #define ECONN 1000 /* Tried to connect to already connected port */ +#define ETYPE 1001 /* Tried an operation on a cell that does not support it */ #endif // FPGA_GLOBAL_H diff --git a/sw/kousaten/src/main.c b/sw/kousaten/src/main.c index 46a8cb8..18e692d 100644 --- a/sw/kousaten/src/main.c +++ b/sw/kousaten/src/main.c @@ -11,6 +11,8 @@ int development_test_main(int argc, char *argv[]) { struct fpga_cell *entry_cell; + set_log_level(LL_DEBUG); + entry_cell = fpga_fdef_loader_load("fdef/4x4.fdef"); if (!entry_cell) { @@ -18,11 +20,6 @@ int development_test_main(int argc, char *argv[]) return E_FDEF; } -// if (entry_cell->type != FPGA_CELL_PROG) { -// report(LL_CRITICAL, "Entry cell must be of type P."); -// return E_FDEF; -// } - report(LL_INFO, "FDEF loaded."); if (!fpga_isp_chain_new(entry_cell)) {