Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heizung
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
c3pb
Heizung
Commits
c4c3429b
Commit
c4c3429b
authored
1 year ago
by
Benjamin Koch
Browse files
Options
Downloads
Patches
Plain Diff
some small changes
parent
5092a1fc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
firmware/rust1/src/rs485.rs
+10
-10
10 additions, 10 deletions
firmware/rust1/src/rs485.rs
with
10 additions
and
10 deletions
firmware/rust1/src/rs485.rs
+
10
−
10
View file @
c4c3429b
...
...
@@ -248,7 +248,7 @@ impl RS485 {
// We have a long 1, i.e. UART is idle. Wait for start bit.
"have_long_high:"
,
"irq set 1"
,
// notify MCU in case they want to know about this (
start
of Modbus frame)
"irq set 1"
,
// notify MCU in case they want to know about this (
end
of Modbus frame)
"wait 0 pin 0"
,
"nop [4]"
,
"jmp pin wait_idle"
,
// abort if zero was just a glitch
...
...
@@ -324,8 +324,8 @@ impl RS485 {
let
mut
cfg
=
Config
::
default
();
let
loaded_program
=
common
.load_program
(
&
relocated
);
cfg
.use_program
(
&
loaded_program
,
&
[]);
const
SM_FREQ
:
u32
=
1
25_000_000
;
cfg
.clock_divider
=
(
U56F8!
(
125_000_000
)
/
U56F8!
(
1
25_000_000
/* SM_FREQ */
))
.to_fixed
();
const
SM_FREQ
:
u32
=
25_000_000
;
cfg
.clock_divider
=
(
U56F8!
(
125_000_000
)
/
U56F8!
(
25_000_000
/* SM_FREQ */
))
.to_fixed
();
cfg
.shift_in
=
ShiftConfig
{
auto_fill
:
true
,
threshold
:
32
,
...
...
@@ -343,9 +343,10 @@ impl RS485 {
sm
.set_config
(
&
cfg
);
sm
.set_enable
(
true
);
// Timeout: Modbus wants 1.5 ms between frames so we make this a bit smaller. SM runs at 25 MHz
// but we need two clocks per loop.
let
timeout_start_value
=
(
SM_FREQ
as
f32
*
1.4e-3
/
2.
)
as
u32
;
// Timeout: Modbus wants 3.5 char times between frames but we should detect the end of a frame
// after 1.5 char times. This is 0.86 ms at 19200 baud (8e1, i.e. 11 baud times per char).
// We need two clocks for each loop.
let
timeout_start_value
=
(
SM_FREQ
as
f32
*
0.86e-3
/
2.
)
as
u32
;
sm
.tx
()
.push
(
timeout_start_value
);
info!
(
"timeout_start_value: {} = 0x{:08x}"
,
timeout_start_value
,
timeout_start_value
);
...
...
@@ -395,7 +396,6 @@ impl RS485 {
let
mut
rxcrc
=
CRC
.digest
();
let
mut
rx_expected_bytes
=
ModbusFrameLength
::
NeedMoreData
(
3
);
let
mut
rx_received_bytes
=
0u16
;
let
mut
rx_char_prev
:
u8
=
0
;
const
TX_BUF_LENGTH
:
usize
=
32
;
let
mut
txbuf
=
Vec
::
<
u8
,
TX_BUF_LENGTH
>
::
new
();
...
...
@@ -560,19 +560,19 @@ impl RS485 {
tx_data
[
i
+
1
]
=
x
as
u32
|
(((
parity
as
u32
)
&
1
)
<<
8
);
}
info!
(
"Modbus reply: {:?}"
,
txbuf
);
tx_future
=
DontAbort
::
new
(
sm1
.tx
()
.dma_push
(
dma_tx_ref
.reborrow
(),
&
tx_data
[
0
..
(
txbuf
.len
()
+
1
)]),
HangIfReused
);
}
}
rxbuf
.clear
();
rxcrc
=
CRC
.digest
();
//
rxcrc = CRC.digest();
// re-init already done above, don't repeat to avoid warning
rx_expected_bytes
=
ModbusFrameLength
::
NeedMoreData
(
3
);
rx_received_bytes
=
0
;
}
}
rx_char_prev
=
rx_char
;
},
Result
::
Err
(
e
)
=>
{
info!
(
"RX error {:?}"
,
e
);
...
...
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