-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced eeprom module, along with:
>Changed the linker flag to have multiplication possible >Changed the build script to reuse the same command to build emulator and flash target
- Loading branch information
Abhijith Sriram
committed
Oct 11, 2024
1 parent
a35c69a
commit 2df281f
Showing
13 changed files
with
107 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 1,4 @@ | ||
vsCode_workspace.code-workspace | ||
out/ | ||
.vscode/ | ||
.vscode/ | ||
eeprom.hex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 1,24 @@ | ||
#include "utils.h" | ||
#include "pin.h" | ||
#include "eeprom.h" | ||
|
||
#define LED_DELAY (uint16_t)300 | ||
#define DELAY_TIMER (uint8_t)10 | ||
#define DELAY_ADDRESS (uint16_t)0x5FU | ||
|
||
int main() | ||
{ | ||
/* Configure pin PB5 to output*/ | ||
Configure_pinPort(PORTB, (uint8_t)PINB5, OUTPUT); | ||
uint8_t delay_timer = (uint8_t)30; | ||
|
||
/* The main loop for the application */ | ||
while(1) | ||
{ | ||
Write_pin(PORTB, (uint8_t)PINB5, PIN_HIGH); | ||
Delay_ms(LED_DELAY); | ||
Delay_ms((uint16_t)(delay_timer * 10U)); | ||
Write_pin(PORTB, (uint8_t)PINB5, PIN_LOW); | ||
Delay_ms(LED_DELAY); | ||
Delay_ms((uint16_t)(delay_timer * 10U)); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,7 @@ | ||
cmake_minimum_required(VERSION 3.25.0) | ||
|
||
message("Building EEPROM") | ||
set(SOURCES eeprom.c) | ||
set(HEADERS eeprom.h) | ||
add_library(EEPROM STATIC eeprom.c) | ||
set_target_properties(EEPROM PROPERTIES FOLDER "lib/eeprom") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,43 @@ | ||
#include "eeprom.h" | ||
|
||
void ReadFromMemory(uint16_t memory_address, uint8_t* data_read) | ||
{ | ||
/* Make sure there are no current writing operations going on */ | ||
while (GetEepeValue() == (uint8_t)1) | ||
{ | ||
/* Wait for eepe value to go to zero */ | ||
} | ||
*EEAR = memory_address; | ||
*(EECR) |= (1<<EERE); | ||
*data_read = *EEDR; | ||
} | ||
|
||
void WriteToMemory(uint16_t memory_address, uint8_t data_toWrite) | ||
{ | ||
|
||
/* Make sure there are no current writing operations going on */ | ||
while (GetEepeValue() == (uint8_t)1) | ||
{ | ||
/* Wait for eepe value to go to zero */ | ||
} | ||
|
||
/* Write the address and data to the appropriate registers */ | ||
*EEAR = memory_address; | ||
*EEDR = data_toWrite; | ||
|
||
/* Set value to the control register. Maintain this order! */ | ||
*(EECR) |= (1<<EEMPE); | ||
*(EECR) |= (1<<EEPE); | ||
|
||
while (GetEepeValue() == (uint8_t)1) | ||
{ | ||
/* Wait for eepe value to go to zero */ | ||
} | ||
} | ||
|
||
static uint8_t GetEepeValue() | ||
{ | ||
uint8_t eepe_mask = ((uint8_t) 1 << EEPE); | ||
uint8_t eepe_value = (*(EECR) & eepe_mask) >> EEPE; | ||
return eepe_value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,17 @@ | ||
#ifndef __EEPROM__ | ||
#define __EEPROM__ | ||
|
||
#include <stdint.h> | ||
|
||
#define EEAR ((uint16_t*)0x41U) /* Register containing the memory address to be read or write */ | ||
#define EEDR ((uint8_t*)0x40U) /* Register containing the data to be read or written */ | ||
#define EECR ((uint8_t*)0x3FU) /* Register to indicate reading or writing operation to eeprom */ | ||
#define EEMPE (uint8_t)2 | ||
#define EEPE (uint8_t)1 | ||
#define EERE (uint8_t)0 | ||
|
||
void ReadFromMemory(uint16_t memory_address, uint8_t* data_read); | ||
void WriteToMemory(uint16_t memory_address, uint8_t data_toWrite); | ||
static uint8_t GetEepeValue(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,5 @@ | ||
@echo off | ||
SETLOCAL EnableDelayedExpansion | ||
cls | ||
@REM https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/ | ||
"C:\Program Files (x86)\WinAVR\bin\avrdude.exe" -C "C:\Program Files (x86)\WinAVR\bin\avrdude.conf" -v -p ATmega328P -P COM3 -c arduino -b 115200 -D -U eeprom:w:eeprom.hex:i |