RT-Thread STM32F407 BMI088--SPI

news2024/11/20 2:31:00

BMI088是一款高性能6轴惯性传感器,由16位数字三轴±24g加速度计和16位数字三轴±2000°/ s陀螺仪组成。

这里用SPI来驱动BMI088进行数据解读

  • 第一步,首先在 RT-Thread Settings中进行配置
    在这里插入图片描述

  • 第二步,退出RT-Thread Settings,进入board.h,定义宏
    在这里插入图片描述

  • 第三步,**进入stm32f4xx_hal_conf.h **
    在这里插入图片描述

  • 第四步,STM32 CubeMX配置
    在这里插入图片描述

  • 第五步,添加驱动文件到application
    在这里插入图片描述
    bmi088.c

#include "bmi088.h"
#include <rtdbg.h> 
#include <rtdevice.h> 
#include <board.h>
#include "drv_spi.h"

#define BMI088_SPI_MAX_SPEED (10 * 1000 * 1000) // M
#define CSB1_Pin GET_PIN(B, 14)
#define CSB2_Pin GET_PIN(B, 15)

static rt_err_t _bmi088_spi_read(struct rt_spi_device *dev, rt_uint8_t reg_addr, const rt_uint8_t len, rt_uint8_t *buf)
{
    reg_addr |= 0x80;
    
    dev->bus->owner = dev;
    rt_spi_send_then_recv(dev, &reg_addr, 1, buf, len);    
    
    return RT_EOK;
}

static rt_err_t _bmi088_spi_write(struct rt_spi_device *dev, rt_uint8_t reg_addr, const rt_uint8_t len, rt_uint8_t *buf)
{   
    reg_addr &= 0x7f;
    
    dev->bus->owner = dev;
    rt_spi_send_then_send(dev, &reg_addr, 1, buf, len);
    
    return RT_EOK;
}

static rt_err_t _bmi088_get_accel_raw(struct bmi08x_dev *dev, struct bmi088_3axes *accel)
{
    rt_uint8_t buffer[10];
    uint8_t lsb, msb;
    rt_err_t res;

    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->accel_bus);
    res = _bmi088_spi_read(spi_dev, ACC_X_LSB_REG, 10, buffer);
    if (res != RT_EOK)
    {
        return res;
    }
    lsb = buffer[1];
    msb = buffer[2];
    accel->x = (rt_int16_t)((msb << 8) | lsb); /* X */
    
    lsb = buffer[3];
    msb = buffer[4];
    accel->y = (rt_int16_t)((msb << 8) | lsb);/* Y */

    lsb = buffer[5];
    msb = buffer[6];
    accel->z = (rt_int16_t)((msb << 8) | lsb);/* Z */

    return RT_EOK;
}

static rt_err_t _bmi088_get_gyro_raw(struct bmi08x_dev *dev, struct bmi088_3axes *gyro)
{
    rt_uint8_t buffer[6];
    uint8_t lsb, msb;
    rt_err_t res;
    
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->gyro_bus);
    res = _bmi088_spi_read(spi_dev, RATE_X_LSB_REG, 6, buffer);
    if (res != RT_EOK)
    {
        return res;
    }
    lsb = buffer[0];
    msb = buffer[1];
    gyro->x = (rt_int16_t)((msb * 256) + lsb); /* X */

    lsb = buffer[2];
    msb = buffer[3];
    gyro->y = (rt_int16_t)((msb * 256) + lsb); /* Y */

    lsb = buffer[4];
    msb = buffer[5];
    gyro->z = (rt_int16_t)((msb * 256) + lsb); /* Z */

    return RT_EOK;
}

/**
* This function gets the data of the accelerometer, unit: m/ss
 *
 * @param dev the pointer of device driver structure
 * @param accel the pointer of 3axes structure for receive data
 *
 * @return the reading number.
 */
rt_size_t bmi088_get_accel(struct bmi08x_dev *dev, struct bmi088_data *buf)
{ 
    struct bmi088_3axes tmp;
    
    _bmi088_get_accel_raw(dev, &tmp);
    buf->x = ((float)tmp.x) /32768.0f * 6 * G;
    buf->y = ((float)tmp.y) /32768.0f * 6 * G;
    buf->z = ((float)tmp.z) /32768.0f * 6 * G;    

    return 1;// just support rw mode
}

/**
* This function gets the data of the gyroscope, unit: rad/s
 *
 * @param dev the pointer of device driver structure
 * @param gyro the pointer of 3axes structure for receive data
 *
 * @return the reading number.
 */
rt_size_t bmi088_get_gyro(struct bmi08x_dev *dev, struct bmi088_data *buf)
{
    struct bmi088_3axes tmp;
    
    _bmi088_get_gyro_raw(dev, &tmp);
    buf->x = (float)tmp.x / 32767.0f * 2000.0f;
    buf->y = (float)tmp.y / 32767.0f * 2000.0f;
    buf->z = (float)tmp.z / 32767.0f * 2000.0f;   
    
    return 1;
}

/**
 * This function software reset the accelerometer of bmi08x.
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the status of software reset, RT_EOK represents software reset successfully.
 */
static rt_err_t _bmi088a_soft_reset(struct bmi08x_dev *dev)
{
    uint8_t send_cmd = BMI08X_SOFT_RESET_CMD;
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->accel_bus);
    if (_bmi088_spi_write(spi_dev, ACC_SOFTRESET_REG, 1, &send_cmd) == RT_EOK)
    {
        rt_thread_mdelay(BMI08X_ACCEL_SOFTRESET_DELAY_MS);
        return RT_EOK;
    }
    else
    {
        return RT_ERROR;    
    }
}

/**
 * This function software reset the gyroscope of bmi08x.
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the status of software reset, RT_EOK represents software reset successfully.
 */
static rt_err_t _bmi088g_soft_reset(struct bmi08x_dev *dev)
{
    uint8_t send_cmd = BMI08X_SOFT_RESET_CMD;
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->gyro_bus);
    if (_bmi088_spi_write(spi_dev, GYRO_SOFTRESET_REG, 1, &send_cmd) == RT_EOK)
    {
        rt_thread_mdelay(BMI08X_GYRO_SOFTRESET_DELAY_MS);
        return RT_EOK;
    }
    else
    {
        return RT_ERROR;    
    }
}

/**
 * This function initialize the accelerometer of bmi08x.
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the status of initialization, RT_EOK represents initialize successfully.
 */
