Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Aug 11, 2022
1 parent bce6adf commit 7996b70
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 88 deletions.
2 changes: 1 addition & 1 deletion dynalib/inc/dynalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ constexpr T2* dynalib_checked_cast(T2 *p) {
#define __S(x) #x
#define __SX(x) __S(x)

#if HAL_PLATFORM_DYNALIB_DYNAMIC_LOCATION
#if PLATFORM_ID == 32 || PLATFORM_ID == 28
#define DYNALIB_FN_IMPORT(index, tablename, name, counter) \
DYNALIB_STATIC_ASSERT(index == counter, "Index of the dynamically exported function has changed"); \
const char check_name_##tablename_##name[0]={}; /* this will fail if the name is already defined */ \
Expand Down
4 changes: 0 additions & 4 deletions hal/inc/hal_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,4 @@
#define HAL_PLATFORM_CELLULAR_MODEM_VOLTAGE_TRANSLATOR (1)
#endif // HAL_PLATFORM_CELLULAR_MODEM_VOLTAGE_TRANSLATOR

#ifndef HAL_PLATFORM_DYNALIB_DYNAMIC_LOCATION
#define HAL_PLATFORM_DYNALIB_DYNAMIC_LOCATION (0)
#endif

#endif /* HAL_PLATFORM_H */
6 changes: 3 additions & 3 deletions hal/shared/demux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int Demux::write(uint8_t pin, uint8_t value) {
#if HAL_PLATFORM_NRF52840
nrf_gpio_port_out_set(DEMUX_NRF_PORT, ((uint32_t)pin) << DEMUX_PINS_SHIFT);
#elif HAL_PLATFORM_RTL872X
hal_gpio_write(DEMUX_C, pin >> 2);
hal_gpio_write(DEMUX_B, (pin >> 1) & 1);
hal_gpio_write(DEMUX_A, pin & 1);
hal_gpio_write(DEMUX_C, (pin & DEMUX_PIN_2_MASK) ? 1 : 0);
hal_gpio_write(DEMUX_B, (pin & DEMUX_PIN_1_MASK) ? 1 : 0);
hal_gpio_write(DEMUX_A, (pin & DEMUX_PIN_0_MASK) ? 1 : 0);
#endif
setPinValue(pin, 0);
}
Expand Down
3 changes: 2 additions & 1 deletion hal/shared/demux.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
#define DEMUX_MAX_PIN_COUNT 8
#if HAL_PLATFORM_NRF52840
#define DEMUX_NRF_PORT (NRF_P1)
#endif
#define DEMUX_PIN_0_MASK 0x00000400
#define DEMUX_PIN_1_MASK 0x00000800
#define DEMUX_PIN_2_MASK 0x00001000
#define DEMUX_PINS_SHIFT (10)
#endif


namespace particle {

Expand Down
2 changes: 0 additions & 2 deletions hal/src/rtl872x/hal_platform_rtl8721x_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,3 @@
#define HAL_PLATFORM_SYSTEM_POOL_SIZE 1024

#define HAL_PLATFORM_MODULE_SUFFIX_EXTENSIONS (1)

#define HAL_PLATFORM_DYNALIB_DYNAMIC_LOCATION (1)
1 change: 0 additions & 1 deletion hal/src/trackerm/hal_platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define HAL_PLATFORM_I2C_NUM (2)
#define HAL_PLATFORM_USART_NUM (3)
#define HAL_PLATFORM_NCP_COUNT (1)
#undef HAL_PLATFORM_WIFI
#define HAL_PLATFORM_WIFI (0)
// #define HAL_PLATFORM_WIFI_COMPAT (1)
// #define HAL_PLATFORM_WIFI_NCP_SDIO (1)
Expand Down
54 changes: 30 additions & 24 deletions hal/src/trackerm/network/network.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Particle Industries, Inc. All rights reserved.
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -43,10 +43,10 @@ namespace {

/* en2 - Ethernet FeatherWing */
BaseNetif* en2 = nullptr;
/* wl3 - Realtek NCP Station */
BaseNetif* wl3 = nullptr;
/* wl4 - Realtek NCP Access Point */
/* wl4 - Realtek NCP Station */
BaseNetif* wl4 = nullptr;
/* wl5 - Realtek NCP Access Point */
BaseNetif* wl5 = nullptr;
/* pp3 - Cellular */
BaseNetif* pp3 = nullptr;

Expand All @@ -70,8 +70,8 @@ class WifiNetworkManagerInit {
std::unique_ptr<WifiNcpClient> ncpClient(new(std::nothrow) RealtekNcpClient);
CHECK_TRUE(ncpClient, SYSTEM_ERROR_NO_MEMORY);
auto conf = NcpClientConfig()
.eventHandler(RealtekNcpNetif::ncpEventHandlerCb, wl3)
.dataHandler(RealtekNcpNetif::ncpDataHandlerCb, wl3);
.eventHandler(RealtekNcpNetif::ncpEventHandlerCb, wl4)
.dataHandler(RealtekNcpNetif::ncpDataHandlerCb, wl4);
CHECK(ncpClient->init(std::move(conf)));
// Initialize network manager
mgr_.reset(new(std::nothrow) WifiNetworkManager(ncpClient.get()));
Expand Down Expand Up @@ -178,24 +178,26 @@ int if_init_platform(void*) {
reserve_netif_index();
}

/* wl3 - Realtek NCP Station */
/* wl3 = new RealtekNcpNetif();
if (wl3) {
((RealtekNcpNetif*)wl3)->setWifiManager(wifiNetworkManager());
((RealtekNcpNetif*)wl3)->init();
#if !HAL_PLATFORM_WIFI_SCAN_ONLY
/* wl4 - Realtek NCP Station */
wl4 = new RealtekNcpNetif();
if (wl4) {
((RealtekNcpNetif*)wl4)->setWifiManager(wifiNetworkManager());
((RealtekNcpNetif*)wl4)->init();
}
*/
#endif

/* pp3 - Cellular */
pp3 = new PppNcpNetif();
if (pp3) {
((PppNcpNetif*)pp3)->setCellularManager(cellularNetworkManager());
((PppNcpNetif*)pp3)->init();
}

/* TODO: wl4 - ESP32 NCP Access Point */
reserve_netif_index();
reserve_netif_index();
(void)wl4;
reserve_netif_index(); // wl4
reserve_netif_index(); // wl5
/* TODO: wl5 - Realtek NCP Access Point */
(void)wl5;

auto m = mallinfo();
const size_t total = m.uordblks + m.fordblks;
Expand All @@ -211,8 +213,10 @@ struct netif* lwip_hook_ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* d
if (src == nullptr) {
if (en2 && netifCanForwardIpv4(en2->interface())) {
return en2->interface();
} else if (wl3 && netifCanForwardIpv4(wl3->interface())) {
return wl3->interface();
#if !HAL_PLATFORM_WIFI_SCAN_ONLY
} else if (wl4 && netifCanForwardIpv4(wl4->interface())) {
return wl4->interface();
#endif
} else if (pp3 && netifCanForwardIpv4(pp3->interface())) {
return pp3->interface();
}
Expand All @@ -222,28 +226,30 @@ struct netif* lwip_hook_ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* d
}

unsigned char* rltk_wlan_get_ip(int idx) {
return (uint8_t *) &(wl3->interface()->ip_addr);
return (uint8_t *) &(wl4->interface()->ip_addr);
}

unsigned char* rltk_wlan_get_gw(int idx) {
return (uint8_t *) &(wl3->interface()->gw);
return (uint8_t *) &(wl4->interface()->gw);
}

unsigned char* rltk_wlan_get_gwmask(int idx) {
return (uint8_t *) &(wl3->interface()->netmask);
return (uint8_t *) &(wl4->interface()->netmask);
}

void rltk_wlan_set_netif_info(int idx_wlan, void* dev, unsigned char* dev_addr) {
LOG(INFO, "rltk_wlan_set_netif_info: %d, %02x:%02x:%02x:%02x:%02x:%02x", idx_wlan,
dev_addr[0], dev_addr[1], dev_addr[2], dev_addr[3], dev_addr[4], dev_addr[5]);
if (wl3) {
memcpy(wl3->interface()->hwaddr, dev_addr, sizeof(wl3->interface()->hwaddr));
#if !HAL_PLATFORM_WIFI_SCAN_ONLY
if (wl4) {
memcpy(wl4->interface()->hwaddr, dev_addr, sizeof(wl4->interface()->hwaddr));
}
#endif
}

void netif_rx(int idx, unsigned int len) {
// LOG(INFO, "netif_rx %d %u", idx, len);
RealtekNcpNetif::ncpDataHandlerCb(0, nullptr, len, wl3);
RealtekNcpNetif::ncpDataHandlerCb(0, nullptr, len, wl4);
}

int netif_is_valid_IP(int idx, unsigned char *ip_dest) {
Expand Down
29 changes: 15 additions & 14 deletions hal/src/trackerm/ota_flash_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
* @date 27-Jul-2022
* @brief
******************************************************************************
Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

Expand Down
2 changes: 1 addition & 1 deletion hal/src/trackerm/pinmap_defines.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion hal/src/trackerm/pinmap_defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion hal/src/trackerm/platform_ncp_quectel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Particle Industries, Inc. All rights reserved.
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
1 change: 1 addition & 0 deletions hal/src/tron/hal_platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define HAL_PLATFORM_USART_NUM (3)
#define HAL_PLATFORM_NCP_COUNT (1)
#define HAL_PLATFORM_BROKEN_MTU (1)
#define HAL_PLATFORM_WIFI (1)
#define HAL_PLATFORM_WIFI_COMPAT (1)

#define HAL_PLATFORM_RADIO_ANTENNA_INTERNAL (1)
Expand Down
8 changes: 2 additions & 6 deletions platform/MCU/rtl872x/inc/platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@

#define SYSTICK_IRQ_PRIORITY 7 //CORTEX_M33 Systick Interrupt

#if HAL_PLATFORM_RTL872X
#define INTERNAL_FLASH_SIZE (0x800000)
#else
#pragma message "PLATFORM_ID is " PREPSTRING(PLATFORM_ID)
#error "Unknown PLATFORM_ID"
#endif
// Currently works with platforms P2 and TrackerM
#define INTERNAL_FLASH_SIZE (0x800000)

//Push Buttons, use interrupt HAL
#define BUTTON1_PIN BTN
Expand Down
6 changes: 3 additions & 3 deletions user/inc/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ extern GPIO_TypeDef* PORT_AB[2];
# endif

# ifndef portOutputRegister
# define portOutputRegister(port) ( &( port->PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ].DR ) )
# define portOutputRegister(port) ( &( port->PORT[0].DR ) )
# endif

# ifndef portInputRegister
# define portInputRegister(port) ( &( port->EXT_PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ] ) )
# define portInputRegister(port) ( &( port->EXT_PORT[0] ) )
# endif

# ifndef portModeRegister
# define portModeRegister(port) ( &( port->PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ].DDR ) )
# define portModeRegister(port) ( &( port->PORT[0].DDR ) )
# endif

# ifndef digitalPinHasPWM
Expand Down
1 change: 0 additions & 1 deletion user/tests/wiring/no_fixture/i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ test(I2C_04_Serial1_Cannot_Be_Enabled_While_Wire3_Is_Enabled) {

#endif // PLATFORM_ID == PLATFORM_TRACKER


test(I2C_05_Hal_Sleep_API_Test) {
Wire.lock();
bool enabled = Wire.isEnabled();
Expand Down
2 changes: 1 addition & 1 deletion user/tests/wiring/no_fixture_long_running/pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const PinMapping pwm_pins[] = {
// cause problems if the RGB led is enabled.
// PWM HAL also is not interrupt safe and RGB pins are modified in SysTick
PIN(D2), PIN(D3), PIN(D4), PIN(D5), PIN(D6), /* PIN(D7), */ PIN(D8), PIN(A0), PIN(A1), PIN(A2), PIN(A3), PIN(A4), PIN(A5) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */
#elif (PLATFORM_ID == PLATFORM_P2 || PLATFORM_ID == PLATFORM_TRACKERM) // double check. Run tests etc
#elif HAL_PLATFORM_RTL872X // double check. Run tests etc
PIN(D1), PIN(A2), PIN(A5), PIN(S0), PIN(S1) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */
#elif (PLATFORM_ID == PLATFORM_ESOMX)
PIN(D0), PIN(D1), PIN(D2), PIN(A3), PIN(A4), PIN(A5), PIN(A6), PIN(TX), PIN(RX), PIN(B2), PIN(B3), PIN(C4), PIN(C5) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */
Expand Down
2 changes: 1 addition & 1 deletion user/tests/wiring/no_fixture_long_running/servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "unit-test/unit-test.h"

#if HAL_PLATFORM_GEN == 3
#if PLATFORM_ID == PLATFORM_P2 || PLATFORM_ID == PLATFORM_ESOMX || PLATFORM_ID == PLATFORM_TRACKERM
#if PLATFORM_ID == PLATFORM_ESOMX || HAL_PLATFORM_RTL872X
static const hal_pin_t pin = D1, pin2 = D8;
#else
static const hal_pin_t pin = A0, pin2 = A1;
Expand Down
Loading

0 comments on commit 7996b70

Please sign in to comment.