Skip to content
Snippets Groups Projects
Select Git revision
  • 3e251d3a7f44aa26ff38e89f45ec11bf197f8fbb
  • master default
  • test
  • rahix/hw-lock-new-mutex
  • dx/somewhat-more-dynamic-config
  • schneider/sdk-0.2.1-7
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

fileops.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    hw-lock.c 1.38 KiB
    #include "modules/log.h"
    #include "modules/modules.h"
    #include "modules/mutex.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    
    #include <errno.h>
    
    static struct mutex hwlock_mutex[_HWLOCK_MAX] = { { 0 } };
    
    void hwlock_init(void)
    {
    	for (int i = 0; i < _HWLOCK_MAX; i++) {
    		/*
    		 * TODO: mutex_create() names these all these mutexes
    		 *       "&hwlock_mutex[i]" which is not helpful at all.  We
    		 *       should somehow rename them to the actual hwlock names.
    		 */
    		mutex_create(&hwlock_mutex[i]);
    	}
    }
    
    int hwlock_acquire(enum hwlock_periph p, TickType_t wait)
    {
    	assert(p < _HWLOCK_MAX);
    
    	/*
    	 * Check for code still defining a timeout.  It will be ignored in the
    	 * new implementation but a warning is emitted so someone hopefully
    	 * eventually fixes the offending code ...
    	 *
    	 * At some point, the signature of this function should be changed.
    	 * Alternatively it could be split into two, similar to the mutex API.
    	 */
    	if (wait != 0 && wait != portMAX_DELAY) {
    		LOG_WARN(
    			"hwlock",
    			"Attempting to lock %d with a timeout (from %p).",
    			p,
    			__builtin_return_address(0)
    		);
    	}
    
    	/* Non-blocking lock attempt */
    	if (wait == 0) {
    		if (mutex_trylock(&hwlock_mutex[p]) == true) {
    			return 0;
    		} else {
    			return -EBUSY;
    		}
    	}
    
    	mutex_lock(&hwlock_mutex[p]);
    	return 0;
    }
    
    int hwlock_release(enum hwlock_periph p)
    {
    	assert(p < _HWLOCK_MAX);
    	mutex_unlock(&hwlock_mutex[p]);
    	return 0;
    }