Skip to content
Snippets Groups Projects
Select Git revision
  • f49b61a19c79372ee6fc9ff02d1360db2861adae
  • master default protected
  • feature-ambient-sensor
  • feature-timed-vibrate
  • ch3/api-speed-eval2
  • rahix/bma
  • freertos-btle
  • schneider/mp-for-old-bl
  • ch3/leds-api
  • ch3/genapi-refactor
  • ch3/dual-core
  • dualcore
12 results

meson.build

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");
    	}
    }