Skip to content

Commit

Permalink
added EEPROM
Browse files Browse the repository at this point in the history
  • Loading branch information
1brahimmohamed committed Nov 4, 2022
1 parent 70fc043 commit 236205b
Show file tree
Hide file tree
Showing 14 changed files with 1,264 additions and 0 deletions.
115 changes: 115 additions & 0 deletions EEPROM/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="de.innot.avreclipse.configuration.app.debug.1326139227">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.debug.1326139227" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" description="" id="de.innot.avreclipse.configuration.app.debug.1326139227" name="Debug" parent="de.innot.avreclipse.configuration.app.debug">
<folderInfo id="de.innot.avreclipse.configuration.app.debug.1326139227." name="/" resourcePath="">
<toolChain id="de.innot.avreclipse.toolchain.winavr.app.debug.626614867" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.debug">
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug.483772337" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.debug.1056406617" name="Generate HEX file for EEPROM" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.debug"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.debug.186711980" name="Generate Extended Listing (Source + generated Assembler)" superClass="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.debug"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.size.app.debug.358588289" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size.app.debug"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.debug.1522197594" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.debug"/>
<targetPlatform id="de.innot.avreclipse.targetplatform.winavr.app.debug.1619878696" name="AVR Cross-Target" superClass="de.innot.avreclipse.targetplatform.winavr.app.debug"/>
<builder buildPath="${workspace_loc:/EEPROM}/Debug" id="de.innot.avreclipse.target.builder.winavr.app.debug.509026117" managedBuildOn="true" name="AVR GNU Make Builder.Debug" superClass="de.innot.avreclipse.target.builder.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.assembler.winavr.app.debug.2019202502" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.app.debug">
<option id="de.innot.avreclipse.assembler.option.debug.level.1568410825" superClass="de.innot.avreclipse.assembler.option.debug.level"/>
</tool>
<tool id="de.innot.avreclipse.tool.compiler.winavr.app.debug.1312317326" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.debug">
<option id="de.innot.avreclipse.compiler.option.debug.level.80925140" superClass="de.innot.avreclipse.compiler.option.debug.level"/>
<option id="de.innot.avreclipse.compiler.option.optimize.231900584" superClass="de.innot.avreclipse.compiler.option.optimize"/>
</tool>
<tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.1553574579" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug">
<option id="de.innot.avreclipse.cppcompiler.option.debug.level.1000869519" superClass="de.innot.avreclipse.cppcompiler.option.debug.level"/>
<option id="de.innot.avreclipse.cppcompiler.option.optimize.1521509152" superClass="de.innot.avreclipse.cppcompiler.option.optimize"/>
</tool>
<tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.1306853982" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.cpplinker.app.debug.818194373" name="AVR C++ Linker" superClass="de.innot.avreclipse.tool.cpplinker.app.debug"/>
<tool id="de.innot.avreclipse.tool.archiver.winavr.base.411119367" name="AVR Archiver" superClass="de.innot.avreclipse.tool.archiver.winavr.base"/>
<tool id="de.innot.avreclipse.tool.objdump.winavr.app.debug.452000901" name="AVR Create Extended Listing" superClass="de.innot.avreclipse.tool.objdump.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.objcopy.flash.winavr.app.debug.519287040" name="AVR Create Flash image" superClass="de.innot.avreclipse.tool.objcopy.flash.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.debug.55321373" name="AVR Create EEPROM image" superClass="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.size.winavr.app.debug.1448040294" name="Print Size" superClass="de.innot.avreclipse.tool.size.winavr.app.debug"/>
<tool id="de.innot.avreclipse.tool.avrdude.app.debug.1672466287" name="AVRDude" superClass="de.innot.avreclipse.tool.avrdude.app.debug"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="de.innot.avreclipse.configuration.app.release.1537297900">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.1537297900" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" description="" id="de.innot.avreclipse.configuration.app.release.1537297900" name="Release" parent="de.innot.avreclipse.configuration.app.release">
<folderInfo id="de.innot.avreclipse.configuration.app.release.1537297900." name="/" resourcePath="">
<toolChain id="de.innot.avreclipse.toolchain.winavr.app.release.1572195171" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.release">
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release.1125043915" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release.1405188419" name="Generate HEX file for EEPROM" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release.818741122" name="Generate Extended Listing (Source + generated Assembler)" superClass="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.size.app.release.136603898" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size.app.release"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release.1864305536" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release"/>
<targetPlatform id="de.innot.avreclipse.targetplatform.winavr.app.release.1579367801" name="AVR Cross-Target" superClass="de.innot.avreclipse.targetplatform.winavr.app.release"/>
<builder buildPath="${workspace_loc:/EEPROM}/Release" id="de.innot.avreclipse.target.builder.winavr.app.release.1218407645" managedBuildOn="true" name="AVR GNU Make Builder.Release" superClass="de.innot.avreclipse.target.builder.winavr.app.release"/>
<tool id="de.innot.avreclipse.tool.assembler.winavr.app.release.1030679897" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.app.release">
<option id="de.innot.avreclipse.assembler.option.debug.level.307192264" superClass="de.innot.avreclipse.assembler.option.debug.level" value="de.innot.avreclipse.assembler.option.debug.level.none" valueType="enumerated"/>
<inputType id="de.innot.avreclipse.tool.assembler.input.706382614" superClass="de.innot.avreclipse.tool.assembler.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.212808315" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release">
<option id="de.innot.avreclipse.compiler.option.debug.level.1728649588" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/>
<option id="de.innot.avreclipse.compiler.option.optimize.560104103" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/>
<inputType id="de.innot.avreclipse.compiler.winavr.input.558003330" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.cppcompiler.app.release.1579246053" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release">
<option id="de.innot.avreclipse.cppcompiler.option.debug.level.2118818255" superClass="de.innot.avreclipse.cppcompiler.option.debug.level" value="de.innot.avreclipse.cppcompiler.option.debug.level.none" valueType="enumerated"/>
<option id="de.innot.avreclipse.cppcompiler.option.optimize.141768805" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/>
</tool>
<tool id="de.innot.avreclipse.tool.linker.winavr.app.release.1014577341" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release">
<inputType id="de.innot.avreclipse.tool.linker.input.1265475755" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="de.innot.avreclipse.tool.cpplinker.app.release.493637560" name="AVR C++ Linker" superClass="de.innot.avreclipse.tool.cpplinker.app.release"/>
<tool id="de.innot.avreclipse.tool.archiver.winavr.base.960305207" name="AVR Archiver" superClass="de.innot.avreclipse.tool.archiver.winavr.base"/>
<tool id="de.innot.avreclipse.tool.objdump.winavr.app.release.509991140" name="AVR Create Extended Listing" superClass="de.innot.avreclipse.tool.objdump.winavr.app.release"/>
<tool id="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release.1050316308" name="AVR Create Flash image" superClass="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release"/>
<tool id="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release.1262425225" name="AVR Create EEPROM image" superClass="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release"/>
<tool id="de.innot.avreclipse.tool.size.winavr.app.release.1708074963" name="Print Size" superClass="de.innot.avreclipse.tool.size.winavr.app.release"/>
<tool id="de.innot.avreclipse.tool.avrdude.app.release.1368805177" name="AVRDude" superClass="de.innot.avreclipse.tool.avrdude.app.release"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="EEPROM.de.innot.avreclipse.project.winavr.elf_2.1.0.2000067572" name="AVR Cross Target Application" projectType="de.innot.avreclipse.project.winavr.elf_2.1.0"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.1537297900;de.innot.avreclipse.configuration.app.release.1537297900.;de.innot.avreclipse.tool.compiler.winavr.app.release.212808315;de.innot.avreclipse.compiler.winavr.input.558003330">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
27 changes: 27 additions & 0 deletions EEPROM/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EEPROM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions EEPROM/.settings/de.innot.avreclipse.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
avrtarget/ClockFrequency=1000000
avrtarget/ExtRAMSize=0
avrtarget/ExtendedRAM=false
avrtarget/MCUType=atmega32
avrtarget/UseEEPROM=false
avrtarget/UseExtendedRAMforHeap=true
eclipse.preferences.version=1
2 changes: 2 additions & 0 deletions EEPROM/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
34 changes: 34 additions & 0 deletions EEPROM/src/common_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
*
* Module: Common - Macros
* File Name: Common_Macros.h
* Description: Commonly used Macros
* Author: Ibrahim Mohamed
*
*******************************************************************************/