static rt_err_t _bmi088a_init(struct bmi08x_dev *dev)
{
	rt_err_t res = RT_EOK;
    uint8_t chip_acc_id[2] = {0};
    // config acc to spi mode
    rt_pin_write(dev->accel_id, PIN_LOW);
    rt_thread_mdelay(1);
    rt_pin_write(dev->accel_id, PIN_HIGH);
 
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->accel_bus);
    _bmi088_spi_read(spi_dev, ACC_CHIP_ID_REG, 2, chip_acc_id);    /* Dummy read */
    if (chip_acc_id[1] != dev->accel_chip_id) 
    {
        LOG_E("Fail initialize acc");
        goto __exit;        
    }

    rt_thread_mdelay(10);
    res = _bmi088a_soft_reset(dev);
    
    // config acc to spi mode
    rt_pin_write(dev->accel_id, PIN_LOW);
    rt_thread_mdelay(1);
    rt_pin_write(dev->accel_id, PIN_HIGH);
    
    return res;

__exit:
    return RT_ERROR;    
}

/**
 * This function initialize the gyroscope of bmi08x.
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the status of initialization, RT_EOK represents initialize successfully.
 */
static rt_err_t _bmi088g_init(struct bmi08x_dev *dev)
{
	rt_err_t res = RT_EOK;
    rt_uint8_t id = 0;  
    
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)dev->gyro_bus;
    _bmi088_spi_read(spi_dev, GYRO_CHIP_ID_REG, 1, &id);
    
    if (id != dev->gyro_chip_id) 
    {
        LOG_E("Fail initialize gyro");
        goto __exit;
    }
    rt_thread_mdelay(10);
    res = _bmi088g_soft_reset(dev);
    return res;
    
__exit:
    return RT_ERROR;
}

/**
 * This function set the power mode of accelerometer of bmi08x 
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the setting status, RT_EOK represents reading the data successfully.
 */
rt_err_t bmi088a_set_power_mode(struct bmi08x_dev *dev)
{
    uint8_t power_mode = dev->accel_cfg.power;
    uint8_t data[2];
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->accel_bus);
    
    if (power_mode == BMI08X_ACCEL_PM_ACTIVE) 
    {
        data[0] = BMI08X_ACCEL_PWR_ACTIVE_CMD;
        data[1] = BMI08X_ACCEL_POWER_ENABLE_CMD;
    } 
    else if (power_mode == BMI08X_ACCEL_PM_SUSPEND) 
    {
        data[0] = BMI08X_ACCEL_PWR_SUSPEND_CMD;
        data[1] = BMI08X_ACCEL_POWER_DISABLE_CMD;
    } 
    else 
    {
        LOG_E("Invalid acc power mode!");
        goto __exit;          
    }

    if (_bmi088_spi_write(spi_dev, ACC_PWR_CONF_REG, 1, &data[0]) == RT_EOK)
    {
        rt_thread_mdelay(BMI08X_POWER_CONFIG_DELAY);
        data[1] = BMI08X_ACCEL_POWER_ENABLE_CMD;
        if (_bmi088_spi_write(spi_dev, ACC_PWR_CTRL_REG, 1, &data[1]) == RT_EOK)
        {
            rt_thread_mdelay(BMI08X_POWER_CONFIG_DELAY);
            return RT_EOK;
        }
        else
        {
            LOG_E("Failed write CTRL_REG");
            goto __exit;
        }
    }
    else
    {
        LOG_E("Failed write PWR_REG");
        goto __exit;
    }        
    
__exit:
    return RT_ERROR;
}

/**
 * This function set the power mode of gyroscope of bmi08x 
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the setting status, RT_EOK represents reading the data successfully.
 */
rt_err_t bmi088g_set_power_mode(struct bmi08x_dev *dev)
{
	uint8_t power_mode = dev->gyro_cfg.power;
    uint8_t read_data;
	uint8_t is_power_switching_mode_valid = 1;
    
    struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->gyro_bus);
    _bmi088_spi_read(spi_dev, GYRO_LPM1_REG, 1, &read_data);
    
    if (power_mode == read_data) 
    {
        return RT_EOK;
    }
    else 
    {
        // only switching between normal mode and the suspend mode is allowed
        if ((power_mode == BMI08X_GYRO_PM_SUSPEND) && (read_data == BMI08X_GYRO_PM_DEEP_SUSPEND)) 
        {
            is_power_switching_mode_valid = 0;
        }  
        if ((power_mode == BMI08X_GYRO_PM_DEEP_SUSPEND) && (read_data == BMI08X_GYRO_PM_SUSPEND))
        {
            is_power_switching_mode_valid = 0;
        }
        
        if (is_power_switching_mode_valid) 
        {
            if (_bmi088_spi_write(spi_dev, GYRO_LPM1_REG, 1, &power_mode) == RT_EOK)
            {
                rt_thread_mdelay(BMI08X_GYRO_POWER_MODE_CONFIG_DELAY);
            }
        }
        else
        {
            LOG_E("Invalid gyro mode switch");
            goto __exit;        
        }
    
    }
    
__exit:
    return RT_ERROR;   
}

/**
 * This function set the bandwidth(bw), output data rate(odr) and range of accelerometer of bmi08x 
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the setting status, RT_EOK represents  reading the data successfully.
 */
rt_err_t bmi088a_set_meas_conf(struct bmi08x_dev *dev)
{
    uint8_t data[2] = {0};
    uint8_t reg_val[3] = {0};
    uint8_t bw = dev->accel_cfg.bw;
    uint8_t range = dev->accel_cfg.range;
    uint8_t odr = dev->accel_cfg.odr;
    uint8_t is_odr_invalid = 0, is_bw_invalid = 0, is_range_invalid = 0;
    
    if ((odr < BMI08X_ACCEL_ODR_12_5_HZ) || (odr > BMI08X_ACCEL_ODR_1600_HZ))
    {
        is_odr_invalid = 1;
    }
    if (bw > BMI08X_ACCEL_BW_NORMAL) 
    {
        is_bw_invalid = 1;
    }
    if (range > BMI088_ACCEL_RANGE_24G) 
    {
        is_range_invalid = 1;
    }
    
    if ((!is_odr_invalid) && (!is_bw_invalid) && (!is_range_invalid)) 
    {
        //dummy read
        struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->accel_bus);
        if (_bmi088_spi_read(spi_dev, ACC_CONF_REG, 2, data) == RT_EOK)
        {
            data[0] = (1<<7) | (2<<4) | (0xB<<0);// bwp = normal, odr = 800
            _bmi088_spi_write(spi_dev, ACC_CONF_REG, 1, &data[0]);
            
            data[1] = 0x01;// range = 6G
            _bmi088_spi_write(spi_dev, ACC_RANGE_REG, 1, &data[1]);
            
            rt_thread_mdelay(10);
            _bmi088_spi_read(spi_dev, ACC_CONF_REG, 3, reg_val);// dummy read
            if ((reg_val[1] == 0xAB) && (reg_val[2] == 0x01)) 
            {
                return RT_EOK;
            }
        }
        
    }
    return RT_ERROR;
}

