Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

DMA driven PWM implementation #193

Merged
merged 14 commits into from
Dec 18, 2017
Merged

DMA driven PWM implementation #193

merged 14 commits into from
Dec 18, 2017

Conversation

simokawa
Copy link
Contributor

No description provided.

@simokawa
Copy link
Contributor Author

#172

// Memory mapped register
c.srcAddr = physToBus(srcAddr)
// BUG: EXPERIMENTING.
//t |= dmaSrcInc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To commit in master, please remove these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comments.

d.cs = dmaReset
// Clear bits if needed.
d.cs = dmaEnd | dmaInterrupt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearing dmaInterrupt is probably (?) important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I removed those lines because they did not make the channel isAvailable(). Simple dmaReset did work. Anyway, the code is not enabled yet. I leave dmaInterrupt and will test later whether it is harmful.

@@ -763,6 +812,17 @@ func (d *driverDMA) Close() error {
return nil
}

func ResetDMA(ch int) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user shouldn't have to know about channels, so do not export this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it private. Although it is not used anywhere, it is useful while debugging.

edge *sysfs.Pin // Set once, then never set back to nil.
usingEdge bool // Set when edge detection is enabled.
usingClock bool // Set when a GPCLK or PWM clock is used.
dmaCh *dmaChannel // Set when DMA is used for PWM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason I'm unsure about making it GPIO specific is that we can affect multiple GPIO in one operation, for example reading multiple GPIO pins simultaneously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two options, 1 DMA for each channel or 1 DMA for multiple channels.
I think the former is simpler for PWM as long as we have enough DMA channels.
If we have a dedicated DMA channel, we need only two CBs for high and low durations and we can specify them independently.
If we share the channel, CBs will be complicated to accommodate different periods and duties.

For reading, we should share a channel with the highest sampling rate.

//
// PWM1 is exposed on pins 13, 19, 41 and 45.
//
// PWM0 and PWM1 share the same 25Mhz clock source. The period must be a
// divisor of 25Mhz.
//
// DMA driven PWM is aviable for all pins except PWM1 pins, its resolution is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's commit the working code without user visible changes first, then the user visible change afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this file for this change.

@codecov-io
Copy link

codecov-io commented Dec 18, 2017

Codecov Report

Merging #193 into master will decrease coverage by 0.65%.
The diff coverage is 23.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #193      +/-   ##
==========================================
- Coverage      86%   85.35%   -0.66%     
==========================================
  Files          64       64              
  Lines        5251     5291      +40     
==========================================
  Hits         4516     4516              
- Misses        647      687      +40     
  Partials       88       88
Impacted Files Coverage Δ
host/bcm283x/pwm.go 56% <20%> (+6%) ⬆️
host/bcm283x/dma.go 55.97% <24.13%> (-9.81%) ⬇️
devices/lepton/lepton.go 88.34% <0%> (-1.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d337762...574a413. Read the comment docs.

@simokawa
Copy link
Contributor Author

Thanks for the review. I think I have correctly updated the branch but I am still not familiar with github SxS diff tools. If I miss something, please let me know.

Copy link
Contributor

@maruel maruel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small things.

d.cbAddr = 0
d.nextCB = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to clear this one too in case it was set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return nil, nil, err
}
u := buf.Uint32()
cb_bytes := uint32(32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"_" in symbol names is not idiomatic in Go except rare circonstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

@maruel maruel merged commit 5388a53 into google:master Dec 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants