Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build/platform-id.mk
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ PLATFORM_MCU=gcc
PLATFORM_NET=gcc
ARCH=gcc
PRODUCT_DESC=GCC xcompile
# explicitly exclude platform headers
SPARK_NO_PLATFORM=1
DEFAULT_PRODUCT_ID=3
endif

Expand Down
2 changes: 1 addition & 1 deletion communication/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ TARGET_TYPE = a

BUILD_PATH_EXT=$(COMMUNICATION_BUILD_PATH_EXT)

DEPENDENCIES = hal dynalib services wiring crypto
DEPENDENCIES = hal dynalib services wiring crypto platform

include ../build/arm-tlm.mk
2 changes: 1 addition & 1 deletion communication/src/communication_dynalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#define DYNALIB_EXPORT
#include "communication_dynalib.h"
#define INTERRUPTS_HAL_EXCLUDE_PLATFORM_HEADERS
// #define INTERRUPTS_HAL_EXCLUDE_PLATFORM_HEADERS
#include "core_hal.h"

#if PARTICLE_PROTOCOL
Expand Down
8 changes: 8 additions & 0 deletions hal/inc/concurrent_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ os_result_t os_thread_cleanup(os_thread_t thread);
*/
os_result_t os_thread_yield(void);

os_thread_t os_thread_current(void);

/**
* Delays the current task until a specified time to set up periodic tasks
* @param previousWakeTime The time the thread last woke up. May not be NULL.
Expand Down Expand Up @@ -229,6 +231,12 @@ int os_timer_change(os_timer_t timer, os_timer_change_t change, bool fromISR, un
int os_timer_destroy(os_timer_t timer, void* reserved);
int os_timer_is_active(os_timer_t timer, void* reserved);

/**
* Thread local storage
*/
os_result_t os_thread_storage_set(os_thread_t thread, int idx, void* data, void* reserved);
void* os_thread_storage_get(os_thread_t thread, int idx, void* reserved);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions hal/inc/hal_dynalib_concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ DYNALIB_FN(24, hal_concurrent, os_queue_destroy, int(os_queue_t, void*))
DYNALIB_FN(25, hal_concurrent, os_queue_put, int(os_queue_t, const void* item, system_tick_t, void*))
DYNALIB_FN(26, hal_concurrent, os_queue_take, int(os_queue_t, void* item, system_tick_t, void*))
DYNALIB_FN(27, hal_concurrent, os_thread_exit, os_result_t(os_thread_t))
DYNALIB_FN(28, hal_concurrent, os_thread_current, os_thread_t(void))
DYNALIB_FN(29, hal_concurrent, os_thread_storage_set, os_result_t(os_thread_t, int, void*, void*))
DYNALIB_FN(30, hal_concurrent, os_thread_storage_get, void*(os_thread_t, int, void*))
#endif // PLATFORM_THREADING

DYNALIB_END(hal_concurrent)
Expand Down
87 changes: 83 additions & 4 deletions hal/inc/watchdog_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,101 @@
*/

#ifndef WATCHDOG_HAL_H
#define WATCHDOG_HAL_H
#define WATCHDOG_HAL_H

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
#ifdef __cplusplus
extern "C" {
#endif

bool HAL_watchdog_reset_flagged();

void HAL_Notify_WDT();

#define HAL_WATCHDOG_CAPABILITY_NONE (0x00)
// Watchdog timer will reset the CPU
#define HAL_WATCHDOG_CAPABILITY_CPU_RESET (0x01)
// Watchdog is clocked from an independent clock source
#define HAL_WATCHDOG_CAPABILITY_INDEPENDENT (0x02)
// Watchdog counter needs to be reset within a configured window
#define HAL_WATCHDOG_CAPABILITY_WINDOWED (0x04)
// Watchdog timer can be reconfigured
#define HAL_WATCHDOG_CAPABILITY_RECONFIGURABLE (0x08)
// Watchdog timer can somehow notify about its expiration
#define HAL_WATCHDOG_CAPABILITY_NOTIFY (0x10)
// Watchdog timer can be stopped
#define HAL_WATCHDOG_CAPABILITY_STOPPABLE (0x20)

#ifdef __cplusplus
typedef struct {
uint16_t size;
uint16_t version;

uint8_t running;
uint32_t capabilities;
uint32_t period_us;
uint32_t window_us;
} hal_watchdog_status_t;

typedef struct {
uint16_t size;
uint16_t version;

uint32_t capabilities;
uint32_t period_us;
uint32_t window_us;

void (*notify)(void*);
void* notify_arg;
} hal_watchdog_config_t;

typedef struct {
uint16_t size;
uint16_t version;

uint32_t capabilities;
uint32_t capabilities_required;

uint32_t min_period_us;
uint32_t max_period_us;
} hal_watchdog_info_t;

/**
* Queries the capabilities of a specific hardware watchdog
*/
int hal_watchdog_query(int idx, hal_watchdog_info_t* info, void* reserved);

/**
* Starts hardware watchdog (optionally configures it if conf is provided)
*/
int hal_watchdog_start(int idx, hal_watchdog_config_t* conf, void* reserved);

/**
* Configures specified hardware watchdog
*/
int hal_watchdog_configure(int idx, hal_watchdog_config_t* conf, void* reserved);

/**
* Stops specified hardware watchdog
*/
int hal_watchdog_stop(int idx, void* reserved);

/**
* Retrieves running status of specified watchdog
*/
int hal_watchdog_get_status(int idx, hal_watchdog_status_t* status, void* reserved);

/**
* Kicks specified watchdog, or all of them if idx = -1
*/
int hal_watchdog_kick(int idx, void* reserved);

#ifdef __cplusplus
}
#endif