/**
 * This function set the bandwidth(bw), output data rate(odr) and range of gyroscope of bmi08x 
 *
 * @param dev the pointer of bmi08x driver structure
 *
 * @return the setting status, RT_EOK represents reading the data successfully.
 */
rt_err_t bmi088g_set_meas_conf(struct bmi08x_dev *dev)
{
    uint8_t data;
    uint8_t bw_odr = dev->gyro_cfg.bw, range = dev->gyro_cfg.range;
    uint8_t reg_val[2] = {0};
    uint8_t is_range_invalid = 0, is_odr_invalid = 0;

    if (bw_odr > BMI08X_GYRO_BW_32_ODR_100_HZ) 
    {
        is_odr_invalid = 1;
    }
    if (range > BMI08X_GYRO_RANGE_125_DPS) 
    {
        is_range_invalid = 1;
    } 
    if ((!is_odr_invalid) && (!is_range_invalid)) 
    {
//      data = BMI08X_SET_BITS_POS_0(data, BMI08X_GYRO_BW, odr);
        data = 0x01;// ODR = 2000Hz, Filter bandwidth = 230Hz
        struct rt_spi_device *spi_dev = (struct rt_spi_device *)(dev->gyro_bus);
        if (_bmi088_spi_write(spi_dev, GYRO_BANDWIDTH_REG, 1, &data) == RT_EOK)
        {
//          data = BMI08X_SET_BITS_POS_0(data, GYRO_RANGE_REG, range);
            data = 0x00;// range = 2000deg/s
            if (_bmi088_spi_write(spi_dev, GYRO_RANGE_REG, 1, &data) == RT_EOK) 
            {
                rt_thread_mdelay(10);
                _bmi088_spi_read(spi_dev, GYRO_RANGE_REG, 2, reg_val);
                if ((reg_val[0] == 0x00) && (reg_val[1] == 0x81))// 7 bit always 1
                {
                    return RT_EOK;
                }                
            }                
        }
    }
    return RT_ERROR;    
}

/**
 * This function initialize the bmi088 device.
 *
 * @param acc_spi_name the name of spi device(Accelerometer)
 * @param gyro_spi_name the name of spi device(Gyroscope)
 *
 * @return the pointer of bmi08x driver structure, RT_NULL represents initialization failed.
 */
struct bmi08x_dev *bmi088_init(const char *acc_spi_name, const char *gyro_spi_name)
{
    struct bmi08x_dev *dev = RT_NULL;
    rt_uint8_t res = RT_EOK;

    RT_ASSERT(acc_spi_name);
    RT_ASSERT(gyro_spi_name);

    dev = rt_calloc(1, sizeof(struct bmi08x_dev));
    if (dev == RT_NULL)
    {
        LOG_E("Can't allocate memory for bmi08x device on '%s' and '%s' ", acc_spi_name, gyro_spi_name);
        goto __exit;
    }
    
    dev->accel_bus = rt_device_find(acc_spi_name);
    dev->gyro_bus = rt_device_find(gyro_spi_name);
    
    
    if ((dev->accel_bus == RT_NULL) || (dev->gyro_bus == RT_NULL))
    {
        LOG_E("Can't find device:'%s' of '%s'", acc_spi_name, gyro_spi_name);
        goto __exit;
    }
    
    if (dev->accel_bus->type != dev->gyro_bus->type)
    {
        LOG_E("The bus type of '%s' and '%s' should same", acc_spi_name, gyro_spi_name);
        goto __exit;    
    }

    if (dev->accel_bus->type == RT_Device_Class_I2CBUS)
    {
        LOG_E("Bmi08x not support I2C temporarily");
        goto __exit;      
    }
    else if (dev->accel_bus->type == RT_Device_Class_SPIDevice)
    {
//#ifdef RT_USING_SPI
        struct rt_spi_configuration cfg;

        cfg.data_width = 8;
        cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB;
        cfg.max_hz = BMI088_SPI_MAX_SPEED; /* Set spi max speed */
        struct rt_spi_device *spi_dev = (struct rt_spi_device *)dev->accel_bus;
        spi_dev->bus->owner = spi_dev;
        rt_spi_configure(spi_dev, &cfg);
//#endif
    }
    else
    {
        LOG_E("Unsupported bus type:'%s'!", acc_spi_name);
        goto __exit;
    }
    
    // acc init
    {
        dev->accel_id = CSB1_Pin;
        dev->accel_chip_id = 0x1E;
        dev->accel_cfg.bw = BMI08X_ACCEL_BW_NORMAL;
        dev->accel_cfg.odr = BMI08X_ACCEL_ODR_800_HZ;
        dev->accel_cfg.power = BMI08X_ACCEL_PM_ACTIVE; 
        dev->accel_cfg.range = BMI088_ACCEL_RANGE_6G;
        res += _bmi088a_init(dev);
        res += bmi088a_set_power_mode(dev);
        res += bmi088a_set_meas_conf(dev);        
    }
    
    // gyro init
    {
        dev->gyro_id = CSB2_Pin;
        dev->gyro_chip_id = 0x0F;
        dev->gyro_cfg.bw = BMI08X_GYRO_BW_230_ODR_2000_HZ;
        dev->gyro_cfg.odr = BMI08X_GYRO_BW_230_ODR_2000_HZ;
        dev->gyro_cfg.power = BMI08X_GYRO_PM_NORMAL;
        dev->gyro_cfg.range = BMI08X_GYRO_RANGE_2000_DPS;
        res += _bmi088g_init(dev);
        res += bmi088g_set_power_mode(dev);
        res += bmi088g_set_meas_conf(dev);
    }
    
    rt_thread_mdelay(20);
    
    if (res == RT_EOK)
    {
        LOG_I("Device init succeed!");
    }
    else
    {
        goto __exit;
    }

