static void mdlSetWorkWidths(SimStruct *S)
{
/* Set number of run-time parameters */
- if(!ssSetNumRunTimeParams(S, 1)) {
+ if(!ssSetNumRunTimeParams(S, 2)) {
return;
}
%assign pin_num = LibBlockParameterValue(p1, 0)
rpp_aout_setup(%<pin_num>, TRUE);
rpp_aout_set(%<pin_num>, 0);
- rpp_aout_update();
+ /*
+ * Warning! This should be the correct way to initialize AOUT.
+ * Nevertheless rpp_aout_update() has a known bug that if it is called
+ * before starting the FreeRTOS Scheduler the application will freeze.
+ * Check the RPP API documentation for more information.
+ * Not updating now is harmless though.
+ */
+ /* rpp_aout_update(); */
%endif
%endfunction
/**
* Set output to given voltage.
*
- * Helper functions that calculates DAC value given a voltage in millivolts.
+ * Helper function that calculates DAC value given a voltage in millivolts.
*
* @param[in] pin The pin number to set [1-4].
* @param[in] mv Voltage level in mV to be set on specified pin [0-12000].
/**
- * Flush cached output values.
+ * Flush cached output values and configuration changes.
+ *
+ * @bug This function should be called only after the FreeRTOS Scheduler has
+ * started (which implies from a FreeRTOS Task). If called before starting the
+ * scheduler, like for library initialization, or application DAC
+ * initialization, the application will freeze. The cause of this is unknown at
+ * the moment.
*
* @return SUCCESS when transaction was successful.\n
* FAILURE if transaction could not be confirmed.
// Map value
val = map(val, 0, 4095, 0, dac_top);
-
// Check value range
- if(pin > 4095) {
+ if(val > 4095) {
return -2;
}