#endif /* WATCHDOG_HAL_H */
#include "watchdog_hal_impl.h"

#endif /* WATCHDOG_HAL_H */

21 changes: 21 additions & 0 deletions hal/src/core/watchdog_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018 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/>.
*/

#ifndef WATCHDOG_HAL_IMPL_H
#define WATCHDOG_HAL_IMPL_H

#endif /* WATCHDOG_HAL_IMPL_H */
3 changes: 1 addition & 2 deletions hal/src/electron/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ IDX[x] = added IRQ handler
14 [x] PendSV_Handler
15 [x] SysTick_Handler
// External Interrupts ----------------
16 [ ] WWDG_IRQHandler // Window WatchDog
16 [x] WWDG_IRQHandler // Window WatchDog
17 [ ] PVD_IRQHandler // PVD through EXTI Line detection
18 [ ] TAMP_STAMP_IRQHandler // Tamper and TimeStamps through the EXTI line
19 [ ] RTC_WKUP_IRQHandler // RTC Wakeup through the EXTI line
Expand Down Expand Up @@ -480,7 +480,6 @@ void EXTI15_10_IRQHandler(void)
* them for debugging purposes to break on entry and let us know
* which interrupt we are not currently handling.
*/
void WWDG_IRQHandler(void) {__ASM("bkpt 0");}
void PVD_IRQHandler(void) {__ASM("bkpt 0");}
void TAMP_STAMP_IRQHandler(void) {__ASM("bkpt 0");}
void RTC_WKUP_IRQHandler(void) {__ASM("bkpt 0");}
Expand Down
12 changes: 10 additions & 2 deletions hal/src/electron/modem/mdm_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <mutex>
#include "net_hal.h"
#include <limits>
#include "monitor_service.h"

std::recursive_mutex mdm_mutex;