    return dev;

__exit:
    if (dev != RT_NULL)
    {
        rt_free(dev);
    }
    return RT_NULL;

}

/**
 * This function releases memory
 *
 * @param dev the pointer of bmi08x driver structure
 */
void bmi088_deinit(struct bmi08x_dev *dev)
{
    RT_ASSERT(dev);

    rt_free(dev);
}



bmi088.h

#ifndef __BMI088_H__
#define __BMI088_H__

#include <rtthread.h>
#include "sensor.h"


#define IMU_THREAD_STACK_SIZE 4086
/*************************** Common Macros for both Accel and Gyro *****************************/
// Bit #0  : Read/Write bit
// Bit #1-7: Address AD
#define BMI08X_SPI_RD_MASK                          UINT8_C(0x80)
#define BMI08X_SPI_WR_MASK                          UINT8_C(0x7F)

/* CMD: soft reset */
#define BMI08X_SOFT_RESET_CMD                       UINT8_C(0xB6)

/* CMD: accel power save */
#define BMI08X_ACCEL_PWR_ACTIVE_CMD                 UINT8_C(0x00)
#define BMI08X_ACCEL_PWR_SUSPEND_CMD                UINT8_C(0x03)

/* CMD: accel power control */ 
#define BMI08X_ACCEL_POWER_DISABLE_CMD              UINT8_C(0x00)
#define BMI08X_ACCEL_POWER_ENABLE_CMD               UINT8_C(0x04)

/* Accel Power Mode */
#define BMI08X_ACCEL_PM_ACTIVE                      UINT8_C(0x00)
#define BMI08X_ACCEL_PM_SUSPEND                     UINT8_C(0x03)

/* Gyro Power mode */
#define BMI08X_GYRO_PM_NORMAL                       UINT8_C(0x00)
#define BMI08X_GYRO_PM_DEEP_SUSPEND                 UINT8_C(0x20)
#define BMI08X_GYRO_PM_SUSPEND                      UINT8_C(0x80)

/* Accel Bandwidth */
#define BMI08X_ACCEL_BW_OSR4                        UINT8_C(0x00)
#define BMI08X_ACCEL_BW_OSR2                        UINT8_C(0x01)
#define BMI08X_ACCEL_BW_NORMAL                      UINT8_C(0x02)

/* Accel Output Data Rate */
#define BMI08X_ACCEL_ODR_12_5_HZ                    UINT8_C(0x05)
#define BMI08X_ACCEL_ODR_25_HZ                      UINT8_C(0x06)
#define BMI08X_ACCEL_ODR_50_HZ                      UINT8_C(0x07)
#define BMI08X_ACCEL_ODR_100_HZ                     UINT8_C(0x08)
#define BMI08X_ACCEL_ODR_200_HZ                     UINT8_C(0x09)
#define BMI08X_ACCEL_ODR_400_HZ                     UINT8_C(0x0A)
#define BMI08X_ACCEL_ODR_800_HZ                     UINT8_C(0x0B)
#define BMI08X_ACCEL_ODR_1600_HZ                    UINT8_C(0x0C)
/* Accel Range */
#define BMI088_ACCEL_RANGE_3G                       UINT8_C(0x00)
#define BMI088_ACCEL_RANGE_6G                       UINT8_C(0x01)
#define BMI088_ACCEL_RANGE_12G                      UINT8_C(0x02)
#define BMI088_ACCEL_RANGE_24G                      UINT8_C(0x03)

/* Gyro Range */
#define BMI08X_GYRO_RANGE_2000_DPS                  UINT8_C(0x00)
#define BMI08X_GYRO_RANGE_1000_DPS                  UINT8_C(0x01)
#define BMI08X_GYRO_RANGE_500_DPS                   UINT8_C(0x02)
#define BMI08X_GYRO_RANGE_250_DPS                   UINT8_C(0x03)
#define BMI08X_GYRO_RANGE_125_DPS                   UINT8_C(0x04)

/* Gyro Output data rate and bandwidth */
#define BMI08X_GYRO_BW_532_ODR_2000_HZ              UINT8_C(0x00)
#define BMI08X_GYRO_BW_230_ODR_2000_HZ              UINT8_C(0x01)
#define BMI08X_GYRO_BW_116_ODR_1000_HZ              UINT8_C(0x02)
#define BMI08X_GYRO_BW_47_ODR_400_HZ                UINT8_C(0x03)
#define BMI08X_GYRO_BW_23_ODR_200_HZ                UINT8_C(0x04)
#define BMI08X_GYRO_BW_12_ODR_100_HZ                UINT8_C(0x05)
#define BMI08X_GYRO_BW_64_ODR_200_HZ                UINT8_C(0x06)
#define BMI08X_GYRO_BW_32_ODR_100_HZ                UINT8_C(0x07)
#define BMI08X_GYRO_ODR_RESET_VAL                   UINT8_C(0x80)

#define BMI08X_ACCEL_DATA_SYNC_MODE_OFF 0x00
#define BMI08X_ACCEL_DATA_SYNC_MODE_400HZ 0x01
#define BMI08X_ACCEL_DATA_SYNC_MODE_1000HZ 0x02
#define BMI08X_ACCEL_DATA_SYNC_MODE_2000HZ 0x03

/* Wait Time */
#define BMI08X_ACCEL_SOFTRESET_DELAY_MS             UINT8_C(1)
#define BMI08X_GYRO_SOFTRESET_DELAY_MS              UINT8_C(30)
#define BMI08X_GYRO_POWER_MODE_CONFIG_DELAY         UINT8_C(30)
#define BMI08X_POWER_CONFIG_DELAY                   UINT8_C(50)

#define G (9.80f)
#define deg2rad (3.1415926 / 180.0f)
#define rad2deg (180.0f / 3.1415926)

typedef enum 
{
    ACC_CHIP_ID_REG             = 0x00,
    ACC_ERR_REG                 = 0x02,
    ACC_STATUS_REG              = 0x03,
    ACC_X_LSB_REG               = 0x12,
    ACC_X_MSB_REG               = 0x13,
    ACC_Y_LSB_REG               = 0x14,
    ACC_Y_MSB_REG               = 0x15,
    ACC_Z_LSB_REG               = 0x16,
    ACC_Z_MSB_REG               = 0x17,
    TEMP_MSB_REG                = 0x22,
    TEMP_LSB_REG                = 0x23,
    ACC_CONF_REG                = 0x40,
    ACC_RANGE_REG               = 0x41,
    INT1_IO_CTRL_REG            = 0x53,
    INT2_IO_CTRL_REG            = 0x54,
    ACC_SELF_TEST_REG           = 0x6D,
    ACC_PWR_CONF_REG            = 0x7C,
    ACC_PWR_CTRL_REG            = 0x7D,
    ACC_SOFTRESET_REG           = 0x7E
} bmi088a_reg_list_t;

