@@ -277,7 +277,16 @@ static uint32_t SAI_GetInstance(I2S_Type *base)
277
277
}
278
278
}
279
279
280
- assert (instance < ARRAY_SIZE (s_saiBases ));
280
+ if (instance == ARRAY_SIZE (s_saiBases )) {
281
+ assert (false);
282
+ /* asserts may not always be enabled. As such, return NULL here to
283
+ * avoid compilation warnings complaining about a possible out-of-bounds
284
+ * access. If the user decides to disable the asserts, it is up to them
285
+ * to debug in case of out-of-bounds access as SAI_GetInstance() will
286
+ * return a valid instance.
287
+ */
288
+ return 0 ;
289
+ }
281
290
282
291
return instance ;
283
292
}
@@ -940,8 +949,8 @@ void SAI_TxSetFifoConfig(I2S_Type *base, sai_fifo_t *config)
940
949
{
941
950
assert (config != NULL );
942
951
#if defined(FSL_FEATURE_SAI_HAS_FIFO ) && (FSL_FEATURE_SAI_HAS_FIFO )
943
- if (( config -> fifoWatermark == 0U ) ||
944
- ( config -> fifoWatermark > ( uint8_t )(( uint32_t ) FSL_FEATURE_SAI_FIFO_COUNTn ( base )) ))
952
+ if (config -> fifoWatermark > ( uint8_t )(( uint32_t ) FSL_FEATURE_SAI_FIFO_COUNTn ( base ) ) ||
953
+ (! MCUX_SDK_SAI_ALLOW_NULL_FIFO_WATERMARK && config -> fifoWatermark == 0U ))
945
954
{
946
955
config -> fifoWatermark = (uint8_t )((uint32_t )FSL_FEATURE_SAI_FIFO_COUNTn (base ) / 2U );
947
956
}
@@ -986,8 +995,8 @@ void SAI_RxSetFifoConfig(I2S_Type *base, sai_fifo_t *config)
986
995
{
987
996
assert (config != NULL );
988
997
#if defined(FSL_FEATURE_SAI_HAS_FIFO ) && (FSL_FEATURE_SAI_HAS_FIFO )
989
- if (( config -> fifoWatermark == 0U ) ||
990
- ( config -> fifoWatermark > ( uint8_t )(( uint32_t ) FSL_FEATURE_SAI_FIFO_COUNTn ( base )) ))
998
+ if (config -> fifoWatermark > ( uint8_t )(( uint32_t ) FSL_FEATURE_SAI_FIFO_COUNTn ( base ) ) ||
999
+ (! MCUX_SDK_SAI_ALLOW_NULL_FIFO_WATERMARK && config -> fifoWatermark == 0U ))
991
1000
{
992
1001
config -> fifoWatermark = (uint8_t )((uint32_t )FSL_FEATURE_SAI_FIFO_COUNTn (base ) / 2U );
993
1002
}
@@ -1131,24 +1140,15 @@ void SAI_RxSetSerialDataConfig(I2S_Type *base, sai_serial_data_t *config)
1131
1140
base -> RCR4 = rcr4 ;
1132
1141
}
1133
1142
1134
- /*!
1135
- * brief SAI transmitter configurations.
1136
- *
1137
- * param base SAI base pointer.
1138
- * param config transmitter configurations.
1139
- */
1140
- void SAI_TxSetConfig (I2S_Type * base , sai_transceiver_t * config )
1143
+ #if !MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG
1144
+ static void SAI_ComputeChannelConfig (I2S_Type * base , sai_transceiver_t * config )
1141
1145
{
1142
1146
assert (config != NULL );
1143
1147
assert (FSL_FEATURE_SAI_CHANNEL_COUNTn (base ) != -1 );
1144
1148
1145
1149
uint8_t i = 0U ;
1146
- uint32_t val = 0U ;
1147
1150
uint8_t channelNums = 0U ;
1148
1151
1149
- /* reset transmitter */
1150
- SAI_TxReset (base );
1151
-
1152
1152
/* if channel mask is not set, then format->channel must be set,
1153
1153
use it to get channel mask value */
1154
1154
if (config -> channelMask == 0U )
@@ -1175,6 +1175,35 @@ void SAI_TxSetConfig(I2S_Type *base, sai_transceiver_t *config)
1175
1175
}
1176
1176
1177
1177
config -> channelNums = channelNums ;
1178
+ }
1179
+ #endif /* MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG */
1180
+
1181
+ /*!
1182
+ * brief SAI transmitter configurations.
1183
+ *
1184
+ * param base SAI base pointer.
1185
+ * param config transmitter configurations.
1186
+ */
1187
+ void SAI_TxSetConfig (I2S_Type * base , sai_transceiver_t * config )
1188
+ {
1189
+ uint32_t val = 0U ;
1190
+
1191
+ /* reset transmitter */
1192
+ SAI_TxReset (base );
1193
+
1194
+ #if !MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG
1195
+ /* sometimes, the user of the SAI driver may want to
1196
+ * set the channel configuration (i.e: the startChannel,
1197
+ * channelMask, endChannel, and channelNums fields of
1198
+ * sai_transceiver_t) before calling SAI_TxSetConfig().
1199
+ * As such, if the user wants to do this, they can define
1200
+ * FSL_FEATURE_SAI_DISABLE_IMPLICIT_CHAN_CONFIG which will
1201
+ * stop SAI_TxSetConfig() from implicitly computing those
1202
+ * values.
1203
+ */
1204
+ SAI_ComputeChannelConfig (base , config );
1205
+ #endif /* MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG */
1206
+
1178
1207
#if defined(FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE ) && (FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE )
1179
1208
/* make sure combine mode disabled while multipe channel is used */
1180
1209
if (config -> channelNums > 1U )
@@ -1273,42 +1302,24 @@ void SAI_TransferTxSetConfig(I2S_Type *base, sai_handle_t *handle, sai_transceiv
1273
1302
*/
1274
1303
void SAI_RxSetConfig (I2S_Type * base , sai_transceiver_t * config )
1275
1304
{
1276
- assert (config != NULL );
1277
- assert (FSL_FEATURE_SAI_CHANNEL_COUNTn (base ) != -1 );
1278
-
1279
- uint8_t i = 0U ;
1280
- uint32_t val = 0U ;
1281
- uint8_t channelNums = 0U ;
1305
+ uint32_t val = 0U ;
1282
1306
1283
1307
/* reset receiver */
1284
1308
SAI_RxReset (base );
1285
1309
1286
- /* if channel mask is not set, then format->channel must be set,
1287
- use it to get channel mask value */
1288
- if (config -> channelMask == 0U )
1289
- {
1290
- config -> channelMask = 1U << config -> startChannel ;
1291
- }
1292
-
1293
- for (i = 0U ; i < (uint32_t )FSL_FEATURE_SAI_CHANNEL_COUNTn (base ); i ++ )
1294
- {
1295
- if (IS_SAI_FLAG_SET ((1UL << i ), config -> channelMask ))
1296
- {
1297
- channelNums ++ ;
1298
- config -> endChannel = i ;
1299
- }
1300
- }
1301
-
1302
- for (i = 0U ; i < (uint32_t )FSL_FEATURE_SAI_CHANNEL_COUNTn (base ); i ++ )
1303
- {
1304
- if (IS_SAI_FLAG_SET ((1UL << i ), config -> channelMask ))
1305
- {
1306
- config -> startChannel = i ;
1307
- break ;
1308
- }
1309
- }
1310
+ #if !MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG
1311
+ /* sometimes, the user of the SAI driver may want to
1312
+ * set the channel configuration (i.e: the startChannel,
1313
+ * channelMask, endChannel, and channelNums fields of
1314
+ * sai_transceiver_t) before calling SAI_RxSetConfig().
1315
+ * As such, if the user wants to do this, they can define
1316
+ * FSL_FEATURE_SAI_DISABLE_IMPLICIT_CHAN_CONFIG which will
1317
+ * stop SAI_RxSetConfig() from implicitly computing those
1318
+ * values.
1319
+ */
1320
+ SAI_ComputeChannelConfig (base , config );
1321
+ #endif /* MCUX_SDK_SAI_DISABLE_IMPLICIT_CHAN_CONFIG */
1310
1322
1311
- config -> channelNums = channelNums ;
1312
1323
#if defined(FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE ) && (FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE )
1313
1324
/* make sure combine mode disabled while multipe channel is used */
1314
1325
if (config -> channelNums > 1U )
0 commit comments