@@ -85,6 +85,7 @@ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeTransfer(
85
85
int16_t readOffset = 0 ;
86
86
int16_t writeOffset = 0 ;
87
87
SPI_WRITE_READ_SETTINGS rws;
88
+ uint32_t deviceId;
88
89
89
90
bool isLongRunningOperation;
90
91
uint32_t estimatedDurationMiliseconds;
@@ -98,8 +99,7 @@ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeTransfer(
98
99
FAULT_ON_NULL (pThis);
99
100
100
101
// get device handle saved on open
101
- uint32_t deviceId =
102
- pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___deviceId].NumericByRef ().u4 ;
102
+ deviceId = pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___deviceId].NumericByRef ().u4 ;
103
103
104
104
if (stack.m_customState == 0 )
105
105
{
@@ -186,6 +186,7 @@ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeTransfer(
186
186
readSize = 0 ;
187
187
}
188
188
}
189
+
189
190
// Are we using SPI full-duplex for transfer ?
190
191
bool fullDuplex = (bool )stack.Arg3 ().NumericByRef ().u1 ;
191
192
@@ -280,95 +281,95 @@ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeTransfer(
280
281
281
282
// null pointers and vars
282
283
pThis = NULL ;
284
+ }
283
285
284
- NANOCLR_CLEANUP ();
286
+ NANOCLR_CLEANUP ();
285
287
286
- if (hr != CLR_E_THREAD_WAITING)
288
+ if (hr != CLR_E_THREAD_WAITING)
289
+ {
290
+ // unpin buffers
291
+ if (writeBuffer != NULL && writeBuffer->IsPinned ())
287
292
{
288
- // unpin buffers
289
- if (writeBuffer != NULL && writeBuffer->IsPinned ())
290
- {
291
- writeBuffer->Unpin ();
292
- }
293
+ writeBuffer->Unpin ();
294
+ }
293
295
294
- if (readBuffer != NULL && readBuffer->IsPinned ())
295
- {
296
- readBuffer->Unpin ();
297
- }
296
+ if (readBuffer != NULL && readBuffer->IsPinned ())
297
+ {
298
+ readBuffer->Unpin ();
298
299
}
299
300
}
301
+ }
300
302
301
- HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeOpenDevice___I4 (CLR_RT_StackFrame & stack)
302
- {
303
- NANOCLR_HEADER ();
303
+ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeOpenDevice___I4 (CLR_RT_StackFrame &stack)
304
+ {
305
+ NANOCLR_HEADER ();
304
306
305
- uint32_t handle = -1 ;
306
- SPI_DEVICE_CONFIGURATION spiConfig;
307
- CLR_RT_HeapBlock *config = NULL ;
307
+ uint32_t handle = -1 ;
308
+ SPI_DEVICE_CONFIGURATION spiConfig;
309
+ CLR_RT_HeapBlock *config = NULL ;
308
310
309
- // get a pointer to the managed object instance and check that it's not NULL
310
- CLR_RT_HeapBlock *pThis = stack.This ();
311
- FAULT_ON_NULL (pThis);
311
+ // get a pointer to the managed object instance and check that it's not NULL
312
+ CLR_RT_HeapBlock *pThis = stack.This ();
313
+ FAULT_ON_NULL (pThis);
312
314
313
- // Get reference to manage code SPI settings
314
- config =
315
- pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___connectionSettings].Dereference ();
315
+ // Get reference to manage code SPI settings
316
+ config = pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___connectionSettings].Dereference ();
316
317
317
- spiConfig.BusMode = SpiBusMode_master;
318
- spiConfig.DataIs16bits = false ;
318
+ spiConfig.BusMode = SpiBusMode_master;
319
+ spiConfig.DataIs16bits = false ;
319
320
320
- // internally SPI bus ID is zero based, so better take care of that here
321
- spiConfig.Spi_Bus = config[SpiConnectionSettings::FIELD___busId].NumericByRef ().s4 - 1 ;
321
+ // internally SPI bus ID is zero based, so better take care of that here
322
+ spiConfig.Spi_Bus = config[SpiConnectionSettings::FIELD___busId].NumericByRef ().s4 - 1 ;
322
323
323
- spiConfig.DeviceChipSelect = config[SpiConnectionSettings::FIELD___csLine].NumericByRef ().s4 ;
324
+ spiConfig.DeviceChipSelect = config[SpiConnectionSettings::FIELD___csLine].NumericByRef ().s4 ;
324
325
325
- // sanity check chip select line
326
- if (spiConfig.DeviceChipSelect < -1 )
327
- {
328
- NANOCLR_SET_AND_LEAVE (CLR_E_INVALID_PARAMETER);
329
- }
326
+ // sanity check chip select line
327
+ if (spiConfig.DeviceChipSelect < -1 )
328
+ {
329
+ NANOCLR_SET_AND_LEAVE (CLR_E_INVALID_PARAMETER);
330
+ }
330
331
331
- // load CS active state from config (which is always PinValue.Low or PinValue.High
332
- spiConfig.ChipSelectActiveState =
333
- (bool )config[SpiConnectionSettings::FIELD___chipSelectLineActiveState].NumericByRef ().s4 ;
332
+ // load CS active state from config (which is always PinValue.Low or PinValue.High
333
+ spiConfig.ChipSelectActiveState =
334
+ (bool )config[SpiConnectionSettings::FIELD___chipSelectLineActiveState].NumericByRef ().s4 ;
334
335
335
- spiConfig.Spi_Mode = (SpiMode)config[SpiConnectionSettings::FIELD___spiMode].NumericByRef ().s4 ;
336
- spiConfig.DataOrder16 = (DataBitOrder)config[SpiConnectionSettings::FIELD___dataFlow].NumericByRef ().s4 ;
337
- spiConfig.Clock_RateHz = config[SpiConnectionSettings::FIELD___clockFrequency].NumericByRef ().s4 ;
338
- spiConfig.BusConfiguration =
339
- (SpiBusConfiguration)config[SpiConnectionSettings::FIELD___busConfiguration].NumericByRef ().s4 ;
336
+ spiConfig.Spi_Mode = (SpiMode)config[SpiConnectionSettings::FIELD___spiMode].NumericByRef ().s4 ;
337
+ spiConfig.DataOrder16 = (DataBitOrder)config[SpiConnectionSettings::FIELD___dataFlow].NumericByRef ().s4 ;
338
+ spiConfig.Clock_RateHz = config[SpiConnectionSettings::FIELD___clockFrequency].NumericByRef ().s4 ;
339
+ spiConfig.BusConfiguration =
340
+ (SpiBusConfiguration)config[SpiConnectionSettings::FIELD___busConfiguration].NumericByRef ().s4 ;
340
341
341
- // Returns handle to device
342
- hr = nanoSPI_OpenDevice (spiConfig, handle);
343
- NANOCLR_CHECK_HRESULT (hr);
342
+ // Returns handle to device
343
+ hr = nanoSPI_OpenDevice (spiConfig, handle);
344
+ NANOCLR_CHECK_HRESULT (hr);
344
345
345
- // Return device handle
346
- stack.SetResult_I4 (handle);
346
+ // Return device handle
347
+ stack.SetResult_I4 (handle);
347
348
348
- NANOCLR_NOCLEANUP ();
349
- }
349
+ NANOCLR_NOCLEANUP ();
350
+ }
350
351
351
- HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeInit___VOID (CLR_RT_StackFrame & stack)
352
+ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::NativeInit___VOID (CLR_RT_StackFrame &stack)
353
+ {
354
+ NANOCLR_HEADER ();
352
355
{
353
- NANOCLR_HEADER ();
354
- {
355
- (void )stack;
356
- }
357
- NANOCLR_NOCLEANUP_NOLABEL ();
356
+ (void )stack;
358
357
}
358
+ NANOCLR_NOCLEANUP_NOLABEL ();
359
+ }
359
360
360
- HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::DisposeNative___VOID (CLR_RT_StackFrame & stack)
361
+ HRESULT Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::DisposeNative___VOID (CLR_RT_StackFrame &stack)
362
+ {
363
+ NANOCLR_HEADER ();
361
364
{
362
- NANOCLR_HEADER ();
363
- {
364
- // get a pointer to the managed object instance and check that it's not NULL
365
- CLR_RT_HeapBlock *pThis = stack.This ();
365
+ // get a pointer to the managed object instance and check that it's not NULL
366
+ CLR_RT_HeapBlock *pThis = stack.This ();
366
367
367
- // get device handle
368
- int32_t deviceId =
369
- pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___deviceId].NumericByRef ().s4 ;
368
+ // get device handle
369
+ int32_t deviceId =
370
+ pThis[Library_sys_dev_spi_native_System_Device_Spi_SpiDevice::FIELD___deviceId].NumericByRef ().s4 ;
370
371
371
- nanoSPI_CloseDevice (deviceId);
372
- }
373
- NANOCLR_NOCLEANUP_NOLABEL ();
372
+ nanoSPI_CloseDevice (deviceId);
374
373
}
374
+ NANOCLR_NOCLEANUP_NOLABEL ();
375
+ }
0 commit comments