typedef enum 
{
    GYRO_CHIP_ID_REG            = 0x00,
    RATE_X_LSB_REG              = 0x02,
    RATE_X_MSB_REG              = 0x03,
    RATE_Y_LSB_REG              = 0x04,
    RATE_Y_MSB_REG              = 0x05,
    RATE_Z_LSB_REG              = 0x06,
    RATE_Z_MSB_REG              = 0x07,
    GYRO_INT_STAT_1_REG         = 0x0A,
    GYRO_RANGE_REG              = 0x0F,
    GYRO_BANDWIDTH_REG          = 0x10,
    GYRO_LPM1_REG               = 0x11,
    GYRO_SOFTRESET_REG          = 0x14,
    GYRO_INT_CTRL_REG           = 0x15
} bmi088g_reg_list_t;

enum bmi08x_intf {
/*! I2C interface */
BMI08X_I2C_INTF,
/*! SPI interface */
BMI08X_SPI_INTF
};

struct bmi08x_cfg 
{
/*! power mode */
uint8_t power;
/*! range */
uint8_t range;
/*! bandwidth */
uint8_t bw;
/*! output data rate */
uint8_t odr;
};

/* bmi088 device structure */
struct bmi08x_dev 
{
/*! Accel chip Id */
uint8_t accel_chip_id;
/*! Gyro chip Id */
uint8_t gyro_chip_id;
/*! Accel device Id in I2C mode, can be used for chip select pin in SPI mode */
rt_base_t accel_id;
/*! Gyro device Id in I2C mode, can be used for chip select pin in SPI mode */
rt_base_t gyro_id;
/*! Device of accel bus*/
rt_device_t accel_bus;
/*! Device of gyro bus*/
rt_device_t gyro_bus;
/*! 0 - I2C , 1 - SPI Interface */
enum bmi08x_intf intf;
/*! Structure to configure accel sensor  */
struct bmi08x_cfg accel_cfg;
/*! Structure to configure gyro sensor  */
struct bmi08x_cfg gyro_cfg;
/*! Config stream data buffer address will be assigned*/
const uint8_t *config_file_ptr;
/*! Max read/write length (maximum supported length is 32).
To be set by the user */
uint8_t read_write_len;
};

struct bmi088_3axes
{
    rt_int16_t x;
    rt_int16_t y;
    rt_int16_t z;
};

struct bmi088_data
{
    float x;
    float y;
    float z;
};

struct bmi08x_dev *bmi088_init(const char *acc_name, const char *gyro_name);
void bmi088_deinit(struct bmi08x_dev *dev);
rt_err_t bmi088a_set_power_mode(struct bmi08x_dev *dev);
rt_err_t bmi088g_set_power_mode(struct bmi08x_dev *dev);
rt_err_t bmi088a_set_meas_conf(struct bmi08x_dev *dev);
rt_err_t bmi088g_set_meas_conf(struct bmi08x_dev *dev);
rt_size_t bmi088_get_accel(struct bmi08x_dev *dev, struct bmi088_data *buf);
rt_size_t bmi088_get_gyro(struct bmi08x_dev *dev, struct bmi088_data *buf);


#endif // BMI088_H

sensor_intf_bmi088.c

#include "sensor_intf_bmi088.h"
#include "bmi088.h"
#include <rtdbg.h>

static struct bmi08x_dev *bmi_dev;

static rt_err_t _bmi088_init(struct rt_sensor_intf *acc_intf, struct rt_sensor_intf *gyr_intf)
{
    bmi_dev = bmi088_init(acc_intf->dev_name, gyr_intf->dev_name);

    if (bmi_dev == RT_NULL)
    {
        return -RT_ERROR;
    }

    return RT_EOK;
}

static rt_err_t _bmi088_set_power_mode(rt_sensor_t sensor, rt_uint8_t power)
{   
    if (sensor->info.type == RT_SENSOR_CLASS_ACCE)
    {
        if (power == RT_SENSOR_POWER_DOWN) 
        {
            bmi_dev->accel_cfg.power = BMI08X_ACCEL_PM_SUSPEND;
        }
        else if (power == RT_SENSOR_POWER_NORMAL)
        {
            bmi_dev->accel_cfg.power = BMI08X_ACCEL_PM_ACTIVE;
        }
        else 
        {
            LOG_E("Unsupported power mode %d", power);
            return -RT_ERROR;        
        }
        
        bmi088a_set_power_mode(bmi_dev);
    }
    else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
    {
        if (power == RT_SENSOR_POWER_DOWN) 
        {
            bmi_dev->gyro_cfg.power = BMI08X_GYRO_PM_SUSPEND;
        }
        else if (power == RT_SENSOR_POWER_NORMAL)
        {
            bmi_dev->gyro_cfg.power = BMI08X_GYRO_PM_NORMAL;
        }
        else if (power == RT_SENSOR_POWER_NONE)
        {
            bmi_dev->gyro_cfg.power = BMI08X_GYRO_PM_DEEP_SUSPEND;
        }
        else 
        {
            LOG_E("Unsupported power mode %d", power);
            return -RT_ERROR;        
        }
        
        bmi088g_set_power_mode(bmi_dev);
    }
    else 
    {
        LOG_E("Unsupported type %d", sensor->info.type);
        return -RT_ERROR;
    }
    return RT_EOK;
}

/**
* This function get the data of bmi088 sensor, unit: mg, mdps
 *
 * @param sensor the pointer of rt_sensor_device.
 * @param data the pointer of rt_sensor_data
 * 
 * @return the reading number.
 */