#ifndef COMMON_MACROS
#define COMMON_MACROS

/* Set a certain bit in any register */
#define SET_BIT(REG,BIT) (REG|=(1<<BIT))

/* Clear a certain bit in any register */
#define CLEAR_BIT(REG,BIT) (REG&=(~(1<<BIT)))

/* Toggle a certain bit in any register */
#define TOGGLE_BIT(REG,BIT) (REG^=(1<<BIT))

/* Rotate right the register value with specific number of rotates */
#define ROR(REG,num) ( REG= (REG>>num) | (REG<<(8-num)) )

/* Rotate left the register value with specific number of rotates */
#define ROL(REG,num) ( REG= (REG<<num) | (REG>>(8-num)) )

/* Check if a specific bit is set in any register and return true if yes */
#define BIT_IS_SET(REG,BIT) ( REG & (1<<BIT) )

/* Check if a specific bit is cleared in any register and return true if yes */
#define BIT_IS_CLEAR(REG,BIT) ( !(REG & (1<<BIT)) )

#endif
79 changes: 79 additions & 0 deletions EEPROM/src/external_eeprom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/******************************************************************************
*
* Module: External EEPROM
* File Name: external_eeprom.c
* Description: Source file for the External EEPROM Memory
* Author: Ibrahim Mohamed
*
*******************************************************************************/
#include "external_eeprom.h"
#include "twi.h"

