Skip to content

Commit

Permalink
Merge pull request #17 from sagar-apple/bring_system
Browse files Browse the repository at this point in the history
Add more core system components

Merging per three reviewers, thanks!
  • Loading branch information
woody-apple authored Mar 10, 2020
2 parents ee72356 + 287e9ec commit 6188b1a
Show file tree
Hide file tree
Showing 16 changed files with 3,113 additions and 34 deletions.
26 changes: 13 additions & 13 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@
* RNG implementation options:
*
* * #CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM
* * #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG
* * #CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG
* * #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL
*
* Note that these options are mutually exclusive and only one of
Expand All @@ -634,7 +634,7 @@
* implementation of the chip Random Number Generator.
*
* @note This configuration is mutual exclusive with
* #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG and
* #CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG and
* #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL.
*
*/
Expand All @@ -643,7 +643,7 @@
#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM

/**
* @def CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG
* @def CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG
*
* @brief
* Enable (1) or disable (0) support for a chip-provided
Expand All @@ -656,9 +656,9 @@
* #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL.
*
*/
#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG
#define CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG 0
#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG
#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG
#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 0
#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG

/**
* @def CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL
Expand All @@ -669,7 +669,7 @@
*
* @note This configuration is mutual exclusive with
* #CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM and
* #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG.
* #CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG.
*
*/
#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL
Expand All @@ -680,9 +680,9 @@
* @}
*/

#if ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1)
#error "Please assert exactly one of CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM, CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG, or CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL."
#endif // ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1)
#if ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1)
#error "Please assert exactly one of CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM, CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG, or CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL."
#endif // ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1)