static rt_size_t _bmi088_get_data(rt_sensor_t sensor, struct rt_sensor_data *data)
{
    rt_size_t len;
    if (sensor->info.type == RT_SENSOR_CLASS_ACCE)
    {
        struct bmi088_data acce_m_ss;
        len =  bmi088_get_accel(bmi_dev, &acce_m_ss);

        data->type = RT_SENSOR_CLASS_ACCE;
        data->data.acce.x = acce_m_ss.x * 1000;
        data->data.acce.y = acce_m_ss.y * 1000;
        data->data.acce.z = acce_m_ss.z * 1000;
        data->timestamp = rt_sensor_get_ts();
    }
    else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
    {
        struct bmi088_data gyro_rad_s;
        len = bmi088_get_gyro(bmi_dev, &gyro_rad_s);

        data->type = RT_SENSOR_CLASS_GYRO;
        data->data.gyro.x = gyro_rad_s.x * rad2deg * 1000;
        data->data.gyro.y = gyro_rad_s.y * rad2deg * 1000;
        data->data.gyro.z = gyro_rad_s.x * rad2deg * 1000;
        data->timestamp = rt_sensor_get_ts();
    }
    return len;
}

/**
* This function get the data of bmi088 sensor
 *
 * @param sensor the pointer of rt_sensor_device.
 * @param buf the pointer of data buffer.
 * @param len the length of data.
 * 
 * @return the reading number.
 */
static rt_size_t _bmi088_fetch_data(struct rt_sensor_device *sensor, void *buf, rt_size_t len)
{
    if (sensor->config.mode == RT_DEVICE_OFLAG_RDONLY)
    {
        return _bmi088_get_data(sensor, (struct rt_sensor_data *)buf);
    }
    else
    {
        return 0;
    }
}

/**
* This function control the bmi088 sensor
 *
 * @param sensor the pointer of rt_sensor_device.
 * @param cmd the type of command.
 * @param args the null pointer of commmand parameter, notice the pointer is four bytes.
 * 
 * @return the reading number.
 */
static rt_err_t _bmi088_control(struct rt_sensor_device *sensor, int cmd, void *args)//args��32λ(ָ�붼��4���ֽ�)
{
    rt_err_t result = RT_EOK;

    switch (cmd)
    {
    case RT_SENSOR_CTRL_GET_ID:
        if (sensor->info.type == RT_SENSOR_CLASS_ACCE) 
        {
            *(rt_uint8_t *)args = 0x1E;
        }
        else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
        {
            *(rt_uint8_t *)args = 0x0F;
        }
        break;
    case RT_SENSOR_CTRL_SET_ODR:
    case RT_SENSOR_CTRL_SET_RANGE:
        if (sensor->info.type == RT_SENSOR_CLASS_ACCE) 
        {
            result = bmi088a_set_meas_conf(bmi_dev);
        }
        else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
        {
            result = bmi088g_set_meas_conf(bmi_dev);
        }
        break;
    case RT_SENSOR_CTRL_SET_POWER:
        _bmi088_set_power_mode(sensor, (rt_uint32_t)args & 0xff);
        break;
    case RT_SENSOR_CTRL_SET_MODE:
        break;
    case RT_SENSOR_CTRL_SELF_TEST:
        /* TODO */
        result = -RT_EINVAL;
        break;
    default:
        return -RT_EINVAL;
    }
    return result;
}

static struct rt_sensor_ops sensor_ops =
{
    _bmi088_fetch_data, 
    _bmi088_control
};

/**
* This function initialize the bmi088
 *
 * @param name the name of bmi088, just first three characters will be used.
 * @param acc_cfg the pointer of configuration structure for accelarometer.
 * @param gyr_cfg the pointer of configuration structure for gyroscope.
 * 
 * @return the reading number.
 */
rt_err_t rt_hw_bmi088_init(const char *name, struct rt_sensor_config *acc_cfg, struct rt_sensor_config *gyr_cfg)
{   
    rt_int8_t result;
    rt_sensor_t sensor_acce = RT_NULL, sensor_gyro = RT_NULL;

//#ifdef PKG_USING_BMI088_ACCE
    /* accelerometer sensor register */
    {
        sensor_acce = rt_calloc(1, sizeof(struct rt_sensor_device));
        if (sensor_acce == RT_NULL)
        {
            return -1;
        }
            
        sensor_acce->info.type       = RT_SENSOR_CLASS_ACCE;
        sensor_acce->info.vendor     = RT_SENSOR_VENDOR_BOSCH;
        sensor_acce->info.model      = "bmi088_acc";
        sensor_acce->info.unit       = RT_SENSOR_UNIT_MG;
        sensor_acce->info.intf_type  = RT_SENSOR_INTF_SPI;
        sensor_acce->info.range_max  = 16000;
        sensor_acce->info.range_min  = 2000;
        sensor_acce->info.period_min = 5;

        rt_memcpy(&sensor_acce->config, acc_cfg, sizeof(struct rt_sensor_config));
        sensor_acce->ops = &sensor_ops;

        result = rt_hw_sensor_register(sensor_acce, name, RT_DEVICE_FLAG_RDWR, RT_NULL);
        if (result != RT_EOK)
        {
            LOG_E("device register err code: %d", result);
            goto __exit;
        }
    }
//#endif
//#ifdef PKG_USING_BMI088_GYRO
    /* gyroscope sensor register */
    {
        sensor_gyro = rt_calloc(1, sizeof(struct rt_sensor_device));
        if (sensor_gyro == RT_NULL)
        {
            goto __exit;
        }
            
        sensor_gyro->info.type       = RT_SENSOR_CLASS_GYRO;
        sensor_gyro->info.vendor     = RT_SENSOR_VENDOR_BOSCH;
        sensor_gyro->info.model      = "bmi088_gyro";
        sensor_gyro->info.unit       = RT_SENSOR_UNIT_MDPS;
        sensor_gyro->info.intf_type  = RT_SENSOR_INTF_SPI;
        sensor_gyro->info.range_max  = 2000000;
        sensor_gyro->info.range_min  = 250000;
        sensor_gyro->info.period_min = 5;

        rt_memcpy(&sensor_gyro->config, gyr_cfg, sizeof(struct rt_sensor_config));
        sensor_gyro->ops = &sensor_ops;

        result = rt_hw_sensor_register(sensor_gyro, name, RT_DEVICE_FLAG_RDWR, RT_NULL);
        if (result != RT_EOK)
        {
            LOG_E("device register err code: %d", result);
            goto __exit;
        }
    }
//#endif

    result = _bmi088_init(&acc_cfg->intf, &gyr_cfg->intf);
    if (result != RT_EOK)
    {
        LOG_E("_bmi088_init err code: %d", result);
        goto __exit;
    }

    LOG_I("sensor init success");
    return RT_EOK;

__exit:
    if (sensor_acce)
    {
        rt_free(sensor_acce);
    } 
    if (sensor_gyro)
    {
        rt_free(sensor_gyro);
    }  
    if (bmi_dev)
    {
        bmi088_deinit(bmi_dev);
    }
    return -RT_ERROR;
}

