//
Simulink Coder Custom Code Block
Search
Try Notion
Simulink Coder Custom Code Block
C Function
Example: Counter
Simulink Setup
C Code
// In .c File if (zcEvent != NO_ZCEVENT) { /* CFunction: '<S1>/C Function1' */ spi_logger_spi_test_DW.CFunction1_currentCount++; /* MATLABSystem: '<S1>/SPI Master Transfer' incorporates: * CFunction: '<S1>/C Function1' */ MW_SPI_SetSlaveSelect(spi_logger_spi_test_DW.obj.MW_SPI_HANDLE, 0U, true); ClockModeValue = MW_SPI_MODE_0; MsbFirstTransferLoc = MW_SPI_MOST_SIGNIFICANT_BIT_FIRST; rdDataRaw = MW_SPI_SetFormat(spi_logger_spi_test_DW.obj.MW_SPI_HANDLE, 16U, ClockModeValue, MsbFirstTransferLoc); if (rdDataRaw == 0U) { MW_SPI_MasterWriteRead_8bits(spi_logger_spi_test_DW.obj.MW_SPI_HANDLE, &spi_logger_spi_test_DW.CFunction1_currentCount, &rdDataRaw, 1UL); } /* End of MATLABSystem: '<S1>/SPI Master Transfer' */ }
C
// In .h File /* Block states (default storage) for system '<Root>' */ typedef struct { codertarget_tic2000_blocks_SP_T obj; /* '<S1>/SPI Master Transfer' */ int32_T clockTickCounter; /* '<Root>/Pulse Generator' */ int32_T clockTickCounter_h; /* '<Root>/Pulse Generator1' */ uint16_T CFunction1_currentCount; /* '<S1>/C Function1' */ } DW_spi_logger_spi_test_T;
C
Show All