Expand Down Expand Up @@ -368,7 +369,7 @@ int MDMParser::waitFinalResp(_CALLBACKPTR cb /* = NULL*/,
if (type == TYPE_ABORTED)
return RESP_ABORTED; // This means the current command was ABORTED, so retry your command if critical.
}
// relax a bit
SYSTEM_MONITOR_KICK_CURRENT();
HAL_Delay_Milliseconds(10);
}
while (!TIMEOUT(start, timeout_ms) && !_cancel_all_operations);
Expand Down Expand Up @@ -793,9 +794,16 @@ bool MDMParser::registerNet(NetStatus* status /*= NULL*/, system_tick_t timeout_
goto failure;
// Now check every 15 seconds for 5 minutes to see if we're connected to the tower (GSM and GPRS)
system_tick_t start = HAL_Timer_Get_Milli_Seconds();
system_tick_t wd_timeout = SYSTEM_MONITOR_GET_TIMEOUT_CURRENT();
while (!checkNetStatus(status) && !TIMEOUT(start, timeout_ms) && !_cancel_all_operations) {
system_tick_t start = HAL_Timer_Get_Milli_Seconds();
while ((HAL_Timer_Get_Milli_Seconds() - start < 15000UL) && !_cancel_all_operations); // just wait
system_tick_t wd_last = 0;
while ((HAL_Timer_Get_Milli_Seconds() - start < 15000UL) && !_cancel_all_operations) {
if (wd_timeout > 0 && (HAL_Timer_Get_Milli_Seconds() - wd_last) > (wd_timeout / 2)) {
SYSTEM_MONITOR_KICK_CURRENT();
wd_last = HAL_Timer_Get_Milli_Seconds();
}
}
//HAL_Delay_Milliseconds(15000);
}
if (_net.csd == REG_DENIED) MDM_ERROR("CSD Registration Denied\r\n");
Expand Down
36 changes: 36 additions & 0 deletions hal/src/gcc/interrupts_irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018 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/>.
*/

#ifndef INTERRUPTS_IRQ_H
#define INTERRUPTS_IRQ_H

#ifdef __cplusplus
extern "C" {
#endif

typedef int32_t IRQn_Type;

typedef enum hal_irq_t {
__Last_irq = 0
} hal_irq_t;

#ifdef __cplusplus
}
#endif


#endif /* INTERRUPTS_IRQ_H */
21 changes: 21 additions & 0 deletions hal/src/gcc/watchdog_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018 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/>.
*/

#ifndef WATCHDOG_HAL_IMPL_H
#define WATCHDOG_HAL_IMPL_H

#endif /* WATCHDOG_HAL_IMPL_H */
21 changes: 21 additions & 0 deletions hal/src/newhal/watchdog_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018 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/>.
*/

#ifndef WATCHDOG_HAL_IMPL_H
#define WATCHDOG_HAL_IMPL_H

#endif /* WATCHDOG_HAL_IMPL_H */
6 changes: 5 additions & 1 deletion hal/src/photon/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "module_info.h"
#include "flash_mal.h"
#include "delay_hal.h"
#include "stm32f2xx_wwdg.h"
#include <stdint.h>

void SysTickChain();
Expand All @@ -42,6 +43,8 @@ extern char link_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location_end;

extern void WWDG_IRQHandler(void);

const HAL_InterruptOverrideEntry hal_interrupt_overrides[] = {
{HardFault_IRQn, HardFault_Handler},
{MemoryManagement_IRQn, MemManage_Handler},
Expand All @@ -56,7 +59,8 @@ const HAL_InterruptOverrideEntry hal_interrupt_overrides[] = {
{CAN2_TX_IRQn, CAN2_TX_irq},
{CAN2_RX0_IRQn, CAN2_RX0_irq},
{CAN2_RX1_IRQn, CAN2_RX1_irq},
{CAN2_SCE_IRQn, CAN2_SCE_irq}
{CAN2_SCE_IRQn, CAN2_SCE_irq},
{WWDG_IRQn, WWDG_IRQHandler}
};

/**
Expand Down
6 changes: 6 additions & 0 deletions hal/src/photon/dct_hal.c → hal/src/photon/dct_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string.h>
#include <stdint.h>

#include "monitor_service.h"

extern uint32_t Compute_CRC32(const uint8_t *pBuffer, uint32_t bufferSize);

// Compatibility crc32 function for WICED
Expand Down Expand Up @@ -48,6 +50,10 @@ const void* dct_read_app_data(uint32_t offset) {
}

int dct_write_app_data(const void* data, uint32_t offset, uint32_t size) {
// Erase of 16kB sector may take up to 800ms according to the datasheet
// 1 write operation takes at most 100us
// (16384 / 4) * 100us = 409ms
SYSTEM_MONITOR_EXPECT_STALL(1300);
return wiced_dct_write(data, DCT_APP_SECTION, offset, size);
}

Expand Down
6 changes: 5 additions & 1 deletion hal/src/photon/inet_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@

#include "inet_hal.h"
#include "wiced_tcpip.h"
#include "monitor_service.h"

int inet_gethostbyname(const char* hostname, uint16_t hostnameLen, HAL_IPAddress* out_ip_addr, network_interface_t nif, void* reserved)
{
wiced_ip_address_t address;
wiced_result_t result = wiced_hostname_lookup (hostname, &address, 5000);
const uint32_t timeout = 5000;
SYSTEM_MONITOR_MODIFY_TIMEOUT(timeout * 4 / 3);
wiced_result_t result = wiced_hostname_lookup (hostname, &address, timeout);
if (result == WICED_SUCCESS) {
HAL_IPV4_SET(out_ip_addr, GET_IPV4_ADDRESS(address));
}
Expand All @@ -46,6 +49,7 @@ int inet_ping(const HAL_IPAddress* address, network_interface_t nif, uint8_t nTr

int count = 0;
for (int i=0; i<nTries; i++) {
SYSTEM_MONITOR_MODIFY_TIMEOUT(ping_timeout * 4 / 3);
wiced_result_t status = wiced_ping(WICED_STA_INTERFACE, &ping_target_ip, ping_timeout, &elapsed_ms);
if (status==WICED_SUCCESS)
count++;
Expand Down
Loading