Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Ardupilot
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenSource
Ardupilot
Commits
22c8db77
Commit
22c8db77
authored
13 years ago
by
Andrew Tridgell
Browse files
Options
Downloads
Patches
Plain Diff
desktop: fixed for new DataFlash inheritance
parent
dd26ef30
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/Desktop/support/DataFlash_APM1.cpp
+1
-188
1 addition, 188 deletions
libraries/Desktop/support/DataFlash_APM1.cpp
with
1 addition
and
188 deletions
libraries/Desktop/support/DataFlash_APM1.cpp
+
1
−
188
View file @
22c8db77
...
@@ -17,8 +17,6 @@
...
@@ -17,8 +17,6 @@
static
int
flash_fd
;
static
int
flash_fd
;
static
uint8_t
buffer
[
2
][
DF_PAGE_SIZE
];
static
uint8_t
buffer
[
2
][
DF_PAGE_SIZE
];
#define OVERWRITE_DATA 1 // 0: When reach the end page stop, 1: Start overwritten from page 1
// Public Methods //////////////////////////////////////////////////////////////
// Public Methods //////////////////////////////////////////////////////////////
void
DataFlash_APM1
::
Init
(
void
)
void
DataFlash_APM1
::
Init
(
void
)
{
{
...
@@ -34,10 +32,7 @@ void DataFlash_APM1::Init(void)
...
@@ -34,10 +32,7 @@ void DataFlash_APM1::Init(void)
}
}
}
}
df_PageSize
=
DF_PAGE_SIZE
;
df_PageSize
=
DF_PAGE_SIZE
;
df_BufferNum
=
1
;
df_NumPages
=
DF_NUM_PAGES
;
df_BufferIdx
=
0
;
df_PageAdr
=
0
;
df_Stop_Write
=
0
;
}
}
// This function is mainly to test the device
// This function is mainly to test the device
...
@@ -112,187 +107,5 @@ void DataFlash_APM1::ChipErase ()
...
@@ -112,187 +107,5 @@ void DataFlash_APM1::ChipErase ()
}
}
}
}
// *** DATAFLASH PUBLIC FUNCTIONS ***
void
DataFlash_APM1
::
StartWrite
(
int16_t
PageAdr
)
{
df_BufferNum
=
1
;
df_BufferIdx
=
4
;
df_PageAdr
=
PageAdr
;
df_Stop_Write
=
0
;
WaitReady
();
// We are starting a new page - write FileNumber and FilePage
BufferWrite
(
df_BufferNum
,
0
,
df_FileNumber
>>
8
);
// High byte
BufferWrite
(
df_BufferNum
,
1
,
df_FileNumber
&
0xFF
);
// Low byte
BufferWrite
(
df_BufferNum
,
2
,
df_FilePage
>>
8
);
// High byte
BufferWrite
(
df_BufferNum
,
3
,
df_FilePage
&
0xFF
);
// Low byte
}
void
DataFlash_APM1
::
FinishWrite
(
void
)
{
df_BufferIdx
=
0
;
BufferToPage
(
df_BufferNum
,
df_PageAdr
,
0
);
// Write Buffer to memory, NO WAIT
df_PageAdr
++
;
if
(
OVERWRITE_DATA
==
1
)
{
if
(
df_PageAdr
>
DF_LAST_PAGE
)
// If we reach the end of the memory, start from the begining
df_PageAdr
=
1
;
}
else
{
if
(
df_PageAdr
>
DF_LAST_PAGE
)
// If we reach the end of the memory, stop here
df_Stop_Write
=
1
;
}
if
(
df_BufferNum
==
1
)
// Change buffer to continue writing...
df_BufferNum
=
2
;
else
df_BufferNum
=
1
;
}
void
DataFlash_APM1
::
WriteByte
(
byte
data
)
{
if
(
!
df_Stop_Write
)
{
BufferWrite
(
df_BufferNum
,
df_BufferIdx
,
data
);
df_BufferIdx
++
;
if
(
df_BufferIdx
>=
df_PageSize
)
// End of buffer?
{
df_BufferIdx
=
4
;
//(4 bytes for FileNumber, FilePage)
BufferToPage
(
df_BufferNum
,
df_PageAdr
,
0
);
// Write Buffer to memory, NO WAIT
df_PageAdr
++
;
if
(
OVERWRITE_DATA
==
1
)
{
if
(
df_PageAdr
>
DF_LAST_PAGE
)
// If we reach the end of the memory, start from the begining
df_PageAdr
=
1
;
}
else
{
if
(
df_PageAdr
>
DF_LAST_PAGE
)
// If we reach the end of the memory, stop here
df_Stop_Write
=
1
;
}
if
(
df_BufferNum
==
1
)
// Change buffer to continue writing...
df_BufferNum
=
2
;
else
df_BufferNum
=
1
;
// We are starting a new page - write FileNumber and FilePage
BufferWrite
(
df_BufferNum
,
0
,
df_FileNumber
>>
8
);
// High byte
BufferWrite
(
df_BufferNum
,
1
,
df_FileNumber
&
0xFF
);
// Low byte
df_FilePage
++
;
BufferWrite
(
df_BufferNum
,
2
,
df_FilePage
>>
8
);
// High byte
BufferWrite
(
df_BufferNum
,
3
,
df_FilePage
&
0xFF
);
// Low byte
}
}
}
void
DataFlash_APM1
::
WriteInt
(
int16_t
data
)
{
WriteByte
(
data
>>
8
);
// High byte
WriteByte
(
data
&
0xFF
);
// Low byte
}
void
DataFlash_APM1
::
WriteLong
(
int32_t
data
)
{
WriteByte
(
data
>>
24
);
// First byte
WriteByte
(
data
>>
16
);
WriteByte
(
data
>>
8
);
WriteByte
(
data
&
0xFF
);
// Last byte
}
// Get the last page written to
int16_t
DataFlash_APM1
::
GetWritePage
()
{
return
(
df_PageAdr
);
}
// Get the last page read
int16_t
DataFlash_APM1
::
GetPage
()
{
return
(
df_Read_PageAdr
-
1
);
}
void
DataFlash_APM1
::
StartRead
(
int16_t
PageAdr
)
{
df_Read_BufferNum
=
1
;
df_Read_BufferIdx
=
4
;
df_Read_PageAdr
=
PageAdr
;
WaitReady
();
PageToBuffer
(
df_Read_BufferNum
,
df_Read_PageAdr
);
// Write Memory page to buffer
//Serial.print(df_Read_PageAdr, DEC); Serial.print("\t");
df_Read_PageAdr
++
;
// We are starting a new page - read FileNumber and FilePage
df_FileNumber
=
BufferRead
(
df_Read_BufferNum
,
0
);
// High byte
//Serial.print(df_FileNumber, DEC); Serial.print("\t");
df_FileNumber
=
(
df_FileNumber
<<
8
)
|
BufferRead
(
df_Read_BufferNum
,
1
);
// Low byte
//Serial.println(df_FileNumber, DEC); Serial.print("\t");
df_FilePage
=
BufferRead
(
df_Read_BufferNum
,
2
);
// High byte
df_FilePage
=
(
df_FilePage
<<
8
)
|
BufferRead
(
df_Read_BufferNum
,
3
);
// Low byte
}
byte
DataFlash_APM1
::
ReadByte
()
{
byte
result
;
WaitReady
();
result
=
BufferRead
(
df_Read_BufferNum
,
df_Read_BufferIdx
);
df_Read_BufferIdx
++
;
if
(
df_Read_BufferIdx
>=
df_PageSize
)
// End of buffer?
{
df_Read_BufferIdx
=
4
;
//(4 bytes for FileNumber, FilePage)
PageToBuffer
(
df_Read_BufferNum
,
df_Read_PageAdr
);
// Write memory page to Buffer
df_Read_PageAdr
++
;
if
(
df_Read_PageAdr
>
DF_LAST_PAGE
)
// If we reach the end of the memory, start from the begining
{
df_Read_PageAdr
=
0
;
df_Read_END
=
true
;
}
// We are starting a new page - read FileNumber and FilePage
df_FileNumber
=
BufferRead
(
df_Read_BufferNum
,
0
);
// High byte
df_FileNumber
=
(
df_FileNumber
<<
8
)
|
BufferRead
(
df_Read_BufferNum
,
1
);
// Low byte
df_FilePage
=
BufferRead
(
df_Read_BufferNum
,
2
);
// High byte
df_FilePage
=
(
df_FilePage
<<
8
)
|
BufferRead
(
df_Read_BufferNum
,
3
);
// Low byte
}
return
result
;
}
int16_t
DataFlash_APM1
::
ReadInt
()
{
uint16_t
result
;
result
=
ReadByte
();
// High byte
result
=
(
result
<<
8
)
|
ReadByte
();
// Low byte
return
(
int16_t
)
result
;
}
int32_t
DataFlash_APM1
::
ReadLong
()
{
uint32_t
result
;
result
=
ReadByte
();
// First byte
result
=
(
result
<<
8
)
|
ReadByte
();
result
=
(
result
<<
8
)
|
ReadByte
();
result
=
(
result
<<
8
)
|
ReadByte
();
// Last byte
return
(
int32_t
)
result
;
}
void
DataFlash_APM1
::
SetFileNumber
(
uint16_t
FileNumber
)
{
df_FileNumber
=
FileNumber
;
df_FilePage
=
1
;
}
uint16_t
DataFlash_APM1
::
GetFileNumber
()
{
return
df_FileNumber
;
}
uint16_t
DataFlash_APM1
::
GetFilePage
()
{
return
df_FilePage
;
}
// make one instance for the user to use
// make one instance for the user to use
DataFlash_APM1
::
DataFlash_APM1
()
{}
DataFlash_APM1
::
DataFlash_APM1
()
{}
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