%% Copyright (C) 2013-2015 Czech Technical University in Prague %% %% Authors: %% - Michal Horn %% %% Permission is hereby granted, free of charge, to any person %% obtaining a copy of this software and associated documentation %% files (the "Software"), to deal in the Software without %% restriction, including without limitation the rights to use, %% copy, modify, merge, publish, distribute, sublicense, and/or sell %% copies of the Software, and to permit persons to whom the %% Software is furnished to do so, subject to the following %% conditions: %% The above copyright notice and this permission notice shall be %% included in all copies or substantial portions of the Software. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR %% OTHER DEALINGS IN THE SOFTWARE. %% %% File : sfunction_hydctr_init.tlc %% Abstract: %% TLC file for inlining RPP HYDCTR board init block. %% %% References: %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277 %% Outputs() : refs/rtw_tlc.pdf p. 281 %implements sfunction_hydctr_init "C" %include "common.tlc" %% Function: BlockInstanceSetup ================================================ %function BlockInstanceSetup(block, system) void %if EXISTS("rpp_hydctrinit_in_model") == 0 %assign ::rpp_hydctrinit_in_model = 1 % %else % %endif %endfunction %% Function: BlockTypeSetup ==================================================== %function BlockTypeSetup(block, system) void %% Ensure required header files are included % % % %endfunction %% Function: Start ============================================================= %function Start(block, system) Output %if !SLibCodeGenForSim() %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 %% [EOF]