Skip to content
Snippets Groups Projects
Select Git revision
  • 2e00c2b35710d858814fb4162755e5bfea267fa1
  • master default protected
  • backslash
  • nickname-match-configs
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • 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
34 results

i2c.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    i2c.c 590 B
    #include "modules/log.h"
    #include "modules/modules.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "semphr.h"
    
    #include <errno.h>
    
    static StaticSemaphore_t i2c_mutex_data;
    static SemaphoreHandle_t i2c_mutex;
    
    int i2c_init(void)
    {
    	i2c_mutex = xSemaphoreCreateMutexStatic(&i2c_mutex_data);
    	return 0;
    }
    
    int i2c_lock(void)
    {
    	if (xSemaphoreTake(i2c_mutex, pdMS_TO_TICKS(100)) != pdTRUE) {
    		LOG_WARN("i2c", "Mutex is busy");
    		return -EBUSY;
    	}
    	return 0;
    }
    
    void i2c_unlock(void)
    {
    	if (xSemaphoreGive(i2c_mutex) != pdTRUE) {
    		LOG_ERR("i2c", "Mutex was not acquired correctly");
    	}
    }