]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/commitdiff
Update hydctr_init block
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 3 Sep 2015 07:51:17 +0000 (09:51 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 3 Sep 2015 10:57:50 +0000 (12:57 +0200)
- Add error output
- Don't use sci_printf for error reporting
- Improve documentation
- Change default (example) values

rpp/blocks/rpp_hydctr_init.slx
rpp/blocks/sfunction_hydctr_init.c
rpp/blocks/tlc_c/sfunction_hydctr_init.tlc
rpp/demos/board_init_hydctr.slx

index 814cb9f402551dac85fd306f87628412793ae191..a13b74a68b2abb036179c85385f22e0f37aebead 100644 (file)
Binary files a/rpp/blocks/rpp_hydctr_init.slx and b/rpp/blocks/rpp_hydctr_init.slx differ
index 5e2b56ab95a3ec0a3af043f0a488d344385556d7..219bea8f174348cf0e3efe4da5ae868e564e4790 100644 (file)
@@ -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);
 }
index 82886b8e142a373999a0f7fdf6867fe0dfda1bf5..293b550f3b51daedab9bf5958eb80b0df2375cf4 100644 (file)
@@ -26,7 +26,7 @@
 %function BlockInstanceSetup(block, system) void
     %if EXISTS("rpp_hydctrinit_in_model") == 0
         %assign ::rpp_hydctrinit_in_model = 1
-        %<LibAddToCommonIncludes("drv/drv.h")>
+        %<LibAddToCommonIncludes("rpp/spi.h")>
     %else
         %<LibBlockReportError(block, "Only one Board Init block is allowed in the model.")>
     %endif
 
     %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(%<par_name[dev]>)
-          %foreach idx = count
-                %assign val = LibBlockParameterValue(%<par_name[dev]>, idx)
-                if (rpp_spi_transfer16(%<dev_id[dev]>, %<val>, NULL) != SUCCESS)
-                    SPI_TX_ERR();
-            %endforeach
-        %endforeach
-
-        /% Daisy chained device %/
-        %assign size = LibBlockParameterDimensions(adcs)
-        %foreach command = size[0]
-            {
-              uint16_t data[%<size[1]>] = {
-                %foreach data = size[1]
-                  cpu_to_be16(%<LibBlockParameterValue(adcs, size[0]*data + command)>),
-                %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(%<par_name[dev]>)
+             %foreach idx = count
+               %assign val = LibBlockParameterValue(%<par_name[dev]>, idx)
+               err |= (rpp_spi_transfer16(%<dev_id[dev]>, %<val>, &rx) != SUCCESS);
+               %%rpp_sci_printf("%<dev_id[dev]> %<val> -> 0x%04x\n", rx);
+             %endforeach
+           %endforeach
+
+           /% Daisy chained device %/
+            %assign size = LibBlockParameterDimensions(adcs)
+            %foreach command = size[0]
+              {
+                uint16_t data[%<size[1]>] = {
+                  %foreach data = size[1]
+                    cpu_to_be16(%<LibBlockParameterValue(adcs, size[0]*data + command)>),
+                  %endforeach
+                };
+                err |= (rpp_spi_transfer(SPIDEV_MCP6S93_6ADC, sizeof(data), &data, NULL) != SUCCESS);
+              }
         %endforeach
+        %<err_flag> = err;
+      }
     %endif
 
 %endfunction
index decda7b1ee8534f7254544d4b1b1fc606de6489e..cf485350e0d83277fe1ac68d1c7122d216857b98 100644 (file)
Binary files a/rpp/demos/board_init_hydctr.slx and b/rpp/demos/board_init_hydctr.slx differ