sensor_intf_bmi088.h

#ifndef __SENSOR_INTF_BMI088_H__
#define __SENSOR_INTF_BMI088_H__

#include "sensor.h"
#include "BMI088.h"


rt_err_t rt_hw_bmi088_init(const char *name, struct rt_sensor_config *acc_cfg, struct rt_sensor_config *gyr_cfg);

#endif

  • 第六步,到main.c 配置bmi088
    ①配置spi,配置片选引脚
   
    rt_hw_spi_device_attach(BMI088_BUS_NAME, BMI088A_SPI_NAME, GPIOF, GPIO_PIN_3);
    rt_hw_spi_device_attach(BMI088_BUS_NAME, BMI088G_SPI_NAME, GPIOF, GPIO_PIN_4);

②初始化bmi

    struct rt_sensor_config acc_cfg = {0};
    struct rt_sensor_config gyr_cfg = {0};

    acc_cfg.intf.dev_name = BMI088A_SPI_NAME;
    gyr_cfg.intf.dev_name = BMI088G_SPI_NAME;

    rt_hw_bmi088_init("bmi", &acc_cfg, &gyr_cfg);

③查找 spi 设备获取设备句柄


    acce_device_t = rt_device_find("acce_bmi");
    if (acce_device_t == RT_NULL)
    {
        LOG_E("Can't find acce device\r\n");
    }
    else
    {
        rt_device_open(acce_device_t, RT_DEVICE_OFLAG_RDWR);
    }

    gyro_device_t = rt_device_find("gyro_bmi");
    if (gyro_device_t == RT_NULL)
    {
        LOG_E("Can't find gyro device\r\n");
    }
    else
    {
        rt_device_open(gyro_device_t, RT_DEVICE_OFLAG_RDWR);
    }

④读取姿态数据

    rt_device_read(acce_device_t, 0, &acc_test, 1);   //加速度
    rt_device_read(gyro_device_t, 0, &gyr_test, 1);   //陀螺仪

main.c

include <rtthread.h>
#include <rtdbg.h>
#include <rtdevice.h>
#include <board.h>
#include "bmi088.h"
#include "sensor_intf_bmi088.h"

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG

#define SPI_DEVICE_NAME     "spi10"
#define SPI_BUS_NAME        "spi1"
#define BMI088_BUS_NAME "spi1"
#define BMI088A_SPI_NAME "spi10"
#define BMI088G_SPI_NAME "spi11"

static rt_device_t acce_device_t;
static rt_device_t gyro_device_t;
struct rt_sensor_data acc_test;
struct rt_sensor_data gyr_test;

int main(void)
{

    // 配置spi,配置片选引脚(要在acc、gyr初始化之前配置,因为器件初始化中涉及到引脚操作)
    rt_hw_spi_device_attach(BMI088_BUS_NAME, BMI088A_SPI_NAME, GPIOF, GPIO_PIN_3);
    rt_hw_spi_device_attach(BMI088_BUS_NAME, BMI088G_SPI_NAME, GPIOF, GPIO_PIN_4);

    // 注册传感器
    struct rt_sensor_config acc_cfg = {0};
    struct rt_sensor_config gyr_cfg = {0};

    acc_cfg.intf.dev_name = BMI088A_SPI_NAME;
    gyr_cfg.intf.dev_name = BMI088G_SPI_NAME;

    rt_hw_bmi088_init("bmi", &acc_cfg, &gyr_cfg);

    /* 查找 spi 设备获取设备句柄 */
    acce_device_t = rt_device_find("acce_bmi");
    if (acce_device_t == RT_NULL)
    {
        LOG_E("Can't find acce device\r\n");
    }
    else
    {
        rt_device_open(acce_device_t, RT_DEVICE_OFLAG_RDWR);
    }

    gyro_device_t = rt_device_find("gyro_bmi");
    if (gyro_device_t == RT_NULL)
    {
        LOG_E("Can't find gyro device\r\n");
    }
    else
    {
        rt_device_open(gyro_device_t, RT_DEVICE_OFLAG_RDWR);
    }

    while (1)
    {
        rt_device_read(acce_device_t, 0, &acc_test, 1);   //加速度
        rt_device_read(gyro_device_t, 0, &gyr_test, 1);   //陀螺仪

        rt_kprintf("x=%d  y=%d  z=%d\n",acc_test.data.acce.x,acc_test.data.acce.y,acc_test.data.acce.z);
        //rt_kprintf("x=%d  y=%d  z=%d\n",gyr_test.data.gyro.x,gyr_test.data.gyro.y,gyr_test.data.gyro.z);
        rt_thread_mdelay(500);
    }
}

如下为加速度计数据:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1225702.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

未来科技中的云计算之路

随着科技的不断发展&#xff0c;云计算已经不再是一个陌生的词汇&#xff0c;而是我们日常生活中不可或缺的一部分。从智能家居到无人驾驶&#xff0c;再到虚拟现实和人工智能&#xff0c;云计算在这些领域都扮演着至关重要的角色。在这篇博客中&#xff0c;我们将一同探索云计…

SUID提权教程

SUID提权方法 一、SUID是什么&#xff1f;二、如何设置SUID权限&#xff1f;三、已知的具有SUID权限的二进制可执行文件四、查找具有root权限的SUID的文件1.find命令提权2.nmap命令提权3.more命令提权4.less命令提权5.bash命令提权6.vim命令提权7.awk命令提权8.cp命令提权 五、…

【如何学习Python自动化测试】—— 页面元素定位

接上篇自动化测试环境搭建&#xff0c;现在我们介绍 webdriver 对浏览器操作的 API。 2、 页面元素定位 通过自动化操作 web 页面&#xff0c;首先要解决的问题就是定位到要操作的对象&#xff0c;比如要模拟用户在页面上的输入框中输入一段字符串&#xff0c;那就必须得定位到…

UiPath Studio 2023.10 Crack

UiPath Studio是一款功能强大且用户友好的集成开发环境 (IDE)&#xff0c;专为机器人流程自动化 (RPA) 设计。它由自动化技术领域的领先公司UiPath开发。 以下是 UiPath Studio 的一些主要功能和组件&#xff1a; 图形用户界面 (GUI)&#xff1a;UiPath Studio 具有直观且用户友…