uint8 EEPROM_writeByte(uint16 u16addr, uint8 u8data)
{
/* Send the Start Bit */
TWI_start();
if (TWI_getStatus() != TWI_START)
return ERROR;

/* Send the device address, we need to get A8 A9 A10 address bits from the
* memory location address and R/W=0 (write) */
TWI_writeByte((uint8)(0xA0 | ((u16addr & 0x0700)>>7)));
if (TWI_getStatus() != TWI_MT_SLA_W_ACK)
return ERROR;

/* Send the required memory location address */
TWI_writeByte((uint8)(u16addr));
if (TWI_getStatus() != TWI_MT_DATA_ACK)
return ERROR;

/* write byte to eeprom */
TWI_writeByte(u8data);
if (TWI_getStatus() != TWI_MT_DATA_ACK)
return ERROR;

/* Send the Stop Bit */
TWI_stop();

return SUCCESS;
}

uint8 EEPROM_readByte(uint16 u16addr, uint8 *u8data)
{
/* Send the Start Bit */
TWI_start();
if (TWI_getStatus() != TWI_START)
return ERROR;

/* Send the device address, we need to get A8 A9 A10 address bits from the
* memory location address and R/W=0 (write) */
TWI_writeByte((uint8)((0xA0) | ((u16addr & 0x0700)>>7)));
if (TWI_getStatus() != TWI_MT_SLA_W_ACK)
return ERROR;

/* Send the required memory location address */
TWI_writeByte((uint8)(u16addr));
if (TWI_getStatus() != TWI_MT_DATA_ACK)
return ERROR;

/* Send the Repeated Start Bit */
TWI_start();
if (TWI_getStatus() != TWI_REP_START)
return ERROR;

/* Send the device address, we need to get A8 A9 A10 address bits from the
* memory location address and R/W=1 (Read) */
TWI_writeByte((uint8)((0xA0) | ((u16addr & 0x0700)>>7) | 1));
if (TWI_getStatus() != TWI_MT_SLA_R_ACK)
return ERROR;

/* Read Byte from Memory without send ACK */
*u8data = TWI_readByteWithNACK();
if (TWI_getStatus() != TWI_MR_DATA_NACK)
return ERROR;

/* Send the Stop Bit */
TWI_stop();

return SUCCESS;
}
32 changes: 32 additions & 0 deletions EEPROM/src/external_eeprom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
*
* Module: External EEPROM
*
* File Name: external_eeprom.h
*
* Description: Header file for the External EEPROM Memory
*
* Author: Mohamed Tarek
*
*******************************************************************************/


#ifndef EXTERNAL_EEPROM_H_
#define EXTERNAL_EEPROM_H_

#include "std_types.h"

/*******************************************************************************
* Preprocessor Macros *
*******************************************************************************/
#define ERROR 0
#define SUCCESS 1

/*******************************************************************************
* Functions Prototypes *
*******************************************************************************/

uint8 EEPROM_writeByte(uint16 u16addr,uint8 u8data);
uint8 EEPROM_readByte(uint16 u16addr,uint8 *u8data);

#endif /* EXTERNAL_EEPROM_H_ */
Loading

0 comments on commit 236205b

Please sign in to comment.