Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
ec643130
Commit
ec643130
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
stm: add timer to storage cache so it can be flushed.
parent
318aec6b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stm/storage.c
+9
-0
9 additions, 0 deletions
stm/storage.c
stm/storage.h
+1
-0
1 addition, 0 deletions
stm/storage.h
with
10 additions
and
0 deletions
stm/storage.c
+
9
−
0
View file @
ec643130
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include
"std.h"
#include
"std.h"
#include
"misc.h"
#include
"misc.h"
#include
"systick.h"
#include
"led.h"
#include
"led.h"
#include
"flash.h"
#include
"flash.h"
#include
"storage.h"
#include
"storage.h"
...
@@ -17,6 +18,7 @@ static uint32_t cache_flash_sector_id;
...
@@ -17,6 +18,7 @@ static uint32_t cache_flash_sector_id;
static
uint32_t
cache_flash_sector_start
;
static
uint32_t
cache_flash_sector_start
;
static
uint32_t
cache_flash_sector_size
;
static
uint32_t
cache_flash_sector_size
;
static
bool
cache_dirty
;
static
bool
cache_dirty
;
static
uint32_t
sys_tick_counter_last_write
;
static
void
cache_flush
(
void
)
{
static
void
cache_flush
(
void
)
{
if
(
cache_dirty
)
{
if
(
cache_dirty
)
{
...
@@ -50,6 +52,7 @@ void storage_init(void) {
...
@@ -50,6 +52,7 @@ void storage_init(void) {
cache_flash_sector_id
=
0
;
cache_flash_sector_id
=
0
;
cache_dirty
=
false
;
cache_dirty
=
false
;
is_initialised
=
true
;
is_initialised
=
true
;
sys_tick_counter_last_write
=
0
;
}
}
}
}
...
@@ -61,6 +64,11 @@ uint32_t storage_get_block_count(void) {
...
@@ -61,6 +64,11 @@ uint32_t storage_get_block_count(void) {
return
FLASH_PART1_START_BLOCK
+
FLASH_PART1_NUM_BLOCKS
;
return
FLASH_PART1_START_BLOCK
+
FLASH_PART1_NUM_BLOCKS
;
}
}
bool
storage_needs_flush
(
void
)
{
// wait 2 seconds after last write to flush
return
cache_dirty
&&
sys_tick_has_passed
(
sys_tick_counter_last_write
,
2000
);
}
void
storage_flush
(
void
)
{
void
storage_flush
(
void
)
{
cache_flush
();
cache_flush
();
}
}
...
@@ -143,6 +151,7 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
...
@@ -143,6 +151,7 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
uint32_t
flash_addr
=
FLASH_MEM_START_ADDR
+
(
block
-
FLASH_PART1_START_BLOCK
)
*
BLOCK_SIZE
;
uint32_t
flash_addr
=
FLASH_MEM_START_ADDR
+
(
block
-
FLASH_PART1_START_BLOCK
)
*
BLOCK_SIZE
;
uint8_t
*
dest
=
cache_get_addr_for_write
(
flash_addr
);
uint8_t
*
dest
=
cache_get_addr_for_write
(
flash_addr
);
memcpy
(
dest
,
src
,
BLOCK_SIZE
);
memcpy
(
dest
,
src
,
BLOCK_SIZE
);
sys_tick_counter_last_write
=
sys_tick_counter
;
return
true
;
return
true
;
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
stm/storage.h
+
1
−
0
View file @
ec643130
void
storage_init
(
void
);
void
storage_init
(
void
);
uint32_t
storage_get_block_size
(
void
);
uint32_t
storage_get_block_size
(
void
);
uint32_t
storage_get_block_count
(
void
);
uint32_t
storage_get_block_count
(
void
);
bool
storage_needs_flush
(
void
);
void
storage_flush
(
void
);
void
storage_flush
(
void
);
bool
storage_read_block
(
uint8_t
*
dest
,
uint32_t
block
);
bool
storage_read_block
(
uint8_t
*
dest
,
uint32_t
block
);
bool
storage_write_block
(
const
uint8_t
*
src
,
uint32_t
block
);
bool
storage_write_block
(
const
uint8_t
*
src
,
uint32_t
block
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment