Skip to content

Commit 5941926

Browse files
committed
refactor: io rework
Signed-off-by: Adrian Lungu <lunguadrian30@gmail.com>
1 parent f647645 commit 5941926

9 files changed

Lines changed: 5 additions & 269 deletions

File tree

tockloader-lib/src/command_impl/erase_apps.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{CommandEraseApps, IO};
77
#[async_trait]
88
impl CommandEraseApps for TockloaderConnection {
99
async fn erase_apps(&mut self) -> Result<(), TockloaderError> {
10-
self.write(self.get_settings().start_address, &[0u8])
11-
.await
10+
self.write(self.get_settings().start_address, &[0u8]).await
1211
}
1312
}

tockloader-lib/src/command_impl/install.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use crate::CommandInstall;
77

88
#[async_trait]
99
impl CommandInstall for TockloaderConnection {
10-
async fn install_app(
11-
&mut self, _tab: Tab
12-
) -> Result<(), TockloaderError> {
10+
async fn install_app(&mut self, _tab: Tab) -> Result<(), TockloaderError> {
1311
todo!()
1412
}
1513
}

tockloader-lib/src/command_impl/probers/io.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,11 @@ impl IOCommands for ProbeRSConnection {
4545
if !self.is_open() {
4646
return Err(InternalError::ConnectionNotOpen.into());
4747
}
48-
<<<<<<< HEAD
4948
let start_address = self.get_settings().start_address;
5049
let session = self.session.as_mut().expect("Board must be open");
5150
let mut core = session.core(self.target_info.core)?;
5251

5352
AppAttributes::read_apps_data_probe(&mut core, start_address)
54-
=======
55-
let settings = self.get_settings();
56-
let session = self.session.as_mut().expect("Board must be open");
57-
let mut core = session.core(self.target_info.core)?;
58-
59-
AppAttributes::read_apps_data_probe(&mut core, settings.start_address)
60-
>>>>>>> 6df3b8d (feat:io rework)
6153
}
6254

6355
async fn read_system_attributes(&mut self) -> Result<SystemAttributes, TockloaderError> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod io;
1+
pub mod io;

tockloader-lib/src/command_impl/serial/install.rs

Lines changed: 0 additions & 188 deletions
This file was deleted.

tockloader-lib/src/command_impl/serial/io.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ use crate::{
1212
impl IO for SerialConnection {
1313
async fn read(&mut self, address: u64, size: usize) -> Result<Vec<u8>, TockloaderError> {
1414
let mut pkt = (address as u32).to_le_bytes().to_vec();
15-
<<<<<<< HEAD
1615
pkt.append(&mut (size as u16).to_le_bytes().to_vec());
17-
=======
18-
let length = (size as u16).to_le_bytes().to_vec();
19-
for i in length {
20-
pkt.push(i);
21-
}
22-
>>>>>>> 6df3b8d (feat:io rework)
2316
let stream = self.stream.as_mut().expect("Board must be open");
2417

2518
let (_, appdata) = issue_command(
@@ -41,7 +34,6 @@ impl IO for SerialConnection {
4134
}
4235

4336
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError> {
44-
<<<<<<< HEAD
4537
let page_size = self.get_settings().page_size as usize;
4638
let stream = self.stream.as_mut().expect("Board must be open");
4739
let mut binary = pkt.to_vec();
@@ -56,28 +48,6 @@ impl IO for SerialConnection {
5648
.to_vec();
5749
pkt.append(
5850
&mut binary[(page_number * page_size)..((page_number + 1) * page_size)].to_vec(),
59-
=======
60-
let settings = self.get_settings();
61-
let stream = self.stream.as_mut().expect("Board must be open");
62-
let mut binary = pkt.to_vec();
63-
64-
if !binary.len().is_multiple_of(settings.page_size as usize) {
65-
binary.extend(vec![
66-
0u8;
67-
settings.page_size as usize
68-
- (binary.len() % settings.page_size as usize)
69-
]);
70-
}
71-
72-
for page_number in 0..(binary.len() / settings.page_size as usize) {
73-
let mut pkt = (address as u32 + page_number as u32 * settings.page_size as u32)
74-
.to_le_bytes()
75-
.to_vec();
76-
pkt.append(
77-
&mut binary[(page_number * settings.page_size as usize)
78-
..((page_number + 1) * settings.page_size as usize)]
79-
.to_vec(),
80-
>>>>>>> 6df3b8d (feat:io rework)
8151
);
8252
let _ = issue_command(stream, Command::WritePage, pkt, true, 0, Response::OK).await?;
8353
}
@@ -97,20 +67,12 @@ impl IOCommands for SerialConnection {
9767
if !self.is_open() {
9868
return Err(InternalError::ConnectionNotOpen.into());
9969
}
100-
<<<<<<< HEAD
10170
let start_address = self.get_settings().start_address;
102-
=======
103-
let settings = self.get_settings();
104-
>>>>>>> 6df3b8d (feat:io rework)
10571
let stream = self.stream.as_mut().expect("Board must be open");
10672

10773
ping_bootloader_and_wait_for_response(stream).await?;
10874

109-
<<<<<<< HEAD
11075
AppAttributes::read_apps_data_serial(stream, start_address).await
111-
=======
112-
AppAttributes::read_apps_data_serial(stream, settings.start_address).await
113-
>>>>>>> 6df3b8d (feat:io rework)
11476
}
11577

11678
async fn read_system_attributes(&mut self) -> Result<SystemAttributes, TockloaderError> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod io;
1+
pub mod io;

tockloader-lib/src/connection.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ pub trait Connection {
5252
/// `open` or any other method is undefined behavior.
5353
async fn close(&mut self) -> Result<(), TockloaderError>;
5454
fn is_open(&self) -> bool;
55-
<<<<<<< HEAD
5655
fn get_settings(&self) -> &BoardSettings;
57-
=======
58-
fn get_settings(&self) -> BoardSettings;
59-
>>>>>>> 6df3b8d (feat:io rework)
6056
}
6157

6258
pub struct ProbeRSConnection {
@@ -66,11 +62,7 @@ pub struct ProbeRSConnection {
6662
pub(crate) target_info: ProbeTargetInfo,
6763
/// Only used for opening a new connection
6864
debug_probe: DebugProbeInfo,
69-
<<<<<<< HEAD
7065
settings: BoardSettings,
71-
=======
72-
pub settings: BoardSettings,
73-
>>>>>>> 6df3b8d (feat:io rework)
7466
}
7567

7668
impl ProbeRSConnection {
@@ -109,14 +101,8 @@ impl Connection for ProbeRSConnection {
109101
fn is_open(&self) -> bool {
110102
self.session.is_some()
111103
}
112-
113-
<<<<<<< HEAD
114104
fn get_settings(&self) -> &BoardSettings {
115105
&self.settings
116-
=======
117-
fn get_settings(&self) -> BoardSettings {
118-
self.settings.clone()
119-
>>>>>>> 6df3b8d (feat:io rework)
120106
}
121107
}
122108

@@ -127,11 +113,7 @@ pub struct SerialConnection {
127113
pub(crate) target_info: SerialTargetInfo,
128114
/// Path to the serial port. This is only used for opening a new connection.
129115
port: String,
130-
<<<<<<< HEAD
131116
settings: BoardSettings,
132-
=======
133-
pub settings: BoardSettings,
134-
>>>>>>> 6df3b8d (feat:io rework)
135117
}
136118

137119
impl SerialConnection {
@@ -182,13 +164,8 @@ impl Connection for SerialConnection {
182164
self.stream.is_some()
183165
}
184166

185-
<<<<<<< HEAD
186167
fn get_settings(&self) -> &BoardSettings {
187168
&self.settings
188-
=======
189-
fn get_settings(&self) -> BoardSettings {
190-
self.settings.clone()
191-
>>>>>>> 6df3b8d (feat:io rework)
192169
}
193170
}
194171

@@ -235,11 +212,7 @@ impl Connection for TockloaderConnection {
235212
}
236213
}
237214

238-
<<<<<<< HEAD
239215
fn get_settings(&self) -> &BoardSettings {
240-
=======
241-
fn get_settings(&self) -> BoardSettings {
242-
>>>>>>> 6df3b8d (feat:io rework)
243216
match self {
244217
TockloaderConnection::ProbeRS(conn) => conn.get_settings(),
245218
TockloaderConnection::Serial(conn) => conn.get_settings(),

tockloader-lib/src/known_boards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl KnownBoard for MicrobitV2 {
4848
BoardSettings {
4949
arch: Some("cortex-m4".to_string()),
5050
start_address: 0x00040000,
51-
page_size: 512,
51+
page_size: 4096,
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)