upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Macros | Typedefs | Enumerations
Include dependency graph for m24lr64e.h:

API Description

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "m24lr64e.h"
#include "upm_utilities.h"
int main()
{
m24lr64e_context dev = m24lr64e_init(0, M24LR64E_USER_MODE);
int addr = M24LR64E_EEPROM_I2C_LENGTH-1;
printf("address being accessed: %d\n", addr);
uint8_t byte;
if(m24lr64e_read_byte(dev, addr, &byte) != UPM_SUCCESS)
printf("error while reading value\n");
printf("value read from the device: %d\n", byte);
byte = ~byte;
printf("byte to be written: %d\n", byte);
if(m24lr64e_write_byte(dev, addr, byte) != UPM_SUCCESS)
printf("error while writing byte to the device\n");
uint8_t var;
if(m24lr64e_read_byte(dev, addr, &var) != UPM_SUCCESS)
printf("error while reading value back\n");
printf("new value at %d: %d\n", addr, var);
printf("all done!!\n");
return 0;
}

Go to the source code of this file.

Data Structures

struct  _m24lr64e_context
 

Functions

m24lr64e_context m24lr64e_init (int bus, m24lr64e_access_mode mode)
 
void m24lr64e_close (m24lr64e_context dev)
 
upm_result_t m24lr64e_submit_password (m24lr64e_context dev, uint32_t password)
 
upm_result_t m24lr64e_write_password (m24lr64e_context dev, uint32_t password)
 
upm_result_t m24lr64e_sector_protect_config (m24lr64e_context dev, uint32_t sector_number, bool protect_enable, sector_access_right access_right, sector_select_password password)
 
upm_result_t m24lr64e_clear_sector_protect (m24lr64e_context dev)
 
upm_result_t m24lr64e_sector_write_lock_bit (m24lr64e_context dev, uint32_t sector_number, bool sock_enable)
 
upm_result_t m24lr64e_get_dsfid (m24lr64e_context dev, uint8_t *dsfid)
 
upm_result_t m24lr64e_get_afi (m24lr64e_context dev, uint8_t *afi)
 
upm_result_t m24lr64e_get_uid (m24lr64e_context dev, uint8_t *uid)
 
upm_result_t m24lr64e_get_memory_size (m24lr64e_context dev, uint32_t *memory_size)
 
upm_result_t m24lr64e_clear_memory (m24lr64e_context dev)
 
upm_result_t m24lr64e_write_byte (m24lr64e_context dev, uint32_t address, uint8_t data)
 
upm_result_t m24lr64e_write_bytes (m24lr64e_context dev, uint32_t address, uint8_t *buffer, int len)
 
upm_result_t m24lr64e_read_byte (m24lr64e_context dev, uint32_t address, uint8_t *data)
 
upm_result_t m24lr64e_read_bytes (m24lr64e_context dev, uint32_t address, uint8_t *buffer, int len)
 

Macros

#define M24LR64E_I2C_BUS   0
 
#define M24LR64E_DEFAULT_I2C_ADDR   0x53
 
#define M24LR64E_DEFAULT_I2C_ADDR_E2   (M24LR64E_DEFAULT_I2C_ADDR | 0x04)
 
#define M24LR64E_EEPROM_I2C_LENGTH   8192
 
#define M24LR64E_PASSWORD_LENGTH   4
 
#define M24LR64E_SECTOR_SECURITY_STATUS_BASE_ADDR   0x800
 
#define M24LR64E_LOCK_PROTECT_BIT   0x01
 
#define M24LR64E_WRITE_READ_PROTECT_BIT   0x02
 
#define M24LR64E_PASSWORD_CTRL_BIT   0x04
 
#define M24LR64E_UID_LENGTH   8
 
#define M24LR64E_I2C_WRITE_TIME   5
 

Typedefs

typedef struct _m24lr64e_contextm24lr64e_context
 

Enumerations

enum  M24LR64E_ADDR_T {
  M24LR64E_I2C_PASSWORD_ADDRESS = 2304, M24LR64E_RF_PASSWORD_1_ADDRESS = 2308, M24LR64E_RF_PASSWORD_2_ADDRESS = 2312, M24LR64E_RF_PASSWORD_3_ADDRESS = 2316,
  M24LR64E_DSFID_ADDRESS = 2320, M24LR64E_AFI_ADDRESS = 2321, M24LR64E_RESV_ADDRESS = 2322, M24LR64E_CONFIG_ADDRESS = 2323,
  M24LR64E_UID_ADDRESS = 2324, M24LR64E_MEM_SIZE_ADDRESS = 2332, M24LR64E_IC_REF_ADDRESS = 2335, M24LR64E_PROG_COMP_ENERGY_HARVEST_ADDRESS = 2339
}
 