sqli-labs关卡18(基于http头部报错盲注)通关思路

文章目录 前言一、靶场通关需要了解的知识点1、什么是http请求头2、为什么http头部可以进行注入 二、靶场第十八关通关思路1、判断注入点2、爆数据库名3、爆数据库表4、爆数据库列5、爆数据库关键信息 总结 前言 此文章只用于学习和反思巩固sql注入知识&#xff0c;禁止用于做…

【数据预处理3】数据预处理 - 归一化和标准化

处理数据之前&#xff0c;通常会使用一些转换函数将「特征数据」转换成更适合「算法模型」的特征数据。这个过程&#xff0c;也叫数据预处理。 比如&#xff0c;我们在择偶时&#xff0c;有身高、体重、存款三个特征&#xff0c;身高是180、体重是180、存款是180000&#xff1…

算法 LeetCode 题解 | 最小栈

大家好&#xff0c;我是木川 一、题目描述 请你设计一个 最小栈 。它提供 push &#xff0c;pop &#xff0c;top 操作&#xff0c;并能在常数时间内检索到最小元素的栈。 实现 MinStack 类: MinStack() 初始化堆栈对象。void push(int val) 将元素val推入堆栈。void pop() 删除…

【Proteus仿真】【STM32单片机】公交车报站系统

文章目录 一、功能简介二、软件设计三、实验现象联系作者 一、功能简介 本项目使用Proteus8仿真STM32单片机控制器&#xff0c;使用LCD12864显示模块、DS18B20温度传感器、DS1302时钟模块、按键、LED蜂鸣器、ULN2003、28BYJ48步进电机模块等。 主要功能&#xff1a; 系统运行…

vulhub redis-4-unacc

环境搭建 cd vulhub/redis/4-unacc docker-compose up -d 漏洞复现 检测 redis-cli -h ip 使用redis工具 工具地址&#xff1a;https://github.com/vulhub/redis-rogue-getshell 下载完成后&#xff0c;先进入RedisModulesSDK/exp/ 目录进行make操作 获得exp.so后可以进行…

Linux shell编程学习笔记26:stty(set tty)

之前我们探讨了Linux中的tty&#xff0c;tty命令的主要功能是显示当前使用的终端名称。 如果我们想进一步对tty进行设置&#xff0c;就要用到stty。 stty的功能&#xff1a;显示和修改终端特性&#xff08;Print or change terminal characteristics&#xff09;。 1 stty -…

【数据预处理2】数据预处理——数据标准化

数据标准化 1. 什么是标准化&#xff1f;   数据标准化是一个常用的数据预处理操作&#xff0c;目的是将不同规格的数据转换到统一规格或不同分布的数据转换到某个特定范围&#xff0c;以减少规模、特征、分布差异等对模型的影响。这种操作也叫作无量纲化。   除了用作模型…

【Dynamic-datasource】Springboot多数据源整合

引入依赖&#xff1a; <dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.5.0</version> </dependency> 整体pom文件&#xff1a; <?xml versi…

SpringBoot 整合 Freemarker

通过 Freemarker 模版&#xff0c;我们可以将数据渲染成 HTML 网页、电子邮件、配置文件以及源代码等。 Freemarker 不是面向最终用户的&#xff0c;而是一个 Java 类库&#xff0c;我们可以将之作为一个普通的组件嵌入到我们的产品中。 Freemarker 模版后缀为 .ftl(FreeMarke…

【音视频基础】AVI文件格式

AVI文件采用的是RIFF文件结构方式。波形音频wave&#xff0c;MIDI和数字视频AVI都采用这种格式存储。 AVI文件的整体结构如下图所示 构造RIFF文件的基本单元叫做数据块&#xff08;Chunk&#xff09;&#xff0c;每个数据块包含3个部分 4字节的数据块标记&#xff08;或者叫…

2023-11-18 Android Linux资源限制命令 ulimit,比如ulimit -d 是设置进程占用的最大数据段大小,默认是unlimited。

一、通过ulimit -a 命令可以查看当前的各种资源限制&#xff0c;比如ulimit -d 是 进程占用的最大数据段大小。 # ulimit -a -t: time(cpu-seconds) unlimited -f: file(blocks) unlimited -c: coredump(blocks) 0 -d: data(KiB) unlimited -s:…

学习.NET验证模块FluentValidation的基本用法

开源博客项目Blog .NET中使用FluentValidation验证部分对象实例的属性值&#xff0c;本文学习FluentValidation模块的基本用法&#xff0c;后续再学习Blog .NET项目FluentValidation模块的用法。   FluentValidation模块支持Linq 表达式&#xff0c;同时支持链式操作&#xf…

【Linux】进程间通信 -- 共享内存

共享内存 共享内存是SystemV标准进程间通信的一种&#xff0c;该标准还有消息队列和信号量&#xff0c;但下文主要介绍共享内存&#xff0c;然后在谈一下信号量的内容。SystemV标准的进程间通信可以看做单机版的进程间通信。 // 1. log.hpp #pragma once#include <iostrea…

100张照片带你了解真实的日本人

欢迎关注「苏南下」 在这里分享我的旅行和影像创作心得 今年三个月内去了两次日本旅行&#xff0c;到了东京、横滨、大阪、京都、奈良、富士山、神户、富士山等城市&#xff0c;途中一共拍下了10000张照片。 最近整理照片的过程中&#xff0c;发现也拍了许多有意思的人像照&…

〖大前端 - 基础入门三大核心之JS篇㊲〗- DOM改变元素节点的css样式、HTML属性

说明&#xff1a;该文属于 大前端全栈架构白宝书专栏&#xff0c;目前阶段免费&#xff0c;如需要项目实战或者是体系化资源&#xff0c;文末名片加V&#xff01;作者&#xff1a;不渴望力量的哈士奇(哈哥)&#xff0c;十余年工作经验, 从事过全栈研发、产品经理等工作&#xf…

应用场景丨迭代市政综合管廊监测系统建设

市政综合管廊是指在城市地下建造的隧道空间&#xff0c;将市政、电力、通讯、燃气、给排水等各种管线集于一体&#xff0c;实施统一规划、设计、建设和管理。综合管廊有利于解决反复开挖路面、架空线网密集、管线事故频发等问题&#xff0c;是保障城市运行的重要基础设施和“生…