SNS - GPIO - #34
Conversation
|
Please |
ishmis
left a comment
There was a problem hiding this comment.
also, the scripts folder should not be touched at all
| //GPIO Start Addr End Addr | ||
| //GPIO0 0x44E0_7000 0x44E0_7FFF | ||
| //GPIO1 0x4804_C000 0x4804_CFFF | ||
| //GPIO2 0x481A_C000 0x481A_CFFF | ||
| //GPIO3 0x481A_E000 0x481A_EFFF | ||
|
|
||
| //GPIO_DATAIN (READ) 0x138h | ||
| //GPIO_DATAOUT 0x13c | ||
| //SET 0x194 | ||
| //CLEAR 0x190 | ||
| // const uint8_t bank = pin_ / 32; // offset: GPIO_0,1,2,3 | ||
| // const uint8_t pin_id = pin_ % 32; | ||
|
|
There was a problem hiding this comment.
Referenced information for getting pin addresses. Can delete but anybody later on reading might find it useful.
There was a problem hiding this comment.
If it's stuff you need to actually use in the code itself, don't keep it commented and just comment on the method that needs it desribing briefly how to use it.
| std::shared_ptr<HardwareGpioReader> reader; | ||
| return reader; |
There was a problem hiding this comment.
just returning an uninitialized reader?
| std::shared_ptr<HardwareGpioWriter> writer; | ||
| return writer; |
| #include <sys/mman.h> | ||
| #include <unistd.h> | ||
| #include <fcntl.h> | ||
|
|
| // TODO: implement | ||
| throw -1; | ||
|
|
||
| int out = *gpio_readAddr & pinMAP; |
There was a problem hiding this comment.
const and style guide (naming)
| GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state) | ||
| { | ||
| // TODO: implement | ||
| //Not sure if this correct |
| //May just erase everything | ||
| //May need to | ||
| if (state == core::DigitalSignal::kHigh) { | ||
| *gpio_setAddr |= pinMAP; |
| } | ||
|
|
||
|
|
||
|
|
|
|
||
| const off_t pinAddress = bankAddresses[bank]; | ||
| volatile void *gpio_addr; | ||
| volatile unsigned int *gpio_set; |
|
|
||
|
|
||
|
|
||
|
|
| */ | ||
|
|
||
| //GPIO Start Addr End Addr | ||
| //GPIO0 0x44E0_7000 0x44E0_7FFF |
|
|
||
| private: | ||
| hyped::core::ILogger &log_; | ||
| const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; |
There was a problem hiding this comment.
Where are these values from? Is it documented somewhere?
There was a problem hiding this comment.
Taken from old code and also cross referenced from AM335x technical reference manual along with other tutorials.
There was a problem hiding this comment.
Ok sounds good. Is this documented somewhere so that someone next year can know where these values came from?
There was a problem hiding this comment.
Also in general "it was in the old codebase" is not justification. We are writing a new system here with lots of new components and there was lots of flawed legacy code in the 2022 codebase. If you are ever unsure of a value, please either ask someone who may already know (i.e. @SnickeyX) or find the relevant datasheet and document where the values came from.
| std::unordered_map<uint8_t, std::shared_ptr<IGpioWriter>> InitializedWriters; | ||
| std::unordered_map<uint8_t, std::shared_ptr<IGpioReader>> InitializedReaders; | ||
|
|
||
| static constexpr unsigned int pinSize = 0x1000; |
|
This PR definitely needs to be prioritized, @Knhwong don't think you updated the code here with the testing code that worked? |
I sent you the testing code in a slack message, it was a basic main.cpp file that was a condensed gpio. The changes aka just type fixes were already updated in the main code. |
are you not planning on updating it here? |
By "main" I am referring to this branch. In the main.cpp testing code, it's the same lines updated already within the getwriter or getreader on hardware_gpio.cpp back in the added comments and fixed_types commit. Or are you referring to something else here? |
TomLonergan03
left a comment
There was a problem hiding this comment.
scripts/ doesn't contain anything
| const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; | ||
|
|
||
| if (out > 0) { | ||
| return core::DigitalSignal::kHigh; | ||
| } else { | ||
| return core::DigitalSignal::kLow; | ||
| } |
There was a problem hiding this comment.
if (*gpio_readAddr & pinMAP)
also this method doesn't need to be optional
| } else { | ||
| *gpio_clearAddr = pinMAP; | ||
| } | ||
| return core::Result::kSuccess; |
There was a problem hiding this comment.
this can't return kFailure so no reason for returning a result
| // Integer divison to get bank number | ||
| const std::uint32_t bank = pin / 32; | ||
| // Modulo by 32 gets us the ID of the pin relative to the bank | ||
| const std::uint32_t pinID = pin % 32; |
| // Modulo by 32 gets us the ID of the pin relative to the bank | ||
| const std::uint32_t pinID = pin % 32; | ||
| // Gpio addresses contain 32 pins, so we use pinmap to specify specific pin. | ||
| const std::uint32_t pinMAP = (1 << pinID); |
There was a problem hiding this comment.
pin_map unless MAP is an acronym then expand it
| } | ||
|
|
||
| // Get memory address from bank address | ||
| const off_t pinAddress = bankAddresses[bank]; |
| const std::uint32_t pinID = pin % 32; | ||
| const std::uint32_t pinMAP = (1 << pinID); |
There was a problem hiding this comment.
same naming issues as in getReader
| // Bank Addresses are header base addresses. | ||
| // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible | ||
|
|
||
| const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; |
There was a problem hiding this comment.
bank_addresses, also should use c++ style array
|
|
||
| const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; | ||
| std::unordered_map<std::uint8_t, std::shared_ptr<IGpioWriter>> InitializedWriters; | ||
| std::unordered_map<std::uint8_t, std::shared_ptr<IGpioReader>> InitializedReaders; |
There was a problem hiding this comment.
initialised_writers_ and initialised_readers_
| static constexpr std::uint32_t pinSize = 0x1000; | ||
| static constexpr std::uint32_t pinRead = 0x138; | ||
| static constexpr std::uint32_t pinClear = 0x190; | ||
| static constexpr std::uint32_t pinSet = 0x194; |
There was a problem hiding this comment.
kPinSize, kPinRead and so on
|
|
||
| private: | ||
| HardwareGpioReader(); | ||
| HardwareGpioReader(std::uint8_t pin, volatile std::uint32_t *read) |
| static constexpr std::uint32_t pin_size = 0x1000; | ||
| static constexpr std::uint32_t pin_read = 0x138; | ||
| static constexpr std::uint32_t pin_clear = 0x190; | ||
| static constexpr std::uint32_t pin_set = 0x194; |
There was a problem hiding this comment.
these become private static constexprs following the style guide discussion
unless they need to be accessed outside of methods
|
|
||
| namespace hyped::io { | ||
|
|
||
| std::optional<core::DigitalSignal> HardwareGpioReader::read() |
There was a problem hiding this comment.
optional with no nullopt return, so can just have return type core::DigitalSignal
|
also what are the prehook etc files, they seem to be empty |
All primary functionality done, I'll need to ask more about logging since using the pointers makes it harder to find problems.