enum  m24lr64e_access_mode { M24LR64E_USER_MODE = 0x0, M24LR64E_ROOT_MODE = 0x1 }
 
enum  sector_access_right { m24lr64e_access_1110 = 0, m24lr64e_access_1111 = 1, m24lr64e_access_1100 = 2, m24lr64e_access_0111 = 3 }
 
enum  sector_select_password { m24lr64e_no_password = 0, m24lr64e_password_1 = 1, m24lr64e_password_2 = 2, m24lr64e_password_3 = 3 }
 

Function Documentation

m24lr64e_context m24lr64e_init ( int  bus,
m24lr64e_access_mode  mode 
)

M24LR64E Init function

Parameters
busI2C bus to use
modeAccess mode (user or root) to use
void m24lr64e_close ( m24lr64e_context  dev)

M24LR64E close function

Parameters
devvoid pointer to sensor struct
upm_result_t m24lr64e_submit_password ( m24lr64e_context  dev,
uint32_t  password 
)

Submits an I2C access password

Parameters
devvoid pointer to sensor struct
passwd4-byte access password
upm_result_t m24lr64e_write_password ( m24lr64e_context  dev,
uint32_t  password 
)

Writes a new I2C password

Parameters
devvoid pointer to sensor struct
passwd4-byte access password
upm_result_t m24lr64e_sector_protect_config ( m24lr64e_context  dev,
uint32_t  sector_number,
bool  protect_enable,
sector_access_right  access_right,
sector_select_password  password 
)

Sets a protection bit for a sector. Must be in the root mode

Parameters
devvoid pointer to sensor struct
sectorNumberSector whose protection you are modifying
protectEnableTrue if you are enabling protection
accessRightAccess rights to set
passwdPassword number to enable, if any

Here is the call graph for this function:

upm_result_t m24lr64e_clear_sector_protect ( m24lr64e_context  dev)

Clears sector protection bits. Must be in the root mode.

Parameters
devvoid pointer to sensor struct
upm_result_t m24lr64e_sector_write_lock_bit ( m24lr64e_context  dev,
uint32_t  sector_number,
bool  sock_enable 
)

Sets or clears a sector security status lock bit for a sector. Must be in the root mode.

Parameters
devvoid pointer to sensor struct
sectorNumberSector whose SSS you want to modify
sockEnableTrue to set the bit, false to clear it

Here is the call graph for this function:

upm_result_t m24lr64e_get_dsfid ( m24lr64e_context  dev,
uint8_t *  dsfid 
)

Returns a data storage family identifier (DSFID) Must be in the root mode.

Parameters
devvoid pointer to sensor struct
dsfidpointer to hold return value
upm_result_t m24lr64e_get_afi ( m24lr64e_context  dev,
uint8_t *  afi 
)

Returns an application family identifier (AFI) Must be in the root mode.

Parameters
devvoid pointer to sensor struct
afipointer to hold return value
upm_result_t m24lr64e_get_uid ( m24lr64e_context  dev,
uint8_t *  uid 
)

Returns a unique ID. Must be in the root mode. Maintained to preserve compatibility with older code.

Parameters
devvoid pointer to sensor struct
uidpointer to hold return value
upm_result_t m24lr64e_get_memory_size ( m24lr64e_context  dev,
uint32_t *  memory_size 
)

Returns the memory size Must be in the root mode.

Parameters
devvoid pointer to sensor struct
memory_sizepointer to hold return value
upm_result_t m24lr64e_clear_memory ( m24lr64e_context  dev)

Sets all memory to 0, if permissions allow

Parameters
devvoid pointer to sensor struct

Here is the call graph for this function:

upm_result_t m24lr64e_write_byte ( m24lr64e_context  dev,
uint32_t  address,
uint8_t  data 
)

Writes a byte to the EEPROM

Parameters
devvoid pointer to sensor struct
addressAddress to write to
dataData to write

Here is the caller graph for this function:

upm_result_t m24lr64e_write_bytes ( m24lr64e_context  dev,
uint32_t  address,
uint8_t *  buffer,
int  len 
)

Writes bytes to the EEPROM

Parameters
devvoid pointer to sensor struct
addressAddress to write to
dataData to write
dataLength of the data buffer
upm_result_t m24lr64e_read_byte ( m24lr64e_context  dev,
uint32_t  address,
uint8_t *  data 
)

Reads a byte from the EEPROM

Parameters
devvoid pointer to sensor struct
addressAddress to read from
dataholds return value
upm_result_t m24lr64e_read_bytes ( m24lr64e_context  dev,
uint32_t  address,
uint8_t *  buffer,
int  len 
)

Reads multiple bytes from the EEPROM

Parameters
devvoid pointer to sensor struct
addressAddress to read from
bufferBuffer to store data
lenNumber of bytes to read