Revision 5ab6a6a4 periphery-lld/periphAL.h

View differences:

periphery-lld/periphAL.h
343 343
  aosDbgCheck(i2cd != NULL);
344 344

  
345 345
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
346
  i2cAcquireBus(i2cd);
346
  // check whether the I2C driver was locked externally
347
  const bool i2cd_locked_external = i2cd->mutex.owner == currp;
348
  if (!i2cd_locked_external) {
349
    i2cAcquireBus(i2cd);
350
  }
347 351
#endif
348 352

  
349 353
#pragma GCC diagnostic push
......
364 368
#pragma GCC diagnostic pop
365 369

  
366 370
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
367
  i2cReleaseBus(i2cd);
371
  if (!i2cd_locked_external) {
372
    i2cReleaseBus(i2cd);
373
  }
368 374
#endif
369 375

  
370 376
  switch (status)
......
399 405
  aosDbgCheck(i2cd != NULL);
400 406

  
401 407
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
402
  i2cAcquireBus(i2cd);
408
  // check whether the I2C driver was locked externally
409
  const bool i2cd_locked_external = i2cd->mutex.owner == currp;
410
  if (!i2cd_locked_external) {
411
    i2cAcquireBus(i2cd);
412
  }
403 413
#endif
404 414

  
405 415
#pragma GCC diagnostic push
......
420 430
#pragma GCC diagnostic pop
421 431

  
422 432
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
423
  i2cReleaseBus(i2cd);
433
  if (!i2cd_locked_external) {
434
    i2cReleaseBus(i2cd);
435
  }
424 436
#endif
425 437

  
426 438
  switch (status)
......
467 479
  aosDbgCheck(spid != NULL);
468 480

  
469 481
#if (SPI_USE_MUTUAL_EXCLUSION)
470
  spiAcquireBus(spid);
482
  // check whether the SPI driver was locked externally
483
  const bool spid_locked_external = spid->mutex.owner == currp;
484
  if (!spid_locked_external) {
485
    spiAcquireBus(spid);
486
  }
471 487
#endif
488

  
472 489
  spiSelect(spid);
473 490
  spiExchange(spid, length, txData, rxData);
474 491
  spiUnselect(spid);
492

  
475 493
#if (SPI_USE_MUTUAL_EXCLUSION)
476
  spiReleaseBus(spid);
494
  if (!spid_locked_external) {
495
    spiReleaseBus(spid);
496
  }
477 497
#endif
478 498

  
479 499
  return APAL_STATUS_OK;
......
493 513
  aosDbgCheck(spid != NULL);
494 514

  
495 515
#if (SPI_USE_MUTUAL_EXCLUSION)
496
  spiAcquireBus(spid);
516
  // check whether the SPI driver was locked externally
517
  const bool spid_locked_external = spid->mutex.owner == currp;
518
  if (!spid_locked_external) {
519
    spiAcquireBus(spid);
520
  }
497 521
#endif
522

  
498 523
  spiSelect(spid);
499 524
  spiReceive(spid, length, data);
500 525
  spiUnselect(spid);
526

  
501 527
#if (SPI_USE_MUTUAL_EXCLUSION)
502
  spiReleaseBus(spid);
528
  if (!spid_locked_external) {
529
    spiReleaseBus(spid);
530
  }
503 531
#endif
504 532

  
505 533
  return APAL_STATUS_OK;
......
519 547
  aosDbgCheck(spid != NULL);
520 548

  
521 549
#if (SPI_USE_MUTUAL_EXCLUSION)
522
  spiAcquireBus(spid);
550
  // check whether the SPI driver was locked externally
551
  const bool spid_locked_external = spid->mutex.owner == currp;
552
  if (!spid_locked_external) {
553
    spiAcquireBus(spid);
554
  }
523 555
#endif
556

  
524 557
  spiSelect(spid);
525 558
  spiSend(spid, length, data);
526 559
  spiUnselect(spid);
560

  
527 561
#if (SPI_USE_MUTUAL_EXCLUSION)
528
  spiReleaseBus(spid);
562
  if (!spid_locked_external) {
563
    spiReleaseBus(spid);
564
  }
529 565
#endif
530 566

  
531 567
  return APAL_STATUS_OK;
......
547 583
  aosDbgCheck(spid != NULL);
548 584

  
549 585
#if (SPI_USE_MUTUAL_EXCLUSION)
550
  spiAcquireBus(spid);
586
  // check whether the SPI driver was locked externally
587
  const bool spid_locked_external = spid->mutex.owner == currp;
588
  if (!spid_locked_external) {
589
    spiAcquireBus(spid);
590
  }
551 591
#endif
592

  
552 593
  spiSelect(spid);
553 594
  spiSend(spid, txLength, txData);
554 595
  spiReceive(spid, rxLength, rxData);
555 596
  spiUnselect(spid);
597

  
556 598
#if (SPI_USE_MUTUAL_EXCLUSION)
557
  spiReleaseBus(spid);
599
  if (!spid_locked_external) {
600
    spiReleaseBus(spid);
601
  }
558 602
#endif
559 603

  
560 604
  return APAL_STATUS_OK;

Also available in: Unified diff