Implements AoC link layer init
Also restructures code so that initialization errors can be handled at
a higher level code.
Bug: 160899751
Test: Compile and load, verify link manager is successfully initialized
Change-Id: I358bf6c403d00fba4c671b4f134ea5cbaf69ef37
diff --git a/chpp/platform/aoc/chpp_uart_link_manager.cc b/chpp/platform/aoc/chpp_uart_link_manager.cc
index e44aa6c..83db24a 100644
--- a/chpp/platform/aoc/chpp_uart_link_manager.cc
+++ b/chpp/platform/aoc/chpp_uart_link_manager.cc
@@ -18,69 +18,13 @@
#include "chpp/macros.h"
#include "chpp/platform/log.h"
-#include "efw/include/environment.h"
-#include "uart_map.h"
namespace chpp {
-namespace {
-enum UART_MAP getUartMap(ChppLinkType linkType) {
- switch (linkType) {
- case ChppLinkType::CHPP_LINK_TYPE_WIFI:
- return UART_MAP::UART_MAP_WIFI;
- case ChppLinkType::CHPP_LINK_TYPE_GNSS:
- return UART_MAP::UART_MAP_GNSS;
- case ChppLinkType::CHPP_LINK_TYPE_WWAN:
- // TODO: Needs to be defined
- default:
- CHPP_ASSERT(false);
- }
-
- return UART_MAP::UART_MAP_TOT;
-}
-
-bool getWakeOutGpioPinNumber(ChppLinkType linkType, uint8_t *pinNumber) {
- bool success = true;
- switch (linkType) {
- // Refer to pin_configuration.cc for mapping
- case ChppLinkType::CHPP_LINK_TYPE_WIFI:
- *pinNumber = 43;
- break;
- case ChppLinkType::CHPP_LINK_TYPE_GNSS:
- *pinNumber = 86;
- break;
- case ChppLinkType::CHPP_LINK_TYPE_WWAN:
- // TODO: Needs to be defined
- default:
- CHPP_LOGE("No valid wake_out pin number found for link type %d",
- linkType);
- success = false;
- CHPP_ASSERT(false);
- }
-
- return success;
-}
-
-} // anonymous namespace
-
-UartLinkManager::UartLinkManager(ChppPlatformLinkParameters *params) {
- mUart = Environment::Instance()->UART(getUartMap(params->linkType));
- if (mUart == nullptr) {
- CHPP_LOGE("UART was null for link type %d", params->linkType);
- }
- CHPP_ASSERT(mUart != nullptr);
-
- uint8_t pinNumber;
- if (getWakeOutGpioPinNumber(params->linkType, &pinNumber)) {
- mWakeOutGpio = GPIOAoC(pinNumber);
- mWakeOutGpio->SetDirection(GPIO::DIRECTION::OUTPUT);
- mWakeOutGpio->Clear();
- }
-
- if (!isInitialized()) {
- CHPP_LOGE("Failed to initialize UartLinkManager for link type %d",
- params->linkType);
- }
+UartLinkManager::UartLinkManager(UART *uart, uint8_t wakeOutPinNumber)
+ : mUart(uart), mWakeOutGpio(wakeOutPinNumber) {
+ mWakeOutGpio.SetDirection(GPIO::DIRECTION::OUTPUT);
+ mWakeOutGpio.Clear();
}
bool UartLinkManager::prepareTxPacket(uint8_t *buf, size_t len) {
@@ -95,7 +39,7 @@
}
void UartLinkManager::startTransaction() {
- mWakeOutGpio->Set(true /* set */);
+ mWakeOutGpio.Set(true /* set */);
// TODO: Wait for wake_in GPIO high
@@ -103,7 +47,7 @@
int bytesTransmitted = mUart->Tx(mCurrentBuffer, mCurrentBufferLen);
// Deassert wake_out as soon as data is transmitted, per specifications.
- mWakeOutGpio->Clear();
+ mWakeOutGpio.Clear();
if (static_cast<size_t>(bytesTransmitted) != mCurrentBufferLen) {
CHPP_LOGE("Failed to transmit data");
@@ -112,16 +56,12 @@
clearTxPacket();
} else {
// TODO: Wait for pulse width requirement per specifications.
- mWakeOutGpio->Clear();
+ mWakeOutGpio.Clear();
}
// TODO: Wait for wake_in GPIO low
}
-bool UartLinkManager::isInitialized() const {
- return mUart != nullptr && mWakeOutGpio.has_value();
-}
-
bool UartLinkManager::hasTxPacket() const {
return mCurrentBuffer != nullptr && mUart != nullptr;
}
diff --git a/chpp/platform/aoc/include/chpp/platform/chpp_uart_link_manager.h b/chpp/platform/aoc/include/chpp/platform/chpp_uart_link_manager.h
index 803f076..9e386ec 100644
--- a/chpp/platform/aoc/include/chpp/platform/chpp_uart_link_manager.h
+++ b/chpp/platform/aoc/include/chpp/platform/chpp_uart_link_manager.h
@@ -19,7 +19,6 @@
#include "chpp/link.h"
#include "chre/util/non_copyable.h"
-#include "chre/util/optional.h"
#include "gpio_aoc.h"
#include "uart.h"
@@ -51,17 +50,10 @@
class UartLinkManager : public chre::NonCopyable {
public:
/**
- * @param params The link parameters supplied to the CHPP link layer.
+ * @param uart The pointer to the UART instance.
+ * @param wakeOutPinNumber The pin number of the wake_out GPIO.
*/
- UartLinkManager(ChppPlatformLinkParameters *params);
-
- /**
- * No other public member functions in this class may be called if this method
- * returns false.
- *
- * @return true if the UartLinkManager successfully initialized.
- */
- bool isInitialized() const;
+ UartLinkManager(UART *uart, uint8_t wakeOutPinNumber);
/**
* @param buf The non-null pointer to the buffer.
@@ -82,7 +74,7 @@
private:
UART *mUart = nullptr;
- chre::Optional<GPIOAoC> mWakeOutGpio;
+ GPIOAoC mWakeOutGpio;
//! The pointer to the currently pending TX packet.
uint8_t *mCurrentBuffer = nullptr;
diff --git a/chpp/platform/aoc/include/chpp/platform/platform_link.h b/chpp/platform/aoc/include/chpp/platform/platform_link.h
index 43dd560..7a3c14e 100644
--- a/chpp/platform/aoc/include/chpp/platform/platform_link.h
+++ b/chpp/platform/aoc/include/chpp/platform/platform_link.h
@@ -26,14 +26,9 @@
#define CHPP_PLATFORM_TRANSPORT_TIMEOUT_MS 1000
-enum ChppLinkType {
- CHPP_LINK_TYPE_WWAN = 0,
- CHPP_LINK_TYPE_WIFI,
- CHPP_LINK_TYPE_GNSS,
-};
-
struct ChppPlatformLinkParameters {
- enum ChppLinkType linkType;
+ //! Must be of type chpp::UartLinkManager
+ void *uartLinkManager;
};
#ifdef __cplusplus
diff --git a/chpp/platform/aoc/link.cc b/chpp/platform/aoc/link.cc
index c30e94d..971a6d7 100644
--- a/chpp/platform/aoc/link.cc
+++ b/chpp/platform/aoc/link.cc
@@ -18,9 +18,7 @@
#include "chpp/macros.h"
-void chppPlatformLinkInit(struct ChppPlatformLinkParameters *params) {
- // TODO: Implement this
-}
+void chppPlatformLinkInit(struct ChppPlatformLinkParameters *params) {}
void chppPlatformLinkDeinit(struct ChppPlatformLinkParameters *params) {
// TODO: Implement this