/**
Expand All @@ -692,7 +692,7 @@
* Enable (1) or disable (0) a function for seeding the DRBG with
* entropy from the /dev/(u)random device.
*
* @note When enabled along with #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG
* @note When enabled along with #CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG
* this function becomes the default seeding function for the DRBG if
* another isn't specified at initialization time.
*
Expand Down Expand Up @@ -2270,7 +2270,7 @@
* Enable (1) or disable (0) support for the depricated
* version of AddNetwork() message in the Network Provisioning
* profile.
* This option should be enabled to support pairing with Nest
* This option should be enabled to support pairing with CHIP
* legacy devices that don't have latest SW.
*
*/
Expand All @@ -2285,7 +2285,7 @@
* Enable (1) or disable (0) the exclusive use of the depricated
* version of AddNetwork() message in the Network Provisioning
* profile.
* This option should be enabled when exclusively pairing with Nest
* This option should be enabled when exclusively pairing with CHIP
* legacy devices that don't have latest SW.
* This option requires that
* CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE is enabled.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/CHIPCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <core/CHIPConfig.h>
/*
#include <SystemLayer/SystemLayer.h>
#include <SystemLayer.h>
#if CONFIG_NETWORK_LAYER_BLE
#include <BleLayer/BleLayer.h>
Expand Down
20 changes: 14 additions & 6 deletions src/system/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ include $(TOP_DIR)/.yams/cpp_rules.min

Module_Includes = \
-I. \
-I$(TOP_DIR)/src/include \
-I$(TOP_DIR)/src/lib/ \
-I$(TOP_DIR)/build/config/standalone/
-I$(TOP_DIR)/src/include \
-I$(TOP_DIR)/src/lib/ \
-I$(TOP_DIR)/build/config/standalone/ \
-I$(TOP_DIR)/third_party/nlassert/repo/include/ \
-I$(TOP_DIR)/src/lib/core \


Module_Test_Includes = $(Module_Includes)

CPP_Files = \
SystemMutex.cpp \
SystemError.cpp \
SystemClock.cpp
SystemMutex.cpp \
SystemError.cpp \
SystemClock.cpp \
SystemObject.cpp \
SystemStats.cpp \
SystemTimer.cpp \
SystemLayer.cpp \
SystemFaultInjection.cpp \

libSystemLayer.a: $(CPP_Objects)
ar rvs $@ $^
Expand Down
11 changes: 4 additions & 7 deletions src/system/SystemClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME

#include <SystemClock.h>
// #include <support/CodeUtils.h>
#include <support/CodeUtils.h>
#include <SystemError.h>
#include "SystemLayerPrivate.h"

Expand Down Expand Up @@ -84,14 +84,12 @@ uint64_t GetClock_Monotonic(void)
#if HAVE_CLOCK_GETTIME
struct timespec ts;
int res = clock_gettime(MONOTONIC_CLOCK_ID, &ts);
// TODO: use assert library when available
if (res) { abort(); }
VerifyOrDie(res == 0);
return (ts.tv_sec * UINT64_C(1000000)) + (ts.tv_nsec / 1000);
#else // HAVE_CLOCK_GETTIME
struct timeval tv;
int res = gettimeofday(&tv, NULL);
// TODO: use assert library when available
if (res) { abort(); }
VerifyOrDie(res == 0);
return (tv.tv_sec * UINT64_C(1000000)) + tv.tv_usec;
#endif // HAVE_CLOCK_GETTIME
}
Expand All @@ -106,8 +104,7 @@ uint64_t GetClock_MonotonicHiRes(void)
#if HAVE_CLOCK_GETTIME && defined(MONOTONIC_RAW_CLOCK_ID)
struct timespec ts;
int res = clock_gettime(MONOTONIC_RAW_CLOCK_ID, &ts);
// TODO: use assert library when available
if (res) { abort(); }
VerifyOrDie(res == 0);
return (ts.tv_sec * UINT64_C(1000000)) + (ts.tv_nsec / 1000);
#else // HAVE_CLOCK_GETTIME
return GetClock_Monotonic();
Expand Down
14 changes: 7 additions & 7 deletions src/system/SystemClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Layer {
* This function is expected to be thread-safe on any platform that employs threading.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_Monotonic().
*
* @returns Elapsed time in microseconds since an arbitrary, platform-defined epoch.
Expand All @@ -85,7 +85,7 @@ extern uint64_t GetClock_Monotonic(void);
* This function is expected to be thread-safe on any platform that employs threading.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_MonotonicMS().
*
* @returns Elapsed time in milliseconds since an arbitrary, platform-defined epoch.
Expand All @@ -111,7 +111,7 @@ extern uint64_t GetClock_MonotonicMS(void);
* This function is expected to be thread-safe on any platform that employs threading.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_MonotonicHiRes().
*
* @returns Elapsed time in microseconds since an arbitrary, platform-defined epoch.
Expand All @@ -138,7 +138,7 @@ extern uint64_t GetClock_MonotonicHiRes(void);
* This function is expected to be thread-safe on any platform that employs threading.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_RealTime().
*
* @param[out] curTime The current time, expressed as Unix time scaled to microseconds.
Expand All @@ -163,7 +163,7 @@ extern Error GetClock_RealTime(uint64_t & curTime);
* See the documentation for GetClock_RealTime() for details on the expected behavior.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_RealTimeMS().
*
* @param[out] curTime The current time, expressed as Unix time scaled to milliseconds.
Expand All @@ -181,7 +181,7 @@ extern Error GetClock_RealTimeMS(uint64_t & curTimeMS);
* @brief
* Platform-specific function for setting the current real (civil) time.
*
* Weave calls this function to set the local platform's notion of current real time. The new current
* CHIP calls this function to set the local platform's notion of current real time. The new current
* time is expressed as a Unix time value scaled to microseconds.
*
* Once set, underlying platform clock is expected to track real time with a granularity of at least whole
Expand All @@ -199,7 +199,7 @@ extern Error GetClock_RealTimeMS(uint64_t & curTimeMS);
* This function is expected to be thread-safe on any platform that employs threading.
*
* @note
* This function is reserved for internal use by the Weave System Layer. Users of the Weave System
* This function is reserved for internal use by the CHIP System Layer. Users of the CHIP System
* Layer should call System::Layer::GetClock_RealTimeMS().
*
* @param[in] newCurTime The new current time, expressed as Unix time scaled to microseconds.
Expand Down
79 changes: 79 additions & 0 deletions src/system/SystemEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
*
* <COPYRIGHT>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file enumerates and defines the different types of events
* generated at the CHIP System Layer.
*/

#ifndef SYSTEMEVENT_H
#define SYSTEMEVENT_H

// Include headers
#include <SystemConfig.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP

namespace chip {
namespace System {

/**
* @typedef EventType
* The basic type for all InetLayer events.
*
* This is defined to a platform- or system-specific type.
*
*/
typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE EventType;

/**
* @typedef Event
* The basic object for all InetLayer events.
*
* This is defined to a platform- or system-specific type.
*
*/
typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE Event;

/**
* The Inet layer event type definitions.
*
*/
enum
{
kEvent_ReleaseObj = _CHIP_SYSTEM_CONFIG_LWIP_EVENT(0), /**< The event for the drop of a SystemLayer object */
kEvent_ScheduleWork = _CHIP_SYSTEM_CONFIG_LWIP_EVENT(1), /**< The event for scheduling work on the System Layer's thread. */
};

/**
* Check to verify if an EventType is a valid one.
*
* @param[in] aEventType CHIP System Layer event type.
*
* @return true if it falls within the enumerated range; otherwise, false.
*/
static inline bool IsEventOfType(EventType aType)
{
return (aType >= kEvent_ReleaseObj && aType <= kEvent_ScheduleWork);
}

} // namespace System
} // namespace chip

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#endif // defined(SYSTEMEVENT_H)
Loading

0 comments on commit 6188b1a

Please sign in to comment.