From: Michal Sojka Date: Thu, 3 Sep 2015 07:51:17 +0000 (+0200) Subject: Update hydctr_init block X-Git-Tag: eaton-0.6~5 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-simulink.git/commitdiff_plain/cb1283e76e77eddb15ad4f670540b1f383d0151e Update hydctr_init block - Add error output - Don't use sci_printf for error reporting - Improve documentation - Change default (example) values --- diff --git a/rpp/blocks/rpp_hydctr_init.slx b/rpp/blocks/rpp_hydctr_init.slx index 814cb9f..a13b74a 100644 Binary files a/rpp/blocks/rpp_hydctr_init.slx and b/rpp/blocks/rpp_hydctr_init.slx differ diff --git a/rpp/blocks/sfunction_hydctr_init.c b/rpp/blocks/sfunction_hydctr_init.c index 5e2b56a..219bea8 100644 --- a/rpp/blocks/sfunction_hydctr_init.c +++ b/rpp/blocks/sfunction_hydctr_init.c @@ -29,6 +29,7 @@ Mnemonic: BINIT Inputs: Outputs: + - { name: "ErrFlag", type: "bool" } Parameters: - { name: "Thermal1 SPI data (MCP6S93):", type: "uint16 vector of length 2" } @@ -48,19 +49,24 @@ Description: &desc | The format of block parameters depends on the SPI chip. The MCP6S93 needs two commands to be properly initialized – channel selection command and gain selection command. Block parameters for those chips - are vector of two 16 bit numbers, for example `[0x4000; 0x4100]`. - Each element of the vector stands for one command. + are vector of two 16 bit numbers, for example `[hex2dec('4000'); + hex2dex('4100')]`. Each element of the vector stands for one + command. For ADC Conditioning, six MCP6S93 are connected in daisy chain. One SPI transfer for these devices is 96 bits long and we need two transfers to fully configure the chips. Block parameter for this is a 2-by-6 matrix of 16 bit numbers. For example `[4000 4000 4000 4000 - 4000 4000; 4100 4100 4100 4100 4100 4100]`. Each row represents one - SPI transfer. + 4000 4000; 4100 4100 4100 4100 4100 4100]` (note: call to `hex2dec` + omitted for brevity). Each row represents one SPI transfer. The TPS65381 chip can be configured by a set of 16 bit commands. The - parameter is a arbitrary length vector of 16 bit numbers, for - example `[1234; 5678; 01010; 02020; 03030; 04040]`. + parameter is an arbitrary length vector of 16 bit numbers, for + example `[hex2dec('0600') hex2dec('0c00') hex2dec('af00') + hex2dec('4800')]`. + + If the initialization is successful, ErrFlag output is false. When + an error occurred, it is set to true. Help: *desc @@ -89,6 +95,11 @@ enum params { PARAM_COUNT }; +enum outputs { + OUT_ERRFLAG_ID, + OUT_COUNT +}; + #define THERMISTOR1_VEC_PARAM(S) ssGetSFcnParam(S, PARAM_THERMISTOR1_ID) #define THERMISTOR2_VEC_PARAM(S) ssGetSFcnParam(S, PARAM_THERMISTOR2_ID) #define ADCS_VEC_PARAM(S) ssGetSFcnParam(S, PARAM_ADC_SCALE_ID) @@ -125,12 +136,14 @@ static void mdlInitializeSizes(SimStruct *S) } /* - * Configure output ports: 0 + * Configure output ports: 1 */ - if (!ssSetNumOutputPorts(S, 0)) { + if (!ssSetNumOutputPorts(S, OUT_COUNT)) { return; } + rppAddOutputPort(S, OUT_ERRFLAG_ID, SS_BOOLEAN); + /* Set standard options for this block */ rppSetStandardOptions(S); } diff --git a/rpp/blocks/tlc_c/sfunction_hydctr_init.tlc b/rpp/blocks/tlc_c/sfunction_hydctr_init.tlc index 82886b8..293b550 100644 --- a/rpp/blocks/tlc_c/sfunction_hydctr_init.tlc +++ b/rpp/blocks/tlc_c/sfunction_hydctr_init.tlc @@ -26,7 +26,7 @@ %function BlockInstanceSetup(block, system) void %if EXISTS("rpp_hydctrinit_in_model") == 0 %assign ::rpp_hydctrinit_in_model = 1 - % + % %else % %endif @@ -47,38 +47,40 @@ %if !SLibCodeGenForSim() - #define SPI_TX_ERR() do { \ - rpp_sci_printk("ERROR: SPI transmission failed.\r\n"); \ - while (1); \ - } while(0) - - - /% Single-value devices %/ - %assign dev_id = ["SPIDEV_MCP6S93_TH1", "SPIDEV_MCP6S93_TH2", "SPIDEV_TPS65381_PWR", "SPIDEV_MCP6S93_SENSUP", "SPIDEV_MCP6S93_DAC"] - %assign par_name = ["thermistor1", "thermistor2", "powersupply", "sensorsupply", "dacloopback"] - - %foreach dev = SIZE(dev_id, 1) - %assign count = LibBlockParameterWidth(%) - %foreach idx = count - %assign val = LibBlockParameterValue(%, idx) - if (rpp_spi_transfer16(%, %, NULL) != SUCCESS) - SPI_TX_ERR(); - %endforeach - %endforeach - - /% Daisy chained device %/ - %assign size = LibBlockParameterDimensions(adcs) - %foreach command = size[0] - { - uint16_t data[%] = { - %foreach data = size[1] - cpu_to_be16(%), - %endforeach - }; - if (rpp_spi_transfer(SPIDEV_MCP6S93_6ADC, sizeof(data), &data, NULL) != SUCCESS) - SPI_TX_ERR(); - } + %assign err_flag = LibBlockOutputSignal(0, "", "", 0) + + rpp_spi_init(); + { + boolean_t err = FALSE; + uint16_t rx; + + /% Single-value devices %/ + %assign dev_id = ["SPIDEV_MCP6S93_TH1", "SPIDEV_MCP6S93_TH2", "SPIDEV_TPS65381_PWR", "SPIDEV_MCP6S93_SENSUP", "SPIDEV_MCP6S93_DAC"] + %assign par_name = ["thermistor1", "thermistor2", "powersupply", "sensorsupply", "dacloopback"] + + %foreach dev = SIZE(dev_id, 1) + %assign count = LibBlockParameterWidth(%) + %foreach idx = count + %assign val = LibBlockParameterValue(%, idx) + err |= (rpp_spi_transfer16(%, %, &rx) != SUCCESS); + %%rpp_sci_printf("% % -> 0x%04x\n", rx); + %endforeach + %endforeach + + /% Daisy chained device %/ + %assign size = LibBlockParameterDimensions(adcs) + %foreach command = size[0] + { + uint16_t data[%] = { + %foreach data = size[1] + cpu_to_be16(%), + %endforeach + }; + err |= (rpp_spi_transfer(SPIDEV_MCP6S93_6ADC, sizeof(data), &data, NULL) != SUCCESS); + } %endforeach + % = err; + } %endif %endfunction diff --git a/rpp/demos/board_init_hydctr.slx b/rpp/demos/board_init_hydctr.slx index decda7b..cf48535 100644 Binary files a/rpp/demos/board_init_hydctr.slx and b/rpp/demos/board_init_hydctr.slx differ