diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOS_Plus_POSIX_with_actor.sln b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOS_Plus_POSIX_with_actor.sln
index 7f67bc7..4443b91 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOS_Plus_POSIX_with_actor.sln
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOS_Plus_POSIX_with_actor.sln
@@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTOSDemo", "WIN32.vcxproj", "{C686325E-3261-42F7-AEB1-DDE5280E1CEB}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTOS_POSIX_Demo", "WIN32.vcxproj", "{C686325E-3261-42F7-AEB1-DDE5280E1CEB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,4 +19,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {18112148-F9F0-43E0-B713-B146289BDEF3}
+ EndGlobalSection
EndGlobal
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj
index 76d8b13..e2b95db 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj
@@ -13,7 +13,6 @@
{C686325E-3261-42F7-AEB1-DDE5280E1CEB}
RTOS_POSIX_Demo
- 10.0.17763.0
@@ -132,7 +131,6 @@
-
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj.filters b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj.filters
index c4ff3ea..60e3a44 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj.filters
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj.filters
@@ -90,9 +90,6 @@
lib\FreeRTOS\Portable\MSVC-W
-
- lib\FreeRTOS
-
lib\FreeRTOS
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h
index ab39b69..d938709 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -35,7 +35,7 @@
/* FreeRTOS+POSIX platform-specific configuration headers. */
#include "FreeRTOS_POSIX_portable.h"
-#include "portable/FreeRTOS_POSIX_portable_default.h"
+#include "FreeRTOS_POSIX_portable_default.h"
/* FreeRTOS includes. */
#include "FreeRTOS.h"
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_internal.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_internal.h
index 5282154..16f8036 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_internal.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_internal.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -32,64 +32,98 @@
*/
/* Amazon FreeRTOS includes. */
-#include "aws_doubly_linked_list.h"
+#include "iot_doubly_linked_list.h"
/**
* @brief Mutex attribute object.
*/
-typedef struct pthread_mutexattr_internal
-{
- int iType; /**< Mutex type. */
-} pthread_mutexattr_internal_t;
+#if posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1
+ typedef struct pthread_mutexattr_internal
+ {
+ int iType; /**< Mutex type. */
+ } pthread_mutexattr_internal_t;
+#endif
+
+#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
/**
* @brief Mutex.
*/
-typedef struct pthread_mutex_internal
-{
- BaseType_t xIsInitialized; /**< Set to pdTRUE if this mutex is initialized, pdFALSE otherwise. */
- StaticSemaphore_t xMutex; /**< FreeRTOS mutex. */
- TaskHandle_t xTaskOwner; /**< Owner; used for deadlock detection and permission checks. */
- pthread_mutexattr_internal_t xAttr; /**< Mutex attributes. */
-} pthread_mutex_internal_t;
+ typedef struct pthread_mutex_internal
+ {
+ BaseType_t xIsInitialized; /**< Set to pdTRUE if this mutex is initialized, pdFALSE otherwise. */
+ StaticSemaphore_t xMutex; /**< FreeRTOS mutex. */
+ TaskHandle_t xTaskOwner; /**< Owner; used for deadlock detection and permission checks. */
+ pthread_mutexattr_internal_t xAttr; /**< Mutex attributes. */
+ } pthread_mutex_internal_t;
/**
* @brief Compile-time initializer of pthread_mutex_internal_t.
*/
-#define FREERTOS_POSIX_MUTEX_INITIALIZER \
- ( &( ( pthread_mutex_internal_t ) \
- { \
- .xIsInitialized = pdFALSE, \
- .xMutex = { { 0 } }, \
- .xTaskOwner = NULL, \
- .xAttr = { .iType = 0 } \
- } \
- ) \
+ #define FREERTOS_POSIX_MUTEX_INITIALIZER \
+ ( ( ( pthread_mutex_internal_t ) \
+ { \
+ .xIsInitialized = pdFALSE, \
+ .xMutex = { { 0 } }, \
+ .xTaskOwner = NULL, \
+ .xAttr = { .iType = 0 } \
+ } \
+ ) \
)
+#endif /* if posixconfigENABLE_PTHREAD_MUTEX_T == 1 */
+
+#if posixconfigENABLE_PTHREAD_COND_T == 1
/**
* @brief Condition variable.
*/
-typedef struct pthread_cond_internal
-{
- BaseType_t xIsInitialized; /**< Set to pdTRUE if this condition variable is initialized, pdFALSE otherwise. */
- StaticSemaphore_t xCondMutex; /**< Prevents concurrent accesses to iWaitingThreads. */
- StaticSemaphore_t xCondWaitSemaphore; /**< Threads block on this semaphore in pthread_cond_wait. */
- int iWaitingThreads; /**< The number of threads currently waiting on this condition variable. */
-} pthread_cond_internal_t;
+ typedef struct pthread_cond_internal
+ {
+ BaseType_t xIsInitialized; /**< Set to pdTRUE if this condition variable is initialized, pdFALSE otherwise. */
+ StaticSemaphore_t xCondWaitSemaphore; /**< Threads block on this semaphore in pthread_cond_wait. */
+ unsigned iWaitingThreads; /**< The number of threads currently waiting on this condition variable. */
+ } pthread_cond_internal_t;
/**
* @brief Compile-time initializer of pthread_cond_internal_t.
*/
-#define FREERTOS_POSIX_COND_INITIALIZER \
- ( &( ( pthread_cond_internal_t ) \
- { \
- .xIsInitialized = pdFALSE, \
- .xCondMutex = { { 0 } }, \
- .xCondWaitSemaphore = { { 0 } },\
- .iWaitingThreads = 0 \
- } \
- ) \
+
+ #define FREERTOS_POSIX_COND_INITIALIZER \
+ ( ( ( pthread_cond_internal_t ) \
+ { \
+ .xIsInitialized = pdFALSE, \
+ .xCondWaitSemaphore = { { 0 } }, \
+ .iWaitingThreads = 0 \
+ } \
+ ) \
)
+#endif /* if posixconfigENABLE_PTHREAD_COND_T == 1 */
+
+#if posixconfigENABLE_SEM_T == 1
+
+/**
+ * @brief Semaphore type.
+ */
+ typedef struct
+ {
+ StaticSemaphore_t xSemaphore; /**< FreeRTOS semaphore. */
+ int value; /**< POSIX semaphore count. */
+ } sem_internal_t;
+#endif /* if posixconfigENABLE_SEM_T == 1 */
+
+#if posixconfigENABLE_PTHREAD_BARRIER_T == 1
+
+/**
+ * @brief Barrier object.
+ */
+ typedef struct pthread_barrier_internal
+ {
+ unsigned uThreadCount; /**< Current number of threads that have entered barrier. */
+ unsigned uThreshold; /**< The count argument of pthread_barrier_init. */
+ StaticSemaphore_t xThreadCountSemaphore; /**< Prevents more than uThreshold threads from exiting pthread_barrier_wait at once. */
+ StaticEventGroup_t xBarrierEventGroup; /**< FreeRTOS event group that blocks to wait on threads entering barrier. */
+ } pthread_barrier_internal_t;
+#endif /* if posixconfigENABLE_PTHREAD_BARRIER_T == 1 */
+
#endif /* _FREERTOS_POSIX_INTERNAL_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_types.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_types.h
new file mode 100755
index 0000000..3b45b8d
--- /dev/null
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX_types.h
@@ -0,0 +1,81 @@
+/*
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+#ifndef _FREERTOS_POSIX_INTERNAL_TYPES_H_
+#define _FREERTOS_POSIX_INTERNAL_TYPES_H_
+
+#include "FreeRTOS_POSIX_internal.h"
+
+/*
+ * sys/types.h defines a POSIX type when posixconfigENABLE_PTHREAD__T
+ * is not defined AND when posixconfigENABLE_PTHREAD__T is set to 1.
+ * FreeRTOS_POSIX_internal.h defines internal type ONLY when
+ * posixconfigENABLE_PTHREAD__T is set to 1.
+ * #else part below is to have a type defined, so the code compiles, when
+ * posixconfigENABLE_PTHREAD__T is not defined.
+ */
+#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
+ typedef pthread_mutex_internal_t PthreadMutexType_t;
+#else
+ typedef void * PthreadMutexType_t;
+#endif
+
+#if posixconfigENABLE_PTHREAD_COND_T == 1
+ typedef pthread_cond_internal_t PthreadCondType_t;
+#else
+ typedef void * PthreadCondType_t;
+#endif
+
+#if posixconfigENABLE_SEM_T == 1
+ typedef sem_internal_t PosixSemType_t;
+#else
+ typedef void * PosixSemType_t;
+#endif
+
+#if posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1
+ typedef struct pthread_mutexattr
+ {
+ uint32_t ulpthreadMutexAttrStorage;
+ } PthreadMutexAttrType_t;
+#else
+ typedef void * PthreadMutexAttrType_t;
+#endif
+
+#if posixconfigENABLE_PTHREAD_ATTR_T == 1
+ typedef struct pthread_attr
+ {
+ uint32_t ulpthreadAttrStorage;
+ } PthreadAttrType_t;
+#else
+ typedef void * PthreadAttrType_t;
+#endif
+
+#if posixconfigENABLE_PTHREAD_BARRIER_T == 1
+ typedef pthread_barrier_internal_t PthreadBarrierType_t;
+#else
+ typedef void * PthreadBarrierType_t;
+#endif
+
+#endif /* _FREERTOS_POSIX_INTERNAL_TYPES_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/FreeRTOS_POSIX_portable_default.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/FreeRTOS_POSIX_portable_default.h
index 8b0a7cd..763b901 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/FreeRTOS_POSIX_portable_default.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/FreeRTOS_POSIX_portable_default.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -32,21 +32,25 @@
#define _FREERTOS_POSIX_PORTABLE_DEFAULT_H_
/**
- * @brief The FreeRTOS task name given to pthreads.
+ * @name The FreeRTOS task name given to pthreads.
*/
+/**@{ */
#ifndef posixconfigPTHREAD_TASK_NAME
- #define posixconfigPTHREAD_TASK_NAME "pthread"
+ #define posixconfigPTHREAD_TASK_NAME "pthread" /**< Task name. */
#endif
+/**@} */
/**
- * @brief the FreeRTOS timer name given to POSIX timers.
+ * @name the FreeRTOS timer name given to POSIX timers.
*/
+/**@{ */
#ifndef posixconfigTIMER_NAME
- #define posixconfigTIMER_NAME "timer"
+ #define posixconfigTIMER_NAME "timer" /**< Timer name. */
#endif
+/**@} */
/**
- * @defgroup Defaults for POSIX message queue implementation.
+ * @name Defaults for POSIX message queue implementation.
*/
/**@{ */
#ifndef posixconfigMQ_MAX_MESSAGES
@@ -59,7 +63,7 @@
/**@} */
/**
- * @defgroup POSIX implementation-dependent constants usually defined in limits.h.
+ * @name POSIX implementation-dependent constants usually defined in limits.h.
*
* They are defined here to provide portability between platforms.
*/
@@ -71,12 +75,12 @@
#define NAME_MAX 64 /**< Maximum number of bytes in a filename (not including terminating null). */
#endif
#ifndef SEM_VALUE_MAX
- #define SEM_VALUE_MAX 0xFFFFU /**< Maximum value of a sem_t. */
+ #define SEM_VALUE_MAX 0x7FFFU /**< Maximum value of a sem_t. */
#endif
/**@} */
/**
- * @defgroup Enable typedefs of POSIX types.
+ * @name Enable typedefs of POSIX types.
*
* Set these values to 1 or 0 to enable or disable the typedefs, respectively.
* These typedefs should only be disabled if they conflict with system typedefs.
@@ -130,8 +134,11 @@
#ifndef posixconfigENABLE_ITIMERSPEC
#define posixconfigENABLE_ITIMERSPEC 1 /**< struct itimerspec in time.h */
#endif
-#ifndef posixconfigENABLE_TM
- #define posixconfigENABLE_TM 1 /**< struct tm in time.h */
+#ifndef posixconfigENABLE_SEM_T
+ #define posixconfigENABLE_SEM_T 1 /**< struct sem_t in semaphore.h */
+#endif
+#ifndef posixconfigENABLE_PTHREAD_BARRIER_T
+ #define posixconfigENABLE_PTHREAD_BARRIER_T 1 /**< pthread_barrier_t in sys/types.h */
#endif
/**@} */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit/FreeRTOS_POSIX_portable.h
index 2686cc9..c187043 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -42,12 +42,19 @@
#define posixconfigENABLE_PTHREAD_MUTEXATTR_T 0
#define posixconfigENABLE_PTHREAD_T 0
#define posixconfigENABLE_TIME_T 0
-#define posixconfigENABLE_TIMER_T 0
#define posixconfigENABLE_TIMESPEC 0
#define posixconfigENABLE_ITIMERSPEC 0
-/* ESP-IDF already provides the header sched.h. Exclude them by
- * activating the double inclusion guards. */
+/* ESP-IDF already provides the header sched.h. Exclude FreeRTOS+POSIX sched.h by
+ * defining its double inclusion guard. */
#define _FREERTOS_POSIX_SCHED_H_
+/* Use the FreeRTOS+POSIX time.h header instead of the ESP-IDF time.h. Disable
+ * ESP-IDF time.h by defining its double inclusion guard. */
+#define _TIME_H_
+
+/* Disable the timer_t type defined by ESP-IDF. */
+#define __timer_t_defined
+#include
+
#endif /* _FREERTOS_POSIX_PORTABLE_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/microchip/curiosity_pic32mzef/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/microchip/curiosity_pic32mzef/FreeRTOS_POSIX_portable.h
index 5ff2a9c..d4d2db7 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/microchip/curiosity_pic32mzef/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/microchip/curiosity_pic32mzef/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.1
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/nxp/lpc54018iotmodule/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/nxp/lpc54018iotmodule/FreeRTOS_POSIX_portable.h
index 1976064..1022f4b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/nxp/lpc54018iotmodule/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/nxp/lpc54018iotmodule/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/pc/windows/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/pc/windows/FreeRTOS_POSIX_portable.h
index 1976064..1022f4b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/pc/windows/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/pc/windows/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/st/stm32l475_discovery/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/st/stm32l475_discovery/FreeRTOS_POSIX_portable.h
index 1976064..1022f4b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/st/stm32l475_discovery/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/st/stm32l475_discovery/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/ti/cc3220_launchpad/FreeRTOS_POSIX_portable.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/ti/cc3220_launchpad/FreeRTOS_POSIX_portable.h
index 1976064..1022f4b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/ti/cc3220_launchpad/FreeRTOS_POSIX_portable.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/ti/cc3220_launchpad/FreeRTOS_POSIX_portable.h
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS+POSIX V1.0.4
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_clock.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_clock.c
index dcb397b..51e592a 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_clock.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_clock.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -31,7 +31,6 @@
/* C standard library includes. */
#include
#include
-#include
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX.h"
@@ -39,13 +38,20 @@
#include "FreeRTOS_POSIX/time.h"
#include "FreeRTOS_POSIX/utils.h"
+/* Declaration of snprintf. The header stdio.h is not included because it
+ * includes conflicting symbols on some platforms. */
+extern int snprintf( char * s,
+ size_t n,
+ const char * format,
+ ... );
+
/*-----------------------------------------------------------*/
clock_t clock( void )
{
- /* Return the amount of time since the scheduler started that wasn't spent
- * in the idle task. */
- return ( clock_t ) ( xTaskGetTickCount() - xTaskGetIdleTickCount() );
+ /* This function is currently unsupported. It will always return -1. */
+
+ return ( clock_t ) -1;
}
/*-----------------------------------------------------------*/
@@ -57,6 +63,7 @@ int clock_getcpuclockid( pid_t pid,
( void ) pid;
( void ) clock_id;
+ /* This function is currently unsupported. It will always return EPERM. */
return EPERM;
}
@@ -84,7 +91,6 @@ int clock_gettime( clockid_t clock_id,
struct timespec * tp )
{
TimeOut_t xCurrentTime = { 0 };
- int iStatus = 0;
/* Intermediate variable used to convert TimeOut_t to struct timespec.
* Also used to detect overflow issues. It must be unsigned because the
@@ -94,24 +100,21 @@ int clock_gettime( clockid_t clock_id,
/* Silence warnings about unused parameters. */
( void ) clock_id;
- if( iStatus == 0 )
- {
- /* Get the current tick count and overflow count. vTaskSetTimeOutState()
- * is used to get these values because they are both static in tasks.c. */
- vTaskSetTimeOutState( &xCurrentTime );
+ /* Get the current tick count and overflow count. vTaskSetTimeOutState()
+ * is used to get these values because they are both static in tasks.c. */
+ vTaskSetTimeOutState( &xCurrentTime );
- /* Adjust the tick count for the number of times a TickType_t has overflowed.
- * portMAX_DELAY should be the maximum value of a TickType_t. */
- ullTickCount = ( uint64_t ) ( xCurrentTime.xOverflowCount ) << ( sizeof( TickType_t ) * 8 );
+ /* Adjust the tick count for the number of times a TickType_t has overflowed.
+ * portMAX_DELAY should be the maximum value of a TickType_t. */
+ ullTickCount = ( uint64_t ) ( xCurrentTime.xOverflowCount ) << ( sizeof( TickType_t ) * 8 );
- /* Add the current tick count. */
- ullTickCount += xCurrentTime.xTimeOnEntering;
+ /* Add the current tick count. */
+ ullTickCount += xCurrentTime.xTimeOnEntering;
- /* Convert ullTickCount to timespec. */
- UTILS_NanosecondsToTimespec( ( int64_t ) ullTickCount * NANOSECONDS_PER_TICK, tp );
- }
+ /* Convert ullTickCount to timespec. */
+ UTILS_NanosecondsToTimespec( ( int64_t ) ullTickCount * NANOSECONDS_PER_TICK, tp );
- return iStatus;
+ return 0;
}
/*-----------------------------------------------------------*/
@@ -123,6 +126,7 @@ int clock_nanosleep( clockid_t clock_id,
{
int iStatus = 0;
TickType_t xSleepTime = 0;
+ struct timespec xCurrentTime = { 0 };
/* Silence warnings about unused parameters. */
( void ) clock_id;
@@ -135,13 +139,25 @@ int clock_nanosleep( clockid_t clock_id,
iStatus = EINVAL;
}
+ /* Get current time */
+ if( ( iStatus == 0 ) && ( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 ) )
+ {
+ iStatus = EINVAL;
+ }
+
if( iStatus == 0 )
{
/* Check for absolute time sleep. */
if( ( flags & TIMER_ABSTIME ) == TIMER_ABSTIME )
{
+ /* Get current time */
+ if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
+ {
+ iStatus = EINVAL;
+ }
+
/* Get number of ticks until absolute time. */
- if( UTILS_AbsoluteTimespecToTicks( rqtp, &xSleepTime ) == 0 )
+ if( ( iStatus == 0 ) && ( UTILS_AbsoluteTimespecToDeltaTicks( rqtp, &xCurrentTime, &xSleepTime ) == 0 ) )
{
/* Delay until absolute time if vTaskDelayUntil is available. */
#if ( INCLUDE_vTaskDelayUntil == 1 )
@@ -193,32 +209,6 @@ int clock_settime( clockid_t clock_id,
/*-----------------------------------------------------------*/
-struct tm * localtime_r( const time_t * timer,
- struct tm * result )
-{
- /* Silence warnings about unused parameters. */
- ( void ) timer;
- ( void ) result;
-
- /* This function is only supported if the "custom" FreeRTOS+POSIX tm struct
- * is used. */
- #if ( posixconfigENABLE_TM == 0 )
- errno = ENOTSUP;
-
- return NULL;
- #else
-
- /* Zero the tm, then store the FreeRTOS tick count. The input parameter
- * timer isn't used. */
- ( void ) memset( result, 0x00, sizeof( struct tm ) );
- result->tm_tick = ( time_t ) xTaskGetTickCount();
-
- return result;
- #endif
-}
-
-/*-----------------------------------------------------------*/
-
int nanosleep( const struct timespec * rqtp,
struct timespec * rmtp )
{
@@ -248,44 +238,3 @@ int nanosleep( const struct timespec * rqtp,
}
/*-----------------------------------------------------------*/
-
-size_t strftime( char * s,
- size_t maxsize,
- const char * format,
- const struct tm * timeptr )
-{
- int iStatus = 0;
- size_t bytesPrinted = 0;
-
- /* Silence warnings about unused parameters. */
- ( void ) format;
-
- /* Print the time in the buffer. */
- iStatus = snprintf( s, maxsize, "%ld", ( long int ) timeptr->tm_tick );
-
- /* Check for encoding and size errors. */
- if( ( iStatus > 0 ) && ( ( size_t ) iStatus < maxsize ) )
- {
- bytesPrinted = ( size_t ) iStatus;
- }
-
- return bytesPrinted;
-}
-
-/*-----------------------------------------------------------*/
-
-time_t time( time_t * tloc )
-{
- /* Read the current FreeRTOS tick count and convert it to seconds. */
- time_t xCurrentTime = ( time_t ) ( xTaskGetTickCount() / configTICK_RATE_HZ );
-
- /* Set the output parameter if provided. */
- if( tloc != NULL )
- {
- *tloc = xCurrentTime;
- }
-
- return xCurrentTime;
-}
-
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_mqueue.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_mqueue.c
index 49d394b..9f9079b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_mqueue.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_mqueue.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -142,7 +142,7 @@ static BaseType_t prvValidateQueueName( const char * const pcName,
/**
* @brief Guards access to the list of message queues.
*/
-static StaticSemaphore_t xQueueListMutex = { { 0 } };
+static StaticSemaphore_t xQueueListMutex = { { 0 }, .u = { 0 } };
/**
* @brief Head of the linked list of queues.
@@ -172,15 +172,23 @@ static int prvCalculateTickTimeout( long lMessageQueueFlags,
}
else
{
+ struct timespec xCurrentTime = { 0 };
+
/* Check that the given timespec is valid. */
if( UTILS_ValidateTimespec( pxAbsoluteTimeout ) == false )
{
iStatus = EINVAL;
}
+ /* Get current time */
+ if( ( iStatus == 0 ) && ( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 ) )
+ {
+ iStatus = EINVAL;
+ }
+
/* Convert absolute timespec to ticks. */
if( ( iStatus == 0 ) &&
- ( UTILS_AbsoluteTimespecToTicks( pxAbsoluteTimeout, pxTimeoutTicks ) != 0 ) )
+ ( UTILS_AbsoluteTimespecToDeltaTicks( pxAbsoluteTimeout, &xCurrentTime, pxTimeoutTicks ) != 0 ) )
{
iStatus = ETIMEDOUT;
}
@@ -404,7 +412,7 @@ int mq_close( mqd_t mqdes )
if( prvFindQueueInList( NULL, NULL, mqdes ) == pdTRUE )
{
/* Decrement the number of open descriptors. */
- if(pxMessageQueue->xOpenDescriptors > 0)
+ if( pxMessageQueue->xOpenDescriptors > 0 )
{
pxMessageQueue->xOpenDescriptors--;
}
@@ -494,7 +502,7 @@ mqd_t mq_open( const char * name,
/* Default mq_attr. */
struct mq_attr xQueueCreationAttr =
{
- .mq_flags = 0,
+ .mq_flags = 0,
.mq_maxmsg = posixconfigMQ_MAX_MESSAGES,
.mq_msgsize = posixconfigMQ_MAX_SIZE,
.mq_curmsgs = 0
@@ -514,7 +522,7 @@ mqd_t mq_open( const char * name,
xMessageQueue = ( mqd_t ) -1;
}
- /* Check attributes, if O_CREATE is specified and attr is given. */
+ /* Check attributes, if given. */
if( xMessageQueue == NULL )
{
if( ( oflag & O_CREAT ) && ( attr != NULL ) && ( ( attr->mq_maxmsg <= 0 ) || ( attr->mq_msgsize <= 0 ) ) )
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c
index 7d08f56..f34e9ec 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -30,6 +30,7 @@
/* C standard library includes. */
#include
+#include
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX.h"
@@ -41,11 +42,16 @@
*/
typedef struct pthread_attr_internal
{
- size_t xStackSize; /**< Stack size. */
- int iDetachState; /**< Detach state: joinable or detached. */
- struct sched_param xSchedParam; /**< Scheduler parameters. */
+ uint16_t usStackSize; /**< Stack size. */
+ uint16_t usSchedPriorityDetachState; /**< Schedule priority 15 bits (LSB) Detach state: 1 bits (MSB) */
} pthread_attr_internal_t;
+#define pthreadDETACH_STATE_MASK 0x8000
+#define pthreadSCHED_PRIORITY_MASK 0x7FFF
+#define pthreadDETACH_STATE_SHIFT 15
+#define pthreadGET_SCHED_PRIORITY( var ) ( ( var ) & ( pthreadSCHED_PRIORITY_MASK ) )
+#define pthreadIS_JOINABLE( var ) ( ( ( var ) & ( pthreadDETACH_STATE_MASK ) ) == pthreadDETACH_STATE_MASK )
+
/**
* @brief Thread object.
*/
@@ -85,9 +91,8 @@ static void prvRunThread( void * pxArg );
*/
static const pthread_attr_internal_t xDefaultThreadAttributes =
{
- .xStackSize = PTHREAD_STACK_MIN,
- .iDetachState = PTHREAD_CREATE_JOINABLE,
- .xSchedParam = { .sched_priority = tskIDLE_PRIORITY }
+ .usStackSize = PTHREAD_STACK_MIN,
+ .usSchedPriorityDetachState = ( ( uint16_t ) tskIDLE_PRIORITY & pthreadSCHED_PRIORITY_MASK ) | ( PTHREAD_CREATE_JOINABLE << pthreadDETACH_STATE_SHIFT ),
};
/*-----------------------------------------------------------*/
@@ -97,7 +102,7 @@ static void prvExitThread( void )
pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread_self();
/* If this thread is joinable, wait for a call to pthread_join. */
- if( pxThread->xAttr.iDetachState == PTHREAD_CREATE_JOINABLE )
+ if( pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) )
{
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinBarrier );
@@ -130,9 +135,9 @@ static void prvRunThread( void * pxArg )
int pthread_attr_destroy( pthread_attr_t * attr )
{
- int iStatus = 0;
- vPortFree( *attr );
- return iStatus;
+ ( void ) attr;
+
+ return 0;
}
/*-----------------------------------------------------------*/
@@ -140,9 +145,16 @@ int pthread_attr_destroy( pthread_attr_t * attr )
int pthread_attr_getdetachstate( const pthread_attr_t * attr,
int * detachstate )
{
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
- *detachstate = pxAttr->iDetachState;
+ if( pthreadIS_JOINABLE( pxAttr->usSchedPriorityDetachState ) )
+ {
+ *detachstate = PTHREAD_CREATE_JOINABLE;
+ }
+ else
+ {
+ *detachstate = PTHREAD_CREATE_DETACHED;
+ }
return 0;
}
@@ -152,9 +164,9 @@ int pthread_attr_getdetachstate( const pthread_attr_t * attr,
int pthread_attr_getschedparam( const pthread_attr_t * attr,
struct sched_param * param )
{
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
- *param = pxAttr->xSchedParam;
+ param->sched_priority = ( int ) ( pthreadGET_SCHED_PRIORITY( pxAttr->usSchedPriorityDetachState ) );
return 0;
}
@@ -164,9 +176,9 @@ int pthread_attr_getschedparam( const pthread_attr_t * attr,
int pthread_attr_getstacksize( const pthread_attr_t * attr,
size_t * stacksize )
{
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
- *stacksize = pxAttr->xStackSize;
+ *stacksize = ( size_t ) pxAttr->usStackSize;
return 0;
}
@@ -175,24 +187,10 @@ int pthread_attr_getstacksize( const pthread_attr_t * attr,
int pthread_attr_init( pthread_attr_t * attr )
{
- int iStatus = 0;
-
- /* Allocate memory for a new thread attributes object. */
- *attr = pvPortMalloc( sizeof( pthread_attr_internal_t ) );
-
- /* Check that thread attributes object was successfully allocated. */
- if( *attr == NULL )
- {
- iStatus = ENOMEM;
- }
-
/* Copy the default values into the new thread attributes object. */
- if( iStatus == 0 )
- {
- *( ( pthread_attr_internal_t * ) ( *attr ) ) = xDefaultThreadAttributes;
- }
+ *( ( pthread_attr_internal_t * ) ( attr ) ) = xDefaultThreadAttributes;
- return iStatus;
+ return 0;
}
/*-----------------------------------------------------------*/
@@ -201,7 +199,7 @@ int pthread_attr_setdetachstate( pthread_attr_t * attr,
int detachstate )
{
int iStatus = 0;
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
if( ( detachstate != PTHREAD_CREATE_DETACHED ) && ( detachstate != PTHREAD_CREATE_JOINABLE ) )
{
@@ -209,7 +207,9 @@ int pthread_attr_setdetachstate( pthread_attr_t * attr,
}
else
{
- pxAttr->iDetachState = detachstate;
+ /* clear and then set msb bit to detachstate) */
+ pxAttr->usSchedPriorityDetachState &= ~pthreadDETACH_STATE_MASK;
+ pxAttr->usSchedPriorityDetachState |= ( ( uint16_t ) detachstate << pthreadDETACH_STATE_SHIFT );
}
return iStatus;
@@ -221,7 +221,7 @@ int pthread_attr_setschedparam( pthread_attr_t * attr,
const struct sched_param * param )
{
int iStatus = 0;
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
/* Check for NULL param. */
if( param == NULL )
@@ -240,7 +240,9 @@ int pthread_attr_setschedparam( pthread_attr_t * attr,
/* Set the sched_param. */
if( iStatus == 0 )
{
- pxAttr->xSchedParam = *param;
+ /* clear and then set 15 LSB to schedule priority) */
+ pxAttr->usSchedPriorityDetachState &= ~pthreadSCHED_PRIORITY_MASK;
+ pxAttr->usSchedPriorityDetachState |= ( ( uint16_t ) param->sched_priority );
}
return iStatus;
@@ -248,11 +250,23 @@ int pthread_attr_setschedparam( pthread_attr_t * attr,
/*-----------------------------------------------------------*/
+int pthread_attr_setschedpolicy( pthread_attr_t * attr,
+ int policy )
+{
+ /* Silence warnings about unused parameters. */
+ ( void ) attr;
+ ( void ) policy;
+
+ return 0;
+}
+
+/*-----------------------------------------------------------*/
+
int pthread_attr_setstacksize( pthread_attr_t * attr,
size_t stacksize )
{
int iStatus = 0;
- pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( *attr );
+ pthread_attr_internal_t * pxAttr = ( pthread_attr_internal_t * ) ( attr );
if( stacksize < PTHREAD_STACK_MIN )
{
@@ -260,7 +274,7 @@ int pthread_attr_setstacksize( pthread_attr_t * attr,
}
else
{
- pxAttr->xStackSize = stacksize;
+ pxAttr->usStackSize = ( uint16_t ) stacksize;
}
return iStatus;
@@ -275,6 +289,7 @@ int pthread_create( pthread_t * thread,
{
int iStatus = 0;
pthread_internal_t * pxThread = NULL;
+ struct sched_param xSchedParam = { .sched_priority = tskIDLE_PRIORITY };
/* Allocate memory for new thread object. */
pxThread = ( pthread_internal_t * ) pvPortMalloc( sizeof( pthread_internal_t ) );
@@ -295,16 +310,20 @@ int pthread_create( pthread_t * thread,
/* Otherwise, use provided attributes. */
else
{
- pxThread->xAttr = *( ( pthread_attr_internal_t * ) ( *attr ) );
+ pxThread->xAttr = *( ( pthread_attr_internal_t * ) ( attr ) );
}
+ /* Get priority from attributes */
+ xSchedParam.sched_priority = ( int ) pthreadGET_SCHED_PRIORITY( pxThread->xAttr.usSchedPriorityDetachState );
+
/* Set argument and start routine. */
pxThread->xTaskArg = arg;
pxThread->pvStartRoutine = startroutine;
/* If this thread is joinable, create the synchronization mechanisms for
* pthread_join. */
- if( pxThread->xAttr.iDetachState == PTHREAD_CREATE_JOINABLE )
+
+ if( pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) )
{
/* These calls will not fail when their arguments aren't NULL. */
( void ) xSemaphoreCreateMutexStatic( &pxThread->xJoinMutex );
@@ -321,9 +340,9 @@ int pthread_create( pthread_t * thread,
/* Create the FreeRTOS task that will run the pthread. */
if( xTaskCreate( prvRunThread,
posixconfigPTHREAD_TASK_NAME,
- ( uint16_t ) ( pxThread->xAttr.xStackSize / sizeof( StackType_t ) ),
+ ( uint16_t ) ( pxThread->xAttr.usStackSize / sizeof( StackType_t ) ),
( void * ) pxThread,
- pxThread->xAttr.xSchedParam.sched_priority,
+ xSchedParam.sched_priority,
&pxThread->xTaskHandle ) != pdPASS )
{
/* Task creation failed, no memory. */
@@ -352,12 +371,13 @@ int pthread_getschedparam( pthread_t thread,
int * policy,
struct sched_param * param )
{
+ int iStatus = 0;
pthread_internal_t * pxThread = ( pthread_internal_t * ) thread;
*policy = SCHED_OTHER;
- *param = pxThread->xAttr.xSchedParam;
+ param->sched_priority = ( int ) pthreadGET_SCHED_PRIORITY( pxThread->xAttr.usSchedPriorityDetachState );
- return 0;
+ return iStatus;
}
/*-----------------------------------------------------------*/
@@ -391,7 +411,7 @@ int pthread_join( pthread_t pthread,
/* Make sure pthread is joinable. Otherwise, this function would block
* forever waiting for an unjoinable thread. */
- if( pxThread->xAttr.iDetachState != PTHREAD_CREATE_JOINABLE )
+ if( !pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) )
{
iStatus = EDEADLK;
}
@@ -468,18 +488,23 @@ int pthread_setschedparam( pthread_t thread,
int policy,
const struct sched_param * param )
{
+ int iStatus = 0;
+
pthread_internal_t * pxThread = ( pthread_internal_t * ) thread;
/* Silence compiler warnings about unused parameters. */
( void ) policy;
- /* Copy the give sched_param. */
- pxThread->xAttr.xSchedParam = *param;
+ /* Copy the given sched_param. */
+ iStatus = pthread_attr_setschedparam( ( pthread_attr_t * ) &pxThread->xAttr, param );
- /* Change the priority of the FreeRTOS task. */
- vTaskPrioritySet( pxThread->xTaskHandle, pxThread->xAttr.xSchedParam.sched_priority );
+ if( iStatus == 0 )
+ {
+ /* Change the priority of the FreeRTOS task. */
+ vTaskPrioritySet( pxThread->xTaskHandle, param->sched_priority );
+ }
- return 0;
+ return iStatus;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_barrier.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_barrier.c
index 34179d7..6e14ef3 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_barrier.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_barrier.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -36,41 +36,32 @@
#include "FreeRTOS_POSIX/errno.h"
#include "FreeRTOS_POSIX/pthread.h"
+#include "atomic.h"
+
/*
+ * @brief barrier max count
+ *
* Barriers are implemented on FreeRTOS event groups, of which 8 bits are usable
* when configUSE_16_BIT_TICKS is 1. Otherwise, 24 bits are usable.
*/
+/**@{ */
#if ( configUSE_16_BIT_TICKS == 1 )
- #define posixPTHREAD_BARRIER_MAX_COUNT ( 8 )
+ #define posixPTHREAD_BARRIER_MAX_COUNT ( 8 )
#else
- #define posixPTHREAD_BARRIER_MAX_COUNT ( 24 )
+ #define posixPTHREAD_BARRIER_MAX_COUNT ( 24 )
#endif
-
-/**
- * @brief Barrier object.
- */
-typedef struct pthread_barrier_internal
-{
- unsigned uThreadCount; /**< Current number of threads that have entered barrier. */
- unsigned uThreshold; /**< The count argument of pthread_barrier_init. */
- StaticSemaphore_t xThreadCountMutex; /**< Guards access to uThreadCount. */
- StaticSemaphore_t xThreadCountSemaphore; /**< Prevents more than uThreshold threads from exiting pthread_barrier_wait at once. */
- StaticEventGroup_t xBarrierEventGroup; /**< FreeRTOS event group that blocks to wait on threads entering barrier. */
-} pthread_barrier_internal_t;
+/**@} */
/*-----------------------------------------------------------*/
int pthread_barrier_destroy( pthread_barrier_t * barrier )
{
- pthread_barrier_internal_t * pxBarrier = ( pthread_barrier_internal_t * ) ( *barrier );
+ pthread_barrier_internal_t * pxBarrier = ( pthread_barrier_internal_t * ) ( barrier );
/* Free all resources used by the barrier. */
( void ) vEventGroupDelete( ( EventGroupHandle_t ) &pxBarrier->xBarrierEventGroup );
- ( void ) vSemaphoreDelete( ( SemaphoreHandle_t ) &pxBarrier->xThreadCountMutex );
( void ) vSemaphoreDelete( ( SemaphoreHandle_t ) &pxBarrier->xThreadCountSemaphore );
- vPortFree( *barrier );
-
return 0;
}
@@ -81,7 +72,7 @@ int pthread_barrier_init( pthread_barrier_t * barrier,
unsigned count )
{
int iStatus = 0;
- pthread_barrier_internal_t * pxNewBarrier = NULL;
+ pthread_barrier_internal_t * pxNewBarrier = ( pthread_barrier_internal_t * ) ( barrier );
/* Silence warnings about unused parameters. */
( void ) attr;
@@ -103,18 +94,6 @@ int pthread_barrier_init( pthread_barrier_t * barrier,
}
}
- /* Allocate memory for a new barrier. */
- if( iStatus == 0 )
- {
- pxNewBarrier = pvPortMalloc( sizeof( pthread_barrier_internal_t ) );
-
- if( pxNewBarrier == NULL )
- {
- /* No memory. */
- iStatus = ENOMEM;
- }
- }
-
if( iStatus == 0 )
{
/* Set the current thread count and threshold. */
@@ -125,19 +104,12 @@ int pthread_barrier_init( pthread_barrier_t * barrier,
* argument isn't NULL. */
( void ) xEventGroupCreateStatic( &pxNewBarrier->xBarrierEventGroup );
- /* Create the mutex that guards access to uThreadCount. This call
- * will not fail when its argument isn't NULL. */
- ( void ) xSemaphoreCreateMutexStatic( &pxNewBarrier->xThreadCountMutex );
-
/* Create the semaphore that prevents more than count threads from being
* unblocked by a single successful pthread_barrier_wait. This semaphore
* counts down from count and cannot decrement below 0. */
( void ) xSemaphoreCreateCountingStatic( ( UBaseType_t ) count, /* Max count. */
( UBaseType_t ) count, /* Initial count. */
&pxNewBarrier->xThreadCountSemaphore );
-
- /* Set output parameter. */
- *barrier = pxNewBarrier;
}
return iStatus;
@@ -149,7 +121,7 @@ int pthread_barrier_wait( pthread_barrier_t * barrier )
{
int iStatus = 0;
unsigned i = 0; /* Loop iterator. */
- pthread_barrier_internal_t * pxBarrier = ( pthread_barrier_internal_t * ) ( *barrier );
+ pthread_barrier_internal_t * pxBarrier = ( pthread_barrier_internal_t * ) ( barrier );
unsigned uThreadNumber = 0;
/* Decrement the number of threads waiting on this barrier. This will prevent more
@@ -160,31 +132,20 @@ int pthread_barrier_wait( pthread_barrier_t * barrier )
*/
( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxBarrier->xThreadCountSemaphore, portMAX_DELAY );
- /* Lock the mutex so that this thread can change uThreadCount. This call will
- * never fail because it blocks forever.*/
- ( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxBarrier->xThreadCountMutex, portMAX_DELAY );
-
- /* Increment thread count. This is the order that this thread entered the
- * barrier, i.e. uThreadNumber-1 threads entered the barrier before this one. */
- pxBarrier->uThreadCount++;
- uThreadNumber = pxBarrier->uThreadCount;
- configASSERT( uThreadNumber > 0 );
-
- /* Unlock the thread count mutex to allow other threads to change thread count.
- * This call will never fail because xThreadCountMutex is owned by this thread. */
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxBarrier->xThreadCountMutex );
+ uThreadNumber = Atomic_Increment_u32( ( uint32_t * ) &pxBarrier->uThreadCount );
/* Set the bit in the event group representing this thread, then wait for the other
* threads to set their bit. This call should wait forever until all threads have set
* their bit, so the return value is ignored. */
( void ) xEventGroupSync( ( EventGroupHandle_t ) &pxBarrier->xBarrierEventGroup,
- 1 << ( uThreadNumber - 1 ), /* Which bit in the event group to set. */
+ 1 << uThreadNumber, /* Which bit in the event group to set. */
( 1 << pxBarrier->uThreshold ) - 1, /* Wait for all threads to set their bits. */
portMAX_DELAY );
/* The first thread to enter the barrier gets PTHREAD_BARRIER_SERIAL_THREAD as its
* return value and resets xThreadCountSemaphore. */
- if( uThreadNumber == 1 )
+
+ if( uThreadNumber == 0 )
{
iStatus = PTHREAD_BARRIER_SERIAL_THREAD;
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_cond.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_cond.c
index 1830aae..f67d1da 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_cond.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_cond.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -37,6 +37,8 @@
#include "FreeRTOS_POSIX/pthread.h"
#include "FreeRTOS_POSIX/utils.h"
+#include "atomic.h"
+
/**
* @brief Initialize a PTHREAD_COND_INITIALIZER cond.
*
@@ -67,7 +69,6 @@ static void prvInitializeStaticCond( pthread_cond_internal_t * pxCond )
/* Set the members of the cond. The semaphore create calls will never fail
* when their arguments aren't NULL. */
pxCond->xIsInitialized = pdTRUE;
- ( void ) xSemaphoreCreateMutexStatic( &pxCond->xCondMutex );
( void ) xSemaphoreCreateCountingStatic( INT_MAX, 0U, &pxCond->xCondWaitSemaphore );
pxCond->iWaitingThreads = 0;
}
@@ -77,32 +78,61 @@ static void prvInitializeStaticCond( pthread_cond_internal_t * pxCond )
}
}
+/**
+ * @brief Check "atomically" if iLocalWaitingThreads == pxCond->iWaitingThreads and decrement.
+ */
+static void prvTestAndDecrement( pthread_cond_t * pxCond,
+ unsigned iLocalWaitingThreads )
+{
+ /* Test local copy of threads waiting is larger than zero. */
+ while( iLocalWaitingThreads > 0 )
+ {
+ /* Test-and-set. Atomically check whether the copy in memory has changed.
+ * And, if not decrease the copy of threads waiting in memory. */
+ if( ATOMIC_COMPARE_AND_SWAP_SUCCESS == Atomic_CompareAndSwap_u32( ( uint32_t * ) &pxCond->iWaitingThreads, ( uint32_t ) iLocalWaitingThreads - 1, ( uint32_t ) iLocalWaitingThreads ) )
+ {
+ /* Signal one succeeded. Break. */
+ break;
+ }
+
+ /* Local copy may be out dated. Reload, and retry. */
+ iLocalWaitingThreads = pxCond->iWaitingThreads;
+ }
+}
+
/*-----------------------------------------------------------*/
int pthread_cond_broadcast( pthread_cond_t * cond )
{
- int i = 0;
- pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( *cond );
+ unsigned i = 0;
+ pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( cond );
/* If the cond is uninitialized, perform initialization. */
prvInitializeStaticCond( pxCond );
- /* Lock xCondMutex to protect access to iWaitingThreads.
- * This call will never fail because it blocks forever. */
- ( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxCond->xCondMutex, portMAX_DELAY );
+ /* Local copy of number of threads waiting. */
+ unsigned iLocalWaitingThreads = pxCond->iWaitingThreads;
- /* Unblock all threads waiting on this condition variable. */
- for( i = 0; i < pxCond->iWaitingThreads; i++ )
+ /* Test local copy of threads waiting is larger than zero. */
+ while( iLocalWaitingThreads > 0 )
{
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondWaitSemaphore );
+ /* Test-and-set. Atomically check whether the copy in memory has changed.
+ * And, if not set the copy of threads waiting in memory to zero. */
+ if( ATOMIC_COMPARE_AND_SWAP_SUCCESS == Atomic_CompareAndSwap_u32( ( uint32_t * ) &pxCond->iWaitingThreads, 0, ( uint32_t ) iLocalWaitingThreads ) )
+ {
+ /* Unblock all. */
+ for( i = 0; i < iLocalWaitingThreads; i++ )
+ {
+ ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondWaitSemaphore );
+ }
+
+ break;
+ }
+
+ /* Local copy is out dated. Reload, and retry. */
+ iLocalWaitingThreads = pxCond->iWaitingThreads;
}
- /* All threads were unblocked, set waiting threads to 0. */
- pxCond->iWaitingThreads = 0;
-
- /* Release xCondMutex. */
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondMutex );
-
return 0;
}
@@ -110,12 +140,10 @@ int pthread_cond_broadcast( pthread_cond_t * cond )
int pthread_cond_destroy( pthread_cond_t * cond )
{
- pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( *cond );
+ pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( cond );
/* Free all resources in use by the cond. */
- vSemaphoreDelete( ( SemaphoreHandle_t ) &pxCond->xCondMutex );
vSemaphoreDelete( ( SemaphoreHandle_t ) &pxCond->xCondWaitSemaphore );
- vPortFree( pxCond );
return 0;
}
@@ -126,13 +154,11 @@ int pthread_cond_init( pthread_cond_t * cond,
const pthread_condattr_t * attr )
{
int iStatus = 0;
- pthread_cond_internal_t * pxCond = NULL;
+ pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) cond;
/* Silence warnings about unused parameters. */
( void ) attr;
- pxCond = pvPortMalloc( sizeof( pthread_cond_internal_t ) );
-
if( pxCond == NULL )
{
iStatus = ENOMEM;
@@ -143,12 +169,9 @@ int pthread_cond_init( pthread_cond_t * cond,
/* Set the members of the cond. The semaphore create calls will never fail
* when their arguments aren't NULL. */
pxCond->xIsInitialized = pdTRUE;
- ( void ) xSemaphoreCreateMutexStatic( &pxCond->xCondMutex );
+
( void ) xSemaphoreCreateCountingStatic( INT_MAX, 0U, &pxCond->xCondWaitSemaphore );
pxCond->iWaitingThreads = 0;
-
- /* Set the output. */
- *cond = pxCond;
}
return iStatus;
@@ -158,30 +181,30 @@ int pthread_cond_init( pthread_cond_t * cond,
int pthread_cond_signal( pthread_cond_t * cond )
{
- pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( *cond );
+ pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( cond );
/* If the cond is uninitialized, perform initialization. */
prvInitializeStaticCond( pxCond );
- /* Check that at least one thread is waiting for a signal. */
- if( pxCond->iWaitingThreads > 0 )
- {
- /* Lock xCondMutex to protect access to iWaitingThreads.
- * This call will never fail because it blocks forever. */
- ( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxCond->xCondMutex, portMAX_DELAY );
+ /* Local copy of number of threads waiting. */
+ unsigned iLocalWaitingThreads = pxCond->iWaitingThreads;
- /* Check again that at least one thread is waiting for a signal after
- * taking xCondMutex. If so, unblock it. */
- if( pxCond->iWaitingThreads > 0 )
+ /* Test local copy of threads waiting is larger than zero. */
+ while( iLocalWaitingThreads > 0 )
+ {
+ /* Test-and-set. Atomically check whether the copy in memory has changed.
+ * And, if not decrease the copy of threads waiting in memory. */
+ if( ATOMIC_COMPARE_AND_SWAP_SUCCESS == Atomic_CompareAndSwap_u32( ( uint32_t * ) &pxCond->iWaitingThreads, ( uint32_t ) iLocalWaitingThreads - 1, ( uint32_t ) iLocalWaitingThreads ) )
{
+ /* Unblock one. */
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondWaitSemaphore );
- /* Decrease the number of waiting threads. */
- pxCond->iWaitingThreads--;
+ /* Signal one succeeded. Break. */
+ break;
}
- /* Release xCondMutex. */
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondMutex );
+ /* Local copy may be out dated. Reload, and retry. */
+ iLocalWaitingThreads = pxCond->iWaitingThreads;
}
return 0;
@@ -193,8 +216,9 @@ int pthread_cond_timedwait( pthread_cond_t * cond,
pthread_mutex_t * mutex,
const struct timespec * abstime )
{
+ unsigned iLocalWaitingThreads;
int iStatus = 0;
- pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( *cond );
+ pthread_cond_internal_t * pxCond = ( pthread_cond_internal_t * ) ( cond );
TickType_t xDelay = portMAX_DELAY;
/* If the cond is uninitialized, perform initialization. */
@@ -203,16 +227,26 @@ int pthread_cond_timedwait( pthread_cond_t * cond,
/* Convert abstime to a delay in TickType_t if provided. */
if( abstime != NULL )
{
- iStatus = UTILS_AbsoluteTimespecToTicks( abstime, &xDelay );
+ struct timespec xCurrentTime = { 0 };
+
+ /* Get current time */
+ if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
+ {
+ iStatus = EINVAL;
+ }
+ else
+ {
+ iStatus = UTILS_AbsoluteTimespecToDeltaTicks( abstime, &xCurrentTime, &xDelay );
+ }
}
/* Increase the counter of threads blocking on condition variable, then
* unlock mutex. */
if( iStatus == 0 )
{
- ( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxCond->xCondMutex, portMAX_DELAY );
- pxCond->iWaitingThreads++;
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondMutex );
+ /* Atomically increments thread waiting by 1, and
+ * stores number of threads waiting before increment. */
+ iLocalWaitingThreads = Atomic_Increment_u32( ( uint32_t * ) &pxCond->iWaitingThreads );
iStatus = pthread_mutex_unlock( mutex );
}
@@ -232,11 +266,21 @@ int pthread_cond_timedwait( pthread_cond_t * cond,
iStatus = ETIMEDOUT;
( void ) pthread_mutex_lock( mutex );
- ( void ) xSemaphoreTake( ( SemaphoreHandle_t ) &pxCond->xCondMutex, portMAX_DELAY );
- pxCond->iWaitingThreads--;
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxCond->xCondMutex );
+ /* Atomically decrements thread waiting by 1.
+ * If iLocalWaitingThreads is updated by other thread(s) in between,
+ * this implementation guarantees to decrement by 1 based on the
+ * value currently in pxCond->iWaitingThreads. */
+ prvTestAndDecrement( pxCond, iLocalWaitingThreads + 1 );
}
}
+ else
+ {
+ /* Atomically decrements thread waiting by 1.
+ * If iLocalWaitingThreads is updated by other thread(s) in between,
+ * this implementation guarantees to decrement by 1 based on the
+ * value currently in pxCond->iWaitingThreads. */
+ prvTestAndDecrement( pxCond, iLocalWaitingThreads + 1 );
+ }
return iStatus;
}
@@ -247,4 +291,4 @@ int pthread_cond_wait( pthread_cond_t * cond,
pthread_mutex_t * mutex )
{
return pthread_cond_timedwait( cond, mutex, NULL );
-}
+}
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_mutex.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_mutex.c
index 4b63974..0ea3aeb 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_mutex.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread_mutex.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -30,7 +30,7 @@
/* C standard library includes. */
#include
-#include
+#include
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX.h"
@@ -96,13 +96,12 @@ static void prvInitializeStaticMutex( pthread_mutex_internal_t * pxMutex )
int pthread_mutex_destroy( pthread_mutex_t * mutex )
{
- pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( *mutex );
+ pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( mutex );
/* Free resources in use by the mutex. */
if( pxMutex->xTaskOwner == NULL )
{
vSemaphoreDelete( ( SemaphoreHandle_t ) &pxMutex->xMutex );
- vPortFree( pxMutex );
}
return 0;
@@ -114,10 +113,7 @@ int pthread_mutex_init( pthread_mutex_t * mutex,
const pthread_mutexattr_t * attr )
{
int iStatus = 0;
- pthread_mutex_internal_t * pxMutex = NULL;
-
- /* Allocate memory for new mutex object. */
- pxMutex = ( pthread_mutex_internal_t * ) pvPortMalloc( sizeof( pthread_mutex_internal_t ) );
+ pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) mutex;
if( pxMutex == NULL )
{
@@ -127,8 +123,7 @@ int pthread_mutex_init( pthread_mutex_t * mutex,
if( iStatus == 0 )
{
- /* Clear the newly-allocated mutex. */
- ( void ) memset( pxMutex, 0x00, sizeof( pthread_mutex_internal_t ) );
+ *pxMutex = FREERTOS_POSIX_MUTEX_INITIALIZER;
/* No attributes given, use default attributes. */
if( attr == NULL )
@@ -138,7 +133,7 @@ int pthread_mutex_init( pthread_mutex_t * mutex,
/* Otherwise, use provided attributes. */
else
{
- pxMutex->xAttr = *( ( pthread_mutexattr_internal_t * ) ( *attr ) );
+ pxMutex->xAttr = *( ( pthread_mutexattr_internal_t * ) ( attr ) );
}
/* Call the correct FreeRTOS mutex creation function based on mutex type. */
@@ -164,7 +159,6 @@ int pthread_mutex_init( pthread_mutex_t * mutex,
{
/* Mutex successfully created. */
pxMutex->xIsInitialized = pdTRUE;
- *mutex = ( pthread_mutex_t ) pxMutex;
}
}
@@ -184,7 +178,7 @@ int pthread_mutex_timedlock( pthread_mutex_t * mutex,
const struct timespec * abstime )
{
int iStatus = 0;
- pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( *mutex );
+ pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( mutex );
TickType_t xDelay = portMAX_DELAY;
BaseType_t xFreeRTOSMutexTakeStatus = pdFALSE;
@@ -197,7 +191,17 @@ int pthread_mutex_timedlock( pthread_mutex_t * mutex,
/* Convert abstime to a delay in TickType_t if provided. */
if( abstime != NULL )
{
- iStatus = UTILS_AbsoluteTimespecToTicks( abstime, &xDelay );
+ struct timespec xCurrentTime = { 0 };
+
+ /* Get current time */
+ if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
+ {
+ iStatus = EINVAL;
+ }
+ else
+ {
+ iStatus = UTILS_AbsoluteTimespecToDeltaTicks( abstime, &xCurrentTime, &xDelay );
+ }
/* If abstime was in the past, still attempt to lock the mutex without
* blocking, per POSIX spec. */
@@ -272,7 +276,7 @@ int pthread_mutex_trylock( pthread_mutex_t * mutex )
int pthread_mutex_unlock( pthread_mutex_t * mutex )
{
int iStatus = 0;
- pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( *mutex );
+ pthread_mutex_internal_t * pxMutex = ( pthread_mutex_internal_t * ) ( mutex );
/* If mutex in uninitialized, perform initialization. */
prvInitializeStaticMutex( pxMutex );
@@ -287,6 +291,10 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex )
if( iStatus == 0 )
{
+ /* Suspend the scheduler so that
+ * mutex is unlocked AND owner is updated atomically */
+ vTaskSuspendAll();
+
/* Call the correct FreeRTOS mutex unlock function based on mutex type. */
if( pxMutex->xAttr.iType == PTHREAD_MUTEX_RECURSIVE )
{
@@ -300,6 +308,9 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex )
/* Update the owner of the mutex. A recursive mutex may still have an
* owner, so it should be updated with xSemaphoreGetMutexHolder. */
pxMutex->xTaskOwner = xSemaphoreGetMutexHolder( ( SemaphoreHandle_t ) &pxMutex->xMutex );
+
+ /* Resume the scheduler */
+ ( void ) xTaskResumeAll();
}
return iStatus;
@@ -309,8 +320,7 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex )
int pthread_mutexattr_destroy( pthread_mutexattr_t * attr )
{
- /* Free mutex attributes object. */
- vPortFree( *attr );
+ ( void ) attr;
return 0;
}
@@ -320,7 +330,7 @@ int pthread_mutexattr_destroy( pthread_mutexattr_t * attr )
int pthread_mutexattr_gettype( const pthread_mutexattr_t * attr,
int * type )
{
- pthread_mutexattr_internal_t * pxAttr = ( pthread_mutexattr_internal_t * ) ( *attr );
+ pthread_mutexattr_internal_t * pxAttr = ( pthread_mutexattr_internal_t * ) ( attr );
*type = pxAttr->iType;
@@ -331,24 +341,9 @@ int pthread_mutexattr_gettype( const pthread_mutexattr_t * attr,
int pthread_mutexattr_init( pthread_mutexattr_t * attr )
{
- int iStatus = 0;
+ *( ( pthread_mutexattr_internal_t * ) ( attr ) ) = xDefaultMutexAttributes;
- /* Allocate memory for new mutex attributes object. */
- *attr = pvPortMalloc( sizeof( pthread_mutexattr_internal_t ) );
-
- if( *attr == NULL )
- {
- /* No memory. */
- iStatus = ENOMEM;
- }
-
- /* Set the mutex attributes to default values. */
- if( iStatus == 0 )
- {
- *( ( pthread_mutexattr_internal_t * ) ( *attr ) ) = xDefaultMutexAttributes;
- }
-
- return iStatus;
+ return 0;
}
/*-----------------------------------------------------------*/
@@ -357,7 +352,7 @@ int pthread_mutexattr_settype( pthread_mutexattr_t * attr,
int type )
{
int iStatus = 0;
- pthread_mutexattr_internal_t * pxAttr = ( pthread_mutexattr_internal_t * ) ( *attr );
+ pthread_mutexattr_internal_t * pxAttr = ( pthread_mutexattr_internal_t * ) ( attr );
switch( type )
{
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_sched.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_sched.c
index a8b6a3a..7916a99 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_sched.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_sched.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -44,9 +44,21 @@ int sched_get_priority_max( int policy )
/*-----------------------------------------------------------*/
+int sched_get_priority_min( int policy )
+{
+ /* Silence warnings about unused parameters. */
+ ( void ) policy;
+
+ return tskIDLE_PRIORITY;
+}
+
+/*-----------------------------------------------------------*/
+
int sched_yield( void )
{
taskYIELD();
return 0;
}
+
+/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_semaphore.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_semaphore.c
index 07f4cfe..cee43ca 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_semaphore.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_semaphore.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -37,24 +37,17 @@
#include "FreeRTOS_POSIX/semaphore.h"
#include "FreeRTOS_POSIX/utils.h"
-/**
- * @brief Semaphore type.
- */
-typedef struct
-{
- StaticSemaphore_t xSemaphore; /**< FreeRTOS semaphore. */
-} sem_internal_t;
+#include "atomic.h"
/*-----------------------------------------------------------*/
int sem_destroy( sem_t * sem )
{
- sem_internal_t * pxSem = ( sem_internal_t * ) ( *sem );
+ sem_internal_t * pxSem = ( sem_internal_t * ) ( sem );
/* Free the resources in use by the semaphore. */
vSemaphoreDelete( ( SemaphoreHandle_t ) &pxSem->xSemaphore );
- vPortFree( pxSem );
return 0;
}
@@ -64,10 +57,14 @@ int sem_destroy( sem_t * sem )
int sem_getvalue( sem_t * sem,
int * sval )
{
- sem_internal_t * pxSem = ( sem_internal_t * ) ( *sem );
+ sem_internal_t * pxSem = ( sem_internal_t * ) ( sem );
- /* Get the semaphore count using the FreeRTOS API. */
- *sval = ( int ) uxSemaphoreGetCount( ( SemaphoreHandle_t ) &pxSem->xSemaphore );
+ /* Get value does not need atomic operation, since -- Open Group
+ * states "the updated value represents an actual semaphore value that
+ * occurred at some unspecified time during the call, but it need not be the
+ * actual value of the semaphore when it is returned to the calling process."
+ */
+ *sval = pxSem->value;
return 0;
}
@@ -79,7 +76,7 @@ int sem_init( sem_t * sem,
unsigned value )
{
int iStatus = 0;
- sem_internal_t * pxSem = NULL;
+ sem_internal_t * pxSem = ( sem_internal_t * ) ( sem );
/* Silence warnings about unused parameters. */
( void ) pshared;
@@ -91,24 +88,17 @@ int sem_init( sem_t * sem,
iStatus = -1;
}
- /* Allocate memory for a new semaphore. */
+ /* value is guaranteed to not exceed INT32_MAX, which is the default value of SEM_VALUE_MAX (0x7FFFU). */
+ pxSem->value = ( int ) value;
+
+ /* Create the FreeRTOS semaphore.
+ * This is only used to queue threads when no semaphore is available.
+ * Initializing with semaphore initial count zero.
+ * This call will not fail because the memory for the semaphore has already been allocated.
+ */
if( iStatus == 0 )
{
- pxSem = pvPortMalloc( sizeof( sem_internal_t ) );
-
- if( pxSem == NULL )
- {
- errno = ENOSPC;
- iStatus = -1;
- }
- }
-
- /* Create the FreeRTOS semaphore. This call will not fail because the
- * memory for the semaphore has already been allocated. */
- if( iStatus == 0 )
- {
- ( void ) xSemaphoreCreateCountingStatic( SEM_VALUE_MAX, value, &pxSem->xSemaphore );
- *sem = pxSem;
+ ( void ) xSemaphoreCreateCountingStatic( SEM_VALUE_MAX, 0, &pxSem->xSemaphore );
}
return iStatus;
@@ -118,10 +108,18 @@ int sem_init( sem_t * sem,
int sem_post( sem_t * sem )
{
- sem_internal_t * pxSem = ( sem_internal_t * ) ( *sem );
+ sem_internal_t * pxSem = ( sem_internal_t * ) ( sem );
- /* Give the semaphore using the FreeRTOS API. */
- ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxSem->xSemaphore );
+ int iPreviouValue = Atomic_Increment_u32( ( uint32_t * ) &pxSem->value );
+
+ /* If previous semaphore value is equal or larger than zero, there is no
+ * thread waiting for this semaphore. Otherwise (<0), call FreeRTOS interface
+ * to wake up a thread. */
+ if( iPreviouValue < 0 )
+ {
+ /* Give the semaphore using the FreeRTOS API. */
+ ( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxSem->xSemaphore );
+ }
return 0;
}
@@ -132,7 +130,7 @@ int sem_timedwait( sem_t * sem,
const struct timespec * abstime )
{
int iStatus = 0;
- sem_internal_t * pxSem = ( sem_internal_t * ) ( *sem );
+ sem_internal_t * pxSem = ( sem_internal_t * ) ( sem );
TickType_t xDelay = portMAX_DELAY;
if( abstime != NULL )
@@ -146,7 +144,17 @@ int sem_timedwait( sem_t * sem,
}
else
{
- iStatus = UTILS_AbsoluteTimespecToTicks( abstime, &xDelay );
+ struct timespec xCurrentTime = { 0 };
+
+ /* Get current time */
+ if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
+ {
+ iStatus = EINVAL;
+ }
+ else
+ {
+ iStatus = UTILS_AbsoluteTimespecToDeltaTicks( abstime, &xCurrentTime, &xDelay );
+ }
/* If abstime was in the past, still attempt to take the semaphore without
* blocking, per POSIX spec. */
@@ -157,16 +165,37 @@ int sem_timedwait( sem_t * sem,
}
}
- /* Take the semaphore using the FreeRTOS API. */
- if( xSemaphoreTake( ( SemaphoreHandle_t ) &pxSem->xSemaphore,
- xDelay ) != pdTRUE )
+ int iPreviousValue = Atomic_Decrement_u32( ( uint32_t * ) &pxSem->value );
+
+ /* If previous semaphore value is larger than zero, the thread entering this function call
+ * can take the semaphore without yielding. Else (<=0), calling into FreeRTOS API to yield.
+ */
+ if( iPreviousValue > 0 )
{
- errno = iStatus;
- iStatus = -1;
+ /* Under no circumstance shall the function fail with a timeout if the semaphore can be locked immediately. */
+ iStatus = 0;
}
else
{
- iStatus = 0;
+ /* Take the semaphore using the FreeRTOS API. */
+ if( xSemaphoreTake( ( SemaphoreHandle_t ) &pxSem->xSemaphore,
+ xDelay ) != pdTRUE )
+ {
+ if( iStatus == 0 )
+ {
+ errno = ETIMEDOUT;
+ }
+ else
+ {
+ errno = iStatus;
+ }
+
+ iStatus = -1;
+ }
+ else
+ {
+ iStatus = 0;
+ }
}
return iStatus;
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c
index 0b00804..f790e83 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -42,13 +42,9 @@
/* FreeRTOS timer include. */
#include "timers.h"
-/**
- * #brief Timespec zero check macros.
- */
-/**@{ */
+/* Timespec zero check macros. */
#define TIMESPEC_IS_ZERO( xTimespec ) ( xTimespec.tv_sec == 0 && xTimespec.tv_nsec == 0 ) /**< Check for 0. */
#define TIMESPEC_IS_NOT_ZERO( xTimespec ) ( !( TIMESPEC_IS_ZERO( xTimespec ) ) ) /**< Check for not 0. */
-/**@} */
/**
* @brief Internal timer structure.
@@ -66,7 +62,6 @@ void prvTimerCallback( TimerHandle_t xTimerHandle )
{
timer_internal_t * pxTimer = ( timer_internal_t * ) pvTimerGetTimerID( xTimerHandle );
pthread_t xTimerNotificationThread;
- pthread_attr_t xThreadAttributes;
/* The value of the timer ID, set in timer_create, should not be NULL. */
configASSERT( pxTimer != NULL );
@@ -85,23 +80,11 @@ void prvTimerCallback( TimerHandle_t xTimerHandle )
/* Create the timer notification thread if requested. */
if( pxTimer->xTimerEvent.sigev_notify == SIGEV_THREAD )
{
- /* By default, create a detached thread. But if the user has provided
- * thread attributes, use the provided attributes. */
+ /* if the user has provided thread attributes, create a thread
+ * with the provided attributes. Otherwise dispatch callback directly */
if( pxTimer->xTimerEvent.sigev_notify_attributes == NULL )
{
- if( pthread_attr_init( &xThreadAttributes ) == 0 )
- {
- if( pthread_attr_setdetachstate( &xThreadAttributes,
- PTHREAD_CREATE_DETACHED ) == 0 )
- {
- ( void ) pthread_create( &xTimerNotificationThread,
- &xThreadAttributes,
- ( void * ( * )( void * ) )pxTimer->xTimerEvent.sigev_notify_function,
- pxTimer->xTimerEvent.sigev_value.sival_ptr );
- }
-
- ( void ) pthread_attr_destroy( &xThreadAttributes );
- }
+ ( *pxTimer->xTimerEvent.sigev_notify_function )( pxTimer->xTimerEvent.sigev_value );
}
else
{
@@ -196,7 +179,9 @@ int timer_delete( timer_t timerid )
int timer_getoverrun( timer_t timerid )
{
- ( void ) timerid;
+ /* Silence warnings about unused parameters. */
+ ( void ) timerid;
+
return 0;
}
@@ -256,7 +241,29 @@ int timer_settime( timer_t timerid,
/* Absolute timeout. */
if( ( flags & TIMER_ABSTIME ) == TIMER_ABSTIME )
{
- ( void ) UTILS_AbsoluteTimespecToTicks( &value->it_value, &xNextTimerExpiration );
+ struct timespec xCurrentTime = { 0 };
+
+ /* Get current time */
+ if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
+ {
+ iStatus = EINVAL;
+ }
+ else
+ {
+ iStatus = UTILS_AbsoluteTimespecToDeltaTicks( &value->it_value, &xCurrentTime, &xNextTimerExpiration );
+ }
+
+ /* Make sure xNextTimerExpiration is zero in case we got negative time difference */
+ if( iStatus != 0 )
+ {
+ xNextTimerExpiration = 0;
+
+ if( iStatus == ETIMEDOUT )
+ {
+ /* Set Status to 0 as absolute time is past is treated as expiry but not an error */
+ iStatus = 0;
+ }
+ }
}
/* Relative timeout. */
else
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_unistd.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_unistd.c
index 2f363e9..0d3d914 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_unistd.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_unistd.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_utils.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_utils.c
index 78a2384..c121587 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_utils.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_utils.c
@@ -1,5 +1,5 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
+ * Amazon FreeRTOS POSIX V1.1.0
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -30,6 +30,7 @@
/* C standard library includes. */
#include
+#include
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX.h"
@@ -58,35 +59,34 @@ size_t UTILS_strnlen( const char * const pcString,
/*-----------------------------------------------------------*/
-int UTILS_AbsoluteTimespecToTicks( const struct timespec * const pxAbsoluteTime,
- TickType_t * const pxResult )
+int UTILS_AbsoluteTimespecToDeltaTicks( const struct timespec * const pxAbsoluteTime,
+ const struct timespec * const pxCurrentTime,
+ TickType_t * const pxResult )
{
int iStatus = 0;
- struct timespec xCurrentTime = { 0 }, xDifference = { 0 };
+ struct timespec xDifference = { 0 };
/* Check parameters. */
- if( ( pxAbsoluteTime == NULL ) || ( pxResult == NULL ) )
+ if( ( pxAbsoluteTime == NULL ) || ( pxCurrentTime == NULL ) || ( pxResult == NULL ) )
{
iStatus = EINVAL;
}
- /* Get the current time. */
+ /* Calculate the difference between the current time and absolute time. */
if( iStatus == 0 )
{
- if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
- {
- iStatus = errno;
- }
- }
+ iStatus = UTILS_TimespecSubtract( pxAbsoluteTime, pxCurrentTime, &xDifference );
- /* Calculate the difference between the current time and pxAbsoluteTime. */
- if( iStatus == 0 )
- {
- if( UTILS_TimespecSubtract( &xDifference, pxAbsoluteTime, &xCurrentTime ) != 0 )
+ if( iStatus == 1 )
{
/* pxAbsoluteTime was in the past. */
iStatus = ETIMEDOUT;
}
+ else if( iStatus == -1 )
+ {
+ /* error */
+ iStatus = EINVAL;
+ }
}
/* Convert the time difference to ticks. */
@@ -104,7 +104,7 @@ int UTILS_TimespecToTicks( const struct timespec * const pxTimespec,
TickType_t * const pxResult )
{
int iStatus = 0;
- uint64_t ullTotalTicks = 0;
+ int64_t llTotalTicks = 0;
long lNanoseconds = 0;
/* Check parameters. */
@@ -112,7 +112,7 @@ int UTILS_TimespecToTicks( const struct timespec * const pxTimespec,
{
iStatus = EINVAL;
}
- else if( ( pxTimespec != NULL ) && ( UTILS_ValidateTimespec( pxTimespec ) == false ) )
+ else if( ( iStatus == 0 ) && ( UTILS_ValidateTimespec( pxTimespec ) == false ) )
{
iStatus = EINVAL;
}
@@ -120,7 +120,7 @@ int UTILS_TimespecToTicks( const struct timespec * const pxTimespec,
if( iStatus == 0 )
{
/* Convert timespec.tv_sec to ticks. */
- ullTotalTicks = ( uint64_t ) configTICK_RATE_HZ * ( uint64_t ) ( pxTimespec->tv_sec );
+ llTotalTicks = ( int64_t ) configTICK_RATE_HZ * ( pxTimespec->tv_sec );
/* Convert timespec.tv_nsec to ticks. This value does not have to be checked
* for overflow because a valid timespec has 0 <= tv_nsec < 1000000000 and
@@ -129,10 +129,30 @@ int UTILS_TimespecToTicks( const struct timespec * const pxTimespec,
( long ) ( pxTimespec->tv_nsec % ( long ) NANOSECONDS_PER_TICK != 0 ); /* Add 1 to round up if needed. */
/* Add the nanoseconds to the total ticks. */
- ullTotalTicks += ( uint64_t ) lNanoseconds;
+ llTotalTicks += ( int64_t ) lNanoseconds;
+
+ /* Check for overflow */
+ if( llTotalTicks < 0 )
+ {
+ iStatus = EINVAL;
+ }
+ else
+ {
+ /* check if TickType_t is 32 bit or 64 bit */
+ uint32_t ulTickTypeSize = sizeof( TickType_t );
+
+ /* check for downcast overflow */
+ if( ulTickTypeSize == sizeof( uint32_t ) )
+ {
+ if( llTotalTicks > UINT_MAX )
+ {
+ iStatus = EINVAL;
+ }
+ }
+ }
/* Write result. */
- *pxResult = ( TickType_t ) ullTotalTicks;
+ *pxResult = ( TickType_t ) llTotalTicks;
}
return iStatus;
@@ -162,71 +182,188 @@ void UTILS_NanosecondsToTimespec( int64_t llSource,
/*-----------------------------------------------------------*/
-int UTILS_TimespecAdd( struct timespec * const pxResult,
- const struct timespec * const x,
- const struct timespec * const y )
+int UTILS_TimespecAdd( const struct timespec * const x,
+ const struct timespec * const y,
+ struct timespec * const pxResult )
{
- int64_t llResult64 = 0;
+ int64_t llPartialSec = 0;
+ int iStatus = 0;
/* Check parameters. */
if( ( pxResult == NULL ) || ( x == NULL ) || ( y == NULL ) )
{
- return -1;
+ iStatus = -1;
}
- /* Perform addition. */
- llResult64 = ( ( ( int64_t ) ( x->tv_sec ) * NANOSECONDS_PER_SECOND ) + ( int64_t ) ( x->tv_nsec ) )
- + ( ( ( int64_t ) ( y->tv_sec ) * NANOSECONDS_PER_SECOND ) + ( int64_t ) ( y->tv_nsec ) );
+ if( iStatus == 0 )
+ {
+ /* Perform addition. */
+ pxResult->tv_nsec = x->tv_nsec + y->tv_nsec;
- /* Convert result to timespec. */
- UTILS_NanosecondsToTimespec( llResult64, pxResult );
+ /* check for overflow in case nsec value was invalid */
+ if( pxResult->tv_nsec < 0 )
+ {
+ iStatus = 1;
+ }
+ else
+ {
+ llPartialSec = ( pxResult->tv_nsec ) / NANOSECONDS_PER_SECOND;
+ pxResult->tv_nsec = ( pxResult->tv_nsec ) % NANOSECONDS_PER_SECOND;
+ pxResult->tv_sec = x->tv_sec + y->tv_sec + llPartialSec;
- return ( int ) ( llResult64 < 0LL );
+ /* check for overflow */
+ if( pxResult->tv_sec < 0 )
+ {
+ iStatus = 1;
+ }
+ }
+ }
+
+ return iStatus;
}
/*-----------------------------------------------------------*/
-int UTILS_TimespecAddNanoseconds( struct timespec * const pxResult,
- const struct timespec * const x,
- int64_t llNanoseconds )
+int UTILS_TimespecAddNanoseconds( const struct timespec * const x,
+ int64_t llNanoseconds,
+ struct timespec * const pxResult )
{
- struct timespec y = { .tv_sec = ( time_t ) 0, .tv_nsec = 0L };
+ int64_t llTotalNSec = 0;
+ int iStatus = 0;
/* Check parameters. */
if( ( pxResult == NULL ) || ( x == NULL ) )
{
- return -1;
+ iStatus = -1;
}
- /* Convert llNanoseconds to a timespec. */
- UTILS_NanosecondsToTimespec( llNanoseconds, &y );
+ if( iStatus == 0 )
+ {
+ /* add nano seconds */
+ llTotalNSec = x->tv_nsec + llNanoseconds;
- /* Perform addition. */
- return UTILS_TimespecAdd( pxResult, x, &y );
+ /* check for nano seconds overflow */
+ if( llTotalNSec < 0 )
+ {
+ iStatus = 1;
+ }
+ else
+ {
+ pxResult->tv_nsec = llTotalNSec % NANOSECONDS_PER_SECOND;
+ pxResult->tv_sec = x->tv_sec + ( llTotalNSec / NANOSECONDS_PER_SECOND );
+
+ /* check for seconds overflow */
+ if( pxResult->tv_sec < 0 )
+ {
+ iStatus = 1;
+ }
+ }
+ }
+
+ return iStatus;
}
/*-----------------------------------------------------------*/
-int UTILS_TimespecSubtract( struct timespec * const pxResult,
- const struct timespec * const x,
- const struct timespec * const y )
+int UTILS_TimespecSubtract( const struct timespec * const x,
+ const struct timespec * const y,
+ struct timespec * const pxResult )
{
- int64_t llResult64 = 0;
+ int iCompareResult = 0;
+ int iStatus = 0;
/* Check parameters. */
if( ( pxResult == NULL ) || ( x == NULL ) || ( y == NULL ) )
{
- return -1;
+ iStatus = -1;
}
- /* Perform addition. */
- llResult64 = ( ( ( int64_t ) ( x->tv_sec ) * NANOSECONDS_PER_SECOND ) + ( int64_t ) ( x->tv_nsec ) )
- - ( ( ( int64_t ) ( y->tv_sec ) * NANOSECONDS_PER_SECOND ) + ( int64_t ) ( y->tv_nsec ) );
+ if( iStatus == 0 )
+ {
+ iCompareResult = UTILS_TimespecCompare( x, y );
- /* Convert result to timespec. */
- UTILS_NanosecondsToTimespec( llResult64, pxResult );
+ /* if x < y then result would be negative, return 1 */
+ if( iCompareResult == -1 )
+ {
+ iStatus = 1;
+ }
+ else if( iCompareResult == 0 )
+ {
+ /* if times are the same return zero */
+ pxResult->tv_sec = 0;
+ pxResult->tv_nsec = 0;
+ }
+ else
+ {
+ /* If x > y Perform subtraction. */
+ pxResult->tv_sec = x->tv_sec - y->tv_sec;
+ pxResult->tv_nsec = x->tv_nsec - y->tv_nsec;
- return ( int ) ( llResult64 < 0LL );
+ /* check if nano seconds value needs to borrow */
+ if( pxResult->tv_nsec < 0 )
+ {
+ /* Based on comparison, tv_sec > 0 */
+ pxResult->tv_sec--;
+ pxResult->tv_nsec += ( long ) NANOSECONDS_PER_SECOND;
+ }
+
+ /* if nano second is negative after borrow, it is an overflow error */
+ if( pxResult->tv_nsec < 0 )
+ {
+ iStatus = -1;
+ }
+ }
+ }
+
+ return iStatus;
+}
+
+/*-----------------------------------------------------------*/
+
+int UTILS_TimespecCompare( const struct timespec * const x,
+ const struct timespec * const y )
+{
+ int iStatus = 0;
+
+ /* Check parameters */
+ if( ( x == NULL ) && ( y == NULL ) )
+ {
+ iStatus = 0;
+ }
+ else if( y == NULL )
+ {
+ iStatus = 1;
+ }
+ else if( x == NULL )
+ {
+ iStatus = -1;
+ }
+ else if( x->tv_sec > y->tv_sec )
+ {
+ iStatus = 1;
+ }
+ else if( x->tv_sec < y->tv_sec )
+ {
+ iStatus = -1;
+ }
+ else
+ {
+ /* seconds are equal compare nano seconds */
+ if( x->tv_nsec > y->tv_nsec )
+ {
+ iStatus = 1;
+ }
+ else if( x->tv_nsec < y->tv_nsec )
+ {
+ iStatus = -1;
+ }
+ else
+ {
+ iStatus = 0;
+ }
+ }
+
+ return iStatus;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/errno.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/errno.h
index b9fcc44..136e04b 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/errno.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/errno.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -56,41 +56,39 @@
#undef ETIMEDOUT
/**
- * @brief posix_errno Definition of POSIX errnos.
+ * @name Definition of POSIX errnos.
*/
/**@{ */
-#define EPERM 1 /**< Operation not permitted. */
-#define ENOENT 2 /**< No such file or directory. */
-#define EBADF 9 /**< Bad file descriptor. */
-#define EAGAIN 11 /**< Resource unavailable, try again. */
-#define ENOMEM 12 /**< Not enough space. */
-#define EEXIST 17 /**< File exists. */
-#define EBUSY 16 /**< Device or resource busy. */
-#define EINVAL 22 /**< Invalid argument. */
-#define ENOSPC 28 /**< No space left on device. */
-#define ERANGE 34 /**< Result too large. */
-#define ENAMETOOLONG 36 /**< File name too long. */
-#define EDEADLK 45 /**< Resource deadlock would occur. */
-#define EOVERFLOW 75 /**< Value too large to be stored in data type. */
-#define ENOSYS 88 /**< Function not supported. */
-#define EMSGSIZE 90 /**< Message too long. */
-#define ENOTSUP 95 /**< Operation not supported. */
-#define ETIMEDOUT 116 /**< Connection timed out. */
+#define EPERM 1 /**< Operation not permitted. */
+#define ENOENT 2 /**< No such file or directory. */
+#define EBADF 9 /**< Bad file descriptor. */
+#define EAGAIN 11 /**< Resource unavailable, try again. */
+#define ENOMEM 12 /**< Not enough space. */
+#define EEXIST 17 /**< File exists. */
+#define EBUSY 16 /**< Device or resource busy. */
+#define EINVAL 22 /**< Invalid argument. */
+#define ENOSPC 28 /**< No space left on device. */
+#define ERANGE 34 /**< Result too large. */
+#define ENAMETOOLONG 36 /**< File name too long. */
+#define EDEADLK 45 /**< Resource deadlock would occur. */
+#define EOVERFLOW 75 /**< Value too large to be stored in data type. */
+#define ENOSYS 88 /**< Function not supported. */
+#define EMSGSIZE 90 /**< Message too long. */
+#define ENOTSUP 95 /**< Operation not supported. */
+#define ETIMEDOUT 116 /**< Connection timed out. */
/**@} */
/**
* @name System Variable
*
- * @brief Define FreeRTOS+POSIX errno, if enabled.
+ * @brief Define FreeRTOS+POSIX errno, if enabled.
* Set configUSE_POSIX_ERRNO to enable, and clear to disable. See FreeRTOS.h.
*
* @{
*/
#if ( configUSE_POSIX_ERRNO == 1 )
extern int FreeRTOS_errno;
- #ifndef errno
- #define errno FreeRTOS_errno
- #endif
+ #define errno FreeRTOS_errno
#endif
/**@} */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/fcntl.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/fcntl.h
index c0400c4..1e921ce 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/fcntl.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/fcntl.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -33,11 +33,10 @@
#ifndef _FREERTOS_POSIX_FCNTL_H_
#define _FREERTOS_POSIX_FCNTL_H_
-/**
+/**
* @name File creation flags for use in the oflag value to open() and openat().
- *
- * @{
*/
+/**@{ */
#define O_CLOEXEC 0x0001 /**< Close the file descriptor upon exec(). */
#define O_CREAT 0x0002 /**< Create file if it does not exist. */
#define O_DIRECTORY 0x0004 /**< Fail if file is a non-directory file. */
@@ -48,11 +47,10 @@
#define O_TTY_INIT 0x0080 /**< termios structure provides conforming behavior. */
/**@} */
-/**
+/**
* @name File status flags for open(), openat(), and fcntl().
- *
- * @{
*/
+/**@{ */
#define O_APPEND 0x0100 /**< Set append mode. */
#define O_DSYNC 0x0200 /**< Write according to synchronized I/O data integrity completion. */
#define O_NONBLOCK 0x0400 /**< Non-blocking mode. */
@@ -62,21 +60,20 @@
/**
* @name Mask for file access modes.
- *
- * @{
*/
+/**@{ */
#define O_ACCMODE 0xF000
+/**@} */
/**
* @name File access modes for open(), openat(), and fcntl().
- *
- * @{
*/
-#define O_EXEC 0x1000 /**< Open for execute only (non-directory files). */
-#define O_RDONLY 0x2000 /**< Open for reading only. */
-#define O_RDWR 0xA000 /**< Open for reading and writing. */
-#define O_SEARCH 0x4000 /**< Open directory for search only. */
-#define O_WRONLY 0x8000 /**< Open for writing only. */
+/**@{ */
+#define O_EXEC 0x1000 /**< Open for execute only (non-directory files). */
+#define O_RDONLY 0x2000 /**< Open for reading only. */
+#define O_RDWR 0xA000 /**< Open for reading and writing. */
+#define O_SEARCH 0x4000 /**< Open directory for search only. */
+#define O_WRONLY 0x8000 /**< Open for writing only. */
/**@} */
#endif /* ifndef _FREERTOS_POSIX_FCNTL_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/mqueue.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/mqueue.h
index 219e08d..7cbf01c 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/mqueue.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/mqueue.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -59,10 +59,10 @@ struct mq_attr
*
* @retval 0 - Upon successful completion
* @retval -1 - A error occurred. errno is also set.
- *
- * \sideeffect Possible errno values
+ *
+ * @sideeffect Possible errno values
*
- * EBADF - The mqdes argument is not a valid message queue descriptor.
+ * EBADF - The mqdes argument is not a valid message queue descriptor.
*/
int mq_close( mqd_t mqdes );
@@ -70,11 +70,11 @@ int mq_close( mqd_t mqdes );
* @brief Get message queue attributes.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html
- *
+ *
* @retval 0 - Upon successful completion
* @retval -1 - A error occurred. errno is also set.
*
- * \sideeffect Possible errno values
+ * @sideeffect Possible errno values
*
* DBADF - The mqdes argument is not a valid message queue descriptor.
*/
@@ -86,21 +86,21 @@ int mq_getattr( mqd_t mqdes,
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html
*
- * @note Supported name pattern: leading <slash> character in name is always required;
- * the maximum length (excluding null-terminator) of the name argument can be NAME_MAX.
- * The default value of NAME_MAX in FreeRTOS_POSIX_portable_default.h is 64, which can be
+ * @note Supported name pattern: leading <slash> character in name is always required;
+ * the maximum length (excluding null-terminator) of the name argument can be NAME_MAX.
+ * The default value of NAME_MAX in FreeRTOS_POSIX_portable_default.h is 64, which can be
* overwritten by user.
* @note mode argument is not supported.
- * @note Supported oflags: O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
+ * @note Supported oflags: O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
*
* @retval Message queue descriptor -- Upon successful completion
- * @retval (mqd_t) - 1 -- An error occurred. errno is also set.
+ * @retval (mqd_t) - 1 -- An error occurred. errno is also set.
*
- * \sideeffect Possible errno values
+ * @sideeffect Possible errno values
*
- * EINVAL - name argument is invalid (not following name pattern),
- * OR if O_CREAT is specified in oflag with attr argument not NULL and either mq_maxmsg or mq_msgsize is equal to or less than zero,
- * OR either O_CREAT or O_EXCL is not set and a queue with the same name is unlinked but pending to be removed.
+ * EINVAL - name argument is invalid (not following name pattern),
+ * OR if O_CREAT is specified in oflag with attr argument not NULL and either mq_maxmsg or mq_msgsize is equal to or less than zero,
+ * OR either O_CREAT or O_EXCL is not set and a queue with the same name is unlinked but pending to be removed.
*
* EEXIST - O_CREAT and O_EXCL are set and the named message queue already exists.
*
@@ -119,18 +119,18 @@ mqd_t mq_open( const char * name,
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html
*
* @note msg_prio argument is not supported. Messages are not checked for corruption.
- *
- * @retval The length of the selected message in bytes - Upon successful completion.
+ *
+ * @retval The length of the selected message in bytes - Upon successful completion.
* The message is removed from the queue
* @retval -1 - An error occurred. errno is also set.
*
- * \sideeffect Possible errno values
+ * @sideeffect Possible errno values
*
* EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
*
* EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
*
- * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
+ * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
* but no message arrived on the queue before the specified timeout expired.
*
* EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
@@ -146,23 +146,22 @@ ssize_t mq_receive( mqd_t mqdes,
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html
*
* @note msg_prio argument is not supported.
- *
+ *
* @retval 0 - Upon successful completion.
- * @retval -1 - An error occurred. errno is also set.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - An error occurred. errno is also set.
+ *
+ * @sideeffect Possible errno values
*
* EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
*
- * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
+ * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
* OR insufficient memory for the message to be sent.
*
- * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
+ * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
* but the timeout expired before the message could be added to the queue.
*
- * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
+ * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
* and the specified message queue is full.
- *
*/
int mq_send( mqd_t mqdes,
const char * msg_ptr,
@@ -175,21 +174,21 @@ int mq_send( mqd_t mqdes,
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedreceive.html
*
* @note msg_prio argument is not supported. Messages are not checked for corruption.
- *
- * @retval The length of the selected message in bytes - Upon successful completion.
+ *
+ * @retval The length of the selected message in bytes - Upon successful completion.
* The message is removed from the queue
* @retval -1 - An error occurred. errno is also set.
- *
- * \sideeffect Possible errno values
+ *
+ * @sideeffect Possible errno values
*
* EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
*
* EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
*
- * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field value
+ * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field value
* less than zero or greater than or equal to 1000 million.
*
- * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
+ * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
* but no message arrived on the queue before the specified timeout expired.
*
* EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
@@ -206,26 +205,25 @@ ssize_t mq_timedreceive( mqd_t mqdes,
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedsend.html
*
* @note msg_prio argument is not supported.
- *
+ *
* @retval 0 - Upon successful completion.
- * @retval -1 - An error occurred. errno is also set.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - An error occurred. errno is also set.
+ *
+ * @sideeffect Possible errno values
*
* EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
*
- * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
+ * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
* OR insufficient memory for the message to be sent.
*
- * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field
+ * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field
* value less than zero or greater than or equal to 1000 million.
*
- * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
+ * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
* but the timeout expired before the message could be added to the queue.
*
- * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
+ * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
* and the specified message queue is full.
- *
*/
int mq_timedsend( mqd_t mqdes,
const char * msg_ptr,
@@ -237,11 +235,11 @@ int mq_timedsend( mqd_t mqdes,
* @brief Remove a message queue.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html
- *
+ *
* @retval 0 - Upon successful completion.
- * @retval -1 - An error occurred. errno is also set.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - An error occurred. errno is also set.
+ *
+ * @sideeffect Possible errno values
*
* EINVAL - name argument is invalid. Refer to requirements on name argument in mq_open().
*
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h
index 73b90aa..77f949a 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -39,7 +39,7 @@
#include "FreeRTOS_POSIX/time.h"
/**
- * @brief pthread detach state.
+ * @name pthread detach state.
*/
/**@{ */
#define PTHREAD_CREATE_DETACHED 0 /**< Detached. */
@@ -47,15 +47,16 @@
/**@} */
/**
- * @brief Returned to a single thread after a successful pthread_barrier_wait.
+ * @name Returned to a single thread after a successful pthread_barrier_wait.
*
- * POSIX specifies that "The constant PTHREAD_BARRIER_SERIAL_THREAD is defined in and its value shall be distinct from any other value returned by pthread_barrier_wait()."
+ * @brief POSIX specifies that "The constant PTHREAD_BARRIER_SERIAL_THREAD is defined in
+ * and its value shall be distinct from any other value returned by pthread_barrier_wait()."
* So it's defined as negative to distinguish it from the errnos, which are positive.
*/
#define PTHREAD_BARRIER_SERIAL_THREAD ( -2 )
/**
- * @brief Mutex types.
+ * @name Mutex types.
*/
/**@{ */
#ifndef PTHREAD_MUTEX_NORMAL
@@ -73,15 +74,20 @@
/**@} */
/**
- * @brief Compile-time initializers.
+ * @name Compile-time initializers.
+ *
+ * @brief To use PTHREAD_COND_INITIALIZER, posixconfigENABLE_PTHREAD_COND_T needs to be set to 1
+ * in port specific POSIX config file.
+ *
+ * To use PTHREAD_MUTEX_INITIALIZER, posixconfigENABLE_PTHREAD_MUTEX_T needs to be set to 1 in
+ * port specific POSIX config file.
*/
/**@{ */
-#define PTHREAD_COND_INITIALIZER FREERTOS_POSIX_COND_INITIALIZER /**< pthread_cond_t. */
+#if posixconfigENABLE_PTHREAD_COND_T == 1
+ #define PTHREAD_COND_INITIALIZER FREERTOS_POSIX_COND_INITIALIZER /**< pthread_cond_t. */
+#endif
#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
- /**
- * @brief To use this initializer, posixconfigENABLE_PTHREAD_MUTEX_T needs to be set to 1 in FreeRTOS_POSIX_portable_default.h.
- */
#define PTHREAD_MUTEX_INITIALIZER FREERTOS_POSIX_MUTEX_INITIALIZER /**< pthread_mutex_t. */
#endif
@@ -91,8 +97,8 @@
* @brief Destroy the thread attributes object.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_destroy.html
- *
- * @retval 0 - Upon successful completion
+ *
+ * @retval 0 - Upon successful completion.
*/
int pthread_attr_destroy( pthread_attr_t * attr );
@@ -101,8 +107,7 @@ int pthread_attr_destroy( pthread_attr_t * attr );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html
*
- * @retval 0 - Upon successful completion
- *
+ * @retval 0 - Upon successful completion.
*/
int pthread_attr_getdetachstate( const pthread_attr_t * attr,
int * detachstate );
@@ -112,7 +117,7 @@ int pthread_attr_getdetachstate( const pthread_attr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedparam.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_attr_getschedparam( const pthread_attr_t * attr,
struct sched_param * param );
@@ -122,7 +127,7 @@ int pthread_attr_getschedparam( const pthread_attr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_attr_getstacksize( const pthread_attr_t * attr,
size_t * stacksize );
@@ -132,10 +137,9 @@ int pthread_attr_getstacksize( const pthread_attr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html
*
- * @retval 0 - Upon successful completion
- * @retval ENOMEM - Insufficient memory exists to initialize the thread attributes object.
- *
- * @note Currently, only stack size, sched param, and detach state attributes
+ * @retval 0 - Upon successful completion.
+ *
+ * @note Currently, only stack size, sched_param, and detach state attributes
* are supported. Also see pthread_attr_get*() and pthread_attr_set*().
*/
int pthread_attr_init( pthread_attr_t * attr );
@@ -146,7 +150,8 @@ int pthread_attr_init( pthread_attr_t * attr );
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html
*
* @retval 0 - Upon successful completion
- * @retval EINVAL - The value of detachstate was not valid. Currently, supported detach states are -- PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE.
+ * @retval EINVAL - The value of detachstate is not valid. Currently, supported detach states are --
+ * PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE.
*/
int pthread_attr_setdetachstate( pthread_attr_t * attr,
int detachstate );
@@ -156,20 +161,32 @@ int pthread_attr_setdetachstate( pthread_attr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html
*
- * @retval 0 - Upon successful completion
- * @retval EINVAL - The value of param is not valid.
- * @retval ENOTSUP - An attempt was made to set the attribute to an unsupported value.
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - The value of param is not valid.
+ * @retval ENOTSUP - An attempt was made to set the attribute to an unsupported value.
*/
int pthread_attr_setschedparam( pthread_attr_t * attr,
const struct sched_param * param );
+/**
+ * @brief Set the schedpolicy attribute.
+ *
+ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedpolicy.html
+ *
+ * @retval 0 - Upon successful completion.
+ *
+ * @warning This function is a stub and always returns 0.
+ */
+int pthread_attr_setschedpolicy( pthread_attr_t * attr,
+ int policy );
+
/**
* @brief Set stacksize attribute.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setstacksize.html
*
- * @retval 0 - Upon successful completion
- * @retval EINVAL - The value of stacksize is less than {PTHREAD_STACK_MIN}
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - The value of stacksize is less than {PTHREAD_STACK_MIN}.
*/
int pthread_attr_setstacksize( pthread_attr_t * attr,
size_t stacksize );
@@ -179,9 +196,9 @@ int pthread_attr_setstacksize( pthread_attr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_destroy.html
*
- * @retval 0 - Upon successful completion
- *
- * @note This function does not validate whether there is any thread blocking on the barrier before destroying.
+ * @retval 0 - Upon successful completion.
+ *
+ * @note This function does not validate whether there is any thread blocking on the barrier before destroying.
*/
int pthread_barrier_destroy( pthread_barrier_t * barrier );
@@ -190,16 +207,17 @@ int pthread_barrier_destroy( pthread_barrier_t * barrier );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_init.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
* @retval EINVAL - The value specified by count is equal to zero.
* @retval ENOMEM - count cannot fit into FreeRTOS event group type OR insufficient memory exists to initialize the barrier.
- *
- * @note attr is ignored.
- *
- * @note pthread_barrier_init() is implemented with FreeRTOS event group.
- * To ensure count fits in event group, count may be at most 8 when configUSE_16_BIT_TICKS is 1; it may be at most 24 otherwise.
- * configUSE_16_BIT_TICKS is configured in application FreeRTOSConfig.h file, which defines how many bits tick count type has.
- * See further details and limitation about event group and configUSE_16_BIT_TICKS in FreeRTOS site.
+ *
+ * @note attr is ignored.
+ *
+ * @note pthread_barrier_init() is implemented with FreeRTOS event group.
+ * To ensure count fits in event group, count may be at most 8 when configUSE_16_BIT_TICKS is 1;
+ * it may be at most 24 otherwise. configUSE_16_BIT_TICKS is configured in application FreeRTOSConfig.h
+ * file, which defines how many bits tick count type has. See further details and limitation about event
+ * group and configUSE_16_BIT_TICKS in FreeRTOS site.
*/
int pthread_barrier_init( pthread_barrier_t * barrier,
const pthread_barrierattr_t * attr,
@@ -211,7 +229,7 @@ int pthread_barrier_init( pthread_barrier_t * barrier,
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_wait.html
*
* @retval PTHREAD_BARRIER_SERIAL_THREAD - Upon successful completion, the first thread.
- * @retval 0 - Upon successful completion, other thread(s).
+ * @retval 0 - Upon successful completion, other thread(s).
*/
int pthread_barrier_wait( pthread_barrier_t * barrier );
@@ -220,7 +238,7 @@ int pthread_barrier_wait( pthread_barrier_t * barrier );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
* @retval EAGAIN - Insufficient memory for either thread structure or task creation.
*/
int pthread_create( pthread_t * thread,
@@ -232,8 +250,8 @@ int pthread_create( pthread_t * thread,
* @brief Broadcast a condition.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html
- *
- * @retval 0 - Upon successful completion
+ *
+ * @retval 0 - Upon successful completion.
*/
int pthread_cond_broadcast( pthread_cond_t * cond );
@@ -242,7 +260,7 @@ int pthread_cond_broadcast( pthread_cond_t * cond );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_cond_destroy( pthread_cond_t * cond );
@@ -251,10 +269,10 @@ int pthread_cond_destroy( pthread_cond_t * cond );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
* @retval ENOMEM - Insufficient memory exists to initialize the condition variable.
*
- * @note attr is ignored and treated as NULL. Default setting is always used.
+ * @note attr is ignored and treated as NULL. Default setting is always used.
*/
int pthread_cond_init( pthread_cond_t * cond,
const pthread_condattr_t * attr );
@@ -264,7 +282,7 @@ int pthread_cond_init( pthread_cond_t * cond,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_cond_signal( pthread_cond_t * cond );
@@ -273,9 +291,10 @@ int pthread_cond_signal( pthread_cond_t * cond );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
*
- * @retval 0 - Upon successful completion
- * @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
- * the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
+ * the abstime parameter specified a nanoseconds field value less than zero or
+ * greater than or equal to 1000 million.
* @retval ETIMEDOUT - The time specified by abstime to pthread_cond_timedwait() has passed.
*/
int pthread_cond_timedwait( pthread_cond_t * cond,
@@ -287,7 +306,7 @@ int pthread_cond_timedwait( pthread_cond_t * cond,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_cond_wait( pthread_cond_t * cond,
pthread_mutex_t * mutex );
@@ -296,9 +315,9 @@ int pthread_cond_wait( pthread_cond_t * cond,
* @brief Compare thread IDs.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html
- *
- * @retval 0 - t1 and t2 are both not NULL && equal
- * @retval non-zero - otherwise
+ *
+ * @retval 0 - t1 and t2 are both not NULL && equal.
+ * @retval non-zero - otherwise.
*/
int pthread_equal( pthread_t t1,
pthread_t t2 );
@@ -307,7 +326,7 @@ int pthread_equal( pthread_t t1,
* @brief Thread termination.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html
- *
+ *
* @retval void - this function cannot return to its caller.
*/
void pthread_exit( void * value_ptr );
@@ -316,10 +335,10 @@ void pthread_exit( void * value_ptr );
* @brief Dynamic thread scheduling parameters access.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html
- *
- * @retval 0 - Upon successful completion
*
- * @note policy is always set to SCHED_OTHER by this function.
+ * @retval 0 - Upon successful completion.
+ *
+ * @note policy is always set to SCHED_OTHER by this function.
*/
int pthread_getschedparam( pthread_t thread,
int * policy,
@@ -329,11 +348,12 @@ int pthread_getschedparam( pthread_t thread,
* @brief Wait for thread termination.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html
- *
- * @retval 0 - Upon successful completion
- * @retval EDEADLK - The value specified by the thread argument to pthread_join() does not refer to
- * a joinable thread OR multiple simultaneous calls to pthread_join() specifying the same target thread OR
- * the value specified by the thread argument to pthread_join() refers to the calling thread.
+ *
+ * @retval 0 - Upon successful completion.
+ * @retval EDEADLK - The value specified by the thread argument to pthread_join() does not refer
+ * to a joinable thread OR multiple simultaneous calls to pthread_join()
+ * specifying the same target thread OR the value specified by the thread argument
+ * to pthread_join() refers to the calling thread.
*/
int pthread_join( pthread_t thread,
void ** retval );
@@ -343,10 +363,9 @@ int pthread_join( pthread_t thread,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html
*
- * @retval 0 - Upon successful completion
- *
- * @note If there exists a thread holding this mutex, this function returns 0 with mutex not being destroyed.
+ * @retval 0 - Upon successful completion.
*
+ * @note If there exists a thread holding this mutex, this function returns 0 with mutex not being destroyed.
*/
int pthread_mutex_destroy( pthread_mutex_t * mutex );
@@ -354,8 +373,8 @@ int pthread_mutex_destroy( pthread_mutex_t * mutex );
* @brief Initialize a mutex.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
- *
- * @retval 0 - Upon successful completion
+ *
+ * @retval 0 - Upon successful completion.
* @retval ENOMEM - Insufficient memory exists to initialize the mutex structure.
* @retval EAGAIN - Unable to initialize the mutex structure member(s).
*/
@@ -366,11 +385,12 @@ int pthread_mutex_init( pthread_mutex_t * mutex,
* @brief Lock a mutex.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
- *
- * @retval 0 - Upon successful completion
- * @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
- * @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
*
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero
+ * or greater than or equal to 1000 million.
+ * @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already
+ * owns the mutex.
*/
int pthread_mutex_lock( pthread_mutex_t * mutex );
@@ -378,13 +398,13 @@ int pthread_mutex_lock( pthread_mutex_t * mutex );
* @brief Lock a mutex with timeout.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html
- *
- * @retval 0 - Upon successful completion
- * @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
- * the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
+ *
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
+ * the abstime parameter specified a nanoseconds field value less than zero or
+ * greater than or equal to 1000 million.
* @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
* @retval ETIMEDOUT - The mutex could not be locked before the specified timeout expired.
- *
*/
int pthread_mutex_timedlock( pthread_mutex_t * mutex,
const struct timespec * abstime );
@@ -394,11 +414,12 @@ int pthread_mutex_timedlock( pthread_mutex_t * mutex,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html
*
- * @retval 0 - Upon successful completion
- * @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
- * @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero
+ * or greater than or equal to 1000 million.
+ * @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already
+ * owns the mutex.
* @retval EBUSY - The mutex could not be acquired because it was already locked.
- *
*/
int pthread_mutex_trylock( pthread_mutex_t * mutex );
@@ -407,8 +428,9 @@ int pthread_mutex_trylock( pthread_mutex_t * mutex );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html
*
- * @retval 0 - Upon successful completion
- * @retval EPERM - The mutex type is PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE, and the current thread does not own the mutex.
+ * @retval 0 - Upon successful completion.
+ * @retval EPERM - The mutex type is PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE, and
+ * the current thread does not own the mutex.
*/
int pthread_mutex_unlock( pthread_mutex_t * mutex );
@@ -417,7 +439,7 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_destroy.html
*
- * @retval 0 - Upon successful completion
+ * @retval 0 - Upon successful completion.
*/
int pthread_mutexattr_destroy( pthread_mutexattr_t * attr );
@@ -425,8 +447,8 @@ int pthread_mutexattr_destroy( pthread_mutexattr_t * attr );
* @brief Get the mutex type attribute.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html
- *
- * @retval 0 - Upon successful completion
+ *
+ * @retval 0 - Upon successful completion.
*/
int pthread_mutexattr_gettype( const pthread_mutexattr_t * attr,
int * type );
@@ -436,10 +458,10 @@ int pthread_mutexattr_gettype( const pthread_mutexattr_t * attr,
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_init.html
*
- * @retval 0 - Upon successful completion
- * @retval ENOMEM - Insufficient memory exists to initialize the mutex attributes object.
- *
- * @note Currently, only the type attribute is supported. Also see pthread_mutexattr_settype() and pthread_mutexattr_gettype().
+ * @retval 0 - Upon successful completion.
+ *
+ * @note Currently, only the type attribute is supported. Also see pthread_mutexattr_settype()
+ * and pthread_mutexattr_gettype().
*/
int pthread_mutexattr_init( pthread_mutexattr_t * attr );
@@ -448,8 +470,8 @@ int pthread_mutexattr_init( pthread_mutexattr_t * attr );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html
*
- * @retval 0 - Upon successful completion
- * @retval EINVAL - The value type is invalid.
+ * @retval 0 - Upon successful completion.
+ * @retval EINVAL - The value type is invalid.
*/
int pthread_mutexattr_settype( pthread_mutexattr_t * attr,
int type );
@@ -468,9 +490,9 @@ pthread_t pthread_self( void );
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedparam.html
*
- * @retval 0 - Upon successful completion
- *
* @note policy is ignored; only priority (param.sched_priority) may be changed.
+ *
+ * @retval 0 - Upon successful completion.
*/
int pthread_setschedparam( pthread_t thread,
int policy,
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sched.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sched.h
index a37b0ef..5a72c44 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sched.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sched.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -34,10 +34,10 @@
#define _FREERTOS_POSIX_SCHED_H_
/**
- * @brief Scheduling Policies
+ * @name Scheduling Policies
*/
/**@{ */
-#define SCHED_OTHER 0 /**< Another scheduling policy. */
+#define SCHED_OTHER 0 /**< Another scheduling policy. */
/**@} */
/**
@@ -50,19 +50,28 @@ struct sched_param
};
/**
- * @brief Get priority limit.
+ * @brief Get priority limit (max).
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html
*
* @note policy is ignored.
*
- * @return the maxium priority value (0-based) system configuration allows.
+ * @return the maximum priority value (0-based) system configuration allows.
*
- * e.g. if configMAX_PRIORITIES == 7, this function returns (configMAX_PRIORITIES - 1).
- * configMAX_PRIORITIES is configured in appication FreeRTOSConfig.h file.
+ * e.g. if configMAX_PRIORITIES == 7, this function returns (configMAX_PRIORITIES - 1).
+ * configMAX_PRIORITIES is configured in application FreeRTOSConfig.h file.
*/
int sched_get_priority_max( int policy );
+/**
+ * @brief Get priority limit (min).
+ *
+ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_min.html
+ *
+ * @note policy is ignored.
+ */
+int sched_get_priority_min( int policy );
+
/**
* @brief Yield the processor.
*
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/semaphore.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/semaphore.h
index 6ee312c..fa1da91 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/semaphore.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/semaphore.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -35,11 +35,12 @@
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX/time.h"
+#include "FreeRTOS_POSIX_types.h"
/**
* @brief Semaphore type.
*/
-typedef void * sem_t;
+typedef PosixSemType_t sem_t;
/**
* @brief Destroy an unnamed semaphore.
@@ -47,8 +48,8 @@ typedef void * sem_t;
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_destroy.html
*
* @retval 0 - upon successful completion
- *
- * @note Semaphore is destroyed regardless of whether there is any thread currently blocked on this semaphore.
+ *
+ * @note Semaphore is destroyed regardless of whether there is any thread currently blocked on this semaphore.
*/
int sem_destroy( sem_t * sem );
@@ -58,7 +59,7 @@ int sem_destroy( sem_t * sem );
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_getvalue.html
*
* @retval 0 - Upon successful completion
- *
+ *
* @note If sem is locked, then the object to which sval points is set to zero.
*/
int sem_getvalue( sem_t * sem,
@@ -70,16 +71,15 @@ int sem_getvalue( sem_t * sem,
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html
*
* @note pshared is ignored. Semaphores will always be considered "shared".
- *
+ *
* @retval 0 - upon successful completion
- * @retval -1 - otherwise. System error variable errno is also set in this case.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - otherwise. System error variable errno is also set in this case.
+ *
+ * @sideeffect Possible errno values
*
* EINVAL - The value argument exceeds {SEM_VALUE_MAX}.
*
- * ENOSPC - A resource required to initialize the semaphore has been exhausted.
- *
+ * ENOSPC - A resource required to initialize the semaphore has been exhausted.
*/
int sem_init( sem_t * sem,
int pshared,
@@ -98,17 +98,17 @@ int sem_post( sem_t * sem );
* @brief Lock a semaphore with timeout.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html
- *
- * @retval 0 - upon successful completion
- * @retval -1 - otherwise. System error variable errno is also set in this case.
*
- * \sideeffect Possible errno values
+ * @retval 0 - upon successful completion
+ * @retval -1 - otherwise. System error variable errno is also set in this case.
+ *
+ * @sideeffect Possible errno values
*
- * EINVAL - parameter specified a nanoseconds field value less than zero or greater
- * than or equal to 1000 million
+ * EINVAL - parameter specified a nanoseconds field value less than zero or greater
+ * than or equal to 1000 million
*
* ETIMEDOUT - The semaphore could not be locked before the specified timeout expired.
- *
+ *
* @note Deadlock detection is not implemented.
*/
int sem_timedwait( sem_t * sem,
@@ -118,11 +118,11 @@ int sem_timedwait( sem_t * sem,
* @brief Lock a semaphore if available.
*
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html
- *
+ *
* @retval 0 - upon successful completion
- * @retval -1 - otherwise. System error variable errno is also set in this case.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - otherwise. System error variable errno is also set in this case.
+ *
+ * @sideeffect Possible errno values
*
* EAGAIN - The semaphore was already locked, so it cannot be immediately locked by the sem_trywait() operation.
*/
@@ -134,8 +134,8 @@ int sem_trywait( sem_t * sem );
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
*
* @retval 0 - upon successful completion
- * @retval -1 - otherwise. System error variable errno is also set in this case.
- *
+ * @retval -1 - otherwise. System error variable errno is also set in this case.
+ *
* @note Deadlock detection is not implemented.
*/
int sem_wait( sem_t * sem );
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/signal.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/signal.h
index 889873f..8f9cc6d 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/signal.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/signal.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -38,7 +38,7 @@
#define _FREERTOS_POSIX_SIGNAL_H_
/**
- * @brief Values of sigev_notify.
+ * @name Values of sigev_notify.
*/
/**@{ */
#define SIGEV_NONE 0 /**< No asynchronous notification is delivered when the event of interest occurs. */
@@ -60,11 +60,11 @@ union sigval
*/
struct sigevent
{
- int sigev_notify; /**< Notification type. A value of SIGEV_SIGNAL is not supported. */
- int sigev_signo; /**< Signal number. This member is ignored. */
- union sigval sigev_value; /**< Signal value. Only the sival_ptr member is used. */
- void ( * sigev_notify_function ) ( union sigval ); /**< Notification function. */
- pthread_attr_t * sigev_notify_attributes; /**< Notification attributes. */
+ int sigev_notify; /**< Notification type. A value of SIGEV_SIGNAL is not supported. */
+ int sigev_signo; /**< Signal number. This member is ignored. */
+ union sigval sigev_value; /**< Signal value. Only the sival_ptr member is used. */
+ void ( * sigev_notify_function )( union sigval ); /**< Notification function. */
+ pthread_attr_t * sigev_notify_attributes; /**< Notification attributes. */
};
#endif /* ifndef _FREERTOS_POSIX_SIGNAL_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sys/types.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sys/types.h
index 829d787..9cb3428 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sys/types.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/sys/types.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -36,126 +36,156 @@
/* C standard library includes. */
#include
+/* FreeRTOS types include */
+#include "FreeRTOS_POSIX_types.h"
+
/**
- * @brief Used for system times in clock ticks or CLOCKS_PER_SEC.
+ * @brief Used for system times in clock ticks or CLOCKS_PER_SEC.
+ *
* Enabled/disabled by posixconfigENABLE_CLOCK_T.
*/
#if !defined( posixconfigENABLE_CLOCK_T ) || ( posixconfigENABLE_CLOCK_T == 1 )
- typedef uint32_t clock_t;
+ typedef uint32_t clock_t;
#endif
/**
* @brief Used for clock ID type in the clock and timer functions.
+ *
* Enabled/disabled by posixconfigENABLE_CLOCKID_T.
*/
#if !defined( posixconfigENABLE_CLOCKID_T ) || ( posixconfigENABLE_CLOCKID_T == 1 )
- typedef int clockid_t;
+ typedef int clockid_t;
#endif
/**
* @brief Used for some file attributes.
+ *
* Enabled/disabled by posixconfigENABLE_MODE_T.
*/
#if !defined( posixconfigENABLE_MODE_T ) || ( posixconfigENABLE_MODE_T == 1 )
- typedef int mode_t;
+ typedef int mode_t;
#endif
/**
* @brief Used for process IDs and process group IDs.
+ *
* Enabled/disabled by posixconfigENABLE_PID_T.
*/
#if !defined( posixconfigENABLE_PID_T ) || ( posixconfigENABLE_PID_T == 1 )
- typedef int pid_t;
+ typedef int pid_t;
#endif
/**
* @brief Used to identify a thread attribute object.
+ *
* Enabled/disabled by posixconfigENABLE_PTHREAD_ATTR_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_ATTR_T ) || ( posixconfigENABLE_PTHREAD_ATTR_T == 1 )
- typedef void * pthread_attr_t;
+ typedef PthreadAttrType_t pthread_attr_t;
#endif
/**
* @brief Used to identify a barrier.
+ *
+ * Enabled/disabled by posixconfigENABLE_PTHREAD_BARRIER_T.
*/
-typedef void * pthread_barrier_t;
+#if !defined( posixconfigENABLE_PTHREAD_BARRIER_T ) || ( posixconfigENABLE_PTHREAD_BARRIER_T == 1 )
+ typedef PthreadBarrierType_t pthread_barrier_t;
+#endif
/**
* @brief Used to define a barrier attributes object.
*/
-typedef void * pthread_barrierattr_t;
+typedef void * pthread_barrierattr_t;
/**
* @brief Used for condition variables.
+ *
* Enabled/disabled by posixconfigENABLE_PTHREAD_COND_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_COND_T ) || ( posixconfigENABLE_PTHREAD_COND_T == 1 )
- typedef void * pthread_cond_t;
+ typedef PthreadCondType_t pthread_cond_t;
#endif
/**
* @brief Used to identify a condition attribute object.
+ *
* Enabled/disabled by posixconfigENABLE_PTHREAD_CONDATTR_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_CONDATTR_T ) || ( posixconfigENABLE_PTHREAD_CONDATTR_T == 1 )
- typedef void * pthread_condattr_t;
+ typedef void * pthread_condattr_t;
#endif
/**
* @brief Used for mutexes.
+ *
* Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEX_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_MUTEX_T ) || ( posixconfigENABLE_PTHREAD_MUTEX_T == 1 )
- typedef void * pthread_mutex_t;
+ typedef PthreadMutexType_t pthread_mutex_t;
#endif
/**
* @brief Used to identify a mutex attribute object.
+ *
* Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEXATTR_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_MUTEXATTR_T ) || ( posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1 )
- typedef void * pthread_mutexattr_t;
+ typedef PthreadMutexAttrType_t pthread_mutexattr_t;
#endif
/**
* @brief Used to identify a thread.
- * Enabled/disabled by posixconfigENABLE_PTHREAD_T
+ *
+ * Enabled/disabled by posixconfigENABLE_PTHREAD_T.
*/
#if !defined( posixconfigENABLE_PTHREAD_T ) || ( posixconfigENABLE_PTHREAD_T == 1 )
- typedef void * pthread_t;
+ typedef void * pthread_t;
#endif
/**
* @brief Used for a count of bytes or an error indication.
+ *
* Enabled/disabled by posixconfigENABLE_SSIZE_T.
*/
#if !defined( posixconfigENABLE_SSIZE_T ) || ( posixconfigENABLE_SSIZE_T == 1 )
- typedef int ssize_t;
+ typedef int ssize_t;
#endif
/**
* @brief Used for time in seconds.
+ *
* Enabled/disabled by posixconfigENABLE_TIME_T.
*/
#if !defined( posixconfigENABLE_TIME_T ) || ( posixconfigENABLE_TIME_T == 1 )
- typedef int64_t time_t;
+ typedef int64_t time_t;
#endif
/**
* @brief Used for timer ID returned by timer_create().
+ *
* Enabled/disabled by posixconfigENABLE_TIMER_T.
*/
#if !defined( posixconfigENABLE_TIMER_T ) || ( posixconfigENABLE_TIMER_T == 1 )
- typedef void * timer_t;
+ typedef void * timer_t;
#endif
/**
* @brief Used for time in microseconds.
+ *
* Enabled/disabled by posixconfigENABLE_USECONDS_T.
*/
#if !defined( posixconfigENABLE_USECONDS_T ) || ( posixconfigENABLE_USECONDS_T == 1 )
- typedef unsigned long useconds_t;
+ typedef unsigned long useconds_t;
+#endif
+
+/**
+ * @brief Used for file sizes.
+ *
+ * Enabled/disabled by posixconfigENABLE_OFF_T.
+ */
+#if !defined( posixconfigENABLE_OFF_T ) || ( posixconfigENABLE_OFF_T == 1 )
+ typedef long int off_t;
#endif
#endif /* ifndef _FREERTOS_POSIX_TYPES_H_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/time.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/time.h
index 41fddb1..d04de0f 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/time.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/time.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -38,7 +38,7 @@
#include "FreeRTOS_POSIX/signal.h"
/**
- * @brief Unit conversion constants.
+ * @name Unit conversion constants.
*/
/**@{ */
#define MICROSECONDS_PER_SECOND ( 1000000LL ) /**< Microseconds per second. */
@@ -47,7 +47,7 @@
/**@} */
/**
- * @brief Clock identifiers.
+ * @name Clock identifiers.
*/
/**@{ */
#define CLOCK_REALTIME 0 /**< The identifier of the system-wide clock measuring real time. */
@@ -55,21 +55,26 @@
/**@} */
/**
- * @brief A number used to convert the value returned by the clock() function into seconds.
+ * @name A number used to convert the value returned by the clock() function into seconds.
*/
+/**@{ */
#define CLOCKS_PER_SEC ( ( clock_t ) configTICK_RATE_HZ )
+/**@} */
/**
- * @brief Flag indicating time is absolute.
+ * @name Flag indicating time is absolute.
*
* For functions taking timer objects, this refers to the clock associated with the timer.
*/
-#define TIMER_ABSTIME 0x01
+/**@{ */
+#define TIMER_ABSTIME 0x01
+/**@} */
#if !defined( posixconfigENABLE_TIMESPEC ) || ( posixconfigENABLE_TIMESPEC == 1 )
- /**
- * @brief represents an elapsed time
- */
+
+/**
+ * @brief represents an elapsed time
+ */
struct timespec
{
time_t tv_sec; /**< Seconds. */
@@ -78,9 +83,10 @@
#endif
#if !defined( posixconfigENABLE_ITIMERSPEC ) || ( posixconfigENABLE_ITIMERSPEC == 1 )
- /**
- * @brief timer
- */
+
+/**
+ * @brief timer
+ */
struct itimerspec
{
struct timespec it_interval; /**< Timer period. */
@@ -88,33 +94,14 @@
};
#endif
-#if !defined( posixconfigENABLE_TM ) || ( posixconfigENABLE_TM == 1 )
- /**
- * @brief calendar representation of time
- */
- struct tm
- {
- time_t tm_tick; /**< FreeRTOS tick count. */
- int tm_sec; /**< Seconds [0,60]. Not used. */
- int tm_min; /**< Minutes [0,59]. Not used. */
- int tm_hour; /**< Hour [0,23]. Not used. */
- int tm_mday; /**< Day of month [1,31]. Not used. */
- int tm_mon; /**< Month of year [0,11]. Not used. */
- int tm_year; /**< Years since 1900. Not used. */
- int tm_wday; /**< Day of week [0,6] (Sunday=0). Not used. */
- int tm_yday; /**< Day of year [0,365]. Not used. */
- int tm_isdst; /**< Daylight Savings flag. Not used. */
- };
-#endif
-
/**
* @brief Report CPU time used.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
*
* @return The number of FreeRTOS ticks since the scheduler
- * was started minus the ticks spent in the idle task.
- *
+ * was started minus the ticks spent in the idle task.
+ *
* @note This function does NOT report the number of ticks spent by the calling thread.
*/
clock_t clock( void );
@@ -125,7 +112,7 @@ clock_t clock( void );
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
*
* @retval EPERM
- *
+ *
* @note This function is currently unsupported.
*
*/
@@ -152,9 +139,8 @@ int clock_getres( clockid_t clock_id,
*
* @note clock_id is ignored
* @note this function does not check for overflows of time_t.
- *
- * @retval 0 - Upon successful completion.
*
+ * @retval 0 - Upon successful completion.
*/
int clock_gettime( clockid_t clock_id,
struct timespec * tp );
@@ -164,9 +150,9 @@ int clock_gettime( clockid_t clock_id,
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
*
- * @note clock_id is ignored, as this function uses the FreeRTOS tick count as its clock.
+ * @note clock_id is ignored, as this function uses the FreeRTOS tick count as its clock.
* @note flags is ignored, if INCLUDE_vTaskDelayUntil is 0. i.e. the FreeRTOS function vTaskDelayUntil isn't available.
- * @note rmtp is also ignored, as signals are not implemented.
+ * @note rmtp is also ignored, as signals are not implemented.
*
* @retval 0 - Upon successful completion.
* @retval EINVAL - The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
@@ -181,32 +167,13 @@ int clock_nanosleep( clockid_t clock_id,
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html
*
- * @retval -1 with errno set to EPERM.
- *
+ * @retval -1 with errno set to EPERM.
+ *
* @note This function is currently unsupported, as FreeRTOS does not provide a function to modify the tick count.
*/
int clock_settime( clockid_t clock_id,
const struct timespec * tp );
-/**
- * @brief Convert a time value to a broken-down local time.
- *
- * http://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime_r.html
- *
- * @note timer is ignored
- *
- * @note This function can only store the time as tm.tm_tick. All other members of
- * the struct will be set to 0.
- *
- * @note In order to store tm.tm_tick in result, posixconfgENABLE_TM needs to be set to 1.
- * See FreeRTOS_POSIX_portable_default.h for porting configurations.
- *
- * @return Upon successful completion, returns a pointer points to the object holding structure of type tm.
- * @return If any error, rutrns NULL, with errno set to ENOTSUP.
- */
-struct tm * localtime_r( const time_t * timer,
- struct tm * result );
-
/**
* @brief High resolution sleep.
*
@@ -216,50 +183,23 @@ struct tm * localtime_r( const time_t * timer,
*
* @retval 0 - Upon successful completion.
* @retval -1 - The rqtp argument is invalid OR the rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
- *
+ *
*/
int nanosleep( const struct timespec * rqtp,
struct timespec * rmtp );
-/**
- * @brief Convert date and time to a string.
- *
- * http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html
- *
- * @note format is ignored.
- *
- * @retval the number of bytes placed into the array pointed to by s,
- * if the total number of resulting bytes including the terminating null byte is not more than maxsize.
- * @retval 0, otherwise. In this case, the array pointed to by s contains partially copied data.
- */
-size_t strftime( char * s,
- size_t maxsize,
- const char * format,
- const struct tm * timeptr );
-
-/**
- * @brief Get time.
- *
- * http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html
- *
- * @note This function returns the FreeRTOS tick count, not the seconds since UNIX epoch.
- *
- * @retval FreeRTOS tick count - upon successful completion
- */
-time_t time( time_t * tloc );
-
/**
* @brief Create a per-process timer.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
*
- * @note clock_id is ignored, as this function used the FreeRTOS tick count as its clock.
+ * @note clock_id is ignored, as this function used the FreeRTOS tick count as its clock.
* @note evp.sigev_notify must be set to SIGEV_THREAD, since signals are currently not supported.
- *
+ *
* @retval 0 - Upon successful completion, with location referenced by timerid updated.
- * @retval -1 - If an error occurs. errno is also set.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - If an error occurs. errno is also set.
+ *
+ * @sideeffect Possible errno values
*
* ENOTSUP - If evp is NULL OR evp->sigen_notify == SIGEV_SIGNAL.
*
@@ -303,11 +243,11 @@ int timer_gettime( timer_t timerid,
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_settime.html
*
* @retval 0 - Upon successful completion.
- * @retval -1 - An error occured, errno is also set.
- *
- * \sideeffect Possible errno values
+ * @retval -1 - An error occurred, errno is also set.
+ *
+ * @sideeffect Possible errno values
*
- * EINVAL - A value structure specified a nanosecond value less than zero or greater than or equal to 1000 million,
+ * EINVAL - A value structure specified a nanosecond value less than zero or greater than or equal to 1000 million,
* AND the it_value member of that structure did not specify zero seconds and nanoseconds.
*/
int timer_settime( timer_t timerid,
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/unistd.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/unistd.h
index ab44847..3b8af22 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/unistd.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/unistd.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -33,16 +33,18 @@
#ifndef _FREERTOS_POSIX_UNISTD_H_
#define _FREERTOS_POSIX_UNISTD_H_
+#include "FreeRTOS_POSIX/sys/types.h"
+
/**
* @brief Suspend execution for an interval of time.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html
- *
- * @param[in] seconds The number of seconds to suspend execution.
- *
- * @retval 0 - Upon successful completion.
*
- * @note Return value of a positive number is not yet supported.
+ * @param[in] seconds The number of seconds to suspend execution.
+ *
+ * @retval 0 - Upon successful completion.
+ *
+ * @note Return value of a positive number is not yet supported.
*/
unsigned sleep( unsigned seconds );
@@ -52,7 +54,7 @@ unsigned sleep( unsigned seconds );
* This is a useful, non-POSIX function.
* @param[in] usec The number of microseconds to suspend execution.
*
- * @retval 0 - Upon successful cocmpletion.
+ * @retval 0 - Upon successful completion.
*/
int usleep( useconds_t usec );
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/utils.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/utils.h
index ab4769b..c893a95 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/utils.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/utils.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS+POSIX V1.0.0
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS POSIX V1.1.0
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -55,20 +55,23 @@ size_t UTILS_strnlen( const char * const pcString,
*
* @param[in] pxAbsoluteTime A time in the future, specified as seconds and
* nanoseconds since CLOCK_REALTIME's 0.
+ * @param[in] pxCurrentTime current time, specified as seconds and
+ * nanoseconds.
* @param[out] pxResult Where the result of the conversion is stored. The result
* is rounded up for fractional ticks.
*
* @return 0 on success. Otherwise, ETIMEDOUT if pxAbsoluteTime is in the past,
* or EINVAL for invalid parameters.
*/
-int UTILS_AbsoluteTimespecToTicks( const struct timespec * const pxAbsoluteTime,
- TickType_t * const pxResult );
+int UTILS_AbsoluteTimespecToDeltaTicks( const struct timespec * const pxAbsoluteTime,
+ const struct timespec * const pxCurrentTime,
+ TickType_t * const pxResult );
/**
* @brief Converts a struct timespec to FreeRTOS ticks.
*
* @param[in] pxTimespec The timespec to convert.
- * @param[out] pxResult Where the result of the conversion is stored. The result is rounded
+ * @param[out] Where the result of the conversion is stored. The result is rounded
* up for fractional ticks.
*
* @return 0 on success. Otherwise, EINVAL for invalid parameters.
@@ -90,51 +93,63 @@ void UTILS_NanosecondsToTimespec( int64_t llSource,
/**
* @brief Calculates pxResult = x + y.
*
- * @param[out] pxResult Where the result of the calculation is stored.
* @param[in] x The first argument for addition.
* @param[in] y The second argument for addition.
+ * @param[out] pxResult Where the result of the calculation is stored.
*
- * @return -1 if any argument was NULL; 1 if result is negative; otherwise, 0.
+ * @return -1 if any argument was NULL; 1 if result is negative (overflow); otherwise, 0.
*/
-int UTILS_TimespecAdd( struct timespec * const pxResult,
- const struct timespec * const x,
- const struct timespec * const y );
+int UTILS_TimespecAdd( const struct timespec * const x,
+ const struct timespec * const y,
+ struct timespec * const pxResult );
/**
* @brief Calculates pxResult = x + ( struct timespec ) nanosec.
*
- * @param[out] pxResult Where the result of the calculation is stored.
* @param[in] x The first argument for addition.
* @param[in] llNanoseconds The second argument for addition.
+ * @param[out] pxResult Where the result of the calculation is stored.
*
* @return -1 if pxResult or x was NULL; 1 if result is negative; otherwise, 0.
*/
-int UTILS_TimespecAddNanoseconds( struct timespec * const pxResult,
- const struct timespec * const x,
- int64_t llNanoseconds );
+int UTILS_TimespecAddNanoseconds( const struct timespec * const x,
+ int64_t llNanoseconds,
+ struct timespec * const pxResult );
/**
- * @brief Calculates pxResult = x - y.
+ * @brief Calculates pxResult = x - y. If the result is negative contents of
+ * pResult are undefined
*
- * @param[out] pxResult Where the result of the calculation is stored.
* @param[in] x The first argument for subtraction.
* @param[in] y The second argument for subtraction.
+ * @param[out] pxResult Where the result of the calculation is stored.
*
* @return -1 if any argument was NULL; 1 if result is negative; otherwise, 0.
*/
-int UTILS_TimespecSubtract( struct timespec * const pxResult,
- const struct timespec * const x,
- const struct timespec * const y );
+int UTILS_TimespecSubtract( const struct timespec * const x,
+ const struct timespec * const y,
+ struct timespec * const pxResult );
/**
-* @brief Checks that a timespec conforms to POSIX.
-*
-* A valid timespec must have 0 <= tv_nsec < 1000000000.
-*
-* @param[in] pxTimespec The timespec to validate.
-*
-* @return true if the pxTimespec is valid, false otherwise.
-*/
-bool UTILS_ValidateTimespec(const struct timespec * const pxTimespec);
+ * @brief Compare x == y.
+ *
+ * @param[in] x The first argument for comparison.
+ * @param[in] y The second argument for comparison.
+ *
+ * @return 0 if x == y; 1 if x > y; -1 if x < y or any argument was NULL
+ */
+int UTILS_TimespecCompare( const struct timespec * const x,
+ const struct timespec * const y );
+
+/**
+ * @brief Checks that a timespec conforms to POSIX.
+ *
+ * A valid timespec must have 0 <= tv_nsec < 1000000000.
+ *
+ * @param[in] pxTimespec The timespec to validate.
+ *
+ * @return true if the pxTimespec is valid, false otherwise.
+ */
+bool UTILS_ValidateTimespec( const struct timespec * const pxTimespec );
#endif /* ifndef _FREERTOS_POSIX_UTILS_ */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/aws_doubly_linked_list.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/iot_doubly_linked_list.h
similarity index 98%
rename from FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/aws_doubly_linked_list.h
rename to FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/iot_doubly_linked_list.h
index ec912b4..338c539 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/aws_doubly_linked_list.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/private/iot_doubly_linked_list.h
@@ -1,6 +1,6 @@
/*
- * Amazon FreeRTOS
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * Amazon FreeRTOS Common V1.0.0
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@@ -23,9 +23,8 @@
* http://www.FreeRTOS.org
*/
-
/**
- * @file aws_doubly_linked_list.h
+ * @file iot_doubly_linked_list.h
* @brief Doubly Linked List implementation.
*
* A generic implementation of circular Doubly Linked List which consists of a
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c
index 94f4030..63560c7 100755
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c
@@ -73,6 +73,7 @@
/* System headers. */
#include
#include
+#include
/* Demo includes. */
#include "posix_demo.h"
@@ -270,11 +271,14 @@ static void * prvDispatcherThread( void * pvArgs )
*
* See the top of this file for detailed description.
*/
-void vStartPOSIXDemo( void )
+void vStartPOSIXDemo( void *pvParameters )
{
int i = 0;
int iStatus = 0;
+ /* Remove warnings about unused parameters. */
+ ( void ) pvParameters;
+
/* Handles of the threads and related resources. */
DispatcherThreadResources_t pxDispatcher = { 0 };
WorkerThreadResources_t pxWorkers[ MQUEUE_NUMBER_OF_WORKERS ] = { { 0 } };
@@ -363,4 +367,8 @@ void vStartPOSIXDemo( void )
{
printf( "Queues did not get initialized properly. Did not run demo. %s", LINE_BREAK );
}
+
+ /* This task was created with the native xTaskCreate() API function, so
+ must not run off the end of its implementing thread. */
+ vTaskDelete( NULL );
}
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
deleted file mode 100755
index 72f4828..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * FreeRTOS+CLI V1.0.4
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-
-/* Utils includes. */
-#include "FreeRTOS_CLI.h"
-
-/* If the application writer needs to place the buffer used by the CLI at a
-fixed address then set configAPPLICATION_PROVIDES_cOutputBuffer to 1 in
-FreeRTOSConfig.h, then declare an array with the following name and size in
-one of the application files:
- char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
-*/
-#ifndef configAPPLICATION_PROVIDES_cOutputBuffer
- #define configAPPLICATION_PROVIDES_cOutputBuffer 0
-#endif
-
-typedef struct xCOMMAND_INPUT_LIST
-{
- const CLI_Command_Definition_t *pxCommandLineDefinition;
- struct xCOMMAND_INPUT_LIST *pxNext;
-} CLI_Definition_List_Item_t;
-
-/*
- * The callback function that is executed when "help" is entered. This is the
- * only default command that is always present.
- */
-static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
-
-/*
- * Return the number of parameters that follow the command name.
- */
-static int8_t prvGetNumberOfParameters( const char *pcCommandString );
-
-/* The definition of the "help" command. This command is always at the front
-of the list of registered commands. */
-static const CLI_Command_Definition_t xHelpCommand =
-{
- "help",
- "\r\nhelp:\r\n Lists all the registered commands\r\n\r\n",
- prvHelpCommand,
- 0
-};
-
-/* The definition of the list of commands. Commands that are registered are
-added to this list. */
-static CLI_Definition_List_Item_t xRegisteredCommands =
-{
- &xHelpCommand, /* The first command in the list is always the help command, defined in this file. */
- NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */
-};
-
-/* A buffer into which command outputs can be written is declared here, rather
-than in the command console implementation, to allow multiple command consoles
-to share the same buffer. For example, an application may allow access to the
-command interpreter by UART and by Ethernet. Sharing a buffer is done purely
-to save RAM. Note, however, that the command console itself is not re-entrant,
-so only one command interpreter interface can be used at any one time. For that
-reason, no attempt at providing mutual exclusion to the cOutputBuffer array is
-attempted.
-
-configAPPLICATION_PROVIDES_cOutputBuffer is provided to allow the application
-writer to provide their own cOutputBuffer declaration in cases where the
-buffer needs to be placed at a fixed address (rather than by the linker). */
-#if( configAPPLICATION_PROVIDES_cOutputBuffer == 0 )
- static char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
-#else
- extern char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
-#endif
-
-
-/*-----------------------------------------------------------*/
-
-BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
-{
-static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
-CLI_Definition_List_Item_t *pxNewListItem;
-BaseType_t xReturn = pdFAIL;
-
- /* Check the parameter is not NULL. */
- configASSERT( pxCommandToRegister );
-
- /* Create a new list item that will reference the command being registered. */
- pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
- configASSERT( pxNewListItem );
-
- if( pxNewListItem != NULL )
- {
- taskENTER_CRITICAL();
- {
- /* Reference the command being registered from the newly created
- list item. */
- pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
-
- /* The new list item will get added to the end of the list, so
- pxNext has nowhere to point. */
- pxNewListItem->pxNext = NULL;
-
- /* Add the newly created list item to the end of the already existing
- list. */
- pxLastCommandInList->pxNext = pxNewListItem;
-
- /* Set the end of list marker to the new list item. */
- pxLastCommandInList = pxNewListItem;
- }
- taskEXIT_CRITICAL();
-
- xReturn = pdPASS;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen )
-{
-static const CLI_Definition_List_Item_t *pxCommand = NULL;
-BaseType_t xReturn = pdTRUE;
-const char *pcRegisteredCommandString;
-size_t xCommandStringLength;
-
- /* Note: This function is not re-entrant. It must not be called from more
- thank one task. */
-
- if( pxCommand == NULL )
- {
- /* Search for the command string in the list of registered commands. */
- for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )
- {
- pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;
- xCommandStringLength = strlen( pcRegisteredCommandString );
-
- /* To ensure the string lengths match exactly, so as not to pick up
- a sub-string of a longer command, check the byte after the expected
- end of the string is either the end of the string or a space before
- a parameter. */
- if( ( pcCommandInput[ xCommandStringLength ] == ' ' ) || ( pcCommandInput[ xCommandStringLength ] == 0x00 ) )
- {
- if( strncmp( pcCommandInput, pcRegisteredCommandString, xCommandStringLength ) == 0 )
- {
- /* The command has been found. Check it has the expected
- number of parameters. If cExpectedNumberOfParameters is -1,
- then there could be a variable number of parameters and no
- check is made. */
- if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )
- {
- if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )
- {
- xReturn = pdFALSE;
- }
- }
-
- break;
- }
- }
- }
- }
-
- if( ( pxCommand != NULL ) && ( xReturn == pdFALSE ) )
- {
- /* The command was found, but the number of parameters with the command
- was incorrect. */
- strncpy( pcWriteBuffer, "Incorrect command parameter(s). Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
- pxCommand = NULL;
- }
- else if( pxCommand != NULL )
- {
- /* Call the callback function that is registered to this command. */
- xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen, pcCommandInput );
-
- /* If xReturn is pdFALSE, then no further strings will be returned
- after this one, and pxCommand can be reset to NULL ready to search
- for the next entered command. */
- if( xReturn == pdFALSE )
- {
- pxCommand = NULL;
- }
- }
- else
- {
- /* pxCommand was NULL, the command was not found. */
- strncpy( pcWriteBuffer, "Command not recognised. Enter 'help' to view a list of available commands.\r\n\r\n", xWriteBufferLen );
- xReturn = pdFALSE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-char *FreeRTOS_CLIGetOutputBuffer( void )
-{
- return cOutputBuffer;
-}
-/*-----------------------------------------------------------*/
-
-const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t uxWantedParameter, BaseType_t *pxParameterStringLength )
-{
-UBaseType_t uxParametersFound = 0;
-const char *pcReturn = NULL;
-
- *pxParameterStringLength = 0;
-
- while( uxParametersFound < uxWantedParameter )
- {
- /* Index the character pointer past the current word. If this is the start
- of the command string then the first word is the command itself. */
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
- {
- pcCommandString++;
- }
-
- /* Find the start of the next string. */
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) == ' ' ) )
- {
- pcCommandString++;
- }
-
- /* Was a string found? */
- if( *pcCommandString != 0x00 )
- {
- /* Is this the start of the required parameter? */
- uxParametersFound++;
-
- if( uxParametersFound == uxWantedParameter )
- {
- /* How long is the parameter? */
- pcReturn = pcCommandString;
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
- {
- ( *pxParameterStringLength )++;
- pcCommandString++;
- }
-
- if( *pxParameterStringLength == 0 )
- {
- pcReturn = NULL;
- }
-
- break;
- }
- }
- else
- {
- break;
- }
- }
-
- return pcReturn;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
-{
-static const CLI_Definition_List_Item_t * pxCommand = NULL;
-BaseType_t xReturn;
-
- ( void ) pcCommandString;
-
- if( pxCommand == NULL )
- {
- /* Reset the pxCommand pointer back to the start of the list. */
- pxCommand = &xRegisteredCommands;
- }
-
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( pcWriteBuffer, pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );
- pxCommand = pxCommand->pxNext;
-
- if( pxCommand == NULL )
- {
- /* There are no more commands in the list, so there will be no more
- strings to return after this one and pdFALSE should be returned. */
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static int8_t prvGetNumberOfParameters( const char *pcCommandString )
-{
-int8_t cParameters = 0;
-BaseType_t xLastCharacterWasSpace = pdFALSE;
-
- /* Count the number of space delimited words in pcCommandString. */
- while( *pcCommandString != 0x00 )
- {
- if( ( *pcCommandString ) == ' ' )
- {
- if( xLastCharacterWasSpace != pdTRUE )
- {
- cParameters++;
- xLastCharacterWasSpace = pdTRUE;
- }
- }
- else
- {
- xLastCharacterWasSpace = pdFALSE;
- }
-
- pcCommandString++;
- }
-
- /* If the command string ended with spaces, then there will have been too
- many parameters counted. */
- if( xLastCharacterWasSpace == pdTRUE )
- {
- cParameters--;
- }
-
- /* The value returned is one less than the number of space delimited words,
- as the first word should be the command itself. */
- return cParameters;
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
deleted file mode 100755
index 6281c12..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * FreeRTOS+CLI V1.0.4
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-#ifndef COMMAND_INTERPRETER_H
-#define COMMAND_INTERPRETER_H
-
-/* The prototype to which callback functions used to process command line
-commands must comply. pcWriteBuffer is a buffer into which the output from
-executing the command can be written, xWriteBufferLen is the length, in bytes of
-the pcWriteBuffer buffer, and pcCommandString is the entire string as input by
-the user (from which parameters can be extracted).*/
-typedef BaseType_t (*pdCOMMAND_LINE_CALLBACK)( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
-
-/* The structure that defines command line commands. A command line command
-should be defined by declaring a const structure of this type. */
-typedef struct xCOMMAND_LINE_INPUT
-{
- const char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */
- const char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For example "help: Returns a list of all the commands\r\n". */
- const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */
- int8_t cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */
-} CLI_Command_Definition_t;
-
-/* For backward compatibility. */
-#define xCommandLineInput CLI_Command_Definition_t
-
-/*
- * Register the command passed in using the pxCommandToRegister parameter.
- * Registering a command adds the command to the list of commands that are
- * handled by the command interpreter. Once a command has been registered it
- * can be executed from the command line.
- */
-BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister );
-
-/*
- * Runs the command interpreter for the command string "pcCommandInput". Any
- * output generated by running the command will be placed into pcWriteBuffer.
- * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to
- * by pcWriteBuffer.
- *
- * FreeRTOS_CLIProcessCommand should be called repeatedly until it returns pdFALSE.
- *
- * pcCmdIntProcessCommand is not reentrant. It must not be called from more
- * than one task - or at least - by more than one task at a time.
- */
-BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen );
-
-/*-----------------------------------------------------------*/
-
-/*
- * A buffer into which command outputs can be written is declared in the
- * main command interpreter, rather than in the command console implementation,
- * to allow application that provide access to the command console via multiple
- * interfaces to share a buffer, and therefore save RAM. Note, however, that
- * the command interpreter itself is not re-entrant, so only one command
- * console interface can be used at any one time. For that reason, no attempt
- * is made to provide any mutual exclusion mechanism on the output buffer.
- *
- * FreeRTOS_CLIGetOutputBuffer() returns the address of the output buffer.
- */
-char *FreeRTOS_CLIGetOutputBuffer( void );
-
-/*
- * Return a pointer to the xParameterNumber'th word in pcCommandString.
- */
-const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t uxWantedParameter, BaseType_t *pxParameterStringLength );
-
-#endif /* COMMAND_INTERPRETER_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/History.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/History.txt
deleted file mode 100755
index 01c95fe..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/History.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-Changes between V1.0.3 and V1.0.4 released
-
- + Update to use stdint and the FreeRTOS specific typedefs that were
- introduced in FreeRTOS V8.0.0.
-
-Changes between V1.0.2 and V1.0.3 released
-
- + Previously, and in line with good software engineering practice, the
- FreeRTOS coding standard did not permit the use of char types that were
- not explicitly qualified as either signed or unsigned. As a result char
- pointers used to reference strings required casts, as did the use of any
- standard string handling functions. The casts ensured compiler warnings
- were not generated by compilers that defaulted unqualified char types to
- be signed or compilers that defaulted unqualified char types to be
- unsigned. As it has in later MISRA standards, this rule has now been
- relaxed, and unqualified char types are now permitted, but only when:
- 1) The char is used to point to a human readable text string.
- 2) The char is used to hold a single ASCII character.
-
-Changes between V1.0.1 and V1.0.2 released 14/10/2013
-
- + Changed double quotes (") to single quotes (') in the help string to
- allow the strings to be used with JSON in FreeRTOS+Nabto.
-
-Changes between V1.0.0 and V1.0.1 released 05/07/2012
-
- + Change the name of the structure used to map a function that implements
- a CLI command to the string used to call the command from
- xCommandLineInput to CLI_Command_Definition_t, as it was always intended
- to be. A #define was added to map the old name to the new name for
- reasons of backward compatibility.
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/LICENSE_INFORMATION.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/LICENSE_INFORMATION.txt
deleted file mode 100755
index a8b0a6d..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/LICENSE_INFORMATION.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-FreeRTOS+CLI is released under the following MIT license.
-
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/readme.txt
deleted file mode 100755
index 801d535..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/readme.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-Contains source and header files that implement FreeRTOS+CLI. See
-http://www.FreeRTOS.org/cli for documentation and license information.
-
-
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/LinkToDemo.url b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/LinkToDemo.url
deleted file mode 100755
index a7a7a27..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/LinkToDemo.url
+++ /dev/null
@@ -1,5 +0,0 @@
-[InternetShortcut]
-URL=http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_IO/Demo_Applications/LPCXpresso_LPC1769/NXP_LPC1769_Demo_Description.shtml
-IDList=
-[{000214A0-0000-0000-C000-000000000046}]
-Prop3=19,2
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/readme.txt
deleted file mode 100755
index b685d51..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/readme.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-It is not possible to create an example FreeRTOS+IO project for the Windows
-simulator. FreeRTOS+IO information can be found on http://www.FreeRTOS.org/IO.
-
-A featured demo that includes telnet like functionality, a web server,
-a command line interface (using FreeRTOS+CLI) and a FAT file system is
-described on
-http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_IO/Demo_Applications/LPCXpresso_LPC1769/NXP_LPC1769_Demo_Description.shtml
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
deleted file mode 100755
index 0792483..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
+++ /dev/null
@@ -1,653 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_ARP.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_DHCP.h"
-#if( ipconfigUSE_LLMNR == 1 )
- #include "FreeRTOS_DNS.h"
-#endif /* ipconfigUSE_LLMNR */
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-
-
-/* When the age of an entry in the ARP table reaches this value (it counts down
-to zero, so this is an old entry) an ARP request will be sent to see if the
-entry is still valid and can therefore be refreshed. */
-#define arpMAX_ARP_AGE_BEFORE_NEW_ARP_REQUEST ( 3 )
-
-/* The time between gratuitous ARPs. */
-#ifndef arpGRATUITOUS_ARP_PERIOD
- #define arpGRATUITOUS_ARP_PERIOD ( pdMS_TO_TICKS( 20000 ) )
-#endif
-
-/*-----------------------------------------------------------*/
-
-/*
- * Lookup an MAC address in the ARP cache from the IP address.
- */
-static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, MACAddress_t * const pxMACAddress );
-
-/*-----------------------------------------------------------*/
-
-/* The ARP cache. */
-static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ];
-
-/* The time at which the last gratuitous ARP was sent. Gratuitous ARPs are used
-to ensure ARP tables are up to date and to detect IP address conflicts. */
-static TickType_t xLastGratuitousARPTime = ( TickType_t ) 0;
-
-/*
- * IP-clash detection is currently only used internally. When DHCP doesn't respond, the
- * driver can try out a random LinkLayer IP address (169.254.x.x). It will send out a
- * gratuitos ARP message and, after a period of time, check the variables here below:
- */
-#if( ipconfigARP_USE_CLASH_DETECTION != 0 )
- /* Becomes non-zero if another device responded to a gratuitos ARP message. */
- BaseType_t xARPHadIPClash;
- /* MAC-address of the other device containing the same IP-address. */
- MACAddress_t xARPClashMacAddress;
-#endif /* ipconfigARP_USE_CLASH_DETECTION */
-
-/* Part of the Ethernet and ARP headers are always constant when sending an IPv4
-ARP packet. This array defines the constant parts, allowing this part of the
-packet to be filled in using a simple memcpy() instead of individual writes. */
-static const uint8_t xDefaultPartARPPacketHeader[] =
-{
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* Ethernet destination address. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source address. */
- 0x08, 0x06, /* Ethernet frame type (ipARP_FRAME_TYPE). */
- 0x00, 0x01, /* usHardwareType (ipARP_HARDWARE_TYPE_ETHERNET). */
- 0x08, 0x00, /* usProtocolType. */
- ipMAC_ADDRESS_LENGTH_BYTES, /* ucHardwareAddressLength. */
- ipIP_ADDRESS_LENGTH_BYTES, /* ucProtocolAddressLength. */
- 0x00, 0x01, /* usOperation (ipARP_REQUEST). */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* xSenderHardwareAddress. */
- 0x00, 0x00, 0x00, 0x00, /* ulSenderProtocolAddress. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* xTargetHardwareAddress. */
-};
-
-/*-----------------------------------------------------------*/
-
-eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame )
-{
-eFrameProcessingResult_t eReturn = eReleaseBuffer;
-ARPHeader_t *pxARPHeader;
-uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
-
- pxARPHeader = &( pxARPFrame->xARPHeader );
-
- /* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */
- memcpy( ( void *)&( ulSenderProtocolAddress ), ( void * )pxARPHeader->ucSenderProtocolAddress, sizeof( ulSenderProtocolAddress ) );
- /* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */
- ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress;
-
- traceARP_PACKET_RECEIVED();
-
- /* Don't do anything if the local IP address is zero because
- that means a DHCP request has not completed. */
- if( *ipLOCAL_IP_ADDRESS_POINTER != 0UL )
- {
- switch( pxARPHeader->usOperation )
- {
- case ipARP_REQUEST :
- /* The packet contained an ARP request. Was it for the IP
- address of the node running this code? */
- if( ulTargetProtocolAddress == *ipLOCAL_IP_ADDRESS_POINTER )
- {
- iptraceSENDING_ARP_REPLY( ulSenderProtocolAddress );
-
- /* The request is for the address of this node. Add the
- entry into the ARP cache, or refresh the entry if it
- already exists. */
- vARPRefreshCacheEntry( &( pxARPHeader->xSenderHardwareAddress ), ulSenderProtocolAddress );
-
- /* Generate a reply payload in the same buffer. */
- pxARPHeader->usOperation = ( uint16_t ) ipARP_REPLY;
- if( ulTargetProtocolAddress == ulSenderProtocolAddress )
- {
- /* A double IP address is detected! */
- /* Give the sources MAC address the value of the broadcast address, will be swapped later */
- memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) );
- memset( pxARPHeader->xTargetHardwareAddress.ucBytes, '\0', sizeof( MACAddress_t ) );
- pxARPHeader->ulTargetProtocolAddress = 0UL;
- }
- else
- {
- memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) );
- pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress;
- }
- memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
- memcpy( ( void* )pxARPHeader->ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
-
- eReturn = eReturnEthernetFrame;
- }
- break;
-
- case ipARP_REPLY :
- iptracePROCESSING_RECEIVED_ARP_REPLY( ulTargetProtocolAddress );
- vARPRefreshCacheEntry( &( pxARPHeader->xSenderHardwareAddress ), ulSenderProtocolAddress );
- /* Process received ARP frame to see if there is a clash. */
- #if( ipconfigARP_USE_CLASH_DETECTION != 0 )
- {
- if( ulSenderProtocolAddress == *ipLOCAL_IP_ADDRESS_POINTER )
- {
- xARPHadIPClash = pdTRUE;
- memcpy( xARPClashMacAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( xARPClashMacAddress.ucBytes ) );
- }
- }
- #endif /* ipconfigARP_USE_CLASH_DETECTION */
- break;
-
- default :
- /* Invalid. */
- break;
- }
- }
-
- return eReturn;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )
-
- uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress )
- {
- BaseType_t x;
- uint32_t lResult = 0;
-
- /* For each entry in the ARP cache table. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) )
- {
- lResult = xARPCache[ x ].ulIPAddress;
- memset( &xARPCache[ x ], '\0', sizeof( xARPCache[ x ] ) );
- break;
- }
- }
-
- return lResult;
- }
-
-#endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */
-/*-----------------------------------------------------------*/
-
-void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress )
-{
-BaseType_t x = 0;
-BaseType_t xIpEntry = -1;
-BaseType_t xMacEntry = -1;
-BaseType_t xUseEntry = 0;
-uint8_t ucMinAgeFound = 0U;
-
- #if( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 )
- /* Only process the IP address if it is on the local network.
- Unless: when '*ipLOCAL_IP_ADDRESS_POINTER' equals zero, the IP-address
- and netmask are still unknown. */
- if( ( ( ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) ) ||
- ( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ) )
- #else
- /* If ipconfigARP_STORES_REMOTE_ADDRESSES is non-zero, IP addresses with
- a different netmask will also be stored. After when replying to a UDP
- message from a different netmask, the IP address can be looped up and a
- reply sent. This option is useful for systems with multiple gateways,
- the reply will surely arrive. If ipconfigARP_STORES_REMOTE_ADDRESSES is
- zero the the gateway address is the only option. */
- if( pdTRUE )
- #endif
- {
- /* Start with the maximum possible number. */
- ucMinAgeFound--;
-
- /* For each entry in the ARP cache table. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- /* Does this line in the cache table hold an entry for the IP
- address being queried? */
- if( xARPCache[ x ].ulIPAddress == ulIPAddress )
- {
- if( pxMACAddress == NULL )
- {
- /* In case the parameter pxMACAddress is NULL, an entry will be reserved to
- indicate that there is an outstanding ARP request, This entry will have
- "ucValid == pdFALSE". */
- xIpEntry = x;
- break;
- }
-
- /* See if the MAC-address also matches. */
- if( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 )
- {
- /* This function will be called for each received packet
- As this is by far the most common path the coding standard
- is relaxed in this case and a return is permitted as an
- optimisation. */
- xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE;
- xARPCache[ x ].ucValid = ( uint8_t ) pdTRUE;
- return;
- }
-
- /* Found an entry containing ulIPAddress, but the MAC address
- doesn't match. Might be an entry with ucValid=pdFALSE, waiting
- for an ARP reply. Still want to see if there is match with the
- given MAC address.ucBytes. If found, either of the two entries
- must be cleared. */
- xIpEntry = x;
- }
- else if( ( pxMACAddress != NULL ) && ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) )
- {
- /* Found an entry with the given MAC-address, but the IP-address
- is different. Continue looping to find a possible match with
- ulIPAddress. */
- #if( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 )
- /* If ARP stores the MAC address of IP addresses outside the
- network, than the MAC address of the gateway should not be
- overwritten. */
- BaseType_t bIsLocal[ 2 ];
- bIsLocal[ 0 ] = ( ( xARPCache[ x ].ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) );
- bIsLocal[ 1 ] = ( ( ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) );
- if( bIsLocal[ 0 ] == bIsLocal[ 1 ] )
- {
- xMacEntry = x;
- }
- #else
- xMacEntry = x;
- #endif
- }
- /* _HT_
- Shouldn't we test for xARPCache[ x ].ucValid == pdFALSE here ? */
- else if( xARPCache[ x ].ucAge < ucMinAgeFound )
- {
- /* As the table is traversed, remember the table row that
- contains the oldest entry (the lowest age count, as ages are
- decremented to zero) so the row can be re-used if this function
- needs to add an entry that does not already exist. */
- ucMinAgeFound = xARPCache[ x ].ucAge;
- xUseEntry = x;
- }
- }
-
- if( xMacEntry >= 0 )
- {
- xUseEntry = xMacEntry;
-
- if( xIpEntry >= 0 )
- {
- /* Both the MAC address as well as the IP address were found in
- different locations: clear the entry which matches the
- IP-address */
- memset( &xARPCache[ xIpEntry ], '\0', sizeof( xARPCache[ xIpEntry ] ) );
- }
- }
- else if( xIpEntry >= 0 )
- {
- /* An entry containing the IP-address was found, but it had a different MAC address */
- xUseEntry = xIpEntry;
- }
-
- /* If the entry was not found, we use the oldest entry and set the IPaddress */
- xARPCache[ xUseEntry ].ulIPAddress = ulIPAddress;
-
- if( pxMACAddress != NULL )
- {
- memcpy( xARPCache[ xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) );
-
- iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, (*pxMACAddress) );
- /* And this entry does not need immediate attention */
- xARPCache[ xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE;
- xARPCache[ xUseEntry ].ucValid = ( uint8_t ) pdTRUE;
- }
- else if( xIpEntry < 0 )
- {
- xARPCache[ xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_RETRANSMISSIONS;
- xARPCache[ xUseEntry ].ucValid = ( uint8_t ) pdFALSE;
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_ARP_REVERSED_LOOKUP == 1 )
- eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress, uint32_t *pulIPAddress )
- {
- BaseType_t x;
- eARPLookupResult_t eReturn = eARPCacheMiss;
-
- /* Loop through each entry in the ARP cache. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- /* Does this row in the ARP cache table hold an entry for the MAC
- address being searched? */
- if( memcmp( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 )
- {
- *pulIPAddress = xARPCache[ x ].ulIPAddress;
- eReturn = eARPCacheHit;
- break;
- }
- }
-
- return eReturn;
- }
-#endif /* ipconfigUSE_ARP_REVERSED_LOOKUP */
-
-/*-----------------------------------------------------------*/
-
-eARPLookupResult_t eARPGetCacheEntry( uint32_t *pulIPAddress, MACAddress_t * const pxMACAddress )
-{
-eARPLookupResult_t eReturn;
-uint32_t ulAddressToLookup;
-
-#if( ipconfigUSE_LLMNR == 1 )
- if( *pulIPAddress == ipLLMNR_IP_ADDR ) /* Is in network byte order. */
- {
- /* The LLMNR IP-address has a fixed virtual MAC address. */
- memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) );
- eReturn = eARPCacheHit;
- }
- else
-#endif
- if( ( *pulIPAddress == ipBROADCAST_IP_ADDRESS ) || /* Is it the general broadcast address 255.255.255.255? */
- ( *pulIPAddress == xNetworkAddressing.ulBroadcastAddress ) )/* Or a local broadcast address, eg 192.168.1.255? */
- {
- /* This is a broadcast so uses the broadcast MAC address. */
- memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
- eReturn = eARPCacheHit;
- }
- else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
- {
- /* The IP address has not yet been assigned, so there is nothing that
- can be done. */
- eReturn = eCantSendPacket;
- }
- else
- {
- eReturn = eARPCacheMiss;
-
- if( ( *pulIPAddress & xNetworkAddressing.ulNetMask ) != ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) )
- {
-#if( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 )
- eReturn = prvCacheLookup( *pulIPAddress, pxMACAddress );
-
- if( eReturn == eARPCacheHit )
- {
- /* The stack is configured to store 'remote IP addresses', i.e. addresses
- belonging to a different the netmask. prvCacheLookup() returned a hit, so
- the MAC address is known */
- }
- else
-#endif
- {
- /* The IP address is off the local network, so look up the
- hardware address of the router, if any. */
- if( xNetworkAddressing.ulGatewayAddress != ( uint32_t )0u )
- {
- ulAddressToLookup = xNetworkAddressing.ulGatewayAddress;
- }
- else
- {
- ulAddressToLookup = *pulIPAddress;
- }
- }
- }
- else
- {
- /* The IP address is on the local network, so lookup the requested
- IP address directly. */
- ulAddressToLookup = *pulIPAddress;
- }
-
- if( eReturn == eARPCacheMiss )
- {
- if( ulAddressToLookup == 0UL )
- {
- /* The address is not on the local network, and there is not a
- router. */
- eReturn = eCantSendPacket;
- }
- else
- {
- eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress );
-
- if( eReturn == eARPCacheMiss )
- {
- /* It might be that the ARP has to go to the gateway. */
- *pulIPAddress = ulAddressToLookup;
- }
- }
- }
- }
-
- return eReturn;
-}
-
-/*-----------------------------------------------------------*/
-
-static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, MACAddress_t * const pxMACAddress )
-{
-BaseType_t x;
-eARPLookupResult_t eReturn = eARPCacheMiss;
-
- /* Loop through each entry in the ARP cache. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- /* Does this row in the ARP cache table hold an entry for the IP address
- being queried? */
- if( xARPCache[ x ].ulIPAddress == ulAddressToLookup )
- {
- /* A matching valid entry was found. */
- if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE )
- {
- /* This entry is waiting an ARP reply, so is not valid. */
- eReturn = eCantSendPacket;
- }
- else
- {
- /* A valid entry was found. */
- memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) );
- eReturn = eARPCacheHit;
- }
- break;
- }
- }
-
- return eReturn;
-}
-/*-----------------------------------------------------------*/
-
-void vARPAgeCache( void )
-{
-BaseType_t x;
-TickType_t xTimeNow;
-
- /* Loop through each entry in the ARP cache. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- /* If the entry is valid (its age is greater than zero). */
- if( xARPCache[ x ].ucAge > 0U )
- {
- /* Decrement the age value of the entry in this ARP cache table row.
- When the age reaches zero it is no longer considered valid. */
- ( xARPCache[ x ].ucAge )--;
-
- /* If the entry is not yet valid, then it is waiting an ARP
- reply, and the ARP request should be retransmitted. */
- if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE )
- {
- FreeRTOS_OutputARPRequest( xARPCache[ x ].ulIPAddress );
- }
- else if( xARPCache[ x ].ucAge <= ( uint8_t ) arpMAX_ARP_AGE_BEFORE_NEW_ARP_REQUEST )
- {
- /* This entry will get removed soon. See if the MAC address is
- still valid to prevent this happening. */
- iptraceARP_TABLE_ENTRY_WILL_EXPIRE( xARPCache[ x ].ulIPAddress );
- FreeRTOS_OutputARPRequest( xARPCache[ x ].ulIPAddress );
- }
- else
- {
- /* The age has just ticked down, with nothing to do. */
- }
-
- if( xARPCache[ x ].ucAge == 0u )
- {
- /* The entry is no longer valid. Wipe it out. */
- iptraceARP_TABLE_ENTRY_EXPIRED( xARPCache[ x ].ulIPAddress );
- xARPCache[ x ].ulIPAddress = 0UL;
- }
- }
- }
-
- xTimeNow = xTaskGetTickCount ();
-
- if( ( xLastGratuitousARPTime == ( TickType_t ) 0 ) || ( ( xTimeNow - xLastGratuitousARPTime ) > ( TickType_t ) arpGRATUITOUS_ARP_PERIOD ) )
- {
- FreeRTOS_OutputARPRequest( *ipLOCAL_IP_ADDRESS_POINTER );
- xLastGratuitousARPTime = xTimeNow;
- }
-}
-/*-----------------------------------------------------------*/
-
-void vARPSendGratuitous( void )
-{
- /* Setting xLastGratuitousARPTime to 0 will force a gratuitous ARP the next
- time vARPAgeCache() is called. */
- xLastGratuitousARPTime = ( TickType_t ) 0;
-
- /* Let the IP-task call vARPAgeCache(). */
- xSendEventToIPTask( eARPTimerEvent );
-}
-
-/*-----------------------------------------------------------*/
-void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-
- /* This is called from the context of the IP event task, so a block time
- must not be used. */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( ARPPacket_t ), ( TickType_t ) 0 );
-
- if( pxNetworkBuffer != NULL )
- {
- pxNetworkBuffer->ulIPAddress = ulIPAddress;
- vARPGenerateRequestPacket( pxNetworkBuffer );
-
- #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- BaseType_t xIndex;
-
- for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
- {
- pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0u;
- }
- pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
- }
- }
- #endif
-
- xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
- }
-}
-
-void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-ARPPacket_t *pxARPPacket;
-
- pxARPPacket = ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
-
- /* memcpy the const part of the header information into the correct
- location in the packet. This copies:
- xEthernetHeader.ulDestinationAddress
- xEthernetHeader.usFrameType;
- xARPHeader.usHardwareType;
- xARPHeader.usProtocolType;
- xARPHeader.ucHardwareAddressLength;
- xARPHeader.ucProtocolAddressLength;
- xARPHeader.usOperation;
- xARPHeader.xTargetHardwareAddress;
- */
- memcpy( ( void * ) pxARPPacket, ( void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) );
- memcpy( ( void * ) pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
- memcpy( ( void * ) pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
-
- memcpy( ( void* )pxARPPacket->xARPHeader.ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
- pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress;
-
- pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t );
-
- iptraceCREATING_ARP_REQUEST( pxNetworkBuffer->ulIPAddress );
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_ClearARP( void )
-{
- memset( xARPCache, '\0', sizeof( xARPCache ) );
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 )
-
- void FreeRTOS_PrintARPCache( void )
- {
- BaseType_t x, xCount = 0;
-
- /* Loop through each entry in the ARP cache. */
- for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
- {
- if( ( xARPCache[ x ].ulIPAddress != 0ul ) && ( xARPCache[ x ].ucAge > 0U ) )
- {
- /* See if the MAC-address also matches, and we're all happy */
- FreeRTOS_printf( ( "Arp %2ld: %3u - %16lxip : %02x:%02x:%02x : %02x:%02x:%02x\n",
- x,
- xARPCache[ x ].ucAge,
- xARPCache[ x ].ulIPAddress,
- xARPCache[ x ].xMACAddress.ucBytes[0],
- xARPCache[ x ].xMACAddress.ucBytes[1],
- xARPCache[ x ].xMACAddress.ucBytes[2],
- xARPCache[ x ].xMACAddress.ucBytes[3],
- xARPCache[ x ].xMACAddress.ucBytes[4],
- xARPCache[ x ].xMACAddress.ucBytes[5] ) );
- xCount++;
- }
- }
-
- FreeRTOS_printf( ( "Arp has %ld entries\n", xCount ) );
- }
-
-#endif /* ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
deleted file mode 100755
index 8fe04bb..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
+++ /dev/null
@@ -1,1011 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_TCP_IP.h"
-#include "FreeRTOS_DHCP.h"
-#include "FreeRTOS_ARP.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-
-/* Exclude the entire file if DHCP is not enabled. */
-#if( ipconfigUSE_DHCP != 0 )
-
-#if ( ipconfigUSE_DHCP != 0 ) && ( ipconfigNETWORK_MTU < 586u )
- /* DHCP must be able to receive an options field of 312 bytes, the fixed
- part of the DHCP packet is 240 bytes, and the IP/UDP headers take 28 bytes. */
- #error ipconfigNETWORK_MTU needs to be at least 586 to use DHCP
-#endif
-
-/* Parameter widths in the DHCP packet. */
-#define dhcpCLIENT_HARDWARE_ADDRESS_LENGTH 16
-#define dhcpSERVER_HOST_NAME_LENGTH 64
-#define dhcpBOOT_FILE_NAME_LENGTH 128
-
-/* Timer parameters */
-#ifndef dhcpINITIAL_DHCP_TX_PERIOD
- #define dhcpINITIAL_TIMER_PERIOD ( pdMS_TO_TICKS( 250 ) )
- #define dhcpINITIAL_DHCP_TX_PERIOD ( pdMS_TO_TICKS( 5000 ) )
-#endif
-
-/* Codes of interest found in the DHCP options field. */
-#define dhcpZERO_PAD_OPTION_CODE ( 0u )
-#define dhcpSUBNET_MASK_OPTION_CODE ( 1u )
-#define dhcpGATEWAY_OPTION_CODE ( 3u )
-#define dhcpDNS_SERVER_OPTIONS_CODE ( 6u )
-#define dhcpDNS_HOSTNAME_OPTIONS_CODE ( 12u )
-#define dhcpREQUEST_IP_ADDRESS_OPTION_CODE ( 50u )
-#define dhcpLEASE_TIME_OPTION_CODE ( 51u )
-#define dhcpMESSAGE_TYPE_OPTION_CODE ( 53u )
-#define dhcpSERVER_IP_ADDRESS_OPTION_CODE ( 54u )
-#define dhcpPARAMETER_REQUEST_OPTION_CODE ( 55u )
-#define dhcpCLIENT_IDENTIFIER_OPTION_CODE ( 61u )
-
-/* The four DHCP message types of interest. */
-#define dhcpMESSAGE_TYPE_DISCOVER ( 1 )
-#define dhcpMESSAGE_TYPE_OFFER ( 2 )
-#define dhcpMESSAGE_TYPE_REQUEST ( 3 )
-#define dhcpMESSAGE_TYPE_ACK ( 5 )
-#define dhcpMESSAGE_TYPE_NACK ( 6 )
-
-/* Offsets into the transmitted DHCP options fields at which various parameters
-are located. */
-#define dhcpCLIENT_IDENTIFIER_OFFSET ( 5 )
-#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 13 )
-#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 19 )
-
-/* Values used in the DHCP packets. */
-#define dhcpREQUEST_OPCODE ( 1 )
-#define dhcpREPLY_OPCODE ( 2 )
-#define dhcpADDRESS_TYPE_ETHERNET ( 1 )
-#define dhcpETHERNET_ADDRESS_LENGTH ( 6 )
-
-/* If a lease time is not received, use the default of two days. */
-/* 48 hours in ticks. Can not use pdMS_TO_TICKS() as integer overflow can occur. */
-#define dhcpDEFAULT_LEASE_TIME ( ( 48UL * 60UL * 60UL ) * configTICK_RATE_HZ )
-
-/* Don't allow the lease time to be too short. */
-#define dhcpMINIMUM_LEASE_TIME ( pdMS_TO_TICKS( 60000UL ) ) /* 60 seconds in ticks. */
-
-/* Marks the end of the variable length options field in the DHCP packet. */
-#define dhcpOPTION_END_BYTE 0xffu
-
-/* Offset into a DHCP message at which the first byte of the options is
-located. */
-#define dhcpFIRST_OPTION_BYTE_OFFSET ( 0xf0 )
-
-/* When walking the variable length options field, the following value is used
-to ensure the walk has not gone past the end of the valid options. 2 bytes is
-made up of the length byte, and minimum one byte value. */
-#define dhcpMAX_OPTION_LENGTH_OF_INTEREST ( 2L )
-
-/* Standard DHCP port numbers and magic cookie value. */
-#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
- #define dhcpCLIENT_PORT 0x4400u
- #define dhcpSERVER_PORT 0x4300u
- #define dhcpCOOKIE 0x63538263ul
- #define dhcpBROADCAST 0x0080u
-#else
- #define dhcpCLIENT_PORT 0x0044u
- #define dhcpSERVER_PORT 0x0043u
- #define dhcpCOOKIE 0x63825363ul
- #define dhcpBROADCAST 0x8000u
-#endif /* ipconfigBYTE_ORDER */
-
-#include "pack_struct_start.h"
-struct xDHCPMessage
-{
- uint8_t ucOpcode;
- uint8_t ucAddressType;
- uint8_t ucAddressLength;
- uint8_t ucHops;
- uint32_t ulTransactionID;
- uint16_t usElapsedTime;
- uint16_t usFlags;
- uint32_t ulClientIPAddress_ciaddr;
- uint32_t ulYourIPAddress_yiaddr;
- uint32_t ulServerIPAddress_siaddr;
- uint32_t ulRelayAgentIPAddress_giaddr;
- uint8_t ucClientHardwareAddress[ dhcpCLIENT_HARDWARE_ADDRESS_LENGTH ];
- uint8_t ucServerHostName[ dhcpSERVER_HOST_NAME_LENGTH ];
- uint8_t ucBootFileName[ dhcpBOOT_FILE_NAME_LENGTH ];
- uint32_t ulDHCPCookie;
- uint8_t ucFirstOptionByte;
-}
-#include "pack_struct_end.h"
-typedef struct xDHCPMessage DHCPMessage_t;
-
-/* DHCP state machine states. */
-typedef enum
-{
- eWaitingSendFirstDiscover = 0, /* Initial state. Send a discover the first time it is called, and reset all timers. */
- eWaitingOffer, /* Either resend the discover, or, if the offer is forthcoming, send a request. */
- eWaitingAcknowledge, /* Either resend the request. */
- #if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- eGetLinkLayerAddress, /* When DHCP didn't respond, try to obtain a LinkLayer address 168.254.x.x. */
- #endif
- eLeasedAddress, /* Resend the request at the appropriate time to renew the lease. */
- eNotUsingLeasedAddress /* DHCP failed, and a default IP address is being used. */
-} eDHCPState_t;
-
-/* Hold information in between steps in the DHCP state machine. */
-struct xDHCP_DATA
-{
- uint32_t ulTransactionId;
- uint32_t ulOfferedIPAddress;
- uint32_t ulDHCPServerAddress;
- uint32_t ulLeaseTime;
- /* Hold information on the current timer state. */
- TickType_t xDHCPTxTime;
- TickType_t xDHCPTxPeriod;
- /* Try both without and with the broadcast flag */
- BaseType_t xUseBroadcast;
- /* Maintains the DHCP state machine state. */
- eDHCPState_t eDHCPState;
- /* The UDP socket used for all incoming and outgoing DHCP traffic. */
- Socket_t xDHCPSocket;
-};
-
-typedef struct xDHCP_DATA DHCPData_t;
-
-#if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- /* Define the Link Layer IP address: 169.254.x.x */
- #define LINK_LAYER_ADDRESS_0 169
- #define LINK_LAYER_ADDRESS_1 254
-
- /* Define the netmask used: 255.255.0.0 */
- #define LINK_LAYER_NETMASK_0 255
- #define LINK_LAYER_NETMASK_1 255
- #define LINK_LAYER_NETMASK_2 0
- #define LINK_LAYER_NETMASK_3 0
-#endif
-
-
-/*
- * Generate a DHCP discover message and send it on the DHCP socket.
- */
-static void prvSendDHCPDiscover( void );
-
-/*
- * Interpret message received on the DHCP socket.
- */
-static BaseType_t prvProcessDHCPReplies( BaseType_t xExpectedMessageType );
-
-/*
- * Generate a DHCP request packet, and send it on the DHCP socket.
- */
-static void prvSendDHCPRequest( void );
-
-/*
- * Prepare to start a DHCP transaction. This initialises some state variables
- * and creates the DHCP socket if necessary.
- */
-static void prvInitialiseDHCP( void );
-
-/*
- * Creates the part of outgoing DHCP messages that are common to all outgoing
- * DHCP messages.
- */
-static uint8_t *prvCreatePartDHCPMessage( struct freertos_sockaddr *pxAddress, BaseType_t xOpcode, const uint8_t * const pucOptionsArray, size_t *pxOptionsArraySize );
-
-/*
- * Create the DHCP socket, if it has not been created already.
- */
-static void prvCreateDHCPSocket( void );
-
-/*
- * After DHCP has failed to answer, prepare everything to start searching
- * for (trying-out) LinkLayer IP-addresses, using the random method: Send
- * a gratuitous ARP request and wait if another device responds to it.
- */
-#if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- static void prvPrepareLinkLayerIPLookUp( void );
-#endif
-
-/*-----------------------------------------------------------*/
-
-/* The next DHCP transaction Id to be used. */
-static DHCPData_t xDHCPData;
-
-/*-----------------------------------------------------------*/
-
-BaseType_t xIsDHCPSocket( Socket_t xSocket )
-{
-BaseType_t xReturn;
-
- if( xDHCPData.xDHCPSocket == xSocket )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-void vDHCPProcess( BaseType_t xReset )
-{
-BaseType_t xGivingUp = pdFALSE;
-#if( ipconfigUSE_DHCP_HOOK != 0 )
- eDHCPCallbackAnswer_t eAnswer;
-#endif /* ipconfigUSE_DHCP_HOOK */
-
- /* Is DHCP starting over? */
- if( xReset != pdFALSE )
- {
- xDHCPData.eDHCPState = eWaitingSendFirstDiscover;
- }
-
- switch( xDHCPData.eDHCPState )
- {
- case eWaitingSendFirstDiscover :
- /* Ask the user if a DHCP discovery is required. */
- #if( ipconfigUSE_DHCP_HOOK != 0 )
- eAnswer = xApplicationDHCPHook( eDHCPPhasePreDiscover, xNetworkAddressing.ulDefaultIPAddress );
- if( eAnswer == eDHCPContinue )
- #endif /* ipconfigUSE_DHCP_HOOK */
- {
- /* Initial state. Create the DHCP socket, timer, etc. if they
- have not already been created. */
- prvInitialiseDHCP();
-
- /* See if prvInitialiseDHCP() has creates a socket. */
- if( xDHCPData.xDHCPSocket == NULL )
- {
- xGivingUp = pdTRUE;
- break;
- }
-
- *ipLOCAL_IP_ADDRESS_POINTER = 0UL;
-
- /* Send the first discover request. */
- if( xDHCPData.xDHCPSocket != NULL )
- {
- xDHCPData.xDHCPTxTime = xTaskGetTickCount();
- prvSendDHCPDiscover( );
- xDHCPData.eDHCPState = eWaitingOffer;
- }
- }
- #if( ipconfigUSE_DHCP_HOOK != 0 )
- else
- {
- if( eAnswer == eDHCPUseDefaults )
- {
- memcpy( &xNetworkAddressing, &xDefaultAddressing, sizeof( xNetworkAddressing ) );
- }
-
- /* The user indicates that the DHCP process does not continue. */
- xGivingUp = pdTRUE;
- }
- #endif /* ipconfigUSE_DHCP_HOOK */
- break;
-
- case eWaitingOffer :
-
- xGivingUp = pdFALSE;
-
- /* Look for offers coming in. */
- if( prvProcessDHCPReplies( dhcpMESSAGE_TYPE_OFFER ) == pdPASS )
- {
- #if( ipconfigUSE_DHCP_HOOK != 0 )
- /* Ask the user if a DHCP request is required. */
- eAnswer = xApplicationDHCPHook( eDHCPPhasePreRequest, xDHCPData.ulOfferedIPAddress );
-
- if( eAnswer == eDHCPContinue )
- #endif /* ipconfigUSE_DHCP_HOOK */
- {
- /* An offer has been made, the user wants to continue,
- generate the request. */
- xDHCPData.xDHCPTxTime = xTaskGetTickCount();
- xDHCPData.xDHCPTxPeriod = dhcpINITIAL_DHCP_TX_PERIOD;
- prvSendDHCPRequest( );
- xDHCPData.eDHCPState = eWaitingAcknowledge;
- break;
- }
-
- #if( ipconfigUSE_DHCP_HOOK != 0 )
- if( eAnswer == eDHCPUseDefaults )
- {
- memcpy( &xNetworkAddressing, &xDefaultAddressing, sizeof( xNetworkAddressing ) );
- }
-
- /* The user indicates that the DHCP process does not continue. */
- xGivingUp = pdTRUE;
- #endif /* ipconfigUSE_DHCP_HOOK */
- }
- else if( ( xTaskGetTickCount() - xDHCPData.xDHCPTxTime ) > xDHCPData.xDHCPTxPeriod )
- {
- /* It is time to send another Discover. Increase the time
- period, and if it has not got to the point of giving up - send
- another discovery. */
- xDHCPData.xDHCPTxPeriod <<= 1;
-
- if( xDHCPData.xDHCPTxPeriod <= ipconfigMAXIMUM_DISCOVER_TX_PERIOD )
- {
- xDHCPData.ulTransactionId = ipconfigRAND32( );
-
- if( 0 != xDHCPData.ulTransactionId )
- {
- xDHCPData.xDHCPTxTime = xTaskGetTickCount( );
- xDHCPData.xUseBroadcast = !xDHCPData.xUseBroadcast;
- prvSendDHCPDiscover( );
- FreeRTOS_debug_printf( ( "vDHCPProcess: timeout %lu ticks\n", xDHCPData.xDHCPTxPeriod ) );
- }
- else
- {
- FreeRTOS_debug_printf( ( "vDHCPProcess: failed to generate a random Transaction ID\n" ) );
- }
- }
- else
- {
- FreeRTOS_debug_printf( ( "vDHCPProcess: giving up %lu > %lu ticks\n", xDHCPData.xDHCPTxPeriod, ipconfigMAXIMUM_DISCOVER_TX_PERIOD ) );
-
- #if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- {
- /* Only use a fake Ack if the default IP address == 0x00
- and the link local addressing is used. Start searching
- a free LinkLayer IP-address. Next state will be
- 'eGetLinkLayerAddress'. */
- prvPrepareLinkLayerIPLookUp();
-
- /* Setting an IP address manually so set to not using
- leased address mode. */
- xDHCPData.eDHCPState = eGetLinkLayerAddress;
- }
- #else
- {
- xGivingUp = pdTRUE;
- }
- #endif /* ipconfigDHCP_FALL_BACK_AUTO_IP */
- }
- }
- break;
-
- case eWaitingAcknowledge :
-
- /* Look for acks coming in. */
- if( prvProcessDHCPReplies( dhcpMESSAGE_TYPE_ACK ) == pdPASS )
- {
- FreeRTOS_debug_printf( ( "vDHCPProcess: acked %lxip\n", FreeRTOS_ntohl( xDHCPData.ulOfferedIPAddress ) ) );
-
- /* DHCP completed. The IP address can now be used, and the
- timer set to the lease timeout time. */
- *ipLOCAL_IP_ADDRESS_POINTER = xDHCPData.ulOfferedIPAddress;
-
- /* Setting the 'local' broadcast address, something like
- '192.168.1.255'. */
- xNetworkAddressing.ulBroadcastAddress = ( xDHCPData.ulOfferedIPAddress & xNetworkAddressing.ulNetMask ) | ~xNetworkAddressing.ulNetMask;
- xDHCPData.eDHCPState = eLeasedAddress;
-
- iptraceDHCP_SUCCEDEED( xDHCPData.ulOfferedIPAddress );
-
- /* DHCP failed, the default configured IP-address will be used
- Now call vIPNetworkUpCalls() to send the network-up event and
- start the ARP timer. */
- vIPNetworkUpCalls( );
-
- /* Close socket to ensure packets don't queue on it. */
- vSocketClose( xDHCPData.xDHCPSocket );
- xDHCPData.xDHCPSocket = NULL;
-
- if( xDHCPData.ulLeaseTime == 0UL )
- {
- xDHCPData.ulLeaseTime = dhcpDEFAULT_LEASE_TIME;
- }
- else if( xDHCPData.ulLeaseTime < dhcpMINIMUM_LEASE_TIME )
- {
- xDHCPData.ulLeaseTime = dhcpMINIMUM_LEASE_TIME;
- }
- else
- {
- /* The lease time is already valid. */
- }
-
- /* Check for clashes. */
- vARPSendGratuitous();
- vIPReloadDHCPTimer( xDHCPData.ulLeaseTime );
- }
- else
- {
- /* Is it time to send another Discover? */
- if( ( xTaskGetTickCount() - xDHCPData.xDHCPTxTime ) > xDHCPData.xDHCPTxPeriod )
- {
- /* Increase the time period, and if it has not got to the
- point of giving up - send another request. */
- xDHCPData.xDHCPTxPeriod <<= 1;
-
- if( xDHCPData.xDHCPTxPeriod <= ipconfigMAXIMUM_DISCOVER_TX_PERIOD )
- {
- xDHCPData.xDHCPTxTime = xTaskGetTickCount();
- prvSendDHCPRequest( );
- }
- else
- {
- /* Give up, start again. */
- xDHCPData.eDHCPState = eWaitingSendFirstDiscover;
- }
- }
- }
- break;
-
- #if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- case eGetLinkLayerAddress:
- if( ( xTaskGetTickCount() - xDHCPData.xDHCPTxTime ) > xDHCPData.xDHCPTxPeriod )
- {
- if( xARPHadIPClash == pdFALSE )
- {
- /* ARP OK. proceed. */
- iptraceDHCP_SUCCEDEED( xDHCPData.ulOfferedIPAddress );
-
- /* Auto-IP succeeded, the default configured IP-address will
- be used. Now call vIPNetworkUpCalls() to send the
- network-up event and start the ARP timer. */
- vIPNetworkUpCalls( );
- xDHCPData.eDHCPState = eNotUsingLeasedAddress;
- }
- else
- {
- /* ARP clashed - try another IP address. */
- prvPrepareLinkLayerIPLookUp();
-
- /* Setting an IP address manually so set to not using leased
- address mode. */
- xDHCPData.eDHCPState = eGetLinkLayerAddress;
- }
- }
- break;
- #endif /* ipconfigDHCP_FALL_BACK_AUTO_IP */
-
- case eLeasedAddress :
-
- /* Resend the request at the appropriate time to renew the lease. */
- prvCreateDHCPSocket();
-
- if( xDHCPData.xDHCPSocket != NULL )
- {
- xDHCPData.xDHCPTxTime = xTaskGetTickCount();
- xDHCPData.xDHCPTxPeriod = dhcpINITIAL_DHCP_TX_PERIOD;
- prvSendDHCPRequest( );
- xDHCPData.eDHCPState = eWaitingAcknowledge;
-
- /* From now on, we should be called more often */
- vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD );
- }
- break;
-
- case eNotUsingLeasedAddress:
-
- vIPSetDHCPTimerEnableState( pdFALSE );
- break;
-
- default:
- break;
- }
-
- if( xGivingUp != pdFALSE )
- {
- /* xGivingUp became true either because of a time-out, or because
- xApplicationDHCPHook() returned another value than 'eDHCPContinue',
- meaning that the conversion is canceled from here. */
-
- /* Revert to static IP address. */
- taskENTER_CRITICAL();
- {
- *ipLOCAL_IP_ADDRESS_POINTER = xNetworkAddressing.ulDefaultIPAddress;
- iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS( xNetworkAddressing.ulDefaultIPAddress );
- }
- taskEXIT_CRITICAL();
-
- xDHCPData.eDHCPState = eNotUsingLeasedAddress;
- vIPSetDHCPTimerEnableState( pdFALSE );
-
- /* DHCP failed, the default configured IP-address will be used. Now
- call vIPNetworkUpCalls() to send the network-up event and start the ARP
- timer. */
- vIPNetworkUpCalls( );
-
- /* Test if socket was indeed created. */
- if( xDHCPData.xDHCPSocket != NULL )
- {
- /* Close socket to ensure packets don't queue on it. */
- vSocketClose( xDHCPData.xDHCPSocket );
- xDHCPData.xDHCPSocket = NULL;
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvCreateDHCPSocket( void )
-{
-struct freertos_sockaddr xAddress;
-BaseType_t xReturn;
-TickType_t xTimeoutTime = ( TickType_t ) 0;
-
- /* Create the socket, if it has not already been created. */
- if( xDHCPData.xDHCPSocket == NULL )
- {
- xDHCPData.xDHCPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
- if( xDHCPData.xDHCPSocket != FREERTOS_INVALID_SOCKET )
- {
-
- /* Ensure the Rx and Tx timeouts are zero as the DHCP executes in the
- context of the IP task. */
- FreeRTOS_setsockopt( xDHCPData.xDHCPSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xTimeoutTime, sizeof( TickType_t ) );
- FreeRTOS_setsockopt( xDHCPData.xDHCPSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xTimeoutTime, sizeof( TickType_t ) );
-
- /* Bind to the standard DHCP client port. */
- xAddress.sin_port = ( uint16_t ) dhcpCLIENT_PORT;
- xReturn = vSocketBind( xDHCPData.xDHCPSocket, &xAddress, sizeof( xAddress ), pdFALSE );
- if( xReturn != 0 )
- {
- /* Binding failed, close the socket again. */
- vSocketClose( xDHCPData.xDHCPSocket );
- xDHCPData.xDHCPSocket = NULL;
- }
- }
- else
- {
- /* Change to NULL for easier testing. */
- xDHCPData.xDHCPSocket = NULL;
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvInitialiseDHCP( void )
-{
- /* Initialise the parameters that will be set by the DHCP process. Per
- https://www.ietf.org/rfc/rfc2131.txt, Transaction ID should be a random
- value chosen by the client. */
- xDHCPData.ulTransactionId = ipconfigRAND32();
-
- /* Check for random number generator API failure. */
- if( 0 != xDHCPData.ulTransactionId )
- {
- xDHCPData.xUseBroadcast = 0;
- xDHCPData.ulOfferedIPAddress = 0UL;
- xDHCPData.ulDHCPServerAddress = 0UL;
- xDHCPData.xDHCPTxPeriod = dhcpINITIAL_DHCP_TX_PERIOD;
-
- /* Create the DHCP socket if it has not already been created. */
- prvCreateDHCPSocket();
- FreeRTOS_debug_printf( ( "prvInitialiseDHCP: start after %lu ticks\n", dhcpINITIAL_TIMER_PERIOD ) );
- vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD );
- }
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvProcessDHCPReplies( BaseType_t xExpectedMessageType )
-{
-uint8_t *pucUDPPayload, *pucLastByte;
-struct freertos_sockaddr xClient;
-uint32_t xClientLength = sizeof( xClient );
-int32_t lBytes;
-DHCPMessage_t *pxDHCPMessage;
-uint8_t *pucByte, ucOptionCode, ucLength;
-uint32_t ulProcessed, ulParameter;
-BaseType_t xReturn = pdFALSE;
-const uint32_t ulMandatoryOptions = 2ul; /* DHCP server address, and the correct DHCP message type must be present in the options. */
-
- lBytes = FreeRTOS_recvfrom( xDHCPData.xDHCPSocket, ( void * ) &pucUDPPayload, 0ul, FREERTOS_ZERO_COPY, &xClient, &xClientLength );
-
- if( lBytes > 0 )
- {
- /* Map a DHCP structure onto the received data. */
- pxDHCPMessage = ( DHCPMessage_t * ) ( pucUDPPayload );
-
- /* Sanity check. */
- if( ( lBytes >= sizeof( DHCPMessage_t ) ) &&
- ( pxDHCPMessage->ulDHCPCookie == ( uint32_t ) dhcpCOOKIE ) &&
- ( pxDHCPMessage->ucOpcode == ( uint8_t ) dhcpREPLY_OPCODE ) &&
- ( pxDHCPMessage->ulTransactionID == FreeRTOS_htonl( xDHCPData.ulTransactionId ) ) )
- {
- if( memcmp( ( void * ) &( pxDHCPMessage->ucClientHardwareAddress ),
- ( void * ) ipLOCAL_MAC_ADDRESS,
- sizeof( MACAddress_t ) ) == 0 )
- {
- /* None of the essential options have been processed yet. */
- ulProcessed = 0ul;
-
- /* Walk through the options until the dhcpOPTION_END_BYTE byte
- is found, taking care not to walk off the end of the options. */
- pucByte = &( pxDHCPMessage->ucFirstOptionByte );
- pucLastByte = &( pucUDPPayload[ lBytes - dhcpMAX_OPTION_LENGTH_OF_INTEREST ] );
-
- while( pucByte < pucLastByte )
- {
- ucOptionCode = pucByte[ 0 ];
- if( ucOptionCode == dhcpOPTION_END_BYTE )
- {
- /* Ready, the last byte has been seen. */
- break;
- }
- if( ucOptionCode == dhcpZERO_PAD_OPTION_CODE )
- {
- /* The value zero is used as a pad byte,
- it is not followed by a length byte. */
- pucByte += 1;
- continue;
- }
-
- /* Stop if the response is malformed. */
- if( pucByte < pucLastByte - 1 )
- {
- ucLength = pucByte[ 1 ];
- pucByte += 2;
-
- if( pucByte >= pucLastByte - ucLength )
- {
- break;
- }
- }
- else
- {
- break;
- }
-
- /* In most cases, a 4-byte network-endian parameter follows,
- just get it once here and use later. */
- if( ucLength >= sizeof( ulParameter ) )
- {
- memcpy( ( void * ) &( ulParameter ),
- ( void * ) pucByte,
- ( size_t ) sizeof( ulParameter ) );
- }
- else
- {
- ulParameter = 0;
- }
-
- /* Option-specific handling. */
- switch( ucOptionCode )
- {
- case dhcpMESSAGE_TYPE_OPTION_CODE :
-
- if( *pucByte == ( uint8_t ) xExpectedMessageType )
- {
- /* The message type is the message type the
- state machine is expecting. */
- ulProcessed++;
- }
- else if( *pucByte == ( uint8_t ) dhcpMESSAGE_TYPE_NACK )
- {
- if( xExpectedMessageType == ( BaseType_t ) dhcpMESSAGE_TYPE_ACK )
- {
- /* Start again. */
- xDHCPData.eDHCPState = eWaitingSendFirstDiscover;
- }
- }
- else
- {
- /* Don't process other message types. */
- }
- break;
-
- case dhcpSUBNET_MASK_OPTION_CODE :
-
- if( ucLength == sizeof( uint32_t ) )
- {
- xNetworkAddressing.ulNetMask = ulParameter;
- }
- break;
-
- case dhcpGATEWAY_OPTION_CODE :
-
- if( ucLength == sizeof( uint32_t ) )
- {
- /* ulProcessed is not incremented in this case
- because the gateway is not essential. */
- xNetworkAddressing.ulGatewayAddress = ulParameter;
- }
- break;
-
- case dhcpDNS_SERVER_OPTIONS_CODE :
-
- /* ulProcessed is not incremented in this case
- because the DNS server is not essential. Only the
- first DNS server address is taken. */
- xNetworkAddressing.ulDNSServerAddress = ulParameter;
- break;
-
- case dhcpSERVER_IP_ADDRESS_OPTION_CODE :
-
- if( ucLength == sizeof( uint32_t ) )
- {
- if( xExpectedMessageType == ( BaseType_t ) dhcpMESSAGE_TYPE_OFFER )
- {
- /* Offers state the replying server. */
- ulProcessed++;
- xDHCPData.ulDHCPServerAddress = ulParameter;
- }
- else
- {
- /* The ack must come from the expected server. */
- if( xDHCPData.ulDHCPServerAddress == ulParameter )
- {
- ulProcessed++;
- }
- }
- }
- break;
-
- case dhcpLEASE_TIME_OPTION_CODE :
-
- if( ucLength == sizeof( xDHCPData.ulLeaseTime ) )
- {
- /* ulProcessed is not incremented in this case
- because the lease time is not essential. */
- /* The DHCP parameter is in seconds, convert
- to host-endian format. */
- xDHCPData.ulLeaseTime = FreeRTOS_ntohl( ulParameter );
-
- /* Divide the lease time by two to ensure a
- renew request is sent before the lease actually
- expires. */
- xDHCPData.ulLeaseTime >>= 1UL;
-
- /* Multiply with configTICK_RATE_HZ to get clock
- ticks. */
- xDHCPData.ulLeaseTime = configTICK_RATE_HZ * xDHCPData.ulLeaseTime;
- }
- break;
-
- default :
-
- /* Not interested in this field. */
-
- break;
- }
-
- /* Jump over the data to find the next option code. */
- if( ucLength == 0u )
- {
- break;
- }
- else
- {
- pucByte += ucLength;
- }
- }
-
- /* Were all the mandatory options received? */
- if( ulProcessed >= ulMandatoryOptions )
- {
- /* HT:endian: used to be network order */
- xDHCPData.ulOfferedIPAddress = pxDHCPMessage->ulYourIPAddress_yiaddr;
- FreeRTOS_printf( ( "vDHCPProcess: offer %lxip\n", FreeRTOS_ntohl( xDHCPData.ulOfferedIPAddress ) ) );
- xReturn = pdPASS;
- }
- }
- }
-
- FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayload );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static uint8_t *prvCreatePartDHCPMessage( struct freertos_sockaddr *pxAddress, BaseType_t xOpcode, const uint8_t * const pucOptionsArray, size_t *pxOptionsArraySize )
-{
-DHCPMessage_t *pxDHCPMessage;
-size_t xRequiredBufferSize = sizeof( DHCPMessage_t ) + *pxOptionsArraySize;
-uint8_t *pucUDPPayloadBuffer;
-
-#if( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
- const char *pucHostName = pcApplicationHostnameHook ();
- size_t xNameLength = strlen( pucHostName );
- uint8_t *pucPtr;
-
- xRequiredBufferSize += ( 2 + xNameLength );
-#endif
-
- /* Get a buffer. This uses a maximum delay, but the delay will be capped
- to ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS so the return value still needs to
- be test. */
- do
- {
- } while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xRequiredBufferSize, portMAX_DELAY ) ) == NULL );
-
- pxDHCPMessage = ( DHCPMessage_t * ) pucUDPPayloadBuffer;
-
- /* Most fields need to be zero. */
- memset( ( void * ) pxDHCPMessage, 0x00, sizeof( DHCPMessage_t ) );
-
- /* Create the message. */
- pxDHCPMessage->ucOpcode = ( uint8_t ) xOpcode;
- pxDHCPMessage->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
- pxDHCPMessage->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
- pxDHCPMessage->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
- pxDHCPMessage->ulDHCPCookie = ( uint32_t ) dhcpCOOKIE;
- if( xDHCPData.xUseBroadcast != pdFALSE )
- {
- pxDHCPMessage->usFlags = ( uint16_t ) dhcpBROADCAST;
- }
- else
- {
- pxDHCPMessage->usFlags = 0u;
- }
-
- memcpy( ( void * ) &( pxDHCPMessage->ucClientHardwareAddress[ 0 ] ), ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
-
- /* Copy in the const part of the options options. */
- memcpy( ( void * ) &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET ] ), ( void * ) pucOptionsArray, *pxOptionsArraySize );
-
- #if( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
- {
- /* With this option, the hostname can be registered as well which makes
- it easier to lookup a device in a router's list of DHCP clients. */
-
- /* Point to where the OPTION_END was stored to add data. */
- pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1 ) ] );
- pucPtr[ 0 ] = dhcpDNS_HOSTNAME_OPTIONS_CODE;
- pucPtr[ 1 ] = ( uint8_t ) xNameLength;
- memcpy( ( void *) ( pucPtr + 2 ), pucHostName, xNameLength );
- pucPtr[ 2 + xNameLength ] = dhcpOPTION_END_BYTE;
- *pxOptionsArraySize += ( 2 + xNameLength );
- }
- #endif
-
- /* Map in the client identifier. */
- memcpy( ( void * ) &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpCLIENT_IDENTIFIER_OFFSET ] ),
- ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
-
- /* Set the addressing. */
- pxAddress->sin_addr = ipBROADCAST_IP_ADDRESS;
- pxAddress->sin_port = ( uint16_t ) dhcpSERVER_PORT;
-
- return pucUDPPayloadBuffer;
-}
-/*-----------------------------------------------------------*/
-
-static void prvSendDHCPRequest( void )
-{
-uint8_t *pucUDPPayloadBuffer;
-struct freertos_sockaddr xAddress;
-static const uint8_t ucDHCPRequestOptions[] =
-{
- /* Do not change the ordering without also changing
- dhcpCLIENT_IDENTIFIER_OFFSET, dhcpREQUESTED_IP_ADDRESS_OFFSET and
- dhcpDHCP_SERVER_IP_ADDRESS_OFFSET. */
- dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_REQUEST, /* Message type option. */
- dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */
- dhcpREQUEST_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address being requested. */
- dhcpSERVER_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address of the DHCP server. */
- dhcpOPTION_END_BYTE
-};
-size_t xOptionsLength = sizeof( ucDHCPRequestOptions );
-
- pucUDPPayloadBuffer = prvCreatePartDHCPMessage( &xAddress, dhcpREQUEST_OPCODE, ucDHCPRequestOptions, &xOptionsLength );
-
- /* Copy in the IP address being requested. */
- memcpy( ( void * ) &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ] ),
- ( void * ) &( xDHCPData.ulOfferedIPAddress ), sizeof( xDHCPData.ulOfferedIPAddress ) );
-
- /* Copy in the address of the DHCP server being used. */
- memcpy( ( void * ) &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ] ),
- ( void * ) &( xDHCPData.ulDHCPServerAddress ), sizeof( xDHCPData.ulDHCPServerAddress ) );
-
- FreeRTOS_debug_printf( ( "vDHCPProcess: reply %lxip\n", FreeRTOS_ntohl( xDHCPData.ulOfferedIPAddress ) ) );
- iptraceSENDING_DHCP_REQUEST();
-
- if( FreeRTOS_sendto( xDHCPData.xDHCPSocket, pucUDPPayloadBuffer, ( sizeof( DHCPMessage_t ) + xOptionsLength ), FREERTOS_ZERO_COPY, &xAddress, sizeof( xAddress ) ) == 0 )
- {
- /* The packet was not successfully queued for sending and must be
- returned to the stack. */
- FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvSendDHCPDiscover( void )
-{
-uint8_t *pucUDPPayloadBuffer;
-struct freertos_sockaddr xAddress;
-static const uint8_t ucDHCPDiscoverOptions[] =
-{
- /* Do not change the ordering without also changing dhcpCLIENT_IDENTIFIER_OFFSET. */
- dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_DISCOVER, /* Message type option. */
- dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */
- dhcpPARAMETER_REQUEST_OPTION_CODE, 3, dhcpSUBNET_MASK_OPTION_CODE, dhcpGATEWAY_OPTION_CODE, dhcpDNS_SERVER_OPTIONS_CODE, /* Parameter request option. */
- dhcpOPTION_END_BYTE
-};
-size_t xOptionsLength = sizeof( ucDHCPDiscoverOptions );
-
- pucUDPPayloadBuffer = prvCreatePartDHCPMessage( &xAddress, dhcpREQUEST_OPCODE, ucDHCPDiscoverOptions, &xOptionsLength );
-
- FreeRTOS_debug_printf( ( "vDHCPProcess: discover\n" ) );
- iptraceSENDING_DHCP_DISCOVER();
-
- if( FreeRTOS_sendto( xDHCPData.xDHCPSocket, pucUDPPayloadBuffer, ( sizeof( DHCPMessage_t ) + xOptionsLength ), FREERTOS_ZERO_COPY, &xAddress, sizeof( xAddress ) ) == 0 )
- {
- /* The packet was not successfully queued for sending and must be
- returned to the stack. */
- FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
- }
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
-
- static void prvPrepareLinkLayerIPLookUp( void )
- {
- uint8_t ucLinkLayerIPAddress[ 2 ];
-
- /* After DHCP has failed to answer, prepare everything to start
- trying-out LinkLayer IP-addresses, using the random method. */
- xDHCPData.xDHCPTxTime = xTaskGetTickCount();
-
- ucLinkLayerIPAddress[ 0 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */
- ucLinkLayerIPAddress[ 1 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 4th byte of IP address to try. */
-
- xNetworkAddressing.ulGatewayAddress = FreeRTOS_htonl( 0xA9FE0203 );
-
- /* prepare xDHCPData with data to test. */
- xDHCPData.ulOfferedIPAddress =
- FreeRTOS_inet_addr_quick( LINK_LAYER_ADDRESS_0, LINK_LAYER_ADDRESS_1, ucLinkLayerIPAddress[ 0 ], ucLinkLayerIPAddress[ 1 ] );
-
- xDHCPData.ulLeaseTime = dhcpDEFAULT_LEASE_TIME; /* don't care about lease time. just put anything. */
-
- xNetworkAddressing.ulNetMask =
- FreeRTOS_inet_addr_quick( LINK_LAYER_NETMASK_0, LINK_LAYER_NETMASK_1, LINK_LAYER_NETMASK_2, LINK_LAYER_NETMASK_3 );
-
- /* DHCP completed. The IP address can now be used, and the
- timer set to the lease timeout time. */
- *ipLOCAL_IP_ADDRESS_POINTER = xDHCPData.ulOfferedIPAddress;
-
- /* Setting the 'local' broadcast address, something like 192.168.1.255' */
- xNetworkAddressing.ulBroadcastAddress = ( xDHCPData.ulOfferedIPAddress & xNetworkAddressing.ulNetMask ) | ~xNetworkAddressing.ulNetMask;
-
- /* Close socket to ensure packets don't queue on it. not needed anymore as DHCP failed. but still need timer for ARP testing. */
- vSocketClose( xDHCPData.xDHCPSocket );
- xDHCPData.xDHCPSocket = NULL;
- xDHCPData.xDHCPTxPeriod = pdMS_TO_TICKS( 3000ul + ( ipconfigRAND32() & 0x3fful ) ); /* do ARP test every (3 + 0-1024mS) seconds. */
-
- xARPHadIPClash = pdFALSE; /* reset flag that shows if have ARP clash. */
- vARPSendGratuitous();
- }
-
-#endif /* ipconfigDHCP_FALL_BACK_AUTO_IP */
-/*-----------------------------------------------------------*/
-
-#endif /* ipconfigUSE_DHCP != 0 */
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
deleted file mode 100755
index bb76b40..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
+++ /dev/null
@@ -1,1424 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "list.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_DNS.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-#include "IPTraceMacroDefaults.h"
-
-/* Exclude the entire file if DNS is not enabled. */
-#if( ipconfigUSE_DNS != 0 )
-
-#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
- #define dnsDNS_PORT 0x3500
- #define dnsONE_QUESTION 0x0100
- #define dnsOUTGOING_FLAGS 0x0001 /* Standard query. */
- #define dnsRX_FLAGS_MASK 0x0f80 /* The bits of interest in the flags field of incoming DNS messages. */
- #define dnsEXPECTED_RX_FLAGS 0x0080 /* Should be a response, without any errors. */
-#else
- #define dnsDNS_PORT 0x0035
- #define dnsONE_QUESTION 0x0001
- #define dnsOUTGOING_FLAGS 0x0100 /* Standard query. */
- #define dnsRX_FLAGS_MASK 0x800f /* The bits of interest in the flags field of incoming DNS messages. */
- #define dnsEXPECTED_RX_FLAGS 0x8000 /* Should be a response, without any errors. */
-
-#endif /* ipconfigBYTE_ORDER */
-
-/* The maximum number of times a DNS request should be sent out if a response
-is not received, before giving up. */
-#ifndef ipconfigDNS_REQUEST_ATTEMPTS
- #define ipconfigDNS_REQUEST_ATTEMPTS 5
-#endif
-
-/* If the top two bits in the first character of a name field are set then the
-name field is an offset to the string, rather than the string itself. */
-#define dnsNAME_IS_OFFSET ( ( uint8_t ) 0xc0 )
-
-/* NBNS flags. */
-#define dnsNBNS_FLAGS_RESPONSE 0x8000
-#define dnsNBNS_FLAGS_OPCODE_MASK 0x7800
-#define dnsNBNS_FLAGS_OPCODE_QUERY 0x0000
-#define dnsNBNS_FLAGS_OPCODE_REGISTRATION 0x2800
-
-/* Host types. */
-#define dnsTYPE_A_HOST 0x01
-#define dnsCLASS_IN 0x01
-
-/* LLMNR constants. */
-#define dnsLLMNR_TTL_VALUE 300000
-#define dnsLLMNR_FLAGS_IS_REPONSE 0x8000
-
-/* NBNS constants. */
-#define dnsNBNS_TTL_VALUE 3600 /* 1 hour valid */
-#define dnsNBNS_TYPE_NET_BIOS 0x0020
-#define dnsNBNS_CLASS_IN 0x01
-#define dnsNBNS_NAME_FLAGS 0x6000
-#define dnsNBNS_ENCODED_NAME_LENGTH 32
-
-/* If the queried NBNS name matches with the device's name,
-the query will be responded to with these flags: */
-#define dnsNBNS_QUERY_RESPONSE_FLAGS ( 0x8500 )
-
-/* Flag DNS parsing errors in situations where an IPv4 address is the return
-type. */
-#define dnsPARSE_ERROR 0UL
-
-/*
- * Create a socket and bind it to the standard DNS port number. Return the
- * the created socket - or NULL if the socket could not be created or bound.
- */
-static Socket_t prvCreateDNSSocket( void );
-
-/*
- * Create the DNS message in the zero copy buffer passed in the first parameter.
- */
-static size_t prvCreateDNSMessage( uint8_t *pucUDPPayloadBuffer, const char *pcHostName, TickType_t xIdentifier );
-
-/*
- * Simple routine that jumps over the NAME field of a resource record.
- */
-static uint8_t *prvSkipNameField( uint8_t *pucByte, size_t xSourceLen );
-
-/*
- * Process a response packet from a DNS server.
- */
-static uint32_t prvParseDNSReply( uint8_t *pucUDPPayloadBuffer, size_t xBufferLength, TickType_t xIdentifier );
-
-/*
- * Prepare and send a message to a DNS server. 'xReadTimeOut_ms' will be passed as
- * zero, in case the user has supplied a call-back function.
- */
-static uint32_t prvGetHostByName( const char *pcHostName, TickType_t xIdentifier, TickType_t xReadTimeOut_ms );
-
-/*
- * The NBNS and the LLMNR protocol share this reply function.
- */
-#if( ( ipconfigUSE_NBNS == 1 ) || ( ipconfigUSE_LLMNR == 1 ) )
- static void prvReplyDNSMessage( NetworkBufferDescriptor_t *pxNetworkBuffer, BaseType_t lNetLength );
-#endif
-
-#if( ipconfigUSE_NBNS == 1 )
- static portINLINE void prvTreatNBNS( uint8_t *pucUDPPayloadBuffer, size_t xBufferLength, uint32_t ulIPAddress );
-#endif /* ipconfigUSE_NBNS */
-
-#if( ipconfigUSE_DNS_CACHE == 1 )
- static uint8_t *prvReadNameField( uint8_t *pucByte, size_t xSourceLen, char *pcName, size_t xLen );
- static void prvProcessDNSCache( const char *pcName, uint32_t *pulIP, uint32_t ulTTL, BaseType_t xLookUp );
-
- typedef struct xDNS_CACHE_TABLE_ROW
- {
- uint32_t ulIPAddress; /* The IP address of an ARP cache entry. */
- char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /* The name of the host */
- uint32_t ulTTL; /* Time-to-Live (in seconds) from the DNS server. */
- uint32_t ulTimeWhenAddedInSeconds;
- } DNSCacheRow_t;
-
- static DNSCacheRow_t xDNSCache[ ipconfigDNS_CACHE_ENTRIES ];
-#endif /* ipconfigUSE_DNS_CACHE == 1 */
-
-#if( ipconfigUSE_LLMNR == 1 )
- const MACAddress_t xLLMNR_MacAdress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
-#endif /* ipconfigUSE_LLMNR == 1 */
-
-/*-----------------------------------------------------------*/
-
-#include "pack_struct_start.h"
-struct xDNSMessage
-{
- uint16_t usIdentifier;
- uint16_t usFlags;
- uint16_t usQuestions;
- uint16_t usAnswers;
- uint16_t usAuthorityRRs;
- uint16_t usAdditionalRRs;
-}
-#include "pack_struct_end.h"
-typedef struct xDNSMessage DNSMessage_t;
-
-/* A DNS query consists of a header, as described in 'struct xDNSMessage'
-It is followed by 1 or more queries, each one consisting of a name and a tail,
-with two fields: type and class
-*/
-#include "pack_struct_start.h"
-struct xDNSTail
-{
- uint16_t usType;
- uint16_t usClass;
-}
-#include "pack_struct_end.h"
-typedef struct xDNSTail DNSTail_t;
-
-/* DNS answer record header. */
-#include "pack_struct_start.h"
-struct xDNSAnswerRecord
-{
- uint16_t usType;
- uint16_t usClass;
- uint32_t ulTTL;
- uint16_t usDataLength;
-}
-#include "pack_struct_end.h"
-typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
-
-#if( ipconfigUSE_LLMNR == 1 )
-
- #include "pack_struct_start.h"
- struct xLLMNRAnswer
- {
- uint8_t ucNameCode;
- uint8_t ucNameOffset; /* The name is not repeated in the answer, only the offset is given with "0xc0 " */
- uint16_t usType;
- uint16_t usClass;
- uint32_t ulTTL;
- uint16_t usDataLength;
- uint32_t ulIPAddress;
- }
- #include "pack_struct_end.h"
- typedef struct xLLMNRAnswer LLMNRAnswer_t;
-
-#endif /* ipconfigUSE_LLMNR == 1 */
-
-#if( ipconfigUSE_NBNS == 1 )
-
- #include "pack_struct_start.h"
- struct xNBNSRequest
- {
- uint16_t usRequestId;
- uint16_t usFlags;
- uint16_t ulRequestCount;
- uint16_t usAnswerRSS;
- uint16_t usAuthRSS;
- uint16_t usAdditionalRSS;
- uint8_t ucNameSpace;
- uint8_t ucName[ dnsNBNS_ENCODED_NAME_LENGTH ];
- uint8_t ucNameZero;
- uint16_t usType;
- uint16_t usClass;
- }
- #include "pack_struct_end.h"
- typedef struct xNBNSRequest NBNSRequest_t;
-
- #include "pack_struct_start.h"
- struct xNBNSAnswer
- {
- uint16_t usType;
- uint16_t usClass;
- uint32_t ulTTL;
- uint16_t usDataLength;
- uint16_t usNbFlags; /* NetBIOS flags 0x6000 : IP-address, big-endian */
- uint32_t ulIPAddress;
- }
- #include "pack_struct_end.h"
- typedef struct xNBNSAnswer NBNSAnswer_t;
-
-#endif /* ipconfigUSE_NBNS == 1 */
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_DNS_CACHE == 1 )
- uint32_t FreeRTOS_dnslookup( const char *pcHostName )
- {
- uint32_t ulIPAddress = 0UL;
- prvProcessDNSCache( pcHostName, &ulIPAddress, 0, pdTRUE );
- return ulIPAddress;
- }
-#endif /* ipconfigUSE_DNS_CACHE == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigDNS_USE_CALLBACKS != 0 )
-
- typedef struct xDNS_Callback {
- TickType_t xRemaningTime; /* Timeout in ms */
- FOnDNSEvent pCallbackFunction; /* Function to be called when the address has been found or when a timeout has beeen reached */
- TimeOut_t xTimeoutState;
- void *pvSearchID;
- struct xLIST_ITEM xListItem;
- char pcName[ 1 ];
- } DNSCallback_t;
-
- static List_t xCallbackList;
-
- /* Define FreeRTOS_gethostbyname() as a normal blocking call. */
- uint32_t FreeRTOS_gethostbyname( const char *pcHostName )
- {
- return FreeRTOS_gethostbyname_a( pcHostName, ( FOnDNSEvent ) NULL, ( void* )NULL, 0 );
- }
- /*-----------------------------------------------------------*/
-
- /* Initialise the list of call-back structures. */
- void vDNSInitialise( void );
- void vDNSInitialise( void )
- {
- vListInitialise( &xCallbackList );
- }
- /*-----------------------------------------------------------*/
-
- /* Iterate through the list of call-back structures and remove
- old entries which have reached a timeout.
- As soon as the list hase become empty, the DNS timer will be stopped
- In case pvSearchID is supplied, the user wants to cancel a DNS request
- */
- void vDNSCheckCallBack( void *pvSearchID );
- void vDNSCheckCallBack( void *pvSearchID )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t* xEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xCallbackList );
-
- vTaskSuspendAll();
- {
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( xEnd );
- pxIterator != ( const ListItem_t * ) xEnd;
- )
- {
- DNSCallback_t *pxCallback = ( DNSCallback_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- /* Move to the next item because we might remove this item */
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator );
- if( ( pvSearchID != NULL ) && ( pvSearchID == pxCallback->pvSearchID ) )
- {
- uxListRemove( &pxCallback->xListItem );
- vPortFree( pxCallback );
- }
- else if( xTaskCheckForTimeOut( &pxCallback->xTimeoutState, &pxCallback->xRemaningTime ) != pdFALSE )
- {
- pxCallback->pCallbackFunction( pxCallback->pcName, pxCallback->pvSearchID, 0 );
- uxListRemove( &pxCallback->xListItem );
- vPortFree( ( void * ) pxCallback );
- }
- }
- }
- xTaskResumeAll();
-
- if( listLIST_IS_EMPTY( &xCallbackList ) )
- {
- vIPSetDnsTimerEnableState( pdFALSE );
- }
- }
- /*-----------------------------------------------------------*/
-
- void FreeRTOS_gethostbyname_cancel( void *pvSearchID )
- {
- /* _HT_ Should better become a new API call to have the IP-task remove the callback */
- vDNSCheckCallBack( pvSearchID );
- }
- /*-----------------------------------------------------------*/
-
- /* FreeRTOS_gethostbyname_a() was called along with callback parameters.
- Store them in a list for later reference. */
- static void vDNSSetCallBack( const char *pcHostName, void *pvSearchID, FOnDNSEvent pCallbackFunction, TickType_t xTimeout, TickType_t xIdentifier );
- static void vDNSSetCallBack( const char *pcHostName, void *pvSearchID, FOnDNSEvent pCallbackFunction, TickType_t xTimeout, TickType_t xIdentifier )
- {
- size_t lLength = strlen( pcHostName );
- DNSCallback_t *pxCallback = ( DNSCallback_t * )pvPortMalloc( sizeof( *pxCallback ) + lLength );
-
- /* Translate from ms to number of clock ticks. */
- xTimeout /= portTICK_PERIOD_MS;
- if( pxCallback != NULL )
- {
- if( listLIST_IS_EMPTY( &xCallbackList ) )
- {
- /* This is the first one, start the DNS timer to check for timeouts */
- vIPReloadDNSTimer( FreeRTOS_min_uint32( 1000U, xTimeout ) );
- }
- strcpy( pxCallback->pcName, pcHostName );
- pxCallback->pCallbackFunction = pCallbackFunction;
- pxCallback->pvSearchID = pvSearchID;
- pxCallback->xRemaningTime = xTimeout;
- vTaskSetTimeOutState( &pxCallback->xTimeoutState );
- listSET_LIST_ITEM_OWNER( &( pxCallback->xListItem ), ( void* ) pxCallback );
- listSET_LIST_ITEM_VALUE( &( pxCallback->xListItem ), xIdentifier );
- vTaskSuspendAll();
- {
- vListInsertEnd( &xCallbackList, &pxCallback->xListItem );
- }
- xTaskResumeAll();
- }
- }
- /*-----------------------------------------------------------*/
-
- /* A DNS reply was received, see if there is any matching entry and
- call the handler. */
- static void vDNSDoCallback( TickType_t xIdentifier, const char *pcName, uint32_t ulIPAddress );
- static void vDNSDoCallback( TickType_t xIdentifier, const char *pcName, uint32_t ulIPAddress )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t* xEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xCallbackList );
-
- vTaskSuspendAll();
- {
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( xEnd );
- pxIterator != ( const ListItem_t * ) xEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- if( listGET_LIST_ITEM_VALUE( pxIterator ) == xIdentifier )
- {
- DNSCallback_t *pxCallback = ( DNSCallback_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- pxCallback->pCallbackFunction( pcName, pxCallback->pvSearchID, ulIPAddress );
- uxListRemove( &pxCallback->xListItem );
- vPortFree( pxCallback );
- if( listLIST_IS_EMPTY( &xCallbackList ) )
- {
- vIPSetDnsTimerEnableState( pdFALSE );
- }
- break;
- }
- }
- }
- xTaskResumeAll();
- }
-
-#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigDNS_USE_CALLBACKS == 0 )
-uint32_t FreeRTOS_gethostbyname( const char *pcHostName )
-#else
-uint32_t FreeRTOS_gethostbyname_a( const char *pcHostName, FOnDNSEvent pCallback, void *pvSearchID, TickType_t xTimeout )
-#endif
-{
-uint32_t ulIPAddress = 0UL;
-TickType_t xReadTimeOut_ms = ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME;
-TickType_t xIdentifier = 0;
-
- /* If the supplied hostname is IP address, convert it to uint32_t
- and return. */
- #if( ipconfigINCLUDE_FULL_INET_ADDR == 1 )
- {
- ulIPAddress = FreeRTOS_inet_addr( pcHostName );
- }
- #endif /* ipconfigINCLUDE_FULL_INET_ADDR == 1 */
-
- /* If a DNS cache is used then check the cache before issuing another DNS
- request. */
- #if( ipconfigUSE_DNS_CACHE == 1 )
- {
- if( ulIPAddress == 0UL )
- {
- ulIPAddress = FreeRTOS_dnslookup( pcHostName );
- if( ulIPAddress != 0 )
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_gethostbyname: found '%s' in cache: %lxip\n", pcHostName, ulIPAddress ) );
- }
- else
- {
- /* prvGetHostByName will be called to start a DNS lookup */
- }
- }
- }
- #endif /* ipconfigUSE_DNS_CACHE == 1 */
-
- /* Generate a unique identifier. */
- if( 0 == ulIPAddress )
- {
- xIdentifier = ( TickType_t )ipconfigRAND32( );
- }
-
- #if( ipconfigDNS_USE_CALLBACKS != 0 )
- {
- if( pCallback != NULL )
- {
- if( ulIPAddress == 0UL )
- {
- /* The user has provided a callback function, so do not block on recvfrom() */
- if( 0 != xIdentifier )
- {
- xReadTimeOut_ms = 0;
- vDNSSetCallBack( pcHostName, pvSearchID, pCallback, xTimeout, ( TickType_t )xIdentifier );
- }
- }
- else
- {
- /* The IP address is known, do the call-back now. */
- pCallback( pcHostName, pvSearchID, ulIPAddress );
- }
- }
- }
- #endif
-
- if( ( ulIPAddress == 0UL ) && ( 0 != xIdentifier ) )
- {
- ulIPAddress = prvGetHostByName( pcHostName, xIdentifier, xReadTimeOut_ms );
- }
-
- return ulIPAddress;
-}
-/*-----------------------------------------------------------*/
-
-static uint32_t prvGetHostByName( const char *pcHostName, TickType_t xIdentifier, TickType_t xReadTimeOut_ms )
-{
-struct freertos_sockaddr xAddress;
-Socket_t xDNSSocket;
-uint32_t ulIPAddress = 0UL;
-uint8_t *pucUDPPayloadBuffer;
-uint32_t ulAddressLength = sizeof( struct freertos_sockaddr );
-BaseType_t xAttempt;
-int32_t lBytes;
-size_t xPayloadLength, xExpectedPayloadLength;
-TickType_t xWriteTimeOut_ms = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME;
-
-#if( ipconfigUSE_LLMNR == 1 )
- BaseType_t bHasDot = pdFALSE;
-#endif /* ipconfigUSE_LLMNR == 1 */
-
- /* If LLMNR is being used then determine if the host name includes a '.' -
- if not then LLMNR can be used as the lookup method. */
- #if( ipconfigUSE_LLMNR == 1 )
- {
- const char *pucPtr;
- for( pucPtr = pcHostName; *pucPtr; pucPtr++ )
- {
- if( *pucPtr == '.' )
- {
- bHasDot = pdTRUE;
- break;
- }
- }
- }
- #endif /* ipconfigUSE_LLMNR == 1 */
-
- /* Two is added at the end for the count of characters in the first
- subdomain part and the string end byte. */
- xExpectedPayloadLength = sizeof( DNSMessage_t ) + strlen( pcHostName ) + sizeof( uint16_t ) + sizeof( uint16_t ) + 2u;
-
- xDNSSocket = prvCreateDNSSocket();
-
- if( xDNSSocket != NULL )
- {
- FreeRTOS_setsockopt( xDNSSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xWriteTimeOut_ms, sizeof( TickType_t ) );
- FreeRTOS_setsockopt( xDNSSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xReadTimeOut_ms, sizeof( TickType_t ) );
-
- for( xAttempt = 0; xAttempt < ipconfigDNS_REQUEST_ATTEMPTS; xAttempt++ )
- {
- /* Get a buffer. This uses a maximum delay, but the delay will be
- capped to ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS so the return value
- still needs to be tested. */
- pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xExpectedPayloadLength, portMAX_DELAY );
-
- if( pucUDPPayloadBuffer != NULL )
- {
- /* Create the message in the obtained buffer. */
- xPayloadLength = prvCreateDNSMessage( pucUDPPayloadBuffer, pcHostName, xIdentifier );
-
- iptraceSENDING_DNS_REQUEST();
-
- /* Obtain the DNS server address. */
- FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulIPAddress );
-
- /* Send the DNS message. */
-#if( ipconfigUSE_LLMNR == 1 )
- if( bHasDot == pdFALSE )
- {
- /* Use LLMNR addressing. */
- ( ( DNSMessage_t * ) pucUDPPayloadBuffer) -> usFlags = 0;
- xAddress.sin_addr = ipLLMNR_IP_ADDR; /* Is in network byte order. */
- xAddress.sin_port = FreeRTOS_ntohs( ipLLMNR_PORT );
- }
- else
-#endif
- {
- /* Use DNS server. */
- xAddress.sin_addr = ulIPAddress;
- xAddress.sin_port = dnsDNS_PORT;
- }
-
- ulIPAddress = 0UL;
-
- if( FreeRTOS_sendto( xDNSSocket, pucUDPPayloadBuffer, xPayloadLength, FREERTOS_ZERO_COPY, &xAddress, sizeof( xAddress ) ) != 0 )
- {
- /* Wait for the reply. */
- lBytes = FreeRTOS_recvfrom( xDNSSocket, &pucUDPPayloadBuffer, 0, FREERTOS_ZERO_COPY, &xAddress, &ulAddressLength );
-
- if( lBytes > 0 )
- {
- /* The reply was received. Process it. */
- ulIPAddress = prvParseDNSReply( pucUDPPayloadBuffer, lBytes, xIdentifier );
-
- /* Finished with the buffer. The zero copy interface
- is being used, so the buffer must be freed by the
- task. */
- FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer );
-
- if( ulIPAddress != 0UL )
- {
- /* All done. */
- break;
- }
- }
- }
- else
- {
- /* The message was not sent so the stack will not be
- releasing the zero copy - it must be released here. */
- FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer );
- }
- }
- }
-
- /* Finished with the socket. */
- FreeRTOS_closesocket( xDNSSocket );
- }
-
- return ulIPAddress;
-}
-/*-----------------------------------------------------------*/
-
-static size_t prvCreateDNSMessage( uint8_t *pucUDPPayloadBuffer, const char *pcHostName, TickType_t xIdentifier )
-{
-DNSMessage_t *pxDNSMessageHeader;
-uint8_t *pucStart, *pucByte;
-DNSTail_t *pxTail;
-static const DNSMessage_t xDefaultPartDNSHeader =
-{
- 0, /* The identifier will be overwritten. */
- dnsOUTGOING_FLAGS, /* Flags set for standard query. */
- dnsONE_QUESTION, /* One question is being asked. */
- 0, /* No replies are included. */
- 0, /* No authorities. */
- 0 /* No additional authorities. */
-};
-
- /* Copy in the const part of the header. */
- memcpy( ( void * ) pucUDPPayloadBuffer, ( void * ) &xDefaultPartDNSHeader, sizeof( xDefaultPartDNSHeader ) );
-
- /* Write in a unique identifier. */
- pxDNSMessageHeader = ( DNSMessage_t * ) pucUDPPayloadBuffer;
- pxDNSMessageHeader->usIdentifier = ( uint16_t ) xIdentifier;
-
- /* Create the resource record at the end of the header. First
- find the end of the header. */
- pucStart = pucUDPPayloadBuffer + sizeof( xDefaultPartDNSHeader );
-
- /* Leave a gap for the first length bytes. */
- pucByte = pucStart + 1;
-
- /* Copy in the host name. */
- strcpy( ( char * ) pucByte, pcHostName );
-
- /* Mark the end of the string. */
- pucByte += strlen( pcHostName );
- *pucByte = 0x00u;
-
- /* Walk the string to replace the '.' characters with byte counts.
- pucStart holds the address of the byte count. Walking the string
- starts after the byte count position. */
- pucByte = pucStart;
-
- do
- {
- pucByte++;
-
- while( ( *pucByte != 0x00 ) && ( *pucByte != '.' ) )
- {
- pucByte++;
- }
-
- /* Fill in the byte count, then move the pucStart pointer up to
- the found byte position. */
- *pucStart = ( uint8_t ) ( ( uint32_t ) pucByte - ( uint32_t ) pucStart );
- ( *pucStart )--;
-
- pucStart = pucByte;
-
- } while( *pucByte != 0x00 );
-
- /* Finish off the record. */
-
- pxTail = (DNSTail_t *)( pucByte + 1 );
-
- vSetField16( pxTail, DNSTail_t, usType, dnsTYPE_A_HOST ); /* Type A: host */
- vSetField16( pxTail, DNSTail_t, usClass, dnsCLASS_IN ); /* 1: Class IN */
-
- /* Return the total size of the generated message, which is the space from
- the last written byte to the beginning of the buffer. */
- return ( ( uint32_t ) pucByte - ( uint32_t ) pucUDPPayloadBuffer + 1 ) + sizeof( *pxTail );
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_DNS_CACHE == 1 )
-
- static uint8_t *prvReadNameField( uint8_t *pucByte, size_t xSourceLen, char *pcName, size_t xDestLen )
- {
- size_t xNameLen = 0;
- BaseType_t xCount;
-
- if( 0 == xSourceLen )
- {
- return NULL;
- }
-
- /* Determine if the name is the fully coded name, or an offset to the name
- elsewhere in the message. */
- if( ( *pucByte & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET )
- {
- /* Jump over the two byte offset. */
- if( xSourceLen > sizeof( uint16_t ) )
- {
- pucByte += sizeof( uint16_t );
- }
- else
- {
- pucByte = NULL;
- }
- }
- else
- {
- /* pucByte points to the full name. Walk over the string. */
- while( ( NULL != pucByte ) && ( *pucByte != 0x00 ) && ( xSourceLen > 1 ) )
- {
- /* If this is not the first time through the loop, then add a
- separator in the output. */
- if( ( xNameLen > 0 ) && ( xNameLen < ( xDestLen - 1 ) ) )
- {
- pcName[ xNameLen++ ] = '.';
- }
-
- /* Process the first/next sub-string. */
- for( xCount = *(pucByte++), xSourceLen--;
- xCount-- && xSourceLen > 1;
- pucByte++, xSourceLen-- )
- {
- if( xNameLen < xDestLen - 1 )
- {
- pcName[ xNameLen++ ] = *( ( char * )pucByte );
- }
- else
- {
- /* DNS name is too big for the provided buffer. */
- pucByte = NULL;
- break;
- }
- }
- }
-
- /* Confirm that a fully formed name was found. */
- if( NULL != pucByte )
- {
- if( 0x00 == *pucByte )
- {
- pucByte++;
- xSourceLen--;
- pcName[ xNameLen++ ] = '\0';
- }
- else
- {
- pucByte = NULL;
- }
- }
- }
-
- return pucByte;
- }
-#endif /* ipconfigUSE_DNS_CACHE == 1 */
-/*-----------------------------------------------------------*/
-
-static uint8_t *prvSkipNameField( uint8_t *pucByte, size_t xSourceLen )
-{
- size_t xChunkLength;
-
- if( 0 == xSourceLen )
- {
- return NULL;
- }
-
- /* Determine if the name is the fully coded name, or an offset to the name
- elsewhere in the message. */
- if( ( *pucByte & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET )
- {
- /* Jump over the two byte offset. */
- if( xSourceLen > sizeof( uint16_t ) )
- {
- pucByte += sizeof( uint16_t );
- }
- else
- {
- pucByte = NULL;
- }
- }
- else
- {
- /* pucByte points to the full name. Walk over the string. */
- while( ( *pucByte != 0x00 ) && ( xSourceLen > 1 ) )
- {
- xChunkLength = *pucByte + 1;
-
- if( xSourceLen > xChunkLength )
- {
- xSourceLen -= xChunkLength;
- pucByte += xChunkLength;
- }
- else
- {
- pucByte = NULL;
- break;
- }
- }
-
- /* Confirm that a fully formed name was found. */
- if( NULL != pucByte )
- {
- if( 0x00 == *pucByte )
- {
- pucByte++;
- }
- else
- {
- pucByte = NULL;
- }
- }
- }
-
- return pucByte;
-}
-/*-----------------------------------------------------------*/
-
-uint32_t ulDNSHandlePacket( NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-uint8_t *pucUDPPayloadBuffer;
-size_t xPlayloadBufferLength;
-DNSMessage_t *pxDNSMessageHeader;
-
- xPlayloadBufferLength = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t );
- if ( xPlayloadBufferLength < sizeof( DNSMessage_t ) )
- {
- return pdFAIL;
- }
-
- pucUDPPayloadBuffer = pxNetworkBuffer->pucEthernetBuffer + sizeof( UDPPacket_t );
- pxDNSMessageHeader = ( DNSMessage_t * ) pucUDPPayloadBuffer;
-
- if( pxNetworkBuffer->xDataLength > sizeof( UDPPacket_t ) )
- {
- prvParseDNSReply( pucUDPPayloadBuffer,
- xPlayloadBufferLength,
- ( uint32_t )pxDNSMessageHeader->usIdentifier );
- }
-
- /* The packet was not consumed. */
- return pdFAIL;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_NBNS == 1 )
-
- uint32_t ulNBNSHandlePacket (NetworkBufferDescriptor_t *pxNetworkBuffer )
- {
- UDPPacket_t *pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
- uint8_t *pucUDPPayloadBuffer = pxNetworkBuffer->pucEthernetBuffer + sizeof( UDPPacket_t );
-
- if( pxNetworkBuffer->xDataLength > sizeof( UDPPacket_t) )
- {
- prvTreatNBNS( pucUDPPayloadBuffer,
- pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t ),
- pxUDPPacket->xIPHeader.ulSourceIPAddress );
- }
-
- /* The packet was not consumed. */
- return pdFAIL;
- }
-
-#endif /* ipconfigUSE_NBNS */
-/*-----------------------------------------------------------*/
-
-static uint32_t prvParseDNSReply( uint8_t *pucUDPPayloadBuffer, size_t xBufferLength, TickType_t xIdentifier )
-{
-DNSMessage_t *pxDNSMessageHeader;
-DNSAnswerRecord_t *pxDNSAnswerRecord;
-uint32_t ulIPAddress = 0UL;
-#if( ipconfigUSE_LLMNR == 1 )
- char *pcRequestedName = NULL;
-#endif
-uint8_t *pucByte;
-size_t xSourceBytesRemaining;
-uint16_t x, usDataLength, usQuestions;
-#if( ipconfigUSE_LLMNR == 1 )
- uint16_t usType = 0, usClass = 0;
-#endif
-#if( ipconfigUSE_DNS_CACHE == 1 )
- char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ] = "";
-#endif
-
- /* Ensure that the buffer is of at least minimal DNS message length. */
- if( xBufferLength < sizeof( DNSMessage_t ) )
- {
- return dnsPARSE_ERROR;
- }
- else
- {
- xSourceBytesRemaining = xBufferLength;
- }
-
- /* Parse the DNS message header. */
- pxDNSMessageHeader = ( DNSMessage_t * ) pucUDPPayloadBuffer;
-
- if( pxDNSMessageHeader->usIdentifier == ( uint16_t ) xIdentifier )
- {
- /* Start at the first byte after the header. */
- pucByte = pucUDPPayloadBuffer + sizeof( DNSMessage_t );
- xSourceBytesRemaining -= sizeof( DNSMessage_t );
-
- /* Skip any question records. */
- usQuestions = FreeRTOS_ntohs( pxDNSMessageHeader->usQuestions );
- for( x = 0; x < usQuestions; x++ )
- {
- #if( ipconfigUSE_LLMNR == 1 )
- {
- if( x == 0 )
- {
- pcRequestedName = ( char * ) pucByte;
- }
- }
- #endif
-
-#if( ipconfigUSE_DNS_CACHE == 1 )
- if( x == 0 )
- {
- pucByte = prvReadNameField( pucByte,
- xSourceBytesRemaining,
- pcName,
- sizeof( pcName ) );
-
- /* Check for a malformed response. */
- if( NULL == pucByte )
- {
- return dnsPARSE_ERROR;
- }
- else
- {
- xSourceBytesRemaining = ( pucUDPPayloadBuffer + xBufferLength ) - pucByte;
- }
- }
- else
-#endif /* ipconfigUSE_DNS_CACHE */
- {
- /* Skip the variable length pcName field. */
- pucByte = prvSkipNameField( pucByte,
- xSourceBytesRemaining );
-
- /* Check for a malformed response. */
- if( NULL == pucByte )
- {
- return dnsPARSE_ERROR;
- }
- else
- {
- xSourceBytesRemaining = pucUDPPayloadBuffer + xBufferLength - pucByte;
- }
- }
-
- /* Check the remaining buffer size. */
- if( xSourceBytesRemaining >= sizeof( uint32_t ) )
- {
- #if( ipconfigUSE_LLMNR == 1 )
- {
- /* usChar2u16 returns value in host endianness */
- usType = usChar2u16( pucByte );
- usClass = usChar2u16( pucByte + 2 );
- }
- #endif /* ipconfigUSE_LLMNR */
-
- /* Skip the type and class fields. */
- pucByte += sizeof( uint32_t );
- xSourceBytesRemaining -= sizeof( uint32_t );
- }
- else
- {
- /* Malformed response. */
- return dnsPARSE_ERROR;
- }
- }
-
- /* Search through the answer records. */
- pxDNSMessageHeader->usAnswers = FreeRTOS_ntohs( pxDNSMessageHeader->usAnswers );
-
- if( ( pxDNSMessageHeader->usFlags & dnsRX_FLAGS_MASK ) == dnsEXPECTED_RX_FLAGS )
- {
- for( x = 0; x < pxDNSMessageHeader->usAnswers; x++ )
- {
- pucByte = prvSkipNameField( pucByte,
- xSourceBytesRemaining );
-
- /* Check for a malformed response. */
- if( NULL == pucByte )
- {
- return dnsPARSE_ERROR;
- }
- else
- {
- xSourceBytesRemaining = pucUDPPayloadBuffer + xBufferLength - pucByte;
- }
-
- /* Is there enough data for an IPv4 A record answer and, if so,
- is this an A record? */
- if( xSourceBytesRemaining >= sizeof( DNSAnswerRecord_t ) + sizeof( uint32_t ) &&
- usChar2u16( pucByte ) == dnsTYPE_A_HOST )
- {
- /* This is the required record type and is of sufficient size. */
- pxDNSAnswerRecord = ( DNSAnswerRecord_t * )pucByte;
-
- /* Sanity check the data length of an IPv4 answer. */
- if( FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength ) == sizeof( uint32_t ) )
- {
- /* Copy the IP address out of the record. */
- memcpy( &ulIPAddress,
- pucByte + sizeof( DNSAnswerRecord_t ),
- sizeof( uint32_t ) );
-
- #if( ipconfigUSE_DNS_CACHE == 1 )
- {
- prvProcessDNSCache( pcName, &ulIPAddress, pxDNSAnswerRecord->ulTTL, pdFALSE );
- }
- #endif /* ipconfigUSE_DNS_CACHE */
- #if( ipconfigDNS_USE_CALLBACKS != 0 )
- {
- /* See if any asynchronous call was made to FreeRTOS_gethostbyname_a() */
- vDNSDoCallback( ( TickType_t ) pxDNSMessageHeader->usIdentifier, pcName, ulIPAddress );
- }
- #endif /* ipconfigDNS_USE_CALLBACKS != 0 */
- }
-
- pucByte += sizeof( DNSAnswerRecord_t ) + sizeof( uint32_t );
- xSourceBytesRemaining -= ( sizeof( DNSAnswerRecord_t ) + sizeof( uint32_t ) );
- break;
- }
- else if( xSourceBytesRemaining >= sizeof( DNSAnswerRecord_t ) )
- {
- /* It's not an A record, so skip it. Get the header location
- and then jump over the header. */
- pxDNSAnswerRecord = ( DNSAnswerRecord_t * )pucByte;
- pucByte += sizeof( DNSAnswerRecord_t );
- xSourceBytesRemaining -= sizeof( DNSAnswerRecord_t );
-
- /* Determine the length of the answer data from the header. */
- usDataLength = FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength );
-
- /* Jump over the answer. */
- if( xSourceBytesRemaining >= usDataLength )
- {
- pucByte += usDataLength;
- xSourceBytesRemaining -= usDataLength;
- }
- else
- {
- /* Malformed response. */
- return dnsPARSE_ERROR;
- }
- }
- }
- }
-#if( ipconfigUSE_LLMNR == 1 )
- else if( usQuestions && ( usType == dnsTYPE_A_HOST ) && ( usClass == dnsCLASS_IN ) )
- {
- /* If this is not a reply to our DNS request, it might an LLMNR
- request. */
- if( xApplicationDNSQueryHook ( ( pcRequestedName + 1 ) ) )
- {
- int16_t usLength;
- NetworkBufferDescriptor_t *pxNewBuffer = NULL;
- NetworkBufferDescriptor_t *pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( pucUDPPayloadBuffer );
- LLMNRAnswer_t *pxAnswer;
-
- if( ( xBufferAllocFixedSize == pdFALSE ) && ( pxNetworkBuffer != NULL ) )
- {
- BaseType_t xDataLength = xBufferLength + sizeof( UDPHeader_t ) + sizeof( EthernetHeader_t ) + sizeof( IPHeader_t );
-
- /* The field xDataLength was set to the length of the UDP payload.
- The answer (reply) will be longer than the request, so the packet
- must be duplicaed into a bigger buffer */
- pxNetworkBuffer->xDataLength = xDataLength;
- pxNewBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, xDataLength + 16 );
- if( pxNewBuffer != NULL )
- {
- BaseType_t xOffset1, xOffset2;
-
- xOffset1 = ( BaseType_t ) ( pucByte - pucUDPPayloadBuffer );
- xOffset2 = ( BaseType_t ) ( ( ( uint8_t * ) pcRequestedName ) - pucUDPPayloadBuffer );
-
- pxNetworkBuffer = pxNewBuffer;
- pucUDPPayloadBuffer = pxNetworkBuffer->pucEthernetBuffer + ipUDP_PAYLOAD_OFFSET_IPv4;
-
- pucByte = pucUDPPayloadBuffer + xOffset1;
- pcRequestedName = ( char * ) ( pucUDPPayloadBuffer + xOffset2 );
- pxDNSMessageHeader = ( DNSMessage_t * ) pucUDPPayloadBuffer;
-
- }
- else
- {
- /* Just to indicate that the message may not be answered. */
- pxNetworkBuffer = NULL;
- }
- }
- if( pxNetworkBuffer != NULL )
- {
- pxAnswer = (LLMNRAnswer_t *)pucByte;
-
- /* We leave 'usIdentifier' and 'usQuestions' untouched */
- vSetField16( pxDNSMessageHeader, DNSMessage_t, usFlags, dnsLLMNR_FLAGS_IS_REPONSE ); /* Set the response flag */
- vSetField16( pxDNSMessageHeader, DNSMessage_t, usAnswers, 1 ); /* Provide a single answer */
- vSetField16( pxDNSMessageHeader, DNSMessage_t, usAuthorityRRs, 0 ); /* No authority */
- vSetField16( pxDNSMessageHeader, DNSMessage_t, usAdditionalRRs, 0 ); /* No additional info */
-
- pxAnswer->ucNameCode = dnsNAME_IS_OFFSET;
- pxAnswer->ucNameOffset = ( uint8_t )( pcRequestedName - ( char * ) pucUDPPayloadBuffer );
-
- vSetField16( pxAnswer, LLMNRAnswer_t, usType, dnsTYPE_A_HOST ); /* Type A: host */
- vSetField16( pxAnswer, LLMNRAnswer_t, usClass, dnsCLASS_IN ); /* 1: Class IN */
- vSetField32( pxAnswer, LLMNRAnswer_t, ulTTL, dnsLLMNR_TTL_VALUE );
- vSetField16( pxAnswer, LLMNRAnswer_t, usDataLength, 4 );
- vSetField32( pxAnswer, LLMNRAnswer_t, ulIPAddress, FreeRTOS_ntohl( *ipLOCAL_IP_ADDRESS_POINTER ) );
-
- usLength = ( int16_t ) ( sizeof( *pxAnswer ) + ( size_t ) ( pucByte - pucUDPPayloadBuffer ) );
-
- prvReplyDNSMessage( pxNetworkBuffer, usLength );
-
- if( pxNewBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNewBuffer );
- }
- }
- }
- }
-#endif /* ipconfigUSE_LLMNR == 1 */
- }
-
- return ulIPAddress;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_NBNS == 1 )
-
- static void prvTreatNBNS( uint8_t *pucUDPPayloadBuffer, size_t xBufferLength, uint32_t ulIPAddress )
- {
- uint16_t usFlags, usType, usClass;
- uint8_t *pucSource, *pucTarget;
- uint8_t ucByte;
- uint8_t ucNBNSName[ 17 ];
-
- /* Check for minimum buffer size. */
- if( xBufferLength < sizeof( NBNSRequest_t ) )
- {
- return;
- }
-
- /* Read the request flags in host endianness. */
- usFlags = usChar2u16( pucUDPPayloadBuffer + offsetof( NBNSRequest_t, usFlags ) );
-
- if( ( usFlags & dnsNBNS_FLAGS_OPCODE_MASK ) == dnsNBNS_FLAGS_OPCODE_QUERY )
- {
- usType = usChar2u16( pucUDPPayloadBuffer + offsetof( NBNSRequest_t, usType ) );
- usClass = usChar2u16( pucUDPPayloadBuffer + offsetof( NBNSRequest_t, usClass ) );
-
- /* Not used for now */
- ( void )usClass;
- /* For NBNS a name is 16 bytes long, written with capitals only.
- Make sure that the copy is terminated with a zero. */
- pucTarget = ucNBNSName + sizeof(ucNBNSName ) - 2;
- pucTarget[ 1 ] = '\0';
-
- /* Start with decoding the last 2 bytes. */
- pucSource = pucUDPPayloadBuffer + ( offsetof( NBNSRequest_t, ucName ) + ( dnsNBNS_ENCODED_NAME_LENGTH - 2 ) );
-
- for( ;; )
- {
- ucByte = ( uint8_t ) ( ( ( pucSource[ 0 ] - 0x41 ) << 4 ) | ( pucSource[ 1 ] - 0x41 ) );
-
- /* Make sure there are no trailing spaces in the name. */
- if( ( ucByte == ' ' ) && ( pucTarget[ 1 ] == '\0' ) )
- {
- ucByte = '\0';
- }
-
- *pucTarget = ucByte;
-
- if( pucTarget == ucNBNSName )
- {
- break;
- }
-
- pucTarget -= 1;
- pucSource -= 2;
- }
-
- #if( ipconfigUSE_DNS_CACHE == 1 )
- {
- if( ( usFlags & dnsNBNS_FLAGS_RESPONSE ) != 0 )
- {
- /* If this is a response from another device,
- add the name to the DNS cache */
- prvProcessDNSCache( ( char * ) ucNBNSName, &ulIPAddress, 0, pdFALSE );
- }
- }
- #else
- {
- /* Avoid compiler warnings. */
- ( void ) ulIPAddress;
- }
- #endif /* ipconfigUSE_DNS_CACHE */
-
- if( ( ( usFlags & dnsNBNS_FLAGS_RESPONSE ) == 0 ) &&
- ( usType == dnsNBNS_TYPE_NET_BIOS ) &&
- ( xApplicationDNSQueryHook( ( const char * ) ucNBNSName ) != pdFALSE ) )
- {
- uint16_t usLength;
- DNSMessage_t *pxMessage;
- NBNSAnswer_t *pxAnswer;
-
- /* Someone is looking for a device with ucNBNSName,
- prepare a positive reply. */
- NetworkBufferDescriptor_t *pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( pucUDPPayloadBuffer );
-
- if( ( xBufferAllocFixedSize == pdFALSE ) && ( pxNetworkBuffer != NULL ) )
- {
- NetworkBufferDescriptor_t *pxNewBuffer;
- BaseType_t xDataLength = pxNetworkBuffer->xDataLength + sizeof( UDPHeader_t ) +
- sizeof( EthernetHeader_t ) + sizeof( IPHeader_t );
-
- /* The field xDataLength was set to the length of the UDP payload.
- The answer (reply) will be longer than the request, so the packet
- must be duplicated into a bigger buffer */
- pxNetworkBuffer->xDataLength = xDataLength;
- pxNewBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, xDataLength + 16 );
- if( pxNewBuffer != NULL )
- {
- pucUDPPayloadBuffer = pxNewBuffer->pucEthernetBuffer + sizeof( UDPPacket_t );
- pxNetworkBuffer = pxNewBuffer;
- }
- else
- {
- /* Just prevent that a reply will be sent */
- pxNetworkBuffer = NULL;
- }
- }
-
- /* Should not occur: pucUDPPayloadBuffer is part of a xNetworkBufferDescriptor */
- if( pxNetworkBuffer != NULL )
- {
- pxMessage = (DNSMessage_t *)pucUDPPayloadBuffer;
-
- /* As the fields in the structures are not word-aligned, we have to
- copy the values byte-by-byte using macro's vSetField16() and vSetField32() */
- vSetField16( pxMessage, DNSMessage_t, usFlags, dnsNBNS_QUERY_RESPONSE_FLAGS ); /* 0x8500 */
- vSetField16( pxMessage, DNSMessage_t, usQuestions, 0 );
- vSetField16( pxMessage, DNSMessage_t, usAnswers, 1 );
- vSetField16( pxMessage, DNSMessage_t, usAuthorityRRs, 0 );
- vSetField16( pxMessage, DNSMessage_t, usAdditionalRRs, 0 );
-
- pxAnswer = (NBNSAnswer_t *)( pucUDPPayloadBuffer + offsetof( NBNSRequest_t, usType ) );
-
- vSetField16( pxAnswer, NBNSAnswer_t, usType, usType ); /* Type */
- vSetField16( pxAnswer, NBNSAnswer_t, usClass, dnsNBNS_CLASS_IN ); /* Class */
- vSetField32( pxAnswer, NBNSAnswer_t, ulTTL, dnsNBNS_TTL_VALUE );
- vSetField16( pxAnswer, NBNSAnswer_t, usDataLength, 6 ); /* 6 bytes including the length field */
- vSetField16( pxAnswer, NBNSAnswer_t, usNbFlags, dnsNBNS_NAME_FLAGS );
- vSetField32( pxAnswer, NBNSAnswer_t, ulIPAddress, FreeRTOS_ntohl( *ipLOCAL_IP_ADDRESS_POINTER ) );
-
- usLength = ( uint16_t ) ( offsetof( NBNSRequest_t, usType ) + sizeof( NBNSAnswer_t ) );
-
- prvReplyDNSMessage( pxNetworkBuffer, usLength );
- }
- }
- }
- }
-
-#endif /* ipconfigUSE_NBNS */
-/*-----------------------------------------------------------*/
-
-static Socket_t prvCreateDNSSocket( void )
-{
-Socket_t xSocket = NULL;
-struct freertos_sockaddr xAddress;
-BaseType_t xReturn;
-TickType_t xTimeoutTime = pdMS_TO_TICKS( 200 );
-
- /* This must be the first time this function has been called. Create
- the socket. */
- xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
-
- /* Auto bind the port. */
- xAddress.sin_port = 0u;
- xReturn = FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );
-
- /* Check the bind was successful, and clean up if not. */
- if( xReturn != 0 )
- {
- FreeRTOS_closesocket( xSocket );
- xSocket = NULL;
- }
- else
- {
- /* Set the send and receive timeouts. */
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xTimeoutTime, sizeof( TickType_t ) );
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xTimeoutTime, sizeof( TickType_t ) );
- }
-
- return xSocket;
-}
-/*-----------------------------------------------------------*/
-
-#if( ( ipconfigUSE_NBNS == 1 ) || ( ipconfigUSE_LLMNR == 1 ) )
-
- static void prvReplyDNSMessage( NetworkBufferDescriptor_t *pxNetworkBuffer, BaseType_t lNetLength )
- {
- UDPPacket_t *pxUDPPacket;
- IPHeader_t *pxIPHeader;
- UDPHeader_t *pxUDPHeader;
-
- pxUDPPacket = (UDPPacket_t *) pxNetworkBuffer->pucEthernetBuffer;
- pxIPHeader = &pxUDPPacket->xIPHeader;
- pxUDPHeader = &pxUDPPacket->xUDPHeader;
- /* HT: started using defines like 'ipSIZE_OF_xxx' */
- pxIPHeader->usLength = FreeRTOS_htons( lNetLength + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER );
- /* HT:endian: should not be translated, copying from packet to packet */
- pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress;
- pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
- pxIPHeader->ucTimeToLive = ipconfigUDP_TIME_TO_LIVE;
- pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
- usPacketIdentifier++;
- pxUDPHeader->usLength = FreeRTOS_htons( lNetLength + ipSIZE_OF_UDP_HEADER );
- vFlip_16( pxUDPPacket->xUDPHeader.usSourcePort, pxUDPPacket->xUDPHeader.usDestinationPort );
-
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
- {
- /* calculate the IP header checksum */
- pxIPHeader->usHeaderChecksum = 0x00;
- pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0UL, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
- pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
-
- /* calculate the UDP checksum for outgoing package */
- usGenerateProtocolChecksum( ( uint8_t* ) pxUDPPacket, lNetLength, pdTRUE );
- }
- #endif
-
- /* Important: tell NIC driver how many bytes must be sent */
- pxNetworkBuffer->xDataLength = ( size_t ) ( lNetLength + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER + ipSIZE_OF_ETH_HEADER );
-
- /* This function will fill in the eth addresses and send the packet */
- vReturnEthernetFrame( pxNetworkBuffer, pdFALSE );
- }
-
-#endif /* ipconfigUSE_NBNS == 1 || ipconfigUSE_LLMNR == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_DNS_CACHE == 1 )
-
- static void prvProcessDNSCache( const char *pcName, uint32_t *pulIP, uint32_t ulTTL, BaseType_t xLookUp )
- {
- BaseType_t x;
- BaseType_t xFound = pdFALSE;
- uint32_t ulCurrentTimeSeconds = ( xTaskGetTickCount() / portTICK_PERIOD_MS ) / 1000UL;
- static BaseType_t xFreeEntry = 0;
-
- /* For each entry in the DNS cache table. */
- for( x = 0; x < ipconfigDNS_CACHE_ENTRIES; x++ )
- {
- if( xDNSCache[ x ].pcName[ 0 ] == 0 )
- {
- break;
- }
-
- if( 0 == strcmp( xDNSCache[ x ].pcName, pcName ) )
- {
- /* Is this function called for a lookup or to add/update an IP address? */
- if( xLookUp != pdFALSE )
- {
- /* Confirm that the record is still fresh. */
- if( ulCurrentTimeSeconds < ( xDNSCache[ x ].ulTimeWhenAddedInSeconds + FreeRTOS_ntohl( xDNSCache[ x ].ulTTL ) ) )
- {
- *pulIP = xDNSCache[ x ].ulIPAddress;
- }
- else
- {
- /* Age out the old cached record. */
- xDNSCache[ x ].pcName[ 0 ] = 0;
- }
- }
- else
- {
- xDNSCache[ x ].ulIPAddress = *pulIP;
- xDNSCache[ x ].ulTTL = ulTTL;
- xDNSCache[ x ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds;
- }
-
- xFound = pdTRUE;
- break;
- }
- }
-
- if( xFound == pdFALSE )
- {
- if( xLookUp != pdFALSE )
- {
- *pulIP = 0;
- }
- else
- {
- /* Add or update the item. */
- if( strlen( pcName ) < ipconfigDNS_CACHE_NAME_LENGTH )
- {
- strcpy( xDNSCache[ xFreeEntry ].pcName, pcName );
-
- xDNSCache[ xFreeEntry ].ulIPAddress = *pulIP;
- xDNSCache[ xFreeEntry ].ulTTL = ulTTL;
- xDNSCache[ xFreeEntry ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds;
-
- xFreeEntry++;
- if( xFreeEntry == ipconfigDNS_CACHE_ENTRIES )
- {
- xFreeEntry = 0;
- }
- }
- }
- }
-
- if( ( xLookUp == 0 ) || ( *pulIP != 0 ) )
- {
- FreeRTOS_debug_printf( ( "prvProcessDNSCache: %s: '%s' @ %lxip\n", xLookUp ? "look-up" : "add", pcName, FreeRTOS_ntohl( *pulIP ) ) );
- }
- }
-
-#endif /* ipconfigUSE_DNS_CACHE */
-
-#endif /* ipconfigUSE_DNS != 0 */
-
-/*-----------------------------------------------------------*/
-
-/* Provide access to private members for testing. */
-#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
- #include "aws_freertos_tcp_test_access_dns_define.h"
-#endif
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
deleted file mode 100755
index 9fc2a07..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
+++ /dev/null
@@ -1,2313 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_ARP.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_TCP_IP.h"
-#include "FreeRTOS_DHCP.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-#include "FreeRTOS_DNS.h"
-
-
-/* Used to ensure the structure packing is having the desired effect. The
-'volatile' is used to prevent compiler warnings about comparing a constant with
-a constant. */
-#define ipEXPECTED_EthernetHeader_t_SIZE ( ( size_t ) 14 )
-#define ipEXPECTED_ARPHeader_t_SIZE ( ( size_t ) 28 )
-#define ipEXPECTED_IPHeader_t_SIZE ( ( size_t ) 20 )
-#define ipEXPECTED_IGMPHeader__SIZE ( ( size_t ) 8 )
-#define ipEXPECTED_ICMPHeader_t_SIZE ( ( size_t ) 8 )
-#define ipEXPECTED_UDPHeader_t_SIZE ( ( size_t ) 8 )
-#define ipEXPECTED_TCPHeader_t_SIZE ( ( size_t ) 20 )
-
-
-/* ICMP protocol definitions. */
-#define ipICMP_ECHO_REQUEST ( ( uint8_t ) 8 )
-#define ipICMP_ECHO_REPLY ( ( uint8_t ) 0 )
-
-
-/* Time delay between repeated attempts to initialise the network hardware. */
-#define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000 ) )
-
-/* Defines how often the ARP timer callback function is executed. The time is
-shorted in the Windows simulator as simulated time is not real time. */
-#ifndef ipARP_TIMER_PERIOD_MS
- #ifdef _WINDOWS_
- #define ipARP_TIMER_PERIOD_MS ( 500 ) /* For windows simulator builds. */
- #else
- #define ipARP_TIMER_PERIOD_MS ( 10000 )
- #endif
-#endif
-
-#ifndef iptraceIP_TASK_STARTING
- #define iptraceIP_TASK_STARTING() do {} while( 0 )
-#endif
-
-#if( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
- /* When initialising the TCP timer,
- give it an initial time-out of 1 second. */
- #define ipTCP_TIMER_PERIOD_MS ( 1000 )
-#endif
-
-/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet
-driver will filter incoming packets and only pass the stack those packets it
-considers need processing. In this case ipCONSIDER_FRAME_FOR_PROCESSING() can
-be #defined away. If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 0
-then the Ethernet driver will pass all received packets to the stack, and the
-stack must do the filtering itself. In this case ipCONSIDER_FRAME_FOR_PROCESSING
-needs to call eConsiderFrameForProcessing. */
-#if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
-#else
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
-#endif
-
-/* The character used to fill ICMP echo requests, and therefore also the
-character expected to fill ICMP echo replies. */
-#define ipECHO_DATA_FILL_BYTE 'x'
-
-#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
- /* The bits in the two byte IP header field that make up the fragment offset value. */
- #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff0f )
-#else
- /* The bits in the two byte IP header field that make up the fragment offset value. */
- #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff )
-#endif /* ipconfigBYTE_ORDER */
-
-/* The maximum time the IP task is allowed to remain in the Blocked state if no
-events are posted to the network event queue. */
-#ifndef ipconfigMAX_IP_TASK_SLEEP_TIME
- #define ipconfigMAX_IP_TASK_SLEEP_TIME ( pdMS_TO_TICKS( 10000UL ) )
-#endif
-
-/* When a new TCP connection is established, the value of
-'ulNextInitialSequenceNumber' will be used as the initial sequence number. It
-is very important that at start-up, 'ulNextInitialSequenceNumber' contains a
-random value. Also its value must be increased continuously in time, to prevent
-a third party guessing the next sequence number and take-over a TCP connection.
-It is advised to increment it by 1 ever 4us, which makes about 256 times
-per ms: */
-#define ipINITIAL_SEQUENCE_NUMBER_FACTOR 256UL
-
-/* Returned as the (invalid) checksum when the protocol being checked is not
-handled. The value is chosen simply to be easy to spot when debugging. */
-#define ipUNHANDLED_PROTOCOL 0x4321u
-
-/* Returned to indicate a valid checksum when the checksum does not need to be
-calculated. */
-#define ipCORRECT_CRC 0xffffu
-
-/* Returned as the (invalid) checksum when the length of the data being checked
-had an invalid length. */
-#define ipINVALID_LENGTH 0x1234u
-
-/*-----------------------------------------------------------*/
-
-typedef struct xIP_TIMER
-{
- uint32_t
- bActive : 1, /* This timer is running and must be processed. */
- bExpired : 1; /* Timer has expired and a task must be processed. */
- TimeOut_t xTimeOut;
- TickType_t ulRemainingTime;
- TickType_t ulReloadTime;
-} IPTimer_t;
-
-/* Used in checksum calculation. */
-typedef union _xUnion32
-{
- uint32_t u32;
- uint16_t u16[ 2 ];
- uint8_t u8[ 4 ];
-} xUnion32;
-
-/* Used in checksum calculation. */
-typedef union _xUnionPtr
-{
- uint32_t *u32ptr;
- uint16_t *u16ptr;
- uint8_t *u8ptr;
-} xUnionPtr;
-
-/*-----------------------------------------------------------*/
-
-/*
- * The main TCP/IP stack processing task. This task receives commands/events
- * from the network hardware drivers and tasks that are using sockets. It also
- * maintains a set of protocol timers.
- */
-static void prvIPTask( void *pvParameters );
-
-/*
- * Called when new data is available from the network interface.
- */
-static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
-
-/*
- * Process incoming IP packets.
- */
-static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * const pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer );
-
-#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
- /*
- * Process incoming ICMP packets.
- */
- static eFrameProcessingResult_t prvProcessICMPPacket( ICMPPacket_t * const pxICMPPacket );
-#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */
-
-/*
- * Turns around an incoming ping request to convert it into a ping reply.
- */
-#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 )
- static eFrameProcessingResult_t prvProcessICMPEchoRequest( ICMPPacket_t * const pxICMPPacket );
-#endif /* ipconfigREPLY_TO_INCOMING_PINGS */
-
-/*
- * Processes incoming ping replies. The application callback function
- * vApplicationPingReplyHook() is called with the results.
- */
-#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
- static void prvProcessICMPEchoReply( ICMPPacket_t * const pxICMPPacket );
-#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
-
-/*
- * Called to create a network connection when the stack is first started, or
- * when the network connection is lost.
- */
-static void prvProcessNetworkDownEvent( void );
-
-/*
- * Checks the ARP, DHCP and TCP timers to see if any periodic or timeout
- * processing is required.
- */
-static void prvCheckNetworkTimers( void );
-
-/*
- * Determine how long the IP task can sleep for, which depends on when the next
- * periodic or timeout processing must be performed.
- */
-static TickType_t prvCalculateSleepTime( void );
-
-/*
- * The network card driver has received a packet. In the case that it is part
- * of a linked packet chain, walk through it to handle every message.
- */
-static void prvHandleEthernetPacket( NetworkBufferDescriptor_t *pxBuffer );
-
-/*
- * Utility functions for the light weight IP timers.
- */
-static void prvIPTimerStart( IPTimer_t *pxTimer, TickType_t xTime );
-static BaseType_t prvIPTimerCheck( IPTimer_t *pxTimer );
-static void prvIPTimerReload( IPTimer_t *pxTimer, TickType_t xTime );
-
-static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPPacket,
- NetworkBufferDescriptor_t * const pxNetworkBuffer, UBaseType_t uxHeaderLength );
-
-/*-----------------------------------------------------------*/
-
-/* The queue used to pass events into the IP-task for processing. */
-QueueHandle_t xNetworkEventQueue = NULL;
-
-/*_RB_ Requires comment. */
-uint16_t usPacketIdentifier = 0U;
-
-/* For convenience, a MAC address of all 0xffs is defined const for quick
-reference. */
-const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
-
-/* Structure that stores the netmask, gateway address and DNS server addresses. */
-NetworkAddressingParameters_t xNetworkAddressing = { 0, 0, 0, 0, 0 };
-
-/* Default values for the above struct in case DHCP
-does not lead to a confirmed request. */
-NetworkAddressingParameters_t xDefaultAddressing = { 0, 0, 0, 0, 0 };
-
-/* Used to ensure network down events cannot be missed when they cannot be
-posted to the network event queue because the network event queue is already
-full. */
-static BaseType_t xNetworkDownEventPending = pdFALSE;
-
-/* Stores the handle of the task that handles the stack. The handle is used
-(indirectly) by some utility function to determine if the utility function is
-being called by a task (in which case it is ok to block) or by the IP task
-itself (in which case it is not ok to block). */
-static TaskHandle_t xIPTaskHandle = NULL;
-
-#if( ipconfigUSE_TCP != 0 )
- /* Set to a non-zero value if one or more TCP message have been processed
- within the last round. */
- static BaseType_t xProcessedTCPMessage;
-#endif
-
-/* Simple set to pdTRUE or pdFALSE depending on whether the network is up or
-down (connected, not connected) respectively. */
-static BaseType_t xNetworkUp = pdFALSE;
-
-/*
-A timer for each of the following processes, all of which need attention on a
-regular basis:
- 1. ARP, to check its table entries
- 2. DPHC, to send requests and to renew a reservation
- 3. TCP, to check for timeouts, resends
- 4. DNS, to check for timeouts when looking-up a domain.
- */
-static IPTimer_t xARPTimer;
-#if( ipconfigUSE_DHCP != 0 )
- static IPTimer_t xDHCPTimer;
-#endif
-#if( ipconfigUSE_TCP != 0 )
- static IPTimer_t xTCPTimer;
-#endif
-#if( ipconfigDNS_USE_CALLBACKS != 0 )
- static IPTimer_t xDNSTimer;
-#endif
-
-/* Set to pdTRUE when the IP task is ready to start processing packets. */
-static BaseType_t xIPTaskInitialised = pdFALSE;
-
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- /* Keep track of the lowest amount of space in 'xNetworkEventQueue'. */
- static UBaseType_t uxQueueMinimumSpace = ipconfigEVENT_QUEUE_LENGTH;
-#endif
-
-/*-----------------------------------------------------------*/
-
-static void prvIPTask( void *pvParameters )
-{
-IPStackEvent_t xReceivedEvent;
-TickType_t xNextIPSleep;
-FreeRTOS_Socket_t *pxSocket;
-struct freertos_sockaddr xAddress;
-
- /* Just to prevent compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* A possibility to set some additional task properties. */
- iptraceIP_TASK_STARTING();
-
- /* Generate a dummy message to say that the network connection has gone
- down. This will cause this task to initialise the network interface. After
- this it is the responsibility of the network interface hardware driver to
- send this message if a previously connected network is disconnected. */
- FreeRTOS_NetworkDown();
-
- #if( ipconfigUSE_TCP == 1 )
- {
- /* Initialise the TCP timer. */
- prvIPTimerReload( &xTCPTimer, pdMS_TO_TICKS( ipTCP_TIMER_PERIOD_MS ) );
- }
- #endif
-
- /* Initialisation is complete and events can now be processed. */
- xIPTaskInitialised = pdTRUE;
-
- FreeRTOS_debug_printf( ( "prvIPTask started\n" ) );
-
- /* Loop, processing IP events. */
- for( ;; )
- {
- ipconfigWATCHDOG_TIMER();
-
- /* Check the ARP, DHCP and TCP timers to see if there is any periodic
- or timeout processing to perform. */
- prvCheckNetworkTimers();
-
- /* Calculate the acceptable maximum sleep time. */
- xNextIPSleep = prvCalculateSleepTime();
-
- /* Wait until there is something to do. If the following call exits
- * due to a time out rather than a message being received, set a
- * 'NoEvent' value. */
- if ( xQueueReceive( xNetworkEventQueue, ( void * ) &xReceivedEvent, xNextIPSleep ) == pdFALSE )
- {
- xReceivedEvent.eEventType = eNoEvent;
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- if( xReceivedEvent.eEventType != eNoEvent )
- {
- UBaseType_t uxCount;
-
- uxCount = uxQueueSpacesAvailable( xNetworkEventQueue );
- if( uxQueueMinimumSpace > uxCount )
- {
- uxQueueMinimumSpace = uxCount;
- }
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- iptraceNETWORK_EVENT_RECEIVED( xReceivedEvent.eEventType );
-
- switch( xReceivedEvent.eEventType )
- {
- case eNetworkDownEvent :
- /* Attempt to establish a connection. */
- xNetworkUp = pdFALSE;
- prvProcessNetworkDownEvent();
- break;
-
- case eNetworkRxEvent:
- /* The network hardware driver has received a new packet. A
- pointer to the received buffer is located in the pvData member
- of the received event structure. */
- prvHandleEthernetPacket( ( NetworkBufferDescriptor_t * ) ( xReceivedEvent.pvData ) );
- break;
-
- case eARPTimerEvent :
- /* The ARP timer has expired, process the ARP cache. */
- vARPAgeCache();
- break;
-
- case eSocketBindEvent:
- /* FreeRTOS_bind (a user API) wants the IP-task to bind a socket
- to a port. The port number is communicated in the socket field
- usLocalPort. vSocketBind() will actually bind the socket and the
- API will unblock as soon as the eSOCKET_BOUND event is
- triggered. */
- pxSocket = ( FreeRTOS_Socket_t * ) ( xReceivedEvent.pvData );
- xAddress.sin_addr = 0u; /* For the moment. */
- xAddress.sin_port = FreeRTOS_ntohs( pxSocket->usLocalPort );
- pxSocket->usLocalPort = 0u;
- vSocketBind( pxSocket, &xAddress, sizeof( xAddress ), pdFALSE );
-
- /* Before 'eSocketBindEvent' was sent it was tested that
- ( xEventGroup != NULL ) so it can be used now to wake up the
- user. */
- pxSocket->xEventBits |= eSOCKET_BOUND;
- vSocketWakeUpUser( pxSocket );
- break;
-
- case eSocketCloseEvent :
- /* The user API FreeRTOS_closesocket() has sent a message to the
- IP-task to actually close a socket. This is handled in
- vSocketClose(). As the socket gets closed, there is no way to
- report back to the API, so the API won't wait for the result */
- vSocketClose( ( FreeRTOS_Socket_t * ) ( xReceivedEvent.pvData ) );
- break;
-
- case eStackTxEvent :
- /* The network stack has generated a packet to send. A
- pointer to the generated buffer is located in the pvData
- member of the received event structure. */
- vProcessGeneratedUDPPacket( ( NetworkBufferDescriptor_t * ) ( xReceivedEvent.pvData ) );
- break;
-
- case eDHCPEvent:
- /* The DHCP state machine needs processing. */
- #if( ipconfigUSE_DHCP == 1 )
- {
- vDHCPProcess( pdFALSE );
- }
- #endif /* ipconfigUSE_DHCP */
- break;
-
- case eSocketSelectEvent :
- /* FreeRTOS_select() has got unblocked by a socket event,
- vSocketSelect() will check which sockets actually have an event
- and update the socket field xSocketBits. */
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- vSocketSelect( ( SocketSelect_t * ) ( xReceivedEvent.pvData ) );
- }
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
- break;
-
- case eSocketSignalEvent :
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- /* Some task wants to signal the user of this socket in
- order to interrupt a call to recv() or a call to select(). */
- FreeRTOS_SignalSocket( ( Socket_t ) xReceivedEvent.pvData );
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
- break;
-
- case eTCPTimerEvent :
- #if( ipconfigUSE_TCP == 1 )
- {
- /* Simply mark the TCP timer as expired so it gets processed
- the next time prvCheckNetworkTimers() is called. */
- xTCPTimer.bExpired = pdTRUE_UNSIGNED;
- }
- #endif /* ipconfigUSE_TCP */
- break;
-
- case eTCPAcceptEvent:
- /* The API FreeRTOS_accept() was called, the IP-task will now
- check if the listening socket (communicated in pvData) actually
- received a new connection. */
- #if( ipconfigUSE_TCP == 1 )
- {
- pxSocket = ( FreeRTOS_Socket_t * ) ( xReceivedEvent.pvData );
-
- if( xTCPCheckNewClient( pxSocket ) != pdFALSE )
- {
- pxSocket->xEventBits |= eSOCKET_ACCEPT;
- vSocketWakeUpUser( pxSocket );
- }
- }
- #endif /* ipconfigUSE_TCP */
- break;
-
- case eTCPNetStat:
- /* FreeRTOS_netstat() was called to have the IP-task print an
- overview of all sockets and their connections */
- #if( ( ipconfigUSE_TCP == 1 ) && ( ipconfigHAS_PRINTF == 1 ) )
- {
- vTCPNetStat();
- }
- #endif /* ipconfigUSE_TCP */
- break;
-
- default :
- /* Should not get here. */
- break;
- }
-
- if( xNetworkDownEventPending != pdFALSE )
- {
- /* A network down event could not be posted to the network event
- queue because the queue was full. Try posting again. */
- FreeRTOS_NetworkDown();
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xIsCallingFromIPTask( void )
-{
-BaseType_t xReturn;
-
- if( xTaskGetCurrentTaskHandle() == xIPTaskHandle )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void prvHandleEthernetPacket( NetworkBufferDescriptor_t *pxBuffer )
-{
- #if( ipconfigUSE_LINKED_RX_MESSAGES == 0 )
- {
- /* When ipconfigUSE_LINKED_RX_MESSAGES is not set to 0 then only one
- buffer will be sent at a time. This is the default way for +TCP to pass
- messages from the MAC to the TCP/IP stack. */
- prvProcessEthernetPacket( pxBuffer );
- }
- #else /* ipconfigUSE_LINKED_RX_MESSAGES */
- {
- NetworkBufferDescriptor_t *pxNextBuffer;
-
- /* An optimisation that is useful when there is high network traffic.
- Instead of passing received packets into the IP task one at a time the
- network interface can chain received packets together and pass them into
- the IP task in one go. The packets are chained using the pxNextBuffer
- member. The loop below walks through the chain processing each packet
- in the chain in turn. */
- do
- {
- /* Store a pointer to the buffer after pxBuffer for use later on. */
- pxNextBuffer = pxBuffer->pxNextBuffer;
-
- /* Make it NULL to avoid using it later on. */
- pxBuffer->pxNextBuffer = NULL;
-
- prvProcessEthernetPacket( pxBuffer );
- pxBuffer = pxNextBuffer;
-
- /* While there is another packet in the chain. */
- } while( pxBuffer != NULL );
- }
- #endif /* ipconfigUSE_LINKED_RX_MESSAGES */
-}
-/*-----------------------------------------------------------*/
-
-static TickType_t prvCalculateSleepTime( void )
-{
-TickType_t xMaximumSleepTime;
-
- /* Start with the maximum sleep time, then check this against the remaining
- time in any other timers that are active. */
- xMaximumSleepTime = ipconfigMAX_IP_TASK_SLEEP_TIME;
-
- if( xARPTimer.bActive != pdFALSE_UNSIGNED )
- {
- if( xARPTimer.ulRemainingTime < xMaximumSleepTime )
- {
- xMaximumSleepTime = xARPTimer.ulReloadTime;
- }
- }
-
- #if( ipconfigUSE_DHCP == 1 )
- {
- if( xDHCPTimer.bActive != pdFALSE_UNSIGNED )
- {
- if( xDHCPTimer.ulRemainingTime < xMaximumSleepTime )
- {
- xMaximumSleepTime = xDHCPTimer.ulRemainingTime;
- }
- }
- }
- #endif /* ipconfigUSE_DHCP */
-
- #if( ipconfigUSE_TCP == 1 )
- {
- if( xTCPTimer.ulRemainingTime < xMaximumSleepTime )
- {
- xMaximumSleepTime = xTCPTimer.ulRemainingTime;
- }
- }
- #endif
-
- #if( ipconfigDNS_USE_CALLBACKS != 0 )
- {
- if( xDNSTimer.bActive != pdFALSE )
- {
- if( xDNSTimer.ulRemainingTime < xMaximumSleepTime )
- {
- xMaximumSleepTime = xDNSTimer.ulRemainingTime;
- }
- }
- }
- #endif
-
- return xMaximumSleepTime;
-}
-/*-----------------------------------------------------------*/
-
-static void prvCheckNetworkTimers( void )
-{
- /* Is it time for ARP processing? */
- if( prvIPTimerCheck( &xARPTimer ) != pdFALSE )
- {
- xSendEventToIPTask( eARPTimerEvent );
- }
-
- #if( ipconfigUSE_DHCP == 1 )
- {
- /* Is it time for DHCP processing? */
- if( prvIPTimerCheck( &xDHCPTimer ) != pdFALSE )
- {
- xSendEventToIPTask( eDHCPEvent );
- }
- }
- #endif /* ipconfigUSE_DHCP */
-
- #if( ipconfigDNS_USE_CALLBACKS != 0 )
- {
- extern void vDNSCheckCallBack( void *pvSearchID );
-
- /* Is it time for DNS processing? */
- if( prvIPTimerCheck( &xDNSTimer ) != pdFALSE )
- {
- vDNSCheckCallBack( NULL );
- }
- }
- #endif /* ipconfigDNS_USE_CALLBACKS */
-
- #if( ipconfigUSE_TCP == 1 )
- {
- BaseType_t xWillSleep;
- TickType_t xNextTime;
- BaseType_t xCheckTCPSockets;
-
- if( uxQueueMessagesWaiting( xNetworkEventQueue ) == 0u )
- {
- xWillSleep = pdTRUE;
- }
- else
- {
- xWillSleep = pdFALSE;
- }
-
- /* Sockets need to be checked if the TCP timer has expired. */
- xCheckTCPSockets = prvIPTimerCheck( &xTCPTimer );
-
- /* Sockets will also be checked if there are TCP messages but the
- message queue is empty (indicated by xWillSleep being true). */
- if( ( xProcessedTCPMessage != pdFALSE ) && ( xWillSleep != pdFALSE ) )
- {
- xCheckTCPSockets = pdTRUE;
- }
-
- if( xCheckTCPSockets != pdFALSE )
- {
- /* Attend to the sockets, returning the period after which the
- check must be repeated. */
- xNextTime = xTCPTimerCheck( xWillSleep );
- prvIPTimerStart( &xTCPTimer, xNextTime );
- xProcessedTCPMessage = 0;
- }
- }
- #endif /* ipconfigUSE_TCP == 1 */
-}
-/*-----------------------------------------------------------*/
-
-static void prvIPTimerStart( IPTimer_t *pxTimer, TickType_t xTime )
-{
- vTaskSetTimeOutState( &pxTimer->xTimeOut );
- pxTimer->ulRemainingTime = xTime;
-
- if( xTime == ( TickType_t ) 0 )
- {
- pxTimer->bExpired = pdTRUE_UNSIGNED;
- }
- else
- {
- pxTimer->bExpired = pdFALSE_UNSIGNED;
- }
-
- pxTimer->bActive = pdTRUE_UNSIGNED;
-}
-/*-----------------------------------------------------------*/
-
-static void prvIPTimerReload( IPTimer_t *pxTimer, TickType_t xTime )
-{
- pxTimer->ulReloadTime = xTime;
- prvIPTimerStart( pxTimer, xTime );
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvIPTimerCheck( IPTimer_t *pxTimer )
-{
-BaseType_t xReturn;
-
- if( pxTimer->bActive == pdFALSE_UNSIGNED )
- {
- /* The timer is not enabled. */
- xReturn = pdFALSE;
- }
- else
- {
- /* The timer might have set the bExpired flag already, if not, check the
- value of xTimeOut against ulRemainingTime. */
- if( ( pxTimer->bExpired != pdFALSE_UNSIGNED ) ||
- ( xTaskCheckForTimeOut( &( pxTimer->xTimeOut ), &( pxTimer->ulRemainingTime ) ) != pdFALSE ) )
- {
- prvIPTimerStart( pxTimer, pxTimer->ulReloadTime );
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_NetworkDown( void )
-{
-static const IPStackEvent_t xNetworkDownEvent = { eNetworkDownEvent, NULL };
-const TickType_t xDontBlock = ( TickType_t ) 0;
-
- /* Simply send the network task the appropriate event. */
- if( xSendEventStructToIPTask( &xNetworkDownEvent, xDontBlock ) != pdPASS )
- {
- /* Could not send the message, so it is still pending. */
- xNetworkDownEventPending = pdTRUE;
- }
- else
- {
- /* Message was sent so it is not pending. */
- xNetworkDownEventPending = pdFALSE;
- }
-
- iptraceNETWORK_DOWN();
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t FreeRTOS_NetworkDownFromISR( void )
-{
-static const IPStackEvent_t xNetworkDownEvent = { eNetworkDownEvent, NULL };
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* Simply send the network task the appropriate event. */
- if( xQueueSendToBackFromISR( xNetworkEventQueue, &xNetworkDownEvent, &xHigherPriorityTaskWoken ) != pdPASS )
- {
- xNetworkDownEventPending = pdTRUE;
- }
- else
- {
- xNetworkDownEventPending = pdFALSE;
- }
-
- iptraceNETWORK_DOWN();
-
- return xHigherPriorityTaskWoken;
-}
-/*-----------------------------------------------------------*/
-
-void *FreeRTOS_GetUDPPayloadBuffer( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-void *pvReturn;
-
- /* Cap the block time. The reason for this is explained where
- ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined (assuming an official
- FreeRTOSIPConfig.h header file is being used). */
- if( xBlockTimeTicks > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS )
- {
- xBlockTimeTicks = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
- }
-
- /* Obtain a network buffer with the required amount of storage. */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( UDPPacket_t ) + xRequestedSizeBytes, xBlockTimeTicks );
-
- if( pxNetworkBuffer != NULL )
- {
- /* Set the actual packet size in case a bigger buffer was returned. */
- pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ) + xRequestedSizeBytes;
-
- /* Leave space for the UPD header. */
- pvReturn = ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
- }
- else
- {
- pvReturn = NULL;
- }
-
- return ( void * ) pvReturn;
-}
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxDuplicateNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer,
- BaseType_t xNewLength )
-{
-NetworkBufferDescriptor_t * pxNewBuffer;
-
- /* This function is only used when 'ipconfigZERO_COPY_TX_DRIVER' is set to 1.
- The transmit routine wants to have ownership of the network buffer
- descriptor, because it will pass the buffer straight to DMA. */
- pxNewBuffer = pxGetNetworkBufferWithDescriptor( ( size_t ) xNewLength, ( TickType_t ) 0 );
-
- if( pxNewBuffer != NULL )
- {
- /* Set the actual packet size in case a bigger buffer than requested
- was returned. */
- pxNewBuffer->xDataLength = xNewLength;
-
- /* Copy the original packet information. */
- pxNewBuffer->ulIPAddress = pxNetworkBuffer->ulIPAddress;
- pxNewBuffer->usPort = pxNetworkBuffer->usPort;
- pxNewBuffer->usBoundPort = pxNetworkBuffer->usBoundPort;
- memcpy( pxNewBuffer->pucEthernetBuffer, pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
- }
-
- return pxNewBuffer;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 ) || ( ipconfigZERO_COPY_RX_DRIVER != 0 )
-
- NetworkBufferDescriptor_t *pxPacketBuffer_to_NetworkBuffer( const void *pvBuffer )
- {
- uint8_t *pucBuffer;
- NetworkBufferDescriptor_t *pxResult;
-
- if( pvBuffer == NULL )
- {
- pxResult = NULL;
- }
- else
- {
- /* Obtain the network buffer from the zero copy pointer. */
- pucBuffer = ( uint8_t * ) pvBuffer;
-
- /* The input here is a pointer to a payload buffer. Subtract the
- size of the header in the network buffer, usually 8 + 2 bytes. */
- pucBuffer -= ipBUFFER_PADDING;
-
- /* Here a pointer was placed to the network descriptor. As a
- pointer is dereferenced, make sure it is well aligned. */
- if( ( ( ( uint32_t ) pucBuffer ) & ( sizeof( pucBuffer ) - ( size_t ) 1 ) ) == ( uint32_t ) 0 )
- {
- pxResult = * ( ( NetworkBufferDescriptor_t ** ) pucBuffer );
- }
- else
- {
- pxResult = NULL;
- }
- }
-
- return pxResult;
- }
-
-#endif /* ipconfigZERO_COPY_TX_DRIVER != 0 */
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxUDPPayloadBuffer_to_NetworkBuffer( void *pvBuffer )
-{
-uint8_t *pucBuffer;
-NetworkBufferDescriptor_t *pxResult;
-
- if( pvBuffer == NULL )
- {
- pxResult = NULL;
- }
- else
- {
- /* Obtain the network buffer from the zero copy pointer. */
- pucBuffer = ( uint8_t * ) pvBuffer;
-
- /* The input here is a pointer to a payload buffer. Subtract
- the total size of a UDP/IP header plus the size of the header in
- the network buffer, usually 8 + 2 bytes. */
- pucBuffer -= ( sizeof( UDPPacket_t ) + ipBUFFER_PADDING );
-
- /* Here a pointer was placed to the network descriptor,
- As a pointer is dereferenced, make sure it is well aligned */
- if( ( ( ( uint32_t ) pucBuffer ) & ( sizeof( pucBuffer ) - 1 ) ) == 0 )
- {
- /* The following statement may trigger a:
- warning: cast increases required alignment of target type [-Wcast-align].
- It has been confirmed though that the alignment is suitable. */
- pxResult = * ( ( NetworkBufferDescriptor_t ** ) pucBuffer );
- }
- else
- {
- pxResult = NULL;
- }
- }
-
- return pxResult;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_ReleaseUDPPayloadBuffer( void *pvBuffer )
-{
- vReleaseNetworkBufferAndDescriptor( pxUDPPayloadBuffer_to_NetworkBuffer( pvBuffer ) );
-}
-/*-----------------------------------------------------------*/
-
-/*_RB_ Should we add an error or assert if the task priorities are set such that the servers won't function as expected? */
-/*_HT_ There was a bug in FreeRTOS_TCP_IP.c that only occurred when the applications' priority was too high.
- As that bug has been repaired, there is not an urgent reason to warn.
- It is better though to use the advised priority scheme. */
-BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ], const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ], const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ], const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ], const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] )
-{
-BaseType_t xReturn = pdFALSE;
-
- /* This function should only be called once. */
- configASSERT( xIPIsNetworkTaskReady() == pdFALSE );
- configASSERT( xNetworkEventQueue == NULL );
- configASSERT( xIPTaskHandle == NULL );
-
- /* Check structure packing is correct. */
- configASSERT( sizeof( EthernetHeader_t ) == ipEXPECTED_EthernetHeader_t_SIZE );
- configASSERT( sizeof( ARPHeader_t ) == ipEXPECTED_ARPHeader_t_SIZE );
- configASSERT( sizeof( IPHeader_t ) == ipEXPECTED_IPHeader_t_SIZE );
- configASSERT( sizeof( ICMPHeader_t ) == ipEXPECTED_ICMPHeader_t_SIZE );
- configASSERT( sizeof( UDPHeader_t ) == ipEXPECTED_UDPHeader_t_SIZE );
-
- /* Attempt to create the queue used to communicate with the IP task. */
- xNetworkEventQueue = xQueueCreate( ( UBaseType_t ) ipconfigEVENT_QUEUE_LENGTH, ( UBaseType_t ) sizeof( IPStackEvent_t ) );
- configASSERT( xNetworkEventQueue );
-
- if( xNetworkEventQueue != NULL )
- {
- #if ( configQUEUE_REGISTRY_SIZE > 0 )
- {
- /* A queue registry is normally used to assist a kernel aware
- debugger. If one is in use then it will be helpful for the debugger
- to show information about the network event queue. */
- vQueueAddToRegistry( xNetworkEventQueue, "NetEvnt" );
- }
- #endif /* configQUEUE_REGISTRY_SIZE */
-
- if( xNetworkBuffersInitialise() == pdPASS )
- {
- /* Store the local IP and MAC address. */
- xNetworkAddressing.ulDefaultIPAddress = FreeRTOS_inet_addr_quick( ucIPAddress[ 0 ], ucIPAddress[ 1 ], ucIPAddress[ 2 ], ucIPAddress[ 3 ] );
- xNetworkAddressing.ulNetMask = FreeRTOS_inet_addr_quick( ucNetMask[ 0 ], ucNetMask[ 1 ], ucNetMask[ 2 ], ucNetMask[ 3 ] );
- xNetworkAddressing.ulGatewayAddress = FreeRTOS_inet_addr_quick( ucGatewayAddress[ 0 ], ucGatewayAddress[ 1 ], ucGatewayAddress[ 2 ], ucGatewayAddress[ 3 ] );
- xNetworkAddressing.ulDNSServerAddress = FreeRTOS_inet_addr_quick( ucDNSServerAddress[ 0 ], ucDNSServerAddress[ 1 ], ucDNSServerAddress[ 2 ], ucDNSServerAddress[ 3 ] );
- xNetworkAddressing.ulBroadcastAddress = ( xNetworkAddressing.ulDefaultIPAddress & xNetworkAddressing.ulNetMask ) | ~xNetworkAddressing.ulNetMask;
-
- memcpy( &xDefaultAddressing, &xNetworkAddressing, sizeof( xDefaultAddressing ) );
-
- #if ipconfigUSE_DHCP == 1
- {
- /* The IP address is not set until DHCP completes. */
- *ipLOCAL_IP_ADDRESS_POINTER = 0x00UL;
- }
- #else
- {
- /* The IP address is set from the value passed in. */
- *ipLOCAL_IP_ADDRESS_POINTER = xNetworkAddressing.ulDefaultIPAddress;
-
- /* Added to prevent ARP flood to gateway. Ensure the
- gateway is on the same subnet as the IP address. */
- configASSERT( ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) == ( xNetworkAddressing.ulGatewayAddress & xNetworkAddressing.ulNetMask ) );
- }
- #endif /* ipconfigUSE_DHCP == 1 */
-
- /* The MAC address is stored in the start of the default packet
- header fragment, which is used when sending UDP packets. */
- memcpy( ( void * ) ipLOCAL_MAC_ADDRESS, ( void * ) ucMACAddress, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
-
- /* Prepare the sockets interface. */
- xReturn = vNetworkSocketsInit();
-
- if( pdTRUE == xReturn )
- {
- /* Create the task that processes Ethernet and stack events. */
- xReturn = xTaskCreate( prvIPTask, "IP-task", ( uint16_t )ipconfigIP_TASK_STACK_SIZE_WORDS, NULL, ( UBaseType_t )ipconfigIP_TASK_PRIORITY, &xIPTaskHandle );
- }
- }
- else
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_IPInit: xNetworkBuffersInitialise() failed\n") );
-
- /* Clean up. */
- vQueueDelete( xNetworkEventQueue );
- xNetworkEventQueue = NULL;
- }
- }
- else
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_IPInit: Network event queue could not be created\n") );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_GetAddressConfiguration( uint32_t *pulIPAddress, uint32_t *pulNetMask, uint32_t *pulGatewayAddress, uint32_t *pulDNSServerAddress )
-{
- /* Return the address configuration to the caller. */
-
- if( pulIPAddress != NULL )
- {
- *pulIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
- }
-
- if( pulNetMask != NULL )
- {
- *pulNetMask = xNetworkAddressing.ulNetMask;
- }
-
- if( pulGatewayAddress != NULL )
- {
- *pulGatewayAddress = xNetworkAddressing.ulGatewayAddress;
- }
-
- if( pulDNSServerAddress != NULL )
- {
- *pulDNSServerAddress = xNetworkAddressing.ulDNSServerAddress;
- }
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, const uint32_t *pulNetMask, const uint32_t *pulGatewayAddress, const uint32_t *pulDNSServerAddress )
-{
- /* Update the address configuration. */
-
- if( pulIPAddress != NULL )
- {
- *ipLOCAL_IP_ADDRESS_POINTER = *pulIPAddress;
- }
-
- if( pulNetMask != NULL )
- {
- xNetworkAddressing.ulNetMask = *pulNetMask;
- }
-
- if( pulGatewayAddress != NULL )
- {
- xNetworkAddressing.ulGatewayAddress = *pulGatewayAddress;
- }
-
- if( pulDNSServerAddress != NULL )
- {
- xNetworkAddressing.ulDNSServerAddress = *pulDNSServerAddress;
- }
-}
-/*-----------------------------------------------------------*/
-
-#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
-
- BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t xNumberOfBytesToSend, TickType_t xBlockTimeTicks )
- {
- NetworkBufferDescriptor_t *pxNetworkBuffer;
- ICMPHeader_t *pxICMPHeader;
- BaseType_t xReturn = pdFAIL;
- static uint16_t usSequenceNumber = 0;
- uint8_t *pucChar;
- IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL };
-
- if( (xNumberOfBytesToSend >= 1 ) && ( xNumberOfBytesToSend < ( ( ipconfigNETWORK_MTU - sizeof( IPHeader_t ) ) - sizeof( ICMPHeader_t ) ) ) && ( uxGetNumberOfFreeNetworkBuffers() >= 3 ) )
- {
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( xNumberOfBytesToSend + sizeof( ICMPPacket_t ), xBlockTimeTicks );
-
- if( pxNetworkBuffer != NULL )
- {
- pxICMPHeader = ( ICMPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipIP_PAYLOAD_OFFSET ] );
- usSequenceNumber++;
-
- /* Fill in the basic header information. */
- pxICMPHeader->ucTypeOfMessage = ipICMP_ECHO_REQUEST;
- pxICMPHeader->ucTypeOfService = 0;
- pxICMPHeader->usIdentifier = usSequenceNumber;
- pxICMPHeader->usSequenceNumber = usSequenceNumber;
-
- /* Find the start of the data. */
- pucChar = ( uint8_t * ) pxICMPHeader;
- pucChar += sizeof( ICMPHeader_t );
-
- /* Just memset the data to a fixed value. */
- memset( ( void * ) pucChar, ( int ) ipECHO_DATA_FILL_BYTE, xNumberOfBytesToSend );
-
- /* The message is complete, IP and checksum's are handled by
- vProcessGeneratedUDPPacket */
- pxNetworkBuffer->pucEthernetBuffer[ ipSOCKET_OPTIONS_OFFSET ] = FREERTOS_SO_UDPCKSUM_OUT;
- pxNetworkBuffer->ulIPAddress = ulIPAddress;
- pxNetworkBuffer->usPort = ipPACKET_CONTAINS_ICMP_DATA;
- pxNetworkBuffer->xDataLength = xNumberOfBytesToSend + sizeof( ICMPHeader_t );
-
- /* Send to the stack. */
- xStackTxEvent.pvData = pxNetworkBuffer;
-
- if( xSendEventStructToIPTask( &xStackTxEvent, xBlockTimeTicks) != pdPASS )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- iptraceSTACK_TX_EVENT_LOST( ipSTACK_TX_EVENT );
- }
- else
- {
- xReturn = usSequenceNumber;
- }
- }
- }
- else
- {
- /* The requested number of bytes will not fit in the available space
- in the network buffer. */
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigSUPPORT_OUTGOING_PINGS == 1 */
-/*-----------------------------------------------------------*/
-
-BaseType_t xSendEventToIPTask( eIPEvent_t eEvent )
-{
-IPStackEvent_t xEventMessage;
-const TickType_t xDontBlock = ( TickType_t ) 0;
-
- xEventMessage.eEventType = eEvent;
- xEventMessage.pvData = ( void* )NULL;
-
- return xSendEventStructToIPTask( &xEventMessage, xDontBlock );
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xSendEventStructToIPTask( const IPStackEvent_t *pxEvent, TickType_t xTimeout )
-{
-BaseType_t xReturn, xSendMessage;
-
- if( ( xIPIsNetworkTaskReady() == pdFALSE ) && ( pxEvent->eEventType != eNetworkDownEvent ) )
- {
- /* Only allow eNetworkDownEvent events if the IP task is not ready
- yet. Not going to attempt to send the message so the send failed. */
- xReturn = pdFAIL;
- }
- else
- {
- xSendMessage = pdTRUE;
-
- #if( ipconfigUSE_TCP == 1 )
- {
- if( pxEvent->eEventType == eTCPTimerEvent )
- {
- /* TCP timer events are sent to wake the timer task when
- xTCPTimer has expired, but there is no point sending them if the
- IP task is already awake processing other message. */
- xTCPTimer.bExpired = pdTRUE_UNSIGNED;
-
- if( uxQueueMessagesWaiting( xNetworkEventQueue ) != 0u )
- {
- /* Not actually going to send the message but this is not a
- failure as the message didn't need to be sent. */
- xSendMessage = pdFALSE;
- }
- }
- }
- #endif /* ipconfigUSE_TCP */
-
- if( xSendMessage != pdFALSE )
- {
- /* The IP task cannot block itself while waiting for itself to
- respond. */
- if( ( xIsCallingFromIPTask() == pdTRUE ) && ( xTimeout > ( TickType_t ) 0 ) )
- {
- xTimeout = ( TickType_t ) 0;
- }
-
- xReturn = xQueueSendToBack( xNetworkEventQueue, pxEvent, xTimeout );
-
- if( xReturn == pdFAIL )
- {
- /* A message should have been sent to the IP task, but wasn't. */
- FreeRTOS_debug_printf( ( "xSendEventStructToIPTask: CAN NOT ADD %d\n", pxEvent->eEventType ) );
- iptraceSTACK_TX_EVENT_LOST( pxEvent->eEventType );
- }
- }
- else
- {
- /* It was not necessary to send the message to process the event so
- even though the message was not sent the call was successful. */
- xReturn = pdPASS;
- }
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer )
-{
-eFrameProcessingResult_t eReturn;
-const EthernetHeader_t *pxEthernetHeader;
-
- pxEthernetHeader = ( const EthernetHeader_t * ) pucEthernetBuffer;
-
- if( memcmp( ( void * ) ipLOCAL_MAC_ADDRESS, ( void * ) &( pxEthernetHeader->xDestinationAddress ), sizeof( MACAddress_t ) ) == 0 )
- {
- /* The packet was directed to this node directly - process it. */
- eReturn = eProcessBuffer;
- }
- else if( memcmp( ( void * ) xBroadcastMACAddress.ucBytes, ( void * ) pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 )
- {
- /* The packet was a broadcast - process it. */
- eReturn = eProcessBuffer;
- }
- else
-#if( ipconfigUSE_LLMNR == 1 )
- if( memcmp( ( void * ) xLLMNR_MacAdress.ucBytes, ( void * ) pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 )
- {
- /* The packet is a request for LLMNR - process it. */
- eReturn = eProcessBuffer;
- }
- else
-#endif /* ipconfigUSE_LLMNR */
- {
- /* The packet was not a broadcast, or for this node, just release
- the buffer without taking any other action. */
- eReturn = eReleaseBuffer;
- }
-
- #if( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES == 1 )
- {
- uint16_t usFrameType;
-
- if( eReturn == eProcessBuffer )
- {
- usFrameType = pxEthernetHeader->usFrameType;
- usFrameType = FreeRTOS_ntohs( usFrameType );
-
- if( usFrameType <= 0x600U )
- {
- /* Not an Ethernet II frame. */
- eReturn = eReleaseBuffer;
- }
- }
- }
- #endif /* ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES == 1 */
-
- return eReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void prvProcessNetworkDownEvent( void )
-{
- /* Stop the ARP timer while there is no network. */
- xARPTimer.bActive = pdFALSE_UNSIGNED;
-
- #if ipconfigUSE_NETWORK_EVENT_HOOK == 1
- {
- static BaseType_t xCallEventHook = pdFALSE;
-
- /* The first network down event is generated by the IP stack itself to
- initialise the network hardware, so do not call the network down event
- the first time through. */
- if( xCallEventHook == pdTRUE )
- {
- vApplicationIPNetworkEventHook( eNetworkDown );
- }
- xCallEventHook = pdTRUE;
- }
- #endif
-
- /* The network has been disconnected (or is being initialised for the first
- time). Perform whatever hardware processing is necessary to bring it up
- again, or wait for it to be available again. This is hardware dependent. */
- if( xNetworkInterfaceInitialise() != pdPASS )
- {
- /* Ideally the network interface initialisation function will only
- return when the network is available. In case this is not the case,
- wait a while before retrying the initialisation. */
- vTaskDelay( ipINITIALISATION_RETRY_DELAY );
- FreeRTOS_NetworkDown();
- }
- else
- {
- /* Set remaining time to 0 so it will become active immediately. */
- #if ipconfigUSE_DHCP == 1
- {
- /* The network is not up until DHCP has completed. */
- vDHCPProcess( pdTRUE );
- xSendEventToIPTask( eDHCPEvent );
- }
- #else
- {
- /* Perform any necessary 'network up' processing. */
- vIPNetworkUpCalls();
- }
- #endif
- }
-}
-/*-----------------------------------------------------------*/
-
-void vIPNetworkUpCalls( void )
-{
- xNetworkUp = pdTRUE;
-
- #if( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
- {
- vApplicationIPNetworkEventHook( eNetworkUp );
- }
- #endif /* ipconfigUSE_NETWORK_EVENT_HOOK */
-
- #if( ipconfigDNS_USE_CALLBACKS != 0 )
- {
- /* The following function is declared in FreeRTOS_DNS.c and 'private' to
- this library */
- extern void vDNSInitialise( void );
- vDNSInitialise();
- }
- #endif /* ipconfigDNS_USE_CALLBACKS != 0 */
-
- /* Set remaining time to 0 so it will become active immediately. */
- prvIPTimerReload( &xARPTimer, pdMS_TO_TICKS( ipARP_TIMER_PERIOD_MS ) );
-}
-/*-----------------------------------------------------------*/
-
-static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-EthernetHeader_t *pxEthernetHeader;
-eFrameProcessingResult_t eReturned = eReleaseBuffer;
-
- configASSERT( pxNetworkBuffer );
-
- /* Interpret the Ethernet frame. */
- if( pxNetworkBuffer->xDataLength >= sizeof( EthernetHeader_t ) )
- {
- eReturned = ipCONSIDER_FRAME_FOR_PROCESSING( pxNetworkBuffer->pucEthernetBuffer );
- pxEthernetHeader = ( EthernetHeader_t * )( pxNetworkBuffer->pucEthernetBuffer );
-
- if( eReturned == eProcessBuffer )
- {
- /* Interpret the received Ethernet packet. */
- switch( pxEthernetHeader->usFrameType )
- {
- case ipARP_FRAME_TYPE:
- /* The Ethernet frame contains an ARP packet. */
- if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) )
- {
- eReturned = eARPProcessPacket( ( ARPPacket_t * )pxNetworkBuffer->pucEthernetBuffer );
- }
- else
- {
- eReturned = eReleaseBuffer;
- }
- break;
-
- case ipIPv4_FRAME_TYPE:
- /* The Ethernet frame contains an IP packet. */
- if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) )
- {
- eReturned = prvProcessIPPacket( ( IPPacket_t * )pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer );
- }
- else
- {
- eReturned = eReleaseBuffer;
- }
- break;
-
- default:
- /* No other packet types are handled. Nothing to do. */
- eReturned = eReleaseBuffer;
- break;
- }
- }
- }
-
- /* Perform any actions that resulted from processing the Ethernet frame. */
- switch( eReturned )
- {
- case eReturnEthernetFrame :
- /* The Ethernet frame will have been updated (maybe it was
- an ARP request or a PING request?) and should be sent back to
- its source. */
- vReturnEthernetFrame( pxNetworkBuffer, pdTRUE );
- /* parameter pdTRUE: the buffer must be released once
- the frame has been transmitted */
- break;
-
- case eFrameConsumed :
- /* The frame is in use somewhere, don't release the buffer
- yet. */
- break;
-
- default :
- /* The frame is not being used anywhere, and the
- NetworkBufferDescriptor_t structure containing the frame should
- just be released back to the list of free buffers. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- break;
- }
-}
-/*-----------------------------------------------------------*/
-
-static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPPacket,
- NetworkBufferDescriptor_t * const pxNetworkBuffer, UBaseType_t uxHeaderLength )
-{
-eFrameProcessingResult_t eReturn = eProcessBuffer;
-
-#if( ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 ) || ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 0 ) )
- const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );
-#else
- /* or else, the parameter won't be used and the function will be optimised
- away */
- ( void ) pxIPPacket;
-#endif
-
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 )
- {
- /* In systems with a very small amount of RAM, it might be advantageous
- to have incoming messages checked earlier, by the network card driver.
- This method may decrease the usage of sparse network buffers. */
- uint32_t ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;
-
- /* Ensure that the incoming packet is not fragmented (only outgoing
- packets can be fragmented) as these are the only handled IP frames
- currently. */
- if( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) != 0U )
- {
- /* Can not handle, fragmented packet. */
- eReturn = eReleaseBuffer;
- }
- /* 0x45 means: IPv4 with an IP header of 5 x 4 = 20 bytes
- * 0x47 means: IPv4 with an IP header of 7 x 4 = 28 bytes */
- else if( ( pxIPHeader->ucVersionHeaderLength < 0x45u ) || ( pxIPHeader->ucVersionHeaderLength > 0x4Fu ) )
- {
- /* Can not handle, unknown or invalid header version. */
- eReturn = eReleaseBuffer;
- }
- /* Is the packet for this IP address? */
- else if( ( ulDestinationIPAddress != *ipLOCAL_IP_ADDRESS_POINTER ) &&
- /* Is it the global broadcast address 255.255.255.255 ? */
- ( ulDestinationIPAddress != ipBROADCAST_IP_ADDRESS ) &&
- /* Is it a specific broadcast address 192.168.1.255 ? */
- ( ulDestinationIPAddress != xNetworkAddressing.ulBroadcastAddress ) &&
- #if( ipconfigUSE_LLMNR == 1 )
- /* Is it the LLMNR multicast address? */
- ( ulDestinationIPAddress != ipLLMNR_IP_ADDR ) &&
- #endif
- /* Or (during DHCP negotiation) we have no IP-address yet? */
- ( *ipLOCAL_IP_ADDRESS_POINTER != 0UL ) )
- {
- /* Packet is not for this node, release it */
- eReturn = eReleaseBuffer;
- }
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
-
- #if( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 0 )
- {
- /* Some drivers of NIC's with checksum-offloading will enable the above
- define, so that the checksum won't be checked again here */
- if (eReturn == eProcessBuffer )
- {
- /* Is the IP header checksum correct? */
- if( ( pxIPHeader->ucProtocol != ( uint8_t ) ipPROTOCOL_ICMP ) &&
- ( usGenerateChecksum( 0UL, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ( size_t ) uxHeaderLength ) != ipCORRECT_CRC ) )
- {
- /* Check sum in IP-header not correct. */
- eReturn = eReleaseBuffer;
- }
- /* Is the upper-layer checksum (TCP/UDP/ICMP) correct? */
- else if( usGenerateProtocolChecksum( ( uint8_t * )( pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer->xDataLength, pdFALSE ) != ipCORRECT_CRC )
- {
- /* Protocol checksum not accepted. */
- eReturn = eReleaseBuffer;
- }
- }
- }
- #else
- {
- /* to avoid warning unused parameters */
- ( void ) pxNetworkBuffer;
- ( void ) uxHeaderLength;
- }
- #endif /* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 0 */
-
- return eReturn;
-}
-/*-----------------------------------------------------------*/
-
-static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * const pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-eFrameProcessingResult_t eReturn;
-IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );
-UBaseType_t uxHeaderLength = ( UBaseType_t ) ( ( pxIPHeader->ucVersionHeaderLength & 0x0Fu ) << 2 );
-uint8_t ucProtocol;
-
- /* Bound the calculated header length: take away the Ethernet header size,
- then check if the IP header is claiming to be longer than the remaining
- total packet size. Also check for minimal header field length. */
- if( ( uxHeaderLength > ( pxNetworkBuffer->xDataLength - ipSIZE_OF_ETH_HEADER ) ) ||
- ( uxHeaderLength < ipSIZE_OF_IPv4_HEADER ) )
- {
- return eReleaseBuffer;
- }
-
- ucProtocol = pxIPPacket->xIPHeader.ucProtocol;
- /* Check if the IP headers are acceptable and if it has our destination. */
- eReturn = prvAllowIPPacket( pxIPPacket, pxNetworkBuffer, uxHeaderLength );
-
- if( eReturn == eProcessBuffer )
- {
- if( uxHeaderLength > ipSIZE_OF_IPv4_HEADER )
- {
- /* All structs of headers expect a IP header size of 20 bytes
- * IP header options were included, we'll ignore them and cut them out
- * Note: IP options are mostly use in Multi-cast protocols */
- const size_t optlen = ( ( size_t ) uxHeaderLength ) - ipSIZE_OF_IPv4_HEADER;
- /* From: the previous start of UDP/ICMP/TCP data */
- uint8_t *pucSource = ( uint8_t* )(pxNetworkBuffer->pucEthernetBuffer + sizeof( EthernetHeader_t ) + uxHeaderLength);
- /* To: the usual start of UDP/ICMP/TCP data at offset 20 from IP header */
- uint8_t *pucTarget = ( uint8_t* )(pxNetworkBuffer->pucEthernetBuffer + sizeof( EthernetHeader_t ) + ipSIZE_OF_IPv4_HEADER);
- /* How many: total length minus the options and the lower headers */
- const size_t xMoveLen = pxNetworkBuffer->xDataLength - optlen - ipSIZE_OF_IPv4_HEADER - ipSIZE_OF_ETH_HEADER;
-
- memmove( pucTarget, pucSource, xMoveLen );
- pxNetworkBuffer->xDataLength -= optlen;
-
- /* Fix-up new version/header length field in IP packet. */
- pxIPHeader->ucVersionHeaderLength = ( pxIPHeader->ucVersionHeaderLength & 0xF0 ) | /* High nibble is the version. */
- ( ( ipSIZE_OF_IPv4_HEADER >> 2 ) & 0x0F ); /* Low nibble is the header size, in bytes, divided by four. */
- }
-
- /* Add the IP and MAC addresses to the ARP table if they are not
- already there - otherwise refresh the age of the existing
- entry. */
- if( ucProtocol != ( uint8_t ) ipPROTOCOL_UDP )
- {
- /* Refresh the ARP cache with the IP/MAC-address of the received packet
- * For UDP packets, this will be done later in xProcessReceivedUDPPacket()
- * as soon as know that the message will be handled by someone
- * This will prevent that the ARP cache will get overwritten
- * with the IP-address of useless broadcast packets
- */
- vARPRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ), pxIPHeader->ulSourceIPAddress );
- }
- switch( ucProtocol )
- {
- case ipPROTOCOL_ICMP :
- /* The IP packet contained an ICMP frame. Don't bother
- checking the ICMP checksum, as if it is wrong then the
- wrong data will also be returned, and the source of the
- ping will know something went wrong because it will not
- be able to validate what it receives. */
- #if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
- {
- if( pxNetworkBuffer->xDataLength >= sizeof( ICMPPacket_t ) )
- {
- ICMPPacket_t *pxICMPPacket = ( ICMPPacket_t * )( pxNetworkBuffer->pucEthernetBuffer );
- if( pxIPHeader->ulDestinationIPAddress == *ipLOCAL_IP_ADDRESS_POINTER )
- {
- eReturn = prvProcessICMPPacket( pxICMPPacket );
- }
- }
- else
- {
- eReturn = eReleaseBuffer;
- }
- }
- #endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */
- break;
-
- case ipPROTOCOL_UDP :
- {
- /* The IP packet contained a UDP frame. */
- UDPPacket_t *pxUDPPacket = ( UDPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-
- /* Only proceed if the payload length indicated in the header
- appears to be valid. */
- if ( pxNetworkBuffer->xDataLength >= sizeof( UDPPacket_t ) )
- {
- /* Ensure that downstream UDP packet handling has the lesser
- * of: the actual network buffer Ethernet frame length, or
- * the sender's UDP packet header payload length, minus the
- * size of the UDP header.
- *
- * The size of the UDP packet structure in this implementation
- * includes the size of the Ethernet header, the size of
- * the IP header, and the size of the UDP header.
- */
-
- pxNetworkBuffer->xDataLength -= sizeof( UDPPacket_t );
- if( ( FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t ) ) <
- pxNetworkBuffer->xDataLength )
- {
- pxNetworkBuffer->xDataLength = FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t );
- }
-
- /* Fields in pxNetworkBuffer (usPort, ulIPAddress) are network order. */
- pxNetworkBuffer->usPort = pxUDPPacket->xUDPHeader.usSourcePort;
- pxNetworkBuffer->ulIPAddress = pxUDPPacket->xIPHeader.ulSourceIPAddress;
-
- /* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM:
- * In some cases, the upper-layer checksum has been calculated
- * by the NIC driver.
- *
- * Pass the packet payload to the UDP sockets implementation. */
- if( xProcessReceivedUDPPacket( pxNetworkBuffer,
- pxUDPPacket->xUDPHeader.usDestinationPort ) == pdPASS )
- {
- eReturn = eFrameConsumed;
- }
- }
- else
- {
- eReturn = eReleaseBuffer;
- }
- }
- break;
-
-#if ipconfigUSE_TCP == 1
- case ipPROTOCOL_TCP :
- {
-
- if( xProcessReceivedTCPPacket( pxNetworkBuffer ) == pdPASS )
- {
- eReturn = eFrameConsumed;
- }
-
- /* Setting this variable will cause xTCPTimerCheck()
- to be called just before the IP-task blocks. */
- xProcessedTCPMessage++;
- }
- break;
-#endif
- default :
- /* Not a supported frame type. */
- break;
- }
- }
-
- return eReturn;
-}
-/*-----------------------------------------------------------*/
-
-#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
-
- static void prvProcessICMPEchoReply( ICMPPacket_t * const pxICMPPacket )
- {
- ePingReplyStatus_t eStatus = eSuccess;
- uint16_t usDataLength, usCount;
- uint8_t *pucByte;
-
- /* Find the total length of the IP packet. */
- usDataLength = pxICMPPacket->xIPHeader.usLength;
- usDataLength = FreeRTOS_ntohs( usDataLength );
-
- /* Remove the length of the IP headers to obtain the length of the ICMP
- message itself. */
- usDataLength = ( uint16_t ) ( ( ( uint32_t ) usDataLength ) - ipSIZE_OF_IPv4_HEADER );
-
- /* Remove the length of the ICMP header, to obtain the length of
- data contained in the ping. */
- usDataLength = ( uint16_t ) ( ( ( uint32_t ) usDataLength ) - ipSIZE_OF_ICMP_HEADER );
-
- /* Checksum has already been checked before in prvProcessIPPacket */
-
- /* Find the first byte of the data within the ICMP packet. */
- pucByte = ( uint8_t * ) pxICMPPacket;
- pucByte += sizeof( ICMPPacket_t );
-
- /* Check each byte. */
- for( usCount = 0; usCount < usDataLength; usCount++ )
- {
- if( *pucByte != ipECHO_DATA_FILL_BYTE )
- {
- eStatus = eInvalidData;
- break;
- }
-
- pucByte++;
- }
-
- /* Call back into the application to pass it the result. */
- vApplicationPingReplyHook( eStatus, pxICMPPacket->xICMPHeader.usIdentifier );
- }
-
-#endif
-/*-----------------------------------------------------------*/
-
-#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 )
-
- static eFrameProcessingResult_t prvProcessICMPEchoRequest( ICMPPacket_t * const pxICMPPacket )
- {
- ICMPHeader_t *pxICMPHeader;
- IPHeader_t *pxIPHeader;
- uint16_t usRequest;
-
- pxICMPHeader = &( pxICMPPacket->xICMPHeader );
- pxIPHeader = &( pxICMPPacket->xIPHeader );
-
- /* HT:endian: changed back */
- iptraceSENDING_PING_REPLY( pxIPHeader->ulSourceIPAddress );
-
- /* The checksum can be checked here - but a ping reply should be
- returned even if the checksum is incorrect so the other end can
- tell that the ping was received - even if the ping reply contains
- invalid data. */
- pxICMPHeader->ucTypeOfMessage = ( uint8_t ) ipICMP_ECHO_REPLY;
- pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress;
- pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
-
- /* Update the checksum because the ucTypeOfMessage member in the header
- has been changed to ipICMP_ECHO_REPLY. This is faster than calling
- usGenerateChecksum(). */
-
- /* due to compiler warning "integer operation result is out of range" */
-
- usRequest = ( uint16_t ) ( ( uint16_t )ipICMP_ECHO_REQUEST << 8 );
-
- if( pxICMPHeader->usChecksum >= FreeRTOS_htons( 0xFFFFu - usRequest ) )
- {
- pxICMPHeader->usChecksum = ( uint16_t )
- ( ( ( uint32_t ) pxICMPHeader->usChecksum ) +
- FreeRTOS_htons( usRequest + 1UL ) );
- }
- else
- {
- pxICMPHeader->usChecksum = ( uint16_t )
- ( ( ( uint32_t ) pxICMPHeader->usChecksum ) +
- FreeRTOS_htons( usRequest ) );
- }
- return eReturnEthernetFrame;
- }
-
-#endif /* ipconfigREPLY_TO_INCOMING_PINGS == 1 */
-/*-----------------------------------------------------------*/
-
-#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
-
- static eFrameProcessingResult_t prvProcessICMPPacket( ICMPPacket_t * const pxICMPPacket )
- {
- eFrameProcessingResult_t eReturn = eReleaseBuffer;
-
- iptraceICMP_PACKET_RECEIVED();
- switch( pxICMPPacket->xICMPHeader.ucTypeOfMessage )
- {
- case ipICMP_ECHO_REQUEST :
- #if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 )
- {
- eReturn = prvProcessICMPEchoRequest( pxICMPPacket );
- }
- #endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) */
- break;
-
- case ipICMP_ECHO_REPLY :
- #if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
- {
- prvProcessICMPEchoReply( pxICMPPacket );
- }
- #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
- break;
-
- default :
- break;
- }
-
- return eReturn;
- }
-
-#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */
-/*-----------------------------------------------------------*/
-
-uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, size_t uxBufferLength, BaseType_t xOutgoingPacket )
-{
-uint32_t ulLength;
-uint16_t usChecksum, *pusChecksum;
-const IPPacket_t * pxIPPacket;
-UBaseType_t uxIPHeaderLength;
-ProtocolPacket_t *pxProtPack;
-uint8_t ucProtocol;
-#if( ipconfigHAS_DEBUG_PRINTF != 0 )
- const char *pcType;
-#endif
-
- /* Check for minimum packet size. */
- if( uxBufferLength < sizeof( IPPacket_t ) )
- {
- return ipINVALID_LENGTH;
- }
-
- /* Parse the packet length. */
- pxIPPacket = ( const IPPacket_t * ) pucEthernetBuffer;
-
- /* Per https://tools.ietf.org/html/rfc791, the four-bit Internet Header
- Length field contains the length of the internet header in 32-bit words. */
- uxIPHeaderLength = ( UBaseType_t ) ( sizeof( uint32_t ) * ( pxIPPacket->xIPHeader.ucVersionHeaderLength & 0x0Fu ) );
-
- /* Check for minimum packet size. */
- if( uxBufferLength < sizeof( IPPacket_t ) + uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER )
- {
- return ipINVALID_LENGTH;
- }
- if( uxBufferLength < FreeRTOS_ntohs( pxIPPacket->xIPHeader.usLength ) )
- {
- return ipINVALID_LENGTH;
- }
-
- /* Identify the next protocol. */
- ucProtocol = pxIPPacket->xIPHeader.ucProtocol;
-
- /* N.B., if this IP packet header includes Options, then the following
- assignment results in a pointer into the protocol packet with the Ethernet
- and IP headers incorrectly aligned. However, either way, the "third"
- protocol (Layer 3 or 4) header will be aligned, which is the convenience
- of this calculation. */
- pxProtPack = ( ProtocolPacket_t * ) ( pucEthernetBuffer + ( uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ) );
-
- /* Switch on the Layer 3/4 protocol. */
- if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP )
- {
- if( uxBufferLength < ( uxIPHeaderLength + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_UDP_HEADER ) )
- {
- return ipINVALID_LENGTH;
- }
-
- pusChecksum = ( uint16_t * ) ( &( pxProtPack->xUDPPacket.xUDPHeader.usChecksum ) );
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- pcType = "UDP";
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
- }
- else if( ucProtocol == ( uint8_t ) ipPROTOCOL_TCP )
- {
- if( uxBufferLength < ( uxIPHeaderLength + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_TCP_HEADER ) )
- {
- return ipINVALID_LENGTH;
- }
-
- pusChecksum = ( uint16_t * ) ( &( pxProtPack->xTCPPacket.xTCPHeader.usChecksum ) );
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- pcType = "TCP";
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
- }
- else if( ( ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP ) ||
- ( ucProtocol == ( uint8_t ) ipPROTOCOL_IGMP ) )
- {
- if( uxBufferLength < ( uxIPHeaderLength + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_ICMP_HEADER ) )
- {
- return ipINVALID_LENGTH;
- }
-
- pusChecksum = ( uint16_t * ) ( &( pxProtPack->xICMPPacket.xICMPHeader.usChecksum ) );
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP )
- {
- pcType = "ICMP";
- }
- else
- {
- pcType = "IGMP";
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
- }
- else
- {
- /* Unhandled protocol, other than ICMP, IGMP, UDP, or TCP. */
- return ipUNHANDLED_PROTOCOL;
- }
-
- /* The protocol and checksum field have been identified. Check the direction
- of the packet. */
- if( xOutgoingPacket != pdFALSE )
- {
- /* This is an outgoing packet. Before calculating the checksum, set it
- to zero. */
- *( pusChecksum ) = 0u;
- }
- else if( ( *pusChecksum == 0u ) && ( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) )
- {
- /* Sender hasn't set the checksum, no use to calculate it. */
- return ipCORRECT_CRC;
- }
-
- ulLength = ( uint32_t )
- ( FreeRTOS_ntohs( pxIPPacket->xIPHeader.usLength ) - ( ( uint16_t ) uxIPHeaderLength ) ); /* normally minus 20 */
-
- if( ( ulLength < sizeof( pxProtPack->xUDPPacket.xUDPHeader ) ) ||
- ( ulLength > ( uint32_t )( ipconfigNETWORK_MTU - uxIPHeaderLength ) ) )
- {
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- FreeRTOS_debug_printf( ( "usGenerateProtocolChecksum[%s]: len invalid: %lu\n", pcType, ulLength ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
- /* Again, in a 16-bit return value there is no space to indicate an
- error. For incoming packets, 0x1234 will cause dropping of the packet.
- For outgoing packets, there is a serious problem with the
- format/length */
- return ipINVALID_LENGTH;
- }
- if( ucProtocol <= ( uint8_t ) ipPROTOCOL_IGMP )
- {
- /* ICMP/IGMP do not have a pseudo header for CRC-calculation. */
- usChecksum = ( uint16_t )
- ( ~usGenerateChecksum( 0UL,
- ( uint8_t * ) &( pxProtPack->xTCPPacket.xTCPHeader ), ( size_t ) ulLength ) );
- }
- else
- {
- /* For UDP and TCP, sum the pseudo header, i.e. IP protocol + length
- fields */
- usChecksum = ( uint16_t ) ( ulLength + ( ( uint16_t ) ucProtocol ) );
-
- /* And then continue at the IPv4 source and destination addresses. */
- usChecksum = ( uint16_t )
- ( ~usGenerateChecksum( ( uint32_t ) usChecksum, ( uint8_t * )&( pxIPPacket->xIPHeader.ulSourceIPAddress ),
- ( 2u * sizeof( pxIPPacket->xIPHeader.ulSourceIPAddress ) + ulLength ) ) );
-
- /* Sum TCP header and data. */
- }
-
- if( xOutgoingPacket == pdFALSE )
- {
- /* This is in incoming packet. If the CRC is correct, it should be zero. */
- if( usChecksum == 0u )
- {
- usChecksum = ( uint16_t )ipCORRECT_CRC;
- }
- }
- else
- {
- if( ( usChecksum == 0u ) && ( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) )
- {
- /* In case of UDP, a calculated checksum of 0x0000 is transmitted
- as 0xffff. A value of zero would mean that the checksum is not used. */
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( xOutgoingPacket != pdFALSE )
- {
- FreeRTOS_debug_printf( ( "usGenerateProtocolChecksum[%s]: crc swap: %04X\n", pcType, usChecksum ) );
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
- usChecksum = ( uint16_t )0xffffu;
- }
- }
- usChecksum = FreeRTOS_htons( usChecksum );
-
- if( xOutgoingPacket != pdFALSE )
- {
- *( pusChecksum ) = usChecksum;
- }
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- else if( ( xOutgoingPacket == pdFALSE ) && ( usChecksum != ipCORRECT_CRC ) )
- {
- FreeRTOS_debug_printf( ( "usGenerateProtocolChecksum[%s]: ID %04X: from %lxip to %lxip bad crc: %04X\n",
- pcType,
- FreeRTOS_ntohs( pxIPPacket->xIPHeader.usIdentification ),
- FreeRTOS_ntohl( pxIPPacket->xIPHeader.ulSourceIPAddress ),
- FreeRTOS_ntohl( pxIPPacket->xIPHeader.ulDestinationIPAddress ),
- FreeRTOS_ntohs( *pusChecksum ) ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
- return usChecksum;
-}
-/*-----------------------------------------------------------*/
-
-/**
- * This method generates a checksum for a given IPv4 header, per RFC791 (page 14).
- * The checksum algorithm is decribed as:
- * "[T]he 16 bit one's complement of the one's complement sum of all 16 bit words in the
- * header. For purposes of computing the checksum, the value of the checksum field is zero."
- *
- * In a nutshell, that means that each 16-bit 'word' must be summed, after which
- * the number of 'carries' (overflows) is added to the result. If that addition
- * produces an overflow, that 'carry' must also be added to the final result. The final checksum
- * should be the bitwise 'not' (ones-complement) of the result if the packet is
- * meant to be transmitted, but this method simply returns the raw value, probably
- * because when a packet is received, the checksum is verified by checking that
- * ((received & calculated) == 0) without applying a bitwise 'not' to the 'calculated' checksum.
- *
- * This logic is optimized for microcontrollers which have limited resources, so the logic looks odd.
- * It iterates over the full range of 16-bit words, but it does so by processing several 32-bit
- * words at once whenever possible. Its first step is to align the memory pointer to a 32-bit boundary,
- * after which it runs a fast loop to process multiple 32-bit words at once and adding their 'carries'.
- * Finally, it finishes up by processing any remaining 16-bit words, and adding up all of the 'carries'.
- * With 32-bit arithmetic, the number of 16-bit 'carries' produced by sequential additions can be found
- * by looking at the 16 most-significant bits of the 32-bit integer, since a 32-bit int will continue
- * counting up instead of overflowing after 16 bits. That is why the actual checksum calculations look like:
- * union.u32 = ( uint32_t ) union.u16[ 0 ] + union.u16[ 1 ];
- *
- * Arguments:
- * ulSum: This argument provides a value to initialize the progressive summation
- * of the header's values to. It is often 0, but protocols like TCP or UDP
- * can have pseudo-header fields which need to be included in the checksum.
- * pucNextData: This argument contains the address of the first byte which this
- * method should process. The method's memory iterator is initialized to this value.
- * uxDataLengthBytes: This argument contains the number of bytes that this method
- * should process.
- */
-uint16_t usGenerateChecksum( uint32_t ulSum, const uint8_t * pucNextData, size_t uxDataLengthBytes )
-{
-xUnion32 xSum2, xSum, xTerm;
-xUnionPtr xSource; /* Points to first byte */
-xUnionPtr xLastSource; /* Points to last byte plus one */
-uint32_t ulAlignBits, ulCarry = 0ul;
-
- /* Small MCUs often spend up to 30% of the time doing checksum calculations
- This function is optimised for 32-bit CPUs; Each time it will try to fetch
- 32-bits, sums it with an accumulator and counts the number of carries. */
-
- /* Swap the input (little endian platform only). */
- xSum.u32 = FreeRTOS_ntohs( ulSum );
- xTerm.u32 = 0ul;
-
- xSource.u8ptr = ( uint8_t * ) pucNextData;
- ulAlignBits = ( ( ( uint32_t ) pucNextData ) & 0x03u ); /* gives 0, 1, 2, or 3 */
-
- /* If byte (8-bit) aligned... */
- if( ( ( ulAlignBits & 1ul ) != 0ul ) && ( uxDataLengthBytes >= ( size_t ) 1 ) )
- {
- xTerm.u8[ 1 ] = *( xSource.u8ptr );
- ( xSource.u8ptr )++;
- uxDataLengthBytes--;
- /* Now xSource is word (16-bit) aligned. */
- }
-
- /* If half-word (16-bit) aligned... */
- if( ( ( ulAlignBits == 1u ) || ( ulAlignBits == 2u ) ) && ( uxDataLengthBytes >= 2u ) )
- {
- xSum.u32 += *(xSource.u16ptr);
- ( xSource.u16ptr )++;
- uxDataLengthBytes -= 2u;
- /* Now xSource is word (32-bit) aligned. */
- }
-
- /* Word (32-bit) aligned, do the most part. */
- xLastSource.u32ptr = ( xSource.u32ptr + ( uxDataLengthBytes / 4u ) ) - 3u;
-
- /* In this loop, four 32-bit additions will be done, in total 16 bytes.
- Indexing with constants (0,1,2,3) gives faster code than using
- post-increments. */
- while( xSource.u32ptr < xLastSource.u32ptr )
- {
- /* Use a secondary Sum2, just to see if the addition produced an
- overflow. */
- xSum2.u32 = xSum.u32 + xSource.u32ptr[ 0 ];
- if( xSum2.u32 < xSum.u32 )
- {
- ulCarry++;
- }
-
- /* Now add the secondary sum to the major sum, and remember if there was
- a carry. */
- xSum.u32 = xSum2.u32 + xSource.u32ptr[ 1 ];
- if( xSum2.u32 > xSum.u32 )
- {
- ulCarry++;
- }
-
- /* And do the same trick once again for indexes 2 and 3 */
- xSum2.u32 = xSum.u32 + xSource.u32ptr[ 2 ];
- if( xSum2.u32 < xSum.u32 )
- {
- ulCarry++;
- }
-
- xSum.u32 = xSum2.u32 + xSource.u32ptr[ 3 ];
-
- if( xSum2.u32 > xSum.u32 )
- {
- ulCarry++;
- }
-
- /* And finally advance the pointer 4 * 4 = 16 bytes. */
- xSource.u32ptr += 4;
- }
-
- /* Now add all carries. */
- xSum.u32 = ( uint32_t )xSum.u16[ 0 ] + xSum.u16[ 1 ] + ulCarry;
-
- uxDataLengthBytes %= 16u;
- xLastSource.u8ptr = ( uint8_t * ) ( xSource.u8ptr + ( uxDataLengthBytes & ~( ( size_t ) 1 ) ) );
-
- /* Half-word aligned. */
- while( xSource.u16ptr < xLastSource.u16ptr )
- {
- /* At least one more short. */
- xSum.u32 += xSource.u16ptr[ 0 ];
- xSource.u16ptr++;
- }
-
- if( ( uxDataLengthBytes & ( size_t ) 1 ) != 0u ) /* Maybe one more ? */
- {
- xTerm.u8[ 0 ] = xSource.u8ptr[ 0 ];
- }
- xSum.u32 += xTerm.u32;
-
- /* Now add all carries again. */
- xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ];
-
- /* The previous summation might have given a 16-bit carry. */
- xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ];
-
- if( ( ulAlignBits & 1u ) != 0u )
- {
- /* Quite unlikely, but pucNextData might be non-aligned, which would
- mean that a checksum is calculated starting at an odd position. */
- xSum.u32 = ( ( xSum.u32 & 0xffu ) << 8 ) | ( ( xSum.u32 & 0xff00u ) >> 8 );
- }
-
- /* swap the output (little endian platform only). */
- return FreeRTOS_htons( ( (uint16_t) xSum.u32 ) );
-}
-/*-----------------------------------------------------------*/
-
-void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend )
-{
-EthernetHeader_t *pxEthernetHeader;
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNewBuffer;
-#endif
-
- #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- BaseType_t xIndex;
-
- FreeRTOS_printf( ( "vReturnEthernetFrame: length %lu\n", ( uint32_t )pxNetworkBuffer->xDataLength ) );
- for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
- {
- pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0u;
- }
- pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
- }
- }
- #endif
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
-
- if( xReleaseAfterSend == pdFALSE )
- {
- pxNewBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, ( BaseType_t ) pxNetworkBuffer->xDataLength );
- xReleaseAfterSend = pdTRUE;
- pxNetworkBuffer = pxNewBuffer;
- }
-
- if( pxNetworkBuffer != NULL )
-#endif
- {
- pxEthernetHeader = ( EthernetHeader_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-
- /* Swap source and destination MAC addresses. */
- memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( void * ) &( pxEthernetHeader->xSourceAddress ), sizeof( pxEthernetHeader->xDestinationAddress ) );
- memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
-
- /* Send! */
- xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend );
- }
-}
-/*-----------------------------------------------------------*/
-
-uint32_t FreeRTOS_GetIPAddress( void )
-{
- /* Returns the IP address of the NIC. */
- return *ipLOCAL_IP_ADDRESS_POINTER;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_SetIPAddress( uint32_t ulIPAddress )
-{
- /* Sets the IP address of the NIC. */
- *ipLOCAL_IP_ADDRESS_POINTER = ulIPAddress;
-}
-/*-----------------------------------------------------------*/
-
-uint32_t FreeRTOS_GetGatewayAddress( void )
-{
- return xNetworkAddressing.ulGatewayAddress;
-}
-/*-----------------------------------------------------------*/
-
-uint32_t FreeRTOS_GetDNSServerAddress( void )
-{
- return xNetworkAddressing.ulDNSServerAddress;
-}
-/*-----------------------------------------------------------*/
-
-uint32_t FreeRTOS_GetNetmask( void )
-{
- return xNetworkAddressing.ulNetMask;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES] )
-{
- /* Copy the MAC address at the start of the default packet header fragment. */
- memcpy( ( void * )ipLOCAL_MAC_ADDRESS, ( void * )ucMACAddress, ( size_t )ipMAC_ADDRESS_LENGTH_BYTES );
-}
-/*-----------------------------------------------------------*/
-
-const uint8_t * FreeRTOS_GetMACAddress( void )
-{
- return ipLOCAL_MAC_ADDRESS;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_SetNetmask ( uint32_t ulNetmask )
-{
- xNetworkAddressing.ulNetMask = ulNetmask;
-}
-/*-----------------------------------------------------------*/
-
-void FreeRTOS_SetGatewayAddress ( uint32_t ulGatewayAddress )
-{
- xNetworkAddressing.ulGatewayAddress = ulGatewayAddress;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_DHCP == 1 )
- void vIPSetDHCPTimerEnableState( BaseType_t xEnableState )
- {
- if( xEnableState != pdFALSE )
- {
- xDHCPTimer.bActive = pdTRUE_UNSIGNED;
- }
- else
- {
- xDHCPTimer.bActive = pdFALSE_UNSIGNED;
- }
- }
-#endif /* ipconfigUSE_DHCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_DHCP == 1 )
- void vIPReloadDHCPTimer( uint32_t ulLeaseTime )
- {
- prvIPTimerReload( &xDHCPTimer, ulLeaseTime );
- }
-#endif /* ipconfigUSE_DHCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigDNS_USE_CALLBACKS == 1 )
- void vIPSetDnsTimerEnableState( BaseType_t xEnableState )
- {
- if( xEnableState != 0 )
- {
- xDNSTimer.bActive = pdTRUE;
- }
- else
- {
- xDNSTimer.bActive = pdFALSE;
- }
- }
-#endif /* ipconfigUSE_DHCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigDNS_USE_CALLBACKS != 0 )
- void vIPReloadDNSTimer( uint32_t ulCheckTime )
- {
- prvIPTimerReload( &xDNSTimer, ulCheckTime );
- }
-#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
-/*-----------------------------------------------------------*/
-
-BaseType_t xIPIsNetworkTaskReady( void )
-{
- return xIPTaskInitialised;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t FreeRTOS_IsNetworkUp( void )
-{
- return xNetworkUp;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- UBaseType_t uxGetMinimumIPQueueSpace( void )
- {
- return uxQueueMinimumSpace;
- }
-#endif
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
deleted file mode 100755
index d6b05ac..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
+++ /dev/null
@@ -1,3632 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_DNS.h"
-#include "NetworkBufferManagement.h"
-
-/* The ItemValue of the sockets xBoundSocketListItem member holds the socket's
-port number. */
-#define socketSET_SOCKET_PORT( pxSocket, usPort ) listSET_LIST_ITEM_VALUE( ( &( ( pxSocket )->xBoundSocketListItem ) ), ( usPort ) )
-#define socketGET_SOCKET_PORT( pxSocket ) listGET_LIST_ITEM_VALUE( ( &( ( pxSocket )->xBoundSocketListItem ) ) )
-
-/* Test if a socket it bound which means it is either included in
-xBoundUDPSocketsList or xBoundTCPSocketsList */
-#define socketSOCKET_IS_BOUND( pxSocket ) ( listLIST_ITEM_CONTAINER( & ( pxSocket )->xBoundSocketListItem ) != NULL )
-
-/* If FreeRTOS_sendto() is called on a socket that is not bound to a port
-number then, depending on the FreeRTOSIPConfig.h settings, it might be that a
-port number is automatically generated for the socket. Automatically generated
-port numbers will be between socketAUTO_PORT_ALLOCATION_START_NUMBER and
-0xffff.
-
-Per https://tools.ietf.org/html/rfc6056, "the dynamic ports consist of the range
-49152-65535. However, ephemeral port selection algorithms should use the whole
-range 1024-65535" excluding those already in use (inbound or outbound). */
-#if !defined( socketAUTO_PORT_ALLOCATION_START_NUMBER )
- #define socketAUTO_PORT_ALLOCATION_START_NUMBER ( ( uint16_t ) 0x0400 )
-#endif
-
-#define socketAUTO_PORT_ALLOCATION_MAX_NUMBER ( ( uint16_t ) 0xffff )
-
-/* The number of octets that make up an IP address. */
-#define socketMAX_IP_ADDRESS_OCTETS 4u
-
-/* A block time of 0 simply means "don't block". */
-#define socketDONT_BLOCK ( ( TickType_t ) 0 )
-
-#if( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
- #define ipTCP_TIMER_PERIOD_MS ( 1000 )
-#endif
-
-/* The next private port number to use when binding a client socket is stored in
-the usNextPortToUse[] array - which has either 1 or two indexes depending on
-whether TCP is being supported. */
-#if( ipconfigUSE_TCP == 1 )
- #define socketPROTOCOL_COUNT 2
-#else
- #define socketPROTOCOL_COUNT 1
-#endif
-
-/* Indexes into the usNextPortToUse[] array for UDP and TCP sockets
-respectively. */
-#define socketNEXT_UDP_PORT_NUMBER_INDEX 0
-#define socketNEXT_TCP_PORT_NUMBER_INDEX 1
-
-
-/*-----------------------------------------------------------*/
-
-/*
- * Allocate the next port number from the private allocation range.
- * TCP and UDP each have their own series of port numbers
- * ulProtocol is either ipPROTOCOL_UDP or ipPROTOCOL_TCP
- */
-static uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol );
-
-/*
- * Return the list item from within pxList that has an item value of
- * xWantedItemValue. If there is no such list item return NULL.
- */
-static const ListItem_t * pxListFindListItemWithValue( const List_t *pxList, TickType_t xWantedItemValue );
-
-/*
- * Return pdTRUE only if pxSocket is valid and bound, as far as can be
- * determined.
- */
-static BaseType_t prvValidSocket( FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound );
-
-/*
- * Before creating a socket, check the validity of the parameters used
- * and find the size of the socket space, which is different for UDP and TCP
- */
-static BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol, size_t *pxSocketSize );
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * Create a txStream or a rxStream, depending on the parameter 'xIsInputStream'
- */
- static StreamBuffer_t *prvTCPCreateStream (FreeRTOS_Socket_t *pxSocket, BaseType_t xIsInputStream );
-#endif /* ipconfigUSE_TCP == 1 */
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * Called from FreeRTOS_send(): some checks which will be done before
- * sending a TCP packed.
- */
- static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t xDataLength );
-#endif /* ipconfigUSE_TCP */
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * When a child socket gets closed, make sure to update the child-count of the parent
- */
- static void prvTCPSetSocketCount( FreeRTOS_Socket_t *pxSocketToDelete );
-#endif /* ipconfigUSE_TCP == 1 */
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * Called from FreeRTOS_connect(): make some checks and if allowed, send a
- * message to the IP-task to start connecting to a remote socket
- */
- static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr *pxAddress );
-#endif /* ipconfigUSE_TCP */
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- /* Executed by the IP-task, it will check all sockets belonging to a set */
- static FreeRTOS_Socket_t *prvFindSelectedSocket( SocketSelect_t *pxSocketSet );
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-/* The list that contains mappings between sockets and port numbers. Accesses
-to this list must be protected by critical sections of one kind or another. */
-List_t xBoundUDPSocketsList;
-
-#if ipconfigUSE_TCP == 1
- List_t xBoundTCPSocketsList;
-#endif /* ipconfigUSE_TCP == 1 */
-
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvValidSocket( FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound )
-{
-BaseType_t xReturn = pdTRUE;
-
- if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) )
- {
- xReturn = pdFALSE;
- }
- else if( ( xIsBound != pdFALSE ) && ( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE ) )
- {
- /* The caller expects the socket to be bound, but it isn't. */
- xReturn = pdFALSE;
- }
- else if( pxSocket->ucProtocol != ( uint8_t ) xProtocol )
- {
- /* Socket has a wrong type (UDP != TCP). */
- xReturn = pdFALSE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t vNetworkSocketsInit( void )
-{
- vListInitialise( &xBoundUDPSocketsList );
-
- #if( ipconfigUSE_TCP == 1 )
- {
- vListInitialise( &xBoundTCPSocketsList );
- }
- #endif /* ipconfigUSE_TCP == 1 */
-
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol, size_t *pxSocketSize )
-{
-BaseType_t xReturn = pdPASS;
-FreeRTOS_Socket_t *pxSocket;
-
- /* Asserts must not appear before it has been determined that the network
- task is ready - otherwise the asserts will fail. */
- if( xIPIsNetworkTaskReady() == pdFALSE )
- {
- xReturn = pdFAIL;
- }
- else
- {
- /* Only Ethernet is currently supported. */
- configASSERT( xDomain == FREERTOS_AF_INET );
-
- /* Check if the UDP socket-list has been initialised. */
- configASSERT( listLIST_IS_INITIALISED( &xBoundUDPSocketsList ) );
- #if( ipconfigUSE_TCP == 1 )
- {
- /* Check if the TCP socket-list has been initialised. */
- configASSERT( listLIST_IS_INITIALISED( &xBoundTCPSocketsList ) );
- }
- #endif /* ipconfigUSE_TCP == 1 */
-
- if( xProtocol == FREERTOS_IPPROTO_UDP )
- {
- if( xType != FREERTOS_SOCK_DGRAM )
- {
- xReturn = pdFAIL;
- configASSERT( xReturn );
- }
- /* In case a UDP socket is created, do not allocate space for TCP data. */
- *pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xUDP );
- }
-#if( ipconfigUSE_TCP == 1 )
- else if( xProtocol == FREERTOS_IPPROTO_TCP )
- {
- if( xType != FREERTOS_SOCK_STREAM )
- {
- xReturn = pdFAIL;
- configASSERT( xReturn );
- }
-
- *pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xTCP );
- }
-#endif /* ipconfigUSE_TCP == 1 */
- else
- {
- xReturn = pdFAIL;
- configASSERT( xReturn );
- }
- }
- /* In case configASSERT() is not used */
- ( void )xDomain;
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-/* FreeRTOS_socket() allocates and initiates a socket */
-Socket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol )
-{
-FreeRTOS_Socket_t *pxSocket;
-size_t uxSocketSize;
-EventGroupHandle_t xEventGroup;
-Socket_t xReturn;
-
- if( prvDetermineSocketSize( xDomain, xType, xProtocol, &uxSocketSize ) == pdFAIL )
- {
- xReturn = FREERTOS_INVALID_SOCKET;
- }
- else
- {
- /* Allocate the structure that will hold the socket information. The
- size depends on the type of socket: UDP sockets need less space. A
- define 'pvPortMallocSocket' will used to allocate the necessary space.
- By default it points to the FreeRTOS function 'pvPortMalloc()'. */
- pxSocket = ( FreeRTOS_Socket_t * ) pvPortMallocSocket( uxSocketSize );
-
- if( pxSocket == NULL )
- {
- pxSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET;
- iptraceFAILED_TO_CREATE_SOCKET();
- }
- else if( ( xEventGroup = xEventGroupCreate() ) == NULL )
- {
- vPortFreeSocket( pxSocket );
- pxSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET;
- iptraceFAILED_TO_CREATE_EVENT_GROUP();
- }
- else
- {
- /* Clear the entire space to avoid nulling individual entries */
- memset( pxSocket, '\0', uxSocketSize );
-
- pxSocket->xEventGroup = xEventGroup;
-
- /* Initialise the socket's members. The semaphore will be created
- if the socket is bound to an address, for now the pointer to the
- semaphore is just set to NULL to show it has not been created. */
- if( xProtocol == FREERTOS_IPPROTO_UDP )
- {
- vListInitialise( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
-
- #if( ipconfigUDP_MAX_RX_PACKETS > 0 )
- {
- pxSocket->u.xUDP.uxMaxPackets = ( UBaseType_t ) ipconfigUDP_MAX_RX_PACKETS;
- }
- #endif /* ipconfigUDP_MAX_RX_PACKETS > 0 */
- }
-
- vListInitialiseItem( &( pxSocket->xBoundSocketListItem ) );
- listSET_LIST_ITEM_OWNER( &( pxSocket->xBoundSocketListItem ), ( void * ) pxSocket );
-
- pxSocket->xReceiveBlockTime = ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME;
- pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME;
- pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT;
- pxSocket->ucProtocol = ( uint8_t ) xProtocol; /* protocol: UDP or TCP */
-
- #if( ipconfigUSE_TCP == 1 )
- {
- if( xProtocol == FREERTOS_IPPROTO_TCP )
- {
- /* StreamSize is expressed in number of bytes */
- /* Round up buffer sizes to nearest multiple of MSS */
- pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ipconfigTCP_MSS;
- pxSocket->u.xTCP.uxRxStreamSize = ( size_t ) ipconfigTCP_RX_BUFFER_LENGTH;
- pxSocket->u.xTCP.uxTxStreamSize = ( size_t ) FreeRTOS_round_up( ipconfigTCP_TX_BUFFER_LENGTH, ipconfigTCP_MSS );
- /* Use half of the buffer size of the TCP windows */
- #if ( ipconfigUSE_TCP_WIN == 1 )
- {
- pxSocket->u.xTCP.uxRxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxRxStreamSize / 2 ) / ipconfigTCP_MSS );
- pxSocket->u.xTCP.uxTxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxTxStreamSize / 2 ) / ipconfigTCP_MSS );
- }
- #else
- {
- pxSocket->u.xTCP.uxRxWinSize = 1u;
- pxSocket->u.xTCP.uxTxWinSize = 1u;
- }
- #endif
- /* The above values are just defaults, and can be overridden by
- calling FreeRTOS_setsockopt(). No buffers will be allocated until a
- socket is connected and data is exchanged. */
- }
- }
- #endif /* ipconfigUSE_TCP == 1 */
- }
-
- xReturn = ( Socket_t ) pxSocket;
- }
-
- /* Remove compiler warnings in the case the configASSERT() is not defined. */
- ( void ) xDomain;
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- SocketSet_t FreeRTOS_CreateSocketSet( void )
- {
- SocketSelect_t *pxSocketSet;
-
- pxSocketSet = ( SocketSelect_t * ) pvPortMalloc( sizeof( *pxSocketSet ) );
-
- if( pxSocketSet != NULL )
- {
- memset( pxSocketSet, '\0', sizeof( *pxSocketSet ) );
- pxSocketSet->xSelectGroup = xEventGroupCreate();
-
- if( pxSocketSet->xSelectGroup == NULL )
- {
- vPortFree( ( void* ) pxSocketSet );
- pxSocketSet = NULL;
- }
- }
-
- return ( SocketSet_t * ) pxSocketSet;
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- void FreeRTOS_DeleteSocketSet( SocketSet_t xSocketSet )
- {
- SocketSelect_t *pxSocketSet = ( SocketSelect_t*) xSocketSet;
-
- vEventGroupDelete( pxSocketSet->xSelectGroup );
- vPortFree( ( void* ) pxSocketSet );
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- /* Add a socket to a set */
- void FreeRTOS_FD_SET( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xSelectBits )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- SocketSelect_t *pxSocketSet = ( SocketSelect_t * ) xSocketSet;
-
- configASSERT( pxSocket != NULL );
- configASSERT( xSocketSet != NULL );
-
- /* Make sure we're not adding bits which are reserved for internal use,
- such as eSELECT_CALL_IP */
- pxSocket->xSelectBits |= ( xSelectBits & eSELECT_ALL );
-
- if( ( pxSocket->xSelectBits & eSELECT_ALL ) != 0 )
- {
- /* Adding a socket to a socket set. */
- pxSocket->pxSocketSet = ( SocketSelect_t * ) xSocketSet;
-
- /* Now have the IP-task call vSocketSelect() to see if the set contains
- any sockets which are 'ready' and set the proper bits.
- By setting 'bApiCalled = false', vSocketSelect() knows that it was
- not called from a user API */
- pxSocketSet->bApiCalled = pdFALSE;
- prvFindSelectedSocket( pxSocketSet );
- }
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- /* Clear select bits for a socket
- If the mask becomes 0, remove the socket from the set */
- void FreeRTOS_FD_CLR( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xSelectBits )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- configASSERT( pxSocket != NULL );
- configASSERT( xSocketSet != NULL );
-
- pxSocket->xSelectBits &= ~( xSelectBits & eSELECT_ALL );
- if( ( pxSocket->xSelectBits & eSELECT_ALL ) != 0 )
- {
- pxSocket->pxSocketSet = ( SocketSelect_t *)xSocketSet;
- }
- else
- {
- /* disconnect it from the socket set */
- pxSocket->pxSocketSet = ( SocketSelect_t *)NULL;
- }
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- /* Test if a socket belongs to a socket-set */
- EventBits_t FreeRTOS_FD_ISSET( Socket_t xSocket, SocketSet_t xSocketSet )
- {
- EventBits_t xReturn;
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- configASSERT( pxSocket != NULL );
- configASSERT( xSocketSet != NULL );
-
- if( xSocketSet == ( SocketSet_t ) pxSocket->pxSocketSet )
- {
- /* Make sure we're not adding bits which are reserved for internal
- use. */
- xReturn = pxSocket->xSocketBits & eSELECT_ALL;
- }
- else
- {
- xReturn = 0;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- /* The select() statement: wait for an event to occur on any of the sockets
- included in a socket set */
- BaseType_t FreeRTOS_select( SocketSet_t xSocketSet, TickType_t xBlockTimeTicks )
- {
- TimeOut_t xTimeOut;
- TickType_t xRemainingTime;
- SocketSelect_t *pxSocketSet = ( SocketSelect_t*) xSocketSet;
- BaseType_t xResult;
-
- configASSERT( xSocketSet != NULL );
-
- /* Only in the first round, check for non-blocking */
- xRemainingTime = xBlockTimeTicks;
-
- /* Fetch the current time */
- vTaskSetTimeOutState( &xTimeOut );
-
- for( ;; )
- {
- /* Find a socket which might have triggered the bit
- This function might return immediately or block for a limited time */
- xResult = ( BaseType_t ) xEventGroupWaitBits( pxSocketSet->xSelectGroup, eSELECT_ALL, pdFALSE, pdFALSE, xRemainingTime );
-
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- if( ( xResult & eSELECT_INTR ) != 0u )
- {
- xEventGroupClearBits( pxSocketSet->xSelectGroup, eSELECT_INTR );
- FreeRTOS_debug_printf( ( "FreeRTOS_select: interrupted\n" ) );
- break;
- }
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
-
- /* Have the IP-task find the socket which had an event */
- pxSocketSet->bApiCalled = pdTRUE;
- prvFindSelectedSocket( pxSocketSet );
-
- xResult = ( BaseType_t ) xEventGroupGetBits( pxSocketSet->xSelectGroup );
-
- if( xResult != 0 )
- {
- break;
- }
-
- /* Has the timeout been reached? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE )
- {
- break;
- }
- }
-
- return xResult;
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- /* Send a message to the IP-task to have it check all sockets belonging to
- 'pxSocketSet' */
- static FreeRTOS_Socket_t *prvFindSelectedSocket( SocketSelect_t *pxSocketSet )
- {
- IPStackEvent_t xSelectEvent;
- FreeRTOS_Socket_t *xReturn;
-
- xSelectEvent.eEventType = eSocketSelectEvent;
- xSelectEvent.pvData = ( void * ) pxSocketSet;
-
- /* while the IP-task works on the request, the API will block on
- 'eSELECT_CALL_IP'. So clear it first. */
- xEventGroupClearBits( pxSocketSet->xSelectGroup, eSELECT_CALL_IP );
-
- /* Now send the socket select event */
- if( xSendEventStructToIPTask( &xSelectEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL )
- {
- /* Oops, we failed to wake-up the IP task. No use to wait for it. */
- FreeRTOS_debug_printf( ( "prvFindSelectedSocket: failed\n" ) );
- xReturn = NULL;
- }
- else
- {
- /* As soon as the IP-task is ready, it will set 'eSELECT_CALL_IP' to
- wakeup the calling API */
- xEventGroupWaitBits( pxSocketSet->xSelectGroup, eSELECT_CALL_IP, pdTRUE, pdFALSE, portMAX_DELAY );
-
- /* Return 'pxSocket' which is set by the IP-task */
- xReturn = pxSocketSet->pxSocket;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-/*
- * FreeRTOS_recvfrom: receive data from a bound socket
- * In this library, the function can only be used with connectionsless sockets
- * (UDP)
- */
-int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength )
-{
-BaseType_t lPacketCount = 0;
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-TickType_t xRemainingTime = ( TickType_t ) 0; /* Obsolete assignment, but some compilers output a warning if its not done. */
-BaseType_t xTimed = pdFALSE;
-TimeOut_t xTimeOut;
-int32_t lReturn;
-EventBits_t xEventBits = ( EventBits_t ) 0;
-
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_UDP, pdTRUE ) == pdFALSE )
- {
- return -pdFREERTOS_ERRNO_EINVAL;
- }
-
- lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
-
- /* The function prototype is designed to maintain the expected Berkeley
- sockets standard, but this implementation does not use all the parameters. */
- ( void ) pxSourceAddressLength;
-
- while( lPacketCount == 0 )
- {
- if( xTimed == pdFALSE )
- {
- /* Check to see if the socket is non blocking on the first
- iteration. */
- xRemainingTime = pxSocket->xReceiveBlockTime;
-
- if( xRemainingTime == ( TickType_t ) 0 )
- {
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- /* Just check for the interrupt flag. */
- xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_INTR,
- pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, socketDONT_BLOCK );
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
- break;
- }
-
- if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 )
- {
- break;
- }
-
- /* To ensure this part only executes once. */
- xTimed = pdTRUE;
-
- /* Fetch the current time. */
- vTaskSetTimeOutState( &xTimeOut );
- }
-
- /* Wait for arrival of data. While waiting, the IP-task may set the
- 'eSOCKET_RECEIVE' bit in 'xEventGroup', if it receives data for this
- socket, thus unblocking this API call. */
- xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_RECEIVE | eSOCKET_INTR,
- pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
-
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- if( ( xEventBits & eSOCKET_INTR ) != 0 )
- {
- if( ( xEventBits & eSOCKET_RECEIVE ) != 0 )
- {
- /* Shouldn't have cleared the eSOCKET_RECEIVE flag. */
- xEventGroupSetBits( pxSocket->xEventGroup, eSOCKET_RECEIVE );
- }
- break;
- }
- }
- #else
- {
- ( void ) xEventBits;
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
-
- lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
-
- if( lPacketCount != 0 )
- {
- break;
- }
-
- /* Has the timeout been reached ? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) )
- {
- break;
- }
- } /* while( lPacketCount == 0 ) */
-
- if( lPacketCount != 0 )
- {
- taskENTER_CRITICAL();
- {
- /* The owner of the list item is the network buffer. */
- pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
-
- if( ( xFlags & FREERTOS_MSG_PEEK ) == 0 )
- {
- /* Remove the network buffer from the list of buffers waiting to
- be processed by the socket. */
- uxListRemove( &( pxNetworkBuffer->xBufferListItem ) );
- }
- }
- taskEXIT_CRITICAL();
-
- /* The returned value is the data length, which may have been capped to
- the receive buffer size. */
- lReturn = ( int32_t ) pxNetworkBuffer->xDataLength;
-
- if( pxSourceAddress != NULL )
- {
- pxSourceAddress->sin_port = pxNetworkBuffer->usPort;
- pxSourceAddress->sin_addr = pxNetworkBuffer->ulIPAddress;
- }
-
- if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 )
- {
- /* The zero copy flag is not set. Truncate the length if it won't
- fit in the provided buffer. */
- if( lReturn > ( int32_t ) xBufferLength )
- {
- iptraceRECVFROM_DISCARDING_BYTES( ( xBufferLength - lReturn ) );
- lReturn = ( int32_t )xBufferLength;
- }
-
- /* Copy the received data into the provided buffer, then release the
- network buffer. */
- memcpy( pvBuffer, ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( size_t )lReturn );
-
- if( ( xFlags & FREERTOS_MSG_PEEK ) == 0 )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- }
- else
- {
- /* The zero copy flag was set. pvBuffer is not a buffer into which
- the received data can be copied, but a pointer that must be set to
- point to the buffer in which the received data has already been
- placed. */
- *( ( void** ) pvBuffer ) = ( void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ) );
- }
-
- }
-#if( ipconfigSUPPORT_SIGNALS != 0 )
- else if( ( xEventBits & eSOCKET_INTR ) != 0 )
- {
- lReturn = -pdFREERTOS_ERRNO_EINTR;
- iptraceRECVFROM_INTERRUPTED();
- }
-#endif /* ipconfigSUPPORT_SIGNALS */
- else
- {
- lReturn = -pdFREERTOS_ERRNO_EWOULDBLOCK;
- iptraceRECVFROM_TIMEOUT();
- }
-
- return lReturn;
-}
-/*-----------------------------------------------------------*/
-
-int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t xTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL };
-TimeOut_t xTimeOut;
-TickType_t xTicksToWait;
-int32_t lReturn = 0;
-FreeRTOS_Socket_t *pxSocket;
-
- pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- /* The function prototype is designed to maintain the expected Berkeley
- sockets standard, but this implementation does not use all the
- parameters. */
- ( void ) xDestinationAddressLength;
- configASSERT( pvBuffer );
-
- if( xTotalDataLength <= ( size_t ) ipMAX_UDP_PAYLOAD_LENGTH )
- {
- /* If the socket is not already bound to an address, bind it now.
- Passing NULL as the address parameter tells FreeRTOS_bind() to select
- the address to bind to. */
- if( ( socketSOCKET_IS_BOUND( pxSocket ) != pdFALSE ) ||
- ( FreeRTOS_bind( xSocket, NULL, 0u ) == 0 ) )
- {
- xTicksToWait = pxSocket->xSendBlockTime;
-
- #if( ipconfigUSE_CALLBACKS != 0 )
- {
- if( xIsCallingFromIPTask() != pdFALSE )
- {
- /* If this send function is called from within a call-back
- handler it may not block, otherwise chances would be big to
- get a deadlock: the IP-task waiting for itself. */
- xTicksToWait = ( TickType_t )0;
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 )
- {
- xTicksToWait = ( TickType_t ) 0;
- }
-
- if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 )
- {
- /* Zero copy is not set, so obtain a network buffer into
- which the payload will be copied. */
- vTaskSetTimeOutState( &xTimeOut );
-
- /* Block until a buffer becomes available, or until a
- timeout has been reached */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( xTotalDataLength + sizeof( UDPPacket_t ), xTicksToWait );
-
- if( pxNetworkBuffer != NULL )
- {
- memcpy( ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( void * ) pvBuffer, xTotalDataLength );
-
- if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdTRUE )
- {
- /* The entire block time has been used up. */
- xTicksToWait = ( TickType_t ) 0;
- }
- }
- }
- else
- {
- /* When zero copy is used, pvBuffer is a pointer to the
- payload of a buffer that has already been obtained from the
- stack. Obtain the network buffer pointer from the buffer. */
- pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( (void*)pvBuffer );
- }
-
- if( pxNetworkBuffer != NULL )
- {
- pxNetworkBuffer->xDataLength = xTotalDataLength;
- pxNetworkBuffer->usPort = pxDestinationAddress->sin_port;
- pxNetworkBuffer->usBoundPort = ( uint16_t ) socketGET_SOCKET_PORT( pxSocket );
- pxNetworkBuffer->ulIPAddress = pxDestinationAddress->sin_addr;
-
- /* The socket options are passed to the IP layer in the
- space that will eventually get used by the Ethernet header. */
- pxNetworkBuffer->pucEthernetBuffer[ ipSOCKET_OPTIONS_OFFSET ] = pxSocket->ucSocketOptions;
-
- /* Tell the networking task that the packet needs sending. */
- xStackTxEvent.pvData = pxNetworkBuffer;
-
- /* Ask the IP-task to send this packet */
- if( xSendEventStructToIPTask( &xStackTxEvent, xTicksToWait ) == pdPASS )
- {
- /* The packet was successfully sent to the IP task. */
- lReturn = ( int32_t ) xTotalDataLength;
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xUDP.pxHandleSent ) )
- {
- pxSocket->u.xUDP.pxHandleSent( (Socket_t *)pxSocket, xTotalDataLength );
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
- }
- else
- {
- /* If the buffer was allocated in this function, release
- it. */
- if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- iptraceSTACK_TX_EVENT_LOST( ipSTACK_TX_EVENT );
- }
- }
- else
- {
- /* If errno was available, errno would be set to
- FREERTOS_ENOPKTS. As it is, the function must return the
- number of transmitted bytes, so the calling function knows
- how much data was actually sent. */
- iptraceNO_BUFFER_FOR_SENDTO();
- }
- }
- else
- {
- iptraceSENDTO_SOCKET_NOT_BOUND();
- }
- }
- else
- {
- /* The data is longer than the available buffer space. */
- iptraceSENDTO_DATA_TOO_LONG();
- }
-
- return lReturn;
-} /* Tested */
-/*-----------------------------------------------------------*/
-
-/*
- * FreeRTOS_bind() : binds a sockt to a local port number. If port 0 is
- * provided, a system provided port number will be assigned. This function can
- * be used for both UDP and TCP sockets. The actual binding will be performed
- * by the IP-task to avoid mutual access to the bound-socket-lists
- * (xBoundUDPSocketsList or xBoundTCPSocketsList).
- */
-BaseType_t FreeRTOS_bind( Socket_t xSocket, struct freertos_sockaddr * pxAddress, socklen_t xAddressLength )
-{
-IPStackEvent_t xBindEvent;
-FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-BaseType_t xReturn = 0;
-
- ( void ) xAddressLength;
-
- if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- /* Once a socket is bound to a port, it can not be bound to a different
- port number */
- else if( socketSOCKET_IS_BOUND( pxSocket) != pdFALSE )
- {
- /* The socket is already bound. */
- FreeRTOS_debug_printf( ( "vSocketBind: Socket already bound to %d\n", pxSocket->usLocalPort ) );
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- /* Prepare a messages to the IP-task in order to perform the binding.
- The desired port number will be passed in usLocalPort. */
- xBindEvent.eEventType = eSocketBindEvent;
- xBindEvent.pvData = ( void * ) xSocket;
- if( pxAddress != NULL )
- {
- pxSocket->usLocalPort = FreeRTOS_ntohs( pxAddress->sin_port );
- }
- else
- {
- /* Caller wants to bind to a random port number. */
- pxSocket->usLocalPort = 0u;
- }
-
- /* portMAX_DELAY is used as a the time-out parameter, as binding *must*
- succeed before the socket can be used. _RB_ The use of an infinite
- block time needs be changed as it could result in the task hanging. */
- if( xSendEventStructToIPTask( &xBindEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL )
- {
- /* Failed to wake-up the IP-task, no use to wait for it */
- FreeRTOS_debug_printf( ( "FreeRTOS_bind: send event failed\n" ) );
- xReturn = -pdFREERTOS_ERRNO_ECANCELED;
- }
- else
- {
- /* The IP-task will set the 'eSOCKET_BOUND' bit when it has done its
- job. */
- xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_BOUND, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, portMAX_DELAY );
- if( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- }
- }
-
- return xReturn;
-}
-
-/*
- * vSocketBind(): internal version of bind() that should not be called directly.
- * 'xInternal' is used for TCP sockets only: it allows to have several
- * (connected) child sockets bound to the same server port.
- */
-BaseType_t vSocketBind( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr * pxAddress, size_t uxAddressLength, BaseType_t xInternal )
-{
-BaseType_t xReturn = 0; /* In Berkeley sockets, 0 means pass for bind(). */
-List_t *pxSocketList;
-#if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 )
- struct freertos_sockaddr xAddress;
-#endif /* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND */
-
-#if( ipconfigUSE_TCP == 1 )
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- pxSocketList = &xBoundTCPSocketsList;
- }
- else
-#endif /* ipconfigUSE_TCP == 1 */
- {
- pxSocketList = &xBoundUDPSocketsList;
- }
-
- /* The function prototype is designed to maintain the expected Berkeley
- sockets standard, but this implementation does not use all the parameters. */
- ( void ) uxAddressLength;
-
- configASSERT( pxSocket );
- configASSERT( pxSocket != FREERTOS_INVALID_SOCKET );
-
- #if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 )
- {
- /* pxAddress will be NULL if sendto() was called on a socket without the
- socket being bound to an address. In this case, automatically allocate
- an address and port to the socket. */
- if( pxAddress == NULL )
- {
- pxAddress = &xAddress;
- /* Put the port to zero to be assigned later. */
- pxAddress->sin_port = 0u;
- }
- }
- #endif /* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 */
-
- /* Sockets must be bound before calling FreeRTOS_sendto() if
- ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is not set to 1. */
- configASSERT( pxAddress );
-
- if( pxAddress != NULL )
- {
- if( pxAddress->sin_port == 0u )
- {
- pxAddress->sin_port = prvGetPrivatePortNumber( ( BaseType_t )pxSocket->ucProtocol );
- if( 0 == pxAddress->sin_port )
- {
- return -pdFREERTOS_ERRNO_EADDRNOTAVAIL;
- }
- }
-
- /* If vSocketBind() is called from the API FreeRTOS_bind() it has been
- confirmed that the socket was not yet bound to a port. If it is called
- from the IP-task, no such check is necessary. */
-
- /* Check to ensure the port is not already in use. If the bind is
- called internally, a port MAY be used by more than one socket. */
- if( ( ( xInternal == pdFALSE ) || ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) ) &&
- ( pxListFindListItemWithValue( pxSocketList, ( TickType_t ) pxAddress->sin_port ) != NULL ) )
- {
- FreeRTOS_debug_printf( ( "vSocketBind: %sP port %d in use\n",
- pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ? "TC" : "UD",
- FreeRTOS_ntohs( pxAddress->sin_port ) ) );
- xReturn = -pdFREERTOS_ERRNO_EADDRINUSE;
- }
- else
- {
- /* Allocate the port number to the socket.
- This macro will set 'xBoundSocketListItem->xItemValue' */
- socketSET_SOCKET_PORT( pxSocket, pxAddress->sin_port );
-
- /* And also store it in a socket field 'usLocalPort' in host-byte-order,
- mostly used for logging and debugging purposes */
- pxSocket->usLocalPort = FreeRTOS_ntohs( pxAddress->sin_port );
-
- /* Add the socket to the list of bound ports. */
- {
- /* If the network driver can iterate through 'xBoundUDPSocketsList',
- by calling xPortHasUDPSocket() then the IP-task must temporarily
- suspend the scheduler to keep the list in a consistent state. */
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- vTaskSuspendAll();
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
-
- /* Add the socket to 'xBoundUDPSocketsList' or 'xBoundTCPSocketsList' */
- vListInsertEnd( pxSocketList, &( pxSocket->xBoundSocketListItem ) );
-
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- xTaskResumeAll();
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
- }
- }
- }
- else
- {
- xReturn = -pdFREERTOS_ERRNO_EADDRNOTAVAIL;
- FreeRTOS_debug_printf( ( "vSocketBind: Socket no addr\n" ) );
- }
-
- if( xReturn != 0 )
- {
- iptraceBIND_FAILED( xSocket, ( FreeRTOS_ntohs( pxAddress->sin_port ) ) );
- }
-
- return xReturn;
-} /* Tested */
-/*-----------------------------------------------------------*/
-
-/*
- * Close a socket and free the allocated space
- * In case of a TCP socket: the connection will not be closed automatically
- * Subsequent messages for the closed socket will be responded to with a RST
- * The IP-task will actually close the socket, after receiving a 'eSocketCloseEvent' message
- */
-BaseType_t FreeRTOS_closesocket( Socket_t xSocket )
-{
-BaseType_t xResult;
-#if( ipconfigUSE_TCP == 1 ) && ( ipconfigUSE_CALLBACKS == 1 )
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * )xSocket;
-#endif
-IPStackEvent_t xCloseEvent;
-xCloseEvent.eEventType = eSocketCloseEvent;
-xCloseEvent.pvData = ( void * ) xSocket;
-
- if( ( xSocket == NULL ) || ( xSocket == FREERTOS_INVALID_SOCKET ) )
- {
- xResult = 0;
- }
- else
- {
- #if( ( ipconfigUSE_TCP == 1 ) && ( ipconfigUSE_CALLBACKS == 1 ) )
- {
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- /* Make sure that IP-task won't call the user callback's anymore */
- pxSocket->u.xTCP.pxHandleConnected = NULL;
- pxSocket->u.xTCP.pxHandleReceive = NULL;
- pxSocket->u.xTCP.pxHandleSent = NULL;
- }
- }
- #endif /* ( ( ipconfigUSE_TCP == 1 ) && ( ipconfigUSE_CALLBACKS == 1 ) ) */
-
- /* Let the IP task close the socket to keep it synchronised with the
- packet handling. */
-
- /* Note when changing the time-out value below, it must be checked who is calling
- this function. If it is called by the IP-task, a deadlock could occur.
- The IP-task would only call it in case of a user call-back */
- if( xSendEventStructToIPTask( &xCloseEvent, ( TickType_t ) 0 ) == pdFAIL )
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_closesocket: failed\n" ) );
- xResult = -1;
- }
- else
- {
- xResult = 1;
- }
- }
-
- return xResult;
-}
-
-/* This is the internal version of FreeRTOS_closesocket()
- * It will be called by the IPtask only to avoid problems with synchronicity
- */
-void *vSocketClose( FreeRTOS_Socket_t *pxSocket )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-
- #if( ipconfigUSE_TCP == 1 )
- {
- /* For TCP: clean up a little more. */
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- if( pxSocket->u.xTCP.pxAckMessage != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxSocket->u.xTCP.pxAckMessage );
- }
- /* Free the resources which were claimed by the tcpWin member */
- vTCPWindowDestroy( &pxSocket->u.xTCP.xTCPWindow );
- }
- #endif /* ipconfigUSE_TCP_WIN */
-
- /* Free the input and output streams */
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- vPortFreeLarge( pxSocket->u.xTCP.rxStream );
- }
-
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- vPortFreeLarge( pxSocket->u.xTCP.txStream );
- }
-
- /* In case this is a child socket, make sure the child-count of the
- parent socket is decreased. */
- prvTCPSetSocketCount( pxSocket );
- }
- }
- #endif /* ipconfigUSE_TCP == 1 */
-
- /* Socket must be unbound first, to ensure no more packets are queued on
- it. */
- if( socketSOCKET_IS_BOUND( pxSocket ) != pdFALSE )
- {
- /* If the network driver can iterate through 'xBoundUDPSocketsList',
- by calling xPortHasUDPSocket(), then the IP-task must temporarily
- suspend the scheduler to keep the list in a consistent state. */
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- vTaskSuspendAll();
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
-
- uxListRemove( &( pxSocket->xBoundSocketListItem ) );
-
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- xTaskResumeAll();
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
- }
-
- /* Now the socket is not bound the list of waiting packets can be
- drained. */
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP )
- {
- while( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U )
- {
- pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
- uxListRemove( &( pxNetworkBuffer->xBufferListItem ) );
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- }
-
- if( pxSocket->xEventGroup )
- {
- vEventGroupDelete( pxSocket->xEventGroup );
- }
-
- #if( ipconfigUSE_TCP == 1 ) && ( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_closesocket[%u to %lxip:%u]: buffers %lu socks %lu\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- uxGetNumberOfFreeNetworkBuffers(),
- listCURRENT_LIST_LENGTH( &xBoundTCPSocketsList ) ) );
- }
- }
- #endif /* ( ipconfigUSE_TCP == 1 ) && ( ipconfigHAS_DEBUG_PRINTF != 0 ) */
-
- /* Anf finally, after all resources have been freed, free the socket space */
- vPortFreeSocket( pxSocket );
-
- return 0;
-} /* Tested */
-
-/*-----------------------------------------------------------*/
-
-#if ipconfigUSE_TCP == 1
-
- /*
- * When a child socket gets closed, make sure to update the child-count of the
- * parent. When a listening parent socket is closed, make sure no child-sockets
- * keep a pointer to it.
- */
- static void prvTCPSetSocketCount( FreeRTOS_Socket_t *pxSocketToDelete )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t *pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList );
- FreeRTOS_Socket_t *pxOtherSocket;
- uint16_t usLocalPort = pxSocketToDelete->usLocalPort;
-
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( const ListItem_t * ) pxEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- pxOtherSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- if( ( pxOtherSocket->u.xTCP.ucTCPState == eTCP_LISTEN ) &&
- ( pxOtherSocket->usLocalPort == usLocalPort ) &&
- ( pxOtherSocket->u.xTCP.usChildCount ) )
- {
- pxOtherSocket->u.xTCP.usChildCount--;
- FreeRTOS_debug_printf( ( "Lost: Socket %u now has %u / %u child%s\n",
- pxOtherSocket->usLocalPort,
- pxOtherSocket->u.xTCP.usChildCount,
- pxOtherSocket->u.xTCP.usBacklog,
- pxOtherSocket->u.xTCP.usChildCount == 1u ? "" : "ren" ) );
- break;
- }
- }
- }
-
-#endif /* ipconfigUSE_TCP == 1 */
-
-/*-----------------------------------------------------------*/
-
-BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength )
-{
-/* The standard Berkeley function returns 0 for success. */
-BaseType_t xReturn = -pdFREERTOS_ERRNO_EINVAL;
-BaseType_t lOptionValue;
-FreeRTOS_Socket_t *pxSocket;
-
- pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- /* The function prototype is designed to maintain the expected Berkeley
- sockets standard, but this implementation does not use all the parameters. */
- ( void ) lLevel;
- ( void ) xOptionLength;
-
- configASSERT( xSocket );
-
- switch( lOptionName )
- {
- case FREERTOS_SO_RCVTIMEO :
- /* Receive time out. */
- pxSocket->xReceiveBlockTime = *( ( TickType_t * ) pvOptionValue );
- xReturn = 0;
- break;
-
- case FREERTOS_SO_SNDTIMEO :
- pxSocket->xSendBlockTime = *( ( TickType_t * ) pvOptionValue );
- if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP )
- {
- /* The send time out is capped for the reason stated in the
- comments where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined
- in FreeRTOSIPConfig.h (assuming an official configuration file
- is being used. */
- if( pxSocket->xSendBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS )
- {
- pxSocket->xSendBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
- }
- }
- else
- {
- /* For TCP socket, it isn't necessary to limit the blocking time
- because the FreeRTOS_send() function does not wait for a network
- buffer to become available. */
- }
- xReturn = 0;
- break;
- #if( ipconfigUDP_MAX_RX_PACKETS > 0 )
- case FREERTOS_SO_UDP_MAX_RX_PACKETS:
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
- pxSocket->u.xUDP.uxMaxPackets = *( ( UBaseType_t * ) pvOptionValue );
- xReturn = 0;
- break;
- #endif /* ipconfigUDP_MAX_RX_PACKETS */
-
- case FREERTOS_SO_UDPCKSUM_OUT :
- /* Turn calculating of the UDP checksum on/off for this socket. */
- lOptionValue = ( BaseType_t ) pvOptionValue;
-
- if( lOptionValue == 0 )
- {
- pxSocket->ucSocketOptions &= ( uint8_t ) ~FREERTOS_SO_UDPCKSUM_OUT;
- }
- else
- {
- pxSocket->ucSocketOptions |= ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT;
- }
- xReturn = 0;
- break;
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- #if( ipconfigUSE_TCP == 1 )
- case FREERTOS_SO_TCP_CONN_HANDLER: /* Set a callback for (dis)connection events */
- case FREERTOS_SO_TCP_RECV_HANDLER: /* Install a callback for receiving TCP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- case FREERTOS_SO_TCP_SENT_HANDLER: /* Install a callback for sending TCP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- #endif /* ipconfigUSE_TCP */
- case FREERTOS_SO_UDP_RECV_HANDLER: /* Install a callback for receiving UDP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- case FREERTOS_SO_UDP_SENT_HANDLER: /* Install a callback for sending UDP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- {
- #if( ipconfigUSE_TCP == 1 )
- {
- UBaseType_t uxProtocol;
- if( ( lOptionName == FREERTOS_SO_UDP_RECV_HANDLER ) ||
- ( lOptionName == FREERTOS_SO_UDP_SENT_HANDLER ) )
- {
- uxProtocol = ( UBaseType_t ) FREERTOS_IPPROTO_UDP;
- }
- else
- {
- uxProtocol = ( UBaseType_t ) FREERTOS_IPPROTO_TCP;
- }
-
- if( pxSocket->ucProtocol != ( uint8_t ) uxProtocol )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
- }
- #else
- {
- /* No need to check if the socket has the right
- protocol, because only UDP socket can be created. */
- }
- #endif /* ipconfigUSE_TCP */
-
- switch( lOptionName )
- {
- #if ipconfigUSE_TCP == 1
- case FREERTOS_SO_TCP_CONN_HANDLER:
- pxSocket->u.xTCP.pxHandleConnected = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPConnected;
- break;
- case FREERTOS_SO_TCP_RECV_HANDLER:
- pxSocket->u.xTCP.pxHandleReceive = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPReceive;
- break;
- case FREERTOS_SO_TCP_SENT_HANDLER:
- pxSocket->u.xTCP.pxHandleSent = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPSent;
- break;
- #endif /* ipconfigUSE_TCP */
- case FREERTOS_SO_UDP_RECV_HANDLER:
- pxSocket->u.xUDP.pxHandleReceive = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnUDPReceive;
- break;
- case FREERTOS_SO_UDP_SENT_HANDLER:
- pxSocket->u.xUDP.pxHandleSent = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnUDPSent;
- break;
- default:
- break;
- }
- }
-
- xReturn = 0;
- break;
- #endif /* ipconfigUSE_CALLBACKS */
-
- #if( ipconfigUSE_TCP != 0 )
- #if( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 )
- /* Each socket has a semaphore on which the using task normally
- sleeps. */
- case FREERTOS_SO_SET_SEMAPHORE:
- {
- pxSocket->pxUserSemaphore = *( ( SemaphoreHandle_t * ) pvOptionValue );
- xReturn = 0;
- }
- break;
- #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
-
- #if( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK != 0 )
- case FREERTOS_SO_WAKEUP_CALLBACK:
- {
- /* Each socket can have a callback function that is executed
- when there is an event the socket's owner might want to
- process. */
- pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue;
- xReturn = 0;
- }
- break;
- #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */
-
- case FREERTOS_SO_SNDBUF: /* Set the size of the send buffer, in units of MSS (TCP only) */
- case FREERTOS_SO_RCVBUF: /* Set the size of the receive buffer, in units of MSS (TCP only) */
- {
- uint32_t ulNewValue;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- FreeRTOS_debug_printf( ( "Set SO_%sBUF: wrong socket type\n",
- ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- if( ( ( lOptionName == FREERTOS_SO_SNDBUF ) && ( pxSocket->u.xTCP.txStream != NULL ) ) ||
- ( ( lOptionName == FREERTOS_SO_RCVBUF ) && ( pxSocket->u.xTCP.rxStream != NULL ) ) )
- {
- FreeRTOS_debug_printf( ( "Set SO_%sBUF: buffer already created\n",
- ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- ulNewValue = *( ( uint32_t * ) pvOptionValue );
-
- if( lOptionName == FREERTOS_SO_SNDBUF )
- {
- /* Round up to nearest MSS size */
- ulNewValue = FreeRTOS_round_up( ulNewValue, ( uint32_t ) pxSocket->u.xTCP.usInitMSS );
- pxSocket->u.xTCP.uxTxStreamSize = ulNewValue;
- }
- else
- {
- pxSocket->u.xTCP.uxRxStreamSize = ulNewValue;
- }
- }
- xReturn = 0;
- break;
-
- case FREERTOS_SO_WIN_PROPERTIES: /* Set all buffer and window properties in one call, parameter is pointer to WinProperties_t */
- {
- WinProperties_t* pxProps;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- FreeRTOS_debug_printf( ( "Set SO_WIN_PROP: wrong socket type\n" ) );
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- if( ( pxSocket->u.xTCP.txStream != NULL ) || ( pxSocket->u.xTCP.rxStream != NULL ) )
- {
- FreeRTOS_debug_printf( ( "Set SO_WIN_PROP: buffer already created\n" ) );
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- pxProps = ( ( WinProperties_t * ) pvOptionValue );
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDBUF, &( pxProps->lTxBufSize ), sizeof( pxProps->lTxBufSize ) );
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVBUF, &( pxProps->lRxBufSize ), sizeof( pxProps->lRxBufSize ) );
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- pxSocket->u.xTCP.uxRxWinSize = ( uint32_t )pxProps->lRxWinSize; /* Fixed value: size of the TCP reception window */
- pxSocket->u.xTCP.uxTxWinSize = ( uint32_t )pxProps->lTxWinSize; /* Fixed value: size of the TCP transmit window */
- }
- #else
- {
- pxSocket->u.xTCP.uxRxWinSize = 1u;
- pxSocket->u.xTCP.uxTxWinSize = 1u;
- }
- #endif
-
- /* In case the socket has already initialised its tcpWin,
- adapt the window size parameters */
- if( pxSocket->u.xTCP.xTCPWindow.u.bits.bHasInit != pdFALSE_UNSIGNED )
- {
- pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength = pxSocket->u.xTCP.uxRxWinSize * pxSocket->u.xTCP.usInitMSS;
- pxSocket->u.xTCP.xTCPWindow.xSize.ulTxWindowLength = pxSocket->u.xTCP.uxTxWinSize * pxSocket->u.xTCP.usInitMSS;
- }
- }
-
- xReturn = 0;
- break;
-
- case FREERTOS_SO_REUSE_LISTEN_SOCKET: /* If true, the server-socket will turn into a connected socket */
- {
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
- if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
- {
- pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE_UNSIGNED;
- }
- else
- {
- pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE_UNSIGNED;
- }
- }
- xReturn = 0;
- break;
-
- case FREERTOS_SO_CLOSE_AFTER_SEND: /* As soon as the last byte has been transmitted, finalise the connection */
- {
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
- {
- pxSocket->u.xTCP.bits.bCloseAfterSend = pdTRUE_UNSIGNED;
- }
- else
- {
- pxSocket->u.xTCP.bits.bCloseAfterSend = pdFALSE_UNSIGNED;
- }
- }
- xReturn = 0;
- break;
-
- case FREERTOS_SO_SET_FULL_SIZE: /* Refuse to send packets smaller than MSS */
- {
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
- {
- pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
- }
- else
- {
- pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdFALSE_UNSIGNED;
- }
-
- if( ( pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize == pdFALSE_UNSIGNED ) &&
- ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) &&
- ( FreeRTOS_outstanding( pxSocket ) != 0 ) )
- {
- pxSocket->u.xTCP.usTimeout = 1u; /* to set/clear bSendFullSize */
- xSendEventToIPTask( eTCPTimerEvent );
- }
- }
- xReturn = 0;
- break;
-
- case FREERTOS_SO_STOP_RX: /* Refuse to receive more packts */
- {
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- break; /* will return -pdFREERTOS_ERRNO_EINVAL */
- }
-
- if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
- {
- pxSocket->u.xTCP.bits.bRxStopped = pdTRUE_UNSIGNED;
- }
- else
- {
- pxSocket->u.xTCP.bits.bRxStopped = pdFALSE_UNSIGNED;
- }
-
- pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.usTimeout = 1u; /* to set/clear bRxStopped */
- xSendEventToIPTask( eTCPTimerEvent );
- }
- xReturn = 0;
- break;
-
- #endif /* ipconfigUSE_TCP == 1 */
-
- default :
- /* No other options are handled. */
- xReturn = -pdFREERTOS_ERRNO_ENOPROTOOPT;
- break;
- }
-
- return xReturn;
-} /* Tested */
-
-/*-----------------------------------------------------------*/
-
-/* Find an available port number per https://tools.ietf.org/html/rfc6056. */
-static uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol )
-{
-const uint16_t usEphemeralPortCount =
- socketAUTO_PORT_ALLOCATION_MAX_NUMBER - socketAUTO_PORT_ALLOCATION_START_NUMBER + 1;
-uint16_t usIterations = usEphemeralPortCount;
-uint32_t ulRandomSeed = 0;
-uint16_t usResult = 0;
-BaseType_t xGotZeroOnce = pdFALSE;
-const List_t *pxList;
-
-#if ipconfigUSE_TCP == 1
- if( xProtocol == ( BaseType_t ) FREERTOS_IPPROTO_TCP )
- {
- pxList = &xBoundTCPSocketsList;
- }
- else
-#endif
- {
- pxList = &xBoundUDPSocketsList;
- }
-
- /* Avoid compiler warnings if ipconfigUSE_TCP is not defined. */
- ( void ) xProtocol;
-
- /* Find the next available port using the random seed as a starting
- point. */
- do
- {
- /* Generate a random seed. */
- ulRandomSeed = ipconfigRAND32( );
-
- /* Only proceed if the random number generator succeeded. */
- if( 0 == ulRandomSeed )
- {
- if( pdFALSE == xGotZeroOnce )
- {
- xGotZeroOnce = pdTRUE;
- continue;
- }
- else
- {
- break;
- }
- }
-
- /* Map the random to a candidate port. */
- usResult =
- socketAUTO_PORT_ALLOCATION_START_NUMBER +
- ( ( ( uint16_t )ulRandomSeed ) % usEphemeralPortCount );
-
- /* Check if there's already an open socket with the same protocol
- and port. */
- if( NULL == pxListFindListItemWithValue(
- pxList,
- ( TickType_t )FreeRTOS_htons( usResult ) ) )
- {
- usResult = FreeRTOS_htons( usResult );
- break;
- }
- else
- {
- usResult = 0;
- }
-
- usIterations--;
- }
- while( usIterations > 0 );
-
- return usResult;
-}
-/*-----------------------------------------------------------*/
-
-/* pxListFindListItemWithValue: find a list item in a bound socket list
-'xWantedItemValue' refers to a port number */
-static const ListItem_t * pxListFindListItemWithValue( const List_t *pxList, TickType_t xWantedItemValue )
-{
-const ListItem_t * pxResult = NULL;
-
- if( ( xIPIsNetworkTaskReady() != pdFALSE ) && ( pxList != NULL ) )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t *pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( pxList );
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( const ListItem_t * ) pxEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- if( listGET_LIST_ITEM_VALUE( pxIterator ) == xWantedItemValue )
- {
- pxResult = pxIterator;
- break;
- }
- }
- }
-
- return pxResult;
-} /* Tested */
-
-/*-----------------------------------------------------------*/
-
-FreeRTOS_Socket_t *pxUDPSocketLookup( UBaseType_t uxLocalPort )
-{
-const ListItem_t *pxListItem;
-FreeRTOS_Socket_t *pxSocket = NULL;
-
- /* Looking up a socket is quite simple, find a match with the local port.
-
- See if there is a list item associated with the port number on the
- list of bound sockets. */
- pxListItem = pxListFindListItemWithValue( &xBoundUDPSocketsList, ( TickType_t ) uxLocalPort );
-
- if( pxListItem != NULL )
- {
- /* The owner of the list item is the socket itself. */
- pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxListItem );
- configASSERT( pxSocket != NULL );
- }
- return pxSocket;
-}
-
-/*-----------------------------------------------------------*/
-
-#if ipconfigINCLUDE_FULL_INET_ADDR == 1
-
- uint32_t FreeRTOS_inet_addr( const char * pcIPAddress )
- {
- const uint32_t ulDecimalBase = 10u;
- uint8_t ucOctet[ socketMAX_IP_ADDRESS_OCTETS ];
- const char *pcPointerOnEntering;
- uint32_t ulReturn = 0UL, ulValue;
- UBaseType_t uxOctetNumber;
- BaseType_t xResult = pdPASS;
-
- for( uxOctetNumber = 0u; uxOctetNumber < socketMAX_IP_ADDRESS_OCTETS; uxOctetNumber++ )
- {
- ulValue = 0ul;
- pcPointerOnEntering = pcIPAddress;
-
- while( ( *pcIPAddress >= '0' ) && ( *pcIPAddress <= '9' ) )
- {
- /* Move previous read characters into the next decimal
- position. */
- ulValue *= ulDecimalBase;
-
- /* Add the binary value of the ascii character. */
- ulValue += ( ( uint32_t ) ( *pcIPAddress ) - ( uint32_t ) '0' );
-
- /* Move to next character in the string. */
- pcIPAddress++;
- }
-
- /* Check characters were read. */
- if( pcIPAddress == pcPointerOnEntering )
- {
- xResult = pdFAIL;
- }
-
- /* Check the value fits in an 8-bit number. */
- if( ulValue > 0xffUL )
- {
- xResult = pdFAIL;
- }
- else
- {
- ucOctet[ uxOctetNumber ] = ( uint8_t ) ulValue;
-
- /* Check the next character is as expected. */
- if( uxOctetNumber < ( socketMAX_IP_ADDRESS_OCTETS - 1u ) )
- {
- if( *pcIPAddress != '.' )
- {
- xResult = pdFAIL;
- }
- else
- {
- /* Move past the dot. */
- pcIPAddress++;
- }
- }
- }
-
- if( xResult == pdFAIL )
- {
- /* No point going on. */
- break;
- }
- }
-
- if( *pcIPAddress != ( char ) 0 )
- {
- /* Expected the end of the string. */
- xResult = pdFAIL;
- }
-
- if( uxOctetNumber != socketMAX_IP_ADDRESS_OCTETS )
- {
- /* Didn't read enough octets. */
- xResult = pdFAIL;
- }
-
- if( xResult == pdPASS )
- {
- ulReturn = FreeRTOS_inet_addr_quick( ucOctet[ 0 ], ucOctet[ 1 ], ucOctet[ 2 ], ucOctet[ 3 ] );
- }
-
- return ulReturn;
- }
-
-#endif /* ipconfigINCLUDE_FULL_INET_ADDR */
-
-/*-----------------------------------------------------------*/
-
-/* Function to get the local address and IP port */
-size_t FreeRTOS_GetLocalAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress )
-{
-FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- /* IP address of local machine. */
- pxAddress->sin_addr = *ipLOCAL_IP_ADDRESS_POINTER;
-
- /* Local port on this machine. */
- pxAddress->sin_port = FreeRTOS_htons( pxSocket->usLocalPort );
-
- return sizeof( *pxAddress );
-}
-
-/*-----------------------------------------------------------*/
-
-void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
-{
-/* _HT_ must work this out, now vSocketWakeUpUser will be called for any important
- * event or transition */
- #if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
- {
- if( pxSocket->pxUserSemaphore != NULL )
- {
- xSemaphoreGive( pxSocket->pxUserSemaphore );
- }
- }
- #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
-
- #if( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
- {
- if( pxSocket->pxUserWakeCallback != NULL )
- {
- pxSocket->pxUserWakeCallback( pxSocket );
- }
- }
- #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- if( pxSocket->pxSocketSet != NULL )
- {
- EventBits_t xSelectBits = ( pxSocket->xEventBits >> SOCKET_EVENT_BIT_COUNT ) & eSELECT_ALL;
- if( xSelectBits != 0ul )
- {
- pxSocket->xSocketBits |= xSelectBits;
- xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, xSelectBits );
- }
- }
-
- pxSocket->xEventBits &= eSOCKET_ALL;
- }
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
-
- if( ( pxSocket->xEventGroup != NULL ) && ( pxSocket->xEventBits != 0u ) )
- {
- xEventGroupSetBits( pxSocket->xEventGroup, pxSocket->xEventBits );
- }
-
- pxSocket->xEventBits = 0ul;
-}
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
-
- /* This define makes it possible for network-card drivers to inspect
- * UDP message and see if there is any UDP socket bound to a given port
- * number.
- * This is probably only usefull in systems with a minimum of RAM and
- * when lots of anonymous broadcast messages come in
- */
- BaseType_t xPortHasUDPSocket( uint16_t usPortNr )
- {
- BaseType_t xFound = pdFALSE;
-
- vTaskSuspendAll();
- {
- if( ( pxListFindListItemWithValue( &xBoundUDPSocketsList, ( TickType_t ) usPortNr ) != NULL ) )
- {
- xFound = pdTRUE;
- }
- }
- xTaskResumeAll();
-
- return xFound;
- }
-
-#endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- static BaseType_t bMayConnect( FreeRTOS_Socket_t *pxSocket );
- static BaseType_t bMayConnect( FreeRTOS_Socket_t *pxSocket )
- {
- switch( pxSocket->u.xTCP.ucTCPState )
- {
- case eCLOSED:
- case eCLOSE_WAIT: return 0;
- case eCONNECT_SYN: return -pdFREERTOS_ERRNO_EINPROGRESS;
- default: return -pdFREERTOS_ERRNO_EAGAIN;
- }
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr *pxAddress )
- {
- BaseType_t xResult = 0;
-
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdFALSE ) == pdFALSE )
- {
- /* Not a valid socket or wrong type */
- xResult = -pdFREERTOS_ERRNO_EBADF;
- }
- else if( FreeRTOS_issocketconnected( pxSocket ) > 0 )
- {
- /* The socket is already connected. */
- xResult = -pdFREERTOS_ERRNO_EISCONN;
- }
- else if( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE )
- {
- /* Bind the socket to the port that the client task will send from.
- Non-standard, so the error returned is that returned by bind(). */
- xResult = FreeRTOS_bind( ( Socket_t ) pxSocket, NULL, 0u );
- }
-
- if( xResult == 0 )
- {
- /* Check if it makes any sense to wait for a connect event, this condition
- might change while sleeping, so it must be checked within each loop */
- xResult = bMayConnect( pxSocket ); /* -EINPROGRESS, -EAGAIN, or 0 for OK */
-
- /* Start the connect procedure, kernel will start working on it */
- if( xResult == 0 )
- {
- pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.ucRepCount = 0u;
-
- FreeRTOS_debug_printf( ( "FreeRTOS_connect: %u to %lxip:%u\n",
- pxSocket->usLocalPort, FreeRTOS_ntohl( pxAddress->sin_addr ), FreeRTOS_ntohs( pxAddress->sin_port ) ) );
-
- /* Port on remote machine. */
- pxSocket->u.xTCP.usRemotePort = FreeRTOS_ntohs( pxAddress->sin_port );
-
- /* IP address of remote machine. */
- pxSocket->u.xTCP.ulRemoteIP = FreeRTOS_ntohl( pxAddress->sin_addr );
-
- /* (client) internal state: socket wants to send a connect. */
- vTCPStateChange( pxSocket, eCONNECT_SYN );
-
- /* To start an active connect. */
- pxSocket->u.xTCP.usTimeout = 1u;
-
- if( xSendEventToIPTask( eTCPTimerEvent ) != pdPASS )
- {
- xResult = -pdFREERTOS_ERRNO_ECANCELED;
- }
- }
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * FreeRTOS_connect: socket wants to connect to a remote port
- */
- BaseType_t FreeRTOS_connect( Socket_t xClientSocket, struct freertos_sockaddr *pxAddress, socklen_t xAddressLength )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t* ) xClientSocket;
- TickType_t xRemainingTime;
- BaseType_t xTimed = pdFALSE;
- BaseType_t xResult;
- TimeOut_t xTimeOut;
-
- ( void ) xAddressLength;
-
- xResult = prvTCPConnectStart( pxSocket, pxAddress );
-
- if( xResult == 0 )
- {
- /* And wait for the result */
- for( ;; )
- {
- if( xTimed == pdFALSE )
- {
- /* Only in the first round, check for non-blocking */
- xRemainingTime = pxSocket->xReceiveBlockTime;
- if( xRemainingTime == ( TickType_t )0 )
- {
- /* Not yet connected, correct state, non-blocking. */
- xResult = -pdFREERTOS_ERRNO_EWOULDBLOCK;
- break;
- }
-
- /* Don't get here a second time. */
- xTimed = pdTRUE;
-
- /* Fetch the current time */
- vTaskSetTimeOutState( &xTimeOut );
- }
-
- /* Did it get connected while sleeping ? */
- xResult = FreeRTOS_issocketconnected( pxSocket );
-
- /* Returns positive when connected, negative means an error */
- if( xResult < 0 )
- {
- /* Return the error */
- break;
- }
-
- if( xResult > 0 )
- {
- /* Socket now connected, return a zero */
- xResult = 0;
- break;
- }
-
- /* Is it allowed to sleep more? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) )
- {
- xResult = -pdFREERTOS_ERRNO_ETIMEDOUT;
- break;
- }
-
- /* Go sleeping until we get any down-stream event */
- xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_CONNECT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
- }
- }
-
- return xResult;
- }
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * FreeRTOS_accept: can return a new connected socket
- * if the server socket is in listen mode and receives a connection request
- * The new socket will be bound already to the same port number as the listing
- * socket.
- */
- Socket_t FreeRTOS_accept( Socket_t xServerSocket, struct freertos_sockaddr *pxAddress, socklen_t *pxAddressLength )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xServerSocket;
- FreeRTOS_Socket_t *pxClientSocket = NULL;
- TickType_t xRemainingTime;
- BaseType_t xTimed = pdFALSE, xAsk = pdFALSE;
- TimeOut_t xTimeOut;
- IPStackEvent_t xAskEvent;
-
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE )
- {
- /* Not a valid socket or wrong type */
- pxClientSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET;
- }
- else if( ( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) &&
- ( pxSocket->u.xTCP.ucTCPState != eTCP_LISTEN ) )
- {
- /* Parent socket is not in listening mode */
- pxClientSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET;
- }
- else
- {
- /* Loop will stop with breaks. */
- for( ; ; )
- {
- /* Is there a new client? */
- vTaskSuspendAll();
- {
- if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
- {
- pxClientSocket = pxSocket->u.xTCP.pxPeerSocket;
- }
- else
- {
- pxClientSocket = pxSocket;
- }
- if( pxClientSocket != NULL )
- {
- pxSocket->u.xTCP.pxPeerSocket = NULL;
-
- /* Is it still not taken ? */
- if( pxClientSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED )
- {
- pxClientSocket->u.xTCP.bits.bPassAccept = pdFALSE_UNSIGNED;
- }
- else
- {
- pxClientSocket = NULL;
- }
- }
- }
- xTaskResumeAll();
-
- if( pxClientSocket != NULL )
- {
- if( pxAddress != NULL )
- {
- /* IP address of remote machine. */
- pxAddress->sin_addr = FreeRTOS_ntohl( pxClientSocket->u.xTCP.ulRemoteIP );
-
- /* Port on remote machine. */
- pxAddress->sin_port = FreeRTOS_ntohs( pxClientSocket->u.xTCP.usRemotePort );
- }
- if( pxAddressLength != NULL )
- {
- *pxAddressLength = sizeof( *pxAddress );
- }
-
- if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
- {
- xAsk = pdTRUE;
- }
- }
-
- if( xAsk != pdFALSE )
- {
- /* Ask to set an event in 'xEventGroup' as soon as a new
- client gets connected for this listening socket. */
- xAskEvent.eEventType = eTCPAcceptEvent;
- xAskEvent.pvData = ( void * ) pxSocket;
- xSendEventStructToIPTask( &xAskEvent, portMAX_DELAY );
- }
-
- if( pxClientSocket != NULL )
- {
- break;
- }
-
- if( xTimed == pdFALSE )
- {
- /* Only in the first round, check for non-blocking */
- xRemainingTime = pxSocket->xReceiveBlockTime;
- if( xRemainingTime == ( TickType_t ) 0 )
- {
- break;
- }
-
- /* Don't get here a second time */
- xTimed = pdTRUE;
-
- /* Fetch the current time */
- vTaskSetTimeOutState( &xTimeOut );
- }
-
- /* Has the timeout been reached? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE )
- {
- break;
- }
-
- /* Go sleeping until we get any down-stream event */
- xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_ACCEPT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
- }
- }
-
- return ( Socket_t ) pxClientSocket;
- }
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * Read incoming data from a TCP socket
- * Only after the last byte has been read, a close error might be returned
- */
- BaseType_t FreeRTOS_recv( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags )
- {
- BaseType_t xByteCount;
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- TickType_t xRemainingTime;
- BaseType_t xTimed = pdFALSE;
- TimeOut_t xTimeOut;
- EventBits_t xEventBits = ( EventBits_t ) 0;
-
- /* Check if the socket is valid, has type TCP and if it is bound to a
- port. */
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE )
- {
- xByteCount = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- xByteCount = ( BaseType_t )uxStreamBufferGetSize ( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- xByteCount = 0;
- }
-
- while( xByteCount == 0 )
- {
- switch( pxSocket->u.xTCP.ucTCPState )
- {
- case eCLOSED:
- case eCLOSE_WAIT: /* (server + client) waiting for a connection termination request from the local user. */
- case eCLOSING: /* (server + client) waiting for a connection termination request acknowledgement from the remote TCP. */
- if( pxSocket->u.xTCP.bits.bMallocError != pdFALSE_UNSIGNED )
- {
- /* The no-memory error has priority above the non-connected error.
- Both are fatal and will elad to closing the socket. */
- xByteCount = -pdFREERTOS_ERRNO_ENOMEM;
- }
- else
- {
- xByteCount = -pdFREERTOS_ERRNO_ENOTCONN;
- }
- /* Call continue to break out of the switch and also the while
- loop. */
- continue;
- default:
- break;
- }
-
- if( xTimed == pdFALSE )
- {
- /* Only in the first round, check for non-blocking. */
- xRemainingTime = pxSocket->xReceiveBlockTime;
-
- if( xRemainingTime == ( TickType_t ) 0 )
- {
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- /* Just check for the interrupt flag. */
- xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_INTR,
- pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, socketDONT_BLOCK );
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
- break;
- }
-
- if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 )
- {
- break;
- }
-
- /* Don't get here a second time. */
- xTimed = pdTRUE;
-
- /* Fetch the current time. */
- vTaskSetTimeOutState( &xTimeOut );
- }
-
- /* Has the timeout been reached? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE )
- {
- break;
- }
-
- /* Block until there is a down-stream event. */
- xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup,
- eSOCKET_RECEIVE | eSOCKET_CLOSED | eSOCKET_INTR,
- pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- if( ( xEventBits & eSOCKET_INTR ) != 0u )
- {
- break;
- }
- }
- #else
- {
- ( void ) xEventBits;
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
-
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- xByteCount = ( BaseType_t ) uxStreamBufferGetSize ( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- xByteCount = 0;
- }
- }
-
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- if( ( xEventBits & eSOCKET_INTR ) != 0 )
- {
- if( ( xEventBits & ( eSOCKET_RECEIVE | eSOCKET_CLOSED ) ) != 0 )
- {
- /* Shouldn't have cleared other flags. */
- xEventBits &= ~eSOCKET_INTR;
- xEventGroupSetBits( pxSocket->xEventGroup, xEventBits );
- }
- xByteCount = -pdFREERTOS_ERRNO_EINTR;
- }
- else
- #endif /* ipconfigSUPPORT_SIGNALS */
- if( xByteCount > 0 )
- {
- if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 )
- {
- xByteCount = ( BaseType_t ) uxStreamBufferGet( pxSocket->u.xTCP.rxStream, 0ul, ( uint8_t * ) pvBuffer, ( size_t ) xBufferLength, ( xFlags & FREERTOS_MSG_PEEK ) != 0 );
- if( pxSocket->u.xTCP.bits.bLowWater != pdFALSE_UNSIGNED )
- {
- /* We had reached the low-water mark, now see if the flag
- can be cleared */
- size_t uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream );
-
- if( uxFrontSpace >= pxSocket->u.xTCP.uxEnoughSpace )
- {
- pxSocket->u.xTCP.bits.bLowWater = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.usTimeout = 1u; /* because bLowWater is cleared. */
- xSendEventToIPTask( eTCPTimerEvent );
- }
- }
- }
- else
- {
- /* Zero-copy reception of data: pvBuffer is a pointer to a pointer. */
- xByteCount = ( BaseType_t ) uxStreamBufferGetPtr( pxSocket->u.xTCP.rxStream, (uint8_t **)pvBuffer );
- }
- }
- } /* prvValidSocket() */
-
- return xByteCount;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t xDataLength )
- {
- int32_t xResult = 1;
-
- /* Is this a socket of type TCP and is it already bound to a port number ? */
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE )
- {
- xResult = -pdFREERTOS_ERRNO_EINVAL;
- }
- else if( pxSocket->u.xTCP.bits.bMallocError != pdFALSE_UNSIGNED )
- {
- xResult = -pdFREERTOS_ERRNO_ENOMEM;
- }
- else if( pxSocket->u.xTCP.ucTCPState == eCLOSED )
- {
- xResult = -pdFREERTOS_ERRNO_ENOTCONN;
- }
- else if( pxSocket->u.xTCP.bits.bFinSent != pdFALSE_UNSIGNED )
- {
- /* This TCP connection is closing already, the FIN flag has been sent.
- Maybe it is still delivering or receiving data.
- Return OK in order not to get closed/deleted too quickly */
- xResult = 0;
- }
- else if( xDataLength == 0ul )
- {
- /* send() is being called to send zero bytes */
- xResult = 0;
- }
- else if( pxSocket->u.xTCP.txStream == NULL )
- {
- /* Create the outgoing stream only when it is needed */
- prvTCPCreateStream( pxSocket, pdFALSE );
-
- if( pxSocket->u.xTCP.txStream == NULL )
- {
- xResult = -pdFREERTOS_ERRNO_ENOMEM;
- }
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* Get a direct pointer to the circular transmit buffer.
- '*pxLength' will contain the number of bytes that may be written. */
- uint8_t *FreeRTOS_get_tx_head( Socket_t xSocket, BaseType_t *pxLength )
- {
- uint8_t *pucReturn;
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- StreamBuffer_t *pxBuffer = pxSocket->u.xTCP.txStream;
-
- if( pxBuffer != NULL )
- {
- BaseType_t xSpace = ( BaseType_t ) uxStreamBufferGetSpace( pxBuffer );
- BaseType_t xRemain = ( BaseType_t ) ( pxBuffer->LENGTH - pxBuffer->uxHead );
-
- *pxLength = FreeRTOS_min_BaseType( xSpace, xRemain );
- pucReturn = pxBuffer->ucArray + pxBuffer->uxHead;
- }
- else
- {
- *pxLength = 0;
- pucReturn = NULL;
- }
-
- return pucReturn;
- }
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * Send data using a TCP socket. It is not necessary to have the socket
- * connected already. Outgoing data will be stored and delivered as soon as
- * the socket gets connected.
- */
- BaseType_t FreeRTOS_send( Socket_t xSocket, const void *pvBuffer, size_t uxDataLength, BaseType_t xFlags )
- {
- BaseType_t xByteCount;
- BaseType_t xBytesLeft;
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- TickType_t xRemainingTime;
- BaseType_t xTimed = pdFALSE;
- TimeOut_t xTimeOut;
- BaseType_t xCloseAfterSend;
-
- /* Prevent compiler warnings about unused parameters. The parameter
- may be used in future versions. */
- ( void ) xFlags;
-
- xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength );
-
- if( xByteCount > 0 )
- {
- /* xBytesLeft is number of bytes to send, will count to zero. */
- xBytesLeft = ( BaseType_t ) uxDataLength;
-
- /* xByteCount is number of bytes that can be sent now. */
- xByteCount = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream );
-
- /* While there are still bytes to be sent. */
- while( xBytesLeft > 0 )
- {
- /* If txStream has space. */
- if( xByteCount > 0 )
- {
- /* Don't send more than necessary. */
- if( xByteCount > xBytesLeft )
- {
- xByteCount = xBytesLeft;
- }
-
- /* Is the close-after-send flag set and is this really the
- last transmission? */
- if( ( pxSocket->u.xTCP.bits.bCloseAfterSend != pdFALSE_UNSIGNED ) && ( xByteCount == xBytesLeft ) )
- {
- xCloseAfterSend = pdTRUE;
- }
- else
- {
- xCloseAfterSend = pdFALSE;
- }
-
- /* The flag 'bCloseAfterSend' can be set before sending data
- using setsockopt()
-
- When the last data packet is being sent out, a FIN flag will
- be included to let the peer know that no more data is to be
- expected. The use of 'bCloseAfterSend' is not mandatory, it
- is just a faster way of transferring files (e.g. when using
- FTP). */
- if( xCloseAfterSend != pdFALSE )
- {
- /* Now suspend the scheduler: sending the last data and
- setting bCloseRequested must be done together */
- vTaskSuspendAll();
- pxSocket->u.xTCP.bits.bCloseRequested = pdTRUE_UNSIGNED;
- }
-
- xByteCount = ( BaseType_t ) uxStreamBufferAdd( pxSocket->u.xTCP.txStream, 0ul, ( const uint8_t * ) pvBuffer, ( size_t ) xByteCount );
-
- if( xCloseAfterSend != pdFALSE )
- {
- /* Now when the IP-task transmits the data, it will also
- see that bCloseRequested is true and include the FIN
- flag to start closure of the connection. */
- xTaskResumeAll();
- }
-
- /* Send a message to the IP-task so it can work on this
- socket. Data is sent, let the IP-task work on it. */
- pxSocket->u.xTCP.usTimeout = 1u;
-
- if( xIsCallingFromIPTask() == pdFALSE )
- {
- /* Only send a TCP timer event when not called from the
- IP-task. */
- xSendEventToIPTask( eTCPTimerEvent );
- }
-
- xBytesLeft -= xByteCount;
-
- if( xBytesLeft == 0 )
- {
- break;
- }
-
- /* As there are still bytes left to be sent, increase the
- data pointer. */
- pvBuffer = ( void * ) ( ( ( const uint8_t * ) pvBuffer) + xByteCount );
- }
-
- /* Not all bytes have been sent. In case the socket is marked as
- blocking sleep for a while. */
- if( xTimed == pdFALSE )
- {
- /* Only in the first round, check for non-blocking. */
- xRemainingTime = pxSocket->xSendBlockTime;
-
- #if( ipconfigUSE_CALLBACKS != 0 )
- {
- if( xIsCallingFromIPTask() != pdFALSE )
- {
- /* If this send function is called from within a
- call-back handler it may not block, otherwise
- chances would be big to get a deadlock: the IP-task
- waiting for itself. */
- xRemainingTime = ( TickType_t ) 0;
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- if( xRemainingTime == ( TickType_t ) 0 )
- {
- break;
- }
-
- if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 )
- {
- break;
- }
-
- /* Don't get here a second time. */
- xTimed = pdTRUE;
-
- /* Fetch the current time. */
- vTaskSetTimeOutState( &xTimeOut );
- }
- else
- {
- /* Has the timeout been reached? */
- if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE )
- {
- break;
- }
- }
-
- /* Go sleeping until down-stream events are received. */
- xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED,
- pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
-
- xByteCount = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream );
- }
-
- /* How much was actually sent? */
- xByteCount = ( ( BaseType_t ) uxDataLength ) - xBytesLeft;
-
- if( xByteCount == 0 )
- {
- if( pxSocket->u.xTCP.ucTCPState > eESTABLISHED )
- {
- xByteCount = ( BaseType_t ) -pdFREERTOS_ERRNO_ENOTCONN;
- }
- else
- {
- if( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE )
- {
- FreeRTOS_debug_printf( ( "FreeRTOS_send: %u -> %lxip:%d: no space\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort ) );
- }
-
- xByteCount = ( BaseType_t ) -pdFREERTOS_ERRNO_ENOSPC;
- }
- }
- }
-
- return xByteCount;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * Request to put a socket in listen mode
- */
- BaseType_t FreeRTOS_listen( Socket_t xSocket, BaseType_t xBacklog )
- {
- FreeRTOS_Socket_t *pxSocket;
- BaseType_t xResult = 0;
-
- pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
-
- /* listen() is allowed for a valid TCP socket in Closed state and already
- bound. */
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE )
- {
- xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP;
- }
- else if( ( pxSocket->u.xTCP.ucTCPState != eCLOSED ) && ( pxSocket->u.xTCP.ucTCPState != eCLOSE_WAIT ) )
- {
- /* Socket is in a wrong state. */
- xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP;
- }
- else
- {
- /* Backlog is interpreted here as "the maximum number of child
- sockets. */
- pxSocket->u.xTCP.usBacklog = ( uint16_t )FreeRTOS_min_int32( ( int32_t ) 0xffff, ( int32_t ) xBacklog );
-
- /* This cleaning is necessary only if a listening socket is being
- reused as it might have had a previous connection. */
- if( pxSocket->u.xTCP.bits.bReuseSocket )
- {
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- vStreamBufferClear( pxSocket->u.xTCP.rxStream );
- }
-
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- vStreamBufferClear( pxSocket->u.xTCP.txStream );
- }
-
- memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, '\0', sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
- memset( &pxSocket->u.xTCP.xTCPWindow, '\0', sizeof( pxSocket->u.xTCP.xTCPWindow ) );
- memset( &pxSocket->u.xTCP.bits, '\0', sizeof( pxSocket->u.xTCP.bits ) );
-
- /* Now set the bReuseSocket flag again, because the bits have
- just been cleared. */
- pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE_UNSIGNED;
- }
-
- vTCPStateChange( pxSocket, eTCP_LISTEN );
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* shutdown - shut down part of a full-duplex connection */
- BaseType_t FreeRTOS_shutdown( Socket_t xSocket, BaseType_t xHow )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xResult;
-
- if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE )
- {
- /*_RB_ Is this comment correct? The socket is not of a type that
- supports the listen() operation. */
- xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP;
- }
- else if ( pxSocket->u.xTCP.ucTCPState != eESTABLISHED )
- {
- /*_RB_ Is this comment correct? The socket is not of a type that
- supports the listen() operation. */
- xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP;
- }
- else
- {
- pxSocket->u.xTCP.bits.bUserShutdown = pdTRUE_UNSIGNED;
-
- /* Let the IP-task perform the shutdown of the connection. */
- pxSocket->u.xTCP.usTimeout = 1u;
- xSendEventToIPTask( eTCPTimerEvent );
- xResult = 0;
- }
- (void) xHow;
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * A TCP timer has expired, now check all TCP sockets for:
- * - Active connect
- * - Send a delayed ACK
- * - Send new data
- * - Send a keep-alive packet
- * - Check for timeout (in non-connected states only)
- */
- TickType_t xTCPTimerCheck( BaseType_t xWillSleep )
- {
- FreeRTOS_Socket_t *pxSocket;
- TickType_t xShortest = pdMS_TO_TICKS( ( TickType_t ) ipTCP_TIMER_PERIOD_MS );
- TickType_t xNow = xTaskGetTickCount();
- static TickType_t xLastTime = 0u;
- TickType_t xDelta = xNow - xLastTime;
- ListItem_t* pxEnd = ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList );
- ListItem_t *pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
-
- xLastTime = xNow;
-
- if( xDelta == 0u )
- {
- xDelta = 1u;
- }
-
- while( pxIterator != pxEnd )
- {
- pxSocket = ( FreeRTOS_Socket_t * )listGET_LIST_ITEM_OWNER( pxIterator );
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator );
-
- /* Sockets with 'tmout == 0' do not need any regular attention. */
- if( pxSocket->u.xTCP.usTimeout == 0u )
- {
- continue;
- }
-
- if( xDelta < ( TickType_t ) pxSocket->u.xTCP.usTimeout )
- {
- pxSocket->u.xTCP.usTimeout = ( uint16_t ) ( ( ( TickType_t ) pxSocket->u.xTCP.usTimeout ) - xDelta );
- }
- else
- {
- int rc ;
- pxSocket->u.xTCP.usTimeout = 0u;
- rc = xTCPSocketCheck( pxSocket );
-
- /* Within this function, the socket might want to send a delayed
- ack or send out data or whatever it needs to do. */
- if( rc < 0 )
- {
- /* Continue because the socket was deleted. */
- continue;
- }
- }
-
- /* In xEventBits the driver may indicate that the socket has
- important events for the user. These are only done just before the
- IP-task goes to sleep. */
- if( pxSocket->xEventBits != 0u )
- {
- if( xWillSleep != pdFALSE )
- {
- /* The IP-task is about to go to sleep, so messages can be
- sent to the socket owners. */
- vSocketWakeUpUser( pxSocket );
- }
- else
- {
- /* Or else make sure this will be called again to wake-up
- the sockets' owner. */
- xShortest = ( TickType_t ) 0;
- }
- }
-
- if( ( pxSocket->u.xTCP.usTimeout != 0u ) && ( xShortest > ( TickType_t ) pxSocket->u.xTCP.usTimeout ) )
- {
- xShortest = ( TickType_t ) pxSocket->u.xTCP.usTimeout;
- }
- }
-
- return xShortest;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * TCP: as multiple sockets may be bound to the same local port number
- * looking up a socket is a little more complex:
- * Both a local port, and a remote port and IP address are being used
- * For a socket in listening mode, the remote port and IP address are both 0
- */
- FreeRTOS_Socket_t *pxTCPSocketLookup( uint32_t ulLocalIP, UBaseType_t uxLocalPort, uint32_t ulRemoteIP, UBaseType_t uxRemotePort )
- {
- ListItem_t *pxIterator;
- FreeRTOS_Socket_t *pxResult = NULL, *pxListenSocket = NULL;
- MiniListItem_t *pxEnd = ( MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList );
-
- /* Parameter not yet supported. */
- ( void ) ulLocalIP;
-
- for( pxIterator = ( ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( ListItem_t * ) pxEnd;
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
-
- if( pxSocket->usLocalPort == ( uint16_t ) uxLocalPort )
- {
- if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN )
- {
- /* If this is a socket listening to uxLocalPort, remember it
- in case there is no perfect match. */
- pxListenSocket = pxSocket;
- }
- else if( ( pxSocket->u.xTCP.usRemotePort == ( uint16_t ) uxRemotePort ) && ( pxSocket->u.xTCP.ulRemoteIP == ulRemoteIP ) )
- {
- /* For sockets not in listening mode, find a match with
- xLocalPort, ulRemoteIP AND xRemotePort. */
- pxResult = pxSocket;
- break;
- }
- }
- }
- if( pxResult == NULL )
- {
- /* An exact match was not found, maybe a listening socket was
- found. */
- pxResult = pxListenSocket;
- }
-
- return pxResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- const struct xSTREAM_BUFFER *FreeRTOS_get_rx_buf( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = (FreeRTOS_Socket_t *)xSocket;
-
- return pxSocket->u.xTCP.rxStream;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- static StreamBuffer_t *prvTCPCreateStream ( FreeRTOS_Socket_t *pxSocket, BaseType_t xIsInputStream )
- {
- StreamBuffer_t *pxBuffer;
- size_t uxLength;
- size_t uxSize;
-
- /* Now that a stream is created, the maximum size is fixed before
- creation, it could still be changed with setsockopt(). */
- if( xIsInputStream != pdFALSE )
- {
- uxLength = pxSocket->u.xTCP.uxRxStreamSize;
-
- if( pxSocket->u.xTCP.uxLittleSpace == 0ul )
- {
- pxSocket->u.xTCP.uxLittleSpace = ( 1ul * pxSocket->u.xTCP.uxRxStreamSize ) / 5u; /*_RB_ Why divide by 5? Can this be changed to a #define? */
- }
-
- if( pxSocket->u.xTCP.uxEnoughSpace == 0ul )
- {
- pxSocket->u.xTCP.uxEnoughSpace = ( 4ul * pxSocket->u.xTCP.uxRxStreamSize ) / 5u; /*_RB_ Why multiply by 4? Maybe sock80_PERCENT?*/
- }
- }
- else
- {
- uxLength = pxSocket->u.xTCP.uxTxStreamSize;
- }
-
- /* Add an extra 4 (or 8) bytes. */
- uxLength += sizeof( size_t );
-
- /* And make the length a multiple of sizeof( size_t ). */
- uxLength &= ~( sizeof( size_t ) - 1u );
-
- uxSize = sizeof( *pxBuffer ) - sizeof( pxBuffer->ucArray ) + uxLength;
-
- pxBuffer = ( StreamBuffer_t * )pvPortMallocLarge( uxSize );
-
- if( pxBuffer == NULL )
- {
- FreeRTOS_debug_printf( ( "prvTCPCreateStream: malloc failed\n" ) );
- pxSocket->u.xTCP.bits.bMallocError = pdTRUE_UNSIGNED;
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
- }
- else
- {
- /* Clear the markers of the stream */
- memset( pxBuffer, '\0', sizeof( *pxBuffer ) - sizeof( pxBuffer->ucArray ) );
- pxBuffer->LENGTH = ( size_t ) uxLength ;
-
- if( xTCPWindowLoggingLevel != 0 )
- {
- FreeRTOS_debug_printf( ( "prvTCPCreateStream: %cxStream created %lu bytes (total %lu)\n", xIsInputStream ? 'R' : 'T', uxLength, uxSize ) );
- }
-
- if( xIsInputStream != 0 )
- {
- pxSocket->u.xTCP.rxStream = pxBuffer;
- }
- else
- {
- pxSocket->u.xTCP.txStream = pxBuffer;
- }
- }
-
- return pxBuffer;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * Add data to the RxStream. When uxOffset > 0, data has come in out-of-order
- * and will be put in front of the head so it can not be popped by the user.
- */
- int32_t lTCPAddRxdata( FreeRTOS_Socket_t *pxSocket, size_t uxOffset, const uint8_t *pcData, uint32_t ulByteCount )
- {
- StreamBuffer_t *pxStream = pxSocket->u.xTCP.rxStream;
- int32_t xResult;
- #if( ipconfigUSE_CALLBACKS == 1 )
- BaseType_t bHasHandler = ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleReceive );
- const uint8_t *pucBuffer = NULL;
- #endif /* ipconfigUSE_CALLBACKS */
-
- /* int32_t uxStreamBufferAdd( pxBuffer, uxOffset, pucData, aCount )
- if( pucData != NULL ) copy data the the buffer
- if( pucData == NULL ) no copying, just advance rxHead
- if( uxOffset != 0 ) Just store data which has come out-of-order
- if( uxOffset == 0 ) Also advance rxHead */
- if( pxStream == NULL )
- {
- pxStream = prvTCPCreateStream( pxSocket, pdTRUE );
- if( pxStream == NULL )
- {
- return -1;
- }
- }
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ( bHasHandler != pdFALSE ) && ( uxStreamBufferGetSize( pxStream ) == 0u ) && ( uxOffset == 0ul ) && ( pcData != NULL ) )
- {
- /* Data can be passed directly to the user */
- pucBuffer = pcData;
-
- /* Zero-copy for call-back: no need to add the bytes to the
- stream, only the pointer will be advanced by uxStreamBufferAdd(). */
- pcData = NULL;
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- xResult = ( int32_t ) uxStreamBufferAdd( pxStream, uxOffset, pcData, ( size_t ) ulByteCount );
-
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( xResult != ( int32_t ) ulByteCount )
- {
- FreeRTOS_debug_printf( ( "lTCPAddRxdata: at %ld: %ld/%lu bytes (tail %lu head %lu space %lu front %lu)\n",
- uxOffset, xResult, ulByteCount,
- pxStream->uxTail,
- pxStream->uxHead,
- uxStreamBufferFrontSpace( pxStream ),
- pxStream->uxFront ) );
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
-
- if( uxOffset == 0u )
- {
- /* Data is being added to rxStream at the head (offs = 0) */
- #if( ipconfigUSE_CALLBACKS == 1 )
- if( bHasHandler != pdFALSE )
- {
- /* The socket owner has installed an OnReceive handler. Pass the
- Rx data, without copying from the rxStream, to the user. */
- for (;;)
- {
- uint8_t *ucReadPtr = NULL;
- uint32_t ulCount;
- if( pucBuffer != NULL )
- {
- ucReadPtr = ( uint8_t * )pucBuffer;
- ulCount = ulByteCount;
- pucBuffer = NULL;
- }
- else
- {
- ulCount = ( uint32_t ) uxStreamBufferGetPtr( pxStream, &( ucReadPtr ) );
- }
-
- if( ulCount == 0ul )
- {
- break;
- }
-
- pxSocket->u.xTCP.pxHandleReceive( (Socket_t *)pxSocket, ( void* )ucReadPtr, ( size_t ) ulCount );
- uxStreamBufferGet( pxStream, 0ul, NULL, ( size_t ) ulCount, pdFALSE );
- }
- } else
- #endif /* ipconfigUSE_CALLBACKS */
- {
- /* See if running out of space. */
- if( pxSocket->u.xTCP.bits.bLowWater == pdFALSE_UNSIGNED )
- {
- size_t uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream );
- if( uxFrontSpace <= pxSocket->u.xTCP.uxLittleSpace )
- {
- pxSocket->u.xTCP.bits.bLowWater = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
-
- /* bLowWater was reached, send the changed window size. */
- pxSocket->u.xTCP.usTimeout = 1u;
- xSendEventToIPTask( eTCPTimerEvent );
- }
- }
-
- /* New incoming data is available, wake up the user. User's
- semaphores will be set just before the IP-task goes asleep. */
- pxSocket->xEventBits |= eSOCKET_RECEIVE;
-
- #if ipconfigSUPPORT_SELECT_FUNCTION == 1
- {
- if( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 )
- {
- pxSocket->xEventBits |= ( eSELECT_READ << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
- }
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* Function to get the remote address and IP port */
- BaseType_t FreeRTOS_GetRemoteAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xResult;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xResult = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- /* BSD style sockets communicate IP and port addresses in network
- byte order.
-
- IP address of remote machine. */
- pxAddress->sin_addr = FreeRTOS_htonl ( pxSocket->u.xTCP.ulRemoteIP );
-
- /* Port on remote machine. */
- pxAddress->sin_port = FreeRTOS_htons ( pxSocket->u.xTCP.usRemotePort );
-
- xResult = ( BaseType_t ) sizeof( ( *pxAddress ) );
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* Returns the number of bytes that may be added to txStream */
- BaseType_t FreeRTOS_maywrite( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xResult;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xResult = -pdFREERTOS_ERRNO_EINVAL;
- }
- else if( pxSocket->u.xTCP.ucTCPState != eESTABLISHED )
- {
- if( ( pxSocket->u.xTCP.ucTCPState < eCONNECT_SYN ) || ( pxSocket->u.xTCP.ucTCPState > eESTABLISHED ) )
- {
- xResult = -1;
- }
- else
- {
- xResult = 0;
- }
- }
- else if( pxSocket->u.xTCP.txStream == NULL )
- {
- xResult = ( BaseType_t ) pxSocket->u.xTCP.uxTxStreamSize;
- }
- else
- {
- xResult = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream );
- }
-
- return xResult;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP ==1 )
-
- BaseType_t FreeRTOS_tx_space( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- xReturn = ( BaseType_t ) uxStreamBufferGetSpace ( pxSocket->u.xTCP.txStream );
- }
- else
- {
- xReturn = ( BaseType_t ) pxSocket->u.xTCP.uxTxStreamSize;
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- BaseType_t FreeRTOS_tx_size( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- xReturn = ( BaseType_t ) uxStreamBufferGetSize ( pxSocket->u.xTCP.txStream );
- }
- else
- {
- xReturn = 0;
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* Returns pdTRUE if TCP socket is connected. */
- BaseType_t FreeRTOS_issocketconnected( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn = pdFALSE;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- if( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED )
- {
- if( pxSocket->u.xTCP.ucTCPState < eCLOSE_WAIT )
- {
- xReturn = pdTRUE;
- }
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* returns the actual size of MSS being used */
- BaseType_t FreeRTOS_mss( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- /* usCurMSS is declared as uint16_t to save space. FreeRTOS_mss()
- will often be used in signed native-size expressions cast it to
- BaseType_t. */
- xReturn = ( BaseType_t ) ( pxSocket->u.xTCP.usCurMSS );
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /* HT: for internal use only: return the connection status */
- BaseType_t FreeRTOS_connstatus( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- {
- /* Cast it to BaseType_t */
- xReturn = ( BaseType_t ) ( pxSocket->u.xTCP.ucTCPState );
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * Returns the number of bytes which can be read.
- */
- BaseType_t FreeRTOS_rx_size( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else if( pxSocket->u.xTCP.rxStream != NULL )
- {
- xReturn = ( BaseType_t ) uxStreamBufferGetSize( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- xReturn = 0;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP == 1 )
-
- void FreeRTOS_netstat( void )
- {
- IPStackEvent_t xAskEvent;
-
- /* Ask the IP-task to call vTCPNetStat()
- * to avoid accessing xBoundTCPSocketsList
- */
- xAskEvent.eEventType = eTCPNetStat;
- xAskEvent.pvData = ( void * ) NULL;
- xSendEventStructToIPTask( &xAskEvent, 1000u );
- }
-
-#endif /* ipconfigUSE_TCP */
-/*-----------------------------------------------------------*/
-
-#if( ( ipconfigHAS_PRINTF != 0 ) && ( ipconfigUSE_TCP == 1 ) )
-
- void vTCPNetStat( void )
- {
- /* Show a simple listing of all created sockets and their connections */
- ListItem_t *pxIterator;
- BaseType_t count = 0;
-
- if( listLIST_IS_INITIALISED( &xBoundTCPSocketsList ) == pdFALSE )
- {
- FreeRTOS_printf( ( "PLUS-TCP not initialized\n" ) );
- }
- else
- {
- FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) );
- for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
- pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList );
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- #if( ipconfigTCP_KEEP_ALIVE == 1 )
- TickType_t age = xTaskGetTickCount() - pxSocket->u.xTCP.xLastAliveTime;
- #else
- TickType_t age = 0u;
- #endif
- #if( ipconfigUSE_CALLBACKS == 1 )
- void *pxHandleReceive = (void*)pxSocket->u.xTCP.pxHandleReceive;
- #else
- void *pxHandleReceive = (void*)NULL;
- #endif
- char ucChildText[16] = "";
- if (pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN)
- {
- const int32_t copied_len = snprintf( ucChildText, sizeof( ucChildText ), " %d/%d",
- ( int ) pxSocket->u.xTCP.usChildCount,
- ( int ) pxSocket->u.xTCP.usBacklog);
- /* These should never evaluate to false since the buffers are both shorter than 5-6 characters (<=65535) */
- configASSERT( copied_len >= 0 );
- configASSERT( copied_len < sizeof( ucChildText ) );
- }
- FreeRTOS_printf( ( "TCP %5d %-16lxip:%5d %d/%d %-13.13s %6lu %6u%s\n",
- pxSocket->usLocalPort, /* Local port on this machine */
- pxSocket->u.xTCP.ulRemoteIP, /* IP address of remote machine */
- pxSocket->u.xTCP.usRemotePort, /* Port on remote machine */
- pxSocket->u.xTCP.rxStream != NULL,
- pxSocket->u.xTCP.txStream != NULL,
- FreeRTOS_GetTCPStateName( pxSocket->u.xTCP.ucTCPState ),
- (age > 999999 ? 999999 : age), /* Format 'age' for printing */
- pxSocket->u.xTCP.usTimeout,
- ucChildText ) );
- /* Remove compiler warnings if FreeRTOS_debug_printf() is not defined. */
- ( void ) pxHandleReceive;
- count++;
- }
-
- for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundUDPSocketsList );
- pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundUDPSocketsList );
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- /* Local port on this machine */
- FreeRTOS_printf( ( "UDP Port %5u\n",
- FreeRTOS_ntohs( listGET_LIST_ITEM_VALUE( pxIterator ) ) ) );
- count++;
- }
-
- FreeRTOS_printf( ( "FreeRTOS_netstat: %lu sockets %lu < %lu < %d buffers free\n",
- count,
- uxGetMinimumFreeNetworkBuffers( ),
- uxGetNumberOfFreeNetworkBuffers( ),
- ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) );
- }
- }
-
-#endif /* ( ( ipconfigHAS_PRINTF != 0 ) && ( ipconfigUSE_TCP == 1 ) ) */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
- void vSocketSelect( SocketSelect_t *pxSocketSet )
- {
- BaseType_t xRound;
- EventBits_t xSocketBits, xBitsToClear;
- #if ipconfigUSE_TCP == 1
- BaseType_t xLastRound = 1;
- #else
- BaseType_t xLastRound = 0;
- #endif
-
- /* These flags will be switched on after checking the socket status. */
- EventBits_t xGroupBits = 0;
- pxSocketSet->pxSocket = NULL;
-
- for( xRound = 0; xRound <= xLastRound; xRound++ )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t *pxEnd;
- if( xRound == 0 )
- {
- pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundUDPSocketsList );
- }
- #if ipconfigUSE_TCP == 1
- else
- {
- pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList );
- }
- #endif /* ipconfigUSE_TCP == 1 */
- for( pxIterator = ( const ListItem_t * ) ( listGET_NEXT( pxEnd ) );
- pxIterator != ( const ListItem_t * ) pxEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- if( pxSocket->pxSocketSet != pxSocketSet )
- {
- /* Socket does not belong to this select group. */
- continue;
- }
- xSocketBits = 0;
-
- #if( ipconfigUSE_TCP == 1 )
- if( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP )
- {
- /* Check if the socket has already been accepted by the
- owner. If not, it is useless to return it from a
- select(). */
- BaseType_t bAccepted = pdFALSE;
-
- if( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED )
- {
- if( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED )
- {
- bAccepted = pdTRUE;
- }
- }
-
- /* Is the set owner interested in READ events? */
- if( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 )
- {
- if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN )
- {
- if( ( pxSocket->u.xTCP.pxPeerSocket != NULL ) && ( pxSocket->u.xTCP.pxPeerSocket->u.xTCP.bits.bPassAccept != 0 ) )
- {
- xSocketBits |= eSELECT_READ;
- }
- }
- else if( ( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED ) && ( pxSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
- {
- /* This socket has the re-use flag. After connecting it turns into
- aconnected socket. Set the READ event, so that accept() will be called. */
- xSocketBits |= eSELECT_READ;
- }
- else if( ( bAccepted != 0 ) && ( FreeRTOS_recvcount( pxSocket ) > 0 ) )
- {
- xSocketBits |= eSELECT_READ;
- }
- }
- /* Is the set owner interested in EXCEPTION events? */
- if( ( pxSocket->xSelectBits & eSELECT_EXCEPT ) != 0 )
- {
- if( ( pxSocket->u.xTCP.ucTCPState == eCLOSE_WAIT ) || ( pxSocket->u.xTCP.ucTCPState == eCLOSED ) )
- {
- xSocketBits |= eSELECT_EXCEPT;
- }
- }
-
- /* Is the set owner interested in WRITE events? */
- if( ( pxSocket->xSelectBits & eSELECT_WRITE ) != 0 )
- {
- BaseType_t bMatch = pdFALSE;
-
- if( bAccepted != 0 )
- {
- if( FreeRTOS_tx_space( pxSocket ) > 0 )
- {
- bMatch = pdTRUE;
- }
- }
-
- if( bMatch == pdFALSE )
- {
- if( ( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED ) &&
- ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) &&
- ( pxSocket->u.xTCP.bits.bConnPassed == pdFALSE_UNSIGNED ) )
- {
- pxSocket->u.xTCP.bits.bConnPassed = pdTRUE_UNSIGNED;
- bMatch = pdTRUE;
- }
- }
-
- if( bMatch != pdFALSE )
- {
- xSocketBits |= eSELECT_WRITE;
- }
- }
- }
- else
- #endif /* ipconfigUSE_TCP == 1 */
- {
- /* Select events for UDP are simpler. */
- if( ( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 ) &&
- ( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U ) )
- {
- xSocketBits |= eSELECT_READ;
- }
- /* The WRITE and EXCEPT bits are not used for UDP */
- } /* if( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP ) */
-
- /* Each socket keeps its own event flags, which are looked-up
- by FreeRTOS_FD_ISSSET() */
- pxSocket->xSocketBits = xSocketBits;
-
- /* The ORed value will be used to set the bits in the event
- group. */
- xGroupBits |= xSocketBits;
-
- } /* for( pxIterator ... ) */
- } /* for( xRound = 0; xRound <= xLastRound; xRound++ ) */
-
- xBitsToClear = xEventGroupGetBits( pxSocketSet->xSelectGroup );
-
- /* Now set the necessary bits. */
- xBitsToClear = ( xBitsToClear & ~xGroupBits ) & eSELECT_ALL;
-
- #if( ipconfigSUPPORT_SIGNALS != 0 )
- {
- /* Maybe the socketset was signalled, but don't
- clear the 'eSELECT_INTR' bit here, as it will be used
- and cleared in FreeRTOS_select(). */
- xBitsToClear &= ( EventBits_t ) ~eSELECT_INTR;
- }
- #endif /* ipconfigSUPPORT_SIGNALS */
-
- if( xBitsToClear != 0 )
- {
- xEventGroupClearBits( pxSocketSet->xSelectGroup, xBitsToClear );
- }
-
- /* Now include eSELECT_CALL_IP to wakeup the caller. */
- xEventGroupSetBits( pxSocketSet->xSelectGroup, xGroupBits | eSELECT_CALL_IP );
- }
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SIGNALS != 0 )
-
- /* Send a signal to the task which reads from this socket. */
- BaseType_t FreeRTOS_SignalSocket( Socket_t xSocket )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
-
- if( pxSocket == NULL )
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
- else
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- if( ( pxSocket->pxSocketSet != NULL ) && ( pxSocket->pxSocketSet->xSelectGroup != NULL ) )
- {
- xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, eSELECT_INTR );
- xReturn = 0;
- }
- else
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
- if( pxSocket->xEventGroup != NULL )
- {
- xEventGroupSetBits( pxSocket->xEventGroup, eSOCKET_INTR );
- xReturn = 0;
- }
- else
- {
- xReturn = -pdFREERTOS_ERRNO_EINVAL;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigSUPPORT_SIGNALS */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigSUPPORT_SIGNALS != 0 )
-
- /* Send a signal to the task which reads from this socket (FromISR version). */
- BaseType_t FreeRTOS_SignalSocketFromISR( Socket_t xSocket, BaseType_t *pxHigherPriorityTaskWoken )
- {
- FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
- BaseType_t xReturn;
- IPStackEvent_t xEvent;
- extern QueueHandle_t xNetworkEventQueue;
-
- configASSERT( pxSocket != NULL );
- configASSERT( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP );
- configASSERT( pxSocket->xEventGroup );
-
- xEvent.eEventType = eSocketSignalEvent;
- xEvent.pvData = ( void * )pxSocket;
-
- /* The IP-task will call FreeRTOS_SignalSocket for this socket. */
- xReturn = xQueueSendToBackFromISR( xNetworkEventQueue, &xEvent, pxHigherPriorityTaskWoken );
-
- return xReturn;
- }
-
-#endif /* ipconfigSUPPORT_SIGNALS */
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c
deleted file mode 100755
index 09067f0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-
-/*
- * uxStreamBufferAdd( )
- * Adds data to a stream buffer. If uxOffset > 0, data will be written at
- * an offset from uxHead while uxHead will not be moved yet. This possibility
- * will be used when TCP data is received while earlier data is still missing.
- * If 'pucData' equals NULL, the function is called to advance 'uxHead' only.
- */
-size_t uxStreamBufferAdd( StreamBuffer_t *pxBuffer, size_t uxOffset, const uint8_t *pucData, size_t uxCount )
-{
-size_t uxSpace, uxNextHead, uxFirst;
-
- uxSpace = uxStreamBufferGetSpace( pxBuffer );
-
- /* If uxOffset > 0, items can be placed in front of uxHead */
- if( uxSpace > uxOffset )
- {
- uxSpace -= uxOffset;
- }
- else
- {
- uxSpace = 0u;
- }
-
- /* The number of bytes that can be written is the minimum of the number of
- bytes requested and the number available. */
- uxCount = FreeRTOS_min_uint32( uxSpace, uxCount );
-
- if( uxCount != 0u )
- {
- uxNextHead = pxBuffer->uxHead;
-
- if( uxOffset != 0u )
- {
- /* ( uxOffset > 0 ) means: write in front if the uxHead marker */
- uxNextHead += uxOffset;
- if( uxNextHead >= pxBuffer->LENGTH )
- {
- uxNextHead -= pxBuffer->LENGTH;
- }
- }
-
- if( pucData != NULL )
- {
- /* Calculate the number of bytes that can be added in the first
- write - which may be less than the total number of bytes that need
- to be added if the buffer will wrap back to the beginning. */
- uxFirst = FreeRTOS_min_uint32( pxBuffer->LENGTH - uxNextHead, uxCount );
-
- /* Write as many bytes as can be written in the first write. */
- memcpy( ( void* ) ( pxBuffer->ucArray + uxNextHead ), pucData, uxFirst );
-
- /* If the number of bytes written was less than the number that
- could be written in the first write... */
- if( uxCount > uxFirst )
- {
- /* ...then write the remaining bytes to the start of the
- buffer. */
- memcpy( ( void * )pxBuffer->ucArray, pucData + uxFirst, uxCount - uxFirst );
- }
- }
-
- if( uxOffset == 0u )
- {
- /* ( uxOffset == 0 ) means: write at uxHead position */
- uxNextHead += uxCount;
- if( uxNextHead >= pxBuffer->LENGTH )
- {
- uxNextHead -= pxBuffer->LENGTH;
- }
- pxBuffer->uxHead = uxNextHead;
- }
-
- if( xStreamBufferLessThenEqual( pxBuffer, pxBuffer->uxFront, uxNextHead ) != pdFALSE )
- {
- /* Advance the front pointer */
- pxBuffer->uxFront = uxNextHead;
- }
- }
-
- return uxCount;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * uxStreamBufferGet( )
- * 'uxOffset' can be used to read data located at a certain offset from 'lTail'.
- * If 'pucData' equals NULL, the function is called to advance 'lTail' only.
- * if 'xPeek' is pdTRUE, or if 'uxOffset' is non-zero, the 'lTail' pointer will
- * not be advanced.
- */
-size_t uxStreamBufferGet( StreamBuffer_t *pxBuffer, size_t uxOffset, uint8_t *pucData, size_t uxMaxCount, BaseType_t xPeek )
-{
-size_t uxSize, uxCount, uxFirst, uxNextTail;
-
- /* How much data is available? */
- uxSize = uxStreamBufferGetSize( pxBuffer );
-
- if( uxSize > uxOffset )
- {
- uxSize -= uxOffset;
- }
- else
- {
- uxSize = 0u;
- }
-
- /* Use the minimum of the wanted bytes and the available bytes. */
- uxCount = FreeRTOS_min_uint32( uxSize, uxMaxCount );
-
- if( uxCount > 0u )
- {
- uxNextTail = pxBuffer->uxTail;
-
- if( uxOffset != 0u )
- {
- uxNextTail += uxOffset;
- if( uxNextTail >= pxBuffer->LENGTH )
- {
- uxNextTail -= pxBuffer->LENGTH;
- }
- }
-
- if( pucData != NULL )
- {
- /* Calculate the number of bytes that can be read - which may be
- less than the number wanted if the data wraps around to the start of
- the buffer. */
- uxFirst = FreeRTOS_min_uint32( pxBuffer->LENGTH - uxNextTail, uxCount );
-
- /* Obtain the number of bytes it is possible to obtain in the first
- read. */
- memcpy( pucData, pxBuffer->ucArray + uxNextTail, uxFirst );
-
- /* If the total number of wanted bytes is greater than the number
- that could be read in the first read... */
- if( uxCount > uxFirst )
- {
- /*...then read the remaining bytes from the start of the buffer. */
- memcpy( pucData + uxFirst, pxBuffer->ucArray, uxCount - uxFirst );
- }
- }
-
- if( ( xPeek == pdFALSE ) && ( uxOffset == 0UL ) )
- {
- /* Move the tail pointer to effecively remove the data read from
- the buffer. */
- uxNextTail += uxCount;
-
- if( uxNextTail >= pxBuffer->LENGTH )
- {
- uxNextTail -= pxBuffer->LENGTH;
- }
-
- pxBuffer->uxTail = uxNextTail;
- }
- }
-
- return uxCount;
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
deleted file mode 100755
index 27e6484..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
+++ /dev/null
@@ -1,3309 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/*
- * FreeRTOS_TCP_IP.c
- * Module which handles the TCP connections for FreeRTOS+TCP.
- * It depends on FreeRTOS_TCP_WIN.c, which handles the TCP windowing
- * schemes.
- *
- * Endianness: in this module all ports and IP addresses are stored in
- * host byte-order, except fields in the IP-packets
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_TCP_IP.h"
-#include "FreeRTOS_DHCP.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-#include "FreeRTOS_ARP.h"
-#include "FreeRTOS_TCP_WIN.h"
-
-
-/* Just make sure the contents doesn't get compiled if TCP is not enabled. */
-#if ipconfigUSE_TCP == 1
-
-/* This compile-time test was moved to here because some macro's
-were unknown within 'FreeRTOSIPConfigDefaults.h'. It tests whether
-the defined MTU size can contain at least a complete TCP packet. */
-
-#if ( ( ipconfigTCP_MSS + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) > ipconfigNETWORK_MTU )
- #error The ipconfigTCP_MSS setting in FreeRTOSIPConfig.h is too large.
-#endif
-
-/*
- * The meaning of the TCP flags:
- */
-#define ipTCP_FLAG_FIN 0x0001u /* No more data from sender */
-#define ipTCP_FLAG_SYN 0x0002u /* Synchronize sequence numbers */
-#define ipTCP_FLAG_RST 0x0004u /* Reset the connection */
-#define ipTCP_FLAG_PSH 0x0008u /* Push function: please push buffered data to the recv application */
-#define ipTCP_FLAG_ACK 0x0010u /* Acknowledgment field is significant */
-#define ipTCP_FLAG_URG 0x0020u /* Urgent pointer field is significant */
-#define ipTCP_FLAG_ECN 0x0040u /* ECN-Echo */
-#define ipTCP_FLAG_CWR 0x0080u /* Congestion Window Reduced */
-#define ipTCP_FLAG_NS 0x0100u /* ECN-nonce concealment protection */
-#define ipTCP_FLAG_RSV 0x0E00u /* Reserved, keep 0 */
-
-/* A mask to filter all protocol flags. */
-#define ipTCP_FLAG_CTRL 0x001Fu
-
-/*
- * A few values of the TCP options:
- */
-#define TCP_OPT_END 0u /* End of TCP options list */
-#define TCP_OPT_NOOP 1u /* "No-operation" TCP option */
-#define TCP_OPT_MSS 2u /* Maximum segment size TCP option */
-#define TCP_OPT_WSOPT 3u /* TCP Window Scale Option (3-byte long) */
-#define TCP_OPT_SACK_P 4u /* Advertize that SACK is permitted */
-#define TCP_OPT_SACK_A 5u /* SACK option with first/last */
-#define TCP_OPT_TIMESTAMP 8u /* Time-stamp option */
-
-#define TCP_OPT_MSS_LEN 4u /* Length of TCP MSS option. */
-#define TCP_OPT_WSOPT_LEN 3u /* Length of TCP WSOPT option. */
-
-#define TCP_OPT_TIMESTAMP_LEN 10 /* fixed length of the time-stamp option */
-
-#ifndef ipconfigTCP_ACK_EARLIER_PACKET
- #define ipconfigTCP_ACK_EARLIER_PACKET 1
-#endif
-
-/*
- * The macro NOW_CONNECTED() is use to determine if the connection makes a
- * transition from connected to non-connected and vice versa.
- * NOW_CONNECTED() returns true when the status has one of these values:
- * eESTABLISHED, eFIN_WAIT_1, eFIN_WAIT_2, eCLOSING, eLAST_ACK, eTIME_WAIT
- * Technically the connection status is closed earlier, but the library wants
- * to prevent that the socket will be deleted before the last ACK has been
- * and thus causing a 'RST' packet on either side.
- */
-#define NOW_CONNECTED( status )\
- ( ( status >= eESTABLISHED ) && ( status != eCLOSE_WAIT ) )
-
-/*
- * The highest 4 bits in the TCP offset byte indicate the total length of the
- * TCP header, divided by 4.
- */
-#define VALID_BITS_IN_TCP_OFFSET_BYTE ( 0xF0u )
-
-/*
- * Acknowledgements to TCP data packets may be delayed as long as more is being expected.
- * A normal delay would be 200ms. Here a much shorter delay of 20 ms is being used to
- * gain performance.
- */
-#define DELAYED_ACK_SHORT_DELAY_MS ( 2 )
-#define DELAYED_ACK_LONGER_DELAY_MS ( 20 )
-
-/*
- * The MSS (Maximum Segment Size) will be taken as large as possible. However, packets with
- * an MSS of 1460 bytes won't be transported through the internet. The MSS will be reduced
- * to 1400 bytes.
- */
-#define REDUCED_MSS_THROUGH_INTERNET ( 1400 )
-
-/*
- * When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
- * the number 5 (words) in the higher niblle of the TCP-offset byte.
- */
-#define TCP_OFFSET_LENGTH_BITS ( 0xf0u )
-#define TCP_OFFSET_STANDARD_LENGTH ( 0x50u )
-
-/*
- * Each TCP socket is checked regularly to see if it can send data packets.
- * By default, the maximum number of packets sent during one check is limited to 8.
- * This amount may be further limited by setting the socket's TX window size.
- */
-#if( !defined( SEND_REPEATED_COUNT ) )
- #define SEND_REPEATED_COUNT ( 8 )
-#endif /* !defined( SEND_REPEATED_COUNT ) */
-
-/*
- * Define a maximum perdiod of time (ms) to leave a TCP-socket unattended.
- * When a TCP timer expires, retries and keep-alive messages will be checked.
- */
-#ifndef tcpMAXIMUM_TCP_WAKEUP_TIME_MS
- #define tcpMAXIMUM_TCP_WAKEUP_TIME_MS 20000u
-#endif
-
-/*
- * The names of the different TCP states may be useful in logging.
- */
-#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
- static const char *pcStateNames[] = {
- "eCLOSED",
- "eTCP_LISTEN",
- "eCONNECT_SYN",
- "eSYN_FIRST",
- "eSYN_RECEIVED",
- "eESTABLISHED",
- "eFIN_WAIT_1",
- "eFIN_WAIT_2",
- "eCLOSE_WAIT",
- "eCLOSING",
- "eLAST_ACK",
- "eTIME_WAIT",
- "eUNKNOWN",
-};
-#endif /* ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) */
-
-/*
- * Returns true if the socket must be checked. Non-active sockets are waiting
- * for user action, either connect() or close().
- */
-static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus );
-
-/*
- * Either sends a SYN or calls prvTCPSendRepeated (for regular messages).
- */
-static int32_t prvTCPSendPacket( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Try to send a series of messages.
- */
-static int32_t prvTCPSendRepeated( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer );
-
-/*
- * Return or send a packet to the other party.
- */
-static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
- uint32_t ulLen, BaseType_t xReleaseAfterSend );
-
-/*
- * Initialise the data structures which keep track of the TCP windowing system.
- */
-static void prvTCPCreateWindow( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Let ARP look-up the MAC-address of the peer and initialise the first SYN
- * packet.
- */
-static BaseType_t prvTCPPrepareConnect( FreeRTOS_Socket_t *pxSocket );
-
-#if( ipconfigHAS_DEBUG_PRINTF != 0 )
- /*
- * For logging and debugging: make a string showing the TCP flags.
- */
- static const char *prvTCPFlagMeaning( UBaseType_t xFlags);
-#endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
-/*
- * Parse the TCP option(s) received, if present.
- */
-static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-/*
- * Set the initial properties in the options fields, like the preferred
- * value of MSS and whether SACK allowed. Will be transmitted in the state
- * 'eCONNECT_SYN'.
- */
-static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPPacket_t * pxTCPPacket );
-
-/*
- * For anti-hang protection and TCP keep-alive messages. Called in two places:
- * after receiving a packet and after a state change. The socket's alive timer
- * may be reset.
- */
-static void prvTCPTouchSocket( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Prepare an outgoing message, if anything has to be sent.
- */
-static int32_t prvTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer, UBaseType_t uxOptionsLength );
-
-/*
- * Calculate when this socket needs to be checked to do (re-)transmissions.
- */
-static TickType_t prvTCPNextTimeout( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * The API FreeRTOS_send() adds data to the TX stream. Add
- * this data to the windowing system to it can be transmitted.
- */
-static void prvTCPAddTxData( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Called to handle the closure of a TCP connection.
- */
-static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-/*
- * Called from prvTCPHandleState(). Find the TCP payload data and check and
- * return its length.
- */
-static BaseType_t prvCheckRxData( NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData );
-
-/*
- * Called from prvTCPHandleState(). Check if the payload data may be accepted.
- * If so, it will be added to the socket's reception queue.
- */
-static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, uint8_t *pucRecvData,
- NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength );
-
-/*
- * Set the TCP options (if any) for the outgoing packet.
- */
-static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-/*
- * Called from prvTCPHandleState() as long as the TCP status is eSYN_RECEIVED to
- * eCONNECT_SYN.
- */
-static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, UBaseType_t uxOptionsLength );
-
-/*
- * Called from prvTCPHandleState() as long as the TCP status is eESTABLISHED.
- */
-static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, UBaseType_t uxOptionsLength );
-
-/*
- * Called from prvTCPHandleState(). There is data to be sent.
- * If ipconfigUSE_TCP_WIN is defined, and if only an ACK must be sent, it will
- * be checked if it would better be postponed for efficiency.
- */
-static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, BaseType_t xSendLength );
-
-/*
- * The heart of all: check incoming packet for valid data and acks and do what
- * is necessary in each state.
- */
-static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer );
-
-/*
- * Reply to a peer with the RST flag on, in case a packet can not be handled.
- */
-static BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-/*
- * Set the initial value for MSS (Maximum Segment Size) to be used.
- */
-static void prvSocketSetMSS( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Return either a newly created socket, or the current socket in a connected
- * state (depends on the 'bReuseSocket' flag).
- */
-static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-/*
- * After a listening socket receives a new connection, it may duplicate itself.
- * The copying takes place in prvTCPSocketCopy.
- */
-static BaseType_t prvTCPSocketCopy( FreeRTOS_Socket_t *pxNewSocket, FreeRTOS_Socket_t *pxSocket );
-
-/*
- * prvTCPStatusAgeCheck() will see if the socket has been in a non-connected
- * state for too long. If so, the socket will be closed, and -1 will be
- * returned.
- */
-#if( ipconfigTCP_HANG_PROTECTION == 1 )
- static BaseType_t prvTCPStatusAgeCheck( FreeRTOS_Socket_t *pxSocket );
-#endif
-
-static NetworkBufferDescriptor_t *prvTCPBufferResize( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
- int32_t lDataLen, UBaseType_t uxOptionsLength );
-
-#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
- const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState );
-#endif
-
-#if( ipconfigUSE_TCP_WIN != 0 )
- static uint8_t prvWinScaleFactor( FreeRTOS_Socket_t *pxSocket );
-#endif
-
-/*
- * Generate a randomized TCP Initial Sequence Number per RFC.
- */
-extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
- uint16_t usSourcePort,
- uint32_t ulDestinationAddress,
- uint16_t usDestinationPort );
-
-/*-----------------------------------------------------------*/
-
-/* prvTCPSocketIsActive() returns true if the socket must be checked.
- * Non-active sockets are waiting for user action, either connect()
- * or close(). */
-static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
-{
- switch( uxStatus )
- {
- case eCLOSED:
- case eCLOSE_WAIT:
- case eFIN_WAIT_2:
- case eCLOSING:
- case eTIME_WAIT:
- return pdFALSE;
- default:
- return pdTRUE;
- }
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigTCP_HANG_PROTECTION == 1 )
-
- static BaseType_t prvTCPStatusAgeCheck( FreeRTOS_Socket_t *pxSocket )
- {
- BaseType_t xResult;
- switch( pxSocket->u.xTCP.ucTCPState )
- {
- case eESTABLISHED:
- /* If the 'ipconfigTCP_KEEP_ALIVE' option is enabled, sockets in
- state ESTABLISHED can be protected using keep-alive messages. */
- xResult = pdFALSE;
- break;
- case eCLOSED:
- case eTCP_LISTEN:
- case eCLOSE_WAIT:
- /* These 3 states may last for ever, up to the owner. */
- xResult = pdFALSE;
- break;
- default:
- /* All other (non-connected) states will get anti-hanging
- protection. */
- xResult = pdTRUE;
- break;
- }
- if( xResult != pdFALSE )
- {
- /* How much time has past since the last active moment which is
- defined as A) a state change or B) a packet has arrived. */
- TickType_t xAge = xTaskGetTickCount( ) - pxSocket->u.xTCP.xLastActTime;
-
- /* ipconfigTCP_HANG_PROTECTION_TIME is in units of seconds. */
- if( xAge > ( ipconfigTCP_HANG_PROTECTION_TIME * configTICK_RATE_HZ ) )
- {
- #if( ipconfigHAS_DEBUG_PRINTF == 1 )
- {
- FreeRTOS_debug_printf( ( "Inactive socket closed: port %u rem %lxip:%u status %s\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- FreeRTOS_GetTCPStateName( ( UBaseType_t ) pxSocket->u.xTCP.ucTCPState ) ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
-
- /* Move to eCLOSE_WAIT, user may close the socket. */
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
-
- /* When 'bPassQueued' true, this socket is an orphan until it
- gets connected. */
- if( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED )
- {
- if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
- {
- /* As it did not get connected, and the user can never
- accept() it anymore, it will be deleted now. Called from
- the IP-task, so it's safe to call the internal Close
- function: vSocketClose(). */
- vSocketClose( pxSocket );
- }
- /* Return a negative value to tell to inform the caller
- xTCPTimerCheck()
- that the socket got closed and may not be accessed anymore. */
- xResult = -1;
- }
- }
- }
- return xResult;
- }
- /*-----------------------------------------------------------*/
-
-#endif
-
-/*
- * As soon as a TCP socket timer expires, this function xTCPSocketCheck
- * will be called (from xTCPTimerCheck)
- * It can send a delayed ACK or new data
- * Sequence of calling (normally) :
- * IP-Task:
- * xTCPTimerCheck() // Check all sockets ( declared in FreeRTOS_Sockets.c )
- * xTCPSocketCheck() // Either send a delayed ACK or call prvTCPSendPacket()
- * prvTCPSendPacket() // Either send a SYN or call prvTCPSendRepeated ( regular messages )
- * prvTCPSendRepeated() // Send at most 8 messages on a row
- * prvTCPReturnPacket() // Prepare for returning
- * xNetworkInterfaceOutput() // Sends data to the NIC ( declared in portable/NetworkInterface/xxx )
- */
-BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t *pxSocket )
-{
-BaseType_t xResult = 0;
-BaseType_t xReady = pdFALSE;
-
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && ( pxSocket->u.xTCP.txStream != NULL ) )
- {
- /* The API FreeRTOS_send() might have added data to the TX stream. Add
- this data to the windowing system to it can be transmitted. */
- prvTCPAddTxData( pxSocket );
- }
-
- #if ipconfigUSE_TCP_WIN == 1
- {
- if( pxSocket->u.xTCP.pxAckMessage != NULL )
- {
- /* The first task of this regular socket check is to send-out delayed
- ACK's. */
- if( pxSocket->u.xTCP.bits.bUserShutdown == pdFALSE_UNSIGNED )
- {
- /* Earlier data was received but not yet acknowledged. This
- function is called when the TCP timer for the socket expires, the
- ACK may be sent now. */
- if( pxSocket->u.xTCP.ucTCPState != eCLOSED )
- {
- if( xTCPWindowLoggingLevel > 1 && ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) )
- {
- FreeRTOS_debug_printf( ( "Send[%u->%u] del ACK %lu SEQ %lu (len %u)\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
- pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - pxSocket->u.xTCP.xTCPWindow.tx.ulFirstSequenceNumber,
- ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) );
- }
-
- prvTCPReturnPacket( pxSocket, pxSocket->u.xTCP.pxAckMessage, ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER, ipconfigZERO_COPY_TX_DRIVER );
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* The ownership has been passed to the SEND routine,
- clear the pointer to it. */
- pxSocket->u.xTCP.pxAckMessage = NULL;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
- }
- if( prvTCPNextTimeout( pxSocket ) > 1 )
- {
- /* Tell the code below that this function is ready. */
- xReady = pdTRUE;
- }
- }
- else
- {
- /* The user wants to perform an active shutdown(), skip sending
- the delayed ACK. The function prvTCPSendPacket() will send the
- FIN along with the ACK's. */
- }
-
- if( pxSocket->u.xTCP.pxAckMessage != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxSocket->u.xTCP.pxAckMessage );
- pxSocket->u.xTCP.pxAckMessage = NULL;
- }
- }
- }
- #endif /* ipconfigUSE_TCP_WIN */
-
- if( xReady == pdFALSE )
- {
- /* The second task of this regular socket check is sending out data. */
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) ||
- ( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ) )
- {
- prvTCPSendPacket( pxSocket );
- }
-
- /* Set the time-out for the next wakeup for this socket. */
- prvTCPNextTimeout( pxSocket );
-
- #if( ipconfigTCP_HANG_PROTECTION == 1 )
- {
- /* In all (non-connected) states in which keep-alive messages can not be sent
- the anti-hang protocol will close sockets that are 'hanging'. */
- xResult = prvTCPStatusAgeCheck( pxSocket );
- }
- #endif
- }
-
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvTCPSendPacket() will be called when the socket time-out has been reached.
- * It is only called by xTCPSocketCheck().
- */
-static int32_t prvTCPSendPacket( FreeRTOS_Socket_t *pxSocket )
-{
-int32_t lResult = 0;
-UBaseType_t uxOptionsLength;
-TCPPacket_t *pxTCPPacket;
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-
- if( pxSocket->u.xTCP.ucTCPState != eCONNECT_SYN )
- {
- /* The connection is in s state other than SYN. */
- pxNetworkBuffer = NULL;
-
- /* prvTCPSendRepeated() will only create a network buffer if necessary,
- i.e. when data must be sent to the peer. */
- lResult = prvTCPSendRepeated( pxSocket, &pxNetworkBuffer );
-
- if( pxNetworkBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- }
- else
- {
- if( pxSocket->u.xTCP.ucRepCount >= 3u )
- {
- /* The connection is in the SYN status. The packet will be repeated
- to most 3 times. When there is no response, the socket get the
- status 'eCLOSE_WAIT'. */
- FreeRTOS_debug_printf( ( "Connect: giving up %lxip:%u\n",
- pxSocket->u.xTCP.ulRemoteIP, /* IP address of remote machine. */
- pxSocket->u.xTCP.usRemotePort ) ); /* Port on remote machine. */
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
- }
- else if( ( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED ) || ( prvTCPPrepareConnect( pxSocket ) == pdTRUE ) )
- {
- /* Or else, if the connection has been prepared, or can be prepared
- now, proceed to send the packet with the SYN flag.
- prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if
- the Ethernet address of the peer or the gateway is found. */
- pxTCPPacket = ( TCPPacket_t * )pxSocket->u.xTCP.xPacket.u.ucLastPacket;
-
- /* About to send a SYN packet. Call prvSetSynAckOptions() to set
- the proper options: The size of MSS and whether SACK's are
- allowed. */
- uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPPacket );
-
- /* Return the number of bytes to be sent. */
- lResult = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
-
- /* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and
- uxOptionsLength is always a multiple of 4. The complete expression
- would be:
- ucTCPOffset = ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) / 4 ) << 4 */
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
-
- /* Repeat Count is used for a connecting socket, to limit the number
- of tries. */
- pxSocket->u.xTCP.ucRepCount++;
-
- /* Send the SYN message to make a connection. The messages is
- stored in the socket field 'xPacket'. It will be wrapped in a
- pseudo network buffer descriptor before it will be sent. */
- prvTCPReturnPacket( pxSocket, NULL, ( uint32_t ) lResult, pdFALSE );
- }
- }
-
- /* Return the total number of bytes sent. */
- return lResult;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvTCPSendRepeated will try to send a series of messages, as long as there is
- * data to be sent and as long as the transmit window isn't full.
- */
-static int32_t prvTCPSendRepeated( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer )
-{
-UBaseType_t uxIndex;
-int32_t lResult = 0;
-UBaseType_t uxOptionsLength = 0u;
-int32_t xSendLength;
-
- for( uxIndex = 0u; uxIndex < ( UBaseType_t ) SEND_REPEATED_COUNT; uxIndex++ )
- {
- /* prvTCPPrepareSend() might allocate a network buffer if there is data
- to be sent. */
- xSendLength = prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );
- if( xSendLength <= 0 )
- {
- break;
- }
-
- /* And return the packet to the peer. */
- prvTCPReturnPacket( pxSocket, *ppxNetworkBuffer, ( uint32_t ) xSendLength, ipconfigZERO_COPY_TX_DRIVER );
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- *ppxNetworkBuffer = NULL;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- lResult += xSendLength;
- }
-
- /* Return the total number of bytes sent. */
- return lResult;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Return (or send) a packet the the peer. The data is stored in pxBuffer,
- * which may either point to a real network buffer or to a TCP socket field
- * called 'xTCP.xPacket'. A temporary xNetworkBuffer will be used to pass
- * the data to the NIC.
- */
-static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulLen, BaseType_t xReleaseAfterSend )
-{
-TCPPacket_t * pxTCPPacket;
-IPHeader_t *pxIPHeader;
-EthernetHeader_t *pxEthernetHeader;
-uint32_t ulFrontSpace, ulSpace, ulSourceAddress, ulWinSize;
-TCPWindow_t *pxTCPWindow;
-NetworkBufferDescriptor_t xTempBuffer;
-/* For sending, a pseudo network buffer will be used, as explained above. */
-
- if( pxNetworkBuffer == NULL )
- {
- pxNetworkBuffer = &xTempBuffer;
-
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- {
- xTempBuffer.pxNextBuffer = NULL;
- }
- #endif
- xTempBuffer.pucEthernetBuffer = pxSocket->u.xTCP.xPacket.u.ucLastPacket;
- xTempBuffer.xDataLength = sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
- xReleaseAfterSend = pdFALSE;
- }
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- if( xReleaseAfterSend == pdFALSE )
- {
- pxNetworkBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, ( BaseType_t ) pxNetworkBuffer->xDataLength );
- if( pxNetworkBuffer == NULL )
- {
- FreeRTOS_debug_printf( ( "prvTCPReturnPacket: duplicate failed\n" ) );
- }
- xReleaseAfterSend = pdTRUE;
- }
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- if( pxNetworkBuffer != NULL )
- {
- pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
- pxIPHeader = &pxTCPPacket->xIPHeader;
- pxEthernetHeader = &pxTCPPacket->xEthernetHeader;
-
- /* Fill the packet, using hton translations. */
- if( pxSocket != NULL )
- {
- /* Calculate the space in the RX buffer in order to advertise the
- size of this socket's reception window. */
- pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
-
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- /* An RX stream was created already, see how much space is
- available. */
- ulFrontSpace = ( uint32_t ) uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- /* No RX stream has been created, the full stream size is
- available. */
- ulFrontSpace = ( uint32_t ) pxSocket->u.xTCP.uxRxStreamSize;
- }
-
- /* Take the minimum of the RX buffer space and the RX window size. */
- ulSpace = FreeRTOS_min_uint32( pxSocket->u.xTCP.ulRxCurWinSize, pxTCPWindow->xSize.ulRxWindowLength );
-
- if( ( pxSocket->u.xTCP.bits.bLowWater != pdFALSE_UNSIGNED ) || ( pxSocket->u.xTCP.bits.bRxStopped != pdFALSE_UNSIGNED ) )
- {
- /* The low-water mark was reached, meaning there was little
- space left. The socket will wait until the application has read
- or flushed the incoming data, and 'zero-window' will be
- advertised. */
- ulSpace = 0u;
- }
-
- /* If possible, advertise an RX window size of at least 1 MSS, otherwise
- the peer might start 'zero window probing', i.e. sending small packets
- (1, 2, 4, 8... bytes). */
- if( ( ulSpace < pxSocket->u.xTCP.usCurMSS ) && ( ulFrontSpace >= pxSocket->u.xTCP.usCurMSS ) )
- {
- ulSpace = pxSocket->u.xTCP.usCurMSS;
- }
-
- /* Avoid overflow of the 16-bit win field. */
- #if( ipconfigUSE_TCP_WIN != 0 )
- {
- ulWinSize = ( ulSpace >> pxSocket->u.xTCP.ucMyWinScaleFactor );
- }
- #else
- {
- ulWinSize = ulSpace;
- }
- #endif
- if( ulWinSize > 0xfffcUL )
- {
- ulWinSize = 0xfffcUL;
- }
-
- pxTCPPacket->xTCPHeader.usWindow = FreeRTOS_htons( ( uint16_t ) ulWinSize );
-
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE )
- {
- if( ( xTCPWindowLoggingLevel != 0 ) && ( pxSocket->u.xTCP.bits.bWinChange != pdFALSE_UNSIGNED ) )
- {
- size_t uxFrontSpace;
-
- if(pxSocket->u.xTCP.rxStream != NULL)
- {
- uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream ) ;
- }
- else
- {
- uxFrontSpace = 0u;
- }
-
- FreeRTOS_debug_printf( ( "%s: %lxip:%u: [%lu < %lu] winSize %ld\n",
- pxSocket->u.xTCP.bits.bLowWater ? "STOP" : "GO ",
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- pxSocket->u.xTCP.bits.bLowWater ? pxSocket->u.xTCP.uxLittleSpace : uxFrontSpace, pxSocket->u.xTCP.uxEnoughSpace,
- (int32_t) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulCurrentSequenceNumber ) ) );
- }
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
- /* The new window size has been advertised, switch off the flag. */
- pxSocket->u.xTCP.bits.bWinChange = pdFALSE_UNSIGNED;
-
- /* Later on, when deciding to delay an ACK, a precise estimate is needed
- of the free RX space. At this moment, 'ulHighestRxAllowed' would be the
- highest sequence number minus 1 that the socket will accept. */
- pxSocket->u.xTCP.ulHighestRxAllowed = pxTCPWindow->rx.ulCurrentSequenceNumber + ulSpace;
-
- #if( ipconfigTCP_KEEP_ALIVE == 1 )
- if( pxSocket->u.xTCP.bits.bSendKeepAlive != pdFALSE_UNSIGNED )
- {
- /* Sending a keep-alive packet, send the current sequence number
- minus 1, which will be recognised as a keep-alive packet an
- responded to by acknowledging the last byte. */
- pxSocket->u.xTCP.bits.bSendKeepAlive = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.bits.bWaitKeepAlive = pdTRUE_UNSIGNED;
-
- pxTCPPacket->xTCPHeader.ulSequenceNumber = pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - 1UL;
- pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
- }
- else
- #endif
- {
- pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber );
-
- if( ( pxTCPPacket->xTCPHeader.ucTCPFlags & ( uint8_t ) ipTCP_FLAG_FIN ) != 0u )
- {
- /* Suppress FIN in case this packet carries earlier data to be
- retransmitted. */
- uint32_t ulDataLen = ( uint32_t ) ( ulLen - ( ipSIZE_OF_TCP_HEADER + ipSIZE_OF_IPv4_HEADER ) );
- if( ( pxTCPWindow->ulOurSequenceNumber + ulDataLen ) != pxTCPWindow->tx.ulFINSequenceNumber )
- {
- pxTCPPacket->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~ipTCP_FLAG_FIN );
- FreeRTOS_debug_printf( ( "Suppress FIN for %lu + %lu < %lu\n",
- pxTCPWindow->ulOurSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- ulDataLen,
- pxTCPWindow->tx.ulFINSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber ) );
- }
- }
- }
-
- /* Tell which sequence number is expected next time */
- pxTCPPacket->xTCPHeader.ulAckNr = FreeRTOS_htonl( pxTCPWindow->rx.ulCurrentSequenceNumber );
- }
- else
- {
- /* Sending data without a socket, probably replying with a RST flag
- Just swap the two sequence numbers. */
- vFlip_32( pxTCPPacket->xTCPHeader.ulSequenceNumber, pxTCPPacket->xTCPHeader.ulAckNr );
- }
-
- pxIPHeader->ucTimeToLive = ( uint8_t ) ipconfigTCP_TIME_TO_LIVE;
- pxIPHeader->usLength = FreeRTOS_htons( ulLen );
- if( ( pxSocket == NULL ) || ( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ) )
- {
- /* When pxSocket is NULL, this function is called by prvTCPSendReset()
- and the IP-addresses must be swapped.
- Also swap the IP-addresses in case the IP-tack doesn't have an
- IP-address yet, i.e. when ( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ). */
- ulSourceAddress = pxIPHeader->ulDestinationIPAddress;
- }
- else
- {
- ulSourceAddress = *ipLOCAL_IP_ADDRESS_POINTER;
- }
- pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress;
- pxIPHeader->ulSourceIPAddress = ulSourceAddress;
- vFlip_16( pxTCPPacket->xTCPHeader.usSourcePort, pxTCPPacket->xTCPHeader.usDestinationPort );
-
- /* Just an increasing number. */
- pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
- usPacketIdentifier++;
- pxIPHeader->usFragmentOffset = 0u;
-
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
- {
- /* calculate the IP header checksum, in case the driver won't do that. */
- pxIPHeader->usHeaderChecksum = 0x00u;
- pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0UL, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
- pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
-
- /* calculate the TCP checksum for an outgoing packet. */
- usGenerateProtocolChecksum( (uint8_t*)pxTCPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
-
- /* A calculated checksum of 0 must be inverted as 0 means the checksum
- is disabled. */
- if( pxTCPPacket->xTCPHeader.usChecksum == 0x00u )
- {
- pxTCPPacket->xTCPHeader.usChecksum = 0xffffU;
- }
- }
- #endif
-
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- pxNetworkBuffer->pxNextBuffer = NULL;
- #endif
-
- /* Important: tell NIC driver how many bytes must be sent. */
- pxNetworkBuffer->xDataLength = ulLen + ipSIZE_OF_ETH_HEADER;
-
- /* Fill in the destination MAC addresses. */
- memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( void * ) &( pxEthernetHeader->xSourceAddress ),
- sizeof( pxEthernetHeader->xDestinationAddress ) );
-
- /* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */
- memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
-
- #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- BaseType_t xIndex;
-
- for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
- {
- pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0u;
- }
- pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
- }
- }
- #endif
-
- /* Send! */
- xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend );
-
- if( xReleaseAfterSend == pdFALSE )
- {
- /* Swap-back some fields, as pxBuffer probably points to a socket field
- containing the packet header. */
- vFlip_16( pxTCPPacket->xTCPHeader.usSourcePort, pxTCPPacket->xTCPHeader.usDestinationPort);
- pxTCPPacket->xIPHeader.ulSourceIPAddress = pxTCPPacket->xIPHeader.ulDestinationIPAddress;
- memcpy( pxEthernetHeader->xSourceAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
- }
- else
- {
- /* Nothing to do: the buffer has been passed to DMA and will be released after use */
- }
- } /* if( pxNetworkBuffer != NULL ) */
-}
-/*-----------------------------------------------------------*/
-
-/*
- * The SYN event is very important: the sequence numbers, which have a kind of
- * random starting value, are being synchronised. The sliding window manager
- * (in FreeRTOS_TCP_WIN.c) needs to know them, along with the Maximum Segment
- * Size (MSS) in use.
- */
-static void prvTCPCreateWindow( FreeRTOS_Socket_t *pxSocket )
-{
- if( xTCPWindowLoggingLevel )
- FreeRTOS_debug_printf( ( "Limits (using): TCP Win size %lu Water %lu <= %lu <= %lu\n",
- pxSocket->u.xTCP.uxRxWinSize * ipconfigTCP_MSS,
- pxSocket->u.xTCP.uxLittleSpace ,
- pxSocket->u.xTCP.uxEnoughSpace,
- pxSocket->u.xTCP.uxRxStreamSize ) );
- vTCPWindowCreate(
- &pxSocket->u.xTCP.xTCPWindow,
- ipconfigTCP_MSS * pxSocket->u.xTCP.uxRxWinSize,
- ipconfigTCP_MSS * pxSocket->u.xTCP.uxTxWinSize,
- pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber,
- pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber,
- ( uint32_t ) pxSocket->u.xTCP.usInitMSS );
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Connecting sockets have a special state: eCONNECT_SYN. In this phase,
- * the Ethernet address of the target will be found using ARP. In case the
- * target IP address is not within the netmask, the hardware address of the
- * gateway will be used.
- */
-static BaseType_t prvTCPPrepareConnect( FreeRTOS_Socket_t *pxSocket )
-{
-TCPPacket_t *pxTCPPacket;
-IPHeader_t *pxIPHeader;
-eARPLookupResult_t eReturned;
-uint32_t ulRemoteIP;
-MACAddress_t xEthAddress;
-BaseType_t xReturn = pdTRUE;
-uint32_t ulInitialSequenceNumber = 0;
-
- #if( ipconfigHAS_PRINTF != 0 )
- {
- /* Only necessary for nicer logging. */
- memset( xEthAddress.ucBytes, '\0', sizeof( xEthAddress.ucBytes ) );
- }
- #endif /* ipconfigHAS_PRINTF != 0 */
-
- ulRemoteIP = FreeRTOS_htonl( pxSocket->u.xTCP.ulRemoteIP );
-
- /* Determine the ARP cache status for the requested IP address. */
- eReturned = eARPGetCacheEntry( &( ulRemoteIP ), &( xEthAddress ) );
-
- switch( eReturned )
- {
- case eARPCacheHit: /* An ARP table lookup found a valid entry. */
- break; /* We can now prepare the SYN packet. */
- case eARPCacheMiss: /* An ARP table lookup did not find a valid entry. */
- case eCantSendPacket: /* There is no IP address, or an ARP is still in progress. */
- default:
- /* Count the number of times it couldn't find the ARP address. */
- pxSocket->u.xTCP.ucRepCount++;
-
- FreeRTOS_debug_printf( ( "ARP for %lxip (using %lxip): rc=%d %02X:%02X:%02X %02X:%02X:%02X\n",
- pxSocket->u.xTCP.ulRemoteIP,
- FreeRTOS_htonl( ulRemoteIP ),
- eReturned,
- xEthAddress.ucBytes[ 0 ],
- xEthAddress.ucBytes[ 1 ],
- xEthAddress.ucBytes[ 2 ],
- xEthAddress.ucBytes[ 3 ],
- xEthAddress.ucBytes[ 4 ],
- xEthAddress.ucBytes[ 5 ] ) );
-
- /* And issue a (new) ARP request */
- FreeRTOS_OutputARPRequest( ulRemoteIP );
-
- xReturn = pdFALSE;
- }
-
- if( xReturn != pdFALSE )
- {
- /* Get a difficult-to-predict initial sequence number for this 4-tuple. */
- ulInitialSequenceNumber = ulApplicationGetNextSequenceNumber( *ipLOCAL_IP_ADDRESS_POINTER,
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort );
-
- /* Check for a random number generation error. */
- if( 0 == ulInitialSequenceNumber )
- {
- xReturn = pdFALSE;
- }
- }
-
- if( xReturn != pdFALSE )
- {
- /* The MAC-address of the peer (or gateway) has been found,
- now prepare the initial TCP packet and some fields in the socket. */
- pxTCPPacket = ( TCPPacket_t * )pxSocket->u.xTCP.xPacket.u.ucLastPacket;
- pxIPHeader = &pxTCPPacket->xIPHeader;
-
- /* reset the retry counter to zero. */
- pxSocket->u.xTCP.ucRepCount = 0u;
-
- /* And remember that the connect/SYN data are prepared. */
- pxSocket->u.xTCP.bits.bConnPrepared = pdTRUE_UNSIGNED;
-
- /* Now that the Ethernet address is known, the initial packet can be
- prepared. */
- memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, '\0', sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
-
- /* Write the Ethernet address in Source, because it will be swapped by
- prvTCPReturnPacket(). */
- memcpy( &pxTCPPacket->xEthernetHeader.xSourceAddress, &xEthAddress, sizeof( xEthAddress ) );
-
- /* 'ipIPv4_FRAME_TYPE' is already in network-byte-order. */
- pxTCPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE;
-
- pxIPHeader->ucVersionHeaderLength = 0x45u;
- pxIPHeader->usLength = FreeRTOS_htons( sizeof( TCPPacket_t ) - sizeof( pxTCPPacket->xEthernetHeader ) );
- pxIPHeader->ucTimeToLive = ( uint8_t ) ipconfigTCP_TIME_TO_LIVE;
-
- pxIPHeader->ucProtocol = ( uint8_t ) ipPROTOCOL_TCP;
-
- /* Addresses and ports will be stored swapped because prvTCPReturnPacket
- will swap them back while replying. */
- pxIPHeader->ulDestinationIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
- pxIPHeader->ulSourceIPAddress = FreeRTOS_htonl( pxSocket->u.xTCP.ulRemoteIP );
-
- pxTCPPacket->xTCPHeader.usSourcePort = FreeRTOS_htons( pxSocket->u.xTCP.usRemotePort );
- pxTCPPacket->xTCPHeader.usDestinationPort = FreeRTOS_htons( pxSocket->usLocalPort );
-
- /* We are actively connecting, so the peer's Initial Sequence Number (ISN)
- isn't known yet. */
- pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = 0ul;
-
- /* Start with ISN (Initial Sequence Number). */
- pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber;
-
- /* The TCP header size is 20 bytes, divided by 4 equals 5, which is put in
- the high nibble of the TCP offset field. */
- pxTCPPacket->xTCPHeader.ucTCPOffset = 0x50u;
-
- /* Only set the SYN flag. */
- pxTCPPacket->xTCPHeader.ucTCPFlags = ipTCP_FLAG_SYN;
-
- /* Set the values of usInitMSS / usCurMSS for this socket. */
- prvSocketSetMSS( pxSocket );
-
- /* For now this is also the advertised window size. */
- pxSocket->u.xTCP.ulRxCurWinSize = pxSocket->u.xTCP.usInitMSS;
-
- /* The initial sequence numbers at our side are known. Later
- vTCPWindowInit() will be called to fill in the peer's sequence numbers, but
- first wait for a SYN+ACK reply. */
- prvTCPCreateWindow( pxSocket );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-/* For logging and debugging: make a string showing the TCP flags
-*/
-#if( ipconfigHAS_DEBUG_PRINTF != 0 )
-
- static const char *prvTCPFlagMeaning( UBaseType_t xFlags)
- {
- static char retString[10];
- snprintf(retString, sizeof( retString ), "%c%c%c%c%c%c%c%c%c",
- ( xFlags & ipTCP_FLAG_FIN ) ? 'F' : '.', /* 0x0001: No more data from sender */
- ( xFlags & ipTCP_FLAG_SYN ) ? 'S' : '.', /* 0x0002: Synchronize sequence numbers */
- ( xFlags & ipTCP_FLAG_RST ) ? 'R' : '.', /* 0x0004: Reset the connection */
- ( xFlags & ipTCP_FLAG_PSH ) ? 'P' : '.', /* 0x0008: Push function: please push buffered data to the recv application */
- ( xFlags & ipTCP_FLAG_ACK ) ? 'A' : '.', /* 0x0010: Acknowledgment field is significant */
- ( xFlags & ipTCP_FLAG_URG ) ? 'U' : '.', /* 0x0020: Urgent pointer field is significant */
- ( xFlags & ipTCP_FLAG_ECN ) ? 'E' : '.', /* 0x0040: ECN-Echo */
- ( xFlags & ipTCP_FLAG_CWR ) ? 'C' : '.', /* 0x0080: Congestion Window Reduced */
- ( xFlags & ipTCP_FLAG_NS ) ? 'N' : '.'); /* 0x0100: ECN-nonce concealment protection */
- return retString;
- }
- /*-----------------------------------------------------------*/
-
-#endif /* ipconfigHAS_DEBUG_PRINTF */
-
-/*
- * Parse the TCP option(s) received, if present. It has already been verified
- * that: ((pxTCPHeader->ucTCPOffset & 0xf0) > 0x50), meaning that the TP header
- * is longer than the usual 20 (5 x 4) bytes.
- */
-static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-TCPPacket_t * pxTCPPacket;
-TCPHeader_t * pxTCPHeader;
-const unsigned char *pucPtr;
-const unsigned char *pucLast;
-TCPWindow_t *pxTCPWindow;
-UBaseType_t uxNewMSS;
-
- pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
- pxTCPHeader = &pxTCPPacket->xTCPHeader;
-
- /* A character pointer to iterate through the option data */
- pucPtr = pxTCPHeader->ucOptdata;
- pucLast = pucPtr + (((pxTCPHeader->ucTCPOffset >> 4) - 5) << 2);
- pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-
- /* Validate options size calculation. */
- if( pucLast > ( pxNetworkBuffer->pucEthernetBuffer + pxNetworkBuffer->xDataLength ) )
- {
- return;
- }
-
- /* The comparison with pucLast is only necessary in case the option data are
- corrupted, we don't like to run into invalid memory and crash. */
- while( pucPtr < pucLast )
- {
- UBaseType_t xRemainingOptionsBytes = pucLast - pucPtr;
-
- if( pucPtr[ 0 ] == TCP_OPT_END )
- {
- /* End of options. */
- break;
- }
- if( pucPtr[ 0 ] == TCP_OPT_NOOP)
- {
- /* NOP option, inserted to make the length a multiple of 4. */
- pucPtr++;
- continue;
- }
-
- /* Any other well-formed option must be at least two bytes: the option
- type byte followed by a length byte. */
- if( xRemainingOptionsBytes < 2 )
- {
- break;
- }
-#if( ipconfigUSE_TCP_WIN != 0 )
- else if( pucPtr[ 0 ] == TCP_OPT_WSOPT )
- {
- /* Confirm that the option fits in the remaining buffer space. */
- if( ( xRemainingOptionsBytes < TCP_OPT_WSOPT_LEN ) || ( pucPtr[ 1 ] != TCP_OPT_WSOPT_LEN ) )
- {
- break;
- }
-
- pxSocket->u.xTCP.ucPeerWinScaleFactor = pucPtr[ 2 ];
- pxSocket->u.xTCP.bits.bWinScaling = pdTRUE_UNSIGNED;
- pucPtr += TCP_OPT_WSOPT_LEN;
- }
-#endif /* ipconfigUSE_TCP_WIN */
- else if( pucPtr[ 0 ] == TCP_OPT_MSS )
- {
- /* Confirm that the option fits in the remaining buffer space. */
- if( ( xRemainingOptionsBytes < TCP_OPT_MSS_LEN ) || ( pucPtr[ 1 ] != TCP_OPT_MSS_LEN ) )
- {
- break;
- }
-
- /* An MSS option with the correct option length. FreeRTOS_htons()
- is not needed here because usChar2u16() already returns a host
- endian number. */
- uxNewMSS = usChar2u16( pucPtr + 2 );
-
- if( pxSocket->u.xTCP.usInitMSS != uxNewMSS )
- {
- /* Perform a basic check on the the new MSS. */
- if( uxNewMSS == 0 )
- {
- break;
- }
-
- FreeRTOS_debug_printf( ( "MSS change %u -> %lu\n", pxSocket->u.xTCP.usInitMSS, uxNewMSS ) );
- }
-
- if( pxSocket->u.xTCP.usInitMSS > uxNewMSS )
- {
- /* our MSS was bigger than the MSS of the other party: adapt it. */
- pxSocket->u.xTCP.bits.bMssChange = pdTRUE_UNSIGNED;
- if( ( pxTCPWindow != NULL ) && ( pxSocket->u.xTCP.usCurMSS > uxNewMSS ) )
- {
- /* The peer advertises a smaller MSS than this socket was
- using. Use that as well. */
- FreeRTOS_debug_printf( ( "Change mss %d => %lu\n", pxSocket->u.xTCP.usCurMSS, uxNewMSS ) );
- pxSocket->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
- }
- pxTCPWindow->xSize.ulRxWindowLength = ( ( uint32_t ) uxNewMSS ) * ( pxTCPWindow->xSize.ulRxWindowLength / ( ( uint32_t ) uxNewMSS ) );
- pxTCPWindow->usMSSInit = ( uint16_t ) uxNewMSS;
- pxTCPWindow->usMSS = ( uint16_t ) uxNewMSS;
- pxSocket->u.xTCP.usInitMSS = ( uint16_t ) uxNewMSS;
- pxSocket->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
- }
-
- #if( ipconfigUSE_TCP_WIN != 1 )
- /* Without scaled windows, MSS is the only interesting option. */
- break;
- #else
- /* Or else we continue to check another option: selective ACK. */
- pucPtr += TCP_OPT_MSS_LEN;
- #endif /* ipconfigUSE_TCP_WIN != 1 */
- }
- else
- {
- /* All other options have a length field, so that we easily
- can skip past them. */
- unsigned char len = pucPtr[ 1 ];
- if( ( len < 2 ) || ( len > xRemainingOptionsBytes ) )
- {
- /* If the length field is too small or too big, the options are malformed.
- Don't process them further. */
- break;
- }
-
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- /* Selective ACK: the peer has received a packet but it is missing earlier
- packets. At least this packet does not need retransmission anymore
- ulTCPWindowTxSack( ) takes care of this administration. */
- if( pucPtr[0] == TCP_OPT_SACK_A )
- {
- len -= 2;
- pucPtr += 2;
-
- while( len >= 8 )
- {
- uint32_t ulFirst = ulChar2u32( pucPtr );
- uint32_t ulLast = ulChar2u32( pucPtr + 4 );
- uint32_t ulCount = ulTCPWindowTxSack( &pxSocket->u.xTCP.xTCPWindow, ulFirst, ulLast );
- /* ulTCPWindowTxSack( ) returns the number of bytes which have been acked
- starting from the head position.
- Advance the tail pointer in txStream. */
- if( ( pxSocket->u.xTCP.txStream != NULL ) && ( ulCount > 0 ) )
- {
- /* Just advancing the tail index, 'ulCount' bytes have been confirmed. */
- uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0, NULL, ( size_t ) ulCount, pdFALSE );
- pxSocket->xEventBits |= eSOCKET_SEND;
-
- #if ipconfigSUPPORT_SELECT_FUNCTION == 1
- {
- if( pxSocket->xSelectBits & eSELECT_WRITE )
- {
- /* The field 'xEventBits' is used to store regular socket events (at most 8),
- as well as 'select events', which will be left-shifted */
- pxSocket->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
-
- /* In case the socket owner has installed an OnSent handler,
- call it now. */
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) )
- {
- pxSocket->u.xTCP.pxHandleSent( (Socket_t *)pxSocket, ulCount );
- }
- }
- #endif /* ipconfigUSE_CALLBACKS == 1 */
- }
- pucPtr += 8;
- len -= 8;
- }
- /* len should be 0 by now. */
- }
- }
- #endif /* ipconfigUSE_TCP_WIN == 1 */
-
- pucPtr += len;
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN != 0 )
-
- static uint8_t prvWinScaleFactor( FreeRTOS_Socket_t *pxSocket )
- {
- size_t uxWinSize;
- uint8_t ucFactor;
-
- /* 'xTCP.uxRxWinSize' is the size of the reception window in units of MSS. */
- uxWinSize = pxSocket->u.xTCP.uxRxWinSize * ( size_t ) pxSocket->u.xTCP.usInitMSS;
- ucFactor = 0u;
- while( uxWinSize > 0xfffful )
- {
- /* Divide by two and increase the binary factor by 1. */
- uxWinSize >>= 1;
- ucFactor++;
- }
-
- FreeRTOS_debug_printf( ( "prvWinScaleFactor: uxRxWinSize %lu MSS %lu Factor %u\n",
- pxSocket->u.xTCP.uxRxWinSize,
- pxSocket->u.xTCP.usInitMSS,
- ucFactor ) );
-
- return ucFactor;
- }
-
-#endif
-/*-----------------------------------------------------------*/
-
-/*
- * When opening a TCP connection, while SYN's are being sent, the parties may
- * communicate what MSS (Maximum Segment Size) they intend to use. MSS is the
- * nett size of the payload, always smaller than MTU.
-*/
-static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPPacket_t * pxTCPPacket )
-{
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-uint16_t usMSS = pxSocket->u.xTCP.usInitMSS;
-UBaseType_t uxOptionsLength;
-
- /* We send out the TCP Maximum Segment Size option with our SYN[+ACK]. */
-
- pxTCPHeader->ucOptdata[ 0 ] = ( uint8_t ) TCP_OPT_MSS;
- pxTCPHeader->ucOptdata[ 1 ] = ( uint8_t ) TCP_OPT_MSS_LEN;
- pxTCPHeader->ucOptdata[ 2 ] = ( uint8_t ) ( usMSS >> 8 );
- pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( usMSS & 0xffu );
-
- #if( ipconfigUSE_TCP_WIN != 0 )
- {
- pxSocket->u.xTCP.ucMyWinScaleFactor = prvWinScaleFactor( pxSocket );
-
- pxTCPHeader->ucOptdata[ 4 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ 5 ] = ( uint8_t ) ( TCP_OPT_WSOPT );
- pxTCPHeader->ucOptdata[ 6 ] = ( uint8_t ) ( TCP_OPT_WSOPT_LEN );
- pxTCPHeader->ucOptdata[ 7 ] = ( uint8_t ) pxSocket->u.xTCP.ucMyWinScaleFactor;
- uxOptionsLength = 8u;
- }
- #else
- {
- uxOptionsLength = 4u;
- }
- #endif
-
- #if( ipconfigUSE_TCP_WIN == 0 )
- {
- return uxOptionsLength;
- }
- #else
- {
- pxTCPHeader->ucOptdata[ uxOptionsLength + 0 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ uxOptionsLength + 1 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ uxOptionsLength + 2 ] = TCP_OPT_SACK_P; /* 4: Sack-Permitted Option. */
- pxTCPHeader->ucOptdata[ uxOptionsLength + 3 ] = 2; /* 2: length of this option. */
- uxOptionsLength += 4u;
-
- return uxOptionsLength; /* bytes, not words. */
- }
- #endif /* ipconfigUSE_TCP_WIN == 0 */
-}
-
-/*
- * For anti-hanging protection and TCP keep-alive messages. Called in two
- * places: after receiving a packet and after a state change. The socket's
- * alive timer may be reset.
- */
-static void prvTCPTouchSocket( FreeRTOS_Socket_t *pxSocket )
-{
- #if( ipconfigTCP_HANG_PROTECTION == 1 )
- {
- pxSocket->u.xTCP.xLastActTime = xTaskGetTickCount( );
- }
- #endif
-
- #if( ipconfigTCP_KEEP_ALIVE == 1 )
- {
- pxSocket->u.xTCP.bits.bWaitKeepAlive = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.bits.bSendKeepAlive = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.ucKeepRepCount = 0u;
- pxSocket->u.xTCP.xLastAliveTime = xTaskGetTickCount();
- }
- #endif
-
- ( void ) pxSocket;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Changing to a new state. Centralised here to do specific actions such as
- * resetting the alive timer, calling the user's OnConnect handler to notify
- * that a socket has got (dis)connected, and setting bit to unblock a call to
- * FreeRTOS_select()
- */
-void vTCPStateChange( FreeRTOS_Socket_t *pxSocket, enum eTCP_STATE eTCPState )
-{
-FreeRTOS_Socket_t *xParent = NULL;
-BaseType_t bBefore = ( BaseType_t ) NOW_CONNECTED( pxSocket->u.xTCP.ucTCPState ); /* Was it connected ? */
-BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it connected now ? */
-#if( ipconfigHAS_DEBUG_PRINTF != 0 )
- BaseType_t xPreviousState = ( BaseType_t ) pxSocket->u.xTCP.ucTCPState;
-#endif
-#if( ipconfigUSE_CALLBACKS == 1 )
- FreeRTOS_Socket_t *xConnected = NULL;
-#endif
-
- /* Has the connected status changed? */
- if( bBefore != bAfter )
- {
- /* Is the socket connected now ? */
- if( bAfter != pdFALSE )
- {
- /* if bPassQueued is true, this socket is an orphan until it gets connected. */
- if( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED )
- {
- /* Now that it is connected, find it's parent. */
- if( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED )
- {
- xParent = pxSocket;
- }
- else
- {
- xParent = pxSocket->u.xTCP.pxPeerSocket;
- configASSERT( xParent != NULL );
- }
- if( xParent != NULL )
- {
- if( xParent->u.xTCP.pxPeerSocket == NULL )
- {
- xParent->u.xTCP.pxPeerSocket = pxSocket;
- }
-
- xParent->xEventBits |= eSOCKET_ACCEPT;
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- /* Library support FreeRTOS_select(). Receiving a new
- connection is being translated as a READ event. */
- if( ( xParent->xSelectBits & eSELECT_READ ) != 0 )
- {
- xParent->xEventBits |= ( eSELECT_READ << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ( ipconfigIS_VALID_PROG_ADDRESS( xParent->u.xTCP.pxHandleConnected ) != pdFALSE ) &&
- ( xParent->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) )
- {
- /* The listening socket does not become connected itself, in stead
- a child socket is created.
- Postpone a call the OnConnect event until the end of this function. */
- xConnected = xParent;
- }
- }
- #endif
- }
-
- /* Don't need to access the parent socket anymore, so the
- reference 'pxPeerSocket' may be cleared. */
- pxSocket->u.xTCP.pxPeerSocket = NULL;
- pxSocket->u.xTCP.bits.bPassQueued = pdFALSE_UNSIGNED;
-
- /* When true, this socket may be returned in a call to accept(). */
- pxSocket->u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED;
- }
- else
- {
- pxSocket->xEventBits |= eSOCKET_CONNECT;
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- if( pxSocket->xSelectBits & eSELECT_WRITE )
- {
- pxSocket->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
- }
- }
- else /* bAfter == pdFALSE, connection is closed. */
- {
- /* Notify/wake-up the socket-owner by setting a semaphore. */
- pxSocket->xEventBits |= eSOCKET_CLOSED;
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- if( ( pxSocket->xSelectBits & eSELECT_EXCEPT ) != 0 )
- {
- pxSocket->xEventBits |= ( eSELECT_EXCEPT << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
- }
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleConnected ) != pdFALSE ) && ( xConnected == NULL ) )
- {
- /* The 'connected' state has changed, call the user handler. */
- xConnected = pxSocket;
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- if( prvTCPSocketIsActive( ( UBaseType_t ) pxSocket->u.xTCP.ucTCPState ) == pdFALSE )
- {
- /* Now the socket isn't in an active state anymore so it
- won't need further attention of the IP-task.
- Setting time-out to zero means that the socket won't get checked during
- timer events. */
- pxSocket->u.xTCP.usTimeout = 0u;
- }
- }
- else
- {
- if( eTCPState == eCLOSED )
- {
- /* Socket goes to status eCLOSED because of a RST.
- When nobody owns the socket yet, delete it. */
- if( ( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED ) ||
- ( pxSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
- {
- FreeRTOS_debug_printf( ( "vTCPStateChange: Closing socket\n" ) );
- if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
- {
- FreeRTOS_closesocket( pxSocket );
- }
- }
- }
- }
-
- /* Fill in the new state. */
- pxSocket->u.xTCP.ucTCPState = ( uint8_t ) eTCPState;
-
- /* touch the alive timers because moving to another state. */
- prvTCPTouchSocket( pxSocket );
-
- #if( ipconfigHAS_DEBUG_PRINTF == 1 )
- {
- if( ( xTCPWindowLoggingLevel >= 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
- FreeRTOS_debug_printf( ( "Socket %d -> %lxip:%u State %s->%s\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- FreeRTOS_GetTCPStateName( ( UBaseType_t ) xPreviousState ),
- FreeRTOS_GetTCPStateName( ( UBaseType_t ) eTCPState ) ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( xConnected != NULL )
- {
- /* The 'connected' state has changed, call the OnConnect handler of the parent. */
- xConnected->u.xTCP.pxHandleConnected( ( Socket_t * ) xConnected, bAfter );
- }
- }
- #endif
- if( xParent != NULL )
- {
- vSocketWakeUpUser( xParent );
- }
-}
-/*-----------------------------------------------------------*/
-
-static NetworkBufferDescriptor_t *prvTCPBufferResize( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
- int32_t lDataLen, UBaseType_t uxOptionsLength )
-{
-NetworkBufferDescriptor_t *pxReturn;
-int32_t lNeeded;
-BaseType_t xResize;
-
- if( xBufferAllocFixedSize != pdFALSE )
- {
- /* Network buffers are created with a fixed size and can hold the largest
- MTU. */
- lNeeded = ( int32_t ) ipTOTAL_ETHERNET_FRAME_SIZE;
- /* and therefore, the buffer won't be too small.
- Only ask for a new network buffer in case none was supplied. */
- xResize = ( pxNetworkBuffer == NULL );
- }
- else
- {
- /* Network buffers are created with a variable size. See if it must
- grow. */
- lNeeded = FreeRTOS_max_int32( ( int32_t ) sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ),
- ( int32_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + lDataLen );
- /* In case we were called from a TCP timer event, a buffer must be
- created. Otherwise, test 'xDataLength' of the provided buffer. */
- xResize = ( pxNetworkBuffer == NULL ) || ( pxNetworkBuffer->xDataLength < (size_t)lNeeded );
- }
-
- if( xResize != pdFALSE )
- {
- /* The caller didn't provide a network buffer or the provided buffer is
- too small. As we must send-out a data packet, a buffer will be created
- here. */
- pxReturn = pxGetNetworkBufferWithDescriptor( ( uint32_t ) lNeeded, 0u );
-
- if( pxReturn != NULL )
- {
- /* Set the actual packet size, in case the returned buffer is larger. */
- pxReturn->xDataLength = lNeeded;
-
- /* Copy the existing data to the new created buffer. */
- if( pxNetworkBuffer )
- {
- /* Either from the previous buffer... */
- memcpy( pxReturn->pucEthernetBuffer, pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
-
- /* ...and release it. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- else
- {
- /* Or from the socket field 'xTCP.xPacket'. */
- memcpy( pxReturn->pucEthernetBuffer, pxSocket->u.xTCP.xPacket.u.ucLastPacket, sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
- }
- }
- }
- else
- {
- /* xResize is false, the network buffer provided was big enough. */
- pxReturn = pxNetworkBuffer;
-
- /* Thanks to Andrey Ivanov from swissEmbedded for reporting that the
- xDataLength member must get the correct length too! */
- pxNetworkBuffer->xDataLength = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + ( size_t ) lDataLen;
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Prepare an outgoing message, in case anything has to be sent.
- */
-static int32_t prvTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer, UBaseType_t uxOptionsLength )
-{
-int32_t lDataLen;
-uint8_t *pucEthernetBuffer, *pucSendData;
-TCPPacket_t *pxTCPPacket;
-size_t uxOffset;
-uint32_t ulDataGot, ulDistance;
-TCPWindow_t *pxTCPWindow;
-NetworkBufferDescriptor_t *pxNewBuffer;
-int32_t lStreamPos;
-
- if( ( *ppxNetworkBuffer ) != NULL )
- {
- /* A network buffer descriptor was already supplied */
- pucEthernetBuffer = ( *ppxNetworkBuffer )->pucEthernetBuffer;
- }
- else
- {
- /* For now let it point to the last packet header */
- pucEthernetBuffer = pxSocket->u.xTCP.xPacket.u.ucLastPacket;
- }
-
- pxTCPPacket = ( TCPPacket_t * ) ( pucEthernetBuffer );
- pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
- lDataLen = 0;
- lStreamPos = 0;
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_ACK;
-
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- /* ulTCPWindowTxGet will return the amount of data which may be sent
- along with the position in the txStream.
- Why check for MSS > 1 ?
- Because some TCP-stacks (like uIP) use it for flow-control. */
- if( pxSocket->u.xTCP.usCurMSS > 1u )
- {
- lDataLen = ( int32_t ) ulTCPWindowTxGet( pxTCPWindow, pxSocket->u.xTCP.ulWindowSize, &lStreamPos );
- }
-
- if( lDataLen > 0 )
- {
- /* Check if the current network buffer is big enough, if not,
- resize it. */
- pxNewBuffer = prvTCPBufferResize( pxSocket, *ppxNetworkBuffer, lDataLen, uxOptionsLength );
-
- if( pxNewBuffer != NULL )
- {
- *ppxNetworkBuffer = pxNewBuffer;
- pucEthernetBuffer = pxNewBuffer->pucEthernetBuffer;
- pxTCPPacket = ( TCPPacket_t * ) ( pucEthernetBuffer );
-
- pucSendData = pucEthernetBuffer + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength;
-
- /* Translate the position in txStream to an offset from the tail
- marker. */
- uxOffset = uxStreamBufferDistance( pxSocket->u.xTCP.txStream, pxSocket->u.xTCP.txStream->uxTail, ( size_t ) lStreamPos );
-
- /* Here data is copied from the txStream in 'peek' mode. Only
- when the packets are acked, the tail marker will be updated. */
- ulDataGot = ( uint32_t ) uxStreamBufferGet( pxSocket->u.xTCP.txStream, uxOffset, pucSendData, ( size_t ) lDataLen, pdTRUE );
-
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( ulDataGot != ( uint32_t ) lDataLen )
- {
- FreeRTOS_debug_printf( ( "uxStreamBufferGet: pos %lu offs %lu only %lu != %lu\n",
- lStreamPos, uxOffset, ulDataGot, lDataLen ) );
- }
- }
- #endif
-
- /* If the owner of the socket requests a closure, add the FIN
- flag to the last packet. */
- if( ( pxSocket->u.xTCP.bits.bCloseRequested != pdFALSE_UNSIGNED ) && ( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) )
- {
- ulDistance = ( uint32_t ) uxStreamBufferDistance( pxSocket->u.xTCP.txStream, ( size_t ) lStreamPos, pxSocket->u.xTCP.txStream->uxHead );
-
- if( ulDistance == ulDataGot )
- {
- #if (ipconfigHAS_DEBUG_PRINTF == 1)
- {
- /* the order of volatile accesses is undefined
- so such workaround */
- size_t uxHead = pxSocket->u.xTCP.txStream->uxHead;
- size_t uxMid = pxSocket->u.xTCP.txStream->uxMid;
- size_t uxTail = pxSocket->u.xTCP.txStream->uxTail;
-
- FreeRTOS_debug_printf( ( "CheckClose %lu <= %lu (%lu <= %lu <= %lu)\n", ulDataGot, ulDistance,
- uxTail, uxMid, uxHead ) );
- }
- #endif
- /* Although the socket sends a FIN, it will stay in
- ESTABLISHED until all current data has been received or
- delivered. */
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_FIN;
- pxTCPWindow->tx.ulFINSequenceNumber = pxTCPWindow->ulOurSequenceNumber + ( uint32_t ) lDataLen;
- pxSocket->u.xTCP.bits.bFinSent = pdTRUE_UNSIGNED;
- }
- }
- }
- else
- {
- lDataLen = -1;
- }
- }
- }
-
- if( ( lDataLen >= 0 ) && ( pxSocket->u.xTCP.ucTCPState == eESTABLISHED ) )
- {
- /* See if the socket owner wants to shutdown this connection. */
- if( ( pxSocket->u.xTCP.bits.bUserShutdown != pdFALSE_UNSIGNED ) &&
- ( xTCPWindowTxDone( pxTCPWindow ) != pdFALSE ) )
- {
- pxSocket->u.xTCP.bits.bUserShutdown = pdFALSE_UNSIGNED;
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_FIN;
- pxSocket->u.xTCP.bits.bFinSent = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
- pxTCPWindow->tx.ulFINSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
- vTCPStateChange( pxSocket, eFIN_WAIT_1 );
- }
-
- #if( ipconfigTCP_KEEP_ALIVE != 0 )
- {
- if( pxSocket->u.xTCP.ucKeepRepCount > 3u )
- {
- FreeRTOS_debug_printf( ( "keep-alive: giving up %lxip:%u\n",
- pxSocket->u.xTCP.ulRemoteIP, /* IP address of remote machine. */
- pxSocket->u.xTCP.usRemotePort ) ); /* Port on remote machine. */
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
- lDataLen = -1;
- }
- if( ( lDataLen == 0 ) && ( pxSocket->u.xTCP.bits.bWinChange == pdFALSE_UNSIGNED ) )
- {
- /* If there is no data to be sent, and no window-update message,
- we might want to send a keep-alive message. */
- TickType_t xAge = xTaskGetTickCount( ) - pxSocket->u.xTCP.xLastAliveTime;
- TickType_t xMax;
- xMax = ( ( TickType_t ) ipconfigTCP_KEEP_ALIVE_INTERVAL * configTICK_RATE_HZ );
- if( pxSocket->u.xTCP.ucKeepRepCount )
- {
- xMax = ( 3u * configTICK_RATE_HZ );
- }
- if( xAge > xMax )
- {
- pxSocket->u.xTCP.xLastAliveTime = xTaskGetTickCount( );
- if( xTCPWindowLoggingLevel )
- FreeRTOS_debug_printf( ( "keep-alive: %lxip:%u count %u\n",
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- pxSocket->u.xTCP.ucKeepRepCount ) );
- pxSocket->u.xTCP.bits.bSendKeepAlive = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.usTimeout = ( ( uint16_t ) pdMS_TO_TICKS( 2500 ) );
- pxSocket->u.xTCP.ucKeepRepCount++;
- }
- }
- }
- #endif /* ipconfigTCP_KEEP_ALIVE */
- }
-
- /* Anything to send, a change of the advertised window size, or maybe send a
- keep-alive message? */
- if( ( lDataLen > 0 ) ||
- ( pxSocket->u.xTCP.bits.bWinChange != pdFALSE_UNSIGNED ) ||
- ( pxSocket->u.xTCP.bits.bSendKeepAlive != pdFALSE_UNSIGNED ) )
- {
- pxTCPPacket->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~ipTCP_FLAG_PSH );
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
-
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ( uint8_t ) ipTCP_FLAG_ACK;
-
- if( lDataLen != 0l )
- {
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ( uint8_t ) ipTCP_FLAG_PSH;
- }
-
- lDataLen += ( int32_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
- }
-
- return lDataLen;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Calculate after how much time this socket needs to be checked again.
- */
-static TickType_t prvTCPNextTimeout ( FreeRTOS_Socket_t *pxSocket )
-{
-TickType_t ulDelayMs = ( TickType_t ) tcpMAXIMUM_TCP_WAKEUP_TIME_MS;
-
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
- {
- /* The socket is actively connecting to a peer. */
- if( pxSocket->u.xTCP.bits.bConnPrepared )
- {
- /* Ethernet address has been found, use progressive timeout for
- active connect(). */
- if( pxSocket->u.xTCP.ucRepCount < 3u )
- {
- ulDelayMs = ( 3000UL << ( pxSocket->u.xTCP.ucRepCount - 1u ) );
- }
- else
- {
- ulDelayMs = 11000UL;
- }
- }
- else
- {
- /* Still in the ARP phase: check every half second. */
- ulDelayMs = 500UL;
- }
-
- FreeRTOS_debug_printf( ( "Connect[%lxip:%u]: next timeout %u: %lu ms\n",
- pxSocket->u.xTCP.ulRemoteIP, pxSocket->u.xTCP.usRemotePort,
- pxSocket->u.xTCP.ucRepCount, ulDelayMs ) );
- pxSocket->u.xTCP.usTimeout = ( uint16_t )pdMS_TO_MIN_TICKS( ulDelayMs );
- }
- else if( pxSocket->u.xTCP.usTimeout == 0u )
- {
- /* Let the sliding window mechanism decide what time-out is appropriate. */
- BaseType_t xResult = xTCPWindowTxHasData( &pxSocket->u.xTCP.xTCPWindow, pxSocket->u.xTCP.ulWindowSize, &ulDelayMs );
- if( ulDelayMs == 0u )
- {
- if( xResult != ( BaseType_t )0 )
- {
- ulDelayMs = 1UL;
- }
- else
- {
- ulDelayMs = tcpMAXIMUM_TCP_WAKEUP_TIME_MS;
- }
- }
- else
- {
- /* ulDelayMs contains the time to wait before a re-transmission. */
- }
- pxSocket->u.xTCP.usTimeout = ( uint16_t )pdMS_TO_MIN_TICKS( ulDelayMs );
- }
- else
- {
- /* field '.usTimeout' has already been set (by the
- keep-alive/delayed-ACK mechanism). */
- }
-
- /* Return the number of clock ticks before the timer expires. */
- return ( TickType_t ) pxSocket->u.xTCP.usTimeout;
-}
-/*-----------------------------------------------------------*/
-
-static void prvTCPAddTxData( FreeRTOS_Socket_t *pxSocket )
-{
-int32_t lCount, lLength;
-
- /* A txStream has been created already, see if the socket has new data for
- the sliding window.
-
- uxStreamBufferMidSpace() returns the distance between rxHead and rxMid. It contains new
- Tx data which has not been passed to the sliding window yet. The oldest
- data not-yet-confirmed can be found at rxTail. */
- lLength = ( int32_t ) uxStreamBufferMidSpace( pxSocket->u.xTCP.txStream );
-
- if( lLength > 0 )
- {
- /* All data between txMid and rxHead will now be passed to the sliding
- window manager, so it can start transmitting them.
-
- Hand over the new data to the sliding window handler. It will be
- split-up in chunks of 1460 bytes each (or less, depending on
- ipconfigTCP_MSS). */
- lCount = lTCPWindowTxAdd( &pxSocket->u.xTCP.xTCPWindow,
- ( uint32_t ) lLength,
- ( int32_t ) pxSocket->u.xTCP.txStream->uxMid,
- ( int32_t ) pxSocket->u.xTCP.txStream->LENGTH );
-
- /* Move the rxMid pointer forward up to rxHead. */
- if( lCount > 0 )
- {
- vStreamBufferMoveMid( pxSocket->u.xTCP.txStream, ( size_t ) lCount );
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvTCPHandleFin() will be called to handle socket closure
- * The Closure starts when either a FIN has been received and accepted,
- * Or when the socket has sent a FIN flag to the peer
- * Before being called, it has been checked that both reception and transmission
- * are complete.
- */
-static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-BaseType_t xSendLength = 0;
-uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
-
- if( ( ucTCPFlags & ipTCP_FLAG_FIN ) != 0u )
- {
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulFINSequenceNumber + 1u;
- }
- if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
- {
- /* We haven't yet replied with a FIN, do so now. */
- pxTCPWindow->tx.ulFINSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
- pxSocket->u.xTCP.bits.bFinSent = pdTRUE_UNSIGNED;
- }
- else
- {
- /* We did send a FIN already, see if it's ACK'd. */
- if( ulAckNr == pxTCPWindow->tx.ulFINSequenceNumber + 1u )
- {
- pxSocket->u.xTCP.bits.bFinAcked = pdTRUE_UNSIGNED;
- }
- }
-
- if( pxSocket->u.xTCP.bits.bFinAcked == pdFALSE_UNSIGNED )
- {
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber;
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK | ipTCP_FLAG_FIN;
-
- /* And wait for the final ACK. */
- vTCPStateChange( pxSocket, eLAST_ACK );
- }
- else
- {
- /* Our FIN has been ACK'd, the outgoing sequence number is now fixed. */
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber + 1u;
- if( pxSocket->u.xTCP.bits.bFinRecv == pdFALSE_UNSIGNED )
- {
- /* We have sent out a FIN but the peer hasn't replied with a FIN
- yet. Do nothing for the moment. */
- pxTCPHeader->ucTCPFlags = 0u;
- }
- else
- {
- if( pxSocket->u.xTCP.bits.bFinLast == pdFALSE_UNSIGNED )
- {
- /* This is the third of the three-way hand shake: the last
- ACK. */
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
- }
- else
- {
- /* The other party started the closure, so we just wait for the
- last ACK. */
- pxTCPHeader->ucTCPFlags = 0u;
- }
-
- /* And wait for the user to close this socket. */
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
- }
- }
-
- pxTCPWindow->ulOurSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
-
- if( pxTCPHeader->ucTCPFlags != 0u )
- {
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength );
- }
-
- pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength ) << 2 );
-
- if( xTCPWindowLoggingLevel != 0 )
- {
- FreeRTOS_debug_printf( ( "TCP: send FIN+ACK (ack %lu, cur/nxt %lu/%lu) ourSeqNr %lu | Rx %lu\n",
- ulAckNr - pxTCPWindow->tx.ulFirstSequenceNumber,
- pxTCPWindow->tx.ulCurrentSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- pxTCPWindow->ulNextTxSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- pxTCPWindow->ulOurSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) );
- }
-
- return xSendLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvCheckRxData(): called from prvTCPHandleState()
- *
- * The first thing that will be done is find the TCP payload data
- * and check the length of this data.
- */
-static BaseType_t prvCheckRxData( NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &( pxTCPPacket->xTCPHeader );
-int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
-
- /* Determine the length and the offset of the user-data sent to this
- node.
-
- The size of the TCP header is given in a multiple of 4-byte words (single
- byte, needs no ntoh() translation). A shift-right 2: is the same as
- (offset >> 4) * 4. */
- lTCPHeaderLength = ( BaseType_t ) ( ( pxTCPHeader->ucTCPOffset & VALID_BITS_IN_TCP_OFFSET_BYTE ) >> 2 );
-
- /* Let pucRecvData point to the first byte received. */
- *ppucRecvData = pxNetworkBuffer->pucEthernetBuffer + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + lTCPHeaderLength;
-
- /* Calculate lReceiveLength - the length of the TCP data received. This is
- equal to the total packet length minus:
- ( LinkLayer length (14) + IP header length (20) + size of TCP header(20 +) ).*/
- lReceiveLength = ( ( int32_t ) pxNetworkBuffer->xDataLength ) - ( int32_t ) ipSIZE_OF_ETH_HEADER;
- lLength = ( int32_t )FreeRTOS_htons( pxTCPPacket->xIPHeader.usLength );
-
- if( lReceiveLength > lLength )
- {
- /* More bytes were received than the reported length, often because of
- padding bytes at the end. */
- lReceiveLength = lLength;
- }
-
- /* Subtract the size of the TCP and IP headers and the actual data size is
- known. */
- if( lReceiveLength > ( lTCPHeaderLength + ( int32_t ) ipSIZE_OF_IPv4_HEADER ) )
- {
- lReceiveLength -= ( lTCPHeaderLength + ( int32_t ) ipSIZE_OF_IPv4_HEADER );
- }
- else
- {
- lReceiveLength = 0;
- }
-
- /* Urgent Pointer:
- This field communicates the current value of the urgent pointer as a
- positive offset from the sequence number in this segment. The urgent
- pointer points to the sequence number of the octet following the urgent
- data. This field is only be interpreted in segments with the URG control
- bit set. */
- if( ( pxTCPHeader->ucTCPFlags & ipTCP_FLAG_URG ) != 0u )
- {
- /* Although we ignore the urgent data, we have to skip it. */
- lUrgentLength = ( int32_t ) FreeRTOS_htons( pxTCPHeader->usUrgent );
- *ppucRecvData += lUrgentLength;
- lReceiveLength -= FreeRTOS_min_int32( lReceiveLength, lUrgentLength );
- }
-
- return ( BaseType_t ) lReceiveLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvStoreRxData(): called from prvTCPHandleState()
- *
- * The second thing is to do is check if the payload data may be accepted
- * If so, they will be added to the reception queue.
- */
-static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, uint8_t *pucRecvData,
- NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-uint32_t ulSequenceNumber, ulSpace;
-int32_t lOffset, lStored;
-BaseType_t xResult = 0;
-
- ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber );
-
- if( ( ulReceiveLength > 0u ) && ( pxSocket->u.xTCP.ucTCPState >= eSYN_RECEIVED ) )
- {
- /* See if way may accept the data contents and forward it to the socket
- owner.
-
- If it can't be "accept"ed it may have to be stored and send a selective
- ack (SACK) option to confirm it. In that case, xTCPWindowRxStore() will be
- called later to store an out-of-order packet (in case lOffset is
- negative). */
- if ( pxSocket->u.xTCP.rxStream )
- {
- ulSpace = ( uint32_t )uxStreamBufferGetSpace ( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- ulSpace = ( uint32_t )pxSocket->u.xTCP.uxRxStreamSize;
- }
-
- lOffset = lTCPWindowRxCheck( pxTCPWindow, ulSequenceNumber, ulReceiveLength, ulSpace );
-
- if( lOffset >= 0 )
- {
- /* New data has arrived and may be made available to the user. See
- if the head marker in rxStream may be advanced, only if lOffset == 0.
- In case the low-water mark is reached, bLowWater will be set
- "low-water" here stands for "little space". */
- lStored = lTCPAddRxdata( pxSocket, ( uint32_t ) lOffset, pucRecvData, ulReceiveLength );
-
- if( lStored != ( int32_t ) ulReceiveLength )
- {
- FreeRTOS_debug_printf( ( "lTCPAddRxdata: stored %ld / %lu bytes??\n", lStored, ulReceiveLength ) );
-
- /* Received data could not be stored. The socket's flag
- bMallocError has been set. The socket now has the status
- eCLOSE_WAIT and a RST packet will be sent back. */
- prvTCPSendReset( pxNetworkBuffer );
- xResult = -1;
- }
- }
-
- /* After a missing packet has come in, higher packets may be passed to
- the user. */
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- /* Now lTCPAddRxdata() will move the rxHead pointer forward
- so data becomes available to the user immediately
- In case the low-water mark is reached, bLowWater will be set. */
- if( ( xResult == 0 ) && ( pxTCPWindow->ulUserDataLength > 0 ) )
- {
- lTCPAddRxdata( pxSocket, 0ul, NULL, pxTCPWindow->ulUserDataLength );
- pxTCPWindow->ulUserDataLength = 0;
- }
- }
- #endif /* ipconfigUSE_TCP_WIN */
- }
- else
- {
- pxTCPWindow->ucOptionLength = 0u;
- }
-
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-/* Set the TCP options (if any) for the outgoing packet. */
-static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
-
- #if( ipconfigUSE_TCP_WIN == 1 )
- if( uxOptionsLength != 0u )
- {
- /* TCP options must be sent because a packet which is out-of-order
- was received. */
- if( xTCPWindowLoggingLevel >= 0 )
- FreeRTOS_debug_printf( ( "SACK[%d,%d]: optlen %lu sending %lu - %lu\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- uxOptionsLength,
- FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
- FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) );
- memcpy( pxTCPHeader->ucOptdata, pxTCPWindow->ulOptionsData, ( size_t ) uxOptionsLength );
-
- /* The header length divided by 4, goes into the higher nibble,
- effectively a shift-left 2. */
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
- }
- else
- #endif /* ipconfigUSE_TCP_WIN */
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && ( pxSocket->u.xTCP.bits.bMssChange != pdFALSE_UNSIGNED ) )
- {
- /* TCP options must be sent because the MSS has changed. */
- pxSocket->u.xTCP.bits.bMssChange = pdFALSE_UNSIGNED;
- if( xTCPWindowLoggingLevel >= 0 )
- {
- FreeRTOS_debug_printf( ( "MSS: sending %d\n", pxSocket->u.xTCP.usCurMSS ) );
- }
-
- pxTCPHeader->ucOptdata[ 0 ] = TCP_OPT_MSS;
- pxTCPHeader->ucOptdata[ 1 ] = TCP_OPT_MSS_LEN;
- pxTCPHeader->ucOptdata[ 2 ] = ( uint8_t ) ( ( pxSocket->u.xTCP.usCurMSS ) >> 8 );
- pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( ( pxSocket->u.xTCP.usCurMSS ) & 0xffu );
- uxOptionsLength = 4u;
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
- }
-
- return uxOptionsLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvHandleSynReceived(): called from prvTCPHandleState()
- *
- * Called from the states: eSYN_RECEIVED and eCONNECT_SYN
- * If the flags received are correct, the socket will move to eESTABLISHED.
- */
-static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
-uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber );
-BaseType_t xSendLength = 0;
-
- /* Either expect a ACK or a SYN+ACK. */
- uint16_t usExpect = ( uint16_t ) ipTCP_FLAG_ACK;
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
- {
- usExpect |= ( uint16_t ) ipTCP_FLAG_SYN;
- }
-
- if( ( ucTCPFlags & 0x17u ) != usExpect )
- {
- /* eSYN_RECEIVED: flags 0010 expected, not 0002. */
- /* eSYN_RECEIVED: flags ACK expected, not SYN. */
- FreeRTOS_debug_printf( ( "%s: flags %04X expected, not %04X\n",
- pxSocket->u.xTCP.ucTCPState == eSYN_RECEIVED ? "eSYN_RECEIVED" : "eCONNECT_SYN",
- usExpect, ucTCPFlags ) );
- vTCPStateChange( pxSocket, eCLOSE_WAIT );
- pxTCPHeader->ucTCPFlags |= ipTCP_FLAG_RST;
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
- }
- else
- {
- pxTCPWindow->usPeerPortNumber = pxSocket->u.xTCP.usRemotePort;
- pxTCPWindow->usOurPortNumber = pxSocket->usLocalPort;
-
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
- {
- TCPPacket_t *pxLastTCPPacket = ( TCPPacket_t * ) ( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
-
- /* Clear the SYN flag in lastPacket. */
- pxLastTCPPacket->xTCPHeader.ucTCPFlags = ipTCP_FLAG_ACK;
-
- /* This socket was the one connecting actively so now perofmr the
- synchronisation. */
- vTCPWindowInit( &pxSocket->u.xTCP.xTCPWindow,
- ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, ( uint32_t ) pxSocket->u.xTCP.usCurMSS );
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1u;
- pxTCPWindow->tx.ulCurrentSequenceNumber++; /* because we send a TCP_SYN [ | TCP_ACK ]; */
- pxTCPWindow->ulNextTxSequenceNumber++;
- }
- else if( ulReceiveLength == 0u )
- {
- pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber;
- }
-
- /* The SYN+ACK has been confirmed, increase the next sequence number by
- 1. */
- pxTCPWindow->ulOurSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1u;
-
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- FreeRTOS_debug_printf( ( "TCP: %s %d => %lxip:%d set ESTAB (scaling %u)\n",
- pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ? "active" : "passive",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- ( unsigned ) pxSocket->u.xTCP.bits.bWinScaling ) );
- }
- #endif /* ipconfigUSE_TCP_WIN */
-
- if( ( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ) || ( ulReceiveLength != 0u ) )
- {
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
- pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
- }
- #if( ipconfigUSE_TCP_WIN != 0 )
- {
- if( pxSocket->u.xTCP.bits.bWinScaling == pdFALSE_UNSIGNED )
- {
- /* The other party did not send a scaling factor.
- A shifting factor in this side must be canceled. */
- pxSocket->u.xTCP.ucMyWinScaleFactor = 0;
- pxSocket->u.xTCP.ucPeerWinScaleFactor = 0;
- }
- }
- #endif /* ipconfigUSE_TCP_WIN */
- /* This was the third step of connecting: SYN, SYN+ACK, ACK so now the
- connection is established. */
- vTCPStateChange( pxSocket, eESTABLISHED );
- }
-
- return xSendLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvHandleEstablished(): called from prvTCPHandleState()
- *
- * Called if the status is eESTABLISHED. Data reception has been handled
- * earlier. Here the ACK's from peer will be checked, and if a FIN is received,
- * the code will check if it may be accepted, i.e. if all expected data has been
- * completely received.
- */
-static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
-uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ), ulCount;
-BaseType_t xSendLength = 0, xMayClose = pdFALSE, bRxComplete, bTxDone;
-int32_t lDistance, lSendResult;
-
- /* Remember the window size the peer is advertising. */
- pxSocket->u.xTCP.ulWindowSize = FreeRTOS_ntohs( pxTCPHeader->usWindow );
- #if( ipconfigUSE_TCP_WIN != 0 )
- {
- pxSocket->u.xTCP.ulWindowSize =
- ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor );
- }
- #endif
-
- if( ( ucTCPFlags & ( uint8_t ) ipTCP_FLAG_ACK ) != 0u )
- {
- ulCount = ulTCPWindowTxAck( pxTCPWindow, FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulAckNr ) );
-
- /* ulTCPWindowTxAck() returns the number of bytes which have been acked,
- starting at 'tx.ulCurrentSequenceNumber'. Advance the tail pointer in
- txStream. */
- if( ( pxSocket->u.xTCP.txStream != NULL ) && ( ulCount > 0u ) )
- {
- /* Just advancing the tail index, 'ulCount' bytes have been
- confirmed, and because there is new space in the txStream, the
- user/owner should be woken up. */
- /* _HT_ : only in case the socket's waiting? */
- if( uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0u, NULL, ( size_t ) ulCount, pdFALSE ) != 0u )
- {
- pxSocket->xEventBits |= eSOCKET_SEND;
-
- #if ipconfigSUPPORT_SELECT_FUNCTION == 1
- {
- if( ( pxSocket->xSelectBits & eSELECT_WRITE ) != 0 )
- {
- pxSocket->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
- }
- }
- #endif
- /* In case the socket owner has installed an OnSent handler,
- call it now. */
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) )
- {
- pxSocket->u.xTCP.pxHandleSent( (Socket_t *)pxSocket, ulCount );
- }
- }
- #endif /* ipconfigUSE_CALLBACKS == 1 */
- }
- }
- }
-
- /* If this socket has a stream for transmission, add the data to the
- outgoing segment(s). */
- if( pxSocket->u.xTCP.txStream != NULL )
- {
- prvTCPAddTxData( pxSocket );
- }
-
- pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
-
- if( ( pxSocket->u.xTCP.bits.bFinAccepted != pdFALSE_UNSIGNED ) || ( ( ucTCPFlags & ( uint8_t ) ipTCP_FLAG_FIN ) != 0u ) )
- {
- /* Peer is requesting to stop, see if we're really finished. */
- xMayClose = pdTRUE;
-
- /* Checks are only necessary if we haven't sent a FIN yet. */
- if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
- {
- /* xTCPWindowTxDone returns true when all Tx queues are empty. */
- bRxComplete = xTCPWindowRxEmpty( pxTCPWindow );
- bTxDone = xTCPWindowTxDone( pxTCPWindow );
-
- if( ( bRxComplete == 0 ) || ( bTxDone == 0 ) )
- {
- /* Refusing FIN: Rx incomp 1 optlen 4 tx done 1. */
- FreeRTOS_debug_printf( ( "Refusing FIN[%u,%u]: RxCompl %lu tx done %ld\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- bRxComplete, bTxDone ) );
- xMayClose = pdFALSE;
- }
- else
- {
- lDistance = ( int32_t ) ( ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber );
-
- if( lDistance > 1 )
- {
- FreeRTOS_debug_printf( ( "Refusing FIN: Rx not complete %ld (cur %lu high %lu)\n",
- lDistance, pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber,
- pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) );
-
- xMayClose = pdFALSE;
- }
- }
- }
-
- if( xTCPWindowLoggingLevel > 0 )
- {
- FreeRTOS_debug_printf( ( "TCP: FIN received, mayClose = %ld (Rx %lu Len %ld, Tx %lu)\n",
- xMayClose, ulSequenceNumber - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber, ulReceiveLength,
- pxTCPWindow->tx.ulCurrentSequenceNumber - pxSocket->u.xTCP.xTCPWindow.tx.ulFirstSequenceNumber ) );
- }
-
- if( xMayClose != pdFALSE )
- {
- pxSocket->u.xTCP.bits.bFinAccepted = pdTRUE_UNSIGNED;
- xSendLength = prvTCPHandleFin( pxSocket, *ppxNetworkBuffer );
- }
- }
-
- if( xMayClose == pdFALSE )
- {
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
-
- if( ulReceiveLength != 0u )
- {
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
- /* TCP-offsett equals '( ( length / 4 ) << 4 )', resulting in a shift-left 2 */
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
-
- if( pxSocket->u.xTCP.bits.bFinSent != pdFALSE_UNSIGNED )
- {
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber;
- }
- }
-
- /* Now get data to be transmitted. */
- /* _HT_ patch: since the MTU has be fixed at 1500 in stead of 1526, TCP
- can not send-out both TCP options and also a full packet. Sending
- options (SACK) is always more urgent than sending data, which can be
- sent later. */
- if( uxOptionsLength == 0u )
- {
- /* prvTCPPrepareSend might allocate a bigger network buffer, if
- necessary. */
- lSendResult = prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );
- if( lSendResult > 0 )
- {
- xSendLength = ( BaseType_t ) lSendResult;
- }
- }
- }
-
- return xSendLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Called from prvTCPHandleState(). There is data to be sent. If
- * ipconfigUSE_TCP_WIN is defined, and if only an ACK must be sent, it will be
- * checked if it would better be postponed for efficiency.
- */
-static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, BaseType_t xSendLength )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-/* Find out what window size we may advertised. */
-uint32_t ulFrontSpace;
-int32_t lRxSpace;
-#if( ipconfigUSE_TCP_WIN == 1 )
- #if( ipconfigTCP_ACK_EARLIER_PACKET == 0 )
- const int32_t lMinLength = 0;
- #else
- int32_t lMinLength;
- #endif
-#endif
- pxSocket->u.xTCP.ulRxCurWinSize = pxTCPWindow->xSize.ulRxWindowLength -
- ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulCurrentSequenceNumber );
-
- /* Free space in rxStream. */
- if( pxSocket->u.xTCP.rxStream != NULL )
- {
- ulFrontSpace = ( uint32_t ) uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream );
- }
- else
- {
- ulFrontSpace = ( uint32_t ) pxSocket->u.xTCP.uxRxStreamSize;
- }
-
- pxSocket->u.xTCP.ulRxCurWinSize = FreeRTOS_min_uint32( ulFrontSpace, pxSocket->u.xTCP.ulRxCurWinSize );
-
- /* Set the time-out field, so that we'll be called by the IP-task in case no
- next message will be received. */
- lRxSpace = (int32_t)( pxSocket->u.xTCP.ulHighestRxAllowed - pxTCPWindow->rx.ulCurrentSequenceNumber );
- #if ipconfigUSE_TCP_WIN == 1
- {
-
- #if( ipconfigTCP_ACK_EARLIER_PACKET != 0 )
- {
- lMinLength = ( ( int32_t ) 2 ) * ( ( int32_t ) pxSocket->u.xTCP.usCurMSS );
- }
- #endif /* ipconfigTCP_ACK_EARLIER_PACKET */
-
- /* In case we're receiving data continuously, we might postpone sending
- an ACK to gain performance. */
- if( ( ulReceiveLength > 0 ) && /* Data was sent to this socket. */
- ( lRxSpace >= lMinLength ) && /* There is Rx space for more data. */
- ( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) && /* Not in a closure phase. */
- ( xSendLength == ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) ) && /* No Tx data or options to be sent. */
- ( pxSocket->u.xTCP.ucTCPState == eESTABLISHED ) && /* Connection established. */
- ( pxTCPHeader->ucTCPFlags == ipTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */
- {
- if( pxSocket->u.xTCP.pxAckMessage != *ppxNetworkBuffer )
- {
- /* There was still a delayed in queue, delete it. */
- if( pxSocket->u.xTCP.pxAckMessage != 0 )
- {
- vReleaseNetworkBufferAndDescriptor( pxSocket->u.xTCP.pxAckMessage );
- }
-
- pxSocket->u.xTCP.pxAckMessage = *ppxNetworkBuffer;
- }
- if( ( ulReceiveLength < ( uint32_t ) pxSocket->u.xTCP.usCurMSS ) || /* Received a small message. */
- ( lRxSpace < ( int32_t ) ( 2U * pxSocket->u.xTCP.usCurMSS ) ) ) /* There are less than 2 x MSS space in the Rx buffer. */
- {
- pxSocket->u.xTCP.usTimeout = ( uint16_t ) pdMS_TO_MIN_TICKS( DELAYED_ACK_SHORT_DELAY_MS );
- }
- else
- {
- /* Normally a delayed ACK should wait 200 ms for a next incoming
- packet. Only wait 20 ms here to gain performance. A slow ACK
- for full-size message. */
- pxSocket->u.xTCP.usTimeout = ( uint16_t ) pdMS_TO_MIN_TICKS( DELAYED_ACK_LONGER_DELAY_MS );
- }
-
- if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "Send[%u->%u] del ACK %lu SEQ %lu (len %lu) tmout %u d %lu\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber,
- pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- xSendLength,
- pxSocket->u.xTCP.usTimeout, lRxSpace ) );
- }
-
- *ppxNetworkBuffer = NULL;
- xSendLength = 0;
- }
- else if( pxSocket->u.xTCP.pxAckMessage != NULL )
- {
- /* As an ACK is not being delayed, remove any earlier delayed ACK
- message. */
- if( pxSocket->u.xTCP.pxAckMessage != *ppxNetworkBuffer )
- {
- vReleaseNetworkBufferAndDescriptor( pxSocket->u.xTCP.pxAckMessage );
- }
-
- pxSocket->u.xTCP.pxAckMessage = NULL;
- }
- }
- #else
- {
- /* Remove compiler warnings. */
- ( void ) ulReceiveLength;
- ( void ) pxTCPHeader;
- ( void ) lRxSpace;
- }
- #endif /* ipconfigUSE_TCP_WIN */
-
- if( xSendLength != 0 )
- {
- if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "Send[%u->%u] imm ACK %lu SEQ %lu (len %lu)\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber,
- pxTCPWindow->ulOurSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
- xSendLength ) );
- }
-
- /* Set the parameter 'xReleaseAfterSend' to the value of
- ipconfigZERO_COPY_TX_DRIVER. */
- prvTCPReturnPacket( pxSocket, *ppxNetworkBuffer, ( uint32_t ) xSendLength, ipconfigZERO_COPY_TX_DRIVER );
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* The driver has taken ownership of the Network Buffer. */
- *ppxNetworkBuffer = NULL;
- }
- #endif
- }
-
- return xSendLength;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * prvTCPHandleState()
- * is the most important function of this TCP stack
- * We've tried to keep it (relatively short) by putting a lot of code in
- * the static functions above:
- *
- * prvCheckRxData()
- * prvStoreRxData()
- * prvSetOptions()
- * prvHandleSynReceived()
- * prvHandleEstablished()
- * prvSendData()
- *
- * As these functions are declared static, and they're called from one location
- * only, most compilers will inline them, thus avoiding a call and return.
- */
-static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer )
-{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &( pxTCPPacket->xTCPHeader );
-BaseType_t xSendLength = 0;
-uint32_t ulReceiveLength; /* Number of bytes contained in the TCP message. */
-uint8_t *pucRecvData;
-uint32_t ulSequenceNumber = FreeRTOS_ntohl (pxTCPHeader->ulSequenceNumber);
-
- /* uxOptionsLength: the size of the options to be sent (always a multiple of
- 4 bytes)
- 1. in the SYN phase, we shall communicate the MSS
- 2. in case of a SACK, Selective ACK, ack a segment which comes in
- out-of-order. */
-UBaseType_t uxOptionsLength = 0u;
-uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
-TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
-
- /* First get the length and the position of the received data, if any.
- pucRecvData will point to the first byte of the TCP payload. */
- ulReceiveLength = ( uint32_t ) prvCheckRxData( *ppxNetworkBuffer, &pucRecvData );
-
- if( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED )
- {
- if ( pxTCPWindow->rx.ulCurrentSequenceNumber == ulSequenceNumber + 1u )
- {
- /* This is most probably a keep-alive message from peer. Setting
- 'bWinChange' doesn't cause a window-size-change, the flag is used
- here to force sending an immediate ACK. */
- pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
- }
- }
-
- /* Keep track of the highest sequence number that might be expected within
- this connection. */
- if( ( ( int32_t ) ( ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulHighestSequenceNumber ) ) > 0 )
- {
- pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + ulReceiveLength;
- }
-
- /* Storing data may result in a fatal error if malloc() fails. */
- if( prvStoreRxData( pxSocket, pucRecvData, *ppxNetworkBuffer, ulReceiveLength ) < 0 )
- {
- xSendLength = -1;
- }
- else
- {
- uxOptionsLength = prvSetOptions( pxSocket, *ppxNetworkBuffer );
-
- if( ( pxSocket->u.xTCP.ucTCPState == eSYN_RECEIVED ) && ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) == ipTCP_FLAG_SYN ) )
- {
- FreeRTOS_debug_printf( ( "eSYN_RECEIVED: ACK expected, not SYN: peer missed our SYN+ACK\n" ) );
-
- /* In eSYN_RECEIVED a simple ACK is expected, but apparently the
- 'SYN+ACK' didn't arrive. Step back to the previous state in which
- a first incoming SYN is handled. The SYN was counted already so
- decrease it first. */
- vTCPStateChange( pxSocket, eSYN_FIRST );
- }
-
- if( ( ( ucTCPFlags & ipTCP_FLAG_FIN ) != 0u ) && ( pxSocket->u.xTCP.bits.bFinRecv == pdFALSE_UNSIGNED ) )
- {
- /* It's the first time a FIN has been received, remember its
- sequence number. */
- pxTCPWindow->rx.ulFINSequenceNumber = ulSequenceNumber + ulReceiveLength;
- pxSocket->u.xTCP.bits.bFinRecv = pdTRUE_UNSIGNED;
-
- /* Was peer the first one to send a FIN? */
- if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
- {
- /* If so, don't send the-last-ACK. */
- pxSocket->u.xTCP.bits.bFinLast = pdTRUE_UNSIGNED;
- }
- }
-
- switch (pxSocket->u.xTCP.ucTCPState)
- {
- case eCLOSED: /* (server + client) no connection state at all. */
- /* Nothing to do for a closed socket, except waiting for the
- owner. */
- break;
-
- case eTCP_LISTEN: /* (server) waiting for a connection request from
- any remote TCP and port. */
- /* The listen state was handled in xProcessReceivedTCPPacket().
- Should not come here. */
- break;
-
- case eSYN_FIRST: /* (server) Just received a SYN request for a server
- socket. */
- {
- /* A new socket has been created, reply with a SYN+ACK.
- Acknowledge with seq+1 because the SYN is seen as pseudo data
- with len = 1. */
- uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPPacket );
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_SYN | ipTCP_FLAG_ACK;
-
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
-
- /* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and
- uxOptionsLength is a multiple of 4. The complete expression is:
- ucTCPOffset = ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) / 4 ) << 4 */
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
- vTCPStateChange( pxSocket, eSYN_RECEIVED );
-
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1u;
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->ulNextTxSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1u; /* because we send a TCP_SYN. */
- }
- break;
-
- case eCONNECT_SYN: /* (client) also called SYN_SENT: we've just send a
- SYN, expect a SYN+ACK and send a ACK now. */
- /* Fall through */
- case eSYN_RECEIVED: /* (server) we've had a SYN, replied with SYN+SCK
- expect a ACK and do nothing. */
- xSendLength = prvHandleSynReceived( pxSocket, ppxNetworkBuffer, ulReceiveLength, uxOptionsLength );
- break;
-
- case eESTABLISHED: /* (server + client) an open connection, data
- received can be delivered to the user. The normal
- state for the data transfer phase of the connection
- The closing states are also handled here with the
- use of some flags. */
- xSendLength = prvHandleEstablished( pxSocket, ppxNetworkBuffer, ulReceiveLength, uxOptionsLength );
- break;
-
- case eLAST_ACK: /* (server + client) waiting for an acknowledgement
- of the connection termination request previously
- sent to the remote TCP (which includes an
- acknowledgement of its connection termination
- request). */
- /* Fall through */
- case eFIN_WAIT_1: /* (server + client) waiting for a connection termination request from the remote TCP,
- * or an acknowledgement of the connection termination request previously sent. */
- /* Fall through */
- case eFIN_WAIT_2: /* (server + client) waiting for a connection termination request from the remote TCP. */
- xSendLength = prvTCPHandleFin( pxSocket, *ppxNetworkBuffer );
- break;
-
- case eCLOSE_WAIT: /* (server + client) waiting for a connection
- termination request from the local user. Nothing to
- do, connection is closed, wait for owner to close
- this socket. */
- break;
-
- case eCLOSING: /* (server + client) waiting for a connection
- termination request acknowledgement from the remote
- TCP. */
- break;
-
- case eTIME_WAIT: /* (either server or client) waiting for enough time
- to pass to be sure the remote TCP received the
- acknowledgement of its connection termination
- request. [According to RFC 793 a connection can stay
- in TIME-WAIT for a maximum of four minutes known as
- a MSL (maximum segment lifetime).] These states are
- implemented implicitly by settings flags like
- 'bFinSent', 'bFinRecv', and 'bFinAcked'. */
- break;
- default:
- break;
- }
- }
-
- if( xSendLength > 0 )
- {
- xSendLength = prvSendData( pxSocket, ppxNetworkBuffer, ulReceiveLength, xSendLength );
- }
-
- return xSendLength;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
- #if( ipconfigIGNORE_UNKNOWN_PACKETS == 0 )
- {
- TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
- const BaseType_t xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + 0u ); /* Plus 0 options. */
-
- pxTCPPacket->xTCPHeader.ucTCPFlags = ipTCP_FLAG_ACK | ipTCP_FLAG_RST;
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( ipSIZE_OF_TCP_HEADER + 0u ) << 2;
-
- prvTCPReturnPacket( NULL, pxNetworkBuffer, ( uint32_t ) xSendLength, pdFALSE );
- }
- #endif /* !ipconfigIGNORE_UNKNOWN_PACKETS */
-
- /* Remove compiler warnings if ipconfigIGNORE_UNKNOWN_PACKETS == 1. */
- ( void ) pxNetworkBuffer;
-
- /* The packet was not consumed. */
- return pdFAIL;
-}
-/*-----------------------------------------------------------*/
-
-static void prvSocketSetMSS( FreeRTOS_Socket_t *pxSocket )
-{
-uint32_t ulMSS = ipconfigTCP_MSS;
-
- if( ( ( FreeRTOS_ntohl( pxSocket->u.xTCP.ulRemoteIP ) ^ *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) != 0ul )
- {
- /* Data for this peer will pass through a router, and maybe through
- the internet. Limit the MSS to 1400 bytes or less. */
- ulMSS = FreeRTOS_min_uint32( ( uint32_t ) REDUCED_MSS_THROUGH_INTERNET, ulMSS );
- }
-
- FreeRTOS_debug_printf( ( "prvSocketSetMSS: %lu bytes for %lxip:%u\n", ulMSS, pxSocket->u.xTCP.ulRemoteIP, pxSocket->u.xTCP.usRemotePort ) );
-
- pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ( uint16_t ) ulMSS;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * FreeRTOS_TCP_IP has only 2 public functions, this is the second one:
- * xProcessReceivedTCPPacket()
- * prvTCPHandleState()
- * prvTCPPrepareSend()
- * prvTCPReturnPacket()
- * xNetworkInterfaceOutput() // Sends data to the NIC
- * prvTCPSendRepeated()
- * prvTCPReturnPacket() // Prepare for returning
- * xNetworkInterfaceOutput() // Sends data to the NIC
-*/
-BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-FreeRTOS_Socket_t *pxSocket;
-TCPPacket_t * pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-uint16_t ucTCPFlags;
-uint32_t ulLocalIP;
-uint16_t xLocalPort;
-uint32_t ulRemoteIP;
-uint16_t xRemotePort;
-BaseType_t xResult = pdPASS;
-
- /* Check for a minimum packet size. */
- if( pxNetworkBuffer->xDataLength >= ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) )
- {
- ucTCPFlags = pxTCPPacket->xTCPHeader.ucTCPFlags;
- ulLocalIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulDestinationIPAddress );
- xLocalPort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usDestinationPort );
- ulRemoteIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress );
- xRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
-
- /* Find the destination socket, and if not found: return a socket listing to
- the destination PORT. */
- pxSocket = ( FreeRTOS_Socket_t * )pxTCPSocketLookup( ulLocalIP, xLocalPort, ulRemoteIP, xRemotePort );
- }
- else
- {
- return pdFAIL;
- }
-
- if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( ( UBaseType_t ) pxSocket->u.xTCP.ucTCPState ) == pdFALSE ) )
- {
- /* A TCP messages is received but either there is no socket with the
- given port number or the there is a socket, but it is in one of these
- non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or
- eTIME_WAIT. */
-
- FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%lxip:%d)\n", xLocalPort, ulRemoteIP, xRemotePort ) );
-
- /* Send a RST to all packets that can not be handled. As a result
- the other party will get a ECONN error. There are two exceptions:
- 1) A packet that already has the RST flag set.
- 2) A packet that only has the ACK flag set.
- A packet with only the ACK flag set might be the last ACK in
- a three-way hand-shake that closes a connection. */
- if( ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) != ipTCP_FLAG_ACK ) &&
- ( ( ucTCPFlags & ipTCP_FLAG_RST ) == 0u ) )
- {
- prvTCPSendReset( pxNetworkBuffer );
- }
-
- /* The packet can't be handled. */
- xResult = pdFAIL;
- }
- else
- {
- pxSocket->u.xTCP.ucRepCount = 0u;
-
- if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN )
- {
- /* The matching socket is in a listening state. Test if the peer
- has set the SYN flag. */
- if( ( ucTCPFlags & ipTCP_FLAG_CTRL ) != ipTCP_FLAG_SYN )
- {
- /* What happens: maybe after a reboot, a client doesn't know the
- connection had gone. Send a RST in order to get a new connect
- request. */
- #if( ipconfigHAS_DEBUG_PRINTF == 1 )
- {
- FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %lxip:%u to port %u\n",
- prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), ulRemoteIP, xRemotePort, xLocalPort ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
-
- if( ( ucTCPFlags & ipTCP_FLAG_RST ) == 0u )
- {
- prvTCPSendReset( pxNetworkBuffer );
- }
- xResult = pdFAIL;
- }
- else
- {
- /* prvHandleListen() will either return a newly created socket
- (if bReuseSocket is false), otherwise it returns the current
- socket which will later get connected. */
- pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer );
-
- if( pxSocket == NULL )
- {
- xResult = pdFAIL;
- }
- }
- } /* if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN ). */
- else
- {
- /* This is not a socket in listening mode. Check for the RST
- flag. */
- if( ( ucTCPFlags & ipTCP_FLAG_RST ) != 0u )
- {
- /* The target socket is not in a listening state, any RST packet
- will cause the socket to be closed. */
- FreeRTOS_debug_printf( ( "TCP: RST received from %lxip:%u for %u\n", ulRemoteIP, xRemotePort, xLocalPort ) );
- /* _HT_: should indicate that 'ECONNRESET' must be returned to the used during next API. */
- vTCPStateChange( pxSocket, eCLOSED );
-
- /* The packet cannot be handled. */
- xResult = pdFAIL;
- }
- else if( ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) == ipTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) )
- {
- /* SYN flag while this socket is already connected. */
- FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %lxip:%u\n", ulRemoteIP, xRemotePort ) );
-
- /* The packet cannot be handled. */
- xResult = pdFAIL;
- }
- else
- {
- /* Update the copy of the TCP header only (skipping eth and IP
- headers). It might be used later on, whenever data must be sent
- to the peer. */
- const BaseType_t lOffset = ( BaseType_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER );
- memcpy( pxSocket->u.xTCP.xPacket.u.ucLastPacket + lOffset, pxNetworkBuffer->pucEthernetBuffer + lOffset, ipSIZE_OF_TCP_HEADER );
- }
- }
- }
-
- if( xResult != pdFAIL )
- {
- /* Touch the alive timers because we received a message for this
- socket. */
- prvTCPTouchSocket( pxSocket );
-
- /* Parse the TCP option(s), if present. */
- /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option,
- then we MUST assume an MSS size of 536 bytes for backward compatibility. */
-
- /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
- the number 5 (words) in the higher niblle of the TCP-offset byte. */
- if( ( pxTCPPacket->xTCPHeader.ucTCPOffset & TCP_OFFSET_LENGTH_BITS ) > TCP_OFFSET_STANDARD_LENGTH )
- {
- prvCheckOptions( pxSocket, pxNetworkBuffer );
- }
-
-
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- pxSocket->u.xTCP.ulWindowSize = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usWindow );
- pxSocket->u.xTCP.ulWindowSize =
- ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor );
- }
- #endif
-
- /* In prvTCPHandleState() the incoming messages will be handled
- depending on the current state of the connection. */
- if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 )
- {
- /* prvTCPHandleState() has sent a message, see if there are more to
- be transmitted. */
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- prvTCPSendRepeated( pxSocket, &pxNetworkBuffer );
- }
- #endif /* ipconfigUSE_TCP_WIN */
- }
-
- if( pxNetworkBuffer != NULL )
- {
- /* We must check if the buffer is unequal to NULL, because the
- socket might keep a reference to it in case a delayed ACK must be
- sent. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- pxNetworkBuffer = NULL;
- }
-
- /* And finally, calculate when this socket wants to be woken up. */
- prvTCPNextTimeout ( pxSocket );
- /* Return pdPASS to tell that the network buffer is 'consumed'. */
- xResult = pdPASS;
- }
-
- /* pdPASS being returned means the buffer has been consumed. */
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
-{
-TCPPacket_t * pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-FreeRTOS_Socket_t *pxReturn = NULL;
-uint32_t ulInitialSequenceNumber;
-
- /* Assume that a new Initial Sequence Number will be required. Request
- it now in order to fail out if necessary. */
- ulInitialSequenceNumber = ulApplicationGetNextSequenceNumber( *ipLOCAL_IP_ADDRESS_POINTER,
- pxSocket->usLocalPort,
- pxTCPPacket->xIPHeader.ulSourceIPAddress,
- pxTCPPacket->xTCPHeader.usSourcePort );
-
- /* A pure SYN (without ACK) has come in, create a new socket to answer
- it. */
- if( 0 != ulInitialSequenceNumber )
- {
- if( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED )
- {
- /* The flag bReuseSocket indicates that the same instance of the
- listening socket should be used for the connection. */
- pxReturn = pxSocket;
- pxSocket->u.xTCP.bits.bPassQueued = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.pxPeerSocket = pxSocket;
- }
- else
- {
- /* The socket does not have the bReuseSocket flag set meaning create a
- new socket when a connection comes in. */
- pxReturn = NULL;
-
- if( pxSocket->u.xTCP.usChildCount >= pxSocket->u.xTCP.usBacklog )
- {
- FreeRTOS_printf( ( "Check: Socket %u already has %u / %u child%s\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usChildCount,
- pxSocket->u.xTCP.usBacklog,
- pxSocket->u.xTCP.usChildCount == 1 ? "" : "ren" ) );
- prvTCPSendReset( pxNetworkBuffer );
- }
- else
- {
- FreeRTOS_Socket_t *pxNewSocket = ( FreeRTOS_Socket_t * )
- FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
-
- if( ( pxNewSocket == NULL ) || ( pxNewSocket == FREERTOS_INVALID_SOCKET ) )
- {
- FreeRTOS_debug_printf( ( "TCP: Listen: new socket failed\n" ) );
- prvTCPSendReset( pxNetworkBuffer );
- }
- else if( prvTCPSocketCopy( pxNewSocket, pxSocket ) != pdFALSE )
- {
- /* The socket will be connected immediately, no time for the
- owner to setsockopt's, therefore copy properties of the server
- socket to the new socket. Only the binding might fail (due to
- lack of resources). */
- pxReturn = pxNewSocket;
- }
- }
- }
- }
-
- if( ( 0 != ulInitialSequenceNumber ) && ( pxReturn != NULL ) )
- {
- pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
- pxReturn->u.xTCP.ulRemoteIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress );
- pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber;
-
- /* Here is the SYN action. */
- pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
- prvSocketSetMSS( pxReturn );
-
- prvTCPCreateWindow( pxReturn );
-
- vTCPStateChange( pxReturn, eSYN_FIRST );
-
- /* Make a copy of the header up to the TCP header. It is needed later
- on, whenever data must be sent to the peer. */
- memcpy( pxReturn->u.xTCP.xPacket.u.ucLastPacket, pxNetworkBuffer->pucEthernetBuffer, sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) );
- }
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Duplicates a socket after a listening socket receives a connection.
- */
-static BaseType_t prvTCPSocketCopy( FreeRTOS_Socket_t *pxNewSocket, FreeRTOS_Socket_t *pxSocket )
-{
-struct freertos_sockaddr xAddress;
-
- pxNewSocket->xReceiveBlockTime = pxSocket->xReceiveBlockTime;
- pxNewSocket->xSendBlockTime = pxSocket->xSendBlockTime;
- pxNewSocket->ucSocketOptions = pxSocket->ucSocketOptions;
- pxNewSocket->u.xTCP.uxRxStreamSize = pxSocket->u.xTCP.uxRxStreamSize;
- pxNewSocket->u.xTCP.uxTxStreamSize = pxSocket->u.xTCP.uxTxStreamSize;
- pxNewSocket->u.xTCP.uxLittleSpace = pxSocket->u.xTCP.uxLittleSpace;
- pxNewSocket->u.xTCP.uxEnoughSpace = pxSocket->u.xTCP.uxEnoughSpace;
- pxNewSocket->u.xTCP.uxRxWinSize = pxSocket->u.xTCP.uxRxWinSize;
- pxNewSocket->u.xTCP.uxTxWinSize = pxSocket->u.xTCP.uxTxWinSize;
-
- #if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
- {
- pxNewSocket->pxUserSemaphore = pxSocket->pxUserSemaphore;
- }
- #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- /* In case call-backs are used, copy them from parent to child. */
- pxNewSocket->u.xTCP.pxHandleConnected = pxSocket->u.xTCP.pxHandleConnected;
- pxNewSocket->u.xTCP.pxHandleReceive = pxSocket->u.xTCP.pxHandleReceive;
- pxNewSocket->u.xTCP.pxHandleSent = pxSocket->u.xTCP.pxHandleSent;
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- /* Child socket of listening sockets will inherit the Socket Set
- Otherwise the owner has no chance of including it into the set. */
- if( pxSocket->pxSocketSet )
- {
- pxNewSocket->pxSocketSet = pxSocket->pxSocketSet;
- pxNewSocket->xSelectBits = pxSocket->xSelectBits | eSELECT_READ | eSELECT_EXCEPT;
- }
- }
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
-
- /* And bind it to the same local port as its parent. */
- xAddress.sin_addr = *ipLOCAL_IP_ADDRESS_POINTER;
- xAddress.sin_port = FreeRTOS_htons( pxSocket->usLocalPort );
-
- #if( ipconfigTCP_HANG_PROTECTION == 1 )
- {
- /* Only when there is anti-hanging protection, a socket may become an
- orphan temporarily. Once this socket is really connected, the owner of
- the server socket will be notified. */
-
- /* When bPassQueued is true, the socket is an orphan until it gets
- connected. */
- pxNewSocket->u.xTCP.bits.bPassQueued = pdTRUE_UNSIGNED;
- pxNewSocket->u.xTCP.pxPeerSocket = pxSocket;
- }
- #else
- {
- /* A reference to the new socket may be stored and the socket is marked
- as 'passable'. */
-
- /* When bPassAccept is pdTRUE_UNSIGNED this socket may be returned in a call to
- accept(). */
- pxNewSocket->u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED;
- if(pxSocket->u.xTCP.pxPeerSocket == NULL )
- {
- pxSocket->u.xTCP.pxPeerSocket = pxNewSocket;
- }
- }
- #endif
-
- pxSocket->u.xTCP.usChildCount++;
-
- FreeRTOS_debug_printf( ( "Gain: Socket %u now has %u / %u child%s\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usChildCount,
- pxSocket->u.xTCP.usBacklog,
- pxSocket->u.xTCP.usChildCount == 1u ? "" : "ren" ) );
-
- /* Now bind the child socket to the same port as the listening socket. */
- if( vSocketBind ( pxNewSocket, &xAddress, sizeof( xAddress ), pdTRUE ) != 0 )
- {
- FreeRTOS_debug_printf( ( "TCP: Listen: new socket bind error\n" ) );
- vSocketClose( pxNewSocket );
- return pdFALSE;
- }
-
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
-
- const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState )
- {
- if( ulState >= ( UBaseType_t ) ARRAY_SIZE( pcStateNames ) )
- {
- ulState = ( UBaseType_t ) ARRAY_SIZE( pcStateNames ) - 1u;
- }
- return pcStateNames[ ulState ];
- }
-
-#endif /* ( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) ) */
-/*-----------------------------------------------------------*/
-
-/*
- * In the API accept(), the user asks is there is a new client? As API's can
- * not walk through the xBoundTCPSocketsList the IP-task will do this.
- */
-BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t *pxSocket )
-{
-TickType_t xLocalPort = FreeRTOS_htons( pxSocket->usLocalPort );
-ListItem_t *pxIterator;
-FreeRTOS_Socket_t *pxFound;
-BaseType_t xResult = pdFALSE;
-
- /* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one
- who has access. */
- for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
- pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList );
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- if( listGET_LIST_ITEM_VALUE( pxIterator ) == xLocalPort )
- {
- pxFound = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- if( ( pxFound->ucProtocol == FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
- {
- pxSocket->u.xTCP.pxPeerSocket = pxFound;
- FreeRTOS_debug_printf( ( "xTCPCheckNewClient[0]: client on port %u\n", pxSocket->usLocalPort ) );
- xResult = pdTRUE;
- break;
- }
- }
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-#endif /* ipconfigUSE_TCP == 1 */
-
-/* Provide access to private members for testing. */
-#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
- #include "aws_freertos_tcp_test_access_tcp_define.h"
-#endif
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
deleted file mode 100755
index 953d9f2..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
+++ /dev/null
@@ -1,1981 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/*
- * FreeRTOS_TCP_WIN.c
- * Module which handles the TCP windowing schemes for FreeRTOS+TCP. Many
- * functions have two versions - one for FreeRTOS+TCP (full) and one for
- * FreeRTOS+TCP (lite).
- *
- * In this module all ports and IP addresses and sequence numbers are
- * being stored in host byte-order.
- */
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-#include "FreeRTOS_TCP_WIN.h"
-
-/* Constants used for Smoothed Round Trip Time (SRTT). */
-#define winSRTT_INCREMENT_NEW 2
-#define winSRTT_INCREMENT_CURRENT 6
-#define winSRTT_DECREMENT_NEW 1
-#define winSRTT_DECREMENT_CURRENT 7
-#define winSRTT_CAP_mS 50
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- #define xTCPWindowRxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdTRUE )
-
- #define xTCPWindowTxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdFALSE )
-
- /* The code to send a single Selective ACK (SACK):
- * NOP (0x01), NOP (0x01), SACK (0x05), LEN (0x0a),
- * followed by a lower and a higher sequence number,
- * where LEN is 2 + 2*4 = 10 bytes. */
- #if( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN )
- #define OPTION_CODE_SINGLE_SACK ( 0x0101050aUL )
- #else
- #define OPTION_CODE_SINGLE_SACK ( 0x0a050101UL )
- #endif
-
- /* Normal retransmission:
- * A packet will be retransmitted after a Retransmit Time-Out (RTO).
- * Fast retransmission:
- * When 3 packets with a higher sequence number have been acknowledged
- * by the peer, it is very unlikely a current packet will ever arrive.
- * It will be retransmitted far before the RTO.
- */
- #define DUPLICATE_ACKS_BEFORE_FAST_RETRANSMIT ( 3u )
-
- /* If there have been several retransmissions (4), decrease the
- * size of the transmission window to at most 2 times MSS.
- */
- #define MAX_TRANSMIT_COUNT_USING_LARGE_WINDOW ( 4u )
-
-#endif /* configUSE_TCP_WIN */
-/*-----------------------------------------------------------*/
-
-extern void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewListItem, MiniListItem_t * const pxWhere );
-
-/*
- * All TCP sockets share a pool of segment descriptors (TCPSegment_t)
- * Available descriptors are stored in the 'xSegmentList'
- * When a socket owns a descriptor, it will either be stored in
- * 'xTxSegments' or 'xRxSegments'
- * As soon as a package has been confirmed, the descriptor will be returned
- * to the segment pool
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static BaseType_t prvCreateSectors( void );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * Find a segment with a given sequence number in the list of received
- * segments: 'pxWindow->xRxSegments'.
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPWindowRxFind( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * Allocate a new segment
- * The socket will borrow all segments from a common pool: 'xSegmentList',
- * which is a list of 'TCPSegment_t'
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPWindowNew( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, int32_t lCount, BaseType_t xIsForRx );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/* When the peer has a close request (FIN flag), the driver will check if
- * there are missing packets in the Rx-queue
- * It will accept the closure of the connection if both conditions are true:
- * - the Rx-queue is empty
- * - we've ACK'd the highest Rx sequence number seen
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- BaseType_t xTCPWindowRxEmpty( TCPWindow_t *pxWindow );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * Detaches and returns the head of a queue
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPWindowGetHead( List_t *pxList );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * Returns the head of a queue but it won't be detached
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPWindowPeekHead( List_t *pxList );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * Free entry pxSegment because it's not used anymore
- * The ownership will be passed back to the segment pool
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static void vTCPWindowFree( TCPSegment_t *pxSegment );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * A segment has been received with sequence number 'ulSequenceNumber', where
- * 'ulCurrentSequenceNumber == ulSequenceNumber', which means that exactly this
- * segment was expected. xTCPWindowRxConfirm() will check if there is already
- * another segment with a sequence number between (ulSequenceNumber) and
- * (ulSequenceNumber+xLength). Normally none will be found, because the next Rx
- * segment should have a sequence number equal to '(ulSequenceNumber+xLength)'.
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPWindowRxConfirm( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * FreeRTOS+TCP stores data in circular buffers. Calculate the next position to
- * store.
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static int32_t lTCPIncrementTxPosition( int32_t lPosition, int32_t lMax, int32_t lCount );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * This function will look if there is new transmission data. It will return
- * true if there is data to be sent.
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static BaseType_t prvTCPWindowTxHasSpace( TCPWindow_t *pxWindow, uint32_t ulWindowSize );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * An acknowledge was received. See if some outstanding data may be removed
- * from the transmission queue(s).
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static uint32_t prvTCPWindowTxCheckAck( TCPWindow_t *pxWindow, uint32_t ulFirst, uint32_t ulLast );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*
- * A higher Tx block has been acknowledged. Now iterate through the xWaitQueue
- * to find a possible condition for a FAST retransmission.
- */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static uint32_t prvTCPWindowFastRetransmit( TCPWindow_t *pxWindow, uint32_t ulFirst );
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/*-----------------------------------------------------------*/
-
-/* TCP segement pool. */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static TCPSegment_t *xTCPSegments = NULL;
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-
-/* List of free TCP segments. */
-#if( ipconfigUSE_TCP_WIN == 1 )
- static List_t xSegmentList;
-#endif
-
-/* Logging verbosity level. */
-BaseType_t xTCPWindowLoggingLevel = 0;
-
-#if( ipconfigUSE_TCP_WIN == 1 )
- /* Some 32-bit arithmetic: comparing sequence numbers */
- static portINLINE BaseType_t xSequenceLessThanOrEqual( uint32_t a, uint32_t b );
- static portINLINE BaseType_t xSequenceLessThanOrEqual( uint32_t a, uint32_t b )
- {
- /* Test if a <= b
- Return true if the unsigned subtraction of (b-a) doesn't generate an
- arithmetic overflow. */
- return ( ( b - a ) & 0x80000000UL ) == 0UL;
- }
-#endif /* ipconfigUSE_TCP_WIN */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
- static portINLINE BaseType_t xSequenceLessThan( uint32_t a, uint32_t b );
- static portINLINE BaseType_t xSequenceLessThan( uint32_t a, uint32_t b )
- {
- /* Test if a < b */
- return ( ( b - a - 1UL ) & 0x80000000UL ) == 0UL;
- }
-#endif /* ipconfigUSE_TCP_WIN */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
- static portINLINE BaseType_t xSequenceGreaterThan( uint32_t a, uint32_t b );
- static portINLINE BaseType_t xSequenceGreaterThan( uint32_t a, uint32_t b )
- {
- /* Test if a > b */
- return ( ( a - b - 1UL ) & 0x80000000UL ) == 0UL;
- }
-#endif /* ipconfigUSE_TCP_WIN */
-
-/*-----------------------------------------------------------*/
-static portINLINE BaseType_t xSequenceGreaterThanOrEqual( uint32_t a, uint32_t b );
-static portINLINE BaseType_t xSequenceGreaterThanOrEqual( uint32_t a, uint32_t b )
-{
- /* Test if a >= b */
- return ( ( a - b ) & 0x80000000UL ) == 0UL;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
- static portINLINE void vListInsertFifo( List_t * const pxList, ListItem_t * const pxNewListItem );
- static portINLINE void vListInsertFifo( List_t * const pxList, ListItem_t * const pxNewListItem )
- {
- vListInsertGeneric( pxList, pxNewListItem, &pxList->xListEnd );
- }
-#endif
-/*-----------------------------------------------------------*/
-
-static portINLINE void vTCPTimerSet( TCPTimer_t *pxTimer );
-static portINLINE void vTCPTimerSet( TCPTimer_t *pxTimer )
-{
- pxTimer->ulBorn = xTaskGetTickCount ( );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE uint32_t ulTimerGetAge( TCPTimer_t *pxTimer );
-static portINLINE uint32_t ulTimerGetAge( TCPTimer_t *pxTimer )
-{
- return ( ( xTaskGetTickCount() - pxTimer->ulBorn ) * portTICK_PERIOD_MS );
-}
-/*-----------------------------------------------------------*/
-
-/* _HT_ GCC (using the settings that I'm using) checks for every public function if it is
-preceded by a prototype. Later this prototype will be located in list.h? */
-
-extern void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewListItem, MiniListItem_t * const pxWhere );
-
-void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewListItem, MiniListItem_t * const pxWhere )
-{
- /* Insert a new list item into pxList, it does not sort the list,
- but it puts the item just before xListEnd, so it will be the last item
- returned by listGET_HEAD_ENTRY() */
- pxNewListItem->pxNext = (struct xLIST_ITEM * configLIST_VOLATILE)pxWhere;
- pxNewListItem->pxPrevious = pxWhere->pxPrevious;
- pxWhere->pxPrevious->pxNext = pxNewListItem;
- pxWhere->pxPrevious = pxNewListItem;
-
- /* Remember which list the item is in. */
- pxNewListItem->pvContainer = ( void * ) pxList; /* If this line fails to build then ensure configENABLE_BACKWARD_COMPATIBILITY is set to 1 in FreeRTOSConfig.h. */
-
- ( pxList->uxNumberOfItems )++;
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static BaseType_t prvCreateSectors( void )
- {
- BaseType_t xIndex, xReturn;
-
- /* Allocate space for 'xTCPSegments' and store them in 'xSegmentList'. */
-
- vListInitialise( &xSegmentList );
- xTCPSegments = ( TCPSegment_t * ) pvPortMallocLarge( ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) );
-
- if( xTCPSegments == NULL )
- {
- FreeRTOS_debug_printf( ( "prvCreateSectors: malloc %lu failed\n",
- ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) );
-
- xReturn = pdFAIL;
- }
- else
- {
- /* Clear the allocated space. */
- memset( xTCPSegments, '\0', ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) );
-
- for( xIndex = 0; xIndex < ipconfigTCP_WIN_SEG_COUNT; xIndex++ )
- {
- /* Could call vListInitialiseItem here but all data has been
- nulled already. Set the owner to a segment descriptor. */
- listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xListItem ), ( void* ) &( xTCPSegments[ xIndex ] ) );
- listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ( void* ) &( xTCPSegments[ xIndex ] ) );
-
- /* And add it to the pool of available segments */
- vListInsertFifo( &xSegmentList, &( xTCPSegments[xIndex].xListItem ) );
- }
-
- xReturn = pdPASS;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static TCPSegment_t *xTCPWindowRxFind( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t* pxEnd;
- TCPSegment_t *pxSegment, *pxReturn = NULL;
-
- /* Find a segment with a given sequence number in the list of received
- segments. */
-
- pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &pxWindow->xRxSegments );
-
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( const ListItem_t * ) pxEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
-
- if( pxSegment->ulSequenceNumber == ulSequenceNumber )
- {
- pxReturn = pxSegment;
- break;
- }
- }
-
- return pxReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static TCPSegment_t *xTCPWindowNew( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, int32_t lCount, BaseType_t xIsForRx )
- {
- TCPSegment_t *pxSegment;
- ListItem_t * pxItem;
-
- /* Allocate a new segment. The socket will borrow all segments from a
- common pool: 'xSegmentList', which is a list of 'TCPSegment_t' */
- if( listLIST_IS_EMPTY( &xSegmentList ) != pdFALSE )
- {
- /* If the TCP-stack runs out of segments, you might consider
- increasing 'ipconfigTCP_WIN_SEG_COUNT'. */
- FreeRTOS_debug_printf( ( "xTCPWindow%cxNew: Error: all segments occupied\n", xIsForRx ? 'R' : 'T' ) );
- pxSegment = NULL;
- }
- else
- {
- /* Pop the item at the head of the list. Semaphore protection is
- not required as only the IP task will call these functions. */
- pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( &xSegmentList );
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxItem );
-
- configASSERT( pxItem != NULL );
- configASSERT( pxSegment != NULL );
-
- /* Remove the item from xSegmentList. */
- uxListRemove( pxItem );
-
- /* Add it to either the connections' Rx or Tx queue. */
- vListInsertFifo( xIsForRx ? &pxWindow->xRxSegments : &pxWindow->xTxSegments, pxItem );
-
- /* And set the segment's timer to zero */
- vTCPTimerSet( &pxSegment->xTransmitTimer );
-
- pxSegment->u.ulFlags = 0;
- pxSegment->u.bits.bIsForRx = ( xIsForRx != 0 );
- pxSegment->lMaxLength = lCount;
- pxSegment->lDataLength = lCount;
- pxSegment->ulSequenceNumber = ulSequenceNumber;
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- static UBaseType_t xLowestLength = ipconfigTCP_WIN_SEG_COUNT;
- UBaseType_t xLength = listCURRENT_LIST_LENGTH( &xSegmentList );
-
- if( xLowestLength > xLength )
- {
- xLowestLength = xLength;
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
- }
-
- return pxSegment;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- BaseType_t xTCPWindowRxEmpty( TCPWindow_t *pxWindow )
- {
- BaseType_t xReturn;
-
- /* When the peer has a close request (FIN flag), the driver will check
- if there are missing packets in the Rx-queue. It will accept the
- closure of the connection if both conditions are true:
- - the Rx-queue is empty
- - the highest Rx sequence number has been ACK'ed */
- if( listLIST_IS_EMPTY( ( &pxWindow->xRxSegments ) ) == pdFALSE )
- {
- /* Rx data has been stored while earlier packets were missing. */
- xReturn = pdFALSE;
- }
- else if( xSequenceGreaterThanOrEqual( pxWindow->rx.ulCurrentSequenceNumber, pxWindow->rx.ulHighestSequenceNumber ) != pdFALSE )
- {
- /* No Rx packets are being stored and the highest sequence number
- that has been received has been ACKed. */
- xReturn = pdTRUE;
- }
- else
- {
- FreeRTOS_debug_printf( ( "xTCPWindowRxEmpty: cur %lu highest %lu (empty)\n",
- ( pxWindow->rx.ulCurrentSequenceNumber - pxWindow->rx.ulFirstSequenceNumber ),
- ( pxWindow->rx.ulHighestSequenceNumber - pxWindow->rx.ulFirstSequenceNumber ) ) );
- xReturn = pdFALSE;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static TCPSegment_t *xTCPWindowGetHead( List_t *pxList )
- {
- TCPSegment_t *pxSegment;
- ListItem_t * pxItem;
-
- /* Detaches and returns the head of a queue. */
- if( listLIST_IS_EMPTY( pxList ) != pdFALSE )
- {
- pxSegment = NULL;
- }
- else
- {
- pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxItem );
-
- uxListRemove( pxItem );
- }
-
- return pxSegment;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static TCPSegment_t *xTCPWindowPeekHead( List_t *pxList )
- {
- ListItem_t *pxItem;
- TCPSegment_t *pxReturn;
-
- /* Returns the head of a queue but it won't be detached. */
- if( listLIST_IS_EMPTY( pxList ) != pdFALSE )
- {
- pxReturn = NULL;
- }
- else
- {
- pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
- pxReturn = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxItem );
- }
-
- return pxReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static void vTCPWindowFree( TCPSegment_t *pxSegment )
- {
- /* Free entry pxSegment because it's not used any more. The ownership
- will be passed back to the segment pool.
-
- Unlink it from one of the queues, if any. */
- if( listLIST_ITEM_CONTAINER( &( pxSegment->xQueueItem ) ) != NULL )
- {
- uxListRemove( &( pxSegment->xQueueItem ) );
- }
-
- pxSegment->ulSequenceNumber = 0u;
- pxSegment->lDataLength = 0l;
- pxSegment->u.ulFlags = 0u;
-
- /* Take it out of xRxSegments/xTxSegments */
- if( listLIST_ITEM_CONTAINER( &( pxSegment->xListItem ) ) != NULL )
- {
- uxListRemove( &( pxSegment->xListItem ) );
- }
-
- /* Return it to xSegmentList */
- vListInsertFifo( &xSegmentList, &( pxSegment->xListItem ) );
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- void vTCPWindowDestroy( TCPWindow_t *pxWindow )
- {
- List_t * pxSegments;
- BaseType_t xRound;
- TCPSegment_t *pxSegment;
-
- /* Destroy a window. A TCP window doesn't serve any more. Return all
- owned segments to the pool. In order to save code, it will make 2 rounds,
- one to remove the segments from xRxSegments, and a second round to clear
- xTxSegments*/
- for( xRound = 0; xRound < 2; xRound++ )
- {
- if( xRound != 0 )
- {
- pxSegments = &( pxWindow->xRxSegments );
- }
- else
- {
- pxSegments = &( pxWindow->xTxSegments );
- }
-
- if( listLIST_IS_INITIALISED( pxSegments ) != pdFALSE )
- {
- while( listCURRENT_LIST_LENGTH( pxSegments ) > 0U )
- {
- pxSegment = ( TCPSegment_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxSegments );
- vTCPWindowFree( pxSegment );
- }
- }
- }
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-void vTCPWindowCreate( TCPWindow_t *pxWindow, uint32_t ulRxWindowLength,
- uint32_t ulTxWindowLength, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS )
-{
- /* Create and initialize a window. */
-
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- if( xTCPSegments == NULL )
- {
- prvCreateSectors();
- }
-
- vListInitialise( &pxWindow->xTxSegments );
- vListInitialise( &pxWindow->xRxSegments );
-
- vListInitialise( &pxWindow->xPriorityQueue ); /* Priority queue: segments which must be sent immediately */
- vListInitialise( &pxWindow->xTxQueue ); /* Transmit queue: segments queued for transmission */
- vListInitialise( &pxWindow->xWaitQueue ); /* Waiting queue: outstanding segments */
- }
- #endif /* ipconfigUSE_TCP_WIN == 1 */
-
- if( xTCPWindowLoggingLevel != 0 )
- {
- FreeRTOS_debug_printf( ( "vTCPWindowCreate: for WinLen = Rx/Tx: %lu/%lu\n",
- ulRxWindowLength, ulTxWindowLength ) );
- }
-
- pxWindow->xSize.ulRxWindowLength = ulRxWindowLength;
- pxWindow->xSize.ulTxWindowLength = ulTxWindowLength;
-
- vTCPWindowInit( pxWindow, ulAckNumber, ulSequenceNumber, ulMSS );
-}
-/*-----------------------------------------------------------*/
-
-void vTCPWindowInit( TCPWindow_t *pxWindow, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS )
-{
-const int32_t l500ms = 500;
-
- pxWindow->u.ulFlags = 0ul;
- pxWindow->u.bits.bHasInit = pdTRUE_UNSIGNED;
-
- if( ulMSS != 0ul )
- {
- if( pxWindow->usMSSInit != 0u )
- {
- pxWindow->usMSSInit = ( uint16_t ) ulMSS;
- }
-
- if( ( ulMSS < ( uint32_t ) pxWindow->usMSS ) || ( pxWindow->usMSS == 0u ) )
- {
- pxWindow->xSize.ulRxWindowLength = ( pxWindow->xSize.ulRxWindowLength / ulMSS ) * ulMSS;
- pxWindow->usMSS = ( uint16_t ) ulMSS;
- }
- }
-
- #if( ipconfigUSE_TCP_WIN == 0 )
- {
- pxWindow->xTxSegment.lMaxLength = ( int32_t ) pxWindow->usMSS;
- }
- #endif /* ipconfigUSE_TCP_WIN == 1 */
-
- /*Start with a timeout of 2 * 500 ms (1 sec). */
- pxWindow->lSRTT = l500ms;
-
- /* Just for logging, to print relative sequence numbers. */
- pxWindow->rx.ulFirstSequenceNumber = ulAckNumber;
-
- /* The segment asked for in the next transmission. */
- pxWindow->rx.ulCurrentSequenceNumber = ulAckNumber;
-
- /* The right-hand side of the receive window. */
- pxWindow->rx.ulHighestSequenceNumber = ulAckNumber;
-
- pxWindow->tx.ulFirstSequenceNumber = ulSequenceNumber;
-
- /* The segment asked for in next transmission. */
- pxWindow->tx.ulCurrentSequenceNumber = ulSequenceNumber;
-
- /* The sequence number given to the next outgoing byte to be added is
- maintained by lTCPWindowTxAdd(). */
- pxWindow->ulNextTxSequenceNumber = ulSequenceNumber;
-
- /* The right-hand side of the transmit window. */
- pxWindow->tx.ulHighestSequenceNumber = ulSequenceNumber;
- pxWindow->ulOurSequenceNumber = ulSequenceNumber;
-}
-/*-----------------------------------------------------------*/
-
-/*=============================================================================
- *
- * ###### # #
- * # # # #
- * # # # #
- * # # ####
- * ###### ##
- * # ## ####
- * # # # #
- * # # # #
- * ### ## # #
- * Rx functions
- *
- *=============================================================================*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static TCPSegment_t *xTCPWindowRxConfirm( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength )
- {
- TCPSegment_t *pxBest = NULL;
- const ListItem_t *pxIterator;
- uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength;
- const MiniListItem_t* pxEnd = ( const MiniListItem_t* ) listGET_END_MARKER( &pxWindow->xRxSegments );
- TCPSegment_t *pxSegment;
-
- /* A segment has been received with sequence number 'ulSequenceNumber',
- where 'ulCurrentSequenceNumber == ulSequenceNumber', which means that
- exactly this segment was expected. xTCPWindowRxConfirm() will check if
- there is already another segment with a sequence number between (ulSequenceNumber)
- and (ulSequenceNumber+ulLength). Normally none will be found, because
- the next RX segment should have a sequence number equal to
- '(ulSequenceNumber+ulLength)'. */
-
- /* Iterate through all RX segments that are stored: */
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( const ListItem_t * ) pxEnd;
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
- {
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- /* And see if there is a segment for which:
- 'ulSequenceNumber' <= 'pxSegment->ulSequenceNumber' < 'ulNextSequenceNumber'
- If there are more matching segments, the one with the lowest sequence number
- shall be taken */
- if( ( xSequenceGreaterThanOrEqual( pxSegment->ulSequenceNumber, ulSequenceNumber ) != 0 ) &&
- ( xSequenceLessThan( pxSegment->ulSequenceNumber, ulNextSequenceNumber ) != 0 ) )
- {
- if( ( pxBest == NULL ) || ( xSequenceLessThan( pxSegment->ulSequenceNumber, pxBest->ulSequenceNumber ) != 0 ) )
- {
- pxBest = pxSegment;
- }
- }
- }
-
- if( ( pxBest != NULL ) &&
- ( ( pxBest->ulSequenceNumber != ulSequenceNumber ) || ( pxBest->lDataLength != ( int32_t ) ulLength ) ) )
- {
- FreeRTOS_flush_logging();
- FreeRTOS_debug_printf( ( "xTCPWindowRxConfirm[%u]: search %lu (+%ld=%lu) found %lu (+%ld=%lu)\n",
- pxWindow->usPeerPortNumber,
- ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- ulLength,
- ulSequenceNumber + ulLength - pxWindow->rx.ulFirstSequenceNumber,
- pxBest->ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- pxBest->lDataLength,
- pxBest->ulSequenceNumber + ( ( uint32_t ) pxBest->lDataLength ) - pxWindow->rx.ulFirstSequenceNumber ) );
- }
-
- return pxBest;
- }
-
-#endif /* ipconfgiUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- int32_t lTCPWindowRxCheck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength, uint32_t ulSpace )
- {
- uint32_t ulCurrentSequenceNumber, ulLast, ulSavedSequenceNumber;
- int32_t lReturn, lDistance;
- TCPSegment_t *pxFound;
-
- /* If lTCPWindowRxCheck( ) returns == 0, the packet will be passed
- directly to user (segment is expected). If it returns a positive
- number, an earlier packet is missing, but this packet may be stored.
- If negative, the packet has already been stored, or it is out-of-order,
- or there is not enough space.
-
- As a side-effect, pxWindow->ulUserDataLength will get set to non-zero,
- if more Rx data may be passed to the user after this packet. */
-
- ulCurrentSequenceNumber = pxWindow->rx.ulCurrentSequenceNumber;
-
- /* For Selective Ack (SACK), used when out-of-sequence data come in. */
- pxWindow->ucOptionLength = 0u;
-
- /* Non-zero if TCP-windows contains data which must be popped. */
- pxWindow->ulUserDataLength = 0ul;
-
- if( ulCurrentSequenceNumber == ulSequenceNumber )
- {
- /* This is the packet with the lowest sequence number we're waiting
- for. It can be passed directly to the rx stream. */
- if( ulLength > ulSpace )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Refuse %lu bytes, due to lack of space (%lu)\n", ulLength, ulSpace ) );
- lReturn = -1;
- }
- else
- {
- ulCurrentSequenceNumber += ulLength;
-
- if( listCURRENT_LIST_LENGTH( &( pxWindow->xRxSegments ) ) != 0 )
- {
- ulSavedSequenceNumber = ulCurrentSequenceNumber;
-
- /* Clean up all sequence received between ulSequenceNumber and ulSequenceNumber + ulLength since they are duplicated.
- If the server is forced to retransmit packets several time in a row it might send a batch of concatenated packet for speed.
- So we cannot rely on the packets between ulSequenceNumber and ulSequenceNumber + ulLength to be sequential and it is better to just
- clean them out. */
- do
- {
- pxFound = xTCPWindowRxConfirm( pxWindow, ulSequenceNumber, ulLength );
-
- if ( pxFound != NULL )
- {
- /* Remove it because it will be passed to user directly. */
- vTCPWindowFree( pxFound );
- }
- } while ( pxFound );
-
- /* Check for following segments that are already in the
- queue and increment ulCurrentSequenceNumber. */
- while( ( pxFound = xTCPWindowRxFind( pxWindow, ulCurrentSequenceNumber ) ) != NULL )
- {
- ulCurrentSequenceNumber += ( uint32_t ) pxFound->lDataLength;
-
- /* As all packet below this one have been passed to the
- user it can be discarded. */
- vTCPWindowFree( pxFound );
- }
-
- if( ulSavedSequenceNumber != ulCurrentSequenceNumber )
- {
- /* After the current data-package, there is more data
- to be popped. */
- pxWindow->ulUserDataLength = ulCurrentSequenceNumber - ulSavedSequenceNumber;
-
- if( xTCPWindowLoggingLevel >= 1 )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowRxCheck[%d,%d]: retran %lu (Found %lu bytes at %lu cnt %ld)\n",
- pxWindow->usPeerPortNumber, pxWindow->usOurPortNumber,
- ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- pxWindow->ulUserDataLength,
- ulSavedSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- listCURRENT_LIST_LENGTH( &pxWindow->xRxSegments ) ) );
- }
- }
- }
-
- pxWindow->rx.ulCurrentSequenceNumber = ulCurrentSequenceNumber;
-
- /* Packet was expected, may be passed directly to the socket
- buffer or application. Store the packet at offset 0. */
- lReturn = 0;
- }
- }
- else if( ulCurrentSequenceNumber == ( ulSequenceNumber + 1UL ) )
- {
- /* Looks like a TCP keep-alive message. Do not accept/store Rx data
- ulUserDataLength = 0. Not packet out-of-sync. Just reply to it. */
- lReturn = -1;
- }
- else
- {
- /* The packet is not the one expected. See if it falls within the Rx
- window so it can be stored. */
-
- /* An "out-of-sequence" segment was received, must have missed one.
- Prepare a SACK (Selective ACK). */
- ulLast = ulSequenceNumber + ulLength;
- lDistance = ( int32_t ) ( ulLast - ulCurrentSequenceNumber );
-
- if( lDistance <= 0 )
- {
- /* An earlier has been received, must be a retransmission of a
- packet that has been accepted already. No need to send out a
- Selective ACK (SACK). */
- lReturn = -1;
- }
- else if( lDistance > ( int32_t ) ulSpace )
- {
- /* The new segment is ahead of rx.ulCurrentSequenceNumber. The
- sequence number of this packet is too far ahead, ignore it. */
- FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Refuse %lu+%lu bytes, due to lack of space (%lu)\n", lDistance, ulLength, ulSpace ) );
- lReturn = -1;
- }
- else
- {
- /* See if there is more data in a contiguous block to make the
- SACK describe a longer range of data. */
-
- /* TODO: SACK's may also be delayed for a short period
- * This is useful because subsequent packets will be SACK'd with
- * single one message
- */
- while( ( pxFound = xTCPWindowRxFind( pxWindow, ulLast ) ) != NULL )
- {
- ulLast += ( uint32_t ) pxFound->lDataLength;
- }
-
- if( xTCPWindowLoggingLevel >= 1 )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowRxCheck[%d,%d]: seqnr %lu exp %lu (dist %ld) SACK to %lu\n",
- pxWindow->usPeerPortNumber, pxWindow->usOurPortNumber,
- ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- ulCurrentSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- ( BaseType_t ) ( ulSequenceNumber - ulCurrentSequenceNumber ), /* want this signed */
- ulLast - pxWindow->rx.ulFirstSequenceNumber ) );
- }
-
- /* Now prepare the SACK message.
- Code OPTION_CODE_SINGLE_SACK already in network byte order. */
- pxWindow->ulOptionsData[0] = OPTION_CODE_SINGLE_SACK;
-
- /* First sequence number that we received. */
- pxWindow->ulOptionsData[1] = FreeRTOS_htonl( ulSequenceNumber );
-
- /* Last + 1 */
- pxWindow->ulOptionsData[2] = FreeRTOS_htonl( ulLast );
-
- /* Which make 12 (3*4) option bytes. */
- pxWindow->ucOptionLength = 3 * sizeof( pxWindow->ulOptionsData[ 0 ] );
-
- pxFound = xTCPWindowRxFind( pxWindow, ulSequenceNumber );
-
- if( pxFound != NULL )
- {
- /* This out-of-sequence packet has been received for a
- second time. It is already stored but do send a SACK
- again. */
- lReturn = -1;
- }
- else
- {
- pxFound = xTCPWindowRxNew( pxWindow, ulSequenceNumber, ( int32_t ) ulLength );
-
- if( pxFound == NULL )
- {
- /* Can not send a SACK, because the segment cannot be
- stored. */
- pxWindow->ucOptionLength = 0u;
-
- /* Needs to be stored but there is no segment
- available. */
- lReturn = -1;
- }
- else
- {
- if( xTCPWindowLoggingLevel != 0 )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowRxCheck[%u,%u]: seqnr %lu (cnt %lu)\n",
- pxWindow->usPeerPortNumber, pxWindow->usOurPortNumber, ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber,
- listCURRENT_LIST_LENGTH( &pxWindow->xRxSegments ) ) );
- FreeRTOS_flush_logging( );
- }
-
- /* Return a positive value. The packet may be accepted
- and stored but an earlier packet is still missing. */
- lReturn = ( int32_t ) ( ulSequenceNumber - ulCurrentSequenceNumber );
- }
- }
- }
- }
-
- return lReturn;
- }
-
-#endif /* ipconfgiUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-/*=============================================================================
- *
- * ######### # #
- * # # # # #
- * # # #
- * # ####
- * # ##
- * # ####
- * # # #
- * # # #
- * ##### # #
- *
- * Tx functions
- *
- *=============================================================================*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static int32_t lTCPIncrementTxPosition( int32_t lPosition, int32_t lMax, int32_t lCount )
- {
- /* +TCP stores data in circular buffers. Calculate the next position to
- store. */
- lPosition += lCount;
- if( lPosition >= lMax )
- {
- lPosition -= lMax;
- }
-
- return lPosition;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- int32_t lTCPWindowTxAdd( TCPWindow_t *pxWindow, uint32_t ulLength, int32_t lPosition, int32_t lMax )
- {
- int32_t lBytesLeft = ( int32_t ) ulLength, lToWrite;
- int32_t lDone = 0;
- TCPSegment_t *pxSegment = pxWindow->pxHeadSegment;
-
- /* Puts a message in the Tx-window (after buffer size has been
- verified). */
- if( pxSegment != NULL )
- {
- if( pxSegment->lDataLength < pxSegment->lMaxLength )
- {
- if( ( pxSegment->u.bits.bOutstanding == pdFALSE_UNSIGNED ) && ( pxSegment->lDataLength != 0 ) )
- {
- /* Adding data to a segment that was already in the TX queue. It
- will be filled-up to a maximum of MSS (maximum segment size). */
- lToWrite = FreeRTOS_min_int32( lBytesLeft, pxSegment->lMaxLength - pxSegment->lDataLength );
-
- pxSegment->lDataLength += lToWrite;
-
- if( pxSegment->lDataLength >= pxSegment->lMaxLength )
- {
- /* This segment is full, don't add more bytes. */
- pxWindow->pxHeadSegment = NULL;
- }
-
- lBytesLeft -= lToWrite;
-
- /* ulNextTxSequenceNumber is the sequence number of the next byte to
- be stored for transmission. */
- pxWindow->ulNextTxSequenceNumber += ( uint32_t ) lToWrite;
-
- /* Increased the return value. */
- lDone += lToWrite;
-
- /* Some detailed logging, for those who're interested. */
- if( ( xTCPWindowLoggingLevel >= 2 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != 0 ) )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: Add %4lu bytes for seqNr %lu len %4lu (nxt %lu) pos %lu\n",
- ulLength,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->lDataLength,
- pxWindow->ulNextTxSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->lStreamPos ) );
- FreeRTOS_flush_logging( );
- }
-
- /* Calculate the next position in the circular data buffer, knowing
- its maximum length 'lMax'. */
- lPosition = lTCPIncrementTxPosition( lPosition, lMax, lToWrite );
- }
- }
- }
-
- while( lBytesLeft > 0 )
- {
- /* The current transmission segment is full, create new segments as
- needed. */
- pxSegment = xTCPWindowTxNew( pxWindow, pxWindow->ulNextTxSequenceNumber, pxWindow->usMSS );
-
- if( pxSegment != NULL )
- {
- /* Store as many as needed, but no more than the maximum
- (MSS). */
- lToWrite = FreeRTOS_min_int32( lBytesLeft, pxSegment->lMaxLength );
-
- pxSegment->lDataLength = lToWrite;
- pxSegment->lStreamPos = lPosition;
- lBytesLeft -= lToWrite;
- lPosition = lTCPIncrementTxPosition( lPosition, lMax, lToWrite );
- pxWindow->ulNextTxSequenceNumber += ( uint32_t ) lToWrite;
- lDone += lToWrite;
-
- /* Link this segment in the Tx-Queue. */
- vListInsertFifo( &( pxWindow->xTxQueue ), &( pxSegment->xQueueItem ) );
-
- /* Let 'pxHeadSegment' point to this segment if there is still
- space. */
- if( pxSegment->lDataLength < pxSegment->lMaxLength )
- {
- pxWindow->pxHeadSegment = pxSegment;
- }
- else
- {
- pxWindow->pxHeadSegment = NULL;
- }
-
- if( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != 0 )
- {
- if( ( xTCPWindowLoggingLevel >= 3 ) ||
- ( ( xTCPWindowLoggingLevel >= 2 ) && ( pxWindow->pxHeadSegment != NULL ) ) )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: New %4ld bytes for seqNr %lu len %4lu (nxt %lu) pos %lu\n",
- ulLength,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->lDataLength,
- pxWindow->ulNextTxSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->lStreamPos ) );
- FreeRTOS_flush_logging( );
- }
- }
- }
- else
- {
- /* A sever situation: running out of segments for transmission.
- No more data can be sent at the moment. */
- if( lDone != 0 )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: Sorry all buffers full (cancel %ld bytes)\n", lBytesLeft ) );
- }
- break;
- }
- }
-
- return lDone;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- BaseType_t xTCPWindowTxDone( TCPWindow_t *pxWindow )
- {
- return listLIST_IS_EMPTY( ( &pxWindow->xTxSegments) );
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static BaseType_t prvTCPWindowTxHasSpace( TCPWindow_t *pxWindow, uint32_t ulWindowSize )
- {
- uint32_t ulTxOutstanding;
- BaseType_t xHasSpace;
- TCPSegment_t *pxSegment;
-
- /* This function will look if there is new transmission data. It will
- return true if there is data to be sent. */
-
- pxSegment = xTCPWindowPeekHead( &( pxWindow->xTxQueue ) );
-
- if( pxSegment == NULL )
- {
- xHasSpace = pdFALSE;
- }
- else
- {
- /* How much data is outstanding, i.e. how much data has been sent
- but not yet acknowledged ? */
- if( pxWindow->tx.ulHighestSequenceNumber >= pxWindow->tx.ulCurrentSequenceNumber )
- {
- ulTxOutstanding = pxWindow->tx.ulHighestSequenceNumber - pxWindow->tx.ulCurrentSequenceNumber;
- }
- else
- {
- ulTxOutstanding = 0UL;
- }
-
- /* Subtract this from the peer's space. */
- ulWindowSize -= FreeRTOS_min_uint32( ulWindowSize, ulTxOutstanding );
-
- /* See if the next segment may be sent. */
- if( ulWindowSize >= ( uint32_t ) pxSegment->lDataLength )
- {
- xHasSpace = pdTRUE;
- }
- else
- {
- xHasSpace = pdFALSE;
- }
-
- /* If 'xHasSpace', it looks like the peer has at least space for 1
- more new segment of size MSS. xSize.ulTxWindowLength is the self-imposed
- limitation of the transmission window (in case of many resends it
- may be decreased). */
- if( ( ulTxOutstanding != 0UL ) && ( pxWindow->xSize.ulTxWindowLength < ulTxOutstanding + ( ( uint32_t ) pxSegment->lDataLength ) ) )
- {
- xHasSpace = pdFALSE;
- }
- }
-
- return xHasSpace;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- BaseType_t xTCPWindowTxHasData( TCPWindow_t *pxWindow, uint32_t ulWindowSize, TickType_t *pulDelay )
- {
- TCPSegment_t *pxSegment;
- BaseType_t xReturn;
- TickType_t ulAge, ulMaxAge;
-
- *pulDelay = 0u;
-
- if( listLIST_IS_EMPTY( &pxWindow->xPriorityQueue ) == pdFALSE )
- {
- /* No need to look at retransmissions or new transmission as long as
- there are priority segments. *pulDelay equals zero, meaning it must
- be sent out immediately. */
- xReturn = pdTRUE;
- }
- else
- {
- pxSegment = xTCPWindowPeekHead( &( pxWindow->xWaitQueue ) );
-
- if( pxSegment != NULL )
- {
- /* There is an outstanding segment, see if it is time to resend
- it. */
- ulAge = ulTimerGetAge( &pxSegment->xTransmitTimer );
-
- /* After a packet has been sent for the first time, it will wait
- '1 * lSRTT' ms for an ACK. A second time it will wait '2 * lSRTT' ms,
- each time doubling the time-out */
- ulMaxAge = ( 1u << pxSegment->u.bits.ucTransmitCount ) * ( ( uint32_t ) pxWindow->lSRTT );
-
- if( ulMaxAge > ulAge )
- {
- /* A segment must be sent after this amount of msecs */
- *pulDelay = ulMaxAge - ulAge;
- }
-
- xReturn = pdTRUE;
- }
- else
- {
- /* No priority segment, no outstanding data, see if there is new
- transmission data. */
- pxSegment = xTCPWindowPeekHead( &pxWindow->xTxQueue );
-
- /* See if it fits in the peer's reception window. */
- if( pxSegment == NULL )
- {
- xReturn = pdFALSE;
- }
- else if( prvTCPWindowTxHasSpace( pxWindow, ulWindowSize ) == pdFALSE )
- {
- /* Too many outstanding messages. */
- xReturn = pdFALSE;
- }
- else if( ( pxWindow->u.bits.bSendFullSize != pdFALSE_UNSIGNED ) && ( pxSegment->lDataLength < pxSegment->lMaxLength ) )
- {
- /* 'bSendFullSize' is a special optimisation. If true, the
- driver will only sent completely filled packets (of MSS
- bytes). */
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- uint32_t ulTCPWindowTxGet( TCPWindow_t *pxWindow, uint32_t ulWindowSize, int32_t *plPosition )
- {
- TCPSegment_t *pxSegment;
- uint32_t ulMaxTime;
- uint32_t ulReturn = ~0UL;
-
-
- /* Fetches data to be sent-out now.
-
- Priority messages: segments with a resend need no check current sliding
- window size. */
- pxSegment = xTCPWindowGetHead( &( pxWindow->xPriorityQueue ) );
- pxWindow->ulOurSequenceNumber = pxWindow->tx.ulHighestSequenceNumber;
-
- if( pxSegment == NULL )
- {
- /* Waiting messages: outstanding messages with a running timer
- neither check peer's reception window size because these packets
- have been sent earlier. */
- pxSegment = xTCPWindowPeekHead( &( pxWindow->xWaitQueue ) );
-
- if( pxSegment != NULL )
- {
- /* Do check the timing. */
- ulMaxTime = ( 1u << pxSegment->u.bits.ucTransmitCount ) * ( ( uint32_t ) pxWindow->lSRTT );
-
- if( ulTimerGetAge( &pxSegment->xTransmitTimer ) > ulMaxTime )
- {
- /* A normal (non-fast) retransmission. Move it from the
- head of the waiting queue. */
- pxSegment = xTCPWindowGetHead( &( pxWindow->xWaitQueue ) );
- pxSegment->u.bits.ucDupAckCount = pdFALSE_UNSIGNED;
-
- /* Some detailed logging. */
- if( ( xTCPWindowLoggingLevel != 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != 0 ) )
- {
- FreeRTOS_debug_printf( ( "ulTCPWindowTxGet[%u,%u]: WaitQueue %ld bytes for sequence number %lu (%lX)\n",
- pxWindow->usPeerPortNumber,
- pxWindow->usOurPortNumber,
- pxSegment->lDataLength,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->ulSequenceNumber ) );
- FreeRTOS_flush_logging( );
- }
- }
- else
- {
- pxSegment = NULL;
- }
- }
-
- if( pxSegment == NULL )
- {
- /* New messages: sent-out for the first time. Check current
- sliding window size of peer. */
- pxSegment = xTCPWindowPeekHead( &( pxWindow->xTxQueue ) );
-
- if( pxSegment == NULL )
- {
- /* No segments queued. */
- ulReturn = 0UL;
- }
- else if( ( pxWindow->u.bits.bSendFullSize != pdFALSE_UNSIGNED ) && ( pxSegment->lDataLength < pxSegment->lMaxLength ) )
- {
- /* A segment has been queued but the driver waits until it
- has a full size of MSS. */
- ulReturn = 0;
- }
- else if( prvTCPWindowTxHasSpace( pxWindow, ulWindowSize ) == pdFALSE )
- {
- /* Peer has no more space at this moment. */
- ulReturn = 0;
- }
- else
- {
- /* Move it out of the Tx queue. */
- pxSegment = xTCPWindowGetHead( &( pxWindow->xTxQueue ) );
-
- /* Don't let pxHeadSegment point to this segment any more,
- so no more data will be added. */
- if( pxWindow->pxHeadSegment == pxSegment )
- {
- pxWindow->pxHeadSegment = NULL;
- }
-
- /* pxWindow->tx.highest registers the highest sequence
- number in our transmission window. */
- pxWindow->tx.ulHighestSequenceNumber = pxSegment->ulSequenceNumber + ( ( uint32_t ) pxSegment->lDataLength );
-
- /* ...and more detailed logging */
- if( ( xTCPWindowLoggingLevel >= 2 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "ulTCPWindowTxGet[%u,%u]: XmitQueue %ld bytes for sequence number %lu (ws %lu)\n",
- pxWindow->usPeerPortNumber,
- pxWindow->usOurPortNumber,
- pxSegment->lDataLength,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulWindowSize ) );
- FreeRTOS_flush_logging( );
- }
- }
- }
- }
- else
- {
- /* There is a priority segment. It doesn't need any checking for
- space or timeouts. */
- if( xTCPWindowLoggingLevel != 0 )
- {
- FreeRTOS_debug_printf( ( "ulTCPWindowTxGet[%u,%u]: PrioQueue %ld bytes for sequence number %lu (ws %lu)\n",
- pxWindow->usPeerPortNumber,
- pxWindow->usOurPortNumber,
- pxSegment->lDataLength,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulWindowSize ) );
- FreeRTOS_flush_logging( );
- }
- }
-
- /* See if it has already been determined to return 0. */
- if( ulReturn != 0UL )
- {
- configASSERT( listLIST_ITEM_CONTAINER( &(pxSegment->xQueueItem ) ) == NULL );
-
- /* Now that the segment will be transmitted, add it to the tail of
- the waiting queue. */
- vListInsertFifo( &pxWindow->xWaitQueue, &pxSegment->xQueueItem );
-
- /* And mark it as outstanding. */
- pxSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
-
- /* Administer the transmit count, needed for fast
- retransmissions. */
- ( pxSegment->u.bits.ucTransmitCount )++;
-
- /* If there have been several retransmissions (4), decrease the
- size of the transmission window to at most 2 times MSS. */
- if( pxSegment->u.bits.ucTransmitCount == MAX_TRANSMIT_COUNT_USING_LARGE_WINDOW )
- {
- if( pxWindow->xSize.ulTxWindowLength > ( 2U * pxWindow->usMSS ) )
- {
- FreeRTOS_debug_printf( ( "ulTCPWindowTxGet[%u - %d]: Change Tx window: %lu -> %u\n",
- pxWindow->usPeerPortNumber, pxWindow->usOurPortNumber,
- pxWindow->xSize.ulTxWindowLength, 2 * pxWindow->usMSS ) );
- pxWindow->xSize.ulTxWindowLength = ( 2UL * pxWindow->usMSS );
- }
- }
-
- /* Clear the transmit timer. */
- vTCPTimerSet( &( pxSegment->xTransmitTimer ) );
-
- pxWindow->ulOurSequenceNumber = pxSegment->ulSequenceNumber;
-
- /* Inform the caller where to find the data within the queue. */
- *plPosition = pxSegment->lStreamPos;
-
- /* And return the length of the data segment */
- ulReturn = ( uint32_t ) pxSegment->lDataLength;
- }
-
- return ulReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static uint32_t prvTCPWindowTxCheckAck( TCPWindow_t *pxWindow, uint32_t ulFirst, uint32_t ulLast )
- {
- uint32_t ulBytesConfirmed = 0u;
- uint32_t ulSequenceNumber = ulFirst, ulDataLength;
- const ListItem_t *pxIterator;
- const MiniListItem_t *pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &pxWindow->xTxSegments );
- BaseType_t xDoUnlink;
- TCPSegment_t *pxSegment;
- /* An acknowledgement or a selective ACK (SACK) was received. See if some outstanding data
- may be removed from the transmission queue(s).
- All TX segments for which
- ( ( ulSequenceNumber >= ulFirst ) && ( ulSequenceNumber < ulLast ) in a
- contiguous block. Note that the segments are stored in xTxSegments in a
- strict sequential order. */
-
- /* SRTT[i] = (1-a) * SRTT[i-1] + a * RTT
-
- 0 < a < 1; usually a = 1/8
-
- RTO = 2 * SRTT
-
- where:
- RTT is Round Trip Time
- SRTT is Smoothed RTT
- RTO is Retransmit timeout
-
- A Smoothed RTT will increase quickly, but it is conservative when
- becoming smaller. */
-
- for(
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- ( pxIterator != ( const ListItem_t * ) pxEnd ) && ( xSequenceLessThan( ulSequenceNumber, ulLast ) != 0 );
- )
- {
- xDoUnlink = pdFALSE;
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
-
- /* Move to the next item because the current item might get
- removed. */
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator );
-
- /* Continue if this segment does not fall within the ACK'd range. */
- if( xSequenceGreaterThan( ulSequenceNumber, pxSegment->ulSequenceNumber ) != pdFALSE )
- {
- continue;
- }
-
- /* Is it ready? */
- if( ulSequenceNumber != pxSegment->ulSequenceNumber )
- {
- break;
- }
-
- ulDataLength = ( uint32_t ) pxSegment->lDataLength;
-
- if( pxSegment->u.bits.bAcked == pdFALSE_UNSIGNED )
- {
- if( xSequenceGreaterThan( pxSegment->ulSequenceNumber + ( uint32_t )ulDataLength, ulLast ) != pdFALSE )
- {
- /* What happens? Only part of this segment was accepted,
- probably due to WND limits
-
- AAAAAAA BBBBBBB << acked
- aaaaaaa aaaa << sent */
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- uint32_t ulFirstSeq = pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber;
- FreeRTOS_debug_printf( ( "prvTCPWindowTxCheckAck[%u.%u]: %lu - %lu Partial sequence number %lu - %lu\n",
- pxWindow->usPeerPortNumber,
- pxWindow->usOurPortNumber,
- ulFirstSeq - pxWindow->tx.ulFirstSequenceNumber,
- ulLast - pxWindow->tx.ulFirstSequenceNumber,
- ulFirstSeq, ulFirstSeq + ulDataLength ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
- break;
- }
-
- /* This segment is fully ACK'd, set the flag. */
- pxSegment->u.bits.bAcked = pdTRUE_UNSIGNED;
-
- /* Calculate the RTT only if the segment was sent-out for the
- first time and if this is the last ACK'd segment in a range. */
- if( ( pxSegment->u.bits.ucTransmitCount == 1 ) && ( ( pxSegment->ulSequenceNumber + ulDataLength ) == ulLast ) )
- {
- int32_t mS = ( int32_t ) ulTimerGetAge( &( pxSegment->xTransmitTimer ) );
-
- if( pxWindow->lSRTT >= mS )
- {
- /* RTT becomes smaller: adapt slowly. */
- pxWindow->lSRTT = ( ( winSRTT_DECREMENT_NEW * mS ) + ( winSRTT_DECREMENT_CURRENT * pxWindow->lSRTT ) ) / ( winSRTT_DECREMENT_NEW + winSRTT_DECREMENT_CURRENT );
- }
- else
- {
- /* RTT becomes larger: adapt quicker */
- pxWindow->lSRTT = ( ( winSRTT_INCREMENT_NEW * mS ) + ( winSRTT_INCREMENT_CURRENT * pxWindow->lSRTT ) ) / ( winSRTT_INCREMENT_NEW + winSRTT_INCREMENT_CURRENT );
- }
-
- /* Cap to the minimum of 50ms. */
- if( pxWindow->lSRTT < winSRTT_CAP_mS )
- {
- pxWindow->lSRTT = winSRTT_CAP_mS;
- }
- }
-
- /* Unlink it from the 3 queues, but do not destroy it (yet). */
- xDoUnlink = pdTRUE;
- }
-
- /* pxSegment->u.bits.bAcked is now true. Is it located at the left
- side of the transmission queue? If so, it may be freed. */
- if( ulSequenceNumber == pxWindow->tx.ulCurrentSequenceNumber )
- {
- if( ( xTCPWindowLoggingLevel >= 2 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "prvTCPWindowTxCheckAck: %lu - %lu Ready sequence number %lu\n",
- ulFirst - pxWindow->tx.ulFirstSequenceNumber,
- ulLast - pxWindow->tx.ulFirstSequenceNumber,
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber ) );
- }
-
- /* Increase the left-hand value of the transmission window. */
- pxWindow->tx.ulCurrentSequenceNumber += ulDataLength;
-
- /* This function will return the number of bytes that the tail
- of txStream may be advanced. */
- ulBytesConfirmed += ulDataLength;
-
- /* All segments below tx.ulCurrentSequenceNumber may be freed. */
- vTCPWindowFree( pxSegment );
-
- /* No need to unlink it any more. */
- xDoUnlink = pdFALSE;
- }
-
- if( ( xDoUnlink != pdFALSE ) && ( listLIST_ITEM_CONTAINER( &( pxSegment->xQueueItem ) ) != NULL ) )
- {
- /* Remove item from its queues. */
- uxListRemove( &pxSegment->xQueueItem );
- }
-
- ulSequenceNumber += ulDataLength;
- }
-
- return ulBytesConfirmed;
- }
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- static uint32_t prvTCPWindowFastRetransmit( TCPWindow_t *pxWindow, uint32_t ulFirst )
- {
- const ListItem_t *pxIterator;
- const MiniListItem_t* pxEnd;
- TCPSegment_t *pxSegment;
- uint32_t ulCount = 0UL;
-
- /* A higher Tx block has been acknowledged. Now iterate through the
- xWaitQueue to find a possible condition for a FAST retransmission. */
-
- pxEnd = ( const MiniListItem_t* ) listGET_END_MARKER( &( pxWindow->xWaitQueue ) );
-
- for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd );
- pxIterator != ( const ListItem_t * ) pxEnd; )
- {
- /* Get the owner, which is a TCP segment. */
- pxSegment = ( TCPSegment_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
-
- /* Hop to the next item before the current gets unlinked. */
- pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator );
-
- /* Fast retransmission:
- When 3 packets with a higher sequence number have been acknowledged
- by the peer, it is very unlikely a current packet will ever arrive.
- It will be retransmitted far before the RTO. */
- if( ( pxSegment->u.bits.bAcked == pdFALSE_UNSIGNED ) &&
- ( xSequenceLessThan( pxSegment->ulSequenceNumber, ulFirst ) != pdFALSE ) &&
- ( ++( pxSegment->u.bits.ucDupAckCount ) == DUPLICATE_ACKS_BEFORE_FAST_RETRANSMIT ) )
- {
- pxSegment->u.bits.ucTransmitCount = pdFALSE_UNSIGNED;
-
- /* Not clearing 'ucDupAckCount' yet as more SACK's might come in
- which might lead to a second fast rexmit. */
- if( ( xTCPWindowLoggingLevel >= 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "prvTCPWindowFastRetransmit: Requeue sequence number %lu < %lu\n",
- pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulFirst - pxWindow->tx.ulFirstSequenceNumber ) );
- FreeRTOS_flush_logging( );
- }
-
- /* Remove it from xWaitQueue. */
- uxListRemove( &pxSegment->xQueueItem );
-
- /* Add this segment to the priority queue so it gets
- retransmitted immediately. */
- vListInsertFifo( &( pxWindow->xPriorityQueue ), &( pxSegment->xQueueItem ) );
- ulCount++;
- }
- }
-
- return ulCount;
- }
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- uint32_t ulTCPWindowTxAck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber )
- {
- uint32_t ulFirstSequence, ulReturn;
-
- /* Receive a normal ACK. */
-
- ulFirstSequence = pxWindow->tx.ulCurrentSequenceNumber;
-
- if( xSequenceLessThanOrEqual( ulSequenceNumber, ulFirstSequence ) != pdFALSE )
- {
- ulReturn = 0UL;
- }
- else
- {
- ulReturn = prvTCPWindowTxCheckAck( pxWindow, ulFirstSequence, ulSequenceNumber );
- }
-
- return ulReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 1 )
-
- uint32_t ulTCPWindowTxSack( TCPWindow_t *pxWindow, uint32_t ulFirst, uint32_t ulLast )
- {
- uint32_t ulAckCount = 0UL;
- uint32_t ulCurrentSequenceNumber = pxWindow->tx.ulCurrentSequenceNumber;
-
- /* Receive a SACK option. */
- ulAckCount = prvTCPWindowTxCheckAck( pxWindow, ulFirst, ulLast );
- prvTCPWindowFastRetransmit( pxWindow, ulFirst );
-
- if( ( xTCPWindowLoggingLevel >= 1 ) && ( xSequenceGreaterThan( ulFirst, ulCurrentSequenceNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "ulTCPWindowTxSack[%u,%u]: from %lu to %lu (ack = %lu)\n",
- pxWindow->usPeerPortNumber,
- pxWindow->usOurPortNumber,
- ulFirst - pxWindow->tx.ulFirstSequenceNumber,
- ulLast - pxWindow->tx.ulFirstSequenceNumber,
- pxWindow->tx.ulCurrentSequenceNumber - pxWindow->tx.ulFirstSequenceNumber ) );
- FreeRTOS_flush_logging( );
- }
-
- return ulAckCount;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 1 */
-/*-----------------------------------------------------------*/
-
-/*
-##### # ##### #### ######
-# # # # # # # # # # #
- # # # # # #
- # ### ##### # # # # # #
- # # # # # # # # #####
- # # # # # # #### # # #
- # # # # # # # # # #
- # # # # #### # # # #
- #### ##### # # # #### #### ####
- #
- ###
-*/
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- int32_t lTCPWindowRxCheck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength, uint32_t ulSpace )
- {
- int32_t iReturn;
-
- /* Data was received at 'ulSequenceNumber'. See if it was expected
- and if there is enough space to store the new data. */
- if( ( pxWindow->rx.ulCurrentSequenceNumber != ulSequenceNumber ) || ( ulSpace < ulLength ) )
- {
- iReturn = -1;
- }
- else
- {
- pxWindow->rx.ulCurrentSequenceNumber += ( uint32_t ) ulLength;
- iReturn = 0;
- }
-
- return iReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- int32_t lTCPWindowTxAdd( TCPWindow_t *pxWindow, uint32_t ulLength, int32_t lPosition, int32_t lMax )
- {
- TCPSegment_t *pxSegment = &( pxWindow->xTxSegment );
- int32_t lResult;
-
- /* Data is being scheduled for transmission. */
-
- /* lMax would indicate the size of the txStream. */
- ( void ) lMax;
- /* This is tiny TCP: there is only 1 segment for outgoing data.
- As long as 'lDataLength' is unequal to zero, the segment is still occupied. */
- if( pxSegment->lDataLength > 0 )
- {
- lResult = 0L;
- }
- else
- {
- if( ulLength > ( uint32_t ) pxSegment->lMaxLength )
- {
- if( ( xTCPWindowLoggingLevel != 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: can only store %ld / %ld bytes\n", ulLength, pxSegment->lMaxLength ) );
- }
-
- ulLength = ( uint32_t ) pxSegment->lMaxLength;
- }
-
- if( ( xTCPWindowLoggingLevel != 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: SeqNr %ld (%ld) Len %ld\n",
- pxWindow->ulNextTxSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxWindow->tx.ulCurrentSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulLength ) );
- }
-
- /* The sequence number of the first byte in this packet. */
- pxSegment->ulSequenceNumber = pxWindow->ulNextTxSequenceNumber;
- pxSegment->lDataLength = ( int32_t ) ulLength;
- pxSegment->lStreamPos = lPosition;
- pxSegment->u.ulFlags = 0UL;
- vTCPTimerSet( &( pxSegment->xTransmitTimer ) );
-
- /* Increase the sequence number of the next data to be stored for
- transmission. */
- pxWindow->ulNextTxSequenceNumber += ulLength;
- lResult = ( int32_t )ulLength;
- }
-
- return lResult;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- uint32_t ulTCPWindowTxGet( TCPWindow_t *pxWindow, uint32_t ulWindowSize, int32_t *plPosition )
- {
- TCPSegment_t *pxSegment = &( pxWindow->xTxSegment );
- uint32_t ulLength = ( uint32_t ) pxSegment->lDataLength;
- uint32_t ulMaxTime;
-
- if( ulLength != 0UL )
- {
- /* _HT_ Still under investigation */
- ( void ) ulWindowSize;
-
- if( pxSegment->u.bits.bOutstanding != pdFALSE_UNSIGNED )
- {
- /* As 'ucTransmitCount' has a minimum of 1, take 2 * RTT */
- ulMaxTime = ( ( uint32_t ) 1u << pxSegment->u.bits.ucTransmitCount ) * ( ( uint32_t ) pxWindow->lSRTT );
-
- if( ulTimerGetAge( &( pxSegment->xTransmitTimer ) ) < ulMaxTime )
- {
- ulLength = 0ul;
- }
- }
-
- if( ulLength != 0ul )
- {
- pxSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
- pxSegment->u.bits.ucTransmitCount++;
- vTCPTimerSet (&pxSegment->xTransmitTimer);
- pxWindow->ulOurSequenceNumber = pxSegment->ulSequenceNumber;
- *plPosition = pxSegment->lStreamPos;
- }
- }
-
- return ulLength;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- BaseType_t xTCPWindowTxDone( TCPWindow_t *pxWindow )
- {
- BaseType_t xReturn;
-
- /* Has the outstanding data been sent because user wants to shutdown? */
- if( pxWindow->xTxSegment.lDataLength == 0 )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- static BaseType_t prvTCPWindowTxHasSpace( TCPWindow_t *pxWindow, uint32_t ulWindowSize );
- static BaseType_t prvTCPWindowTxHasSpace( TCPWindow_t *pxWindow, uint32_t ulWindowSize )
- {
- BaseType_t xReturn;
-
- if( ulWindowSize >= pxWindow->usMSSInit )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- BaseType_t xTCPWindowTxHasData( TCPWindow_t *pxWindow, uint32_t ulWindowSize, TickType_t *pulDelay )
- {
- TCPSegment_t *pxSegment = &( pxWindow->xTxSegment );
- BaseType_t xReturn;
- TickType_t ulAge, ulMaxAge;
-
- /* Check data to be sent. */
- *pulDelay = ( TickType_t ) 0;
- if( pxSegment->lDataLength == 0 )
- {
- /* Got nothing to send right now. */
- xReturn = pdFALSE;
- }
- else
- {
- if( pxSegment->u.bits.bOutstanding != pdFALSE_UNSIGNED )
- {
- ulAge = ulTimerGetAge ( &pxSegment->xTransmitTimer );
- ulMaxAge = ( ( TickType_t ) 1u << pxSegment->u.bits.ucTransmitCount ) * ( ( uint32_t ) pxWindow->lSRTT );
-
- if( ulMaxAge > ulAge )
- {
- *pulDelay = ulMaxAge - ulAge;
- }
-
- xReturn = pdTRUE;
- }
- else if( prvTCPWindowTxHasSpace( pxWindow, ulWindowSize ) == pdFALSE )
- {
- /* Too many outstanding messages. */
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- uint32_t ulTCPWindowTxAck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber )
- {
- TCPSegment_t *pxSegment = &( pxWindow->xTxSegment );
- uint32_t ulDataLength = ( uint32_t ) pxSegment->lDataLength;
-
- /* Receive a normal ACK */
-
- if( ulDataLength != 0ul )
- {
- if( ulSequenceNumber < ( pxWindow->tx.ulCurrentSequenceNumber + ulDataLength ) )
- {
- if( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE )
- {
- FreeRTOS_debug_printf( ( "win_tx_ack: acked %ld expc %ld len %ld\n",
- ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- pxWindow->tx.ulCurrentSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulDataLength ) );
- }
-
- /* Nothing to send right now. */
- ulDataLength = 0ul;
- }
- else
- {
- pxWindow->tx.ulCurrentSequenceNumber += ulDataLength;
-
- if( ( xTCPWindowLoggingLevel != 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) != pdFALSE ) )
- {
- FreeRTOS_debug_printf( ( "win_tx_ack: acked seqnr %ld len %ld\n",
- ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber,
- ulDataLength ) );
- }
-
- pxSegment->lDataLength = 0;
- }
- }
-
- return ulDataLength;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- BaseType_t xTCPWindowRxEmpty( TCPWindow_t *pxWindow )
- {
- /* Return true if 'ulCurrentSequenceNumber >= ulHighestSequenceNumber'
- 'ulCurrentSequenceNumber' is the highest sequence number stored,
- 'ulHighestSequenceNumber' is the highest sequence number seen. */
- return xSequenceGreaterThanOrEqual( pxWindow->rx.ulCurrentSequenceNumber, pxWindow->rx.ulHighestSequenceNumber );
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_TCP_WIN == 0 )
-
- /* Destroy a window (always returns NULL) */
- void vTCPWindowDestroy( TCPWindow_t *pxWindow )
- {
- /* As in tiny TCP there are no shared segments descriptors, there is
- nothing to release. */
- ( void ) pxWindow;
- }
-
-#endif /* ipconfigUSE_TCP_WIN == 0 */
-/*-----------------------------------------------------------*/
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
deleted file mode 100755
index f35551d..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_ARP.h"
-#include "FreeRTOS_DHCP.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-
-#if( ipconfigUSE_DNS == 1 )
- #include "FreeRTOS_DNS.h"
-#endif
-
-/* The expected IP version and header length coded into the IP header itself. */
-#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )
-
-/* Part of the Ethernet and IP headers are always constant when sending an IPv4
-UDP packet. This array defines the constant parts, allowing this part of the
-packet to be filled in using a simple memcpy() instead of individual writes. */
-UDPPacketHeader_t xDefaultPartUDPPacketHeader =
-{
- /* .ucBytes : */
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source MAC address. */
- 0x08, 0x00, /* Ethernet frame type. */
- ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
- 0x00, /* ucDifferentiatedServicesCode. */
- 0x00, 0x00, /* usLength. */
- 0x00, 0x00, /* usIdentification. */
- 0x00, 0x00, /* usFragmentOffset. */
- ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
- ipPROTOCOL_UDP, /* ucProtocol. */
- 0x00, 0x00, /* usHeaderChecksum. */
- 0x00, 0x00, 0x00, 0x00 /* Source IP address. */
- }
-};
-/*-----------------------------------------------------------*/
-
-void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-UDPPacket_t *pxUDPPacket;
-IPHeader_t *pxIPHeader;
-eARPLookupResult_t eReturned;
-uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress;
-
- /* Map the UDP packet onto the start of the frame. */
- pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
-
- /* Determine the ARP cache status for the requested IP address. */
- eReturned = eARPGetCacheEntry( &( ulIPAddress ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ) );
-
- if( eReturned != eCantSendPacket )
- {
- if( eReturned == eARPCacheHit )
- {
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
- uint8_t ucSocketOptions;
- #endif
- iptraceSENDING_UDP_PACKET( pxNetworkBuffer->ulIPAddress );
-
- /* Create short cuts to the data within the packet. */
- pxIPHeader = &( pxUDPPacket->xIPHeader );
-
- #if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
- /* Is it possible that the packet is not actually a UDP packet
- after all, but an ICMP packet. */
- if( pxNetworkBuffer->usPort != ipPACKET_CONTAINS_ICMP_DATA )
- #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
- {
- UDPHeader_t *pxUDPHeader;
-
- pxUDPHeader = &( pxUDPPacket->xUDPHeader );
-
- pxUDPHeader->usDestinationPort = pxNetworkBuffer->usPort;
- pxUDPHeader->usSourcePort = pxNetworkBuffer->usBoundPort;
- pxUDPHeader->usLength = ( uint16_t ) ( pxNetworkBuffer->xDataLength + sizeof( UDPHeader_t ) );
- pxUDPHeader->usLength = FreeRTOS_htons( pxUDPHeader->usLength );
- pxUDPHeader->usChecksum = 0u;
- }
-
- /* memcpy() the constant parts of the header information into
- the correct location within the packet. This fills in:
- xEthernetHeader.xSourceAddress
- xEthernetHeader.usFrameType
- xIPHeader.ucVersionHeaderLength
- xIPHeader.ucDifferentiatedServicesCode
- xIPHeader.usLength
- xIPHeader.usIdentification
- xIPHeader.usFragmentOffset
- xIPHeader.ucTimeToLive
- xIPHeader.ucProtocol
- and
- xIPHeader.usHeaderChecksum
- */
- /* Save options now, as they will be overwritten by memcpy */
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
- ucSocketOptions = pxNetworkBuffer->pucEthernetBuffer[ ipSOCKET_OPTIONS_OFFSET ];
- #endif
- /*
- * Offset the memcpy by the size of a MAC address to start at the packet's
- * Ethernet header 'source' MAC address; the preceding 'destination' should not be altered.
- */
- char *pxUdpSrcAddrOffset = ( char *) pxUDPPacket + sizeof( MACAddress_t );
- memcpy( pxUdpSrcAddrOffset, xDefaultPartUDPPacketHeader.ucBytes, sizeof( xDefaultPartUDPPacketHeader ) );
-
- #if ipconfigSUPPORT_OUTGOING_PINGS == 1
- if( pxNetworkBuffer->usPort == ipPACKET_CONTAINS_ICMP_DATA )
- {
- pxIPHeader->ucProtocol = ipPROTOCOL_ICMP;
- pxIPHeader->usLength = ( uint16_t ) ( pxNetworkBuffer->xDataLength + sizeof( IPHeader_t ) );
- }
- else
- #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
- {
- pxIPHeader->usLength = ( uint16_t ) ( pxNetworkBuffer->xDataLength + sizeof( IPHeader_t ) + sizeof( UDPHeader_t ) );
- }
-
- /* The total transmit size adds on the Ethernet header. */
- pxNetworkBuffer->xDataLength = pxIPHeader->usLength + sizeof( EthernetHeader_t );
- pxIPHeader->usLength = FreeRTOS_htons( pxIPHeader->usLength );
- /* HT:endian: changed back to network endian */
- pxIPHeader->ulDestinationIPAddress = pxNetworkBuffer->ulIPAddress;
-
- #if( ipconfigUSE_LLMNR == 1 )
- {
- /* LLMNR messages are typically used on a LAN and they're
- * not supposed to cross routers */
- if( pxNetworkBuffer->ulIPAddress == ipLLMNR_IP_ADDR )
- {
- pxIPHeader->ucTimeToLive = 0x01;
- }
- }
- #endif
-
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
- {
- pxIPHeader->usHeaderChecksum = 0u;
- pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0UL, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
- pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
-
- if( ( ucSocketOptions & ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT ) != 0u )
- {
- usGenerateProtocolChecksum( (uint8_t*)pxUDPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
- }
- else
- {
- pxUDPPacket->xUDPHeader.usChecksum = 0u;
- }
- }
- #endif
- }
- else if( eReturned == eARPCacheMiss )
- {
- /* Add an entry to the ARP table with a null hardware address.
- This allows the ARP timer to know that an ARP reply is
- outstanding, and perform retransmissions if necessary. */
- vARPRefreshCacheEntry( NULL, ulIPAddress );
-
- /* Generate an ARP for the required IP address. */
- iptracePACKET_DROPPED_TO_GENERATE_ARP( pxNetworkBuffer->ulIPAddress );
- pxNetworkBuffer->ulIPAddress = ulIPAddress;
- vARPGenerateRequestPacket( pxNetworkBuffer );
- }
- else
- {
- /* The lookup indicated that an ARP request has already been
- sent out for the queried IP address. */
- eReturned = eCantSendPacket;
- }
- }
-
- if( eReturned != eCantSendPacket )
- {
- /* The network driver is responsible for freeing the network buffer
- after the packet has been sent. */
-
- #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- {
- BaseType_t xIndex;
-
- for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
- {
- pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0u;
- }
- pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
- }
- }
- #endif
-
- xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
- }
- else
- {
- /* The packet can't be sent (DHCP not completed?). Just drop the
- packet. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort )
-{
-BaseType_t xReturn = pdPASS;
-FreeRTOS_Socket_t *pxSocket;
-
-UDPPacket_t *pxUDPPacket = (UDPPacket_t *) pxNetworkBuffer->pucEthernetBuffer;
-
- /* Caller must check for minimum packet size. */
- pxSocket = pxUDPSocketLookup( usPort );
-
- if( pxSocket )
- {
-
- /* When refreshing the ARP cache with received UDP packets we must be
- careful; hundreds of broadcast messages may pass and if we're not
- handling them, no use to fill the ARP cache with those IP addresses. */
- vARPRefreshCacheEntry( &( pxUDPPacket->xEthernetHeader.xSourceAddress ), pxUDPPacket->xIPHeader.ulSourceIPAddress );
-
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- /* Did the owner of this socket register a reception handler ? */
- if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xUDP.pxHandleReceive ) )
- {
- struct freertos_sockaddr xSourceAddress, destinationAddress;
- void *pcData = ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
- FOnUDPReceive_t xHandler = ( FOnUDPReceive_t ) pxSocket->u.xUDP.pxHandleReceive;
- xSourceAddress.sin_port = pxNetworkBuffer->usPort;
- xSourceAddress.sin_addr = pxNetworkBuffer->ulIPAddress;
- destinationAddress.sin_port = usPort;
- destinationAddress.sin_addr = pxUDPPacket->xIPHeader.ulDestinationIPAddress;
-
- if( xHandler( ( Socket_t * ) pxSocket, ( void* ) pcData, ( size_t ) pxNetworkBuffer->xDataLength,
- &xSourceAddress, &destinationAddress ) )
- {
- xReturn = pdFAIL; /* FAIL means that we did not consume or release the buffer */
- }
- }
- }
- #endif /* ipconfigUSE_CALLBACKS */
-
- #if( ipconfigUDP_MAX_RX_PACKETS > 0 )
- {
- if( xReturn == pdPASS )
- {
- if ( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) >= pxSocket->u.xUDP.uxMaxPackets )
- {
- FreeRTOS_debug_printf( ( "xProcessReceivedUDPPacket: buffer full %ld >= %ld port %u\n",
- listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ),
- pxSocket->u.xUDP.uxMaxPackets, pxSocket->usLocalPort ) );
- xReturn = pdFAIL; /* we did not consume or release the buffer */
- }
- }
- }
- #endif
-
- if( xReturn == pdPASS )
- {
- vTaskSuspendAll();
- {
- if( xReturn == pdPASS )
- {
- taskENTER_CRITICAL();
- {
- /* Add the network packet to the list of packets to be
- processed by the socket. */
- vListInsertEnd( &( pxSocket->u.xUDP.xWaitingPacketsList ), &( pxNetworkBuffer->xBufferListItem ) );
- }
- taskEXIT_CRITICAL();
- }
- }
- xTaskResumeAll();
-
- /* Set the socket's receive event */
- if( pxSocket->xEventGroup != NULL )
- {
- xEventGroupSetBits( pxSocket->xEventGroup, eSOCKET_RECEIVE );
- }
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- {
- if( ( pxSocket->pxSocketSet != NULL ) && ( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 ) )
- {
- xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, eSELECT_READ );
- }
- }
- #endif
-
- #if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
- {
- if( pxSocket->pxUserSemaphore != NULL )
- {
- xSemaphoreGive( pxSocket->pxUserSemaphore );
- }
- }
- #endif
-
- #if( ipconfigUSE_DHCP == 1 )
- {
- if( xIsDHCPSocket( pxSocket ) )
- {
- xSendEventToIPTask( eDHCPEvent );
- }
- }
- #endif
- }
- }
- else
- {
- /* There is no socket listening to the target port, but still it might
- be for this node. */
-
- #if( ipconfigUSE_LLMNR == 1 )
- /* a LLMNR request, check for the destination port. */
- if( ( usPort == FreeRTOS_ntohs( ipLLMNR_PORT ) ) ||
- ( pxUDPPacket->xUDPHeader.usSourcePort == FreeRTOS_ntohs( ipLLMNR_PORT ) ) )
- {
- vARPRefreshCacheEntry( &( pxUDPPacket->xEthernetHeader.xSourceAddress ), pxUDPPacket->xIPHeader.ulSourceIPAddress );
- xReturn = ( BaseType_t )ulDNSHandlePacket( pxNetworkBuffer );
- }
- else
- #endif /* ipconfigUSE_LLMNR */
-
- #if( ipconfigUSE_NBNS == 1 )
- /* a NetBIOS request, check for the destination port */
- if( ( usPort == FreeRTOS_ntohs( ipNBNS_PORT ) ) ||
- ( pxUDPPacket->xUDPHeader.usSourcePort == FreeRTOS_ntohs( ipNBNS_PORT ) ) )
- {
- vARPRefreshCacheEntry( &( pxUDPPacket->xEthernetHeader.xSourceAddress ), pxUDPPacket->xIPHeader.ulSourceIPAddress );
- xReturn = ( BaseType_t )ulNBNSHandlePacket( pxNetworkBuffer );
- }
- else
- #endif /* ipconfigUSE_NBNS */
- {
- xReturn = pdFAIL;
- }
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt
deleted file mode 100755
index ec66f0b..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt
+++ /dev/null
@@ -1,187 +0,0 @@
-Changes between 160919 and 180821 releases:
-
- + Multiple security improvements and fixes in packet parsing routines, DNS
- caching, and TCP sequence number and ID generation.
- + Disable NBNS and LLMNR by default.
- + Add TCP hang protection by default.
-
- We thank Ori Karliner of Zimperium zLabs Team for reporting these issues.
-
- + Update FreeRTOS_gethostbyname() to allow an IP address to be passed in -
- in which case it is just returned as a uint32_t.
- + Introduce ipconfigSOCKET_HAS_USER_WAKE_CALLBACK to FreeRTOS_Sockets.c to
- allow a user supposed callback function to be executed when socket events
- occur in the same way that the socket semaphore is currently used.
- + Update xNetworkBuffersInitialise() to ensure the semaphore created by the
- function is not accessed until after the NULL check.
- + Improve print messages output by the Win32 port layer version of
- prvPrintAvailableNetworkInterfaces().
-
-Changes between 160908 and 160919 releases:
-
- + Add a NULL check before attempting to close the DHCP socket. [Prior to
- 160823 the IP task closed the DHCP socket by calling a public API function
- - which checked for the socket being NULL. This was changed to call a
- local private function, which did not have a NULL check, in place of the
- public API function.]
- + Various [internal only] naming changes to better comply with the FreeRTOS
- naming conventions.
- + Improvements to the Zynq network driver. DMA transmission buffers now use
- a counting semaphore. When all TX-buffers are in-use, the IP-task will
- block momentarily until a TX-buffer becomes available.
- + Experimental implementation of the TCP window scaling protocol. The
- scaling option will always be offered, at least with a factor 1. If the
- TCP sliding window size becomes more than 64KB, the factor will increase
- automatically.
- + ipconfigETHERNET_MINIMUM_PACKET_BYTES is now applied for every protocol:
- TCP, UDP, and ARP.
- + Updated the Zynq project to use BufferAllocation_1.c rather than
- BufferAllocation_2.c - which is a requirement with its current
- configuration (due to the alignment requirements on the combined cache and
- DMA configuration).
-
-Changes between 160823 and 160908 releases:
-
- + Use ipconfigZERO_COPY_TX_DRIVER as the xReleaseAfterSend() parameter where
- prvTCPReturnPacket() is called in prvSendData() to prevent unnecessary
- copying of data.
- + Remove the use of the uxGetRxEventCount variable, which was used to give
- priority to incoming messages, but could result in the IP task starving
- application tasks of processing time.
-
-Changes between 160112 and 160823 releases
-
- NOTE: The 160908 release is a maintenance release for the 160112 single
- interface labs release - not a release of the current development branch.
-
- + Various minor stability enhancements, including the ability to work with
- configTICK_RATE_HZ set to less than 1KHz, closing DHCP sockets directly
- rather than via FreeRTOS_closesocket(), and better handling of unknown
- TCP packets before an IP address has been assigned.
- + ipBUFFER_PADDING is now configurable through the ipconfigBUFFER_PADDING
- constant to improve network buffer alignment handling capabilities (expert
- users/driver writers only).
- + Multiple improvements to the FTP server, including to how read only and
- zero length files are handled.
- + ipconfigFTP_HAS_USER_PROPERTIES_HOOK (to allow each user to have a
- different root directory and access rights) and
- ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK (to handle AJAX style data)
- introduced, although these are not yet fully tested and the constant names
- are likely to change.
- + Introduce ipconfigHAS_TX_CRC_OFFLOADING.
- + ipconfigUSE_DHCP_HOOK is now called ipconfigUSE_DHCP_HOOK, and the name
- of the callback function has also changed. See the web documentation for
- details.
- + ipconfigTCP_RX_BUF_LEN is now ipconfigTCP_RX_BUFFER_LENGTH, and
- ipconfigTCP_TX_BUF_LEN is now ipconfigTCP_TX_BUFFER_LENGTH, which is
- actually how they have always been documented.
- + Added example TFTP server capable of receiving (not sending) files.
- Intended for bootloader type functionality.
- + Various variable name changes for consistency (mainly ensuring UDP, TCP,
- DNS, etc. always use the same case letters, and type prefixes are correct).
- + Various minor edits to improve types used by internal variables.
- + Simplified mapping of standard library functions to their Visual Studio
- equivalents.
- + Improve robustness of network drivers.
- + Introduce pxResizeNetworkBufferWithDescriptor().
- + Removed obsolete FreeRTOSIPConfig.h constants from
- FreeRTOSIPConfigDefaults.h.
- + Added additional asserts() - predominantly to catch incorrect structure
- packing.
-
-Changes between 160112 and 160111 releases
-
- + Updated the STM32 network driver so checksums are calculated by the
- hardware.
- + Implemented a simple "quit" command in the TCP command console.
-
-Changes between 150825 and 160111 releases
-
- + New device support: Demo applications and example drivers are provided
- for Atmel SAM4E and ST STM32F4 microcontrollers.
- + Various updates to improve compliance with the FreeRTOS coding standard.
- + Added a command console example that uses TCP/IP for input and output (the
- pre-existing command console example uses UDP/IP).
- + Updated the UDP logging example so it will send log messages to the local
- UDP broadcast address if a specific IP address is not provided. This
- simplifies configuration, but note not all switches and routers will pass
- broadcast messages.
- + Add TCP echo client and TCP echo server examples to the Zynq demo.
- + Minor updates to the Zynq network driver.
- + Update the Zynq project to use version 2015.4 of the Xilinx SDK.
- + Introduce FreeRTOS_SignalSocket(), which can be used to interrupt a task
- that is blocked while reading from a socket ( FreeRTOS_recv[from] ).
- + Make use of FreeRTOS_SignalSocket() in the FTP and HTTP servers.
- + Major updates to the NTP client, although this is not included in any of
- the pre-configured demo applications yet.
- + Added support for DHCP zero pad option.
- + Added uxGetMinimumIPQueueSpace(), a function to monitor the minimum amount
- of space on the message queue.
- + Better handling of zero length files in the FTP server.
- + Fixed a bug reported by Andrey Ivanov from swissEmbedded that affects
- users of 'ipconfigZERO_COPY_TX_DRIVER'.
-
-
-Changes between 150825 150825 (?)
-
- + Added xApplicationDHCPUserHook() so a user defined hook will be
- called at certain points in the DHCP process if
- ipconfigDHCP_USES_USER_HOOK is set to 1.
- + Added FreeRTOS_get_tx_head() to improve TCP zero copy behaviour - for
- expert use only.
- + RST is no longer sent if only the ACK flag is set.
- + Previously, an immediate ACK was only sent when buffer space was
- exhausted. Now, to improve performance, it is possible to send an
- immediate ACK earlier - dependent on the ipconfigTCP_ACK_EARLIER_PACKET
- setting.
- + LLMNR and NBNS requests can now be sent to locate other devices -
- previously these protocols would only be replied to, not generated.
- + Added Auto-IP functionality (still in test) in case DHCP fails. Dependent
- on the ipconfigDHCP_FALL_BACK_LINK_LAYER_ADDRESS and
- ipconfigARP_USE_CLASH_DETECTION settings.
- + Added NTP code and demo.
- + FTP can now STOR and RETR zero-length files.
- + Added LLMNR demo to Win32 demo - so now the Win32 responds to
- "ping RTOSDemo".
-
-Changes between 141019 and 150825
-
- + Added FTP server, which uses the new FreeRTOS+FAT component.
- + Added basic HTTP server, which uses the new FreeRTOS+FAT component.
- + Multiple definitions that are now common with FreeRTOS+FAT have been moved
- into FreeRTOS's ProjDefs.h header file, and so prefixed with 'pd'.
- + Introduced ipconfigZERO_COPY_TX_DRIVER, which defines who is responsible
- for freeing a buffer sent to to the MAC driver for transmission, and
- facilitates the development of zero copy drivers.
- + Introduced the FREERTOS_MSG_DONTWAIT flag. The flag can be used as a
- simpler and faster alternative to using FreeRTOS_setsockopt() to set the
- send or receive timeout to 0.
- + A few functions that were previously all lower case are now mixed case, as
- lower case function names are only used when they are equivalent to a
- a Berkeley sockets API function of the same name.
- + Introduced uxGetMinimumFreeNetworkBuffers() to return the minimum number
- of network buffers that have ever existed since the application started
- executing.
- + Introduce ipconfigETHERNET_MINIMUM_PACKET_BYTES to allow the application
- writer to set their own minimum buffer size should the hardware not be
- capable of padding under-sized Ethernet frames.
- + vNetworkBufferRelease() renamed vReleaseNetworkBuffer() - just for
- consistency with the names of other functions in the same file.
- + Grouped DHCP status data into a structure.
- + DHCP is now tried both with and without the broadcast flag.
- + Replaced occurrences of configASSERT_VOID() with configASSERT().
- + ipconfigDNS_USE_CALLBACKS introduced to allow FreeRTOS_gethostbyname() to
- be used without blocking.
- + Fix: LLMNR and NBNS behaviour when the reply is in a larger buffer than the
- request, and BufferAllocation_2 was used.
- + Introduced ipMAX_IP_TASK_SLEEP_TIME to allow the application writer to
- override the default value of 10 seconds.
- + Fix: Correct error in *pxUDPPayloadBuffer_to_NetworkBuffer().
- + FreeRTOS_recv() now recognises the FREERTOS_ZERO_COPY flag, which, when
- set, the void *pvBuffer parameter is interpreted as void **pvBuffer.
- + FreeRTOS_listen() now returns an error code. Previously it always
- returned 0.
- + Fix: Previously if a listening socket was reused, and a connection
- failed, the TCP/IP stack closed the socket, now the socket is correctly
- left unclosed as it is owned by the application.
- + Various other formatting and minor fix alterations.
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/LICENSE_INFORMATION.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/LICENSE_INFORMATION.txt
deleted file mode 100755
index 04dc563..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/LICENSE_INFORMATION.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-FreeRTOS+TCP is released under the following MIT license.
-
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/ReadMe.url b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/ReadMe.url
deleted file mode 100755
index 4174076..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/ReadMe.url
+++ /dev/null
@@ -1,5 +0,0 @@
-[{000214A0-0000-0000-C000-000000000046}]
-Prop3=19,2
-[InternetShortcut]
-URL=http://www.freertos.org/tcp
-IDList=
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h
deleted file mode 100755
index f75efaa..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h
+++ /dev/null
@@ -1,560 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-#ifndef FREERTOS_DEFAULT_IP_CONFIG_H
-#define FREERTOS_DEFAULT_IP_CONFIG_H
-
-/* The error numbers defined in this file will be moved to the core FreeRTOS
-code in future versions of FreeRTOS - at which time the following header file
-will be removed. */
-#include "FreeRTOS_errno_TCP.h"
-
-/* This file provides default values for configuration options that are missing
-from the FreeRTOSIPConfig.h configuration header file. */
-
-
-/* Ensure defined configuration constants are using the most up to date naming. */
-#ifdef tcpconfigIP_TIME_TO_LIVE
- #error now called: ipconfigTCP_TIME_TO_LIVE
-#endif
-
-#ifdef updconfigIP_TIME_TO_LIVE
- #error now called: ipconfigUDP_TIME_TO_LIVE
-#endif
-
-#ifdef ipFILLER_SIZE
- #error now called: ipconfigPACKET_FILLER_SIZE
-#endif
-
-#ifdef dnsMAX_REQUEST_ATTEMPTS
- #error now called: ipconfigDNS_REQUEST_ATTEMPTS
-#endif
-
-#ifdef ipconfigUDP_TASK_PRIORITY
- #error now called: ipconfigIP_TASK_PRIORITY
-#endif
-
-#ifdef ipconfigUDP_TASK_STACK_SIZE_WORDS
- #error now called: ipconfigIP_TASK_STACK_SIZE_WORDS
-#endif
-
-#ifdef ipconfigDRIVER_INCLUDED_RX_IP_FILTERING
- #error now called: ipconfigETHERNET_DRIVER_FILTERS_PACKETS
-#endif
-
-#ifdef ipconfigMAX_SEND_BLOCK_TIME_TICKS
- #error now called: ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS
-#endif
-
-#ifdef ipconfigUSE_RECEIVE_CONNECT_CALLBACKS
- #error now called: ipconfigUSE_CALLBACKS
-#endif
-
-#ifdef ipconfigNUM_NETWORK_BUFFERS
- #error now called: ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS
-#endif
-
-#ifdef ipconfigTCP_HANG_PROT
- #error now called: ipconfigTCP_HANG_PROTECTION
-#endif
-
-#ifdef ipconfigTCP_HANG_PROT_TIME
- #error now called: ipconfigTCP_HANG_PROTECTION_TIME
-#endif
-
-#ifdef FreeRTOS_lprintf
- #error now called: FreeRTOS_debug_printf
-#endif
-
-#if ( ipconfigEVENT_QUEUE_LENGTH < ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 ) )
- #error The ipconfigEVENT_QUEUE_LENGTH parameter must be at least ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5
-#endif
-
-#if ( ipconfigNETWORK_MTU < 46 )
- #error ipconfigNETWORK_MTU must be at least 46.
-#endif
-
-#ifdef ipconfigBUFFER_ALLOC_FIXED_SIZE
- #error ipconfigBUFFER_ALLOC_FIXED_SIZE was dropped and replaced by a const value, declared in BufferAllocation[12].c
-#endif
-
-#ifdef ipconfigNIC_SEND_PASSES_DMA
- #error now called: ipconfigZERO_COPY_TX_DRIVER
-#endif
-
-#ifdef HAS_TX_CRC_OFFLOADING
- /* _HT_ As these macro names have changed, throw an error
- if they're still defined. */
- #error now called: ipconfigHAS_TX_CRC_OFFLOADING
-#endif
-
-#ifdef HAS_RX_CRC_OFFLOADING
- #error now called: ipconfigHAS_RX_CRC_OFFLOADING
-#endif
-
-#ifdef ipconfigTCP_RX_BUF_LEN
- #error ipconfigTCP_RX_BUF_LEN is now called ipconfigTCP_RX_BUFFER_LENGTH
-#endif
-
-#ifdef ipconfigTCP_TX_BUF_LEN
- #error ipconfigTCP_TX_BUF_LEN is now called ipconfigTCP_TX_BUFFER_LENGTH
-#endif
-
-#ifdef ipconfigDHCP_USES_USER_HOOK
- #error ipconfigDHCP_USES_USER_HOOK and its associated callback have been superceeded - see http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK
-#endif
-
-#ifndef ipconfigUSE_TCP
- #define ipconfigUSE_TCP ( 1 )
-#endif
-
-#if ipconfigUSE_TCP
-
- /* Include support for TCP scaling windows */
- #ifndef ipconfigUSE_TCP_WIN
- #define ipconfigUSE_TCP_WIN ( 1 )
- #endif
-
- #ifndef ipconfigTCP_WIN_SEG_COUNT
- #define ipconfigTCP_WIN_SEG_COUNT ( 256 )
- #endif
-
- #ifndef ipconfigIGNORE_UNKNOWN_PACKETS
- /* When non-zero, TCP will not send RST packets in reply to
- TCP packets which are unknown, or out-of-order. */
- #define ipconfigIGNORE_UNKNOWN_PACKETS ( 0 )
- #endif
-#endif
-
-/*
- * For debuging/logging: check if the port number is used for telnet
- * Some events will not be logged for telnet connections
- * because it would produce logging about the transmission of the logging...
- * This macro will only be used if FreeRTOS_debug_printf() is defined for logging
- */
-#ifndef ipconfigTCP_MAY_LOG_PORT
- #define ipconfigTCP_MAY_LOG_PORT(xPort) ( ( xPort ) != 23u )
-#endif
-
-
-#ifndef ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME
- #define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME portMAX_DELAY
-#endif
-
-#ifndef ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME
- #define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME portMAX_DELAY
-#endif
-
-/*
- * FreeRTOS debug logging routine (proposal)
- * The macro will be called in the printf() style. Users can define
- * their own logging routine as:
- *
- * #define FreeRTOS_debug_printf( MSG ) my_printf MSG
- *
- * The FreeRTOS_debug_printf() must be thread-safe but does not have to be
- * interrupt-safe.
- */
-#ifdef ipconfigHAS_DEBUG_PRINTF
- #if( ipconfigHAS_DEBUG_PRINTF == 0 )
- #ifdef FreeRTOS_debug_printf
- #error Do not define FreeRTOS_debug_print if ipconfigHAS_DEBUG_PRINTF is set to 0
- #endif /* ifdef FreeRTOS_debug_printf */
- #endif /* ( ipconfigHAS_DEBUG_PRINTF == 0 ) */
-#endif /* ifdef ipconfigHAS_DEBUG_PRINTF */
-
-#ifndef FreeRTOS_debug_printf
- #define FreeRTOS_debug_printf( MSG ) do{} while(0)
- #define ipconfigHAS_DEBUG_PRINTF 0
-#endif
-
-/*
- * FreeRTOS general logging routine (proposal)
- * Used in some utility functions such as FreeRTOS_netstat() and FreeRTOS_PrintARPCache()
- *
- * #define FreeRTOS_printf( MSG ) my_printf MSG
- *
- * The FreeRTOS_printf() must be thread-safe but does not have to be interrupt-safe
- */
-#ifdef ipconfigHAS_PRINTF
- #if( ipconfigHAS_PRINTF == 0 )
- #ifdef FreeRTOS_printf
- #error Do not define FreeRTOS_print if ipconfigHAS_PRINTF is set to 0
- #endif /* ifdef FreeRTOS_debug_printf */
- #endif /* ( ipconfigHAS_PRINTF == 0 ) */
-#endif /* ifdef ipconfigHAS_PRINTF */
-
-#ifndef FreeRTOS_printf
- #define FreeRTOS_printf( MSG ) do{} while(0)
- #define ipconfigHAS_PRINTF 0
-#endif
-
-/*
- * In cases where a lot of logging is produced, FreeRTOS_flush_logging( )
- * will be called to give the logging module a chance to flush the data
- * An example of this is the netstat command, which produces many lines of logging
- */
-#ifndef FreeRTOS_flush_logging
- #define FreeRTOS_flush_logging( ) do{} while(0)
-#endif
-
-/* Malloc functions. Within most applications of FreeRTOS, the couple
- * pvPortMalloc()/vPortFree() will be used.
- * If there is also SDRAM, the user may decide to use a different memory
- * allocator:
- * MallocLarge is used to allocate large TCP buffers (for Rx/Tx)
- * MallocSocket is used to allocate the space for the sockets
- */
-#ifndef pvPortMallocLarge
- #define pvPortMallocLarge( x ) pvPortMalloc( x )
-#endif
-
-#ifndef vPortFreeLarge
- #define vPortFreeLarge(ptr) vPortFree(ptr)
-#endif
-
-#ifndef pvPortMallocSocket
- #define pvPortMallocSocket( x ) pvPortMalloc( x )
-#endif
-
-#ifndef vPortFreeSocket
- #define vPortFreeSocket(ptr) vPortFree(ptr)
-#endif
-
-/*
- * At several places within the library, random numbers are needed:
- * - DHCP: For creating a DHCP transaction number
- * - TCP: Set the Initial Sequence Number: this is the value of the first outgoing
- * sequence number being used when connecting to a peer.
- * Having a well randomised ISN is important to avoid spoofing
- * - UDP/TCP: for setting the first port number to be used, in case a socket
- * uses a 'random' or anonymous port number
- */
-#ifndef ipconfigRAND32
- #define ipconfigRAND32() rand()
-#endif
-/* --------------------------------------------------------
- * End of: HT Added some macro defaults for the PLUS-UDP project
- * -------------------------------------------------------- */
-
-#ifndef ipconfigUSE_NETWORK_EVENT_HOOK
- #define ipconfigUSE_NETWORK_EVENT_HOOK 0
-#endif
-
-#ifndef ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS
- #define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( pdMS_TO_TICKS( 20 ) )
-#endif
-
-#ifndef ipconfigARP_CACHE_ENTRIES
- #define ipconfigARP_CACHE_ENTRIES 10
-#endif
-
-#ifndef ipconfigMAX_ARP_RETRANSMISSIONS
- #define ipconfigMAX_ARP_RETRANSMISSIONS ( 5u )
-#endif
-
-#ifndef ipconfigMAX_ARP_AGE
- #define ipconfigMAX_ARP_AGE 150u
-#endif
-
-#ifndef ipconfigUSE_ARP_REVERSED_LOOKUP
- #define ipconfigUSE_ARP_REVERSED_LOOKUP 0
-#endif
-
-#ifndef ipconfigUSE_ARP_REMOVE_ENTRY
- #define ipconfigUSE_ARP_REMOVE_ENTRY 0
-#endif
-
-#ifndef ipconfigINCLUDE_FULL_INET_ADDR
- #define ipconfigINCLUDE_FULL_INET_ADDR 1
-#endif
-
-#ifndef ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS
- #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 45
-#endif
-
-#ifndef ipconfigEVENT_QUEUE_LENGTH
- #define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
-#endif
-
-#ifndef ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND
- #define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
-#endif
-
-#ifndef ipconfigUDP_TIME_TO_LIVE
- #define ipconfigUDP_TIME_TO_LIVE 128
-#endif
-
-#ifndef ipconfigTCP_TIME_TO_LIVE
- #define ipconfigTCP_TIME_TO_LIVE 128
-#endif
-
-#ifndef ipconfigUDP_MAX_RX_PACKETS
- /* Make postive to define the maximum number of packets which will be buffered
- * for each UDP socket.
- * Can be overridden with the socket option FREERTOS_SO_UDP_MAX_RX_PACKETS
- */
- #define ipconfigUDP_MAX_RX_PACKETS 0u
-#endif
-
-#ifndef ipconfigUSE_DHCP
- #define ipconfigUSE_DHCP 1
-#endif
-
-#ifndef ipconfigUSE_DHCP_HOOK
- #define ipconfigUSE_DHCP_HOOK 0
-#endif
-
-#ifndef ipconfigDHCP_FALL_BACK_AUTO_IP
- /*
- * Only applicable when DHCP is in use:
- * If no DHCP server responds, use "Auto-IP" : the
- * device will allocate a random LinkLayer IP address.
- */
- #define ipconfigDHCP_FALL_BACK_AUTO_IP ( 0 )
-#endif
-
-#if( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
- #define ipconfigARP_USE_CLASH_DETECTION 1
-#endif
-
-#ifndef ipconfigARP_USE_CLASH_DETECTION
- #define ipconfigARP_USE_CLASH_DETECTION 0
-#endif
-
-#ifndef ipconfigNETWORK_MTU
- #define ipconfigNETWORK_MTU 1500
-#endif
-
-#ifndef ipconfigTCP_MSS
- #define ipconfigTCP_MSS ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER - ipSIZE_OF_TCP_HEADER )
-#endif
-
-/* Each TCP socket has circular stream buffers for Rx and Tx, which
- * have a fixed maximum size.
- * The defaults for these size are defined here, although
- * they can be overridden at runtime by using the setsockopt() call */
-#ifndef ipconfigTCP_RX_BUFFER_LENGTH
- #define ipconfigTCP_RX_BUFFER_LENGTH ( 4u * ipconfigTCP_MSS ) /* defaults to 5840 bytes */
-#endif
-
-/* Define the size of Tx stream buffer for TCP sockets */
-#ifndef ipconfigTCP_TX_BUFFER_LENGTH
-# define ipconfigTCP_TX_BUFFER_LENGTH ( 4u * ipconfigTCP_MSS ) /* defaults to 5840 bytes */
-#endif
-
-#ifndef ipconfigMAXIMUM_DISCOVER_TX_PERIOD
- #ifdef _WINDOWS_
- #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( pdMS_TO_TICKS( 999 ) )
- #else
- #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( pdMS_TO_TICKS( 30000 ) )
- #endif /* _WINDOWS_ */
-#endif /* ipconfigMAXIMUM_DISCOVER_TX_PERIOD */
-
-#ifndef ipconfigUSE_DNS
- #define ipconfigUSE_DNS 1
-#endif
-
-#ifndef ipconfigDNS_REQUEST_ATTEMPTS
- #define ipconfigDNS_REQUEST_ATTEMPTS 5
-#endif
-
-#ifndef ipconfigUSE_DNS_CACHE
- #define ipconfigUSE_DNS_CACHE 0
-#endif
-
-#if( ipconfigUSE_DNS_CACHE != 0 )
- #ifndef ipconfigDNS_CACHE_NAME_LENGTH
- /* Per https://tools.ietf.org/html/rfc1035, 253 is the maximum string length
- of a DNS name. The following default accounts for a null terminator. */
- #define ipconfigDNS_CACHE_NAME_LENGTH 254
- #endif
-
- #ifndef ipconfigDNS_CACHE_ENTRIES
- #define ipconfigDNS_CACHE_ENTRIES 1
- #endif
-#endif /* ipconfigUSE_DNS_CACHE != 0 */
-
-#ifndef ipconfigCHECK_IP_QUEUE_SPACE
- #define ipconfigCHECK_IP_QUEUE_SPACE 0
-#endif
-
-#ifndef ipconfigUSE_LLMNR
- /* Include support for LLMNR: Link-local Multicast Name Resolution (non-Microsoft) */
- #define ipconfigUSE_LLMNR ( 0 )
-#endif
-
-#if( !defined( ipconfigUSE_DNS ) )
- #if( ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) )
- /* LLMNR and NBNS depend on DNS because those protocols share a lot of code. */
- #error When either LLMNR or NBNS is used, ipconfigUSE_DNS must be defined
- #endif
-#endif
-
-#ifndef ipconfigREPLY_TO_INCOMING_PINGS
- #define ipconfigREPLY_TO_INCOMING_PINGS 1
-#endif
-
-#ifndef ipconfigSUPPORT_OUTGOING_PINGS
- #define ipconfigSUPPORT_OUTGOING_PINGS 0
-#endif
-
-#ifndef ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES
- #define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
-#endif
-
-#ifndef ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES
- #define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
-#endif
-
-#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
- #define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS 0
-#else
- #define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS configINCLUDE_TRACE_RELATED_CLI_COMMANDS
-#endif
-
-#ifndef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM
- #define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM ( 0 )
-#endif
-
-#ifndef ipconfigETHERNET_DRIVER_FILTERS_PACKETS
- #define ipconfigETHERNET_DRIVER_FILTERS_PACKETS ( 0 )
-#endif
-
-#ifndef ipconfigWATCHDOG_TIMER
- /* This macro will be called in every loop the IP-task makes. It may be
- replaced by user-code that triggers a watchdog */
- #define ipconfigWATCHDOG_TIMER()
-#endif
-
-#ifndef ipconfigUSE_CALLBACKS
- #define ipconfigUSE_CALLBACKS ( 0 )
-#endif
-
-#if( ipconfigUSE_CALLBACKS != 0 )
- #ifndef ipconfigIS_VALID_PROG_ADDRESS
- /* Replace this macro with a test returning non-zero if the memory pointer to by x
- * is valid memory which can contain executable code
- * In fact this is an extra safety measure: if a handler points to invalid memory,
- * it will not be called
- */
- #define ipconfigIS_VALID_PROG_ADDRESS(x) ( ( x ) != NULL )
- #endif
-#endif
-
-#ifndef ipconfigHAS_INLINE_FUNCTIONS
- #define ipconfigHAS_INLINE_FUNCTIONS ( 1 )
-#endif
-
-#ifndef portINLINE
- #define portINLINE inline
-#endif
-
-#ifndef ipconfigZERO_COPY_TX_DRIVER
- /* When non-zero, the buffers passed to the SEND routine may be passed
- to DMA. As soon as sending is ready, the buffers must be released by
- calling vReleaseNetworkBufferAndDescriptor(), */
- #define ipconfigZERO_COPY_TX_DRIVER ( 0 )
-#endif
-
-#ifndef ipconfigZERO_COPY_RX_DRIVER
- /* This define doesn't mean much to the driver, except that it makes
- sure that pxPacketBuffer_to_NetworkBuffer() will be included. */
- #define ipconfigZERO_COPY_RX_DRIVER ( 0 )
-#endif
-
-#ifndef ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM
- #define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0
-#endif
-
-#ifndef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM
- #define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
-#endif
-
-#ifndef ipconfigDHCP_REGISTER_HOSTNAME
- #define ipconfigDHCP_REGISTER_HOSTNAME 0
-#endif
-
-#ifndef ipconfigSOCKET_HAS_USER_SEMAPHORE
- #define ipconfigSOCKET_HAS_USER_SEMAPHORE 0
-#endif
-
-#ifndef ipconfigSOCKET_HAS_USER_WAKE_CALLBACK
- #define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK 0
-#endif
-
-#ifndef ipconfigSUPPORT_SELECT_FUNCTION
- #define ipconfigSUPPORT_SELECT_FUNCTION 0
-#endif
-
-#ifndef ipconfigTCP_KEEP_ALIVE
- #define ipconfigTCP_KEEP_ALIVE 0
-#endif
-
-#ifndef ipconfigDNS_USE_CALLBACKS
- #define ipconfigDNS_USE_CALLBACKS 0
-#endif
-
-#ifndef ipconfigSUPPORT_SIGNALS
- #define ipconfigSUPPORT_SIGNALS 0
-#endif
-
-#ifndef ipconfigUSE_NBNS
- #define ipconfigUSE_NBNS 0
-#endif
-
-/* As an attack surface reduction for ports that listen for inbound
-connections, hang protection can help reduce the impact of SYN floods. */
-#ifndef ipconfigTCP_HANG_PROTECTION
- #define ipconfigTCP_HANG_PROTECTION 1
-#endif
-
-/* Non-activity timeout is expressed in seconds. */
-#ifndef ipconfigTCP_HANG_PROTECTION_TIME
- #define ipconfigTCP_HANG_PROTECTION_TIME 30
-#endif
-
-#ifndef ipconfigTCP_IP_SANITY
- #define ipconfigTCP_IP_SANITY 0
-#endif
-
-#ifndef ipconfigARP_STORES_REMOTE_ADDRESSES
- #define ipconfigARP_STORES_REMOTE_ADDRESSES 0
-#endif
-
-#ifndef ipconfigBUFFER_PADDING
- /* Expert option: define a value for 'ipBUFFER_PADDING'.
- When 'ipconfigBUFFER_PADDING' equals 0,
- 'ipBUFFER_PADDING' will get a default value of 8 + 2 bytes. */
- #define ipconfigBUFFER_PADDING 0
-#endif
-
-#ifndef ipconfigPACKET_FILLER_SIZE
- #define ipconfigPACKET_FILLER_SIZE 2
-#endif
-
-#endif /* FREERTOS_DEFAULT_IP_CONFIG_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h
deleted file mode 100755
index 94d1cba..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_ARP_H
-#define FREERTOS_ARP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-#include "FreeRTOSIPConfigDefaults.h"
-#include "IPTraceMacroDefaults.h"
-
-/*-----------------------------------------------------------*/
-/* Miscellaneous structure and definitions. */
-/*-----------------------------------------------------------*/
-
-typedef struct xARP_CACHE_TABLE_ROW
-{
- uint32_t ulIPAddress; /* The IP address of an ARP cache entry. */
- MACAddress_t xMACAddress; /* The MAC address of an ARP cache entry. */
- uint8_t ucAge; /* A value that is periodically decremented but can also be refreshed by active communication. The ARP cache entry is removed if the value reaches zero. */
- uint8_t ucValid; /* pdTRUE: xMACAddress is valid, pdFALSE: waiting for ARP reply */
-} ARPCacheRow_t;
-
-typedef enum
-{
- eARPCacheMiss = 0, /* 0 An ARP table lookup did not find a valid entry. */
- eARPCacheHit, /* 1 An ARP table lookup found a valid entry. */
- eCantSendPacket /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */
-} eARPLookupResult_t;
-
-typedef enum
-{
- eNotFragment = 0, /* The IP packet being sent is not part of a fragment. */
- eFirstFragment, /* The IP packet being sent is the first in a set of fragmented packets. */
- eFollowingFragment /* The IP packet being sent is part of a set of fragmented packets. */
-} eIPFragmentStatus_t;
-
-/*
- * If ulIPAddress is already in the ARP cache table then reset the age of the
- * entry back to its maximum value. If ulIPAddress is not already in the ARP
- * cache table then add it - replacing the oldest current entry if there is not
- * a free space available.
- */
-void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress );
-
-#if( ipconfigARP_USE_CLASH_DETECTION != 0 )
- /* Becomes non-zero if another device responded to a gratuitos ARP message. */
- extern BaseType_t xARPHadIPClash;
- /* MAC-address of the other device containing the same IP-address. */
- extern MACAddress_t xARPClashMacAddress;
-#endif /* ipconfigARP_USE_CLASH_DETECTION */
-
-#if( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )
-
- /*
- * In some rare cases, it might be useful to remove a ARP cache entry of a
- * known MAC address to make sure it gets refreshed.
- */
- uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress );
-
-#endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */
-
-/*
- * Look for ulIPAddress in the ARP cache. If the IP address exists, copy the
- * associated MAC address into pxMACAddress, refresh the ARP cache entry's
- * age, and return eARPCacheHit. If the IP address does not exist in the ARP
- * cache return eARPCacheMiss. If the packet cannot be sent for any reason
- * (maybe DHCP is still in process, or the addressing needs a gateway but there
- * isn't a gateway defined) then return eCantSendPacket.
- */
-eARPLookupResult_t eARPGetCacheEntry( uint32_t *pulIPAddress, MACAddress_t * const pxMACAddress );
-
-#if( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )
-
- /* Lookup an IP-address if only the MAC-address is known */
- eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress, uint32_t *pulIPAddress );
-
-#endif
-/*
- * Reduce the age count in each entry within the ARP cache. An entry is no
- * longer considered valid and is deleted if its age reaches zero.
- */
-void vARPAgeCache( void );
-
-/*
- * Send out an ARP request for the IP address contained in pxNetworkBuffer, and
- * add an entry into the ARP table that indicates that an ARP reply is
- * outstanding so re-transmissions can be generated.
- */
-void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
-
-/*
- * After DHCP is ready and when changing IP address, force a quick send of our new IP
- * address
- */
-void vARPSendGratuitous( void );
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* FREERTOS_ARP_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h
deleted file mode 100755
index 04d151f..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_DHCP_H
-#define FREERTOS_DHCP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-#include "IPTraceMacroDefaults.h"
-
-/* Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
-typedef enum eDHCP_PHASE
-{
- eDHCPPhasePreDiscover, /* Driver is about to send a DHCP discovery. */
- eDHCPPhasePreRequest, /* Driver is about to request DHCP an IP address. */
-#if( ipconfigDHCP_SEND_DISCOVER_AFTER_AUTO_IP != 0 )
- eDHCPPhasePreLLA, /* Driver is about to try get an LLA address */
-#endif /* ipconfigDHCP_SEND_DISCOVER_AFTER_AUTO_IP */
-} eDHCPCallbackPhase_t;
-
-/* Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
-typedef enum eDHCP_ANSWERS
-{
- eDHCPContinue, /* Continue the DHCP process */
- eDHCPUseDefaults, /* Stop DHCP and use the static defaults. */
- eDHCPStopNoChanges, /* Stop DHCP and continue with current settings. */
-} eDHCPCallbackAnswer_t;
-
-/*
- * NOT A PUBLIC API FUNCTION.
- */
-void vDHCPProcess( BaseType_t xReset );
-
-/* Internal call: returns true if socket is the current DHCP socket */
-BaseType_t xIsDHCPSocket( Socket_t xSocket );
-
-/* Prototype of the hook (or callback) function that must be provided by the
-application if ipconfigUSE_DHCP_HOOK is set to 1. See the following URL for
-usage information:
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK
-*/
-eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase, uint32_t ulIPAddress );
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* FREERTOS_DHCP_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h
deleted file mode 100755
index 92e27a2..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_DNS_H
-#define FREERTOS_DNS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-#include "IPTraceMacroDefaults.h"
-
-
-/* The Link-local Multicast Name Resolution (LLMNR)
- * is included.
- * Note that a special MAC address is required in addition to the NIC's actual
- * MAC address: 01:00:5E:00:00:FC
- *
- * The target IP address will be 224.0.0.252
- */
-#if( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN )
- #define ipLLMNR_IP_ADDR 0xE00000FC
-#else
- #define ipLLMNR_IP_ADDR 0xFC0000E0
-#endif /* ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN */
-
-#define ipLLMNR_PORT 5355 /* Standard LLMNR port. */
-#define ipDNS_PORT 53 /* Standard DNS port. */
-#define ipDHCP_CLIENT 67
-#define ipDHCP_SERVER 68
-#define ipNBNS_PORT 137 /* NetBIOS Name Service. */
-#define ipNBDGM_PORT 138 /* Datagram Service, not included. */
-
-/*
- * The following function should be provided by the user and return true if it
- * matches the domain name.
- */
-extern BaseType_t xApplicationDNSQueryHook( const char *pcName );
-
-/*
- * LLMNR is very similar to DNS, so is handled by the DNS routines.
- */
-uint32_t ulDNSHandlePacket( NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-#if( ipconfigUSE_LLMNR == 1 )
- extern const MACAddress_t xLLMNR_MacAdress;
-#endif /* ipconfigUSE_LLMNR */
-
-#if( ipconfigUSE_NBNS != 0 )
-
- /*
- * Inspect a NetBIOS Names-Service message. If the name matches with ours
- * (xApplicationDNSQueryHook returns true) an answer will be sent back.
- * Note that LLMNR is a better protocol for name services on a LAN as it is
- * less polluted
- */
- uint32_t ulNBNSHandlePacket (NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-#endif /* ipconfigUSE_NBNS */
-
-#if( ipconfigUSE_DNS_CACHE != 0 )
-
- uint32_t FreeRTOS_dnslookup( const char *pcHostName );
-
-#endif /* ipconfigUSE_DNS_CACHE != 0 */
-
-#if( ipconfigDNS_USE_CALLBACKS != 0 )
-
- /*
- * Users may define this type of function as a callback.
- * It will be called when a DNS reply is received or when a timeout has been reached.
- */
- typedef void (* FOnDNSEvent ) ( const char * /* pcName */, void * /* pvSearchID */, uint32_t /* ulIPAddress */ );
-
- /*
- * Asynchronous version of gethostbyname()
- * xTimeout is in units of ms.
- */
- uint32_t FreeRTOS_gethostbyname_a( const char *pcHostName, FOnDNSEvent pCallback, void *pvSearchID, TickType_t xTimeout );
- void FreeRTOS_gethostbyname_cancel( void *pvSearchID );
-
-#endif
-
-/*
- * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
- * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
- * _TBD_ Add URL
- */
-uint32_t FreeRTOS_gethostbyname( const char *pcHostName );
-
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* FREERTOS_DNS_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h
deleted file mode 100755
index 28b23a5..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_IP_H
-#define FREERTOS_IP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-#include "FreeRTOSIPConfigDefaults.h"
-#include "IPTraceMacroDefaults.h"
-
-/* Some constants defining the sizes of several parts of a packet */
-#define ipSIZE_OF_ETH_HEADER 14u
-#define ipSIZE_OF_IPv4_HEADER 20u
-#define ipSIZE_OF_IGMP_HEADER 8u
-#define ipSIZE_OF_ICMP_HEADER 8u
-#define ipSIZE_OF_UDP_HEADER 8u
-#define ipSIZE_OF_TCP_HEADER 20u
-
-
-/* The number of octets in the MAC and IP addresses respectively. */
-#define ipMAC_ADDRESS_LENGTH_BYTES ( 6 )
-#define ipIP_ADDRESS_LENGTH_BYTES ( 4 )
-
-/* IP protocol definitions. */
-#define ipPROTOCOL_ICMP ( 1 )
-#define ipPROTOCOL_IGMP ( 2 )
-#define ipPROTOCOL_TCP ( 6 )
-#define ipPROTOCOL_UDP ( 17 )
-
-/* Dimensions the buffers that are filled by received Ethernet frames. */
-#define ipSIZE_OF_ETH_CRC_BYTES ( 4UL )
-#define ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES ( 4UL )
-#define ipTOTAL_ETHERNET_FRAME_SIZE ( ( ( uint32_t ) ipconfigNETWORK_MTU ) + ( ( uint32_t ) ipSIZE_OF_ETH_HEADER ) + ipSIZE_OF_ETH_CRC_BYTES + ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES )
-
-/*_RB_ Comment may need updating. */
-/* Space left at the beginning of a network buffer storage area to store a
-pointer back to the network buffer. Should be a multiple of 8 to ensure 8 byte
-alignment is maintained on architectures that require it.
-
-In order to get a 32-bit alignment of network packets, an offset of 2 bytes
-would be desirable, as defined by ipconfigPACKET_FILLER_SIZE. So the malloc'd
-buffer will have the following contents:
- uint32_t pointer; // word-aligned
- uchar_8 filler[6];
- << ETH-header >> // half-word-aligned
- uchar_8 dest[6]; // start of pucEthernetBuffer
- uchar_8 dest[6];
- uchar16_t type;
- << IP-header >> // word-aligned
- uint8_t ucVersionHeaderLength;
- etc
- */
-#if( ipconfigBUFFER_PADDING != 0 )
- #define ipBUFFER_PADDING ipconfigBUFFER_PADDING
-#else
- #define ipBUFFER_PADDING ( 8u + ipconfigPACKET_FILLER_SIZE )
-#endif
-
-/* The structure used to store buffers and pass them around the network stack.
-Buffers can be in use by the stack, in use by the network interface hardware
-driver, or free (not in use). */
-typedef struct xNETWORK_BUFFER
-{
- ListItem_t xBufferListItem; /* Used to reference the buffer form the free buffer list or a socket. */
- uint32_t ulIPAddress; /* Source or destination IP address, depending on usage scenario. */
- uint8_t *pucEthernetBuffer; /* Pointer to the start of the Ethernet frame. */
- size_t xDataLength; /* Starts by holding the total Ethernet frame length, then the UDP/TCP payload length. */
- uint16_t usPort; /* Source or destination port, depending on usage scenario. */
- uint16_t usBoundPort; /* The port to which a transmitting socket is bound. */
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- struct xNETWORK_BUFFER *pxNextBuffer; /* Possible optimisation for expert users - requires network driver support. */
- #endif
-} NetworkBufferDescriptor_t;
-
-#include "pack_struct_start.h"
-struct xMAC_ADDRESS
-{
- uint8_t ucBytes[ ipMAC_ADDRESS_LENGTH_BYTES ];
-}
-#include "pack_struct_end.h"
-
-typedef struct xMAC_ADDRESS MACAddress_t;
-
-typedef enum eNETWORK_EVENTS
-{
- eNetworkUp, /* The network is configured. */
- eNetworkDown /* The network connection has been lost. */
-} eIPCallbackEvent_t;
-
-typedef enum ePING_REPLY_STATUS
-{
- eSuccess = 0, /* A correct reply has been received for an outgoing ping. */
- eInvalidChecksum, /* A reply was received for an outgoing ping but the checksum of the reply was incorrect. */
- eInvalidData /* A reply was received to an outgoing ping but the payload of the reply was not correct. */
-} ePingReplyStatus_t;
-
-typedef enum eNETWORK_ADDRESS_TYPE
-{
- eNetWorkAddressTypeIPV4,
- eNetWorkAddressTypeIPV6,
- eNetWorkAddressTypeHostName
-} eNetWorkAddressType_t;
-
-/* Endian related definitions. */
-#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
-
- /* FreeRTOS_htons / FreeRTOS_htonl: some platforms might have built-in versions
- using a single instruction so allow these versions to be overridden. */
- #ifndef FreeRTOS_htons
- #define FreeRTOS_htons( usIn ) ( (uint16_t) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )
- #endif
-
- #ifndef FreeRTOS_htonl
- #define FreeRTOS_htonl( ulIn ) \
- ( \
- ( uint32_t ) \
- ( \
- ( ( ( ( uint32_t ) ( ulIn ) ) ) << 24 ) | \
- ( ( ( ( uint32_t ) ( ulIn ) ) & 0x0000ff00UL ) << 8 ) | \
- ( ( ( ( uint32_t ) ( ulIn ) ) & 0x00ff0000UL ) >> 8 ) | \
- ( ( ( ( uint32_t ) ( ulIn ) ) ) >> 24 ) \
- ) \
- )
- #endif
-
-#else /* ipconfigBYTE_ORDER */
-
- #define FreeRTOS_htons( x ) ( ( uint16_t ) ( x ) )
- #define FreeRTOS_htonl( x ) ( ( uint32_t ) ( x ) )
-
-#endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */
-
-#define FreeRTOS_ntohs( x ) FreeRTOS_htons( x )
-#define FreeRTOS_ntohl( x ) FreeRTOS_htonl( x )
-
-#if( ipconfigHAS_INLINE_FUNCTIONS == 1 )
-
- static portINLINE int32_t FreeRTOS_max_int32 (int32_t a, int32_t b);
- static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b);
- static portINLINE int32_t FreeRTOS_min_int32 (int32_t a, int32_t b);
- static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b);
- static portINLINE uint32_t FreeRTOS_round_up (uint32_t a, uint32_t d);
- static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d);
- static portINLINE BaseType_t FreeRTOS_min_BaseType (BaseType_t a, BaseType_t b);
- static portINLINE BaseType_t FreeRTOS_max_BaseType (BaseType_t a, BaseType_t b);
- static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b);
- static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t a, UBaseType_t b);
-
-
- static portINLINE int32_t FreeRTOS_max_int32 (int32_t a, int32_t b) { return a >= b ? a : b; }
- static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b) { return a >= b ? a : b; }
- static portINLINE int32_t FreeRTOS_min_int32 (int32_t a, int32_t b) { return a <= b ? a : b; }
- static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b) { return a <= b ? a : b; }
- static portINLINE uint32_t FreeRTOS_round_up (uint32_t a, uint32_t d) { return d * ( ( a + d - 1u ) / d ); }
- static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d) { return d * ( a / d ); }
-
- static portINLINE BaseType_t FreeRTOS_max_BaseType (BaseType_t a, BaseType_t b) { return a >= b ? a : b; }
- static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b) { return a >= b ? a : b; }
- static portINLINE BaseType_t FreeRTOS_min_BaseType (BaseType_t a, BaseType_t b) { return a <= b ? a : b; }
- static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t a, UBaseType_t b) { return a <= b ? a : b; }
-
-#else
-
- #define FreeRTOS_max_int32(a,b) ( ( ( int32_t ) ( a ) ) >= ( ( int32_t ) ( b ) ) ? ( ( int32_t ) ( a ) ) : ( ( int32_t ) ( b ) ) )
- #define FreeRTOS_max_uint32(a,b) ( ( ( uint32_t ) ( a ) ) >= ( ( uint32_t ) ( b ) ) ? ( ( uint32_t ) ( a ) ) : ( ( uint32_t ) ( b ) ) )
-
- #define FreeRTOS_min_int32(a,b) ( ( ( int32_t ) a ) <= ( ( int32_t ) b ) ? ( ( int32_t ) a ) : ( ( int32_t ) b ) )
- #define FreeRTOS_min_uint32(a,b) ( ( ( uint32_t ) a ) <= ( ( uint32_t ) b ) ? ( ( uint32_t ) a ) : ( ( uint32_t ) b ) )
-
- /* Round-up: a = d * ( ( a + d - 1 ) / d ) */
- #define FreeRTOS_round_up(a,d) ( ( ( uint32_t ) ( d ) ) * ( ( ( ( uint32_t ) ( a ) ) + ( ( uint32_t ) ( d ) ) - 1UL ) / ( ( uint32_t ) ( d ) ) ) )
- #define FreeRTOS_round_down(a,d) ( ( ( uint32_t ) ( d ) ) * ( ( ( uint32_t ) ( a ) ) / ( ( uint32_t ) ( d ) ) ) )
-
- #define FreeRTOS_ms_to_tick(ms) ( ( ms * configTICK_RATE_HZ + 500 ) / 1000 )
-
- #define FreeRTOS_max_BaseType(a, b) ( ( ( BaseType_t ) ( a ) ) >= ( ( BaseType_t ) ( b ) ) ? ( ( BaseType_t ) ( a ) ) : ( ( BaseType_t ) ( b ) ) )
- #define FreeRTOS_max_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) >= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) )
- #define FreeRTOS_min_BaseType(a, b) ( ( ( BaseType_t ) ( a ) ) <= ( ( BaseType_t ) ( b ) ) ? ( ( BaseType_t ) ( a ) ) : ( ( BaseType_t ) ( b ) ) )
- #define FreeRTOS_min_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) <= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) )
-
-#endif /* ipconfigHAS_INLINE_FUNCTIONS */
-
-#define pdMS_TO_MIN_TICKS( xTimeInMs ) ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1 ) ? ( ( TickType_t ) 1 ) : pdMS_TO_TICKS( ( xTimeInMs ) ) )
-
-#ifndef pdTRUE_SIGNED
- /* Temporary solution: eventually the defines below will appear in 'Source\include\projdefs.h' */
- #define pdTRUE_SIGNED pdTRUE
- #define pdFALSE_SIGNED pdFALSE
- #define pdTRUE_UNSIGNED ( ( UBaseType_t ) 1u )
- #define pdFALSE_UNSIGNED ( ( UBaseType_t ) 0u )
-#endif
-
-/*
- * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
- * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html
- */
-BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
- const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],
- const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
- const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
- const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
-
-void * FreeRTOS_GetUDPPayloadBuffer( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks );
-void FreeRTOS_GetAddressConfiguration( uint32_t *pulIPAddress, uint32_t *pulNetMask, uint32_t *pulGatewayAddress, uint32_t *pulDNSServerAddress );
-void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, const uint32_t *pulNetMask, const uint32_t *pulGatewayAddress, const uint32_t *pulDNSServerAddress );
-BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t xNumberOfBytesToSend, TickType_t xBlockTimeTicks );
-void FreeRTOS_ReleaseUDPPayloadBuffer( void *pvBuffer );
-const uint8_t * FreeRTOS_GetMACAddress( void );
-void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES] );
-void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
-void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier );
-uint32_t FreeRTOS_GetIPAddress( void );
-void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
-void FreeRTOS_SetNetmask( uint32_t ulNetmask );
-void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
-uint32_t FreeRTOS_GetGatewayAddress( void );
-uint32_t FreeRTOS_GetDNSServerAddress( void );
-uint32_t FreeRTOS_GetNetmask( void );
-void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress );
-BaseType_t FreeRTOS_IsNetworkUp( void );
-
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- UBaseType_t uxGetMinimumIPQueueSpace( void );
-#endif
-
-/*
- * Defined in FreeRTOS_Sockets.c
- * //_RB_ Don't think this comment is correct. If this is for internal use only it should appear after all the public API functions and not start with FreeRTOS_.
- * Socket has had activity, reset the timer so it will not be closed
- * because of inactivity
- */
-const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState);
-
-/* _HT_ Temporary: show all valid ARP entries
- */
-void FreeRTOS_PrintARPCache( void );
-void FreeRTOS_ClearARP( void );
-
-#if( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
-
- /* DHCP has an option for clients to register their hostname. It doesn't
- have much use, except that a device can be found in a router along with its
- name. If this option is used the callback below must be provided by the
- application writer to return a const string, denoting the device's name. */
- const char *pcApplicationHostnameHook( void );
-
-#endif /* ipconfigDHCP_REGISTER_HOSTNAME */
-
-
-/* For backward compatibility define old structure names to the newer equivalent
-structure name. */
-#ifndef ipconfigENABLE_BACKWARD_COMPATIBILITY
- #define ipconfigENABLE_BACKWARD_COMPATIBILITY 1
-#endif
-
-#if( ipconfigENABLE_BACKWARD_COMPATIBILITY == 1 )
- #define xIPStackEvent_t IPStackEvent_t
- #define xNetworkBufferDescriptor_t NetworkBufferDescriptor_t
- #define xMACAddress_t MACAddress_t
- #define xWinProperties_t WinProperties_t
- #define xSocket_t Socket_t
- #define xSocketSet_t SocketSet_t
- #define ipSIZE_OF_IP_HEADER ipSIZE_OF_IPv4_HEADER
-
- /* Since August 2016, the public types and fields below have changed name:
- abbreviations TCP/UDP are now written in capitals, and type names now end with "_t". */
- #define FOnConnected FOnConnected_t
- #define FOnTcpReceive FOnTCPReceive_t
- #define FOnTcpSent FOnTCPSent_t
- #define FOnUdpReceive FOnUDPReceive_t
- #define FOnUdpSent FOnUDPSent_t
-
- #define pOnTcpConnected pxOnTCPConnected
- #define pOnTcpReceive pxOnTCPReceive
- #define pOnTcpSent pxOnTCPSent
- #define pOnUdpReceive pxOnUDPReceive
- #define pOnUdpSent pxOnUDPSent
-
- #define FOnUdpSent FOnUDPSent_t
- #define FOnTcpSent FOnTCPSent_t
-#endif /* ipconfigENABLE_BACKWARD_COMPATIBILITY */
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* FREERTOS_IP_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
deleted file mode 100755
index 3bcac62..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_IP_PRIVATE_H
-#define FREERTOS_IP_PRIVATE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-#include "FreeRTOSIPConfigDefaults.h"
-#include "FreeRTOS_Sockets.h"
-#include "IPTraceMacroDefaults.h"
-#include "FreeRTOS_Stream_Buffer.h"
-#if( ipconfigUSE_TCP == 1 )
- #include "FreeRTOS_TCP_WIN.h"
- #include "FreeRTOS_TCP_IP.h"
-#endif
-
-#include "event_groups.h"
-
-typedef struct xNetworkAddressingParameters
-{
- uint32_t ulDefaultIPAddress;
- uint32_t ulNetMask;
- uint32_t ulGatewayAddress;
- uint32_t ulDNSServerAddress;
- uint32_t ulBroadcastAddress;
-} NetworkAddressingParameters_t;
-
-extern BaseType_t xTCPWindowLoggingLevel;
-
-/*-----------------------------------------------------------*/
-/* Protocol headers. */
-/*-----------------------------------------------------------*/
-
-#include "pack_struct_start.h"
-struct xETH_HEADER
-{
- MACAddress_t xDestinationAddress; /* 0 + 6 = 6 */
- MACAddress_t xSourceAddress; /* 6 + 6 = 12 */
- uint16_t usFrameType; /* 12 + 2 = 14 */
-}
-#include "pack_struct_end.h"
-typedef struct xETH_HEADER EthernetHeader_t;
-
-#include "pack_struct_start.h"
-struct xARP_HEADER
-{
- uint16_t usHardwareType; /* 0 + 2 = 2 */
- uint16_t usProtocolType; /* 2 + 2 = 4 */
- uint8_t ucHardwareAddressLength; /* 4 + 1 = 5 */
- uint8_t ucProtocolAddressLength; /* 5 + 1 = 6 */
- uint16_t usOperation; /* 6 + 2 = 8 */
- MACAddress_t xSenderHardwareAddress; /* 8 + 6 = 14 */
- uint8_t ucSenderProtocolAddress[ 4 ]; /* 14 + 4 = 18 */
- MACAddress_t xTargetHardwareAddress; /* 18 + 6 = 24 */
- uint32_t ulTargetProtocolAddress; /* 24 + 4 = 28 */
-}
-#include "pack_struct_end.h"
-typedef struct xARP_HEADER ARPHeader_t;
-
-#include "pack_struct_start.h"
-struct xIP_HEADER
-{
- uint8_t ucVersionHeaderLength; /* 0 + 1 = 1 */
- uint8_t ucDifferentiatedServicesCode; /* 1 + 1 = 2 */
- uint16_t usLength; /* 2 + 2 = 4 */
- uint16_t usIdentification; /* 4 + 2 = 6 */
- uint16_t usFragmentOffset; /* 6 + 2 = 8 */
- uint8_t ucTimeToLive; /* 8 + 1 = 9 */
- uint8_t ucProtocol; /* 9 + 1 = 10 */
- uint16_t usHeaderChecksum; /* 10 + 2 = 12 */
- uint32_t ulSourceIPAddress; /* 12 + 4 = 16 */
- uint32_t ulDestinationIPAddress; /* 16 + 4 = 20 */
-}
-#include "pack_struct_end.h"
-typedef struct xIP_HEADER IPHeader_t;
-
-#include "pack_struct_start.h"
-struct xIGMP_HEADER
-{
- uint8_t ucVersionType; /* 0 + 1 = 1 */
- uint8_t ucMaxResponseTime; /* 1 + 1 = 2 */
- uint16_t usChecksum; /* 2 + 2 = 4 */
- uint32_t usGroupAddress; /* 4 + 4 = 8 */
-}
-#include "pack_struct_end.h"
-typedef struct xIGMP_HEADER IGMPHeader_t;
-
-#include "pack_struct_start.h"
-struct xICMP_HEADER
-{
- uint8_t ucTypeOfMessage; /* 0 + 1 = 1 */
- uint8_t ucTypeOfService; /* 1 + 1 = 2 */
- uint16_t usChecksum; /* 2 + 2 = 4 */
- uint16_t usIdentifier; /* 4 + 2 = 6 */
- uint16_t usSequenceNumber; /* 6 + 2 = 8 */
-}
-#include "pack_struct_end.h"
-typedef struct xICMP_HEADER ICMPHeader_t;
-
-#include "pack_struct_start.h"
-struct xUDP_HEADER
-{
- uint16_t usSourcePort; /* 0 + 2 = 2 */
- uint16_t usDestinationPort; /* 2 + 2 = 4 */
- uint16_t usLength; /* 4 + 2 = 6 */
- uint16_t usChecksum; /* 6 + 2 = 8 */
-}
-#include "pack_struct_end.h"
-typedef struct xUDP_HEADER UDPHeader_t;
-
-#include "pack_struct_start.h"
-struct xTCP_HEADER
-{
- uint16_t usSourcePort; /* + 2 = 2 */
- uint16_t usDestinationPort; /* + 2 = 4 */
- uint32_t ulSequenceNumber; /* + 4 = 8 */
- uint32_t ulAckNr; /* + 4 = 12 */
- uint8_t ucTCPOffset; /* + 1 = 13 */
- uint8_t ucTCPFlags; /* + 1 = 14 */
- uint16_t usWindow; /* + 2 = 15 */
- uint16_t usChecksum; /* + 2 = 18 */
- uint16_t usUrgent; /* + 2 = 20 */
-#if ipconfigUSE_TCP == 1
- /* the option data is not a part of the TCP header */
- uint8_t ucOptdata[ipSIZE_TCP_OPTIONS]; /* + 12 = 32 */
-#endif
-}
-#include "pack_struct_end.h"
-typedef struct xTCP_HEADER TCPHeader_t;
-
-#include "pack_struct_start.h"
-struct xPSEUDO_HEADER
-{
- uint32_t ulSourceAddress;
- uint32_t ulDestinationAddress;
- uint8_t ucZeros;
- uint8_t ucProtocol;
- uint16_t usUDPLength;
-}
-#include "pack_struct_end.h"
-typedef struct xPSEUDO_HEADER PseudoHeader_t;
-
-/*-----------------------------------------------------------*/
-/* Nested protocol packets. */
-/*-----------------------------------------------------------*/
-
-#include "pack_struct_start.h"
-struct xARP_PACKET
-{
- EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
- ARPHeader_t xARPHeader; /* 14 + 28 = 42 */
-}
-#include "pack_struct_end.h"
-typedef struct xARP_PACKET ARPPacket_t;
-
-#include "pack_struct_start.h"
-struct xIP_PACKET
-{
- EthernetHeader_t xEthernetHeader;
- IPHeader_t xIPHeader;
-}
-#include "pack_struct_end.h"
-typedef struct xIP_PACKET IPPacket_t;
-
-#include "pack_struct_start.h"
-struct xICMP_PACKET
-{
- EthernetHeader_t xEthernetHeader;
- IPHeader_t xIPHeader;
- ICMPHeader_t xICMPHeader;
-}
-#include "pack_struct_end.h"
-typedef struct xICMP_PACKET ICMPPacket_t;
-
-#include "pack_struct_start.h"
-struct xUDP_PACKET
-{
- EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
- IPHeader_t xIPHeader; /* 14 + 20 = 34 */
- UDPHeader_t xUDPHeader; /* 34 + 8 = 42 */
-}
-#include "pack_struct_end.h"
-typedef struct xUDP_PACKET UDPPacket_t;
-
-#include "pack_struct_start.h"
-struct xTCP_PACKET
-{
- EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
- IPHeader_t xIPHeader; /* 14 + 20 = 34 */
- TCPHeader_t xTCPHeader; /* 34 + 32 = 66 */
-}
-#include "pack_struct_end.h"
-typedef struct xTCP_PACKET TCPPacket_t;
-
-typedef union XPROT_PACKET
-{
- ARPPacket_t xARPPacket;
- TCPPacket_t xTCPPacket;
- UDPPacket_t xUDPPacket;
- ICMPPacket_t xICMPPacket;
-} ProtocolPacket_t;
-
-
-/* The maximum UDP payload length. */
-#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
-
-typedef enum
-{
- eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
- eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
- eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
- eFrameConsumed /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
-} eFrameProcessingResult_t;
-
-typedef enum
-{
- eNoEvent = -1,
- eNetworkDownEvent, /* 0: The network interface has been lost and/or needs [re]connecting. */
- eNetworkRxEvent, /* 1: The network interface has queued a received Ethernet frame. */
- eARPTimerEvent, /* 2: The ARP timer expired. */
- eStackTxEvent, /* 3: The software stack has queued a packet to transmit. */
- eDHCPEvent, /* 4: Process the DHCP state machine. */
- eTCPTimerEvent, /* 5: See if any TCP socket needs attention. */
- eTCPAcceptEvent, /* 6: Client API FreeRTOS_accept() waiting for client connections. */
- eTCPNetStat, /* 7: IP-task is asked to produce a netstat listing. */
- eSocketBindEvent, /* 8: Send a message to the IP-task to bind a socket to a port. */
- eSocketCloseEvent, /* 9: Send a message to the IP-task to close a socket. */
- eSocketSelectEvent, /*10: Send a message to the IP-task for select(). */
- eSocketSignalEvent, /*11: A socket must be signalled. */
-} eIPEvent_t;
-
-typedef struct IP_TASK_COMMANDS
-{
- eIPEvent_t eEventType;
- void *pvData;
-} IPStackEvent_t;
-
-#define ipBROADCAST_IP_ADDRESS 0xffffffffUL
-
-/* Offset into the Ethernet frame that is used to temporarily store information
-on the fragmentation status of the packet being sent. The value is important,
-as it is past the location into which the destination address will get placed. */
-#define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
-#define ipSOCKET_OPTIONS_OFFSET ( 6 )
-
-/* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
-setting. */
-#define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET_IPv4 : ipIP_PAYLOAD_OFFSET )
-
-/* The offset into a UDP packet at which the UDP data (payload) starts. */
-#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
-
-/* The offset into an IP packet into which the IP data (payload) starts. */
-#define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) )
-
-#include "pack_struct_start.h"
-struct xUDP_IP_FRAGMENT_PARAMETERS
-{
- uint8_t ucSocketOptions;
- uint8_t ucPadFor16BitAlignment;
- uint16_t usFragmentedPacketOffset;
- uint16_t usFragmentLength;
- uint16_t usPayloadChecksum;
-}
-#include "pack_struct_end.h"
-typedef struct xUDP_IP_FRAGMENT_PARAMETERS IPFragmentParameters_t;
-
-#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
-
- /* Ethernet frame types. */
- #define ipARP_FRAME_TYPE ( 0x0608U )
- #define ipIPv4_FRAME_TYPE ( 0x0008U )
-
- /* ARP related definitions. */
- #define ipARP_PROTOCOL_TYPE ( 0x0008U )
- #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
- #define ipARP_REQUEST ( 0x0100U )
- #define ipARP_REPLY ( 0x0200U )
-
-#else
-
- /* Ethernet frame types. */
- #define ipARP_FRAME_TYPE ( 0x0806U )
- #define ipIPv4_FRAME_TYPE ( 0x0800U )
-
- /* ARP related definitions. */
- #define ipARP_PROTOCOL_TYPE ( 0x0800U )
- #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
- #define ipARP_REQUEST ( 0x0001 )
- #define ipARP_REPLY ( 0x0002 )
-
-#endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */
-
-
-/* For convenience, a MAC address of all zeros and another of all 0xffs are
-defined const for quick reference. */
-extern const MACAddress_t xBroadcastMACAddress; /* all 0xff's */
-extern uint16_t usPacketIdentifier;
-
-/* Define a default UDP packet header (declared in FreeRTOS_UDP_IP.c) */
-typedef union xUDPPacketHeader
-{
- uint8_t ucBytes[24];
- uint32_t ulWords[6];
-} UDPPacketHeader_t;
-extern UDPPacketHeader_t xDefaultPartUDPPacketHeader;
-
-/* Structure that stores the netmask, gateway address and DNS server addresses. */
-extern NetworkAddressingParameters_t xNetworkAddressing;
-
-/* Structure that stores the defaults for netmask, gateway address and DNS.
-These values will be copied to 'xNetworkAddressing' in case DHCP is not used,
-and also in case DHCP does not lead to a confirmed request. */
-extern NetworkAddressingParameters_t xDefaultAddressing;
-
-/* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
-extern const BaseType_t xBufferAllocFixedSize;
-
-/* Defined in FreeRTOS_Sockets.c */
-#if ( ipconfigUSE_TCP == 1 )
- extern List_t xBoundTCPSocketsList;
-#endif
-
-/* The local IP address is accessed from within xDefaultPartUDPPacketHeader,
-rather than duplicated in its own variable. */
-#define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[ 20u / sizeof(uint32_t) ] ) )
-
-/* The local MAC address is accessed from within xDefaultPartUDPPacketHeader,
-rather than duplicated in its own variable. */
-#define ipLOCAL_MAC_ADDRESS ( &xDefaultPartUDPPacketHeader.ucBytes[0] )
-
-/* ICMP packets are sent using the same function as UDP packets. The port
-number is used to distinguish between the two, as 0 is an invalid UDP port. */
-#define ipPACKET_CONTAINS_ICMP_DATA ( 0 )
-
-/* For now, the lower 8 bits in 'xEventBits' will be reserved for the above
-socket events. */
-#define SOCKET_EVENT_BIT_COUNT 8
-
-#define vSetField16( pxBase, xType, xField, usValue ) \
-{ \
- ( ( uint8_t* )( pxBase ) ) [ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( usValue ) >> 8 ); \
- ( ( uint8_t* )( pxBase ) ) [ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( usValue ) & 0xff ); \
-}
-
-#define vSetField32( pxBase, xType, xField, ulValue ) \
-{ \
- ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( ulValue ) >> 24 ); \
- ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( ( ulValue ) >> 16 ) & 0xff ); \
- ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 2 ] = ( uint8_t ) ( ( ( ulValue ) >> 8 ) & 0xff ); \
- ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 3 ] = ( uint8_t ) ( ( ulValue ) & 0xff ); \
-}
-
-#define vFlip_16( left, right ) \
- do { \
- uint16_t tmp = (left); \
- (left) = (right); \
- (right) = tmp; \
- } while (0)
-
-#define vFlip_32( left, right ) \
- do { \
- uint32_t tmp = (left); \
- (left) = (right); \
- (right) = tmp; \
- } while (0)
-
-#ifndef ARRAY_SIZE
- #define ARRAY_SIZE(x) (BaseType_t)(sizeof(x)/sizeof(x)[0])
-#endif
-
-/*
- * A version of FreeRTOS_GetReleaseNetworkBuffer() that can be called from an
- * interrupt. If a non zero value is returned, then the calling ISR should
- * perform a context switch before exiting the ISR.
- */
-BaseType_t FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );
-
-/*
- * Create a message that contains a command to initialise the network interface.
- * This is used during initialisation, and at any time the network interface
- * goes down thereafter. The network interface hardware driver is responsible
- * for sending the message that contains the network interface down command/
- * event.
- *
- * Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
- * called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
- * returns a non-zero value then a context switch should be performed ebfore
- * the interrupt is exited.
- */
-void FreeRTOS_NetworkDown( void );
-BaseType_t FreeRTOS_NetworkDownFromISR( void );
-
-/*
- * Processes incoming ARP packets.
- */
-eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame );
-
-/*
- * Inspect an Ethernet frame to see if it contains data that the stack needs to
- * process. eProcessBuffer is returned if the frame should be processed by the
- * stack. eReleaseBuffer is returned if the frame should be discarded.
- */
-eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
-
-/*
- * Return the checksum generated over xDataLengthBytes from pucNextData.
- */
-uint16_t usGenerateChecksum( uint32_t ulSum, const uint8_t * pucNextData, size_t uxDataLengthBytes );
-
-/* Socket related private functions. */
-
-/*
- * The caller must ensure that pxNetworkBuffer->xDataLength is the UDP packet
- * payload size (excluding packet headers) and that the packet in pucEthernetBuffer
- * is at least the size of UDPPacket_t.
- */
-BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );
-
-/*
- * Initialize the socket list data structures for TCP and UDP.
- */
-BaseType_t vNetworkSocketsInit( void );
-
-/*
- * Returns pdTRUE if the IP task has been created and is initialised. Otherwise
- * returns pdFALSE.
- */
-BaseType_t xIPIsNetworkTaskReady( void );
-
-#if( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
- struct XSOCKET;
- typedef void (*SocketWakeupCallback_t)( struct XSOCKET * pxSocket );
-#endif
-
-#if( ipconfigUSE_TCP == 1 )
-
- /*
- * Actually a user thing, but because xBoundTCPSocketsList, let it do by the
- * IP-task
- */
- void vTCPNetStat( void );
-
- /*
- * At least one socket needs to check for timeouts
- */
- TickType_t xTCPTimerCheck( BaseType_t xWillSleep );
-
- /* Every TCP socket has a buffer space just big enough to store
- the last TCP header received.
- As a reference of this field may be passed to DMA, force the
- alignment to 8 bytes. */
- typedef union
- {
- struct
- {
- /* Increase the alignment of this union by adding a 64-bit variable. */
- uint64_t ullAlignmentWord;
- } a;
- struct
- {
- /* The next field only serves to give 'ucLastPacket' a correct
- alignment of 8 + 2. See comments in FreeRTOS_IP.h */
- uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
- uint8_t ucLastPacket[ sizeof( TCPPacket_t ) ];
- } u;
- } LastTCPPacket_t;
-
- /*
- * Note that the values of all short and long integers in these structs
- * are being stored in the native-endian way
- * Translation should take place when accessing any structure which defines
- * network packets, such as IPHeader_t and TCPHeader_t
- */
- typedef struct TCPSOCKET
- {
- uint32_t ulRemoteIP; /* IP address of remote machine */
- uint16_t usRemotePort; /* Port on remote machine */
- struct {
- /* Most compilers do like bit-flags */
- uint32_t
- bMssChange : 1, /* This socket has seen a change in MSS */
- bPassAccept : 1, /* when true, this socket may be returned in a call to accept() */
- bPassQueued : 1, /* when true, this socket is an orphan until it gets connected
- * Why an orphan? Because it may not be returned in a accept() call until it
- * gets the state eESTABLISHED */
- bReuseSocket : 1, /* When a listening socket gets a connection, do not create a new instance but keep on using it */
- bCloseAfterSend : 1,/* As soon as the last byte has been transmitted, finalise the connection
- * Useful in e.g. FTP connections, where the last data bytes are sent along with the FIN flag */
- bUserShutdown : 1, /* User requesting a graceful shutdown */
- bCloseRequested : 1,/* Request to finalise the connection */
- bLowWater : 1, /* high-water level has been reached. Cleared as soon as 'rx-count < lo-water' */
- bWinChange : 1, /* The value of bLowWater has changed, must send a window update */
- bSendKeepAlive : 1, /* When this flag is true, a TCP keep-alive message must be send */
- bWaitKeepAlive : 1, /* When this flag is true, a TCP keep-alive reply is expected */
- bConnPrepared : 1, /* Connecting socket: Message has been prepared */
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- bConnPassed : 1, /* Connecting socket: Socket has been passed in a successful select() */
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
- bFinAccepted : 1, /* This socket has received (or sent) a FIN and accepted it */
- bFinSent : 1, /* We've sent out a FIN */
- bFinRecv : 1, /* We've received a FIN from our peer */
- bFinAcked : 1, /* Our FIN packet has been acked */
- bFinLast : 1, /* The last ACK (after FIN and FIN+ACK) has been sent or will be sent by the peer */
- bRxStopped : 1, /* Application asked to temporarily stop reception */
- bMallocError : 1, /* There was an error allocating a stream */
- bWinScaling : 1; /* A TCP-Window Scaling option was offered and accepted in the SYN phase. */
- } bits;
- uint32_t ulHighestRxAllowed;
- /* The highest sequence number that we can receive at any moment */
- uint16_t usTimeout; /* Time (in ticks) after which this socket needs attention */
- uint16_t usCurMSS; /* Current Maximum Segment Size */
- uint16_t usInitMSS; /* Initial maximum segment Size */
- uint16_t usChildCount; /* In case of a listening socket: number of connections on this port number */
- uint16_t usBacklog; /* In case of a listening socket: maximum number of concurrent connections on this port number */
- uint8_t ucRepCount; /* Send repeat count, for retransmissions
- * This counter is separate from the xmitCount in the
- * TCP win segments */
- uint8_t ucTCPState; /* TCP state: see eTCP_STATE */
- struct XSOCKET *pxPeerSocket; /* for server socket: child, for child socket: parent */
- #if( ipconfigTCP_KEEP_ALIVE == 1 )
- uint8_t ucKeepRepCount;
- TickType_t xLastAliveTime;
- #endif /* ipconfigTCP_KEEP_ALIVE */
- #if( ipconfigTCP_HANG_PROTECTION == 1 )
- TickType_t xLastActTime;
- #endif /* ipconfigTCP_HANG_PROTECTION */
- size_t uxLittleSpace;
- size_t uxEnoughSpace;
- size_t uxRxStreamSize;
- size_t uxTxStreamSize;
- StreamBuffer_t *rxStream;
- StreamBuffer_t *txStream;
- #if( ipconfigUSE_TCP_WIN == 1 )
- NetworkBufferDescriptor_t *pxAckMessage;
- #endif /* ipconfigUSE_TCP_WIN */
- /* Buffer space to store the last TCP header received. */
- LastTCPPacket_t xPacket;
- uint8_t tcpflags; /* TCP flags */
- #if( ipconfigUSE_TCP_WIN != 0 )
- uint8_t ucMyWinScaleFactor;
- uint8_t ucPeerWinScaleFactor;
- #endif
- #if( ipconfigUSE_CALLBACKS == 1 )
- FOnTCPReceive_t pxHandleReceive; /*
- * In case of a TCP socket:
- * typedef void (* FOnTCPReceive_t) (Socket_t xSocket, void *pData, size_t xLength );
- */
- FOnTCPSent_t pxHandleSent;
- FOnConnected_t pxHandleConnected; /* Actually type: typedef void (* FOnConnected_t) (Socket_t xSocket, BaseType_t ulConnected ); */
- #endif /* ipconfigUSE_CALLBACKS */
- uint32_t ulWindowSize; /* Current Window size advertised by peer */
- uint32_t ulRxCurWinSize; /* Constantly changing: this is the current size available for data reception */
- size_t uxRxWinSize; /* Fixed value: size of the TCP reception window */
- size_t uxTxWinSize; /* Fixed value: size of the TCP transmit window */
-
- TCPWindow_t xTCPWindow;
- } IPTCPSocket_t;
-
-#endif /* ipconfigUSE_TCP */
-
-typedef struct UDPSOCKET
-{
- List_t xWaitingPacketsList; /* Incoming packets */
- #if( ipconfigUDP_MAX_RX_PACKETS > 0 )
- UBaseType_t uxMaxPackets; /* Protection: limits the number of packets buffered per socket */
- #endif /* ipconfigUDP_MAX_RX_PACKETS */
- #if( ipconfigUSE_CALLBACKS == 1 )
- FOnUDPReceive_t pxHandleReceive; /*
- * In case of a UDP socket:
- * typedef void (* FOnUDPReceive_t) (Socket_t xSocket, void *pData, size_t xLength, struct freertos_sockaddr *pxAddr );
- */
- FOnUDPSent_t pxHandleSent;
- #endif /* ipconfigUSE_CALLBACKS */
-} IPUDPSocket_t;
-
-typedef enum eSOCKET_EVENT {
- eSOCKET_RECEIVE = 0x0001,
- eSOCKET_SEND = 0x0002,
- eSOCKET_ACCEPT = 0x0004,
- eSOCKET_CONNECT = 0x0008,
- eSOCKET_BOUND = 0x0010,
- eSOCKET_CLOSED = 0x0020,
- eSOCKET_INTR = 0x0040,
- eSOCKET_ALL = 0x007F,
-} eSocketEvent_t;
-
-typedef struct XSOCKET
-{
- EventBits_t xEventBits;
- EventGroupHandle_t xEventGroup;
-
- ListItem_t xBoundSocketListItem; /* Used to reference the socket from a bound sockets list. */
- TickType_t xReceiveBlockTime; /* if recv[to] is called while no data is available, wait this amount of time. Unit in clock-ticks */
- TickType_t xSendBlockTime; /* if send[to] is called while there is not enough space to send, wait this amount of time. Unit in clock-ticks */
-
- uint16_t usLocalPort; /* Local port on this machine */
- uint8_t ucSocketOptions;
- uint8_t ucProtocol; /* choice of FREERTOS_IPPROTO_UDP/TCP */
- #if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
- SemaphoreHandle_t pxUserSemaphore;
- #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
- #if( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
- SocketWakeupCallback_t pxUserWakeCallback;
- #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */
-
- #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
- struct xSOCKET_SET *pxSocketSet;
- /* User may indicate which bits are interesting for this socket. */
- EventBits_t xSelectBits;
- /* These bits indicate the events which have actually occurred.
- They are maintained by the IP-task */
- EventBits_t xSocketBits;
- #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
- /* TCP/UDP specific fields: */
- /* Before accessing any member of this structure, it should be confirmed */
- /* that the protocol corresponds with the type of structure */
-
- union
- {
- IPUDPSocket_t xUDP;
- #if( ipconfigUSE_TCP == 1 )
- IPTCPSocket_t xTCP;
- /* Make sure that xTCP is 8-bytes aligned by
- declaring a 64-bit variable in the same union */
- uint64_t ullTCPAlignment;
- #endif /* ipconfigUSE_TCP */
- } u;
-} FreeRTOS_Socket_t;
-
-#if( ipconfigUSE_TCP == 1 )
- /*
- * Lookup a TCP socket, using a multiple matching: both port numbers and
- * return IP address.
- */
- FreeRTOS_Socket_t *pxTCPSocketLookup( uint32_t ulLocalIP, UBaseType_t uxLocalPort, uint32_t ulRemoteIP, UBaseType_t uxRemotePort );
-
-#endif /* ipconfigUSE_TCP */
-
-/*
- * Look up a local socket by finding a match with the local port.
- */
-FreeRTOS_Socket_t *pxUDPSocketLookup( UBaseType_t uxLocalPort );
-
-/*
- * Called when the application has generated a UDP packet to send.
- */
-void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
-
-/*
- * Calculate the upper-layer checksum
- * Works both for UDP, ICMP and TCP packages
- * bOut = true: checksum will be set in outgoing packets
- * bOut = false: checksum will be calculated for incoming packets
- * returning 0xffff means: checksum was correct
- */
-uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, size_t uxBufferLength, BaseType_t xOutgoingPacket );
-
-/*
- * An Ethernet frame has been updated (maybe it was an ARP request or a PING
- * request?) and is to be sent back to its source.
- */
-void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend );
-
-/*
- * The internal version of bind()
- * If 'ulInternal' is true, it is called by the driver
- * The TCP driver needs to bind a socket at the moment a listening socket
- * creates a new connected socket
- */
-BaseType_t vSocketBind( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr * pxAddress, size_t uxAddressLength, BaseType_t xInternal );
-
-/*
- * Internal function to add streaming data to a TCP socket. If ulIn == true,
- * data will be added to the rxStream, otherwise to the tXStream. Normally data
- * will be written with ulOffset == 0, meaning: at the end of the FIFO. When
- * packet come in out-of-order, an offset will be used to put it in front and
- * the head will not change yet.
- */
-int32_t lTCPAddRxdata(FreeRTOS_Socket_t *pxSocket, size_t uxOffset, const uint8_t *pcData, uint32_t ulByteCount);
-
-/*
- * Currently called for any important event.
- */
-void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Some helping function, their meaning should be clear
- */
-static portINLINE uint32_t ulChar2u32 (const uint8_t *apChr);
-static portINLINE uint32_t ulChar2u32 (const uint8_t *apChr)
-{
- return ( ( ( uint32_t )apChr[0] ) << 24) |
- ( ( ( uint32_t )apChr[1] ) << 16) |
- ( ( ( uint32_t )apChr[2] ) << 8) |
- ( ( ( uint32_t )apChr[3] ) );
-}
-
-static portINLINE uint16_t usChar2u16 (const uint8_t *apChr);
-static portINLINE uint16_t usChar2u16 (const uint8_t *apChr)
-{
- return ( uint16_t )
- ( ( ( ( uint32_t )apChr[0] ) << 8) |
- ( ( ( uint32_t )apChr[1] ) ) );
-}
-
-/* Check a single socket for retransmissions and timeouts */
-BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t *pxSocket );
-
-BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t *pxSocket );
-
-/* Defined in FreeRTOS_Sockets.c
- * Close a socket
- */
-void *vSocketClose( FreeRTOS_Socket_t *pxSocket );
-
-/*
- * Send the event eEvent to the IP task event queue, using a block time of
- * zero. Return pdPASS if the message was sent successfully, otherwise return
- * pdFALSE.
-*/
-BaseType_t xSendEventToIPTask( eIPEvent_t eEvent );
-
-/*
- * The same as above, but a struct as a parameter, containing:
- * eIPEvent_t eEventType;
- * void *pvData;
- */
-BaseType_t xSendEventStructToIPTask( const IPStackEvent_t *pxEvent, TickType_t xTimeout );
-
-/*
- * Returns a pointer to the original NetworkBuffer from a pointer to a UDP
- * payload buffer.
- */
-NetworkBufferDescriptor_t *pxUDPPayloadBuffer_to_NetworkBuffer( void *pvBuffer );
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- /*
- * For the case where the network driver passes a buffer directly to a DMA
- * descriptor, this function can be used to translate a 'network buffer' to
- * a 'network buffer descriptor'.
- */
- NetworkBufferDescriptor_t *pxPacketBuffer_to_NetworkBuffer( const void *pvBuffer );
-#endif
-
-/*
- * Internal: Sets a new state for a TCP socket and performs the necessary
- * actions like calling a OnConnected handler to notify the socket owner.
- */
-#if( ipconfigUSE_TCP == 1 )
- void vTCPStateChange( FreeRTOS_Socket_t *pxSocket, enum eTCP_STATE eTCPState );
-#endif /* ipconfigUSE_TCP */
-
-/*_RB_ Should this be part of the public API? */
-void FreeRTOS_netstat( void );
-
-/* Returns pdTRUE is this function is called from the IP-task */
-BaseType_t xIsCallingFromIPTask( void );
-
-#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
-
-typedef struct xSOCKET_SET
-{
- EventGroupHandle_t xSelectGroup;
- BaseType_t bApiCalled; /* True if the API was calling the private vSocketSelect */
- FreeRTOS_Socket_t *pxSocket;
-} SocketSelect_t;
-
-extern void vSocketSelect( SocketSelect_t *pxSocketSelect );
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
-
-void vIPSetDHCPTimerEnableState( BaseType_t xEnableState );
-void vIPReloadDHCPTimer( uint32_t ulLeaseTime );
-#if( ipconfigDNS_USE_CALLBACKS != 0 )
- void vIPReloadDNSTimer( uint32_t ulCheckTime );
- void vIPSetDnsTimerEnableState( BaseType_t xEnableState );
-#endif
-
-/* Send the network-up event and start the ARP timer. */
-void vIPNetworkUpCalls( void );
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* FREERTOS_IP_PRIVATE_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h
deleted file mode 100755
index 657757d..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_SOCKETS_H
-#define FREERTOS_SOCKETS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Standard includes. */
-#include
-
-/* Application level configuration options. */
-#include "FreeRTOSIPConfig.h"
-
-#ifndef FREERTOS_IP_CONFIG_H
- #error FreeRTOSIPConfig.h has not been included yet
-#endif
-
-/* Event bit definitions are required by the select functions. */
-#include "event_groups.h"
-
-#ifndef INC_FREERTOS_H
- #error FreeRTOS.h must be included before FreeRTOS_Sockets.h.
-#endif
-
-#ifndef INC_TASK_H
- #ifndef TASK_H /* For compatibility with older FreeRTOS versions. */
- #error The FreeRTOS header file task.h must be included before FreeRTOS_Sockets.h.
- #endif
-#endif
-
-/* Assigned to an Socket_t variable when the socket is not valid, probably
-because it could not be created. */
-#define FREERTOS_INVALID_SOCKET ( ( void * ) ~0U )
-
-/* API function error values. As errno is supported, the FreeRTOS sockets
-functions return error codes rather than just a pass or fail indication. */
-/* HT: Extended the number of error codes, gave them positive values and if possible
-the corresponding found in errno.h
-In case of an error, API's will still return negative numbers, e.g.
- return -pdFREERTOS_ERRNO_EWOULDBLOCK;
-in case an operation would block */
-
-/* The following defines are obsolete, please use -pdFREERTOS_ERRNO_Exxx */
-
-#define FREERTOS_SOCKET_ERROR ( -1 )
-#define FREERTOS_EWOULDBLOCK ( - pdFREERTOS_ERRNO_EWOULDBLOCK )
-#define FREERTOS_EINVAL ( - pdFREERTOS_ERRNO_EINVAL )
-#define FREERTOS_EADDRNOTAVAIL ( - pdFREERTOS_ERRNO_EADDRNOTAVAIL )
-#define FREERTOS_EADDRINUSE ( - pdFREERTOS_ERRNO_EADDRINUSE )
-#define FREERTOS_ENOBUFS ( - pdFREERTOS_ERRNO_ENOBUFS )
-#define FREERTOS_ENOPROTOOPT ( - pdFREERTOS_ERRNO_ENOPROTOOPT )
-#define FREERTOS_ECLOSED ( - pdFREERTOS_ERRNO_ENOTCONN )
-
-/* Values for the parameters to FreeRTOS_socket(), inline with the Berkeley
-standard. See the documentation of FreeRTOS_socket() for more information. */
-#define FREERTOS_AF_INET ( 2 )
-#define FREERTOS_AF_INET6 ( 10 )
-#define FREERTOS_SOCK_DGRAM ( 2 )
-#define FREERTOS_IPPROTO_UDP ( 17 )
-
-#define FREERTOS_SOCK_STREAM ( 1 )
-#define FREERTOS_IPPROTO_TCP ( 6 )
-/* IP packet of type "Any local network"
- * can be used in stead of TCP for testing with sockets in raw mode
- */
-#define FREERTOS_IPPROTO_USR_LAN ( 63 )
-
-/* A bit value that can be passed into the FreeRTOS_sendto() function as part of
-the flags parameter. Setting the FREERTOS_ZERO_COPY in the flags parameter
-indicates that the zero copy interface is being used. See the documentation for
-FreeRTOS_sockets() for more information. */
-#define FREERTOS_ZERO_COPY ( 1 )
-
-/* Values that can be passed in the option name parameter of calls to
-FreeRTOS_setsockopt(). */
-#define FREERTOS_SO_RCVTIMEO ( 0 ) /* Used to set the receive time out. */
-#define FREERTOS_SO_SNDTIMEO ( 1 ) /* Used to set the send time out. */
-#define FREERTOS_SO_UDPCKSUM_OUT ( 2 ) /* Used to turn the use of the UDP checksum by a socket on or off. This also doubles as part of an 8-bit bitwise socket option. */
-#if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
- #define FREERTOS_SO_SET_SEMAPHORE ( 3 ) /* Used to set a user's semaphore */
-#endif
-#define FREERTOS_SO_SNDBUF ( 4 ) /* Set the size of the send buffer (TCP only) */
-#define FREERTOS_SO_RCVBUF ( 5 ) /* Set the size of the receive buffer (TCP only) */
-
-#if ipconfigUSE_CALLBACKS == 1
- #define FREERTOS_SO_TCP_CONN_HANDLER ( 6 ) /* Install a callback for (dis) connection events. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- #define FREERTOS_SO_TCP_RECV_HANDLER ( 7 ) /* Install a callback for receiving TCP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- #define FREERTOS_SO_TCP_SENT_HANDLER ( 8 ) /* Install a callback for sending TCP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- #define FREERTOS_SO_UDP_RECV_HANDLER ( 9 ) /* Install a callback for receiving UDP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
- #define FREERTOS_SO_UDP_SENT_HANDLER ( 10 ) /* Install a callback for sending UDP data. Supply pointer to 'F_TCP_UDP_Handler_t' (see below) */
-#endif /* ipconfigUSE_CALLBACKS */
-
-#define FREERTOS_SO_REUSE_LISTEN_SOCKET ( 11 ) /* When a listening socket gets connected, do not create a new one but re-use it */
-#define FREERTOS_SO_CLOSE_AFTER_SEND ( 12 ) /* As soon as the last byte has been transmitted, finalise the connection */
-#define FREERTOS_SO_WIN_PROPERTIES ( 13 ) /* Set all buffer and window properties in one call, parameter is pointer to WinProperties_t */
-#define FREERTOS_SO_SET_FULL_SIZE ( 14 ) /* Refuse to send packets smaller than MSS */
-
-#define FREERTOS_SO_STOP_RX ( 15 ) /* Temporarily hold up reception, used by streaming client */
-
-#if( ipconfigUDP_MAX_RX_PACKETS > 0 )
- #define FREERTOS_SO_UDP_MAX_RX_PACKETS ( 16 ) /* This option helps to limit the maximum number of packets a UDP socket will buffer */
-#endif
-
-#if( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
- #define FREERTOS_SO_WAKEUP_CALLBACK ( 17 )
-#endif
-
-
-#define FREERTOS_NOT_LAST_IN_FRAGMENTED_PACKET ( 0x80 ) /* For internal use only, but also part of an 8-bit bitwise value. */
-#define FREERTOS_FRAGMENTED_PACKET ( 0x40 ) /* For internal use only, but also part of an 8-bit bitwise value. */
-
-/* Values for flag for FreeRTOS_shutdown(). */
-#define FREERTOS_SHUT_RD ( 0 ) /* Not really at this moment, just for compatibility of the interface */
-#define FREERTOS_SHUT_WR ( 1 )
-#define FREERTOS_SHUT_RDWR ( 2 )
-
-/* Values for flag for FreeRTOS_recv(). */
-#define FREERTOS_MSG_OOB ( 2 ) /* process out-of-band data */
-#define FREERTOS_MSG_PEEK ( 4 ) /* peek at incoming message */
-#define FREERTOS_MSG_DONTROUTE ( 8 ) /* send without using routing tables */
-#define FREERTOS_MSG_DONTWAIT ( 16 ) /* Can be used with recvfrom(), sendto(), recv(), and send(). */
-
-typedef struct xWIN_PROPS {
- /* Properties of the Tx buffer and Tx window */
- int32_t lTxBufSize; /* Unit: bytes */
- int32_t lTxWinSize; /* Unit: MSS */
-
- /* Properties of the Rx buffer and Rx window */
- int32_t lRxBufSize; /* Unit: bytes */
- int32_t lRxWinSize; /* Unit: MSS */
-} WinProperties_t;
-
-/* For compatibility with the expected Berkeley sockets naming. */
-#define socklen_t uint32_t
-
-/* For this limited implementation, only two members are required in the
-Berkeley style sockaddr structure. */
-struct freertos_sockaddr
-{
- /* _HT_ On 32- and 64-bit architectures, the addition of the two uint8_t
- fields doesn't make the structure bigger, due to alignment.
- The fields are inserted as a preparation for IPv6. */
-
- /* sin_len and sin_family not used in the IPv4-only release. */
- uint8_t sin_len; /* length of this structure. */
- uint8_t sin_family; /* FREERTOS_AF_INET. */
- uint16_t sin_port;
- uint32_t sin_addr;
-};
-
-#if ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN
-
- #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
- ( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) | \
- ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) | \
- ( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) | \
- ( ( uint32_t ) ( ucOctet0 ) ) )
-
- #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer ) \
- sprintf( ( char * ) ( pucBuffer ), "%u.%u.%u.%u", \
- ( ( unsigned ) ( ( ulIPAddress ) & 0xffUL ) ), \
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 8 ) & 0xffUL ) ), \
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 16 ) & 0xffUL ) ),\
- ( ( unsigned ) ( ( ulIPAddress ) >> 24 ) ) )
-
-#else /* ipconfigBYTE_ORDER */
-
- #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
- ( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) | \
- ( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) | \
- ( ( ( uint32_t ) ( ucOctet2 ) ) << 8UL ) | \
- ( ( uint32_t ) ( ucOctet3 ) ) )
-
- #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer ) \
- sprintf( ( char * ) ( pucBuffer ), "%u.%u.%u.%u", \
- ( ( unsigned ) ( ( ulIPAddress ) >> 24 ) ), \
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 16 ) & 0xffUL ) ),\
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 8 ) & 0xffUL ) ), \
- ( ( unsigned ) ( ( ulIPAddress ) & 0xffUL ) ) )
-
-#endif /* ipconfigBYTE_ORDER */
-
-/* The socket type itself. */
-typedef void *Socket_t;
-
-/* The SocketSet_t type is the equivalent to the fd_set type used by the
-Berkeley API. */
-typedef void *SocketSet_t;
-
-/**
- * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
- * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html
- */
-Socket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol );
-int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength );
-int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t xTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength );
-BaseType_t FreeRTOS_bind( Socket_t xSocket, struct freertos_sockaddr *pxAddress, socklen_t xAddressLength );
-
-/* function to get the local address and IP port */
-size_t FreeRTOS_GetLocalAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress );
-
-/* Made available when ipconfigETHERNET_DRIVER_FILTERS_PACKETS is set to 1. */
-BaseType_t xPortHasUDPSocket( uint16_t usPortNr );
-
-#if ipconfigUSE_TCP == 1
-
-BaseType_t FreeRTOS_connect( Socket_t xClientSocket, struct freertos_sockaddr *pxAddress, socklen_t xAddressLength );
-BaseType_t FreeRTOS_listen( Socket_t xSocket, BaseType_t xBacklog );
-BaseType_t FreeRTOS_recv( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags );
-BaseType_t FreeRTOS_send( Socket_t xSocket, const void *pvBuffer, size_t uxDataLength, BaseType_t xFlags );
-Socket_t FreeRTOS_accept( Socket_t xServerSocket, struct freertos_sockaddr *pxAddress, socklen_t *pxAddressLength );
-BaseType_t FreeRTOS_shutdown (Socket_t xSocket, BaseType_t xHow);
-
-#if( ipconfigSUPPORT_SIGNALS != 0 )
- /* Send a signal to the task which is waiting for a given socket. */
- BaseType_t FreeRTOS_SignalSocket( Socket_t xSocket );
-
- /* Send a signal to the task which reads from this socket (FromISR
- version). */
- BaseType_t FreeRTOS_SignalSocketFromISR( Socket_t xSocket, BaseType_t *pxHigherPriorityTaskWoken );
-#endif /* ipconfigSUPPORT_SIGNALS */
-
-/* Return the remote address and IP port. */
-BaseType_t FreeRTOS_GetRemoteAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress );
-
-/* returns pdTRUE if TCP socket is connected */
-BaseType_t FreeRTOS_issocketconnected( Socket_t xSocket );
-
-/* returns the actual size of MSS being used */
-BaseType_t FreeRTOS_mss( Socket_t xSocket );
-
-/* for internal use only: return the connection status */
-BaseType_t FreeRTOS_connstatus( Socket_t xSocket );
-
-/* Returns the number of bytes that may be added to txStream */
-BaseType_t FreeRTOS_maywrite( Socket_t xSocket );
-
-/*
- * Two helper functions, mostly for testing
- * rx_size returns the number of bytes available in the Rx buffer
- * tx_space returns the free space in the Tx buffer
- */
-BaseType_t FreeRTOS_rx_size( Socket_t xSocket );
-BaseType_t FreeRTOS_tx_space( Socket_t xSocket );
-BaseType_t FreeRTOS_tx_size( Socket_t xSocket );
-
-/* Returns the number of outstanding bytes in txStream. */
-/* The function FreeRTOS_outstanding() was already implemented
-FreeRTOS_tx_size(). */
-#define FreeRTOS_outstanding( xSocket ) FreeRTOS_tx_size( xSocket )
-
-/* Returns the number of bytes in the socket's rxStream. */
-/* The function FreeRTOS_recvcount() was already implemented
-FreeRTOS_rx_size(). */
-#define FreeRTOS_recvcount( xSocket ) FreeRTOS_rx_size( xSocket )
-
-/*
- * For advanced applications only:
- * Get a direct pointer to the circular transmit buffer.
- * '*pxLength' will contain the number of bytes that may be written.
- */
-uint8_t *FreeRTOS_get_tx_head( Socket_t xSocket, BaseType_t *pxLength );
-
-#endif /* ipconfigUSE_TCP */
-
-/*
- * Connect / disconnect handler for a TCP socket
- * For example:
- * static void vMyConnectHandler (Socket_t xSocket, BaseType_t ulConnected)
- * {
- * }
- * F_TCP_UDP_Handler_t xHnd = { vMyConnectHandler };
- * FreeRTOS_setsockopt( sock, 0, FREERTOS_SO_TCP_CONN_HANDLER, ( void * ) &xHnd, sizeof( xHnd ) );
- */
-
-typedef void (* FOnConnected_t )( Socket_t /* xSocket */, BaseType_t /* ulConnected */ );
-
-/*
- * Reception handler for a TCP socket
- * A user-proved function will be called on reception of a message
- * If the handler returns a positive number, the messages will not be stored
- * For example:
- * static BaseType_t xOnTCPReceive( Socket_t xSocket, void * pData, size_t xLength )
- * {
- * // handle the message
- * return 1;
- * }
- * F_TCP_UDP_Handler_t xHand = { xOnTCPReceive };
- * FreeRTOS_setsockopt( sock, 0, FREERTOS_SO_TCP_RECV_HANDLER, ( void * ) &xHand, sizeof( xHand ) );
- */
-typedef BaseType_t (* FOnTCPReceive_t )( Socket_t /* xSocket */, void * /* pData */, size_t /* xLength */ );
-typedef void (* FOnTCPSent_t )( Socket_t /* xSocket */, size_t /* xLength */ );
-
-/*
- * Reception handler for a UDP socket
- * A user-proved function will be called on reception of a message
- * If the handler returns a positive number, the messages will not be stored
- */
-typedef BaseType_t (* FOnUDPReceive_t ) (Socket_t /* xSocket */, void * /* pData */, size_t /* xLength */,
- const struct freertos_sockaddr * /* pxFrom */, const struct freertos_sockaddr * /* pxDest */ );
-typedef void (* FOnUDPSent_t )( Socket_t /* xSocket */, size_t /* xLength */ );
-
-
-typedef union xTCP_UDP_HANDLER
-{
- FOnConnected_t pxOnTCPConnected; /* FREERTOS_SO_TCP_CONN_HANDLER */
- FOnTCPReceive_t pxOnTCPReceive; /* FREERTOS_SO_TCP_RECV_HANDLER */
- FOnTCPSent_t pxOnTCPSent; /* FREERTOS_SO_TCP_SENT_HANDLER */
- FOnUDPReceive_t pxOnUDPReceive; /* FREERTOS_SO_UDP_RECV_HANDLER */
- FOnUDPSent_t pxOnUDPSent; /* FREERTOS_SO_UDP_SENT_HANDLER */
-} F_TCP_UDP_Handler_t;
-
-BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength );
-BaseType_t FreeRTOS_closesocket( Socket_t xSocket );
-uint32_t FreeRTOS_gethostbyname( const char *pcHostName );
-uint32_t FreeRTOS_inet_addr( const char * pcIPAddress );
-
-/*
- * For the web server: borrow the circular Rx buffer for inspection
- * HTML driver wants to see if a sequence of 13/10/13/10 is available
- */
-const struct xSTREAM_BUFFER *FreeRTOS_get_rx_buf( Socket_t xSocket );
-
-void FreeRTOS_netstat( void );
-
-#if ipconfigSUPPORT_SELECT_FUNCTION == 1
-
- /* For FD_SET and FD_CLR, a combination of the following bits can be used: */
-
- typedef enum eSELECT_EVENT {
- eSELECT_READ = 0x0001,
- eSELECT_WRITE = 0x0002,
- eSELECT_EXCEPT = 0x0004,
- eSELECT_INTR = 0x0008,
- eSELECT_ALL = 0x000F,
- /* Reserved for internal use: */
- eSELECT_CALL_IP = 0x0010,
- /* end */
- } eSelectEvent_t;
-
- SocketSet_t FreeRTOS_CreateSocketSet( void );
- void FreeRTOS_DeleteSocketSet( SocketSet_t xSocketSet );
- void FreeRTOS_FD_SET( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xBitsToSet );
- void FreeRTOS_FD_CLR( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xBitsToClear );
- EventBits_t FreeRTOS_FD_ISSET( Socket_t xSocket, SocketSet_t xSocketSet );
- BaseType_t FreeRTOS_select( SocketSet_t xSocketSet, TickType_t xBlockTimeTicks );
-
-#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* FREERTOS_SOCKETS_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h
deleted file mode 100755
index a220577..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/*
- * FreeRTOS_Stream_Buffer.h
- *
- * A cicular character buffer
- * An implementation of a circular buffer without a length field
- * If LENGTH defines the size of the buffer, a maximum of (LENGT-1) bytes can be stored
- * In order to add or read data from the buffer, memcpy() will be called at most 2 times
- */
-
-#ifndef FREERTOS_STREAM_BUFFER_H
-#define FREERTOS_STREAM_BUFFER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct xSTREAM_BUFFER {
- volatile size_t uxTail; /* next item to read */
- volatile size_t uxMid; /* iterator within the valid items */
- volatile size_t uxHead; /* next position store a new item */
- volatile size_t uxFront; /* iterator within the free space */
- size_t LENGTH; /* const value: number of reserved elements */
- uint8_t ucArray[ sizeof( size_t ) ];
-} StreamBuffer_t;
-
-static portINLINE void vStreamBufferClear( StreamBuffer_t *pxBuffer );
-static portINLINE void vStreamBufferClear( StreamBuffer_t *pxBuffer )
-{
- /* Make the circular buffer empty */
- pxBuffer->uxHead = 0u;
- pxBuffer->uxTail = 0u;
- pxBuffer->uxFront = 0u;
- pxBuffer->uxMid = 0u;
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferSpace( const StreamBuffer_t *pxBuffer, const size_t uxLower, const size_t uxUpper );
-static portINLINE size_t uxStreamBufferSpace( const StreamBuffer_t *pxBuffer, const size_t uxLower, const size_t uxUpper )
-{
-/* Returns the space between uxLower and uxUpper, which equals to the distance minus 1 */
-size_t uxCount;
-
- uxCount = pxBuffer->LENGTH + uxUpper - uxLower - 1u;
- if( uxCount >= pxBuffer->LENGTH )
- {
- uxCount -= pxBuffer->LENGTH;
- }
-
- return uxCount;
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferDistance( const StreamBuffer_t *pxBuffer, const size_t uxLower, const size_t uxUpper );
-static portINLINE size_t uxStreamBufferDistance( const StreamBuffer_t *pxBuffer, const size_t uxLower, const size_t uxUpper )
-{
-/* Returns the distance between uxLower and uxUpper */
-size_t uxCount;
-
- uxCount = pxBuffer->LENGTH + uxUpper - uxLower;
- if ( uxCount >= pxBuffer->LENGTH )
- {
- uxCount -= pxBuffer->LENGTH;
- }
-
- return uxCount;
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferGetSpace( const StreamBuffer_t *pxBuffer );
-static portINLINE size_t uxStreamBufferGetSpace( const StreamBuffer_t *pxBuffer )
-{
-/* Returns the number of items which can still be added to uxHead
-before hitting on uxTail */
-size_t uxHead = pxBuffer->uxHead;
-size_t uxTail = pxBuffer->uxTail;
-
- return uxStreamBufferSpace( pxBuffer, uxHead, uxTail );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferFrontSpace( const StreamBuffer_t *pxBuffer );
-static portINLINE size_t uxStreamBufferFrontSpace( const StreamBuffer_t *pxBuffer )
-{
-/* Distance between uxFront and uxTail
-or the number of items which can still be added to uxFront,
-before hitting on uxTail */
-
-size_t uxFront = pxBuffer->uxFront;
-size_t uxTail = pxBuffer->uxTail;
-
- return uxStreamBufferSpace( pxBuffer, uxFront, uxTail );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferGetSize( const StreamBuffer_t *pxBuffer );
-static portINLINE size_t uxStreamBufferGetSize( const StreamBuffer_t *pxBuffer )
-{
-/* Returns the number of items which can be read from uxTail
-before reaching uxHead */
-size_t uxHead = pxBuffer->uxHead;
-size_t uxTail = pxBuffer->uxTail;
-
- return uxStreamBufferDistance( pxBuffer, uxTail, uxHead );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferMidSpace( const StreamBuffer_t *pxBuffer );
-static portINLINE size_t uxStreamBufferMidSpace( const StreamBuffer_t *pxBuffer )
-{
-/* Returns the distance between uxHead and uxMid */
-size_t uxHead = pxBuffer->uxHead;
-size_t uxMid = pxBuffer->uxMid;
-
- return uxStreamBufferDistance( pxBuffer, uxMid, uxHead );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE void vStreamBufferMoveMid( StreamBuffer_t *pxBuffer, size_t uxCount );
-static portINLINE void vStreamBufferMoveMid( StreamBuffer_t *pxBuffer, size_t uxCount )
-{
-/* Increment uxMid, but no further than uxHead */
-size_t uxSize = uxStreamBufferMidSpace( pxBuffer );
-
- if( uxCount > uxSize )
- {
- uxCount = uxSize;
- }
- pxBuffer->uxMid += uxCount;
- if( pxBuffer->uxMid >= pxBuffer->LENGTH )
- {
- pxBuffer->uxMid -= pxBuffer->LENGTH;
- }
-}
-/*-----------------------------------------------------------*/
-static portINLINE BaseType_t xStreamBufferIsEmpty( const StreamBuffer_t *pxBuffer );
-static portINLINE BaseType_t xStreamBufferIsEmpty( const StreamBuffer_t *pxBuffer )
-{
-BaseType_t xReturn;
-
- /* True if no item is available */
- if( pxBuffer->uxHead == pxBuffer->uxTail )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE BaseType_t xStreamBufferIsFull( const StreamBuffer_t *pxBuffer );
-static portINLINE BaseType_t xStreamBufferIsFull( const StreamBuffer_t *pxBuffer )
-{
- /* True if the available space equals zero. */
- return ( BaseType_t ) ( uxStreamBufferGetSpace( pxBuffer ) == 0u );
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t *pxBuffer, const size_t uxLeft, const size_t uxRight );
-static portINLINE BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t *pxBuffer, const size_t uxLeft, const size_t uxRight )
-{
-BaseType_t xReturn;
-size_t uxTail = pxBuffer->uxTail;
-
- /* Returns true if ( uxLeft < uxRight ) */
- if( ( uxLeft < uxTail ) ^ ( uxRight < uxTail ) )
- {
- if( uxRight < uxTail )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
- }
- else
- {
- if( uxLeft <= uxRight )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
- }
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static portINLINE size_t uxStreamBufferGetPtr( StreamBuffer_t *pxBuffer, uint8_t **ppucData );
-static portINLINE size_t uxStreamBufferGetPtr( StreamBuffer_t *pxBuffer, uint8_t **ppucData )
-{
-size_t uxNextTail = pxBuffer->uxTail;
-size_t uxSize = uxStreamBufferGetSize( pxBuffer );
-
- *ppucData = pxBuffer->ucArray + uxNextTail;
-
- return FreeRTOS_min_uint32( uxSize, pxBuffer->LENGTH - uxNextTail );
-}
-
-/*
- * Add bytes to a stream buffer.
- *
- * pxBuffer - The buffer to which the bytes will be added.
- * uxOffset - If uxOffset > 0, data will be written at an offset from uxHead
- * while uxHead will not be moved yet.
- * pucData - A pointer to the data to be added.
- * uxCount - The number of bytes to add.
- */
-size_t uxStreamBufferAdd( StreamBuffer_t *pxBuffer, size_t uxOffset, const uint8_t *pucData, size_t uxCount );
-
-/*
- * Read bytes from a stream buffer.
- *
- * pxBuffer - The buffer from which the bytes will be read.
- * uxOffset - Can be used to read data located at a certain offset from 'uxTail'.
- * pucData - A pointer to the buffer into which data will be read.
- * uxMaxCount - The number of bytes to read.
- * xPeek - If set to pdTRUE the data will remain in the buffer.
- */
-size_t uxStreamBufferGet( StreamBuffer_t *pxBuffer, size_t uxOffset, uint8_t *pucData, size_t uxMaxCount, BaseType_t xPeek );
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* !defined( FREERTOS_STREAM_BUFFER_H ) */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h
deleted file mode 100755
index f792c8a..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_TCP_IP_H
-#define FREERTOS_TCP_IP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer );
-
-typedef enum eTCP_STATE {
- /* Comments about the TCP states are borrowed from the very useful
- * Wiki page:
- * http://en.wikipedia.org/wiki/Transmission_Control_Protocol */
- eCLOSED = 0u, /* 0 (server + client) no connection state at all. */
- eTCP_LISTEN, /* 1 (server) waiting for a connection request
- from any remote TCP and port. */
- eCONNECT_SYN, /* 2 (client) internal state: socket wants to send
- a connect */
- eSYN_FIRST, /* 3 (server) Just created, must ACK the SYN request. */
- eSYN_RECEIVED, /* 4 (server) waiting for a confirming connection request
- acknowledgement after having both received and sent a connection request. */
- eESTABLISHED, /* 5 (server + client) an open connection, data received can be
- delivered to the user. The normal state for the data transfer phase of the connection. */
- eFIN_WAIT_1, /* 6 (server + client) waiting for a connection termination request from the remote TCP,
- or an acknowledgement of the connection termination request previously sent. */
- eFIN_WAIT_2, /* 7 (server + client) waiting for a connection termination request from the remote TCP. */
- eCLOSE_WAIT, /* 8 (server + client) waiting for a connection termination request from the local user. */
- eCLOSING, /* (server + client) waiting for a connection termination request acknowledgement from the remote TCP. */
- eLAST_ACK, /* 9 (server + client) waiting for an acknowledgement of the connection termination request
- previously sent to the remote TCP
- (which includes an acknowledgement of its connection termination request). */
- eTIME_WAIT, /* 10 (either server or client) waiting for enough time to pass to be sure the remote TCP received the
- acknowledgement of its connection termination request. [According to RFC 793 a connection can
- stay in TIME-WAIT for a maximum of four minutes known as a MSL (maximum segment lifetime).] */
-} eIPTCPState_t;
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* FREERTOS_TCP_IP_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h
deleted file mode 100755
index 5019665..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/*
- * FreeRTOS_TCP_WIN.c
- * Module which handles the TCP windowing schemes for FreeRTOS-PLUS-TCP
- */
-
-#ifndef FREERTOS_TCP_WIN_H
-#define FREERTOS_TCP_WIN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern BaseType_t xTCPWindowLoggingLevel;
-
-typedef struct xTCPTimer
-{
- uint32_t ulBorn;
-} TCPTimer_t;
-
-typedef struct xTCP_SEGMENT
-{
- uint32_t ulSequenceNumber; /* The sequence number of the first byte in this packet */
- int32_t lMaxLength; /* Maximum space, number of bytes which can be stored in this segment */
- int32_t lDataLength; /* Actual number of bytes */
- int32_t lStreamPos; /* reference to the [t|r]xStream of the socket */
- TCPTimer_t xTransmitTimer; /* saves a timestamp at the moment this segment gets transmitted (TX only) */
- union
- {
- struct
- {
- uint32_t
- ucTransmitCount : 8,/* Number of times the segment has been transmitted, used to calculate the RTT */
- ucDupAckCount : 8, /* Counts the number of times that a higher segment was ACK'd. After 3 times a Fast Retransmission takes place */
- bOutstanding : 1, /* It the peer's turn, we're just waiting for an ACK */
- bAcked : 1, /* This segment has been acknowledged */
- bIsForRx : 1; /* pdTRUE if segment is used for reception */
- } bits;
- uint32_t ulFlags;
- } u;
-#if( ipconfigUSE_TCP_WIN != 0 )
- struct xLIST_ITEM xQueueItem; /* TX only: segments can be linked in one of three queues: xPriorityQueue, xTxQueue, and xWaitQueue */
- struct xLIST_ITEM xListItem; /* With this item the segment can be connected to a list, depending on who is owning it */
-#endif
-} TCPSegment_t;
-
-typedef struct xTCP_WINSIZE
-{
- uint32_t ulRxWindowLength;
- uint32_t ulTxWindowLength;
-} TCPWinSize_t;
-
-/*
- * If TCP time-stamps are being used, they will occupy 12 bytes in
- * each packet, and thus the message space will become smaller
- */
-/* Keep this as a multiple of 4 */
-#if( ipconfigUSE_TCP_WIN == 1 )
- #define ipSIZE_TCP_OPTIONS 16u
-#else
- #define ipSIZE_TCP_OPTIONS 12u
-#endif
-
-/*
- * Every TCP connection owns a TCP window for the administration of all packets
- * It owns two sets of segment descriptors, incoming and outgoing
- */
-typedef struct xTCP_WINDOW
-{
- union
- {
- struct
- {
- uint32_t
- bHasInit : 1, /* The window structure has been initialised */
- bSendFullSize : 1, /* May only send packets with a size equal to MSS (for optimisation) */
- bTimeStamps : 1; /* Socket is supposed to use TCP time-stamps. This depends on the */
- } bits; /* party which opens the connection */
- uint32_t ulFlags;
- } u;
- TCPWinSize_t xSize;
- struct
- {
- uint32_t ulFirstSequenceNumber; /* Logging & debug: the first segment received/sent in this connection
- * for Tx: initial send sequence number (ISS)
- * for Rx: initial receive sequence number (IRS) */
- uint32_t ulCurrentSequenceNumber;/* Tx/Rx: the oldest sequence number not yet confirmed, also SND.UNA / RCV.NXT
- * In other words: the sequence number of the left side of the sliding window */
- uint32_t ulFINSequenceNumber; /* The sequence number which carried the FIN flag */
- uint32_t ulHighestSequenceNumber;/* Sequence number of the right-most byte + 1 */
- } rx, tx;
- uint32_t ulOurSequenceNumber; /* The SEQ number we're sending out */
- uint32_t ulUserDataLength; /* Number of bytes in Rx buffer which may be passed to the user, after having received a 'missing packet' */
- uint32_t ulNextTxSequenceNumber; /* The sequence number given to the next byte to be added for transmission */
- int32_t lSRTT; /* Smoothed Round Trip Time, it may increment quickly and it decrements slower */
- uint8_t ucOptionLength; /* Number of valid bytes in ulOptionsData[] */
-#if( ipconfigUSE_TCP_WIN == 1 )
- List_t xPriorityQueue; /* Priority queue: segments which must be sent immediately */
- List_t xTxQueue; /* Transmit queue: segments queued for transmission */
- List_t xWaitQueue; /* Waiting queue: outstanding segments */
- TCPSegment_t *pxHeadSegment; /* points to a segment which has not been transmitted and it's size is still growing (user data being added) */
- uint32_t ulOptionsData[ipSIZE_TCP_OPTIONS/sizeof(uint32_t)]; /* Contains the options we send out */
- List_t xTxSegments; /* A linked list of all transmission segments, sorted on sequence number */
- List_t xRxSegments; /* A linked list of reception segments, order depends on sequence of arrival */
-#else
- /* For tiny TCP, there is only 1 outstanding TX segment */
- TCPSegment_t xTxSegment; /* Priority queue */
-#endif
- uint16_t usOurPortNumber; /* Mostly for debugging/logging: our TCP port number */
- uint16_t usPeerPortNumber; /* debugging/logging: the peer's TCP port number */
- uint16_t usMSS; /* Current accepted MSS */
- uint16_t usMSSInit; /* MSS as configured by the socket owner */
-} TCPWindow_t;
-
-
-/*=============================================================================
- *
- * Creation and destruction
- *
- *=============================================================================*/
-
-/* Create and initialize a window */
-void vTCPWindowCreate( TCPWindow_t *pxWindow, uint32_t ulRxWindowLength,
- uint32_t ulTxWindowLength, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS );
-
-/* Destroy a window (always returns NULL)
- * It will free some resources: a collection of segments */
-void vTCPWindowDestroy( TCPWindow_t *pxWindow );
-
-/* Initialize a window */
-void vTCPWindowInit( TCPWindow_t *pxWindow, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS );
-
-/*=============================================================================
- *
- * Rx functions
- *
- *=============================================================================*/
-
-/* if true may be passed directly to user (segment expected and window is empty)
- * But pxWindow->ackno should always be used to set "BUF->ackno" */
-int32_t lTCPWindowRxCheck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength, uint32_t ulSpace );
-
-/* When lTCPWindowRxCheck returned false, please call store for this unexpected data */
-BaseType_t xTCPWindowRxStore( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength );
-
-/* This function will be called as soon as a FIN is received. It will return true
- * if there are no 'open' reception segments */
-BaseType_t xTCPWindowRxEmpty( TCPWindow_t *pxWindow );
-
-/* _HT_ Temporary function for testing/debugging
- * Not used at this moment */
-void vTCPWinShowSegments( TCPWindow_t *pxWindow, BaseType_t bForRx );
-
-/*=============================================================================
- *
- * Tx functions
- *
- *=============================================================================*/
-
-/* Adds data to the Tx-window */
-int32_t lTCPWindowTxAdd( TCPWindow_t *pxWindow, uint32_t ulLength, int32_t lPosition, int32_t lMax );
-
-/* Check data to be sent and calculate the time period we may sleep */
-BaseType_t xTCPWindowTxHasData( TCPWindow_t *pxWindow, uint32_t ulWindowSize, TickType_t *pulDelay );
-
-/* See if anything is left to be sent
- * Function will be called when a FIN has been received. Only when the TX window is clean,
- * it will return pdTRUE */
-BaseType_t xTCPWindowTxDone( TCPWindow_t *pxWindow );
-
-/* Fetches data to be sent.
- * apPos will point to a location with the circular data buffer: txStream */
-uint32_t ulTCPWindowTxGet( TCPWindow_t *pxWindow, uint32_t ulWindowSize, int32_t *plPosition );
-
-/* Receive a normal ACK */
-uint32_t ulTCPWindowTxAck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber );
-
-/* Receive a SACK option */
-uint32_t ulTCPWindowTxSack( TCPWindow_t *pxWindow, uint32_t ulFirst, uint32_t ulLast );
-
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* FREERTOS_TCP_WIN_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h
deleted file mode 100755
index 71020bd..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef FREERTOS_ERRNO_TCP
-#define FREERTOS_ERRNO_TCP
-
-/* The following definitions will be included in the core FreeRTOS code in
-future versions of FreeRTOS - hence the 'pd' (ProjDefs) prefix - at which time
-this file will be removed. */
-
-/* The following errno values are used by FreeRTOS+ components, not FreeRTOS
-itself. */
-
-/* For future compatibility (see comment above), check the definitions have not
-already been made. */
-#ifndef pdFREERTOS_ERRNO_NONE
- #define pdFREERTOS_ERRNO_NONE 0 /* No errors */
- #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */
- #define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */
- #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */
- #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */
- #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */
- #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */
- #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */
- #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */
- #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */
- #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */
- #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */
- #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */
- #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */
- #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */
- #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */
- #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */
- #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */
- #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */
- #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */
- #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */
- #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */
- #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */
- #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */
- #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */
- #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */
- #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */
- #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
- #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */
- #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */
- #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */
- #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */
- #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */
- #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */
- #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */
- #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */
- #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */
- #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */
- #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */
- #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */
-
- /* The following endian values are used by FreeRTOS+ components, not FreeRTOS
- itself. */
- #define pdFREERTOS_LITTLE_ENDIAN 0
- #define pdFREERTOS_BIG_ENDIAN 1
-
-#endif /* pdFREERTOS_ERRNO_NONE */
-
-#endif /* FREERTOS_ERRNO_TCP */
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h
deleted file mode 100755
index e9ad503..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-/* This file provides default (empty) implementations for any IP trace macros
-that are not defined by the user. See
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Trace.html */
-
-#ifndef UDP_TRACE_MACRO_DEFAULTS_H
-#define UDP_TRACE_MACRO_DEFAULTS_H
-
-#ifndef iptraceNETWORK_DOWN
- #define iptraceNETWORK_DOWN()
-#endif
-
-#ifndef iptraceNETWORK_BUFFER_RELEASED
- #define iptraceNETWORK_BUFFER_RELEASED( pxBufferAddress )
-#endif
-
-#ifndef iptraceNETWORK_BUFFER_OBTAINED
- #define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress )
-#endif
-
-#ifndef iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR
- #define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress )
-#endif
-
-#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER
- #define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER()
-#endif
-
-#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR
- #define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR()
-#endif
-
-#ifndef iptraceCREATING_ARP_REQUEST
- #define iptraceCREATING_ARP_REQUEST( ulIPAddress )
-#endif
-
-#ifndef iptraceARP_TABLE_ENTRY_WILL_EXPIRE
- #define iptraceARP_TABLE_ENTRY_WILL_EXPIRE( ulIPAddress )
-#endif
-
-#ifndef iptraceARP_TABLE_ENTRY_EXPIRED
- #define iptraceARP_TABLE_ENTRY_EXPIRED( ulIPAddress )
-#endif
-
-#ifndef iptraceARP_TABLE_ENTRY_CREATED
- #define iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, ucMACAddress )
-#endif
-
-#ifndef iptraceSENDING_UDP_PACKET
- #define iptraceSENDING_UDP_PACKET( ulIPAddress )
-#endif
-
-#ifndef iptracePACKET_DROPPED_TO_GENERATE_ARP
- #define iptracePACKET_DROPPED_TO_GENERATE_ARP( ulIPAddress )
-#endif
-
-#ifndef iptraceICMP_PACKET_RECEIVED
- #define iptraceICMP_PACKET_RECEIVED()
-#endif
-
-#ifndef iptraceSENDING_PING_REPLY
- #define iptraceSENDING_PING_REPLY( ulIPAddress )
-#endif
-
-#ifndef traceARP_PACKET_RECEIVED
- #define traceARP_PACKET_RECEIVED()
-#endif
-
-#ifndef iptracePROCESSING_RECEIVED_ARP_REPLY
- #define iptracePROCESSING_RECEIVED_ARP_REPLY( ulIPAddress )
-#endif
-
-#ifndef iptraceSENDING_ARP_REPLY
- #define iptraceSENDING_ARP_REPLY( ulIPAddress )
-#endif
-
-#ifndef iptraceFAILED_TO_CREATE_SOCKET
- #define iptraceFAILED_TO_CREATE_SOCKET()
-#endif
-
-#ifndef iptraceFAILED_TO_CREATE_EVENT_GROUP
- #define iptraceFAILED_TO_CREATE_EVENT_GROUP()
-#endif
-
-#ifndef iptraceRECVFROM_DISCARDING_BYTES
- #define iptraceRECVFROM_DISCARDING_BYTES( xNumberOfBytesDiscarded )
-#endif
-
-#ifndef iptraceETHERNET_RX_EVENT_LOST
- #define iptraceETHERNET_RX_EVENT_LOST()
-#endif
-
-#ifndef iptraceSTACK_TX_EVENT_LOST
- #define iptraceSTACK_TX_EVENT_LOST( xEvent )
-#endif
-
-#ifndef iptraceNETWORK_EVENT_RECEIVED
- #define iptraceNETWORK_EVENT_RECEIVED( eEvent )
-#endif
-
-#ifndef iptraceBIND_FAILED
- #define iptraceBIND_FAILED( xSocket, usPort )
-#endif
-
-#ifndef iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
- #define iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS( ulIPAddress )
-#endif
-
-#ifndef iptraceSENDING_DHCP_DISCOVER
- #define iptraceSENDING_DHCP_DISCOVER()
-#endif
-
-#ifndef iptraceSENDING_DHCP_REQUEST
- #define iptraceSENDING_DHCP_REQUEST()
-#endif
-
-#ifndef iptraceDHCP_SUCCEDEED
- #define iptraceDHCP_SUCCEDEED( address )
-#endif
-
-#ifndef iptraceNETWORK_INTERFACE_TRANSMIT
- #define iptraceNETWORK_INTERFACE_TRANSMIT()
-#endif
-
-#ifndef iptraceNETWORK_INTERFACE_RECEIVE
- #define iptraceNETWORK_INTERFACE_RECEIVE()
-#endif
-
-#ifndef iptraceSENDING_DNS_REQUEST
- #define iptraceSENDING_DNS_REQUEST()
-#endif
-
-#ifndef iptraceWAITING_FOR_TX_DMA_DESCRIPTOR
- #define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR()
-#endif
-
-#ifndef ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS
- #define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS 0
-#endif
-
-#ifndef iptraceFAILED_TO_NOTIFY_SELECT_GROUP
- #define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket )
-#endif
-
-#ifndef pvPortMallocSocket
- #define pvPortMallocSocket(xSize) pvPortMalloc( ( xSize ) )
-#endif
-
-#ifndef iptraceRECVFROM_TIMEOUT
- #define iptraceRECVFROM_TIMEOUT()
-#endif
-
-#ifndef iptraceRECVFROM_INTERRUPTED
- #define iptraceRECVFROM_INTERRUPTED()
-#endif
-
-#ifndef iptraceNO_BUFFER_FOR_SENDTO
- #define iptraceNO_BUFFER_FOR_SENDTO()
-#endif
-
-#ifndef iptraceSENDTO_SOCKET_NOT_BOUND
- #define iptraceSENDTO_SOCKET_NOT_BOUND()
-#endif
-
-#ifndef iptraceSENDTO_DATA_TOO_LONG
- #define iptraceSENDTO_DATA_TOO_LONG()
-#endif
-
-#endif /* UDP_TRACE_MACRO_DEFAULTS_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h
deleted file mode 100755
index ededc40..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-#ifndef NETWORK_BUFFER_MANAGEMENT_H
-#define NETWORK_BUFFER_MANAGEMENT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* NOTE PUBLIC API FUNCTIONS. */
-BaseType_t xNetworkBuffersInitialise( void );
-NetworkBufferDescriptor_t *pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks );
-NetworkBufferDescriptor_t *pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes );
-void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer );
-BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer );
-uint8_t *pucGetNetworkBuffer( size_t *pxRequestedSizeBytes );
-void vReleaseNetworkBuffer( uint8_t *pucEthernetBuffer );
-
-/* Get the current number of free network buffers. */
-UBaseType_t uxGetNumberOfFreeNetworkBuffers( void );
-
-/* Get the lowest number of free network buffers. */
-UBaseType_t uxGetMinimumFreeNetworkBuffers( void );
-
-/* Copy a network buffer into a bigger buffer. */
-NetworkBufferDescriptor_t *pxDuplicateNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer,
- BaseType_t xNewLength);
-
-/* Increase the size of a Network Buffer.
-In case BufferAllocation_2.c is used, the new space must be allocated. */
-NetworkBufferDescriptor_t *pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer,
- size_t xNewSizeBytes );
-
-#if ipconfigTCP_IP_SANITY
- /*
- * Check if an address is a valid pointer to a network descriptor
- * by looking it up in the array of network descriptors
- */
- UBaseType_t bIsValidNetworkDescriptor (const NetworkBufferDescriptor_t * pxDesc);
- BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t *pxDescr );
-#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* NETWORK_BUFFER_MANAGEMENT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c
deleted file mode 100755
index e1fa9a7..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/******************************************************************************
- *
- * See the following web page for essential buffer allocation scheme usage and
- * configuration details:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html
- *
- ******************************************************************************/
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-
-/* For an Ethernet interrupt to be able to obtain a network buffer there must
-be at least this number of buffers available. */
-#define baINTERRUPT_BUFFER_GET_THRESHOLD ( 3 )
-
-/* A list of free (available) NetworkBufferDescriptor_t structures. */
-static List_t xFreeBuffersList;
-
-/* Some statistics about the use of buffers. */
-static UBaseType_t uxMinimumFreeNetworkBuffers = 0u;
-
-/* Declares the pool of NetworkBufferDescriptor_t structures that are available
-to the system. All the network buffers referenced from xFreeBuffersList exist
-in this array. The array is not accessed directly except during initialisation,
-when the xFreeBuffersList is filled (as all the buffers are free when the system
-is booted). */
-static NetworkBufferDescriptor_t xNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ];
-
-/* This constant is defined as true to let FreeRTOS_TCP_IP.c know that the
-network buffers have constant size, large enough to hold the biggest Ethernet
-packet. No resizing will be done. */
-const BaseType_t xBufferAllocFixedSize = pdTRUE;
-
-/* The semaphore used to obtain network buffers. */
-static SemaphoreHandle_t xNetworkBufferSemaphore = NULL;
-
-#if( ipconfigTCP_IP_SANITY != 0 )
- static char cIsLow = pdFALSE;
- UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc );
-#else
- static UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc );
-#endif /* ipconfigTCP_IP_SANITY */
-
-static void prvShowWarnings( void );
-
-/* The user can define their own ipconfigBUFFER_ALLOC_LOCK() and
-ipconfigBUFFER_ALLOC_UNLOCK() macros, especially for use form an ISR. If these
-are not defined then default them to call the normal enter/exit critical
-section macros. */
-#if !defined( ipconfigBUFFER_ALLOC_LOCK )
-
- #define ipconfigBUFFER_ALLOC_INIT( ) do {} while (0)
- #define ipconfigBUFFER_ALLOC_LOCK_FROM_ISR() \
- UBaseType_t uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \
- {
-
- #define ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR() \
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
- }
-
- #define ipconfigBUFFER_ALLOC_LOCK() taskENTER_CRITICAL()
- #define ipconfigBUFFER_ALLOC_UNLOCK() taskEXIT_CRITICAL()
-
-#endif /* ipconfigBUFFER_ALLOC_LOCK */
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigTCP_IP_SANITY != 0 )
-
- /* HT: SANITY code will be removed as soon as the library is stable
- * and and ready to become public
- * Function below gives information about the use of buffers */
- #define WARN_LOW ( 2 )
- #define WARN_HIGH ( ( 5 * ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) / 10 )
-
-#endif /* ipconfigTCP_IP_SANITY */
-
-/*-----------------------------------------------------------*/
-
-#if( ipconfigTCP_IP_SANITY != 0 )
-
- BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t *pxDescr )
- {
- return ( bIsValidNetworkDescriptor( pxDescr ) != 0 ) &&
- ( listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxDescr->xBufferListItem ) ) != 0 );
- }
- /*-----------------------------------------------------------*/
-
- static void prvShowWarnings( void )
- {
- UBaseType_t uxCount = uxGetNumberOfFreeNetworkBuffers( );
- if( ( ( cIsLow == 0 ) && ( uxCount <= WARN_LOW ) ) || ( ( cIsLow != 0 ) && ( uxCount >= WARN_HIGH ) ) )
- {
- cIsLow = !cIsLow;
- FreeRTOS_debug_printf( ( "*** Warning *** %s %lu buffers left\n", cIsLow ? "only" : "now", uxCount ) );
- }
- }
- /*-----------------------------------------------------------*/
-
- UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc )
- {
- uint32_t offset = ( uint32_t ) ( ((const char *)pxDesc) - ((const char *)xNetworkBuffers) );
- if( ( offset >= sizeof( xNetworkBuffers ) ) ||
- ( ( offset % sizeof( xNetworkBuffers[0] ) ) != 0 ) )
- return pdFALSE;
- return (UBaseType_t) (pxDesc - xNetworkBuffers) + 1;
- }
- /*-----------------------------------------------------------*/
-
-#else
- static UBaseType_t bIsValidNetworkDescriptor (const NetworkBufferDescriptor_t * pxDesc)
- {
- ( void ) pxDesc;
- return ( UBaseType_t ) pdTRUE;
- }
- /*-----------------------------------------------------------*/
-
- static void prvShowWarnings( void )
- {
- }
- /*-----------------------------------------------------------*/
-
-#endif /* ipconfigTCP_IP_SANITY */
-
-BaseType_t xNetworkBuffersInitialise( void )
-{
-BaseType_t xReturn, x;
-
- /* Only initialise the buffers and their associated kernel objects if they
- have not been initialised before. */
- if( xNetworkBufferSemaphore == NULL )
- {
- /* In case alternative locking is used, the mutexes can be initialised
- here */
- ipconfigBUFFER_ALLOC_INIT();
-
- xNetworkBufferSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
- configASSERT( xNetworkBufferSemaphore );
-
- if( xNetworkBufferSemaphore != NULL )
- {
- vListInitialise( &xFreeBuffersList );
-
- /* Initialise all the network buffers. The buffer storage comes
- from the network interface, and different hardware has different
- requirements. */
- vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
- for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
- {
- /* Initialise and set the owner of the buffer list items. */
- vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) );
- listSET_LIST_ITEM_OWNER( &( xNetworkBuffers[ x ].xBufferListItem ), &xNetworkBuffers[ x ] );
-
- /* Currently, all buffers are available for use. */
- vListInsert( &xFreeBuffersList, &( xNetworkBuffers[ x ].xBufferListItem ) );
- }
-
- uxMinimumFreeNetworkBuffers = ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
- }
- }
-
- if( xNetworkBufferSemaphore == NULL )
- {
- xReturn = pdFAIL;
- }
- else
- {
- xReturn = pdPASS;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks )
-{
-NetworkBufferDescriptor_t *pxReturn = NULL;
-BaseType_t xInvalid = pdFALSE;
-UBaseType_t uxCount;
-
- /* The current implementation only has a single size memory block, so
- the requested size parameter is not used (yet). */
- ( void ) xRequestedSizeBytes;
-
- if( xNetworkBufferSemaphore != NULL )
- {
- /* If there is a semaphore available, there is a network buffer
- available. */
- if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS )
- {
- /* Protect the structure as they are accessed from tasks and
- interrupts. */
- ipconfigBUFFER_ALLOC_LOCK();
- {
- pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );
-
- if( ( bIsValidNetworkDescriptor( pxReturn ) != pdFALSE_UNSIGNED ) &&
- listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxReturn->xBufferListItem ) ) )
- {
- uxListRemove( &( pxReturn->xBufferListItem ) );
- }
- else
- {
- xInvalid = pdTRUE;
- }
- }
- ipconfigBUFFER_ALLOC_UNLOCK();
-
- if( xInvalid == pdTRUE )
- {
- /* _RB_ Can printf() be called from an interrupt? (comment
- above says this can be called from an interrupt too) */
- /* _HT_ The function shall not be called from an ISR. Comment
- was indeed misleading. Hopefully clear now?
- So the printf()is OK here. */
- FreeRTOS_debug_printf( ( "pxGetNetworkBufferWithDescriptor: INVALID BUFFER: %p (valid %lu)\n",
- pxReturn, bIsValidNetworkDescriptor( pxReturn ) ) );
- pxReturn = NULL;
- }
- else
- {
- /* Reading UBaseType_t, no critical section needed. */
- uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList );
-
- /* For stats, latch the lowest number of network buffers since
- booting. */
- if( uxMinimumFreeNetworkBuffers > uxCount )
- {
- uxMinimumFreeNetworkBuffers = uxCount;
- }
-
- pxReturn->xDataLength = xRequestedSizeBytes;
-
- #if( ipconfigTCP_IP_SANITY != 0 )
- {
- prvShowWarnings();
- }
- #endif /* ipconfigTCP_IP_SANITY */
-
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- {
- /* make sure the buffer is not linked */
- pxReturn->pxNextBuffer = NULL;
- }
- #endif /* ipconfigUSE_LINKED_RX_MESSAGES */
-
- if( xTCPWindowLoggingLevel > 3 )
- {
- FreeRTOS_debug_printf( ( "BUF_GET[%ld]: %p (%p)\n",
- bIsValidNetworkDescriptor( pxReturn ),
- pxReturn, pxReturn->pucEthernetBuffer ) );
- }
- }
- iptraceNETWORK_BUFFER_OBTAINED( pxReturn );
- }
- else
- {
- iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER();
- }
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes )
-{
-NetworkBufferDescriptor_t *pxReturn = NULL;
-
- /* The current implementation only has a single size memory block, so
- the requested size parameter is not used (yet). */
- ( void ) xRequestedSizeBytes;
-
- /* If there is a semaphore available then there is a buffer available, but,
- as this is called from an interrupt, only take a buffer if there are at
- least baINTERRUPT_BUFFER_GET_THRESHOLD buffers remaining. This prevents,
- to a certain degree at least, a rapidly executing interrupt exhausting
- buffer and in so doing preventing tasks from continuing. */
- if( uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) xNetworkBufferSemaphore ) > ( UBaseType_t ) baINTERRUPT_BUFFER_GET_THRESHOLD )
- {
- if( xSemaphoreTakeFromISR( xNetworkBufferSemaphore, NULL ) == pdPASS )
- {
- /* Protect the structure as it is accessed from tasks and interrupts. */
- ipconfigBUFFER_ALLOC_LOCK_FROM_ISR();
- {
- pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );
- uxListRemove( &( pxReturn->xBufferListItem ) );
- }
- ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR();
-
- iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxReturn );
- }
- }
-
- if( pxReturn == NULL )
- {
- iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR();
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* Ensure the buffer is returned to the list of free buffers before the
- counting semaphore is 'given' to say a buffer is available. */
- ipconfigBUFFER_ALLOC_LOCK_FROM_ISR();
- {
- vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
- }
- ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR();
-
- xSemaphoreGiveFromISR( xNetworkBufferSemaphore, &xHigherPriorityTaskWoken );
- iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer );
-
- return xHigherPriorityTaskWoken;
-}
-/*-----------------------------------------------------------*/
-
-void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-BaseType_t xListItemAlreadyInFreeList;
-
- if( bIsValidNetworkDescriptor( pxNetworkBuffer ) == pdFALSE_UNSIGNED )
- {
- FreeRTOS_debug_printf( ( "vReleaseNetworkBufferAndDescriptor: Invalid buffer %p\n", pxNetworkBuffer ) );
- return ;
- }
- /* Ensure the buffer is returned to the list of free buffers before the
- counting semaphore is 'given' to say a buffer is available. */
- ipconfigBUFFER_ALLOC_LOCK();
- {
- {
- xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
-
- if( xListItemAlreadyInFreeList == pdFALSE )
- {
- vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
- }
- }
- }
- ipconfigBUFFER_ALLOC_UNLOCK();
-
- if( xListItemAlreadyInFreeList )
- {
- FreeRTOS_debug_printf( ( "vReleaseNetworkBufferAndDescriptor: %p ALREADY RELEASED (now %lu)\n",
- pxNetworkBuffer, uxGetNumberOfFreeNetworkBuffers( ) ) );
- }
- if( xListItemAlreadyInFreeList == pdFALSE )
- {
- xSemaphoreGive( xNetworkBufferSemaphore );
- prvShowWarnings();
- if( xTCPWindowLoggingLevel > 3 )
- FreeRTOS_debug_printf( ( "BUF_PUT[%ld]: %p (%p) (now %lu)\n",
- bIsValidNetworkDescriptor( pxNetworkBuffer ),
- pxNetworkBuffer, pxNetworkBuffer->pucEthernetBuffer,
- uxGetNumberOfFreeNetworkBuffers( ) ) );
- }
- iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer );
-}
-/*-----------------------------------------------------------*/
-
-UBaseType_t uxGetMinimumFreeNetworkBuffers( void )
-{
- return uxMinimumFreeNetworkBuffers;
-}
-/*-----------------------------------------------------------*/
-
-UBaseType_t uxGetNumberOfFreeNetworkBuffers( void )
-{
- return listCURRENT_LIST_LENGTH( &xFreeBuffersList );
-}
-
-NetworkBufferDescriptor_t *pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, size_t xNewSizeBytes )
-{
- /* In BufferAllocation_1.c all network buffer are allocated with a
- maximum size of 'ipTOTAL_ETHERNET_FRAME_SIZE'.No need to resize the
- network buffer. */
- ( void ) xNewSizeBytes;
- return pxNetworkBuffer;
-}
-
-/*#endif */ /* ipconfigINCLUDE_TEST_CODE */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
deleted file mode 100755
index 415aeb3..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.7
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-/******************************************************************************
- *
- * See the following web page for essential buffer allocation scheme usage and
- * configuration details:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html
- *
- ******************************************************************************/
-
-/* THIS FILE SHOULD NOT BE USED IF THE PROJECT INCLUDES A MEMORY ALLOCATOR
-THAT WILL FRAGMENT THE HEAP MEMORY. For example, heap_2 must not be used,
-heap_4 can be used. */
-
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-
-/* The obtained network buffer must be large enough to hold a packet that might
-replace the packet that was requested to be sent. */
-#if ipconfigUSE_TCP == 1
- #define baMINIMAL_BUFFER_SIZE sizeof( TCPPacket_t )
-#else
- #define baMINIMAL_BUFFER_SIZE sizeof( ARPPacket_t )
-#endif /* ipconfigUSE_TCP == 1 */
-
-/*_RB_ This is too complex not to have an explanation. */
-#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
- #define ASSERT_CONCAT_(a, b) a##b
- #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b)
- #define STATIC_ASSERT(e) \
- ;enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }
-
- STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE );
-#endif
-
-/* A list of free (available) NetworkBufferDescriptor_t structures. */
-static List_t xFreeBuffersList;
-
-/* Some statistics about the use of buffers. */
-static size_t uxMinimumFreeNetworkBuffers;
-
-/* Declares the pool of NetworkBufferDescriptor_t structures that are available
-to the system. All the network buffers referenced from xFreeBuffersList exist
-in this array. The array is not accessed directly except during initialisation,
-when the xFreeBuffersList is filled (as all the buffers are free when the system
-is booted). */
-static NetworkBufferDescriptor_t xNetworkBufferDescriptors[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ];
-
-/* This constant is defined as false to let FreeRTOS_TCP_IP.c know that the
-network buffers have a variable size: resizing may be necessary */
-const BaseType_t xBufferAllocFixedSize = pdFALSE;
-
-/* The semaphore used to obtain network buffers. */
-static SemaphoreHandle_t xNetworkBufferSemaphore = NULL;
-
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkBuffersInitialise( void )
-{
-BaseType_t xReturn, x;
-
- /* Only initialise the buffers and their associated kernel objects if they
- have not been initialised before. */
- if( xNetworkBufferSemaphore == NULL )
- {
- xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
- configASSERT( xNetworkBufferSemaphore );
-
- if( xNetworkBufferSemaphore != NULL )
- {
- #if ( configQUEUE_REGISTRY_SIZE > 0 )
- {
- vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" );
- }
- #endif /* configQUEUE_REGISTRY_SIZE */
-
- /* If the trace recorder code is included name the semaphore for viewing
- in FreeRTOS+Trace. */
- #if( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 )
- {
- extern QueueHandle_t xNetworkEventQueue;
- vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
- vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" );
- }
- #endif /* ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */
-
- vListInitialise( &xFreeBuffersList );
-
- /* Initialise all the network buffers. No storage is allocated to
- the buffers yet. */
- for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
- {
- /* Initialise and set the owner of the buffer list items. */
- xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL;
- vListInitialiseItem( &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
- listSET_LIST_ITEM_OWNER( &( xNetworkBufferDescriptors[ x ].xBufferListItem ), &xNetworkBufferDescriptors[ x ] );
-
- /* Currently, all buffers are available for use. */
- vListInsert( &xFreeBuffersList, &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
- }
-
- uxMinimumFreeNetworkBuffers = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
- }
- }
-
- if( xNetworkBufferSemaphore == NULL )
- {
- xReturn = pdFAIL;
- }
- else
- {
- xReturn = pdPASS;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-uint8_t *pucGetNetworkBuffer( size_t *pxRequestedSizeBytes )
-{
-uint8_t *pucEthernetBuffer;
-size_t xSize = *pxRequestedSizeBytes;
-
- if( xSize < baMINIMAL_BUFFER_SIZE )
- {
- /* Buffers must be at least large enough to hold a TCP-packet with
- headers, or an ARP packet, in case TCP is not included. */
- xSize = baMINIMAL_BUFFER_SIZE;
- }
-
- /* Round up xSize to the nearest multiple of N bytes,
- where N equals 'sizeof( size_t )'. */
- if( ( xSize & ( sizeof( size_t ) - 1u ) ) != 0u )
- {
- xSize = ( xSize | ( sizeof( size_t ) - 1u ) ) + 1u;
- }
- *pxRequestedSizeBytes = xSize;
-
- /* Allocate a buffer large enough to store the requested Ethernet frame size
- and a pointer to a network buffer structure (hence the addition of
- ipBUFFER_PADDING bytes). */
- pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xSize + ipBUFFER_PADDING );
- configASSERT( pucEthernetBuffer );
-
- if( pucEthernetBuffer != NULL )
- {
- /* Enough space is left at the start of the buffer to place a pointer to
- the network buffer structure that references this Ethernet buffer.
- Return a pointer to the start of the Ethernet buffer itself. */
- pucEthernetBuffer += ipBUFFER_PADDING;
- }
-
- return pucEthernetBuffer;
-}
-/*-----------------------------------------------------------*/
-
-void vReleaseNetworkBuffer( uint8_t *pucEthernetBuffer )
-{
- /* There is space before the Ethernet buffer in which a pointer to the
- network buffer that references this Ethernet buffer is stored. Remove the
- space before freeing the buffer. */
- if( pucEthernetBuffer != NULL )
- {
- pucEthernetBuffer -= ipBUFFER_PADDING;
- vPortFree( ( void * ) pucEthernetBuffer );
- }
-}
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks )
-{
-NetworkBufferDescriptor_t *pxReturn = NULL;
-size_t uxCount;
-
- if( ( xRequestedSizeBytes != 0u ) && ( xRequestedSizeBytes < ( size_t ) baMINIMAL_BUFFER_SIZE ) )
- {
- /* ARP packets can replace application packets, so the storage must be
- at least large enough to hold an ARP. */
- xRequestedSizeBytes = baMINIMAL_BUFFER_SIZE;
- }
-
- /* Add 2 bytes to xRequestedSizeBytes and round up xRequestedSizeBytes
- to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */
- xRequestedSizeBytes += 2u;
- if( ( xRequestedSizeBytes & ( sizeof( size_t ) - 1u ) ) != 0u )
- {
- xRequestedSizeBytes = ( xRequestedSizeBytes | ( sizeof( size_t ) - 1u ) ) + 1u;
- }
-
- /* If there is a semaphore available, there is a network buffer available. */
- if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS )
- {
- /* Protect the structure as it is accessed from tasks and interrupts. */
- taskENTER_CRITICAL();
- {
- pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );
- uxListRemove( &( pxReturn->xBufferListItem ) );
- }
- taskEXIT_CRITICAL();
-
- /* Reading UBaseType_t, no critical section needed. */
- uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList );
-
- if( uxMinimumFreeNetworkBuffers > uxCount )
- {
- uxMinimumFreeNetworkBuffers = uxCount;
- }
-
- /* Allocate storage of exactly the requested size to the buffer. */
- configASSERT( pxReturn->pucEthernetBuffer == NULL );
- if( xRequestedSizeBytes > 0 )
- {
- /* Extra space is obtained so a pointer to the network buffer can
- be stored at the beginning of the buffer. */
- pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xRequestedSizeBytes + ipBUFFER_PADDING );
-
- if( pxReturn->pucEthernetBuffer == NULL )
- {
- /* The attempt to allocate storage for the buffer payload failed,
- so the network buffer structure cannot be used and must be
- released. */
- vReleaseNetworkBufferAndDescriptor( pxReturn );
- pxReturn = NULL;
- }
- else
- {
- /* Store a pointer to the network buffer structure in the
- buffer storage area, then move the buffer pointer on past the
- stored pointer so the pointer value is not overwritten by the
- application when the buffer is used. */
- *( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;
- pxReturn->pucEthernetBuffer += ipBUFFER_PADDING;
-
- /* Store the actual size of the allocated buffer, which may be
- greater than the original requested size. */
- pxReturn->xDataLength = xRequestedSizeBytes;
-
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- {
- /* make sure the buffer is not linked */
- pxReturn->pxNextBuffer = NULL;
- }
- #endif /* ipconfigUSE_LINKED_RX_MESSAGES */
- }
- }
- else
- {
- /* A descriptor is being returned without an associated buffer being
- allocated. */
- }
- }
-
- if( pxReturn == NULL )
- {
- iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER();
- }
- else
- {
- iptraceNETWORK_BUFFER_OBTAINED( pxReturn );
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-BaseType_t xListItemAlreadyInFreeList;
-
- /* Ensure the buffer is returned to the list of free buffers before the
- counting semaphore is 'given' to say a buffer is available. Release the
- storage allocated to the buffer payload. THIS FILE SHOULD NOT BE USED
- IF THE PROJECT INCLUDES A MEMORY ALLOCATOR THAT WILL FRAGMENT THE HEAP
- MEMORY. For example, heap_2 must not be used, heap_4 can be used. */
- vReleaseNetworkBuffer( pxNetworkBuffer->pucEthernetBuffer );
- pxNetworkBuffer->pucEthernetBuffer = NULL;
-
- taskENTER_CRITICAL();
- {
- xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
-
- if( xListItemAlreadyInFreeList == pdFALSE )
- {
- vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
- }
- }
- taskEXIT_CRITICAL();
-
- /*
- * Update the network state machine, unless the program fails to release its 'xNetworkBufferSemaphore'.
- * The program should only try to release its semaphore if 'xListItemAlreadyInFreeList' is false.
- */
- if( xListItemAlreadyInFreeList == pdFALSE )
- {
- if ( xSemaphoreGive( xNetworkBufferSemaphore ) == pdTRUE )
- {
- iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer );
- }
- }
- else
- {
- iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer );
- }
-}
-/*-----------------------------------------------------------*/
-
-/*
- * Returns the number of free network buffers
- */
-UBaseType_t uxGetNumberOfFreeNetworkBuffers( void )
-{
- return listCURRENT_LIST_LENGTH( &xFreeBuffersList );
-}
-/*-----------------------------------------------------------*/
-
-UBaseType_t uxGetMinimumFreeNetworkBuffers( void )
-{
- return uxMinimumFreeNetworkBuffers;
-}
-/*-----------------------------------------------------------*/
-
-NetworkBufferDescriptor_t *pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, size_t xNewSizeBytes )
-{
-size_t xOriginalLength;
-uint8_t *pucBuffer;
-
- xOriginalLength = pxNetworkBuffer->xDataLength + ipBUFFER_PADDING;
- xNewSizeBytes = xNewSizeBytes + ipBUFFER_PADDING;
-
- pucBuffer = pucGetNetworkBuffer( &( xNewSizeBytes ) );
-
- if( pucBuffer == NULL )
- {
- /* In case the allocation fails, return NULL. */
- pxNetworkBuffer = NULL;
- }
- else
- {
- pxNetworkBuffer->xDataLength = xNewSizeBytes;
- if( xNewSizeBytes > xOriginalLength )
- {
- xNewSizeBytes = xOriginalLength;
- }
-
- memcpy( pucBuffer - ipBUFFER_PADDING, pxNetworkBuffer->pucEthernetBuffer - ipBUFFER_PADDING, xNewSizeBytes );
- vReleaseNetworkBuffer( pxNetworkBuffer->pucEthernetBuffer );
- pxNetworkBuffer->pucEthernetBuffer = pucBuffer;
- }
-
- return pxNetworkBuffer;
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h
deleted file mode 100755
index ef125f6..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-__attribute__( (packed) );
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h
deleted file mode 100755
index 374efb0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-/* Nothing to do here. */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h
deleted file mode 100755
index 23168d5..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-__packed
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h
deleted file mode 100755
index 8dab699..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-;
-#pragma pack( pop )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h
deleted file mode 100755
index 9917e9c..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-#pragma pack( push, 1 )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h
deleted file mode 100755
index 678f248..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-
-#ifdef _SH
- #ifdef __RENESAS__
- ;
- #pragma unpack
- #endif
-#endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h
deleted file mode 100755
index 9bbd4ee..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/*****************************************************************************
- *
- * See the following URL for an explanation of this file:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html
- *
- *****************************************************************************/
-
-
-#ifdef _SH
- #ifdef __RENESAS__
- #pragma pack 1
- #endif
-#endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c
deleted file mode 100755
index db1f376..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c
+++ /dev/null
@@ -1,649 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.3
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-
-/* Some files from the Atmel Software Framework */
-/*_RB_ The SAM4E portable layer has three different header files called gmac.h! */
-#include "instance/gmac.h"
-#include
-#include
-
-#ifndef BMSR_LINK_STATUS
- #define BMSR_LINK_STATUS 0x0004 //!< Link status
-#endif
-
-#ifndef PHY_LS_HIGH_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still high after 15 seconds of not
- receiving packets. */
- #define PHY_LS_HIGH_CHECK_TIME_MS 15000
-#endif
-
-#ifndef PHY_LS_LOW_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still low every second. */
- #define PHY_LS_LOW_CHECK_TIME_MS 1000
-#endif
-
-/* Interrupt events to process. Currently only the Rx event is processed
-although code for other events is included to allow for possible future
-expansion. */
-#define EMAC_IF_RX_EVENT 1UL
-#define EMAC_IF_TX_EVENT 2UL
-#define EMAC_IF_ERR_EVENT 4UL
-#define EMAC_IF_ALL_EVENT ( EMAC_IF_RX_EVENT | EMAC_IF_TX_EVENT | EMAC_IF_ERR_EVENT )
-
-#define ETHERNET_CONF_PHY_ADDR BOARD_GMAC_PHY_ADDR
-
-#define HZ_PER_MHZ ( 1000000UL )
-
-#ifndef EMAC_MAX_BLOCK_TIME_MS
- #define EMAC_MAX_BLOCK_TIME_MS 100ul
-#endif
-
-#if !defined( GMAC_USES_TX_CALLBACK ) || ( GMAC_USES_TX_CALLBACK != 1 )
- #error Please define GMAC_USES_TX_CALLBACK as 1
-#endif
-
-#if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- #warning The EMAC of SAM4E has fixed-size RX buffers so ZERO_COPY_RX is not possible
-#endif
-
-/* Default the size of the stack used by the EMAC deferred handler task to 4x
-the size of the stack used by the idle task - but allow this to be overridden in
-FreeRTOSConfig.h as configMINIMAL_STACK_SIZE is a user definable constant. */
-#ifndef configEMAC_TASK_STACK_SIZE
- #define configEMAC_TASK_STACK_SIZE ( 4 * configMINIMAL_STACK_SIZE )
-#endif
-
-/*-----------------------------------------------------------*/
-
-/*
- * Wait a fixed time for the link status to indicate the network is up.
- */
-static BaseType_t xGMACWaitLS( TickType_t xMaxTime );
-
-#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) && ( ipconfigHAS_TX_CRC_OFFLOADING == 0 )
- void vGMACGenerateChecksum( uint8_t *apBuffer );
-#endif
-
-/*
- * Called from the ASF GMAC driver.
- */
-static void prvRxCallback( uint32_t ulStatus );
-static void prvTxCallback( uint32_t ulStatus, uint8_t *puc_buffer );
-
-/*
- * A deferred interrupt handler task that processes GMAC interrupts.
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*
- * Initialise the ASF GMAC driver.
- */
-static BaseType_t prvGMACInit( void );
-
-/*
- * Try to obtain an Rx packet from the hardware.
- */
-static uint32_t prvEMACRxPoll( void );
-
-/*-----------------------------------------------------------*/
-
-/* Bit map of outstanding ETH interrupt events for processing. Currently only
-the Rx interrupt is handled, although code is included for other events to
-enable future expansion. */
-static volatile uint32_t ulISREvents;
-
-/* A copy of PHY register 1: 'PHY_REG_01_BMSR' */
-static uint32_t ulPHYLinkStatus = 0;
-static volatile BaseType_t xGMACSwitchRequired;
-
-/* ethernet_phy_addr: the address of the PHY in use.
-Atmel was a bit ambiguous about it so the address will be stored
-in this variable, see ethernet_phy.c */
-extern int ethernet_phy_addr;
-
-/* LLMNR multicast address. */
-static const uint8_t llmnr_mac_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
-
-/* The GMAC object as defined by the ASF drivers. */
-static gmac_device_t gs_gmac_dev;
-
-/* MAC address to use. */
-extern const uint8_t ucMACAddress[ 6 ];
-
-/* Holds the handle of the task used as a deferred interrupt processor. The
-handle is used so direct notifications can be sent to the task for all EMAC/DMA
-related interrupts. */
-TaskHandle_t xEMACTaskHandle = NULL;
-
-static QueueHandle_t xTxBufferQueue;
-int tx_release_count[ 4 ];
-
-/* xTXDescriptorSemaphore is a counting semaphore with
-a maximum count of GMAC_TX_BUFFERS, which is the number of
-DMA TX descriptors. */
-static SemaphoreHandle_t xTXDescriptorSemaphore = NULL;
-
-/*-----------------------------------------------------------*/
-
-/*
- * GMAC interrupt handler.
- */
-void GMAC_Handler(void)
-{
- xGMACSwitchRequired = pdFALSE;
-
- /* gmac_handler() may call prvRxCallback() which may change
- the value of xGMACSwitchRequired. */
- gmac_handler( &gs_gmac_dev );
-
- if( xGMACSwitchRequired != pdFALSE )
- {
- portEND_SWITCHING_ISR( xGMACSwitchRequired );
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvRxCallback( uint32_t ulStatus )
-{
- if( ( ( ulStatus & GMAC_RSR_REC ) != 0 ) && ( xEMACTaskHandle != NULL ) )
- {
- /* let the prvEMACHandlerTask know that there was an RX event. */
- ulISREvents |= EMAC_IF_RX_EVENT;
- /* Only an RX interrupt can wakeup prvEMACHandlerTask. */
- vTaskNotifyGiveFromISR( xEMACTaskHandle, ( BaseType_t * ) &xGMACSwitchRequired );
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvTxCallback( uint32_t ulStatus, uint8_t *puc_buffer )
-{
- if( ( xTxBufferQueue != NULL ) && ( xEMACTaskHandle != NULL ) )
- {
- /* let the prvEMACHandlerTask know that there was an RX event. */
- ulISREvents |= EMAC_IF_TX_EVENT;
-
- vTaskNotifyGiveFromISR( xEMACTaskHandle, ( BaseType_t * ) &xGMACSwitchRequired );
- xQueueSendFromISR( xTxBufferQueue, &puc_buffer, ( BaseType_t * ) &xGMACSwitchRequired );
- tx_release_count[ 2 ]++;
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-const TickType_t x5_Seconds = 5000UL;
-
- if( xEMACTaskHandle == NULL )
- {
- prvGMACInit();
-
- /* Wait at most 5 seconds for a Link Status in the PHY. */
- xGMACWaitLS( pdMS_TO_TICKS( x5_Seconds ) );
-
- /* The handler task is created at the highest possible priority to
- ensure the interrupt handler can return directly to it. */
- xTaskCreate( prvEMACHandlerTask, "EMAC", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
- configASSERT( xEMACTaskHandle );
- }
-
- if( xTxBufferQueue == NULL )
- {
- xTxBufferQueue = xQueueCreate( GMAC_TX_BUFFERS, sizeof( void * ) );
- configASSERT( xTxBufferQueue );
- }
-
- if( xTXDescriptorSemaphore == NULL )
- {
- xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) GMAC_TX_BUFFERS, ( UBaseType_t ) GMAC_TX_BUFFERS );
- configASSERT( xTXDescriptorSemaphore );
- }
- /* When returning non-zero, the stack will become active and
- start DHCP (in configured) */
- return ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xResult;
-
- /* This function returns true if the Link Status in the PHY is high. */
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xResult = pdTRUE;
- }
- else
- {
- xResult = pdFALSE;
- }
-
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t bReleaseAfterSend )
-{
-/* Do not wait too long for a free TX DMA buffer. */
-const TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 50u );
-
- do {
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) == 0 )
- {
- /* Do not attempt to send packets as long as the Link Status is low. */
- break;
- }
- if( xTXDescriptorSemaphore == NULL )
- {
- /* Semaphore has not been created yet? */
- break;
- }
- if( xSemaphoreTake( xTXDescriptorSemaphore, xBlockTimeTicks ) != pdPASS )
- {
- /* Time-out waiting for a free TX descriptor. */
- tx_release_count[ 3 ]++;
- break;
- }
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* Confirm that the pxDescriptor may be kept by the driver. */
- configASSERT( bReleaseAfterSend != pdFALSE );
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- gmac_dev_write( &gs_gmac_dev, (void *)pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, prvTxCallback );
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* Confirm that the pxDescriptor may be kept by the driver. */
- bReleaseAfterSend = pdFALSE;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
- /* Not interested in a call-back after TX. */
- iptraceNETWORK_INTERFACE_TRANSMIT();
- } while( 0 );
-
- if( bReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvGMACInit( void )
-{
-uint32_t ncfgr;
-
- gmac_options_t gmac_option;
-
- memset( &gmac_option, '\0', sizeof( gmac_option ) );
- gmac_option.uc_copy_all_frame = 0;
- gmac_option.uc_no_boardcast = 0;
- memcpy( gmac_option.uc_mac_addr, ucMACAddress, sizeof( gmac_option.uc_mac_addr ) );
-
- gs_gmac_dev.p_hw = GMAC;
- gmac_dev_init( GMAC, &gs_gmac_dev, &gmac_option );
-
- NVIC_SetPriority( GMAC_IRQn, configMAC_INTERRUPT_PRIORITY );
- NVIC_EnableIRQ( GMAC_IRQn );
-
- /* Contact the Ethernet PHY and store it's address in 'ethernet_phy_addr' */
- ethernet_phy_init( GMAC, ETHERNET_CONF_PHY_ADDR, sysclk_get_cpu_hz() );
-
- ethernet_phy_auto_negotiate( GMAC, ethernet_phy_addr );
- ethernet_phy_set_link( GMAC, ethernet_phy_addr, 1 );
-
- /* The GMAC driver will call a hook prvRxCallback(), which
- in turn will wake-up the task by calling vTaskNotifyGiveFromISR() */
- gmac_dev_set_rx_callback( &gs_gmac_dev, prvRxCallback );
- gmac_set_address( GMAC, 1, (uint8_t*)llmnr_mac_address );
-
- ncfgr = GMAC_NCFGR_SPD | GMAC_NCFGR_FD;
-
- GMAC->GMAC_NCFGR = ( GMAC->GMAC_NCFGR & ~( GMAC_NCFGR_SPD | GMAC_NCFGR_FD ) ) | ncfgr;
-
- return 1;
-}
-/*-----------------------------------------------------------*/
-
-static inline unsigned long ulReadMDIO( unsigned /*short*/ usAddress )
-{
-uint32_t ulValue, ulReturn;
-int rc;
-
- gmac_enable_management( GMAC, 1 );
- rc = gmac_phy_read( GMAC, ethernet_phy_addr, usAddress, &ulValue );
- gmac_enable_management( GMAC, 0 );
- if( rc == GMAC_OK )
- {
- ulReturn = ulValue;
- }
- else
- {
- ulReturn = 0UL;
- }
-
- return ulReturn;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t xGMACWaitLS( TickType_t xMaxTime )
-{
-TickType_t xStartTime = xTaskGetTickCount();
-TickType_t xEndTime;
-BaseType_t xReturn;
-const TickType_t xShortTime = pdMS_TO_TICKS( 100UL );
-
- for( ;; )
- {
- xEndTime = xTaskGetTickCount();
-
- if( ( xEndTime - xStartTime ) > xMaxTime )
- {
- /* Wated more than xMaxTime, return. */
- xReturn = pdFALSE;
- break;
- }
-
- /* Check the link status again. */
- ulPHYLinkStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- /* Link is up - return. */
- xReturn = pdTRUE;
- break;
- }
-
- /* Link is down - wait in the Blocked state for a short while (to allow
- other tasks to execute) before checking again. */
- vTaskDelay( xShortTime );
- }
-
- FreeRTOS_printf( ( "xGMACWaitLS: %ld (PHY %d) freq %lu Mz\n",
- xReturn,
- ethernet_phy_addr,
- sysclk_get_cpu_hz() / HZ_PER_MHZ ) );
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-//#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) && ( ipconfigHAS_TX_CRC_OFFLOADING == 0 )
-
- void vGMACGenerateChecksum( uint8_t *apBuffer )
- {
- ProtocolPacket_t *xProtPacket = (ProtocolPacket_t *)apBuffer;
-
- if ( xProtPacket->xTCPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE )
- {
- IPHeader_t *pxIPHeader = &( xProtPacket->xTCPPacket.xIPHeader );
-
- /* Calculate the IP header checksum. */
- pxIPHeader->usHeaderChecksum = 0x00;
- pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0u, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
- pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
-
- /* Calculate the TCP checksum for an outgoing packet. */
- usGenerateProtocolChecksum( ( uint8_t * ) apBuffer, pdTRUE );
- }
- }
-
-//#endif
-/*-----------------------------------------------------------*/
-
-static uint32_t prvEMACRxPoll( void )
-{
-unsigned char *pucUseBuffer;
-uint32_t ulReceiveCount, ulResult, ulReturnValue = 0;
-static NetworkBufferDescriptor_t *pxNextNetworkBufferDescriptor = NULL;
-const UBaseType_t xMinDescriptorsToLeave = 2UL;
-const TickType_t xBlockTime = pdMS_TO_TICKS( 100UL );
-static IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-
- for( ;; )
- {
- /* If pxNextNetworkBufferDescriptor was not left pointing at a valid
- descriptor then allocate one now. */
- if( ( pxNextNetworkBufferDescriptor == NULL ) && ( uxGetNumberOfFreeNetworkBuffers() > xMinDescriptorsToLeave ) )
- {
- pxNextNetworkBufferDescriptor = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, xBlockTime );
- }
-
- if( pxNextNetworkBufferDescriptor != NULL )
- {
- /* Point pucUseBuffer to the buffer pointed to by the descriptor. */
- pucUseBuffer = ( unsigned char* ) ( pxNextNetworkBufferDescriptor->pucEthernetBuffer - ipconfigPACKET_FILLER_SIZE );
- }
- else
- {
- /* As long as pxNextNetworkBufferDescriptor is NULL, the incoming
- messages will be flushed and ignored. */
- pucUseBuffer = NULL;
- }
-
- /* Read the next packet from the hardware into pucUseBuffer. */
- ulResult = gmac_dev_read( &gs_gmac_dev, pucUseBuffer, ipTOTAL_ETHERNET_FRAME_SIZE, &ulReceiveCount );
-
- if( ( ulResult != GMAC_OK ) || ( ulReceiveCount == 0 ) )
- {
- /* No data from the hardware. */
- break;
- }
-
- if( pxNextNetworkBufferDescriptor == NULL )
- {
- /* Data was read from the hardware, but no descriptor was available
- for it, so it will be dropped. */
- iptraceETHERNET_RX_EVENT_LOST();
- continue;
- }
-
- iptraceNETWORK_INTERFACE_RECEIVE();
- pxNextNetworkBufferDescriptor->xDataLength = ( size_t ) ulReceiveCount;
- xRxEvent.pvData = ( void * ) pxNextNetworkBufferDescriptor;
-
- /* Send the descriptor to the IP task for processing. */
- if( xSendEventStructToIPTask( &xRxEvent, xBlockTime ) != pdTRUE )
- {
- /* The buffer could not be sent to the stack so must be released
- again. */
- vReleaseNetworkBufferAndDescriptor( pxNextNetworkBufferDescriptor );
- iptraceETHERNET_RX_EVENT_LOST();
- FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue return packet!\n" ) );
- }
-
- /* Now the buffer has either been passed to the IP-task,
- or it has been released in the code above. */
- pxNextNetworkBufferDescriptor = NULL;
- ulReturnValue++;
- }
-
- return ulReturnValue;
-}
-/*-----------------------------------------------------------*/
-
-void vCheckBuffersAndQueue( void )
-{
-static UBaseType_t uxLastMinBufferCount = 0;
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- static UBaseType_t uxLastMinQueueSpace;
-#endif
-static UBaseType_t uxCurrentCount;
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
-}
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-TimeOut_t xPhyTime;
-TickType_t xPhyRemTime;
-UBaseType_t uxCount;
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxBuffer;
-#endif
-uint8_t *pucBuffer;
-BaseType_t xResult = 0;
-uint32_t xStatus;
-const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( EMAC_MAX_BLOCK_TIME_MS );
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- configASSERT( xEMACTaskHandle );
-
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
-
- for( ;; )
- {
- vCheckBuffersAndQueue();
-
- if( ( ulISREvents & EMAC_IF_ALL_EVENT ) == 0 )
- {
- /* No events to process now, wait for the next. */
- ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
- }
-
- if( ( ulISREvents & EMAC_IF_RX_EVENT ) != 0 )
- {
- ulISREvents &= ~EMAC_IF_RX_EVENT;
-
- /* Wait for the EMAC interrupt to indicate that another packet has been
- received. */
- xResult = prvEMACRxPoll();
- }
-
- if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0 )
- {
- /* Future extension: code to release TX buffers if zero-copy is used. */
- ulISREvents &= ~EMAC_IF_TX_EVENT;
- while( xQueueReceive( xTxBufferQueue, &pucBuffer, 0 ) != pdFALSE )
- {
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- pxBuffer = pxPacketBuffer_to_NetworkBuffer( pucBuffer );
- if( pxBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxBuffer );
- tx_release_count[ 0 ]++;
- }
- else
- {
- tx_release_count[ 1 ]++;
- }
- }
- #else
- {
- tx_release_count[ 0 ]++;
- }
- #endif
- uxCount = uxQueueMessagesWaiting( ( QueueHandle_t ) xTXDescriptorSemaphore );
- if( uxCount < GMAC_TX_BUFFERS )
- {
- /* Tell the counting semaphore that one more TX descriptor is available. */
- xSemaphoreGive( xTXDescriptorSemaphore );
- }
- }
- }
-
- if( ( ulISREvents & EMAC_IF_ERR_EVENT ) != 0 )
- {
- /* Future extension: logging about errors that occurred. */
- ulISREvents &= ~EMAC_IF_ERR_EVENT;
- }
-
- if( xResult > 0 )
- {
- /* A packet was received. No need to check for the PHY status now,
- but set a timer to check it later on. */
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- xResult = 0;
- }
- else if( xTaskCheckForTimeOut( &xPhyTime, &xPhyRemTime ) != pdFALSE )
- {
- /* Check the link status again. */
- xStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != ( xStatus & BMSR_LINK_STATUS ) )
- {
- ulPHYLinkStatus = xStatus;
- FreeRTOS_printf( ( "prvEMACHandlerTask: PHY LS now %d\n", ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 ) );
- }
-
- vTaskSetTimeOutState( &xPhyTime );
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- }
- else
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
- }
- }
- }
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/component/gmac.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/component/gmac.h
deleted file mode 100755
index ae40ac9..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/component/gmac.h
+++ /dev/null
@@ -1,746 +0,0 @@
-/**
- * \file
- *
- * Copyright (c) 2012 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-#ifndef _SAM4E_GMAC_COMPONENT_
-#define _SAM4E_GMAC_COMPONENT_
-
-/* ============================================================================= */
-/** SOFTWARE API DEFINITION FOR Gigabit Ethernet MAC */
-/* ============================================================================= */
-/** \addtogroup SAM4E_GMAC Gigabit Ethernet MAC */
-/*@{*/
-
-#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
-/** \brief GmacSa hardware registers */
-typedef struct {
- RwReg GMAC_SAB; /**< \brief (GmacSa Offset: 0x0) Specific Address 1 Bottom [31:0] Register */
- RwReg GMAC_SAT; /**< \brief (GmacSa Offset: 0x4) Specific Address 1 Top [47:32] Register */
-} GmacSa;
-/** \brief Gmac hardware registers */
-#define GMACSA_NUMBER 4
-typedef struct {
- RwReg GMAC_NCR; /**< \brief (Gmac Offset: 0x000) Network Control Register */
- RwReg GMAC_NCFGR; /**< \brief (Gmac Offset: 0x004) Network Configuration Register */
- RoReg GMAC_NSR; /**< \brief (Gmac Offset: 0x008) Network Status Register */
- RwReg GMAC_UR; /**< \brief (Gmac Offset: 0x00C) User Register */
- RwReg GMAC_DCFGR; /**< \brief (Gmac Offset: 0x010) DMA Configuration Register */
- RwReg GMAC_TSR; /**< \brief (Gmac Offset: 0x014) Transmit Status Register */
- RwReg GMAC_RBQB; /**< \brief (Gmac Offset: 0x018) Receive Buffer Queue Base Address */
- RwReg GMAC_TBQB; /**< \brief (Gmac Offset: 0x01C) Transmit Buffer Queue Base Address */
- RwReg GMAC_RSR; /**< \brief (Gmac Offset: 0x020) Receive Status Register */
- RoReg GMAC_ISR; /**< \brief (Gmac Offset: 0x024) Interrupt Status Register */
- WoReg GMAC_IER; /**< \brief (Gmac Offset: 0x028) Interrupt Enable Register */
- WoReg GMAC_IDR; /**< \brief (Gmac Offset: 0x02C) Interrupt Disable Register */
- RoReg GMAC_IMR; /**< \brief (Gmac Offset: 0x030) Interrupt Mask Register */
- RwReg GMAC_MAN; /**< \brief (Gmac Offset: 0x034) PHY Maintenance Register */
- RoReg GMAC_RPQ; /**< \brief (Gmac Offset: 0x038) Received Pause Quantum Register */
- RwReg GMAC_TPQ; /**< \brief (Gmac Offset: 0x03C) Transmit Pause Quantum Register */
- RwReg GMAC_TPSF; /**< \brief (Gmac Offset: 0x040) TX Partial Store and Forward Register */
- RwReg GMAC_RPSF; /**< \brief (Gmac Offset: 0x044) RX Partial Store and Forward Register */
- RoReg Reserved1[14];
- RwReg GMAC_HRB; /**< \brief (Gmac Offset: 0x080) Hash Register Bottom [31:0] */
- RwReg GMAC_HRT; /**< \brief (Gmac Offset: 0x084) Hash Register Top [63:32] */
- GmacSa GMAC_SA[GMACSA_NUMBER]; /**< \brief (Gmac Offset: 0x088) 1 .. 4 */
- RwReg GMAC_TIDM[4]; /**< \brief (Gmac Offset: 0x0A8) Type ID Match 1 Register */
- RwReg GMAC_WOL; /**< \brief (Gmac Offset: 0x0B8) Wake on LAN Register */
- RwReg GMAC_IPGS; /**< \brief (Gmac Offset: 0x0BC) IPG Stretch Register */
- RwReg GMAC_SVLAN; /**< \brief (Gmac Offset: 0x0C0) Stacked VLAN Register */
- RwReg GMAC_TPFCP; /**< \brief (Gmac Offset: 0x0C4) Transmit PFC Pause Register */
- RwReg GMAC_SAMB1; /**< \brief (Gmac Offset: 0x0C8) Specific Address 1 Mask Bottom [31:0] Register */
- RwReg GMAC_SAMT1; /**< \brief (Gmac Offset: 0x0CC) Specific Address 1 Mask Top [47:32] Register */
- RoReg Reserved2[12];
- RoReg GMAC_OTLO; /**< \brief (Gmac Offset: 0x100) Octets Transmitted [31:0] Register */
- RoReg GMAC_OTHI; /**< \brief (Gmac Offset: 0x104) Octets Transmitted [47:32] Register */
- RoReg GMAC_FT; /**< \brief (Gmac Offset: 0x108) Frames Transmitted Register */
- RoReg GMAC_BCFT; /**< \brief (Gmac Offset: 0x10C) Broadcast Frames Transmitted Register */
- RoReg GMAC_MFT; /**< \brief (Gmac Offset: 0x110) Multicast Frames Transmitted Register */
- RoReg GMAC_PFT; /**< \brief (Gmac Offset: 0x114) Pause Frames Transmitted Register */
- RoReg GMAC_BFT64; /**< \brief (Gmac Offset: 0x118) 64 Byte Frames Transmitted Register */
- RoReg GMAC_TBFT127; /**< \brief (Gmac Offset: 0x11C) 65 to 127 Byte Frames Transmitted Register */
- RoReg GMAC_TBFT255; /**< \brief (Gmac Offset: 0x120) 128 to 255 Byte Frames Transmitted Register */
- RoReg GMAC_TBFT511; /**< \brief (Gmac Offset: 0x124) 256 to 511 Byte Frames Transmitted Register */
- RoReg GMAC_TBFT1023; /**< \brief (Gmac Offset: 0x128) 512 to 1023 Byte Frames Transmitted Register */
- RoReg GMAC_TBFT1518; /**< \brief (Gmac Offset: 0x12C) 1024 to 1518 Byte Frames Transmitted Register */
- RoReg GMAC_GTBFT1518; /**< \brief (Gmac Offset: 0x130) Greater Than 1518 Byte Frames Transmitted Register */
- RoReg GMAC_TUR; /**< \brief (Gmac Offset: 0x134) Transmit Under Runs Register */
- RoReg GMAC_SCF; /**< \brief (Gmac Offset: 0x138) Single Collision Frames Register */
- RoReg GMAC_MCF; /**< \brief (Gmac Offset: 0x13C) Multiple Collision Frames Register */
- RoReg GMAC_EC; /**< \brief (Gmac Offset: 0x140) Excessive Collisions Register */
- RoReg GMAC_LC; /**< \brief (Gmac Offset: 0x144) Late Collisions Register */
- RoReg GMAC_DTF; /**< \brief (Gmac Offset: 0x148) Deferred Transmission Frames Register */
- RoReg GMAC_CSE; /**< \brief (Gmac Offset: 0x14C) Carrier Sense Errors Register */
- RoReg GMAC_ORLO; /**< \brief (Gmac Offset: 0x150) Octets Received [31:0] Received */
- RoReg GMAC_ORHI; /**< \brief (Gmac Offset: 0x154) Octets Received [47:32] Received */
- RoReg GMAC_FR; /**< \brief (Gmac Offset: 0x158) Frames Received Register */
- RoReg GMAC_BCFR; /**< \brief (Gmac Offset: 0x15C) Broadcast Frames Received Register */
- RoReg GMAC_MFR; /**< \brief (Gmac Offset: 0x160) Multicast Frames Received Register */
- RoReg GMAC_PFR; /**< \brief (Gmac Offset: 0x164) Pause Frames Received Register */
- RoReg GMAC_BFR64; /**< \brief (Gmac Offset: 0x168) 64 Byte Frames Received Register */
- RoReg GMAC_TBFR127; /**< \brief (Gmac Offset: 0x16C) 65 to 127 Byte Frames Received Register */
- RoReg GMAC_TBFR255; /**< \brief (Gmac Offset: 0x170) 128 to 255 Byte Frames Received Register */
- RoReg GMAC_TBFR511; /**< \brief (Gmac Offset: 0x174) 256 to 511Byte Frames Received Register */
- RoReg GMAC_TBFR1023; /**< \brief (Gmac Offset: 0x178) 512 to 1023 Byte Frames Received Register */
- RoReg GMAC_TBFR1518; /**< \brief (Gmac Offset: 0x17C) 1024 to 1518 Byte Frames Received Register */
- RoReg GMAC_TMXBFR; /**< \brief (Gmac Offset: 0x180) 1519 to Maximum Byte Frames Received Register */
- RoReg GMAC_UFR; /**< \brief (Gmac Offset: 0x184) Undersize Frames Received Register */
- RoReg GMAC_OFR; /**< \brief (Gmac Offset: 0x188) Oversize Frames Received Register */
- RoReg GMAC_JR; /**< \brief (Gmac Offset: 0x18C) Jabbers Received Register */
- RoReg GMAC_FCSE; /**< \brief (Gmac Offset: 0x190) Frame Check Sequence Errors Register */
- RoReg GMAC_LFFE; /**< \brief (Gmac Offset: 0x194) Length Field Frame Errors Register */
- RoReg GMAC_RSE; /**< \brief (Gmac Offset: 0x198) Receive Symbol Errors Register */
- RoReg GMAC_AE; /**< \brief (Gmac Offset: 0x19C) Alignment Errors Register */
- RoReg GMAC_RRE; /**< \brief (Gmac Offset: 0x1A0) Receive Resource Errors Register */
- RoReg GMAC_ROE; /**< \brief (Gmac Offset: 0x1A4) Receive Overrun Register */
- RoReg GMAC_IHCE; /**< \brief (Gmac Offset: 0x1A8) IP Header Checksum Errors Register */
- RoReg GMAC_TCE; /**< \brief (Gmac Offset: 0x1AC) TCP Checksum Errors Register */
- RoReg GMAC_UCE; /**< \brief (Gmac Offset: 0x1B0) UDP Checksum Errors Register */
- RoReg Reserved3[5];
- RwReg GMAC_TSSS; /**< \brief (Gmac Offset: 0x1C8) 1588 Timer Sync Strobe Seconds Register */
- RwReg GMAC_TSSN; /**< \brief (Gmac Offset: 0x1CC) 1588 Timer Sync Strobe Nanoseconds Register */
- RwReg GMAC_TS; /**< \brief (Gmac Offset: 0x1D0) 1588 Timer Seconds Register */
- RwReg GMAC_TN; /**< \brief (Gmac Offset: 0x1D4) 1588 Timer Nanoseconds Register */
- WoReg GMAC_TA; /**< \brief (Gmac Offset: 0x1D8) 1588 Timer Adjust Register */
- RwReg GMAC_TI; /**< \brief (Gmac Offset: 0x1DC) 1588 Timer Increment Register */
- RoReg GMAC_EFTS; /**< \brief (Gmac Offset: 0x1E0) PTP Event Frame Transmitted Seconds */
- RoReg GMAC_EFTN; /**< \brief (Gmac Offset: 0x1E4) PTP Event Frame Transmitted Nanoseconds */
- RoReg GMAC_EFRS; /**< \brief (Gmac Offset: 0x1E8) PTP Event Frame Received Seconds */
- RoReg GMAC_EFRN; /**< \brief (Gmac Offset: 0x1EC) PTP Event Frame Received Nanoseconds */
- RoReg GMAC_PEFTS; /**< \brief (Gmac Offset: 0x1F0) PTP Peer Event Frame Transmitted Seconds */
- RoReg GMAC_PEFTN; /**< \brief (Gmac Offset: 0x1F4) PTP Peer Event Frame Transmitted Nanoseconds */
- RoReg GMAC_PEFRS; /**< \brief (Gmac Offset: 0x1F8) PTP Peer Event Frame Received Seconds */
- RoReg GMAC_PEFRN; /**< \brief (Gmac Offset: 0x1FC) PTP Peer Event Frame Received Nanoseconds */
- RoReg Reserved4[128];
- RoReg GMAC_ISRPQ[7]; /**< \brief (Gmac Offset: 0x400) Interrupt Status Register Priority Queue */
- RoReg Reserved5[9];
- RwReg GMAC_TBQBAPQ[7]; /**< \brief (Gmac Offset: 0x440) Transmit Buffer Queue Base Address Priority Queue */
- RoReg Reserved6[9];
- RwReg GMAC_RBQBAPQ[7]; /**< \brief (Gmac Offset: 0x480) Receive Buffer Queue Base Address Priority Queue */
- RoReg Reserved7[1];
- RwReg GMAC_RBSRPQ[7]; /**< \brief (Gmac Offset: 0x4A0) Receive Buffer Size Register Priority Queue */
- RoReg Reserved8[17];
- RwReg GMAC_ST1RPQ[16]; /**< \brief (Gmac Offset: 0x500) Screening Type1 Register Priority Queue */
- RwReg GMAC_ST2RPQ[16]; /**< \brief (Gmac Offset: 0x540) Screening Type2 Register Priority Queue */
- RoReg Reserved9[32];
- WoReg GMAC_IERPQ[7]; /**< \brief (Gmac Offset: 0x600) Interrupt Enable Register Priority Queue */
- RoReg Reserved10[1];
- WoReg GMAC_IDRPQ[7]; /**< \brief (Gmac Offset: 0x620) Interrupt Disable Register Priority Queue */
- RoReg Reserved11[1];
- RwReg GMAC_IMRPQ[7]; /**< \brief (Gmac Offset: 0x640) Interrupt Mask Register Priority Queue */
-} Gmac;
-#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
-/* -------- GMAC_NCR : (GMAC Offset: 0x000) Network Control Register -------- */
-#define GMAC_NCR_LB (0x1u << 0) /**< \brief (GMAC_NCR) Loop Back */
-#define GMAC_NCR_LBL (0x1u << 1) /**< \brief (GMAC_NCR) Loop Back Local */
-#define GMAC_NCR_RXEN (0x1u << 2) /**< \brief (GMAC_NCR) Receive Enable */
-#define GMAC_NCR_TXEN (0x1u << 3) /**< \brief (GMAC_NCR) Transmit Enable */
-#define GMAC_NCR_MPE (0x1u << 4) /**< \brief (GMAC_NCR) Management Port Enable */
-#define GMAC_NCR_CLRSTAT (0x1u << 5) /**< \brief (GMAC_NCR) Clear Statistics Registers */
-#define GMAC_NCR_INCSTAT (0x1u << 6) /**< \brief (GMAC_NCR) Increment Statistics Registers */
-#define GMAC_NCR_WESTAT (0x1u << 7) /**< \brief (GMAC_NCR) Write Enable for Statistics Registers */
-#define GMAC_NCR_BP (0x1u << 8) /**< \brief (GMAC_NCR) Back pressure */
-#define GMAC_NCR_TSTART (0x1u << 9) /**< \brief (GMAC_NCR) Start Transmission */
-#define GMAC_NCR_THALT (0x1u << 10) /**< \brief (GMAC_NCR) Transmit Halt */
-#define GMAC_NCR_TXPF (0x1u << 11) /**< \brief (GMAC_NCR) Transmit Pause Frame */
-#define GMAC_NCR_TXZQPF (0x1u << 12) /**< \brief (GMAC_NCR) Transmit Zero Quantum Pause Frame */
-#define GMAC_NCR_RDS (0x1u << 14) /**< \brief (GMAC_NCR) Read Snapshot */
-#define GMAC_NCR_SRTSM (0x1u << 15) /**< \brief (GMAC_NCR) Store Receive Time Stamp to Memory */
-#define GMAC_NCR_ENPBPR (0x1u << 16) /**< \brief (GMAC_NCR) Enable PFC Priority-based Pause Reception */
-#define GMAC_NCR_TXPBPF (0x1u << 17) /**< \brief (GMAC_NCR) Transmit PFC Priority-based Pause Frame */
-#define GMAC_NCR_FNP (0x1u << 18) /**< \brief (GMAC_NCR) Flush Next Packet */
-/* -------- GMAC_NCFGR : (GMAC Offset: 0x004) Network Configuration Register -------- */
-#define GMAC_NCFGR_SPD (0x1u << 0) /**< \brief (GMAC_NCFGR) Speed */
-#define GMAC_NCFGR_FD (0x1u << 1) /**< \brief (GMAC_NCFGR) Full Duplex */
-#define GMAC_NCFGR_DNVLAN (0x1u << 2) /**< \brief (GMAC_NCFGR) Discard Non-VLAN FRAMES */
-#define GMAC_NCFGR_JFRAME (0x1u << 3) /**< \brief (GMAC_NCFGR) Jumbo Frame Size */
-#define GMAC_NCFGR_CAF (0x1u << 4) /**< \brief (GMAC_NCFGR) Copy All Frames */
-#define GMAC_NCFGR_NBC (0x1u << 5) /**< \brief (GMAC_NCFGR) No Broadcast */
-#define GMAC_NCFGR_MTIHEN (0x1u << 6) /**< \brief (GMAC_NCFGR) Multicast Hash Enable */
-#define GMAC_NCFGR_UNIHEN (0x1u << 7) /**< \brief (GMAC_NCFGR) Unicast Hash Enable */
-#define GMAC_NCFGR_MAXFS (0x1u << 8) /**< \brief (GMAC_NCFGR) 1536 Maximum Frame Size */
-#define GMAC_NCFGR_GBE (0x1u << 10) /**< \brief (GMAC_NCFGR) Gigabit Mode Enable */
-#define GMAC_NCFGR_PIS (0x1u << 11) /**< \brief (GMAC_NCFGR) Physical Interface Select */
-#define GMAC_NCFGR_RTY (0x1u << 12) /**< \brief (GMAC_NCFGR) Retry Test */
-#define GMAC_NCFGR_PEN (0x1u << 13) /**< \brief (GMAC_NCFGR) Pause Enable */
-#define GMAC_NCFGR_RXBUFO_Pos 14
-#define GMAC_NCFGR_RXBUFO_Msk (0x3u << GMAC_NCFGR_RXBUFO_Pos) /**< \brief (GMAC_NCFGR) Receive Buffer Offset */
-#define GMAC_NCFGR_RXBUFO(value) ((GMAC_NCFGR_RXBUFO_Msk & ((value) << GMAC_NCFGR_RXBUFO_Pos)))
-#define GMAC_NCFGR_LFERD (0x1u << 16) /**< \brief (GMAC_NCFGR) Length Field Error Frame Discard */
-#define GMAC_NCFGR_RFCS (0x1u << 17) /**< \brief (GMAC_NCFGR) Remove FCS */
-#define GMAC_NCFGR_CLK_Pos 18
-#define GMAC_NCFGR_CLK_Msk (0x7u << GMAC_NCFGR_CLK_Pos) /**< \brief (GMAC_NCFGR) MDC CLock Division */
-#define GMAC_NCFGR_CLK_MCK_8 (0x0u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 8 (MCK up to 20 MHz) */
-#define GMAC_NCFGR_CLK_MCK_16 (0x1u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 16 (MCK up to 40 MHz) */
-#define GMAC_NCFGR_CLK_MCK_32 (0x2u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 32 (MCK up to 80 MHz) */
-#define GMAC_NCFGR_CLK_MCK_48 (0x3u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 48 (MCK up to 120MHz) */
-#define GMAC_NCFGR_CLK_MCK_64 (0x4u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 64 (MCK up to 160 MHz) */
-#define GMAC_NCFGR_CLK_MCK_96 (0x5u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 96 (MCK up to 240 MHz) */
-#define GMAC_NCFGR_CLK_MCK_128 (0x6u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 128 (MCK up to 320 MHz) */
-#define GMAC_NCFGR_CLK_MCK_224 (0x7u << 18) /**< \brief (GMAC_NCFGR) MCK divided by 224 (MCK up to 540 MHz) */
-#define GMAC_NCFGR_DBW_Pos 21
-#define GMAC_NCFGR_DBW_Msk (0x3u << GMAC_NCFGR_DBW_Pos) /**< \brief (GMAC_NCFGR) Data Bus Width */
-#define GMAC_NCFGR_DBW_DBW32 (0x0u << 21) /**< \brief (GMAC_NCFGR) 32-bit data bus width */
-#define GMAC_NCFGR_DBW_DBW64 (0x1u << 21) /**< \brief (GMAC_NCFGR) 64-bit data bus width */
-#define GMAC_NCFGR_DCPF (0x1u << 23) /**< \brief (GMAC_NCFGR) Disable Copy of Pause Frames */
-#define GMAC_NCFGR_RXCOEN (0x1u << 24) /**< \brief (GMAC_NCFGR) Receive Checksum Offload Enable */
-#define GMAC_NCFGR_EFRHD (0x1u << 25) /**< \brief (GMAC_NCFGR) Enable Frames Received in Half Duplex */
-#define GMAC_NCFGR_IRXFCS (0x1u << 26) /**< \brief (GMAC_NCFGR) Ignore RX FCS */
-#define GMAC_NCFGR_IPGSEN (0x1u << 28) /**< \brief (GMAC_NCFGR) IP Stretch Enable */
-#define GMAC_NCFGR_RXBP (0x1u << 29) /**< \brief (GMAC_NCFGR) Receive Bad Preamble */
-#define GMAC_NCFGR_IRXER (0x1u << 30) /**< \brief (GMAC_NCFGR) Ignore IPG rx_er */
-/* -------- GMAC_NSR : (GMAC Offset: 0x008) Network Status Register -------- */
-#define GMAC_NSR_MDIO (0x1u << 1) /**< \brief (GMAC_NSR) MDIO Input Status */
-#define GMAC_NSR_IDLE (0x1u << 2) /**< \brief (GMAC_NSR) PHY Management Logic Idle */
-/* -------- GMAC_UR : (GMAC Offset: 0x00C) User Register -------- */
-#define GMAC_UR_RGMII (0x1u << 0) /**< \brief (GMAC_UR) RGMII Mode */
-#define GMAC_UR_HDFC (0x1u << 6) /**< \brief (GMAC_UR) Half Duplex Flow Control */
-#define GMAC_UR_BPDG (0x1u << 7) /**< \brief (GMAC_UR) BPDG Bypass Deglitchers */
-/* -------- GMAC_DCFGR : (GMAC Offset: 0x010) DMA Configuration Register -------- */
-#define GMAC_DCFGR_FBLDO_Pos 0
-#define GMAC_DCFGR_FBLDO_Msk (0x1fu << GMAC_DCFGR_FBLDO_Pos) /**< \brief (GMAC_DCFGR) Fixed Burst Length for DMA Data Operations: */
-#define GMAC_DCFGR_FBLDO_SINGLE (0x1u << 0) /**< \brief (GMAC_DCFGR) 00001: Always use SINGLE AHB bursts */
-#define GMAC_DCFGR_FBLDO_INCR4 (0x4u << 0) /**< \brief (GMAC_DCFGR) 001xx: Attempt to use INCR4 AHB bursts (Default) */
-#define GMAC_DCFGR_FBLDO_INCR8 (0x8u << 0) /**< \brief (GMAC_DCFGR) 01xxx: Attempt to use INCR8 AHB bursts */
-#define GMAC_DCFGR_FBLDO_INCR16 (0x10u << 0) /**< \brief (GMAC_DCFGR) 1xxxx: Attempt to use INCR16 AHB bursts */
-#define GMAC_DCFGR_ESMA (0x1u << 6) /**< \brief (GMAC_DCFGR) Endian Swap Mode Enable for Management Descriptor Accesses */
-#define GMAC_DCFGR_ESPA (0x1u << 7) /**< \brief (GMAC_DCFGR) Endian Swap Mode Enable for Packet Data Accesses */
-#define GMAC_DCFGR_RXBMS_Pos 8
-#define GMAC_DCFGR_RXBMS_Msk (0x3u << GMAC_DCFGR_RXBMS_Pos) /**< \brief (GMAC_DCFGR) Receiver Packet Buffer Memory Size Select */
-#define GMAC_DCFGR_RXBMS_EIGHTH (0x0u << 8) /**< \brief (GMAC_DCFGR) 1 Kbyte Memory Size */
-#define GMAC_DCFGR_RXBMS_QUARTER (0x1u << 8) /**< \brief (GMAC_DCFGR) 2 Kbytes Memory Size */
-#define GMAC_DCFGR_RXBMS_HALF (0x2u << 8) /**< \brief (GMAC_DCFGR) 4 Kbytes Memory Size */
-#define GMAC_DCFGR_RXBMS_FULL (0x3u << 8) /**< \brief (GMAC_DCFGR) 8 Kbytes Memory Size */
-#define GMAC_DCFGR_TXPBMS (0x1u << 10) /**< \brief (GMAC_DCFGR) Transmitter Packet Buffer Memory Size Select */
-#define GMAC_DCFGR_TXCOEN (0x1u << 11) /**< \brief (GMAC_DCFGR) Transmitter Checksum Generation Offload Enable */
-#define GMAC_DCFGR_DRBS_Pos 16
-#define GMAC_DCFGR_DRBS_Msk (0xffu << GMAC_DCFGR_DRBS_Pos) /**< \brief (GMAC_DCFGR) DMA Receive Buffer Size */
-#define GMAC_DCFGR_DRBS(value) ((GMAC_DCFGR_DRBS_Msk & ((value) << GMAC_DCFGR_DRBS_Pos)))
-#define GMAC_DCFGR_DDRP (0x1u << 24) /**< \brief (GMAC_DCFGR) DMA Discard Receive Packets */
-/* -------- GMAC_TSR : (GMAC Offset: 0x014) Transmit Status Register -------- */
-#define GMAC_TSR_UBR (0x1u << 0) /**< \brief (GMAC_TSR) Used Bit Read */
-#define GMAC_TSR_COL (0x1u << 1) /**< \brief (GMAC_TSR) Collision Occurred */
-#define GMAC_TSR_RLE (0x1u << 2) /**< \brief (GMAC_TSR) Retry Limit Exceeded */
-#define GMAC_TSR_TXGO (0x1u << 3) /**< \brief (GMAC_TSR) Transmit Go */
-#define GMAC_TSR_TFC (0x1u << 4) /**< \brief (GMAC_TSR) Transmit Frame Corruption due to AHB error */
-#define GMAC_TSR_TXCOMP (0x1u << 5) /**< \brief (GMAC_TSR) Transmit Complete */
-#define GMAC_TSR_UND (0x1u << 6) /**< \brief (GMAC_TSR) Transmit Under Run */
-#define GMAC_TSR_LCO (0x1u << 7) /**< \brief (GMAC_TSR) Late Collision Occurred */
-#define GMAC_TSR_HRESP (0x1u << 8) /**< \brief (GMAC_TSR) HRESP Not OK */
-/* -------- GMAC_RBQB : (GMAC Offset: 0x018) Receive Buffer Queue Base Address -------- */
-#define GMAC_RBQB_ADDR_Pos 2
-#define GMAC_RBQB_ADDR_Msk (0x3fffffffu << GMAC_RBQB_ADDR_Pos) /**< \brief (GMAC_RBQB) Receive buffer queue base address */
-#define GMAC_RBQB_ADDR(value) ((GMAC_RBQB_ADDR_Msk & ((value) << GMAC_RBQB_ADDR_Pos)))
-/* -------- GMAC_TBQB : (GMAC Offset: 0x01C) Transmit Buffer Queue Base Address -------- */
-#define GMAC_TBQB_ADDR_Pos 2
-#define GMAC_TBQB_ADDR_Msk (0x3fffffffu << GMAC_TBQB_ADDR_Pos) /**< \brief (GMAC_TBQB) Transmit Buffer Queue Base Address */
-#define GMAC_TBQB_ADDR(value) ((GMAC_TBQB_ADDR_Msk & ((value) << GMAC_TBQB_ADDR_Pos)))
-/* -------- GMAC_RSR : (GMAC Offset: 0x020) Receive Status Register -------- */
-#define GMAC_RSR_BNA (0x1u << 0) /**< \brief (GMAC_RSR) Buffer Not Available */
-#define GMAC_RSR_REC (0x1u << 1) /**< \brief (GMAC_RSR) Frame Received */
-#define GMAC_RSR_RXOVR (0x1u << 2) /**< \brief (GMAC_RSR) Receive Overrun */
-#define GMAC_RSR_HNO (0x1u << 3) /**< \brief (GMAC_RSR) HRESP Not OK */
-/* -------- GMAC_ISR : (GMAC Offset: 0x024) Interrupt Status Register -------- */
-#define GMAC_ISR_MFS (0x1u << 0) /**< \brief (GMAC_ISR) Management Frame Sent */
-#define GMAC_ISR_RCOMP (0x1u << 1) /**< \brief (GMAC_ISR) Receive Complete */
-#define GMAC_ISR_RXUBR (0x1u << 2) /**< \brief (GMAC_ISR) RX Used Bit Read */
-#define GMAC_ISR_TXUBR (0x1u << 3) /**< \brief (GMAC_ISR) TX Used Bit Read */
-#define GMAC_ISR_TUR (0x1u << 4) /**< \brief (GMAC_ISR) Transmit Under Run */
-#define GMAC_ISR_RLEX (0x1u << 5) /**< \brief (GMAC_ISR) Retry Limit Exceeded or Late Collision */
-#define GMAC_ISR_TFC (0x1u << 6) /**< \brief (GMAC_ISR) Transmit Frame Corruption due to AHB error */
-#define GMAC_ISR_TCOMP (0x1u << 7) /**< \brief (GMAC_ISR) Transmit Complete */
-#define GMAC_ISR_ROVR (0x1u << 10) /**< \brief (GMAC_ISR) Receive Overrun */
-#define GMAC_ISR_HRESP (0x1u << 11) /**< \brief (GMAC_ISR) HRESP Not OK */
-#define GMAC_ISR_PFNZ (0x1u << 12) /**< \brief (GMAC_ISR) Pause Frame with Non-zero Pause Quantum Received */
-#define GMAC_ISR_PTZ (0x1u << 13) /**< \brief (GMAC_ISR) Pause Time Zero */
-#define GMAC_ISR_PFTR (0x1u << 14) /**< \brief (GMAC_ISR) Pause Frame Transmitted */
-#define GMAC_ISR_EXINT (0x1u << 15) /**< \brief (GMAC_ISR) External Interrupt */
-#define GMAC_ISR_DRQFR (0x1u << 18) /**< \brief (GMAC_ISR) PTP Delay Request Frame Received */
-#define GMAC_ISR_SFR (0x1u << 19) /**< \brief (GMAC_ISR) PTP Sync Frame Received */
-#define GMAC_ISR_DRQFT (0x1u << 20) /**< \brief (GMAC_ISR) PTP Delay Request Frame Transmitted */
-#define GMAC_ISR_SFT (0x1u << 21) /**< \brief (GMAC_ISR) PTP Sync Frame Transmitted */
-#define GMAC_ISR_PDRQFR (0x1u << 22) /**< \brief (GMAC_ISR) PDelay Request Frame Received */
-#define GMAC_ISR_PDRSFR (0x1u << 23) /**< \brief (GMAC_ISR) PDelay Response Frame Received */
-#define GMAC_ISR_PDRQFT (0x1u << 24) /**< \brief (GMAC_ISR) PDelay Request Frame Transmitted */
-#define GMAC_ISR_PDRSFT (0x1u << 25) /**< \brief (GMAC_ISR) PDelay Response Frame Transmitted */
-#define GMAC_ISR_SRI (0x1u << 26) /**< \brief (GMAC_ISR) TSU Seconds Register Increment */
-#define GMAC_ISR_WOL (0x1u << 28) /**< \brief (GMAC_ISR) Wake On LAN */
-/* -------- GMAC_IER : (GMAC Offset: 0x028) Interrupt Enable Register -------- */
-#define GMAC_IER_MFS (0x1u << 0) /**< \brief (GMAC_IER) Management Frame Sent */
-#define GMAC_IER_RCOMP (0x1u << 1) /**< \brief (GMAC_IER) Receive Complete */
-#define GMAC_IER_RXUBR (0x1u << 2) /**< \brief (GMAC_IER) RX Used Bit Read */
-#define GMAC_IER_TXUBR (0x1u << 3) /**< \brief (GMAC_IER) TX Used Bit Read */
-#define GMAC_IER_TUR (0x1u << 4) /**< \brief (GMAC_IER) Transmit Under Run */
-#define GMAC_IER_RLEX (0x1u << 5) /**< \brief (GMAC_IER) Retry Limit Exceeded or Late Collision */
-#define GMAC_IER_TFC (0x1u << 6) /**< \brief (GMAC_IER) Transmit Frame Corruption due to AHB error */
-#define GMAC_IER_TCOMP (0x1u << 7) /**< \brief (GMAC_IER) Transmit Complete */
-#define GMAC_IER_ROVR (0x1u << 10) /**< \brief (GMAC_IER) Receive Overrun */
-#define GMAC_IER_HRESP (0x1u << 11) /**< \brief (GMAC_IER) HRESP Not OK */
-#define GMAC_IER_PFNZ (0x1u << 12) /**< \brief (GMAC_IER) Pause Frame with Non-zero Pause Quantum Received */
-#define GMAC_IER_PTZ (0x1u << 13) /**< \brief (GMAC_IER) Pause Time Zero */
-#define GMAC_IER_PFTR (0x1u << 14) /**< \brief (GMAC_IER) Pause Frame Transmitted */
-#define GMAC_IER_EXINT (0x1u << 15) /**< \brief (GMAC_IER) External Interrupt */
-#define GMAC_IER_DRQFR (0x1u << 18) /**< \brief (GMAC_IER) PTP Delay Request Frame Received */
-#define GMAC_IER_SFR (0x1u << 19) /**< \brief (GMAC_IER) PTP Sync Frame Received */
-#define GMAC_IER_DRQFT (0x1u << 20) /**< \brief (GMAC_IER) PTP Delay Request Frame Transmitted */
-#define GMAC_IER_SFT (0x1u << 21) /**< \brief (GMAC_IER) PTP Sync Frame Transmitted */
-#define GMAC_IER_PDRQFR (0x1u << 22) /**< \brief (GMAC_IER) PDelay Request Frame Received */
-#define GMAC_IER_PDRSFR (0x1u << 23) /**< \brief (GMAC_IER) PDelay Response Frame Received */
-#define GMAC_IER_PDRQFT (0x1u << 24) /**< \brief (GMAC_IER) PDelay Request Frame Transmitted */
-#define GMAC_IER_PDRSFT (0x1u << 25) /**< \brief (GMAC_IER) PDelay Response Frame Transmitted */
-#define GMAC_IER_SRI (0x1u << 26) /**< \brief (GMAC_IER) TSU Seconds Register Increment */
-#define GMAC_IER_WOL (0x1u << 28) /**< \brief (GMAC_IER) Wake On LAN */
-/* -------- GMAC_IDR : (GMAC Offset: 0x02C) Interrupt Disable Register -------- */
-#define GMAC_IDR_MFS (0x1u << 0) /**< \brief (GMAC_IDR) Management Frame Sent */
-#define GMAC_IDR_RCOMP (0x1u << 1) /**< \brief (GMAC_IDR) Receive Complete */
-#define GMAC_IDR_RXUBR (0x1u << 2) /**< \brief (GMAC_IDR) RX Used Bit Read */
-#define GMAC_IDR_TXUBR (0x1u << 3) /**< \brief (GMAC_IDR) TX Used Bit Read */
-#define GMAC_IDR_TUR (0x1u << 4) /**< \brief (GMAC_IDR) Transmit Under Run */
-#define GMAC_IDR_RLEX (0x1u << 5) /**< \brief (GMAC_IDR) Retry Limit Exceeded or Late Collision */
-#define GMAC_IDR_TFC (0x1u << 6) /**< \brief (GMAC_IDR) Transmit Frame Corruption due to AHB error */
-#define GMAC_IDR_TCOMP (0x1u << 7) /**< \brief (GMAC_IDR) Transmit Complete */
-#define GMAC_IDR_ROVR (0x1u << 10) /**< \brief (GMAC_IDR) Receive Overrun */
-#define GMAC_IDR_HRESP (0x1u << 11) /**< \brief (GMAC_IDR) HRESP Not OK */
-#define GMAC_IDR_PFNZ (0x1u << 12) /**< \brief (GMAC_IDR) Pause Frame with Non-zero Pause Quantum Received */
-#define GMAC_IDR_PTZ (0x1u << 13) /**< \brief (GMAC_IDR) Pause Time Zero */
-#define GMAC_IDR_PFTR (0x1u << 14) /**< \brief (GMAC_IDR) Pause Frame Transmitted */
-#define GMAC_IDR_EXINT (0x1u << 15) /**< \brief (GMAC_IDR) External Interrupt */
-#define GMAC_IDR_DRQFR (0x1u << 18) /**< \brief (GMAC_IDR) PTP Delay Request Frame Received */
-#define GMAC_IDR_SFR (0x1u << 19) /**< \brief (GMAC_IDR) PTP Sync Frame Received */
-#define GMAC_IDR_DRQFT (0x1u << 20) /**< \brief (GMAC_IDR) PTP Delay Request Frame Transmitted */
-#define GMAC_IDR_SFT (0x1u << 21) /**< \brief (GMAC_IDR) PTP Sync Frame Transmitted */
-#define GMAC_IDR_PDRQFR (0x1u << 22) /**< \brief (GMAC_IDR) PDelay Request Frame Received */
-#define GMAC_IDR_PDRSFR (0x1u << 23) /**< \brief (GMAC_IDR) PDelay Response Frame Received */
-#define GMAC_IDR_PDRQFT (0x1u << 24) /**< \brief (GMAC_IDR) PDelay Request Frame Transmitted */
-#define GMAC_IDR_PDRSFT (0x1u << 25) /**< \brief (GMAC_IDR) PDelay Response Frame Transmitted */
-#define GMAC_IDR_SRI (0x1u << 26) /**< \brief (GMAC_IDR) TSU Seconds Register Increment */
-#define GMAC_IDR_WOL (0x1u << 28) /**< \brief (GMAC_IDR) Wake On LAN */
-/* -------- GMAC_IMR : (GMAC Offset: 0x030) Interrupt Mask Register -------- */
-#define GMAC_IMR_MFS (0x1u << 0) /**< \brief (GMAC_IMR) Management Frame Sent */
-#define GMAC_IMR_RCOMP (0x1u << 1) /**< \brief (GMAC_IMR) Receive Complete */
-#define GMAC_IMR_RXUBR (0x1u << 2) /**< \brief (GMAC_IMR) RX Used Bit Read */
-#define GMAC_IMR_TXUBR (0x1u << 3) /**< \brief (GMAC_IMR) TX Used Bit Read */
-#define GMAC_IMR_TUR (0x1u << 4) /**< \brief (GMAC_IMR) Transmit Under Run */
-#define GMAC_IMR_RLEX (0x1u << 5) /**< \brief (GMAC_IMR) Retry Limit Exceeded or Late Collision */
-#define GMAC_IMR_TFC (0x1u << 6) /**< \brief (GMAC_IMR) Transmit Frame Corruption due to AHB error */
-#define GMAC_IMR_TCOMP (0x1u << 7) /**< \brief (GMAC_IMR) Transmit Complete */
-#define GMAC_IMR_ROVR (0x1u << 10) /**< \brief (GMAC_IMR) Receive Overrun */
-#define GMAC_IMR_HRESP (0x1u << 11) /**< \brief (GMAC_IMR) HRESP Not OK */
-#define GMAC_IMR_PFNZ (0x1u << 12) /**< \brief (GMAC_IMR) Pause Frame with Non-zero Pause Quantum Received */
-#define GMAC_IMR_PTZ (0x1u << 13) /**< \brief (GMAC_IMR) Pause Time Zero */
-#define GMAC_IMR_PFTR (0x1u << 14) /**< \brief (GMAC_IMR) Pause Frame Transmitted */
-#define GMAC_IMR_EXINT (0x1u << 15) /**< \brief (GMAC_IMR) External Interrupt */
-#define GMAC_IMR_DRQFR (0x1u << 18) /**< \brief (GMAC_IMR) PTP Delay Request Frame Received */
-#define GMAC_IMR_SFR (0x1u << 19) /**< \brief (GMAC_IMR) PTP Sync Frame Received */
-#define GMAC_IMR_DRQFT (0x1u << 20) /**< \brief (GMAC_IMR) PTP Delay Request Frame Transmitted */
-#define GMAC_IMR_SFT (0x1u << 21) /**< \brief (GMAC_IMR) PTP Sync Frame Transmitted */
-#define GMAC_IMR_PDRQFR (0x1u << 22) /**< \brief (GMAC_IMR) PDelay Request Frame Received */
-#define GMAC_IMR_PDRSFR (0x1u << 23) /**< \brief (GMAC_IMR) PDelay Response Frame Received */
-#define GMAC_IMR_PDRQFT (0x1u << 24) /**< \brief (GMAC_IMR) PDelay Request Frame Transmitted */
-#define GMAC_IMR_PDRSFT (0x1u << 25) /**< \brief (GMAC_IMR) PDelay Response Frame Transmitted */
-/* -------- GMAC_MAN : (GMAC Offset: 0x034) PHY Maintenance Register -------- */
-#define GMAC_MAN_DATA_Pos 0
-#define GMAC_MAN_DATA_Msk (0xffffu << GMAC_MAN_DATA_Pos) /**< \brief (GMAC_MAN) PHY Data */
-#define GMAC_MAN_DATA(value) ((GMAC_MAN_DATA_Msk & ((value) << GMAC_MAN_DATA_Pos)))
-#define GMAC_MAN_WTN_Pos 16
-#define GMAC_MAN_WTN_Msk (0x3u << GMAC_MAN_WTN_Pos) /**< \brief (GMAC_MAN) Write Ten */
-#define GMAC_MAN_WTN(value) ((GMAC_MAN_WTN_Msk & ((value) << GMAC_MAN_WTN_Pos)))
-#define GMAC_MAN_REGA_Pos 18
-#define GMAC_MAN_REGA_Msk (0x1fu << GMAC_MAN_REGA_Pos) /**< \brief (GMAC_MAN) Register Address */
-#define GMAC_MAN_REGA(value) ((GMAC_MAN_REGA_Msk & ((value) << GMAC_MAN_REGA_Pos)))
-#define GMAC_MAN_PHYA_Pos 23
-#define GMAC_MAN_PHYA_Msk (0x1fu << GMAC_MAN_PHYA_Pos) /**< \brief (GMAC_MAN) PHY Address */
-#define GMAC_MAN_PHYA(value) ((GMAC_MAN_PHYA_Msk & ((value) << GMAC_MAN_PHYA_Pos)))
-#define GMAC_MAN_OP_Pos 28
-#define GMAC_MAN_OP_Msk (0x3u << GMAC_MAN_OP_Pos) /**< \brief (GMAC_MAN) Operation */
-#define GMAC_MAN_OP(value) ((GMAC_MAN_OP_Msk & ((value) << GMAC_MAN_OP_Pos)))
-#define GMAC_MAN_CLTTO (0x1u << 30) /**< \brief (GMAC_MAN) Clause 22 Operation */
-#define GMAC_MAN_WZO (0x1u << 31) /**< \brief (GMAC_MAN) Write ZERO */
-/* -------- GMAC_RPQ : (GMAC Offset: 0x038) Received Pause Quantum Register -------- */
-#define GMAC_RPQ_RPQ_Pos 0
-#define GMAC_RPQ_RPQ_Msk (0xffffu << GMAC_RPQ_RPQ_Pos) /**< \brief (GMAC_RPQ) Received Pause Quantum */
-/* -------- GMAC_TPQ : (GMAC Offset: 0x03C) Transmit Pause Quantum Register -------- */
-#define GMAC_TPQ_TPQ_Pos 0
-#define GMAC_TPQ_TPQ_Msk (0xffffu << GMAC_TPQ_TPQ_Pos) /**< \brief (GMAC_TPQ) Transmit Pause Quantum */
-#define GMAC_TPQ_TPQ(value) ((GMAC_TPQ_TPQ_Msk & ((value) << GMAC_TPQ_TPQ_Pos)))
-/* -------- GMAC_TPSF : (GMAC Offset: 0x040) TX Partial Store and Forward Register -------- */
-#define GMAC_TPSF_TPB1ADR_Pos 0
-#define GMAC_TPSF_TPB1ADR_Msk (0xfffu << GMAC_TPSF_TPB1ADR_Pos) /**< \brief (GMAC_TPSF) tx_pbuf_addr-1:0 */
-#define GMAC_TPSF_TPB1ADR(value) ((GMAC_TPSF_TPB1ADR_Msk & ((value) << GMAC_TPSF_TPB1ADR_Pos)))
-#define GMAC_TPSF_ENTXP (0x1u << 31) /**< \brief (GMAC_TPSF) Enable TX Partial Store and Forward Operation */
-/* -------- GMAC_RPSF : (GMAC Offset: 0x044) RX Partial Store and Forward Register -------- */
-#define GMAC_RPSF_RPB1ADR_Pos 0
-#define GMAC_RPSF_RPB1ADR_Msk (0xfffu << GMAC_RPSF_RPB1ADR_Pos) /**< \brief (GMAC_RPSF) rx_pbuf_addr-1:0 */
-#define GMAC_RPSF_RPB1ADR(value) ((GMAC_RPSF_RPB1ADR_Msk & ((value) << GMAC_RPSF_RPB1ADR_Pos)))
-#define GMAC_RPSF_ENRXP (0x1u << 31) /**< \brief (GMAC_RPSF) Enable RX Partial Store and Forward Operation */
-/* -------- GMAC_HRB : (GMAC Offset: 0x080) Hash Register Bottom [31:0] -------- */
-#define GMAC_HRB_ADDR_Pos 0
-#define GMAC_HRB_ADDR_Msk (0xffffffffu << GMAC_HRB_ADDR_Pos) /**< \brief (GMAC_HRB) Hash Address */
-#define GMAC_HRB_ADDR(value) ((GMAC_HRB_ADDR_Msk & ((value) << GMAC_HRB_ADDR_Pos)))
-/* -------- GMAC_HRT : (GMAC Offset: 0x084) Hash Register Top [63:32] -------- */
-#define GMAC_HRT_ADDR_Pos 0
-#define GMAC_HRT_ADDR_Msk (0xffffffffu << GMAC_HRT_ADDR_Pos) /**< \brief (GMAC_HRT) Hash Address */
-#define GMAC_HRT_ADDR(value) ((GMAC_HRT_ADDR_Msk & ((value) << GMAC_HRT_ADDR_Pos)))
-/* -------- GMAC_SAB1 : (GMAC Offset: 0x088) Specific Address 1 Bottom [31:0] Register -------- */
-#define GMAC_SAB1_ADDR_Pos 0
-#define GMAC_SAB1_ADDR_Msk (0xffffffffu << GMAC_SAB1_ADDR_Pos) /**< \brief (GMAC_SAB1) Specific Address 1 */
-#define GMAC_SAB1_ADDR(value) ((GMAC_SAB1_ADDR_Msk & ((value) << GMAC_SAB1_ADDR_Pos)))
-/* -------- GMAC_SAT1 : (GMAC Offset: 0x08C) Specific Address 1 Top [47:32] Register -------- */
-#define GMAC_SAT1_ADDR_Pos 0
-#define GMAC_SAT1_ADDR_Msk (0xffffu << GMAC_SAT1_ADDR_Pos) /**< \brief (GMAC_SAT1) Specific Address 1 */
-#define GMAC_SAT1_ADDR(value) ((GMAC_SAT1_ADDR_Msk & ((value) << GMAC_SAT1_ADDR_Pos)))
-/* -------- GMAC_SAB2 : (GMAC Offset: 0x090) Specific Address 2 Bottom [31:0] Register -------- */
-#define GMAC_SAB2_ADDR_Pos 0
-#define GMAC_SAB2_ADDR_Msk (0xffffffffu << GMAC_SAB2_ADDR_Pos) /**< \brief (GMAC_SAB2) Specific Address 2 */
-#define GMAC_SAB2_ADDR(value) ((GMAC_SAB2_ADDR_Msk & ((value) << GMAC_SAB2_ADDR_Pos)))
-/* -------- GMAC_SAT2 : (GMAC Offset: 0x094) Specific Address 2 Top [47:32] Register -------- */
-#define GMAC_SAT2_ADDR_Pos 0
-#define GMAC_SAT2_ADDR_Msk (0xffffu << GMAC_SAT2_ADDR_Pos) /**< \brief (GMAC_SAT2) Specific Address 2 */
-#define GMAC_SAT2_ADDR(value) ((GMAC_SAT2_ADDR_Msk & ((value) << GMAC_SAT2_ADDR_Pos)))
-/* -------- GMAC_SAB3 : (GMAC Offset: 0x098) Specific Address 3 Bottom [31:0] Register -------- */
-#define GMAC_SAB3_ADDR_Pos 0
-#define GMAC_SAB3_ADDR_Msk (0xffffffffu << GMAC_SAB3_ADDR_Pos) /**< \brief (GMAC_SAB3) Specific Address 3 */
-#define GMAC_SAB3_ADDR(value) ((GMAC_SAB3_ADDR_Msk & ((value) << GMAC_SAB3_ADDR_Pos)))
-/* -------- GMAC_SAT3 : (GMAC Offset: 0x09C) Specific Address 3 Top [47:32] Register -------- */
-#define GMAC_SAT3_ADDR_Pos 0
-#define GMAC_SAT3_ADDR_Msk (0xffffu << GMAC_SAT3_ADDR_Pos) /**< \brief (GMAC_SAT3) Specific Address 3 */
-#define GMAC_SAT3_ADDR(value) ((GMAC_SAT3_ADDR_Msk & ((value) << GMAC_SAT3_ADDR_Pos)))
-/* -------- GMAC_SAB4 : (GMAC Offset: 0x0A0) Specific Address 4 Bottom [31:0] Register -------- */
-#define GMAC_SAB4_ADDR_Pos 0
-#define GMAC_SAB4_ADDR_Msk (0xffffffffu << GMAC_SAB4_ADDR_Pos) /**< \brief (GMAC_SAB4) Specific Address 4 */
-#define GMAC_SAB4_ADDR(value) ((GMAC_SAB4_ADDR_Msk & ((value) << GMAC_SAB4_ADDR_Pos)))
-/* -------- GMAC_SAT4 : (GMAC Offset: 0x0A4) Specific Address 4 Top [47:32] Register -------- */
-#define GMAC_SAT4_ADDR_Pos 0
-#define GMAC_SAT4_ADDR_Msk (0xffffu << GMAC_SAT4_ADDR_Pos) /**< \brief (GMAC_SAT4) Specific Address 4 */
-#define GMAC_SAT4_ADDR(value) ((GMAC_SAT4_ADDR_Msk & ((value) << GMAC_SAT4_ADDR_Pos)))
-/* -------- GMAC_TIDM[4] : (GMAC Offset: 0x0A8) Type ID Match 1 Register -------- */
-#define GMAC_TIDM_TID_Pos 0
-#define GMAC_TIDM_TID_Msk (0xffffu << GMAC_TIDM_TID_Pos) /**< \brief (GMAC_TIDM[4]) Type ID Match 1 */
-#define GMAC_TIDM_TID(value) ((GMAC_TIDM_TID_Msk & ((value) << GMAC_TIDM_TID_Pos)))
-/* -------- GMAC_WOL : (GMAC Offset: 0x0B8) Wake on LAN Register -------- */
-#define GMAC_WOL_IP_Pos 0
-#define GMAC_WOL_IP_Msk (0xffffu << GMAC_WOL_IP_Pos) /**< \brief (GMAC_WOL) ARP Request IP Address */
-#define GMAC_WOL_IP(value) ((GMAC_WOL_IP_Msk & ((value) << GMAC_WOL_IP_Pos)))
-#define GMAC_WOL_MAG (0x1u << 16) /**< \brief (GMAC_WOL) Magic Packet Event Enable */
-#define GMAC_WOL_ARP (0x1u << 17) /**< \brief (GMAC_WOL) ARP Request IP Address */
-#define GMAC_WOL_SA1 (0x1u << 18) /**< \brief (GMAC_WOL) Specific Address Register 1 Event Enable */
-#define GMAC_WOL_MTI (0x1u << 19) /**< \brief (GMAC_WOL) Multicast Hash Event Enable */
-/* -------- GMAC_IPGS : (GMAC Offset: 0x0BC) IPG Stretch Register -------- */
-#define GMAC_IPGS_FL_Pos 0
-#define GMAC_IPGS_FL_Msk (0xffffu << GMAC_IPGS_FL_Pos) /**< \brief (GMAC_IPGS) Frame Length */
-#define GMAC_IPGS_FL(value) ((GMAC_IPGS_FL_Msk & ((value) << GMAC_IPGS_FL_Pos)))
-/* -------- GMAC_SVLAN : (GMAC Offset: 0x0C0) Stacked VLAN Register -------- */
-#define GMAC_SVLAN_VLAN_TYPE_Pos 0
-#define GMAC_SVLAN_VLAN_TYPE_Msk (0xffffu << GMAC_SVLAN_VLAN_TYPE_Pos) /**< \brief (GMAC_SVLAN) User Defined VLAN_TYPE Field */
-#define GMAC_SVLAN_VLAN_TYPE(value) ((GMAC_SVLAN_VLAN_TYPE_Msk & ((value) << GMAC_SVLAN_VLAN_TYPE_Pos)))
-#define GMAC_SVLAN_ESVLAN (0x1u << 31) /**< \brief (GMAC_SVLAN) Enable Stacked VLAN Processing Mode */
-/* -------- GMAC_TPFCP : (GMAC Offset: 0x0C4) Transmit PFC Pause Register -------- */
-#define GMAC_TPFCP_PEV_Pos 0
-#define GMAC_TPFCP_PEV_Msk (0xffu << GMAC_TPFCP_PEV_Pos) /**< \brief (GMAC_TPFCP) Priority Enable Vector */
-#define GMAC_TPFCP_PEV(value) ((GMAC_TPFCP_PEV_Msk & ((value) << GMAC_TPFCP_PEV_Pos)))
-#define GMAC_TPFCP_PQ_Pos 8
-#define GMAC_TPFCP_PQ_Msk (0xffu << GMAC_TPFCP_PQ_Pos) /**< \brief (GMAC_TPFCP) Pause Quantum */
-#define GMAC_TPFCP_PQ(value) ((GMAC_TPFCP_PQ_Msk & ((value) << GMAC_TPFCP_PQ_Pos)))
-/* -------- GMAC_SAMB1 : (GMAC Offset: 0x0C8) Specific Address 1 Mask Bottom [31:0] Register -------- */
-#define GMAC_SAMB1_ADDR_Pos 0
-#define GMAC_SAMB1_ADDR_Msk (0xffffffffu << GMAC_SAMB1_ADDR_Pos) /**< \brief (GMAC_SAMB1) Specific Address 1 Mask */
-#define GMAC_SAMB1_ADDR(value) ((GMAC_SAMB1_ADDR_Msk & ((value) << GMAC_SAMB1_ADDR_Pos)))
-/* -------- GMAC_SAMT1 : (GMAC Offset: 0x0CC) Specific Address 1 Mask Top [47:32] Register -------- */
-#define GMAC_SAMT1_ADDR_Pos 0
-#define GMAC_SAMT1_ADDR_Msk (0xffffu << GMAC_SAMT1_ADDR_Pos) /**< \brief (GMAC_SAMT1) Specific Address 1 Mask */
-#define GMAC_SAMT1_ADDR(value) ((GMAC_SAMT1_ADDR_Msk & ((value) << GMAC_SAMT1_ADDR_Pos)))
-/* -------- GMAC_OTLO : (GMAC Offset: 0x100) Octets Transmitted [31:0] Register -------- */
-#define GMAC_OTLO_TXO_Pos 0
-#define GMAC_OTLO_TXO_Msk (0xffffffffu << GMAC_OTLO_TXO_Pos) /**< \brief (GMAC_OTLO) Transmitted Octets */
-/* -------- GMAC_OTHI : (GMAC Offset: 0x104) Octets Transmitted [47:32] Register -------- */
-#define GMAC_OTHI_TXO_Pos 0
-#define GMAC_OTHI_TXO_Msk (0xffffu << GMAC_OTHI_TXO_Pos) /**< \brief (GMAC_OTHI) Transmitted Octets */
-/* -------- GMAC_FT : (GMAC Offset: 0x108) Frames Transmitted Register -------- */
-#define GMAC_FT_FTX_Pos 0
-#define GMAC_FT_FTX_Msk (0xffffffffu << GMAC_FT_FTX_Pos) /**< \brief (GMAC_FT) Frames Transmitted without Error */
-/* -------- GMAC_BCFT : (GMAC Offset: 0x10C) Broadcast Frames Transmitted Register -------- */
-#define GMAC_BCFT_BFTX_Pos 0
-#define GMAC_BCFT_BFTX_Msk (0xffffffffu << GMAC_BCFT_BFTX_Pos) /**< \brief (GMAC_BCFT) Broadcast Frames Transmitted without Error */
-/* -------- GMAC_MFT : (GMAC Offset: 0x110) Multicast Frames Transmitted Register -------- */
-#define GMAC_MFT_MFTX_Pos 0
-#define GMAC_MFT_MFTX_Msk (0xffffffffu << GMAC_MFT_MFTX_Pos) /**< \brief (GMAC_MFT) Multicast Frames Transmitted without Error */
-/* -------- GMAC_PFT : (GMAC Offset: 0x114) Pause Frames Transmitted Register -------- */
-#define GMAC_PFT_PFTX_Pos 0
-#define GMAC_PFT_PFTX_Msk (0xffffu << GMAC_PFT_PFTX_Pos) /**< \brief (GMAC_PFT) Pause Frames Transmitted Register */
-/* -------- GMAC_BFT64 : (GMAC Offset: 0x118) 64 Byte Frames Transmitted Register -------- */
-#define GMAC_BFT64_NFTX_Pos 0
-#define GMAC_BFT64_NFTX_Msk (0xffffffffu << GMAC_BFT64_NFTX_Pos) /**< \brief (GMAC_BFT64) 64 Byte Frames Transmitted without Error */
-/* -------- GMAC_TBFT127 : (GMAC Offset: 0x11C) 65 to 127 Byte Frames Transmitted Register -------- */
-#define GMAC_TBFT127_NFTX_Pos 0
-#define GMAC_TBFT127_NFTX_Msk (0xffffffffu << GMAC_TBFT127_NFTX_Pos) /**< \brief (GMAC_TBFT127) 65 to 127 Byte Frames Transmitted without Error */
-/* -------- GMAC_TBFT255 : (GMAC Offset: 0x120) 128 to 255 Byte Frames Transmitted Register -------- */
-#define GMAC_TBFT255_NFTX_Pos 0
-#define GMAC_TBFT255_NFTX_Msk (0xffffffffu << GMAC_TBFT255_NFTX_Pos) /**< \brief (GMAC_TBFT255) 128 to 255 Byte Frames Transmitted without Error */
-/* -------- GMAC_TBFT511 : (GMAC Offset: 0x124) 256 to 511 Byte Frames Transmitted Register -------- */
-#define GMAC_TBFT511_NFTX_Pos 0
-#define GMAC_TBFT511_NFTX_Msk (0xffffffffu << GMAC_TBFT511_NFTX_Pos) /**< \brief (GMAC_TBFT511) 256 to 511 Byte Frames Transmitted without Error */
-/* -------- GMAC_TBFT1023 : (GMAC Offset: 0x128) 512 to 1023 Byte Frames Transmitted Register -------- */
-#define GMAC_TBFT1023_NFTX_Pos 0
-#define GMAC_TBFT1023_NFTX_Msk (0xffffffffu << GMAC_TBFT1023_NFTX_Pos) /**< \brief (GMAC_TBFT1023) 512 to 1023 Byte Frames Transmitted without Error */
-/* -------- GMAC_TBFT1518 : (GMAC Offset: 0x12C) 1024 to 1518 Byte Frames Transmitted Register -------- */
-#define GMAC_TBFT1518_NFTX_Pos 0
-#define GMAC_TBFT1518_NFTX_Msk (0xffffffffu << GMAC_TBFT1518_NFTX_Pos) /**< \brief (GMAC_TBFT1518) 1024 to 1518 Byte Frames Transmitted without Error */
-/* -------- GMAC_GTBFT1518 : (GMAC Offset: 0x130) Greater Than 1518 Byte Frames Transmitted Register -------- */
-#define GMAC_GTBFT1518_NFTX_Pos 0
-#define GMAC_GTBFT1518_NFTX_Msk (0xffffffffu << GMAC_GTBFT1518_NFTX_Pos) /**< \brief (GMAC_GTBFT1518) Greater than 1518 Byte Frames Transmitted without Error */
-/* -------- GMAC_TUR : (GMAC Offset: 0x134) Transmit Under Runs Register -------- */
-#define GMAC_TUR_TXUNR_Pos 0
-#define GMAC_TUR_TXUNR_Msk (0x3ffu << GMAC_TUR_TXUNR_Pos) /**< \brief (GMAC_TUR) Transmit Under Runs */
-/* -------- GMAC_SCF : (GMAC Offset: 0x138) Single Collision Frames Register -------- */
-#define GMAC_SCF_SCOL_Pos 0
-#define GMAC_SCF_SCOL_Msk (0x3ffffu << GMAC_SCF_SCOL_Pos) /**< \brief (GMAC_SCF) Single Collision */
-/* -------- GMAC_MCF : (GMAC Offset: 0x13C) Multiple Collision Frames Register -------- */
-#define GMAC_MCF_MCOL_Pos 0
-#define GMAC_MCF_MCOL_Msk (0x3ffffu << GMAC_MCF_MCOL_Pos) /**< \brief (GMAC_MCF) Multiple Collision */
-/* -------- GMAC_EC : (GMAC Offset: 0x140) Excessive Collisions Register -------- */
-#define GMAC_EC_XCOL_Pos 0
-#define GMAC_EC_XCOL_Msk (0x3ffu << GMAC_EC_XCOL_Pos) /**< \brief (GMAC_EC) Excessive Collisions */
-/* -------- GMAC_LC : (GMAC Offset: 0x144) Late Collisions Register -------- */
-#define GMAC_LC_LCOL_Pos 0
-#define GMAC_LC_LCOL_Msk (0x3ffu << GMAC_LC_LCOL_Pos) /**< \brief (GMAC_LC) Late Collisions */
-/* -------- GMAC_DTF : (GMAC Offset: 0x148) Deferred Transmission Frames Register -------- */
-#define GMAC_DTF_DEFT_Pos 0
-#define GMAC_DTF_DEFT_Msk (0x3ffffu << GMAC_DTF_DEFT_Pos) /**< \brief (GMAC_DTF) Deferred Transmission */
-/* -------- GMAC_CSE : (GMAC Offset: 0x14C) Carrier Sense Errors Register -------- */
-#define GMAC_CSE_CSR_Pos 0
-#define GMAC_CSE_CSR_Msk (0x3ffu << GMAC_CSE_CSR_Pos) /**< \brief (GMAC_CSE) Carrier Sense Error */
-/* -------- GMAC_ORLO : (GMAC Offset: 0x150) Octets Received [31:0] Received -------- */
-#define GMAC_ORLO_RXO_Pos 0
-#define GMAC_ORLO_RXO_Msk (0xffffffffu << GMAC_ORLO_RXO_Pos) /**< \brief (GMAC_ORLO) Received Octets */
-/* -------- GMAC_ORHI : (GMAC Offset: 0x154) Octets Received [47:32] Received -------- */
-#define GMAC_ORHI_RXO_Pos 0
-#define GMAC_ORHI_RXO_Msk (0xffffu << GMAC_ORHI_RXO_Pos) /**< \brief (GMAC_ORHI) Received Octets */
-/* -------- GMAC_FR : (GMAC Offset: 0x158) Frames Received Register -------- */
-#define GMAC_FR_FRX_Pos 0
-#define GMAC_FR_FRX_Msk (0xffffffffu << GMAC_FR_FRX_Pos) /**< \brief (GMAC_FR) Frames Received without Error */
-/* -------- GMAC_BCFR : (GMAC Offset: 0x15C) Broadcast Frames Received Register -------- */
-#define GMAC_BCFR_BFRX_Pos 0
-#define GMAC_BCFR_BFRX_Msk (0xffffffffu << GMAC_BCFR_BFRX_Pos) /**< \brief (GMAC_BCFR) Broadcast Frames Received without Error */
-/* -------- GMAC_MFR : (GMAC Offset: 0x160) Multicast Frames Received Register -------- */
-#define GMAC_MFR_MFRX_Pos 0
-#define GMAC_MFR_MFRX_Msk (0xffffffffu << GMAC_MFR_MFRX_Pos) /**< \brief (GMAC_MFR) Multicast Frames Received without Error */
-/* -------- GMAC_PFR : (GMAC Offset: 0x164) Pause Frames Received Register -------- */
-#define GMAC_PFR_PFRX_Pos 0
-#define GMAC_PFR_PFRX_Msk (0xffffu << GMAC_PFR_PFRX_Pos) /**< \brief (GMAC_PFR) Pause Frames Received Register */
-/* -------- GMAC_BFR64 : (GMAC Offset: 0x168) 64 Byte Frames Received Register -------- */
-#define GMAC_BFR64_NFRX_Pos 0
-#define GMAC_BFR64_NFRX_Msk (0xffffffffu << GMAC_BFR64_NFRX_Pos) /**< \brief (GMAC_BFR64) 64 Byte Frames Received without Error */
-/* -------- GMAC_TBFR127 : (GMAC Offset: 0x16C) 65 to 127 Byte Frames Received Register -------- */
-#define GMAC_TBFR127_NFRX_Pos 0
-#define GMAC_TBFR127_NFRX_Msk (0xffffffffu << GMAC_TBFR127_NFRX_Pos) /**< \brief (GMAC_TBFR127) 65 to 127 Byte Frames Received without Error */
-/* -------- GMAC_TBFR255 : (GMAC Offset: 0x170) 128 to 255 Byte Frames Received Register -------- */
-#define GMAC_TBFR255_NFRX_Pos 0
-#define GMAC_TBFR255_NFRX_Msk (0xffffffffu << GMAC_TBFR255_NFRX_Pos) /**< \brief (GMAC_TBFR255) 128 to 255 Byte Frames Received without Error */
-/* -------- GMAC_TBFR511 : (GMAC Offset: 0x174) 256 to 511Byte Frames Received Register -------- */
-#define GMAC_TBFR511_NFRX_Pos 0
-#define GMAC_TBFR511_NFRX_Msk (0xffffffffu << GMAC_TBFR511_NFRX_Pos) /**< \brief (GMAC_TBFR511) 256 to 511 Byte Frames Received without Error */
-/* -------- GMAC_TBFR1023 : (GMAC Offset: 0x178) 512 to 1023 Byte Frames Received Register -------- */
-#define GMAC_TBFR1023_NFRX_Pos 0
-#define GMAC_TBFR1023_NFRX_Msk (0xffffffffu << GMAC_TBFR1023_NFRX_Pos) /**< \brief (GMAC_TBFR1023) 512 to 1023 Byte Frames Received without Error */
-/* -------- GMAC_TBFR1518 : (GMAC Offset: 0x17C) 1024 to 1518 Byte Frames Received Register -------- */
-#define GMAC_TBFR1518_NFRX_Pos 0
-#define GMAC_TBFR1518_NFRX_Msk (0xffffffffu << GMAC_TBFR1518_NFRX_Pos) /**< \brief (GMAC_TBFR1518) 1024 to 1518 Byte Frames Received without Error */
-/* -------- GMAC_TMXBFR : (GMAC Offset: 0x180) 1519 to Maximum Byte Frames Received Register -------- */
-#define GMAC_TMXBFR_NFRX_Pos 0
-#define GMAC_TMXBFR_NFRX_Msk (0xffffffffu << GMAC_TMXBFR_NFRX_Pos) /**< \brief (GMAC_TMXBFR) 1519 to Maximum Byte Frames Received without Error */
-/* -------- GMAC_UFR : (GMAC Offset: 0x184) Undersize Frames Received Register -------- */
-#define GMAC_UFR_UFRX_Pos 0
-#define GMAC_UFR_UFRX_Msk (0x3ffu << GMAC_UFR_UFRX_Pos) /**< \brief (GMAC_UFR) Undersize Frames Received */
-/* -------- GMAC_OFR : (GMAC Offset: 0x188) Oversize Frames Received Register -------- */
-#define GMAC_OFR_OFRX_Pos 0
-#define GMAC_OFR_OFRX_Msk (0x3ffu << GMAC_OFR_OFRX_Pos) /**< \brief (GMAC_OFR) Oversized Frames Received */
-/* -------- GMAC_JR : (GMAC Offset: 0x18C) Jabbers Received Register -------- */
-#define GMAC_JR_JRX_Pos 0
-#define GMAC_JR_JRX_Msk (0x3ffu << GMAC_JR_JRX_Pos) /**< \brief (GMAC_JR) Jabbers Received */
-/* -------- GMAC_FCSE : (GMAC Offset: 0x190) Frame Check Sequence Errors Register -------- */
-#define GMAC_FCSE_FCKR_Pos 0
-#define GMAC_FCSE_FCKR_Msk (0x3ffu << GMAC_FCSE_FCKR_Pos) /**< \brief (GMAC_FCSE) Frame Check Sequence Errors */
-/* -------- GMAC_LFFE : (GMAC Offset: 0x194) Length Field Frame Errors Register -------- */
-#define GMAC_LFFE_LFER_Pos 0
-#define GMAC_LFFE_LFER_Msk (0x3ffu << GMAC_LFFE_LFER_Pos) /**< \brief (GMAC_LFFE) Length Field Frame Errors */
-/* -------- GMAC_RSE : (GMAC Offset: 0x198) Receive Symbol Errors Register -------- */
-#define GMAC_RSE_RXSE_Pos 0
-#define GMAC_RSE_RXSE_Msk (0x3ffu << GMAC_RSE_RXSE_Pos) /**< \brief (GMAC_RSE) Receive Symbol Errors */
-/* -------- GMAC_AE : (GMAC Offset: 0x19C) Alignment Errors Register -------- */
-#define GMAC_AE_AER_Pos 0
-#define GMAC_AE_AER_Msk (0x3ffu << GMAC_AE_AER_Pos) /**< \brief (GMAC_AE) Alignment Errors */
-/* -------- GMAC_RRE : (GMAC Offset: 0x1A0) Receive Resource Errors Register -------- */
-#define GMAC_RRE_RXRER_Pos 0
-#define GMAC_RRE_RXRER_Msk (0x3ffffu << GMAC_RRE_RXRER_Pos) /**< \brief (GMAC_RRE) Receive Resource Errors */
-/* -------- GMAC_ROE : (GMAC Offset: 0x1A4) Receive Overrun Register -------- */
-#define GMAC_ROE_RXOVR_Pos 0
-#define GMAC_ROE_RXOVR_Msk (0x3ffu << GMAC_ROE_RXOVR_Pos) /**< \brief (GMAC_ROE) Receive Overruns */
-/* -------- GMAC_IHCE : (GMAC Offset: 0x1A8) IP Header Checksum Errors Register -------- */
-#define GMAC_IHCE_HCKER_Pos 0
-#define GMAC_IHCE_HCKER_Msk (0xffu << GMAC_IHCE_HCKER_Pos) /**< \brief (GMAC_IHCE) IP Header Checksum Errors */
-/* -------- GMAC_TCE : (GMAC Offset: 0x1AC) TCP Checksum Errors Register -------- */
-#define GMAC_TCE_TCKER_Pos 0
-#define GMAC_TCE_TCKER_Msk (0xffu << GMAC_TCE_TCKER_Pos) /**< \brief (GMAC_TCE) TCP Checksum Errors */
-/* -------- GMAC_UCE : (GMAC Offset: 0x1B0) UDP Checksum Errors Register -------- */
-#define GMAC_UCE_UCKER_Pos 0
-#define GMAC_UCE_UCKER_Msk (0xffu << GMAC_UCE_UCKER_Pos) /**< \brief (GMAC_UCE) UDP Checksum Errors */
-/* -------- GMAC_TSSS : (GMAC Offset: 0x1C8) 1588 Timer Sync Strobe Seconds Register -------- */
-#define GMAC_TSSS_VTS_Pos 0
-#define GMAC_TSSS_VTS_Msk (0xffffffffu << GMAC_TSSS_VTS_Pos) /**< \brief (GMAC_TSSS) Value of Timer Seconds Register Capture */
-#define GMAC_TSSS_VTS(value) ((GMAC_TSSS_VTS_Msk & ((value) << GMAC_TSSS_VTS_Pos)))
-/* -------- GMAC_TSSN : (GMAC Offset: 0x1CC) 1588 Timer Sync Strobe Nanoseconds Register -------- */
-#define GMAC_TSSN_VTN_Pos 0
-#define GMAC_TSSN_VTN_Msk (0x3fffffffu << GMAC_TSSN_VTN_Pos) /**< \brief (GMAC_TSSN) Value Timer Nanoseconds Register Capture */
-#define GMAC_TSSN_VTN(value) ((GMAC_TSSN_VTN_Msk & ((value) << GMAC_TSSN_VTN_Pos)))
-/* -------- GMAC_TS : (GMAC Offset: 0x1D0) 1588 Timer Seconds Register -------- */
-#define GMAC_TS_TCS_Pos 0
-#define GMAC_TS_TCS_Msk (0xffffffffu << GMAC_TS_TCS_Pos) /**< \brief (GMAC_TS) Timer Count in Seconds */
-#define GMAC_TS_TCS(value) ((GMAC_TS_TCS_Msk & ((value) << GMAC_TS_TCS_Pos)))
-/* -------- GMAC_TN : (GMAC Offset: 0x1D4) 1588 Timer Nanoseconds Register -------- */
-#define GMAC_TN_TNS_Pos 0
-#define GMAC_TN_TNS_Msk (0x3fffffffu << GMAC_TN_TNS_Pos) /**< \brief (GMAC_TN) Timer Count in Nanoseconds */
-#define GMAC_TN_TNS(value) ((GMAC_TN_TNS_Msk & ((value) << GMAC_TN_TNS_Pos)))
-/* -------- GMAC_TA : (GMAC Offset: 0x1D8) 1588 Timer Adjust Register -------- */
-#define GMAC_TA_ITDT_Pos 0
-#define GMAC_TA_ITDT_Msk (0x3fffffffu << GMAC_TA_ITDT_Pos) /**< \brief (GMAC_TA) Increment/Decrement */
-#define GMAC_TA_ITDT(value) ((GMAC_TA_ITDT_Msk & ((value) << GMAC_TA_ITDT_Pos)))
-#define GMAC_TA_ADJ (0x1u << 31) /**< \brief (GMAC_TA) Adjust 1588 Timer */
-/* -------- GMAC_TI : (GMAC Offset: 0x1DC) 1588 Timer Increment Register -------- */
-#define GMAC_TI_CNS_Pos 0
-#define GMAC_TI_CNS_Msk (0xffu << GMAC_TI_CNS_Pos) /**< \brief (GMAC_TI) Count Nanoseconds */
-#define GMAC_TI_CNS(value) ((GMAC_TI_CNS_Msk & ((value) << GMAC_TI_CNS_Pos)))
-#define GMAC_TI_ACNS_Pos 8
-#define GMAC_TI_ACNS_Msk (0xffu << GMAC_TI_ACNS_Pos) /**< \brief (GMAC_TI) Alternative Count Nanoseconds */
-#define GMAC_TI_ACNS(value) ((GMAC_TI_ACNS_Msk & ((value) << GMAC_TI_ACNS_Pos)))
-#define GMAC_TI_NIT_Pos 16
-#define GMAC_TI_NIT_Msk (0xffu << GMAC_TI_NIT_Pos) /**< \brief (GMAC_TI) Number of Increments */
-#define GMAC_TI_NIT(value) ((GMAC_TI_NIT_Msk & ((value) << GMAC_TI_NIT_Pos)))
-/* -------- GMAC_EFTS : (GMAC Offset: 0x1E0) PTP Event Frame Transmitted Seconds -------- */
-#define GMAC_EFTS_RUD_Pos 0
-#define GMAC_EFTS_RUD_Msk (0xffffffffu << GMAC_EFTS_RUD_Pos) /**< \brief (GMAC_EFTS) Register Update */
-/* -------- GMAC_EFTN : (GMAC Offset: 0x1E4) PTP Event Frame Transmitted Nanoseconds -------- */
-#define GMAC_EFTN_RUD_Pos 0
-#define GMAC_EFTN_RUD_Msk (0x3fffffffu << GMAC_EFTN_RUD_Pos) /**< \brief (GMAC_EFTN) Register Update */
-/* -------- GMAC_EFRS : (GMAC Offset: 0x1E8) PTP Event Frame Received Seconds -------- */
-#define GMAC_EFRS_RUD_Pos 0
-#define GMAC_EFRS_RUD_Msk (0xffffffffu << GMAC_EFRS_RUD_Pos) /**< \brief (GMAC_EFRS) Register Update */
-/* -------- GMAC_EFRN : (GMAC Offset: 0x1EC) PTP Event Frame Received Nanoseconds -------- */
-#define GMAC_EFRN_RUD_Pos 0
-#define GMAC_EFRN_RUD_Msk (0x3fffffffu << GMAC_EFRN_RUD_Pos) /**< \brief (GMAC_EFRN) Register Update */
-/* -------- GMAC_PEFTS : (GMAC Offset: 0x1F0) PTP Peer Event Frame Transmitted Seconds -------- */
-#define GMAC_PEFTS_RUD_Pos 0
-#define GMAC_PEFTS_RUD_Msk (0xffffffffu << GMAC_PEFTS_RUD_Pos) /**< \brief (GMAC_PEFTS) Register Update */
-/* -------- GMAC_PEFTN : (GMAC Offset: 0x1F4) PTP Peer Event Frame Transmitted Nanoseconds -------- */
-#define GMAC_PEFTN_RUD_Pos 0
-#define GMAC_PEFTN_RUD_Msk (0x3fffffffu << GMAC_PEFTN_RUD_Pos) /**< \brief (GMAC_PEFTN) Register Update */
-/* -------- GMAC_PEFRS : (GMAC Offset: 0x1F8) PTP Peer Event Frame Received Seconds -------- */
-#define GMAC_PEFRS_RUD_Pos 0
-#define GMAC_PEFRS_RUD_Msk (0xffffffffu << GMAC_PEFRS_RUD_Pos) /**< \brief (GMAC_PEFRS) Register Update */
-/* -------- GMAC_PEFRN : (GMAC Offset: 0x1FC) PTP Peer Event Frame Received Nanoseconds -------- */
-#define GMAC_PEFRN_RUD_Pos 0
-#define GMAC_PEFRN_RUD_Msk (0x3fffffffu << GMAC_PEFRN_RUD_Pos) /**< \brief (GMAC_PEFRN) Register Update */
-/* -------- GMAC_ISRPQ[7] : (GMAC Offset: 0x400) Interrupt Status Register Priority Queue -------- */
-#define GMAC_ISRPQ_RCOMP (0x1u << 1) /**< \brief (GMAC_ISRPQ[7]) Receive Complete */
-#define GMAC_ISRPQ_RXUBR (0x1u << 2) /**< \brief (GMAC_ISRPQ[7]) RX Used Bit Read */
-#define GMAC_ISRPQ_RLEX (0x1u << 5) /**< \brief (GMAC_ISRPQ[7]) Retry Limit Exceeded or Late Collision */
-#define GMAC_ISRPQ_TFC (0x1u << 6) /**< \brief (GMAC_ISRPQ[7]) Transmit Frame Corruption due to AHB error */
-#define GMAC_ISRPQ_TCOMP (0x1u << 7) /**< \brief (GMAC_ISRPQ[7]) Transmit Complete */
-#define GMAC_ISRPQ_ROVR (0x1u << 10) /**< \brief (GMAC_ISRPQ[7]) Receive Overrun */
-#define GMAC_ISRPQ_HRESP (0x1u << 11) /**< \brief (GMAC_ISRPQ[7]) HRESP Not OK */
-/* -------- GMAC_TBQBAPQ[7] : (GMAC Offset: 0x440) Transmit Buffer Queue Base Address Priority Queue -------- */
-#define GMAC_TBQBAPQ_TXBQBA_Pos 2
-#define GMAC_TBQBAPQ_TXBQBA_Msk (0x3fu << GMAC_TBQBAPQ_TXBQBA_Pos) /**< \brief (GMAC_TBQBAPQ[7]) Transmit Buffer Queue Base Address */
-#define GMAC_TBQBAPQ_TXBQBA(value) ((GMAC_TBQBAPQ_TXBQBA_Msk & ((value) << GMAC_TBQBAPQ_TXBQBA_Pos)))
-/* -------- GMAC_RBQBAPQ[7] : (GMAC Offset: 0x480) Receive Buffer Queue Base Address Priority Queue -------- */
-#define GMAC_RBQBAPQ_RXBQBA_Pos 2
-#define GMAC_RBQBAPQ_RXBQBA_Msk (0x3fu << GMAC_RBQBAPQ_RXBQBA_Pos) /**< \brief (GMAC_RBQBAPQ[7]) Receive Buffer Queue Base Address */
-#define GMAC_RBQBAPQ_RXBQBA(value) ((GMAC_RBQBAPQ_RXBQBA_Msk & ((value) << GMAC_RBQBAPQ_RXBQBA_Pos)))
-/* -------- GMAC_RBSRPQ[7] : (GMAC Offset: 0x4A0) Receive Buffer Size Register Priority Queue -------- */
-#define GMAC_RBSRPQ_RBS_Pos 0
-#define GMAC_RBSRPQ_RBS_Msk (0xffffu << GMAC_RBSRPQ_RBS_Pos) /**< \brief (GMAC_RBSRPQ[7]) Receive Buffer Size */
-#define GMAC_RBSRPQ_RBS(value) ((GMAC_RBSRPQ_RBS_Msk & ((value) << GMAC_RBSRPQ_RBS_Pos)))
-/* -------- GMAC_ST1RPQ[16] : (GMAC Offset: 0x500) Screening Type1 Register Priority Queue -------- */
-#define GMAC_ST1RPQ_QNB_Pos 0
-#define GMAC_ST1RPQ_QNB_Msk (0xfu << GMAC_ST1RPQ_QNB_Pos) /**< \brief (GMAC_ST1RPQ[16]) Que Number (0->7) */
-#define GMAC_ST1RPQ_QNB(value) ((GMAC_ST1RPQ_QNB_Msk & ((value) << GMAC_ST1RPQ_QNB_Pos)))
-#define GMAC_ST1RPQ_DSTCM_Pos 4
-#define GMAC_ST1RPQ_DSTCM_Msk (0xffu << GMAC_ST1RPQ_DSTCM_Pos) /**< \brief (GMAC_ST1RPQ[16]) Differentiated Services or Traffic Class Match */
-#define GMAC_ST1RPQ_DSTCM(value) ((GMAC_ST1RPQ_DSTCM_Msk & ((value) << GMAC_ST1RPQ_DSTCM_Pos)))
-#define GMAC_ST1RPQ_UDPM_Pos 12
-#define GMAC_ST1RPQ_UDPM_Msk (0xffffu << GMAC_ST1RPQ_UDPM_Pos) /**< \brief (GMAC_ST1RPQ[16]) UDP Port Match */
-#define GMAC_ST1RPQ_UDPM(value) ((GMAC_ST1RPQ_UDPM_Msk & ((value) << GMAC_ST1RPQ_UDPM_Pos)))
-#define GMAC_ST1RPQ_DSTCE (0x1u << 28) /**< \brief (GMAC_ST1RPQ[16]) Differentiated Services or Traffic Class Match Enable */
-#define GMAC_ST1RPQ_UDPE (0x1u << 29) /**< \brief (GMAC_ST1RPQ[16]) UDP Port Match Enable */
-/* -------- GMAC_ST2RPQ[16] : (GMAC Offset: 0x540) Screening Type2 Register Priority Queue -------- */
-#define GMAC_ST2RPQ_QNB_Pos 0
-#define GMAC_ST2RPQ_QNB_Msk (0xfu << GMAC_ST2RPQ_QNB_Pos) /**< \brief (GMAC_ST2RPQ[16]) Que Number (0->7) */
-#define GMAC_ST2RPQ_QNB(value) ((GMAC_ST2RPQ_QNB_Msk & ((value) << GMAC_ST2RPQ_QNB_Pos)))
-#define GMAC_ST2RPQ_VLANP_Pos 4
-#define GMAC_ST2RPQ_VLANP_Msk (0xfu << GMAC_ST2RPQ_VLANP_Pos) /**< \brief (GMAC_ST2RPQ[16]) VLAN Priority */
-#define GMAC_ST2RPQ_VLANP(value) ((GMAC_ST2RPQ_VLANP_Msk & ((value) << GMAC_ST2RPQ_VLANP_Pos)))
-#define GMAC_ST2RPQ_VLANE (0x1u << 8) /**< \brief (GMAC_ST2RPQ[16]) VLAN Enable */
-/* -------- GMAC_IERPQ[7] : (GMAC Offset: 0x600) Interrupt Enable Register Priority Queue -------- */
-#define GMAC_IERPQ_RCOMP (0x1u << 1) /**< \brief (GMAC_IERPQ[7]) Receive Complete */
-#define GMAC_IERPQ_RXUBR (0x1u << 2) /**< \brief (GMAC_IERPQ[7]) RX Used Bit Read */
-#define GMAC_IERPQ_RLEX (0x1u << 5) /**< \brief (GMAC_IERPQ[7]) Retry Limit Exceeded or Late Collision */
-#define GMAC_IERPQ_TFC (0x1u << 6) /**< \brief (GMAC_IERPQ[7]) Transmit Frame Corruption due to AHB error */
-#define GMAC_IERPQ_TCOMP (0x1u << 7) /**< \brief (GMAC_IERPQ[7]) Transmit Complete */
-#define GMAC_IERPQ_ROVR (0x1u << 10) /**< \brief (GMAC_IERPQ[7]) Receive Overrun */
-#define GMAC_IERPQ_HRESP (0x1u << 11) /**< \brief (GMAC_IERPQ[7]) HRESP Not OK */
-/* -------- GMAC_IDRPQ[7] : (GMAC Offset: 0x620) Interrupt Disable Register Priority Queue -------- */
-#define GMAC_IDRPQ_RCOMP (0x1u << 1) /**< \brief (GMAC_IDRPQ[7]) Receive Complete */
-#define GMAC_IDRPQ_RXUBR (0x1u << 2) /**< \brief (GMAC_IDRPQ[7]) RX Used Bit Read */
-#define GMAC_IDRPQ_RLEX (0x1u << 5) /**< \brief (GMAC_IDRPQ[7]) Retry Limit Exceeded or Late Collision */
-#define GMAC_IDRPQ_TFC (0x1u << 6) /**< \brief (GMAC_IDRPQ[7]) Transmit Frame Corruption due to AHB error */
-#define GMAC_IDRPQ_TCOMP (0x1u << 7) /**< \brief (GMAC_IDRPQ[7]) Transmit Complete */
-#define GMAC_IDRPQ_ROVR (0x1u << 10) /**< \brief (GMAC_IDRPQ[7]) Receive Overrun */
-#define GMAC_IDRPQ_HRESP (0x1u << 11) /**< \brief (GMAC_IDRPQ[7]) HRESP Not OK */
-/* -------- GMAC_IMRPQ[7] : (GMAC Offset: 0x640) Interrupt Mask Register Priority Queue -------- */
-#define GMAC_IMRPQ_RCOMP (0x1u << 1) /**< \brief (GMAC_IMRPQ[7]) Receive Complete */
-#define GMAC_IMRPQ_RXUBR (0x1u << 2) /**< \brief (GMAC_IMRPQ[7]) RX Used Bit Read */
-#define GMAC_IMRPQ_RLEX (0x1u << 5) /**< \brief (GMAC_IMRPQ[7]) Retry Limit Exceeded or Late Collision */
-#define GMAC_IMRPQ_AHB (0x1u << 6) /**< \brief (GMAC_IMRPQ[7]) AHB Error */
-#define GMAC_IMRPQ_TCOMP (0x1u << 7) /**< \brief (GMAC_IMRPQ[7]) Transmit Complete */
-#define GMAC_IMRPQ_ROVR (0x1u << 10) /**< \brief (GMAC_IMRPQ[7]) Receive Overrun */
-#define GMAC_IMRPQ_HRESP (0x1u << 11) /**< \brief (GMAC_IMRPQ[7]) HRESP Not OK */
-
-/*@}*/
-
-
-#endif /* _SAM4E_GMAC_COMPONENT_ */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.c
deleted file mode 100755
index fc72c6a..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.c
+++ /dev/null
@@ -1,454 +0,0 @@
- /**
- * \file
- *
- * \brief API driver for KSZ8051MNL PHY component.
- *
- * Copyright (c) 2013 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "FreeRTOSIPConfig.h"
-
-#include "ethernet_phy.h"
-#include "instance/gmac.h"
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-extern "C" {
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/**
- * \defgroup ksz8051mnl_ethernet_phy_group PHY component (KSZ8051MNL)
- *
- * Driver for the ksz8051mnl component. This driver provides access to the main
- * features of the PHY.
- *
- * \section dependencies Dependencies
- * This driver depends on the following modules:
- * - \ref gmac_group Ethernet Media Access Controller (GMAC) module.
- *
- * @{
- */
-
-SPhyProps phyProps;
-
-/* Max PHY number */
-#define ETH_PHY_MAX_ADDR 31
-
-/* Ethernet PHY operation max retry count */
-#define ETH_PHY_RETRY_MAX 1000000
-
-/* Ethernet PHY operation timeout */
-#define ETH_PHY_TIMEOUT 10
-
-/**
- * \brief Find a valid PHY Address ( from addrStart to 31 ).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param uc_start_addr Start address of the PHY to be searched.
- *
- * \return 0xFF when no valid PHY address is found.
- */
-int ethernet_phy_addr = 0;
-static uint8_t ethernet_phy_find_valid(Gmac *p_gmac, uint8_t uc_phy_addr,
- uint8_t uc_start_addr)
-{
- uint32_t ul_value = 0;
- uint8_t uc_cnt;
- uint8_t uc_phy_address = uc_phy_addr;
-
- gmac_enable_management(p_gmac, true);
-/*
-#define GMII_OUI_MSB 0x0022
-#define GMII_OUI_LSB 0x05
-
-PHYID1 = 0x0022
-PHYID2 = 0x1550
-0001_0101_0101_0000 = 0x1550 <= mask should be 0xFFF0
-*/
- /* Check the current PHY address */
- gmac_phy_read(p_gmac, uc_phy_addr, GMII_PHYID1, &ul_value);
-
- /* Find another one */
- if (ul_value != GMII_OUI_MSB) {
- ethernet_phy_addr = 0xFF;
- for (uc_cnt = uc_start_addr; uc_cnt <= ETH_PHY_MAX_ADDR; uc_cnt++) {
- uc_phy_address = (uc_phy_address + 1) & 0x1F;
- ul_value = 0;
- gmac_phy_read(p_gmac, uc_phy_address, GMII_PHYID1, &ul_value);
- if (ul_value == GMII_OUI_MSB) {
- ethernet_phy_addr = uc_phy_address;
- break;
- }
- }
- }
-
- gmac_enable_management(p_gmac, false);
-
- if (ethernet_phy_addr != 0xFF) {
- gmac_phy_read(p_gmac, uc_phy_address, GMII_BMSR, &ul_value);
- }
- return ethernet_phy_addr;
-}
-
-
-/**
- * \brief Perform a HW initialization to the PHY and set up clocks.
- *
- * This should be called only once to initialize the PHY pre-settings.
- * The PHY address is the reset status of CRS, RXD[3:0] (the emacPins' pullups).
- * The COL pin is used to select MII mode on reset (pulled up for Reduced MII).
- * The RXDV pin is used to select test mode on reset (pulled up for test mode).
- * The above pins should be predefined for corresponding settings in resetPins.
- * The GMAC peripheral pins are configured after the reset is done.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param ul_mck GMAC MCK.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t mck)
-{
- uint8_t uc_rc = GMAC_TIMEOUT;
- uint8_t uc_phy;
-
- ethernet_phy_reset(GMAC,uc_phy_addr);
-
- /* Configure GMAC runtime clock */
- uc_rc = gmac_set_mdc_clock(p_gmac, mck);
- if (uc_rc != GMAC_OK) {
- return 0;
- }
-
- /* Check PHY Address */
- uc_phy = ethernet_phy_find_valid(p_gmac, uc_phy_addr, 0);
- if (uc_phy == 0xFF) {
- return 0;
- }
- if (uc_phy != uc_phy_addr) {
- ethernet_phy_reset(p_gmac, uc_phy_addr);
- }
- phy_props.phy_chn = uc_phy;
- return uc_phy;
-}
-
-
-/**
- * \brief Get the Link & speed settings, and automatically set up the GMAC with the
- * settings.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param uc_apply_setting_flag Set to 0 to not apply the PHY configurations, else to apply.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_set_link(Gmac *p_gmac, uint8_t uc_phy_addr,
- uint8_t uc_apply_setting_flag)
-{
- uint32_t ul_stat1;
- uint32_t ul_stat2;
- uint8_t uc_phy_address, uc_speed = true, uc_fd = true;
- uint8_t uc_rc = GMAC_TIMEOUT;
-
- gmac_enable_management(p_gmac, true);
-
- uc_phy_address = uc_phy_addr;
-
- uc_rc = gmac_phy_read(p_gmac, uc_phy_address, GMII_BMSR, &ul_stat1);
- if (uc_rc != GMAC_OK) {
- /* Disable PHY management and start the GMAC transfer */
- gmac_enable_management(p_gmac, false);
-
- return uc_rc;
- }
- if ((ul_stat1 & GMII_LINK_STATUS) == 0) {
- /* Disable PHY management and start the GMAC transfer */
- gmac_enable_management(p_gmac, false);
-
- return GMAC_INVALID;
- }
-
- if (uc_apply_setting_flag == 0) {
- /* Disable PHY management and start the GMAC transfer */
- gmac_enable_management(p_gmac, false);
-
- return uc_rc;
- }
-
- /* Read advertisement */
- uc_rc = gmac_phy_read(p_gmac, uc_phy_address, GMII_ANAR, &ul_stat2);
-phy_props.phy_stat1 = ul_stat1;
-phy_props.phy_stat2 = ul_stat2;
- if (uc_rc != GMAC_OK) {
- /* Disable PHY management and start the GMAC transfer */
- gmac_enable_management(p_gmac, false);
-
- return uc_rc;
- }
-
- if ((ul_stat1 & GMII_100BASE_TX_FD) && (ul_stat2 & GMII_100TX_FDX)) {
- /* Set GMAC for 100BaseTX and Full Duplex */
- uc_speed = true;
- uc_fd = true;
- } else
- if ((ul_stat1 & GMII_100BASE_T4_HD) && (ul_stat2 & GMII_100TX_HDX)) {
- /* Set MII for 100BaseTX and Half Duplex */
- uc_speed = true;
- uc_fd = false;
- } else
- if ((ul_stat1 & GMII_10BASE_T_FD) && (ul_stat2 & GMII_10_FDX)) {
- /* Set MII for 10BaseT and Full Duplex */
- uc_speed = false;
- uc_fd = true;
- } else
- if ((ul_stat1 & GMII_10BASE_T_HD) && (ul_stat2 & GMII_10_HDX)) {
- /* Set MII for 10BaseT and Half Duplex */
- uc_speed = false;
- uc_fd = false;
- }
-
- gmac_set_speed(p_gmac, uc_speed);
- gmac_enable_full_duplex(p_gmac, uc_fd);
-
- /* Start the GMAC transfers */
- gmac_enable_management(p_gmac, false);
- return uc_rc;
-}
-
-PhyProps_t phy_props;
-
-/**
- * \brief Issue an auto negotiation of the PHY.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_auto_negotiate(Gmac *p_gmac, uint8_t uc_phy_addr)
-{
- uint32_t ul_retry_max = ETH_PHY_RETRY_MAX;
- uint32_t ul_value;
- uint32_t ul_phy_anar;
- uint32_t ul_retry_count = 0;
- uint8_t uc_speed = 0;
- uint8_t uc_fd=0;
- uint8_t uc_rc = GMAC_TIMEOUT;
-
- gmac_enable_management(p_gmac, true);
-
- /* Set up control register */
- uc_rc = gmac_phy_read(p_gmac, uc_phy_addr, GMII_BMCR, &ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -1;
- return uc_rc;
- }
-
- ul_value &= ~(uint32_t)GMII_AUTONEG; /* Remove auto-negotiation enable */
- ul_value &= ~(uint32_t)(GMII_LOOPBACK | GMII_POWER_DOWN);
- ul_value |= (uint32_t)GMII_ISOLATE; /* Electrically isolate PHY */
- uc_rc = gmac_phy_write(p_gmac, uc_phy_addr, GMII_BMCR, ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -2;
- return uc_rc;
- }
-
- /*
- * Set the Auto_negotiation Advertisement Register.
- * MII advertising for Next page.
- * 100BaseTxFD and HD, 10BaseTFD and HD, IEEE 802.3.
- */
- ul_phy_anar = GMII_100TX_FDX | GMII_100TX_HDX | GMII_10_FDX | GMII_10_HDX |
- GMII_AN_IEEE_802_3;
- uc_rc = gmac_phy_write(p_gmac, uc_phy_addr, GMII_ANAR, ul_phy_anar);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -3;
- return uc_rc;
- }
-
- /* Read & modify control register */
- uc_rc = gmac_phy_read(p_gmac, uc_phy_addr, GMII_BMCR, &ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -4;
- return uc_rc;
- }
-
- ul_value |= GMII_SPEED_SELECT | GMII_AUTONEG | GMII_DUPLEX_MODE;
- uc_rc = gmac_phy_write(p_gmac, uc_phy_addr, GMII_BMCR, ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -5;
- return uc_rc;
- }
-
- /* Restart auto negotiation */
- ul_value |= (uint32_t)GMII_RESTART_AUTONEG;
- ul_value &= ~(uint32_t)GMII_ISOLATE;
- uc_rc = gmac_phy_write(p_gmac, uc_phy_addr, GMII_BMCR, ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -6;
- return uc_rc;
- }
-
- /* Check if auto negotiation is completed */
- while (1) {
- uc_rc = gmac_phy_read(p_gmac, uc_phy_addr, GMII_BMSR, &ul_value);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -7;
- return uc_rc;
- }
- /* Done successfully */
- if (ul_value & GMII_AUTONEG_COMP) {
- break;
- }
-
- /* Timeout check */
- if (ul_retry_max) {
- if (++ul_retry_count >= ul_retry_max) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -8;
- return GMAC_TIMEOUT;
- }
- }
- }
-
- /* Get the auto negotiate link partner base page */
- uc_rc = gmac_phy_read(p_gmac, uc_phy_addr, GMII_PCR1, &phy_props.phy_params);
- if (uc_rc != GMAC_OK) {
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = -9;
- return uc_rc;
- }
-
-
- /* Set up the GMAC link speed */
- if ((ul_phy_anar & phy_props.phy_params) & GMII_100TX_FDX) {
- /* Set MII for 100BaseTX and Full Duplex */
- uc_speed = true;
- uc_fd = true;
- } else if ((ul_phy_anar & phy_props.phy_params) & GMII_10_FDX) {
- /* Set MII for 10BaseT and Full Duplex */
- uc_speed = false;
- uc_fd = true;
- } else if ((ul_phy_anar & phy_props.phy_params) & GMII_100TX_HDX) {
- /* Set MII for 100BaseTX and half Duplex */
- uc_speed = true;
- uc_fd = false;
- } else if ((ul_phy_anar & phy_props.phy_params) & GMII_10_HDX) {
- /* Set MII for 10BaseT and half Duplex */
- uc_speed = false;
- uc_fd = false;
- }
-
- gmac_set_speed(p_gmac, uc_speed);
- gmac_enable_full_duplex(p_gmac, uc_fd);
-
- /* Select Media Independent Interface type */
- gmac_select_mii_mode(p_gmac, ETH_PHY_MODE);
-
- gmac_enable_transmit(GMAC, true);
- gmac_enable_receive(GMAC, true);
-
- gmac_enable_management(p_gmac, false);
-phy_props.phy_result = 1;
- return uc_rc;
-}
-
-/**
- * \brief Issue a SW reset to reset all registers of the PHY.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- *
- * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_reset(Gmac *p_gmac, uint8_t uc_phy_addr)
-{
- uint32_t ul_bmcr = GMII_RESET;
- uint8_t uc_phy_address = uc_phy_addr;
- uint32_t ul_timeout = ETH_PHY_TIMEOUT;
- uint8_t uc_rc = GMAC_TIMEOUT;
-
- gmac_enable_management(p_gmac, true);
-
- ul_bmcr = GMII_RESET;
- gmac_phy_write(p_gmac, uc_phy_address, GMII_BMCR, ul_bmcr);
-
- do {
- gmac_phy_read(p_gmac, uc_phy_address, GMII_BMCR, &ul_bmcr);
- ul_timeout--;
- } while ((ul_bmcr & GMII_RESET) && ul_timeout);
-
- gmac_enable_management(p_gmac, false);
-
- if (!ul_timeout) {
- uc_rc = GMAC_OK;
- }
-
- return (uc_rc);
-}
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-}
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/**
- * \}
- */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.h
deleted file mode 100755
index 6729df0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.h
+++ /dev/null
@@ -1,281 +0,0 @@
-/**
- * \file
- *
- * \brief KSZ8051MNL (Ethernet PHY) driver for SAM.
- *
- * Copyright (c) 2013 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-#ifndef ETHERNET_PHY_H_INCLUDED
-#define ETHERNET_PHY_H_INCLUDED
-
-#include "compiler.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// IEEE defined Registers
-#define GMII_BMCR 0x00 // Basic Control
-#define GMII_BMSR 0x01 // Basic Status
-#define GMII_PHYID1 0x02 // PHY Idendifier 1
-#define GMII_PHYID2 0x03 // PHY Idendifier 2
-#define GMII_ANAR 0x04 // Auto_Negotiation Advertisement
-#define GMII_ANLPAR 0x05 // Auto_negotiation Link Partner Ability
-#define GMII_ANER 0x06 // Auto-negotiation Expansion
-#define GMII_ANNPR 0x07 // Auto-negotiation Next Page
-#define GMII_ANLPNPAR 0x08 // Link Partner Next Page Ability
-//#define GMII_1000BTCR 9 // 1000Base-T Control // Reserved
-//#define GMII_1000BTSR 10 // 1000Base-T Status // Reserved
-#define GMII_AFECR1 0x11 // AFE Control 1
-//#define GMII_ERDWR 12 // Extend Register - Data Write Register
-//#define GMII_ERDRR 13 // Extend Register - Data Read Register
-//14 reserved
-#define GMII_RXERCR 0x15 // RXER Counter
-
- #define PHY_REG_01_BMSR 0x01 // Basic mode status register
- #define PHY_REG_02_PHYSID1 0x02 // PHYS ID 1
- #define PHY_REG_03_PHYSID2 0x03 // PHYS ID 2
- #define PHY_REG_04_ADVERTISE 0x04 // Advertisement control reg
- #define PHY_REG_05_LPA 0x05 // Link partner ability reg
- #define PHY_REG_06_ANER 0x06 // 6 RW Auto-Negotiation Expansion Register
- #define PHY_REG_07_ANNPTR 0x07 // 7 RW Auto-Negotiation Next Page TX
- #define PHY_REG_08_RESERVED0 0x08 // 0x08..0x0Fh 8-15 RW RESERVED
-
- #define PHY_REG_10_PHYSTS 0x10 // 16 RO PHY Status Register
- #define PHY_REG_11_MICR 0x11 // 17 RW MII Interrupt Control Register
- #define PHY_REG_12_MISR 0x12 // 18 RO MII Interrupt Status Register
- #define PHY_REG_13_RESERVED1 0x13 // 19 RW RESERVED
- #define PHY_REG_14_FCSCR 0x14 // 20 RO False Carrier Sense Counter Register
- #define PHY_REG_15_RECR 0x15 // 21 RO Receive Error Counter Register
- #define PHY_REG_16_PCSR 0x16 // 22 RW PCS Sub-Layer Configuration and Status Register
- #define PHY_REG_17_RBR 0x17 // 23 RW RMII and Bypass Register
- #define PHY_REG_18_LEDCR 0x18 // 24 RW LED Direct Control Register
- #define PHY_REG_19_PHYCR 0x19 // 25 RW PHY Control Register
- #define PHY_REG_1A_10BTSCR 0x1A // 26 RW 10Base-T Status/Control Register
- #define PHY_REG_1B_CDCTRL1 0x1B // 27 RW CD Test Control Register and BIST Extensions Register
- #define PHY_REG_1B_INT_CTRL 0x1B // 27 RW KSZ8041NL interrupt control
- #define PHY_REG_1C_RESERVED2 0x1C // 28 RW RESERVED
- #define PHY_REG_1D_EDCR 0x1D // 29 RW Energy Detect Control Register
- #define PHY_REG_1E_RESERVED3 0x1E //
- #define PHY_REG_1F_RESERVED4 0x1F // 30-31 RW RESERVED
-
- #define PHY_REG_1E_PHYCR_1 0x1E //
- #define PHY_REG_1F_PHYCR_2 0x1F //
-
- #define PHY_SPEED_10 1
- #define PHY_SPEED_100 2
- #define PHY_SPEED_AUTO (PHY_SPEED_10|PHY_SPEED_100)
-
- #define PHY_MDIX_DIRECT 1
- #define PHY_MDIX_CROSSED 2
- #define PHY_MDIX_AUTO (PHY_MDIX_CROSSED|PHY_MDIX_DIRECT)
-
- #define PHY_DUPLEX_HALF 1
- #define PHY_DUPLEX_FULL 2
- #define PHY_DUPLEX_AUTO (PHY_DUPLEX_FULL|PHY_DUPLEX_HALF)
-
- typedef struct _SPhyProps {
- unsigned char speed;
- unsigned char mdix;
- unsigned char duplex;
- unsigned char spare;
- } SPhyProps;
-
- const char *phyPrintable (const SPhyProps *apProps);
-
- extern SPhyProps phyProps;
-
-#define GMII_OMSOR 0x16 // Operation Mode Strap Override
-#define GMII_OMSSR 0x17 // Operation Mode Strap Status
-#define GMII_ECR 0x18 // Expanded Control
-//#define GMII_DPPSR 19 // Digital PMA/PCS Status
-//20 reserved
-//#define GMII_RXERCR 21 // RXER Counter Register
-//22-26 reserved
-#define GMII_ICSR 0x1B // Interrupt Control/Status
-//#define GMII_DDC1R 28 // Digital Debug Control 1 Register
-#define GMII_LCSR 0x1D // LinkMD Control/Status
-
-//29-30 reserved
-#define GMII_PCR1 0x1E // PHY Control 1
-#define GMII_PCR2 0x1F // PHY Control 2
-
-/*
-//Extend Registers
-#define GMII_CCR 256 // Common Control Register
-#define GMII_SSR 257 // Strap Status Register
-#define GMII_OMSOR 258 // Operation Mode Strap Override Register
-#define GMII_OMSSR 259 // Operation Mode Strap Status Register
-#define GMII_RCCPSR 260 // RGMII Clock and Control Pad Skew Register
-#define GMII_RRDPSR 261 // RGMII RX Data Pad Skew Register
-#define GMII_ATR 263 // Analog Test Register
-*/
-
-
-// Bit definitions: GMII_BMCR 0x00 Basic Control
-#define GMII_RESET (1 << 15) // 1= Software Reset; 0=Normal Operation
-#define GMII_LOOPBACK (1 << 14) // 1=loopback Enabled; 0=Normal Operation
-#define GMII_SPEED_SELECT (1 << 13) // 1=100Mbps; 0=10Mbps
-#define GMII_AUTONEG (1 << 12) // Auto-negotiation Enable
-#define GMII_POWER_DOWN (1 << 11) // 1=Power down 0=Normal operation
-#define GMII_ISOLATE (1 << 10) // 1 = Isolates 0 = Normal operation
-#define GMII_RESTART_AUTONEG (1 << 9) // 1 = Restart auto-negotiation 0 = Normal operation
-#define GMII_DUPLEX_MODE (1 << 8) // 1 = Full duplex operation 0 = Normal operation
-#define GMII_COLLISION_TEST (1 << 7) // 1 = Enable COL test; 0 = Disable COL test
-//#define GMII_SPEED_SELECT_MSB (1 << 6) // Reserved
-// Reserved 6 to 0 // Read as 0, ignore on write
-
-// Bit definitions: GMII_BMSR 0x01 Basic Status
-#define GMII_100BASE_T4 (1 << 15) // 100BASE-T4 Capable
-#define GMII_100BASE_TX_FD (1 << 14) // 100BASE-TX Full Duplex Capable
-#define GMII_100BASE_T4_HD (1 << 13) // 100BASE-TX Half Duplex Capable
-#define GMII_10BASE_T_FD (1 << 12) // 10BASE-T Full Duplex Capable
-#define GMII_10BASE_T_HD (1 << 11) // 10BASE-T Half Duplex Capable
-// Reserved 10 to79 // Read as 0, ignore on write
-//#define GMII_EXTEND_STATUS (1 << 8) // 1 = Extend Status Information In Reg 15
-// Reserved 7
-#define GMII_MF_PREAMB_SUPPR (1 << 6) // MII Frame Preamble Suppression
-#define GMII_AUTONEG_COMP (1 << 5) // Auto-negotiation Complete
-#define GMII_REMOTE_FAULT (1 << 4) // Remote Fault
-#define GMII_AUTONEG_ABILITY (1 << 3) // Auto Configuration Ability
-#define GMII_LINK_STATUS (1 << 2) // Link Status
-#define GMII_JABBER_DETECT (1 << 1) // Jabber Detect
-#define GMII_EXTEND_CAPAB (1 << 0) // Extended Capability
-
-
-// Bit definitions: GMII_PHYID1 0x02 PHY Idendifier 1
-// Bit definitions: GMII_PHYID2 0x03 PHY Idendifier 2
-#define GMII_LSB_MASK 0x3F
-#define GMII_OUI_MSB 0x0022
-#define GMII_OUI_LSB 0x05
-
-
-// Bit definitions: GMII_ANAR 0x04 Auto_Negotiation Advertisement
-// Bit definitions: GMII_ANLPAR 0x05 Auto_negotiation Link Partner Ability
-#define GMII_NP (1 << 15) // Next page Indication
-// Reserved 7
-#define GMII_RF (1 << 13) // Remote Fault
-// Reserved 12 // Write as 0, ignore on read
-#define GMII_PAUSE_MASK (3 << 11) // 0,0 = No Pause 1,0 = Asymmetric Pause(link partner)
- // 0,1 = Symmetric Pause 1,1 = Symmetric&Asymmetric Pause(local device)
-#define GMII_100T4 (1 << 9) // 100BASE-T4 Support
-#define GMII_100TX_FDX (1 << 8) // 100BASE-TX Full Duplex Support
-#define GMII_100TX_HDX (1 << 7) // 100BASE-TX Support
-#define GMII_10_FDX (1 << 6) // 10BASE-T Full Duplex Support
-#define GMII_10_HDX (1 << 5) // 10BASE-T Support
-// Selector 4 to 0 // Protocol Selection Bits
-#define GMII_AN_IEEE_802_3 0x0001 // [00001] = IEEE 802.3
-
-
-// Bit definitions: GMII_ANER 0x06 Auto-negotiation Expansion
-// Reserved 15 to 5 // Read as 0, ignore on write
-#define GMII_PDF (1 << 4) // Local Device Parallel Detection Fault
-#define GMII_LP_NP_ABLE (1 << 3) // Link Partner Next Page Able
-#define GMII_NP_ABLE (1 << 2) // Local Device Next Page Able
-#define GMII_PAGE_RX (1 << 1) // New Page Received
-#define GMII_LP_AN_ABLE (1 << 0) // Link Partner Auto-negotiation Able
-
-/**
- * \brief Perform a HW initialization to the PHY and set up clocks.
- *
- * This should be called only once to initialize the PHY pre-settings.
- * The PHY address is the reset status of CRS, RXD[3:0] (the GmacPins' pullups).
- * The COL pin is used to select MII mode on reset (pulled up for Reduced MII).
- * The RXDV pin is used to select test mode on reset (pulled up for test mode).
- * The above pins should be predefined for corresponding settings in resetPins.
- * The GMAC peripheral pins are configured after the reset is done.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param ul_mck GMAC MCK.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t ul_mck);
-
-
-/**
- * \brief Get the Link & speed settings, and automatically set up the GMAC with the
- * settings.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param uc_apply_setting_flag Set to 0 to not apply the PHY configurations, else to apply.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_set_link(Gmac *p_gmac, uint8_t uc_phy_addr,
- uint8_t uc_apply_setting_flag);
-
-
-/**
- * \brief Issue an auto negotiation of the PHY.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- *
- * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_auto_negotiate(Gmac *p_gmac, uint8_t uc_phy_addr);
-
-/**
- * \brief Issue a SW reset to reset all registers of the PHY.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- *
- * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t ethernet_phy_reset(Gmac *p_gmac, uint8_t uc_phy_addr);
-
-typedef struct xPHY_PROPS {
- signed char phy_result;
- uint32_t phy_params;
- uint32_t phy_stat1;
- uint32_t phy_stat2;
- unsigned char phy_chn;
-} PhyProps_t;
-extern PhyProps_t phy_props;
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* #ifndef ETHERNET_PHY_H_INCLUDED */
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.c
deleted file mode 100755
index 5c21491..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.c
+++ /dev/null
@@ -1,945 +0,0 @@
- /**
- * \file
- *
- * \brief GMAC (Ethernet MAC) driver for SAM.
- *
- * Copyright (c) 2013 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-
-#include "FreeRTOSIPConfig.h"
-
-#include "compiler.h"
-#include "instance/gmac.h"
-#include "ethernet_phy.h"
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-extern "C" {
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (int)( sizeof(x) / sizeof(x)[0] )
-#endif
-/**
- * \defgroup gmac_group Ethernet Media Access Controller
- *
- * See \ref gmac_quickstart.
- *
- * Driver for the GMAC (Ethernet Media Access Controller).
- * This file contains basic functions for the GMAC, with support for all modes, settings
- * and clock speeds.
- *
- * \section dependencies Dependencies
- * This driver does not depend on other modules.
- *
- * @{
- */
-
-/** TX descriptor lists */
-COMPILER_ALIGNED(8)
-static gmac_tx_descriptor_t gs_tx_desc[ GMAC_TX_BUFFERS ];
-#if( GMAC_USES_TX_CALLBACK != 0 )
-/** TX callback lists */
-static gmac_dev_tx_cb_t gs_tx_callback[ GMAC_TX_BUFFERS ];
-#endif
-/** RX descriptors lists */
-COMPILER_ALIGNED(8)
-static gmac_rx_descriptor_t gs_rx_desc[ GMAC_RX_BUFFERS ];
-
-#if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- /** Send Buffer. Section 3.6 of AMBA 2.0 spec states that burst should not cross the
- * 1K Boundaries. Receive buffer manager write operations are burst of 2 words => 3 lsb bits
- * of the address shall be set to 0.
- */
- COMPILER_ALIGNED(8)
- static uint8_t gs_uc_tx_buffer[ GMAC_TX_BUFFERS * GMAC_TX_UNITSIZE ];
-#endif /* ipconfigZERO_COPY_TX_DRIVER */
-
-/** Receive Buffer */
-COMPILER_ALIGNED(8)
-static uint8_t gs_uc_rx_buffer[ GMAC_RX_BUFFERS * GMAC_RX_UNITSIZE ];
-
-/**
- * GMAC device memory management struct.
- */
-typedef struct gmac_dev_mem {
- /* Pointer to allocated buffer for RX. The address should be 8-byte aligned
- and the size should be GMAC_RX_UNITSIZE * wRxSize. */
- uint8_t *p_rx_buffer;
- /* Pointer to allocated RX descriptor list. */
- gmac_rx_descriptor_t *p_rx_dscr;
- /* RX size, in number of registered units (RX descriptors). */
- /* Increased size from 16- to 32-bits, because it's more efficient */
- uint32_t us_rx_size;
- /* Pointer to allocated buffer for TX. The address should be 8-byte aligned
- and the size should be GMAC_TX_UNITSIZE * wTxSize. */
- uint8_t *p_tx_buffer;
- /* Pointer to allocated TX descriptor list. */
- gmac_tx_descriptor_t *p_tx_dscr;
- /* TX size, in number of registered units (TX descriptors). */
- uint32_t us_tx_size;
-} gmac_dev_mem_t;
-
-/** Return count in buffer */
-#define CIRC_CNT( head, tail, size ) ( ( ( head ) - ( tail ) ) % ( size ) )
-
-/*
- * Return space available, from 0 to size-1.
- * Always leave one free char as a completely full buffer that has (head == tail),
- * which is the same as empty.
- */
-#define CIRC_SPACE( head, tail, size ) CIRC_CNT( ( tail ), ( ( head ) + 1 ), ( size ) )
-
-/** Circular buffer is empty ? */
-#define CIRC_EMPTY( head, tail ) ( head == tail )
-/** Clear circular buffer */
-#define CIRC_CLEAR( head, tail ) do { ( head ) = 0; ( tail ) = 0; } while( 0 )
-
-/** Increment head or tail */
-static __inline void circ_inc32( int32_t *lHeadOrTail, uint32_t ulSize )
-{
- ( *lHeadOrTail ) ++;
- if( ( *lHeadOrTail ) >= ( int32_t )ulSize )
- {
- ( *lHeadOrTail ) = 0;
- }
-}
-
-/**
- * \brief Wait PHY operation to be completed.
- *
- * \param p_gmac HW controller address.
- * \param ul_retry The retry times, 0 to wait forever until completeness.
- *
- * Return GMAC_OK if the operation is completed successfully.
- */
-static uint8_t gmac_wait_phy(Gmac* p_gmac, const uint32_t ul_retry)
-{
- volatile uint32_t ul_retry_count = 0;
- const uint32_t xPHYPollDelay = pdMS_TO_TICKS( 1ul );
-
- while (!gmac_is_phy_idle(p_gmac)) {
- if (ul_retry == 0) {
- continue;
- }
-
- ul_retry_count++;
-
- if (ul_retry_count >= ul_retry) {
- return GMAC_TIMEOUT;
- }
-
- /* Block the task to allow other tasks to execute while the PHY
- is not connected. */
- vTaskDelay( xPHYPollDelay );
- }
- return GMAC_OK;
-}
-
-/**
- * \brief Disable transfer, reset registers and descriptor lists.
- *
- * \param p_dev Pointer to GMAC driver instance.
- *
- */
-static void gmac_reset_tx_mem(gmac_device_t* p_dev)
-{
- Gmac *p_hw = p_dev->p_hw;
- uint8_t *p_tx_buff = p_dev->p_tx_buffer;
- gmac_tx_descriptor_t *p_td = p_dev->p_tx_dscr;
-
- uint32_t ul_index;
- uint32_t ul_address;
-
- /* Disable TX */
- gmac_enable_transmit(p_hw, 0);
-
- /* Set up the TX descriptors */
- CIRC_CLEAR(p_dev->l_tx_head, p_dev->l_tx_tail);
- for( ul_index = 0; ul_index < p_dev->ul_tx_list_size; ul_index++ )
- {
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- ul_address = (uint32_t) 0u;
- }
- #else
- {
- ul_address = (uint32_t) (&(p_tx_buff[ul_index * GMAC_TX_UNITSIZE]));
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
- p_td[ul_index].addr = ul_address;
- p_td[ul_index].status.val = GMAC_TXD_USED;
- }
- p_td[p_dev->ul_tx_list_size - 1].status.val =
- GMAC_TXD_USED | GMAC_TXD_WRAP;
-
- /* Set transmit buffer queue */
- gmac_set_tx_queue(p_hw, (uint32_t) p_td);
-}
-
-/**
- * \brief Disable receiver, reset registers and descriptor list.
- *
- * \param p_drv Pointer to GMAC Driver instance.
- */
-static void gmac_reset_rx_mem(gmac_device_t* p_dev)
-{
- Gmac *p_hw = p_dev->p_hw;
- uint8_t *p_rx_buff = p_dev->p_rx_buffer;
- gmac_rx_descriptor_t *pRd = p_dev->p_rx_dscr;
-
- uint32_t ul_index;
- uint32_t ul_address;
-
- /* Disable RX */
- gmac_enable_receive(p_hw, 0);
-
- /* Set up the RX descriptors */
- p_dev->ul_rx_idx = 0;
- for( ul_index = 0; ul_index < p_dev->ul_rx_list_size; ul_index++ )
- {
- ul_address = (uint32_t) (&(p_rx_buff[ul_index * GMAC_RX_UNITSIZE]));
- pRd[ul_index].addr.val = ul_address & GMAC_RXD_ADDR_MASK;
- pRd[ul_index].status.val = 0;
- }
- pRd[p_dev->ul_rx_list_size - 1].addr.val |= GMAC_RXD_WRAP;
-
- /* Set receive buffer queue */
- gmac_set_rx_queue(p_hw, (uint32_t) pRd);
-}
-
-
-/**
- * \brief Initialize the allocated buffer lists for GMAC driver to transfer data.
- * Must be invoked after gmac_dev_init() but before RX/TX starts.
- *
- * \note If input address is not 8-byte aligned, the address is automatically
- * adjusted and the list size is reduced by one.
- *
- * \param p_gmac Pointer to GMAC instance.
- * \param p_gmac_dev Pointer to GMAC device instance.
- * \param p_dev_mm Pointer to the GMAC memory management control block.
- * \param p_tx_cb Pointer to allocated TX callback list.
- *
- * \return GMAC_OK or GMAC_PARAM.
- */
-static uint8_t gmac_init_mem(Gmac* p_gmac, gmac_device_t* p_gmac_dev,
- gmac_dev_mem_t* p_dev_mm
-#if( GMAC_USES_TX_CALLBACK != 0 )
- , gmac_dev_tx_cb_t* p_tx_cb
-#endif
- )
-{
- if (p_dev_mm->us_rx_size <= 1 || p_dev_mm->us_tx_size <= 1
-#if( GMAC_USES_TX_CALLBACK != 0 )
- || p_tx_cb == NULL
-#endif
- ) {
- return GMAC_PARAM;
- }
-
- /* Assign RX buffers */
- if (((uint32_t) p_dev_mm->p_rx_buffer & 0x7)
- || ((uint32_t) p_dev_mm->p_rx_dscr & 0x7)) {
- p_dev_mm->us_rx_size--;
- }
- p_gmac_dev->p_rx_buffer =
- (uint8_t *) ((uint32_t) p_dev_mm->p_rx_buffer & 0xFFFFFFF8);
- p_gmac_dev->p_rx_dscr =
- (gmac_rx_descriptor_t *) ((uint32_t) p_dev_mm->p_rx_dscr
- & 0xFFFFFFF8);
- p_gmac_dev->ul_rx_list_size = p_dev_mm->us_rx_size;
-
- /* Assign TX buffers */
- if (((uint32_t) p_dev_mm->p_tx_buffer & 0x7)
- || ((uint32_t) p_dev_mm->p_tx_dscr & 0x7)) {
- p_dev_mm->us_tx_size--;
- }
- p_gmac_dev->p_tx_buffer =
- (uint8_t *) ((uint32_t) p_dev_mm->p_tx_buffer & 0xFFFFFFF8);
- p_gmac_dev->p_tx_dscr =
- (gmac_tx_descriptor_t *) ((uint32_t) p_dev_mm->p_tx_dscr
- & 0xFFFFFFF8);
- p_gmac_dev->ul_tx_list_size = p_dev_mm->us_tx_size;
-#if( GMAC_USES_TX_CALLBACK != 0 )
- p_gmac_dev->func_tx_cb_list = p_tx_cb;
-#endif
- /* Reset TX & RX */
- gmac_reset_rx_mem(p_gmac_dev);
- gmac_reset_tx_mem(p_gmac_dev);
-
- /* Enable Rx and Tx, plus the statistics register */
- gmac_enable_transmit(p_gmac, true);
- gmac_enable_receive(p_gmac, true);
- gmac_enable_statistics_write(p_gmac, true);
-
- /* Set up the interrupts for transmission and errors */
- gmac_enable_interrupt(p_gmac,
- GMAC_IER_RXUBR | /* Enable receive used bit read interrupt. */
- GMAC_IER_TUR | /* Enable transmit underrun interrupt. */
- GMAC_IER_RLEX | /* Enable retry limit exceeded interrupt. */
- GMAC_IER_TFC | /* Enable transmit buffers exhausted in mid-frame interrupt. */
- GMAC_IER_TCOMP | /* Enable transmit complete interrupt. */
- GMAC_IER_ROVR | /* Enable receive overrun interrupt. */
- GMAC_IER_HRESP | /* Enable Hresp not OK interrupt. */
- GMAC_IER_PFNZ | /* Enable pause frame received interrupt. */
- GMAC_IER_PTZ); /* Enable pause time zero interrupt. */
-
- return GMAC_OK;
-}
-
-/**
- * \brief Read the PHY register.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_address PHY address.
- * \param uc_address Register address.
- * \param p_value Pointer to a 32-bit location to store read data.
- *
- * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t gmac_phy_read(Gmac* p_gmac, uint8_t uc_phy_address, uint8_t uc_address,
- uint32_t* p_value)
-{
- gmac_maintain_phy(p_gmac, uc_phy_address, uc_address, 1, 0);
-
- if (gmac_wait_phy(p_gmac, MAC_PHY_RETRY_MAX) == GMAC_TIMEOUT) {
- return GMAC_TIMEOUT;
- }
- *p_value = gmac_get_phy_data(p_gmac);
- return GMAC_OK;
-}
-
-/**
- * \brief Write the PHY register.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_address PHY Address.
- * \param uc_address Register Address.
- * \param ul_value Data to write, actually 16-bit data.
- *
- * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
- */
-uint8_t gmac_phy_write(Gmac* p_gmac, uint8_t uc_phy_address,
- uint8_t uc_address, uint32_t ul_value)
-{
- gmac_maintain_phy(p_gmac, uc_phy_address, uc_address, 0, ul_value);
-
- if (gmac_wait_phy(p_gmac, MAC_PHY_RETRY_MAX) == GMAC_TIMEOUT) {
- return GMAC_TIMEOUT;
- }
- return GMAC_OK;
-}
-
-/**
- * \brief Initialize the GMAC driver.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param p_gmac_dev Pointer to the GMAC device instance.
- * \param p_opt GMAC configure options.
- */
-void gmac_dev_init(Gmac* p_gmac, gmac_device_t* p_gmac_dev,
- gmac_options_t* p_opt)
-{
- gmac_dev_mem_t gmac_dev_mm;
-
- /* Disable TX & RX and more */
- gmac_network_control(p_gmac, 0);
- gmac_disable_interrupt(p_gmac, ~0u);
-
-
- gmac_clear_statistics(p_gmac);
-
- /* Clear all status bits in the receive status register. */
- gmac_clear_rx_status(p_gmac, GMAC_RSR_RXOVR | GMAC_RSR_REC | GMAC_RSR_BNA);
-
- /* Clear all status bits in the transmit status register */
- gmac_clear_tx_status(p_gmac, GMAC_TSR_UBR | GMAC_TSR_COL | GMAC_TSR_RLE
- | GMAC_TSR_TFC | GMAC_TSR_TXCOMP | GMAC_TSR_UND);
-
- /* Clear interrupts */
- gmac_get_interrupt_status(p_gmac);
-#if !defined(ETHERNET_CONF_DATA_OFFSET)
- /* Receive Buffer Offset
- * Indicates the number of bytes by which the received data
- * is offset from the start of the receive buffer
- * which can be handy for alignment reasons */
- /* Note: FreeRTOS+TCP wants to have this offset set to 2 bytes */
- #error ETHERNET_CONF_DATA_OFFSET not defined, assuming 0
-#endif
- /* Enable the copy of data into the buffers
- ignore broadcasts, and not copy FCS. */
-
- gmac_set_configure(p_gmac,
- ( gmac_get_configure(p_gmac) & ~GMAC_NCFGR_RXBUFO_Msk ) |
- GMAC_NCFGR_RFCS | /* Remove FCS, frame check sequence (last 4 bytes) */
- GMAC_NCFGR_PEN | /* Pause Enable */
- GMAC_NCFGR_RXBUFO( ETHERNET_CONF_DATA_OFFSET ) |
- GMAC_RXD_RXCOEN );
-
- /*
- * GMAC_DCFGR_TXCOEN: (GMAC_DCFGR) Transmitter Checksum Generation Offload Enable.
- * Note: tha SAM4E does have RX checksum offloading
- * but TX checksum offloading has NOT been implemented.
- * http://community.atmel.com/forum/sam4e-gmac-transmit-checksum-offload-enablesolved
- */
-
- gmac_set_dma(p_gmac,
- gmac_get_dma(p_gmac) | GMAC_DCFGR_TXCOEN );
-
- gmac_enable_copy_all(p_gmac, p_opt->uc_copy_all_frame);
- gmac_disable_broadcast(p_gmac, p_opt->uc_no_boardcast);
-
- /* Fill in GMAC device memory management */
- gmac_dev_mm.p_rx_buffer = gs_uc_rx_buffer;
- gmac_dev_mm.p_rx_dscr = gs_rx_desc;
- gmac_dev_mm.us_rx_size = GMAC_RX_BUFFERS;
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- gmac_dev_mm.p_tx_buffer = NULL;
- }
- #else
- {
- gmac_dev_mm.p_tx_buffer = gs_uc_tx_buffer;
- }
- #endif
- gmac_dev_mm.p_tx_dscr = gs_tx_desc;
- gmac_dev_mm.us_tx_size = GMAC_TX_BUFFERS;
-
- gmac_init_mem(p_gmac, p_gmac_dev, &gmac_dev_mm
-#if( GMAC_USES_TX_CALLBACK != 0 )
- , gs_tx_callback
-#endif
- );
-
- gmac_set_address(p_gmac, 0, p_opt->uc_mac_addr);
-}
-
-/**
- * \brief Frames can be read from the GMAC in multiple sections.
- *
- * Returns > 0 if a complete frame is available
- * It also it cleans up incomplete older frames
- */
-
-static uint32_t gmac_dev_poll(gmac_device_t* p_gmac_dev)
-{
- uint32_t ulReturn = 0;
- int32_t ulIndex = p_gmac_dev->ul_rx_idx;
- gmac_rx_descriptor_t *pxHead = &p_gmac_dev->p_rx_dscr[ulIndex];
-
- /* Discard any incomplete frames */
- while ((pxHead->addr.val & GMAC_RXD_OWNERSHIP) &&
- (pxHead->status.val & GMAC_RXD_SOF) == 0) {
- pxHead->addr.val &= ~(GMAC_RXD_OWNERSHIP);
- circ_inc32 (&ulIndex, p_gmac_dev->ul_rx_list_size);
- pxHead = &p_gmac_dev->p_rx_dscr[ulIndex];
- p_gmac_dev->ul_rx_idx = ulIndex;
- #if( GMAC_STATS != 0 )
- {
- gmacStats.incompCount++;
- }
- #endif
- }
-
- while ((pxHead->addr.val & GMAC_RXD_OWNERSHIP) != 0) {
- if ((pxHead->status.val & GMAC_RXD_EOF) != 0) {
- /* Here a complete frame has been seen with SOF and EOF */
- ulReturn = pxHead->status.bm.len;
- break;
- }
- circ_inc32 (&ulIndex, p_gmac_dev->ul_rx_list_size);
- pxHead = &p_gmac_dev->p_rx_dscr[ulIndex];
- if ((pxHead->addr.val & GMAC_RXD_OWNERSHIP) == 0) {
- /* CPU is not the owner (yet) */
- break;
- }
- if ((pxHead->status.val & GMAC_RXD_SOF) != 0) {
- /* Strange, we found a new Start Of Frame
- * discard previous segments */
- int32_t ulPrev = p_gmac_dev->ul_rx_idx;
- pxHead = &p_gmac_dev->p_rx_dscr[ulPrev];
- do {
- pxHead->addr.val &= ~(GMAC_RXD_OWNERSHIP);
- circ_inc32 (&ulPrev, p_gmac_dev->ul_rx_list_size);
- pxHead = &p_gmac_dev->p_rx_dscr[ulPrev];
- #if( GMAC_STATS != 0 )
- {
- gmacStats.truncCount++;
- }
- #endif
- } while (ulPrev != ulIndex);
- p_gmac_dev->ul_rx_idx = ulIndex;
- }
- }
- return ulReturn;
-}
-
-/**
- * \brief Frames can be read from the GMAC in multiple sections.
- * Read ul_frame_size bytes from the GMAC receive buffers to pcTo.
- * p_rcv_size is the size of the entire frame. Generally gmac_read
- * will be repeatedly called until the sum of all the ul_frame_size equals
- * the value of p_rcv_size.
- *
- * \param p_gmac_dev Pointer to the GMAC device instance.
- * \param p_frame Address of the frame buffer.
- * \param ul_frame_size Length of the frame.
- * \param p_rcv_size Received frame size.
- *
- * \return GMAC_OK if receiving frame successfully, otherwise failed.
- */
-uint32_t gmac_dev_read(gmac_device_t* p_gmac_dev, uint8_t* p_frame,
- uint32_t ul_frame_size, uint32_t* p_rcv_size)
-{
- int32_t nextIdx; /* A copy of the Rx-index 'ul_rx_idx' */
- int32_t bytesLeft = gmac_dev_poll (p_gmac_dev);
- gmac_rx_descriptor_t *pxHead;
-
- if (bytesLeft == 0 )
- {
- return GMAC_RX_NULL;
- }
-
- /* gmac_dev_poll has confirmed that there is a complete frame at
- * the current position 'ul_rx_idx'
- */
- nextIdx = p_gmac_dev->ul_rx_idx;
-
- /* Read +2 bytes because buffers are aligned at -2 bytes */
- bytesLeft = min( bytesLeft + 2, ( int32_t )ul_frame_size );
-
- /* The frame will be copied in 1 or 2 memcpy's */
- if( ( p_frame != NULL ) && ( bytesLeft != 0 ) )
- {
- const uint8_t *source;
- int32_t left;
- int32_t toCopy;
-
- source = p_gmac_dev->p_rx_buffer + nextIdx * GMAC_RX_UNITSIZE;
- left = bytesLeft;
- toCopy = ( p_gmac_dev->ul_rx_list_size - nextIdx ) * GMAC_RX_UNITSIZE;
- if(toCopy > left )
- {
- toCopy = left;
- }
- memcpy (p_frame, source, toCopy);
- left -= toCopy;
-
- if( left != 0ul )
- {
- memcpy (p_frame + toCopy, (void*)p_gmac_dev->p_rx_buffer, left);
- }
- }
-
- do
- {
- pxHead = &p_gmac_dev->p_rx_dscr[nextIdx];
- pxHead->addr.val &= ~(GMAC_RXD_OWNERSHIP);
- circ_inc32 (&nextIdx, p_gmac_dev->ul_rx_list_size);
- } while ((pxHead->status.val & GMAC_RXD_EOF) == 0);
-
- p_gmac_dev->ul_rx_idx = nextIdx;
-
- *p_rcv_size = bytesLeft;
-
- return GMAC_OK;
-}
-
-
-extern void vGMACGenerateChecksum( uint8_t *apBuffer );
-
-/**
- * \brief Send ulLength bytes from pcFrom. This copies the buffer to one of the
- * GMAC Tx buffers, and then indicates to the GMAC that the buffer is ready.
- * If lEndOfFrame is true then the data being copied is the end of the frame
- * and the frame can be transmitted.
- *
- * \param p_gmac_dev Pointer to the GMAC device instance.
- * \param p_buffer Pointer to the data buffer.
- * \param ul_size Length of the frame.
- * \param func_tx_cb Transmit callback function.
- *
- * \return Length sent.
- */
-uint32_t gmac_dev_write(gmac_device_t* p_gmac_dev, void *p_buffer,
- uint32_t ul_size, gmac_dev_tx_cb_t func_tx_cb)
-{
-
- volatile gmac_tx_descriptor_t *p_tx_td;
-#if( GMAC_USES_TX_CALLBACK != 0 )
- volatile gmac_dev_tx_cb_t *p_func_tx_cb;
-#endif
-
- Gmac *p_hw = p_gmac_dev->p_hw;
-
-#if( GMAC_USES_TX_CALLBACK == 0 )
- ( void )func_tx_cb;
-#endif
-
- /* Check parameter */
- if (ul_size > GMAC_TX_UNITSIZE) {
- return GMAC_PARAM;
- }
-
- /* Pointers to the current transmit descriptor */
- p_tx_td = &p_gmac_dev->p_tx_dscr[p_gmac_dev->l_tx_head];
-
- /* If no free TxTd, buffer can't be sent, schedule the wakeup callback */
-// if (CIRC_SPACE(p_gmac_dev->l_tx_head, p_gmac_dev->l_tx_tail,
-// p_gmac_dev->ul_tx_list_size) == 0)
- {
- if ((p_tx_td->status.val & GMAC_TXD_USED) == 0)
- return GMAC_TX_BUSY;
- }
-#if( GMAC_USES_TX_CALLBACK != 0 )
- /* Pointers to the current Tx callback */
- p_func_tx_cb = &p_gmac_dev->func_tx_cb_list[p_gmac_dev->l_tx_head];
-#endif
-
- /* Set up/copy data to transmission buffer */
- if (p_buffer && ul_size) {
- /* Driver manages the ring buffer */
- /* Calculating the checksum here is faster than calculating it from the GMAC buffer
- * because withing p_buffer, it is well aligned */
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* Zero-copy... */
- p_tx_td->addr = ( uint32_t ) p_buffer;
- }
- #else
- {
- /* Or memcopy... */
- memcpy((void *)p_tx_td->addr, p_buffer, ul_size);
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
- vGMACGenerateChecksum( ( uint8_t * ) p_tx_td->addr );
- }
-
-#if( GMAC_USES_TX_CALLBACK != 0 )
- /* Tx callback */
- *p_func_tx_cb = func_tx_cb;
-#endif
-
- /* Update transmit descriptor status */
-
- /* The buffer size defined is the length of ethernet frame,
- so it's always the last buffer of the frame. */
- if( p_gmac_dev->l_tx_head == ( int32_t )( p_gmac_dev->ul_tx_list_size - 1 ) )
- {
- /* No need to 'and' with GMAC_TXD_LEN_MASK because ul_size has been checked */
- p_tx_td->status.val =
- ul_size | GMAC_TXD_LAST | GMAC_TXD_WRAP;
- } else {
- p_tx_td->status.val =
- ul_size | GMAC_TXD_LAST;
- }
-
- circ_inc32( &p_gmac_dev->l_tx_head, p_gmac_dev->ul_tx_list_size );
-
- /* Now start to transmit if it is still not done */
- gmac_start_transmission(p_hw);
-
- return GMAC_OK;
-}
-
-/**
- * \brief Get current load of transmit.
- *
- * \param p_gmac_dev Pointer to the GMAC device instance.
- *
- * \return Current load of transmit.
- */
-#if( GMAC_USES_TX_CALLBACK != 0 )
-/* Without defining GMAC_USES_TX_CALLBACK, l_tx_tail won't be updated */
-uint32_t gmac_dev_get_tx_load(gmac_device_t* p_gmac_dev)
-{
- uint16_t us_head = p_gmac_dev->l_tx_head;
- uint16_t us_tail = p_gmac_dev->l_tx_tail;
- return CIRC_CNT(us_head, us_tail, p_gmac_dev->ul_tx_list_size);
-}
-#endif
-
-/**
- * \brief Register/Clear RX callback. Callback will be invoked after the next received
- * frame.
- *
- * When gmac_dev_read() returns GMAC_RX_NULL, the application task calls
- * gmac_dev_set_rx_callback() to register func_rx_cb() callback and enters suspend state.
- * The callback is in charge to resume the task once a new frame has been
- * received. The next time gmac_dev_read() is called, it will be successful.
- *
- * This function is usually invoked from the RX callback itself with NULL
- * callback, to unregister. Once the callback has resumed the application task,
- * there is no need to invoke the callback again.
- *
- * \param p_gmac_dev Pointer to the GMAC device instance.
- * \param func_tx_cb Receive callback function.
- */
-void gmac_dev_set_rx_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_rx_cb_t func_rx_cb)
-{
- Gmac *p_hw = p_gmac_dev->p_hw;
-
- if (func_rx_cb == NULL) {
- gmac_disable_interrupt(p_hw, GMAC_IDR_RCOMP);
- p_gmac_dev->func_rx_cb = NULL;
- } else {
- p_gmac_dev->func_rx_cb = func_rx_cb;
- gmac_enable_interrupt(p_hw, GMAC_IER_RCOMP);
- }
-}
-
-/**
- * \brief Register/Clear TX wakeup callback.
- *
- * When gmac_dev_write() returns GMAC_TX_BUSY (all transmit descriptor busy), the application
- * task calls gmac_dev_set_tx_wakeup_callback() to register func_wakeup() callback and
- * enters suspend state. The callback is in charge to resume the task once
- * several transmit descriptors have been released. The next time gmac_dev_write() will be called,
- * it shall be successful.
- *
- * This function is usually invoked with NULL callback from the TX wakeup
- * callback itself, to unregister. Once the callback has resumed the
- * application task, there is no need to invoke the callback again.
- *
- * \param p_gmac_dev Pointer to GMAC device instance.
- * \param func_wakeup Pointer to wakeup callback function.
- * \param uc_threshold Number of free transmit descriptor before wakeup callback invoked.
- *
- * \return GMAC_OK, GMAC_PARAM on parameter error.
- */
-#if( GMAC_USES_WAKEUP_CALLBACK )
-uint8_t gmac_dev_set_tx_wakeup_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_wakeup_cb_t func_wakeup_cb, uint8_t uc_threshold)
-{
- if (func_wakeup_cb == NULL) {
- p_gmac_dev->func_wakeup_cb = NULL;
- } else {
- if (uc_threshold <= p_gmac_dev->ul_tx_list_size) {
- p_gmac_dev->func_wakeup_cb = func_wakeup_cb;
- p_gmac_dev->uc_wakeup_threshold = uc_threshold;
- } else {
- return GMAC_PARAM;
- }
- }
-
- return GMAC_OK;
-}
-#endif /* GMAC_USES_WAKEUP_CALLBACK */
-
-/**
- * \brief Reset TX & RX queue & statistics.
- *
- * \param p_gmac_dev Pointer to GMAC device instance.
- */
-void gmac_dev_reset(gmac_device_t* p_gmac_dev)
-{
- Gmac *p_hw = p_gmac_dev->p_hw;
-
- gmac_reset_rx_mem(p_gmac_dev);
- gmac_reset_tx_mem(p_gmac_dev);
- gmac_network_control(p_hw, GMAC_NCR_TXEN | GMAC_NCR_RXEN
- | GMAC_NCR_WESTAT | GMAC_NCR_CLRSTAT);
-}
-
-void gmac_dev_halt(Gmac* p_gmac);
-
-void gmac_dev_halt(Gmac* p_gmac)
-{
- gmac_network_control(p_gmac, GMAC_NCR_WESTAT | GMAC_NCR_CLRSTAT);
- gmac_disable_interrupt(p_gmac, ~0u);
-}
-
-
-/**
- * \brief GMAC Interrupt handler.
- *
- * \param p_gmac_dev Pointer to GMAC device instance.
- */
-
-#if( GMAC_STATS != 0 )
- extern int logPrintf( const char *pcFormat, ... );
-
- void gmac_show_irq_counts ()
- {
- int index;
- for (index = 0; index < ARRAY_SIZE(intPairs); index++) {
- if (gmacStats.intStatus[intPairs[index].index]) {
- logPrintf("%s : %6u\n", intPairs[index].name, gmacStats.intStatus[intPairs[index].index]);
- }
- }
- }
-#endif
-
-void gmac_handler(gmac_device_t* p_gmac_dev)
-{
- Gmac *p_hw = p_gmac_dev->p_hw;
-
-#if( GMAC_USES_TX_CALLBACK != 0 )
- gmac_tx_descriptor_t *p_tx_td;
- gmac_dev_tx_cb_t *p_tx_cb = NULL;
- uint32_t ul_tx_status_flag;
-#endif
-#if( GMAC_STATS != 0 )
- int index;
-#endif
-
- /* volatile */ uint32_t ul_isr;
- /* volatile */ uint32_t ul_rsr;
- /* volatile */ uint32_t ul_tsr;
-
- ul_isr = gmac_get_interrupt_status(p_hw);
- ul_rsr = gmac_get_rx_status(p_hw);
- ul_tsr = gmac_get_tx_status(p_hw);
-
-/* Why clear bits that are ignored anyway ? */
-/* ul_isr &= ~(gmac_get_interrupt_mask(p_hw) | 0xF8030300); */
- #if( GMAC_STATS != 0 )
- {
- for (index = 0; index < ARRAY_SIZE(intPairs); index++) {
- if (ul_isr & intPairs[index].mask)
- gmacStats.intStatus[intPairs[index].index]++;
- }
- }
- #endif /* GMAC_STATS != 0 */
-
- /* RX packet */
- if ((ul_isr & GMAC_ISR_RCOMP) || (ul_rsr & (GMAC_RSR_REC|GMAC_RSR_RXOVR|GMAC_RSR_BNA))) {
- /* Clear status */
- gmac_clear_rx_status(p_hw, ul_rsr);
-
- if (ul_isr & GMAC_ISR_RCOMP)
- ul_rsr |= GMAC_RSR_REC;
- /* Invoke callbacks which can be useful to wake op a task */
- if (p_gmac_dev->func_rx_cb) {
- p_gmac_dev->func_rx_cb(ul_rsr);
- }
- }
-
- /* TX packet */
- if ((ul_isr & GMAC_ISR_TCOMP) || (ul_tsr & (GMAC_TSR_TXCOMP|GMAC_TSR_COL|GMAC_TSR_RLE|GMAC_TSR_UND))) {
-
-#if( GMAC_USES_TX_CALLBACK != 0 )
- ul_tx_status_flag = GMAC_TSR_TXCOMP;
-#endif
- /* A frame transmitted */
-
- /* Check RLE */
- if (ul_tsr & GMAC_TSR_RLE) {
- /* Status RLE & Number of discarded buffers */
-#if( GMAC_USES_TX_CALLBACK != 0 )
- ul_tx_status_flag = GMAC_TSR_RLE | CIRC_CNT(p_gmac_dev->l_tx_head,
- p_gmac_dev->l_tx_tail, p_gmac_dev->ul_tx_list_size);
- p_tx_cb = &p_gmac_dev->func_tx_cb_list[p_gmac_dev->l_tx_tail];
-#endif
- gmac_reset_tx_mem(p_gmac_dev);
- gmac_enable_transmit(p_hw, 1);
- }
- /* Clear status */
- gmac_clear_tx_status(p_hw, ul_tsr);
-
-#if( GMAC_USES_TX_CALLBACK != 0 )
- if (!CIRC_EMPTY(p_gmac_dev->l_tx_head, p_gmac_dev->l_tx_tail)) {
- /* Check the buffers */
- do {
- p_tx_td = &p_gmac_dev->p_tx_dscr[p_gmac_dev->l_tx_tail];
- p_tx_cb = &p_gmac_dev->func_tx_cb_list[p_gmac_dev->l_tx_tail];
- /* Any error? Exit if buffer has not been sent yet */
- if ((p_tx_td->status.val & GMAC_TXD_USED) == 0) {
- break;
- }
-
- /* Notify upper layer that a packet has been sent */
- if (*p_tx_cb) {
- (*p_tx_cb) (ul_tx_status_flag, (void*)p_tx_td->addr);
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- p_tx_td->addr = 0ul;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
- }
-
- circ_inc32(&p_gmac_dev->l_tx_tail, p_gmac_dev->ul_tx_list_size);
- } while (CIRC_CNT(p_gmac_dev->l_tx_head, p_gmac_dev->l_tx_tail,
- p_gmac_dev->ul_tx_list_size));
- }
-
- if (ul_tsr & GMAC_TSR_RLE) {
- /* Notify upper layer RLE */
- if (*p_tx_cb) {
- (*p_tx_cb) (ul_tx_status_flag, NULL);
- }
- }
-#endif /* GMAC_USES_TX_CALLBACK */
-
-#if( GMAC_USES_WAKEUP_CALLBACK )
- /* If a wakeup has been scheduled, notify upper layer that it can
- send other packets, and the sending will be successful. */
- if ((CIRC_SPACE(p_gmac_dev->l_tx_head, p_gmac_dev->l_tx_tail,
- p_gmac_dev->ul_tx_list_size) >= p_gmac_dev->uc_wakeup_threshold)
- && p_gmac_dev->func_wakeup_cb) {
- p_gmac_dev->func_wakeup_cb();
- }
-#endif
- }
-}
-
-//@}
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-}
-#endif
-/**INDENT-ON**/
-/// @endcond
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.h
deleted file mode 100755
index d741a2a..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/gmac.h
+++ /dev/null
@@ -1,1346 +0,0 @@
- /**
- * \file
- *
- * \brief GMAC (Ethernet MAC) driver for SAM.
- *
- * Copyright (c) 2013 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-#ifndef GMAC_H_INCLUDED
-#define GMAC_H_INCLUDED
-
-#include "compiler.h"
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-extern "C" {
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/** The buffer addresses written into the descriptors must be aligned, so the
- last few bits are zero. These bits have special meaning for the GMAC
- peripheral and cannot be used as part of the address. */
-#define GMAC_RXD_ADDR_MASK 0xFFFFFFFC
-#define GMAC_RXD_WRAP (1ul << 1) /**< Wrap bit */
-#define GMAC_RXD_OWNERSHIP (1ul << 0) /**< Ownership bit */
-
-#define GMAC_RXD_BROADCAST (1ul << 31) /**< Broadcast detected */
-#define GMAC_RXD_MULTIHASH (1ul << 30) /**< Multicast hash match */
-#define GMAC_RXD_UNIHASH (1ul << 29) /**< Unicast hash match */
-#define GMAC_RXD_ADDR_FOUND (1ul << 27) /**< Specific address match found */
-#define GMAC_RXD_ADDR (3ul << 25) /**< Address match */
-#define GMAC_RXD_RXCOEN (1ul << 24) /**< RXCOEN related function */
-#define GMAC_RXD_TYPE (3ul << 22) /**< Type ID match */
-#define GMAC_RXD_VLAN (1ul << 21) /**< VLAN tag detected */
-#define GMAC_RXD_PRIORITY (1ul << 20) /**< Priority tag detected */
-#define GMAC_RXD_PRIORITY_MASK (3ul << 17) /**< VLAN priority */
-#define GMAC_RXD_CFI (1ul << 16) /**< Concatenation Format Indicator only if bit 21 is set */
-#define GMAC_RXD_EOF (1ul << 15) /**< End of frame */
-#define GMAC_RXD_SOF (1ul << 14) /**< Start of frame */
-#define GMAC_RXD_FCS (1ul << 13) /**< Frame check sequence */
-#define GMAC_RXD_OFFSET_MASK /**< Receive buffer offset */
-#define GMAC_RXD_LEN_MASK (0xFFF) /**< Length of frame including FCS (if selected) */
-#define GMAC_RXD_LENJUMBO_MASK (0x3FFF) /**< Jumbo frame length */
-
-#define GMAC_TXD_USED (1ul << 31) /**< Frame is transmitted */
-#define GMAC_TXD_WRAP (1ul << 30) /**< Last descriptor */
-#define GMAC_TXD_ERROR (1ul << 29) /**< Retry limit exceeded, error */
-#define GMAC_TXD_UNDERRUN (1ul << 28) /**< Transmit underrun */
-#define GMAC_TXD_EXHAUSTED (1ul << 27) /**< Buffer exhausted */
-#define GMAC_TXD_LATE (1ul << 26) /**< Late collision,transmit error */
-#define GMAC_TXD_CHECKSUM_ERROR (7ul << 20) /**< Checksum error */
-#define GMAC_TXD_NOCRC (1ul << 16) /**< No CRC */
-#define GMAC_TXD_LAST (1ul << 15) /**< Last buffer in frame */
-#define GMAC_TXD_LEN_MASK (0x1FFF) /**< Length of buffer */
-
-/** The MAC can support frame lengths up to 1536 bytes */
-#define GMAC_FRAME_LENTGH_MAX 1536
-
-#define GMAC_RX_UNITSIZE 128 /**< Fixed size for RX buffer */
-#define GMAC_TX_UNITSIZE 1518 /**< Size for ETH frame length */
-
-/** GMAC clock speed */
-#define GMAC_MCK_SPEED_240MHZ (240*1000*1000)
-#define GMAC_MCK_SPEED_160MHZ (160*1000*1000)
-#define GMAC_MCK_SPEED_120MHZ (120*1000*1000)
-#define GMAC_MCK_SPEED_80MHZ (80*1000*1000)
-#define GMAC_MCK_SPEED_40MHZ (40*1000*1000)
-#define GMAC_MCK_SPEED_20MHZ (20*1000*1000)
-
-/** GMAC maintain code default value*/
-#define GMAC_MAN_CODE_VALUE (10)
-
-/** GMAC maintain start of frame default value*/
-#define GMAC_MAN_SOF_VALUE (1)
-
-/** GMAC maintain read/write*/
-#define GMAC_MAN_RW_TYPE (2)
-
-/** GMAC maintain read only*/
-#define GMAC_MAN_READ_ONLY (1)
-
-/** GMAC address length */
-#define GMAC_ADDR_LENGTH (6)
-
-
-#define GMAC_DUPLEX_HALF 0
-#define GMAC_DUPLEX_FULL 1
-
-#define GMAC_SPEED_10M 0
-#define GMAC_SPEED_100M 1
-
-/**
- * \brief Return codes for GMAC APIs.
- */
-typedef enum {
- GMAC_OK = 0, /** 0 Operation OK */
- GMAC_TIMEOUT = 1, /** 1 GMAC operation timeout */
- GMAC_TX_BUSY, /** 2 TX in progress */
- GMAC_RX_NULL, /** 3 No data received */
- GMAC_SIZE_TOO_SMALL, /** 4 Buffer size not enough */
- GMAC_PARAM, /** 5 Parameter error, TX packet invalid or RX size too small */
- GMAC_INVALID = 0xFF, /* Invalid */
-} gmac_status_t;
-
-/**
- * \brief Media Independent Interface (MII) type.
- */
-typedef enum {
- GMAC_PHY_MII = 0, /** MII mode */
- GMAC_PHY_RMII = 1, /** Reduced MII mode */
- GMAC_PHY_INVALID = 0xFF, /* Invalid mode*/
-} gmac_mii_mode_t;
-
-/** Receive buffer descriptor struct */
-COMPILER_PACK_SET(8)
-typedef struct gmac_rx_descriptor {
- union gmac_rx_addr {
- uint32_t val;
- struct gmac_rx_addr_bm {
- uint32_t b_ownership:1, /**< User clear, GMAC sets this to 1 once it has successfully written a frame to memory */
- b_wrap:1, /**< Marks last descriptor in receive buffer */
- addr_dw:30; /**< Address in number of DW */
- } bm;
- } addr; /**< Address, Wrap & Ownership */
- union gmac_rx_status {
- uint32_t val;
- struct gmac_rx_status_bm {
- uint32_t len:13, /** 0..12 Length of frame including FCS */
- b_fcs:1, /** 13 Receive buffer offset, bits 13:12 of frame length for jumbo frame */
- b_sof:1, /** 14 Start of frame */
- b_eof:1, /** 15 End of frame */
- b_cfi:1, /** 16 Concatenation Format Indicator */
- vlan_priority:3, /** 17..19 VLAN priority (if VLAN detected) */
- b_priority_detected:1, /** 20 Priority tag detected */
- b_vlan_detected:1, /** 21 VLAN tag detected */
- b_type_id_match:2, /** 22..23 Type ID match */
- b_checksumoffload:1, /** 24 Checksum offload specific function */
- b_addrmatch:2, /** 25..26 Address register match */
- b_ext_addr_match:1, /** 27 External address match found */
- reserved:1, /** 28 */
- b_uni_hash_match:1, /** 29 Unicast hash match */
- b_multi_hash_match:1, /** 30 Multicast hash match */
- b_boardcast_detect:1; /** 31 Global broadcast address detected */
- } bm;
- } status;
-} gmac_rx_descriptor_t;
-
-/** Transmit buffer descriptor struct */
-COMPILER_PACK_SET(8)
-typedef struct gmac_tx_descriptor {
- uint32_t addr;
- union gmac_tx_status {
- uint32_t val;
- struct gmac_tx_status_bm {
- uint32_t len:14, /** 0..13 Length of buffer */
- reserved:1, /** 14 */
- b_last_buffer:1, /** 15 Last buffer (in the current frame) */
- b_no_crc:1, /** 16 No CRC */
- reserved1:3, /** 17..19 */
- b_checksumoffload:3, /** 20..22 Transmit checksum generation offload errors */
- reserved2:3, /** 23..25 */
- b_lco:1, /** 26 Late collision, transmit error detected */
- b_exhausted:1, /** 27 Buffer exhausted in mid frame */
- b_underrun:1, /** 28 Transmit underrun */
- b_error:1, /** 29 Retry limit exceeded, error detected */
- b_wrap:1, /** 30 Marks last descriptor in TD list */
- b_used:1; /** 31 User clear, GMAC sets this to 1 once a frame has been successfully transmitted */
- } bm;
- } status;
-} gmac_tx_descriptor_t;
-
-COMPILER_PACK_RESET()
-
-/**
- * \brief Input parameters when initializing the gmac module mode.
- */
-typedef struct gmac_options {
- /* Enable/Disable CopyAllFrame */
- uint8_t uc_copy_all_frame;
- /* Enable/Disable NoBroadCast */
- uint8_t uc_no_boardcast;
- /* MAC address */
- uint8_t uc_mac_addr[GMAC_ADDR_LENGTH];
-} gmac_options_t;
-
-/** RX callback */
-typedef void (*gmac_dev_tx_cb_t) (uint32_t ul_status);
-/** Wakeup callback */
-typedef void (*gmac_dev_wakeup_cb_t) (void);
-
-/**
- * GMAC driver structure.
- */
-typedef struct gmac_device {
-
- /** Pointer to HW register base */
- Gmac *p_hw;
- /**
- * Pointer to allocated TX buffer.
- * Section 3.6 of AMBA 2.0 spec states that burst should not cross
- * 1K Boundaries.
- * Receive buffer manager writes are burst of 2 words => 3 lsb bits
- * of the address shall be set to 0.
- */
- uint8_t *p_tx_buffer;
- /** Pointer to allocated RX buffer */
- uint8_t *p_rx_buffer;
- /** Pointer to Rx TDs (must be 8-byte aligned) */
- gmac_rx_descriptor_t *p_rx_dscr;
- /** Pointer to Tx TDs (must be 8-byte aligned) */
- gmac_tx_descriptor_t *p_tx_dscr;
- /** Optional callback to be invoked once a frame has been received */
- gmac_dev_tx_cb_t func_rx_cb;
-#if( GMAC_USES_WAKEUP_CALLBACK )
- /** Optional callback to be invoked once several TDs have been released */
- gmac_dev_wakeup_cb_t func_wakeup_cb;
-#endif
-#if( GMAC_USES_TX_CALLBACK != 0 )
- /** Optional callback list to be invoked once TD has been processed */
- gmac_dev_tx_cb_t *func_tx_cb_list;
-#endif
- /** RX TD list size */
- uint32_t ul_rx_list_size;
- /** RX index for current processing TD */
- uint32_t ul_rx_idx;
- /** TX TD list size */
- uint32_t ul_tx_list_size;
- /** Circular buffer head pointer by upper layer (buffer to be sent) */
- int32_t l_tx_head;
- /** Circular buffer tail pointer incremented by handlers (buffer sent) */
- int32_t l_tx_tail;
-
- /** Number of free TD before wakeup callback is invoked */
- uint32_t uc_wakeup_threshold;
-} gmac_device_t;
-
-/**
- * \brief Write network control value.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_ncr Network control value.
- */
-static inline void gmac_network_control(Gmac* p_gmac, uint32_t ul_ncr)
-{
- p_gmac->GMAC_NCR = ul_ncr;
-}
-
-/**
- * \brief Get network control value.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-
-static inline uint32_t gmac_get_network_control(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NCR;
-}
-
-/**
- * \brief Enable/Disable GMAC receive.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC receiver, else to enable it.
- */
-static inline void gmac_enable_receive(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_RXEN;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_RXEN;
- }
-}
-
-/**
- * \brief Enable/Disable GMAC transmit.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC transmit, else to enable it.
- */
-static inline void gmac_enable_transmit(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_TXEN;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_TXEN;
- }
-}
-
-/**
- * \brief Enable/Disable GMAC management.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC management, else to enable it.
- */
-static inline void gmac_enable_management(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_MPE;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_MPE;
- }
-}
-
-/**
- * \brief Clear all statistics registers.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_clear_statistics(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_CLRSTAT;
-}
-
-/**
- * \brief Increase all statistics registers.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_increase_statistics(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_INCSTAT;
-}
-
-/**
- * \brief Enable/Disable statistics registers writing.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the statistics registers writing, else to enable it.
- */
-static inline void gmac_enable_statistics_write(Gmac* p_gmac,
- uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_WESTAT;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_WESTAT;
- }
-}
-
-/**
- * \brief In half-duplex mode, forces collisions on all received frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the back pressure, else to enable it.
- */
-static inline void gmac_enable_back_pressure(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_BP;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_BP;
- }
-}
-
-/**
- * \brief Start transmission.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_start_transmission(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TSTART;
-}
-
-/**
- * \brief Halt transmission.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_halt_transmission(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_THALT;
-}
-
-/**
- * \brief Transmit pause frame.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_tx_pause_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXPF;
-}
-
-/**
- * \brief Transmit zero quantum pause frame.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_tx_pause_zero_quantum_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXZQPF;
-}
-
-/**
- * \brief Read snapshot.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_read_snapshot(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_RDS;
-}
-
-/**
- * \brief Store receivetime stamp to memory.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to normal operation, else to enable the store.
- */
-static inline void gmac_store_rx_time_stamp(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_SRTSM;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_SRTSM;
- }
-}
-
-/**
- * \brief Enable PFC priority-based pause reception.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 1 to set the reception, 0 to disable.
- */
-static inline void gmac_enable_pfc_pause_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_ENPBPR;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_ENPBPR;
- }
-}
-
-/**
- * \brief Transmit PFC priority-based pause reception.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_transmit_pfc_pause_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXPBPF;
-}
-
-/**
- * \brief Flush next packet.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_flush_next_packet(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_FNP;
-}
-
-/**
- * \brief Set up network configuration register.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_cfg Network configuration value.
- */
-static inline void gmac_set_configure(Gmac* p_gmac, uint32_t ul_cfg)
-{
- p_gmac->GMAC_NCFGR = ul_cfg;
-}
-
-/**
- * \brief Get network configuration.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Network configuration.
- */
-static inline uint32_t gmac_get_configure(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NCFGR;
-}
-
-
-/* Get and set DMA Configuration Register */
-static inline void gmac_set_dma(Gmac* p_gmac, uint32_t ul_cfg)
-{
- p_gmac->GMAC_DCFGR = ul_cfg;
-}
-
-static inline uint32_t gmac_get_dma(Gmac* p_gmac)
-{
- return p_gmac->GMAC_DCFGR;
-}
-
-/**
- * \brief Set speed.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_speed 1 to indicate 100Mbps, 0 to 10Mbps.
- */
-static inline void gmac_set_speed(Gmac* p_gmac, uint8_t uc_speed)
-{
- if (uc_speed) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_SPD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_SPD;
- }
-}
-
-/**
- * \brief Enable/Disable Full-Duplex mode.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the Full-Duplex mode, else to enable it.
- */
-static inline void gmac_enable_full_duplex(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_FD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_FD;
- }
-}
-
-/**
- * \brief Enable/Disable Copy(Receive) All Valid Frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable copying all valid frames, else to enable it.
- */
-static inline void gmac_enable_copy_all(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_CAF;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_CAF;
- }
-}
-
-/**
- * \brief Enable/Disable jumbo frames (up to 10240 bytes).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the jumbo frames, else to enable it.
- */
-static inline void gmac_enable_jumbo_frames(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_JFRAME;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_JFRAME;
- }
-}
-
-/**
- * \brief Disable/Enable broadcast receiving.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 1 to disable the broadcast, else to enable it.
- */
-static inline void gmac_disable_broadcast(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_NBC;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_NBC;
- }
-}
-
-/**
- * \brief Enable/Disable multicast hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the multicast hash, else to enable it.
- */
-static inline void gmac_enable_multicast_hash(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_UNIHEN;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_UNIHEN;
- }
-}
-
-/**
- * \brief Enable/Disable big frames (over 1518, up to 1536).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable big frames else to enable it.
- */
-static inline void gmac_enable_big_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_MAXFS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_MAXFS;
- }
-}
-
-/**
- * \brief Set MDC clock divider.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_mck GMAC MCK.
- *
- * \return GMAC_OK if successfully.
- */
-static inline uint8_t gmac_set_mdc_clock(Gmac* p_gmac, uint32_t ul_mck)
-{
- uint32_t ul_clk;
-
- if (ul_mck > GMAC_MCK_SPEED_240MHZ) {
- return GMAC_INVALID;
- } else if (ul_mck > GMAC_MCK_SPEED_160MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_96;
- } else if (ul_mck > GMAC_MCK_SPEED_120MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_64;
- } else if (ul_mck > GMAC_MCK_SPEED_80MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_48;
- } else if (ul_mck > GMAC_MCK_SPEED_40MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_32;
- } else if (ul_mck > GMAC_MCK_SPEED_20MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_16;
- } else {
- ul_clk = GMAC_NCFGR_CLK_MCK_8;
- }
- ;
- p_gmac->GMAC_NCFGR = (p_gmac->GMAC_NCFGR & ~GMAC_NCFGR_CLK_Msk) | ul_clk;
- return GMAC_OK;
-}
-
-/**
- * \brief Enable/Disable retry test.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the GMAC receiver, else to enable it.
- */
-static inline void gmac_enable_retry_test(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RTY;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RTY;
- }
-}
-
-/**
- * \brief Enable/Disable pause (when a valid pause frame is received).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable pause frame, else to enable it.
- */
-static inline void gmac_enable_pause_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_PEN;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_PEN;
- }
-}
-
-/**
- * \brief Set receive buffer offset to 0 ~ 3.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_set_rx_buffer_offset(Gmac* p_gmac, uint8_t uc_offset)
-{
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RXBUFO_Msk;
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RXBUFO(uc_offset);
-}
-
-/**
- * \brief Enable/Disable receive length field checking.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable receive length field checking, else to enable it.
- */
-static inline void gmac_enable_rx_length_check(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_LFERD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_LFERD;
- }
-}
-
-/**
- * \brief Enable/Disable discarding FCS field of received frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable discarding FCS field of received frames, else to enable it.
- */
-static inline void gmac_enable_discard_fcs(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RFCS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RFCS;
- }
-}
-
-
-/**
- * \brief Enable/Disable frames to be received in half-duplex mode
- * while transmitting.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the received in half-duplex mode, else to enable it.
- */
-static inline void gmac_enable_efrhd(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_EFRHD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_EFRHD;
- }
-}
-
-/**
- * \brief Enable/Disable ignore RX FCS.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable ignore RX FCS, else to enable it.
- */
-static inline void gmac_enable_ignore_rx_fcs(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_IRXFCS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_IRXFCS;
- }
-}
-
-/**
- * \brief Get Network Status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Network status.
- */
-static inline uint32_t gmac_get_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NSR;
-}
-
-/**
- * \brief Get MDIO IN pin status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return MDIO IN pin status.
- */
-static inline uint8_t gmac_get_MDIO(Gmac* p_gmac)
-{
- return ((p_gmac->GMAC_NSR & GMAC_NSR_MDIO) > 0);
-}
-
-/**
- * \brief Check if PHY is idle.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return 1 if PHY is idle.
- */
-static inline uint8_t gmac_is_phy_idle(Gmac* p_gmac)
-{
- return ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) > 0);
-}
-
-/**
- * \brief Return transmit status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Transmit status.
- */
-static inline uint32_t gmac_get_tx_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_TSR;
-}
-
-/**
- * \brief Clear transmit status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_status Transmit status.
- */
-static inline void gmac_clear_tx_status(Gmac* p_gmac, uint32_t ul_status)
-{
- p_gmac->GMAC_TSR = ul_status;
-}
-
-/**
- * \brief Return receive status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline uint32_t gmac_get_rx_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_RSR;
-}
-
-/**
- * \brief Clear receive status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_status Receive status.
- */
-static inline void gmac_clear_rx_status(Gmac* p_gmac, uint32_t ul_status)
-{
- p_gmac->GMAC_RSR = ul_status;
-}
-
-/**
- * \brief Set Rx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_addr Rx queue address.
- */
-static inline void gmac_set_rx_queue(Gmac* p_gmac, uint32_t ul_addr)
-{
- p_gmac->GMAC_RBQB = GMAC_RBQB_ADDR_Msk & ul_addr;
-}
-
-/**
- * \brief Get Rx Queue Address.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Rx queue address.
- */
-static inline uint32_t gmac_get_rx_queue(Gmac* p_gmac)
-{
- return p_gmac->GMAC_RBQB;
-}
-
-/**
- * \brief Set Tx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_addr Tx queue address.
- */
-static inline void gmac_set_tx_queue(Gmac* p_gmac, uint32_t ul_addr)
-{
- p_gmac->GMAC_TBQB = GMAC_TBQB_ADDR_Msk & ul_addr;
-}
-
-/**
- * \brief Get Tx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Rx queue address.
- */
-static inline uint32_t gmac_get_tx_queue(Gmac* p_gmac)
-{
- return p_gmac->GMAC_TBQB;
-}
-
-/**
- * \brief Enable interrupt(s).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_source Interrupt source(s) to be enabled.
- */
-static inline void gmac_enable_interrupt(Gmac* p_gmac, uint32_t ul_source)
-{
- p_gmac->GMAC_IER = ul_source;
-}
-
-/**
- * \brief Disable interrupt(s).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_source Interrupt source(s) to be disabled.
- */
-static inline void gmac_disable_interrupt(Gmac* p_gmac, uint32_t ul_source)
-{
- p_gmac->GMAC_IDR = ul_source;
-}
-
-/**
- * \brief Return interrupt status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Interrupt status.
- */
-static inline uint32_t gmac_get_interrupt_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_ISR;
-}
-
-/**
- * \brief Return interrupt mask.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Interrupt mask.
- */
-static inline uint32_t gmac_get_interrupt_mask(Gmac* p_gmac)
-{
- return p_gmac->GMAC_IMR;
-}
-
-/**
- * \brief Execute PHY maintenance command.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param uc_reg_addr Register address.
- * \param uc_rw 1 to Read, 0 to write.
- * \param us_data Data to be performed, write only.
- */
-static inline void gmac_maintain_phy(Gmac* p_gmac,
- uint8_t uc_phy_addr, uint8_t uc_reg_addr, uint8_t uc_rw,
- uint16_t us_data)
-{
- /* Wait until bus idle */
- while ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) == 0);
- /* Write maintain register */
- p_gmac->GMAC_MAN = GMAC_MAN_WTN(GMAC_MAN_CODE_VALUE)
- | GMAC_MAN_CLTTO
- | GMAC_MAN_PHYA(uc_phy_addr)
- | GMAC_MAN_REGA(uc_reg_addr)
- | GMAC_MAN_OP((uc_rw ? GMAC_MAN_RW_TYPE : GMAC_MAN_READ_ONLY))
- | GMAC_MAN_DATA(us_data);
-}
-
-/**
- * \brief Get PHY maintenance data returned.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Get PHY data.
- */
-static inline uint16_t gmac_get_phy_data(Gmac* p_gmac)
-{
- /* Wait until bus idle */
- while ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) == 0);
- /* Return data */
- return (uint16_t) (p_gmac->GMAC_MAN & GMAC_MAN_DATA_Msk);
-}
-
-/**
- * \brief Set Hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_hash_top Hash top.
- * \param ul_hash_bottom Hash bottom.
- */
-static inline void gmac_set_hash(Gmac* p_gmac, uint32_t ul_hash_top,
- uint32_t ul_hash_bottom)
-{
- p_gmac->GMAC_HRB = ul_hash_bottom;
- p_gmac->GMAC_HRT = ul_hash_top;
-}
-
-/**
- * \brief Set 64 bits Hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ull_hash 64 bits hash value.
- */
-static inline void gmac_set_hash64(Gmac* p_gmac, uint64_t ull_hash)
-{
- p_gmac->GMAC_HRB = (uint32_t) ull_hash;
- p_gmac->GMAC_HRT = (uint32_t) (ull_hash >> 32);
-}
-
-/**
- * \brief Set MAC Address.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param p_mac_addr GMAC address.
- */
-static inline void gmac_set_address(Gmac* p_gmac, uint8_t uc_index,
- uint8_t* p_mac_addr)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = (p_mac_addr[3] << 24)
- | (p_mac_addr[2] << 16)
- | (p_mac_addr[1] << 8)
- | (p_mac_addr[0]);
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = (p_mac_addr[5] << 8)
- | (p_mac_addr[4]);
-}
-
-/**
- * \brief Set MAC Address via 2 dword.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param ul_mac_top GMAC top address.
- * \param ul_mac_bottom GMAC bottom address.
- */
-static inline void gmac_set_address32(Gmac* p_gmac, uint8_t uc_index,
- uint32_t ul_mac_top, uint32_t ul_mac_bottom)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = ul_mac_bottom;
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = ul_mac_top;
-}
-
-/**
- * \brief Set MAC Address via int64.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param ull_mac 64-bit GMAC address.
- */
-static inline void gmac_set_address64(Gmac* p_gmac, uint8_t uc_index,
- uint64_t ull_mac)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = (uint32_t) ull_mac;
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = (uint32_t) (ull_mac >> 32);
-}
-
-/**
- * \brief Select media independent interface mode.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param mode Media independent interface mode.
- */
-static inline void gmac_select_mii_mode(Gmac* p_gmac, gmac_mii_mode_t mode)
-{
- switch (mode) {
- case GMAC_PHY_MII:
- case GMAC_PHY_RMII:
- p_gmac->GMAC_UR |= GMAC_UR_RMIIMII;
- break;
-
- default:
- p_gmac->GMAC_UR &= ~GMAC_UR_RMIIMII;
- break;
- }
-}
-
-uint8_t gmac_phy_read(Gmac* p_gmac, uint8_t uc_phy_address, uint8_t uc_address,
- uint32_t* p_value);
-uint8_t gmac_phy_write(Gmac* p_gmac, uint8_t uc_phy_address,
- uint8_t uc_address, uint32_t ul_value);
-void gmac_dev_init(Gmac* p_gmac, gmac_device_t* p_gmac_dev,
- gmac_options_t* p_opt);
-uint32_t gmac_dev_read(gmac_device_t* p_gmac_dev, uint8_t* p_frame,
- uint32_t ul_frame_size, uint32_t* p_rcv_size);
-uint32_t gmac_dev_write(gmac_device_t* p_gmac_dev, void *p_buffer,
- uint32_t ul_size, gmac_dev_tx_cb_t func_tx_cb);
-uint32_t gmac_dev_get_tx_load(gmac_device_t* p_gmac_dev);
-void gmac_dev_set_rx_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_tx_cb_t func_rx_cb);
-uint8_t gmac_dev_set_tx_wakeup_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_wakeup_cb_t func_wakeup, uint8_t uc_threshold);
-void gmac_dev_reset(gmac_device_t* p_gmac_dev);
-void gmac_handler(gmac_device_t* p_gmac_dev);
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-}
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/**
- * \page gmac_quickstart Quickstart guide for GMAC driver.
- *
- * This is the quickstart guide for the \ref gmac_group "Ethernet MAC",
- * with step-by-step instructions on how to configure and use the driver in a
- * selection of use cases.
- *
- * The use cases contain several code fragments. The code fragments in the
- * steps for setup can be copied into a custom initialization function, while
- * the steps for usage can be copied into, e.g., the main application function.
- *
- * \section gmac_basic_use_case Basic use case
- * In the basic use case, the GMAC driver are configured for:
- * - PHY component KSZ8051MNL is used
- * - GMAC uses MII mode
- * - The number of receive buffer is 16
- * - The number of transfer buffer is 8
- * - MAC address is set to 00-04-25-1c-a0-02
- * - IP address is set to 192.168.0.2
- * - IP address is set to 192.168.0.2
- * - Gateway is set to 192.168.0.1
- * - Network mask is 255.255.255.0
- * - PHY operation max retry count is 1000000
- * - GMAC is configured to not support copy all frame and support broadcast
- * - The data will be read from the ethernet
- *
- * \section gmac_basic_use_case_setup Setup steps
- *
- * \subsection gmac_basic_use_case_setup_prereq Prerequisites
- * -# \ref sysclk_group "System Clock Management (sysclock)"
- * -# \ref pmc_group "Power Management Controller (pmc)"
- * -# \ref ksz8051mnl_ethernet_phy_group "PHY component (KSZ8051MNL)"
- *
- * \subsection gmac_basic_use_case_setup_code Example code
- * Content of conf_eth.h
- * \code
- * #define GMAC_RX_BUFFERS 16
- * #define GMAC_TX_BUFFERS 8
- * #define MAC_PHY_RETRY_MAX 1000000
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR1 0x04
- * #define ETHERNET_CONF_ETHADDR2 0x25
- * #define ETHERNET_CONF_ETHADDR3 0x1C
- * #define ETHERNET_CONF_ETHADDR4 0xA0
- * #define ETHERNET_CONF_ETHADDR5 0x02
- * #define ETHERNET_CONF_IPADDR0 192
- * #define ETHERNET_CONF_IPADDR1 168
- * #define ETHERNET_CONF_IPADDR2 0
- * #define ETHERNET_CONF_IPADDR3 2
- * #define ETHERNET_CONF_GATEWAY_ADDR0 192
- * #define ETHERNET_CONF_GATEWAY_ADDR1 168
- * #define ETHERNET_CONF_GATEWAY_ADDR2 0
- * #define ETHERNET_CONF_GATEWAY_ADDR3 1
- * #define ETHERNET_CONF_NET_MASK0 255
- * #define ETHERNET_CONF_NET_MASK1 255
- * #define ETHERNET_CONF_NET_MASK2 255
- * #define ETHERNET_CONF_NET_MASK3 0
- * #define ETH_PHY_MODE ETH_PHY_MODE
- * \endcode
- *
- * A specific gmac device and the receive data buffer must be defined; another ul_frm_size should be defined
- * to trace the actual size of the data received.
- * \code
- * static gmac_device_t gs_gmac_dev;
- * static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
- *
- * uint32_t ul_frm_size;
- * \endcode
- *
- * Add to application C-file:
- * \code
- * void gmac_init(void)
- * {
- * sysclk_init();
- *
- * board_init();
- *
- * pmc_enable_periph_clk(ID_GMAC);
- *
- * gmac_option.uc_copy_all_frame = 0;
- * gmac_option.uc_no_boardcast = 0;
- * memcpy(gmac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
- * gs_gmac_dev.p_hw = GMAC;
- *
- * gmac_dev_init(GMAC, &gs_gmac_dev, &gmac_option);
- *
- * NVIC_EnableIRQ(GMAC_IRQn);
- *
- * ethernet_phy_init(GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz());
- *
- * ethernet_phy_auto_negotiate(GMAC, BOARD_GMAC_PHY_ADDR);
- *
- * ethernet_phy_set_link(GMAC, BOARD_GMAC_PHY_ADDR, 1);
- * \endcode
- *
- * \subsection gmac_basic_use_case_setup_flow Workflow
- * - Ensure that conf_eth.h is present and contains the
- * following configuration symbol. This configuration file is used
- * by the driver and should not be included by the application.
- * -# Define the receiving buffer size used in the internal GMAC driver.
- * The buffer size used for RX is GMAC_RX_BUFFERS * 128.
- * If it was supposed receiving a large number of frame, the
- * GMAC_RX_BUFFERS should be set higher. E.g., the application wants to accept
- * a ping echo test of 2048, the GMAC_RX_BUFFERS should be set at least
- * (2048/128)=16, and as there are additional frames coming, a preferred
- * number is 24 depending on a normal Ethernet throughput.
- * - \code
- * #define GMAC_RX_BUFFERS 16
- * \endcode
- * -# Define the transmitting buffer size used in the internal GMAC driver.
- * The buffer size used for TX is GMAC_TX_BUFFERS * 1518.
- * - \code
- * #define GMAC_TX_BUFFERS 8
- * \endcode
- * -# Define maximum retry time for a PHY read/write operation.
- * - \code
- * #define MAC_PHY_RETRY_MAX 1000000
- * \endcode
- * -# Define the MAC address. 00:04:25:1C:A0:02 is the address reserved
- * for ATMEL, application should always change this address to its' own.
- * - \code
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR1 0x04
- * #define ETHERNET_CONF_ETHADDR2 0x25
- * #define ETHERNET_CONF_ETHADDR3 0x1C
- * #define ETHERNET_CONF_ETHADDR4 0xA0
- * #define ETHERNET_CONF_ETHADDR5 0x02
- * \endcode
- * -# Define the IP address configration used in the application. When DHCP
- * is enabled, this configuration is not effected.
- * - \code
- * #define ETHERNET_CONF_IPADDR0 192
- * #define ETHERNET_CONF_IPADDR1 168
- * #define ETHERNET_CONF_IPADDR2 0
- * #define ETHERNET_CONF_IPADDR3 2
- * #define ETHERNET_CONF_GATEWAY_ADDR0 192
- * #define ETHERNET_CONF_GATEWAY_ADDR1 168
- * #define ETHERNET_CONF_GATEWAY_ADDR2 0
- * #define ETHERNET_CONF_GATEWAY_ADDR3 1
- * #define ETHERNET_CONF_NET_MASK0 255
- * #define ETHERNET_CONF_NET_MASK1 255
- * #define ETHERNET_CONF_NET_MASK2 255
- * #define ETHERNET_CONF_NET_MASK3 0
- * \endcode
- * -# Configure the PHY maintainance interface.
- * - \code
- * #define ETH_PHY_MODE GMAC_PHY_MII
- * \endcode
- * -# Enable the system clock:
- * - \code sysclk_init(); \endcode
- * -# Enable PIO configurations for GMAC:
- * - \code board_init(); \endcode
- * -# Enable PMC clock for GMAC:
- * - \code pmc_enable_periph_clk(ID_GMAC); \endcode
- * -# Set the GMAC options; it's set to copy all frame and support broadcast:
- * - \code
- * gmac_option.uc_copy_all_frame = 0;
- * gmac_option.uc_no_boardcast = 0;
- * memcpy(gmac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
- * gs_gmac_dev.p_hw = GMAC;
- * \endcode
- * -# Initialize GMAC device with the filled option:
- * - \code
- * gmac_dev_init(GMAC, &gs_gmac_dev, &gmac_option);
- * \endcode
- * -# Enable the interrupt service for GMAC:
- * - \code
- * NVIC_EnableIRQ(GMAC_IRQn);
- * \endcode
- * -# Initialize the PHY component:
- * - \code
- * ethernet_phy_init(GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz());
- * \endcode
- * -# The link will be established based on auto negotiation.
- * - \code
- * ethernet_phy_auto_negotiate(GMAC, BOARD_GMAC_PHY_ADDR);
- * \endcode
- * -# Establish the ethernet link; the network can be worked from now on:
- * - \code
- * ethernet_phy_set_link(GMAC, BOARD_GMAC_PHY_ADDR, 1);
- * \endcode
- *
- * \section gmac_basic_use_case_usage Usage steps
- * \subsection gmac_basic_use_case_usage_code Example code
- * Add to, e.g., main loop in application C-file:
- * \code
- * gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size));
- * \endcode
- *
- * \subsection gmac_basic_use_case_usage_flow Workflow
- * -# Start reading the data from the ethernet:
- * - \code gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size)); \endcode
- */
-
-# define GMAC_STATS 0
-
-#if( GMAC_STATS != 0 )
-
- /* Here below some code to study the types and
- frequencies of GMAC interrupts. */
- #define GMAC_IDX_RXUBR 0
- #define GMAC_IDX_TUR 1
- #define GMAC_IDX_RLEX 2
- #define GMAC_IDX_TFC 3
- #define GMAC_IDX_RCOMP 4
- #define GMAC_IDX_TCOMP 5
- #define GMAC_IDX_ROVR 6
- #define GMAC_IDX_HRESP 7
- #define GMAC_IDX_PFNZ 8
- #define GMAC_IDX_PTZ 9
-
- struct SGmacStats {
- unsigned recvCount;
- unsigned rovrCount;
- unsigned bnaCount;
- unsigned sendCount;
- unsigned sovrCount;
- unsigned incompCount;
- unsigned truncCount;
-
- unsigned intStatus[10];
- };
- extern struct SGmacStats gmacStats;
-
- struct SIntPair {
- const char *name;
- unsigned mask;
- int index;
- };
-
- #define MK_PAIR( NAME ) #NAME, GMAC_IER_##NAME, GMAC_IDX_##NAME
- static const struct SIntPair intPairs[] = {
- { MK_PAIR( RXUBR ) }, /* Enable receive used bit read interrupt. */
- { MK_PAIR( TUR ) }, /* Enable transmit underrun interrupt. */
- { MK_PAIR( RLEX ) }, /* Enable retry limit exceeded interrupt. */
- { MK_PAIR( TFC ) }, /* Enable transmit buffers exhausted in mid-frame interrupt. */
- { MK_PAIR( RCOMP ) }, /* Receive complete */
- { MK_PAIR( TCOMP ) }, /* Enable transmit complete interrupt. */
- { MK_PAIR( ROVR ) }, /* Enable receive overrun interrupt. */
- { MK_PAIR( HRESP ) }, /* Enable Hresp not OK interrupt. */
- { MK_PAIR( PFNZ ) }, /* Enable pause frame received interrupt. */
- { MK_PAIR( PTZ ) } /* Enable pause time zero interrupt. */
- };
-
- void gmac_show_irq_counts ();
-
-#endif
-
-#endif /* GMAC_H_INCLUDED */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/instance/gmac.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/instance/gmac.h
deleted file mode 100755
index dd29dfe..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/instance/gmac.h
+++ /dev/null
@@ -1,1349 +0,0 @@
- /**
- * \file
- *
- * \brief GMAC (Ethernet MAC) driver for SAM.
- *
- * Copyright (c) 2013 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-
-#ifndef GMAC_H_INCLUDED
-#define GMAC_H_INCLUDED
-
-#include "compiler.h"
-#include "component/gmac.h"
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-extern "C" {
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/** The buffer addresses written into the descriptors must be aligned, so the
- last few bits are zero. These bits have special meaning for the GMAC
- peripheral and cannot be used as part of the address. */
-#define GMAC_RXD_ADDR_MASK 0xFFFFFFFC
-#define GMAC_RXD_WRAP (1ul << 1) /**< Wrap bit */
-#define GMAC_RXD_OWNERSHIP (1ul << 0) /**< Ownership bit */
-
-#define GMAC_RXD_BROADCAST (1ul << 31) /**< Broadcast detected */
-#define GMAC_RXD_MULTIHASH (1ul << 30) /**< Multicast hash match */
-#define GMAC_RXD_UNIHASH (1ul << 29) /**< Unicast hash match */
-#define GMAC_RXD_ADDR_FOUND (1ul << 27) /**< Specific address match found */
-#define GMAC_RXD_ADDR (3ul << 25) /**< Address match */
-#define GMAC_RXD_RXCOEN (1ul << 24) /**< RXCOEN related function */
-#define GMAC_RXD_TYPE (3ul << 22) /**< Type ID match */
-#define GMAC_RXD_VLAN (1ul << 21) /**< VLAN tag detected */
-#define GMAC_RXD_PRIORITY (1ul << 20) /**< Priority tag detected */
-#define GMAC_RXD_PRIORITY_MASK (3ul << 17) /**< VLAN priority */
-#define GMAC_RXD_CFI (1ul << 16) /**< Concatenation Format Indicator only if bit 21 is set */
-#define GMAC_RXD_EOF (1ul << 15) /**< End of frame */
-#define GMAC_RXD_SOF (1ul << 14) /**< Start of frame */
-#define GMAC_RXD_FCS (1ul << 13) /**< Frame check sequence */
-#define GMAC_RXD_OFFSET_MASK /**< Receive buffer offset */
-#define GMAC_RXD_LEN_MASK (0xFFF) /**< Length of frame including FCS (if selected) */
-#define GMAC_RXD_LENJUMBO_MASK (0x3FFF) /**< Jumbo frame length */
-
-#define GMAC_TXD_USED (1ul << 31) /**< Frame is transmitted */
-#define GMAC_TXD_WRAP (1ul << 30) /**< Last descriptor */
-#define GMAC_TXD_ERROR (1ul << 29) /**< Retry limit exceeded, error */
-#define GMAC_TXD_UNDERRUN (1ul << 28) /**< Transmit underrun */
-#define GMAC_TXD_EXHAUSTED (1ul << 27) /**< Buffer exhausted */
-#define GMAC_TXD_LATE (1ul << 26) /**< Late collision,transmit error */
-#define GMAC_TXD_CHECKSUM_ERROR (7ul << 20) /**< Checksum error */
-#define GMAC_TXD_NOCRC (1ul << 16) /**< No CRC */
-#define GMAC_TXD_LAST (1ul << 15) /**< Last buffer in frame */
-#define GMAC_TXD_LEN_MASK (0x1FFF) /**< Length of buffer */
-
-/** The MAC can support frame lengths up to 1536 bytes */
-#define GMAC_FRAME_LENTGH_MAX 1536
-
-#define GMAC_RX_UNITSIZE 128 /**< Fixed size for RX buffer */
-#define GMAC_TX_UNITSIZE 1518 /**< Size for ETH frame length */
-
-/** GMAC clock speed */
-#define GMAC_MCK_SPEED_240MHZ (240*1000*1000)
-#define GMAC_MCK_SPEED_160MHZ (160*1000*1000)
-#define GMAC_MCK_SPEED_120MHZ (120*1000*1000)
-#define GMAC_MCK_SPEED_80MHZ (80*1000*1000)
-#define GMAC_MCK_SPEED_40MHZ (40*1000*1000)
-#define GMAC_MCK_SPEED_20MHZ (20*1000*1000)
-
-/** GMAC maintain code default value*/
-#define GMAC_MAN_CODE_VALUE (10)
-
-/** GMAC maintain start of frame default value*/
-#define GMAC_MAN_SOF_VALUE (1)
-
-/** GMAC maintain read/write*/
-#define GMAC_MAN_RW_TYPE (2)
-
-/** GMAC maintain read only*/
-#define GMAC_MAN_READ_ONLY (1)
-
-/** GMAC address length */
-#define GMAC_ADDR_LENGTH (6)
-
-
-#define GMAC_DUPLEX_HALF 0
-#define GMAC_DUPLEX_FULL 1
-
-#define GMAC_SPEED_10M 0
-#define GMAC_SPEED_100M 1
-
-/**
- * \brief Return codes for GMAC APIs.
- */
-typedef enum {
- GMAC_OK = 0, /** 0 Operation OK */
- GMAC_TIMEOUT = 1, /** 1 GMAC operation timeout */
- GMAC_TX_BUSY, /** 2 TX in progress */
- GMAC_RX_NULL, /** 3 No data received */
- GMAC_SIZE_TOO_SMALL, /** 4 Buffer size not enough */
- GMAC_PARAM, /** 5 Parameter error, TX packet invalid or RX size too small */
- GMAC_INVALID = 0xFF, /* Invalid */
-} gmac_status_t;
-
-/**
- * \brief Media Independent Interface (MII) type.
- */
-typedef enum {
- GMAC_PHY_MII = 0, /** MII mode */
- GMAC_PHY_RMII = 1, /** Reduced MII mode */
- GMAC_PHY_INVALID = 0xFF, /* Invalid mode*/
-} gmac_mii_mode_t;
-
-/** Receive buffer descriptor struct */
-COMPILER_PACK_SET(8)
-typedef struct gmac_rx_descriptor {
- union gmac_rx_addr {
- uint32_t val;
- struct gmac_rx_addr_bm {
- uint32_t b_ownership:1, /**< User clear, GMAC sets this to 1 once it has successfully written a frame to memory */
- b_wrap:1, /**< Marks last descriptor in receive buffer */
- addr_dw:30; /**< Address in number of DW */
- } bm;
- } addr; /**< Address, Wrap & Ownership */
- union gmac_rx_status {
- uint32_t val;
- struct gmac_rx_status_bm {
- uint32_t len:13, /** 0..12 Length of frame including FCS */
- b_fcs:1, /** 13 Receive buffer offset, bits 13:12 of frame length for jumbo frame */
- b_sof:1, /** 14 Start of frame */
- b_eof:1, /** 15 End of frame */
- b_cfi:1, /** 16 Concatenation Format Indicator */
- vlan_priority:3, /** 17..19 VLAN priority (if VLAN detected) */
- b_priority_detected:1, /** 20 Priority tag detected */
- b_vlan_detected:1, /** 21 VLAN tag detected */
- b_type_id_match:2, /** 22..23 Type ID match */
- b_checksumoffload:1, /** 24 Checksum offload specific function */
- b_addrmatch:2, /** 25..26 Address register match */
- b_ext_addr_match:1, /** 27 External address match found */
- reserved:1, /** 28 */
- b_uni_hash_match:1, /** 29 Unicast hash match */
- b_multi_hash_match:1, /** 30 Multicast hash match */
- b_boardcast_detect:1; /** 31 Global broadcast address detected */
- } bm;
- } status;
-} gmac_rx_descriptor_t;
-
-/** Transmit buffer descriptor struct */
-COMPILER_PACK_SET(8)
-typedef struct gmac_tx_descriptor {
- uint32_t addr;
- union gmac_tx_status {
- uint32_t val;
- struct gmac_tx_status_bm {
- uint32_t len:14, /** 0..13 Length of buffer */
- reserved:1, /** 14 */
- b_last_buffer:1, /** 15 Last buffer (in the current frame) */
- b_no_crc:1, /** 16 No CRC */
- reserved1:3, /** 17..19 */
- b_checksumoffload:3, /** 20..22 Transmit checksum generation offload errors */
- reserved2:3, /** 23..25 */
- b_lco:1, /** 26 Late collision, transmit error detected */
- b_exhausted:1, /** 27 Buffer exhausted in mid frame */
- b_underrun:1, /** 28 Transmit underrun */
- b_error:1, /** 29 Retry limit exceeded, error detected */
- b_wrap:1, /** 30 Marks last descriptor in TD list */
- b_used:1; /** 31 User clear, GMAC sets this to 1 once a frame has been successfully transmitted */
- } bm;
- } status;
-} gmac_tx_descriptor_t;
-
-COMPILER_PACK_RESET()
-
-/**
- * \brief Input parameters when initializing the gmac module mode.
- */
-typedef struct gmac_options {
- /* Enable/Disable CopyAllFrame */
- uint8_t uc_copy_all_frame;
- /* Enable/Disable NoBroadCast */
- uint8_t uc_no_boardcast;
- /* MAC address */
- uint8_t uc_mac_addr[GMAC_ADDR_LENGTH];
-} gmac_options_t;
-
-/** TX callback */
-typedef void (*gmac_dev_tx_cb_t) (uint32_t ul_status, uint8_t *puc_buffer);
-/** RX callback */
-typedef void (*gmac_dev_rx_cb_t) (uint32_t ul_status);
-/** Wakeup callback */
-typedef void (*gmac_dev_wakeup_cb_t) (void);
-
-/**
- * GMAC driver structure.
- */
-typedef struct gmac_device {
-
- /** Pointer to HW register base */
- Gmac *p_hw;
- /**
- * Pointer to allocated TX buffer.
- * Section 3.6 of AMBA 2.0 spec states that burst should not cross
- * 1K Boundaries.
- * Receive buffer manager writes are burst of 2 words => 3 lsb bits
- * of the address shall be set to 0.
- */
- uint8_t *p_tx_buffer;
- /** Pointer to allocated RX buffer */
- uint8_t *p_rx_buffer;
- /** Pointer to Rx TDs (must be 8-byte aligned) */
- gmac_rx_descriptor_t *p_rx_dscr;
- /** Pointer to Tx TDs (must be 8-byte aligned) */
- gmac_tx_descriptor_t *p_tx_dscr;
- /** Optional callback to be invoked once a frame has been received */
- gmac_dev_rx_cb_t func_rx_cb;
-#if( GMAC_USES_WAKEUP_CALLBACK )
- /** Optional callback to be invoked once several TDs have been released */
- gmac_dev_wakeup_cb_t func_wakeup_cb;
-#endif
-#if( GMAC_USES_TX_CALLBACK != 0 )
- /** Optional callback list to be invoked once TD has been processed */
- gmac_dev_tx_cb_t *func_tx_cb_list;
-#endif
- /** RX TD list size */
- uint32_t ul_rx_list_size;
- /** RX index for current processing TD */
- uint32_t ul_rx_idx;
- /** TX TD list size */
- uint32_t ul_tx_list_size;
- /** Circular buffer head pointer by upper layer (buffer to be sent) */
- int32_t l_tx_head;
- /** Circular buffer tail pointer incremented by handlers (buffer sent) */
- int32_t l_tx_tail;
-
- /** Number of free TD before wakeup callback is invoked */
- uint32_t uc_wakeup_threshold;
-} gmac_device_t;
-
-/**
- * \brief Write network control value.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_ncr Network control value.
- */
-static inline void gmac_network_control(Gmac* p_gmac, uint32_t ul_ncr)
-{
- p_gmac->GMAC_NCR = ul_ncr;
-}
-
-/**
- * \brief Get network control value.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-
-static inline uint32_t gmac_get_network_control(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NCR;
-}
-
-/**
- * \brief Enable/Disable GMAC receive.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC receiver, else to enable it.
- */
-static inline void gmac_enable_receive(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_RXEN;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_RXEN;
- }
-}
-
-/**
- * \brief Enable/Disable GMAC transmit.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC transmit, else to enable it.
- */
-static inline void gmac_enable_transmit(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_TXEN;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_TXEN;
- }
-}
-
-/**
- * \brief Enable/Disable GMAC management.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable GMAC management, else to enable it.
- */
-static inline void gmac_enable_management(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_MPE;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_MPE;
- }
-}
-
-/**
- * \brief Clear all statistics registers.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_clear_statistics(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_CLRSTAT;
-}
-
-/**
- * \brief Increase all statistics registers.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_increase_statistics(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_INCSTAT;
-}
-
-/**
- * \brief Enable/Disable statistics registers writing.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the statistics registers writing, else to enable it.
- */
-static inline void gmac_enable_statistics_write(Gmac* p_gmac,
- uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_WESTAT;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_WESTAT;
- }
-}
-
-/**
- * \brief In half-duplex mode, forces collisions on all received frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the back pressure, else to enable it.
- */
-static inline void gmac_enable_back_pressure(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_BP;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_BP;
- }
-}
-
-/**
- * \brief Start transmission.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_start_transmission(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TSTART;
-}
-
-/**
- * \brief Halt transmission.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_halt_transmission(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_THALT;
-}
-
-/**
- * \brief Transmit pause frame.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_tx_pause_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXPF;
-}
-
-/**
- * \brief Transmit zero quantum pause frame.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_tx_pause_zero_quantum_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXZQPF;
-}
-
-/**
- * \brief Read snapshot.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_read_snapshot(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_RDS;
-}
-
-/**
- * \brief Store receivetime stamp to memory.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to normal operation, else to enable the store.
- */
-static inline void gmac_store_rx_time_stamp(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_SRTSM;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_SRTSM;
- }
-}
-
-/**
- * \brief Enable PFC priority-based pause reception.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 1 to set the reception, 0 to disable.
- */
-static inline void gmac_enable_pfc_pause_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCR |= GMAC_NCR_ENPBPR;
- } else {
- p_gmac->GMAC_NCR &= ~GMAC_NCR_ENPBPR;
- }
-}
-
-/**
- * \brief Transmit PFC priority-based pause reception.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_transmit_pfc_pause_frame(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_TXPBPF;
-}
-
-/**
- * \brief Flush next packet.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_flush_next_packet(Gmac* p_gmac)
-{
- p_gmac->GMAC_NCR |= GMAC_NCR_FNP;
-}
-
-/**
- * \brief Set up network configuration register.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_cfg Network configuration value.
- */
-static inline void gmac_set_configure(Gmac* p_gmac, uint32_t ul_cfg)
-{
- p_gmac->GMAC_NCFGR = ul_cfg;
-}
-
-/**
- * \brief Get network configuration.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Network configuration.
- */
-static inline uint32_t gmac_get_configure(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NCFGR;
-}
-
-
-/* Get and set DMA Configuration Register */
-static inline void gmac_set_dma(Gmac* p_gmac, uint32_t ul_cfg)
-{
- p_gmac->GMAC_DCFGR = ul_cfg;
-}
-
-static inline uint32_t gmac_get_dma(Gmac* p_gmac)
-{
- return p_gmac->GMAC_DCFGR;
-}
-
-/**
- * \brief Set speed.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_speed 1 to indicate 100Mbps, 0 to 10Mbps.
- */
-static inline void gmac_set_speed(Gmac* p_gmac, uint8_t uc_speed)
-{
- if (uc_speed) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_SPD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_SPD;
- }
-}
-
-/**
- * \brief Enable/Disable Full-Duplex mode.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the Full-Duplex mode, else to enable it.
- */
-static inline void gmac_enable_full_duplex(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_FD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_FD;
- }
-}
-
-/**
- * \brief Enable/Disable Copy(Receive) All Valid Frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable copying all valid frames, else to enable it.
- */
-static inline void gmac_enable_copy_all(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_CAF;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_CAF;
- }
-}
-
-/**
- * \brief Enable/Disable jumbo frames (up to 10240 bytes).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the jumbo frames, else to enable it.
- */
-static inline void gmac_enable_jumbo_frames(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_JFRAME;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_JFRAME;
- }
-}
-
-/**
- * \brief Disable/Enable broadcast receiving.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 1 to disable the broadcast, else to enable it.
- */
-static inline void gmac_disable_broadcast(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_NBC;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_NBC;
- }
-}
-
-/**
- * \brief Enable/Disable multicast hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the multicast hash, else to enable it.
- */
-static inline void gmac_enable_multicast_hash(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_UNIHEN;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_UNIHEN;
- }
-}
-
-/**
- * \brief Enable/Disable big frames (over 1518, up to 1536).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable big frames else to enable it.
- */
-static inline void gmac_enable_big_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_MAXFS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_MAXFS;
- }
-}
-
-/**
- * \brief Set MDC clock divider.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_mck GMAC MCK.
- *
- * \return GMAC_OK if successfully.
- */
-static inline uint8_t gmac_set_mdc_clock(Gmac* p_gmac, uint32_t ul_mck)
-{
- uint32_t ul_clk;
-
- if (ul_mck > GMAC_MCK_SPEED_240MHZ) {
- return GMAC_INVALID;
- } else if (ul_mck > GMAC_MCK_SPEED_160MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_96;
- } else if (ul_mck > GMAC_MCK_SPEED_120MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_64;
- } else if (ul_mck > GMAC_MCK_SPEED_80MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_48;
- } else if (ul_mck > GMAC_MCK_SPEED_40MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_32;
- } else if (ul_mck > GMAC_MCK_SPEED_20MHZ) {
- ul_clk = GMAC_NCFGR_CLK_MCK_16;
- } else {
- ul_clk = GMAC_NCFGR_CLK_MCK_8;
- }
- ;
- p_gmac->GMAC_NCFGR = (p_gmac->GMAC_NCFGR & ~GMAC_NCFGR_CLK_Msk) | ul_clk;
- return GMAC_OK;
-}
-
-/**
- * \brief Enable/Disable retry test.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the GMAC receiver, else to enable it.
- */
-static inline void gmac_enable_retry_test(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RTY;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RTY;
- }
-}
-
-/**
- * \brief Enable/Disable pause (when a valid pause frame is received).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable pause frame, else to enable it.
- */
-static inline void gmac_enable_pause_frame(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_PEN;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_PEN;
- }
-}
-
-/**
- * \brief Set receive buffer offset to 0 ~ 3.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline void gmac_set_rx_buffer_offset(Gmac* p_gmac, uint8_t uc_offset)
-{
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RXBUFO_Msk;
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RXBUFO(uc_offset);
-}
-
-/**
- * \brief Enable/Disable receive length field checking.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable receive length field checking, else to enable it.
- */
-static inline void gmac_enable_rx_length_check(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_LFERD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_LFERD;
- }
-}
-
-/**
- * \brief Enable/Disable discarding FCS field of received frames.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable discarding FCS field of received frames, else to enable it.
- */
-static inline void gmac_enable_discard_fcs(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_RFCS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_RFCS;
- }
-}
-
-
-/**
- * \brief Enable/Disable frames to be received in half-duplex mode
- * while transmitting.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable the received in half-duplex mode, else to enable it.
- */
-static inline void gmac_enable_efrhd(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_EFRHD;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_EFRHD;
- }
-}
-
-/**
- * \brief Enable/Disable ignore RX FCS.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_enable 0 to disable ignore RX FCS, else to enable it.
- */
-static inline void gmac_enable_ignore_rx_fcs(Gmac* p_gmac, uint8_t uc_enable)
-{
- if (uc_enable) {
- p_gmac->GMAC_NCFGR |= GMAC_NCFGR_IRXFCS;
- } else {
- p_gmac->GMAC_NCFGR &= ~GMAC_NCFGR_IRXFCS;
- }
-}
-
-/**
- * \brief Get Network Status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Network status.
- */
-static inline uint32_t gmac_get_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_NSR;
-}
-
-/**
- * \brief Get MDIO IN pin status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return MDIO IN pin status.
- */
-static inline uint8_t gmac_get_MDIO(Gmac* p_gmac)
-{
- return ((p_gmac->GMAC_NSR & GMAC_NSR_MDIO) > 0);
-}
-
-/**
- * \brief Check if PHY is idle.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return 1 if PHY is idle.
- */
-static inline uint8_t gmac_is_phy_idle(Gmac* p_gmac)
-{
- return ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) > 0);
-}
-
-/**
- * \brief Return transmit status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Transmit status.
- */
-static inline uint32_t gmac_get_tx_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_TSR;
-}
-
-/**
- * \brief Clear transmit status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_status Transmit status.
- */
-static inline void gmac_clear_tx_status(Gmac* p_gmac, uint32_t ul_status)
-{
- p_gmac->GMAC_TSR = ul_status;
-}
-
-/**
- * \brief Return receive status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- */
-static inline uint32_t gmac_get_rx_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_RSR;
-}
-
-/**
- * \brief Clear receive status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_status Receive status.
- */
-static inline void gmac_clear_rx_status(Gmac* p_gmac, uint32_t ul_status)
-{
- p_gmac->GMAC_RSR = ul_status;
-}
-
-/**
- * \brief Set Rx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_addr Rx queue address.
- */
-static inline void gmac_set_rx_queue(Gmac* p_gmac, uint32_t ul_addr)
-{
- p_gmac->GMAC_RBQB = GMAC_RBQB_ADDR_Msk & ul_addr;
-}
-
-/**
- * \brief Get Rx Queue Address.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Rx queue address.
- */
-static inline uint32_t gmac_get_rx_queue(Gmac* p_gmac)
-{
- return p_gmac->GMAC_RBQB;
-}
-
-/**
- * \brief Set Tx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_addr Tx queue address.
- */
-static inline void gmac_set_tx_queue(Gmac* p_gmac, uint32_t ul_addr)
-{
- p_gmac->GMAC_TBQB = GMAC_TBQB_ADDR_Msk & ul_addr;
-}
-
-/**
- * \brief Get Tx Queue.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Rx queue address.
- */
-static inline uint32_t gmac_get_tx_queue(Gmac* p_gmac)
-{
- return p_gmac->GMAC_TBQB;
-}
-
-/**
- * \brief Enable interrupt(s).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_source Interrupt source(s) to be enabled.
- */
-static inline void gmac_enable_interrupt(Gmac* p_gmac, uint32_t ul_source)
-{
- p_gmac->GMAC_IER = ul_source;
-}
-
-/**
- * \brief Disable interrupt(s).
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_source Interrupt source(s) to be disabled.
- */
-static inline void gmac_disable_interrupt(Gmac* p_gmac, uint32_t ul_source)
-{
- p_gmac->GMAC_IDR = ul_source;
-}
-
-/**
- * \brief Return interrupt status.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Interrupt status.
- */
-static inline uint32_t gmac_get_interrupt_status(Gmac* p_gmac)
-{
- return p_gmac->GMAC_ISR;
-}
-
-/**
- * \brief Return interrupt mask.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Interrupt mask.
- */
-static inline uint32_t gmac_get_interrupt_mask(Gmac* p_gmac)
-{
- return p_gmac->GMAC_IMR;
-}
-
-/**
- * \brief Execute PHY maintenance command.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_phy_addr PHY address.
- * \param uc_reg_addr Register address.
- * \param uc_rw 1 to Read, 0 to write.
- * \param us_data Data to be performed, write only.
- */
-static inline void gmac_maintain_phy(Gmac* p_gmac,
- uint8_t uc_phy_addr, uint8_t uc_reg_addr, uint8_t uc_rw,
- uint16_t us_data)
-{
- /* Wait until bus idle */
- while ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) == 0);
- /* Write maintain register */
- p_gmac->GMAC_MAN = GMAC_MAN_WTN(GMAC_MAN_CODE_VALUE)
- | GMAC_MAN_CLTTO
- | GMAC_MAN_PHYA(uc_phy_addr)
- | GMAC_MAN_REGA(uc_reg_addr)
- | GMAC_MAN_OP((uc_rw ? GMAC_MAN_RW_TYPE : GMAC_MAN_READ_ONLY))
- | GMAC_MAN_DATA(us_data);
-}
-
-/**
- * \brief Get PHY maintenance data returned.
- *
- * \param p_gmac Pointer to the GMAC instance.
- *
- * \return Get PHY data.
- */
-static inline uint16_t gmac_get_phy_data(Gmac* p_gmac)
-{
- /* Wait until bus idle */
- while ((p_gmac->GMAC_NSR & GMAC_NSR_IDLE) == 0);
- /* Return data */
- return (uint16_t) (p_gmac->GMAC_MAN & GMAC_MAN_DATA_Msk);
-}
-
-/**
- * \brief Set Hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ul_hash_top Hash top.
- * \param ul_hash_bottom Hash bottom.
- */
-static inline void gmac_set_hash(Gmac* p_gmac, uint32_t ul_hash_top,
- uint32_t ul_hash_bottom)
-{
- p_gmac->GMAC_HRB = ul_hash_bottom;
- p_gmac->GMAC_HRT = ul_hash_top;
-}
-
-/**
- * \brief Set 64 bits Hash.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param ull_hash 64 bits hash value.
- */
-static inline void gmac_set_hash64(Gmac* p_gmac, uint64_t ull_hash)
-{
- p_gmac->GMAC_HRB = (uint32_t) ull_hash;
- p_gmac->GMAC_HRT = (uint32_t) (ull_hash >> 32);
-}
-
-/**
- * \brief Set MAC Address.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param p_mac_addr GMAC address.
- */
-static inline void gmac_set_address(Gmac* p_gmac, uint8_t uc_index,
- uint8_t* p_mac_addr)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = (p_mac_addr[3] << 24)
- | (p_mac_addr[2] << 16)
- | (p_mac_addr[1] << 8)
- | (p_mac_addr[0]);
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = (p_mac_addr[5] << 8)
- | (p_mac_addr[4]);
-}
-
-/**
- * \brief Set MAC Address via 2 dword.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param ul_mac_top GMAC top address.
- * \param ul_mac_bottom GMAC bottom address.
- */
-static inline void gmac_set_address32(Gmac* p_gmac, uint8_t uc_index,
- uint32_t ul_mac_top, uint32_t ul_mac_bottom)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = ul_mac_bottom;
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = ul_mac_top;
-}
-
-/**
- * \brief Set MAC Address via int64.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param uc_index GMAC specific address register index.
- * \param ull_mac 64-bit GMAC address.
- */
-static inline void gmac_set_address64(Gmac* p_gmac, uint8_t uc_index,
- uint64_t ull_mac)
-{
- p_gmac->GMAC_SA[uc_index].GMAC_SAB = (uint32_t) ull_mac;
- p_gmac->GMAC_SA[uc_index].GMAC_SAT = (uint32_t) (ull_mac >> 32);
-}
-
-/**
- * \brief Select media independent interface mode.
- *
- * \param p_gmac Pointer to the GMAC instance.
- * \param mode Media independent interface mode.
- */
-static inline void gmac_select_mii_mode(Gmac* p_gmac, gmac_mii_mode_t mode)
-{
- switch (mode) {
- case GMAC_PHY_MII:
- case GMAC_PHY_RMII:
- p_gmac->GMAC_UR |= GMAC_UR_RMIIMII;
- break;
-
- default:
- p_gmac->GMAC_UR &= ~GMAC_UR_RMIIMII;
- break;
- }
-}
-
-uint8_t gmac_phy_read(Gmac* p_gmac, uint8_t uc_phy_address, uint8_t uc_address,
- uint32_t* p_value);
-uint8_t gmac_phy_write(Gmac* p_gmac, uint8_t uc_phy_address,
- uint8_t uc_address, uint32_t ul_value);
-void gmac_dev_init(Gmac* p_gmac, gmac_device_t* p_gmac_dev,
- gmac_options_t* p_opt);
-uint32_t gmac_dev_read(gmac_device_t* p_gmac_dev, uint8_t* p_frame,
- uint32_t ul_frame_size, uint32_t* p_rcv_size);
-uint32_t gmac_dev_write(gmac_device_t* p_gmac_dev, void *p_buffer,
- uint32_t ul_size, gmac_dev_tx_cb_t func_tx_cb);
-uint32_t gmac_dev_get_tx_load(gmac_device_t* p_gmac_dev);
-void gmac_dev_set_rx_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_rx_cb_t func_rx_cb);
-uint8_t gmac_dev_set_tx_wakeup_callback(gmac_device_t* p_gmac_dev,
- gmac_dev_wakeup_cb_t func_wakeup, uint8_t uc_threshold);
-void gmac_dev_reset(gmac_device_t* p_gmac_dev);
-void gmac_handler(gmac_device_t* p_gmac_dev);
-
-/// @cond 0
-/**INDENT-OFF**/
-#ifdef __cplusplus
-}
-#endif
-/**INDENT-ON**/
-/// @endcond
-
-/**
- * \page gmac_quickstart Quickstart guide for GMAC driver.
- *
- * This is the quickstart guide for the \ref gmac_group "Ethernet MAC",
- * with step-by-step instructions on how to configure and use the driver in a
- * selection of use cases.
- *
- * The use cases contain several code fragments. The code fragments in the
- * steps for setup can be copied into a custom initialization function, while
- * the steps for usage can be copied into, e.g., the main application function.
- *
- * \section gmac_basic_use_case Basic use case
- * In the basic use case, the GMAC driver are configured for:
- * - PHY component KSZ8051MNL is used
- * - GMAC uses MII mode
- * - The number of receive buffer is 16
- * - The number of transfer buffer is 8
- * - MAC address is set to 00-04-25-1c-a0-02
- * - IP address is set to 192.168.0.2
- * - IP address is set to 192.168.0.2
- * - Gateway is set to 192.168.0.1
- * - Network mask is 255.255.255.0
- * - PHY operation max retry count is 1000000
- * - GMAC is configured to not support copy all frame and support broadcast
- * - The data will be read from the ethernet
- *
- * \section gmac_basic_use_case_setup Setup steps
- *
- * \subsection gmac_basic_use_case_setup_prereq Prerequisites
- * -# \ref sysclk_group "System Clock Management (sysclock)"
- * -# \ref pmc_group "Power Management Controller (pmc)"
- * -# \ref ksz8051mnl_ethernet_phy_group "PHY component (KSZ8051MNL)"
- *
- * \subsection gmac_basic_use_case_setup_code Example code
- * Content of conf_eth.h
- * \code
- * #define GMAC_RX_BUFFERS 16
- * #define GMAC_TX_BUFFERS 8
- * #define MAC_PHY_RETRY_MAX 1000000
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR1 0x04
- * #define ETHERNET_CONF_ETHADDR2 0x25
- * #define ETHERNET_CONF_ETHADDR3 0x1C
- * #define ETHERNET_CONF_ETHADDR4 0xA0
- * #define ETHERNET_CONF_ETHADDR5 0x02
- * #define ETHERNET_CONF_IPADDR0 192
- * #define ETHERNET_CONF_IPADDR1 168
- * #define ETHERNET_CONF_IPADDR2 0
- * #define ETHERNET_CONF_IPADDR3 2
- * #define ETHERNET_CONF_GATEWAY_ADDR0 192
- * #define ETHERNET_CONF_GATEWAY_ADDR1 168
- * #define ETHERNET_CONF_GATEWAY_ADDR2 0
- * #define ETHERNET_CONF_GATEWAY_ADDR3 1
- * #define ETHERNET_CONF_NET_MASK0 255
- * #define ETHERNET_CONF_NET_MASK1 255
- * #define ETHERNET_CONF_NET_MASK2 255
- * #define ETHERNET_CONF_NET_MASK3 0
- * #define ETH_PHY_MODE ETH_PHY_MODE
- * \endcode
- *
- * A specific gmac device and the receive data buffer must be defined; another ul_frm_size should be defined
- * to trace the actual size of the data received.
- * \code
- * static gmac_device_t gs_gmac_dev;
- * static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
- *
- * uint32_t ul_frm_size;
- * \endcode
- *
- * Add to application C-file:
- * \code
- * void gmac_init(void)
- * {
- * sysclk_init();
- *
- * board_init();
- *
- * pmc_enable_periph_clk(ID_GMAC);
- *
- * gmac_option.uc_copy_all_frame = 0;
- * gmac_option.uc_no_boardcast = 0;
- * memcpy(gmac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
- * gs_gmac_dev.p_hw = GMAC;
- *
- * gmac_dev_init(GMAC, &gs_gmac_dev, &gmac_option);
- *
- * NVIC_EnableIRQ(GMAC_IRQn);
- *
- * ethernet_phy_init(GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz());
- *
- * ethernet_phy_auto_negotiate(GMAC, BOARD_GMAC_PHY_ADDR);
- *
- * ethernet_phy_set_link(GMAC, BOARD_GMAC_PHY_ADDR, 1);
- * \endcode
- *
- * \subsection gmac_basic_use_case_setup_flow Workflow
- * - Ensure that conf_eth.h is present and contains the
- * following configuration symbol. This configuration file is used
- * by the driver and should not be included by the application.
- * -# Define the receiving buffer size used in the internal GMAC driver.
- * The buffer size used for RX is GMAC_RX_BUFFERS * 128.
- * If it was supposed receiving a large number of frame, the
- * GMAC_RX_BUFFERS should be set higher. E.g., the application wants to accept
- * a ping echo test of 2048, the GMAC_RX_BUFFERS should be set at least
- * (2048/128)=16, and as there are additional frames coming, a preferred
- * number is 24 depending on a normal Ethernet throughput.
- * - \code
- * #define GMAC_RX_BUFFERS 16
- * \endcode
- * -# Define the transmitting buffer size used in the internal GMAC driver.
- * The buffer size used for TX is GMAC_TX_BUFFERS * 1518.
- * - \code
- * #define GMAC_TX_BUFFERS 8
- * \endcode
- * -# Define maximum retry time for a PHY read/write operation.
- * - \code
- * #define MAC_PHY_RETRY_MAX 1000000
- * \endcode
- * -# Define the MAC address. 00:04:25:1C:A0:02 is the address reserved
- * for ATMEL, application should always change this address to its' own.
- * - \code
- * #define ETHERNET_CONF_ETHADDR0 0x00
- * #define ETHERNET_CONF_ETHADDR1 0x04
- * #define ETHERNET_CONF_ETHADDR2 0x25
- * #define ETHERNET_CONF_ETHADDR3 0x1C
- * #define ETHERNET_CONF_ETHADDR4 0xA0
- * #define ETHERNET_CONF_ETHADDR5 0x02
- * \endcode
- * -# Define the IP address configration used in the application. When DHCP
- * is enabled, this configuration is not effected.
- * - \code
- * #define ETHERNET_CONF_IPADDR0 192
- * #define ETHERNET_CONF_IPADDR1 168
- * #define ETHERNET_CONF_IPADDR2 0
- * #define ETHERNET_CONF_IPADDR3 2
- * #define ETHERNET_CONF_GATEWAY_ADDR0 192
- * #define ETHERNET_CONF_GATEWAY_ADDR1 168
- * #define ETHERNET_CONF_GATEWAY_ADDR2 0
- * #define ETHERNET_CONF_GATEWAY_ADDR3 1
- * #define ETHERNET_CONF_NET_MASK0 255
- * #define ETHERNET_CONF_NET_MASK1 255
- * #define ETHERNET_CONF_NET_MASK2 255
- * #define ETHERNET_CONF_NET_MASK3 0
- * \endcode
- * -# Configure the PHY maintainance interface.
- * - \code
- * #define ETH_PHY_MODE GMAC_PHY_MII
- * \endcode
- * -# Enable the system clock:
- * - \code sysclk_init(); \endcode
- * -# Enable PIO configurations for GMAC:
- * - \code board_init(); \endcode
- * -# Enable PMC clock for GMAC:
- * - \code pmc_enable_periph_clk(ID_GMAC); \endcode
- * -# Set the GMAC options; it's set to copy all frame and support broadcast:
- * - \code
- * gmac_option.uc_copy_all_frame = 0;
- * gmac_option.uc_no_boardcast = 0;
- * memcpy(gmac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
- * gs_gmac_dev.p_hw = GMAC;
- * \endcode
- * -# Initialize GMAC device with the filled option:
- * - \code
- * gmac_dev_init(GMAC, &gs_gmac_dev, &gmac_option);
- * \endcode
- * -# Enable the interrupt service for GMAC:
- * - \code
- * NVIC_EnableIRQ(GMAC_IRQn);
- * \endcode
- * -# Initialize the PHY component:
- * - \code
- * ethernet_phy_init(GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz());
- * \endcode
- * -# The link will be established based on auto negotiation.
- * - \code
- * ethernet_phy_auto_negotiate(GMAC, BOARD_GMAC_PHY_ADDR);
- * \endcode
- * -# Establish the ethernet link; the network can be worked from now on:
- * - \code
- * ethernet_phy_set_link(GMAC, BOARD_GMAC_PHY_ADDR, 1);
- * \endcode
- *
- * \section gmac_basic_use_case_usage Usage steps
- * \subsection gmac_basic_use_case_usage_code Example code
- * Add to, e.g., main loop in application C-file:
- * \code
- * gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size));
- * \endcode
- *
- * \subsection gmac_basic_use_case_usage_flow Workflow
- * -# Start reading the data from the ethernet:
- * - \code gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size)); \endcode
- */
-
-# define GMAC_STATS 0
-
-#if( GMAC_STATS != 0 )
-
- /* Here below some code to study the types and
- frequencies of GMAC interrupts. */
- #define GMAC_IDX_RXUBR 0
- #define GMAC_IDX_TUR 1
- #define GMAC_IDX_RLEX 2
- #define GMAC_IDX_TFC 3
- #define GMAC_IDX_RCOMP 4
- #define GMAC_IDX_TCOMP 5
- #define GMAC_IDX_ROVR 6
- #define GMAC_IDX_HRESP 7
- #define GMAC_IDX_PFNZ 8
- #define GMAC_IDX_PTZ 9
-
- struct SGmacStats {
- unsigned recvCount;
- unsigned rovrCount;
- unsigned bnaCount;
- unsigned sendCount;
- unsigned sovrCount;
- unsigned incompCount;
- unsigned truncCount;
-
- unsigned intStatus[10];
- };
- extern struct SGmacStats gmacStats;
-
- struct SIntPair {
- const char *name;
- unsigned mask;
- int index;
- };
-
- #define MK_PAIR( NAME ) #NAME, GMAC_IER_##NAME, GMAC_IDX_##NAME
- static const struct SIntPair intPairs[] = {
- { MK_PAIR( RXUBR ) }, /* Enable receive used bit read interrupt. */
- { MK_PAIR( TUR ) }, /* Enable transmit underrun interrupt. */
- { MK_PAIR( RLEX ) }, /* Enable retry limit exceeded interrupt. */
- { MK_PAIR( TFC ) }, /* Enable transmit buffers exhausted in mid-frame interrupt. */
- { MK_PAIR( RCOMP ) }, /* Receive complete */
- { MK_PAIR( TCOMP ) }, /* Enable transmit complete interrupt. */
- { MK_PAIR( ROVR ) }, /* Enable receive overrun interrupt. */
- { MK_PAIR( HRESP ) }, /* Enable Hresp not OK interrupt. */
- { MK_PAIR( PFNZ ) }, /* Enable pause frame received interrupt. */
- { MK_PAIR( PTZ ) } /* Enable pause time zero interrupt. */
- };
-
- void gmac_show_irq_counts ();
-
-#endif
-
-#endif /* GMAC_H_INCLUDED */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Common/phyHandling.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Common/phyHandling.c
deleted file mode 100755
index 62b3a95..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Common/phyHandling.c
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * Handling of Ethernet PHY's
- * PHY's communicate with an EMAC either through
- * a Media-Independent Interface (MII), or a Reduced Media-Independent Interface (RMII).
- * The EMAC can poll for PHY ports on 32 different addresses. Each of the PHY ports
- * shall be treated independently.
- *
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-
-#include "phyHandling.h"
-
-#include "eventLogging.h"
-
-#define phyMIN_PHY_ADDRESS 0
-#define phyMAX_PHY_ADDRESS 31
-
-#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
- #warning please use the new defines with 'ipconfig' prefix
-#endif
-
-#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still high after 15 seconds of not
- receiving packets. */
- #define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000
-#endif
-
-#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still low every second. */
- #define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000
-#endif
-
-/* Naming and numbering of basic PHY registers. */
-#define phyREG_00_BMCR 0x00u /* Basic Mode Control Register. */
-#define phyREG_01_BMSR 0x01u /* Basic Mode Status Register. */
-#define phyREG_02_PHYSID1 0x02u /* PHYS ID 1 */
-#define phyREG_03_PHYSID2 0x03u /* PHYS ID 2 */
-#define phyREG_04_ADVERTISE 0x04u /* Advertisement control reg */
-
-/* Naming and numbering of extended PHY registers. */
-#define PHYREG_10_PHYSTS 0x10u /* 16 PHY status register Offset */
-#define phyREG_19_PHYCR 0x19u /* 25 RW PHY Control Register */
-#define phyREG_1F_PHYSPCS 0x1Fu /* 31 RW PHY Special Control Status */
-
-/* Bit fields for 'phyREG_00_BMCR', the 'Basic Mode Control Register'. */
-#define phyBMCR_FULL_DUPLEX 0x0100u /* Full duplex. */
-#define phyBMCR_AN_RESTART 0x0200u /* Auto negotiation restart. */
-#define phyBMCR_AN_ENABLE 0x1000u /* Enable auto negotiation. */
-#define phyBMCR_SPEED_100 0x2000u /* Select 100Mbps. */
-#define phyBMCR_RESET 0x8000u /* Reset the PHY. */
-
-/* Bit fields for 'phyREG_19_PHYCR', the 'PHY Control Register'. */
-#define PHYCR_MDIX_EN 0x8000u /* Enable Auto MDIX. */
-#define PHYCR_MDIX_FORCE 0x4000u /* Force MDIX crossed. */
-
-#define phyBMSR_AN_COMPLETE 0x0020u /* Auto-Negotiation process completed */
-
-#define phyBMSR_LINK_STATUS 0x0004u
-
-#define phyPHYSTS_LINK_STATUS 0x0001u /* PHY Link mask */
-#define phyPHYSTS_SPEED_STATUS 0x0002u /* PHY Speed mask */
-#define phyPHYSTS_DUPLEX_STATUS 0x0004u /* PHY Duplex mask */
-
-/* Bit fields for 'phyREG_1F_PHYSPCS
- 001 = 10BASE-T half-duplex
- 101 = 10BASE-T full-duplex
- 010 = 100BASE-TX half-duplex
- 110 = 100BASE-TX full-duplex
-*/
-#define phyPHYSPCS_SPEED_MASK 0x000Cu
-#define phyPHYSPCS_SPEED_10 0x0004u
-#define phyPHYSPCS_FULL_DUPLEX 0x0010u
-
-/*
- * Description of all capabilities that can be advertised to
- * the peer (usually a switch or router).
- */
-#define phyADVERTISE_CSMA 0x0001u /* Only selector supported. */
-#define phyADVERTISE_10HALF 0x0020u /* Try for 10mbps half-duplex. */
-#define phyADVERTISE_10FULL 0x0040u /* Try for 10mbps full-duplex. */
-#define phyADVERTISE_100HALF 0x0080u /* Try for 100mbps half-duplex. */
-#define phyADVERTISE_100FULL 0x0100u /* Try for 100mbps full-duplex. */
-
-#define phyADVERTISE_ALL ( phyADVERTISE_10HALF | phyADVERTISE_10FULL | \
- phyADVERTISE_100HALF | phyADVERTISE_100FULL )
-
-/* Send a reset commando to a set of PHY-ports. */
-static uint32_t xPhyReset( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
-
-static BaseType_t xHas_1F_PHYSPCS( uint32_t ulPhyID )
-{
-BaseType_t xResult;
-
- switch( ulPhyID )
- {
- case PHY_ID_LAN8720:
- case PHY_ID_LAN8742A:
- case PHY_ID_KSZ8041:
-/*
- case PHY_ID_KSZ8051: // same ID as 8041
- case PHY_ID_KSZ8081: // same ID as 8041
-*/
- case PHY_ID_KSZ8863:
- default:
- /* Most PHY's have a 1F_PHYSPCS */
- xResult = pdTRUE;
- break;
- case PHY_ID_DP83848I:
- xResult = pdFALSE;
- break;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t xHas_19_PHYCR( uint32_t ulPhyID )
-{
-BaseType_t xResult;
-
- switch( ulPhyID )
- {
- case PHY_ID_LAN8742A:
- case PHY_ID_DP83848I:
- xResult = pdTRUE;
- break;
- default:
- /* Most PHY's do not have a 19_PHYCR */
- xResult = pdFALSE;
- break;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-/* Initialise the struct and assign a PHY-read and -write function. */
-void vPhyInitialise( EthernetPhy_t *pxPhyObject, xApplicationPhyReadHook_t fnPhyRead, xApplicationPhyWriteHook_t fnPhyWrite )
-{
- memset( ( void * )pxPhyObject, '\0', sizeof( *pxPhyObject ) );
-
- pxPhyObject->fnPhyRead = fnPhyRead;
- pxPhyObject->fnPhyWrite = fnPhyWrite;
-}
-/*-----------------------------------------------------------*/
-
-/* Discover all PHY's connected by polling 32 indexes ( zero-based ) */
-BaseType_t xPhyDiscover( EthernetPhy_t *pxPhyObject )
-{
-BaseType_t xPhyAddress;
-
- pxPhyObject->xPortCount = 0;
-
- for( xPhyAddress = phyMIN_PHY_ADDRESS; xPhyAddress <= phyMAX_PHY_ADDRESS; xPhyAddress++ )
- {
- uint32_t ulLowerID;
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_03_PHYSID2, &ulLowerID );
- /* A valid PHY id can not be all zeros or all ones. */
- if( ( ulLowerID != ( uint16_t )~0u ) && ( ulLowerID != ( uint16_t )0u ) )
- {
- uint32_t ulUpperID;
- uint32_t ulPhyID;
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_02_PHYSID1, &ulUpperID );
- ulPhyID = ( ( ( uint32_t ) ulUpperID ) << 16 ) | ( ulLowerID & 0xFFF0 );
-
- pxPhyObject->ucPhyIndexes[ pxPhyObject->xPortCount ] = xPhyAddress;
- pxPhyObject->ulPhyIDs[ pxPhyObject->xPortCount ] = ulPhyID;
-
- pxPhyObject->xPortCount++;
-
- /* See if there is more storage space. */
- if( pxPhyObject->xPortCount == ipconfigPHY_MAX_PORTS )
- {
- break;
- }
- }
- }
- if( pxPhyObject->xPortCount > 0 )
- {
- FreeRTOS_printf( ( "PHY ID %lX\n", pxPhyObject->ulPhyIDs[ 0 ] ) );
- eventLogAdd( "PHY ID 0x%lX", pxPhyObject->ulPhyIDs[ 0 ] );
- }
-
- return pxPhyObject->xPortCount;
-}
-/*-----------------------------------------------------------*/
-
-/* Send a reset commando to a set of PHY-ports. */
-static uint32_t xPhyReset( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask )
-{
-uint32_t ulDoneMask, ulConfig;
-TickType_t xRemainingTime;
-TimeOut_t xTimer;
-BaseType_t xPhyIndex;
-
- /* A bit-mask ofPHY ports that are ready. */
- ulDoneMask = 0ul;
-
- /* Set the RESET bits high. */
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++ )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- /* Read Control register. */
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_00_BMCR, &ulConfig );
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_00_BMCR, ulConfig | phyBMCR_RESET );
- }
-
- xRemainingTime = ( TickType_t ) pdMS_TO_TICKS( 1000UL );
- vTaskSetTimeOutState( &xTimer );
-
- /* The reset should last less than a second. */
- for( ;; )
- {
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++ )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_00_BMCR, &ulConfig );
- if( ( ulConfig & phyBMCR_RESET ) == 0 )
- {
- FreeRTOS_printf( ( "xPhyReset: phyBMCR_RESET %d ready\n", (int)xPhyIndex ) );
- ulDoneMask |= ( 1ul << xPhyIndex );
- }
- }
- if( ulDoneMask == ulPhyMask )
- {
- break;
- }
- if( xTaskCheckForTimeOut( &xTimer, &xRemainingTime ) != pdFALSE )
- {
- FreeRTOS_printf( ( "xPhyReset: phyBMCR_RESET timed out ( done 0x%02lX )\n", ulDoneMask ) );
- break;
- }
- }
-
- /* Clear the reset bits. */
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++ )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_00_BMCR, &ulConfig );
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_00_BMCR, ulConfig & ~phyBMCR_RESET );
- }
-
- vTaskDelay( pdMS_TO_TICKS( 50ul ) );
- eventLogAdd( "PHY reset %d ports", (int)pxPhyObject->xPortCount );
- return ulDoneMask;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xPhyConfigure( EthernetPhy_t *pxPhyObject, const PhyProperties_t *pxPhyProperties )
-{
-uint32_t ulConfig, ulAdvertise;
-BaseType_t xPhyIndex;
-
- if( pxPhyObject->xPortCount < 1 )
- {
- FreeRTOS_printf( ( "xPhyResetAll: No PHY's detected.\n" ) );
- return -1;
- }
-
- /* The expected ID for the 'LAN8742A' is 0x0007c130. */
- /* The expected ID for the 'LAN8720' is 0x0007c0f0. */
- /* The expected ID for the 'DP83848I' is 0x20005C90. */
-
- /* Set advertise register. */
- if( ( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_AUTO ) && ( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_AUTO ) )
- {
- ulAdvertise = phyADVERTISE_CSMA | phyADVERTISE_ALL;
- /* Reset auto-negotiation capability. */
- }
- else
- {
- ulAdvertise = phyADVERTISE_CSMA;
-
- if( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_AUTO )
- {
- if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_FULL )
- {
- ulAdvertise |= phyADVERTISE_10FULL | phyADVERTISE_100FULL;
- }
- else
- {
- ulAdvertise |= phyADVERTISE_10HALF | phyADVERTISE_100HALF;
- }
- }
- else if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_AUTO )
- {
- if( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_10 )
- {
- ulAdvertise |= phyADVERTISE_10FULL | phyADVERTISE_10HALF;
- }
- else
- {
- ulAdvertise |= phyADVERTISE_100FULL | phyADVERTISE_100HALF;
- }
- }
- else if( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_100 )
- {
- if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_FULL )
- {
- ulAdvertise |= phyADVERTISE_100FULL;
- }
- else
- {
- ulAdvertise |= phyADVERTISE_100HALF;
- }
- }
- else
- {
- if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_FULL )
- {
- ulAdvertise |= phyADVERTISE_10FULL;
- }
- else
- {
- ulAdvertise |= phyADVERTISE_10HALF;
- }
- }
- }
-
- /* Send a reset commando to a set of PHY-ports. */
- xPhyReset( pxPhyObject, xPhyGetMask( pxPhyObject ) );
-
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++ )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
- uint32_t ulPhyID = pxPhyObject->ulPhyIDs[ xPhyIndex ];
-
- /* Write advertise register. */
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_04_ADVERTISE, ulAdvertise );
-
- /*
- AN_EN AN1 AN0 Forced Mode
- 0 0 0 10BASE-T, Half-Duplex
- 0 0 1 10BASE-T, Full-Duplex
- 0 1 0 100BASE-TX, Half-Duplex
- 0 1 1 100BASE-TX, Full-Duplex
- AN_EN AN1 AN0 Advertised Mode
- 1 0 0 10BASE-T, Half/Full-Duplex
- 1 0 1 100BASE-TX, Half/Full-Duplex
- 1 1 0 10BASE-T Half-Duplex
- 100BASE-TX, Half-Duplex
- 1 1 1 10BASE-T, Half/Full-Duplex
- 100BASE-TX, Half/Full-Duplex
- */
-
- /* Read Control register. */
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_00_BMCR, &ulConfig );
-
- ulConfig &= ~( phyBMCR_SPEED_100 | phyBMCR_FULL_DUPLEX );
-
- ulConfig |= phyBMCR_AN_ENABLE;
-
- if( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_100 )
- {
- ulConfig |= phyBMCR_SPEED_100;
- }
- else if( pxPhyProperties->ucSpeed == ( uint8_t )PHY_SPEED_10 )
- {
- ulConfig &= ~phyBMCR_SPEED_100;
- }
-
- if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_FULL )
- {
- ulConfig |= phyBMCR_FULL_DUPLEX;
- }
- else if( pxPhyProperties->ucDuplex == ( uint8_t )PHY_DUPLEX_HALF )
- {
- ulConfig &= ~phyBMCR_FULL_DUPLEX;
- }
-
- if( xHas_19_PHYCR( ulPhyID ) )
- {
- uint32_t ulPhyControl;
- /* Read PHY Control register. */
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_19_PHYCR, &ulPhyControl );
-
- /* Clear bits which might get set: */
- ulPhyControl &= ~( PHYCR_MDIX_EN|PHYCR_MDIX_FORCE );
-
- if( pxPhyProperties->ucMDI_X == PHY_MDIX_AUTO )
- {
- ulPhyControl |= PHYCR_MDIX_EN;
- }
- else if( pxPhyProperties->ucMDI_X == PHY_MDIX_CROSSED )
- {
- /* Force direct link = Use crossed RJ45 cable. */
- ulPhyControl &= ~PHYCR_MDIX_FORCE;
- }
- else
- {
- /* Force crossed link = Use direct RJ45 cable. */
- ulPhyControl |= PHYCR_MDIX_FORCE;
- }
- /* update PHY Control Register. */
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_19_PHYCR, ulPhyControl );
- }
-
- FreeRTOS_printf( ( "+TCP: advertise: %04lX config %04lX\n", ulAdvertise, ulConfig ) );
- eventLogAdd( "adv: %04lX config %04lX", ulAdvertise, ulConfig );
- }
-
- /* Keep these values for later use. */
- pxPhyObject->ulBCRValue = ulConfig;
- pxPhyObject->ulACRValue = ulAdvertise;
-
- return 0;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xPhyFixedValue( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask )
-{
-BaseType_t xPhyIndex;
-uint32_t ulValue, ulBitMask = ( uint32_t )1u;
-
- ulValue = ( uint32_t )0u;
-
- if( pxPhyObject->xPhyPreferences.ucDuplex == PHY_DUPLEX_FULL )
- {
- ulValue |= phyBMCR_FULL_DUPLEX;
- }
- if( pxPhyObject->xPhyPreferences.ucSpeed == PHY_SPEED_100 )
- {
- ulValue |= phyBMCR_SPEED_100;
- }
-
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++, ulBitMask <<= 1 )
- {
- if( ( ulPhyMask & ulBitMask ) != 0lu )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- /* Enable Auto-Negotiation. */
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_00_BMCR, ulValue );
- }
- }
- return 0;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xPhyStartAutoNegotiation( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask )
-{
-uint32_t xPhyIndex, ulDoneMask, ulBitMask;
-uint32_t ulPHYLinkStatus, ulRegValue;
-TickType_t xRemainingTime;
-TimeOut_t xTimer;
-
- if( ulPhyMask == ( uint32_t )0u )
- {
- return 0;
- }
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++ )
- {
- if( ( ulPhyMask & ( 1lu << xPhyIndex ) ) != 0lu )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- /* Enable Auto-Negotiation. */
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_04_ADVERTISE, pxPhyObject->ulACRValue);
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_00_BMCR, pxPhyObject->ulBCRValue | phyBMCR_AN_RESTART );
- }
- }
-eventLogAdd( "AN start" );
- xRemainingTime = ( TickType_t ) pdMS_TO_TICKS( 3000UL );
- vTaskSetTimeOutState( &xTimer );
- ulDoneMask = 0;
- /* Wait until the auto-negotiation will be completed */
- for( ;; )
- {
- ulBitMask = ( uint32_t )1u;
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++, ulBitMask <<= 1 )
- {
- if( ( ulPhyMask & ulBitMask ) != 0lu )
- {
- if( ( ulDoneMask & ulBitMask ) == 0lu )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_01_BMSR, &ulRegValue );
- if( ( ulRegValue & phyBMSR_AN_COMPLETE ) != 0 )
- {
- ulDoneMask |= ulBitMask;
- }
- }
- }
- }
- if( ulPhyMask == ulDoneMask )
- {
- break;
- }
- if( xTaskCheckForTimeOut( &xTimer, &xRemainingTime ) != pdFALSE )
- {
- FreeRTOS_printf( ( "xPhyReset: phyBMCR_RESET timed out ( done 0x%02lX )\n", ulDoneMask ) );
- eventLogAdd( "ANtimed out");
- break;
- }
- }
-eventLogAdd( "AN done %02lX / %02lX", ulDoneMask, ulPhyMask );
-
- if( ulDoneMask != ( uint32_t)0u )
- {
- ulBitMask = ( uint32_t )1u;
- pxPhyObject->ulLinkStatusMask &= ~( ulDoneMask );
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++, ulBitMask <<= 1 )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
- uint32_t ulPhyID = pxPhyObject->ulPhyIDs[ xPhyIndex ];
-
- if( ( ulDoneMask & ulBitMask ) == ( uint32_t )0u )
- {
- continue;
- }
-
- /* Clear the 'phyBMCR_AN_RESTART' bit. */
- pxPhyObject->fnPhyWrite( xPhyAddress, phyREG_00_BMCR, pxPhyObject->ulBCRValue );
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_01_BMSR, &ulRegValue);
- if( ( ulRegValue & phyBMSR_LINK_STATUS ) != 0 )
- {
- ulPHYLinkStatus |= phyBMSR_LINK_STATUS;
- pxPhyObject->ulLinkStatusMask |= ulBitMask;
- }
- else
- {
- ulPHYLinkStatus &= ~( phyBMSR_LINK_STATUS );
- }
-
- if( xHas_1F_PHYSPCS( ulPhyID ) )
- {
- /* 31 RW PHY Special Control Status */
- uint32_t ulControlStatus;
-
- pxPhyObject->fnPhyRead( xPhyAddress, phyREG_1F_PHYSPCS, &ulControlStatus);
- ulRegValue = 0;
- if( ( ulControlStatus & phyPHYSPCS_FULL_DUPLEX ) != 0 )
- {
- ulRegValue |= phyPHYSTS_DUPLEX_STATUS;
- }
- if( ( ulControlStatus & phyPHYSPCS_SPEED_MASK ) == phyPHYSPCS_SPEED_10 )
- {
- ulRegValue |= phyPHYSTS_SPEED_STATUS;
- }
-
- }
- else
- {
- /* Read the result of the auto-negotiation. */
- pxPhyObject->fnPhyRead( xPhyAddress, PHYREG_10_PHYSTS, &ulRegValue);
- }
-
- FreeRTOS_printf( ( ">> Autonego ready: %08lx: %s duplex %u mbit %s status\n",
- ulRegValue,
- ( ulRegValue & phyPHYSTS_DUPLEX_STATUS ) ? "full" : "half",
- ( ulRegValue & phyPHYSTS_SPEED_STATUS ) ? 10 : 100,
- ( ( ulPHYLinkStatus |= phyBMSR_LINK_STATUS ) != 0) ? "high" : "low" ) );
- eventLogAdd( "%s duplex %u mbit %s st",
- ( ulRegValue & phyPHYSTS_DUPLEX_STATUS ) ? "full" : "half",
- ( ulRegValue & phyPHYSTS_SPEED_STATUS ) ? 10 : 100,
- ( ( ulPHYLinkStatus |= phyBMSR_LINK_STATUS ) != 0) ? "high" : "low" );
-{
- uint32_t regs[4];
- int i,j;
- int address = 0x10;
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < 4; j++)
- {
- pxPhyObject->fnPhyRead( xPhyAddress, address, regs + j );
- address++;
- }
- eventLogAdd("%04lX %04lX %04lX %04lX",
- regs[0], regs[1], regs[2], regs[3]);
- }
-}
- if( ( ulRegValue & phyPHYSTS_DUPLEX_STATUS ) != ( uint32_t )0u )
- {
- pxPhyObject->xPhyProperties.ucDuplex = PHY_DUPLEX_FULL;
- }
- else
- {
- pxPhyObject->xPhyProperties.ucDuplex = PHY_DUPLEX_HALF;
- }
-
- if( ( ulRegValue & phyPHYSTS_SPEED_STATUS ) != 0 )
- {
- pxPhyObject->xPhyProperties.ucSpeed = PHY_SPEED_10;
- }
- else
- {
- pxPhyObject->xPhyProperties.ucSpeed = PHY_SPEED_100;
- }
- }
- } /* if( ulDoneMask != ( uint32_t)0u ) */
-
- return 0;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xPhyCheckLinkStatus( EthernetPhy_t *pxPhyObject, BaseType_t xHadReception )
-{
-uint32_t ulStatus, ulBitMask = 1u;
-BaseType_t xPhyIndex;
-BaseType_t xNeedCheck = pdFALSE;
-
- if( xHadReception > 0 )
- {
- /* A packet was received. No need to check for the PHY status now,
- but set a timer to check it later on. */
- vTaskSetTimeOutState( &( pxPhyObject->xLinkStatusTimer ) );
- pxPhyObject->xLinkStatusRemaining = pdMS_TO_TICKS( ipconfigPHY_LS_HIGH_CHECK_TIME_MS );
- }
- else if( xTaskCheckForTimeOut( &( pxPhyObject->xLinkStatusTimer ), &( pxPhyObject->xLinkStatusRemaining ) ) != pdFALSE )
- {
- for( xPhyIndex = 0; xPhyIndex < pxPhyObject->xPortCount; xPhyIndex++, ulBitMask <<= 1 )
- {
- BaseType_t xPhyAddress = pxPhyObject->ucPhyIndexes[ xPhyIndex ];
-
- if( pxPhyObject->fnPhyRead( xPhyAddress, phyREG_01_BMSR, &ulStatus ) == 0 )
- {
- if( !!( pxPhyObject->ulLinkStatusMask & ulBitMask ) != !!( ulStatus & phyBMSR_LINK_STATUS ) )
- {
- if( ( ulStatus & phyBMSR_LINK_STATUS ) != 0 )
- {
- pxPhyObject->ulLinkStatusMask |= ulBitMask;
- }
- else
- {
- pxPhyObject->ulLinkStatusMask &= ~( ulBitMask );
- }
- FreeRTOS_printf( ( "xPhyCheckLinkStatus: PHY LS now %02lX\n", pxPhyObject->ulLinkStatusMask ) );
- eventLogAdd( "PHY LS now %02lX", pxPhyObject->ulLinkStatusMask );
- xNeedCheck = pdTRUE;
- }
- }
- }
- vTaskSetTimeOutState( &( pxPhyObject->xLinkStatusTimer ) );
- if( ( pxPhyObject->ulLinkStatusMask & phyBMSR_LINK_STATUS ) != 0 )
- {
- pxPhyObject->xLinkStatusRemaining = pdMS_TO_TICKS( ipconfigPHY_LS_HIGH_CHECK_TIME_MS );
- }
- else
- {
- pxPhyObject->xLinkStatusRemaining = pdMS_TO_TICKS( ipconfigPHY_LS_LOW_CHECK_TIME_MS );
- }
- }
- return xNeedCheck;
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c
deleted file mode 100755
index c9502fa..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* Hardware abstraction. */
-#include "FreeRTOS_IO.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "NetworkBufferManagement.h"
-
-/* Driver includes. */
-#include "lpc17xx_emac.h"
-#include "lpc17xx_pinsel.h"
-
-/* Demo includes. */
-#include "NetworkInterface.h"
-
-#if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
-#else
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
-#endif
-
-/* When a packet is ready to be sent, if it cannot be sent immediately then the
-task performing the transmit will block for niTX_BUFFER_FREE_WAIT
-milliseconds. It will do this a maximum of niMAX_TX_ATTEMPTS before giving
-up. */
-#define niTX_BUFFER_FREE_WAIT ( pdMS_TO_TICKS( 2UL ) )
-#define niMAX_TX_ATTEMPTS ( 5 )
-
-/* The length of the queue used to send interrupt status words from the
-interrupt handler to the deferred handler task. */
-#define niINTERRUPT_QUEUE_LENGTH ( 10 )
-
-/*-----------------------------------------------------------*/
-
-/*
- * A deferred interrupt handler task that processes
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*-----------------------------------------------------------*/
-
-/* The queue used to communicate Ethernet events with the IP task. */
-extern QueueHandle_t xNetworkEventQueue;
-
-/* The semaphore used to wake the deferred interrupt handler task when an Rx
-interrupt is received. */
-static SemaphoreHandle_t xEMACRxEventSemaphore = NULL;
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-EMAC_CFG_Type Emac_Config;
-PINSEL_CFG_Type xPinConfig;
-BaseType_t xStatus, xReturn;
-extern uint8_t ucMACAddress[ 6 ];
-
- /* Enable Ethernet Pins */
- boardCONFIGURE_ENET_PINS( xPinConfig );
-
- Emac_Config.Mode = EMAC_MODE_AUTO;
- Emac_Config.pbEMAC_Addr = ucMACAddress;
- xStatus = EMAC_Init( &Emac_Config );
-
- LPC_EMAC->IntEnable &= ~( EMAC_INT_TX_DONE );
-
- if( xStatus != ERROR )
- {
- vSemaphoreCreateBinary( xEMACRxEventSemaphore );
- configASSERT( xEMACRxEventSemaphore );
-
- /* The handler task is created at the highest possible priority to
- ensure the interrupt handler can return directly to it. */
- xTaskCreate( prvEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
-
- /* Enable the interrupt and set its priority to the minimum
- interrupt priority. */
- NVIC_SetPriority( ENET_IRQn, configMAC_INTERRUPT_PRIORITY );
- NVIC_EnableIRQ( ENET_IRQn );
-
- xReturn = pdPASS;
- }
- else
- {
- xReturn = pdFAIL;
- }
-
- configASSERT( xStatus != ERROR );
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-BaseType_t xReturn = pdFAIL;
-int32_t x;
-extern void EMAC_StartTransmitNextBuffer( uint32_t ulLength );
-extern void EMAC_SetNextPacketToSend( uint8_t * pucBuffer );
-
-
- /* Attempt to obtain access to a Tx buffer. */
- for( x = 0; x < niMAX_TX_ATTEMPTS; x++ )
- {
- if( EMAC_CheckTransmitIndex() == TRUE )
- {
- /* Will the data fit in the Tx buffer? */
- if( pxNetworkBuffer->xDataLength < EMAC_ETH_MAX_FLEN ) /*_RB_ The size needs to come from FreeRTOSIPConfig.h. */
- {
- /* Assign the buffer to the Tx descriptor that is now known to
- be free. */
- EMAC_SetNextPacketToSend( pxNetworkBuffer->pucBuffer );
-
- /* The EMAC now owns the buffer. */
- pxNetworkBuffer->pucBuffer = NULL;
-
- /* Initiate the Tx. */
- EMAC_StartTransmitNextBuffer( pxNetworkBuffer->xDataLength );
- iptraceNETWORK_INTERFACE_TRANSMIT();
-
- /* The Tx has been initiated. */
- xReturn = pdPASS;
- }
- break;
- }
- else
- {
- vTaskDelay( niTX_BUFFER_FREE_WAIT );
- }
- }
-
- /* Finished with the network buffer. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-void ENET_IRQHandler( void )
-{
-uint32_t ulInterruptCause;
-
- while( ( ulInterruptCause = LPC_EMAC->IntStatus ) != 0 )
- {
- /* Clear the interrupt. */
- LPC_EMAC->IntClear = ulInterruptCause;
-
- /* Clear fatal error conditions. NOTE: The driver does not clear all
- errors, only those actually experienced. For future reference, range
- errors are not actually errors so can be ignored. */
- if( ( ulInterruptCause & EMAC_INT_TX_UNDERRUN ) != 0U )
- {
- LPC_EMAC->Command |= EMAC_CR_TX_RES;
- }
-
- /* Unblock the deferred interrupt handler task if the event was an
- Rx. */
- if( ( ulInterruptCause & EMAC_INT_RX_DONE ) != 0UL )
- {
- xSemaphoreGiveFromISR( xEMACRxEventSemaphore, NULL );
- }
- }
-
- /* ulInterruptCause is used for convenience here. A context switch is
- wanted, but coding portEND_SWITCHING_ISR( 1 ) would likely result in a
- compiler warning. */
- portEND_SWITCHING_ISR( ulInterruptCause );
-}
-/*-----------------------------------------------------------*/
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-size_t xDataLength;
-const uint16_t usCRCLength = 4;
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-
-/* This is not included in the header file for some reason. */
-extern uint8_t *EMAC_NextPacketToRead( void );
-
- ( void ) pvParameters;
- configASSERT( xEMACRxEventSemaphore );
-
- for( ;; )
- {
- /* Wait for the EMAC interrupt to indicate that another packet has been
- received. The while() loop is only needed if INCLUDE_vTaskSuspend is
- set to 0 in FreeRTOSConfig.h. */
- while( xSemaphoreTake( xEMACRxEventSemaphore, portMAX_DELAY ) == pdFALSE );
-
- /* At least one packet has been received. */
- while( EMAC_CheckReceiveIndex() != FALSE )
- {
- /* Obtain the length, minus the CRC. The CRC is four bytes
- but the length is already minus 1. */
- xDataLength = ( size_t ) EMAC_GetReceiveDataSize() - ( usCRCLength - 1U );
-
- if( xDataLength > 0U )
- {
- /* Obtain a network buffer to pass this data into the
- stack. No storage is required as the network buffer
- will point directly to the buffer that already holds
- the received data. */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( 0, ( TickType_t ) 0 );
-
- if( pxNetworkBuffer != NULL )
- {
- pxNetworkBuffer->pucBuffer = EMAC_NextPacketToRead();
- pxNetworkBuffer->xDataLength = xDataLength;
- xRxEvent.pvData = ( void * ) pxNetworkBuffer;
-
- /* Data was received and stored. Send a message to the IP
- task to let it know. */
- if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 0 ) == pdFAIL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- iptraceETHERNET_RX_EVENT_LOST();
- }
- }
- else
- {
- iptraceETHERNET_RX_EVENT_LOST();
- }
-
- iptraceNETWORK_INTERFACE_RECEIVE();
- }
-
- /* Release the frame. */
- EMAC_UpdateRxConsumeIndex();
- }
- }
-}
-/*-----------------------------------------------------------*/
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c
deleted file mode 100755
index 3605513..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c
+++ /dev/null
@@ -1,1069 +0,0 @@
-/*
- * FreeRTOS+TCP V2.0.3
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-
-/* LPCOpen includes. */
-#include "chip.h"
-#include "lpc_phy.h"
-
-/* The size of the stack allocated to the task that handles Rx packets. */
-#define nwRX_TASK_STACK_SIZE 140
-
-#ifndef PHY_LS_HIGH_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still high after 15 seconds of not
- receiving packets. */
- #define PHY_LS_HIGH_CHECK_TIME_MS 15000
-#endif
-
-#ifndef PHY_LS_LOW_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still low every second. */
- #define PHY_LS_LOW_CHECK_TIME_MS 1000
-#endif
-
-#ifndef configUSE_RMII
- #define configUSE_RMII 1
-#endif
-
-#ifndef configNUM_RX_DESCRIPTORS
- #error please define configNUM_RX_DESCRIPTORS in your FreeRTOSIPConfig.h
-#endif
-
-#ifndef configNUM_TX_DESCRIPTORS
- #error please define configNUM_TX_DESCRIPTORS in your FreeRTOSIPConfig.h
-#endif
-
-#ifndef NETWORK_IRQHandler
- #error NETWORK_IRQHandler must be defined to the name of the function that is installed in the interrupt vector table to handle Ethernet interrupts.
-#endif
-
-#if !defined( MAC_FF_HMC )
- /* Hash for multicast. */
- #define MAC_FF_HMC ( 1UL << 2UL )
-#endif
-
-#ifndef iptraceEMAC_TASK_STARTING
- #define iptraceEMAC_TASK_STARTING() do { } while( 0 )
-#endif
-
-/* Define the bits of .STATUS that indicate a reception error. */
-#define nwRX_STATUS_ERROR_BITS \
- ( RDES_CE /* CRC Error */ | \
- RDES_RE /* Receive Error */ | \
- RDES_DE /* Descriptor Error */ | \
- RDES_RWT /* Receive Watchdog Timeout */ | \
- RDES_LC /* Late Collision */ | \
- RDES_OE /* Overflow Error */ | \
- RDES_SAF /* Source Address Filter Fail */ | \
- RDES_AFM /* Destination Address Filter Fail */ | \
- RDES_LE /* Length Error */ )
-
-/* Define the EMAC status bits that should trigger an interrupt. */
-#define nwDMA_INTERRUPT_MASK \
- ( DMA_IE_TIE /* Transmit interrupt enable */ | \
- DMA_IE_TSE /* Transmit stopped enable */ | \
- DMA_IE_OVE /* Overflow interrupt enable */ | \
- DMA_IE_RIE /* Receive interrupt enable */ | \
- DMA_IE_NIE /* Normal interrupt summary enable */ | \
- DMA_IE_AIE /* Abnormal interrupt summary enable */ | \
- DMA_IE_RUE /* Receive buffer unavailable enable */ | \
- DMA_IE_UNE /* Underflow interrupt enable. */ | \
- DMA_IE_TJE /* Transmit jabber timeout enable */ | \
- DMA_IE_RSE /* Received stopped enable */ | \
- DMA_IE_RWE /* Receive watchdog timeout enable */ | \
- DMA_IE_FBE )/* Fatal bus error enable */
-
-/* Interrupt events to process. Currently only the RX/TX events are processed
-although code for other events is included to allow for possible future
-expansion. */
-#define EMAC_IF_RX_EVENT 1UL
-#define EMAC_IF_TX_EVENT 2UL
-#define EMAC_IF_ERR_EVENT 4UL
-#define EMAC_IF_ALL_EVENT ( EMAC_IF_RX_EVENT | EMAC_IF_TX_EVENT | EMAC_IF_ERR_EVENT )
-
- /* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet
- driver will filter incoming packets and only pass the stack those packets it
- considers need processing. */
- #if( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 )
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
- #else
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
- #endif
-
-#if( ipconfigZERO_COPY_RX_DRIVER == 0 ) || ( ipconfigZERO_COPY_TX_DRIVER == 0 )
- #warning It is adviced to enable both macros
-#endif
-
-#ifndef configPLACE_IN_SECTION_RAM
- #define configPLACE_IN_SECTION_RAM
-/*
- #define configPLACE_IN_SECTION_RAM __attribute__ ((section(".ramfunc")))
-*/
-#endif
-
-/*-----------------------------------------------------------*/
-
-/*
- * Delay function passed into the library. The implementation uses FreeRTOS
- * calls so the scheduler must be started before the driver can be used.
- */
-static void prvDelay( uint32_t ulMilliSeconds );
-
-/*
- * Initialises the Tx and Rx descriptors respectively.
- */
-static void prvSetupTxDescriptors( void );
-static void prvSetupRxDescriptors( void );
-
-/*
- * A task that processes received frames.
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*
- * Sets up the MAC with the results of an auto-negotiation.
- */
-static BaseType_t prvSetLinkSpeed( void );
-
-/*
- * Generates a CRC for a MAC address that is then used to generate a hash index.
- */
-static uint32_t prvGenerateCRC32( const uint8_t *ucAddress );
-
-/*
- * Generates a hash index when setting a filter to permit a MAC address.
- */
-static uint32_t prvGetHashIndex( const uint8_t *ucAddress );
-
-/*
- * Update the hash table to allow a MAC address.
- */
-static void prvAddMACAddress( const uint8_t* ucMacAddress );
-
-/*
- * Sometimes the DMA will report received data as being longer than the actual
- * received from length. This function checks the reported length and corrects
- * if if necessary.
- */
-static void prvRemoveTrailingBytes( NetworkBufferDescriptor_t *pxDescriptor );
-
-/*-----------------------------------------------------------*/
-
-/* Bit map of outstanding ETH interrupt events for processing. Currently only
-the Rx and Tx interrupt is handled, although code is included for other events
-to enable future expansion. */
-static volatile uint32_t ulISREvents;
-
-/* A copy of PHY register 1: 'PHY_REG_01_BMSR' */
-static uint32_t ulPHYLinkStatus = 0;
-
-/* Tx descriptors and index. */
-static ENET_ENHTXDESC_T xDMATxDescriptors[ configNUM_TX_DESCRIPTORS ];
-
-/* ulNextFreeTxDescriptor is declared volatile, because it is accessed from
-to different tasks. */
-static volatile uint32_t ulNextFreeTxDescriptor;
-static uint32_t ulTxDescriptorToClear;
-
-/* Rx descriptors and index. */
-static ENET_ENHRXDESC_T xDMARxDescriptors[ configNUM_RX_DESCRIPTORS ];
-static uint32_t ulNextRxDescriptorToProcess;
-
-/* Must be defined externally - the demo applications define this in main.c. */
-extern uint8_t ucMACAddress[ 6 ];
-
-/* The handle of the task that processes Rx packets. The handle is required so
-the task can be notified when new packets arrive. */
-static TaskHandle_t xRxHanderTask = NULL;
-
-#if( ipconfigUSE_LLMNR == 1 )
- static const uint8_t xLLMNR_MACAddress[] = { '\x01', '\x00', '\x5E', '\x00', '\x00', '\xFC' };
-#endif /* ipconfigUSE_LLMNR == 1 */
-
-/* xTXDescriptorSemaphore is a counting semaphore with
-a maximum count of ETH_TXBUFNB, which is the number of
-DMA TX descriptors. */
-static SemaphoreHandle_t xTXDescriptorSemaphore = NULL;
-
-/*-----------------------------------------------------------*/
-
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-BaseType_t xReturn = pdPASS;
-static BaseType_t xHasInitialised = pdFALSE;
-
- if( xHasInitialised == pdFALSE )
- {
- xHasInitialised = pdTRUE;
-
- /* The interrupt will be turned on when a link is established. */
- NVIC_DisableIRQ( ETHERNET_IRQn );
-
- /* Disable receive and transmit DMA processes. */
- LPC_ETHERNET->DMA_OP_MODE &= ~( DMA_OM_ST | DMA_OM_SR );
-
- /* Disable packet reception. */
- LPC_ETHERNET->MAC_CONFIG &= ~( MAC_CFG_RE | MAC_CFG_TE );
-
- /* Call the LPCOpen function to initialise the hardware. */
- Chip_ENET_Init( LPC_ETHERNET );
-
- /* Save MAC address. */
- Chip_ENET_SetADDR( LPC_ETHERNET, ucMACAddress );
-
- /* Clear all MAC address hash entries. */
- LPC_ETHERNET->MAC_HASHTABLE_HIGH = 0;
- LPC_ETHERNET->MAC_HASHTABLE_LOW = 0;
-
- #if( ipconfigUSE_LLMNR == 1 )
- {
- prvAddMACAddress( xLLMNR_MACAddress );
- }
- #endif /* ipconfigUSE_LLMNR == 1 */
-
- /* Promiscuous flag (PR) and Receive All flag (RA) set to zero. The
- registers MAC_HASHTABLE_[LOW|HIGH] will be loaded to allow certain
- multi-cast addresses. */
- LPC_ETHERNET->MAC_FRAME_FILTER = MAC_FF_HMC;
-
- #if( configUSE_RMII == 1 )
- {
- if( lpc_phy_init( pdTRUE, prvDelay ) != SUCCESS )
- {
- xReturn = pdFAIL;
- }
- }
- #else
- {
- #warning This path has not been tested.
- if( lpc_phy_init( pdFALSE, prvDelay ) != SUCCESS )
- {
- xReturn = pdFAIL;
- }
- }
- #endif
-
- if( xReturn == pdPASS )
- {
- if( xTXDescriptorSemaphore == NULL )
- {
- /* Create a counting semaphore, with a value of 'configNUM_TX_DESCRIPTORS'
- and a maximum of 'configNUM_TX_DESCRIPTORS'. */
- xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) configNUM_TX_DESCRIPTORS, ( UBaseType_t ) configNUM_TX_DESCRIPTORS );
- configASSERT( xTXDescriptorSemaphore );
- }
-
- /* Enable MAC interrupts. */
- LPC_ETHERNET->DMA_INT_EN = nwDMA_INTERRUPT_MASK;
-
- /* Auto-negotiate was already started. Wait for it to complete. */
- xReturn = prvSetLinkSpeed();
-
- if( xReturn == pdPASS )
- {
- /* Initialise the descriptors. */
- prvSetupTxDescriptors();
- prvSetupRxDescriptors();
-
- /* Clear all interrupts. */
- LPC_ETHERNET->DMA_STAT = DMA_ST_ALL;
-
- /* Enable receive and transmit DMA processes. */
- LPC_ETHERNET->DMA_OP_MODE |= DMA_OM_ST | DMA_OM_SR;
-
- /* Set Receiver / Transmitter Enable. */
- LPC_ETHERNET->MAC_CONFIG |= MAC_CFG_RE | MAC_CFG_TE;
-
- /* Start receive polling. */
- LPC_ETHERNET->DMA_REC_POLL_DEMAND = 1;
-
- /* Enable interrupts in the NVIC. */
- NVIC_SetPriority( ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY );
- NVIC_EnableIRQ( ETHERNET_IRQn );
- }
- /* Guard against the task being created more than once and the
- descriptors being initialised more than once. */
- if( xRxHanderTask == NULL )
- {
- xReturn = xTaskCreate( prvEMACHandlerTask, "EMAC", nwRX_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xRxHanderTask );
- configASSERT( xReturn );
- }
- }
- }
-
- /* Once prvEMACHandlerTask() has started, the variable
- 'ulPHYLinkStatus' will be updated by that task.
- The IP-task will keep on calling this function untill
- it finally returns pdPASS.
- Only then can the DHCP-procedure start (if configured). */
- if( ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) != 0 )
- {
- xReturn = pdPASS;
- }
- else
- {
- xReturn = pdFAIL;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-#define niBUFFER_1_PACKET_SIZE 1536
-
-static __attribute__ ((section("._ramAHB32"))) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__ ( ( aligned( 32 ) ) );
-
-void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
-{
-
-uint8_t *ucRAMBuffer = ucNetworkPackets;
-uint32_t ul;
-
- for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ )
- {
- pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING;
- *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
- ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
- }
-}
-/*-----------------------------------------------------------*/
-
-configPLACE_IN_SECTION_RAM
-static void vClearTXBuffers()
-{
-uint32_t ulLastDescriptor = ulNextFreeTxDescriptor;
-size_t uxCount = ( ( size_t ) configNUM_TX_DESCRIPTORS ) - uxSemaphoreGetCount( xTXDescriptorSemaphore );
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNetworkBuffer;
- uint8_t *ucPayLoad;
-#endif
-
- /* This function is called after a TX-completion interrupt.
- It will release each Network Buffer used in xNetworkInterfaceOutput().
- 'uxCount' represents the number of descriptors given to DMA for transmission.
- After sending a packet, the DMA will clear the 'TDES_OWN' bit. */
- while( ( uxCount > ( size_t ) 0u ) && ( ( xDMATxDescriptors[ ulTxDescriptorToClear ].CTRLSTAT & TDES_OWN ) == 0 ) )
- {
- if( ( ulTxDescriptorToClear == ulLastDescriptor ) && ( uxCount != ( size_t ) configNUM_TX_DESCRIPTORS ) )
- {
- break;
- }
-
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- ucPayLoad = ( uint8_t * )xDMATxDescriptors[ ulTxDescriptorToClear ].B1ADD;
- if( ucPayLoad != NULL )
- {
- /* B1ADD points to a pucEthernetBuffer of a Network Buffer descriptor. */
- pxNetworkBuffer = pxPacketBuffer_to_NetworkBuffer( ucPayLoad );
-
- configASSERT( pxNetworkBuffer != NULL );
-
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ) ;
- xDMATxDescriptors[ ulTxDescriptorToClear ].B1ADD = ( uint32_t )0u;
- }
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- /* Move onto the next descriptor, wrapping if necessary. */
- ulTxDescriptorToClear++;
- if( ulTxDescriptorToClear >= configNUM_TX_DESCRIPTORS )
- {
- ulTxDescriptorToClear = 0;
- }
-
- uxCount--;
- /* Tell the counting semaphore that one more TX descriptor is available. */
- xSemaphoreGive( xTXDescriptorSemaphore );
- }
-}
-
-/*-----------------------------------------------------------*/
-
-configPLACE_IN_SECTION_RAM
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t bReleaseAfterSend )
-{
-BaseType_t xReturn = pdFAIL;
-const TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 50 );
-
- /* Attempt to obtain access to a Tx descriptor. */
- do
- {
- if( xTXDescriptorSemaphore == NULL )
- {
- break;
- }
- if( xSemaphoreTake( xTXDescriptorSemaphore, xBlockTimeTicks ) != pdPASS )
- {
- /* Time-out waiting for a free TX descriptor. */
- break;
- }
-
- /* If the descriptor is still owned by the DMA it can't be used. */
- if( ( xDMATxDescriptors[ ulNextFreeTxDescriptor ].CTRLSTAT & TDES_OWN ) != 0 )
- {
- /* The semaphore was taken, the TX DMA-descriptor is still not available.
- Actually that should not occur, the 'TDES_OWN' was already confirmed low in vClearTXBuffers(). */
- xSemaphoreGive( xTXDescriptorSemaphore );
- }
- else
- {
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* bReleaseAfterSend should always be set when using the zero
- copy driver. */
- configASSERT( bReleaseAfterSend != pdFALSE );
-
- /* The DMA's descriptor to point directly to the data in the
- network buffer descriptor. The data is not copied. */
- xDMATxDescriptors[ ulNextFreeTxDescriptor ].B1ADD = ( uint32_t ) pxDescriptor->pucEthernetBuffer;
-
- /* The DMA descriptor will 'own' this Network Buffer,
- until it has been sent. So don't release it now. */
- bReleaseAfterSend = pdFALSE;
- }
- #else
- {
- /* The data is copied from the network buffer descriptor into
- the DMA's descriptor. */
- memcpy( ( void * ) xDMATxDescriptors[ ulNextFreeTxDescriptor ].B1ADD, ( void * ) pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength );
- }
- #endif
-
- xDMATxDescriptors[ ulNextFreeTxDescriptor ].BSIZE = ( uint32_t ) TDES_ENH_BS1( pxDescriptor->xDataLength );
-
- /* This descriptor is given back to the DMA. */
- xDMATxDescriptors[ ulNextFreeTxDescriptor ].CTRLSTAT |= TDES_OWN;
-
- /* Ensure the DMA is polling Tx descriptors. */
- LPC_ETHERNET->DMA_TRANS_POLL_DEMAND = 1;
-
- iptraceNETWORK_INTERFACE_TRANSMIT();
-
- /* Move onto the next descriptor, wrapping if necessary. */
- ulNextFreeTxDescriptor++;
- if( ulNextFreeTxDescriptor >= configNUM_TX_DESCRIPTORS )
- {
- ulNextFreeTxDescriptor = 0;
- }
-
- /* The Tx has been initiated. */
- xReturn = pdPASS;
- }
- } while( 0 );
-
- /* The buffer has been sent so can be released. */
- if( bReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void prvDelay( uint32_t ulMilliSeconds )
-{
- /* Ensure the scheduler was started before attempting to use the scheduler to
- create a delay. */
- configASSERT( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING );
-
- vTaskDelay( pdMS_TO_TICKS( ulMilliSeconds ) );
-}
-/*-----------------------------------------------------------*/
-
-static void prvSetupTxDescriptors( void )
-{
-BaseType_t x;
-
- /* Start with Tx descriptors clear. */
- memset( ( void * ) xDMATxDescriptors, 0, sizeof( xDMATxDescriptors ) );
-
- /* Index to the next Tx descriptor to use. */
- ulNextFreeTxDescriptor = 0ul;
-
- /* Index to the next Tx descriptor to clear ( after transmission ). */
- ulTxDescriptorToClear = 0ul;
-
- for( x = 0; x < configNUM_TX_DESCRIPTORS; x++ )
- {
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* Nothing to do, B1ADD will be set when data is ready to transmit.
- Currently the memset above will have set it to NULL. */
- }
- #else
- {
- /* Allocate a buffer to the Tx descriptor. This is the most basic
- way of creating a driver as the data is then copied into the
- buffer. */
- xDMATxDescriptors[ x ].B1ADD = ( uint32_t ) pvPortMalloc( ipTOTAL_ETHERNET_FRAME_SIZE );
-
- /* Use an assert to check the allocation as +TCP applications will
- often not use a malloc() failed hook as the TCP stack will recover
- from allocation failures. */
- configASSERT( xDMATxDescriptors[ x ].B1ADD );
- }
- #endif
-
- /* Buffers hold an entire frame so all buffers are both the start and
- end of a frame. */
- /* TDES_ENH_TCH Second Address Chained. */
- /* TDES_ENH_CIC(n) Checksum Insertion Control, tried but it does not work for the LPC18xx... */
- /* TDES_ENH_FS First Segment. */
- /* TDES_ENH_LS Last Segment. */
- /* TDES_ENH_IC Interrupt on Completion. */
- xDMATxDescriptors[ x ].CTRLSTAT = TDES_ENH_TCH | TDES_ENH_CIC( 3 ) | TDES_ENH_FS | TDES_ENH_LS | TDES_ENH_IC;
- xDMATxDescriptors[ x ].B2ADD = ( uint32_t ) &xDMATxDescriptors[ x + 1 ];
- }
-
- xDMATxDescriptors[ configNUM_TX_DESCRIPTORS - 1 ].CTRLSTAT |= TDES_ENH_TER;
- xDMATxDescriptors[ configNUM_TX_DESCRIPTORS - 1 ].B2ADD = ( uint32_t ) &xDMATxDescriptors[ 0 ];
-
- /* Point the DMA to the base of the descriptor list. */
- LPC_ETHERNET->DMA_TRANS_DES_ADDR = ( uint32_t ) xDMATxDescriptors;
-}
-/*-----------------------------------------------------------*/
-
-static void prvSetupRxDescriptors( void )
-{
-BaseType_t x;
-#if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNetworkBuffer;
-#endif
-
- /* Index to the next Rx descriptor to use. */
- ulNextRxDescriptorToProcess = 0;
-
- /* Clear RX descriptor list. */
- memset( ( void * ) xDMARxDescriptors, 0, sizeof( xDMARxDescriptors ) );
-
- for( x = 0; x < configNUM_RX_DESCRIPTORS; x++ )
- {
- /* Allocate a buffer of the largest possible frame size as it is not
- known what size received frames will be. */
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, 0 );
-
- /* During start-up there should be enough Network Buffers available,
- so it is safe to use configASSERT().
- In case this assert fails, please check: configNUM_RX_DESCRIPTORS,
- ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, and in case BufferAllocation_2.c
- is included, check the amount of available heap. */
- configASSERT( pxNetworkBuffer != NULL );
-
- /* Pass the actual buffer to DMA. */
- xDMARxDescriptors[ x ].B1ADD = ( uint32_t ) pxNetworkBuffer->pucEthernetBuffer;
- }
- #else
- {
- /* All DMA descriptors are populated with permanent memory blocks.
- Their contents will be copy to Network Buffers. */
- xDMARxDescriptors[ x ].B1ADD = ( uint32_t ) pvPortMalloc( ipTOTAL_ETHERNET_FRAME_SIZE );
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- /* Use an assert to check the allocation as +TCP applications will often
- not use a malloc failed hook as the TCP stack will recover from
- allocation failures. */
- configASSERT( xDMARxDescriptors[ x ].B1ADD );
-
- xDMARxDescriptors[ x ].B2ADD = ( uint32_t ) &( xDMARxDescriptors[ x + 1 ] );
- xDMARxDescriptors[ x ].CTRL = ( uint32_t ) RDES_ENH_BS1( ipTOTAL_ETHERNET_FRAME_SIZE ) | RDES_ENH_RCH;
-
- /* The descriptor is available for use by the DMA. */
- xDMARxDescriptors[ x ].STATUS = RDES_OWN;
- }
-
- /* RDES_ENH_RER Receive End of Ring. */
- xDMARxDescriptors[ ( configNUM_RX_DESCRIPTORS - 1 ) ].CTRL |= RDES_ENH_RER;
- xDMARxDescriptors[ configNUM_RX_DESCRIPTORS - 1 ].B2ADD = ( uint32_t ) &( xDMARxDescriptors[ 0 ] );
-
- /* Point the DMA to the base of the descriptor list. */
- LPC_ETHERNET->DMA_REC_DES_ADDR = ( uint32_t ) xDMARxDescriptors;
-}
-/*-----------------------------------------------------------*/
-configPLACE_IN_SECTION_RAM
-static void prvRemoveTrailingBytes( NetworkBufferDescriptor_t *pxDescriptor )
-{
-size_t xExpectedLength;
-IPPacket_t *pxIPPacket;
-
- pxIPPacket = ( IPPacket_t * ) pxDescriptor->pucEthernetBuffer;
- /* Look at the actual length of the packet, translate it to a host-endial notation. */
- xExpectedLength = sizeof( EthernetHeader_t ) + ( size_t ) FreeRTOS_htons( pxIPPacket->xIPHeader.usLength );
-
- if( xExpectedLength == ( pxDescriptor->xDataLength + 4 ) )
- {
- pxDescriptor->xDataLength -= 4;
- }
- else
- {
- if( pxDescriptor->xDataLength > xExpectedLength )
- {
- pxDescriptor->xDataLength = ( size_t ) xExpectedLength;
- }
- }
-}
-/*-----------------------------------------------------------*/
-configPLACE_IN_SECTION_RAM
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xReturn;
-
- if( ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) == 0 )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-configPLACE_IN_SECTION_RAM
-static BaseType_t prvNetworkInterfaceInput()
-{
-BaseType_t xResult = pdFALSE;
-uint32_t ulStatus;
-eFrameProcessingResult_t eResult;
-const TickType_t xDescriptorWaitTime = pdMS_TO_TICKS( 250 );
-const UBaseType_t uxMinimumBuffersRemaining = 3UL;
-uint16_t usLength;
-NetworkBufferDescriptor_t *pxDescriptor;
-#if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNewDescriptor;
-#endif /* ipconfigZERO_COPY_RX_DRIVER */
-IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-
- /* Process each descriptor that is not still in use by the DMA. */
- ulStatus = xDMARxDescriptors[ ulNextRxDescriptorToProcess ].STATUS;
- if( ( ulStatus & RDES_OWN ) == 0 )
- {
- /* Check packet for errors */
- if( ( ulStatus & nwRX_STATUS_ERROR_BITS ) != 0 )
- {
- /* There is some reception error. */
- /* Clear error bits. */
- ulStatus &= ~( ( uint32_t )nwRX_STATUS_ERROR_BITS );
- }
- else
- {
- xResult++;
-
- eResult = ipCONSIDER_FRAME_FOR_PROCESSING( ( const uint8_t * const ) ( xDMARxDescriptors[ ulNextRxDescriptorToProcess ].B1ADD ) );
- if( eResult == eProcessBuffer )
- {
- if( ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) == 0 )
- {
- ulPHYLinkStatus |= PHY_LINK_CONNECTED;
- FreeRTOS_printf( ( "prvEMACHandlerTask: PHY LS now %d (message received)\n", ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) != 0 ) );
- }
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- if( uxGetNumberOfFreeNetworkBuffers() > uxMinimumBuffersRemaining )
- {
- pxNewDescriptor = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, xDescriptorWaitTime );
- }
- else
- {
- /* Too risky to allocate a new Network Buffer. */
- pxNewDescriptor = NULL;
- }
- if( pxNewDescriptor != NULL )
- #else
- if( uxGetNumberOfFreeNetworkBuffers() > uxMinimumBuffersRemaining )
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
- {
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- const uint8_t *pucBuffer;
- #endif
-
- /* Get the actual length. */
- usLength = RDES_FLMSK( ulStatus );
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Replace the character buffer 'B1ADD'. */
- pucBuffer = ( const uint8_t * const ) ( xDMARxDescriptors[ ulNextRxDescriptorToProcess ].B1ADD );
- xDMARxDescriptors[ ulNextRxDescriptorToProcess ].B1ADD = ( uint32_t ) pxNewDescriptor->pucEthernetBuffer;
-
- /* 'B1ADD' contained the address of a 'pucEthernetBuffer' that
- belongs to a Network Buffer. Find the original Network Buffer. */
- pxDescriptor = pxPacketBuffer_to_NetworkBuffer( pucBuffer );
- /* This zero-copy driver makes sure that every 'xDMARxDescriptors' contains
- a reference to a Network Buffer at any time.
- In case it runs out of Network Buffers, a DMA buffer won't be replaced,
- and the received messages is dropped. */
- configASSERT( pxDescriptor != NULL );
- }
- #else
- {
- /* Create a buffer of exactly the required length. */
- pxDescriptor = pxGetNetworkBufferWithDescriptor( usLength, xDescriptorWaitTime );
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- if( pxDescriptor != NULL )
- {
- pxDescriptor->xDataLength = ( size_t ) usLength;
- #if( ipconfigZERO_COPY_RX_DRIVER == 0 )
- {
- /* Copy the data into the allocated buffer. */
- memcpy( ( void * ) pxDescriptor->pucEthernetBuffer, ( void * ) xDMARxDescriptors[ ulNextRxDescriptorToProcess ].B1ADD, usLength );
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
- /* It is possible that more data was copied than
- actually makes up the frame. If this is the case
- adjust the length to remove any trailing bytes. */
- prvRemoveTrailingBytes( pxDescriptor );
-
- /* Pass the data to the TCP/IP task for processing. */
- xRxEvent.pvData = ( void * ) pxDescriptor;
- if( xSendEventStructToIPTask( &xRxEvent, xDescriptorWaitTime ) == pdFALSE )
- {
- /* Could not send the descriptor into the TCP/IP
- stack, it must be released. */
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
- else
- {
- iptraceNETWORK_INTERFACE_RECEIVE();
- }
- }
- }
- }
- /* Got here because received data was sent to the IP task or the
- data contained an error and was discarded. Give the descriptor
- back to the DMA. */
- xDMARxDescriptors[ ulNextRxDescriptorToProcess ].STATUS = ulStatus | RDES_OWN;
-
- /* Move onto the next descriptor. */
- ulNextRxDescriptorToProcess++;
- if( ulNextRxDescriptorToProcess >= configNUM_RX_DESCRIPTORS )
- {
- ulNextRxDescriptorToProcess = 0;
- }
-
- ulStatus = xDMARxDescriptors[ ulNextRxDescriptorToProcess ].STATUS;
- } /* if( ( ulStatus & nwRX_STATUS_ERROR_BITS ) != 0 ) */
- } /* if( ( ulStatus & RDES_OWN ) == 0 ) */
-
- /* Restart receive polling. */
- LPC_ETHERNET->DMA_REC_POLL_DEMAND = 1;
-
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-configPLACE_IN_SECTION_RAM
-void NETWORK_IRQHandler( void )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-uint32_t ulDMAStatus;
-const uint32_t ulRxInterruptMask =
- DMA_ST_RI | /* Receive interrupt */
- DMA_ST_RU; /* Receive buffer unavailable */
-const uint32_t ulTxInterruptMask =
- DMA_ST_TI | /* Transmit interrupt */
- DMA_ST_TPS; /* Transmit process stopped */
-
- configASSERT( xRxHanderTask );
-
- /* Get pending interrupts. */
- ulDMAStatus = LPC_ETHERNET->DMA_STAT;
-
- /* RX group interrupt(s). */
- if( ( ulDMAStatus & ulRxInterruptMask ) != 0x00 )
- {
- /* Remember that an RX event has happened. */
- ulISREvents |= EMAC_IF_RX_EVENT;
- vTaskNotifyGiveFromISR( xRxHanderTask, &xHigherPriorityTaskWoken );
- }
-
- /* TX group interrupt(s). */
- if( ( ulDMAStatus & ulTxInterruptMask ) != 0x00 )
- {
- /* Remember that a TX event has happened. */
- ulISREvents |= EMAC_IF_TX_EVENT;
- vTaskNotifyGiveFromISR( xRxHanderTask, &xHigherPriorityTaskWoken );
- }
-
- /* Test for 'Abnormal interrupt summary'. */
- if( ( ulDMAStatus & DMA_ST_AIE ) != 0x00 )
- {
- /* The trace macro must be written such that it can be called from
- an interrupt. */
- iptraceETHERNET_RX_EVENT_LOST();
- }
-
- /* Clear pending interrupts */
- LPC_ETHERNET->DMA_STAT = ulDMAStatus;
-
- /* Context switch needed? */
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvSetLinkSpeed( void )
-{
-BaseType_t xReturn = pdFAIL;
-TickType_t xTimeOnEntering;
-uint32_t ulPhyStatus;
-const TickType_t xAutoNegotiateDelay = pdMS_TO_TICKS( 5000UL );
-
- /* Ensure polling does not starve lower priority tasks by temporarily
- setting the priority of this task to that of the idle task. */
- vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
-
- xTimeOnEntering = xTaskGetTickCount();
- do
- {
- ulPhyStatus = lpcPHYStsPoll();
- if( ( ulPhyStatus & PHY_LINK_CONNECTED ) != 0x00 )
- {
- /* Set interface speed and duplex. */
- if( ( ulPhyStatus & PHY_LINK_SPEED100 ) != 0x00 )
- {
- Chip_ENET_SetSpeed( LPC_ETHERNET, 1 );
- }
- else
- {
- Chip_ENET_SetSpeed( LPC_ETHERNET, 0 );
- }
-
- if( ( ulPhyStatus & PHY_LINK_FULLDUPLX ) != 0x00 )
- {
- Chip_ENET_SetDuplex( LPC_ETHERNET, pdTRUE );
- }
- else
- {
- Chip_ENET_SetDuplex( LPC_ETHERNET, pdFALSE );
- }
-
- xReturn = pdPASS;
- break;
- }
- } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xAutoNegotiateDelay );
-
- /* Reset the priority of this task back to its original value. */
- vTaskPrioritySet( NULL, ipconfigIP_TASK_PRIORITY );
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static uint32_t prvGenerateCRC32( const uint8_t *ucAddress )
-{
-unsigned int j;
-const uint32_t Polynomial = 0xEDB88320;
-uint32_t crc = ~0ul;
-const uint8_t *pucCurrent = ( const uint8_t * ) ucAddress;
-const uint8_t *pucLast = pucCurrent + 6;
-
- /* Calculate normal CRC32 */
- while( pucCurrent < pucLast )
- {
- crc ^= *( pucCurrent++ );
- for( j = 0; j < 8; j++ )
- {
- if( ( crc & 1 ) != 0 )
- {
- crc = (crc >> 1) ^ Polynomial;
- }
- else
- {
- crc >>= 1;
- }
- }
- }
- return ~crc;
-}
-/*-----------------------------------------------------------*/
-
-static uint32_t prvGetHashIndex( const uint8_t *ucAddress )
-{
-uint32_t ulCrc = prvGenerateCRC32( ucAddress );
-uint32_t ulIndex = 0ul;
-BaseType_t xCount = 6;
-
- /* Take the lowest 6 bits of the CRC32 and reverse them */
- while( xCount-- )
- {
- ulIndex <<= 1;
- ulIndex |= ( ulCrc & 1 );
- ulCrc >>= 1;
- }
-
- /* This is the has value of 'ucAddress' */
- return ulIndex;
-}
-/*-----------------------------------------------------------*/
-
-static void prvAddMACAddress( const uint8_t* ucMacAddress )
-{
-BaseType_t xIndex;
-
- xIndex = prvGetHashIndex( ucMacAddress );
- if( xIndex >= 32 )
- {
- LPC_ETHERNET->MAC_HASHTABLE_HIGH |= ( 1u << ( xIndex - 32 ) );
- }
- else
- {
- LPC_ETHERNET->MAC_HASHTABLE_LOW |= ( 1u << xIndex );
- }
-}
-/*-----------------------------------------------------------*/
-
-configPLACE_IN_SECTION_RAM
-static void prvEMACHandlerTask( void *pvParameters )
-{
-TimeOut_t xPhyTime;
-TickType_t xPhyRemTime;
-UBaseType_t uxLastMinBufferCount = 0;
-UBaseType_t uxCurrentCount;
-BaseType_t xResult = 0;
-uint32_t ulStatus;
-const TickType_t xBlockTime = pdMS_TO_TICKS( 5000ul );
-
- /* Remove compiler warning about unused parameter. */
- ( void ) pvParameters;
-
- /* A possibility to set some additional task properties. */
- iptraceEMAC_TASK_STARTING();
-
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
-
- for( ;; )
- {
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- static UBaseType_t uxLastMinQueueSpace = 0;
-
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- ulTaskNotifyTake( pdTRUE, xBlockTime );
-
- xResult = ( BaseType_t ) 0;
-
- if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0 )
- {
- /* Code to release TX buffers if zero-copy is used. */
- ulISREvents &= ~EMAC_IF_TX_EVENT;
- {
- /* Check if DMA packets have been delivered. */
- vClearTXBuffers();
- }
- }
-
- if( ( ulISREvents & EMAC_IF_RX_EVENT ) != 0 )
- {
- ulISREvents &= ~EMAC_IF_RX_EVENT;
-
- xResult = prvNetworkInterfaceInput();
- if( xResult > 0 )
- {
- while( prvNetworkInterfaceInput() > 0 )
- {
- }
- }
- }
-
- if( xResult > 0 )
- {
- /* A packet was received. No need to check for the PHY status now,
- but set a timer to check it later on. */
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- xResult = 0;
- }
- else if( xTaskCheckForTimeOut( &xPhyTime, &xPhyRemTime ) != pdFALSE )
- {
- ulStatus = lpcPHYStsPoll();
-
- if( ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) != ( ulStatus & PHY_LINK_CONNECTED ) )
- {
- ulPHYLinkStatus = ulStatus;
- FreeRTOS_printf( ( "prvEMACHandlerTask: PHY LS now %d (polled PHY)\n", ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) != 0 ) );
- }
-
- vTaskSetTimeOutState( &xPhyTime );
- if( ( ulPHYLinkStatus & PHY_LINK_CONNECTED ) != 0 )
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- }
- else
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
- }
- }
- }
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/ReadMe.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/ReadMe.txt
deleted file mode 100755
index cde8e0e..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/ReadMe.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-NetworkInterface.c:
-Requires NXP's LPCOpen library and was developed on an LPC1830 and LPC1835 Xplorer
-boards from NGX.
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/README_DRIVER_DISCLAIMER.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/README_DRIVER_DISCLAIMER.txt
deleted file mode 100755
index d4dc868..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/README_DRIVER_DISCLAIMER.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-Network drivers are provided as examples only, and do not form part of the
-FreeRTOS+TCP stack itself. They:
-
- + May be based on driver code provided by the chip vendors,
- + May not have been tested in all possible configurations,
- + Will not necessarily be optimised.
- + May have a dependency on a particular PHY part number.
- + May not necessarily comply with any particular coding standard.
- + May have dependencies on chip company libraries.
- + May include other hardware board dependencies.
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c
deleted file mode 100755
index 64204f1..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/* Standard includes. */
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "NetworkBufferManagement.h"
-
-/* Hardware includes. */
-#include "hwEthernet.h"
-
-/* Demo includes. */
-#include "NetworkInterface.h"
-
-#if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
-#else
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
-#endif
-
-/* When a packet is ready to be sent, if it cannot be sent immediately then the
-task performing the transmit will block for niTX_BUFFER_FREE_WAIT
-milliseconds. It will do this a maximum of niMAX_TX_ATTEMPTS before giving
-up. */
-#define niTX_BUFFER_FREE_WAIT ( ( TickType_t ) 2UL / portTICK_PERIOD_MS )
-#define niMAX_TX_ATTEMPTS ( 5 )
-
-/* The length of the queue used to send interrupt status words from the
-interrupt handler to the deferred handler task. */
-#define niINTERRUPT_QUEUE_LENGTH ( 10 )
-
-/*-----------------------------------------------------------*/
-
-/*
- * A deferred interrupt handler task that processes
- */
-extern void vEMACHandlerTask( void *pvParameters );
-
-/*-----------------------------------------------------------*/
-
-/* The queue used to communicate Ethernet events with the IP task. */
-extern QueueHandle_t xNetworkEventQueue;
-
-/* The semaphore used to wake the deferred interrupt handler task when an Rx
-interrupt is received. */
-SemaphoreHandle_t xEMACRxEventSemaphore = NULL;
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-BaseType_t xStatus, xReturn;
-extern uint8_t ucMACAddress[ 6 ];
-
- /* Initialise the MAC. */
- vInitEmac();
-
- while( lEMACWaitForLink() != pdPASS )
- {
- vTaskDelay( 20 );
- }
-
- vSemaphoreCreateBinary( xEMACRxEventSemaphore );
- configASSERT( xEMACRxEventSemaphore );
-
- /* The handler task is created at the highest possible priority to
- ensure the interrupt handler can return directly to it. */
- xTaskCreate( vEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
- xReturn = pdPASS;
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer )
-{
-extern void vEMACCopyWrite( uint8_t * pucBuffer, uint16_t usLength );
-
- vEMACCopyWrite( pxNetworkBuffer->pucBuffer, pxNetworkBuffer->xDataLength );
-
- /* Finished with the network buffer. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
-
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/NetworkInterface.c
deleted file mode 100755
index a68ed11..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/NetworkInterface.c
+++ /dev/null
@@ -1,1193 +0,0 @@
-/*
- * Some constants, hardware definitions and comments taken from ST's HAL driver
- * library, COPYRIGHT(c) 2015 STMicroelectronics.
- */
-
-/*
- * FreeRTOS+TCP V2.0.1
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_DNS.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-
-#include "phyHandling.h"
-
-/* ST includes. */
-#ifdef STM32F7xx
- #include "stm32f7xx_hal.h"
-#else
- #include "stm32f4xx_hal.h"
-#endif
-
-/* Interrupt events to process. Currently only the Rx event is processed
-although code for other events is included to allow for possible future
-expansion. */
-#define EMAC_IF_RX_EVENT 1UL
-#define EMAC_IF_TX_EVENT 2UL
-#define EMAC_IF_ERR_EVENT 4UL
-#define EMAC_IF_ALL_EVENT ( EMAC_IF_RX_EVENT | EMAC_IF_TX_EVENT | EMAC_IF_ERR_EVENT )
-
-#define ETH_DMA_ALL_INTS \
- ( ETH_DMA_IT_TST | ETH_DMA_IT_PMT | ETH_DMA_IT_MMC | ETH_DMA_IT_NIS | ETH_DMA_IT_ER | \
- ETH_DMA_IT_FBE | ETH_DMA_IT_RWT | ETH_DMA_IT_RPS | ETH_DMA_IT_RBU | ETH_DMA_IT_R | \
- ETH_DMA_IT_TU | ETH_DMA_IT_RO | ETH_DMA_IT_TJT | ETH_DMA_IT_TPS | ETH_DMA_IT_T )
-
-
-
-#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff ) /* The bits in the two byte IP header field that make up the fragment offset value. */
-
-/*
- * Most users will want a PHY that negotiates about
- * the connection properties: speed, dmix and duplex.
- * On some rare cases, you want to select what is being
- * advertised, properties like MDIX and duplex.
- */
-
-#if !defined( ipconfigETHERNET_AN_ENABLE )
- /* Enable auto-negotiation */
- #define ipconfigETHERNET_AN_ENABLE 1
-#endif
-
-#if !defined( ipconfigETHERNET_AUTO_CROSS_ENABLE )
- #define ipconfigETHERNET_AUTO_CROSS_ENABLE 1
-#endif
-
-#if( ipconfigETHERNET_AN_ENABLE == 0 )
- /*
- * The following three defines are only used in case there
- * is no auto-negotiation.
- */
- #if !defined( ipconfigETHERNET_CROSSED_LINK )
- #define ipconfigETHERNET_CROSSED_LINK 1
- #endif
-
- #if !defined( ipconfigETHERNET_USE_100MB )
- #define ipconfigETHERNET_USE_100MB 1
- #endif
-
- #if !defined( ipconfigETHERNET_USE_FULL_DUPLEX )
- #define ipconfigETHERNET_USE_FULL_DUPLEX 1
- #endif
-#endif /* ipconfigETHERNET_AN_ENABLE == 0 */
-
-/* Default the size of the stack used by the EMAC deferred handler task to twice
-the size of the stack used by the idle task - but allow this to be overridden in
-FreeRTOSConfig.h as configMINIMAL_STACK_SIZE is a user definable constant. */
-#ifndef configEMAC_TASK_STACK_SIZE
- #define configEMAC_TASK_STACK_SIZE ( 2 * configMINIMAL_STACK_SIZE )
-#endif
-
-/* Two choices must be made: RMII versus MII,
-and the index of the PHY in use ( between 0 and 31 ). */
-#ifndef ipconfigUSE_RMII
- #ifdef STM32F7xx
- #define ipconfigUSE_RMII 1
- #else
- #define ipconfigUSE_RMII 0
- #endif /* STM32F7xx */
-#endif /* ipconfigUSE_RMII */
-
-#ifndef ipconfigPHY_INDEX
- #ifdef STM32F7xx
- #define ipconfigPHY_INDEX 0
- #else
- #define ipconfigPHY_INDEX 1
- #endif /* STM32F7xx */
-#endif /* ipconfigPHY_INDEX */
-
-
-/*-----------------------------------------------------------*/
-
-/*
- * A deferred interrupt handler task that processes
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*
- * Force a negotiation with the Switch or Router and wait for LS.
- */
-static void prvEthernetUpdateConfig( BaseType_t xForce );
-
-/*
- * See if there is a new packet and forward it to the IP-task.
- */
-static BaseType_t prvNetworkInterfaceInput( void );
-
-#if( ipconfigUSE_LLMNR != 0 )
- /*
- * For LLMNR, an extra MAC-address must be configured to
- * be able to receive the multicast messages.
- */
- static void prvMACAddressConfig(ETH_HandleTypeDef *heth, uint32_t ulIndex, uint8_t *Addr);
-#endif
-
-/*
- * Check if a given packet should be accepted.
- */
-static BaseType_t xMayAcceptPacket( uint8_t *pcBuffer );
-
-/*
- * Initialise the TX descriptors.
- */
-static void prvDMATxDescListInit( void );
-
-/*
- * Initialise the RX descriptors.
- */
-static void prvDMARxDescListInit( void );
-
-/* After packets have been sent, the network
-buffers will be released. */
-static void vClearTXBuffers( void );
-
-/*-----------------------------------------------------------*/
-
-/* Bit map of outstanding ETH interrupt events for processing. Currently only
-the Rx interrupt is handled, although code is included for other events to
-enable future expansion. */
-static volatile uint32_t ulISREvents;
-
-#if( ipconfigUSE_LLMNR == 1 )
- static const uint8_t xLLMNR_MACAddress[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
-#endif
-
-static EthernetPhy_t xPhyObject;
-
-/* Ethernet handle. */
-static ETH_HandleTypeDef xETH;
-
-/* xTXDescriptorSemaphore is a counting semaphore with
-a maximum count of ETH_TXBUFNB, which is the number of
-DMA TX descriptors. */
-static SemaphoreHandle_t xTXDescriptorSemaphore = NULL;
-
-/*
- * Note: it is adviced to define both
- *
- * #define ipconfigZERO_COPY_RX_DRIVER 1
- * #define ipconfigZERO_COPY_TX_DRIVER 1
- *
- * The method using memcpy is slower and probaly uses more RAM memory.
- * The possibility is left in the code just for comparison.
- *
- * It is adviced to define ETH_TXBUFNB at least 4. Note that no
- * TX buffers are allocated in a zero-copy driver.
- */
-/* MAC buffers: ---------------------------------------------------------*/
-
-/* Put the DMA descriptors in '.first_data'.
-This is important for STM32F7, which has an L1 data cache.
-The first 64KB of the SRAM is not cached. */
-
-/* Ethernet Rx MA Descriptor */
-__attribute__ ((aligned (32)))
-__attribute__ ((section(".first_data")))
- ETH_DMADescTypeDef DMARxDscrTab[ ETH_RXBUFNB ];
-
-#if( ipconfigZERO_COPY_RX_DRIVER == 0 )
- /* Ethernet Receive Buffer */
- __ALIGN_BEGIN uint8_t Rx_Buff[ ETH_RXBUFNB ][ ETH_RX_BUF_SIZE ] __ALIGN_END;
-#endif
-
-/* Ethernet Tx DMA Descriptor */
-__attribute__ ((aligned (32)))
-__attribute__ ((section(".first_data")))
- ETH_DMADescTypeDef DMATxDscrTab[ ETH_TXBUFNB ];
-
-#if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- /* Ethernet Transmit Buffer */
- __ALIGN_BEGIN uint8_t Tx_Buff[ ETH_TXBUFNB ][ ETH_TX_BUF_SIZE ] __ALIGN_END;
-#endif
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- /* DMATxDescToClear points to the next TX DMA descriptor
- that must be cleared by vClearTXBuffers(). */
- static __IO ETH_DMADescTypeDef *DMATxDescToClear;
-#endif
-
-/* ucMACAddress as it appears in main.c */
-extern const uint8_t ucMACAddress[ 6 ];
-
-/* Holds the handle of the task used as a deferred interrupt processor. The
-handle is used so direct notifications can be sent to the task for all EMAC/DMA
-related interrupts. */
-static TaskHandle_t xEMACTaskHandle = NULL;
-
-/* For local use only: describe the PHY's properties: */
-const PhyProperties_t xPHYProperties =
-{
- #if( ipconfigETHERNET_AN_ENABLE != 0 )
- .ucSpeed = PHY_SPEED_AUTO,
- .ucDuplex = PHY_DUPLEX_AUTO,
- #else
- #if( ipconfigETHERNET_USE_100MB != 0 )
- .ucSpeed = PHY_SPEED_100,
- #else
- .ucSpeed = PHY_SPEED_10,
- #endif
-
- #if( ipconfigETHERNET_USE_FULL_DUPLEX != 0 )
- .duplex = PHY_DUPLEX_FULL,
- #else
- .duplex = PHY_DUPLEX_HALF,
- #endif
- #endif
-
- #if( ipconfigETHERNET_AN_ENABLE != 0 ) && ( ipconfigETHERNET_AUTO_CROSS_ENABLE != 0 )
- .ucMDI_X = PHY_MDIX_AUTO,
- #elif( ipconfigETHERNET_CROSSED_LINK != 0 )
- .ucMDI_X = PHY_MDIX_CROSSED,
- #else
- .ucMDI_X = PHY_MDIX_DIRECT,
- #endif
-};
-
-/*-----------------------------------------------------------*/
-
-void HAL_ETH_RxCpltCallback( ETH_HandleTypeDef *heth )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* Ethernet RX-Complete callback function, elsewhere declared as weak. */
- ulISREvents |= EMAC_IF_RX_EVENT;
- /* Wakeup the prvEMACHandlerTask. */
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
- }
-}
-/*-----------------------------------------------------------*/
-
-void HAL_ETH_TxCpltCallback( ETH_HandleTypeDef *heth )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* This call-back is only useful in case packets are being sent
- zero-copy. Once they're sent, the buffers will be released
- by the function vClearTXBuffers(). */
- ulISREvents |= EMAC_IF_TX_EVENT;
- /* Wakeup the prvEMACHandlerTask. */
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
- }
-
-}
-/*-----------------------------------------------------------*/
-
-static void vClearTXBuffers()
-{
-__IO ETH_DMADescTypeDef *txLastDescriptor = xETH.TxDesc;
-size_t uxCount = ( ( UBaseType_t ) ETH_TXBUFNB ) - uxSemaphoreGetCount( xTXDescriptorSemaphore );
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNetworkBuffer;
- uint8_t *ucPayLoad;
-#endif
-
- /* This function is called after a TX-completion interrupt.
- It will release each Network Buffer used in xNetworkInterfaceOutput().
- 'uxCount' represents the number of descriptors given to DMA for transmission.
- After sending a packet, the DMA will clear the 'ETH_DMATXDESC_OWN' bit. */
- while( ( uxCount > 0 ) && ( ( DMATxDescToClear->Status & ETH_DMATXDESC_OWN ) == 0 ) )
- {
- if( ( DMATxDescToClear == txLastDescriptor ) && ( uxCount != ETH_TXBUFNB ) )
- {
- break;
- }
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- ucPayLoad = ( uint8_t * )DMATxDescToClear->Buffer1Addr;
-
- if( ucPayLoad != NULL )
- {
- pxNetworkBuffer = pxPacketBuffer_to_NetworkBuffer( ucPayLoad );
- if( pxNetworkBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ) ;
- }
- DMATxDescToClear->Buffer1Addr = ( uint32_t )0u;
- }
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- DMATxDescToClear = ( ETH_DMADescTypeDef * )( DMATxDescToClear->Buffer2NextDescAddr );
-
- uxCount--;
- /* Tell the counting semaphore that one more TX descriptor is available. */
- xSemaphoreGive( xTXDescriptorSemaphore );
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-HAL_StatusTypeDef hal_eth_init_status;
-BaseType_t xResult;
-
- if( xEMACTaskHandle == NULL )
- {
- if( xTXDescriptorSemaphore == NULL )
- {
- xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ETH_TXBUFNB, ( UBaseType_t ) ETH_TXBUFNB );
- configASSERT( xTXDescriptorSemaphore );
- }
-
- /* Initialise ETH */
-
- xETH.Instance = ETH;
-//#warning Enable auto-nego again
- xETH.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
-// xETH.Init.AutoNegotiation = ETH_AUTONEGOTIATION_DISABLE;
- xETH.Init.Speed = ETH_SPEED_100M;
- xETH.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
- xETH.Init.PhyAddress = ipconfigPHY_INDEX;
-
- xETH.Init.MACAddr = ( uint8_t *) ucMACAddress;
- xETH.Init.RxMode = ETH_RXINTERRUPT_MODE;
-
- /* using the ETH_CHECKSUM_BY_HARDWARE option:
- both the IP and the protocol checksums will be calculated
- by the peripheral. */
- xETH.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
-
- #if( ipconfigUSE_RMII != 0 )
- {
- xETH.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
- }
- #else
- {
- xETH.Init.MediaInterface = ETH_MEDIA_INTERFACE_MII;
- }
- #endif /* ipconfigUSE_RMII */
-
- hal_eth_init_status = HAL_ETH_Init( &xETH );
-
- /* Only for inspection by debugger. */
- ( void ) hal_eth_init_status;
-
- /* Set the TxDesc and RxDesc pointers. */
- xETH.TxDesc = DMATxDscrTab;
- xETH.RxDesc = DMARxDscrTab;
-
- /* Make sure that all unused fields are cleared. */
- memset( &DMATxDscrTab, '\0', sizeof( DMATxDscrTab ) );
- memset( &DMARxDscrTab, '\0', sizeof( DMARxDscrTab ) );
-
- /* Initialize Tx Descriptors list: Chain Mode */
- DMATxDescToClear = DMATxDscrTab;
-
- /* Initialise TX-descriptors. */
- prvDMATxDescListInit();
-
- /* Initialise RX-descriptors. */
- prvDMARxDescListInit();
-
- #if( ipconfigUSE_LLMNR != 0 )
- {
- /* Program the LLMNR address at index 1. */
- prvMACAddressConfig( &xETH, ETH_MAC_ADDRESS1, ( uint8_t *) xLLMNR_MACAddress );
- }
- #endif
-
- /* Force a negotiation with the Switch or Router and wait for LS. */
- prvEthernetUpdateConfig( pdTRUE );
-
- /* The deferred interrupt handler task is created at the highest
- possible priority to ensure the interrupt handler can return directly
- to it. The task's handle is stored in xEMACTaskHandle so interrupts can
- notify the task when there is something to process. */
- xTaskCreate( prvEMACHandlerTask, "EMAC", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
- } /* if( xEMACTaskHandle == NULL ) */
-
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- xETH.Instance->DMAIER |= ETH_DMA_ALL_INTS;
- xResult = pdPASS;
- FreeRTOS_printf( ( "Link Status is high\n" ) ) ;
- }
- else
- {
- /* For now pdFAIL will be returned. But prvEMACHandlerTask() is running
- and it will keep on checking the PHY and set 'ulLinkStatusMask' when necessary. */
- xResult = pdFAIL;
- FreeRTOS_printf( ( "Link Status still low\n" ) ) ;
- }
- /* When returning non-zero, the stack will become active and
- start DHCP (in configured) */
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-static void prvDMATxDescListInit()
-{
-ETH_DMADescTypeDef *pxDMADescriptor;
-BaseType_t xIndex;
-
- /* Get the pointer on the first member of the descriptor list */
- pxDMADescriptor = DMATxDscrTab;
-
- /* Fill each DMA descriptor with the right values */
- for( xIndex = 0; xIndex < ETH_TXBUFNB; xIndex++, pxDMADescriptor++ )
- {
- /* Set Second Address Chained bit */
- pxDMADescriptor->Status = ETH_DMATXDESC_TCH;
-
- #if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- {
- /* Set Buffer1 address pointer */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( Tx_Buff[ xIndex ] );
- }
- #endif
-
- if( xETH.Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE )
- {
- /* Set the DMA Tx descriptors checksum insertion for TCP, UDP, and ICMP */
- pxDMADescriptor->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if( xIndex < ETH_TXBUFNB - 1 )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) ( pxDMADescriptor + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) DMATxDscrTab;
- }
- }
-
- /* Set Transmit Descriptor List Address Register */
- xETH.Instance->DMATDLAR = ( uint32_t ) DMATxDscrTab;
-}
-/*-----------------------------------------------------------*/
-
-static void prvDMARxDescListInit()
-{
-ETH_DMADescTypeDef *pxDMADescriptor;
-BaseType_t xIndex;
- /*
- * RX-descriptors.
- */
-
- /* Get the pointer on the first member of the descriptor list */
- pxDMADescriptor = DMARxDscrTab;
-
- /* Fill each DMA descriptor with the right values */
- for( xIndex = 0; xIndex < ETH_RXBUFNB; xIndex++, pxDMADescriptor++ )
- {
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMADescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | (uint32_t)ETH_RX_BUF_SIZE;
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Set Buffer1 address pointer */
- NetworkBufferDescriptor_t *pxBuffer;
-
- pxBuffer = pxGetNetworkBufferWithDescriptor( ETH_RX_BUF_SIZE, 100ul );
- /* If the assert below fails, make sure that there are at least 'ETH_RXBUFNB'
- Network Buffers available during start-up ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) */
- configASSERT( pxBuffer != NULL );
- if( pxBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = (uint32_t)pxBuffer->pucEthernetBuffer;
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
- }
- }
- #else
- {
- /* Set Buffer1 address pointer */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( Rx_Buff[ xIndex ] );
- /* Set Own bit of the Rx descriptor Status */
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
- }
- #endif
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if( xIndex < ETH_RXBUFNB - 1 )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t )( pxDMADescriptor + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) DMARxDscrTab;
- }
-
- }
- /* Set Receive Descriptor List Address Register */
- xETH.Instance->DMARDLAR = ( uint32_t ) DMARxDscrTab;
-}
-/*-----------------------------------------------------------*/
-
-static void prvMACAddressConfig(ETH_HandleTypeDef *heth, uint32_t ulIndex, uint8_t *Addr)
-{
-uint32_t ulTempReg;
-
- /* Calculate the selected MAC address high register. */
- ulTempReg = 0x80000000ul | ( ( uint32_t ) Addr[ 5 ] << 8 ) | ( uint32_t ) Addr[ 4 ];
-
- /* Load the selected MAC address high register. */
- ( *(__IO uint32_t *)( ( uint32_t ) ( ETH_MAC_ADDR_HBASE + ulIndex ) ) ) = ulTempReg;
-
- /* Calculate the selected MAC address low register. */
- ulTempReg = ( ( uint32_t ) Addr[ 3 ] << 24 ) | ( ( uint32_t ) Addr[ 2 ] << 16 ) | ( ( uint32_t ) Addr[ 1 ] << 8 ) | Addr[ 0 ];
-
- /* Load the selected MAC address low register */
- ( *(__IO uint32_t *) ( ( uint32_t ) ( ETH_MAC_ADDR_LBASE + ulIndex ) ) ) = ulTempReg;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t bReleaseAfterSend )
-{
-BaseType_t xReturn = pdFAIL;
-uint32_t ulTransmitSize = 0;
-__IO ETH_DMADescTypeDef *pxDmaTxDesc;
-/* Do not wait too long for a free TX DMA buffer. */
-const TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 50u );
-
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
- {
- ProtocolPacket_t *pxPacket;
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- configASSERT( bReleaseAfterSend != 0 );
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- /* If the peripheral must calculate the checksum, it wants
- the protocol checksum to have a value of zero. */
- pxPacket = ( ProtocolPacket_t * ) ( pxDescriptor->pucEthernetBuffer );
-
- if( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP )
- {
- pxPacket->xICMPPacket.xICMPHeader.usChecksum = ( uint16_t )0u;
- }
- }
- #endif
-
- /* Open a do {} while ( 0 ) loop to be able to call break. */
- do
- {
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- if( xSemaphoreTake( xTXDescriptorSemaphore, xBlockTimeTicks ) != pdPASS )
- {
- /* Time-out waiting for a free TX descriptor. */
- break;
- }
-
- /* This function does the actual transmission of the packet. The packet is
- contained in 'pxDescriptor' that is passed to the function. */
- pxDmaTxDesc = xETH.TxDesc;
-
- /* Is this buffer available? */
- configASSERT ( ( pxDmaTxDesc->Status & ETH_DMATXDESC_OWN ) == 0 );
-
- {
- /* Is this buffer available? */
- /* Get bytes in current buffer. */
- ulTransmitSize = pxDescriptor->xDataLength;
-
- if( ulTransmitSize > ETH_TX_BUF_SIZE )
- {
- ulTransmitSize = ETH_TX_BUF_SIZE;
- }
-
- #if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- {
- /* Copy the bytes. */
- memcpy( ( void * ) pxDmaTxDesc->Buffer1Addr, pxDescriptor->pucEthernetBuffer, ulTransmitSize );
- }
- #else
- {
- /* Move the buffer. */
- pxDmaTxDesc->Buffer1Addr = ( uint32_t )pxDescriptor->pucEthernetBuffer;
- /* The Network Buffer has been passed to DMA, no need to release it. */
- bReleaseAfterSend = pdFALSE_UNSIGNED;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- /* Ask to set the IPv4 checksum.
- Also need an Interrupt on Completion so that 'vClearTXBuffers()' will be called.. */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_CIC_TCPUDPICMP_FULL | ETH_DMATXDESC_IC;
-
- /* Prepare transmit descriptors to give to DMA. */
-
- /* Set LAST and FIRST segment */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_FS | ETH_DMATXDESC_LS;
- /* Set frame size */
- pxDmaTxDesc->ControlBufferSize = ( ulTransmitSize & ETH_DMATXDESC_TBS1 );
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_OWN;
-
- /* Point to next descriptor */
- xETH.TxDesc = ( ETH_DMADescTypeDef * ) ( xETH.TxDesc->Buffer2NextDescAddr );
- /* Ensure completion of memory access */
- __DSB();
- /* Resume DMA transmission*/
- xETH.Instance->DMATPDR = 0;
- iptraceNETWORK_INTERFACE_TRANSMIT();
- xReturn = pdPASS;
- }
- }
- else
- {
- /* The PHY has no Link Status, packet shall be dropped. */
- }
- } while( 0 );
- /* The buffer has been sent so can be released. */
- if( bReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t xMayAcceptPacket( uint8_t *pcBuffer )
-{
-const ProtocolPacket_t *pxProtPacket = ( const ProtocolPacket_t * )pcBuffer;
-
- switch( pxProtPacket->xTCPPacket.xEthernetHeader.usFrameType )
- {
- case ipARP_FRAME_TYPE:
- /* Check it later. */
- return pdTRUE;
- case ipIPv4_FRAME_TYPE:
- /* Check it here. */
- break;
- default:
- /* Refuse the packet. */
- return pdFALSE;
- }
-
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- const IPHeader_t *pxIPHeader = &(pxProtPacket->xTCPPacket.xIPHeader);
- uint32_t ulDestinationIPAddress;
-
- /* Ensure that the incoming packet is not fragmented (only outgoing packets
- * can be fragmented) as these are the only handled IP frames currently. */
- if( ( pxIPHeader->usFragmentOffset & FreeRTOS_ntohs( ipFRAGMENT_OFFSET_BIT_MASK ) ) != 0U )
- {
- return pdFALSE;
- }
- /* HT: Might want to make the following configurable because
- * most IP messages have a standard length of 20 bytes */
-
- /* 0x45 means: IPv4 with an IP header of 5 x 4 = 20 bytes
- * 0x47 means: IPv4 with an IP header of 7 x 4 = 28 bytes */
- if( pxIPHeader->ucVersionHeaderLength < 0x45 || pxIPHeader->ucVersionHeaderLength > 0x4F )
- {
- return pdFALSE;
- }
-
- ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;
- /* Is the packet for this node? */
- if( ( ulDestinationIPAddress != *ipLOCAL_IP_ADDRESS_POINTER ) &&
- /* Is it a broadcast address x.x.x.255 ? */
- ( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xff ) != 0xff ) &&
- #if( ipconfigUSE_LLMNR == 1 )
- ( ulDestinationIPAddress != ipLLMNR_IP_ADDR ) &&
- #endif
- ( *ipLOCAL_IP_ADDRESS_POINTER != 0 ) ) {
- FreeRTOS_printf( ( "Drop IP %lxip\n", FreeRTOS_ntohl( ulDestinationIPAddress ) ) );
- return pdFALSE;
- }
-
- if( pxIPHeader->ucProtocol == ipPROTOCOL_UDP )
- {
- uint16_t port = pxProtPacket->xUDPPacket.xUDPHeader.usDestinationPort;
-
- if( ( xPortHasUDPSocket( port ) == pdFALSE )
- #if ipconfigUSE_LLMNR == 1
- && ( port != FreeRTOS_ntohs( ipLLMNR_PORT ) )
- #endif
- #if ipconfigUSE_NBNS == 1
- && ( port != FreeRTOS_ntohs( ipNBNS_PORT ) )
- #endif
- #if ipconfigUSE_DNS == 1
- && ( pxProtPacket->xUDPPacket.xUDPHeader.usSourcePort != FreeRTOS_ntohs( ipDNS_PORT ) )
- #endif
- ) {
- /* Drop this packet, not for this device. */
- return pdFALSE;
- }
- }
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvNetworkInterfaceInput( void )
-{
-NetworkBufferDescriptor_t *pxCurDescriptor;
-NetworkBufferDescriptor_t *pxNewDescriptor = NULL;
-BaseType_t xReceivedLength, xAccepted;
-__IO ETH_DMADescTypeDef *pxDMARxDescriptor;
-xIPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-const TickType_t xDescriptorWaitTime = pdMS_TO_TICKS( 250 );
-uint8_t *pucBuffer;
-
- pxDMARxDescriptor = xETH.RxDesc;
-
- if( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_OWN) == 0 )
- {
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- xReceivedLength = ( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_FL ) >> ETH_DMARXDESC_FRAMELENGTHSHIFT ) - 4;
-
- pucBuffer = (uint8_t *) pxDMARxDescriptor->Buffer1Addr;
-
- /* Update the ETHERNET DMA global Rx descriptor with next Rx descriptor */
- /* Chained Mode */
- /* Selects the next DMA Rx descriptor list for next buffer to read */
- xETH.RxDesc = ( ETH_DMADescTypeDef* )pxDMARxDescriptor->Buffer2NextDescAddr;
- }
- else
- {
- xReceivedLength = 0;
- }
-
- /* Obtain the size of the packet and put it into the "usReceivedLength" variable. */
-
- /* get received frame */
- if( xReceivedLength > 0ul )
- {
- /* In order to make the code easier and faster, only packets in a single buffer
- will be accepted. This can be done by making the buffers large enough to
- hold a complete Ethernet packet (1536 bytes).
- Therefore, two sanity checks: */
- configASSERT( xReceivedLength <= ETH_RX_BUF_SIZE );
-
- if( ( pxDMARxDescriptor->Status & ( ETH_DMARXDESC_CE | ETH_DMARXDESC_IPV4HCE | ETH_DMARXDESC_FT ) ) != ETH_DMARXDESC_FT )
- {
- /* Not an Ethernet frame-type or a checmsum error. */
- xAccepted = pdFALSE;
- }
- else
- {
- /* See if this packet must be handled. */
- xAccepted = xMayAcceptPacket( pucBuffer );
- }
-
- if( xAccepted != pdFALSE )
- {
- /* The packet wil be accepted, but check first if a new Network Buffer can
- be obtained. If not, the packet will still be dropped. */
- pxNewDescriptor = pxGetNetworkBufferWithDescriptor( ETH_RX_BUF_SIZE, xDescriptorWaitTime );
-
- if( pxNewDescriptor == NULL )
- {
- /* A new descriptor can not be allocated now. This packet will be dropped. */
- xAccepted = pdFALSE;
- }
- }
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Find out which Network Buffer was originally passed to the descriptor. */
- pxCurDescriptor = pxPacketBuffer_to_NetworkBuffer( pucBuffer );
- configASSERT( pxCurDescriptor != NULL );
- }
- #else
- {
- /* In this mode, the two descriptors are the same. */
- pxCurDescriptor = pxNewDescriptor;
- if( pxNewDescriptor != NULL )
- {
- /* The packet is acepted and a new Network Buffer was created,
- copy data to the Network Bufffer. */
- memcpy( pxNewDescriptor->pucEthernetBuffer, pucBuffer, xReceivedLength );
- }
- }
- #endif
-
- if( xAccepted != pdFALSE )
- {
- pxCurDescriptor->xDataLength = xReceivedLength;
- xRxEvent.pvData = ( void * ) pxCurDescriptor;
-
- /* Pass the data to the TCP/IP task for processing. */
- if( xSendEventStructToIPTask( &xRxEvent, xDescriptorWaitTime ) == pdFALSE )
- {
- /* Could not send the descriptor into the TCP/IP stack, it
- must be released. */
- vReleaseNetworkBufferAndDescriptor( pxCurDescriptor );
- iptraceETHERNET_RX_EVENT_LOST();
- }
- else
- {
- iptraceNETWORK_INTERFACE_RECEIVE();
- }
- }
-
- /* Release descriptors to DMA */
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Set Buffer1 address pointer */
- if( pxNewDescriptor != NULL )
- {
- pxDMARxDescriptor->Buffer1Addr = (uint32_t)pxNewDescriptor->pucEthernetBuffer;
- }
- else
- {
- /* The packet was dropped and the same Network
- Buffer will be used to receive a new packet. */
- }
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMARxDescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | (uint32_t)ETH_RX_BUF_SIZE;
- pxDMARxDescriptor->Status = ETH_DMARXDESC_OWN;
-
- /* Ensure completion of memory access */
- __DSB();
- /* When Rx Buffer unavailable flag is set clear it and resume
- reception. */
- if( ( xETH.Instance->DMASR & ETH_DMASR_RBUS ) != 0 )
- {
- /* Clear RBUS ETHERNET DMA flag. */
- xETH.Instance->DMASR = ETH_DMASR_RBUS;
-
- /* Resume DMA reception. */
- xETH.Instance->DMARPDR = 0;
- }
- }
-
- return ( xReceivedLength > 0 );
-}
-/*-----------------------------------------------------------*/
-
-
-BaseType_t xSTM32_PhyRead( BaseType_t xAddress, BaseType_t xRegister, uint32_t *pulValue )
-{
-uint16_t usPrevAddress = xETH.Init.PhyAddress;
-BaseType_t xResult;
-HAL_StatusTypeDef xHALResult;
-
- xETH.Init.PhyAddress = xAddress;
- xHALResult = HAL_ETH_ReadPHYRegister( &xETH, ( uint16_t )xRegister, pulValue );
- xETH.Init.PhyAddress = usPrevAddress;
-
- if( xHALResult == HAL_OK )
- {
- xResult = 0;
- }
- else
- {
- xResult = -1;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xSTM32_PhyWrite( BaseType_t xAddress, BaseType_t xRegister, uint32_t ulValue )
-{
-uint16_t usPrevAddress = xETH.Init.PhyAddress;
-BaseType_t xResult;
-HAL_StatusTypeDef xHALResult;
-
- xETH.Init.PhyAddress = xAddress;
- xHALResult = HAL_ETH_WritePHYRegister( &xETH, ( uint16_t )xRegister, ulValue );
- xETH.Init.PhyAddress = usPrevAddress;
-
- if( xHALResult == HAL_OK )
- {
- xResult = 0;
- }
- else
- {
- xResult = -1;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-void phy_test()
-{
-BaseType_t xPhyCount;
-BaseType_t xPhyIndex;
-
- vPhyInitialise( &xPhyObject, xSTM32_PhyRead, xSTM32_PhyWrite );
- xPhyCount = xPhyDiscover( &xPhyObject );
- FreeRTOS_printf( ( "PHY count %ld\n", xPhyCount ) );
- for( xPhyIndex = 0; xPhyIndex < xPhyCount; xPhyIndex++ )
- {
- FreeRTOS_printf( ( "PHY[%d] at address %d ( 0x%08X )\n",
- xPhyIndex,
- xPhyObject.ucPhyIndexes[ xPhyIndex ],
- xPhyObject.ulPhyIDs[ xPhyIndex ] ) );
-
- }
-
-}
-
-void vMACBProbePhy( void )
-{
- vPhyInitialise( &xPhyObject, xSTM32_PhyRead, xSTM32_PhyWrite );
- xPhyDiscover( &xPhyObject );
- xPhyConfigure( &xPhyObject, &xPHYProperties );
-}
-/*-----------------------------------------------------------*/
-
-static void prvEthernetUpdateConfig( BaseType_t xForce )
-{
- FreeRTOS_printf( ( "prvEthernetUpdateConfig: LS mask %02X Force %d\n",
- xPhyObject.ulLinkStatusMask,
- ( int )xForce ) );
-
- if( ( xForce != pdFALSE ) || ( xPhyObject.ulLinkStatusMask != 0 ) )
- {
- /* Restart the auto-negotiation. */
- if( xETH.Init.AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE )
- {
- xPhyStartAutoNegotiation( &xPhyObject, xPhyGetMask( &xPhyObject ) );
-
- /* Configure the MAC with the Duplex Mode fixed by the
- auto-negotiation process. */
- if( xPhyObject.xPhyProperties.ucDuplex == PHY_DUPLEX_FULL )
- {
- xETH.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
- }
- else
- {
- xETH.Init.DuplexMode = ETH_MODE_HALFDUPLEX;
- }
-
- /* Configure the MAC with the speed fixed by the
- auto-negotiation process. */
- if( xPhyObject.xPhyProperties.ucSpeed == PHY_SPEED_10 )
- {
- xETH.Init.Speed = ETH_SPEED_10M;
- }
- else
- {
- xETH.Init.Speed = ETH_SPEED_100M;
- }
- }
- else /* AutoNegotiation Disable */
- {
- /* Check parameters */
- assert_param( IS_ETH_SPEED( xETH.Init.Speed ) );
- assert_param( IS_ETH_DUPLEX_MODE( xETH.Init.DuplexMode ) );
-
- if( xETH.Init.DuplexMode == ETH_MODE_FULLDUPLEX )
- {
- xPhyObject.xPhyPreferences.ucDuplex = PHY_DUPLEX_HALF;
- }
- else
- {
- xPhyObject.xPhyPreferences.ucDuplex = PHY_DUPLEX_FULL;
- }
-
- if( xETH.Init.Speed == ETH_SPEED_10M )
- {
- xPhyObject.xPhyPreferences.ucSpeed = PHY_SPEED_10;
- }
- else
- {
- xPhyObject.xPhyPreferences.ucSpeed = PHY_SPEED_100;
- }
-
- xPhyObject.xPhyPreferences.ucMDI_X = PHY_MDIX_AUTO;
-
- /* Use predefined (fixed) configuration. */
- xPhyFixedValue( &xPhyObject, xPhyGetMask( &xPhyObject ) );
- }
-
- /* ETHERNET MAC Re-Configuration */
- HAL_ETH_ConfigMAC( &xETH, (ETH_MACInitTypeDef *) NULL);
-
- /* Restart MAC interface */
- HAL_ETH_Start( &xETH);
- }
- else
- {
- /* Stop MAC interface */
- HAL_ETH_Stop( &xETH );
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xReturn;
-
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- xReturn = pdPASS;
- }
- else
- {
- xReturn = pdFAIL;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-#define niBUFFER_1_PACKET_SIZE 1536
-
-static __attribute__ ((section(".first_data"))) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__ ( ( aligned( 32 ) ) );
-
-void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
-{
-
-uint8_t *ucRAMBuffer = ucNetworkPackets;
-uint32_t ul;
-
- for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ )
- {
- pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING;
- *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
- ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-UBaseType_t uxLastMinBufferCount = 0;
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
-UBaseType_t uxLastMinQueueSpace = 0;
-#endif
-UBaseType_t uxCurrentCount;
-BaseType_t xResult;
-const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100UL );
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- xResult = 0;
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
- if( xTXDescriptorSemaphore != NULL )
- {
- static UBaseType_t uxLowestSemCount = ( UBaseType_t ) ETH_TXBUFNB - 1;
-
- uxCurrentCount = uxSemaphoreGetCount( xTXDescriptorSemaphore );
- if( uxLowestSemCount > uxCurrentCount )
- {
- uxLowestSemCount = uxCurrentCount;
- FreeRTOS_printf( ( "TX DMA buffers: lowest %lu\n", uxLowestSemCount ) );
- }
-
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- if( ( ulISREvents & EMAC_IF_ALL_EVENT ) == 0 )
- {
- /* No events to process now, wait for the next. */
- ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
- }
-
- if( ( ulISREvents & EMAC_IF_RX_EVENT ) != 0 )
- {
- ulISREvents &= ~EMAC_IF_RX_EVENT;
-
- xResult = prvNetworkInterfaceInput();
- if( xResult > 0 )
- {
- while( prvNetworkInterfaceInput() > 0 )
- {
- }
- }
- }
-
- if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0 )
- {
- /* Code to release TX buffers if zero-copy is used. */
- ulISREvents &= ~EMAC_IF_TX_EVENT;
- /* Check if DMA packets have been delivered. */
- vClearTXBuffers();
- }
-
- if( ( ulISREvents & EMAC_IF_ERR_EVENT ) != 0 )
- {
- /* Future extension: logging about errors that occurred. */
- ulISREvents &= ~EMAC_IF_ERR_EVENT;
- }
- if( xPhyCheckLinkStatus( &xPhyObject, xResult ) != 0 )
- {
- /* Something has changed to a Link Status, need re-check. */
- prvEthernetUpdateConfig( pdFALSE );
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-void ETH_IRQHandler( void )
-{
- HAL_ETH_IRQHandler( &xETH );
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.c
deleted file mode 100755
index 87b5407..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.c
+++ /dev/null
@@ -1,1835 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f7xx_hal_eth.c
- * @author MCD Application Team
- * @version V1.3.2
- * @date 26-June-2015
- * @brief ETH HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the Ethernet (ETH) peripheral:
- * + Initialization and de-initialization functions
- * + IO operation functions
- * + Peripheral Control functions
- * + Peripheral State and Errors functions
- *
- @verbatim
- ==============================================================================
- ##### How to use this driver #####
- ==============================================================================
- [..]
- (#)Declare a ETH_HandleTypeDef handle structure, for example:
- ETH_HandleTypeDef heth;
-
- (#)Fill parameters of Init structure in heth handle
-
- (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...)
-
- (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:
- (##) Enable the Ethernet interface clock using
- (+++) __HAL_RCC_ETHMAC_CLK_ENABLE();
- (+++) __HAL_RCC_ETHMACTX_CLK_ENABLE();
- (+++) __HAL_RCC_ETHMACRX_CLK_ENABLE();
-
- (##) Initialize the related GPIO clocks
- (##) Configure Ethernet pin-out
- (##) Configure Ethernet NVIC interrupt (IT mode)
-
- (#)Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers:
- (##) HAL_ETH_DMATxDescListInit(); for Transmission process
- (##) HAL_ETH_DMARxDescListInit(); for Reception process
-
- (#)Enable MAC and DMA transmission and reception:
- (##) HAL_ETH_Start();
-
- (#)Prepare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer
- the frame to MAC TX FIFO:
- (##) HAL_ETH_TransmitFrame();
-
- (#)Poll for a received frame in ETH RX DMA Descriptors and get received
- frame parameters
- (##) HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop)
-
- (#) Get a received frame when an ETH RX interrupt occurs:
- (##) HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only)
-
- (#) Communicate with external PHY device:
- (##) Read a specific register from the PHY
- HAL_ETH_ReadPHYRegister();
- (##) Write data to a specific RHY register:
- HAL_ETH_WritePHYRegister();
-
- (#) Configure the Ethernet MAC after ETH peripheral initialization
- HAL_ETH_ConfigMAC(); all MAC parameters should be filled.
-
- (#) Configure the Ethernet DMA after ETH peripheral initialization
- HAL_ETH_ConfigDMA(); all DMA parameters should be filled.
-
- -@- The PTP protocol and the DMA descriptors ring mode are not supported
- in this driver
-
- @endverbatim
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2015 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f7xx_hal.h"
-
-
-int lUDPLoggingPrintf( const char *pcFormatString, ... );
-
-/** @addtogroup STM32F4xx_HAL_Driver
- * @{
- */
-
-/** @defgroup ETH ETH
- * @brief ETH HAL module driver
- * @{
- */
-
-#if !defined( ARRAY_SIZE )
- #define ARRAY_SIZE( x ) ( sizeof ( x ) / sizeof ( x )[ 0 ] )
-#endif
-
-#ifdef HAL_ETH_MODULE_ENABLED
-
-#if defined(STM32F7xx)
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/** @defgroup ETH_Private_Constants ETH Private Constants
- * @{
- */
-#define LINKED_STATE_TIMEOUT_VALUE ((uint32_t)2000) /* 2000 ms */
-#define AUTONEGO_COMPLETED_TIMEOUT_VALUE ((uint32_t)1000) /* 1000 ms */
-
-/**
- * @}
- */
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/** @defgroup ETH_Private_Functions ETH Private Functions
- * @{
- */
-static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);
-static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);
-static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);
-static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);
-static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);
-static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);
-static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);
-static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);
-static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);
-static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);
-static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);
-
-/**
- * @}
- */
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup ETH_Exported_Functions ETH Exported Functions
- * @{
- */
-
-/** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions
- * @brief Initialization and Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Initialization and de-initialization functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) Initialize and configure the Ethernet peripheral
- (+) De-initialize the Ethernet peripheral
-
- @endverbatim
- * @{
- */
-extern void vMACBProbePhy ( void );
-
-/**
- * @brief Initializes the Ethernet MAC and DMA according to default
- * parameters.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = 0;
- uint32_t hclk = 60000000;
- uint32_t err = ETH_SUCCESS;
-
- /* Check the ETH peripheral state */
- if( heth == NULL )
- {
- return HAL_ERROR;
- }
-
- /* Check parameters */
- assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));
- assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));
- assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));
- assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));
-
- if( heth->State == HAL_ETH_STATE_RESET )
- {
- /* Init the low level hardware : GPIO, CLOCK, NVIC. */
- HAL_ETH_MspInit( heth );
- }
-
- /* Enable SYSCFG Clock */
- __HAL_RCC_SYSCFG_CLK_ENABLE();
-
- /* Select MII or RMII Mode*/
- SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);
- SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;
-
- /* Ethernet Software reset */
- /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
- /* After reset all the registers holds their respective reset values */
- /* Also enable EDFE: Enhanced descriptor format enable. */
-// heth->Instance->DMABMR |= ETH_DMABMR_SR | ETH_DMABMR_EDE;
- heth->Instance->DMABMR |= ETH_DMABMR_SR;
-
- /* Wait for software reset */
- while ((heth->Instance->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
- {
- }
-
- /*-------------------------------- MAC Initialization ----------------------*/
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
- /* Clear CSR Clock Range CR[2:0] bits */
- tmpreg &= ETH_MACMIIAR_CR_MASK;
-
- /* Get hclk frequency value (168,000,000) */
- hclk = HAL_RCC_GetHCLKFreq();
-
- /* Set CR bits depending on hclk value */
- if( ( hclk >= 20000000 ) && ( hclk < 35000000 ) )
- {
- /* CSR Clock Range between 20-35 MHz */
- tmpreg |= (uint32_t) ETH_MACMIIAR_CR_Div16;
- }
- else if( ( hclk >= 35000000 ) && ( hclk < 60000000 ) )
- {
- /* CSR Clock Range between 35-60 MHz */
- tmpreg |= ( uint32_t ) ETH_MACMIIAR_CR_Div26;
- }
- else if((hclk >= 60000000 ) && ( hclk < 100000000 ) )
- {
- /* CSR Clock Range between 60-100 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
- }
- else if((hclk >= 100000000 ) && ( hclk < 150000000))
- {
- /* CSR Clock Range between 100-150 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;
- }
- else /* ((hclk >= 150000000 ) && ( hclk <= 168000000)) */
- {
- /* CSR Clock Range between 150-168 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;
- }
-
- /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
- heth->Instance->MACMIIAR = (uint32_t)tmpreg;
-
- /* Initialise the MACB and set all PHY properties */
- vMACBProbePhy();
-
- /* Config MAC and DMA */
- ETH_MACDMAConfig(heth, err);
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief De-Initializes the ETH peripheral.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
-{
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */
- HAL_ETH_MspDeInit( heth );
-
- /* Set ETH HAL state to Disabled */
- heth->State= HAL_ETH_STATE_RESET;
-
- /* Release Lock */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the DMA Tx descriptors in chain mode.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param DMATxDescTab: Pointer to the first Tx desc list
- * @param TxBuff: Pointer to the first TxBuffer list
- * @param TxBuffCount: Number of the used Tx desc in the list
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *pxDMATable, uint8_t *ucDataBuffer, uint32_t ulBufferCount)
-{
- uint32_t i = 0;
- ETH_DMADescTypeDef *pxDMADescriptor;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Set the TxDesc pointer with the first one of the pxDMATable list */
- heth->TxDesc = pxDMATable;
-
- /* Fill each DMA descriptor with the right values */
- for( i=0; i < ulBufferCount; i++ )
- {
- /* Get the pointer on the ith member of the descriptor list */
- pxDMADescriptor = pxDMATable + i;
-
- /* Set Second Address Chained bit */
- pxDMADescriptor->Status = ETH_DMATXDESC_TCH;
-
- pxDMADescriptor->ControlBufferSize = 0;
-
- /* Set Buffer1 address pointer */
- if( ucDataBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( &ucDataBuffer[ i * ETH_TX_BUF_SIZE ] );
- }
- else
- {
- /* Buffer space is not provided because it uses zero-copy transmissions. */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )0u;
- }
-
- if (heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
- {
- /* Set the DMA Tx descriptors checksum insertion for TCP, UDP, and ICMP */
- pxDMADescriptor->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < ( ulBufferCount - 1 ) )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) ( pxDMATable + i + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) pxDMATable;
- }
- }
-
- /* Set Transmit Descriptor List Address Register */
- heth->Instance->DMATDLAR = ( uint32_t ) pxDMATable;
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the DMA Rx descriptors in chain mode.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param DMARxDescTab: Pointer to the first Rx desc list
- * @param RxBuff: Pointer to the first RxBuffer list
- * @param RxBuffCount: Number of the used Rx desc in the list
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *pxDMATable, uint8_t *ucDataBuffer, uint32_t ulBufferCount)
-{
- uint32_t i = 0;
- ETH_DMADescTypeDef *pxDMADescriptor;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Set the RxDesc pointer with the first one of the pxDMATable list */
- heth->RxDesc = pxDMATable;
-
- /* Fill each DMA descriptor with the right values */
- for(i=0; i < ulBufferCount; i++)
- {
- /* Get the pointer on the ith member of the descriptor list */
- pxDMADescriptor = pxDMATable+i;
-
- /* Set Own bit of the Rx descriptor Status */
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMADescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;
-
- /* Set Buffer1 address pointer */
- if( ucDataBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( &ucDataBuffer[ i * ETH_RX_BUF_SIZE ] );
- }
- else
- {
- /* Buffer space is not provided because it uses zero-copy reception. */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )0u;
- }
-
- if( heth->Init.RxMode == ETH_RXINTERRUPT_MODE )
- {
- /* Enable Ethernet DMA Rx Descriptor interrupt */
- pxDMADescriptor->ControlBufferSize &= ~ETH_DMARXDESC_DIC;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < (ulBufferCount-1))
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = (uint32_t)(pxDMATable+i+1);
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) pxDMATable;
- }
- }
-
- /* Set Receive Descriptor List Address Register */
- heth->Instance->DMARDLAR = ( uint32_t ) pxDMATable;
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the ETH MSP.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_MspInit could be implemented in the user file
- */
-}
-
-/**
- * @brief DeInitializes ETH MSP.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_MspDeInit could be implemented in the user file
- */
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group2 IO operation functions
- * @brief Data transfers functions
- *
- @verbatim
- ==============================================================================
- ##### IO operation functions #####
- ==============================================================================
- [..] This section provides functions allowing to:
- (+) Transmit a frame
- HAL_ETH_TransmitFrame();
- (+) Receive a frame
- HAL_ETH_GetReceivedFrame();
- HAL_ETH_GetReceivedFrame_IT();
- (+) Read from an External PHY register
- HAL_ETH_ReadPHYRegister();
- (+) Write to an External PHY register
- HAL_ETH_WritePHYRegister();
-
- @endverbatim
-
- * @{
- */
-
-/**
- * @brief Sends an Ethernet frame.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param FrameLength: Amount of data to be sent
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength)
-{
- uint32_t bufcount = 0, size = 0, i = 0;
- __IO ETH_DMADescTypeDef *pxDmaTxDesc = heth->TxDesc;
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- if( FrameLength == 0 )
- {
- /* Set ETH HAL state to READY */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- return HAL_ERROR;
- }
-
- /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
- if( ( pxDmaTxDesc->Status & ETH_DMATXDESC_OWN ) != ( uint32_t ) RESET )
- {
- /* OWN bit set */
- heth->State = HAL_ETH_STATE_BUSY_TX;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- return HAL_ERROR;
- }
-
- /* Get the number of needed Tx buffers for the current frame, rounding up. */
- bufcount = ( FrameLength + ETH_TX_BUF_SIZE - 1 ) / ETH_TX_BUF_SIZE;
-
- if (bufcount == 1)
- {
- /* Set LAST and FIRST segment */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_FS | ETH_DMATXDESC_LS;
- /* Set frame size */
- pxDmaTxDesc->ControlBufferSize = ( FrameLength & ETH_DMATXDESC_TBS1 );
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_OWN;
- /* Point to next descriptor */
- heth->TxDesc = ( ETH_DMADescTypeDef * ) ( heth->TxDesc->Buffer2NextDescAddr );
- }
- else
- {
- for( i = 0; i < bufcount; i++ )
- {
- /* Clear FIRST and LAST segment bits */
- uint32_t ulStatus = heth->TxDesc->Status & ~( ETH_DMATXDESC_FS | ETH_DMATXDESC_LS );
-
- if( i == 0 )
- {
- /* Setting the first segment bit */
- heth->TxDesc->Status = ulStatus | ETH_DMATXDESC_FS;
- }
-
- /* Program size */
- if (i < (bufcount-1))
- {
- heth->TxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TBS1);
- }
- else
- {
- /* Setting the last segment bit */
- heth->TxDesc->Status = ulStatus | ETH_DMATXDESC_LS;
- size = FrameLength - (bufcount-1)*ETH_TX_BUF_SIZE;
- heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);
- }
-
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
- /* point to next descriptor */
- heth->TxDesc = (ETH_DMADescTypeDef *)( heth->TxDesc->Buffer2NextDescAddr );
- }
- }
-
- __DSB();
-
- /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
- if( ( heth->Instance->DMASR & ETH_DMASR_TBUS ) != ( uint32_t )RESET )
- {
- heth->Instance->DMACHTDR = ( uint32_t )pxDmaTxDesc;
-
- /* Clear TBUS ETHERNET DMA flag */
- heth->Instance->DMASR = ETH_DMASR_TBUS;
- /* Resume DMA transmission*/
- heth->Instance->DMATPDR = 0;
- }
-
- /* Set ETH HAL State to Ready */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Checks for received frames.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT( ETH_HandleTypeDef *heth )
-{
- return HAL_ETH_GetReceivedFrame( heth );
-}
-
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame( ETH_HandleTypeDef *heth )
-{
-uint32_t ulCounter = 0;
-ETH_DMADescTypeDef *pxDescriptor = heth->RxDesc;
-HAL_StatusTypeDef xResult = HAL_ERROR;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Check the ETH state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Scan descriptors owned by CPU */
- while( ( ( pxDescriptor->Status & ETH_DMARXDESC_OWN ) == 0ul ) && ( ulCounter < ETH_RXBUFNB ) )
- {
- uint32_t ulStatus = pxDescriptor->Status;
-
- /* Just for security. */
- ulCounter++;
-
- if( ( ulStatus & ( ETH_DMARXDESC_FS | ETH_DMARXDESC_LS ) ) == ( uint32_t )ETH_DMARXDESC_FS )
- {
- /* First segment in frame, but not the last. */
- heth->RxFrameInfos.FSRxDesc = pxDescriptor;
- heth->RxFrameInfos.LSRxDesc = ( ETH_DMADescTypeDef *)NULL;
- heth->RxFrameInfos.SegCount = 1;
- /* Point to next descriptor. */
- pxDescriptor = (ETH_DMADescTypeDef*) (pxDescriptor->Buffer2NextDescAddr);
- heth->RxDesc = pxDescriptor;
- }
- else if( ( ulStatus & ( ETH_DMARXDESC_LS | ETH_DMARXDESC_FS ) ) == 0ul )
- {
- /* This is an intermediate segment, not first, not last. */
- /* Increment segment count. */
- heth->RxFrameInfos.SegCount++;
- /* Move to the next descriptor. */
- pxDescriptor = ( ETH_DMADescTypeDef * ) ( pxDescriptor->Buffer2NextDescAddr );
- heth->RxDesc = pxDescriptor;
- }
- /* Must be a last segment */
- else
- {
- /* This is the last segment. */
- /* Check if last segment is first segment: one segment contains the frame */
- if( heth->RxFrameInfos.SegCount == 0 )
- {
- /* Remember the first segment. */
- heth->RxFrameInfos.FSRxDesc = pxDescriptor;
- }
-
- /* Increment segment count */
- heth->RxFrameInfos.SegCount++;
-
- /* Remember the last segment. */
- heth->RxFrameInfos.LSRxDesc = pxDescriptor;
-
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- heth->RxFrameInfos.length =
- ( ( ulStatus & ETH_DMARXDESC_FL ) >> ETH_DMARXDESC_FRAMELENGTHSHIFT ) - 4;
-
- /* Get the address of the buffer start address */
- heth->RxFrameInfos.buffer = heth->RxFrameInfos.FSRxDesc->Buffer1Addr;
-
- /* Point to next descriptor */
- heth->RxDesc = ( ETH_DMADescTypeDef * ) pxDescriptor->Buffer2NextDescAddr;
-
- /* Return OK status: a packet was received. */
- xResult = HAL_OK;
- break;
- }
- }
-
- /* Set ETH HAL State to Ready */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return xResult;
-}
-
-#if( STM32_ETHERNET_STATS != 0 )
-
- volatile int rx_count, tx_count, int_count;
- /**
- * @brief This function handles ETH interrupt request.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
- volatile int int_counts[32];
- volatile int tx_status[8];
- volatile unsigned sr_history[32];
- volatile int sr_head;
- #define STM32_STAT_INC( x ) do { ( x )++; } while( 0 )
-
-#else
- #define STM32_STAT_INC( x ) do { } while( 0 )
-#endif /* STM32_ETHERNET_STATS */
-
-#define ETH_DMA_ALL_INTS \
- ( ETH_DMA_IT_TST | ETH_DMA_IT_PMT | ETH_DMA_IT_MMC | ETH_DMA_IT_NIS | ETH_DMA_IT_AIS | ETH_DMA_IT_ER | \
- ETH_DMA_IT_FBE | ETH_DMA_IT_ET | ETH_DMA_IT_RWT | ETH_DMA_IT_RPS | ETH_DMA_IT_RBU | ETH_DMA_IT_R | \
- ETH_DMA_IT_TU | ETH_DMA_IT_RO | ETH_DMA_IT_TJT | ETH_DMA_IT_TPS | ETH_DMA_IT_T )
-
-//#define ETH_DMA_ALL_INTS ETH_DMA_IT_RBU | ETH_DMA_FLAG_T | ETH_DMA_FLAG_AIS
-
-#define INT_MASK ( ( uint32_t ) ~ ( ETH_DMA_IT_TBU ) )
-void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
-{
- uint32_t dmasr;
-
- STM32_STAT_INC( int_count );
-
- dmasr = heth->Instance->DMASR & ETH_DMA_ALL_INTS;
- heth->Instance->DMASR = dmasr;
-
-#if( STM32_ETHERNET_STATS != 0 )
- if( sr_head < ARRAY_SIZE( sr_history ) )
- {
- sr_history[ sr_head++ ] = dmasr;
- }
-
- {
- int i;
- for (i = 0; i < 32; i++) {
- if (dmasr & (1u << i)) {
- int_counts[i]++;
- }
- }
- tx_status[ ( dmasr >> 20 ) & 0x07 ]++;
- }
-#endif
-
- /* Frame received */
- if( ( dmasr & ( ETH_DMA_FLAG_R | ETH_DMA_IT_RBU ) ) != 0 )
- {
- /* Receive complete callback */
- HAL_ETH_RxCpltCallback( heth );
- STM32_STAT_INC( rx_count );
- }
- /* Frame transmitted */
- if( ( dmasr & ( ETH_DMA_FLAG_T ) ) != 0 )
- {
- /* Transfer complete callback */
- HAL_ETH_TxCpltCallback( heth );
- STM32_STAT_INC( tx_count );
- }
-
- /* ETH DMA Error */
- if( ( dmasr & ( ETH_DMA_FLAG_AIS ) ) != 0 )
- {
- /* Ethernet Error callback */
- HAL_ETH_ErrorCallback( heth );
- }
-}
-
-/**
- * @brief Tx Transfer completed callbacks.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Rx Transfer completed callbacks.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Ethernet transfer error callbacks
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Reads a PHY register
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * PHY_BCR: Transceiver Basic Control Register,
- * PHY_BSR: Transceiver Basic Status Register.
- * More PHY register could be read depending on the used PHY
- * @param RegValue: PHY register value
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)
-{
-uint32_t tmpreg = 0;
-uint32_t tickstart = 0;
-HAL_StatusTypeDef xResult;
-
- /* Check parameters */
- assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
-
- /* Check the ETH peripheral state */
- if( heth->State == HAL_ETH_STATE_BUSY_RD )
- {
- xResult = HAL_BUSY;
- }
- else
- {
- __HAL_LOCK( heth );
-
- /* Set ETH HAL State to BUSY_RD */
- heth->State = HAL_ETH_STATE_BUSY_RD;
-
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
-
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~ETH_MACMIIAR_CR_MASK;
-
- /* Prepare the MII address register value */
- tmpreg |= ( ( ( uint32_t )heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA ); /* Set the PHY device address */
- tmpreg |= ( ( ( uint32_t )PHYReg << 6 ) & ETH_MACMIIAR_MR ); /* Set the PHY register address */
- tmpreg &= ~ETH_MACMIIAR_MW; /* Set the read mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
-
- /* Write the result value into the MII Address register */
- heth->Instance->MACMIIAR = tmpreg;
-
- /* Get tick */
- tickstart = HAL_GetTick();
-
- /* Check for the Busy flag */
- while( 1 )
- {
- tmpreg = heth->Instance->MACMIIAR;
-
- if( ( tmpreg & ETH_MACMIIAR_MB ) == 0ul )
- {
- /* Get MACMIIDR value */
- *RegValue = ( uint32_t ) heth->Instance->MACMIIDR;
- xResult = HAL_OK;
- break;
- }
- /* Check for the Timeout */
- if( ( HAL_GetTick( ) - tickstart ) > PHY_READ_TO )
- {
- xResult = HAL_TIMEOUT;
- break;
- }
-
- }
-
- /* Set ETH HAL State to READY */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
- }
-
- if( xResult != HAL_OK )
- {
- lUDPLoggingPrintf( "ReadPHY: %d\n", xResult );
- }
- /* Return function status */
- return xResult;
-}
-
-/**
- * @brief Writes to a PHY register.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * PHY_BCR: Transceiver Control Register.
- * More PHY register could be written depending on the used PHY
- * @param RegValue: the value to write
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)
-{
-uint32_t tmpreg = 0;
-uint32_t tickstart = 0;
-HAL_StatusTypeDef xResult;
-
- /* Check parameters */
- assert_param( IS_ETH_PHY_ADDRESS( heth->Init.PhyAddress ) );
-
- /* Check the ETH peripheral state */
- if( heth->State == HAL_ETH_STATE_BUSY_WR )
- {
- xResult = HAL_BUSY;
- }
- else
- {
- __HAL_LOCK( heth );
-
- /* Set ETH HAL State to BUSY_WR */
- heth->State = HAL_ETH_STATE_BUSY_WR;
-
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
-
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~ETH_MACMIIAR_CR_MASK;
-
- /* Prepare the MII register address value */
- tmpreg |= ( ( ( uint32_t ) heth->Init.PhyAddress << 11 ) & ETH_MACMIIAR_PA ); /* Set the PHY device address */
- tmpreg |= ( ( ( uint32_t ) PHYReg << 6 ) & ETH_MACMIIAR_MR ); /* Set the PHY register address */
- tmpreg |= ETH_MACMIIAR_MW; /* Set the write mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
-
- /* Give the value to the MII data register */
- heth->Instance->MACMIIDR = ( uint16_t ) RegValue;
-
- /* Write the result value into the MII Address register */
- heth->Instance->MACMIIAR = tmpreg;
-
- /* Get tick */
- tickstart = HAL_GetTick();
-
- /* Check for the Busy flag */
- while( 1 )
- {
- tmpreg = heth->Instance->MACMIIAR;
-
- if( ( tmpreg & ETH_MACMIIAR_MB ) == 0ul )
- {
- xResult = HAL_OK;
- break;
- }
- /* Check for the Timeout */
- if( ( HAL_GetTick( ) - tickstart ) > PHY_WRITE_TO )
- {
- xResult = HAL_TIMEOUT;
- break;
- }
- }
-
- /* Set ETH HAL State to READY */
- heth->State = HAL_ETH_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
- }
-
- if( xResult != HAL_OK )
- {
- lUDPLoggingPrintf( "WritePHY: %d\n", xResult );
- }
- /* Return function status */
- return xResult;
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions
- * @brief Peripheral Control functions
- *
-@verbatim
- ===============================================================================
- ##### Peripheral Control functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) Enable MAC and DMA transmission and reception.
- HAL_ETH_Start();
- (+) Disable MAC and DMA transmission and reception.
- HAL_ETH_Stop();
- (+) Set the MAC configuration in runtime mode
- HAL_ETH_ConfigMAC();
- (+) Set the DMA configuration in runtime mode
- HAL_ETH_ConfigDMA();
-
-@endverbatim
- * @{
- */
-
- /**
- * @brief Enables Ethernet MAC and DMA reception/transmission
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Start( ETH_HandleTypeDef *heth )
-{
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Enable transmit state machine of the MAC for transmission on the MII */
- ETH_MACTransmissionEnable( heth );
-
- /* Enable receive state machine of the MAC for reception from the MII */
- ETH_MACReceptionEnable( heth );
-
- /* Flush Transmit FIFO */
- ETH_FlushTransmitFIFO( heth );
-
- /* Start DMA transmission */
- ETH_DMATransmissionEnable( heth );
-
- /* Start DMA reception */
- ETH_DMAReceptionEnable( heth );
-
- /* Set the ETH state to READY*/
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Stop Ethernet MAC and DMA reception/transmission
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
-{
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Stop DMA transmission */
- ETH_DMATransmissionDisable( heth );
-
- /* Stop DMA reception */
- ETH_DMAReceptionDisable( heth );
-
- /* Disable receive state machine of the MAC for reception from the MII */
- ETH_MACReceptionDisable( heth );
-
- /* Flush Transmit FIFO */
- ETH_FlushTransmitFIFO( heth );
-
- /* Disable transmit state machine of the MAC for transmission on the MII */
- ETH_MACTransmissionDisable( heth );
-
- /* Set the ETH state*/
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-static void prvWriteMACFCR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->MACFCR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->MACFCR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->MACFCR = ulValue;
-}
-
-static void prvWriteDMAOMR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->DMAOMR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->DMAOMR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->DMAOMR = ulValue;
-}
-
-static void prvWriteMACCR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->MACCR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->MACCR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->MACCR = ulValue;
-}
-
-/**
- * @brief Set ETH MAC Configuration.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param macconf: MAC Configuration structure
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)
-{
- uint32_t tmpreg = 0;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State= HAL_ETH_STATE_BUSY;
-
- assert_param(IS_ETH_SPEED(heth->Init.Speed));
- assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
-
- if (macconf != NULL)
- {
- /* Check the parameters */
- assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));
- assert_param(IS_ETH_JABBER(macconf->Jabber));
- assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));
- assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));
- assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));
- assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));
- assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));
- assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));
- assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));
- assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));
- assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));
- assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));
- assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));
- assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));
- assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));
- assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));
- assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));
- assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));
- assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));
- assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));
- assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));
- assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));
- assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));
- assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));
- assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));
- assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));
- assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));
-
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
- /* Clear WD, PCE, PS, TE and RE bits */
- tmpreg &= ETH_MACCR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)(
- macconf->Watchdog |
- macconf->Jabber |
- macconf->InterFrameGap |
- macconf->CarrierSense |
- heth->Init.Speed |
- macconf->ReceiveOwn |
- macconf->LoopbackMode |
- heth->Init.DuplexMode |
- macconf->ChecksumOffload |
- macconf->RetryTransmission |
- macconf->AutomaticPadCRCStrip |
- macconf->BackOffLimit |
- macconf->DeferralCheck);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACFFR Configuration --------------------*/
- /* Write to ETHERNET MACFFR */
- heth->Instance->MACFFR = (uint32_t)(
- macconf->ReceiveAll |
- macconf->SourceAddrFilter |
- macconf->PassControlFrames |
- macconf->BroadcastFramesReception |
- macconf->DestinationAddrFilter |
- macconf->PromiscuousMode |
- macconf->MulticastFramesFilter |
- macconf->UnicastFramesFilter);
-
- /* Wait until the write operation will be taken into account :
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACFFR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACFFR = tmpreg;
-
- /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
- /* Write to ETHERNET MACHTHR */
- heth->Instance->MACHTHR = (uint32_t)macconf->HashTableHigh;
-
- /* Write to ETHERNET MACHTLR */
- heth->Instance->MACHTLR = (uint32_t)macconf->HashTableLow;
- /*----------------------- ETHERNET MACFCR Configuration --------------------*/
-
- /* Get the ETHERNET MACFCR value */
- tmpreg = heth->Instance->MACFCR;
- /* Clear xx bits */
- tmpreg &= ETH_MACFCR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)((
- macconf->PauseTime << 16) |
- macconf->ZeroQuantaPause |
- macconf->PauseLowThreshold |
- macconf->UnicastPauseFrameDetect |
- macconf->ReceiveFlowControl |
- macconf->TransmitFlowControl);
-
- /* Write to ETHERNET MACFCR */
- prvWriteMACFCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
- heth->Instance->MACVLANTR = (uint32_t)(macconf->VLANTagComparison |
- macconf->VLANTagIdentifier);
-
- /* Wait until the write operation will be taken into account :
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACVLANTR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACVLANTR = tmpreg;
- }
- else /* macconf == NULL : here we just configure Speed and Duplex mode */
- {
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
-
- /* Clear FES and DM bits */
- tmpreg &= ~((uint32_t)0x00004800);
-
- tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
- }
-
- /* Set the ETH state to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Sets ETH DMA Configuration.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param dmaconf: DMA Configuration structure
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)
-{
- uint32_t tmpreg = 0;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State= HAL_ETH_STATE_BUSY;
-
- /* Check parameters */
- assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));
- assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));
- assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));
- assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));
- assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));
- assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));
- assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));
- assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));
- assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));
- assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));
- assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));
- assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));
- assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));
- assert_param(IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(dmaconf->EnhancedDescriptorFormat));
- assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));
- assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));
-
- /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
- /* Get the ETHERNET DMAOMR value */
- tmpreg = heth->Instance->DMAOMR;
- /* Clear xx bits */
- tmpreg &= ETH_DMAOMR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)(
- dmaconf->DropTCPIPChecksumErrorFrame |
- dmaconf->ReceiveStoreForward |
- dmaconf->FlushReceivedFrame |
- dmaconf->TransmitStoreForward |
- dmaconf->TransmitThresholdControl |
- dmaconf->ForwardErrorFrames |
- dmaconf->ForwardUndersizedGoodFrames |
- dmaconf->ReceiveThresholdControl |
- dmaconf->SecondFrameOperate);
-
- /* Write to ETHERNET DMAOMR */
- prvWriteDMAOMR( heth, tmpreg );
-
- /*----------------------- ETHERNET DMABMR Configuration --------------------*/
- heth->Instance->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats |
- dmaconf->FixedBurst |
- dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
- dmaconf->TxDMABurstLength |
- dmaconf->EnhancedDescriptorFormat |
- (dmaconf->DescriptorSkipLength << 2) |
- dmaconf->DMAArbitration |
- ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->DMABMR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->DMABMR = tmpreg;
-
- /* Set the ETH state to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions
- * @brief Peripheral State functions
- *
- @verbatim
- ===============================================================================
- ##### Peripheral State functions #####
- ===============================================================================
- [..]
- This subsection permits to get in run-time the status of the peripheral
- and the data flow.
- (+) Get the ETH handle state:
- HAL_ETH_GetState();
-
-
- @endverbatim
- * @{
- */
-
-/**
- * @brief Return the ETH HAL state
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL state
- */
-HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)
-{
- /* Return ETH state */
- return heth->State;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/** @addtogroup ETH_Private_Functions
- * @{
- */
-
-/**
- * @brief Configures Ethernet MAC and DMA with default parameters.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param err: Ethernet Init error
- * @retval HAL status
- */
-static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)
-{
- ETH_MACInitTypeDef macinit;
- ETH_DMAInitTypeDef dmainit;
- uint32_t tmpreg = 0;
-
- if (err != ETH_SUCCESS) /* Auto-negotiation failed */
- {
- /* Set Ethernet duplex mode to Full-duplex */
- heth->Init.DuplexMode = ETH_MODE_FULLDUPLEX;
-
- /* Set Ethernet speed to 100M */
- heth->Init.Speed = ETH_SPEED_100M;
- }
-
- /* Ethernet MAC default initialization **************************************/
- macinit.Watchdog = ETH_WATCHDOG_ENABLE;
- macinit.Jabber = ETH_JABBER_ENABLE;
- macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;
- macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;
- macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;
- macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;
- if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
- {
- macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
- }
- else
- {
- macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
- }
- macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;
- macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
- macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;
- macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;
- macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;
- macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
- macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
- macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;
- macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
- macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
- macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
- macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
- macinit.HashTableHigh = 0x0;
- macinit.HashTableLow = 0x0;
- macinit.PauseTime = 0x0;
- macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
- macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
- macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
- macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
- macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
- macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
- macinit.VLANTagIdentifier = 0x0;
-
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
- /* Clear WD, PCE, PS, TE and RE bits */
- tmpreg &= ETH_MACCR_CLEAR_MASK;
- /* Set the WD bit according to ETH Watchdog value */
- /* Set the JD: bit according to ETH Jabber value */
- /* Set the IFG bit according to ETH InterFrameGap value */
- /* Set the DCRS bit according to ETH CarrierSense value */
- /* Set the FES bit according to ETH Speed value */
- /* Set the DO bit according to ETH ReceiveOwn value */
- /* Set the LM bit according to ETH LoopbackMode value */
- /* Set the DM bit according to ETH Mode value */
- /* Set the IPCO bit according to ETH ChecksumOffload value */
- /* Set the DR bit according to ETH RetryTransmission value */
- /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
- /* Set the BL bit according to ETH BackOffLimit value */
- /* Set the DC bit according to ETH DeferralCheck value */
- tmpreg |= (uint32_t)(macinit.Watchdog |
- macinit.Jabber |
- macinit.InterFrameGap |
- macinit.CarrierSense |
- heth->Init.Speed |
- macinit.ReceiveOwn |
- macinit.LoopbackMode |
- heth->Init.DuplexMode |
- macinit.ChecksumOffload |
- macinit.RetryTransmission |
- macinit.AutomaticPadCRCStrip |
- macinit.BackOffLimit |
- macinit.DeferralCheck);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACFFR Configuration --------------------*/
- /* Set the RA bit according to ETH ReceiveAll value */
- /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
- /* Set the PCF bit according to ETH PassControlFrames value */
- /* Set the DBF bit according to ETH BroadcastFramesReception value */
- /* Set the DAIF bit according to ETH DestinationAddrFilter value */
- /* Set the PR bit according to ETH PromiscuousMode value */
- /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
- /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
- /* Write to ETHERNET MACFFR */
- heth->Instance->MACFFR = (uint32_t)(macinit.ReceiveAll |
- macinit.SourceAddrFilter |
- macinit.PassControlFrames |
- macinit.BroadcastFramesReception |
- macinit.DestinationAddrFilter |
- macinit.PromiscuousMode |
- macinit.MulticastFramesFilter |
- macinit.UnicastFramesFilter);
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACFFR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACFFR = tmpreg;
-
- /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/
- /* Write to ETHERNET MACHTHR */
- heth->Instance->MACHTHR = (uint32_t)macinit.HashTableHigh;
-
- /* Write to ETHERNET MACHTLR */
- heth->Instance->MACHTLR = (uint32_t)macinit.HashTableLow;
- /*----------------------- ETHERNET MACFCR Configuration -------------------*/
-
- /* Get the ETHERNET MACFCR value */
- tmpreg = heth->Instance->MACFCR;
- /* Clear xx bits */
- tmpreg &= ETH_MACFCR_CLEAR_MASK;
-
- /* Set the PT bit according to ETH PauseTime value */
- /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
- /* Set the PLT bit according to ETH PauseLowThreshold value */
- /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
- /* Set the RFE bit according to ETH ReceiveFlowControl value */
- /* Set the TFE bit according to ETH TransmitFlowControl value */
- tmpreg |= (uint32_t)((macinit.PauseTime << 16) |
- macinit.ZeroQuantaPause |
- macinit.PauseLowThreshold |
- macinit.UnicastPauseFrameDetect |
- macinit.ReceiveFlowControl |
- macinit.TransmitFlowControl);
-
- /* Write to ETHERNET MACFCR */
- prvWriteMACFCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/
- /* Set the ETV bit according to ETH VLANTagComparison value */
- /* Set the VL bit according to ETH VLANTagIdentifier value */
- heth->Instance->MACVLANTR = (uint32_t)(macinit.VLANTagComparison |
- macinit.VLANTagIdentifier);
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACVLANTR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACVLANTR = tmpreg;
-
- /* Ethernet DMA default initialization ************************************/
- dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;
- dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
- dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
- dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
- dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
- dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
- dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
- dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
- dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;
- dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
- dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;
- dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
- dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
- dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;
- dmainit.DescriptorSkipLength = 0x0;
- dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
-
- /* Get the ETHERNET DMAOMR value */
- tmpreg = heth->Instance->DMAOMR;
- /* Clear xx bits */
- tmpreg &= ETH_DMAOMR_CLEAR_MASK;
-
- /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
- /* Set the RSF bit according to ETH ReceiveStoreForward value */
- /* Set the DFF bit according to ETH FlushReceivedFrame value */
- /* Set the TSF bit according to ETH TransmitStoreForward value */
- /* Set the TTC bit according to ETH TransmitThresholdControl value */
- /* Set the FEF bit according to ETH ForwardErrorFrames value */
- /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
- /* Set the RTC bit according to ETH ReceiveThresholdControl value */
- /* Set the OSF bit according to ETH SecondFrameOperate value */
- tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame |
- dmainit.ReceiveStoreForward |
- dmainit.FlushReceivedFrame |
- dmainit.TransmitStoreForward |
- dmainit.TransmitThresholdControl |
- dmainit.ForwardErrorFrames |
- dmainit.ForwardUndersizedGoodFrames |
- dmainit.ReceiveThresholdControl |
- dmainit.SecondFrameOperate);
-
- /* Write to ETHERNET DMAOMR */
- prvWriteDMAOMR( heth, tmpreg );
-
- /*----------------------- ETHERNET DMABMR Configuration ------------------*/
- /* Set the AAL bit according to ETH AddressAlignedBeats value */
- /* Set the FB bit according to ETH FixedBurst value */
- /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
- /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
- /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/
- /* Set the DSL bit according to ETH DesciptorSkipLength value */
- /* Set the PR and DA bits according to ETH DMAArbitration value */
- heth->Instance->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats |
- dmainit.FixedBurst |
- dmainit.RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
- dmainit.TxDMABurstLength |
- dmainit.EnhancedDescriptorFormat |
- (dmainit.DescriptorSkipLength << 2) |
- dmainit.DMAArbitration |
- ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->DMABMR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->DMABMR = tmpreg;
-
- if(heth->Init.RxMode == ETH_RXINTERRUPT_MODE)
- {
- /* Enable the Ethernet Rx Interrupt */
- __HAL_ETH_DMA_ENABLE_IT(( heth ), ETH_DMA_IT_NIS | ETH_DMA_IT_R);
- }
-
- /* Initialize MAC address in ethernet MAC */
- ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
-}
-
-/**
- * @brief Configures the selected MAC address.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param MacAddr: The MAC address to configure
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address0: MAC Address0
- * @arg ETH_MAC_Address1: MAC Address1
- * @arg ETH_MAC_Address2: MAC Address2
- * @arg ETH_MAC_Address3: MAC Address3
- * @param Addr: Pointer to MAC address buffer data (6 bytes)
- * @retval HAL status
- */
-static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
-{
- uint32_t tmpreg;
-
- /* Check the parameters */
- assert_param( IS_ETH_MAC_ADDRESS0123( MacAddr ) );
-
- /* Calculate the selected MAC address high register */
- tmpreg = 0x80000000ul | ( ( uint32_t )Addr[ 5 ] << 8) | (uint32_t)Addr[ 4 ];
- /* Load the selected MAC address high register */
- ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_HBASE + MacAddr ) ) ) = tmpreg;
- /* Calculate the selected MAC address low register */
- tmpreg = ( ( uint32_t )Addr[ 3 ] << 24 ) | ( ( uint32_t )Addr[ 2 ] << 16 ) | ( ( uint32_t )Addr[ 1 ] << 8 ) | Addr[ 0 ];
-
- /* Load the selected MAC address low register */
- ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_LBASE + MacAddr ) ) ) = tmpreg;
-}
-
-/**
- * @brief Enables the MAC transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_TE;
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the MAC transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_TE );
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the MAC reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)
-{
- __IO uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_RE;
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the MAC reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)
-{
- __IO uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_RE );
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the DMA transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)
-{
- /* Enable the DMA transmission */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_ST;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the DMA transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)
-{
- /* Disable the DMA transmission */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_ST );
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the DMA reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)
-{
- /* Enable the DMA reception */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_SR;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the DMA reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)
-{
- /* Disable the DMA reception */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_SR );
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Clears the ETHERNET transmit FIFO.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)
-{
- /* Set the Flush Transmit FIFO bit */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_FTF;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @}
- */
-
-#endif /* STM32F7xx */
-#endif /* HAL_ETH_MODULE_ENABLED */
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.h
deleted file mode 100755
index 93c3ffc..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32F7xx/stm32f7xx_hal_eth.h
+++ /dev/null
@@ -1,2214 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f7xx_hal_eth.h
- * @author MCD Application Team
- * @version V1.2.2
- * @date 14-April-2017
- * @brief Header file of ETH HAL module.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2017 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F7xx_HAL_ETH_H
-#define __STM32F7xx_HAL_ETH_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f7xx_hal_def.h"
-
-/** @addtogroup STM32F7xx_HAL_Driver
- * @{
- */
-
-/** @addtogroup ETH
- * @{
- */
-
-/** @addtogroup ETH_Private_Macros
- * @{
- */
-#define IS_ETH_PHY_ADDRESS(ADDRESS) ((ADDRESS) <= 0x20)
-#define IS_ETH_AUTONEGOTIATION(CMD) (((CMD) == ETH_AUTONEGOTIATION_ENABLE) || \
- ((CMD) == ETH_AUTONEGOTIATION_DISABLE))
-#define IS_ETH_SPEED(SPEED) (((SPEED) == ETH_SPEED_10M) || \
- ((SPEED) == ETH_SPEED_100M))
-#define IS_ETH_DUPLEX_MODE(MODE) (((MODE) == ETH_MODE_FULLDUPLEX) || \
- ((MODE) == ETH_MODE_HALFDUPLEX))
-#define IS_ETH_RX_MODE(MODE) (((MODE) == ETH_RXPOLLING_MODE) || \
- ((MODE) == ETH_RXINTERRUPT_MODE))
-#define IS_ETH_CHECKSUM_MODE(MODE) (((MODE) == ETH_CHECKSUM_BY_HARDWARE) || \
- ((MODE) == ETH_CHECKSUM_BY_SOFTWARE))
-#define IS_ETH_MEDIA_INTERFACE(MODE) (((MODE) == ETH_MEDIA_INTERFACE_MII) || \
- ((MODE) == ETH_MEDIA_INTERFACE_RMII))
-#define IS_ETH_WATCHDOG(CMD) (((CMD) == ETH_WATCHDOG_ENABLE) || \
- ((CMD) == ETH_WATCHDOG_DISABLE))
-#define IS_ETH_JABBER(CMD) (((CMD) == ETH_JABBER_ENABLE) || \
- ((CMD) == ETH_JABBER_DISABLE))
-#define IS_ETH_INTER_FRAME_GAP(GAP) (((GAP) == ETH_INTERFRAMEGAP_96BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_88BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_80BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_72BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_64BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_56BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_48BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_40BIT))
-#define IS_ETH_CARRIER_SENSE(CMD) (((CMD) == ETH_CARRIERSENCE_ENABLE) || \
- ((CMD) == ETH_CARRIERSENCE_DISABLE))
-#define IS_ETH_RECEIVE_OWN(CMD) (((CMD) == ETH_RECEIVEOWN_ENABLE) || \
- ((CMD) == ETH_RECEIVEOWN_DISABLE))
-#define IS_ETH_LOOPBACK_MODE(CMD) (((CMD) == ETH_LOOPBACKMODE_ENABLE) || \
- ((CMD) == ETH_LOOPBACKMODE_DISABLE))
-#define IS_ETH_CHECKSUM_OFFLOAD(CMD) (((CMD) == ETH_CHECKSUMOFFLAOD_ENABLE) || \
- ((CMD) == ETH_CHECKSUMOFFLAOD_DISABLE))
-#define IS_ETH_RETRY_TRANSMISSION(CMD) (((CMD) == ETH_RETRYTRANSMISSION_ENABLE) || \
- ((CMD) == ETH_RETRYTRANSMISSION_DISABLE))
-#define IS_ETH_AUTOMATIC_PADCRC_STRIP(CMD) (((CMD) == ETH_AUTOMATICPADCRCSTRIP_ENABLE) || \
- ((CMD) == ETH_AUTOMATICPADCRCSTRIP_DISABLE))
-#define IS_ETH_BACKOFF_LIMIT(LIMIT) (((LIMIT) == ETH_BACKOFFLIMIT_10) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_8) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_4) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_1))
-#define IS_ETH_DEFERRAL_CHECK(CMD) (((CMD) == ETH_DEFFERRALCHECK_ENABLE) || \
- ((CMD) == ETH_DEFFERRALCHECK_DISABLE))
-#define IS_ETH_RECEIVE_ALL(CMD) (((CMD) == ETH_RECEIVEALL_ENABLE) || \
- ((CMD) == ETH_RECEIVEAll_DISABLE))
-#define IS_ETH_SOURCE_ADDR_FILTER(CMD) (((CMD) == ETH_SOURCEADDRFILTER_NORMAL_ENABLE) || \
- ((CMD) == ETH_SOURCEADDRFILTER_INVERSE_ENABLE) || \
- ((CMD) == ETH_SOURCEADDRFILTER_DISABLE))
-#define IS_ETH_CONTROL_FRAMES(PASS) (((PASS) == ETH_PASSCONTROLFRAMES_BLOCKALL) || \
- ((PASS) == ETH_PASSCONTROLFRAMES_FORWARDALL) || \
- ((PASS) == ETH_PASSCONTROLFRAMES_FORWARDPASSEDADDRFILTER))
-#define IS_ETH_BROADCAST_FRAMES_RECEPTION(CMD) (((CMD) == ETH_BROADCASTFRAMESRECEPTION_ENABLE) || \
- ((CMD) == ETH_BROADCASTFRAMESRECEPTION_DISABLE))
-#define IS_ETH_DESTINATION_ADDR_FILTER(FILTER) (((FILTER) == ETH_DESTINATIONADDRFILTER_NORMAL) || \
- ((FILTER) == ETH_DESTINATIONADDRFILTER_INVERSE))
-#define IS_ETH_PROMISCUOUS_MODE(CMD) (((CMD) == ETH_PROMISCUOUS_MODE_ENABLE) || \
- ((CMD) == ETH_PROMISCUOUS_MODE_DISABLE))
-#define IS_ETH_MULTICAST_FRAMES_FILTER(FILTER) (((FILTER) == ETH_MULTICASTFRAMESFILTER_PERFECTHASHTABLE) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_HASHTABLE) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_PERFECT) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_NONE))
-#define IS_ETH_UNICAST_FRAMES_FILTER(FILTER) (((FILTER) == ETH_UNICASTFRAMESFILTER_PERFECTHASHTABLE) || \
- ((FILTER) == ETH_UNICASTFRAMESFILTER_HASHTABLE) || \
- ((FILTER) == ETH_UNICASTFRAMESFILTER_PERFECT))
-#define IS_ETH_PAUSE_TIME(TIME) ((TIME) <= 0xFFFF)
-#define IS_ETH_ZEROQUANTA_PAUSE(CMD) (((CMD) == ETH_ZEROQUANTAPAUSE_ENABLE) || \
- ((CMD) == ETH_ZEROQUANTAPAUSE_DISABLE))
-#define IS_ETH_PAUSE_LOW_THRESHOLD(THRESHOLD) (((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS4) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS28) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS144) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS256))
-#define IS_ETH_UNICAST_PAUSE_FRAME_DETECT(CMD) (((CMD) == ETH_UNICASTPAUSEFRAMEDETECT_ENABLE) || \
- ((CMD) == ETH_UNICASTPAUSEFRAMEDETECT_DISABLE))
-#define IS_ETH_RECEIVE_FLOWCONTROL(CMD) (((CMD) == ETH_RECEIVEFLOWCONTROL_ENABLE) || \
- ((CMD) == ETH_RECEIVEFLOWCONTROL_DISABLE))
-#define IS_ETH_TRANSMIT_FLOWCONTROL(CMD) (((CMD) == ETH_TRANSMITFLOWCONTROL_ENABLE) || \
- ((CMD) == ETH_TRANSMITFLOWCONTROL_DISABLE))
-#define IS_ETH_VLAN_TAG_COMPARISON(COMPARISON) (((COMPARISON) == ETH_VLANTAGCOMPARISON_12BIT) || \
- ((COMPARISON) == ETH_VLANTAGCOMPARISON_16BIT))
-#define IS_ETH_VLAN_TAG_IDENTIFIER(IDENTIFIER) ((IDENTIFIER) <= 0xFFFF)
-#define IS_ETH_MAC_ADDRESS0123(ADDRESS) (((ADDRESS) == ETH_MAC_ADDRESS0) || \
- ((ADDRESS) == ETH_MAC_ADDRESS1) || \
- ((ADDRESS) == ETH_MAC_ADDRESS2) || \
- ((ADDRESS) == ETH_MAC_ADDRESS3))
-#define IS_ETH_MAC_ADDRESS123(ADDRESS) (((ADDRESS) == ETH_MAC_ADDRESS1) || \
- ((ADDRESS) == ETH_MAC_ADDRESS2) || \
- ((ADDRESS) == ETH_MAC_ADDRESS3))
-#define IS_ETH_MAC_ADDRESS_FILTER(FILTER) (((FILTER) == ETH_MAC_ADDRESSFILTER_SA) || \
- ((FILTER) == ETH_MAC_ADDRESSFILTER_DA))
-#define IS_ETH_MAC_ADDRESS_MASK(MASK) (((MASK) == ETH_MAC_ADDRESSMASK_BYTE6) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE5) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE4) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE3) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE2) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE1))
-#define IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(CMD) (((CMD) == ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE) || \
- ((CMD) == ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE))
-#define IS_ETH_RECEIVE_STORE_FORWARD(CMD) (((CMD) == ETH_RECEIVESTOREFORWARD_ENABLE) || \
- ((CMD) == ETH_RECEIVESTOREFORWARD_DISABLE))
-#define IS_ETH_FLUSH_RECEIVE_FRAME(CMD) (((CMD) == ETH_FLUSHRECEIVEDFRAME_ENABLE) || \
- ((CMD) == ETH_FLUSHRECEIVEDFRAME_DISABLE))
-#define IS_ETH_TRANSMIT_STORE_FORWARD(CMD) (((CMD) == ETH_TRANSMITSTOREFORWARD_ENABLE) || \
- ((CMD) == ETH_TRANSMITSTOREFORWARD_DISABLE))
-#define IS_ETH_TRANSMIT_THRESHOLD_CONTROL(THRESHOLD) (((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_64BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_128BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_192BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_256BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_40BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_32BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_24BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_16BYTES))
-#define IS_ETH_FORWARD_ERROR_FRAMES(CMD) (((CMD) == ETH_FORWARDERRORFRAMES_ENABLE) || \
- ((CMD) == ETH_FORWARDERRORFRAMES_DISABLE))
-#define IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(CMD) (((CMD) == ETH_FORWARDUNDERSIZEDGOODFRAMES_ENABLE) || \
- ((CMD) == ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE))
-#define IS_ETH_RECEIVE_THRESHOLD_CONTROL(THRESHOLD) (((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_32BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_96BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_128BYTES))
-#define IS_ETH_SECOND_FRAME_OPERATE(CMD) (((CMD) == ETH_SECONDFRAMEOPERARTE_ENABLE) || \
- ((CMD) == ETH_SECONDFRAMEOPERARTE_DISABLE))
-#define IS_ETH_ADDRESS_ALIGNED_BEATS(CMD) (((CMD) == ETH_ADDRESSALIGNEDBEATS_ENABLE) || \
- ((CMD) == ETH_ADDRESSALIGNEDBEATS_DISABLE))
-#define IS_ETH_FIXED_BURST(CMD) (((CMD) == ETH_FIXEDBURST_ENABLE) || \
- ((CMD) == ETH_FIXEDBURST_DISABLE))
-#define IS_ETH_RXDMA_BURST_LENGTH(LENGTH) (((LENGTH) == ETH_RXDMABURSTLENGTH_1BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_2BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_8BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_16BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_32BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_4BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_8BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_16BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_32BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_64BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_128BEAT))
-#define IS_ETH_TXDMA_BURST_LENGTH(LENGTH) (((LENGTH) == ETH_TXDMABURSTLENGTH_1BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_2BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_8BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_16BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_32BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_4BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_8BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_16BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_32BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_64BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_128BEAT))
-#define IS_ETH_DMA_DESC_SKIP_LENGTH(LENGTH) ((LENGTH) <= 0x1F)
-#define IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(RATIO) (((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_2_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_3_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1) || \
- ((RATIO) == ETH_DMAARBITRATION_RXPRIORTX))
-#define IS_ETH_DMATXDESC_GET_FLAG(FLAG) (((FLAG) == ETH_DMATXDESC_OWN) || \
- ((FLAG) == ETH_DMATXDESC_IC) || \
- ((FLAG) == ETH_DMATXDESC_LS) || \
- ((FLAG) == ETH_DMATXDESC_FS) || \
- ((FLAG) == ETH_DMATXDESC_DC) || \
- ((FLAG) == ETH_DMATXDESC_DP) || \
- ((FLAG) == ETH_DMATXDESC_TTSE) || \
- ((FLAG) == ETH_DMATXDESC_TER) || \
- ((FLAG) == ETH_DMATXDESC_TCH) || \
- ((FLAG) == ETH_DMATXDESC_TTSS) || \
- ((FLAG) == ETH_DMATXDESC_IHE) || \
- ((FLAG) == ETH_DMATXDESC_ES) || \
- ((FLAG) == ETH_DMATXDESC_JT) || \
- ((FLAG) == ETH_DMATXDESC_FF) || \
- ((FLAG) == ETH_DMATXDESC_PCE) || \
- ((FLAG) == ETH_DMATXDESC_LCA) || \
- ((FLAG) == ETH_DMATXDESC_NC) || \
- ((FLAG) == ETH_DMATXDESC_LCO) || \
- ((FLAG) == ETH_DMATXDESC_EC) || \
- ((FLAG) == ETH_DMATXDESC_VF) || \
- ((FLAG) == ETH_DMATXDESC_CC) || \
- ((FLAG) == ETH_DMATXDESC_ED) || \
- ((FLAG) == ETH_DMATXDESC_UF) || \
- ((FLAG) == ETH_DMATXDESC_DB))
-#define IS_ETH_DMA_TXDESC_SEGMENT(SEGMENT) (((SEGMENT) == ETH_DMATXDESC_LASTSEGMENTS) || \
- ((SEGMENT) == ETH_DMATXDESC_FIRSTSEGMENT))
-#define IS_ETH_DMA_TXDESC_CHECKSUM(CHECKSUM) (((CHECKSUM) == ETH_DMATXDESC_CHECKSUMBYPASS) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMIPV4HEADER) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL))
-#define IS_ETH_DMATXDESC_BUFFER_SIZE(SIZE) ((SIZE) <= 0x1FFF)
-#define IS_ETH_DMARXDESC_GET_FLAG(FLAG) (((FLAG) == ETH_DMARXDESC_OWN) || \
- ((FLAG) == ETH_DMARXDESC_AFM) || \
- ((FLAG) == ETH_DMARXDESC_ES) || \
- ((FLAG) == ETH_DMARXDESC_DE) || \
- ((FLAG) == ETH_DMARXDESC_SAF) || \
- ((FLAG) == ETH_DMARXDESC_LE) || \
- ((FLAG) == ETH_DMARXDESC_OE) || \
- ((FLAG) == ETH_DMARXDESC_VLAN) || \
- ((FLAG) == ETH_DMARXDESC_FS) || \
- ((FLAG) == ETH_DMARXDESC_LS) || \
- ((FLAG) == ETH_DMARXDESC_IPV4HCE) || \
- ((FLAG) == ETH_DMARXDESC_LC) || \
- ((FLAG) == ETH_DMARXDESC_FT) || \
- ((FLAG) == ETH_DMARXDESC_RWT) || \
- ((FLAG) == ETH_DMARXDESC_RE) || \
- ((FLAG) == ETH_DMARXDESC_DBE) || \
- ((FLAG) == ETH_DMARXDESC_CE) || \
- ((FLAG) == ETH_DMARXDESC_MAMPCE))
-#define IS_ETH_DMA_RXDESC_BUFFER(BUFFER) (((BUFFER) == ETH_DMARXDESC_BUFFER1) || \
- ((BUFFER) == ETH_DMARXDESC_BUFFER2))
-#define IS_ETH_PMT_GET_FLAG(FLAG) (((FLAG) == ETH_PMT_FLAG_WUFR) || \
- ((FLAG) == ETH_PMT_FLAG_MPR))
-#define IS_ETH_DMA_FLAG(FLAG) ((((FLAG) & (uint32_t)0xC7FE1800) == 0x00) && ((FLAG) != 0x00))
-#define IS_ETH_DMA_GET_FLAG(FLAG) (((FLAG) == ETH_DMA_FLAG_TST) || ((FLAG) == ETH_DMA_FLAG_PMT) || \
- ((FLAG) == ETH_DMA_FLAG_MMC) || ((FLAG) == ETH_DMA_FLAG_DATATRANSFERERROR) || \
- ((FLAG) == ETH_DMA_FLAG_READWRITEERROR) || ((FLAG) == ETH_DMA_FLAG_ACCESSERROR) || \
- ((FLAG) == ETH_DMA_FLAG_NIS) || ((FLAG) == ETH_DMA_FLAG_AIS) || \
- ((FLAG) == ETH_DMA_FLAG_ER) || ((FLAG) == ETH_DMA_FLAG_FBE) || \
- ((FLAG) == ETH_DMA_FLAG_ET) || ((FLAG) == ETH_DMA_FLAG_RWT) || \
- ((FLAG) == ETH_DMA_FLAG_RPS) || ((FLAG) == ETH_DMA_FLAG_RBU) || \
- ((FLAG) == ETH_DMA_FLAG_R) || ((FLAG) == ETH_DMA_FLAG_TU) || \
- ((FLAG) == ETH_DMA_FLAG_RO) || ((FLAG) == ETH_DMA_FLAG_TJT) || \
- ((FLAG) == ETH_DMA_FLAG_TBU) || ((FLAG) == ETH_DMA_FLAG_TPS) || \
- ((FLAG) == ETH_DMA_FLAG_T))
-#define IS_ETH_MAC_IT(IT) ((((IT) & (uint32_t)0xFFFFFDF1) == 0x00) && ((IT) != 0x00))
-#define IS_ETH_MAC_GET_IT(IT) (((IT) == ETH_MAC_IT_TST) || ((IT) == ETH_MAC_IT_MMCT) || \
- ((IT) == ETH_MAC_IT_MMCR) || ((IT) == ETH_MAC_IT_MMC) || \
- ((IT) == ETH_MAC_IT_PMT))
-#define IS_ETH_MAC_GET_FLAG(FLAG) (((FLAG) == ETH_MAC_FLAG_TST) || ((FLAG) == ETH_MAC_FLAG_MMCT) || \
- ((FLAG) == ETH_MAC_FLAG_MMCR) || ((FLAG) == ETH_MAC_FLAG_MMC) || \
- ((FLAG) == ETH_MAC_FLAG_PMT))
-#define IS_ETH_DMA_IT(IT) ((((IT) & (uint32_t)0xC7FE1800) == 0x00) && ((IT) != 0x00))
-#define IS_ETH_DMA_GET_IT(IT) (((IT) == ETH_DMA_IT_TST) || ((IT) == ETH_DMA_IT_PMT) || \
- ((IT) == ETH_DMA_IT_MMC) || ((IT) == ETH_DMA_IT_NIS) || \
- ((IT) == ETH_DMA_IT_AIS) || ((IT) == ETH_DMA_IT_ER) || \
- ((IT) == ETH_DMA_IT_FBE) || ((IT) == ETH_DMA_IT_ET) || \
- ((IT) == ETH_DMA_IT_RWT) || ((IT) == ETH_DMA_IT_RPS) || \
- ((IT) == ETH_DMA_IT_RBU) || ((IT) == ETH_DMA_IT_R) || \
- ((IT) == ETH_DMA_IT_TU) || ((IT) == ETH_DMA_IT_RO) || \
- ((IT) == ETH_DMA_IT_TJT) || ((IT) == ETH_DMA_IT_TBU) || \
- ((IT) == ETH_DMA_IT_TPS) || ((IT) == ETH_DMA_IT_T))
-#define IS_ETH_DMA_GET_OVERFLOW(OVERFLOW) (((OVERFLOW) == ETH_DMA_OVERFLOW_RXFIFOCOUNTER) || \
- ((OVERFLOW) == ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER))
-#define IS_ETH_MMC_IT(IT) (((((IT) & (uint32_t)0xFFDF3FFF) == 0x00) || (((IT) & (uint32_t)0xEFFDFF9F) == 0x00)) && \
- ((IT) != 0x00))
-#define IS_ETH_MMC_GET_IT(IT) (((IT) == ETH_MMC_IT_TGF) || ((IT) == ETH_MMC_IT_TGFMSC) || \
- ((IT) == ETH_MMC_IT_TGFSC) || ((IT) == ETH_MMC_IT_RGUF) || \
- ((IT) == ETH_MMC_IT_RFAE) || ((IT) == ETH_MMC_IT_RFCE))
-#define IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(CMD) (((CMD) == ETH_DMAENHANCEDDESCRIPTOR_ENABLE) || \
- ((CMD) == ETH_DMAENHANCEDDESCRIPTOR_DISABLE))
-
-
-/**
- * @}
- */
-
-/** @addtogroup ETH_Private_Defines
- * @{
- */
-/* Delay to wait when writing to some Ethernet registers */
-#define ETH_REG_WRITE_DELAY ((uint32_t)0x00000001U)
-
-/* Ethernet Errors */
-#define ETH_SUCCESS ((uint32_t)0U)
-#define ETH_ERROR ((uint32_t)1U)
-
-/* Ethernet DMA Tx descriptors Collision Count Shift */
-#define ETH_DMATXDESC_COLLISION_COUNTSHIFT ((uint32_t)3U)
-
-/* Ethernet DMA Tx descriptors Buffer2 Size Shift */
-#define ETH_DMATXDESC_BUFFER2_SIZESHIFT ((uint32_t)16U)
-
-/* Ethernet DMA Rx descriptors Frame Length Shift */
-#define ETH_DMARXDESC_FRAME_LENGTHSHIFT ((uint32_t)16U)
-
-/* Ethernet DMA Rx descriptors Buffer2 Size Shift */
-#define ETH_DMARXDESC_BUFFER2_SIZESHIFT ((uint32_t)16U)
-
-/* Ethernet DMA Rx descriptors Frame length Shift */
-#define ETH_DMARXDESC_FRAMELENGTHSHIFT ((uint32_t)16)
-
-/* Ethernet MAC address offsets */
-#define ETH_MAC_ADDR_HBASE (uint32_t)(ETH_MAC_BASE + (uint32_t)0x40U) /* Ethernet MAC address high offset */
-#define ETH_MAC_ADDR_LBASE (uint32_t)(ETH_MAC_BASE + (uint32_t)0x44U) /* Ethernet MAC address low offset */
-
-/* Ethernet MACMIIAR register Mask */
-#define ETH_MACMIIAR_CR_MASK ((uint32_t)0xFFFFFFE3U)
-
-/* Ethernet MACCR register Mask */
-#define ETH_MACCR_CLEAR_MASK ((uint32_t)0xFF20810FU)
-
-/* Ethernet MACFCR register Mask */
-#define ETH_MACFCR_CLEAR_MASK ((uint32_t)0x0000FF41U)
-
-/* Ethernet DMAOMR register Mask */
-#define ETH_DMAOMR_CLEAR_MASK ((uint32_t)0xF8DE3F23U)
-
-/* Ethernet Remote Wake-up frame register length */
-#define ETH_WAKEUP_REGISTER_LENGTH 8U
-
-/* Ethernet Missed frames counter Shift */
-#define ETH_DMA_RX_OVERFLOW_MISSEDFRAMES_COUNTERSHIFT 17U
- /**
- * @}
- */
-
-/* Exported types ------------------------------------------------------------*/
-/** @defgroup ETH_Exported_Types ETH Exported Types
- * @{
- */
-
-/**
- * @brief HAL State structures definition
- */
-typedef enum
-{
- HAL_ETH_STATE_RESET = 0x00U, /*!< Peripheral not yet Initialized or disabled */
- HAL_ETH_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
- HAL_ETH_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
- HAL_ETH_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
- HAL_ETH_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
- HAL_ETH_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission and Reception process is ongoing */
- HAL_ETH_STATE_BUSY_WR = 0x42U, /*!< Write process is ongoing */
- HAL_ETH_STATE_BUSY_RD = 0x82U, /*!< Read process is ongoing */
- HAL_ETH_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
- HAL_ETH_STATE_ERROR = 0x04U /*!< Reception process is ongoing */
-}HAL_ETH_StateTypeDef;
-
-/**
- * @brief ETH Init Structure definition
- */
-
-typedef struct
-{
- uint32_t AutoNegotiation; /*!< Selects or not the AutoNegotiation mode for the external PHY
- The AutoNegotiation allows an automatic setting of the Speed (10/100Mbps)
- and the mode (half/full-duplex).
- This parameter can be a value of @ref ETH_AutoNegotiation */
-
- uint32_t Speed; /*!< Sets the Ethernet speed: 10/100 Mbps.
- This parameter can be a value of @ref ETH_Speed */
-
- uint32_t DuplexMode; /*!< Selects the MAC duplex mode: Half-Duplex or Full-Duplex mode
- This parameter can be a value of @ref ETH_Duplex_Mode */
-
- uint16_t PhyAddress; /*!< Ethernet PHY address.
- This parameter must be a number between Min_Data = 0 and Max_Data = 32 */
-
- uint8_t *MACAddr; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */
-
- uint32_t RxMode; /*!< Selects the Ethernet Rx mode: Polling mode, Interrupt mode.
- This parameter can be a value of @ref ETH_Rx_Mode */
-
- uint32_t ChecksumMode; /*!< Selects if the checksum is check by hardware or by software.
- This parameter can be a value of @ref ETH_Checksum_Mode */
-
- uint32_t MediaInterface ; /*!< Selects the media-independent interface or the reduced media-independent interface.
- This parameter can be a value of @ref ETH_Media_Interface */
-
-} ETH_InitTypeDef;
-
-
- /**
- * @brief ETH MAC Configuration Structure definition
- */
-
-typedef struct
-{
- uint32_t Watchdog; /*!< Selects or not the Watchdog timer
- When enabled, the MAC allows no more then 2048 bytes to be received.
- When disabled, the MAC can receive up to 16384 bytes.
- This parameter can be a value of @ref ETH_Watchdog */
-
- uint32_t Jabber; /*!< Selects or not Jabber timer
- When enabled, the MAC allows no more then 2048 bytes to be sent.
- When disabled, the MAC can send up to 16384 bytes.
- This parameter can be a value of @ref ETH_Jabber */
-
- uint32_t InterFrameGap; /*!< Selects the minimum IFG between frames during transmission.
- This parameter can be a value of @ref ETH_Inter_Frame_Gap */
-
- uint32_t CarrierSense; /*!< Selects or not the Carrier Sense.
- This parameter can be a value of @ref ETH_Carrier_Sense */
-
- uint32_t ReceiveOwn; /*!< Selects or not the ReceiveOwn,
- ReceiveOwn allows the reception of frames when the TX_EN signal is asserted
- in Half-Duplex mode.
- This parameter can be a value of @ref ETH_Receive_Own */
-
- uint32_t LoopbackMode; /*!< Selects or not the internal MAC MII Loopback mode.
- This parameter can be a value of @ref ETH_Loop_Back_Mode */
-
- uint32_t ChecksumOffload; /*!< Selects or not the IPv4 checksum checking for received frame payloads' TCP/UDP/ICMP headers.
- This parameter can be a value of @ref ETH_Checksum_Offload */
-
- uint32_t RetryTransmission; /*!< Selects or not the MAC attempt retries transmission, based on the settings of BL,
- when a collision occurs (Half-Duplex mode).
- This parameter can be a value of @ref ETH_Retry_Transmission */
-
- uint32_t AutomaticPadCRCStrip; /*!< Selects or not the Automatic MAC Pad/CRC Stripping.
- This parameter can be a value of @ref ETH_Automatic_Pad_CRC_Strip */
-
- uint32_t BackOffLimit; /*!< Selects the BackOff limit value.
- This parameter can be a value of @ref ETH_Back_Off_Limit */
-
- uint32_t DeferralCheck; /*!< Selects or not the deferral check function (Half-Duplex mode).
- This parameter can be a value of @ref ETH_Deferral_Check */
-
- uint32_t ReceiveAll; /*!< Selects or not all frames reception by the MAC (No filtering).
- This parameter can be a value of @ref ETH_Receive_All */
-
- uint32_t SourceAddrFilter; /*!< Selects the Source Address Filter mode.
- This parameter can be a value of @ref ETH_Source_Addr_Filter */
-
- uint32_t PassControlFrames; /*!< Sets the forwarding mode of the control frames (including unicast and multicast PAUSE frames)
- This parameter can be a value of @ref ETH_Pass_Control_Frames */
-
- uint32_t BroadcastFramesReception; /*!< Selects or not the reception of Broadcast Frames.
- This parameter can be a value of @ref ETH_Broadcast_Frames_Reception */
-
- uint32_t DestinationAddrFilter; /*!< Sets the destination filter mode for both unicast and multicast frames.
- This parameter can be a value of @ref ETH_Destination_Addr_Filter */
-
- uint32_t PromiscuousMode; /*!< Selects or not the Promiscuous Mode
- This parameter can be a value of @ref ETH_Promiscuous_Mode */
-
- uint32_t MulticastFramesFilter; /*!< Selects the Multicast Frames filter mode: None/HashTableFilter/PerfectFilter/PerfectHashTableFilter.
- This parameter can be a value of @ref ETH_Multicast_Frames_Filter */
-
- uint32_t UnicastFramesFilter; /*!< Selects the Unicast Frames filter mode: HashTableFilter/PerfectFilter/PerfectHashTableFilter.
- This parameter can be a value of @ref ETH_Unicast_Frames_Filter */
-
- uint32_t HashTableHigh; /*!< This field holds the higher 32 bits of Hash table.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFFFFFF */
-
- uint32_t HashTableLow; /*!< This field holds the lower 32 bits of Hash table.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFFFFFF */
-
- uint32_t PauseTime; /*!< This field holds the value to be used in the Pause Time field in the transmit control frame.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFF */
-
- uint32_t ZeroQuantaPause; /*!< Selects or not the automatic generation of Zero-Quanta Pause Control frames.
- This parameter can be a value of @ref ETH_Zero_Quanta_Pause */
-
- uint32_t PauseLowThreshold; /*!< This field configures the threshold of the PAUSE to be checked for
- automatic retransmission of PAUSE Frame.
- This parameter can be a value of @ref ETH_Pause_Low_Threshold */
-
- uint32_t UnicastPauseFrameDetect; /*!< Selects or not the MAC detection of the Pause frames (with MAC Address0
- unicast address and unique multicast address).
- This parameter can be a value of @ref ETH_Unicast_Pause_Frame_Detect */
-
- uint32_t ReceiveFlowControl; /*!< Enables or disables the MAC to decode the received Pause frame and
- disable its transmitter for a specified time (Pause Time)
- This parameter can be a value of @ref ETH_Receive_Flow_Control */
-
- uint32_t TransmitFlowControl; /*!< Enables or disables the MAC to transmit Pause frames (Full-Duplex mode)
- or the MAC back-pressure operation (Half-Duplex mode)
- This parameter can be a value of @ref ETH_Transmit_Flow_Control */
-
- uint32_t VLANTagComparison; /*!< Selects the 12-bit VLAN identifier or the complete 16-bit VLAN tag for
- comparison and filtering.
- This parameter can be a value of @ref ETH_VLAN_Tag_Comparison */
-
- uint32_t VLANTagIdentifier; /*!< Holds the VLAN tag identifier for receive frames */
-
-} ETH_MACInitTypeDef;
-
-
-/**
- * @brief ETH DMA Configuration Structure definition
- */
-
-typedef struct
-{
- uint32_t DropTCPIPChecksumErrorFrame; /*!< Selects or not the Dropping of TCP/IP Checksum Error Frames.
- This parameter can be a value of @ref ETH_Drop_TCP_IP_Checksum_Error_Frame */
-
- uint32_t ReceiveStoreForward; /*!< Enables or disables the Receive store and forward mode.
- This parameter can be a value of @ref ETH_Receive_Store_Forward */
-
- uint32_t FlushReceivedFrame; /*!< Enables or disables the flushing of received frames.
- This parameter can be a value of @ref ETH_Flush_Received_Frame */
-
- uint32_t TransmitStoreForward; /*!< Enables or disables Transmit store and forward mode.
- This parameter can be a value of @ref ETH_Transmit_Store_Forward */
-
- uint32_t TransmitThresholdControl; /*!< Selects or not the Transmit Threshold Control.
- This parameter can be a value of @ref ETH_Transmit_Threshold_Control */
-
- uint32_t ForwardErrorFrames; /*!< Selects or not the forward to the DMA of erroneous frames.
- This parameter can be a value of @ref ETH_Forward_Error_Frames */
-
- uint32_t ForwardUndersizedGoodFrames; /*!< Enables or disables the Rx FIFO to forward Undersized frames (frames with no Error
- and length less than 64 bytes) including pad-bytes and CRC)
- This parameter can be a value of @ref ETH_Forward_Undersized_Good_Frames */
-
- uint32_t ReceiveThresholdControl; /*!< Selects the threshold level of the Receive FIFO.
- This parameter can be a value of @ref ETH_Receive_Threshold_Control */
-
- uint32_t SecondFrameOperate; /*!< Selects or not the Operate on second frame mode, which allows the DMA to process a second
- frame of Transmit data even before obtaining the status for the first frame.
- This parameter can be a value of @ref ETH_Second_Frame_Operate */
-
- uint32_t AddressAlignedBeats; /*!< Enables or disables the Address Aligned Beats.
- This parameter can be a value of @ref ETH_Address_Aligned_Beats */
-
- uint32_t FixedBurst; /*!< Enables or disables the AHB Master interface fixed burst transfers.
- This parameter can be a value of @ref ETH_Fixed_Burst */
-
- uint32_t RxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Rx DMA transaction.
- This parameter can be a value of @ref ETH_Rx_DMA_Burst_Length */
-
- uint32_t TxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Tx DMA transaction.
- This parameter can be a value of @ref ETH_Tx_DMA_Burst_Length */
-
- uint32_t EnhancedDescriptorFormat; /*!< Enables the enhanced descriptor format.
- This parameter can be a value of @ref ETH_DMA_Enhanced_descriptor_format */
-
- uint32_t DescriptorSkipLength; /*!< Specifies the number of word to skip between two unchained descriptors (Ring mode)
- This parameter must be a number between Min_Data = 0 and Max_Data = 32 */
-
- uint32_t DMAArbitration; /*!< Selects the DMA Tx/Rx arbitration.
- This parameter can be a value of @ref ETH_DMA_Arbitration */
-} ETH_DMAInitTypeDef;
-
-
-/**
- * @brief ETH DMA Descriptors data structure definition
- */
-
-typedef struct
-{
- __IO uint32_t Status; /*!< Status */
-
- uint32_t ControlBufferSize; /*!< Control and Buffer1, Buffer2 lengths */
-
- uint32_t Buffer1Addr; /*!< Buffer1 address pointer */
-
- uint32_t Buffer2NextDescAddr; /*!< Buffer2 or next descriptor address pointer */
-
- /*!< Enhanced Ethernet DMA PTP Descriptors */
- uint32_t ExtendedStatus; /*!< Extended status for PTP receive descriptor */
-
- uint32_t Reserved1; /*!< Reserved */
-
- uint32_t TimeStampLow; /*!< Time Stamp Low value for transmit and receive */
-
- uint32_t TimeStampHigh; /*!< Time Stamp High value for transmit and receive */
-
-} ETH_DMADescTypeDef;
-
-
-/**
- * @brief Received Frame Informations structure definition
- */
-typedef struct
-{
- ETH_DMADescTypeDef *FSRxDesc; /*!< First Segment Rx Desc */
-
- ETH_DMADescTypeDef *LSRxDesc; /*!< Last Segment Rx Desc */
-
- uint32_t SegCount; /*!< Segment count */
-
- uint32_t length; /*!< Frame length */
-
- uint32_t buffer; /*!< Frame buffer */
-
-} ETH_DMARxFrameInfos;
-
-
-/**
- * @brief ETH Handle Structure definition
- */
-
-typedef struct
-{
- ETH_TypeDef *Instance; /*!< Register base address */
-
- ETH_InitTypeDef Init; /*!< Ethernet Init Configuration */
-
- uint32_t LinkStatus; /*!< Ethernet link status */
-
- ETH_DMADescTypeDef *RxDesc; /*!< Rx descriptor to Get */
-
- ETH_DMADescTypeDef *TxDesc; /*!< Tx descriptor to Set */
-
- ETH_DMARxFrameInfos RxFrameInfos; /*!< last Rx frame infos */
-
- __IO HAL_ETH_StateTypeDef State; /*!< ETH communication state */
-
- HAL_LockTypeDef Lock; /*!< ETH Lock */
-
-} ETH_HandleTypeDef;
-
- /**
- * @}
- */
-
-/* Exported constants --------------------------------------------------------*/
-/** @defgroup ETH_Exported_Constants ETH Exported Constants
- * @{
- */
-
-/** @defgroup ETH_Buffers_setting ETH Buffers setting
- * @{
- */
-#define ETH_MAX_PACKET_SIZE ((uint32_t)1524U) /*!< ETH_HEADER + ETH_EXTRA + ETH_VLAN_TAG + ETH_MAX_ETH_PAYLOAD + ETH_CRC */
-#define ETH_HEADER ((uint32_t)14U) /*!< 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */
-#define ETH_CRC ((uint32_t)4U) /*!< Ethernet CRC */
-#define ETH_EXTRA ((uint32_t)2U) /*!< Extra bytes in some cases */
-#define ETH_VLAN_TAG ((uint32_t)4U) /*!< optional 802.1q VLAN Tag */
-#define ETH_MIN_ETH_PAYLOAD ((uint32_t)46U) /*!< Minimum Ethernet payload size */
-#define ETH_MAX_ETH_PAYLOAD ((uint32_t)1500U) /*!< Maximum Ethernet payload size */
-#define ETH_JUMBO_FRAME_PAYLOAD ((uint32_t)9000U) /*!< Jumbo frame payload size */
-
- /* Ethernet driver receive buffers are organized in a chained linked-list, when
- an Ethernet packet is received, the Rx-DMA will transfer the packet from RxFIFO
- to the driver receive buffers memory.
-
- Depending on the size of the received Ethernet packet and the size of
- each Ethernet driver receive buffer, the received packet can take one or more
- Ethernet driver receive buffer.
-
- In below are defined the size of one Ethernet driver receive buffer ETH_RX_BUF_SIZE
- and the total count of the driver receive buffers ETH_RXBUFNB.
-
- The configured value for ETH_RX_BUF_SIZE and ETH_RXBUFNB are only provided as
- example, they can be reconfigured in the application layer to fit the application
- needs */
-
-/* Here we configure each Ethernet driver receive buffer to fit the Max size Ethernet
- packet */
-#ifndef ETH_RX_BUF_SIZE
- #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE
-#endif
-
-/* 5 Ethernet driver receive buffers are used (in a chained linked list)*/
-#ifndef ETH_RXBUFNB
- #define ETH_RXBUFNB ((uint32_t)5U) /* 5 Rx buffers of size ETH_RX_BUF_SIZE */
-#endif
-
-
- /* Ethernet driver transmit buffers are organized in a chained linked-list, when
- an Ethernet packet is transmitted, Tx-DMA will transfer the packet from the
- driver transmit buffers memory to the TxFIFO.
-
- Depending on the size of the Ethernet packet to be transmitted and the size of
- each Ethernet driver transmit buffer, the packet to be transmitted can take
- one or more Ethernet driver transmit buffer.
-
- In below are defined the size of one Ethernet driver transmit buffer ETH_TX_BUF_SIZE
- and the total count of the driver transmit buffers ETH_TXBUFNB.
-
- The configured value for ETH_TX_BUF_SIZE and ETH_TXBUFNB are only provided as
- example, they can be reconfigured in the application layer to fit the application
- needs */
-
-/* Here we configure each Ethernet driver transmit buffer to fit the Max size Ethernet
- packet */
-#ifndef ETH_TX_BUF_SIZE
- #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE
-#endif
-
-/* 5 Ethernet driver transmit buffers are used (in a chained linked list)*/
-#ifndef ETH_TXBUFNB
- #define ETH_TXBUFNB ((uint32_t)5U) /* 5 Tx buffers of size ETH_TX_BUF_SIZE */
-#endif
-
- /**
- * @}
- */
-
-/** @defgroup ETH_DMA_TX_Descriptor ETH DMA TX Descriptor
- * @{
- */
-
-/*
- DMA Tx Descriptor
- -----------------------------------------------------------------------------------------------
- TDES0 | OWN(31) | CTRL[30:26] | Reserved[25:24] | CTRL[23:20] | Reserved[19:17] | Status[16:0] |
- -----------------------------------------------------------------------------------------------
- TDES1 | Reserved[31:29] | Buffer2 ByteCount[28:16] | Reserved[15:13] | Buffer1 ByteCount[12:0] |
- -----------------------------------------------------------------------------------------------
- TDES2 | Buffer1 Address [31:0] |
- -----------------------------------------------------------------------------------------------
- TDES3 | Buffer2 Address [31:0] / Next Descriptor Address [31:0] |
- -----------------------------------------------------------------------------------------------
-*/
-
-/**
- * @brief Bit definition of TDES0 register: DMA Tx descriptor status register
- */
-#define ETH_DMATXDESC_OWN ((uint32_t)0x80000000U) /*!< OWN bit: descriptor is owned by DMA engine */
-#define ETH_DMATXDESC_IC ((uint32_t)0x40000000U) /*!< Interrupt on Completion */
-#define ETH_DMATXDESC_LS ((uint32_t)0x20000000U) /*!< Last Segment */
-#define ETH_DMATXDESC_FS ((uint32_t)0x10000000U) /*!< First Segment */
-#define ETH_DMATXDESC_DC ((uint32_t)0x08000000U) /*!< Disable CRC */
-#define ETH_DMATXDESC_DP ((uint32_t)0x04000000U) /*!< Disable Padding */
-#define ETH_DMATXDESC_TTSE ((uint32_t)0x02000000U) /*!< Transmit Time Stamp Enable */
-#define ETH_DMATXDESC_CIC ((uint32_t)0x00C00000U) /*!< Checksum Insertion Control: 4 cases */
-#define ETH_DMATXDESC_CIC_BYPASS ((uint32_t)0x00000000U) /*!< Do Nothing: Checksum Engine is bypassed */
-#define ETH_DMATXDESC_CIC_IPV4HEADER ((uint32_t)0x00400000U) /*!< IPV4 header Checksum Insertion */
-#define ETH_DMATXDESC_CIC_TCPUDPICMP_SEGMENT ((uint32_t)0x00800000U) /*!< TCP/UDP/ICMP Checksum Insertion calculated over segment only */
-#define ETH_DMATXDESC_CIC_TCPUDPICMP_FULL ((uint32_t)0x00C00000U) /*!< TCP/UDP/ICMP Checksum Insertion fully calculated */
-#define ETH_DMATXDESC_TER ((uint32_t)0x00200000U) /*!< Transmit End of Ring */
-#define ETH_DMATXDESC_TCH ((uint32_t)0x00100000U) /*!< Second Address Chained */
-#define ETH_DMATXDESC_TTSS ((uint32_t)0x00020000U) /*!< Tx Time Stamp Status */
-#define ETH_DMATXDESC_IHE ((uint32_t)0x00010000U) /*!< IP Header Error */
-#define ETH_DMATXDESC_ES ((uint32_t)0x00008000U) /*!< Error summary: OR of the following bits: UE || ED || EC || LCO || NC || LCA || FF || JT */
-#define ETH_DMATXDESC_JT ((uint32_t)0x00004000U) /*!< Jabber Timeout */
-#define ETH_DMATXDESC_FF ((uint32_t)0x00002000U) /*!< Frame Flushed: DMA/MTL flushed the frame due to SW flush */
-#define ETH_DMATXDESC_PCE ((uint32_t)0x00001000U) /*!< Payload Checksum Error */
-#define ETH_DMATXDESC_LCA ((uint32_t)0x00000800U) /*!< Loss of Carrier: carrier lost during transmission */
-#define ETH_DMATXDESC_NC ((uint32_t)0x00000400U) /*!< No Carrier: no carrier signal from the transceiver */
-#define ETH_DMATXDESC_LCO ((uint32_t)0x00000200U) /*!< Late Collision: transmission aborted due to collision */
-#define ETH_DMATXDESC_EC ((uint32_t)0x00000100U) /*!< Excessive Collision: transmission aborted after 16 collisions */
-#define ETH_DMATXDESC_VF ((uint32_t)0x00000080U) /*!< VLAN Frame */
-#define ETH_DMATXDESC_CC ((uint32_t)0x00000078U) /*!< Collision Count */
-#define ETH_DMATXDESC_ED ((uint32_t)0x00000004U) /*!< Excessive Deferral */
-#define ETH_DMATXDESC_UF ((uint32_t)0x00000002U) /*!< Underflow Error: late data arrival from the memory */
-#define ETH_DMATXDESC_DB ((uint32_t)0x00000001U) /*!< Deferred Bit */
-
-/**
- * @brief Bit definition of TDES1 register
- */
-#define ETH_DMATXDESC_TBS2 ((uint32_t)0x1FFF0000U) /*!< Transmit Buffer2 Size */
-#define ETH_DMATXDESC_TBS1 ((uint32_t)0x00001FFFU) /*!< Transmit Buffer1 Size */
-
-/**
- * @brief Bit definition of TDES2 register
- */
-#define ETH_DMATXDESC_B1AP ((uint32_t)0xFFFFFFFFU) /*!< Buffer1 Address Pointer */
-
-/**
- * @brief Bit definition of TDES3 register
- */
-#define ETH_DMATXDESC_B2AP ((uint32_t)0xFFFFFFFFU) /*!< Buffer2 Address Pointer */
-
- /*---------------------------------------------------------------------------------------------
- TDES6 | Transmit Time Stamp Low [31:0] |
- -----------------------------------------------------------------------------------------------
- TDES7 | Transmit Time Stamp High [31:0] |
- ----------------------------------------------------------------------------------------------*/
-
-/* Bit definition of TDES6 register */
- #define ETH_DMAPTPTXDESC_TTSL ((uint32_t)0xFFFFFFFFU) /* Transmit Time Stamp Low */
-
-/* Bit definition of TDES7 register */
- #define ETH_DMAPTPTXDESC_TTSH ((uint32_t)0xFFFFFFFFU) /* Transmit Time Stamp High */
-
-/**
- * @}
- */
-/** @defgroup ETH_DMA_RX_Descriptor ETH DMA RX Descriptor
- * @{
- */
-
-/*
- DMA Rx Descriptor
- --------------------------------------------------------------------------------------------------------------------
- RDES0 | OWN(31) | Status [30:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES1 | CTRL(31) | Reserved[30:29] | Buffer2 ByteCount[28:16] | CTRL[15:14] | Reserved(13) | Buffer1 ByteCount[12:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES2 | Buffer1 Address [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES3 | Buffer2 Address [31:0] / Next Descriptor Address [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
-*/
-
-/**
- * @brief Bit definition of RDES0 register: DMA Rx descriptor status register
- */
-#define ETH_DMARXDESC_OWN ((uint32_t)0x80000000U) /*!< OWN bit: descriptor is owned by DMA engine */
-#define ETH_DMARXDESC_AFM ((uint32_t)0x40000000U) /*!< DA Filter Fail for the rx frame */
-#define ETH_DMARXDESC_FL ((uint32_t)0x3FFF0000U) /*!< Receive descriptor frame length */
-#define ETH_DMARXDESC_ES ((uint32_t)0x00008000U) /*!< Error summary: OR of the following bits: DE || OE || IPC || LC || RWT || RE || CE */
-#define ETH_DMARXDESC_DE ((uint32_t)0x00004000U) /*!< Descriptor error: no more descriptors for receive frame */
-#define ETH_DMARXDESC_SAF ((uint32_t)0x00002000U) /*!< SA Filter Fail for the received frame */
-#define ETH_DMARXDESC_LE ((uint32_t)0x00001000U) /*!< Frame size not matching with length field */
-#define ETH_DMARXDESC_OE ((uint32_t)0x00000800U) /*!< Overflow Error: Frame was damaged due to buffer overflow */
-#define ETH_DMARXDESC_VLAN ((uint32_t)0x00000400U) /*!< VLAN Tag: received frame is a VLAN frame */
-#define ETH_DMARXDESC_FS ((uint32_t)0x00000200U) /*!< First descriptor of the frame */
-#define ETH_DMARXDESC_LS ((uint32_t)0x00000100U) /*!< Last descriptor of the frame */
-#define ETH_DMARXDESC_IPV4HCE ((uint32_t)0x00000080U) /*!< IPC Checksum Error: Rx Ipv4 header checksum error */
-#define ETH_DMARXDESC_LC ((uint32_t)0x00000040U) /*!< Late collision occurred during reception */
-#define ETH_DMARXDESC_FT ((uint32_t)0x00000020U) /*!< Frame type - Ethernet, otherwise 802.3 */
-#define ETH_DMARXDESC_RWT ((uint32_t)0x00000010U) /*!< Receive Watchdog Timeout: watchdog timer expired during reception */
-#define ETH_DMARXDESC_RE ((uint32_t)0x00000008U) /*!< Receive error: error reported by MII interface */
-#define ETH_DMARXDESC_DBE ((uint32_t)0x00000004U) /*!< Dribble bit error: frame contains non int multiple of 8 bits */
-#define ETH_DMARXDESC_CE ((uint32_t)0x00000002U) /*!< CRC error */
-#define ETH_DMARXDESC_MAMPCE ((uint32_t)0x00000001U) /*!< Rx MAC Address/Payload Checksum Error: Rx MAC address matched/ Rx Payload Checksum Error */
-
-/**
- * @brief Bit definition of RDES1 register
- */
-#define ETH_DMARXDESC_DIC ((uint32_t)0x80000000U) /*!< Disable Interrupt on Completion */
-#define ETH_DMARXDESC_RBS2 ((uint32_t)0x1FFF0000U) /*!< Receive Buffer2 Size */
-#define ETH_DMARXDESC_RER ((uint32_t)0x00008000U) /*!< Receive End of Ring */
-#define ETH_DMARXDESC_RCH ((uint32_t)0x00004000U) /*!< Second Address Chained */
-#define ETH_DMARXDESC_RBS1 ((uint32_t)0x00001FFFU) /*!< Receive Buffer1 Size */
-
-/**
- * @brief Bit definition of RDES2 register
- */
-#define ETH_DMARXDESC_B1AP ((uint32_t)0xFFFFFFFFU) /*!< Buffer1 Address Pointer */
-
-/**
- * @brief Bit definition of RDES3 register
- */
-#define ETH_DMARXDESC_B2AP ((uint32_t)0xFFFFFFFFU) /*!< Buffer2 Address Pointer */
-
-/*---------------------------------------------------------------------------------------------------------------------
- RDES4 | Reserved[31:15] | Extended Status [14:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES5 | Reserved[31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES6 | Receive Time Stamp Low [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES7 | Receive Time Stamp High [31:0] |
- --------------------------------------------------------------------------------------------------------------------*/
-
-/* Bit definition of RDES4 register */
-#define ETH_DMAPTPRXDESC_PTPV ((uint32_t)0x00002000U) /* PTP Version */
-#define ETH_DMAPTPRXDESC_PTPFT ((uint32_t)0x00001000U) /* PTP Frame Type */
-#define ETH_DMAPTPRXDESC_PTPMT ((uint32_t)0x00000F00U) /* PTP Message Type */
-#define ETH_DMAPTPRXDESC_PTPMT_SYNC ((uint32_t)0x00000100U) /* SYNC message (all clock types) */
-#define ETH_DMAPTPRXDESC_PTPMT_FOLLOWUP ((uint32_t)0x00000200U) /* FollowUp message (all clock types) */
-#define ETH_DMAPTPRXDESC_PTPMT_DELAYREQ ((uint32_t)0x00000300U) /* DelayReq message (all clock types) */
-#define ETH_DMAPTPRXDESC_PTPMT_DELAYRESP ((uint32_t)0x00000400U) /* DelayResp message (all clock types) */
-#define ETH_DMAPTPRXDESC_PTPMT_PDELAYREQ_ANNOUNCE ((uint32_t)0x00000500U) /* PdelayReq message (peer-to-peer transparent clock) or Announce message (Ordinary or Boundary clock) */
-#define ETH_DMAPTPRXDESC_PTPMT_PDELAYRESP_MANAG ((uint32_t)0x00000600U) /* PdelayResp message (peer-to-peer transparent clock) or Management message (Ordinary or Boundary clock) */
-#define ETH_DMAPTPRXDESC_PTPMT_PDELAYRESPFOLLOWUP_SIGNAL ((uint32_t)0x00000700U) /* PdelayRespFollowUp message (peer-to-peer transparent clock) or Signaling message (Ordinary or Boundary clock) */
-#define ETH_DMAPTPRXDESC_IPV6PR ((uint32_t)0x00000080U) /* IPv6 Packet Received */
-#define ETH_DMAPTPRXDESC_IPV4PR ((uint32_t)0x00000040U) /* IPv4 Packet Received */
-#define ETH_DMAPTPRXDESC_IPCB ((uint32_t)0x00000020U) /* IP Checksum Bypassed */
-#define ETH_DMAPTPRXDESC_IPPE ((uint32_t)0x00000010U) /* IP Payload Error */
-#define ETH_DMAPTPRXDESC_IPHE ((uint32_t)0x00000008U) /* IP Header Error */
-#define ETH_DMAPTPRXDESC_IPPT ((uint32_t)0x00000007U) /* IP Payload Type */
-#define ETH_DMAPTPRXDESC_IPPT_UDP ((uint32_t)0x00000001U) /* UDP payload encapsulated in the IP datagram */
-#define ETH_DMAPTPRXDESC_IPPT_TCP ((uint32_t)0x00000002U) /* TCP payload encapsulated in the IP datagram */
-#define ETH_DMAPTPRXDESC_IPPT_ICMP ((uint32_t)0x00000003U) /* ICMP payload encapsulated in the IP datagram */
-
-/* Bit definition of RDES6 register */
-#define ETH_DMAPTPRXDESC_RTSL ((uint32_t)0xFFFFFFFFU) /* Receive Time Stamp Low */
-
-/* Bit definition of RDES7 register */
-#define ETH_DMAPTPRXDESC_RTSH ((uint32_t)0xFFFFFFFFU) /* Receive Time Stamp High */
-/**
- * @}
- */
- /** @defgroup ETH_AutoNegotiation ETH AutoNegotiation
- * @{
- */
-#define ETH_AUTONEGOTIATION_ENABLE ((uint32_t)0x00000001U)
-#define ETH_AUTONEGOTIATION_DISABLE ((uint32_t)0x00000000U)
-
-/**
- * @}
- */
-/** @defgroup ETH_Speed ETH Speed
- * @{
- */
-#define ETH_SPEED_10M ((uint32_t)0x00000000U)
-#define ETH_SPEED_100M ((uint32_t)0x00004000U)
-
-/**
- * @}
- */
-/** @defgroup ETH_Duplex_Mode ETH Duplex Mode
- * @{
- */
-#define ETH_MODE_FULLDUPLEX ((uint32_t)0x00000800U)
-#define ETH_MODE_HALFDUPLEX ((uint32_t)0x00000000U)
-/**
- * @}
- */
-/** @defgroup ETH_Rx_Mode ETH Rx Mode
- * @{
- */
-#define ETH_RXPOLLING_MODE ((uint32_t)0x00000000U)
-#define ETH_RXINTERRUPT_MODE ((uint32_t)0x00000001U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Checksum_Mode ETH Checksum Mode
- * @{
- */
-#define ETH_CHECKSUM_BY_HARDWARE ((uint32_t)0x00000000U)
-#define ETH_CHECKSUM_BY_SOFTWARE ((uint32_t)0x00000001U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Media_Interface ETH Media Interface
- * @{
- */
-#define ETH_MEDIA_INTERFACE_MII ((uint32_t)0x00000000U)
-#define ETH_MEDIA_INTERFACE_RMII ((uint32_t)SYSCFG_PMC_MII_RMII_SEL)
-/**
- * @}
- */
-
-/** @defgroup ETH_Watchdog ETH Watchdog
- * @{
- */
-#define ETH_WATCHDOG_ENABLE ((uint32_t)0x00000000U)
-#define ETH_WATCHDOG_DISABLE ((uint32_t)0x00800000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Jabber ETH Jabber
- * @{
- */
-#define ETH_JABBER_ENABLE ((uint32_t)0x00000000U)
-#define ETH_JABBER_DISABLE ((uint32_t)0x00400000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Inter_Frame_Gap ETH Inter Frame Gap
- * @{
- */
-#define ETH_INTERFRAMEGAP_96BIT ((uint32_t)0x00000000U) /*!< minimum IFG between frames during transmission is 96Bit */
-#define ETH_INTERFRAMEGAP_88BIT ((uint32_t)0x00020000U) /*!< minimum IFG between frames during transmission is 88Bit */
-#define ETH_INTERFRAMEGAP_80BIT ((uint32_t)0x00040000U) /*!< minimum IFG between frames during transmission is 80Bit */
-#define ETH_INTERFRAMEGAP_72BIT ((uint32_t)0x00060000U) /*!< minimum IFG between frames during transmission is 72Bit */
-#define ETH_INTERFRAMEGAP_64BIT ((uint32_t)0x00080000U) /*!< minimum IFG between frames during transmission is 64Bit */
-#define ETH_INTERFRAMEGAP_56BIT ((uint32_t)0x000A0000U) /*!< minimum IFG between frames during transmission is 56Bit */
-#define ETH_INTERFRAMEGAP_48BIT ((uint32_t)0x000C0000U) /*!< minimum IFG between frames during transmission is 48Bit */
-#define ETH_INTERFRAMEGAP_40BIT ((uint32_t)0x000E0000U) /*!< minimum IFG between frames during transmission is 40Bit */
-/**
- * @}
- */
-
-/** @defgroup ETH_Carrier_Sense ETH Carrier Sense
- * @{
- */
-#define ETH_CARRIERSENCE_ENABLE ((uint32_t)0x00000000U)
-#define ETH_CARRIERSENCE_DISABLE ((uint32_t)0x00010000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Own ETH Receive Own
- * @{
- */
-#define ETH_RECEIVEOWN_ENABLE ((uint32_t)0x00000000U)
-#define ETH_RECEIVEOWN_DISABLE ((uint32_t)0x00002000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Loop_Back_Mode ETH Loop Back Mode
- * @{
- */
-#define ETH_LOOPBACKMODE_ENABLE ((uint32_t)0x00001000U)
-#define ETH_LOOPBACKMODE_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Checksum_Offload ETH Checksum Offload
- * @{
- */
-#define ETH_CHECKSUMOFFLAOD_ENABLE ((uint32_t)0x00000400U)
-#define ETH_CHECKSUMOFFLAOD_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Retry_Transmission ETH Retry Transmission
- * @{
- */
-#define ETH_RETRYTRANSMISSION_ENABLE ((uint32_t)0x00000000U)
-#define ETH_RETRYTRANSMISSION_DISABLE ((uint32_t)0x00000200U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Automatic_Pad_CRC_Strip ETH Automatic Pad CRC Strip
- * @{
- */
-#define ETH_AUTOMATICPADCRCSTRIP_ENABLE ((uint32_t)0x00000080U)
-#define ETH_AUTOMATICPADCRCSTRIP_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Back_Off_Limit ETH Back Off Limit
- * @{
- */
-#define ETH_BACKOFFLIMIT_10 ((uint32_t)0x00000000U)
-#define ETH_BACKOFFLIMIT_8 ((uint32_t)0x00000020U)
-#define ETH_BACKOFFLIMIT_4 ((uint32_t)0x00000040U)
-#define ETH_BACKOFFLIMIT_1 ((uint32_t)0x00000060U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Deferral_Check ETH Deferral Check
- * @{
- */
-#define ETH_DEFFERRALCHECK_ENABLE ((uint32_t)0x00000010U)
-#define ETH_DEFFERRALCHECK_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_All ETH Receive All
- * @{
- */
-#define ETH_RECEIVEALL_ENABLE ((uint32_t)0x80000000U)
-#define ETH_RECEIVEAll_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Source_Addr_Filter ETH Source Addr Filter
- * @{
- */
-#define ETH_SOURCEADDRFILTER_NORMAL_ENABLE ((uint32_t)0x00000200U)
-#define ETH_SOURCEADDRFILTER_INVERSE_ENABLE ((uint32_t)0x00000300U)
-#define ETH_SOURCEADDRFILTER_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Pass_Control_Frames ETH Pass Control Frames
- * @{
- */
-#define ETH_PASSCONTROLFRAMES_BLOCKALL ((uint32_t)0x00000040U) /*!< MAC filters all control frames from reaching the application */
-#define ETH_PASSCONTROLFRAMES_FORWARDALL ((uint32_t)0x00000080U) /*!< MAC forwards all control frames to application even if they fail the Address Filter */
-#define ETH_PASSCONTROLFRAMES_FORWARDPASSEDADDRFILTER ((uint32_t)0x000000C0U) /*!< MAC forwards control frames that pass the Address Filter. */
-/**
- * @}
- */
-
-/** @defgroup ETH_Broadcast_Frames_Reception ETH Broadcast Frames Reception
- * @{
- */
-#define ETH_BROADCASTFRAMESRECEPTION_ENABLE ((uint32_t)0x00000000U)
-#define ETH_BROADCASTFRAMESRECEPTION_DISABLE ((uint32_t)0x00000020U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Destination_Addr_Filter ETH Destination Addr Filter
- * @{
- */
-#define ETH_DESTINATIONADDRFILTER_NORMAL ((uint32_t)0x00000000U)
-#define ETH_DESTINATIONADDRFILTER_INVERSE ((uint32_t)0x00000008U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Promiscuous_Mode ETH Promiscuous Mode
- * @{
- */
-#define ETH_PROMISCUOUS_MODE_ENABLE ((uint32_t)0x00000001U)
-#define ETH_PROMISCUOUS_MODE_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Multicast_Frames_Filter ETH Multicast Frames Filter
- * @{
- */
-#define ETH_MULTICASTFRAMESFILTER_PERFECTHASHTABLE ((uint32_t)0x00000404U)
-#define ETH_MULTICASTFRAMESFILTER_HASHTABLE ((uint32_t)0x00000004U)
-#define ETH_MULTICASTFRAMESFILTER_PERFECT ((uint32_t)0x00000000U)
-#define ETH_MULTICASTFRAMESFILTER_NONE ((uint32_t)0x00000010U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Unicast_Frames_Filter ETH Unicast Frames Filter
- * @{
- */
-#define ETH_UNICASTFRAMESFILTER_PERFECTHASHTABLE ((uint32_t)0x00000402U)
-#define ETH_UNICASTFRAMESFILTER_HASHTABLE ((uint32_t)0x00000002U)
-#define ETH_UNICASTFRAMESFILTER_PERFECT ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Zero_Quanta_Pause ETH Zero Quanta Pause
- * @{
- */
-#define ETH_ZEROQUANTAPAUSE_ENABLE ((uint32_t)0x00000000U)
-#define ETH_ZEROQUANTAPAUSE_DISABLE ((uint32_t)0x00000080U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Pause_Low_Threshold ETH Pause Low Threshold
- * @{
- */
-#define ETH_PAUSELOWTHRESHOLD_MINUS4 ((uint32_t)0x00000000U) /*!< Pause time minus 4 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS28 ((uint32_t)0x00000010U) /*!< Pause time minus 28 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS144 ((uint32_t)0x00000020U) /*!< Pause time minus 144 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS256 ((uint32_t)0x00000030U) /*!< Pause time minus 256 slot times */
-/**
- * @}
- */
-
-/** @defgroup ETH_Unicast_Pause_Frame_Detect ETH Unicast Pause Frame Detect
- * @{
- */
-#define ETH_UNICASTPAUSEFRAMEDETECT_ENABLE ((uint32_t)0x00000008U)
-#define ETH_UNICASTPAUSEFRAMEDETECT_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Flow_Control ETH Receive Flow Control
- * @{
- */
-#define ETH_RECEIVEFLOWCONTROL_ENABLE ((uint32_t)0x00000004U)
-#define ETH_RECEIVEFLOWCONTROL_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Flow_Control ETH Transmit Flow Control
- * @{
- */
-#define ETH_TRANSMITFLOWCONTROL_ENABLE ((uint32_t)0x00000002U)
-#define ETH_TRANSMITFLOWCONTROL_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_VLAN_Tag_Comparison ETH VLAN Tag Comparison
- * @{
- */
-#define ETH_VLANTAGCOMPARISON_12BIT ((uint32_t)0x00010000U)
-#define ETH_VLANTAGCOMPARISON_16BIT ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses ETH MAC addresses
- * @{
- */
-#define ETH_MAC_ADDRESS0 ((uint32_t)0x00000000U)
-#define ETH_MAC_ADDRESS1 ((uint32_t)0x00000008U)
-#define ETH_MAC_ADDRESS2 ((uint32_t)0x00000010U)
-#define ETH_MAC_ADDRESS3 ((uint32_t)0x00000018U)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses_filter_SA_DA ETH MAC addresses filter SA DA
- * @{
- */
-#define ETH_MAC_ADDRESSFILTER_SA ((uint32_t)0x00000000U)
-#define ETH_MAC_ADDRESSFILTER_DA ((uint32_t)0x00000008U)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses_filter_Mask_bytes ETH MAC addresses filter Mask bytes
- * @{
- */
-#define ETH_MAC_ADDRESSMASK_BYTE6 ((uint32_t)0x20000000U) /*!< Mask MAC Address high reg bits [15:8] */
-#define ETH_MAC_ADDRESSMASK_BYTE5 ((uint32_t)0x10000000U) /*!< Mask MAC Address high reg bits [7:0] */
-#define ETH_MAC_ADDRESSMASK_BYTE4 ((uint32_t)0x08000000U) /*!< Mask MAC Address low reg bits [31:24] */
-#define ETH_MAC_ADDRESSMASK_BYTE3 ((uint32_t)0x04000000U) /*!< Mask MAC Address low reg bits [23:16] */
-#define ETH_MAC_ADDRESSMASK_BYTE2 ((uint32_t)0x02000000U) /*!< Mask MAC Address low reg bits [15:8] */
-#define ETH_MAC_ADDRESSMASK_BYTE1 ((uint32_t)0x01000000U) /*!< Mask MAC Address low reg bits [70] */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Debug_flags ETH MAC Debug flags
- * @{
- */
-#define ETH_MAC_TXFIFO_FULL ((uint32_t)0x02000000) /* Tx FIFO full */
-#define ETH_MAC_TXFIFONOT_EMPTY ((uint32_t)0x01000000) /* Tx FIFO not empty */
-#define ETH_MAC_TXFIFO_WRITE_ACTIVE ((uint32_t)0x00400000) /* Tx FIFO write active */
-#define ETH_MAC_TXFIFO_IDLE ((uint32_t)0x00000000) /* Tx FIFO read status: Idle */
-#define ETH_MAC_TXFIFO_READ ((uint32_t)0x00100000) /* Tx FIFO read status: Read (transferring data to the MAC transmitter) */
-#define ETH_MAC_TXFIFO_WAITING ((uint32_t)0x00200000) /* Tx FIFO read status: Waiting for TxStatus from MAC transmitter */
-#define ETH_MAC_TXFIFO_WRITING ((uint32_t)0x00300000) /* Tx FIFO read status: Writing the received TxStatus or flushing the TxFIFO */
-#define ETH_MAC_TRANSMISSION_PAUSE ((uint32_t)0x00080000) /* MAC transmitter in pause */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_IDLE ((uint32_t)0x00000000) /* MAC transmit frame controller: Idle */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_WAITING ((uint32_t)0x00020000) /* MAC transmit frame controller: Waiting for Status of previous frame or IFG/backoff period to be over */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_GENRATING_PCF ((uint32_t)0x00040000) /* MAC transmit frame controller: Generating and transmitting a Pause control frame (in full duplex mode) */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_TRANSFERRING ((uint32_t)0x00060000) /* MAC transmit frame controller: Transferring input frame for transmission */
-#define ETH_MAC_MII_TRANSMIT_ACTIVE ((uint32_t)0x00010000) /* MAC MII transmit engine active */
-#define ETH_MAC_RXFIFO_EMPTY ((uint32_t)0x00000000) /* Rx FIFO fill level: empty */
-#define ETH_MAC_RXFIFO_BELOW_THRESHOLD ((uint32_t)0x00000100) /* Rx FIFO fill level: fill-level below flow-control de-activate threshold */
-#define ETH_MAC_RXFIFO_ABOVE_THRESHOLD ((uint32_t)0x00000200) /* Rx FIFO fill level: fill-level above flow-control activate threshold */
-#define ETH_MAC_RXFIFO_FULL ((uint32_t)0x00000300) /* Rx FIFO fill level: full */
-#define ETH_MAC_READCONTROLLER_IDLE ((uint32_t)0x00000060) /* Rx FIFO read controller IDLE state */
-#define ETH_MAC_READCONTROLLER_READING_DATA ((uint32_t)0x00000060) /* Rx FIFO read controller Reading frame data */
-#define ETH_MAC_READCONTROLLER_READING_STATUS ((uint32_t)0x00000060) /* Rx FIFO read controller Reading frame status (or time-stamp) */
-#define ETH_MAC_READCONTROLLER_ FLUSHING ((uint32_t)0x00000060) /* Rx FIFO read controller Flushing the frame data and status */
-#define ETH_MAC_RXFIFO_WRITE_ACTIVE ((uint32_t)0x00000010) /* Rx FIFO write controller active */
-#define ETH_MAC_SMALL_FIFO_NOTACTIVE ((uint32_t)0x00000000) /* MAC small FIFO read / write controllers not active */
-#define ETH_MAC_SMALL_FIFO_READ_ACTIVE ((uint32_t)0x00000002) /* MAC small FIFO read controller active */
-#define ETH_MAC_SMALL_FIFO_WRITE_ACTIVE ((uint32_t)0x00000004) /* MAC small FIFO write controller active */
-#define ETH_MAC_SMALL_FIFO_RW_ACTIVE ((uint32_t)0x00000006) /* MAC small FIFO read / write controllers active */
-#define ETH_MAC_MII_RECEIVE_PROTOCOL_ACTIVE ((uint32_t)0x00000001) /* MAC MII receive protocol engine active */
-/**
- * @}
- */
-
-/** @defgroup ETH_Drop_TCP_IP_Checksum_Error_Frame ETH Drop TCP IP Checksum Error Frame
- * @{
- */
-#define ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE ((uint32_t)0x00000000U)
-#define ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE ((uint32_t)0x04000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Store_Forward ETH Receive Store Forward
- * @{
- */
-#define ETH_RECEIVESTOREFORWARD_ENABLE ((uint32_t)0x02000000U)
-#define ETH_RECEIVESTOREFORWARD_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Flush_Received_Frame ETH Flush Received Frame
- * @{
- */
-#define ETH_FLUSHRECEIVEDFRAME_ENABLE ((uint32_t)0x00000000U)
-#define ETH_FLUSHRECEIVEDFRAME_DISABLE ((uint32_t)0x01000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Store_Forward ETH Transmit Store Forward
- * @{
- */
-#define ETH_TRANSMITSTOREFORWARD_ENABLE ((uint32_t)0x00200000U)
-#define ETH_TRANSMITSTOREFORWARD_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Threshold_Control ETH Transmit Threshold Control
- * @{
- */
-#define ETH_TRANSMITTHRESHOLDCONTROL_64BYTES ((uint32_t)0x00000000U) /*!< threshold level of the MTL Transmit FIFO is 64 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_128BYTES ((uint32_t)0x00004000U) /*!< threshold level of the MTL Transmit FIFO is 128 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_192BYTES ((uint32_t)0x00008000U) /*!< threshold level of the MTL Transmit FIFO is 192 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_256BYTES ((uint32_t)0x0000C000U) /*!< threshold level of the MTL Transmit FIFO is 256 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_40BYTES ((uint32_t)0x00010000U) /*!< threshold level of the MTL Transmit FIFO is 40 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_32BYTES ((uint32_t)0x00014000U) /*!< threshold level of the MTL Transmit FIFO is 32 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_24BYTES ((uint32_t)0x00018000U) /*!< threshold level of the MTL Transmit FIFO is 24 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_16BYTES ((uint32_t)0x0001C000U) /*!< threshold level of the MTL Transmit FIFO is 16 Bytes */
-/**
- * @}
- */
-
-/** @defgroup ETH_Forward_Error_Frames ETH Forward Error Frames
- * @{
- */
-#define ETH_FORWARDERRORFRAMES_ENABLE ((uint32_t)0x00000080U)
-#define ETH_FORWARDERRORFRAMES_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Forward_Undersized_Good_Frames ETH Forward Undersized Good Frames
- * @{
- */
-#define ETH_FORWARDUNDERSIZEDGOODFRAMES_ENABLE ((uint32_t)0x00000040U)
-#define ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Threshold_Control ETH Receive Threshold Control
- * @{
- */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES ((uint32_t)0x00000000U) /*!< threshold level of the MTL Receive FIFO is 64 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_32BYTES ((uint32_t)0x00000008U) /*!< threshold level of the MTL Receive FIFO is 32 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_96BYTES ((uint32_t)0x00000010U) /*!< threshold level of the MTL Receive FIFO is 96 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_128BYTES ((uint32_t)0x00000018U) /*!< threshold level of the MTL Receive FIFO is 128 Bytes */
-/**
- * @}
- */
-
-/** @defgroup ETH_Second_Frame_Operate ETH Second Frame Operate
- * @{
- */
-#define ETH_SECONDFRAMEOPERARTE_ENABLE ((uint32_t)0x00000004U)
-#define ETH_SECONDFRAMEOPERARTE_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Address_Aligned_Beats ETH Address Aligned Beats
- * @{
- */
-#define ETH_ADDRESSALIGNEDBEATS_ENABLE ((uint32_t)0x02000000U)
-#define ETH_ADDRESSALIGNEDBEATS_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Fixed_Burst ETH Fixed Burst
- * @{
- */
-#define ETH_FIXEDBURST_ENABLE ((uint32_t)0x00010000U)
-#define ETH_FIXEDBURST_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_Rx_DMA_Burst_Length ETH Rx DMA Burst Length
- * @{
- */
-#define ETH_RXDMABURSTLENGTH_1BEAT ((uint32_t)0x00020000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 1 */
-#define ETH_RXDMABURSTLENGTH_2BEAT ((uint32_t)0x00040000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 2 */
-#define ETH_RXDMABURSTLENGTH_4BEAT ((uint32_t)0x00080000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 4 */
-#define ETH_RXDMABURSTLENGTH_8BEAT ((uint32_t)0x00100000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 8 */
-#define ETH_RXDMABURSTLENGTH_16BEAT ((uint32_t)0x00200000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 16 */
-#define ETH_RXDMABURSTLENGTH_32BEAT ((uint32_t)0x00400000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 32 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_4BEAT ((uint32_t)0x01020000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 4 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_8BEAT ((uint32_t)0x01040000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 8 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_16BEAT ((uint32_t)0x01080000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 16 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_32BEAT ((uint32_t)0x01100000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 32 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_64BEAT ((uint32_t)0x01200000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 64 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_128BEAT ((uint32_t)0x01400000U) /*!< maximum number of beats to be transferred in one RxDMA transaction is 128 */
-/**
- * @}
- */
-
-/** @defgroup ETH_Tx_DMA_Burst_Length ETH Tx DMA Burst Length
- * @{
- */
-#define ETH_TXDMABURSTLENGTH_1BEAT ((uint32_t)0x00000100U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 1 */
-#define ETH_TXDMABURSTLENGTH_2BEAT ((uint32_t)0x00000200U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 2 */
-#define ETH_TXDMABURSTLENGTH_4BEAT ((uint32_t)0x00000400U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 4 */
-#define ETH_TXDMABURSTLENGTH_8BEAT ((uint32_t)0x00000800U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 8 */
-#define ETH_TXDMABURSTLENGTH_16BEAT ((uint32_t)0x00001000U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 16 */
-#define ETH_TXDMABURSTLENGTH_32BEAT ((uint32_t)0x00002000U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 32 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_4BEAT ((uint32_t)0x01000100U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 4 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_8BEAT ((uint32_t)0x01000200U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 8 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_16BEAT ((uint32_t)0x01000400U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 16 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_32BEAT ((uint32_t)0x01000800U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 32 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_64BEAT ((uint32_t)0x01001000U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 64 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_128BEAT ((uint32_t)0x01002000U) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 128 */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Enhanced_descriptor_format ETH DMA Enhanced descriptor format
- * @{
- */
-#define ETH_DMAENHANCEDDESCRIPTOR_ENABLE ((uint32_t)0x00000080U)
-#define ETH_DMAENHANCEDDESCRIPTOR_DISABLE ((uint32_t)0x00000000U)
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Arbitration ETH DMA Arbitration
- * @{
- */
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1 ((uint32_t)0x00000000U)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_2_1 ((uint32_t)0x00004000U)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_3_1 ((uint32_t)0x00008000U)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1 ((uint32_t)0x0000C000U)
-#define ETH_DMAARBITRATION_RXPRIORTX ((uint32_t)0x00000002U)
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Tx_descriptor_segment ETH DMA Tx descriptor segment
- * @{
- */
-#define ETH_DMATXDESC_LASTSEGMENTS ((uint32_t)0x40000000U) /*!< Last Segment */
-#define ETH_DMATXDESC_FIRSTSEGMENT ((uint32_t)0x20000000U) /*!< First Segment */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Tx_descriptor_Checksum_Insertion_Control ETH DMA Tx descriptor Checksum Insertion Control
- * @{
- */
-#define ETH_DMATXDESC_CHECKSUMBYPASS ((uint32_t)0x00000000U) /*!< Checksum engine bypass */
-#define ETH_DMATXDESC_CHECKSUMIPV4HEADER ((uint32_t)0x00400000U) /*!< IPv4 header checksum insertion */
-#define ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT ((uint32_t)0x00800000U) /*!< TCP/UDP/ICMP checksum insertion. Pseudo header checksum is assumed to be present */
-#define ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL ((uint32_t)0x00C00000U) /*!< TCP/UDP/ICMP checksum fully in hardware including pseudo header */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Rx_descriptor_buffers ETH DMA Rx descriptor buffers
- * @{
- */
-#define ETH_DMARXDESC_BUFFER1 ((uint32_t)0x00000000U) /*!< DMA Rx Desc Buffer1 */
-#define ETH_DMARXDESC_BUFFER2 ((uint32_t)0x00000001U) /*!< DMA Rx Desc Buffer2 */
-/**
- * @}
- */
-
-/** @defgroup ETH_PMT_Flags ETH PMT Flags
- * @{
- */
-#define ETH_PMT_FLAG_WUFFRPR ((uint32_t)0x80000000U) /*!< Wake-Up Frame Filter Register Pointer Reset */
-#define ETH_PMT_FLAG_WUFR ((uint32_t)0x00000040U) /*!< Wake-Up Frame Received */
-#define ETH_PMT_FLAG_MPR ((uint32_t)0x00000020U) /*!< Magic Packet Received */
-/**
- * @}
- */
-
-/** @defgroup ETH_MMC_Tx_Interrupts ETH MMC Tx Interrupts
- * @{
- */
-#define ETH_MMC_IT_TGF ((uint32_t)0x00200000U) /*!< When Tx good frame counter reaches half the maximum value */
-#define ETH_MMC_IT_TGFMSC ((uint32_t)0x00008000U) /*!< When Tx good multi col counter reaches half the maximum value */
-#define ETH_MMC_IT_TGFSC ((uint32_t)0x00004000U) /*!< When Tx good single col counter reaches half the maximum value */
-/**
- * @}
- */
-
-/** @defgroup ETH_MMC_Rx_Interrupts ETH MMC Rx Interrupts
- * @{
- */
-#define ETH_MMC_IT_RGUF ((uint32_t)0x10020000U) /*!< When Rx good unicast frames counter reaches half the maximum value */
-#define ETH_MMC_IT_RFAE ((uint32_t)0x10000040U) /*!< When Rx alignment error counter reaches half the maximum value */
-#define ETH_MMC_IT_RFCE ((uint32_t)0x10000020U) /*!< When Rx crc error counter reaches half the maximum value */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Flags ETH MAC Flags
- * @{
- */
-#define ETH_MAC_FLAG_TST ((uint32_t)0x00000200U) /*!< Time stamp trigger flag (on MAC) */
-#define ETH_MAC_FLAG_MMCT ((uint32_t)0x00000040U) /*!< MMC transmit flag */
-#define ETH_MAC_FLAG_MMCR ((uint32_t)0x00000020U) /*!< MMC receive flag */
-#define ETH_MAC_FLAG_MMC ((uint32_t)0x00000010U) /*!< MMC flag (on MAC) */
-#define ETH_MAC_FLAG_PMT ((uint32_t)0x00000008U) /*!< PMT flag (on MAC) */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Flags ETH DMA Flags
- * @{
- */
-#define ETH_DMA_FLAG_TST ((uint32_t)0x20000000U) /*!< Time-stamp trigger interrupt (on DMA) */
-#define ETH_DMA_FLAG_PMT ((uint32_t)0x10000000U) /*!< PMT interrupt (on DMA) */
-#define ETH_DMA_FLAG_MMC ((uint32_t)0x08000000U) /*!< MMC interrupt (on DMA) */
-#define ETH_DMA_FLAG_DATATRANSFERERROR ((uint32_t)0x00800000U) /*!< Error bits 0-Rx DMA, 1-Tx DMA */
-#define ETH_DMA_FLAG_READWRITEERROR ((uint32_t)0x01000000U) /*!< Error bits 0-write transfer, 1-read transfer */
-#define ETH_DMA_FLAG_ACCESSERROR ((uint32_t)0x02000000U) /*!< Error bits 0-data buffer, 1-desc. access */
-#define ETH_DMA_FLAG_NIS ((uint32_t)0x00010000U) /*!< Normal interrupt summary flag */
-#define ETH_DMA_FLAG_AIS ((uint32_t)0x00008000U) /*!< Abnormal interrupt summary flag */
-#define ETH_DMA_FLAG_ER ((uint32_t)0x00004000U) /*!< Early receive flag */
-#define ETH_DMA_FLAG_FBE ((uint32_t)0x00002000U) /*!< Fatal bus error flag */
-#define ETH_DMA_FLAG_ET ((uint32_t)0x00000400U) /*!< Early transmit flag */
-#define ETH_DMA_FLAG_RWT ((uint32_t)0x00000200U) /*!< Receive watchdog timeout flag */
-#define ETH_DMA_FLAG_RPS ((uint32_t)0x00000100U) /*!< Receive process stopped flag */
-#define ETH_DMA_FLAG_RBU ((uint32_t)0x00000080U) /*!< Receive buffer unavailable flag */
-#define ETH_DMA_FLAG_R ((uint32_t)0x00000040U) /*!< Receive flag */
-#define ETH_DMA_FLAG_TU ((uint32_t)0x00000020U) /*!< Underflow flag */
-#define ETH_DMA_FLAG_RO ((uint32_t)0x00000010U) /*!< Overflow flag */
-#define ETH_DMA_FLAG_TJT ((uint32_t)0x00000008U) /*!< Transmit jabber timeout flag */
-#define ETH_DMA_FLAG_TBU ((uint32_t)0x00000004U) /*!< Transmit buffer unavailable flag */
-#define ETH_DMA_FLAG_TPS ((uint32_t)0x00000002U) /*!< Transmit process stopped flag */
-#define ETH_DMA_FLAG_T ((uint32_t)0x00000001U) /*!< Transmit flag */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Interrupts ETH MAC Interrupts
- * @{
- */
-#define ETH_MAC_IT_TST ((uint32_t)0x00000200U) /*!< Time stamp trigger interrupt (on MAC) */
-#define ETH_MAC_IT_MMCT ((uint32_t)0x00000040U) /*!< MMC transmit interrupt */
-#define ETH_MAC_IT_MMCR ((uint32_t)0x00000020U) /*!< MMC receive interrupt */
-#define ETH_MAC_IT_MMC ((uint32_t)0x00000010U) /*!< MMC interrupt (on MAC) */
-#define ETH_MAC_IT_PMT ((uint32_t)0x00000008U) /*!< PMT interrupt (on MAC) */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Interrupts ETH DMA Interrupts
- * @{
- */
-#define ETH_DMA_IT_TST ((uint32_t)0x20000000U) /*!< Time-stamp trigger interrupt (on DMA) */
-#define ETH_DMA_IT_PMT ((uint32_t)0x10000000U) /*!< PMT interrupt (on DMA) */
-#define ETH_DMA_IT_MMC ((uint32_t)0x08000000U) /*!< MMC interrupt (on DMA) */
-#define ETH_DMA_IT_NIS ((uint32_t)0x00010000U) /*!< Normal interrupt summary */
-#define ETH_DMA_IT_AIS ((uint32_t)0x00008000U) /*!< Abnormal interrupt summary */
-#define ETH_DMA_IT_ER ((uint32_t)0x00004000U) /*!< Early receive interrupt */
-#define ETH_DMA_IT_FBE ((uint32_t)0x00002000U) /*!< Fatal bus error interrupt */
-#define ETH_DMA_IT_ET ((uint32_t)0x00000400U) /*!< Early transmit interrupt */
-#define ETH_DMA_IT_RWT ((uint32_t)0x00000200U) /*!< Receive watchdog timeout interrupt */
-#define ETH_DMA_IT_RPS ((uint32_t)0x00000100U) /*!< Receive process stopped interrupt */
-#define ETH_DMA_IT_RBU ((uint32_t)0x00000080U) /*!< Receive buffer unavailable interrupt */
-#define ETH_DMA_IT_R ((uint32_t)0x00000040U) /*!< Receive interrupt */
-#define ETH_DMA_IT_TU ((uint32_t)0x00000020U) /*!< Underflow interrupt */
-#define ETH_DMA_IT_RO ((uint32_t)0x00000010U) /*!< Overflow interrupt */
-#define ETH_DMA_IT_TJT ((uint32_t)0x00000008U) /*!< Transmit jabber timeout interrupt */
-#define ETH_DMA_IT_TBU ((uint32_t)0x00000004U) /*!< Transmit buffer unavailable interrupt */
-#define ETH_DMA_IT_TPS ((uint32_t)0x00000002U) /*!< Transmit process stopped interrupt */
-#define ETH_DMA_IT_T ((uint32_t)0x00000001U) /*!< Transmit interrupt */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_transmit_process_state ETH DMA transmit process state
- * @{
- */
-#define ETH_DMA_TRANSMITPROCESS_STOPPED ((uint32_t)0x00000000U) /*!< Stopped - Reset or Stop Tx Command issued */
-#define ETH_DMA_TRANSMITPROCESS_FETCHING ((uint32_t)0x00100000U) /*!< Running - fetching the Tx descriptor */
-#define ETH_DMA_TRANSMITPROCESS_WAITING ((uint32_t)0x00200000U) /*!< Running - waiting for status */
-#define ETH_DMA_TRANSMITPROCESS_READING ((uint32_t)0x00300000U) /*!< Running - reading the data from host memory */
-#define ETH_DMA_TRANSMITPROCESS_SUSPENDED ((uint32_t)0x00600000U) /*!< Suspended - Tx Descriptor unavailable */
-#define ETH_DMA_TRANSMITPROCESS_CLOSING ((uint32_t)0x00700000U) /*!< Running - closing Rx descriptor */
-
-/**
- * @}
- */
-
-
-/** @defgroup ETH_DMA_receive_process_state ETH DMA receive process state
- * @{
- */
-#define ETH_DMA_RECEIVEPROCESS_STOPPED ((uint32_t)0x00000000U) /*!< Stopped - Reset or Stop Rx Command issued */
-#define ETH_DMA_RECEIVEPROCESS_FETCHING ((uint32_t)0x00020000U) /*!< Running - fetching the Rx descriptor */
-#define ETH_DMA_RECEIVEPROCESS_WAITING ((uint32_t)0x00060000U) /*!< Running - waiting for packet */
-#define ETH_DMA_RECEIVEPROCESS_SUSPENDED ((uint32_t)0x00080000U) /*!< Suspended - Rx Descriptor unavailable */
-#define ETH_DMA_RECEIVEPROCESS_CLOSING ((uint32_t)0x000A0000U) /*!< Running - closing descriptor */
-#define ETH_DMA_RECEIVEPROCESS_QUEUING ((uint32_t)0x000E0000U) /*!< Running - queuing the receive frame into host memory */
-
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_overflow ETH DMA overflow
- * @{
- */
-#define ETH_DMA_OVERFLOW_RXFIFOCOUNTER ((uint32_t)0x10000000U) /*!< Overflow bit for FIFO overflow counter */
-#define ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER ((uint32_t)0x00010000U) /*!< Overflow bit for missed frame counter */
-/**
- * @}
- */
-
-/** @defgroup ETH_EXTI_LINE_WAKEUP ETH EXTI LINE WAKEUP
- * @{
- */
-#define ETH_EXTI_LINE_WAKEUP ((uint32_t)0x00080000U) /*!< External interrupt line 19 Connected to the ETH EXTI Line */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/* Exported macro ------------------------------------------------------------*/
-/** @defgroup ETH_Exported_Macros ETH Exported Macros
- * @brief macros to handle interrupts and specific clock configurations
- * @{
- */
-
-/** @brief Reset ETH handle state
- * @param __HANDLE__: specifies the ETH handle.
- * @retval None
- */
-#define __HAL_ETH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ETH_STATE_RESET)
-
-/**
- * @brief Checks whether the specified Ethernet DMA Tx Desc flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag of TDES0 to check.
- * @retval the ETH_DMATxDescFlag (SET or RESET).
- */
-#define __HAL_ETH_DMATXDESC_GET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->TxDesc->Status & (__FLAG__) == (__FLAG__))
-
-/**
- * @brief Checks whether the specified Ethernet DMA Rx Desc flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag of RDES0 to check.
- * @retval the ETH_DMATxDescFlag (SET or RESET).
- */
-#define __HAL_ETH_DMARXDESC_GET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->RxDesc->Status & (__FLAG__) == (__FLAG__))
-
-/**
- * @brief Enables the specified DMA Rx Desc receive interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_ENABLE_IT(__HANDLE__) ((__HANDLE__)->RxDesc->ControlBufferSize &=(~(uint32_t)ETH_DMARXDESC_DIC))
-
-/**
- * @brief Disables the specified DMA Rx Desc receive interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_DISABLE_IT(__HANDLE__) ((__HANDLE__)->RxDesc->ControlBufferSize |= ETH_DMARXDESC_DIC)
-
-/**
- * @brief Set the specified DMA Rx Desc Own bit.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_SET_OWN_BIT(__HANDLE__) ((__HANDLE__)->RxDesc->Status |= ETH_DMARXDESC_OWN)
-
-/**
- * @brief Returns the specified Ethernet DMA Tx Desc collision count.
- * @param __HANDLE__: ETH Handle
- * @retval The Transmit descriptor collision counter value.
- */
-#define __HAL_ETH_DMATXDESC_GET_COLLISION_COUNT(__HANDLE__) (((__HANDLE__)->TxDesc->Status & ETH_DMATXDESC_CC) >> ETH_DMATXDESC_COLLISION_COUNTSHIFT)
-
-/**
- * @brief Set the specified DMA Tx Desc Own bit.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SET_OWN_BIT(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_OWN)
-
-/**
- * @brief Enables the specified DMA Tx Desc Transmit interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_ENABLE_IT(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_IC)
-
-/**
- * @brief Disables the specified DMA Tx Desc Transmit interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_DISABLE_IT(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_IC)
-
-/**
- * @brief Selects the specified Ethernet DMA Tx Desc Checksum Insertion.
- * @param __HANDLE__: ETH Handle
- * @param __CHECKSUM__: specifies is the DMA Tx desc checksum insertion.
- * This parameter can be one of the following values:
- * @arg ETH_DMATXDESC_CHECKSUMBYPASS : Checksum bypass
- * @arg ETH_DMATXDESC_CHECKSUMIPV4HEADER : IPv4 header checksum
- * @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT : TCP/UDP/ICMP checksum. Pseudo header checksum is assumed to be present
- * @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL : TCP/UDP/ICMP checksum fully in hardware including pseudo header
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CHECKSUM_INSERTION(__HANDLE__, __CHECKSUM__) ((__HANDLE__)->TxDesc->Status |= (__CHECKSUM__))
-
-/**
- * @brief Enables the DMA Tx Desc CRC.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CRC_ENABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_DC)
-
-/**
- * @brief Disables the DMA Tx Desc CRC.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CRC_DISABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_DC)
-
-/**
- * @brief Enables the DMA Tx Desc padding for frame shorter than 64 bytes.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SHORT_FRAME_PADDING_ENABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_DP)
-
-/**
- * @brief Disables the DMA Tx Desc padding for frame shorter than 64 bytes.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SHORT_FRAME_PADDING_DISABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_DP)
-
-/**
- * @brief Enables the specified Ethernet MAC interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the Ethernet MAC interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @retval None
- */
-#define __HAL_ETH_MAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIMR |= (__INTERRUPT__))
-
-/**
- * @brief Disables the specified Ethernet MAC interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the Ethernet MAC interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @retval None
- */
-#define __HAL_ETH_MAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIMR &= ~(__INTERRUPT__))
-
-/**
- * @brief Initiate a Pause Control Frame (Full-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_INITIATE_PAUSE_CONTROL_FRAME(__HANDLE__) ((__HANDLE__)->Instance->MACFCR |= ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Checks whether the Ethernet flow control busy bit is set or not.
- * @param __HANDLE__: ETH Handle
- * @retval The new state of flow control busy status bit (SET or RESET).
- */
-#define __HAL_ETH_GET_FLOW_CONTROL_BUSY_STATUS(__HANDLE__) (((__HANDLE__)->Instance->MACFCR & ETH_MACFCR_FCBBPA) == ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Enables the MAC Back Pressure operation activation (Half-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_BACK_PRESSURE_ACTIVATION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACFCR |= ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Disables the MAC BackPressure operation activation (Half-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_BACK_PRESSURE_ACTIVATION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACFCR &= ~ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Checks whether the specified Ethernet MAC flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_FLAG_TST : Time stamp trigger flag
- * @arg ETH_MAC_FLAG_MMCT : MMC transmit flag
- * @arg ETH_MAC_FLAG_MMCR : MMC receive flag
- * @arg ETH_MAC_FLAG_MMC : MMC flag
- * @arg ETH_MAC_FLAG_PMT : PMT flag
- * @retval The state of Ethernet MAC flag.
- */
-#define __HAL_ETH_MAC_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->MACSR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Enables the specified Ethernet DMA interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the Ethernet DMA interrupt sources to be
- * enabled @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMAIER |= (__INTERRUPT__))
-
-/**
- * @brief Disables the specified Ethernet DMA interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the Ethernet DMA interrupt sources to be
- * disabled. @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMAIER &= ~(__INTERRUPT__))
-
-/**
- * @brief Clears the Ethernet DMA IT pending bit.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the interrupt pending bit to clear. @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMASR =(__INTERRUPT__))
-
-/**
- * @brief Checks whether the specified Ethernet DMA flag is set or not.
-* @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Flags
- * @retval The new state of ETH_DMA_FLAG (SET or RESET).
- */
-#define __HAL_ETH_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->DMASR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Checks whether the specified Ethernet DMA flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to clear. @ref ETH_DMA_Flags
- * @retval The new state of ETH_DMA_FLAG (SET or RESET).
- */
-#define __HAL_ETH_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->DMASR = (__FLAG__))
-
-/**
- * @brief Checks whether the specified Ethernet DMA overflow flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __OVERFLOW__: specifies the DMA overflow flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMA_OVERFLOW_RXFIFOCOUNTER : Overflow for FIFO Overflows Counter
- * @arg ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER : Overflow for Buffer Unavailable Missed Frame Counter
- * @retval The state of Ethernet DMA overflow Flag (SET or RESET).
- */
-#define __HAL_ETH_GET_DMA_OVERFLOW_STATUS(__HANDLE__, __OVERFLOW__) (((__HANDLE__)->Instance->DMAMFBOCR & (__OVERFLOW__)) == (__OVERFLOW__))
-
-/**
- * @brief Set the DMA Receive status watchdog timer register value
- * @param __HANDLE__: ETH Handle
- * @param __VALUE__: DMA Receive status watchdog timer register value
- * @retval None
- */
-#define __HAL_ETH_SET_RECEIVE_WATCHDOG_TIMER(__HANDLE__, __VALUE__) ((__HANDLE__)->Instance->DMARSWTR = (__VALUE__))
-
-/**
- * @brief Enables any unicast packet filtered by the MAC address
- * recognition to be a wake-up frame.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_GLOBAL_UNICAST_WAKEUP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_GU)
-
-/**
- * @brief Disables any unicast packet filtered by the MAC address
- * recognition to be a wake-up frame.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_GLOBAL_UNICAST_WAKEUP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_GU)
-
-/**
- * @brief Enables the MAC Wake-Up Frame Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_FRAME_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Disables the MAC Wake-Up Frame Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_FRAME_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Enables the MAC Magic Packet Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MAGIC_PACKET_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_MPE)
-
-/**
- * @brief Disables the MAC Magic Packet Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MAGIC_PACKET_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Enables the MAC Power Down.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_POWER_DOWN_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_PD)
-
-/**
- * @brief Disables the MAC Power Down.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_POWER_DOWN_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_PD)
-
-/**
- * @brief Checks whether the specified Ethernet PMT flag is set or not.
- * @param __HANDLE__: ETH Handle.
- * @param __FLAG__: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_PMT_FLAG_WUFFRPR : Wake-Up Frame Filter Register Pointer Reset
- * @arg ETH_PMT_FLAG_WUFR : Wake-Up Frame Received
- * @arg ETH_PMT_FLAG_MPR : Magic Packet Received
- * @retval The new state of Ethernet PMT Flag (SET or RESET).
- */
-#define __HAL_ETH_GET_PMT_FLAG_STATUS(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->MACPMTCSR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Preset and Initialize the MMC counters to almost-full value: 0xFFFF_FFF0 (full - 16)
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FULL_PRESET(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= (ETH_MMCCR_MCFHP | ETH_MMCCR_MCP))
-
-/**
- * @brief Preset and Initialize the MMC counters to almost-half value: 0x7FFF_FFF0 (half - 16)
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_HALF_PRESET(__HANDLE__) do{(__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_MCFHP;\
- (__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_MCP;} while (0)
-
-/**
- * @brief Enables the MMC Counter Freeze.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FREEZE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_MCF)
-
-/**
- * @brief Disables the MMC Counter Freeze.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FREEZE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_MCF)
-
-/**
- * @brief Enables the MMC Reset On Read.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_RESET_ONREAD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_ROR)
-
-/**
- * @brief Disables the MMC Reset On Read.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_RESET_ONREAD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_ROR)
-
-/**
- * @brief Enables the MMC Counter Stop Rollover.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_COUNTER_ROLLOVER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_CSR)
-
-/**
- * @brief Disables the MMC Counter Stop Rollover.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_COUNTER_ROLLOVER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_CSR)
-
-/**
- * @brief Resets the MMC Counters.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTERS_RESET(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_CR)
-
-/**
- * @brief Enables the specified Ethernet MMC Rx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the Ethernet MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_RGUF : When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_RX_IT_ENABLE(__HANDLE__, __INTERRUPT__) (__HANDLE__)->Instance->MMCRIMR &= ~((__INTERRUPT__) & 0xEFFFFFFF)
-/**
- * @brief Disables the specified Ethernet MMC Rx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the Ethernet MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_RGUF : When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_RX_IT_DISABLE(__HANDLE__, __INTERRUPT__) (__HANDLE__)->Instance->MMCRIMR |= ((__INTERRUPT__) & 0xEFFFFFFF)
-/**
- * @brief Enables the specified Ethernet MMC Tx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the Ethernet MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_TX_IT_ENABLE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MMCRIMR &= ~ (__INTERRUPT__))
-
-/**
- * @brief Disables the specified Ethernet MMC Tx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the Ethernet MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_TX_IT_DISABLE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MMCRIMR |= (__INTERRUPT__))
-
-/**
- * @brief Enables the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disables the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enable event on ETH External event line.
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_EVENT() EXTI->EMR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disable event on ETH External event line
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_EVENT() EXTI->EMR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Get flag of the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Clear flag of the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables rising edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_EDGE_TRIGGER() EXTI->RTSR |= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @brief Disables the rising edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_RISING_EDGE_TRIGGER() EXTI->RTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLING_EDGE_TRIGGER() EXTI->FTSR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disables falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_FALLING_EDGE_TRIGGER() EXTI->FTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables rising/falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLINGRISING_TRIGGER() EXTI->RTSR |= ETH_EXTI_LINE_WAKEUP;\
- EXTI->FTSR |= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @brief Disables rising/falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_FALLINGRISING_TRIGGER() EXTI->RTSR &= ~(ETH_EXTI_LINE_WAKEUP);\
- EXTI->FTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Generate a Software interrupt on selected EXTI line.
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_GENERATE_SWIT() EXTI->SWIER|= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @}
- */
-/* Exported functions --------------------------------------------------------*/
-
-/** @addtogroup ETH_Exported_Functions
- * @{
- */
-
-/* Initialization and de-initialization functions ****************************/
-
-/** @addtogroup ETH_Exported_Functions_Group1
- * @{
- */
-HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth);
-void HAL_ETH_MspInit(ETH_HandleTypeDef *heth);
-void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMATxDescTab, uint8_t* TxBuff, uint32_t TxBuffCount);
-HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount);
-
-/**
- * @}
- */
-/* IO operation functions ****************************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group2
- * @{
- */
-HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength);
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame(ETH_HandleTypeDef *heth);
-/* Communication with PHY functions*/
-HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue);
-HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue);
-/* Non-Blocking mode: Interrupt */
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT(ETH_HandleTypeDef *heth);
-void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth);
-/* Callback in non blocking modes (Interrupt) */
-void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth);
-void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth);
-void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth);
-/**
- * @}
- */
-
-/* Peripheral Control functions **********************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group3
- * @{
- */
-
-HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf);
-HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf);
-/**
- * @}
- */
-
-/* Peripheral State functions ************************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group4
- * @{
- */
-HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth);
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F7xx_HAL_ETH_H */
-
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c
deleted file mode 100755
index ab0f676..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c
+++ /dev/null
@@ -1,1182 +0,0 @@
-/*
- * Some constants, hardware definitions and comments taken from ST's HAL driver
- * library, COPYRIGHT(c) 2015 STMicroelectronics.
- */
-
-/*
- * FreeRTOS+TCP V2.0.3
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://aws.amazon.com/freertos
- * http://www.FreeRTOS.org
- */
-
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "FreeRTOS_DNS.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-#include "phyHandling.h"
-
-/* ST includes. */
-#ifdef STM32F7xx
- #include "stm32f7xx_hal.h"
-#else
- #include "stm32f4xx_hal.h"
-#endif
-
-/* Interrupt events to process. Currently only the Rx event is processed
-although code for other events is included to allow for possible future
-expansion. */
-#define EMAC_IF_RX_EVENT 1UL
-#define EMAC_IF_TX_EVENT 2UL
-#define EMAC_IF_ERR_EVENT 4UL
-#define EMAC_IF_ALL_EVENT ( EMAC_IF_RX_EVENT | EMAC_IF_TX_EVENT | EMAC_IF_ERR_EVENT )
-
-#define ETH_DMA_ALL_INTS \
- ( ETH_DMA_IT_TST | ETH_DMA_IT_PMT | ETH_DMA_IT_MMC | ETH_DMA_IT_NIS | ETH_DMA_IT_ER | \
- ETH_DMA_IT_FBE | ETH_DMA_IT_RWT | ETH_DMA_IT_RPS | ETH_DMA_IT_RBU | ETH_DMA_IT_R | \
- ETH_DMA_IT_TU | ETH_DMA_IT_RO | ETH_DMA_IT_TJT | ETH_DMA_IT_TPS | ETH_DMA_IT_T )
-
-
-
-#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff ) /* The bits in the two byte IP header field that make up the fragment offset value. */
-
-/*
- * Most users will want a PHY that negotiates about
- * the connection properties: speed, dmix and duplex.
- * On some rare cases, you want to select what is being
- * advertised, properties like MDIX and duplex.
- */
-
-#if !defined( ipconfigETHERNET_AN_ENABLE )
- /* Enable auto-negotiation */
- #define ipconfigETHERNET_AN_ENABLE 1
-#endif
-
-#if !defined( ipconfigETHERNET_AUTO_CROSS_ENABLE )
- #define ipconfigETHERNET_AUTO_CROSS_ENABLE 1
-#endif
-
-#if( ipconfigETHERNET_AN_ENABLE == 0 )
- /*
- * The following three defines are only used in case there
- * is no auto-negotiation.
- */
- #if !defined( ipconfigETHERNET_CROSSED_LINK )
- #define ipconfigETHERNET_CROSSED_LINK 1
- #endif
-
- #if !defined( ipconfigETHERNET_USE_100MB )
- #define ipconfigETHERNET_USE_100MB 1
- #endif
-
- #if !defined( ipconfigETHERNET_USE_FULL_DUPLEX )
- #define ipconfigETHERNET_USE_FULL_DUPLEX 1
- #endif
-#endif /* ipconfigETHERNET_AN_ENABLE == 0 */
-
-/* Default the size of the stack used by the EMAC deferred handler task to twice
-the size of the stack used by the idle task - but allow this to be overridden in
-FreeRTOSConfig.h as configMINIMAL_STACK_SIZE is a user definable constant. */
-#ifndef configEMAC_TASK_STACK_SIZE
- #define configEMAC_TASK_STACK_SIZE ( 2 * configMINIMAL_STACK_SIZE )
-#endif
-
-/* Two choices must be made: RMII versus MII,
-and the index of the PHY in use ( between 0 and 31 ). */
-#ifndef ipconfigUSE_RMII
- #ifdef STM32F7xx
- #define ipconfigUSE_RMII 1
- #else
- #define ipconfigUSE_RMII 0
- #endif /* STM32F7xx */
-#endif /* ipconfigUSE_RMII */
-
-
-
-/*-----------------------------------------------------------*/
-
-/*
- * A deferred interrupt handler task that processes
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*
- * Force a negotiation with the Switch or Router and wait for LS.
- */
-static void prvEthernetUpdateConfig( BaseType_t xForce );
-
-/*
- * See if there is a new packet and forward it to the IP-task.
- */
-static BaseType_t prvNetworkInterfaceInput( void );
-
-#if( ipconfigUSE_LLMNR != 0 )
- /*
- * For LLMNR, an extra MAC-address must be configured to
- * be able to receive the multicast messages.
- */
- static void prvMACAddressConfig(ETH_HandleTypeDef *heth, uint32_t ulIndex, uint8_t *Addr);
-#endif
-
-/*
- * Check if a given packet should be accepted.
- */
-static BaseType_t xMayAcceptPacket( uint8_t *pcBuffer );
-
-/*
- * Initialise the TX descriptors.
- */
-static void prvDMATxDescListInit( void );
-
-/*
- * Initialise the RX descriptors.
- */
-static void prvDMARxDescListInit( void );
-
-/* After packets have been sent, the network
-buffers will be released. */
-static void vClearTXBuffers( void );
-
-/*-----------------------------------------------------------*/
-
-/* Bit map of outstanding ETH interrupt events for processing. Currently only
-the Rx interrupt is handled, although code is included for other events to
-enable future expansion. */
-static volatile uint32_t ulISREvents;
-
-#if( ipconfigUSE_LLMNR == 1 )
- static const uint8_t xLLMNR_MACAddress[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
-#endif
-
-static EthernetPhy_t xPhyObject;
-
-/* Ethernet handle. */
-static ETH_HandleTypeDef xETH;
-
-/* xTXDescriptorSemaphore is a counting semaphore with
-a maximum count of ETH_TXBUFNB, which is the number of
-DMA TX descriptors. */
-static SemaphoreHandle_t xTXDescriptorSemaphore = NULL;
-
-/*
- * Note: it is adviced to define both
- *
- * #define ipconfigZERO_COPY_RX_DRIVER 1
- * #define ipconfigZERO_COPY_TX_DRIVER 1
- *
- * The method using memcpy is slower and probaly uses more RAM memory.
- * The possibility is left in the code just for comparison.
- *
- * It is adviced to define ETH_TXBUFNB at least 4. Note that no
- * TX buffers are allocated in a zero-copy driver.
- */
-/* MAC buffers: ---------------------------------------------------------*/
-
-/* Put the DMA descriptors in '.first_data'.
-This is important for STM32F7, which has an L1 data cache.
-The first 64KB of the SRAM is not cached. */
-
-/* Ethernet Rx MA Descriptor */
-__attribute__ ((aligned (32)))
-__attribute__ ((section(".first_data")))
- ETH_DMADescTypeDef DMARxDscrTab[ ETH_RXBUFNB ];
-
-#if( ipconfigZERO_COPY_RX_DRIVER == 0 )
- /* Ethernet Receive Buffer */
- __ALIGN_BEGIN uint8_t Rx_Buff[ ETH_RXBUFNB ][ ETH_RX_BUF_SIZE ] __ALIGN_END;
-#endif
-
-/* Ethernet Tx DMA Descriptor */
-__attribute__ ((aligned (32)))
-__attribute__ ((section(".first_data")))
- ETH_DMADescTypeDef DMATxDscrTab[ ETH_TXBUFNB ];
-
-#if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- /* Ethernet Transmit Buffer */
- __ALIGN_BEGIN uint8_t Tx_Buff[ ETH_TXBUFNB ][ ETH_TX_BUF_SIZE ] __ALIGN_END;
-#endif
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- /* DMATxDescToClear points to the next TX DMA descriptor
- that must be cleared by vClearTXBuffers(). */
- static __IO ETH_DMADescTypeDef *DMATxDescToClear;
-#endif
-
-/* ucMACAddress as it appears in main.c */
-extern const uint8_t ucMACAddress[ 6 ];
-
-/* Holds the handle of the task used as a deferred interrupt processor. The
-handle is used so direct notifications can be sent to the task for all EMAC/DMA
-related interrupts. */
-static TaskHandle_t xEMACTaskHandle = NULL;
-
-/* For local use only: describe the PHY's properties: */
-const PhyProperties_t xPHYProperties =
-{
- #if( ipconfigETHERNET_AN_ENABLE != 0 )
- .ucSpeed = PHY_SPEED_AUTO,
- .ucDuplex = PHY_DUPLEX_AUTO,
- #else
- #if( ipconfigETHERNET_USE_100MB != 0 )
- .ucSpeed = PHY_SPEED_100,
- #else
- .ucSpeed = PHY_SPEED_10,
- #endif
-
- #if( ipconfigETHERNET_USE_FULL_DUPLEX != 0 )
- .duplex = PHY_DUPLEX_FULL,
- #else
- .duplex = PHY_DUPLEX_HALF,
- #endif
- #endif
-
- #if( ipconfigETHERNET_AN_ENABLE != 0 ) && ( ipconfigETHERNET_AUTO_CROSS_ENABLE != 0 )
- .ucMDI_X = PHY_MDIX_AUTO,
- #elif( ipconfigETHERNET_CROSSED_LINK != 0 )
- .ucMDI_X = PHY_MDIX_CROSSED,
- #else
- .ucMDI_X = PHY_MDIX_DIRECT,
- #endif
-};
-
-/*-----------------------------------------------------------*/
-
-void HAL_ETH_RxCpltCallback( ETH_HandleTypeDef *heth )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* Ethernet RX-Complete callback function, elsewhere declared as weak. */
- ulISREvents |= EMAC_IF_RX_EVENT;
- /* Wakeup the prvEMACHandlerTask. */
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
- }
-}
-/*-----------------------------------------------------------*/
-
-void HAL_ETH_TxCpltCallback( ETH_HandleTypeDef *heth )
-{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* This call-back is only useful in case packets are being sent
- zero-copy. Once they're sent, the buffers will be released
- by the function vClearTXBuffers(). */
- ulISREvents |= EMAC_IF_TX_EVENT;
- /* Wakeup the prvEMACHandlerTask. */
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
- }
-
-}
-/*-----------------------------------------------------------*/
-
-static void vClearTXBuffers()
-{
-__IO ETH_DMADescTypeDef *txLastDescriptor = xETH.TxDesc;
-size_t uxCount = ( ( UBaseType_t ) ETH_TXBUFNB ) - uxSemaphoreGetCount( xTXDescriptorSemaphore );
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- NetworkBufferDescriptor_t *pxNetworkBuffer;
- uint8_t *ucPayLoad;
-#endif
-
- /* This function is called after a TX-completion interrupt.
- It will release each Network Buffer used in xNetworkInterfaceOutput().
- 'uxCount' represents the number of descriptors given to DMA for transmission.
- After sending a packet, the DMA will clear the 'ETH_DMATXDESC_OWN' bit. */
- while( ( uxCount > 0 ) && ( ( DMATxDescToClear->Status & ETH_DMATXDESC_OWN ) == 0 ) )
- {
- if( ( DMATxDescToClear == txLastDescriptor ) && ( uxCount != ETH_TXBUFNB ) )
- {
- break;
- }
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- ucPayLoad = ( uint8_t * )DMATxDescToClear->Buffer1Addr;
-
- if( ucPayLoad != NULL )
- {
- pxNetworkBuffer = pxPacketBuffer_to_NetworkBuffer( ucPayLoad );
- if( pxNetworkBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ) ;
- }
- DMATxDescToClear->Buffer1Addr = ( uint32_t )0u;
- }
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- DMATxDescToClear = ( ETH_DMADescTypeDef * )( DMATxDescToClear->Buffer2NextDescAddr );
-
- uxCount--;
- /* Tell the counting semaphore that one more TX descriptor is available. */
- xSemaphoreGive( xTXDescriptorSemaphore );
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-HAL_StatusTypeDef hal_eth_init_status;
-BaseType_t xResult;
-
- if( xEMACTaskHandle == NULL )
- {
- if( xTXDescriptorSemaphore == NULL )
- {
- xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ETH_TXBUFNB, ( UBaseType_t ) ETH_TXBUFNB );
- configASSERT( xTXDescriptorSemaphore );
- }
-
- /* Initialise ETH */
-
- xETH.Instance = ETH;
- xETH.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
- xETH.Init.Speed = ETH_SPEED_100M;
- xETH.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
- /* Value of PhyAddress doesn't matter, will be probed for. */
- xETH.Init.PhyAddress = 0;
-
- xETH.Init.MACAddr = ( uint8_t *) ucMACAddress;
- xETH.Init.RxMode = ETH_RXINTERRUPT_MODE;
-
- /* using the ETH_CHECKSUM_BY_HARDWARE option:
- both the IP and the protocol checksums will be calculated
- by the peripheral. */
- xETH.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
-
- #if( ipconfigUSE_RMII != 0 )
- {
- xETH.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
- }
- #else
- {
- xETH.Init.MediaInterface = ETH_MEDIA_INTERFACE_MII;
- }
- #endif /* ipconfigUSE_RMII */
-
- hal_eth_init_status = HAL_ETH_Init( &xETH );
-
- /* Only for inspection by debugger. */
- ( void ) hal_eth_init_status;
-
- /* Set the TxDesc and RxDesc pointers. */
- xETH.TxDesc = DMATxDscrTab;
- xETH.RxDesc = DMARxDscrTab;
-
- /* Make sure that all unused fields are cleared. */
- memset( &DMATxDscrTab, '\0', sizeof( DMATxDscrTab ) );
- memset( &DMARxDscrTab, '\0', sizeof( DMARxDscrTab ) );
-
- /* Initialize Tx Descriptors list: Chain Mode */
- DMATxDescToClear = DMATxDscrTab;
-
- /* Initialise TX-descriptors. */
- prvDMATxDescListInit();
-
- /* Initialise RX-descriptors. */
- prvDMARxDescListInit();
-
- #if( ipconfigUSE_LLMNR != 0 )
- {
- /* Program the LLMNR address at index 1. */
- prvMACAddressConfig( &xETH, ETH_MAC_ADDRESS1, ( uint8_t *) xLLMNR_MACAddress );
- }
- #endif
-
- /* Force a negotiation with the Switch or Router and wait for LS. */
- prvEthernetUpdateConfig( pdTRUE );
-
- /* The deferred interrupt handler task is created at the highest
- possible priority to ensure the interrupt handler can return directly
- to it. The task's handle is stored in xEMACTaskHandle so interrupts can
- notify the task when there is something to process. */
- xTaskCreate( prvEMACHandlerTask, "EMAC", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
- } /* if( xEMACTaskHandle == NULL ) */
-
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- xETH.Instance->DMAIER |= ETH_DMA_ALL_INTS;
- xResult = pdPASS;
- FreeRTOS_printf( ( "Link Status is high\n" ) ) ;
- }
- else
- {
- /* For now pdFAIL will be returned. But prvEMACHandlerTask() is running
- and it will keep on checking the PHY and set 'ulLinkStatusMask' when necessary. */
- xResult = pdFAIL;
- FreeRTOS_printf( ( "Link Status still low\n" ) ) ;
- }
- /* When returning non-zero, the stack will become active and
- start DHCP (in configured) */
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-static void prvDMATxDescListInit()
-{
-ETH_DMADescTypeDef *pxDMADescriptor;
-BaseType_t xIndex;
-
- /* Get the pointer on the first member of the descriptor list */
- pxDMADescriptor = DMATxDscrTab;
-
- /* Fill each DMA descriptor with the right values */
- for( xIndex = 0; xIndex < ETH_TXBUFNB; xIndex++, pxDMADescriptor++ )
- {
- /* Set Second Address Chained bit */
- pxDMADescriptor->Status = ETH_DMATXDESC_TCH;
-
- #if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- {
- /* Set Buffer1 address pointer */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( Tx_Buff[ xIndex ] );
- }
- #endif
-
- if( xETH.Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE )
- {
- /* Set the DMA Tx descriptors checksum insertion for TCP, UDP, and ICMP */
- pxDMADescriptor->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if( xIndex < ETH_TXBUFNB - 1 )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) ( pxDMADescriptor + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) DMATxDscrTab;
- }
- }
-
- /* Set Transmit Descriptor List Address Register */
- xETH.Instance->DMATDLAR = ( uint32_t ) DMATxDscrTab;
-}
-/*-----------------------------------------------------------*/
-
-static void prvDMARxDescListInit()
-{
-ETH_DMADescTypeDef *pxDMADescriptor;
-BaseType_t xIndex;
- /*
- * RX-descriptors.
- */
-
- /* Get the pointer on the first member of the descriptor list */
- pxDMADescriptor = DMARxDscrTab;
-
- /* Fill each DMA descriptor with the right values */
- for( xIndex = 0; xIndex < ETH_RXBUFNB; xIndex++, pxDMADescriptor++ )
- {
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMADescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | (uint32_t)ETH_RX_BUF_SIZE;
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Set Buffer1 address pointer */
- NetworkBufferDescriptor_t *pxBuffer;
-
- pxBuffer = pxGetNetworkBufferWithDescriptor( ETH_RX_BUF_SIZE, 100ul );
- /* If the assert below fails, make sure that there are at least 'ETH_RXBUFNB'
- Network Buffers available during start-up ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) */
- configASSERT( pxBuffer != NULL );
- if( pxBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = (uint32_t)pxBuffer->pucEthernetBuffer;
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
- }
- }
- #else
- {
- /* Set Buffer1 address pointer */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( Rx_Buff[ xIndex ] );
- /* Set Own bit of the Rx descriptor Status */
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
- }
- #endif
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if( xIndex < ETH_RXBUFNB - 1 )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t )( pxDMADescriptor + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) DMARxDscrTab;
- }
-
- }
- /* Set Receive Descriptor List Address Register */
- xETH.Instance->DMARDLAR = ( uint32_t ) DMARxDscrTab;
-}
-/*-----------------------------------------------------------*/
-
-static void prvMACAddressConfig(ETH_HandleTypeDef *heth, uint32_t ulIndex, uint8_t *Addr)
-{
-uint32_t ulTempReg;
-
- /* Calculate the selected MAC address high register. */
- ulTempReg = 0x80000000ul | ( ( uint32_t ) Addr[ 5 ] << 8 ) | ( uint32_t ) Addr[ 4 ];
-
- /* Load the selected MAC address high register. */
- ( *(__IO uint32_t *)( ( uint32_t ) ( ETH_MAC_ADDR_HBASE + ulIndex ) ) ) = ulTempReg;
-
- /* Calculate the selected MAC address low register. */
- ulTempReg = ( ( uint32_t ) Addr[ 3 ] << 24 ) | ( ( uint32_t ) Addr[ 2 ] << 16 ) | ( ( uint32_t ) Addr[ 1 ] << 8 ) | Addr[ 0 ];
-
- /* Load the selected MAC address low register */
- ( *(__IO uint32_t *) ( ( uint32_t ) ( ETH_MAC_ADDR_LBASE + ulIndex ) ) ) = ulTempReg;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t bReleaseAfterSend )
-{
-BaseType_t xReturn = pdFAIL;
-uint32_t ulTransmitSize = 0;
-__IO ETH_DMADescTypeDef *pxDmaTxDesc;
-/* Do not wait too long for a free TX DMA buffer. */
-const TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 50u );
-
- #if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
- {
- ProtocolPacket_t *pxPacket;
-
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- configASSERT( bReleaseAfterSend != 0 );
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- /* If the peripheral must calculate the checksum, it wants
- the protocol checksum to have a value of zero. */
- pxPacket = ( ProtocolPacket_t * ) ( pxDescriptor->pucEthernetBuffer );
-
- if( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP )
- {
- pxPacket->xICMPPacket.xICMPHeader.usChecksum = ( uint16_t )0u;
- }
- }
- #endif
-
- /* Open a do {} while ( 0 ) loop to be able to call break. */
- do
- {
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- if( xSemaphoreTake( xTXDescriptorSemaphore, xBlockTimeTicks ) != pdPASS )
- {
- /* Time-out waiting for a free TX descriptor. */
- break;
- }
-
- /* This function does the actual transmission of the packet. The packet is
- contained in 'pxDescriptor' that is passed to the function. */
- pxDmaTxDesc = xETH.TxDesc;
-
- /* Is this buffer available? */
- configASSERT ( ( pxDmaTxDesc->Status & ETH_DMATXDESC_OWN ) == 0 );
-
- {
- /* Is this buffer available? */
- /* Get bytes in current buffer. */
- ulTransmitSize = pxDescriptor->xDataLength;
-
- if( ulTransmitSize > ETH_TX_BUF_SIZE )
- {
- ulTransmitSize = ETH_TX_BUF_SIZE;
- }
-
- #if( ipconfigZERO_COPY_TX_DRIVER == 0 )
- {
- /* Copy the bytes. */
- memcpy( ( void * ) pxDmaTxDesc->Buffer1Addr, pxDescriptor->pucEthernetBuffer, ulTransmitSize );
- }
- #else
- {
- /* Move the buffer. */
- pxDmaTxDesc->Buffer1Addr = ( uint32_t )pxDescriptor->pucEthernetBuffer;
- /* The Network Buffer has been passed to DMA, no need to release it. */
- bReleaseAfterSend = pdFALSE_UNSIGNED;
- }
- #endif /* ipconfigZERO_COPY_TX_DRIVER */
-
- /* Ask to set the IPv4 checksum.
- Also need an Interrupt on Completion so that 'vClearTXBuffers()' will be called.. */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_CIC_TCPUDPICMP_FULL | ETH_DMATXDESC_IC;
-
- /* Prepare transmit descriptors to give to DMA. */
-
- /* Set LAST and FIRST segment */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_FS | ETH_DMATXDESC_LS;
- /* Set frame size */
- pxDmaTxDesc->ControlBufferSize = ( ulTransmitSize & ETH_DMATXDESC_TBS1 );
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_OWN;
-
- /* Point to next descriptor */
- xETH.TxDesc = ( ETH_DMADescTypeDef * ) ( xETH.TxDesc->Buffer2NextDescAddr );
- /* Ensure completion of memory access */
- __DSB();
- /* Resume DMA transmission*/
- xETH.Instance->DMATPDR = 0;
- iptraceNETWORK_INTERFACE_TRANSMIT();
- xReturn = pdPASS;
- }
- }
- else
- {
- /* The PHY has no Link Status, packet shall be dropped. */
- }
- } while( 0 );
- /* The buffer has been sent so can be released. */
- if( bReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t xMayAcceptPacket( uint8_t *pcBuffer )
-{
-const ProtocolPacket_t *pxProtPacket = ( const ProtocolPacket_t * )pcBuffer;
-
- switch( pxProtPacket->xTCPPacket.xEthernetHeader.usFrameType )
- {
- case ipARP_FRAME_TYPE:
- /* Check it later. */
- return pdTRUE;
- case ipIPv4_FRAME_TYPE:
- /* Check it here. */
- break;
- default:
- /* Refuse the packet. */
- return pdFALSE;
- }
-
- #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
- {
- const IPHeader_t *pxIPHeader = &(pxProtPacket->xTCPPacket.xIPHeader);
- uint32_t ulDestinationIPAddress;
-
- /* Ensure that the incoming packet is not fragmented (only outgoing packets
- * can be fragmented) as these are the only handled IP frames currently. */
- if( ( pxIPHeader->usFragmentOffset & FreeRTOS_ntohs( ipFRAGMENT_OFFSET_BIT_MASK ) ) != 0U )
- {
- return pdFALSE;
- }
- /* HT: Might want to make the following configurable because
- * most IP messages have a standard length of 20 bytes */
-
- /* 0x45 means: IPv4 with an IP header of 5 x 4 = 20 bytes
- * 0x47 means: IPv4 with an IP header of 7 x 4 = 28 bytes */
- if( pxIPHeader->ucVersionHeaderLength < 0x45 || pxIPHeader->ucVersionHeaderLength > 0x4F )
- {
- return pdFALSE;
- }
-
- ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;
- /* Is the packet for this node? */
- if( ( ulDestinationIPAddress != *ipLOCAL_IP_ADDRESS_POINTER ) &&
- /* Is it a broadcast address x.x.x.255 ? */
- ( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xff ) != 0xff ) &&
- #if( ipconfigUSE_LLMNR == 1 )
- ( ulDestinationIPAddress != ipLLMNR_IP_ADDR ) &&
- #endif
- ( *ipLOCAL_IP_ADDRESS_POINTER != 0 ) ) {
- FreeRTOS_printf( ( "Drop IP %lxip\n", FreeRTOS_ntohl( ulDestinationIPAddress ) ) );
- return pdFALSE;
- }
-
- if( pxIPHeader->ucProtocol == ipPROTOCOL_UDP )
- {
- uint16_t port = pxProtPacket->xUDPPacket.xUDPHeader.usDestinationPort;
-
- if( ( xPortHasUDPSocket( port ) == pdFALSE )
- #if ipconfigUSE_LLMNR == 1
- && ( port != FreeRTOS_ntohs( ipLLMNR_PORT ) )
- #endif
- #if ipconfigUSE_NBNS == 1
- && ( port != FreeRTOS_ntohs( ipNBNS_PORT ) )
- #endif
- #if ipconfigUSE_DNS == 1
- && ( pxProtPacket->xUDPPacket.xUDPHeader.usSourcePort != FreeRTOS_ntohs( ipDNS_PORT ) )
- #endif
- ) {
- /* Drop this packet, not for this device. */
- return pdFALSE;
- }
- }
- }
- #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvNetworkInterfaceInput( void )
-{
-NetworkBufferDescriptor_t *pxCurDescriptor;
-NetworkBufferDescriptor_t *pxNewDescriptor = NULL;
-BaseType_t xReceivedLength, xAccepted;
-__IO ETH_DMADescTypeDef *pxDMARxDescriptor;
-xIPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-const TickType_t xDescriptorWaitTime = pdMS_TO_TICKS( 250 );
-uint8_t *pucBuffer;
-
- pxDMARxDescriptor = xETH.RxDesc;
-
- if( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_OWN) == 0 )
- {
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- xReceivedLength = ( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_FL ) >> ETH_DMARXDESC_FRAMELENGTHSHIFT ) - 4;
-
- pucBuffer = (uint8_t *) pxDMARxDescriptor->Buffer1Addr;
-
- /* Update the ETHERNET DMA global Rx descriptor with next Rx descriptor */
- /* Chained Mode */
- /* Selects the next DMA Rx descriptor list for next buffer to read */
- xETH.RxDesc = ( ETH_DMADescTypeDef* )pxDMARxDescriptor->Buffer2NextDescAddr;
- }
- else
- {
- xReceivedLength = 0;
- }
-
- /* Obtain the size of the packet and put it into the "usReceivedLength" variable. */
- /* In order to make the code easier and faster, only packets in a single buffer
- will be accepted. This can be done by making the buffers large enough to
- hold a complete Ethernet packet (1536 bytes). */
- if( xReceivedLength > 0ul && xReceivedLength < ETH_RX_BUF_SIZE )
- {
- if( ( pxDMARxDescriptor->Status & ( ETH_DMARXDESC_CE | ETH_DMARXDESC_IPV4HCE | ETH_DMARXDESC_FT ) ) != ETH_DMARXDESC_FT )
- {
- /* Not an Ethernet frame-type or a checmsum error. */
- xAccepted = pdFALSE;
- }
- else
- {
- /* See if this packet must be handled. */
- xAccepted = xMayAcceptPacket( pucBuffer );
- }
-
- if( xAccepted != pdFALSE )
- {
- /* The packet wil be accepted, but check first if a new Network Buffer can
- be obtained. If not, the packet will still be dropped. */
- pxNewDescriptor = pxGetNetworkBufferWithDescriptor( ETH_RX_BUF_SIZE, xDescriptorWaitTime );
-
- if( pxNewDescriptor == NULL )
- {
- /* A new descriptor can not be allocated now. This packet will be dropped. */
- xAccepted = pdFALSE;
- }
- }
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Find out which Network Buffer was originally passed to the descriptor. */
- pxCurDescriptor = pxPacketBuffer_to_NetworkBuffer( pucBuffer );
- configASSERT( pxCurDescriptor != NULL );
- }
- #else
- {
- /* In this mode, the two descriptors are the same. */
- pxCurDescriptor = pxNewDescriptor;
- if( pxNewDescriptor != NULL )
- {
- /* The packet is acepted and a new Network Buffer was created,
- copy data to the Network Bufffer. */
- memcpy( pxNewDescriptor->pucEthernetBuffer, pucBuffer, xReceivedLength );
- }
- }
- #endif
-
- if( xAccepted != pdFALSE )
- {
- pxCurDescriptor->xDataLength = xReceivedLength;
- xRxEvent.pvData = ( void * ) pxCurDescriptor;
-
- /* Pass the data to the TCP/IP task for processing. */
- if( xSendEventStructToIPTask( &xRxEvent, xDescriptorWaitTime ) == pdFALSE )
- {
- /* Could not send the descriptor into the TCP/IP stack, it
- must be released. */
- vReleaseNetworkBufferAndDescriptor( pxCurDescriptor );
- iptraceETHERNET_RX_EVENT_LOST();
- }
- else
- {
- iptraceNETWORK_INTERFACE_RECEIVE();
- }
- }
-
- /* Release descriptors to DMA */
- #if( ipconfigZERO_COPY_RX_DRIVER != 0 )
- {
- /* Set Buffer1 address pointer */
- if( pxNewDescriptor != NULL )
- {
- pxDMARxDescriptor->Buffer1Addr = (uint32_t)pxNewDescriptor->pucEthernetBuffer;
- }
- else
- {
- /* The packet was dropped and the same Network
- Buffer will be used to receive a new packet. */
- }
- }
- #endif /* ipconfigZERO_COPY_RX_DRIVER */
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMARxDescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | (uint32_t)ETH_RX_BUF_SIZE;
- pxDMARxDescriptor->Status = ETH_DMARXDESC_OWN;
-
- /* Ensure completion of memory access */
- __DSB();
- /* When Rx Buffer unavailable flag is set clear it and resume
- reception. */
- if( ( xETH.Instance->DMASR & ETH_DMASR_RBUS ) != 0 )
- {
- /* Clear RBUS ETHERNET DMA flag. */
- xETH.Instance->DMASR = ETH_DMASR_RBUS;
-
- /* Resume DMA reception. */
- xETH.Instance->DMARPDR = 0;
- }
- }
-
- return ( xReceivedLength > 0 );
-}
-/*-----------------------------------------------------------*/
-
-
-BaseType_t xSTM32_PhyRead( BaseType_t xAddress, BaseType_t xRegister, uint32_t *pulValue )
-{
-uint16_t usPrevAddress = xETH.Init.PhyAddress;
-BaseType_t xResult;
-HAL_StatusTypeDef xHALResult;
-
- xETH.Init.PhyAddress = xAddress;
- xHALResult = HAL_ETH_ReadPHYRegister( &xETH, ( uint16_t )xRegister, pulValue );
- xETH.Init.PhyAddress = usPrevAddress;
-
- if( xHALResult == HAL_OK )
- {
- xResult = 0;
- }
- else
- {
- xResult = -1;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xSTM32_PhyWrite( BaseType_t xAddress, BaseType_t xRegister, uint32_t ulValue )
-{
-uint16_t usPrevAddress = xETH.Init.PhyAddress;
-BaseType_t xResult;
-HAL_StatusTypeDef xHALResult;
-
- xETH.Init.PhyAddress = xAddress;
- xHALResult = HAL_ETH_WritePHYRegister( &xETH, ( uint16_t )xRegister, ulValue );
- xETH.Init.PhyAddress = usPrevAddress;
-
- if( xHALResult == HAL_OK )
- {
- xResult = 0;
- }
- else
- {
- xResult = -1;
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-void phy_test()
-{
-BaseType_t xPhyCount;
-BaseType_t xPhyIndex;
-
- vPhyInitialise( &xPhyObject, xSTM32_PhyRead, xSTM32_PhyWrite );
- xPhyCount = xPhyDiscover( &xPhyObject );
- FreeRTOS_printf( ( "PHY count %ld\n", xPhyCount ) );
- for( xPhyIndex = 0; xPhyIndex < xPhyCount; xPhyIndex++ )
- {
- FreeRTOS_printf( ( "PHY[%d] at address %d ( 0x%08X )\n",
- xPhyIndex,
- xPhyObject.ucPhyIndexes[ xPhyIndex ],
- xPhyObject.ulPhyIDs[ xPhyIndex ] ) );
-
- }
-
-}
-
-void vMACBProbePhy( void )
-{
- vPhyInitialise( &xPhyObject, xSTM32_PhyRead, xSTM32_PhyWrite );
- xPhyDiscover( &xPhyObject );
- xPhyConfigure( &xPhyObject, &xPHYProperties );
-}
-/*-----------------------------------------------------------*/
-
-static void prvEthernetUpdateConfig( BaseType_t xForce )
-{
- FreeRTOS_printf( ( "prvEthernetUpdateConfig: LS mask %02lX Force %d\n",
- xPhyObject.ulLinkStatusMask,
- ( int )xForce ) );
-
- if( ( xForce != pdFALSE ) || ( xPhyObject.ulLinkStatusMask != 0 ) )
- {
- /* Restart the auto-negotiation. */
- if( xETH.Init.AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE )
- {
- xPhyStartAutoNegotiation( &xPhyObject, xPhyGetMask( &xPhyObject ) );
-
- /* Configure the MAC with the Duplex Mode fixed by the
- auto-negotiation process. */
- if( xPhyObject.xPhyProperties.ucDuplex == PHY_DUPLEX_FULL )
- {
- xETH.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
- }
- else
- {
- xETH.Init.DuplexMode = ETH_MODE_HALFDUPLEX;
- }
-
- /* Configure the MAC with the speed fixed by the
- auto-negotiation process. */
- if( xPhyObject.xPhyProperties.ucSpeed == PHY_SPEED_10 )
- {
- xETH.Init.Speed = ETH_SPEED_10M;
- }
- else
- {
- xETH.Init.Speed = ETH_SPEED_100M;
- }
- }
- else /* AutoNegotiation Disable */
- {
- /* Check parameters */
- assert_param( IS_ETH_SPEED( xETH.Init.Speed ) );
- assert_param( IS_ETH_DUPLEX_MODE( xETH.Init.DuplexMode ) );
-
- if( xETH.Init.DuplexMode == ETH_MODE_FULLDUPLEX )
- {
- xPhyObject.xPhyPreferences.ucDuplex = PHY_DUPLEX_HALF;
- }
- else
- {
- xPhyObject.xPhyPreferences.ucDuplex = PHY_DUPLEX_FULL;
- }
-
- if( xETH.Init.Speed == ETH_SPEED_10M )
- {
- xPhyObject.xPhyPreferences.ucSpeed = PHY_SPEED_10;
- }
- else
- {
- xPhyObject.xPhyPreferences.ucSpeed = PHY_SPEED_100;
- }
-
- xPhyObject.xPhyPreferences.ucMDI_X = PHY_MDIX_AUTO;
-
- /* Use predefined (fixed) configuration. */
- xPhyFixedValue( &xPhyObject, xPhyGetMask( &xPhyObject ) );
- }
-
- /* ETHERNET MAC Re-Configuration */
- HAL_ETH_ConfigMAC( &xETH, (ETH_MACInitTypeDef *) NULL);
-
- /* Restart MAC interface */
- HAL_ETH_Start( &xETH);
- }
- else
- {
- /* Stop MAC interface */
- HAL_ETH_Stop( &xETH );
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xReturn;
-
- if( xPhyObject.ulLinkStatusMask != 0 )
- {
- xReturn = pdPASS;
- }
- else
- {
- xReturn = pdFAIL;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-/* Uncomment this in case BufferAllocation_1.c is used. */
-
-/*
-#define niBUFFER_1_PACKET_SIZE 1536
-
-static __attribute__ ((section(".first_data"))) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__ ( ( aligned( 32 ) ) );
-
-void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
-{
-
-uint8_t *ucRAMBuffer = ucNetworkPackets;
-uint32_t ul;
-
- for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ )
- {
- pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING;
- *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
- ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
- }
-}
-*/
-/*-----------------------------------------------------------*/
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-UBaseType_t uxLastMinBufferCount = 0;
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
-UBaseType_t uxLastMinQueueSpace = 0;
-#endif
-UBaseType_t uxCurrentCount;
-BaseType_t xResult;
-const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100UL );
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- xResult = 0;
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
- if( xTXDescriptorSemaphore != NULL )
- {
- static UBaseType_t uxLowestSemCount = ( UBaseType_t ) ETH_TXBUFNB - 1;
-
- uxCurrentCount = uxSemaphoreGetCount( xTXDescriptorSemaphore );
- if( uxLowestSemCount > uxCurrentCount )
- {
- uxLowestSemCount = uxCurrentCount;
- FreeRTOS_printf( ( "TX DMA buffers: lowest %lu\n", uxLowestSemCount ) );
- }
-
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- if( ( ulISREvents & EMAC_IF_ALL_EVENT ) == 0 )
- {
- /* No events to process now, wait for the next. */
- ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
- }
-
- if( ( ulISREvents & EMAC_IF_RX_EVENT ) != 0 )
- {
- ulISREvents &= ~EMAC_IF_RX_EVENT;
-
- xResult = prvNetworkInterfaceInput();
- if( xResult > 0 )
- {
- while( prvNetworkInterfaceInput() > 0 )
- {
- }
- }
- }
-
- if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0 )
- {
- /* Code to release TX buffers if zero-copy is used. */
- ulISREvents &= ~EMAC_IF_TX_EVENT;
- /* Check if DMA packets have been delivered. */
- vClearTXBuffers();
- }
-
- if( ( ulISREvents & EMAC_IF_ERR_EVENT ) != 0 )
- {
- /* Future extension: logging about errors that occurred. */
- ulISREvents &= ~EMAC_IF_ERR_EVENT;
- }
- if( xPhyCheckLinkStatus( &xPhyObject, xResult ) != 0 )
- {
- /* Something has changed to a Link Status, need re-check. */
- prvEthernetUpdateConfig( pdFALSE );
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-void ETH_IRQHandler( void )
-{
- HAL_ETH_IRQHandler( &xETH );
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.c
deleted file mode 100755
index 3e20acb..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.c
+++ /dev/null
@@ -1,1833 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_eth.c
- * @author MCD Application Team
- * @version V1.3.2
- * @date 26-June-2015
- * @brief ETH HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the Ethernet (ETH) peripheral:
- * + Initialization and de-initialization functions
- * + IO operation functions
- * + Peripheral Control functions
- * + Peripheral State and Errors functions
- *
- @verbatim
- ==============================================================================
- ##### How to use this driver #####
- ==============================================================================
- [..]
- (#)Declare a ETH_HandleTypeDef handle structure, for example:
- ETH_HandleTypeDef heth;
-
- (#)Fill parameters of Init structure in heth handle
-
- (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...)
-
- (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:
- (##) Enable the Ethernet interface clock using
- (+++) __HAL_RCC_ETHMAC_CLK_ENABLE();
- (+++) __HAL_RCC_ETHMACTX_CLK_ENABLE();
- (+++) __HAL_RCC_ETHMACRX_CLK_ENABLE();
-
- (##) Initialize the related GPIO clocks
- (##) Configure Ethernet pin-out
- (##) Configure Ethernet NVIC interrupt (IT mode)
-
- (#)Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers:
- (##) HAL_ETH_DMATxDescListInit(); for Transmission process
- (##) HAL_ETH_DMARxDescListInit(); for Reception process
-
- (#)Enable MAC and DMA transmission and reception:
- (##) HAL_ETH_Start();
-
- (#)Prepare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer
- the frame to MAC TX FIFO:
- (##) HAL_ETH_TransmitFrame();
-
- (#)Poll for a received frame in ETH RX DMA Descriptors and get received
- frame parameters
- (##) HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop)
-
- (#) Get a received frame when an ETH RX interrupt occurs:
- (##) HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only)
-
- (#) Communicate with external PHY device:
- (##) Read a specific register from the PHY
- HAL_ETH_ReadPHYRegister();
- (##) Write data to a specific RHY register:
- HAL_ETH_WritePHYRegister();
-
- (#) Configure the Ethernet MAC after ETH peripheral initialization
- HAL_ETH_ConfigMAC(); all MAC parameters should be filled.
-
- (#) Configure the Ethernet DMA after ETH peripheral initialization
- HAL_ETH_ConfigDMA(); all DMA parameters should be filled.
-
- -@- The PTP protocol and the DMA descriptors ring mode are not supported
- in this driver
-
- @endverbatim
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2015 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx_hal.h"
-
-int lUDPLoggingPrintf( const char *pcFormatString, ... );
-
-/** @addtogroup STM32F4xx_HAL_Driver
- * @{
- */
-
-/** @defgroup ETH ETH
- * @brief ETH HAL module driver
- * @{
- */
-
-#if !defined( ARRAY_SIZE )
- #define ARRAY_SIZE( x ) ( sizeof ( x ) / sizeof ( x )[ 0 ] )
-#endif
-
-#ifdef HAL_ETH_MODULE_ENABLED
-
-#if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/** @defgroup ETH_Private_Constants ETH Private Constants
- * @{
- */
-#define LINKED_STATE_TIMEOUT_VALUE ((uint32_t)2000) /* 2000 ms */
-#define AUTONEGO_COMPLETED_TIMEOUT_VALUE ((uint32_t)1000) /* 1000 ms */
-
-/**
- * @}
- */
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/** @defgroup ETH_Private_Functions ETH Private Functions
- * @{
- */
-static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);
-static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);
-static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);
-static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);
-static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);
-static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);
-static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);
-static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);
-static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);
-static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);
-static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);
-
-/**
- * @}
- */
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup ETH_Exported_Functions ETH Exported Functions
- * @{
- */
-
-/** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions
- * @brief Initialization and Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Initialization and de-initialization functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) Initialize and configure the Ethernet peripheral
- (+) De-initialize the Ethernet peripheral
-
- @endverbatim
- * @{
- */
-extern void vMACBProbePhy ( void );
-
-/**
- * @brief Initializes the Ethernet MAC and DMA according to default
- * parameters.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = 0;
- uint32_t hclk = 60000000;
- uint32_t err = ETH_SUCCESS;
-
- /* Check the ETH peripheral state */
- if( heth == NULL )
- {
- return HAL_ERROR;
- }
-
- /* Check parameters */
- assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));
- assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));
- assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));
- assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));
-
- if( heth->State == HAL_ETH_STATE_RESET )
- {
- /* Init the low level hardware : GPIO, CLOCK, NVIC. */
- HAL_ETH_MspInit( heth );
- }
-
- /* Enable SYSCFG Clock */
- __HAL_RCC_SYSCFG_CLK_ENABLE();
-
- /* Select MII or RMII Mode*/
- SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);
- SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;
-
- /* Ethernet Software reset */
- /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
- /* After reset all the registers holds their respective reset values */
- /* Also enable EDFE: Enhanced descriptor format enable. */
- heth->Instance->DMABMR |= ETH_DMABMR_SR | ETH_DMABMR_EDE;
-
- /* Wait for software reset */
- while ((heth->Instance->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
- {
- }
-
- /*-------------------------------- MAC Initialization ----------------------*/
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
- /* Clear CSR Clock Range CR[2:0] bits */
- tmpreg &= ETH_MACMIIAR_CR_MASK;
-
- /* Get hclk frequency value (168,000,000) */
- hclk = HAL_RCC_GetHCLKFreq();
-
- /* Set CR bits depending on hclk value */
- if( ( hclk >= 20000000 ) && ( hclk < 35000000 ) )
- {
- /* CSR Clock Range between 20-35 MHz */
- tmpreg |= (uint32_t) ETH_MACMIIAR_CR_Div16;
- }
- else if( ( hclk >= 35000000 ) && ( hclk < 60000000 ) )
- {
- /* CSR Clock Range between 35-60 MHz */
- tmpreg |= ( uint32_t ) ETH_MACMIIAR_CR_Div26;
- }
- else if((hclk >= 60000000 ) && ( hclk < 100000000 ) )
- {
- /* CSR Clock Range between 60-100 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
- }
- else if((hclk >= 100000000 ) && ( hclk < 150000000))
- {
- /* CSR Clock Range between 100-150 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;
- }
- else /* ((hclk >= 150000000 ) && ( hclk <= 168000000)) */
- {
- /* CSR Clock Range between 150-168 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;
- }
-
- /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
- heth->Instance->MACMIIAR = (uint32_t)tmpreg;
-
- /* Initialise the MACB and set all PHY properties */
- vMACBProbePhy();
-
- /* Config MAC and DMA */
- ETH_MACDMAConfig(heth, err);
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief De-Initializes the ETH peripheral.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
-{
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */
- HAL_ETH_MspDeInit( heth );
-
- /* Set ETH HAL state to Disabled */
- heth->State= HAL_ETH_STATE_RESET;
-
- /* Release Lock */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the DMA Tx descriptors in chain mode.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param DMATxDescTab: Pointer to the first Tx desc list
- * @param TxBuff: Pointer to the first TxBuffer list
- * @param TxBuffCount: Number of the used Tx desc in the list
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *pxDMATable, uint8_t *ucDataBuffer, uint32_t ulBufferCount)
-{
- uint32_t i = 0;
- ETH_DMADescTypeDef *pxDMADescriptor;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Set the TxDesc pointer with the first one of the pxDMATable list */
- heth->TxDesc = pxDMATable;
-
- /* Fill each DMA descriptor with the right values */
- for( i=0; i < ulBufferCount; i++ )
- {
- /* Get the pointer on the ith member of the descriptor list */
- pxDMADescriptor = pxDMATable + i;
-
- /* Set Second Address Chained bit */
- pxDMADescriptor->Status = ETH_DMATXDESC_TCH;
-
- pxDMADescriptor->ControlBufferSize = 0;
-
- /* Set Buffer1 address pointer */
- if( ucDataBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( &ucDataBuffer[ i * ETH_TX_BUF_SIZE ] );
- }
- else
- {
- /* Buffer space is not provided because it uses zero-copy transmissions. */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )0u;
- }
-
- if (heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
- {
- /* Set the DMA Tx descriptors checksum insertion for TCP, UDP, and ICMP */
- pxDMADescriptor->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < ( ulBufferCount - 1 ) )
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) ( pxDMATable + i + 1 );
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) pxDMATable;
- }
- }
-
- /* Set Transmit Descriptor List Address Register */
- heth->Instance->DMATDLAR = ( uint32_t ) pxDMATable;
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the DMA Rx descriptors in chain mode.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param DMARxDescTab: Pointer to the first Rx desc list
- * @param RxBuff: Pointer to the first RxBuffer list
- * @param RxBuffCount: Number of the used Rx desc in the list
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *pxDMATable, uint8_t *ucDataBuffer, uint32_t ulBufferCount)
-{
- uint32_t i = 0;
- ETH_DMADescTypeDef *pxDMADescriptor;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Set the RxDesc pointer with the first one of the pxDMATable list */
- heth->RxDesc = pxDMATable;
-
- /* Fill each DMA descriptor with the right values */
- for(i=0; i < ulBufferCount; i++)
- {
- /* Get the pointer on the ith member of the descriptor list */
- pxDMADescriptor = pxDMATable+i;
-
- /* Set Own bit of the Rx descriptor Status */
- pxDMADescriptor->Status = ETH_DMARXDESC_OWN;
-
- /* Set Buffer1 size and Second Address Chained bit */
- pxDMADescriptor->ControlBufferSize = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;
-
- /* Set Buffer1 address pointer */
- if( ucDataBuffer != NULL )
- {
- pxDMADescriptor->Buffer1Addr = ( uint32_t )( &ucDataBuffer[ i * ETH_RX_BUF_SIZE ] );
- }
- else
- {
- /* Buffer space is not provided because it uses zero-copy reception. */
- pxDMADescriptor->Buffer1Addr = ( uint32_t )0u;
- }
-
- if( heth->Init.RxMode == ETH_RXINTERRUPT_MODE )
- {
- /* Enable Ethernet DMA Rx Descriptor interrupt */
- pxDMADescriptor->ControlBufferSize &= ~ETH_DMARXDESC_DIC;
- }
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < (ulBufferCount-1))
- {
- /* Set next descriptor address register with next descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = (uint32_t)(pxDMATable+i+1);
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- pxDMADescriptor->Buffer2NextDescAddr = ( uint32_t ) pxDMATable;
- }
- }
-
- /* Set Receive Descriptor List Address Register */
- heth->Instance->DMARDLAR = ( uint32_t ) pxDMATable;
-
- /* Set ETH HAL State to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Initializes the ETH MSP.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_MspInit could be implemented in the user file
- */
-}
-
-/**
- * @brief DeInitializes ETH MSP.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_MspDeInit could be implemented in the user file
- */
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group2 IO operation functions
- * @brief Data transfers functions
- *
- @verbatim
- ==============================================================================
- ##### IO operation functions #####
- ==============================================================================
- [..] This section provides functions allowing to:
- (+) Transmit a frame
- HAL_ETH_TransmitFrame();
- (+) Receive a frame
- HAL_ETH_GetReceivedFrame();
- HAL_ETH_GetReceivedFrame_IT();
- (+) Read from an External PHY register
- HAL_ETH_ReadPHYRegister();
- (+) Write to an External PHY register
- HAL_ETH_WritePHYRegister();
-
- @endverbatim
-
- * @{
- */
-
-/**
- * @brief Sends an Ethernet frame.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param FrameLength: Amount of data to be sent
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength)
-{
- uint32_t bufcount = 0, size = 0, i = 0;
- __IO ETH_DMADescTypeDef *pxDmaTxDesc = heth->TxDesc;
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- if( FrameLength == 0 )
- {
- /* Set ETH HAL state to READY */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- return HAL_ERROR;
- }
-
- /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
- if( ( pxDmaTxDesc->Status & ETH_DMATXDESC_OWN ) != ( uint32_t ) RESET )
- {
- /* OWN bit set */
- heth->State = HAL_ETH_STATE_BUSY_TX;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- return HAL_ERROR;
- }
-
- /* Get the number of needed Tx buffers for the current frame, rounding up. */
- bufcount = ( FrameLength + ETH_TX_BUF_SIZE - 1 ) / ETH_TX_BUF_SIZE;
-
- if (bufcount == 1)
- {
- /* Set LAST and FIRST segment */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_FS | ETH_DMATXDESC_LS;
- /* Set frame size */
- pxDmaTxDesc->ControlBufferSize = ( FrameLength & ETH_DMATXDESC_TBS1 );
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- pxDmaTxDesc->Status |= ETH_DMATXDESC_OWN;
- /* Point to next descriptor */
- heth->TxDesc = ( ETH_DMADescTypeDef * ) ( heth->TxDesc->Buffer2NextDescAddr );
- }
- else
- {
- for( i = 0; i < bufcount; i++ )
- {
- /* Clear FIRST and LAST segment bits */
- uint32_t ulStatus = heth->TxDesc->Status & ~( ETH_DMATXDESC_FS | ETH_DMATXDESC_LS );
-
- if( i == 0 )
- {
- /* Setting the first segment bit */
- heth->TxDesc->Status = ulStatus | ETH_DMATXDESC_FS;
- }
-
- /* Program size */
- if (i < (bufcount-1))
- {
- heth->TxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TBS1);
- }
- else
- {
- /* Setting the last segment bit */
- heth->TxDesc->Status = ulStatus | ETH_DMATXDESC_LS;
- size = FrameLength - (bufcount-1)*ETH_TX_BUF_SIZE;
- heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);
- }
-
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
- /* point to next descriptor */
- heth->TxDesc = (ETH_DMADescTypeDef *)( heth->TxDesc->Buffer2NextDescAddr );
- }
- }
-
- __DSB();
-
- /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
- if( ( heth->Instance->DMASR & ETH_DMASR_TBUS ) != ( uint32_t )RESET )
- {
- heth->Instance->DMACHTDR = ( uint32_t )pxDmaTxDesc;
-
- /* Clear TBUS ETHERNET DMA flag */
- heth->Instance->DMASR = ETH_DMASR_TBUS;
- /* Resume DMA transmission*/
- heth->Instance->DMATPDR = 0;
- }
-
- /* Set ETH HAL State to Ready */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Checks for received frames.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT( ETH_HandleTypeDef *heth )
-{
- return HAL_ETH_GetReceivedFrame( heth );
-}
-
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame( ETH_HandleTypeDef *heth )
-{
-uint32_t ulCounter = 0;
-ETH_DMADescTypeDef *pxDescriptor = heth->RxDesc;
-HAL_StatusTypeDef xResult = HAL_ERROR;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Check the ETH state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Scan descriptors owned by CPU */
- while( ( ( pxDescriptor->Status & ETH_DMARXDESC_OWN ) == 0ul ) && ( ulCounter < ETH_RXBUFNB ) )
- {
- uint32_t ulStatus = pxDescriptor->Status;
-
- /* Just for security. */
- ulCounter++;
-
- if( ( ulStatus & ( ETH_DMARXDESC_FS | ETH_DMARXDESC_LS ) ) == ( uint32_t )ETH_DMARXDESC_FS )
- {
- /* First segment in frame, but not the last. */
- heth->RxFrameInfos.FSRxDesc = pxDescriptor;
- heth->RxFrameInfos.LSRxDesc = ( ETH_DMADescTypeDef *)NULL;
- heth->RxFrameInfos.SegCount = 1;
- /* Point to next descriptor. */
- pxDescriptor = (ETH_DMADescTypeDef*) (pxDescriptor->Buffer2NextDescAddr);
- heth->RxDesc = pxDescriptor;
- }
- else if( ( ulStatus & ( ETH_DMARXDESC_LS | ETH_DMARXDESC_FS ) ) == 0ul )
- {
- /* This is an intermediate segment, not first, not last. */
- /* Increment segment count. */
- heth->RxFrameInfos.SegCount++;
- /* Move to the next descriptor. */
- pxDescriptor = ( ETH_DMADescTypeDef * ) ( pxDescriptor->Buffer2NextDescAddr );
- heth->RxDesc = pxDescriptor;
- }
- /* Must be a last segment */
- else
- {
- /* This is the last segment. */
- /* Check if last segment is first segment: one segment contains the frame */
- if( heth->RxFrameInfos.SegCount == 0 )
- {
- /* Remember the first segment. */
- heth->RxFrameInfos.FSRxDesc = pxDescriptor;
- }
-
- /* Increment segment count */
- heth->RxFrameInfos.SegCount++;
-
- /* Remember the last segment. */
- heth->RxFrameInfos.LSRxDesc = pxDescriptor;
-
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- heth->RxFrameInfos.length =
- ( ( ulStatus & ETH_DMARXDESC_FL ) >> ETH_DMARXDESC_FRAMELENGTHSHIFT ) - 4;
-
- /* Get the address of the buffer start address */
- heth->RxFrameInfos.buffer = heth->RxFrameInfos.FSRxDesc->Buffer1Addr;
-
- /* Point to next descriptor */
- heth->RxDesc = ( ETH_DMADescTypeDef * ) pxDescriptor->Buffer2NextDescAddr;
-
- /* Return OK status: a packet was received. */
- xResult = HAL_OK;
- break;
- }
- }
-
- /* Set ETH HAL State to Ready */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return xResult;
-}
-
-#if( STM32_ETHERNET_STATS != 0 )
-
- volatile int rx_count, tx_count, int_count;
- /**
- * @brief This function handles ETH interrupt request.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
- volatile int int_counts[32];
- volatile int tx_status[8];
- volatile unsigned sr_history[32];
- volatile int sr_head;
- #define STM32_STAT_INC( x ) do { ( x )++; } while( 0 )
-
-#else
- #define STM32_STAT_INC( x ) do { } while( 0 )
-#endif /* STM32_ETHERNET_STATS */
-
-#define ETH_DMA_ALL_INTS \
- ( ETH_DMA_IT_TST | ETH_DMA_IT_PMT | ETH_DMA_IT_MMC | ETH_DMA_IT_NIS | ETH_DMA_IT_AIS | ETH_DMA_IT_ER | \
- ETH_DMA_IT_FBE | ETH_DMA_IT_ET | ETH_DMA_IT_RWT | ETH_DMA_IT_RPS | ETH_DMA_IT_RBU | ETH_DMA_IT_R | \
- ETH_DMA_IT_TU | ETH_DMA_IT_RO | ETH_DMA_IT_TJT | ETH_DMA_IT_TPS | ETH_DMA_IT_T )
-
-//#define ETH_DMA_ALL_INTS ETH_DMA_IT_RBU | ETH_DMA_FLAG_T | ETH_DMA_FLAG_AIS
-
-#define INT_MASK ( ( uint32_t ) ~ ( ETH_DMA_IT_TBU ) )
-void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
-{
- uint32_t dmasr;
-
- STM32_STAT_INC( int_count );
-
- dmasr = heth->Instance->DMASR & ETH_DMA_ALL_INTS;
- heth->Instance->DMASR = dmasr;
-
-#if( STM32_ETHERNET_STATS != 0 )
- if( sr_head < ARRAY_SIZE( sr_history ) )
- {
- sr_history[ sr_head++ ] = dmasr;
- }
-
- {
- int i;
- for (i = 0; i < 32; i++) {
- if (dmasr & (1u << i)) {
- int_counts[i]++;
- }
- }
- tx_status[ ( dmasr >> 20 ) & 0x07 ]++;
- }
-#endif
-
- /* Frame received */
- if( ( dmasr & ( ETH_DMA_FLAG_R | ETH_DMA_IT_RBU ) ) != 0 )
- {
- /* Receive complete callback */
- HAL_ETH_RxCpltCallback( heth );
- STM32_STAT_INC( rx_count );
- }
- /* Frame transmitted */
- if( ( dmasr & ( ETH_DMA_FLAG_T ) ) != 0 )
- {
- /* Transfer complete callback */
- HAL_ETH_TxCpltCallback( heth );
- STM32_STAT_INC( tx_count );
- }
-
- /* ETH DMA Error */
- if( ( dmasr & ( ETH_DMA_FLAG_AIS ) ) != 0 )
- {
- /* Ethernet Error callback */
- HAL_ETH_ErrorCallback( heth );
- }
-}
-
-/**
- * @brief Tx Transfer completed callbacks.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Rx Transfer completed callbacks.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Ethernet transfer error callbacks
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-__weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
-{
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_ETH_TxCpltCallback could be implemented in the user file
- */
-}
-
-/**
- * @brief Reads a PHY register
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * PHY_BCR: Transceiver Basic Control Register,
- * PHY_BSR: Transceiver Basic Status Register.
- * More PHY register could be read depending on the used PHY
- * @param RegValue: PHY register value
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)
-{
-uint32_t tmpreg = 0;
-uint32_t tickstart = 0;
-HAL_StatusTypeDef xResult;
-
- /* Check parameters */
- assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
-
- /* Check the ETH peripheral state */
- if( heth->State == HAL_ETH_STATE_BUSY_RD )
- {
- xResult = HAL_BUSY;
- }
- else
- {
- __HAL_LOCK( heth );
-
- /* Set ETH HAL State to BUSY_RD */
- heth->State = HAL_ETH_STATE_BUSY_RD;
-
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
-
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~ETH_MACMIIAR_CR_MASK;
-
- /* Prepare the MII address register value */
- tmpreg |= ( ( ( uint32_t )heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA ); /* Set the PHY device address */
- tmpreg |= ( ( ( uint32_t )PHYReg << 6 ) & ETH_MACMIIAR_MR ); /* Set the PHY register address */
- tmpreg &= ~ETH_MACMIIAR_MW; /* Set the read mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
-
- /* Write the result value into the MII Address register */
- heth->Instance->MACMIIAR = tmpreg;
-
- /* Get tick */
- tickstart = HAL_GetTick();
-
- /* Check for the Busy flag */
- while( 1 )
- {
- tmpreg = heth->Instance->MACMIIAR;
-
- if( ( tmpreg & ETH_MACMIIAR_MB ) == 0ul )
- {
- /* Get MACMIIDR value */
- *RegValue = ( uint32_t ) heth->Instance->MACMIIDR;
- xResult = HAL_OK;
- break;
- }
- /* Check for the Timeout */
- if( ( HAL_GetTick( ) - tickstart ) > PHY_READ_TO )
- {
- xResult = HAL_TIMEOUT;
- break;
- }
-
- }
-
- /* Set ETH HAL State to READY */
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
- }
-
- if( xResult != HAL_OK )
- {
- lUDPLoggingPrintf( "ReadPHY: %d\n", xResult );
- }
- /* Return function status */
- return xResult;
-}
-
-/**
- * @brief Writes to a PHY register.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * PHY_BCR: Transceiver Control Register.
- * More PHY register could be written depending on the used PHY
- * @param RegValue: the value to write
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)
-{
-uint32_t tmpreg = 0;
-uint32_t tickstart = 0;
-HAL_StatusTypeDef xResult;
-
- /* Check parameters */
- assert_param( IS_ETH_PHY_ADDRESS( heth->Init.PhyAddress ) );
-
- /* Check the ETH peripheral state */
- if( heth->State == HAL_ETH_STATE_BUSY_WR )
- {
- xResult = HAL_BUSY;
- }
- else
- {
- __HAL_LOCK( heth );
-
- /* Set ETH HAL State to BUSY_WR */
- heth->State = HAL_ETH_STATE_BUSY_WR;
-
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = heth->Instance->MACMIIAR;
-
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~ETH_MACMIIAR_CR_MASK;
-
- /* Prepare the MII register address value */
- tmpreg |= ( ( ( uint32_t ) heth->Init.PhyAddress << 11 ) & ETH_MACMIIAR_PA ); /* Set the PHY device address */
- tmpreg |= ( ( ( uint32_t ) PHYReg << 6 ) & ETH_MACMIIAR_MR ); /* Set the PHY register address */
- tmpreg |= ETH_MACMIIAR_MW; /* Set the write mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
-
- /* Give the value to the MII data register */
- heth->Instance->MACMIIDR = ( uint16_t ) RegValue;
-
- /* Write the result value into the MII Address register */
- heth->Instance->MACMIIAR = tmpreg;
-
- /* Get tick */
- tickstart = HAL_GetTick();
-
- /* Check for the Busy flag */
- while( 1 )
- {
- tmpreg = heth->Instance->MACMIIAR;
-
- if( ( tmpreg & ETH_MACMIIAR_MB ) == 0ul )
- {
- xResult = HAL_OK;
- break;
- }
- /* Check for the Timeout */
- if( ( HAL_GetTick( ) - tickstart ) > PHY_WRITE_TO )
- {
- xResult = HAL_TIMEOUT;
- break;
- }
- }
-
- /* Set ETH HAL State to READY */
- heth->State = HAL_ETH_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
- }
-
- if( xResult != HAL_OK )
- {
- lUDPLoggingPrintf( "WritePHY: %d\n", xResult );
- }
- /* Return function status */
- return xResult;
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions
- * @brief Peripheral Control functions
- *
-@verbatim
- ===============================================================================
- ##### Peripheral Control functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) Enable MAC and DMA transmission and reception.
- HAL_ETH_Start();
- (+) Disable MAC and DMA transmission and reception.
- HAL_ETH_Stop();
- (+) Set the MAC configuration in runtime mode
- HAL_ETH_ConfigMAC();
- (+) Set the DMA configuration in runtime mode
- HAL_ETH_ConfigDMA();
-
-@endverbatim
- * @{
- */
-
- /**
- * @brief Enables Ethernet MAC and DMA reception/transmission
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Start( ETH_HandleTypeDef *heth )
-{
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Enable transmit state machine of the MAC for transmission on the MII */
- ETH_MACTransmissionEnable( heth );
-
- /* Enable receive state machine of the MAC for reception from the MII */
- ETH_MACReceptionEnable( heth );
-
- /* Flush Transmit FIFO */
- ETH_FlushTransmitFIFO( heth );
-
- /* Start DMA transmission */
- ETH_DMATransmissionEnable( heth );
-
- /* Start DMA reception */
- ETH_DMAReceptionEnable( heth );
-
- /* Set the ETH state to READY*/
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Stop Ethernet MAC and DMA reception/transmission
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
-{
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State = HAL_ETH_STATE_BUSY;
-
- /* Stop DMA transmission */
- ETH_DMATransmissionDisable( heth );
-
- /* Stop DMA reception */
- ETH_DMAReceptionDisable( heth );
-
- /* Disable receive state machine of the MAC for reception from the MII */
- ETH_MACReceptionDisable( heth );
-
- /* Flush Transmit FIFO */
- ETH_FlushTransmitFIFO( heth );
-
- /* Disable transmit state machine of the MAC for transmission on the MII */
- ETH_MACTransmissionDisable( heth );
-
- /* Set the ETH state*/
- heth->State = HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-static void prvWriteMACFCR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->MACFCR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->MACFCR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->MACFCR = ulValue;
-}
-
-static void prvWriteDMAOMR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->DMAOMR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->DMAOMR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->DMAOMR = ulValue;
-}
-
-static void prvWriteMACCR( ETH_HandleTypeDef *heth, uint32_t ulValue)
-{
- /* Enable the MAC transmission */
- heth->Instance->MACCR = ulValue;
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles.
- Read it back, wait a ms and */
- ( void ) heth->Instance->MACCR;
-
- HAL_Delay( ETH_REG_WRITE_DELAY );
-
- heth->Instance->MACCR = ulValue;
-}
-
-/**
- * @brief Set ETH MAC Configuration.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param macconf: MAC Configuration structure
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)
-{
- uint32_t tmpreg = 0;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State= HAL_ETH_STATE_BUSY;
-
- assert_param(IS_ETH_SPEED(heth->Init.Speed));
- assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
-
- if (macconf != NULL)
- {
- /* Check the parameters */
- assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));
- assert_param(IS_ETH_JABBER(macconf->Jabber));
- assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));
- assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));
- assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));
- assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));
- assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));
- assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));
- assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));
- assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));
- assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));
- assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));
- assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));
- assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));
- assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));
- assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));
- assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));
- assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));
- assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));
- assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));
- assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));
- assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));
- assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));
- assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));
- assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));
- assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));
- assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));
-
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
- /* Clear WD, PCE, PS, TE and RE bits */
- tmpreg &= ETH_MACCR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)(
- macconf->Watchdog |
- macconf->Jabber |
- macconf->InterFrameGap |
- macconf->CarrierSense |
- heth->Init.Speed |
- macconf->ReceiveOwn |
- macconf->LoopbackMode |
- heth->Init.DuplexMode |
- macconf->ChecksumOffload |
- macconf->RetryTransmission |
- macconf->AutomaticPadCRCStrip |
- macconf->BackOffLimit |
- macconf->DeferralCheck);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACFFR Configuration --------------------*/
- /* Write to ETHERNET MACFFR */
- heth->Instance->MACFFR = (uint32_t)(
- macconf->ReceiveAll |
- macconf->SourceAddrFilter |
- macconf->PassControlFrames |
- macconf->BroadcastFramesReception |
- macconf->DestinationAddrFilter |
- macconf->PromiscuousMode |
- macconf->MulticastFramesFilter |
- macconf->UnicastFramesFilter);
-
- /* Wait until the write operation will be taken into account :
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACFFR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACFFR = tmpreg;
-
- /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
- /* Write to ETHERNET MACHTHR */
- heth->Instance->MACHTHR = (uint32_t)macconf->HashTableHigh;
-
- /* Write to ETHERNET MACHTLR */
- heth->Instance->MACHTLR = (uint32_t)macconf->HashTableLow;
- /*----------------------- ETHERNET MACFCR Configuration --------------------*/
-
- /* Get the ETHERNET MACFCR value */
- tmpreg = heth->Instance->MACFCR;
- /* Clear xx bits */
- tmpreg &= ETH_MACFCR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)((
- macconf->PauseTime << 16) |
- macconf->ZeroQuantaPause |
- macconf->PauseLowThreshold |
- macconf->UnicastPauseFrameDetect |
- macconf->ReceiveFlowControl |
- macconf->TransmitFlowControl);
-
- /* Write to ETHERNET MACFCR */
- prvWriteMACFCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
- heth->Instance->MACVLANTR = (uint32_t)(macconf->VLANTagComparison |
- macconf->VLANTagIdentifier);
-
- /* Wait until the write operation will be taken into account :
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACVLANTR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACVLANTR = tmpreg;
- }
- else /* macconf == NULL : here we just configure Speed and Duplex mode */
- {
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
-
- /* Clear FES and DM bits */
- tmpreg &= ~((uint32_t)0x00004800);
-
- tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
- }
-
- /* Set the ETH state to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @brief Sets ETH DMA Configuration.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param dmaconf: DMA Configuration structure
- * @retval HAL status
- */
-HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)
-{
- uint32_t tmpreg = 0;
-
- /* Process Locked */
- __HAL_LOCK( heth );
-
- /* Set the ETH peripheral state to BUSY */
- heth->State= HAL_ETH_STATE_BUSY;
-
- /* Check parameters */
- assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));
- assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));
- assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));
- assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));
- assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));
- assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));
- assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));
- assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));
- assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));
- assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));
- assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));
- assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));
- assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));
- assert_param(IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(dmaconf->EnhancedDescriptorFormat));
- assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));
- assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));
-
- /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
- /* Get the ETHERNET DMAOMR value */
- tmpreg = heth->Instance->DMAOMR;
- /* Clear xx bits */
- tmpreg &= ETH_DMAOMR_CLEAR_MASK;
-
- tmpreg |= (uint32_t)(
- dmaconf->DropTCPIPChecksumErrorFrame |
- dmaconf->ReceiveStoreForward |
- dmaconf->FlushReceivedFrame |
- dmaconf->TransmitStoreForward |
- dmaconf->TransmitThresholdControl |
- dmaconf->ForwardErrorFrames |
- dmaconf->ForwardUndersizedGoodFrames |
- dmaconf->ReceiveThresholdControl |
- dmaconf->SecondFrameOperate);
-
- /* Write to ETHERNET DMAOMR */
- prvWriteDMAOMR( heth, tmpreg );
-
- /*----------------------- ETHERNET DMABMR Configuration --------------------*/
- heth->Instance->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats |
- dmaconf->FixedBurst |
- dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
- dmaconf->TxDMABurstLength |
- dmaconf->EnhancedDescriptorFormat |
- (dmaconf->DescriptorSkipLength << 2) |
- dmaconf->DMAArbitration |
- ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->DMABMR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->DMABMR = tmpreg;
-
- /* Set the ETH state to Ready */
- heth->State= HAL_ETH_STATE_READY;
-
- /* Process Unlocked */
- __HAL_UNLOCK( heth );
-
- /* Return function status */
- return HAL_OK;
-}
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions
- * @brief Peripheral State functions
- *
- @verbatim
- ===============================================================================
- ##### Peripheral State functions #####
- ===============================================================================
- [..]
- This subsection permits to get in run-time the status of the peripheral
- and the data flow.
- (+) Get the ETH handle state:
- HAL_ETH_GetState();
-
-
- @endverbatim
- * @{
- */
-
-/**
- * @brief Return the ETH HAL state
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval HAL state
- */
-HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)
-{
- /* Return ETH state */
- return heth->State;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/** @addtogroup ETH_Private_Functions
- * @{
- */
-
-/**
- * @brief Configures Ethernet MAC and DMA with default parameters.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param err: Ethernet Init error
- * @retval HAL status
- */
-static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)
-{
- ETH_MACInitTypeDef macinit;
- ETH_DMAInitTypeDef dmainit;
- uint32_t tmpreg = 0;
-
- if (err != ETH_SUCCESS) /* Auto-negotiation failed */
- {
- /* Set Ethernet duplex mode to Full-duplex */
- heth->Init.DuplexMode = ETH_MODE_FULLDUPLEX;
-
- /* Set Ethernet speed to 100M */
- heth->Init.Speed = ETH_SPEED_100M;
- }
-
- /* Ethernet MAC default initialization **************************************/
- macinit.Watchdog = ETH_WATCHDOG_ENABLE;
- macinit.Jabber = ETH_JABBER_ENABLE;
- macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;
- macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;
- macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;
- macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;
- if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
- {
- macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
- }
- else
- {
- macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
- }
- macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;
- macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
- macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;
- macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;
- macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;
- macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
- macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
- macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;
- macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
- macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
- macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
- macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
- macinit.HashTableHigh = 0x0;
- macinit.HashTableLow = 0x0;
- macinit.PauseTime = 0x0;
- macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
- macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
- macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
- macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
- macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
- macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
- macinit.VLANTagIdentifier = 0x0;
-
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = heth->Instance->MACCR;
- /* Clear WD, PCE, PS, TE and RE bits */
- tmpreg &= ETH_MACCR_CLEAR_MASK;
- /* Set the WD bit according to ETH Watchdog value */
- /* Set the JD: bit according to ETH Jabber value */
- /* Set the IFG bit according to ETH InterFrameGap value */
- /* Set the DCRS bit according to ETH CarrierSense value */
- /* Set the FES bit according to ETH Speed value */
- /* Set the DO bit according to ETH ReceiveOwn value */
- /* Set the LM bit according to ETH LoopbackMode value */
- /* Set the DM bit according to ETH Mode value */
- /* Set the IPCO bit according to ETH ChecksumOffload value */
- /* Set the DR bit according to ETH RetryTransmission value */
- /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
- /* Set the BL bit according to ETH BackOffLimit value */
- /* Set the DC bit according to ETH DeferralCheck value */
- tmpreg |= (uint32_t)(macinit.Watchdog |
- macinit.Jabber |
- macinit.InterFrameGap |
- macinit.CarrierSense |
- heth->Init.Speed |
- macinit.ReceiveOwn |
- macinit.LoopbackMode |
- heth->Init.DuplexMode |
- macinit.ChecksumOffload |
- macinit.RetryTransmission |
- macinit.AutomaticPadCRCStrip |
- macinit.BackOffLimit |
- macinit.DeferralCheck);
-
- /* Write to ETHERNET MACCR */
- prvWriteMACCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACFFR Configuration --------------------*/
- /* Set the RA bit according to ETH ReceiveAll value */
- /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
- /* Set the PCF bit according to ETH PassControlFrames value */
- /* Set the DBF bit according to ETH BroadcastFramesReception value */
- /* Set the DAIF bit according to ETH DestinationAddrFilter value */
- /* Set the PR bit according to ETH PromiscuousMode value */
- /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
- /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
- /* Write to ETHERNET MACFFR */
- heth->Instance->MACFFR = (uint32_t)(macinit.ReceiveAll |
- macinit.SourceAddrFilter |
- macinit.PassControlFrames |
- macinit.BroadcastFramesReception |
- macinit.DestinationAddrFilter |
- macinit.PromiscuousMode |
- macinit.MulticastFramesFilter |
- macinit.UnicastFramesFilter);
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACFFR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACFFR = tmpreg;
-
- /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/
- /* Write to ETHERNET MACHTHR */
- heth->Instance->MACHTHR = (uint32_t)macinit.HashTableHigh;
-
- /* Write to ETHERNET MACHTLR */
- heth->Instance->MACHTLR = (uint32_t)macinit.HashTableLow;
- /*----------------------- ETHERNET MACFCR Configuration -------------------*/
-
- /* Get the ETHERNET MACFCR value */
- tmpreg = heth->Instance->MACFCR;
- /* Clear xx bits */
- tmpreg &= ETH_MACFCR_CLEAR_MASK;
-
- /* Set the PT bit according to ETH PauseTime value */
- /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
- /* Set the PLT bit according to ETH PauseLowThreshold value */
- /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
- /* Set the RFE bit according to ETH ReceiveFlowControl value */
- /* Set the TFE bit according to ETH TransmitFlowControl value */
- tmpreg |= (uint32_t)((macinit.PauseTime << 16) |
- macinit.ZeroQuantaPause |
- macinit.PauseLowThreshold |
- macinit.UnicastPauseFrameDetect |
- macinit.ReceiveFlowControl |
- macinit.TransmitFlowControl);
-
- /* Write to ETHERNET MACFCR */
- prvWriteMACFCR( heth, tmpreg );
-
- /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/
- /* Set the ETV bit according to ETH VLANTagComparison value */
- /* Set the VL bit according to ETH VLANTagIdentifier value */
- heth->Instance->MACVLANTR = (uint32_t)(macinit.VLANTagComparison |
- macinit.VLANTagIdentifier);
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->MACVLANTR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->MACVLANTR = tmpreg;
-
- /* Ethernet DMA default initialization ************************************/
- dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;
- dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
- dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
- dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
- dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
- dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
- dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
- dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
- dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;
- dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
- dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;
- dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
- dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
- dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;
- dmainit.DescriptorSkipLength = 0x0;
- dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
-
- /* Get the ETHERNET DMAOMR value */
- tmpreg = heth->Instance->DMAOMR;
- /* Clear xx bits */
- tmpreg &= ETH_DMAOMR_CLEAR_MASK;
-
- /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
- /* Set the RSF bit according to ETH ReceiveStoreForward value */
- /* Set the DFF bit according to ETH FlushReceivedFrame value */
- /* Set the TSF bit according to ETH TransmitStoreForward value */
- /* Set the TTC bit according to ETH TransmitThresholdControl value */
- /* Set the FEF bit according to ETH ForwardErrorFrames value */
- /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
- /* Set the RTC bit according to ETH ReceiveThresholdControl value */
- /* Set the OSF bit according to ETH SecondFrameOperate value */
- tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame |
- dmainit.ReceiveStoreForward |
- dmainit.FlushReceivedFrame |
- dmainit.TransmitStoreForward |
- dmainit.TransmitThresholdControl |
- dmainit.ForwardErrorFrames |
- dmainit.ForwardUndersizedGoodFrames |
- dmainit.ReceiveThresholdControl |
- dmainit.SecondFrameOperate);
-
- /* Write to ETHERNET DMAOMR */
- prvWriteDMAOMR( heth, tmpreg );
-
- /*----------------------- ETHERNET DMABMR Configuration ------------------*/
- /* Set the AAL bit according to ETH AddressAlignedBeats value */
- /* Set the FB bit according to ETH FixedBurst value */
- /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
- /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
- /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/
- /* Set the DSL bit according to ETH DesciptorSkipLength value */
- /* Set the PR and DA bits according to ETH DMAArbitration value */
- heth->Instance->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats |
- dmainit.FixedBurst |
- dmainit.RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
- dmainit.TxDMABurstLength |
- dmainit.EnhancedDescriptorFormat |
- (dmainit.DescriptorSkipLength << 2) |
- dmainit.DMAArbitration |
- ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
-
- /* Wait until the write operation will be taken into account:
- at least four TX_CLK/RX_CLK clock cycles */
- tmpreg = heth->Instance->DMABMR;
- HAL_Delay(ETH_REG_WRITE_DELAY);
- heth->Instance->DMABMR = tmpreg;
-
- if(heth->Init.RxMode == ETH_RXINTERRUPT_MODE)
- {
- /* Enable the Ethernet Rx Interrupt */
- __HAL_ETH_DMA_ENABLE_IT(( heth ), ETH_DMA_IT_NIS | ETH_DMA_IT_R);
- }
-
- /* Initialize MAC address in ethernet MAC */
- ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
-}
-
-/**
- * @brief Configures the selected MAC address.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @param MacAddr: The MAC address to configure
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address0: MAC Address0
- * @arg ETH_MAC_Address1: MAC Address1
- * @arg ETH_MAC_Address2: MAC Address2
- * @arg ETH_MAC_Address3: MAC Address3
- * @param Addr: Pointer to MAC address buffer data (6 bytes)
- * @retval HAL status
- */
-static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
-{
- uint32_t tmpreg;
-
- /* Check the parameters */
- assert_param( IS_ETH_MAC_ADDRESS0123( MacAddr ) );
-
- /* Calculate the selected MAC address high register */
- tmpreg = 0x80000000ul | ( ( uint32_t )Addr[ 5 ] << 8) | (uint32_t)Addr[ 4 ];
- /* Load the selected MAC address high register */
- ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_HBASE + MacAddr ) ) ) = tmpreg;
- /* Calculate the selected MAC address low register */
- tmpreg = ( ( uint32_t )Addr[ 3 ] << 24 ) | ( ( uint32_t )Addr[ 2 ] << 16 ) | ( ( uint32_t )Addr[ 1 ] << 8 ) | Addr[ 0 ];
-
- /* Load the selected MAC address low register */
- ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_LBASE + MacAddr ) ) ) = tmpreg;
-}
-
-/**
- * @brief Enables the MAC transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_TE;
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the MAC transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)
-{
- uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_TE );
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the MAC reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)
-{
- __IO uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_RE;
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the MAC reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)
-{
- __IO uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_RE );
-
- prvWriteMACCR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the DMA transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)
-{
- /* Enable the DMA transmission */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_ST;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the DMA transmission.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)
-{
- /* Disable the DMA transmission */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_ST );
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Enables the DMA reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)
-{
- /* Enable the DMA reception */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_SR;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Disables the DMA reception.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)
-{
- /* Disable the DMA reception */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_SR );
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @brief Clears the ETHERNET transmit FIFO.
- * @param heth: pointer to a ETH_HandleTypeDef structure that contains
- * the configuration information for ETHERNET module
- * @retval None
- */
-static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)
-{
- /* Set the Flush Transmit FIFO bit */
- __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_FTF;
-
- prvWriteDMAOMR( heth, tmpreg );
-}
-
-/**
- * @}
- */
-
-#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
-#endif /* HAL_ETH_MODULE_ENABLED */
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.h
deleted file mode 100755
index 599a325..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32f4xx_hal_eth.h
+++ /dev/null
@@ -1,2225 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_eth.h
- * @author MCD Application Team
- * @version V1.3.2
- * @date 26-June-2015
- * @brief Header file of ETH HAL module.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2015 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F4xx_HAL_ETH_H
-#define __STM32F4xx_HAL_ETH_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx_hal_def.h"
-
-/** @addtogroup STM32F4xx_HAL_Driver
- * @{
- */
-
-/** @addtogroup ETH
- * @{
- */
-
-/** @addtogroup ETH_Private_Macros
- * @{
- */
-#define IS_ETH_PHY_ADDRESS(ADDRESS) ((ADDRESS) <= 0x20)
-#define IS_ETH_AUTONEGOTIATION(CMD) (((CMD) == ETH_AUTONEGOTIATION_ENABLE) || \
- ((CMD) == ETH_AUTONEGOTIATION_DISABLE))
-#define IS_ETH_SPEED(SPEED) (((SPEED) == ETH_SPEED_10M) || \
- ((SPEED) == ETH_SPEED_100M))
-#define IS_ETH_DUPLEX_MODE(MODE) (((MODE) == ETH_MODE_FULLDUPLEX) || \
- ((MODE) == ETH_MODE_HALFDUPLEX))
-#define IS_ETH_DUPLEX_MODE(MODE) (((MODE) == ETH_MODE_FULLDUPLEX) || \
- ((MODE) == ETH_MODE_HALFDUPLEX))
-#define IS_ETH_RX_MODE(MODE) (((MODE) == ETH_RXPOLLING_MODE) || \
- ((MODE) == ETH_RXINTERRUPT_MODE))
-#define IS_ETH_RX_MODE(MODE) (((MODE) == ETH_RXPOLLING_MODE) || \
- ((MODE) == ETH_RXINTERRUPT_MODE))
-#define IS_ETH_RX_MODE(MODE) (((MODE) == ETH_RXPOLLING_MODE) || \
- ((MODE) == ETH_RXINTERRUPT_MODE))
-#define IS_ETH_CHECKSUM_MODE(MODE) (((MODE) == ETH_CHECKSUM_BY_HARDWARE) || \
- ((MODE) == ETH_CHECKSUM_BY_SOFTWARE))
-#define IS_ETH_MEDIA_INTERFACE(MODE) (((MODE) == ETH_MEDIA_INTERFACE_MII) || \
- ((MODE) == ETH_MEDIA_INTERFACE_RMII))
-#define IS_ETH_WATCHDOG(CMD) (((CMD) == ETH_WATCHDOG_ENABLE) || \
- ((CMD) == ETH_WATCHDOG_DISABLE))
-#define IS_ETH_JABBER(CMD) (((CMD) == ETH_JABBER_ENABLE) || \
- ((CMD) == ETH_JABBER_DISABLE))
-#define IS_ETH_INTER_FRAME_GAP(GAP) (((GAP) == ETH_INTERFRAMEGAP_96BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_88BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_80BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_72BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_64BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_56BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_48BIT) || \
- ((GAP) == ETH_INTERFRAMEGAP_40BIT))
-#define IS_ETH_CARRIER_SENSE(CMD) (((CMD) == ETH_CARRIERSENCE_ENABLE) || \
- ((CMD) == ETH_CARRIERSENCE_DISABLE))
-#define IS_ETH_RECEIVE_OWN(CMD) (((CMD) == ETH_RECEIVEOWN_ENABLE) || \
- ((CMD) == ETH_RECEIVEOWN_DISABLE))
-#define IS_ETH_LOOPBACK_MODE(CMD) (((CMD) == ETH_LOOPBACKMODE_ENABLE) || \
- ((CMD) == ETH_LOOPBACKMODE_DISABLE))
-#define IS_ETH_CHECKSUM_OFFLOAD(CMD) (((CMD) == ETH_CHECKSUMOFFLAOD_ENABLE) || \
- ((CMD) == ETH_CHECKSUMOFFLAOD_DISABLE))
-#define IS_ETH_RETRY_TRANSMISSION(CMD) (((CMD) == ETH_RETRYTRANSMISSION_ENABLE) || \
- ((CMD) == ETH_RETRYTRANSMISSION_DISABLE))
-#define IS_ETH_AUTOMATIC_PADCRC_STRIP(CMD) (((CMD) == ETH_AUTOMATICPADCRCSTRIP_ENABLE) || \
- ((CMD) == ETH_AUTOMATICPADCRCSTRIP_DISABLE))
-#define IS_ETH_BACKOFF_LIMIT(LIMIT) (((LIMIT) == ETH_BACKOFFLIMIT_10) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_8) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_4) || \
- ((LIMIT) == ETH_BACKOFFLIMIT_1))
-#define IS_ETH_DEFERRAL_CHECK(CMD) (((CMD) == ETH_DEFFERRALCHECK_ENABLE) || \
- ((CMD) == ETH_DEFFERRALCHECK_DISABLE))
-#define IS_ETH_RECEIVE_ALL(CMD) (((CMD) == ETH_RECEIVEALL_ENABLE) || \
- ((CMD) == ETH_RECEIVEAll_DISABLE))
-#define IS_ETH_SOURCE_ADDR_FILTER(CMD) (((CMD) == ETH_SOURCEADDRFILTER_NORMAL_ENABLE) || \
- ((CMD) == ETH_SOURCEADDRFILTER_INVERSE_ENABLE) || \
- ((CMD) == ETH_SOURCEADDRFILTER_DISABLE))
-#define IS_ETH_CONTROL_FRAMES(PASS) (((PASS) == ETH_PASSCONTROLFRAMES_BLOCKALL) || \
- ((PASS) == ETH_PASSCONTROLFRAMES_FORWARDALL) || \
- ((PASS) == ETH_PASSCONTROLFRAMES_FORWARDPASSEDADDRFILTER))
-#define IS_ETH_BROADCAST_FRAMES_RECEPTION(CMD) (((CMD) == ETH_BROADCASTFRAMESRECEPTION_ENABLE) || \
- ((CMD) == ETH_BROADCASTFRAMESRECEPTION_DISABLE))
-#define IS_ETH_DESTINATION_ADDR_FILTER(FILTER) (((FILTER) == ETH_DESTINATIONADDRFILTER_NORMAL) || \
- ((FILTER) == ETH_DESTINATIONADDRFILTER_INVERSE))
-#define IS_ETH_PROMISCUOUS_MODE(CMD) (((CMD) == ETH_PROMISCUOUS_MODE_ENABLE) || \
- ((CMD) == ETH_PROMISCUOUS_MODE_DISABLE))
-#define IS_ETH_MULTICAST_FRAMES_FILTER(FILTER) (((FILTER) == ETH_MULTICASTFRAMESFILTER_PERFECTHASHTABLE) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_HASHTABLE) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_PERFECT) || \
- ((FILTER) == ETH_MULTICASTFRAMESFILTER_NONE))
-#define IS_ETH_UNICAST_FRAMES_FILTER(FILTER) (((FILTER) == ETH_UNICASTFRAMESFILTER_PERFECTHASHTABLE) || \
- ((FILTER) == ETH_UNICASTFRAMESFILTER_HASHTABLE) || \
- ((FILTER) == ETH_UNICASTFRAMESFILTER_PERFECT))
-#define IS_ETH_PAUSE_TIME(TIME) ((TIME) <= 0xFFFF)
-#define IS_ETH_ZEROQUANTA_PAUSE(CMD) (((CMD) == ETH_ZEROQUANTAPAUSE_ENABLE) || \
- ((CMD) == ETH_ZEROQUANTAPAUSE_DISABLE))
-#define IS_ETH_PAUSE_LOW_THRESHOLD(THRESHOLD) (((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS4) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS28) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS144) || \
- ((THRESHOLD) == ETH_PAUSELOWTHRESHOLD_MINUS256))
-#define IS_ETH_UNICAST_PAUSE_FRAME_DETECT(CMD) (((CMD) == ETH_UNICASTPAUSEFRAMEDETECT_ENABLE) || \
- ((CMD) == ETH_UNICASTPAUSEFRAMEDETECT_DISABLE))
-#define IS_ETH_RECEIVE_FLOWCONTROL(CMD) (((CMD) == ETH_RECEIVEFLOWCONTROL_ENABLE) || \
- ((CMD) == ETH_RECEIVEFLOWCONTROL_DISABLE))
-#define IS_ETH_TRANSMIT_FLOWCONTROL(CMD) (((CMD) == ETH_TRANSMITFLOWCONTROL_ENABLE) || \
- ((CMD) == ETH_TRANSMITFLOWCONTROL_DISABLE))
-#define IS_ETH_VLAN_TAG_COMPARISON(COMPARISON) (((COMPARISON) == ETH_VLANTAGCOMPARISON_12BIT) || \
- ((COMPARISON) == ETH_VLANTAGCOMPARISON_16BIT))
-#define IS_ETH_VLAN_TAG_IDENTIFIER(IDENTIFIER) ((IDENTIFIER) <= 0xFFFF)
-#define IS_ETH_MAC_ADDRESS0123(ADDRESS) (((ADDRESS) == ETH_MAC_ADDRESS0) || \
- ((ADDRESS) == ETH_MAC_ADDRESS1) || \
- ((ADDRESS) == ETH_MAC_ADDRESS2) || \
- ((ADDRESS) == ETH_MAC_ADDRESS3))
-#define IS_ETH_MAC_ADDRESS123(ADDRESS) (((ADDRESS) == ETH_MAC_ADDRESS1) || \
- ((ADDRESS) == ETH_MAC_ADDRESS2) || \
- ((ADDRESS) == ETH_MAC_ADDRESS3))
-#define IS_ETH_MAC_ADDRESS_FILTER(FILTER) (((FILTER) == ETH_MAC_ADDRESSFILTER_SA) || \
- ((FILTER) == ETH_MAC_ADDRESSFILTER_DA))
-#define IS_ETH_MAC_ADDRESS_MASK(MASK) (((MASK) == ETH_MAC_ADDRESSMASK_BYTE6) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE5) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE4) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE3) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE2) || \
- ((MASK) == ETH_MAC_ADDRESSMASK_BYTE1))
-#define IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(CMD) (((CMD) == ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE) || \
- ((CMD) == ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE))
-#define IS_ETH_RECEIVE_STORE_FORWARD(CMD) (((CMD) == ETH_RECEIVESTOREFORWARD_ENABLE) || \
- ((CMD) == ETH_RECEIVESTOREFORWARD_DISABLE))
-#define IS_ETH_FLUSH_RECEIVE_FRAME(CMD) (((CMD) == ETH_FLUSHRECEIVEDFRAME_ENABLE) || \
- ((CMD) == ETH_FLUSHRECEIVEDFRAME_DISABLE))
-#define IS_ETH_TRANSMIT_STORE_FORWARD(CMD) (((CMD) == ETH_TRANSMITSTOREFORWARD_ENABLE) || \
- ((CMD) == ETH_TRANSMITSTOREFORWARD_DISABLE))
-#define IS_ETH_TRANSMIT_THRESHOLD_CONTROL(THRESHOLD) (((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_64BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_128BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_192BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_256BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_40BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_32BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_24BYTES) || \
- ((THRESHOLD) == ETH_TRANSMITTHRESHOLDCONTROL_16BYTES))
-#define IS_ETH_FORWARD_ERROR_FRAMES(CMD) (((CMD) == ETH_FORWARDERRORFRAMES_ENABLE) || \
- ((CMD) == ETH_FORWARDERRORFRAMES_DISABLE))
-#define IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(CMD) (((CMD) == ETH_FORWARDUNDERSIZEDGOODFRAMES_ENABLE) || \
- ((CMD) == ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE))
-#define IS_ETH_RECEIVE_THRESHOLD_CONTROL(THRESHOLD) (((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_32BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_96BYTES) || \
- ((THRESHOLD) == ETH_RECEIVEDTHRESHOLDCONTROL_128BYTES))
-#define IS_ETH_SECOND_FRAME_OPERATE(CMD) (((CMD) == ETH_SECONDFRAMEOPERARTE_ENABLE) || \
- ((CMD) == ETH_SECONDFRAMEOPERARTE_DISABLE))
-#define IS_ETH_ADDRESS_ALIGNED_BEATS(CMD) (((CMD) == ETH_ADDRESSALIGNEDBEATS_ENABLE) || \
- ((CMD) == ETH_ADDRESSALIGNEDBEATS_DISABLE))
-#define IS_ETH_FIXED_BURST(CMD) (((CMD) == ETH_FIXEDBURST_ENABLE) || \
- ((CMD) == ETH_FIXEDBURST_DISABLE))
-#define IS_ETH_RXDMA_BURST_LENGTH(LENGTH) (((LENGTH) == ETH_RXDMABURSTLENGTH_1BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_2BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_8BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_16BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_32BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_4BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_8BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_16BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_32BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_64BEAT) || \
- ((LENGTH) == ETH_RXDMABURSTLENGTH_4XPBL_128BEAT))
-#define IS_ETH_TXDMA_BURST_LENGTH(LENGTH) (((LENGTH) == ETH_TXDMABURSTLENGTH_1BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_2BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_8BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_16BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_32BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_4BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_8BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_16BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_32BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_64BEAT) || \
- ((LENGTH) == ETH_TXDMABURSTLENGTH_4XPBL_128BEAT))
-#define IS_ETH_DMA_DESC_SKIP_LENGTH(LENGTH) ((LENGTH) <= 0x1F)
-#define IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(RATIO) (((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_2_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_3_1) || \
- ((RATIO) == ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1) || \
- ((RATIO) == ETH_DMAARBITRATION_RXPRIORTX))
-#define IS_ETH_DMATXDESC_GET_FLAG(FLAG) (((FLAG) == ETH_DMATXDESC_OWN) || \
- ((FLAG) == ETH_DMATXDESC_IC) || \
- ((FLAG) == ETH_DMATXDESC_LS) || \
- ((FLAG) == ETH_DMATXDESC_FS) || \
- ((FLAG) == ETH_DMATXDESC_DC) || \
- ((FLAG) == ETH_DMATXDESC_DP) || \
- ((FLAG) == ETH_DMATXDESC_TTSE) || \
- ((FLAG) == ETH_DMATXDESC_TER) || \
- ((FLAG) == ETH_DMATXDESC_TCH) || \
- ((FLAG) == ETH_DMATXDESC_TTSS) || \
- ((FLAG) == ETH_DMATXDESC_IHE) || \
- ((FLAG) == ETH_DMATXDESC_ES) || \
- ((FLAG) == ETH_DMATXDESC_JT) || \
- ((FLAG) == ETH_DMATXDESC_FF) || \
- ((FLAG) == ETH_DMATXDESC_PCE) || \
- ((FLAG) == ETH_DMATXDESC_LCA) || \
- ((FLAG) == ETH_DMATXDESC_NC) || \
- ((FLAG) == ETH_DMATXDESC_LCO) || \
- ((FLAG) == ETH_DMATXDESC_EC) || \
- ((FLAG) == ETH_DMATXDESC_VF) || \
- ((FLAG) == ETH_DMATXDESC_CC) || \
- ((FLAG) == ETH_DMATXDESC_ED) || \
- ((FLAG) == ETH_DMATXDESC_UF) || \
- ((FLAG) == ETH_DMATXDESC_DB))
-#define IS_ETH_DMA_TXDESC_SEGMENT(SEGMENT) (((SEGMENT) == ETH_DMATXDESC_LASTSEGMENTS) || \
- ((SEGMENT) == ETH_DMATXDESC_FIRSTSEGMENT))
-#define IS_ETH_DMA_TXDESC_CHECKSUM(CHECKSUM) (((CHECKSUM) == ETH_DMATXDESC_CHECKSUMBYPASS) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMIPV4HEADER) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT) || \
- ((CHECKSUM) == ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL))
-#define IS_ETH_DMATXDESC_BUFFER_SIZE(SIZE) ((SIZE) <= 0x1FFF)
-#define IS_ETH_DMARXDESC_GET_FLAG(FLAG) (((FLAG) == ETH_DMARXDESC_OWN) || \
- ((FLAG) == ETH_DMARXDESC_AFM) || \
- ((FLAG) == ETH_DMARXDESC_ES) || \
- ((FLAG) == ETH_DMARXDESC_DE) || \
- ((FLAG) == ETH_DMARXDESC_SAF) || \
- ((FLAG) == ETH_DMARXDESC_LE) || \
- ((FLAG) == ETH_DMARXDESC_OE) || \
- ((FLAG) == ETH_DMARXDESC_VLAN) || \
- ((FLAG) == ETH_DMARXDESC_FS) || \
- ((FLAG) == ETH_DMARXDESC_LS) || \
- ((FLAG) == ETH_DMARXDESC_IPV4HCE) || \
- ((FLAG) == ETH_DMARXDESC_LC) || \
- ((FLAG) == ETH_DMARXDESC_FT) || \
- ((FLAG) == ETH_DMARXDESC_RWT) || \
- ((FLAG) == ETH_DMARXDESC_RE) || \
- ((FLAG) == ETH_DMARXDESC_DBE) || \
- ((FLAG) == ETH_DMARXDESC_CE) || \
- ((FLAG) == ETH_DMARXDESC_MAMPCE))
-#define IS_ETH_DMA_RXDESC_BUFFER(BUFFER) (((BUFFER) == ETH_DMARXDESC_BUFFER1) || \
- ((BUFFER) == ETH_DMARXDESC_BUFFER2))
-#define IS_ETH_PMT_GET_FLAG(FLAG) (((FLAG) == ETH_PMT_FLAG_WUFR) || \
- ((FLAG) == ETH_PMT_FLAG_MPR))
-#define IS_ETH_DMA_FLAG(FLAG) ((((FLAG) & (uint32_t)0xC7FE1800) == 0x00) && ((FLAG) != 0x00))
-#define IS_ETH_DMA_GET_FLAG(FLAG) (((FLAG) == ETH_DMA_FLAG_TST) || ((FLAG) == ETH_DMA_FLAG_PMT) || \
- ((FLAG) == ETH_DMA_FLAG_MMC) || ((FLAG) == ETH_DMA_FLAG_DATATRANSFERERROR) || \
- ((FLAG) == ETH_DMA_FLAG_READWRITEERROR) || ((FLAG) == ETH_DMA_FLAG_ACCESSERROR) || \
- ((FLAG) == ETH_DMA_FLAG_NIS) || ((FLAG) == ETH_DMA_FLAG_AIS) || \
- ((FLAG) == ETH_DMA_FLAG_ER) || ((FLAG) == ETH_DMA_FLAG_FBE) || \
- ((FLAG) == ETH_DMA_FLAG_ET) || ((FLAG) == ETH_DMA_FLAG_RWT) || \
- ((FLAG) == ETH_DMA_FLAG_RPS) || ((FLAG) == ETH_DMA_FLAG_RBU) || \
- ((FLAG) == ETH_DMA_FLAG_R) || ((FLAG) == ETH_DMA_FLAG_TU) || \
- ((FLAG) == ETH_DMA_FLAG_RO) || ((FLAG) == ETH_DMA_FLAG_TJT) || \
- ((FLAG) == ETH_DMA_FLAG_TBU) || ((FLAG) == ETH_DMA_FLAG_TPS) || \
- ((FLAG) == ETH_DMA_FLAG_T))
-#define IS_ETH_MAC_IT(IT) ((((IT) & (uint32_t)0xFFFFFDF1) == 0x00) && ((IT) != 0x00))
-#define IS_ETH_MAC_GET_IT(IT) (((IT) == ETH_MAC_IT_TST) || ((IT) == ETH_MAC_IT_MMCT) || \
- ((IT) == ETH_MAC_IT_MMCR) || ((IT) == ETH_MAC_IT_MMC) || \
- ((IT) == ETH_MAC_IT_PMT))
-#define IS_ETH_MAC_GET_FLAG(FLAG) (((FLAG) == ETH_MAC_FLAG_TST) || ((FLAG) == ETH_MAC_FLAG_MMCT) || \
- ((FLAG) == ETH_MAC_FLAG_MMCR) || ((FLAG) == ETH_MAC_FLAG_MMC) || \
- ((FLAG) == ETH_MAC_FLAG_PMT))
-#define IS_ETH_DMA_IT(IT) ((((IT) & (uint32_t)0xC7FE1800) == 0x00) && ((IT) != 0x00))
-#define IS_ETH_DMA_GET_IT(IT) (((IT) == ETH_DMA_IT_TST) || ((IT) == ETH_DMA_IT_PMT) || \
- ((IT) == ETH_DMA_IT_MMC) || ((IT) == ETH_DMA_IT_NIS) || \
- ((IT) == ETH_DMA_IT_AIS) || ((IT) == ETH_DMA_IT_ER) || \
- ((IT) == ETH_DMA_IT_FBE) || ((IT) == ETH_DMA_IT_ET) || \
- ((IT) == ETH_DMA_IT_RWT) || ((IT) == ETH_DMA_IT_RPS) || \
- ((IT) == ETH_DMA_IT_RBU) || ((IT) == ETH_DMA_IT_R) || \
- ((IT) == ETH_DMA_IT_TU) || ((IT) == ETH_DMA_IT_RO) || \
- ((IT) == ETH_DMA_IT_TJT) || ((IT) == ETH_DMA_IT_TBU) || \
- ((IT) == ETH_DMA_IT_TPS) || ((IT) == ETH_DMA_IT_T))
-#define IS_ETH_DMA_GET_OVERFLOW(OVERFLOW) (((OVERFLOW) == ETH_DMA_OVERFLOW_RXFIFOCOUNTER) || \
- ((OVERFLOW) == ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER))
-#define IS_ETH_MMC_IT(IT) (((((IT) & (uint32_t)0xFFDF3FFF) == 0x00) || (((IT) & (uint32_t)0xEFFDFF9F) == 0x00)) && \
- ((IT) != 0x00))
-#define IS_ETH_MMC_GET_IT(IT) (((IT) == ETH_MMC_IT_TGF) || ((IT) == ETH_MMC_IT_TGFMSC) || \
- ((IT) == ETH_MMC_IT_TGFSC) || ((IT) == ETH_MMC_IT_RGUF) || \
- ((IT) == ETH_MMC_IT_RFAE) || ((IT) == ETH_MMC_IT_RFCE))
-#define IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(CMD) (((CMD) == ETH_DMAENHANCEDDESCRIPTOR_ENABLE) || \
- ((CMD) == ETH_DMAENHANCEDDESCRIPTOR_DISABLE))
-
-
-/**
- * @}
- */
-
-/** @addtogroup ETH_Private_Defines
- * @{
- */
-/* Delay to wait when writing to some Ethernet registers */
-#define ETH_REG_WRITE_DELAY ((uint32_t)0x00000001)
-
-/* ETHERNET Errors */
-#define ETH_SUCCESS ((uint32_t)0)
-#define ETH_ERROR ((uint32_t)1)
-
-/* ETHERNET DMA Tx descriptors Collision Count Shift */
-#define ETH_DMATXDESC_COLLISION_COUNTSHIFT ((uint32_t)3)
-
-/* ETHERNET DMA Tx descriptors Buffer2 Size Shift */
-#define ETH_DMATXDESC_BUFFER2_SIZESHIFT ((uint32_t)16)
-
-/* ETHERNET DMA Rx descriptors Frame Length Shift */
-#define ETH_DMARXDESC_FRAME_LENGTHSHIFT ((uint32_t)16)
-
-/* ETHERNET DMA Rx descriptors Buffer2 Size Shift */
-#define ETH_DMARXDESC_BUFFER2_SIZESHIFT ((uint32_t)16)
-
-/* ETHERNET DMA Rx descriptors Frame length Shift */
-#define ETH_DMARXDESC_FRAMELENGTHSHIFT ((uint32_t)16)
-
-/* ETHERNET MAC address offsets */
-#define ETH_MAC_ADDR_HBASE (uint32_t)(ETH_MAC_BASE + (uint32_t)0x40) /* ETHERNET MAC address high offset */
-#define ETH_MAC_ADDR_LBASE (uint32_t)(ETH_MAC_BASE + (uint32_t)0x44) /* ETHERNET MAC address low offset */
-
-/* ETHERNET MACMIIAR register Mask */
-#define ETH_MACMIIAR_CR_MASK ((uint32_t)0xFFFFFFE3)
-
-/* ETHERNET MACCR register Mask */
-#define ETH_MACCR_CLEAR_MASK ((uint32_t)0xFF20810F)
-
-/* ETHERNET MACFCR register Mask */
-#define ETH_MACFCR_CLEAR_MASK ((uint32_t)0x0000FF41)
-
-/* ETHERNET DMAOMR register Mask */
-#define ETH_DMAOMR_CLEAR_MASK ((uint32_t)0xF8DE3F23)
-
-/* ETHERNET Remote Wake-up frame register length */
-#define ETH_WAKEUP_REGISTER_LENGTH 8
-
-/* ETHERNET Missed frames counter Shift */
-#define ETH_DMA_RX_OVERFLOW_MISSEDFRAMES_COUNTERSHIFT 17
- /**
- * @}
- */
-
-/* Exported types ------------------------------------------------------------*/
-/** @defgroup ETH_Exported_Types ETH Exported Types
- * @{
- */
-
-/**
- * @brief HAL State structures definition
- */
-typedef enum
-{
- HAL_ETH_STATE_RESET = 0x00, /*!< Peripheral not yet Initialized or disabled */
- HAL_ETH_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
- HAL_ETH_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
- HAL_ETH_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
- HAL_ETH_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
- HAL_ETH_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
- HAL_ETH_STATE_BUSY_WR = 0x42, /*!< Write process is ongoing */
- HAL_ETH_STATE_BUSY_RD = 0x82, /*!< Read process is ongoing */
- HAL_ETH_STATE_TIMEOUT = 0x03, /*!< Timeout state */
- HAL_ETH_STATE_ERROR = 0x04 /*!< Reception process is ongoing */
-}HAL_ETH_StateTypeDef;
-
-/**
- * @brief ETH Init Structure definition
- */
-
-typedef struct
-{
- uint32_t AutoNegotiation; /*!< Selects or not the AutoNegotiation mode for the external PHY
- The AutoNegotiation allows an automatic setting of the Speed (10/100Mbps)
- and the mode (half/full-duplex).
- This parameter can be a value of @ref ETH_AutoNegotiation */
-
- uint32_t Speed; /*!< Sets the Ethernet speed: 10/100 Mbps.
- This parameter can be a value of @ref ETH_Speed */
-
- uint32_t DuplexMode; /*!< Selects the MAC duplex mode: Half-Duplex or Full-Duplex mode
- This parameter can be a value of @ref ETH_Duplex_Mode */
-
- uint16_t PhyAddress; /*!< Ethernet PHY address.
- This parameter must be a number between Min_Data = 0 and Max_Data = 32 */
-
- uint8_t *MACAddr; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */
-
- uint32_t RxMode; /*!< Selects the Ethernet Rx mode: Polling mode, Interrupt mode.
- This parameter can be a value of @ref ETH_Rx_Mode */
-
- uint32_t ChecksumMode; /*!< Selects if the checksum is check by hardware or by software.
- This parameter can be a value of @ref ETH_Checksum_Mode */
-
- uint32_t MediaInterface ; /*!< Selects the media-independent interface or the reduced media-independent interface.
- This parameter can be a value of @ref ETH_Media_Interface */
-
-} ETH_InitTypeDef;
-
-
- /**
- * @brief ETH MAC Configuration Structure definition
- */
-
-typedef struct
-{
- uint32_t Watchdog; /*!< Selects or not the Watchdog timer
- When enabled, the MAC allows no more then 2048 bytes to be received.
- When disabled, the MAC can receive up to 16384 bytes.
- This parameter can be a value of @ref ETH_Watchdog */
-
- uint32_t Jabber; /*!< Selects or not Jabber timer
- When enabled, the MAC allows no more then 2048 bytes to be sent.
- When disabled, the MAC can send up to 16384 bytes.
- This parameter can be a value of @ref ETH_Jabber */
-
- uint32_t InterFrameGap; /*!< Selects the minimum IFG between frames during transmission.
- This parameter can be a value of @ref ETH_Inter_Frame_Gap */
-
- uint32_t CarrierSense; /*!< Selects or not the Carrier Sense.
- This parameter can be a value of @ref ETH_Carrier_Sense */
-
- uint32_t ReceiveOwn; /*!< Selects or not the ReceiveOwn,
- ReceiveOwn allows the reception of frames when the TX_EN signal is asserted
- in Half-Duplex mode.
- This parameter can be a value of @ref ETH_Receive_Own */
-
- uint32_t LoopbackMode; /*!< Selects or not the internal MAC MII Loopback mode.
- This parameter can be a value of @ref ETH_Loop_Back_Mode */
-
- uint32_t ChecksumOffload; /*!< Selects or not the IPv4 checksum checking for received frame payloads' TCP/UDP/ICMP headers.
- This parameter can be a value of @ref ETH_Checksum_Offload */
-
- uint32_t RetryTransmission; /*!< Selects or not the MAC attempt retries transmission, based on the settings of BL,
- when a collision occurs (Half-Duplex mode).
- This parameter can be a value of @ref ETH_Retry_Transmission */
-
- uint32_t AutomaticPadCRCStrip; /*!< Selects or not the Automatic MAC Pad/CRC Stripping.
- This parameter can be a value of @ref ETH_Automatic_Pad_CRC_Strip */
-
- uint32_t BackOffLimit; /*!< Selects the BackOff limit value.
- This parameter can be a value of @ref ETH_Back_Off_Limit */
-
- uint32_t DeferralCheck; /*!< Selects or not the deferral check function (Half-Duplex mode).
- This parameter can be a value of @ref ETH_Deferral_Check */
-
- uint32_t ReceiveAll; /*!< Selects or not all frames reception by the MAC (No filtering).
- This parameter can be a value of @ref ETH_Receive_All */
-
- uint32_t SourceAddrFilter; /*!< Selects the Source Address Filter mode.
- This parameter can be a value of @ref ETH_Source_Addr_Filter */
-
- uint32_t PassControlFrames; /*!< Sets the forwarding mode of the control frames (including unicast and multicast PAUSE frames)
- This parameter can be a value of @ref ETH_Pass_Control_Frames */
-
- uint32_t BroadcastFramesReception; /*!< Selects or not the reception of Broadcast Frames.
- This parameter can be a value of @ref ETH_Broadcast_Frames_Reception */
-
- uint32_t DestinationAddrFilter; /*!< Sets the destination filter mode for both unicast and multicast frames.
- This parameter can be a value of @ref ETH_Destination_Addr_Filter */
-
- uint32_t PromiscuousMode; /*!< Selects or not the Promiscuous Mode
- This parameter can be a value of @ref ETH_Promiscuous_Mode */
-
- uint32_t MulticastFramesFilter; /*!< Selects the Multicast Frames filter mode: None/HashTableFilter/PerfectFilter/PerfectHashTableFilter.
- This parameter can be a value of @ref ETH_Multicast_Frames_Filter */
-
- uint32_t UnicastFramesFilter; /*!< Selects the Unicast Frames filter mode: HashTableFilter/PerfectFilter/PerfectHashTableFilter.
- This parameter can be a value of @ref ETH_Unicast_Frames_Filter */
-
- uint32_t HashTableHigh; /*!< This field holds the higher 32 bits of Hash table.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFFFFFF */
-
- uint32_t HashTableLow; /*!< This field holds the lower 32 bits of Hash table.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFFFFFF */
-
- uint32_t PauseTime; /*!< This field holds the value to be used in the Pause Time field in the transmit control frame.
- This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFF */
-
- uint32_t ZeroQuantaPause; /*!< Selects or not the automatic generation of Zero-Quanta Pause Control frames.
- This parameter can be a value of @ref ETH_Zero_Quanta_Pause */
-
- uint32_t PauseLowThreshold; /*!< This field configures the threshold of the PAUSE to be checked for
- automatic retransmission of PAUSE Frame.
- This parameter can be a value of @ref ETH_Pause_Low_Threshold */
-
- uint32_t UnicastPauseFrameDetect; /*!< Selects or not the MAC detection of the Pause frames (with MAC Address0
- unicast address and unique multicast address).
- This parameter can be a value of @ref ETH_Unicast_Pause_Frame_Detect */
-
- uint32_t ReceiveFlowControl; /*!< Enables or disables the MAC to decode the received Pause frame and
- disable its transmitter for a specified time (Pause Time)
- This parameter can be a value of @ref ETH_Receive_Flow_Control */
-
- uint32_t TransmitFlowControl; /*!< Enables or disables the MAC to transmit Pause frames (Full-Duplex mode)
- or the MAC back-pressure operation (Half-Duplex mode)
- This parameter can be a value of @ref ETH_Transmit_Flow_Control */
-
- uint32_t VLANTagComparison; /*!< Selects the 12-bit VLAN identifier or the complete 16-bit VLAN tag for
- comparison and filtering.
- This parameter can be a value of @ref ETH_VLAN_Tag_Comparison */
-
- uint32_t VLANTagIdentifier; /*!< Holds the VLAN tag identifier for receive frames */
-
-} ETH_MACInitTypeDef;
-
-
-/**
- * @brief ETH DMA Configuration Structure definition
- */
-
-typedef struct
-{
- uint32_t DropTCPIPChecksumErrorFrame; /*!< Selects or not the Dropping of TCP/IP Checksum Error Frames.
- This parameter can be a value of @ref ETH_Drop_TCP_IP_Checksum_Error_Frame */
-
- uint32_t ReceiveStoreForward; /*!< Enables or disables the Receive store and forward mode.
- This parameter can be a value of @ref ETH_Receive_Store_Forward */
-
- uint32_t FlushReceivedFrame; /*!< Enables or disables the flushing of received frames.
- This parameter can be a value of @ref ETH_Flush_Received_Frame */
-
- uint32_t TransmitStoreForward; /*!< Enables or disables Transmit store and forward mode.
- This parameter can be a value of @ref ETH_Transmit_Store_Forward */
-
- uint32_t TransmitThresholdControl; /*!< Selects or not the Transmit Threshold Control.
- This parameter can be a value of @ref ETH_Transmit_Threshold_Control */
-
- uint32_t ForwardErrorFrames; /*!< Selects or not the forward to the DMA of erroneous frames.
- This parameter can be a value of @ref ETH_Forward_Error_Frames */
-
- uint32_t ForwardUndersizedGoodFrames; /*!< Enables or disables the Rx FIFO to forward Undersized frames (frames with no Error
- and length less than 64 bytes) including pad-bytes and CRC)
- This parameter can be a value of @ref ETH_Forward_Undersized_Good_Frames */
-
- uint32_t ReceiveThresholdControl; /*!< Selects the threshold level of the Receive FIFO.
- This parameter can be a value of @ref ETH_Receive_Threshold_Control */
-
- uint32_t SecondFrameOperate; /*!< Selects or not the Operate on second frame mode, which allows the DMA to process a second
- frame of Transmit data even before obtaining the status for the first frame.
- This parameter can be a value of @ref ETH_Second_Frame_Operate */
-
- uint32_t AddressAlignedBeats; /*!< Enables or disables the Address Aligned Beats.
- This parameter can be a value of @ref ETH_Address_Aligned_Beats */
-
- uint32_t FixedBurst; /*!< Enables or disables the AHB Master interface fixed burst transfers.
- This parameter can be a value of @ref ETH_Fixed_Burst */
-
- uint32_t RxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Rx DMA transaction.
- This parameter can be a value of @ref ETH_Rx_DMA_Burst_Length */
-
- uint32_t TxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Tx DMA transaction.
- This parameter can be a value of @ref ETH_Tx_DMA_Burst_Length */
-
- uint32_t EnhancedDescriptorFormat; /*!< Enables the enhanced descriptor format.
- This parameter can be a value of @ref ETH_DMA_Enhanced_descriptor_format */
-
- uint32_t DescriptorSkipLength; /*!< Specifies the number of word to skip between two unchained descriptors (Ring mode)
- This parameter must be a number between Min_Data = 0 and Max_Data = 32 */
-
- uint32_t DMAArbitration; /*!< Selects the DMA Tx/Rx arbitration.
- This parameter can be a value of @ref ETH_DMA_Arbitration */
-} ETH_DMAInitTypeDef;
-
-
-/**
- * @brief ETH DMA Descriptors data structure definition
- */
-
-typedef struct
-{
- __IO uint32_t Status; /*!< Status */
-
- uint32_t ControlBufferSize; /*!< Control and Buffer1, Buffer2 lengths */
-
- uint32_t Buffer1Addr; /*!< Buffer1 address pointer */
-
- uint32_t Buffer2NextDescAddr; /*!< Buffer2 or next descriptor address pointer */
-
- /*!< Enhanced ETHERNET DMA PTP Descriptors */
- uint32_t ExtendedStatus; /*!< Extended status for PTP receive descriptor */
-
- uint32_t Reserved1; /*!< Reserved */
-
- uint32_t TimeStampLow; /*!< Time Stamp Low value for transmit and receive */
-
- uint32_t TimeStampHigh; /*!< Time Stamp High value for transmit and receive */
-
-} ETH_DMADescTypeDef;
-
-
-/**
- * @brief Received Frame Informations structure definition
- */
-typedef struct
-{
- ETH_DMADescTypeDef *FSRxDesc; /*!< First Segment Rx Desc */
-
- ETH_DMADescTypeDef *LSRxDesc; /*!< Last Segment Rx Desc */
-
- uint32_t SegCount; /*!< Segment count */
-
- uint32_t length; /*!< Frame length */
-
- uint32_t buffer; /*!< Frame buffer */
-
-} ETH_DMARxFrameInfos;
-
-
-/**
- * @brief ETH Handle Structure definition
- */
-
-typedef struct
-{
- ETH_TypeDef *Instance; /*!< Register base address */
-
- ETH_InitTypeDef Init; /*!< Ethernet Init Configuration */
-
- uint32_t LinkStatus; /*!< Ethernet link status */
-
- ETH_DMADescTypeDef *RxDesc; /*!< Rx descriptor to Get */
-
- ETH_DMADescTypeDef *TxDesc; /*!< Tx descriptor to Set */
-
- ETH_DMARxFrameInfos RxFrameInfos; /*!< last Rx frame infos */
-
- __IO HAL_ETH_StateTypeDef State; /*!< ETH communication state */
-
- HAL_LockTypeDef Lock; /*!< ETH Lock */
-
-} ETH_HandleTypeDef;
-
- /**
- * @}
- */
-
-/* Exported constants --------------------------------------------------------*/
-/** @defgroup ETH_Exported_Constants ETH Exported Constants
- * @{
- */
-
-/** @defgroup ETH_Buffers_setting ETH Buffers setting
- * @{
- */
-#define ETH_MAX_PACKET_SIZE (1536u) /*!< ETH_HEADER + ETH_EXTRA + ETH_VLAN_TAG + ETH_MAX_ETH_PAYLOAD + ETH_CRC */
-#define ETH_HEADER ((uint32_t)14) /*!< 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */
-#define ETH_CRC ((uint32_t)4) /*!< Ethernet CRC */
-#define ETH_EXTRA ((uint32_t)2) /*!< Extra bytes in some cases */
-#define ETH_VLAN_TAG ((uint32_t)4) /*!< optional 802.1q VLAN Tag */
-#define ETH_MIN_ETH_PAYLOAD ((uint32_t)46) /*!< Minimum Ethernet payload size */
-#define ETH_MAX_ETH_PAYLOAD ((uint32_t)1500) /*!< Maximum Ethernet payload size */
-#define ETH_JUMBO_FRAME_PAYLOAD ((uint32_t)9000) /*!< Jumbo frame payload size */
-
- /* Ethernet driver receive buffers are organized in a chained linked-list, when
- an ethernet packet is received, the Rx-DMA will transfer the packet from RxFIFO
- to the driver receive buffers memory.
-
- Depending on the size of the received ethernet packet and the size of
- each ethernet driver receive buffer, the received packet can take one or more
- ethernet driver receive buffer.
-
- In below are defined the size of one ethernet driver receive buffer ETH_RX_BUF_SIZE
- and the total count of the driver receive buffers ETH_RXBUFNB.
-
- The configured value for ETH_RX_BUF_SIZE and ETH_RXBUFNB are only provided as
- example, they can be reconfigured in the application layer to fit the application
- needs */
-
-/* Here we configure each Ethernet driver receive buffer to fit the Max size Ethernet
- packet */
-#ifndef ETH_RX_BUF_SIZE
- #error please define ETH_RX_BUF_SIZE
- #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE
-#endif
-
-/* 5 Ethernet driver receive buffers are used (in a chained linked list)*/
-#ifndef ETH_RXBUFNB
- #define ETH_RXBUFNB ((uint32_t)5 /* 5 Rx buffers of size ETH_RX_BUF_SIZE */
-#endif
-
-
- /* Ethernet driver transmit buffers are organized in a chained linked-list, when
- an ethernet packet is transmitted, Tx-DMA will transfer the packet from the
- driver transmit buffers memory to the TxFIFO.
-
- Depending on the size of the Ethernet packet to be transmitted and the size of
- each ethernet driver transmit buffer, the packet to be transmitted can take
- one or more ethernet driver transmit buffer.
-
- In below are defined the size of one ethernet driver transmit buffer ETH_TX_BUF_SIZE
- and the total count of the driver transmit buffers ETH_TXBUFNB.
-
- The configured value for ETH_TX_BUF_SIZE and ETH_TXBUFNB are only provided as
- example, they can be reconfigured in the application layer to fit the application
- needs */
-
-/* Here we configure each Ethernet driver transmit buffer to fit the Max size Ethernet
- packet */
-#ifndef ETH_TX_BUF_SIZE
- #error please define ETH_TX_BUF_SIZE
- #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE
-#endif
-
-/* 5 ethernet driver transmit buffers are used (in a chained linked list)*/
-#ifndef ETH_TXBUFNB
- #define ETH_TXBUFNB ((uint32_t)5 /* 5 Tx buffers of size ETH_TX_BUF_SIZE */
-#endif
-
- /**
- * @}
- */
-
-/** @defgroup ETH_DMA_TX_Descriptor ETH DMA TX Descriptor
- * @{
- */
-
-/*
- DMA Tx Descriptor
- -----------------------------------------------------------------------------------------------
- TDES0 | OWN(31) | CTRL[30:26] | Reserved[25:24] | CTRL[23:20] | Reserved[19:17] | Status[16:0] |
- -----------------------------------------------------------------------------------------------
- TDES1 | Reserved[31:29] | Buffer2 ByteCount[28:16] | Reserved[15:13] | Buffer1 ByteCount[12:0] |
- -----------------------------------------------------------------------------------------------
- TDES2 | Buffer1 Address [31:0] |
- -----------------------------------------------------------------------------------------------
- TDES3 | Buffer2 Address [31:0] / Next Descriptor Address [31:0] |
- -----------------------------------------------------------------------------------------------
-*/
-
-/**
- * @brief Bit definition of TDES0 register: DMA Tx descriptor status register
- */
-#define ETH_DMATXDESC_OWN ((uint32_t)0x80000000) /*!< OWN bit: descriptor is owned by DMA engine */
-#define ETH_DMATXDESC_IC ((uint32_t)0x40000000) /*!< Interrupt on Completion */
-#define ETH_DMATXDESC_LS ((uint32_t)0x20000000) /*!< Last Segment */
-#define ETH_DMATXDESC_FS ((uint32_t)0x10000000) /*!< First Segment */
-#define ETH_DMATXDESC_DC ((uint32_t)0x08000000) /*!< Disable CRC */
-#define ETH_DMATXDESC_DP ((uint32_t)0x04000000) /*!< Disable Padding */
-#define ETH_DMATXDESC_TTSE ((uint32_t)0x02000000) /*!< Transmit Time Stamp Enable */
-#define ETH_DMATXDESC_CIC ((uint32_t)0x00C00000) /*!< Checksum Insertion Control: 4 cases */
-#define ETH_DMATXDESC_CIC_BYPASS ((uint32_t)0x00000000) /*!< Do Nothing: Checksum Engine is bypassed */
-#define ETH_DMATXDESC_CIC_IPV4HEADER ((uint32_t)0x00400000) /*!< IPV4 header Checksum Insertion */
-#define ETH_DMATXDESC_CIC_TCPUDPICMP_SEGMENT ((uint32_t)0x00800000) /*!< TCP/UDP/ICMP Checksum Insertion calculated over segment only */
-#define ETH_DMATXDESC_CIC_TCPUDPICMP_FULL ((uint32_t)0x00C00000) /*!< TCP/UDP/ICMP Checksum Insertion fully calculated */
-#define ETH_DMATXDESC_TER ((uint32_t)0x00200000) /*!< Transmit End of Ring */
-#define ETH_DMATXDESC_TCH ((uint32_t)0x00100000) /*!< Second Address Chained */
-#define ETH_DMATXDESC_TTSS ((uint32_t)0x00020000) /*!< Tx Time Stamp Status */
-#define ETH_DMATXDESC_IHE ((uint32_t)0x00010000) /*!< IP Header Error */
-#define ETH_DMATXDESC_ES ((uint32_t)0x00008000) /*!< Error summary: OR of the following bits: UE || ED || EC || LCO || NC || LCA || FF || JT */
-#define ETH_DMATXDESC_JT ((uint32_t)0x00004000) /*!< Jabber Timeout */
-#define ETH_DMATXDESC_FF ((uint32_t)0x00002000) /*!< Frame Flushed: DMA/MTL flushed the frame due to SW flush */
-#define ETH_DMATXDESC_PCE ((uint32_t)0x00001000) /*!< Payload Checksum Error */
-#define ETH_DMATXDESC_LCA ((uint32_t)0x00000800) /*!< Loss of Carrier: carrier lost during transmission */
-#define ETH_DMATXDESC_NC ((uint32_t)0x00000400) /*!< No Carrier: no carrier signal from the transceiver */
-#define ETH_DMATXDESC_LCO ((uint32_t)0x00000200) /*!< Late Collision: transmission aborted due to collision */
-#define ETH_DMATXDESC_EC ((uint32_t)0x00000100) /*!< Excessive Collision: transmission aborted after 16 collisions */
-#define ETH_DMATXDESC_VF ((uint32_t)0x00000080) /*!< VLAN Frame */
-#define ETH_DMATXDESC_CC ((uint32_t)0x00000078) /*!< Collision Count */
-#define ETH_DMATXDESC_ED ((uint32_t)0x00000004) /*!< Excessive Deferral */
-#define ETH_DMATXDESC_UF ((uint32_t)0x00000002) /*!< Underflow Error: late data arrival from the memory */
-#define ETH_DMATXDESC_DB ((uint32_t)0x00000001) /*!< Deferred Bit */
-
-/**
- * @brief Bit definition of TDES1 register
- */
-#define ETH_DMATXDESC_TBS2 ((uint32_t)0x1FFF0000) /*!< Transmit Buffer2 Size */
-#define ETH_DMATXDESC_TBS1 ((uint32_t)0x00001FFF) /*!< Transmit Buffer1 Size */
-
-/**
- * @brief Bit definition of TDES2 register
- */
-#define ETH_DMATXDESC_B1AP ((uint32_t)0xFFFFFFFF) /*!< Buffer1 Address Pointer */
-
-/**
- * @brief Bit definition of TDES3 register
- */
-#define ETH_DMATXDESC_B2AP ((uint32_t)0xFFFFFFFF) /*!< Buffer2 Address Pointer */
-
- /*---------------------------------------------------------------------------------------------
- TDES6 | Transmit Time Stamp Low [31:0] |
- -----------------------------------------------------------------------------------------------
- TDES7 | Transmit Time Stamp High [31:0] |
- ----------------------------------------------------------------------------------------------*/
-
-/* Bit definition of TDES6 register */
- #define ETH_DMAPTPTXDESC_TTSL ((uint32_t)0xFFFFFFFF) /* Transmit Time Stamp Low */
-
-/* Bit definition of TDES7 register */
- #define ETH_DMAPTPTXDESC_TTSH ((uint32_t)0xFFFFFFFF) /* Transmit Time Stamp High */
-
-/**
- * @}
- */
-/** @defgroup ETH_DMA_RX_Descriptor ETH DMA RX Descriptor
- * @{
- */
-
-/*
- DMA Rx Descriptor
- --------------------------------------------------------------------------------------------------------------------
- RDES0 | OWN(31) | Status [30:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES1 | CTRL(31) | Reserved[30:29] | Buffer2 ByteCount[28:16] | CTRL[15:14] | Reserved(13) | Buffer1 ByteCount[12:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES2 | Buffer1 Address [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES3 | Buffer2 Address [31:0] / Next Descriptor Address [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
-*/
-
-/**
- * @brief Bit definition of RDES0 register: DMA Rx descriptor status register
- */
-#define ETH_DMARXDESC_OWN ((uint32_t)0x80000000) /*!< OWN bit: descriptor is owned by DMA engine */
-#define ETH_DMARXDESC_AFM ((uint32_t)0x40000000) /*!< DA Filter Fail for the rx frame */
-#define ETH_DMARXDESC_FL ((uint32_t)0x3FFF0000) /*!< Receive descriptor frame length */
-#define ETH_DMARXDESC_ES ((uint32_t)0x00008000) /*!< Error summary: OR of the following bits: DE || OE || IPC || LC || RWT || RE || CE */
-#define ETH_DMARXDESC_DE ((uint32_t)0x00004000) /*!< Descriptor error: no more descriptors for receive frame */
-#define ETH_DMARXDESC_SAF ((uint32_t)0x00002000) /*!< SA Filter Fail for the received frame */
-#define ETH_DMARXDESC_LE ((uint32_t)0x00001000) /*!< Frame size not matching with length field */
-#define ETH_DMARXDESC_OE ((uint32_t)0x00000800) /*!< Overflow Error: Frame was damaged due to buffer overflow */
-#define ETH_DMARXDESC_VLAN ((uint32_t)0x00000400) /*!< VLAN Tag: received frame is a VLAN frame */
-#define ETH_DMARXDESC_FS ((uint32_t)0x00000200) /*!< First descriptor of the frame */
-#define ETH_DMARXDESC_LS ((uint32_t)0x00000100) /*!< Last descriptor of the frame */
-#define ETH_DMARXDESC_IPV4HCE ((uint32_t)0x00000080) /*!< IPC Checksum Error: Rx Ipv4 header checksum error */
-#define ETH_DMARXDESC_LC ((uint32_t)0x00000040) /*!< Late collision occurred during reception */
-#define ETH_DMARXDESC_FT ((uint32_t)0x00000020) /*!< Frame type - Ethernet, otherwise 802.3 */
-#define ETH_DMARXDESC_RWT ((uint32_t)0x00000010) /*!< Receive Watchdog Timeout: watchdog timer expired during reception */
-#define ETH_DMARXDESC_RE ((uint32_t)0x00000008) /*!< Receive error: error reported by MII interface */
-#define ETH_DMARXDESC_DBE ((uint32_t)0x00000004) /*!< Dribble bit error: frame contains non int multiple of 8 bits */
-#define ETH_DMARXDESC_CE ((uint32_t)0x00000002) /*!< CRC error */
-#define ETH_DMARXDESC_MAMPCE ((uint32_t)0x00000001) /*!< Rx MAC Address/Payload Checksum Error: Rx MAC address matched/ Rx Payload Checksum Error */
-
-/**
- * @brief Bit definition of RDES1 register
- */
-#define ETH_DMARXDESC_DIC ((uint32_t)0x80000000) /*!< Disable Interrupt on Completion */
-#define ETH_DMARXDESC_RBS2 ((uint32_t)0x1FFF0000) /*!< Receive Buffer2 Size */
-#define ETH_DMARXDESC_RER ((uint32_t)0x00008000) /*!< Receive End of Ring */
-#define ETH_DMARXDESC_RCH ((uint32_t)0x00004000) /*!< Second Address Chained */
-#define ETH_DMARXDESC_RBS1 ((uint32_t)0x00001FFF) /*!< Receive Buffer1 Size */
-
-/**
- * @brief Bit definition of RDES2 register
- */
-#define ETH_DMARXDESC_B1AP ((uint32_t)0xFFFFFFFF) /*!< Buffer1 Address Pointer */
-
-/**
- * @brief Bit definition of RDES3 register
- */
-#define ETH_DMARXDESC_B2AP ((uint32_t)0xFFFFFFFF) /*!< Buffer2 Address Pointer */
-
-/*---------------------------------------------------------------------------------------------------------------------
- RDES4 | Reserved[31:15] | Extended Status [14:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES5 | Reserved[31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES6 | Receive Time Stamp Low [31:0] |
- ---------------------------------------------------------------------------------------------------------------------
- RDES7 | Receive Time Stamp High [31:0] |
- --------------------------------------------------------------------------------------------------------------------*/
-
-/* Bit definition of RDES4 register */
-#define ETH_DMAPTPRXDESC_PTPV ((uint32_t)0x00002000) /* PTP Version */
-#define ETH_DMAPTPRXDESC_PTPFT ((uint32_t)0x00001000) /* PTP Frame Type */
-#define ETH_DMAPTPRXDESC_PTPMT ((uint32_t)0x00000F00) /* PTP Message Type */
- #define ETH_DMAPTPRXDESC_PTPMT_SYNC ((uint32_t)0x00000100) /* SYNC message (all clock types) */
- #define ETH_DMAPTPRXDESC_PTPMT_FOLLOWUP ((uint32_t)0x00000200) /* FollowUp message (all clock types) */
- #define ETH_DMAPTPRXDESC_PTPMT_DELAYREQ ((uint32_t)0x00000300) /* DelayReq message (all clock types) */
- #define ETH_DMAPTPRXDESC_PTPMT_DELAYRESP ((uint32_t)0x00000400) /* DelayResp message (all clock types) */
- #define ETH_DMAPTPRXDESC_PTPMT_PDELAYREQ_ANNOUNCE ((uint32_t)0x00000500) /* PdelayReq message (peer-to-peer transparent clock) or Announce message (Ordinary or Boundary clock) */
- #define ETH_DMAPTPRXDESC_PTPMT_PDELAYRESP_MANAG ((uint32_t)0x00000600) /* PdelayResp message (peer-to-peer transparent clock) or Management message (Ordinary or Boundary clock) */
- #define ETH_DMAPTPRXDESC_PTPMT_PDELAYRESPFOLLOWUP_SIGNAL ((uint32_t)0x00000700) /* PdelayRespFollowUp message (peer-to-peer transparent clock) or Signaling message (Ordinary or Boundary clock) */
-#define ETH_DMAPTPRXDESC_IPV6PR ((uint32_t)0x00000080) /* IPv6 Packet Received */
-#define ETH_DMAPTPRXDESC_IPV4PR ((uint32_t)0x00000040) /* IPv4 Packet Received */
-#define ETH_DMAPTPRXDESC_IPCB ((uint32_t)0x00000020) /* IP Checksum Bypassed */
-#define ETH_DMAPTPRXDESC_IPPE ((uint32_t)0x00000010) /* IP Payload Error */
-#define ETH_DMAPTPRXDESC_IPHE ((uint32_t)0x00000008) /* IP Header Error */
-#define ETH_DMAPTPRXDESC_IPPT ((uint32_t)0x00000007) /* IP Payload Type */
- #define ETH_DMAPTPRXDESC_IPPT_UDP ((uint32_t)0x00000001) /* UDP payload encapsulated in the IP datagram */
- #define ETH_DMAPTPRXDESC_IPPT_TCP ((uint32_t)0x00000002) /* TCP payload encapsulated in the IP datagram */
- #define ETH_DMAPTPRXDESC_IPPT_ICMP ((uint32_t)0x00000003) /* ICMP payload encapsulated in the IP datagram */
-
-/* Bit definition of RDES6 register */
-#define ETH_DMAPTPRXDESC_RTSL ((uint32_t)0xFFFFFFFF) /* Receive Time Stamp Low */
-
-/* Bit definition of RDES7 register */
-#define ETH_DMAPTPRXDESC_RTSH ((uint32_t)0xFFFFFFFF) /* Receive Time Stamp High */
-/**
- * @}
- */
- /** @defgroup ETH_AutoNegotiation ETH AutoNegotiation
- * @{
- */
-#define ETH_AUTONEGOTIATION_ENABLE ((uint32_t)0x00000001)
-#define ETH_AUTONEGOTIATION_DISABLE ((uint32_t)0x00000000)
-
-/**
- * @}
- */
-/** @defgroup ETH_Speed ETH Speed
- * @{
- */
-#define ETH_SPEED_10M ((uint32_t)0x00000000)
-#define ETH_SPEED_100M ((uint32_t)0x00004000)
-
-/**
- * @}
- */
-/** @defgroup ETH_Duplex_Mode ETH Duplex Mode
- * @{
- */
-#define ETH_MODE_FULLDUPLEX ((uint32_t)0x00000800)
-#define ETH_MODE_HALFDUPLEX ((uint32_t)0x00000000)
-/**
- * @}
- */
-/** @defgroup ETH_Rx_Mode ETH Rx Mode
- * @{
- */
-#define ETH_RXPOLLING_MODE ((uint32_t)0x00000000)
-#define ETH_RXINTERRUPT_MODE ((uint32_t)0x00000001)
-/**
- * @}
- */
-
-/** @defgroup ETH_Checksum_Mode ETH Checksum Mode
- * @{
- */
-#define ETH_CHECKSUM_BY_HARDWARE ((uint32_t)0x00000000)
-#define ETH_CHECKSUM_BY_SOFTWARE ((uint32_t)0x00000001)
-/**
- * @}
- */
-
-/** @defgroup ETH_Media_Interface ETH Media Interface
- * @{
- */
-#define ETH_MEDIA_INTERFACE_MII ((uint32_t)0x00000000)
-#define ETH_MEDIA_INTERFACE_RMII ((uint32_t)SYSCFG_PMC_MII_RMII_SEL)
-/**
- * @}
- */
-
-/** @defgroup ETH_Watchdog ETH Watchdog
- * @{
- */
-#define ETH_WATCHDOG_ENABLE ((uint32_t)0x00000000)
-#define ETH_WATCHDOG_DISABLE ((uint32_t)0x00800000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Jabber ETH Jabber
- * @{
- */
-#define ETH_JABBER_ENABLE ((uint32_t)0x00000000)
-#define ETH_JABBER_DISABLE ((uint32_t)0x00400000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Inter_Frame_Gap ETH Inter Frame Gap
- * @{
- */
-#define ETH_INTERFRAMEGAP_96BIT ((uint32_t)0x00000000) /*!< minimum IFG between frames during transmission is 96Bit */
-#define ETH_INTERFRAMEGAP_88BIT ((uint32_t)0x00020000) /*!< minimum IFG between frames during transmission is 88Bit */
-#define ETH_INTERFRAMEGAP_80BIT ((uint32_t)0x00040000) /*!< minimum IFG between frames during transmission is 80Bit */
-#define ETH_INTERFRAMEGAP_72BIT ((uint32_t)0x00060000) /*!< minimum IFG between frames during transmission is 72Bit */
-#define ETH_INTERFRAMEGAP_64BIT ((uint32_t)0x00080000) /*!< minimum IFG between frames during transmission is 64Bit */
-#define ETH_INTERFRAMEGAP_56BIT ((uint32_t)0x000A0000) /*!< minimum IFG between frames during transmission is 56Bit */
-#define ETH_INTERFRAMEGAP_48BIT ((uint32_t)0x000C0000) /*!< minimum IFG between frames during transmission is 48Bit */
-#define ETH_INTERFRAMEGAP_40BIT ((uint32_t)0x000E0000) /*!< minimum IFG between frames during transmission is 40Bit */
-/**
- * @}
- */
-
-/** @defgroup ETH_Carrier_Sense ETH Carrier Sense
- * @{
- */
-#define ETH_CARRIERSENCE_ENABLE ((uint32_t)0x00000000)
-#define ETH_CARRIERSENCE_DISABLE ((uint32_t)0x00010000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Own ETH Receive Own
- * @{
- */
-#define ETH_RECEIVEOWN_ENABLE ((uint32_t)0x00000000)
-#define ETH_RECEIVEOWN_DISABLE ((uint32_t)0x00002000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Loop_Back_Mode ETH Loop Back Mode
- * @{
- */
-#define ETH_LOOPBACKMODE_ENABLE ((uint32_t)0x00001000)
-#define ETH_LOOPBACKMODE_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Checksum_Offload ETH Checksum Offload
- * @{
- */
-#define ETH_CHECKSUMOFFLAOD_ENABLE ((uint32_t)0x00000400)
-#define ETH_CHECKSUMOFFLAOD_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Retry_Transmission ETH Retry Transmission
- * @{
- */
-#define ETH_RETRYTRANSMISSION_ENABLE ((uint32_t)0x00000000)
-#define ETH_RETRYTRANSMISSION_DISABLE ((uint32_t)0x00000200)
-/**
- * @}
- */
-
-/** @defgroup ETH_Automatic_Pad_CRC_Strip ETH Automatic Pad CRC Strip
- * @{
- */
-#define ETH_AUTOMATICPADCRCSTRIP_ENABLE ((uint32_t)0x00000080)
-#define ETH_AUTOMATICPADCRCSTRIP_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Back_Off_Limit ETH Back Off Limit
- * @{
- */
-#define ETH_BACKOFFLIMIT_10 ((uint32_t)0x00000000)
-#define ETH_BACKOFFLIMIT_8 ((uint32_t)0x00000020)
-#define ETH_BACKOFFLIMIT_4 ((uint32_t)0x00000040)
-#define ETH_BACKOFFLIMIT_1 ((uint32_t)0x00000060)
-/**
- * @}
- */
-
-/** @defgroup ETH_Deferral_Check ETH Deferral Check
- * @{
- */
-#define ETH_DEFFERRALCHECK_ENABLE ((uint32_t)0x00000010)
-#define ETH_DEFFERRALCHECK_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_All ETH Receive All
- * @{
- */
-#define ETH_RECEIVEALL_ENABLE ((uint32_t)0x80000000)
-#define ETH_RECEIVEAll_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Source_Addr_Filter ETH Source Addr Filter
- * @{
- */
-#define ETH_SOURCEADDRFILTER_NORMAL_ENABLE ((uint32_t)0x00000200)
-#define ETH_SOURCEADDRFILTER_INVERSE_ENABLE ((uint32_t)0x00000300)
-#define ETH_SOURCEADDRFILTER_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Pass_Control_Frames ETH Pass Control Frames
- * @{
- */
-#define ETH_PASSCONTROLFRAMES_BLOCKALL ((uint32_t)0x00000040) /*!< MAC filters all control frames from reaching the application */
-#define ETH_PASSCONTROLFRAMES_FORWARDALL ((uint32_t)0x00000080) /*!< MAC forwards all control frames to application even if they fail the Address Filter */
-#define ETH_PASSCONTROLFRAMES_FORWARDPASSEDADDRFILTER ((uint32_t)0x000000C0) /*!< MAC forwards control frames that pass the Address Filter. */
-/**
- * @}
- */
-
-/** @defgroup ETH_Broadcast_Frames_Reception ETH Broadcast Frames Reception
- * @{
- */
-#define ETH_BROADCASTFRAMESRECEPTION_ENABLE ((uint32_t)0x00000000)
-#define ETH_BROADCASTFRAMESRECEPTION_DISABLE ((uint32_t)0x00000020)
-/**
- * @}
- */
-
-/** @defgroup ETH_Destination_Addr_Filter ETH Destination Addr Filter
- * @{
- */
-#define ETH_DESTINATIONADDRFILTER_NORMAL ((uint32_t)0x00000000)
-#define ETH_DESTINATIONADDRFILTER_INVERSE ((uint32_t)0x00000008)
-/**
- * @}
- */
-
-/** @defgroup ETH_Promiscuous_Mode ETH Promiscuous Mode
- * @{
- */
-#define ETH_PROMISCUOUS_MODE_ENABLE ((uint32_t)0x00000001)
-#define ETH_PROMISCUOUS_MODE_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Multicast_Frames_Filter ETH Multicast Frames Filter
- * @{
- */
-#define ETH_MULTICASTFRAMESFILTER_PERFECTHASHTABLE ((uint32_t)0x00000404)
-#define ETH_MULTICASTFRAMESFILTER_HASHTABLE ((uint32_t)0x00000004)
-#define ETH_MULTICASTFRAMESFILTER_PERFECT ((uint32_t)0x00000000)
-#define ETH_MULTICASTFRAMESFILTER_NONE ((uint32_t)0x00000010)
-/**
- * @}
- */
-
-/** @defgroup ETH_Unicast_Frames_Filter ETH Unicast Frames Filter
- * @{
- */
-#define ETH_UNICASTFRAMESFILTER_PERFECTHASHTABLE ((uint32_t)0x00000402)
-#define ETH_UNICASTFRAMESFILTER_HASHTABLE ((uint32_t)0x00000002)
-#define ETH_UNICASTFRAMESFILTER_PERFECT ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Zero_Quanta_Pause ETH Zero Quanta Pause
- * @{
- */
-#define ETH_ZEROQUANTAPAUSE_ENABLE ((uint32_t)0x00000000)
-#define ETH_ZEROQUANTAPAUSE_DISABLE ((uint32_t)0x00000080)
-/**
- * @}
- */
-
-/** @defgroup ETH_Pause_Low_Threshold ETH Pause Low Threshold
- * @{
- */
-#define ETH_PAUSELOWTHRESHOLD_MINUS4 ((uint32_t)0x00000000) /*!< Pause time minus 4 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS28 ((uint32_t)0x00000010) /*!< Pause time minus 28 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS144 ((uint32_t)0x00000020) /*!< Pause time minus 144 slot times */
-#define ETH_PAUSELOWTHRESHOLD_MINUS256 ((uint32_t)0x00000030) /*!< Pause time minus 256 slot times */
-/**
- * @}
- */
-
-/** @defgroup ETH_Unicast_Pause_Frame_Detect ETH Unicast Pause Frame Detect
- * @{
- */
-#define ETH_UNICASTPAUSEFRAMEDETECT_ENABLE ((uint32_t)0x00000008)
-#define ETH_UNICASTPAUSEFRAMEDETECT_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Flow_Control ETH Receive Flow Control
- * @{
- */
-#define ETH_RECEIVEFLOWCONTROL_ENABLE ((uint32_t)0x00000004)
-#define ETH_RECEIVEFLOWCONTROL_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Flow_Control ETH Transmit Flow Control
- * @{
- */
-#define ETH_TRANSMITFLOWCONTROL_ENABLE ((uint32_t)0x00000002)
-#define ETH_TRANSMITFLOWCONTROL_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_VLAN_Tag_Comparison ETH VLAN Tag Comparison
- * @{
- */
-#define ETH_VLANTAGCOMPARISON_12BIT ((uint32_t)0x00010000)
-#define ETH_VLANTAGCOMPARISON_16BIT ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses ETH MAC addresses
- * @{
- */
-#define ETH_MAC_ADDRESS0 ((uint32_t)0x00000000)
-#define ETH_MAC_ADDRESS1 ((uint32_t)0x00000008)
-#define ETH_MAC_ADDRESS2 ((uint32_t)0x00000010)
-#define ETH_MAC_ADDRESS3 ((uint32_t)0x00000018)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses_filter_SA_DA ETH MAC addresses filter SA DA
- * @{
- */
-#define ETH_MAC_ADDRESSFILTER_SA ((uint32_t)0x00000000)
-#define ETH_MAC_ADDRESSFILTER_DA ((uint32_t)0x00000008)
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_addresses_filter_Mask_bytes ETH MAC addresses filter Mask bytes
- * @{
- */
-#define ETH_MAC_ADDRESSMASK_BYTE6 ((uint32_t)0x20000000) /*!< Mask MAC Address high reg bits [15:8] */
-#define ETH_MAC_ADDRESSMASK_BYTE5 ((uint32_t)0x10000000) /*!< Mask MAC Address high reg bits [7:0] */
-#define ETH_MAC_ADDRESSMASK_BYTE4 ((uint32_t)0x08000000) /*!< Mask MAC Address low reg bits [31:24] */
-#define ETH_MAC_ADDRESSMASK_BYTE3 ((uint32_t)0x04000000) /*!< Mask MAC Address low reg bits [23:16] */
-#define ETH_MAC_ADDRESSMASK_BYTE2 ((uint32_t)0x02000000) /*!< Mask MAC Address low reg bits [15:8] */
-#define ETH_MAC_ADDRESSMASK_BYTE1 ((uint32_t)0x01000000) /*!< Mask MAC Address low reg bits [70] */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Debug_flags ETH MAC Debug flags
- * @{
- */
-#define ETH_MAC_TXFIFO_FULL ((uint32_t)0x02000000) /* Tx FIFO full */
-#define ETH_MAC_TXFIFONOT_EMPTY ((uint32_t)0x01000000) /* Tx FIFO not empty */
-#define ETH_MAC_TXFIFO_WRITE_ACTIVE ((uint32_t)0x00400000) /* Tx FIFO write active */
-#define ETH_MAC_TXFIFO_IDLE ((uint32_t)0x00000000) /* Tx FIFO read status: Idle */
-#define ETH_MAC_TXFIFO_READ ((uint32_t)0x00100000) /* Tx FIFO read status: Read (transferring data to the MAC transmitter) */
-#define ETH_MAC_TXFIFO_WAITING ((uint32_t)0x00200000) /* Tx FIFO read status: Waiting for TxStatus from MAC transmitter */
-#define ETH_MAC_TXFIFO_WRITING ((uint32_t)0x00300000) /* Tx FIFO read status: Writing the received TxStatus or flushing the TxFIFO */
-#define ETH_MAC_TRANSMISSION_PAUSE ((uint32_t)0x00080000) /* MAC transmitter in pause */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_IDLE ((uint32_t)0x00000000) /* MAC transmit frame controller: Idle */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_WAITING ((uint32_t)0x00020000) /* MAC transmit frame controller: Waiting for Status of previous frame or IFG/backoff period to be over */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_GENRATING_PCF ((uint32_t)0x00040000) /* MAC transmit frame controller: Generating and transmitting a Pause control frame (in full duplex mode) */
-#define ETH_MAC_TRANSMITFRAMECONTROLLER_TRANSFERRING ((uint32_t)0x00060000) /* MAC transmit frame controller: Transferring input frame for transmission */
-#define ETH_MAC_MII_TRANSMIT_ACTIVE ((uint32_t)0x00010000) /* MAC MII transmit engine active */
-#define ETH_MAC_RXFIFO_EMPTY ((uint32_t)0x00000000) /* Rx FIFO fill level: empty */
-#define ETH_MAC_RXFIFO_BELOW_THRESHOLD ((uint32_t)0x00000100) /* Rx FIFO fill level: fill-level below flow-control de-activate threshold */
-#define ETH_MAC_RXFIFO_ABOVE_THRESHOLD ((uint32_t)0x00000200) /* Rx FIFO fill level: fill-level above flow-control activate threshold */
-#define ETH_MAC_RXFIFO_FULL ((uint32_t)0x00000300) /* Rx FIFO fill level: full */
-#define ETH_MAC_READCONTROLLER_IDLE ((uint32_t)0x00000060) /* Rx FIFO read controller IDLE state */
-#define ETH_MAC_READCONTROLLER_READING_DATA ((uint32_t)0x00000060) /* Rx FIFO read controller Reading frame data */
-#define ETH_MAC_READCONTROLLER_READING_STATUS ((uint32_t)0x00000060) /* Rx FIFO read controller Reading frame status (or time-stamp) */
-#define ETH_MAC_READCONTROLLER_ FLUSHING ((uint32_t)0x00000060) /* Rx FIFO read controller Flushing the frame data and status */
-#define ETH_MAC_RXFIFO_WRITE_ACTIVE ((uint32_t)0x00000010) /* Rx FIFO write controller active */
-#define ETH_MAC_SMALL_FIFO_NOTACTIVE ((uint32_t)0x00000000) /* MAC small FIFO read / write controllers not active */
-#define ETH_MAC_SMALL_FIFO_READ_ACTIVE ((uint32_t)0x00000002) /* MAC small FIFO read controller active */
-#define ETH_MAC_SMALL_FIFO_WRITE_ACTIVE ((uint32_t)0x00000004) /* MAC small FIFO write controller active */
-#define ETH_MAC_SMALL_FIFO_RW_ACTIVE ((uint32_t)0x00000006) /* MAC small FIFO read / write controllers active */
-#define ETH_MAC_MII_RECEIVE_PROTOCOL_ACTIVE ((uint32_t)0x00000001) /* MAC MII receive protocol engine active */
-/**
- * @}
- */
-
-/** @defgroup ETH_Drop_TCP_IP_Checksum_Error_Frame ETH Drop TCP IP Checksum Error Frame
- * @{
- */
-#define ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE ((uint32_t)0x00000000)
-#define ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE ((uint32_t)0x04000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Store_Forward ETH Receive Store Forward
- * @{
- */
-#define ETH_RECEIVESTOREFORWARD_ENABLE ((uint32_t)0x02000000)
-#define ETH_RECEIVESTOREFORWARD_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Flush_Received_Frame ETH Flush Received Frame
- * @{
- */
-#define ETH_FLUSHRECEIVEDFRAME_ENABLE ((uint32_t)0x00000000)
-#define ETH_FLUSHRECEIVEDFRAME_DISABLE ((uint32_t)0x01000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Store_Forward ETH Transmit Store Forward
- * @{
- */
-#define ETH_TRANSMITSTOREFORWARD_ENABLE ((uint32_t)0x00200000)
-#define ETH_TRANSMITSTOREFORWARD_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Transmit_Threshold_Control ETH Transmit Threshold Control
- * @{
- */
-#define ETH_TRANSMITTHRESHOLDCONTROL_64BYTES ((uint32_t)0x00000000) /*!< threshold level of the MTL Transmit FIFO is 64 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_128BYTES ((uint32_t)0x00004000) /*!< threshold level of the MTL Transmit FIFO is 128 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_192BYTES ((uint32_t)0x00008000) /*!< threshold level of the MTL Transmit FIFO is 192 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_256BYTES ((uint32_t)0x0000C000) /*!< threshold level of the MTL Transmit FIFO is 256 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_40BYTES ((uint32_t)0x00010000) /*!< threshold level of the MTL Transmit FIFO is 40 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_32BYTES ((uint32_t)0x00014000) /*!< threshold level of the MTL Transmit FIFO is 32 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_24BYTES ((uint32_t)0x00018000) /*!< threshold level of the MTL Transmit FIFO is 24 Bytes */
-#define ETH_TRANSMITTHRESHOLDCONTROL_16BYTES ((uint32_t)0x0001C000) /*!< threshold level of the MTL Transmit FIFO is 16 Bytes */
-/**
- * @}
- */
-
-/** @defgroup ETH_Forward_Error_Frames ETH Forward Error Frames
- * @{
- */
-#define ETH_FORWARDERRORFRAMES_ENABLE ((uint32_t)0x00000080)
-#define ETH_FORWARDERRORFRAMES_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Forward_Undersized_Good_Frames ETH Forward Undersized Good Frames
- * @{
- */
-#define ETH_FORWARDUNDERSIZEDGOODFRAMES_ENABLE ((uint32_t)0x00000040)
-#define ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Receive_Threshold_Control ETH Receive Threshold Control
- * @{
- */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES ((uint32_t)0x00000000) /*!< threshold level of the MTL Receive FIFO is 64 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_32BYTES ((uint32_t)0x00000008) /*!< threshold level of the MTL Receive FIFO is 32 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_96BYTES ((uint32_t)0x00000010) /*!< threshold level of the MTL Receive FIFO is 96 Bytes */
-#define ETH_RECEIVEDTHRESHOLDCONTROL_128BYTES ((uint32_t)0x00000018) /*!< threshold level of the MTL Receive FIFO is 128 Bytes */
-/**
- * @}
- */
-
-/** @defgroup ETH_Second_Frame_Operate ETH Second Frame Operate
- * @{
- */
-#define ETH_SECONDFRAMEOPERARTE_ENABLE ((uint32_t)0x00000004)
-#define ETH_SECONDFRAMEOPERARTE_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Address_Aligned_Beats ETH Address Aligned Beats
- * @{
- */
-#define ETH_ADDRESSALIGNEDBEATS_ENABLE ((uint32_t)0x02000000)
-#define ETH_ADDRESSALIGNEDBEATS_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Fixed_Burst ETH Fixed Burst
- * @{
- */
-#define ETH_FIXEDBURST_ENABLE ((uint32_t)0x00010000)
-#define ETH_FIXEDBURST_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_Rx_DMA_Burst_Length ETH Rx DMA Burst Length
- * @{
- */
-#define ETH_RXDMABURSTLENGTH_1BEAT ((uint32_t)0x00020000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 1 */
-#define ETH_RXDMABURSTLENGTH_2BEAT ((uint32_t)0x00040000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 2 */
-#define ETH_RXDMABURSTLENGTH_4BEAT ((uint32_t)0x00080000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 4 */
-#define ETH_RXDMABURSTLENGTH_8BEAT ((uint32_t)0x00100000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 8 */
-#define ETH_RXDMABURSTLENGTH_16BEAT ((uint32_t)0x00200000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 16 */
-#define ETH_RXDMABURSTLENGTH_32BEAT ((uint32_t)0x00400000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 32 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_4BEAT ((uint32_t)0x01020000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 4 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_8BEAT ((uint32_t)0x01040000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 8 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_16BEAT ((uint32_t)0x01080000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 16 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_32BEAT ((uint32_t)0x01100000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 32 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_64BEAT ((uint32_t)0x01200000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 64 */
-#define ETH_RXDMABURSTLENGTH_4XPBL_128BEAT ((uint32_t)0x01400000) /*!< maximum number of beats to be transferred in one RxDMA transaction is 128 */
-/**
- * @}
- */
-
-/** @defgroup ETH_Tx_DMA_Burst_Length ETH Tx DMA Burst Length
- * @{
- */
-#define ETH_TXDMABURSTLENGTH_1BEAT ((uint32_t)0x00000100) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 1 */
-#define ETH_TXDMABURSTLENGTH_2BEAT ((uint32_t)0x00000200) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 2 */
-#define ETH_TXDMABURSTLENGTH_4BEAT ((uint32_t)0x00000400) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 4 */
-#define ETH_TXDMABURSTLENGTH_8BEAT ((uint32_t)0x00000800) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 8 */
-#define ETH_TXDMABURSTLENGTH_16BEAT ((uint32_t)0x00001000) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 16 */
-#define ETH_TXDMABURSTLENGTH_32BEAT ((uint32_t)0x00002000) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 32 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_4BEAT ((uint32_t)0x01000100) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 4 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_8BEAT ((uint32_t)0x01000200) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 8 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_16BEAT ((uint32_t)0x01000400) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 16 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_32BEAT ((uint32_t)0x01000800) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 32 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_64BEAT ((uint32_t)0x01001000) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 64 */
-#define ETH_TXDMABURSTLENGTH_4XPBL_128BEAT ((uint32_t)0x01002000) /*!< maximum number of beats to be transferred in one TxDMA (or both) transaction is 128 */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Enhanced_descriptor_format ETH DMA Enhanced descriptor format
- * @{
- */
-#define ETH_DMAENHANCEDDESCRIPTOR_ENABLE ((uint32_t)0x00000080)
-#define ETH_DMAENHANCEDDESCRIPTOR_DISABLE ((uint32_t)0x00000000)
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Arbitration ETH DMA Arbitration
- * @{
- */
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1 ((uint32_t)0x00000000)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_2_1 ((uint32_t)0x00004000)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_3_1 ((uint32_t)0x00008000)
-#define ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1 ((uint32_t)0x0000C000)
-#define ETH_DMAARBITRATION_RXPRIORTX ((uint32_t)0x00000002)
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Tx_descriptor_segment ETH DMA Tx descriptor segment
- * @{
- */
-#define ETH_DMATXDESC_LASTSEGMENTS ((uint32_t)0x40000000) /*!< Last Segment */
-#define ETH_DMATXDESC_FIRSTSEGMENT ((uint32_t)0x20000000) /*!< First Segment */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Tx_descriptor_Checksum_Insertion_Control ETH DMA Tx descriptor Checksum Insertion Control
- * @{
- */
-#define ETH_DMATXDESC_CHECKSUMBYPASS ((uint32_t)0x00000000) /*!< Checksum engine bypass */
-#define ETH_DMATXDESC_CHECKSUMIPV4HEADER ((uint32_t)0x00400000) /*!< IPv4 header checksum insertion */
-#define ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT ((uint32_t)0x00800000) /*!< TCP/UDP/ICMP checksum insertion. Pseudo header checksum is assumed to be present */
-#define ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL ((uint32_t)0x00C00000) /*!< TCP/UDP/ICMP checksum fully in hardware including pseudo header */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Rx_descriptor_buffers ETH DMA Rx descriptor buffers
- * @{
- */
-#define ETH_DMARXDESC_BUFFER1 ((uint32_t)0x00000000) /*!< DMA Rx Desc Buffer1 */
-#define ETH_DMARXDESC_BUFFER2 ((uint32_t)0x00000001) /*!< DMA Rx Desc Buffer2 */
-/**
- * @}
- */
-
-/** @defgroup ETH_PMT_Flags ETH PMT Flags
- * @{
- */
-#define ETH_PMT_FLAG_WUFFRPR ((uint32_t)0x80000000) /*!< Wake-Up Frame Filter Register Pointer Reset */
-#define ETH_PMT_FLAG_WUFR ((uint32_t)0x00000040) /*!< Wake-Up Frame Received */
-#define ETH_PMT_FLAG_MPR ((uint32_t)0x00000020) /*!< Magic Packet Received */
-/**
- * @}
- */
-
-/** @defgroup ETH_MMC_Tx_Interrupts ETH MMC Tx Interrupts
- * @{
- */
-#define ETH_MMC_IT_TGF ((uint32_t)0x00200000) /*!< When Tx good frame counter reaches half the maximum value */
-#define ETH_MMC_IT_TGFMSC ((uint32_t)0x00008000) /*!< When Tx good multi col counter reaches half the maximum value */
-#define ETH_MMC_IT_TGFSC ((uint32_t)0x00004000) /*!< When Tx good single col counter reaches half the maximum value */
-/**
- * @}
- */
-
-/** @defgroup ETH_MMC_Rx_Interrupts ETH MMC Rx Interrupts
- * @{
- */
-#define ETH_MMC_IT_RGUF ((uint32_t)0x10020000) /*!< When Rx good unicast frames counter reaches half the maximum value */
-#define ETH_MMC_IT_RFAE ((uint32_t)0x10000040) /*!< When Rx alignment error counter reaches half the maximum value */
-#define ETH_MMC_IT_RFCE ((uint32_t)0x10000020) /*!< When Rx crc error counter reaches half the maximum value */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Flags ETH MAC Flags
- * @{
- */
-#define ETH_MAC_FLAG_TST ((uint32_t)0x00000200) /*!< Time stamp trigger flag (on MAC) */
-#define ETH_MAC_FLAG_MMCT ((uint32_t)0x00000040) /*!< MMC transmit flag */
-#define ETH_MAC_FLAG_MMCR ((uint32_t)0x00000020) /*!< MMC receive flag */
-#define ETH_MAC_FLAG_MMC ((uint32_t)0x00000010) /*!< MMC flag (on MAC) */
-#define ETH_MAC_FLAG_PMT ((uint32_t)0x00000008) /*!< PMT flag (on MAC) */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Flags ETH DMA Flags
- * @{
- */
-#define ETH_DMA_FLAG_TST ((uint32_t)0x20000000) /*!< Time-stamp trigger interrupt (on DMA) */
-#define ETH_DMA_FLAG_PMT ((uint32_t)0x10000000) /*!< PMT interrupt (on DMA) */
-#define ETH_DMA_FLAG_MMC ((uint32_t)0x08000000) /*!< MMC interrupt (on DMA) */
-#define ETH_DMA_FLAG_DATATRANSFERERROR ((uint32_t)0x00800000) /*!< Error bits 0-Rx DMA, 1-Tx DMA */
-#define ETH_DMA_FLAG_READWRITEERROR ((uint32_t)0x01000000) /*!< Error bits 0-write transfer, 1-read transfer */
-#define ETH_DMA_FLAG_ACCESSERROR ((uint32_t)0x02000000) /*!< Error bits 0-data buffer, 1-desc. access */
-#define ETH_DMA_FLAG_NIS ((uint32_t)0x00010000) /*!< Normal interrupt summary flag */
-#define ETH_DMA_FLAG_AIS ((uint32_t)0x00008000) /*!< Abnormal interrupt summary flag */
-#define ETH_DMA_FLAG_ER ((uint32_t)0x00004000) /*!< Early receive flag */
-#define ETH_DMA_FLAG_FBE ((uint32_t)0x00002000) /*!< Fatal bus error flag */
-#define ETH_DMA_FLAG_ET ((uint32_t)0x00000400) /*!< Early transmit flag */
-#define ETH_DMA_FLAG_RWT ((uint32_t)0x00000200) /*!< Receive watchdog timeout flag */
-#define ETH_DMA_FLAG_RPS ((uint32_t)0x00000100) /*!< Receive process stopped flag */
-#define ETH_DMA_FLAG_RBU ((uint32_t)0x00000080) /*!< Receive buffer unavailable flag */
-#define ETH_DMA_FLAG_R ((uint32_t)0x00000040) /*!< Receive flag */
-#define ETH_DMA_FLAG_TU ((uint32_t)0x00000020) /*!< Underflow flag */
-#define ETH_DMA_FLAG_RO ((uint32_t)0x00000010) /*!< Overflow flag */
-#define ETH_DMA_FLAG_TJT ((uint32_t)0x00000008) /*!< Transmit jabber timeout flag */
-#define ETH_DMA_FLAG_TBU ((uint32_t)0x00000004) /*!< Transmit buffer unavailable flag */
-#define ETH_DMA_FLAG_TPS ((uint32_t)0x00000002) /*!< Transmit process stopped flag */
-#define ETH_DMA_FLAG_T ((uint32_t)0x00000001) /*!< Transmit flag */
-/**
- * @}
- */
-
-/** @defgroup ETH_MAC_Interrupts ETH MAC Interrupts
- * @{
- */
-#define ETH_MAC_IT_TST ((uint32_t)0x00000200) /*!< Time stamp trigger interrupt (on MAC) */
-#define ETH_MAC_IT_MMCT ((uint32_t)0x00000040) /*!< MMC transmit interrupt */
-#define ETH_MAC_IT_MMCR ((uint32_t)0x00000020) /*!< MMC receive interrupt */
-#define ETH_MAC_IT_MMC ((uint32_t)0x00000010) /*!< MMC interrupt (on MAC) */
-#define ETH_MAC_IT_PMT ((uint32_t)0x00000008) /*!< PMT interrupt (on MAC) */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_Interrupts ETH DMA Interrupts
- * @{
- */
-#define ETH_DMA_IT_TST ((uint32_t)0x20000000) /*!< Time-stamp trigger interrupt (on DMA) */
-#define ETH_DMA_IT_PMT ((uint32_t)0x10000000) /*!< PMT interrupt (on DMA) */
-#define ETH_DMA_IT_MMC ((uint32_t)0x08000000) /*!< MMC interrupt (on DMA) */
-#define ETH_DMA_IT_NIS ((uint32_t)0x00010000) /*!< Normal interrupt summary */
-#define ETH_DMA_IT_AIS ((uint32_t)0x00008000) /*!< Abnormal interrupt summary */
-#define ETH_DMA_IT_ER ((uint32_t)0x00004000) /*!< Early receive interrupt */
-#define ETH_DMA_IT_FBE ((uint32_t)0x00002000) /*!< Fatal bus error interrupt */
-#define ETH_DMA_IT_ET ((uint32_t)0x00000400) /*!< Early transmit interrupt */
-#define ETH_DMA_IT_RWT ((uint32_t)0x00000200) /*!< Receive watchdog timeout interrupt */
-#define ETH_DMA_IT_RPS ((uint32_t)0x00000100) /*!< Receive process stopped interrupt */
-#define ETH_DMA_IT_RBU ((uint32_t)0x00000080) /*!< Receive buffer unavailable interrupt */
-#define ETH_DMA_IT_R ((uint32_t)0x00000040) /*!< Receive interrupt */
-#define ETH_DMA_IT_TU ((uint32_t)0x00000020) /*!< Underflow interrupt */
-#define ETH_DMA_IT_RO ((uint32_t)0x00000010) /*!< Overflow interrupt */
-#define ETH_DMA_IT_TJT ((uint32_t)0x00000008) /*!< Transmit jabber timeout interrupt */
-#define ETH_DMA_IT_TBU ((uint32_t)0x00000004) /*!< Transmit buffer unavailable interrupt */
-#define ETH_DMA_IT_TPS ((uint32_t)0x00000002) /*!< Transmit process stopped interrupt */
-#define ETH_DMA_IT_T ((uint32_t)0x00000001) /*!< Transmit interrupt */
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_transmit_process_state ETH DMA transmit process state
- * @{
- */
-#define ETH_DMA_TRANSMITPROCESS_STOPPED ((uint32_t)0x00000000) /*!< Stopped - Reset or Stop Tx Command issued */
-#define ETH_DMA_TRANSMITPROCESS_FETCHING ((uint32_t)0x00100000) /*!< Running - fetching the Tx descriptor */
-#define ETH_DMA_TRANSMITPROCESS_WAITING ((uint32_t)0x00200000) /*!< Running - waiting for status */
-#define ETH_DMA_TRANSMITPROCESS_READING ((uint32_t)0x00300000) /*!< Running - reading the data from host memory */
-#define ETH_DMA_TRANSMITPROCESS_SUSPENDED ((uint32_t)0x00600000) /*!< Suspended - Tx Descriptor unavailable */
-#define ETH_DMA_TRANSMITPROCESS_CLOSING ((uint32_t)0x00700000) /*!< Running - closing Rx descriptor */
-
-/**
- * @}
- */
-
-
-/** @defgroup ETH_DMA_receive_process_state ETH DMA receive process state
- * @{
- */
-#define ETH_DMA_RECEIVEPROCESS_STOPPED ((uint32_t)0x00000000) /*!< Stopped - Reset or Stop Rx Command issued */
-#define ETH_DMA_RECEIVEPROCESS_FETCHING ((uint32_t)0x00020000) /*!< Running - fetching the Rx descriptor */
-#define ETH_DMA_RECEIVEPROCESS_WAITING ((uint32_t)0x00060000) /*!< Running - waiting for packet */
-#define ETH_DMA_RECEIVEPROCESS_SUSPENDED ((uint32_t)0x00080000) /*!< Suspended - Rx Descriptor unavailable */
-#define ETH_DMA_RECEIVEPROCESS_CLOSING ((uint32_t)0x000A0000) /*!< Running - closing descriptor */
-#define ETH_DMA_RECEIVEPROCESS_QUEUING ((uint32_t)0x000E0000) /*!< Running - queuing the receive frame into host memory */
-
-/**
- * @}
- */
-
-/** @defgroup ETH_DMA_overflow ETH DMA overflow
- * @{
- */
-#define ETH_DMA_OVERFLOW_RXFIFOCOUNTER ((uint32_t)0x10000000) /*!< Overflow bit for FIFO overflow counter */
-#define ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER ((uint32_t)0x00010000) /*!< Overflow bit for missed frame counter */
-/**
- * @}
- */
-
-/** @defgroup ETH_EXTI_LINE_WAKEUP ETH EXTI LINE WAKEUP
- * @{
- */
-#define ETH_EXTI_LINE_WAKEUP ((uint32_t)0x00080000) /*!< External interrupt line 19 Connected to the ETH EXTI Line */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/* Exported macro ------------------------------------------------------------*/
-/** @defgroup ETH_Exported_Macros ETH Exported Macros
- * @brief macros to handle interrupts and specific clock configurations
- * @{
- */
-
-/** @brief Reset ETH handle state
- * @param __HANDLE__: specifies the ETH handle.
- * @retval None
- */
-#define __HAL_ETH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ETH_STATE_RESET)
-
-/**
- * @brief Checks whether the specified ETHERNET DMA Tx Desc flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag of TDES0 to check.
- * @retval the ETH_DMATxDescFlag (SET or RESET).
- */
-#define __HAL_ETH_DMATXDESC_GET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->TxDesc->Status & (__FLAG__) == (__FLAG__))
-
-/**
- * @brief Checks whether the specified ETHERNET DMA Rx Desc flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag of RDES0 to check.
- * @retval the ETH_DMATxDescFlag (SET or RESET).
- */
-#define __HAL_ETH_DMARXDESC_GET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->RxDesc->Status & (__FLAG__) == (__FLAG__))
-
-/**
- * @brief Enables the specified DMA Rx Desc receive interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_ENABLE_IT(__HANDLE__) ((__HANDLE__)->RxDesc->ControlBufferSize &=(~(uint32_t)ETH_DMARXDESC_DIC))
-
-/**
- * @brief Disables the specified DMA Rx Desc receive interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_DISABLE_IT(__HANDLE__) ((__HANDLE__)->RxDesc->ControlBufferSize |= ETH_DMARXDESC_DIC)
-
-/**
- * @brief Set the specified DMA Rx Desc Own bit.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMARXDESC_SET_OWN_BIT(__HANDLE__) ((__HANDLE__)->RxDesc->Status |= ETH_DMARXDESC_OWN)
-
-/**
- * @brief Returns the specified ETHERNET DMA Tx Desc collision count.
- * @param __HANDLE__: ETH Handle
- * @retval The Transmit descriptor collision counter value.
- */
-#define __HAL_ETH_DMATXDESC_GET_COLLISION_COUNT(__HANDLE__) (((__HANDLE__)->TxDesc->Status & ETH_DMATXDESC_CC) >> ETH_DMATXDESC_COLLISION_COUNTSHIFT)
-
-/**
- * @brief Set the specified DMA Tx Desc Own bit.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SET_OWN_BIT(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_OWN)
-
-/**
- * @brief Enables the specified DMA Tx Desc Transmit interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_ENABLE_IT(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_IC)
-
-/**
- * @brief Disables the specified DMA Tx Desc Transmit interrupt.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_DISABLE_IT(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_IC)
-
-/**
- * @brief Selects the specified ETHERNET DMA Tx Desc Checksum Insertion.
- * @param __HANDLE__: ETH Handle
- * @param __CHECKSUM__: specifies is the DMA Tx desc checksum insertion.
- * This parameter can be one of the following values:
- * @arg ETH_DMATXDESC_CHECKSUMBYPASS : Checksum bypass
- * @arg ETH_DMATXDESC_CHECKSUMIPV4HEADER : IPv4 header checksum
- * @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT : TCP/UDP/ICMP checksum. Pseudo header checksum is assumed to be present
- * @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL : TCP/UDP/ICMP checksum fully in hardware including pseudo header
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CHECKSUM_INSERTION(__HANDLE__, __CHECKSUM__) ((__HANDLE__)->TxDesc->Status |= (__CHECKSUM__))
-
-/**
- * @brief Enables the DMA Tx Desc CRC.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CRC_ENABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_DC)
-
-/**
- * @brief Disables the DMA Tx Desc CRC.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_CRC_DISABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_DC)
-
-/**
- * @brief Enables the DMA Tx Desc padding for frame shorter than 64 bytes.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SHORT_FRAME_PADDING_ENABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status &= ~ETH_DMATXDESC_DP)
-
-/**
- * @brief Disables the DMA Tx Desc padding for frame shorter than 64 bytes.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_DMATXDESC_SHORT_FRAME_PADDING_DISABLE(__HANDLE__) ((__HANDLE__)->TxDesc->Status |= ETH_DMATXDESC_DP)
-
-/**
- * @brief Enables the specified ETHERNET MAC interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @retval None
- */
-#define __HAL_ETH_MAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIMR |= (__INTERRUPT__))
-
-/**
- * @brief Disables the specified ETHERNET MAC interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @retval None
- */
-#define __HAL_ETH_MAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIMR &= ~(__INTERRUPT__))
-
-/**
- * @brief Initiate a Pause Control Frame (Full-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_INITIATE_PAUSE_CONTROL_FRAME(__HANDLE__) ((__HANDLE__)->Instance->MACFCR |= ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Checks whether the ETHERNET flow control busy bit is set or not.
- * @param __HANDLE__: ETH Handle
- * @retval The new state of flow control busy status bit (SET or RESET).
- */
-#define __HAL_ETH_GET_FLOW_CONTROL_BUSY_STATUS(__HANDLE__) (((__HANDLE__)->Instance->MACFCR & ETH_MACFCR_FCBBPA) == ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Enables the MAC Back Pressure operation activation (Half-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_BACK_PRESSURE_ACTIVATION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACFCR |= ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Disables the MAC BackPressure operation activation (Half-duplex only).
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_BACK_PRESSURE_ACTIVATION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACFCR &= ~ETH_MACFCR_FCBBPA)
-
-/**
- * @brief Checks whether the specified ETHERNET MAC flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_FLAG_TST : Time stamp trigger flag
- * @arg ETH_MAC_FLAG_MMCT : MMC transmit flag
- * @arg ETH_MAC_FLAG_MMCR : MMC receive flag
- * @arg ETH_MAC_FLAG_MMC : MMC flag
- * @arg ETH_MAC_FLAG_PMT : PMT flag
- * @retval The state of ETHERNET MAC flag.
- */
-#define __HAL_ETH_MAC_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->MACSR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Enables the specified ETHERNET DMA interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
- * enabled @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMAIER |= (__INTERRUPT__))
-
-/**
- * @brief Disables the specified ETHERNET DMA interrupts.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
- * disabled. @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMAIER &= ~(__INTERRUPT__))
-
-/**
- * @brief Clears the ETHERNET DMA IT pending bit.
- * @param __HANDLE__ : ETH Handle
- * @param __INTERRUPT__: specifies the interrupt pending bit to clear. @ref ETH_DMA_Interrupts
- * @retval None
- */
-#define __HAL_ETH_DMA_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMASR =(__INTERRUPT__))
-
-/**
- * @brief Checks whether the specified ETHERNET DMA flag is set or not.
-* @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Flags
- * @retval The new state of ETH_DMA_FLAG (SET or RESET).
- */
-#define __HAL_ETH_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->DMASR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Checks whether the specified ETHERNET DMA flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __FLAG__: specifies the flag to clear. @ref ETH_DMA_Flags
- * @retval The new state of ETH_DMA_FLAG (SET or RESET).
- */
-#define __HAL_ETH_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->DMASR = (__FLAG__))
-
-/**
- * @brief Checks whether the specified ETHERNET DMA overflow flag is set or not.
- * @param __HANDLE__: ETH Handle
- * @param __OVERFLOW__: specifies the DMA overflow flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMA_OVERFLOW_RXFIFOCOUNTER : Overflow for FIFO Overflows Counter
- * @arg ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER : Overflow for Buffer Unavailable Missed Frame Counter
- * @retval The state of ETHERNET DMA overflow Flag (SET or RESET).
- */
-#define __HAL_ETH_GET_DMA_OVERFLOW_STATUS(__HANDLE__, __OVERFLOW__) (((__HANDLE__)->Instance->DMAMFBOCR & (__OVERFLOW__)) == (__OVERFLOW__))
-
-/**
- * @brief Set the DMA Receive status watchdog timer register value
- * @param __HANDLE__: ETH Handle
- * @param __VALUE__: DMA Receive status watchdog timer register value
- * @retval None
- */
-#define __HAL_ETH_SET_RECEIVE_WATCHDOG_TIMER(__HANDLE__, __VALUE__) ((__HANDLE__)->Instance->DMARSWTR = (__VALUE__))
-
-/**
- * @brief Enables any unicast packet filtered by the MAC address
- * recognition to be a wake-up frame.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_GLOBAL_UNICAST_WAKEUP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_GU)
-
-/**
- * @brief Disables any unicast packet filtered by the MAC address
- * recognition to be a wake-up frame.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_GLOBAL_UNICAST_WAKEUP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_GU)
-
-/**
- * @brief Enables the MAC Wake-Up Frame Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_FRAME_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Disables the MAC Wake-Up Frame Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_FRAME_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Enables the MAC Magic Packet Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MAGIC_PACKET_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_MPE)
-
-/**
- * @brief Disables the MAC Magic Packet Detection.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MAGIC_PACKET_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_WFE)
-
-/**
- * @brief Enables the MAC Power Down.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_POWER_DOWN_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR |= ETH_MACPMTCSR_PD)
-
-/**
- * @brief Disables the MAC Power Down.
- * @param __HANDLE__: ETH Handle
- * @retval None
- */
-#define __HAL_ETH_POWER_DOWN_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MACPMTCSR &= ~ETH_MACPMTCSR_PD)
-
-/**
- * @brief Checks whether the specified ETHERNET PMT flag is set or not.
- * @param __HANDLE__: ETH Handle.
- * @param __FLAG__: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_PMT_FLAG_WUFFRPR : Wake-Up Frame Filter Register Pointer Reset
- * @arg ETH_PMT_FLAG_WUFR : Wake-Up Frame Received
- * @arg ETH_PMT_FLAG_MPR : Magic Packet Received
- * @retval The new state of ETHERNET PMT Flag (SET or RESET).
- */
-#define __HAL_ETH_GET_PMT_FLAG_STATUS(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->MACPMTCSR &( __FLAG__)) == ( __FLAG__))
-
-/**
- * @brief Preset and Initialize the MMC counters to almost-full value: 0xFFFF_FFF0 (full - 16)
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FULL_PRESET(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= (ETH_MMCCR_MCFHP | ETH_MMCCR_MCP))
-
-/**
- * @brief Preset and Initialize the MMC counters to almost-half value: 0x7FFF_FFF0 (half - 16)
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_HALF_PRESET(__HANDLE__) do{(__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_MCFHP;\
- (__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_MCP;} while (0)
-
-/**
- * @brief Enables the MMC Counter Freeze.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FREEZE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_MCF)
-
-/**
- * @brief Disables the MMC Counter Freeze.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTER_FREEZE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_MCF)
-
-/**
- * @brief Enables the MMC Reset On Read.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_RESET_ONREAD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_ROR)
-
-/**
- * @brief Disables the MMC Reset On Read.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_RESET_ONREAD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_ROR)
-
-/**
- * @brief Enables the MMC Counter Stop Rollover.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_COUNTER_ROLLOVER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR &= ~ETH_MMCCR_CSR)
-
-/**
- * @brief Disables the MMC Counter Stop Rollover.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_ETH_MMC_COUNTER_ROLLOVER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_CSR)
-
-/**
- * @brief Resets the MMC Counters.
- * @param __HANDLE__: ETH Handle.
- * @retval None
- */
-#define __HAL_ETH_MMC_COUNTERS_RESET(__HANDLE__) ((__HANDLE__)->Instance->MMCCR |= ETH_MMCCR_CR)
-
-/**
- * @brief Enables the specified ETHERNET MMC Rx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_RGUF : When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_RX_IT_ENABLE(__HANDLE__, __INTERRUPT__) (__HANDLE__)->Instance->MMCRIMR &= ~((__INTERRUPT__) & 0xEFFFFFFF)
-/**
- * @brief Disables the specified ETHERNET MMC Rx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_RGUF : When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_RX_IT_DISABLE(__HANDLE__, __INTERRUPT__) (__HANDLE__)->Instance->MMCRIMR |= ((__INTERRUPT__) & 0xEFFFFFFF)
-/**
- * @brief Enables the specified ETHERNET MMC Tx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_TX_IT_ENABLE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MMCRIMR &= ~ (__INTERRUPT__))
-
-/**
- * @brief Disables the specified ETHERNET MMC Tx interrupts.
- * @param __HANDLE__: ETH Handle.
- * @param __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value
- * @retval None
- */
-#define __HAL_ETH_MMC_TX_IT_DISABLE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MMCRIMR |= (__INTERRUPT__))
-
-/**
- * @brief Enables the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disables the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enable event on ETH External event line.
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_EVENT() EXTI->EMR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disable event on ETH External event line
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_EVENT() EXTI->EMR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Get flag of the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Clear flag of the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables rising edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_EDGE_TRIGGER() EXTI->RTSR |= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @brief Disables the rising edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_RISING_EDGE_TRIGGER() EXTI->RTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLING_EDGE_TRIGGER() EXTI->FTSR |= (ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Disables falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_FALLING_EDGE_TRIGGER() EXTI->FTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Enables rising/falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLINGRISING_TRIGGER() EXTI->RTSR |= ETH_EXTI_LINE_WAKEUP;\
- EXTI->FTSR |= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @brief Disables rising/falling edge trigger to the ETH External interrupt line.
- * @retval None
- */
-#define __HAL_ETH_WAKEUP_EXTI_DISABLE_FALLINGRISING_TRIGGER() EXTI->RTSR &= ~(ETH_EXTI_LINE_WAKEUP);\
- EXTI->FTSR &= ~(ETH_EXTI_LINE_WAKEUP)
-
-/**
- * @brief Generate a Software interrupt on selected EXTI line.
- * @retval None.
- */
-#define __HAL_ETH_WAKEUP_EXTI_GENERATE_SWIT() EXTI->SWIER|= ETH_EXTI_LINE_WAKEUP
-
-/**
- * @}
- */
-/* Exported functions --------------------------------------------------------*/
-
-/** @addtogroup ETH_Exported_Functions
- * @{
- */
-
-/* Initialization and de-initialization functions ****************************/
-
-/** @addtogroup ETH_Exported_Functions_Group1
- * @{
- */
-HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth);
-void HAL_ETH_MspInit(ETH_HandleTypeDef *heth);
-void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMATxDescTab, uint8_t* TxBuff, uint32_t TxBuffCount);
-HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount);
-
-/**
- * @}
- */
-/* IO operation functions ****************************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group2
- * @{
- */
-HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength);
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame(ETH_HandleTypeDef *heth);
-/* Communication with PHY functions*/
-HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue);
-HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue);
-/* Non-Blocking mode: Interrupt */
-HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT(ETH_HandleTypeDef *heth);
-void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth);
-/* Callback in non blocking modes (Interrupt) */
-void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth);
-void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth);
-void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth);
-/**
- * @}
- */
-
-/* Peripheral Control functions **********************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group3
- * @{
- */
-
-HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth);
-HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf);
-HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf);
-/**
- * @}
- */
-
-/* Peripheral State functions ************************************************/
-
-/** @addtogroup ETH_Exported_Functions_Group4
- * @{
- */
-HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth);
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F4xx_HAL_ETH_H */
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/FaultInjection.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/FaultInjection.c
deleted file mode 100755
index 9ae5773..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/FaultInjection.c
+++ /dev/null
@@ -1,173 +0,0 @@
-#define xBUFFER_CACHE_SIZE 10
-#define xMAX_FAULT_INJECTION_RATE 15
-#define xMIN_FAULT_INJECTION_RATE 3
-#define xNUM_FAULT_TYPES 1
-
-static NetworkBufferDescriptor_t *xNetworkBufferCache[ xBUFFER_CACHE_SIZE ] = { 0 };
-
-#define xFAULT_LOG_SIZE 2048
-uint32_t ulInjectedFault[ xFAULT_LOG_SIZE ];
-uint32_t ulFaultLogIndex = 0;
-
-static BaseType_t prvCachePacket( NetworkBufferDescriptor_t *pxNetworkBufferIn )
-{
-BaseType_t x, xReturn = pdFALSE;
-
- for( x = 0; x < xBUFFER_CACHE_SIZE; x++ )
- {
- if( xNetworkBufferCache[ x ] == NULL )
- {
- xNetworkBufferCache[ x ] = pxNetworkBufferIn;
- xReturn = pdTRUE;
- break;
- }
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static NetworkBufferDescriptor_t *prvGetCachedPacket( void )
-{
-BaseType_t x;
-NetworkBufferDescriptor_t *pxReturn = NULL;
-
- for( x = ( xBUFFER_CACHE_SIZE - 1 ); x >= 0; x-- )
- {
- if( xNetworkBufferCache[ x ] != NULL )
- {
- pxReturn = xNetworkBufferCache[ x ];
- xNetworkBufferCache[ x ] = NULL;
- break;
- }
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-static NetworkBufferDescriptor_t *prvDuplicatePacket( NetworkBufferDescriptor_t * pxOriginalPacket, const uint8_t *pucPacketData )
-{
-NetworkBufferDescriptor_t *pxReturn;
-
- /* Obtain a new descriptor. */
- pxReturn = pxGetNetworkBufferWithDescriptor( pxOriginalPacket->xDataLength, 0 );
-
- if( pxReturn != NULL )
- {
- /* Copy in the packet data. */
- pxReturn->xDataLength = pxOriginalPacket->xDataLength;
- memcpy( pxReturn->pucEthernetBuffer, pucPacketData, pxOriginalPacket->xDataLength );
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
-
-static NetworkBufferDescriptor_t *prvRxFaultInjection( NetworkBufferDescriptor_t *pxNetworkBufferIn, const uint8_t *pucPacketData )
-{
-static uint32_t ulCallCount = 0, ulNextFaultCallCount = 0;
-NetworkBufferDescriptor_t *pxReturn = pxNetworkBufferIn;
-IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-uint32_t ulFault;
-
-return pxNetworkBufferIn;
-
- ulCallCount++;
-
- if( ulCallCount > ulNextFaultCallCount )
- {
- ulNextFaultCallCount = ipconfigRAND32() % xMAX_FAULT_INJECTION_RATE;
- if( ulNextFaultCallCount < xMIN_FAULT_INJECTION_RATE )
- {
- ulNextFaultCallCount = xMIN_FAULT_INJECTION_RATE;
- }
-
- ulCallCount = 0;
-
- ulFault = ipconfigRAND32() % xNUM_FAULT_TYPES;
-
- if( ulFaultLogIndex < xFAULT_LOG_SIZE )
- {
- ulInjectedFault[ ulFaultLogIndex ] = ulFault;
- ulFaultLogIndex++;
- }
-
- switch( ulFault )
- {
- case 0:
- /* Just drop the packet. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBufferIn );
- pxReturn = NULL;
- break;
-
- case 1:
- /* Store the packet in the cache for later. */
- if( prvCachePacket( pxNetworkBufferIn ) == pdTRUE )
- {
- /* The packet may get sent later, it is not being sent
- now. */
- pxReturn = NULL;
- }
- break;
-
- case 2:
- /* Send a cached packet. */
- pxReturn = prvGetCachedPacket();
- if( pxReturn != NULL )
- {
- /* A cached packet was obtained so drop the original
- packet. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBufferIn );
- }
- else
- {
- /* Could not obtain a packet from the cache so just return
- the packet that was passed in. */
- pxReturn = pxNetworkBufferIn;
- }
- break;
-
- case 4:
-
- /* Send a duplicate of the packet right away. */
- pxReturn = prvDuplicatePacket( pxNetworkBufferIn, pucPacketData );
-
- /* Send the original packet to the stack. */
- xRxEvent.pvData = ( void * ) pxNetworkBufferIn;
- if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 0 ) == pdFAIL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBufferIn );
- }
- break;
-
- case 5:
-
- /* Send both a cached packet and the current packet. */
- xRxEvent.pvData = ( void * ) prvGetCachedPacket();
- if( xRxEvent.pvData != NULL )
- {
- if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 0 ) == pdFAIL )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBufferIn );
- }
- }
- break;
-
- case 6:
- case 7:
- case 8:
- /* Store the packet in the cache for later. */
- if( prvCachePacket( pxNetworkBufferIn ) == pdTRUE )
- {
- /* The packet may get sent later, it is not being sent
- now. */
- pxReturn = NULL;
- }
- break;
- }
- }
-
- return pxReturn;
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c
deleted file mode 100755
index f273477..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c
+++ /dev/null
@@ -1,634 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/* WinPCap includes. */
-#define HAVE_REMOTE
-#include "pcap.h"
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-
-/* Thread-safe circular buffers are being used to pass data to and from the PCAP
-access functions. */
-#include "Win32-Extensions.h"
-#include "FreeRTOS_Stream_Buffer.h"
-
-/* Sizes of the thread safe circular buffers used to pass data to and from the
-WinPCAP Windows threads. */
-#define xSEND_BUFFER_SIZE 32768
-#define xRECV_BUFFER_SIZE 32768
-
-/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet
-driver will filter incoming packets and only pass the stack those packets it
-considers need processing. */
-#if( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 )
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
-#else
- #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
-#endif
-
-/* Used to insert test code only. */
-#define niDISRUPT_PACKETS 0
-
-/*-----------------------------------------------------------*/
-
-/*
- * Windows threads that are outside of the control of the FreeRTOS simulator are
- * used to interface with the WinPCAP libraries.
- */
-DWORD WINAPI prvWinPcapRecvThread( void *pvParam );
-DWORD WINAPI prvWinPcapSendThread( void *pvParam );
-
-/*
- * Print out a numbered list of network interfaces that are available on the
- * host computer.
- */
-static pcap_if_t * prvPrintAvailableNetworkInterfaces( void );
-
-/*
- * Open the network interface. The number of the interface to be opened is set
- * by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.
- */
-static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces );
-static int prvOpenInterface( const char *pucName );
-
-/*
- * Configure the capture filter to allow blocking reads, and to filter out
- * packets that are not of interest to this demo.
- */
-static void prvConfigureCaptureBehaviour( void );
-
-/*
- * A function that simulates Ethernet interrupts by periodically polling the
- * WinPCap interface for new data.
- */
-static void prvInterruptSimulatorTask( void *pvParameters );
-
-/*
- * Create the buffers that are used to pass data between the FreeRTOS simulator
- * and the Win32 threads that manage WinPCAP.
- */
-static void prvCreateThreadSafeBuffers( void );
-
-/*
- * Utility function used to format print messages only.
- */
-static const char *prvRemoveSpaces( char *pcBuffer, int aBuflen, const char *pcMessage );
-
-/*-----------------------------------------------------------*/
-
-/* Required by the WinPCap library. */
-static char cErrorBuffer[ PCAP_ERRBUF_SIZE ];
-
-/* An event used to wake up the Win32 thread that sends data through the WinPCAP
-library. */
-static void *pvSendEvent = NULL;
-
-/* _HT_ made the PCAP interface number configurable through the program's
-parameters in order to test in different machines. */
-static BaseType_t xConfigNextworkInterfaceToUse = configNETWORK_INTERFACE_TO_USE;
-
-/* Handles to the Windows threads that handle the PCAP IO. */
-static HANDLE vWinPcapRecvThreadHandle = NULL;
-static HANDLE vWinPcapSendThreadHandle = NULL;;
-
-/* The interface being used by WinPCap. */
-static pcap_t *pxOpenedInterfaceHandle = NULL;
-
-/* Circular buffers used by the PCAP Win32 threads. */
-static StreamBuffer_t *xSendBuffer = NULL;
-static StreamBuffer_t *xRecvBuffer = NULL;
-
-/* The MAC address initially set to the constants defined in FreeRTOSConfig.h. */
-extern uint8_t ucMACAddress[ 6 ];
-
-/* Logs the number of WinPCAP send failures, for viewing in the debugger only. */
-static volatile uint32_t ulWinPCAPSendFailures = 0;
-
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-BaseType_t xReturn = pdFALSE;
-pcap_if_t *pxAllNetworkInterfaces;
-
- /* Query the computer the simulation is being executed on to find the
- network interfaces it has installed. */
- pxAllNetworkInterfaces = prvPrintAvailableNetworkInterfaces();
-
- /* Open the network interface. The number of the interface to be opened is
- set by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.
- Calling this function will set the pxOpenedInterfaceHandle variable. If,
- after calling this function, pxOpenedInterfaceHandle is equal to NULL, then
- the interface could not be opened. */
- if( pxAllNetworkInterfaces != NULL )
- {
- prvOpenSelectedNetworkInterface( pxAllNetworkInterfaces );
- }
-
- if( pxOpenedInterfaceHandle != NULL )
- {
- xReturn = pdPASS;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void prvCreateThreadSafeBuffers( void )
-{
- /* The buffer used to pass data to be transmitted from a FreeRTOS task to
- the Win32 thread that sends via the WinPCAP library. */
- if( xSendBuffer == NULL)
- {
- xSendBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xSendBuffer ) - sizeof( xSendBuffer->ucArray ) + xSEND_BUFFER_SIZE + 1 );
- configASSERT( xSendBuffer );
- memset( xSendBuffer, '\0', sizeof( *xSendBuffer ) - sizeof( xSendBuffer->ucArray ) );
- xSendBuffer->LENGTH = xSEND_BUFFER_SIZE + 1;
- }
-
- /* The buffer used to pass received data from the Win32 thread that receives
- via the WinPCAP library to the FreeRTOS task. */
- if( xRecvBuffer == NULL)
- {
- xRecvBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xRecvBuffer ) - sizeof( xRecvBuffer->ucArray ) + xRECV_BUFFER_SIZE + 1 );
- configASSERT( xRecvBuffer );
- memset( xRecvBuffer, '\0', sizeof( *xRecvBuffer ) - sizeof( xRecvBuffer->ucArray ) );
- xRecvBuffer->LENGTH = xRECV_BUFFER_SIZE + 1;
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, BaseType_t bReleaseAfterSend )
-{
-size_t xSpace;
-
- iptraceNETWORK_INTERFACE_TRANSMIT();
- configASSERT( xIsCallingFromIPTask() == pdTRUE );
-
- /* Both the length of the data being sent and the actual data being sent
- are placed in the thread safe buffer used to pass data between the FreeRTOS
- tasks and the Win32 thread that sends data via the WinPCAP library. Drop
- the packet if there is insufficient space in the buffer to hold both. */
- xSpace = uxStreamBufferGetSpace( xSendBuffer );
-
- if( ( pxNetworkBuffer->xDataLength <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) &&
- ( xSpace >= ( pxNetworkBuffer->xDataLength + sizeof( pxNetworkBuffer->xDataLength ) ) ) )
- {
- /* First write in the length of the data, then write in the data
- itself. */
- uxStreamBufferAdd( xSendBuffer, 0, ( const uint8_t * ) &( pxNetworkBuffer->xDataLength ), sizeof( pxNetworkBuffer->xDataLength ) );
- uxStreamBufferAdd( xSendBuffer, 0, ( const uint8_t * ) pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
- }
- else
- {
- FreeRTOS_debug_printf( ( "xNetworkInterfaceOutput: send buffers full to store %lu\n", pxNetworkBuffer->xDataLength ) );
- }
-
- /* Kick the Tx task in either case in case it doesn't know the buffer is
- full. */
- SetEvent( pvSendEvent );
-
- /* The buffer has been sent so can be released. */
- if( bReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
-
- return pdPASS;
-}
-/*-----------------------------------------------------------*/
-
-static pcap_if_t * prvPrintAvailableNetworkInterfaces( void )
-{
-pcap_if_t * pxAllNetworkInterfaces = NULL, *xInterface;
-int32_t lInterfaceNumber = 1;
-char cBuffer[ 512 ];
-static BaseType_t xInvalidInterfaceDetected = pdFALSE;
-
- if( xInvalidInterfaceDetected == pdFALSE )
- {
- if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &pxAllNetworkInterfaces, cErrorBuffer ) == -1 )
- {
- printf( "Could not obtain a list of network interfaces\n%s\n", cErrorBuffer );
- pxAllNetworkInterfaces = NULL;
- }
- else
- {
- printf( "\r\n\r\nThe following network interfaces are available:\r\n\r\n" );
- }
-
- if( pxAllNetworkInterfaces != NULL )
- {
- /* Print out the list of network interfaces. The first in the list
- is interface '1', not interface '0'. */
- for( xInterface = pxAllNetworkInterfaces; xInterface != NULL; xInterface = xInterface->next )
- {
- /* The descriptions of the devices can be full of spaces, clean them
- a little. printf() can only be used here because the network is not
- up yet - so no other network tasks will be running. */
- printf( "Interface %d - %s\n", lInterfaceNumber, prvRemoveSpaces( cBuffer, sizeof( cBuffer ), xInterface->name ) );
- printf( " (%s)\n", prvRemoveSpaces(cBuffer, sizeof( cBuffer ), xInterface->description ? xInterface->description : "No description" ) );
- printf( "\n" );
- lInterfaceNumber++;
- }
- }
-
- if( lInterfaceNumber == 1 )
- {
- /* The interface number was never incremented, so the above for() loop
- did not execute meaning no interfaces were found. */
- printf( " \nNo network interfaces were found.\n" );
- pxAllNetworkInterfaces = NULL;
- }
-
- printf( "\r\nThe interface that will be opened is set by " );
- printf( "\"configNETWORK_INTERFACE_TO_USE\", which\r\nshould be defined in FreeRTOSConfig.h\r\n" );
-
- if( ( xConfigNextworkInterfaceToUse < 0L ) || ( xConfigNextworkInterfaceToUse >= lInterfaceNumber ) )
- {
- printf( "\r\nERROR: configNETWORK_INTERFACE_TO_USE is set to %d, which is an invalid value.\r\n", xConfigNextworkInterfaceToUse );
- printf( "Please set configNETWORK_INTERFACE_TO_USE to one of the interface numbers listed above,\r\n" );
- printf( "then re-compile and re-start the application. Only Ethernet (as opposed to WiFi)\r\n" );
- printf( "interfaces are supported.\r\n\r\nHALTING\r\n\r\n\r\n" );
- xInvalidInterfaceDetected = pdTRUE;
-
- if( pxAllNetworkInterfaces != NULL )
- {
- /* Free the device list, as no devices are going to be opened. */
- pcap_freealldevs( pxAllNetworkInterfaces );
- pxAllNetworkInterfaces = NULL;
- }
- }
- else
- {
- printf( "Attempting to open interface number %d.\n", xConfigNextworkInterfaceToUse );
- }
- }
-
- return pxAllNetworkInterfaces;
-}
-/*-----------------------------------------------------------*/
-
-static int prvOpenInterface( const char *pucName )
-{
-static char pucInterfaceName[ 256 ];
-
- if( pucName != NULL )
- {
- strncpy( pucInterfaceName, pucName, sizeof( pucInterfaceName ) );
- }
-
- pxOpenedInterfaceHandle = pcap_open( pucInterfaceName, /* The name of the selected interface. */
- ipTOTAL_ETHERNET_FRAME_SIZE, /* The size of the packet to capture. */
- PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscuous mode as the MAC and
- IP address is going to be "simulated", and
- not be the real MAC and IP address. This allows
- traffic to the simulated IP address to be routed
- to uIP, and traffic to the real IP address to be
- routed to the Windows TCP/IP stack. */
- 100,
- NULL, /* No authentication is required as this is
- not a remote capture session. */
- cErrorBuffer
- );
-
- if ( pxOpenedInterfaceHandle == NULL )
- {
- printf( "\n%s is not supported by WinPcap and cannot be opened\n", pucInterfaceName );
- return 1;
- }
- else
- {
- /* Configure the capture filter to allow blocking reads, and to filter
- out packets that are not of interest to this demo. */
- prvConfigureCaptureBehaviour();
- }
- return 0;
-}
-/*-----------------------------------------------------------*/
-
-static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces )
-{
-pcap_if_t *xInterface;
-int32_t x;
-
- /* Walk the list of devices until the selected device is located. */
- xInterface = pxAllNetworkInterfaces;
- if (0 == xConfigNextworkInterfaceToUse) {
- while (NULL != xInterface) {
- xInterface = xInterface->next;
- if (0 == prvOpenInterface(xInterface->name)) {
- break;
- }
- }
- }
- else {
- for (x = 1L; x < xConfigNextworkInterfaceToUse; x++)
- {
- xInterface = xInterface->next;
- }
- /* Open the selected interface. */
- (void) prvOpenInterface(xInterface->name);
- }
-
- /* The device list is no longer required. */
- pcap_freealldevs( pxAllNetworkInterfaces );
-}
-/*-----------------------------------------------------------*/
-
-static void prvConfigureCaptureBehaviour( void )
-{
-struct bpf_program xFilterCode;
-uint32_t ulNetMask;
-
- /* Set up a filter so only the packets of interest are passed to the IP
- stack. cErrorBuffer is used for convenience to create the string. Don't
- confuse this with an error message. */
- sprintf( cErrorBuffer, "broadcast or multicast or ether host %x:%x:%x:%x:%x:%x",
- ucMACAddress[0], ucMACAddress[1], ucMACAddress[2], ucMACAddress[3], ucMACAddress[4], ucMACAddress[5] );
-
- ulNetMask = ( configNET_MASK3 << 24UL ) | ( configNET_MASK2 << 16UL ) | ( configNET_MASK1 << 8L ) | configNET_MASK0;
-
- if( pcap_compile( pxOpenedInterfaceHandle, &xFilterCode, cErrorBuffer, 1, ulNetMask ) < 0 )
- {
- printf( "\nThe packet filter string is invalid\n" );
- }
- else
- {
- if( pcap_setfilter( pxOpenedInterfaceHandle, &xFilterCode ) < 0 )
- {
- printf( "\nAn error occurred setting the packet filter.\n" );
- }
- }
-
- /* Create the buffers used to pass packets between the FreeRTOS simulator
- and the Win32 threads that are handling WinPCAP. */
- prvCreateThreadSafeBuffers();
-
- if( pvSendEvent == NULL )
- {
- /* Create event used to signal the Win32 WinPCAP Tx thread. */
- pvSendEvent = CreateEvent( NULL, FALSE, TRUE, NULL );
-
- /* Create the Win32 thread that handles WinPCAP Rx. */
- vWinPcapRecvThreadHandle = CreateThread(
- NULL, /* Pointer to thread security attributes. */
- 0, /* Initial thread stack size, in bytes. */
- prvWinPcapRecvThread, /* Pointer to thread function. */
- NULL, /* Argument for new thread. */
- 0, /* Creation flags. */
- NULL );
-
- /* Use the cores that are not used by the FreeRTOS tasks. */
- SetThreadAffinityMask( vWinPcapRecvThreadHandle, ~0x01u );
-
- /* Create the Win32 thread that handlers WinPCAP Tx. */
- vWinPcapSendThreadHandle = CreateThread(
- NULL, /* Pointer to thread security attributes. */
- 0, /* initial thread stack size, in bytes. */
- prvWinPcapSendThread, /* Pointer to thread function. */
- NULL, /* Argument for new thread. */
- 0, /* Creation flags. */
- NULL );
-
- /* Use the cores that are not used by the FreeRTOS tasks. */
- SetThreadAffinityMask( vWinPcapSendThreadHandle, ~0x01u );
-
- /* Create a task that simulates an interrupt in a real system. This will
- block waiting for packets, then send a message to the IP task when data
- is available. */
- xTaskCreate( prvInterruptSimulatorTask, "MAC_ISR", configMINIMAL_STACK_SIZE, NULL, configMAC_ISR_SIMULATOR_PRIORITY, NULL );
- }
-}
-/*-----------------------------------------------------------*/
-
-/* WinPCAP function. */
-void pcap_callback( u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data )
-{
- (void)user;
-
- /* THIS IS CALLED FROM A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS
- OR TO PRINT OUT MESSAGES HERE. */
-
- /* Pass data to the FreeRTOS simulator on a thread safe circular buffer. */
- if( ( pkt_header->caplen <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) &&
- ( uxStreamBufferGetSpace( xRecvBuffer ) >= ( ( ( size_t ) pkt_header->caplen ) + sizeof( *pkt_header ) ) ) )
- {
- uxStreamBufferAdd( xRecvBuffer, 0, ( const uint8_t* ) pkt_header, sizeof( *pkt_header ) );
- uxStreamBufferAdd( xRecvBuffer, 0, ( const uint8_t* ) pkt_data, ( size_t ) pkt_header->caplen );
- }
-}
-/*-----------------------------------------------------------*/
-
-DWORD WINAPI prvWinPcapRecvThread ( void *pvParam )
-{
- ( void ) pvParam;
-
- /* THIS IS A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS OR TO PRINT
- OUT MESSAGES HERE. */
-
- for( ;; )
- {
- pcap_dispatch( pxOpenedInterfaceHandle, 1, pcap_callback, ( u_char * ) "mydata" );
- }
-}
-/*-----------------------------------------------------------*/
-
-DWORD WINAPI prvWinPcapSendThread( void *pvParam )
-{
-size_t xLength;
-uint8_t ucBuffer[ ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ];
-static char cErrorMessage[ 1024 ];
-const DWORD xMaxMSToWait = 1000;
-
- /* THIS IS A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS OR TO PRINT
- OUT MESSAGES HERE. */
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParam;
-
- for( ;; )
- {
- /* Wait until notified of something to send. */
- WaitForSingleObject( pvSendEvent, xMaxMSToWait );
-
- /* Is there more than the length value stored in the circular buffer
- used to pass data from the FreeRTOS simulator into this Win32 thread? */
- while( uxStreamBufferGetSize( xSendBuffer ) > sizeof( xLength ) )
- {
- uxStreamBufferGet( xSendBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
- uxStreamBufferGet( xSendBuffer, 0, ( uint8_t* ) ucBuffer, xLength, pdFALSE );
- if( pcap_sendpacket( pxOpenedInterfaceHandle, ucBuffer, xLength ) != 0 )
- {
- ulWinPCAPSendFailures++;
- }
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvInterruptSimulatorTask( void *pvParameters )
-{
-struct pcap_pkthdr xHeader;
-static struct pcap_pkthdr *pxHeader;
-const uint8_t *pucPacketData;
-uint8_t ucRecvBuffer[ ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ];
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-eFrameProcessingResult_t eResult;
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Does the circular buffer used to pass data from the Win32 thread that
- handles WinPCAP Rx into the FreeRTOS simulator contain another packet? */
- if( uxStreamBufferGetSize( xRecvBuffer ) > sizeof( xHeader ) )
- {
- /* Get the next packet. */
- uxStreamBufferGet( xRecvBuffer, 0, (uint8_t*)&xHeader, sizeof( xHeader ), pdFALSE );
- uxStreamBufferGet( xRecvBuffer, 0, (uint8_t*)ucRecvBuffer, ( size_t ) xHeader.len, pdFALSE );
- pucPacketData = ucRecvBuffer;
- pxHeader = &xHeader;
-
- iptraceNETWORK_INTERFACE_RECEIVE();
-
- /* Check for minimal size. */
- if( pxHeader->len >= sizeof( EthernetHeader_t ) )
- {
- eResult = ipCONSIDER_FRAME_FOR_PROCESSING( pucPacketData );
- }
- else
- {
- eResult = eReleaseBuffer;
- }
-
- if( eResult == eProcessBuffer )
- {
- /* Will the data fit into the frame buffer? */
- if( pxHeader->len <= ipTOTAL_ETHERNET_FRAME_SIZE )
- {
- /* Obtain a buffer into which the data can be placed. This
- is only an interrupt simulator, not a real interrupt, so it
- is ok to call the task level function here, but note that
- some buffer implementations cannot be called from a real
- interrupt. */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( pxHeader->len, 0 );
-
- if( pxNetworkBuffer != NULL )
- {
- memcpy( pxNetworkBuffer->pucEthernetBuffer, pucPacketData, pxHeader->len );
- pxNetworkBuffer->xDataLength = ( size_t ) pxHeader->len;
-
- #if( niDISRUPT_PACKETS == 1 )
- {
- pxNetworkBuffer = vRxFaultInjection( pxNetworkBuffer, pucPacketData );
- }
- #endif /* niDISRUPT_PACKETS */
-
- if( pxNetworkBuffer != NULL )
- {
- xRxEvent.pvData = ( void * ) pxNetworkBuffer;
-
- /* Data was received and stored. Send a message to
- the IP task to let it know. */
- if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 0 ) == pdFAIL )
- {
- /* The buffer could not be sent to the stack so
- must be released again. This is only an
- interrupt simulator, not a real interrupt, so it
- is ok to use the task level function here, but
- note no all buffer implementations will allow
- this function to be executed from a real
- interrupt. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- iptraceETHERNET_RX_EVENT_LOST();
- }
- }
- else
- {
- /* The packet was already released or stored inside
- vRxFaultInjection(). Don't release it here. */
- }
- }
- else
- {
- iptraceETHERNET_RX_EVENT_LOST();
- }
- }
- else
- {
- /* Log that a packet was dropped because it would have
- overflowed the buffer, but there may be more buffers to
- process. */
- }
- }
- }
- else
- {
- /* There is no real way of simulating an interrupt. Make sure
- other tasks can run. */
- vTaskDelay( configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY );
- }
- }
-}
-/*-----------------------------------------------------------*/
-
-static const char *prvRemoveSpaces( char *pcBuffer, int aBuflen, const char *pcMessage )
-{
- char *pcTarget = pcBuffer;
-
- /* Utility function used to formap messages being printed only. */
- while( ( *pcMessage != 0 ) && ( pcTarget < ( pcBuffer + aBuflen - 1 ) ) )
- {
- *( pcTarget++ ) = *pcMessage;
-
- if( isspace( *pcMessage ) != pdFALSE )
- {
- while( isspace( *pcMessage ) != pdFALSE )
- {
- pcMessage++;
- }
- }
- else
- {
- pcMessage++;
- }
- }
-
- *pcTarget = '\0';
-
- return pcBuffer;
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/NetworkInterface.c
deleted file mode 100755
index 9ae46a8..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/NetworkInterface.c
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-
-/* Xilinx library files. */
-#include
-#include "Zynq/x_topology.h"
-#include "Zynq/x_emacpsif.h"
-#include "Zynq/x_emacpsif_hw.h"
-
-/* Provided memory configured as uncached. */
-#include "uncached_memory.h"
-
-#ifndef BMSR_LINK_STATUS
- #define BMSR_LINK_STATUS 0x0004UL
-#endif
-
-#ifndef PHY_LS_HIGH_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still high after 15 seconds of not
- receiving packets. */
- #define PHY_LS_HIGH_CHECK_TIME_MS 15000
-#endif
-
-#ifndef PHY_LS_LOW_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still low every second. */
- #define PHY_LS_LOW_CHECK_TIME_MS 1000
-#endif
-
-/* The size of each buffer when BufferAllocation_1 is used:
-http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html */
-#define niBUFFER_1_PACKET_SIZE 1536
-
-/* Naming and numbering of PHY registers. */
-#define PHY_REG_01_BMSR 0x01 /* Basic mode status register */
-
-#ifndef iptraceEMAC_TASK_STARTING
- #define iptraceEMAC_TASK_STARTING() do { } while( 0 )
-#endif
-
-/* Default the size of the stack used by the EMAC deferred handler task to twice
-the size of the stack used by the idle task - but allow this to be overridden in
-FreeRTOSConfig.h as configMINIMAL_STACK_SIZE is a user definable constant. */
-#ifndef configEMAC_TASK_STACK_SIZE
- #define configEMAC_TASK_STACK_SIZE ( 2 * configMINIMAL_STACK_SIZE )
-#endif
-
-/*-----------------------------------------------------------*/
-
-/*
- * Look for the link to be up every few milliseconds until either xMaxTime time
- * has passed or a link is found.
- */
-static BaseType_t prvGMACWaitLS( TickType_t xMaxTime );
-
-/*
- * A deferred interrupt handler for all MAC/DMA interrupt sources.
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*-----------------------------------------------------------*/
-
-/* EMAC data/descriptions. */
-static xemacpsif_s xEMACpsif;
-struct xtopology_t xXTopology =
-{
- .emac_baseaddr = XPAR_PS7_ETHERNET_0_BASEADDR,
- .emac_type = xemac_type_emacps,
- .intc_baseaddr = 0x0,
- .intc_emac_intr = 0x0,
- .scugic_baseaddr = XPAR_PS7_SCUGIC_0_BASEADDR,
- .scugic_emac_intr = 0x36,
-};
-
-XEmacPs_Config mac_config =
-{
- .DeviceId = XPAR_PS7_ETHERNET_0_DEVICE_ID, /**< Unique ID of device */
- .BaseAddress = XPAR_PS7_ETHERNET_0_BASEADDR /**< Physical base address of IPIF registers */
-};
-
-extern int phy_detected;
-
-/* A copy of PHY register 1: 'PHY_REG_01_BMSR' */
-static uint32_t ulPHYLinkStatus = 0;
-
-#if( ipconfigUSE_LLMNR == 1 )
- static const uint8_t xLLMNR_MACAddress[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
-#endif
-
-/* ucMACAddress as it appears in main.c */
-extern const uint8_t ucMACAddress[ 6 ];
-
-/* Holds the handle of the task used as a deferred interrupt processor. The
-handle is used so direct notifications can be sent to the task for all EMAC/DMA
-related interrupts. */
-TaskHandle_t xEMACTaskHandle = NULL;
-
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-uint32_t ulLinkSpeed, ulDMAReg;
-BaseType_t xStatus, xLinkStatus;
-XEmacPs *pxEMAC_PS;
-const TickType_t xWaitLinkDelay = pdMS_TO_TICKS( 7000UL ), xWaitRelinkDelay = pdMS_TO_TICKS( 1000UL );
-
- /* Guard against the init function being called more than once. */
- if( xEMACTaskHandle == NULL )
- {
- pxEMAC_PS = &( xEMACpsif.emacps );
- memset( &xEMACpsif, '\0', sizeof( xEMACpsif ) );
-
- xStatus = XEmacPs_CfgInitialize( pxEMAC_PS, &mac_config, mac_config.BaseAddress);
- if( xStatus != XST_SUCCESS )
- {
- FreeRTOS_printf( ( "xEMACInit: EmacPs Configuration Failed....\n" ) );
- }
-
- /* Initialize the mac and set the MAC address. */
- XEmacPs_SetMacAddress( pxEMAC_PS, ( void * ) ucMACAddress, 1 );
-
- #if( ipconfigUSE_LLMNR == 1 )
- {
- /* Also add LLMNR multicast MAC address. */
- XEmacPs_SetMacAddress( pxEMAC_PS, ( void * )xLLMNR_MACAddress, 2 );
- }
- #endif /* ipconfigUSE_LLMNR == 1 */
-
- XEmacPs_SetMdioDivisor( pxEMAC_PS, MDC_DIV_224 );
- ulLinkSpeed = Phy_Setup( pxEMAC_PS );
- XEmacPs_SetOperatingSpeed( pxEMAC_PS, ulLinkSpeed);
-
- /* Setting the operating speed of the MAC needs a delay. */
- vTaskDelay( pdMS_TO_TICKS( 25UL ) );
-
- ulDMAReg = XEmacPs_ReadReg( pxEMAC_PS->Config.BaseAddress, XEMACPS_DMACR_OFFSET);
-
- /* DISC_WHEN_NO_AHB: when set, the GEM DMA will automatically discard receive
- packets from the receiver packet buffer memory when no AHB resource is available. */
- XEmacPs_WriteReg( pxEMAC_PS->Config.BaseAddress, XEMACPS_DMACR_OFFSET,
- ulDMAReg | XEMACPS_DMACR_DISC_WHEN_NO_AHB_MASK);
-
- setup_isr( &xEMACpsif );
- init_dma( &xEMACpsif );
- start_emacps( &xEMACpsif );
-
- prvGMACWaitLS( xWaitLinkDelay );
-
- /* The deferred interrupt handler task is created at the highest
- possible priority to ensure the interrupt handler can return directly
- to it. The task's handle is stored in xEMACTaskHandle so interrupts can
- notify the task when there is something to process. */
- xTaskCreate( prvEMACHandlerTask, "EMAC", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
- }
- else
- {
- /* Initialisation was already performed, just wait for the link. */
- prvGMACWaitLS( xWaitRelinkDelay );
- }
-
- /* Only return pdTRUE when the Link Status of the PHY is high, otherwise the
- DHCP process and all other communication will fail. */
- xLinkStatus = xGetPhyLinkStatus();
-
- return ( xLinkStatus != pdFALSE );
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxBuffer, BaseType_t bReleaseAfterSend )
-{
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- iptraceNETWORK_INTERFACE_TRANSMIT();
- emacps_send_message( &xEMACpsif, pxBuffer, bReleaseAfterSend );
- }
- else if( bReleaseAfterSend != pdFALSE )
- {
- /* No link. */
- vReleaseNetworkBufferAndDescriptor( pxBuffer );
- }
-
- return pdTRUE;
-}
-/*-----------------------------------------------------------*/
-
-static inline unsigned long ulReadMDIO( unsigned ulRegister )
-{
-uint16_t usValue;
-
- XEmacPs_PhyRead( &( xEMACpsif.emacps ), phy_detected, ulRegister, &usValue );
- return usValue;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t prvGMACWaitLS( TickType_t xMaxTime )
-{
-TickType_t xStartTime, xEndTime;
-const TickType_t xShortDelay = pdMS_TO_TICKS( 20UL );
-BaseType_t xReturn;
-
- xStartTime = xTaskGetTickCount();
-
- for( ;; )
- {
- xEndTime = xTaskGetTickCount();
-
- if( xEndTime - xStartTime > xMaxTime )
- {
- xReturn = pdFALSE;
- break;
- }
- ulPHYLinkStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xReturn = pdTRUE;
- break;
- }
-
- vTaskDelay( xShortDelay );
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
-{
-static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__ ( ( aligned( 32 ) ) );
-uint8_t *ucRAMBuffer = ucNetworkPackets;
-uint32_t ul;
-
- for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ )
- {
- pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING;
- *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
- ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
- }
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xReturn;
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) == 0 )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-TimeOut_t xPhyTime;
-TickType_t xPhyRemTime;
-UBaseType_t uxLastMinBufferCount = 0;
-UBaseType_t uxCurrentCount;
-BaseType_t xResult = 0;
-uint32_t xStatus;
-const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100UL );
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* A possibility to set some additional task properties like calling
- portTASK_USES_FLOATING_POINT() */
- iptraceEMAC_TASK_STARTING();
-
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
-
- for( ;; )
- {
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- static UBaseType_t uxLastMinQueueSpace = 0;
-
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- if( ( xEMACpsif.isr_events & EMAC_IF_ALL_EVENT ) == 0 )
- {
- /* No events to process now, wait for the next. */
- ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
- }
-
- if( ( xEMACpsif.isr_events & EMAC_IF_RX_EVENT ) != 0 )
- {
- xEMACpsif.isr_events &= ~EMAC_IF_RX_EVENT;
- xResult = emacps_check_rx( &xEMACpsif );
- }
-
- if( ( xEMACpsif.isr_events & EMAC_IF_TX_EVENT ) != 0 )
- {
- xEMACpsif.isr_events &= ~EMAC_IF_TX_EVENT;
- emacps_check_tx( &xEMACpsif );
- }
-
- if( ( xEMACpsif.isr_events & EMAC_IF_ERR_EVENT ) != 0 )
- {
- xEMACpsif.isr_events &= ~EMAC_IF_ERR_EVENT;
- emacps_check_errors( &xEMACpsif );
- }
-
- if( xResult > 0 )
- {
- /* A packet was received. No need to check for the PHY status now,
- but set a timer to check it later on. */
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- xResult = 0;
- }
- else if( xTaskCheckForTimeOut( &xPhyTime, &xPhyRemTime ) != pdFALSE )
- {
- xStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != ( xStatus & BMSR_LINK_STATUS ) )
- {
- ulPHYLinkStatus = xStatus;
- FreeRTOS_printf( ( "prvEMACHandlerTask: PHY LS now %d\n", ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 ) );
- }
-
- vTaskSetTimeOutState( &xPhyTime );
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- }
- else
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
- }
- }
- }
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/README.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/README.txt
deleted file mode 100755
index f9e54bb..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/README.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-NetworkInterface for Xilinx' Zynq
-
-Please include the following source files:
-
- $(PLUS_TCP_PATH)/portable/NetworkInterface/Zynq/NetworkInterface.c
- $(PLUS_TCP_PATH)/portable/NetworkInterface/Zynq/x_emacpsif_dma.c
- $(PLUS_TCP_PATH)/portable/NetworkInterface/Zynq/x_emacpsif_physpeed.c
- $(PLUS_TCP_PATH)/portable/NetworkInterface/Zynq/x_emacpsif_hw.c
-
-And include the following source files from the Xilinx library:
-
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps.c
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_control.c
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_g.c
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_intr.c
-
- E.g. ps7_cortexa9_0/libsrc/emacps_v2_0/src/xemacps_intr.c
-
-The following source files are NOT used for the FreeRTOS+TCP interface:
-
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_bdring.c
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_hw.c
- $(CPU_PATH)/$(PROCESSOR)/libsrc/emacps_v2_0/src/xemacps_sinit.c
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c
deleted file mode 100755
index 1b55a9d..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c
+++ /dev/null
@@ -1,119 +0,0 @@
-#warning Temoporary file and a dependent on the Zynq network interface.
-
-/*
- * uncached_memory.c
- *
- * This module will declare 1 MB of memory and switch off the caching for it.
- *
- * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length
- * rounded up to a multiple of 4 KB
- *
- * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT
- * within the range of the 1 MB non-cached memory.
- *
- */
-
-/*
- * After "_end", 1 MB of uncached memory will be allocated for DMA transfers.
- * Both the DMA descriptors as well as all EMAC TX-buffers will be allocated in
- * uncached memory.
- */
-
-#include "Zynq/x_emacpsif.h"
-#include "Zynq/x_topology.h"
-#include "xstatus.h"
-
-#include "xparameters.h"
-#include "xparameters_ps.h"
-#include "xil_exception.h"
-#include "xil_mmu.h"
-
-#include "FreeRTOS.h"
-
-#include "uncached_memory.h"
-
-#include "Demo_Logging.h"
-
-#define UNCACHED_MEMORY_SIZE 0x100000ul
-
-#define DDR_MEMORY_END (XPAR_PS7_DDR_0_S_AXI_HIGHADDR+1)
-
-static void vInitialiseUncachedMemory( void );
-
-static uint8_t *pucHeadOfMemory;
-static uint32_t ulMemorySize;
-static uint8_t *pucStartOfMemory = NULL;
-
-uint8_t ucIsCachedMemory( const uint8_t *pucBuffer )
-{
-uint8_t ucReturn;
-
- if( ( pucStartOfMemory != NULL ) &&
- ( pucBuffer >= pucStartOfMemory ) &&
- ( pucBuffer < ( pucStartOfMemory + UNCACHED_MEMORY_SIZE ) ) )
- {
- ucReturn = pdFALSE;
- }
- else
- {
- ucReturn = pdTRUE;
- }
-
- return ucReturn;
-}
-
-uint8_t *pucGetUncachedMemory( uint32_t ulSize )
-{
-uint8_t *pucReturn;
-
- if( pucStartOfMemory == NULL )
- {
- vInitialiseUncachedMemory( );
- }
- if( ( pucStartOfMemory == NULL ) || ( ulSize > ulMemorySize ) )
- {
- pucReturn = NULL;
- }
- else
- {
- uint32_t ulSkipSize;
-
- pucReturn = pucHeadOfMemory;
- ulSkipSize = ( ulSize + 0x1000ul ) & ~0xffful;
- pucHeadOfMemory += ulSkipSize;
- ulMemorySize -= ulSkipSize;
- }
-
- return pucReturn;
-}
-
-extern u8 _end;
-
-static void vInitialiseUncachedMemory( )
-{
- /* At the end of program's space... */
- pucStartOfMemory = (uint8_t *) &_end;
- /*
- * Align the start address to 1 MB boundary.
- */
- pucStartOfMemory = (uint8_t *)( ( ( uint32_t )pucStartOfMemory + UNCACHED_MEMORY_SIZE ) & ( ~( UNCACHED_MEMORY_SIZE - 1 ) ) );
-
- if( ( ( u32 )pucStartOfMemory ) + UNCACHED_MEMORY_SIZE > DDR_MEMORY_END )
- {
- vLoggingPrintf("vInitialiseUncachedMemory: Can not allocate uncached memory\n" );
- }
- else
- {
- /*
- * Some objects want to be stored in uncached memory. Hence the 1 MB
- * address range that starts after "_end" is made uncached
- * by setting appropriate attributes in the translation table.
- */
- Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0xc02 ); // addr, attr
-
- /* For experiments in the SDIO driver, make the remaining uncached memory public */
- pucHeadOfMemory = pucStartOfMemory;
- ulMemorySize = UNCACHED_MEMORY_SIZE;
- memset( pucStartOfMemory, '\0', UNCACHED_MEMORY_SIZE );
- }
-}
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.h
deleted file mode 100755
index 2b8b3b1..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * uncached_memory.h
- *
- * This module will declare 1 MB of memory and switch off the caching for it.
- *
- * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length
- * rounded up to a multiple of 4 KB
- *
- * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT
- * within the range of the 1 MB non-cached memory.
- *
- */
-
-#ifndef UNCACHEMEMORY_H
-
-#define UNCACHEMEMORY_H
-
-uint8_t *pucGetUncachedMemory( uint32_t ulSize );
-
-uint8_t ucIsCachedMemory( const uint8_t *pucBuffer );
-
-#endif /* UNCACHEMEMORY_H */
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif.h
deleted file mode 100755
index 2f1b0df..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (c) 2010-2013 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-#ifndef __NETIF_XEMACPSIF_H__
-#define __NETIF_XEMACPSIF_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#include "xstatus.h"
-#include "sleep.h"
-#include "xparameters.h"
-#include "xparameters_ps.h" /* defines XPAR values */
-#include "xil_types.h"
-#include "xil_assert.h"
-#include "xil_io.h"
-#include "xil_exception.h"
-#include "xpseudo_asm.h"
-#include "xil_cache.h"
-#include "xil_printf.h"
-#include "xuartps.h"
-#include "xscugic.h"
-#include "xemacps.h" /* defines XEmacPs API */
-
-//#include "netif/xpqueue.h"
-//#include "xlwipconfig.h"
-
-void xemacpsif_setmac(uint32_t index, uint8_t *addr);
-uint8_t* xemacpsif_getmac(uint32_t index);
-//int xemacpsif_init(struct netif *netif);
-//int xemacpsif_input(struct netif *netif);
-#ifdef NOTNOW_BHILL
-unsigned get_IEEE_phy_speed(XLlTemac *xlltemacp);
-#endif
-
-/* xaxiemacif_hw.c */
-void xemacps_error_handler(XEmacPs * Temac);
-
-struct xBD_TYPE {
- uint32_t address;
- uint32_t flags;
-};
-
-/*
- * Missing declaration in 'src/xemacps_hw.h' :
- * When set, the GEM DMA will automatically
- * discard receive packets from the receiver packet
- * buffer memory when no AHB resource is
- * available.
- * When low, then received packets will remain to be
- * stored in the SRAM based packet buffer until
- * AHB buffer resource next becomes available.
- */
-#define XEMACPS_DMACR_DISC_WHEN_NO_AHB_MASK 0x01000000
-
-#define EMAC_IF_RX_EVENT 1
-#define EMAC_IF_TX_EVENT 2
-#define EMAC_IF_ERR_EVENT 4
-#define EMAC_IF_ALL_EVENT 7
-
-/* structure within each netif, encapsulating all information required for
- * using a particular temac instance
- */
-typedef struct {
- XEmacPs emacps;
-
- /* pointers to memory holding buffer descriptors (used only with SDMA) */
- struct xBD_TYPE *rxSegments;
- struct xBD_TYPE *txSegments;
-
- unsigned char *tx_space;
- unsigned uTxUnitSize;
-
- char *remain_mem;
- unsigned remain_siz;
-
- volatile int rxHead, rxTail;
- volatile int txHead, txTail;
-
- volatile int txBusy;
-
- volatile uint32_t isr_events;
-
- unsigned int last_rx_frms_cntr;
-
-} xemacpsif_s;
-
-//extern xemacpsif_s xemacpsif;
-
-int is_tx_space_available(xemacpsif_s *emac);
-
-/* xaxiemacif_dma.c */
-
-struct xNETWORK_BUFFER;
-
-int emacps_check_rx( xemacpsif_s *xemacpsif );
-void emacps_check_tx( xemacpsif_s *xemacpsif );
-int emacps_check_errors( xemacpsif_s *xemacps );
-void emacps_set_rx_buffers( xemacpsif_s *xemacpsif, u32 ulCount );
-
-extern XStatus emacps_send_message(xemacpsif_s *xemacpsif, struct xNETWORK_BUFFER *pxBuffer, int iReleaseAfterSend );
-extern unsigned Phy_Setup( XEmacPs *xemacpsp );
-extern void setup_isr( xemacpsif_s *xemacpsif );
-extern XStatus init_dma( xemacpsif_s *xemacpsif );
-extern void start_emacps( xemacpsif_s *xemacpsif );
-
-void EmacEnableIntr(void);
-void EmacDisableIntr(void);
-
-XStatus init_axi_dma(xemacpsif_s *xemacpsif);
-void process_sent_bds( xemacpsif_s *xemacpsif );
-
-void emacps_send_handler(void *arg);
-void emacps_recv_handler(void *arg);
-void emacps_error_handler(void *arg,u8 Direction, u32 ErrorWord);
-void HandleTxErrors(xemacpsif_s *xemacpsif);
-XEmacPs_Config *xemacps_lookup_config(unsigned mac_base);
-
-void clean_dma_txdescs(xemacpsif_s *xemacpsif);
-void resetrx_on_no_rxdata(xemacpsif_s *xemacpsif);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __NETIF_XAXIEMACIF_H__ */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_dma.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_dma.c
deleted file mode 100755
index c813989..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_dma.c
+++ /dev/null
@@ -1,625 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-#include "Zynq/x_emacpsif.h"
-#include "Zynq/x_topology.h"
-#include "xstatus.h"
-
-#include "xparameters.h"
-#include "xparameters_ps.h"
-#include "xil_exception.h"
-#include "xil_mmu.h"
-
-#include "FreeRTOS.h"
-#include "task.h"
-#include "timers.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-
-#include "uncached_memory.h"
-
-/* Two defines used to set or clear the EMAC interrupt */
-#define INTC_BASE_ADDR XPAR_SCUGIC_CPU_BASEADDR
-#define INTC_DIST_BASE_ADDR XPAR_SCUGIC_DIST_BASEADDR
-
-
-
-#if( ipconfigPACKET_FILLER_SIZE != 2 )
- #error Please define ipconfigPACKET_FILLER_SIZE as the value '2'
-#endif
-#define TX_OFFSET ipconfigPACKET_FILLER_SIZE
-
-/* Defined in NetworkInterface.c */
-extern TaskHandle_t xEMACTaskHandle;
-
-/*
- pxDMA_tx_buffers: these are character arrays, each one is big enough to hold 1 MTU.
- The actual TX buffers are located in uncached RAM.
-*/
-static unsigned char *pxDMA_tx_buffers[ ipconfigNIC_N_TX_DESC ] = { NULL };
-
-/*
- pxDMA_rx_buffers: these are pointers to 'NetworkBufferDescriptor_t'.
- Once a message has been received by the EMAC, the descriptor can be passed
- immediately to the IP-task.
-*/
-static NetworkBufferDescriptor_t *pxDMA_rx_buffers[ ipconfigNIC_N_RX_DESC ] = { NULL };
-
-/*
- The FreeRTOS+TCP port is using a fixed 'topology', which is declared in
- ./portable/NetworkInterface/Zynq/NetworkInterface.c
-*/
-extern struct xtopology_t xXTopology;
-
-static SemaphoreHandle_t xTXDescriptorSemaphore = NULL;
-
-/*
- The FreeRTOS+TCP port does not make use of "src/xemacps_bdring.c".
- In stead 'struct xemacpsif_s' has a "head" and a "tail" index.
- "head" is the next index to be written, used.
- "tail" is the next index to be read, freed.
-*/
-
-int is_tx_space_available( xemacpsif_s *xemacpsif )
-{
-size_t uxCount;
-
- if( xTXDescriptorSemaphore != NULL )
- {
- uxCount = ( ( UBaseType_t ) ipconfigNIC_N_TX_DESC ) - uxSemaphoreGetCount( xTXDescriptorSemaphore );
- }
- else
- {
- uxCount = ( UBaseType_t ) 0u;
- }
-
- return uxCount;
-}
-
-void emacps_check_tx( xemacpsif_s *xemacpsif )
-{
-int tail = xemacpsif->txTail;
-int head = xemacpsif->txHead;
-size_t uxCount = ( ( UBaseType_t ) ipconfigNIC_N_TX_DESC ) - uxSemaphoreGetCount( xTXDescriptorSemaphore );
-
- /* uxCount is the number of TX descriptors that are in use by the DMA. */
- /* When done, "TXBUF_USED" will be set. */
-
- while( ( uxCount > 0 ) && ( ( xemacpsif->txSegments[ tail ].flags & XEMACPS_TXBUF_USED_MASK ) != 0 ) )
- {
- if( ( tail == head ) && ( uxCount != ipconfigNIC_N_TX_DESC ) )
- {
- break;
- }
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
-#warning ipconfigZERO_COPY_TX_DRIVER is defined
- {
- void *pvBuffer = pxDMA_tx_buffers[ tail ];
- NetworkBufferDescriptor_t *pxBuffer;
-
- if( pvBuffer != NULL )
- {
- pxDMA_tx_buffers[ tail ] = NULL;
- pxBuffer = pxPacketBuffer_to_NetworkBuffer( pvBuffer );
- if( pxBuffer != NULL )
- {
- vReleaseNetworkBufferAndDescriptor( pxBuffer );
- }
- else
- {
- FreeRTOS_printf( ( "emacps_check_tx: Can not find network buffer\n" ) );
- }
- }
- }
-#endif
- /* Clear all but the "used" and "wrap" bits. */
- if( tail < ipconfigNIC_N_TX_DESC - 1 )
- {
- xemacpsif->txSegments[ tail ].flags = XEMACPS_TXBUF_USED_MASK;
- }
- else
- {
- xemacpsif->txSegments[ tail ].flags = XEMACPS_TXBUF_USED_MASK | XEMACPS_TXBUF_WRAP_MASK;
- }
- uxCount--;
- /* Tell the counting semaphore that one more TX descriptor is available. */
- xSemaphoreGive( xTXDescriptorSemaphore );
- if( ++tail == ipconfigNIC_N_TX_DESC )
- {
- tail = 0;
- }
- xemacpsif->txTail = tail;
- }
-
- return;
-}
-
-void emacps_send_handler(void *arg)
-{
-xemacpsif_s *xemacpsif;
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- xemacpsif = (xemacpsif_s *)(arg);
-
- /* In this port for FreeRTOS+TCP, the EMAC interrupts will only set a bit in
- "isr_events". The task in NetworkInterface will wake-up and do the necessary work.
- */
- xemacpsif->isr_events |= EMAC_IF_TX_EVENT;
- xemacpsif->txBusy = pdFALSE;
-
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- }
-
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
-}
-
-static BaseType_t xValidLength( BaseType_t xLength )
-{
-BaseType_t xReturn;
-
- if( ( xLength >= ( BaseType_t ) sizeof( struct xARP_PACKET ) ) && ( ( ( uint32_t ) xLength ) <= ipTOTAL_ETHERNET_FRAME_SIZE ) )
- {
- xReturn = pdTRUE;
- }
- else
- {
- xReturn = pdFALSE;
- }
-
- return xReturn;
-}
-
-XStatus emacps_send_message(xemacpsif_s *xemacpsif, NetworkBufferDescriptor_t *pxBuffer, int iReleaseAfterSend )
-{
-int head = xemacpsif->txHead;
-int tail = xemacpsif->txTail;
-int iHasSent = 0;
-uint32_t ulBaseAddress = xemacpsif->emacps.Config.BaseAddress;
-TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 5000u );
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- {
- /* This driver wants to own all network buffers which are to be transmitted. */
- configASSERT( iReleaseAfterSend != pdFALSE );
- }
- #endif
-
- /* Open a do {} while ( 0 ) loop to be able to call break. */
- do
- {
- uint32_t ulFlags = 0;
-
- if( xValidLength( pxBuffer->xDataLength ) != pdTRUE )
- {
- break;
- }
-
- if( xTXDescriptorSemaphore == NULL )
- {
- break;
- }
-
- if( xSemaphoreTake( xTXDescriptorSemaphore, xBlockTimeTicks ) != pdPASS )
- {
- FreeRTOS_printf( ( "emacps_send_message: Time-out waiting for TX buffer\n" ) );
- break;
- }
-
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- /* Pass the pointer (and its ownership) directly to DMA. */
- pxDMA_tx_buffers[ head ] = pxBuffer->pucEthernetBuffer;
- if( ucIsCachedMemory( pxBuffer->pucEthernetBuffer ) != 0 )
- {
- Xil_DCacheFlushRange( ( unsigned )pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength );
- }
- /* Buffer has been transferred, do not release it. */
- iReleaseAfterSend = pdFALSE;
-#else
- if( pxDMA_tx_buffers[ head ] == NULL )
- {
- FreeRTOS_printf( ( "emacps_send_message: pxDMA_tx_buffers[ %d ] == NULL\n", head ) );
- break;
- }
- /* Copy the message to unbuffered space in RAM. */
- memcpy( pxDMA_tx_buffers[ head ], pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength );
-#endif
- /* Packets will be sent one-by-one, so for each packet
- the TXBUF_LAST bit will be set. */
- ulFlags |= XEMACPS_TXBUF_LAST_MASK;
- ulFlags |= ( pxBuffer->xDataLength & XEMACPS_TXBUF_LEN_MASK );
- if( head == ( ipconfigNIC_N_TX_DESC - 1 ) )
- {
- ulFlags |= XEMACPS_TXBUF_WRAP_MASK;
- }
-
- /* Copy the address of the buffer and set the flags. */
- xemacpsif->txSegments[ head ].address = ( uint32_t )pxDMA_tx_buffers[ head ];
- xemacpsif->txSegments[ head ].flags = ulFlags;
-
- iHasSent = pdTRUE;
- if( ++head == ipconfigNIC_N_TX_DESC )
- {
- head = 0;
- }
- /* Update the TX-head index. These variable are declared volatile so they will be
- accessed as little as possible. */
- xemacpsif->txHead = head;
- } while( pdFALSE );
-
- if( iReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxBuffer );
- pxBuffer = NULL;
- }
-
- /* Data Synchronization Barrier */
- dsb();
-
- if( iHasSent != pdFALSE )
- {
- /* Make STARTTX high */
- uint32_t ulValue = XEmacPs_ReadReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET);
- /* Start transmit */
- xemacpsif->txBusy = pdTRUE;
- XEmacPs_WriteReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET, ( ulValue | XEMACPS_NWCTRL_STARTTX_MASK ) );
- }
- dsb();
-
- return 0;
-}
-
-void emacps_recv_handler(void *arg)
-{
- xemacpsif_s *xemacpsif;
- BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- xemacpsif = (xemacpsif_s *)(arg);
- xemacpsif->isr_events |= EMAC_IF_RX_EVENT;
-
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- }
-
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
-}
-
-static NetworkBufferDescriptor_t *ethMsg = NULL;
-static NetworkBufferDescriptor_t *ethLast = NULL;
-
-static void passEthMessages( void )
-{
-IPStackEvent_t xRxEvent;
-
- xRxEvent.eEventType = eNetworkRxEvent;
- xRxEvent.pvData = ( void * ) ethMsg;
-
- if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 1000 ) != pdPASS )
- {
- /* The buffer could not be sent to the stack so must be released again.
- This is a deferred handler taskr, not a real interrupt, so it is ok to
- use the task level function here. */
- do
- {
- NetworkBufferDescriptor_t *xNext = ethMsg->pxNextBuffer;
- vReleaseNetworkBufferAndDescriptor( ethMsg );
- ethMsg = xNext;
- } while( ethMsg != NULL );
-
- iptraceETHERNET_RX_EVENT_LOST();
- FreeRTOS_printf( ( "passEthMessages: Can not queue return packet!\n" ) );
- }
-
- ethMsg = ethLast = NULL;
-}
-
-int emacps_check_rx( xemacpsif_s *xemacpsif )
-{
-NetworkBufferDescriptor_t *pxBuffer, *pxNewBuffer;
-int rx_bytes;
-volatile int msgCount = 0;
-int head = xemacpsif->rxHead;
-
- /* There seems to be an issue (SI# 692601), see comments below. */
- resetrx_on_no_rxdata(xemacpsif);
-
- /* This FreeRTOS+TCP driver shall be compiled with the option
- "ipconfigUSE_LINKED_RX_MESSAGES" enabled. It allows the driver to send a
- chain of RX messages within one message to the IP-task. */
- for( ;; )
- {
- if( ( ( xemacpsif->rxSegments[ head ].address & XEMACPS_RXBUF_NEW_MASK ) == 0 ) ||
- ( pxDMA_rx_buffers[ head ] == NULL ) )
- {
- break;
- }
-
- pxNewBuffer = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, ( TickType_t ) 0 );
- if( pxNewBuffer == NULL )
- {
- /* A packet has been received, but there is no replacement for this Network Buffer.
- The packet will be dropped, and it Network Buffer will stay in place. */
- FreeRTOS_printf( ("emacps_check_rx: unable to allocate a Netwrok Buffer\n" ) );
- pxNewBuffer = ( NetworkBufferDescriptor_t * )pxDMA_rx_buffers[ head ];
- }
- else
- {
- pxBuffer = ( NetworkBufferDescriptor_t * )pxDMA_rx_buffers[ head ];
-
- /* Just avoiding to use or refer to the same buffer again */
- pxDMA_rx_buffers[ head ] = pxNewBuffer;
-
- /*
- * Adjust the buffer size to the actual number of bytes received.
- */
- rx_bytes = xemacpsif->rxSegments[ head ].flags & XEMACPS_RXBUF_LEN_MASK;
-
- pxBuffer->xDataLength = rx_bytes;
-
- if( ucIsCachedMemory( pxBuffer->pucEthernetBuffer ) != 0 )
- {
- Xil_DCacheInvalidateRange( ( ( uint32_t )pxBuffer->pucEthernetBuffer ) - ipconfigPACKET_FILLER_SIZE, (unsigned)rx_bytes );
- }
-
- /* store it in the receive queue, where it'll be processed by a
- different handler. */
- iptraceNETWORK_INTERFACE_RECEIVE();
- pxBuffer->pxNextBuffer = NULL;
-
- if( ethMsg == NULL )
- {
- // Becomes the first message
- ethMsg = pxBuffer;
- }
- else if( ethLast != NULL )
- {
- // Add to the tail
- ethLast->pxNextBuffer = pxBuffer;
- }
-
- ethLast = pxBuffer;
- msgCount++;
- }
- {
- if( ucIsCachedMemory( pxNewBuffer->pucEthernetBuffer ) != 0 )
- {
- Xil_DCacheInvalidateRange( ( ( uint32_t )pxNewBuffer->pucEthernetBuffer ) - ipconfigPACKET_FILLER_SIZE, (unsigned)ipTOTAL_ETHERNET_FRAME_SIZE );
- }
- {
- uint32_t addr = ( ( uint32_t )pxNewBuffer->pucEthernetBuffer ) & XEMACPS_RXBUF_ADD_MASK;
- if( head == ( ipconfigNIC_N_RX_DESC - 1 ) )
- {
- addr |= XEMACPS_RXBUF_WRAP_MASK;
- }
- /* Clearing 'XEMACPS_RXBUF_NEW_MASK' 0x00000001 *< Used bit.. */
- xemacpsif->rxSegments[ head ].address = addr;
- xemacpsif->rxSegments[ head ].flags = 0;
- }
- }
-
- if( ++head == ipconfigNIC_N_RX_DESC )
- {
- head = 0;
- }
- xemacpsif->rxHead = head;
- }
-
- if( ethMsg != NULL )
- {
- passEthMessages( );
- }
-
- return msgCount;
-}
-
-void clean_dma_txdescs(xemacpsif_s *xemacpsif)
-{
-int index;
-unsigned char *ucTxBuffer;
-
- /* Clear all TX descriptors and assign uncached memory to each descriptor.
- "tx_space" points to the first available TX buffer. */
- ucTxBuffer = xemacpsif->tx_space;
-
- for( index = 0; index < ipconfigNIC_N_TX_DESC; index++ )
- {
- xemacpsif->txSegments[ index ].address = ( uint32_t )ucTxBuffer;
- xemacpsif->txSegments[ index ].flags = XEMACPS_TXBUF_USED_MASK;
-#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
- pxDMA_tx_buffers[ index ] = ( void* )NULL;
-#else
- pxDMA_tx_buffers[ index ] = ( void* )( ucTxBuffer + TX_OFFSET );
-#endif
- ucTxBuffer += xemacpsif->uTxUnitSize;
- }
- xemacpsif->txSegments[ ipconfigNIC_N_TX_DESC - 1 ].flags =
- XEMACPS_TXBUF_USED_MASK | XEMACPS_TXBUF_WRAP_MASK;
-}
-
-XStatus init_dma(xemacpsif_s *xemacpsif)
-{
- NetworkBufferDescriptor_t *pxBuffer;
-
- int iIndex;
- UBaseType_t xRxSize;
- UBaseType_t xTxSize;
- struct xtopology_t *xtopologyp = &xXTopology;
-
- xRxSize = ipconfigNIC_N_RX_DESC * sizeof( xemacpsif->rxSegments[ 0 ] );
-
- xTxSize = ipconfigNIC_N_TX_DESC * sizeof( xemacpsif->txSegments[ 0 ] );
-
- /* Also round-up to 4KB */
- xemacpsif->uTxUnitSize = ( ipTOTAL_ETHERNET_FRAME_SIZE + 0x1000ul ) & ~0xffful;
- /*
- * We allocate 65536 bytes for RX BDs which can accommodate a
- * maximum of 8192 BDs which is much more than any application
- * will ever need.
- */
- xemacpsif->rxSegments = ( struct xBD_TYPE * )( pucGetUncachedMemory ( xRxSize ) );
- xemacpsif->txSegments = ( struct xBD_TYPE * )( pucGetUncachedMemory ( xTxSize ) );
- xemacpsif->tx_space = ( unsigned char * )( pucGetUncachedMemory ( ipconfigNIC_N_TX_DESC * xemacpsif->uTxUnitSize ) );
-
- /* These variables will be used in XEmacPs_Start (see src/xemacps.c). */
- xemacpsif->emacps.RxBdRing.BaseBdAddr = ( uint32_t ) xemacpsif->rxSegments;
- xemacpsif->emacps.TxBdRing.BaseBdAddr = ( uint32_t ) xemacpsif->txSegments;
-
- if( xTXDescriptorSemaphore == NULL )
- {
- xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNIC_N_TX_DESC, ( UBaseType_t ) ipconfigNIC_N_TX_DESC );
- configASSERT( xTXDescriptorSemaphore );
- }
- /*
- * Allocate RX descriptors, 1 RxBD at a time.
- */
- for( iIndex = 0; iIndex < ipconfigNIC_N_RX_DESC; iIndex++ )
- {
- pxBuffer = pxDMA_rx_buffers[ iIndex ];
- if( pxBuffer == NULL )
- {
- pxBuffer = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, ( TickType_t ) 0 );
- if( pxBuffer == NULL )
- {
- FreeRTOS_printf( ("Unable to allocate a network buffer in recv_handler\n" ) );
- return -1;
- }
- }
-
- xemacpsif->rxSegments[ iIndex ].flags = 0;
- xemacpsif->rxSegments[ iIndex ].address = ( ( uint32_t )pxBuffer->pucEthernetBuffer ) & XEMACPS_RXBUF_ADD_MASK;
-
- pxDMA_rx_buffers[ iIndex ] = pxBuffer;
- /* Make sure this memory is not in cache for now. */
- if( ucIsCachedMemory( pxBuffer->pucEthernetBuffer ) != 0 )
- {
- Xil_DCacheInvalidateRange( ( ( uint32_t )pxBuffer->pucEthernetBuffer ) - ipconfigPACKET_FILLER_SIZE,
- (unsigned)ipTOTAL_ETHERNET_FRAME_SIZE );
- }
- }
-
- xemacpsif->rxSegments[ ipconfigNIC_N_RX_DESC - 1 ].address |= XEMACPS_RXBUF_WRAP_MASK;
-
- memset( xemacpsif->tx_space, '\0', ipconfigNIC_N_TX_DESC * xemacpsif->uTxUnitSize );
-
- clean_dma_txdescs( xemacpsif );
-
- {
- uint32_t value;
- value = XEmacPs_ReadReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_DMACR_OFFSET );
-
- // 1xxxx: Attempt to use INCR16 AHB bursts
- value = ( value & ~( XEMACPS_DMACR_BLENGTH_MASK ) ) | XEMACPS_DMACR_INCR16_AHB_BURST;
-#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
- value |= XEMACPS_DMACR_TCPCKSUM_MASK;
-#else
-#warning Are you sure the EMAC should not calculate outgoing checksums?
- value &= ~XEMACPS_DMACR_TCPCKSUM_MASK;
-#endif
- XEmacPs_WriteReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_DMACR_OFFSET, value );
- }
- {
- uint32_t value;
- value = XEmacPs_ReadReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_NWCFG_OFFSET );
-
- /* Network buffers are 32-bit aligned + 2 bytes (because ipconfigPACKET_FILLER_SIZE = 2 ).
- Now tell the EMAC that received messages should be stored at "address + 2". */
- value = ( value & ~XEMACPS_NWCFG_RXOFFS_MASK ) | 0x8000;
-
-#if( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM != 0 )
- value |= XEMACPS_NWCFG_RXCHKSUMEN_MASK;
-#else
-#warning Are you sure the EMAC should not calculate incoming checksums?
- value &= ~XEMACPS_NWCFG_RXCHKSUMEN_MASK;
-#endif
- XEmacPs_WriteReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_NWCFG_OFFSET, value );
- }
-
- /*
- * Connect the device driver handler that will be called when an
- * interrupt for the device occurs, the handler defined above performs
- * the specific interrupt processing for the device.
- */
- XScuGic_RegisterHandler(INTC_BASE_ADDR, xtopologyp->scugic_emac_intr,
- (Xil_ExceptionHandler)XEmacPs_IntrHandler,
- (void *)&xemacpsif->emacps);
- /*
- * Enable the interrupt for emacps.
- */
- EmacEnableIntr( );
-
- return 0;
-}
-
-/*
- * resetrx_on_no_rxdata():
- *
- * It is called at regular intervals through the API xemacpsif_resetrx_on_no_rxdata
- * called by the user.
- * The EmacPs has a HW bug (SI# 692601) on the Rx path for heavy Rx traffic.
- * Under heavy Rx traffic because of the HW bug there are times when the Rx path
- * becomes unresponsive. The workaround for it is to check for the Rx path for
- * traffic (by reading the stats registers regularly). If the stats register
- * does not increment for sometime (proving no Rx traffic), the function resets
- * the Rx data path.
- *
- */
-
-void resetrx_on_no_rxdata(xemacpsif_s *xemacpsif)
-{
- unsigned long regctrl;
- unsigned long tempcntr;
-
- tempcntr = XEmacPs_ReadReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_RXCNT_OFFSET );
- if ( ( tempcntr == 0 ) && ( xemacpsif->last_rx_frms_cntr == 0 ) )
- {
- regctrl = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET);
- regctrl &= (~XEMACPS_NWCTRL_RXEN_MASK);
- XEmacPs_WriteReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET, regctrl);
- regctrl = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress, XEMACPS_NWCTRL_OFFSET);
- regctrl |= (XEMACPS_NWCTRL_RXEN_MASK);
- XEmacPs_WriteReg(xemacpsif->emacps.Config.BaseAddress, XEMACPS_NWCTRL_OFFSET, regctrl);
- }
- xemacpsif->last_rx_frms_cntr = tempcntr;
-}
-
-void EmacDisableIntr(void)
-{
- XScuGic_DisableIntr(INTC_DIST_BASE_ADDR, xXTopology.scugic_emac_intr);
-}
-
-void EmacEnableIntr(void)
-{
- XScuGic_EnableIntr(INTC_DIST_BASE_ADDR, xXTopology.scugic_emac_intr);
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.c
deleted file mode 100755
index be00f4f..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (c) 2010-2013 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-
-/* Standard includes. */
-#include
-#include
-#include
-
-#include "Zynq/x_emacpsif.h"
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-
-///* FreeRTOS+TCP includes. */
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-
-extern TaskHandle_t xEMACTaskHandle;
-
-/*** IMPORTANT: Define PEEP in xemacpsif.h and sys_arch_raw.c
- *** to run it on a PEEP board
- ***/
-
-unsigned int link_speed = 100;
-
-void setup_isr( xemacpsif_s *xemacpsif )
-{
- /*
- * Setup callbacks
- */
- XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMASEND,
- (void *) emacps_send_handler,
- (void *) xemacpsif);
-
- XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMARECV,
- (void *) emacps_recv_handler,
- (void *) xemacpsif);
-
- XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_ERROR,
- (void *) emacps_error_handler,
- (void *) xemacpsif);
-}
-
-void start_emacps (xemacpsif_s *xemacps)
-{
- /* start the temac */
- XEmacPs_Start(&xemacps->emacps);
-}
-
-extern struct xtopology_t xXTopology;
-
-volatile int error_msg_count = 0;
-volatile const char *last_err_msg = "";
-
-struct xERROR_MSG {
- void *arg;
- u8 Direction;
- u32 ErrorWord;
-};
-
-static struct xERROR_MSG xErrorList[ 8 ];
-static BaseType_t xErrorHead, xErrorTail;
-
-void emacps_error_handler(void *arg, u8 Direction, u32 ErrorWord)
-{
- BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- xemacpsif_s *xemacpsif;
- BaseType_t xNextHead = xErrorHead;
-
- xemacpsif = (xemacpsif_s *)(arg);
-
- if( ( Direction != XEMACPS_SEND ) || (ErrorWord != XEMACPS_TXSR_USEDREAD_MASK ) )
- {
- if( ++xNextHead == ( sizeof( xErrorList ) / sizeof( xErrorList[ 0 ] ) ) )
- xNextHead = 0;
- if( xNextHead != xErrorTail )
- {
-
- xErrorList[ xErrorHead ].arg = arg;
- xErrorList[ xErrorHead ].Direction = Direction;
- xErrorList[ xErrorHead ].ErrorWord = ErrorWord;
-
- xErrorHead = xNextHead;
-
- xemacpsif = (xemacpsif_s *)(arg);
- xemacpsif->isr_events |= EMAC_IF_ERR_EVENT;
- }
-
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
- }
-
- }
-
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
-}
-
-static void emacps_handle_error(void *arg, u8 Direction, u32 ErrorWord);
-
-int emacps_check_errors( xemacpsif_s *xemacps )
-{
-int xResult;
-
- ( void ) xemacps;
-
- if( xErrorHead == xErrorTail )
- {
- xResult = 0;
- }
- else
- {
- xResult = 1;
- emacps_handle_error(
- xErrorList[ xErrorTail ].arg,
- xErrorList[ xErrorTail ].Direction,
- xErrorList[ xErrorTail ].ErrorWord );
- }
-
- return xResult;
-}
-
-BaseType_t xNetworkInterfaceInitialise( void );
-
-static void emacps_handle_error(void *arg, u8 Direction, u32 ErrorWord)
-{
- xemacpsif_s *xemacpsif;
- struct xtopology_t *xtopologyp;
- XEmacPs *xemacps;
-
- xemacpsif = (xemacpsif_s *)(arg);
-
- xtopologyp = &xXTopology;
-
- xemacps = &xemacpsif->emacps;
-
- /* Do not appear to be used. */
- ( void ) xemacps;
- ( void ) xtopologyp;
-
- last_err_msg = NULL;
-
- if( ErrorWord != 0 )
- {
- switch (Direction) {
- case XEMACPS_RECV:
- if( ( ErrorWord & XEMACPS_RXSR_HRESPNOK_MASK ) != 0 )
- {
- last_err_msg = "Receive DMA error";
- xNetworkInterfaceInitialise( );
- }
- if( ( ErrorWord & XEMACPS_RXSR_RXOVR_MASK ) != 0 )
- {
- last_err_msg = "Receive over run";
- emacps_recv_handler(arg);
- }
- if( ( ErrorWord & XEMACPS_RXSR_BUFFNA_MASK ) != 0 )
- {
- last_err_msg = "Receive buffer not available";
- emacps_recv_handler(arg);
- }
- break;
- case XEMACPS_SEND:
- if( ( ErrorWord & XEMACPS_TXSR_HRESPNOK_MASK ) != 0 )
- {
- last_err_msg = "Transmit DMA error";
- xNetworkInterfaceInitialise( );
- }
- if( ( ErrorWord & XEMACPS_TXSR_URUN_MASK ) != 0 )
- {
- last_err_msg = "Transmit under run";
- HandleTxErrors( xemacpsif );
- }
- if( ( ErrorWord & XEMACPS_TXSR_BUFEXH_MASK ) != 0 )
- {
- last_err_msg = "Transmit buffer exhausted";
- HandleTxErrors( xemacpsif );
- }
- if( ( ErrorWord & XEMACPS_TXSR_RXOVR_MASK ) != 0 )
- {
- last_err_msg = "Transmit retry excessed limits";
- HandleTxErrors( xemacpsif );
- }
- if( ( ErrorWord & XEMACPS_TXSR_FRAMERX_MASK ) != 0 )
- {
- last_err_msg = "Transmit collision";
- emacps_check_tx( xemacpsif );
- }
- break;
- }
- }
- // Break on this statement and inspect error_msg if you like
- if( last_err_msg != NULL )
- {
- error_msg_count++;
- FreeRTOS_printf( ( "emacps_handle_error: %s\n", last_err_msg ) );
- }
-}
-
-extern XEmacPs_Config mac_config;
-
-void HandleTxErrors(xemacpsif_s *xemacpsif)
-{
- u32 netctrlreg;
-
- //taskENTER_CRITICAL()
- {
- netctrlreg = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET);
- netctrlreg = netctrlreg & (~XEMACPS_NWCTRL_TXEN_MASK);
- XEmacPs_WriteReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET, netctrlreg);
-
- clean_dma_txdescs( xemacpsif );
- netctrlreg = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET);
- netctrlreg = netctrlreg | (XEMACPS_NWCTRL_TXEN_MASK);
- XEmacPs_WriteReg(xemacpsif->emacps.Config.BaseAddress,
- XEMACPS_NWCTRL_OFFSET, netctrlreg);
- }
- //taskEXIT_CRITICAL( );
-}
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.h
deleted file mode 100755
index 7b0e4fd..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_hw.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2010-2013 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-#ifndef __XEMACPSIF_HW_H_
-#define __XEMACPSIF_HW_H_
-
-#include "Zynq/x_emacpsif.h"
-//#include "lwip/netif.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-XEmacPs_Config * lookup_config(unsigned mac_base);
-
-//void init_emacps(xemacpsif_s *xemacpsif, struct netif *netif);
-
-int emacps_check_errors( xemacpsif_s *xemacps );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_physpeed.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_physpeed.c
deleted file mode 100755
index 742ff8b..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_physpeed.c
+++ /dev/null
@@ -1,585 +0,0 @@
-/*
- * Copyright (c) 2007-2008, Advanced Micro Devices, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Advanced Micro Devices, Inc. nor the names
- * of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Some portions copyright (c) 2010-2013 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-#include "Zynq/x_emacpsif.h"
-//#include "lwipopts.h"
-#include "xparameters_ps.h"
-#include "xparameters.h"
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-///* FreeRTOS+TCP includes. */
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-
-int phy_detected = 0;
-
-/*** IMPORTANT: Define PEEP in xemacpsif.h and sys_arch_raw.c
- *** to run it on a PEEP board
- ***/
-
-/* Advertisement control register. */
-#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
-#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
-#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
-#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
-
-#define ADVERTISE_100_AND_10 (ADVERTISE_10FULL | ADVERTISE_100FULL | \
- ADVERTISE_10HALF | ADVERTISE_100HALF)
-#define ADVERTISE_100 (ADVERTISE_100FULL | ADVERTISE_100HALF)
-#define ADVERTISE_10 (ADVERTISE_10FULL | ADVERTISE_10HALF)
-
-#define ADVERTISE_1000 0x0300
-
-
-//#define PHY_REG_00_BMCR 0x00 // Basic mode control register
-//#define PHY_REG_01_BMSR 0x01 // Basic mode status register
-//#define PHY_REG_02_PHYSID1 0x02 // PHYS ID 1
-//#define PHY_REG_03_PHYSID2 0x03 // PHYS ID 2
-//#define PHY_REG_04_ADVERTISE 0x04 // Advertisement control reg
-
-#define IEEE_CONTROL_REG_OFFSET 0
-#define IEEE_STATUS_REG_OFFSET 1
-#define IEEE_AUTONEGO_ADVERTISE_REG 4
-#define IEEE_PARTNER_ABILITIES_1_REG_OFFSET 5
-#define IEEE_1000_ADVERTISE_REG_OFFSET 9
-#define IEEE_PARTNER_ABILITIES_3_REG_OFFSET 10
-#define IEEE_COPPER_SPECIFIC_CONTROL_REG 16
-#define IEEE_SPECIFIC_STATUS_REG 17
-#define IEEE_COPPER_SPECIFIC_STATUS_REG_2 19
-#define IEEE_CONTROL_REG_MAC 21
-#define IEEE_PAGE_ADDRESS_REGISTER 22
-
-
-#define IEEE_CTRL_1GBPS_LINKSPEED_MASK 0x2040
-#define IEEE_CTRL_LINKSPEED_MASK 0x0040
-#define IEEE_CTRL_LINKSPEED_1000M 0x0040
-#define IEEE_CTRL_LINKSPEED_100M 0x2000
-#define IEEE_CTRL_LINKSPEED_10M 0x0000
-#define IEEE_CTRL_RESET_MASK 0x8000
-#define IEEE_CTRL_AUTONEGOTIATE_ENABLE 0x1000
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
-#define IEEE_CTRL_RESET 0x9140
-#define IEEE_CTRL_ISOLATE_DISABLE 0xFBFF
-#endif
-#define IEEE_STAT_AUTONEGOTIATE_CAPABLE 0x0008
-#define IEEE_STAT_AUTONEGOTIATE_COMPLETE 0x0020
-#define IEEE_STAT_AUTONEGOTIATE_RESTART 0x0200
-#define IEEE_STAT_1GBPS_EXTENSIONS 0x0100
-#define IEEE_AN1_ABILITY_MASK 0x1FE0
-#define IEEE_AN3_ABILITY_MASK_1GBPS 0x0C00
-#define IEEE_AN1_ABILITY_MASK_100MBPS 0x0380
-#define IEEE_AN1_ABILITY_MASK_10MBPS 0x0060
-#define IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK 0x0030
-
-#define IEEE_ASYMMETRIC_PAUSE_MASK 0x0800
-#define IEEE_PAUSE_MASK 0x0400
-#define IEEE_AUTONEG_ERROR_MASK 0x8000
-
-#define PHY_DETECT_REG 1
-#define PHY_DETECT_MASK 0x1808
-
-#define XEMACPS_GMII2RGMII_SPEED1000_FD 0x140
-#define XEMACPS_GMII2RGMII_SPEED100_FD 0x2100
-#define XEMACPS_GMII2RGMII_SPEED10_FD 0x100
-#define XEMACPS_GMII2RGMII_REG_NUM 0x10
-
-/* Frequency setting */
-#define SLCR_LOCK_ADDR (XPS_SYS_CTRL_BASEADDR + 0x4)
-#define SLCR_UNLOCK_ADDR (XPS_SYS_CTRL_BASEADDR + 0x8)
-#define SLCR_GEM0_CLK_CTRL_ADDR (XPS_SYS_CTRL_BASEADDR + 0x140)
-#define SLCR_GEM1_CLK_CTRL_ADDR (XPS_SYS_CTRL_BASEADDR + 0x144)
-#ifdef PEEP
-#define SLCR_GEM_10M_CLK_CTRL_VALUE 0x00103031
-#define SLCR_GEM_100M_CLK_CTRL_VALUE 0x00103001
-#define SLCR_GEM_1G_CLK_CTRL_VALUE 0x00103011
-#endif
-#define SLCR_LOCK_KEY_VALUE 0x767B
-#define SLCR_UNLOCK_KEY_VALUE 0xDF0D
-#define SLCR_ADDR_GEM_RST_CTRL (XPS_SYS_CTRL_BASEADDR + 0x214)
-#define EMACPS_SLCR_DIV_MASK 0xFC0FC0FF
-
-#define EMAC0_BASE_ADDRESS 0xE000B000
-#define EMAC1_BASE_ADDRESS 0xE000C000
-
-static int detect_phy(XEmacPs *xemacpsp)
-{
- u16 phy_reg;
- u32 phy_addr;
-
- for (phy_addr = 31; phy_addr > 0; phy_addr--) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, PHY_DETECT_REG,
- &phy_reg);
-
- if ((phy_reg != 0xFFFF) &&
- ((phy_reg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
- /* Found a valid PHY address */
- FreeRTOS_printf( ("XEmacPs detect_phy: PHY detected at address %d.\r\n",
- phy_addr));
- FreeRTOS_printf( ("XEmacPs detect_phy: PHY detected.\n" ) );
- phy_detected = phy_addr;
- return phy_addr;
- }
- }
-
- FreeRTOS_printf( ("XEmacPs detect_phy: No PHY detected. Assuming a PHY at address 0\n" ) );
-
- /* default to zero */
- return 0;
-}
-
-#ifdef PEEP
-unsigned get_IEEE_phy_speed(XEmacPs *xemacpsp)
-{
-
- u16 control;
- u16 status;
- u16 partner_capabilities;
- u16 partner_capabilities_1000;
- u16 phylinkspeed;
- u32 phy_addr = detect_phy(xemacpsp);
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_1000_ADVERTISE_REG_OFFSET,
- ADVERTISE_1000);
- /* Advertise PHY speed of 100 and 10 Mbps */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG,
- ADVERTISE_100_AND_10);
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET,
- &control);
- control |= (IEEE_CTRL_AUTONEGOTIATE_ENABLE |
- IEEE_STAT_AUTONEGOTIATE_RESTART);
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
-
- /* Read PHY control and status registers is successful. */
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
-
- if ((control & IEEE_CTRL_AUTONEGOTIATE_ENABLE) && (status &
- IEEE_STAT_AUTONEGOTIATE_CAPABLE)) {
-
- while ( !(status & IEEE_STAT_AUTONEGOTIATE_COMPLETE) ) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET,
- &status);
- }
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_PARTNER_ABILITIES_1_REG_OFFSET,
- &partner_capabilities);
-
- if (status & IEEE_STAT_1GBPS_EXTENSIONS) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_PARTNER_ABILITIES_3_REG_OFFSET,
- &partner_capabilities_1000);
- if (partner_capabilities_1000 & IEEE_AN3_ABILITY_MASK_1GBPS)
- return 1000;
- }
-
- if (partner_capabilities & IEEE_AN1_ABILITY_MASK_100MBPS)
- return 100;
- if (partner_capabilities & IEEE_AN1_ABILITY_MASK_10MBPS)
- return 10;
-
- xil_printf("%s: unknown PHY link speed, setting TEMAC speed to be 10 Mbps\r\n",
- __FUNCTION__);
- return 10;
-
- } else {
-
- /* Update TEMAC speed accordingly */
- if (status & IEEE_STAT_1GBPS_EXTENSIONS) {
- /* Get commanded link speed */
- phylinkspeed = control & IEEE_CTRL_1GBPS_LINKSPEED_MASK;
-
- switch (phylinkspeed) {
- case (IEEE_CTRL_LINKSPEED_1000M):
- return 1000;
- case (IEEE_CTRL_LINKSPEED_100M):
- return 100;
- case (IEEE_CTRL_LINKSPEED_10M):
- return 10;
- default:
- xil_printf("%s: unknown PHY link speed (%d), setting TEMAC speed to be 10 Mbps\r\n",
- __FUNCTION__, phylinkspeed);
- return 10;
- }
-
- } else {
-
- return (control & IEEE_CTRL_LINKSPEED_MASK) ? 100 : 10;
-
- }
- }
-}
-
-#else /* Zynq */
-unsigned get_IEEE_phy_speed(XEmacPs *xemacpsp)
-{
- u16 temp;
- u16 control;
- u16 status;
- u16 partner_capabilities;
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
- u32 phy_addr = XPAR_PCSPMA_SGMII_PHYADDR;
-#else
- u32 phy_addr = detect_phy(xemacpsp);
-#endif
- xil_printf("Start PHY autonegotiation \r\n");
-
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
-#else
- XEmacPs_PhyWrite(xemacpsp,phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 2);
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_MAC, &control);
- control |= IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_MAC, control);
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 0);
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, &control);
- control |= IEEE_ASYMMETRIC_PAUSE_MASK;
- control |= IEEE_PAUSE_MASK;
- control |= ADVERTISE_100;
- control |= ADVERTISE_10;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, control);
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_1000_ADVERTISE_REG_OFFSET,
- &control);
- control |= ADVERTISE_1000;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_1000_ADVERTISE_REG_OFFSET,
- control);
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 0);
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_COPPER_SPECIFIC_CONTROL_REG,
- &control);
- control |= (7 << 12); /* max number of gigabit attempts */
- control |= (1 << 11); /* enable downshift */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_COPPER_SPECIFIC_CONTROL_REG,
- control);
-#endif
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
- control |= IEEE_CTRL_AUTONEGOTIATE_ENABLE;
- control |= IEEE_STAT_AUTONEGOTIATE_RESTART;
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
- control &= IEEE_CTRL_ISOLATE_DISABLE;
-#endif
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
-
-
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
-#else
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
- control |= IEEE_CTRL_RESET_MASK;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
-
- while (1) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
- if (control & IEEE_CTRL_RESET_MASK)
- continue;
- else
- break;
- }
-#endif
- xil_printf("Waiting for PHY to complete autonegotiation.\r\n");
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
- while ( !(status & IEEE_STAT_AUTONEGOTIATE_COMPLETE) ) {
- sleep(1);
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
-#else
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_COPPER_SPECIFIC_STATUS_REG_2,
- &temp);
- if (temp & IEEE_AUTONEG_ERROR_MASK) {
- xil_printf("Auto negotiation error \r\n");
- }
-#endif
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET,
- &status);
- }
-
- xil_printf("autonegotiation complete \r\n");
-
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
-#else
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_SPECIFIC_STATUS_REG, &partner_capabilities);
-#endif
-
-#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
- xil_printf("Waiting for Link to be up; Polling for SGMII core Reg \r\n");
- XEmacPs_PhyRead(xemacpsp, phy_addr, 5, &temp);
- while(!(temp & 0x8000)) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, 5, &temp);
- }
- if((temp & 0x0C00) == 0x0800) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, 0, &temp);
- return 1000;
- }
- else if((temp & 0x0C00) == 0x0400) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, 0, &temp);
- return 100;
- }
- else if((temp & 0x0C00) == 0x0000) {
- XEmacPs_PhyRead(xemacpsp, phy_addr, 0, &temp);
- return 10;
- } else {
- xil_printf("get_IEEE_phy_speed(): Invalid speed bit value, Deafulting to Speed = 10 Mbps\r\n");
- XEmacPs_PhyRead(xemacpsp, phy_addr, 0, &temp);
- XEmacPs_PhyWrite(xemacpsp, phy_addr, 0, 0x0100);
- return 10;
- }
-#else
- if ( ((partner_capabilities >> 14) & 3) == 2)/* 1000Mbps */
- return 1000;
- else if ( ((partner_capabilities >> 14) & 3) == 1)/* 100Mbps */
- return 100;
- else /* 10Mbps */
- return 10;
-#endif
-}
-#endif
-
-unsigned configure_IEEE_phy_speed(XEmacPs *xemacpsp, unsigned speed)
-{
- u16 control;
- u32 phy_addr = detect_phy(xemacpsp);
-
- XEmacPs_PhyWrite(xemacpsp,phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 2);
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_MAC, &control);
- control |= IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_MAC, control);
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 0);
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, &control);
- control |= IEEE_ASYMMETRIC_PAUSE_MASK;
- control |= IEEE_PAUSE_MASK;
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, control);
-
- XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
- control &= ~IEEE_CTRL_LINKSPEED_1000M;
- control &= ~IEEE_CTRL_LINKSPEED_100M;
- control &= ~IEEE_CTRL_LINKSPEED_10M;
-
- if (speed == 1000) {
- control |= IEEE_CTRL_LINKSPEED_1000M;
- }
-
- else if (speed == 100) {
- control |= IEEE_CTRL_LINKSPEED_100M;
- /* Dont advertise PHY speed of 1000 Mbps */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_1000_ADVERTISE_REG_OFFSET, 0);
- /* Dont advertise PHY speed of 10 Mbps */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG,
- ADVERTISE_100);
- }
-
- else if (speed == 10) {
- control |= IEEE_CTRL_LINKSPEED_10M;
- /* Dont advertise PHY speed of 1000 Mbps */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_1000_ADVERTISE_REG_OFFSET,
- 0);
- /* Dont advertise PHY speed of 100 Mbps */
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG,
- ADVERTISE_10);
- }
-
- XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET,
- control | IEEE_CTRL_RESET_MASK);
- {
- volatile int wait;
- for (wait=0; wait < 100000; wait++);
- }
- return 0;
-}
-
-static void SetUpSLCRDivisors(int mac_baseaddr, int speed)
-{
- volatile u32 slcrBaseAddress;
-#ifndef PEEP
- u32 SlcrDiv0;
- u32 SlcrDiv1=0;
- u32 SlcrTxClkCntrl;
-#endif
-
- *(volatile unsigned int *)(SLCR_UNLOCK_ADDR) = SLCR_UNLOCK_KEY_VALUE;
-
- if ((unsigned long)mac_baseaddr == EMAC0_BASE_ADDRESS) {
- slcrBaseAddress = SLCR_GEM0_CLK_CTRL_ADDR;
- } else {
- slcrBaseAddress = SLCR_GEM1_CLK_CTRL_ADDR;
- }
-#ifdef PEEP
- if (speed == 1000) {
- *(volatile unsigned int *)(slcrBaseAddress) =
- SLCR_GEM_1G_CLK_CTRL_VALUE;
- } else if (speed == 100) {
- *(volatile unsigned int *)(slcrBaseAddress) =
- SLCR_GEM_100M_CLK_CTRL_VALUE;
- } else {
- *(volatile unsigned int *)(slcrBaseAddress) =
- SLCR_GEM_10M_CLK_CTRL_VALUE;
- }
-#else
- if (speed == 1000) {
- if ((unsigned long)mac_baseaddr == EMAC0_BASE_ADDRESS) {
-#ifdef XPAR_PS7_ETHERNET_0_ENET_SLCR_1000MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_0_ENET_SLCR_1000MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_0_ENET_SLCR_1000MBPS_DIV1;
-#endif
- } else {
-#ifdef XPAR_PS7_ETHERNET_1_ENET_SLCR_1000MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_1_ENET_SLCR_1000MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_1_ENET_SLCR_1000MBPS_DIV1;
-#endif
- }
- } else if (speed == 100) {
- if ((unsigned long)mac_baseaddr == EMAC0_BASE_ADDRESS) {
-#ifdef XPAR_PS7_ETHERNET_0_ENET_SLCR_100MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_0_ENET_SLCR_100MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_0_ENET_SLCR_100MBPS_DIV1;
-#endif
- } else {
-#ifdef XPAR_PS7_ETHERNET_1_ENET_SLCR_100MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_1_ENET_SLCR_100MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_1_ENET_SLCR_100MBPS_DIV1;
-#endif
- }
- } else {
- if ((unsigned long)mac_baseaddr == EMAC0_BASE_ADDRESS) {
-#ifdef XPAR_PS7_ETHERNET_0_ENET_SLCR_10MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_0_ENET_SLCR_10MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_0_ENET_SLCR_10MBPS_DIV1;
-#endif
- } else {
-#ifdef XPAR_PS7_ETHERNET_1_ENET_SLCR_10MBPS_DIV0
- SlcrDiv0 = XPAR_PS7_ETHERNET_1_ENET_SLCR_10MBPS_DIV0;
- SlcrDiv1 = XPAR_PS7_ETHERNET_1_ENET_SLCR_10MBPS_DIV1;
-#endif
- }
- }
- SlcrTxClkCntrl = *(volatile unsigned int *)(slcrBaseAddress);
- SlcrTxClkCntrl &= EMACPS_SLCR_DIV_MASK;
- SlcrTxClkCntrl |= (SlcrDiv1 << 20);
- SlcrTxClkCntrl |= (SlcrDiv0 << 8);
- *(volatile unsigned int *)(slcrBaseAddress) = SlcrTxClkCntrl;
-#endif
- *(volatile unsigned int *)(SLCR_LOCK_ADDR) = SLCR_LOCK_KEY_VALUE;
- return;
-}
-
-
-unsigned link_speed;
-unsigned Phy_Setup (XEmacPs *xemacpsp)
-{
- unsigned long conv_present = 0;
- unsigned long convspeeddupsetting = 0;
- unsigned long convphyaddr = 0;
-
-#ifdef XPAR_GMII2RGMIICON_0N_ETH0_ADDR
- convphyaddr = XPAR_GMII2RGMIICON_0N_ETH0_ADDR;
- conv_present = 1;
-#else
-#ifdef XPAR_GMII2RGMIICON_0N_ETH1_ADDR
- convphyaddr = XPAR_GMII2RGMIICON_0N_ETH1_ADDR;
- conv_present = 1;
-#endif
-#endif
-
-#ifdef ipconfigNIC_LINKSPEED_AUTODETECT
- link_speed = get_IEEE_phy_speed(xemacpsp);
- if (link_speed == 1000) {
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,1000);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED1000_FD;
- } else if (link_speed == 100) {
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,100);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED100_FD;
- } else {
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,10);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED10_FD;
- }
-#elif defined(ipconfigNIC_LINKSPEED1000)
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,1000);
- link_speed = 1000;
- configure_IEEE_phy_speed(xemacpsp, link_speed);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED1000_FD;
- sleep(1);
-#elif defined(ipconfigNIC_LINKSPEED100)
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,100);
- link_speed = 100;
- configure_IEEE_phy_speed(xemacpsp, link_speed);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED100_FD;
- sleep(1);
-#elif defined(ipconfigNIC_LINKSPEED10)
- SetUpSLCRDivisors(xemacpsp->Config.BaseAddress,10);
- link_speed = 10;
- configure_IEEE_phy_speed(xemacpsp, link_speed);
- convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED10_FD;
- sleep(1);
-#endif
- if (conv_present) {
- XEmacPs_PhyWrite(xemacpsp, convphyaddr,
- XEMACPS_GMII2RGMII_REG_NUM, convspeeddupsetting);
- }
-
- xil_printf("link speed: %d\r\n", link_speed);
- return link_speed;
-}
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_topology.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_topology.h
deleted file mode 100755
index 1d8fede..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_topology.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2007-2013 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-#ifndef __XTOPOLOGY_H_
-#define __XTOPOLOGY_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum xemac_types { xemac_type_unknown = -1, xemac_type_xps_emaclite, xemac_type_xps_ll_temac, xemac_type_axi_ethernet, xemac_type_emacps };
-
-struct xtopology_t {
- unsigned emac_baseaddr;
- enum xemac_types emac_type;
- unsigned intc_baseaddr;
- unsigned intc_emac_intr; /* valid only for xemac_type_xps_emaclite */
- unsigned scugic_baseaddr; /* valid only for Zynq */
- unsigned scugic_emac_intr; /* valid only for GEM */
-};
-
-extern int x_topology_n_emacs;
-extern struct xtopology_t x_topology[];
-
-int x_topology_find_index(unsigned base);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/include/phyHandling.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/include/phyHandling.h
deleted file mode 100755
index e9126dc..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/include/phyHandling.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Handling of Ethernet PHY's
- * PHY's communicate with an EMAC either through
- * a Media-Independent Interface (MII), or a Reduced Media-Independent Interface (RMII).
- * The EMAC can poll for PHY ports on 32 different addresses. Each of the PHY ports
- * shall be treated independently.
- *
- */
-
-#ifndef PHYHANDLING_H
-
-#define PHYHANDLING_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifndef ipconfigPHY_MAX_PORTS
- /* There can be at most 32 PHY ports, but in most cases there are 4 or less. */
- #define ipconfigPHY_MAX_PORTS 4
-#endif
-
-/* A generic user-provided function that reads from the PHY-port at 'xAddress'( 0-based ). A 16-bit value shall be stored in
- '*pusValue'. xRegister is the register number ( 0 .. 31 ). In fact all PHY registers are 16-bit.
- Return non-zero in case the action failed. */
-typedef BaseType_t ( *xApplicationPhyReadHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t *pulValue );
-
-/* A generic user-provided function that writes 'usValue' to the
- PHY-port at 'xAddress' ( 0-based ). xRegister is the register number ( 0 .. 31 ).
- Return non-zero in case the action failed. */
-typedef BaseType_t ( *xApplicationPhyWriteHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t ulValue );
-
-typedef struct xPhyProperties
-{
- uint8_t ucSpeed;
- uint8_t ucMDI_X; /* MDI-X : Medium Dependent Interface - Crossover */
- uint8_t ucDuplex;
- uint8_t ucSpare;
-} PhyProperties_t;
-
-typedef struct xEthernetPhy
-{
- xApplicationPhyReadHook_t fnPhyRead;
- xApplicationPhyWriteHook_t fnPhyWrite;
- uint32_t ulPhyIDs[ ipconfigPHY_MAX_PORTS ];
- uint8_t ucPhyIndexes[ ipconfigPHY_MAX_PORTS ];
- TimeOut_t xLinkStatusTimer;
- TickType_t xLinkStatusRemaining;
- BaseType_t xPortCount;
- uint32_t ulBCRValue;
- uint32_t ulACRValue;
- uint32_t ulLinkStatusMask;
- PhyProperties_t xPhyPreferences;
- PhyProperties_t xPhyProperties;
-} EthernetPhy_t;
-
-/* Some defines used internally here to indicate preferences about speed, MDIX
-(wired direct or crossed), and duplex (half or full). */
-
-/* Values for PhyProperties_t::ucSpeed : */
-#define PHY_SPEED_10 1
-#define PHY_SPEED_100 2
-#define PHY_SPEED_AUTO 3
-
-/* Values for PhyProperties_t::ucMDI_X : */
-#define PHY_MDIX_DIRECT 1
-#define PHY_MDIX_CROSSED 2
-#define PHY_MDIX_AUTO 3
-
-/* Values for PhyProperties_t::ucDuplex : */
-#define PHY_DUPLEX_HALF 1
-#define PHY_DUPLEX_FULL 2
-#define PHY_DUPLEX_AUTO 3
-
-/* ID's of supported PHY's : */
-#define PHY_ID_LAN8742A 0x0007c130
-#define PHY_ID_LAN8720 0x0007c0f0
-
-#define PHY_ID_KSZ8041 0x000010A1
-#define PHY_ID_KSZ8051 0x000010A1
-#define PHY_ID_KSZ8081 0x000010A1
-
-#define PHY_ID_KSZ8863 0x00221430
-
-#define PHY_ID_DP83848I 0x20005C90
-
-
-/* Initialise the struct and assign a PHY-read and -write function. */
-void vPhyInitialise( EthernetPhy_t *pxPhyObject, xApplicationPhyReadHook_t fnPhyRead, xApplicationPhyWriteHook_t fnPhyWrite );
-
-/* Discover all PHY's connected by polling 32 indexes ( zero-based ) */
-BaseType_t xPhyDiscover( EthernetPhy_t *pxPhyObject );
-
-/* Send a reset commando to the connected PHY ports and send configuration. */
-BaseType_t xPhyConfigure( EthernetPhy_t *pxPhyObject, const PhyProperties_t *pxPhyProperties );
-
-/* Give a commando to start auto negotiation on a set of PHY port's. */
-BaseType_t xPhyStartAutoNegotiation( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
-
-/* Do not use auto negotiation but use predefined values from 'pxPhyObject->xPhyPreferences'. */
-BaseType_t xPhyFixedValue( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
-
-/* Check the current Link Status.
-'xHadReception' : make this true if a packet has been received since the
-last call to this function. */
-BaseType_t xPhyCheckLinkStatus( EthernetPhy_t *pxPhyObject, BaseType_t xHadReception );
-
-static __inline uint32_t xPhyGetMask( EthernetPhy_t *pxPhyObject )
-{
- return ( ( ( uint32_t ) 1u ) << pxPhyObject-> xPortCount ) - 1;
-}
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c
deleted file mode 100755
index e6085d0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c
+++ /dev/null
@@ -1,1272 +0,0 @@
-/*
-FreeRTOS+TCP V2.0.7
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
-
-/* Standard includes. */
-#include
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "FreeRTOS_IP_Private.h"
-#include "NetworkBufferManagement.h"
-#include "NetworkInterface.h"
-
-#include "sam4e_xplained_pro.h"
-#include "hr_gettime.h"
-#include "conf_eth.h"
-#include "ksz8851snl.h"
-#include "ksz8851snl_reg.h"
-
-/* Some files from the Atmel Software Framework */
-#include
-#include
-#include
-
-/*
- Sending a packet:
-
- 1) Called by UP-task, add buffer to the TX-list:
- xNetworkInterfaceOutput()
- tx_buffers[ us_tx_head ] = pxNetworkBuffer;
- tx_busy[ us_tx_head ] = pdTRUE;
- us_tx_head++;
-
- 2) Called by EMAC-Task: start SPI transfer
- ksz8851snl_update()
- if( ul_spi_pdc_status == SPI_PDC_IDLE )
- {
- if( ( tx_busy[ us_tx_tail ] != pdFALSE ) &&
- ( us_pending_frame == 0 ) &&
- ( ul_had_intn_interrupt == 0 ) )
- {
- // disable all interrupts.
- ksz8851_reg_write( REG_INT_MASK, 0 );
- Bring KSZ8851SNL_CSN_GPIO low
- ksz8851_fifo_write( pxNetworkBuffer->pucEthernetBuffer, xLength, xLength );
- ul_spi_pdc_status = SPI_PDC_TX_START;
- tx_cur_buffer = pxNetworkBuffer;
- }
- }
- 3) Wait for SPI RXBUFF interrupt
- SPI_Handler()
- if( ul_spi_pdc_status == SPI_PDC_TX_START )
- {
- if( SPI_Status & SPI_SR_RXBUFF )
- {
- ul_spi_pdc_status = SPI_PDC_TX_COMPLETE;
- }
- }
-
- 4) Called by EMAC-Task: finish SPI transfer
- ksz8851snl_update()
- if( ul_spi_pdc_status == SPI_PDC_TX_COMPLETE )
- {
- ul_spi_pdc_status = SPI_PDC_IDLE;
- Bring KSZ8851SNL_CSN_GPIO high
- // TX step12: disable TXQ write access.
- ksz8851_reg_clrbits( REG_RXQ_CMD, RXQ_START );
- // TX step12.1: enqueue frame in TXQ.
- ksz8851_reg_setbits( REG_TXQ_CMD, TXQ_ENQUEUE );
-
- // RX step13: enable INT_RX flag.
- ksz8851_reg_write( REG_INT_MASK, INT_RX );
-
- // Buffer sent, free the corresponding buffer and mark descriptor as owned by software.
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
-
- tx_buffers[ us_tx_tail ] = NULL;
- tx_busy[ us_tx_tail ] = pdFALSE;
- us_tx_tail++
- }
-
- Receiving a packet:
-
- 1) Wait for a INTN interrupt
- INTN_Handler()
- ul_had_intn_interrupt = 1
- vTaskNotifyGiveFromISR(); // Wake up the EMAC task
-
- 2) Called by EMAC-Task: check for new fragments and start SPI transfer
- ksz8851snl_update()
- if( ul_spi_pdc_status == SPI_PDC_IDLE )
- {
- if( ( ul_had_intn_interrupt != 0 ) || ( us_pending_frame > 0 ) )
- {
- if( us_pending_frame == 0 )
- {
- us_pending_frame = ksz8851_reg_read(REG_RX_FRAME_CNT_THRES) >> 8;
- if( us_pending_frame == 0 )
- {
- break;
- }
- }
- // RX step2: disable all interrupts.
- ksz8851_reg_write( REG_INT_MASK, 0 );
- Check if there is a valid packet: REG_RX_FHR_STATUS
- Read the length of the next fragment: REG_RX_FHR_BYTE_CNT
- ul_spi_pdc_status = SPI_PDC_RX_START;
- gpio_set_pin_low(KSZ8851SNL_CSN_GPIO);
- // Start SPI data transfer
- ksz8851_fifo_read( pxNetworkBuffer->pucEthernetBuffer, xReadLength );
- }
- }
-
- 3) Wait for SPI RXBUFF interrupt
- SPI_Handler()
- if( ul_spi_pdc_status == SPI_PDC_RX_START:
- {
- if( ( ulCurrentSPIStatus & SPI_SR_RXBUFF ) != 0 )
- {
- // Transfer complete, disable SPI RXBUFF interrupt.
- spi_disable_interrupt( KSZ8851SNL_SPI, SPI_IDR_RXBUFF );
-
- ul_spi_pdc_status = SPI_PDC_RX_COMPLETE;
- }
- }
- }
-
- 4) Finish SPI transfer
- ksz8851snl_update()
- if( ul_spi_pdc_status == SPI_PDC_RX_COMPLETE )
- {
- ul_spi_pdc_status = SPI_PDC_IDLE;
- Bring KSZ8851SNL_CSN_GPIO high
- // RX step21: end RXQ read access.
- ksz8851_reg_clrbits(REG_RXQ_CMD, RXQ_START);
- // RX step22-23: update frame count to be read.
- us_pending_frame--
- // RX step24: enable INT_RX flag if transfer complete.
- if( us_pending_frame == 0 )
- {
- // Allow more RX interrupts.
- ksz8851_reg_write( REG_INT_MASK, INT_RX );
- }
-
- // Mark descriptor ready to be read.
- rx_ready[ rxHead ] = pdTRUE;
- rxHead++
- }
-*/
-
-#define PHY_REG_00_BMCR 0x00 // Basic mode control register
-#define PHY_REG_01_BMSR 0x01 // Basic mode status register
-#define PHY_REG_02_PHYSID1 0x02 // PHYS ID 1
-#define PHY_REG_03_PHYSID2 0x03 // PHYS ID 2
-#define PHY_REG_04_ADVERTISE 0x04 // Advertisement control reg
-#define PHY_REG_05_LPA 0x05 // Link partner ability reg
-#define PHY_REG_06_ANER 0x06 // 6 RW Auto-Negotiation Expansion Register
-#define PHY_REG_07_ANNPTR 0x07 // 7 RW Auto-Negotiation Next Page TX
-#define PHY_REG_08_RESERVED0 0x08 // 0x08..0x0Fh 8-15 RW RESERVED
-
-#define BMSR_LINK_STATUS 0x0004 //!< Link status
-
-#ifndef PHY_LS_HIGH_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still high after 15 seconds of not
- receiving packets. */
- #define PHY_LS_HIGH_CHECK_TIME_MS 15000
-#endif
-
-#ifndef PHY_LS_LOW_CHECK_TIME_MS
- /* Check if the LinkSStatus in the PHY is still low every second. */
- #define PHY_LS_LOW_CHECK_TIME_MS 1000
-#endif
-
-/* Interrupt events to process. Currently only the Rx event is processed
-although code for other events is included to allow for possible future
-expansion. */
-#define EMAC_IF_RX_EVENT 1UL
-#define EMAC_IF_TX_EVENT 2UL
-#define EMAC_IF_ERR_EVENT 4UL
-#define EMAC_IF_ALL_EVENT ( EMAC_IF_RX_EVENT | EMAC_IF_TX_EVENT | EMAC_IF_ERR_EVENT )
-
-#define ETHERNET_CONF_PHY_ADDR BOARD_GMAC_PHY_ADDR
-
-#ifdef ipconfigHAS_TX_CRC_OFFLOADING
- #undef ipconfigHAS_TX_CRC_OFFLOADING
-#endif
-/* Override this define because the KSZ8851 is programmed to set all outgoing CRC's */
-#define ipconfigHAS_TX_CRC_OFFLOADING 1
-
-#ifndef EMAC_MAX_BLOCK_TIME_MS
- #define EMAC_MAX_BLOCK_TIME_MS 100ul
-#endif
-
-/* Default the size of the stack used by the EMAC deferred handler task to 4x
-the size of the stack used by the idle task - but allow this to be overridden in
-FreeRTOSConfig.h as configMINIMAL_STACK_SIZE is a user definable constant. */
-#ifndef configEMAC_TASK_STACK_SIZE
- #define configEMAC_TASK_STACK_SIZE ( 6 * configMINIMAL_STACK_SIZE )
-#endif
-
-#define SPI_PDC_IDLE 0
-#define SPI_PDC_RX_START 1
-#define SPI_PDC_TX_ERROR 2
-#define SPI_PDC_RX_COMPLETE 3
-#define SPI_PDC_TX_START 4
-#define SPI_PDC_RX_ERROR 5
-#define SPI_PDC_TX_COMPLETE 6
-
-/**
- * ksz8851snl driver structure.
- */
-typedef struct {
- /** Set to 1 when owner is software (ready to read), 0 for Micrel. */
- uint32_t rx_ready[MICREL_RX_BUFFERS];
- /** Set to 1 when owner is Micrel, 0 for software. */
- uint32_t tx_busy[MICREL_TX_BUFFERS];
- /** RX NetworkBufferDescriptor_t pointer list */
- NetworkBufferDescriptor_t *rx_buffers[MICREL_RX_BUFFERS];
- /** TX NetworkBufferDescriptor_t pointer list */
- NetworkBufferDescriptor_t *tx_buffers[MICREL_TX_BUFFERS];
- NetworkBufferDescriptor_t *tx_cur_buffer;
-
- /** Circular buffer head pointer for packet received. */
- uint32_t us_rx_head;
- /** Circular buffer tail pointer for packet to be read. */
- uint32_t us_rx_tail;
- /** Circular buffer head pointer by upper layer (buffer to be sent). */
- uint32_t us_tx_head;
- /** Circular buffer tail pointer incremented by handlers (buffer sent). */
- uint32_t us_tx_tail;
-
- uint32_t ul_total_tx;
- uint32_t ul_total_rx;
- uint32_t tx_space;
-
- /** Still experimental: hash table to allow certain multicast addresses. */
- uint16_t pusHashTable[ 4 ];
-
- /* ul_spi_pdc_status has "SPI_PDC_xxx" values. */
- volatile uint32_t ul_spi_pdc_status;
-
- /* ul_had_intn_interrupt becomes true within the INTN interrupt. */
- volatile uint32_t ul_had_intn_interrupt;
-
- uint16_t us_pending_frame;
-} xKSZ8851_Device_t;
-
-/* SPI PDC register base.
-Declared in ASF\sam\components\ksz8851snl\ksz8851snl.c */
-extern Pdc *g_p_spi_pdc;
-
-/* Temporary buffer for PDC reception.
-declared in ASF\sam\components\ksz8851snl\ksz8851snl.c */
-extern uint8_t tmpbuf[1536];
-
-COMPILER_ALIGNED(8)
-static xKSZ8851_Device_t xMicrelDevice;
-
-static TaskHandle_t xTransmitHandle;
-
-/*-----------------------------------------------------------*/
-
-/*
- * Wait a fixed time for the link status to indicate the network is up.
- */
-static BaseType_t xGMACWaitLS( TickType_t xMaxTime );
-
-/*
- * A deferred interrupt handler task that processes GMAC interrupts.
- */
-static void prvEMACHandlerTask( void *pvParameters );
-
-/*
- * Try to obtain an Rx packet from the hardware.
- */
-static uint32_t prvEMACRxPoll( void );
-
-static inline unsigned long ulReadMDIO( unsigned uAddress );
-
-static void ksz8851snl_low_level_init( void );
-
-static NetworkBufferDescriptor_t *ksz8851snl_low_level_input( void );
-
-/*-----------------------------------------------------------*/
-
-/* Bit map of outstanding ETH interrupt events for processing. Currently only
-the Rx interrupt is handled, although code is included for other events to
-enable future expansion. */
-static volatile uint32_t ulISREvents;
-
-/* A copy of PHY register 1: 'PHY_REG_01_BMSR' */
-static uint32_t ulPHYLinkStatus = 0;
-static volatile BaseType_t xGMACSwitchRequired;
-
-static void ksz8851snl_update( void );
-
-static void ksz8851snl_rx_init( void );
-
-static void ksz8851snl_tx_init( void );
-
-/* Holds the handle of the task used as a deferred interrupt processor. The
-handle is used so direct notifications can be sent to the task for all EMAC/DMA
-related interrupts. */
-TaskHandle_t xEMACTaskHandle = NULL;
-
-
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceInitialise( void )
-{
-const TickType_t x5_Seconds = 5000UL;
-
- if( xEMACTaskHandle == NULL )
- {
- ksz8851snl_low_level_init();
-
- /* Wait at most 5 seconds for a Link Status in the PHY. */
- xGMACWaitLS( pdMS_TO_TICKS( x5_Seconds ) );
-
- /* The handler task is created at the highest possible priority to
- ensure the interrupt handler can return directly to it. */
- xTaskCreate( prvEMACHandlerTask, "KSZ8851", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
- configASSERT( xEMACTaskHandle );
- }
-
- /* When returning non-zero, the stack will become active and
- start DHCP (in configured) */
- ulPHYLinkStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- return ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xGetPhyLinkStatus( void )
-{
-BaseType_t xResult;
-
- /* This function returns true if the Link Status in the PHY is high. */
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xResult = pdTRUE;
- }
- else
- {
- xResult = pdFALSE;
- }
-
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, BaseType_t bReleaseAfterSend )
-{
-BaseType_t xResult = pdFALSE;
-int txHead = xMicrelDevice.us_tx_head;
-
- /* Make sure the next descriptor is free. */
- if( xMicrelDevice.tx_busy[ txHead ] != pdFALSE )
- {
- /* All TX buffers busy. */
- }
- else if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) == 0 )
- {
- /* Output: LS low. */
- }
- else
- {
- /* Pass the packet. */
- xMicrelDevice.tx_buffers[ txHead ] = pxNetworkBuffer;
- /* The descriptor is now owned by Micrel. */
- xMicrelDevice.tx_busy[ txHead ] = pdTRUE;
-
- /* Move the head pointer. */
- if( ++txHead == MICREL_TX_BUFFERS )
- {
- txHead = 0;
- }
- xMicrelDevice.us_tx_head = txHead;
- if( xEMACTaskHandle != NULL )
- {
- xTaskNotifyGive( xEMACTaskHandle );
- }
-
- #if( ipconfigZERO_COPY_TX_DRIVER != 1 )
- #warning Please ipconfigZERO_COPY_TX_DRIVER as 1
- #endif
- configASSERT( bReleaseAfterSend != pdFALSE );
- xResult = pdTRUE;
- }
- if( ( xResult == pdFALSE ) && ( bReleaseAfterSend != pdFALSE ) )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
- return xResult;
-}
-/*-----------------------------------------------------------*/
-
-/* This Micrel has numbered it's PHY registers in a different way.
-Translate the register index. */
-static int ks8851_phy_reg( int reg )
-{
- switch (reg) {
- case PHY_REG_00_BMCR:
- return REG_PHY_CNTL; // P1MBCR;
- case PHY_REG_01_BMSR:
- return REG_PHY_STATUS;
- case PHY_REG_02_PHYSID1:
- return REG_PHY_ID_LOW;
- case PHY_REG_03_PHYSID2:
- return REG_PHY_ID_HIGH;
- case PHY_REG_04_ADVERTISE:
- return REG_PHY_AUTO_NEGOTIATION;
- case PHY_REG_05_LPA:
- return REG_PHY_REMOTE_CAPABILITY;
- }
-
- return 0x0;
-}
-/*-----------------------------------------------------------*/
-
-static inline unsigned long ulReadMDIO( unsigned uAddress )
-{
-uint16_t usPHYStatus;
-int ks8851_reg = ks8851_phy_reg( uAddress );
-
- if( ks8851_reg != 0 )
- {
- usPHYStatus = ksz8851_reg_read( ks8851_reg );
- }
- else
- {
- /* Other addresses not yet implemented. */
- usPHYStatus = 0;
- }
- return usPHYStatus;
-}
-/*-----------------------------------------------------------*/
-
-static BaseType_t xGMACWaitLS( TickType_t xMaxTime )
-{
-TickType_t xStartTime = xTaskGetTickCount();
-TickType_t xEndTime;
-BaseType_t xReturn;
-const TickType_t xShortTime = pdMS_TO_TICKS( 100UL );
-const uint32_t ulHz_Per_MHz = 1000000UL;
-
- for( ;; )
- {
- xEndTime = xTaskGetTickCount();
-
- if( ( xEndTime - xStartTime ) > xMaxTime )
- {
- /* Wated more than xMaxTime, return. */
- xReturn = pdFALSE;
- break;
- }
-
- /* Check the link status again. */
- ulPHYLinkStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- /* Link is up - return. */
- xReturn = pdTRUE;
- break;
- }
-
- /* Link is down - wait in the Blocked state for a short while (to allow
- other tasks to execute) before checking again. */
- vTaskDelay( xShortTime );
- }
-
- FreeRTOS_printf( ( "xGMACWaitLS: %ld freq %lu Mz\n",
- xReturn,
- sysclk_get_cpu_hz() / ulHz_Per_MHz ) );
-
- return xReturn;
-}
-/*-----------------------------------------------------------*/
-
-static void vPioSetPinHigh(uint32_t ul_pin)
-{
- Pio *p_pio = (Pio *)((uint32_t)PIOA + (PIO_DELTA * (ul_pin >> 5)));
- // Value to be driven on the I/O line: 1.
- p_pio->PIO_SODR = 1 << (ul_pin & 0x1F);
-}
-
-/**
- * \brief Handler for SPI interrupt.
- */
-void SPI_Handler(void)
-{
-BaseType_t xDoWakeup = pdFALSE;
-BaseType_t xKSZTaskWoken = pdFALSE;
-uint32_t ulCurrentSPIStatus;
-uint32_t ulEnabledSPIStatus;
-
- ulCurrentSPIStatus = spi_read_status( KSZ8851SNL_SPI );
- ulEnabledSPIStatus = spi_read_interrupt_mask( KSZ8851SNL_SPI );
- ulCurrentSPIStatus &= ulEnabledSPIStatus;
- spi_disable_interrupt( KSZ8851SNL_SPI, ulCurrentSPIStatus );
-
-
- switch( xMicrelDevice.ul_spi_pdc_status )
- {
- case SPI_PDC_RX_START:
- {
- if( ( ulCurrentSPIStatus & SPI_SR_OVRES ) != 0 )
- {
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_RX_ERROR;
- xDoWakeup = pdTRUE;
- }
- else
- {
- if( ( ulCurrentSPIStatus & SPI_SR_RXBUFF ) != 0 )
- {
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_RX_COMPLETE;
- xDoWakeup = pdTRUE;
- }
- }
- }
- break;
-
- case SPI_PDC_TX_START:
- {
- /* Middle of TX. */
- if( ( ulCurrentSPIStatus & SPI_SR_OVRES ) != 0 )
- {
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_TX_ERROR;
- xDoWakeup = pdTRUE;
- }
- else
- {
- if( ( ulCurrentSPIStatus & SPI_SR_ENDRX ) != 0 )
- {
- /* Enable RX complete interrupt. */
- spi_enable_interrupt( KSZ8851SNL_SPI, SPI_IER_RXBUFF );
- }
- /* End of TX. */
- if( ( ulCurrentSPIStatus & SPI_END_OF_TX ) != 0 )
- {
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_TX_COMPLETE;
- xDoWakeup = pdTRUE;
- }
- }
- }
- break;
- } /* switch( xMicrelDevice.ul_spi_pdc_status ) */
-
- if( xDoWakeup != pdFALSE )
- {
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, ( BaseType_t * ) &xKSZTaskWoken );
- }
- }
- else
- {
- }
- portEND_SWITCHING_ISR( xKSZTaskWoken );
-}
-/*-----------------------------------------------------------*/
-
-static void INTN_Handler(uint32_t id, uint32_t mask)
-{
-BaseType_t xKSZTaskWoken = pdFALSE;
-
- if( ( id == INTN_ID ) &&
- ( mask == INTN_PIN_MSK ) )
- {
- /* Clear the PIO interrupt flags. */
- pio_get_interrupt_status( INTN_PIO );
-
- /* Set the INTN flag. */
- xMicrelDevice.ul_had_intn_interrupt++;
- if( xEMACTaskHandle != NULL )
- {
- vTaskNotifyGiveFromISR( xEMACTaskHandle, &( xKSZTaskWoken ) );
- }
- }
- portEND_SWITCHING_ISR( xKSZTaskWoken );
-}
-/*-----------------------------------------------------------*/
-
-/**
- * \brief Populate the RX descriptor ring buffers with pbufs.
- *
- * \param p_ksz8851snl_dev Pointer to driver data structure.
- */
-static void ksz8851snl_rx_populate_queue( void )
-{
- uint32_t ul_index = 0;
- NetworkBufferDescriptor_t *pxNetworkBuffer;
-
- /* Set up the RX descriptors */
- for (ul_index = 0; ul_index < MICREL_RX_BUFFERS; ul_index++) {
- if( xMicrelDevice.rx_buffers[ ul_index ] == NULL )
- {
- /* Allocate a new NetworkBufferDescriptor_t with the maximum size. */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ipconfigNETWORK_MTU + 36, 100 );
- if( pxNetworkBuffer == NULL )
- {
- FreeRTOS_printf( ( "ksz8851snl_rx_populate_queue: NetworkBufferDescriptor_t allocation failure\n" ) );
- configASSERT( 1 == 2 );
- }
-
- /* Make sure lwIP is well configured so one NetworkBufferDescriptor_t can contain the maximum packet size. */
- //LWIP_ASSERT("ksz8851snl_rx_populate_queue: NetworkBufferDescriptor_t size too small!", pbuf_clen(pxNetworkBuffer) <= 1);
-
- /* Save NetworkBufferDescriptor_t pointer to be sent to lwIP upper layer. */
- xMicrelDevice.rx_buffers[ ul_index ] = pxNetworkBuffer;
- /* Pass it to Micrel for reception. */
- xMicrelDevice.rx_ready[ ul_index ] = pdFALSE;
- }
- }
-}
-
-unsigned tx_space, wait_tx_space, tx_status, fhr_status;
-unsigned rx_debug = 0;
-/**
- * \brief Update Micrel state machine and perform required actions.
- *
- * \param netif the lwIP network interface structure for this ethernetif.
- */
-static void ksz8851snl_update()
-{
- uint16_t txmir = 0;
-
-/* Check for free PDC. */
- switch( xMicrelDevice.ul_spi_pdc_status )
- {
- case SPI_PDC_TX_ERROR:
- {
- uint32_t ulValue;
- // /* TX step11: end TX transfer. */
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
-
- vTaskDelay( 2 ); gpio_set_pin_low( KSZ8851SNL_CSN_GPIO );
- vTaskDelay( 1 ); gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
- vTaskDelay( 1 );
-
- /* Disable asynchronous transfer mode. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_IDLE;
-
- /* TX step12: disable TXQ write access. */
- ksz8851_reg_clrbits( REG_RXQ_CMD, RXQ_START );
-
- ulValue = ksz8851snl_reset_tx();
-
- xMicrelDevice.tx_space = ksz8851_reg_read( REG_TX_MEM_INFO ) & TX_MEM_AVAILABLE_MASK;
-
- FreeRTOS_printf( ("SPI_PDC_TX_ERROR %02X\n", ulValue ) );
- }
- break;
-
- case SPI_PDC_RX_ERROR:
- {
- uint32_t ulValue;
- /* TX step11: end TX transfer. */
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
-
- vTaskDelay( 2 ); gpio_set_pin_low( KSZ8851SNL_CSN_GPIO );
- vTaskDelay( 1 ); gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
- vTaskDelay( 1 );
-
- /* Disable asynchronous transfer mode. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_IDLE;
-
- /* TX step12: disable TXQ write access. */
- ksz8851_reg_clrbits( REG_RXQ_CMD, RXQ_START );
-
- //ulValue = ksz8851snl_reset_rx();
- ulValue = ksz8851snl_reinit();
-
- xGMACWaitLS( pdMS_TO_TICKS( 5000UL ) );
-
- FreeRTOS_printf( ("SPI_PDC_RX_ERROR %02X\n", ulValue ) );
- }
- break;
- }
- switch( xMicrelDevice.ul_spi_pdc_status )
- {
- case SPI_PDC_IDLE:
- {
- int txTail = xMicrelDevice.us_tx_tail;
-
- /*
- * ========================== Handle RX ==========================
- */
- if( ( xMicrelDevice.ul_had_intn_interrupt != 0 ) || ( xMicrelDevice.us_pending_frame > 0 ) )
- {
- int rxHead = xMicrelDevice.us_rx_head;
- NetworkBufferDescriptor_t *pxNetworkBuffer;
-#warning try
- xMicrelDevice.ul_had_intn_interrupt = 0;
-
- if( xMicrelDevice.us_pending_frame == 0 )
- {
- uint16_t int_status;
- /* RX step1: read interrupt status for INT_RX flag. */
- int_status = ksz8851_reg_read( REG_INT_STATUS );
-
-
- /* RX step2: disable all interrupts. */
- ksz8851_reg_write( REG_INT_MASK, 0 );
-
- /* RX step3: clear INT_RX flag. */
- ksz8851_reg_setbits( REG_INT_STATUS, INT_RX );
-
- /* RX step4-5: check for received frames. */
- xMicrelDevice.us_pending_frame = ksz8851_reg_read(REG_RX_FRAME_CNT_THRES) >> 8;
- if( xMicrelDevice.us_pending_frame == 0 )
- {
- /* RX step24: enable INT_RX flag. */
- ksz8851_reg_write(REG_INT_MASK, INT_RX);
- return;
- }
- }
-#warning try
- xMicrelDevice.ul_had_intn_interrupt = 0;
-
- /* Now xMicrelDevice.us_pending_frame != 0 */
-
- /* Don't break Micrel state machine, wait for a free descriptor first! */
- if( xMicrelDevice.rx_ready[ rxHead ] != pdFALSE )
- {
- FreeRTOS_printf( ( "ksz8851snl_update: out of free descriptor! [tail=%u head=%u]\n",
- xMicrelDevice.us_rx_tail, rxHead ) );
- return;
- }
- pxNetworkBuffer = xMicrelDevice.rx_buffers[ rxHead ];
-
- if( pxNetworkBuffer == NULL )
- {
- ksz8851snl_rx_populate_queue();
- FreeRTOS_printf( ( "ksz8851snl_update: no buffer set [head=%u]\n", rxHead ) );
- return;
- }
-
- /* RX step6: get RX packet status. */
- fhr_status = ksz8851_reg_read( REG_RX_FHR_STATUS );
- if( ( ( fhr_status & RX_VALID ) == 0 ) || ( ( fhr_status & RX_ERRORS ) != 0 ) )
- {
- ksz8851_reg_setbits(REG_RXQ_CMD, RXQ_CMD_FREE_PACKET);
- FreeRTOS_printf( ( "ksz8851snl_update: RX packet error!\n" ) );
-
- /* RX step4-5: check for received frames. */
- xMicrelDevice.us_pending_frame = ksz8851_reg_read(REG_RX_FRAME_CNT_THRES) >> 8;
- if( xMicrelDevice.us_pending_frame == 0 )
- {
- /* RX step24: enable INT_RX flag. */
- ksz8851_reg_write(REG_INT_MASK, INT_RX);
- }
- ulISREvents |= EMAC_IF_ERR_EVENT;
- }
- else
- {
- size_t xLength;
- /* RX step7: read frame length. */
- xLength = ksz8851_reg_read(REG_RX_FHR_BYTE_CNT) & RX_BYTE_CNT_MASK;
-
- /* RX step8: Drop packet if len is invalid or no descriptor available. */
- if( xLength == 0 )
- {
- ksz8851_reg_setbits( REG_RXQ_CMD, RXQ_CMD_FREE_PACKET );
- FreeRTOS_printf( ( "ksz8851snl_update: RX bad len!\n" ) );
- ulISREvents |= EMAC_IF_ERR_EVENT;
- }
- else
- {
- size_t xReadLength = xLength;
-
- xMicrelDevice.ul_total_rx++;
- /* RX step9: reset RX frame pointer. */
- ksz8851_reg_clrbits(REG_RX_ADDR_PTR, ADDR_PTR_MASK);
-
- /* RX step10: start RXQ read access. */
- ksz8851_reg_setbits(REG_RXQ_CMD, RXQ_START);
- /* RX step11-17: start asynchronous FIFO read operation. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_RX_START;
- gpio_set_pin_low( KSZ8851SNL_CSN_GPIO );
- if( ( xReadLength & ( sizeof( size_t ) - 1 ) ) != 0 )
- {
- xReadLength = ( xReadLength | ( sizeof( size_t ) - 1 ) ) + 1;
- }
-
- /* Pass the buffer minus 2 bytes, see ksz8851snl.c: RXQ_TWOBYTE_OFFSET. */
- ksz8851_fifo_read( pxNetworkBuffer->pucEthernetBuffer - 2, xReadLength );
- /* Remove CRC and update buffer length. */
- xLength -= 4;
- pxNetworkBuffer->xDataLength = xLength;
- /* Wait for SPI interrupt to set status 'SPI_PDC_RX_COMPLETE'. */
- }
- }
- break;
- } /* ul_had_intn_interrupt || us_pending_frame */
- /*
- * ========================== Handle TX ==========================
- */
-
- /* Fetch next packet to be sent. */
- if( ( xMicrelDevice.tx_busy[ txTail ] != pdFALSE ) &&
- ( xMicrelDevice.us_pending_frame == 0 ) &&
- ( xMicrelDevice.ul_had_intn_interrupt == 0 ) )
- {
- NetworkBufferDescriptor_t *pxNetworkBuffer = xMicrelDevice.tx_buffers[ txTail ];
- size_t xLength = pxNetworkBuffer->xDataLength;
- int iIndex = xLength;
-
- xLength = 4 * ( ( xLength + 3 ) / 4 );
- while( iIndex < ( int ) xLength )
- {
- pxNetworkBuffer->pucEthernetBuffer[ iIndex ] = '\0';
- iIndex++;
- }
- pxNetworkBuffer->xDataLength = xLength;
-
- /* TX step1: check if TXQ memory size is available for transmit. */
- txmir = ksz8851_reg_read( REG_TX_MEM_INFO );
- txmir = txmir & TX_MEM_AVAILABLE_MASK;
-
- if( txmir < ( xLength + 8 ) )
- {
- if( wait_tx_space == pdFALSE )
- {
- tx_status = ksz8851_reg_read( REG_TX_STATUS );
- fhr_status = ksz8851_reg_read( REG_RX_FHR_STATUS );
- wait_tx_space = pdTRUE;
- }
- //return;
- rx_debug = 1;
- tx_space = txmir;
- }
- else
- {
- tx_space = txmir;
-
- /* TX step2: disable all interrupts. */
- ksz8851_reg_write( REG_INT_MASK, 0 );
-
- xMicrelDevice.tx_space -= xLength;
-
- /* TX step3: enable TXQ write access. */
- ksz8851_reg_setbits( REG_RXQ_CMD, RXQ_START );
- /* TX step4-8: perform FIFO write operation. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_TX_START;
- xMicrelDevice.tx_cur_buffer = pxNetworkBuffer;
- /* Bring SPI SS low. */
- gpio_set_pin_low( KSZ8851SNL_CSN_GPIO );
- xMicrelDevice.ul_total_tx++;
-
- ksz8851_fifo_write( pxNetworkBuffer->pucEthernetBuffer, xLength, xLength );
- }
- }
- }
- break; /* SPI_PDC_IDLE */
-
- case SPI_PDC_RX_COMPLETE:
- {
- int rxHead = xMicrelDevice.us_rx_head;
- /* RX step18-19: pad with dummy data to keep dword alignment. */
- /* Packet lengths will be rounded up to a multiple of "sizeof size_t". */
-// xLength = xMicrelDevice.rx_buffers[ rxHead ]->xDataLength & 3;
-// if( xLength != 0 )
-// {
-// ksz8851_fifo_dummy( 4 - xLength );
-// }
-
- /* RX step20: end RX transfer. */
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
-
- /* Disable asynchronous transfer mode. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_IDLE;
-
- /* RX step21: end RXQ read access. */
- ksz8851_reg_clrbits(REG_RXQ_CMD, RXQ_START);
-
- /* RX step22-23: update frame count to be read. */
- xMicrelDevice.us_pending_frame -= 1;
-
- /* RX step24: enable INT_RX flag if transfer complete. */
- if( xMicrelDevice.us_pending_frame == 0 )
- {
- ksz8851_reg_write(REG_INT_MASK, INT_RX);
- }
-
- /* Mark descriptor ready to be read. */
- xMicrelDevice.rx_ready[ rxHead ] = pdTRUE;
- if( ++rxHead == MICREL_RX_BUFFERS )
- {
- rxHead = 0;
- }
- xMicrelDevice.us_rx_head = rxHead;
- if( rx_debug != 0 )
- {
- uint32_t txmir;
- rx_debug = 0;
- txmir = ksz8851_reg_read( REG_TX_MEM_INFO );
- txmir = txmir & TX_MEM_AVAILABLE_MASK;
- }
- /* Tell prvEMACHandlerTask that RX packets are available. */
- ulISREvents |= EMAC_IF_RX_EVENT;
- } /* case SPI_PDC_RX_COMPLETE */
- break;
-
- case SPI_PDC_TX_COMPLETE:
- {
- int txTail = xMicrelDevice.us_tx_tail;
- NetworkBufferDescriptor_t *pxNetworkBuffer = xMicrelDevice.tx_buffers[ txTail ];
-
- size_t xLength;
- /* TX step9-10: pad with dummy data to keep dword alignment. */
- /* Not necessary: length is already a multiple of 4. */
- xLength = pxNetworkBuffer->xDataLength & 3;
- if( xLength != 0 )
- {
-// ksz8851_fifo_dummy( 4 - xLength );
- }
-
-// /* TX step11: end TX transfer. */
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
-
- /* Disable asynchronous transfer mode. */
- xMicrelDevice.ul_spi_pdc_status = SPI_PDC_IDLE;
-
- /* TX step12: disable TXQ write access. */
- ksz8851_reg_clrbits( REG_RXQ_CMD, RXQ_START );
-
- xMicrelDevice.tx_space = ksz8851_reg_read( REG_TX_MEM_INFO ) & TX_MEM_AVAILABLE_MASK;
-
- /* TX step12.1: enqueue frame in TXQ. */
- ksz8851_reg_setbits( REG_TXQ_CMD, TXQ_ENQUEUE );
-
- /* RX step13: enable INT_RX flag. */
-// ksz8851_reg_write( REG_INT_MASK, INT_RX );
- /* Buffer sent, free the corresponding buffer and mark descriptor as owned by software. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
-
- xMicrelDevice.tx_buffers[ txTail ] = NULL;
- xMicrelDevice.tx_busy[ txTail ] = pdFALSE;
- if( ++txTail == MICREL_TX_BUFFERS )
- {
- txTail = 0;
- }
-
- xMicrelDevice.us_tx_tail = txTail;
- /* Experiment. */
- //xMicrelDevice.ul_had_intn_interrupt = 1;
- if( xTransmitHandle != NULL )
- {
- xTaskNotifyGive( xTransmitHandle );
- }
-#warning moved downward
- /* RX step13: enable INT_RX flag. */
- ksz8851_reg_write( REG_INT_MASK, INT_RX );
- /* Prevent the EMAC task from sleeping a single time. */
- ulISREvents |= EMAC_IF_TX_EVENT;
- } /* case SPI_PDC_TX_COMPLETE */
- break;
- } /* switch( xMicrelDevice.ul_spi_pdc_status ) */
-}
-
-/**
- * \brief Set up the RX descriptor ring buffers.
- *
- * This function sets up the descriptor list used for RX packets.
- *
- */
-static void ksz8851snl_rx_init()
-{
- uint32_t ul_index = 0;
-
- /* Init pointer index. */
- xMicrelDevice.us_rx_head = 0;
- xMicrelDevice.us_rx_tail = 0;
-
- /* Set up the RX descriptors. */
- for (ul_index = 0; ul_index < MICREL_RX_BUFFERS; ul_index++) {
- xMicrelDevice.rx_buffers[ul_index] = NULL;
- xMicrelDevice.rx_ready[ul_index] = pdFALSE;
- }
-
- /* Build RX buffer and descriptors. */
- ksz8851snl_rx_populate_queue();
-}
-
-/**
- * \brief Set up the TX descriptor ring buffers.
- *
- * This function sets up the descriptor list used for TX packets.
- *
- */
-static void ksz8851snl_tx_init()
-{
- uint32_t ul_index = 0;
-
- /* Init TX index pointer. */
- xMicrelDevice.us_tx_head = 0;
- xMicrelDevice.us_tx_tail = 0;
-
- /* Set up the TX descriptors */
- for( ul_index = 0; ul_index < MICREL_TX_BUFFERS; ul_index++ )
- {
- xMicrelDevice.tx_busy[ul_index] = pdFALSE;
- }
- xMicrelDevice.tx_space = 6144;
-}
-
-/**
- * \brief Initialize ksz8851snl ethernet controller.
- *
- * \note Called from ethernetif_init().
- *
- * \param netif the lwIP network interface structure for this ethernetif.
- */
-static void ksz8851snl_low_level_init( void )
-{
- ksz8851snl_rx_init();
- ksz8851snl_tx_init();
-
- /* Enable NVIC interrupts. */
- NVIC_SetPriority(SPI_IRQn, INT_PRIORITY_SPI);
- NVIC_EnableIRQ(SPI_IRQn);
-
- /* Initialize SPI link. */
- if( ksz8851snl_init() < 0 )
- {
- FreeRTOS_printf( ( "ksz8851snl_low_level_init: failed to initialize the Micrel driver!\n" ) );
- configASSERT(0 == 1);
- }
- memset( xMicrelDevice.pusHashTable, 255, sizeof( xMicrelDevice.pusHashTable ) );
- ksz8851_reg_write( REG_MAC_HASH_0, FreeRTOS_htons( xMicrelDevice.pusHashTable[ 0 ] ) );
- ksz8851_reg_write( REG_MAC_HASH_2, FreeRTOS_htons( xMicrelDevice.pusHashTable[ 1 ] ) );
- ksz8851_reg_write( REG_MAC_HASH_4, FreeRTOS_htons( xMicrelDevice.pusHashTable[ 2 ] ) );
- ksz8851_reg_write( REG_MAC_HASH_6, FreeRTOS_htons( xMicrelDevice.pusHashTable[ 3 ] ) );
-
- /* Initialize interrupt line INTN. */
- configure_intn( INTN_Handler );
-}
-
-/**
- * \brief Use pre-allocated pbuf as DMA source and return the incoming packet.
- *
- * \param netif the lwIP network interface structure for this ethernetif.
- *
- * \return a pbuf filled with the received packet (including MAC header).
- * 0 on memory error.
- */
-static NetworkBufferDescriptor_t *ksz8851snl_low_level_input( void )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer = NULL;
-int rxTail = xMicrelDevice.us_rx_tail;
-
- /* Check that descriptor is owned by software (ie packet received). */
- if( xMicrelDevice.rx_ready[ rxTail ] != pdFALSE )
- {
-
- /* Fetch pre-allocated buffer */
- pxNetworkBuffer = xMicrelDevice.rx_buffers[ rxTail ];
-
- /* Remove this pbuf from its descriptor. */
- xMicrelDevice.rx_buffers[ rxTail ] = NULL;
-
- /* Clears rx_ready and sets rx_buffers. */
- ksz8851snl_rx_populate_queue();
-
- if( ++rxTail == MICREL_RX_BUFFERS )
- {
- rxTail = 0;
- }
- xMicrelDevice.us_rx_tail = rxTail;
- }
-
- return pxNetworkBuffer;
-}
-/*-----------------------------------------------------------*/
-
-static uint32_t prvEMACRxPoll( void )
-{
-NetworkBufferDescriptor_t *pxNetworkBuffer;
-IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-uint32_t ulReturnValue = 0;
-
- for( ;; )
- {
- /* Only for logging. */
- int rxTail = xMicrelDevice.us_rx_tail;
- EthernetHeader_t *pxEthernetHeader;
-
- pxNetworkBuffer = ksz8851snl_low_level_input();
-
- if( pxNetworkBuffer == NULL )
- {
- break;
- }
- pxEthernetHeader = ( EthernetHeader_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-
- if( ( pxEthernetHeader->usFrameType != ipIPv4_FRAME_TYPE ) &&
- ( pxEthernetHeader->usFrameType != ipARP_FRAME_TYPE ) )
- {
- FreeRTOS_printf( ( "Frame type %02X received\n", pxEthernetHeader->usFrameType ) );
- }
- ulReturnValue++;
-
- xRxEvent.pvData = ( void * )pxNetworkBuffer;
- /* Send the descriptor to the IP task for processing. */
- if( xSendEventStructToIPTask( &xRxEvent, 100UL ) != pdTRUE )
- {
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- iptraceETHERNET_RX_EVENT_LOST();
- FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue return packet!\n" ) );
- }
- }
-
- return ulReturnValue;
-}
-/*-----------------------------------------------------------*/
-
-static void prvEMACHandlerTask( void *pvParameters )
-{
-TimeOut_t xPhyTime;
-TickType_t xPhyRemTime;
-TickType_t xLoggingTime;
-UBaseType_t uxLastMinBufferCount = 0;
-UBaseType_t uxCurrentCount;
-BaseType_t xResult = 0;
-uint32_t xStatus;
-const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( EMAC_MAX_BLOCK_TIME_MS );
-#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- UBaseType_t uxLastMinQueueSpace = 0;
-#endif
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- configASSERT( xEMACTaskHandle );
-
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
- xLoggingTime = xTaskGetTickCount();
-
- for( ;; )
- {
- uxCurrentCount = uxGetMinimumFreeNetworkBuffers();
- if( uxLastMinBufferCount != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinBufferCount = uxCurrentCount;
- FreeRTOS_printf( ( "Network buffers: %lu lowest %lu\n",
- uxGetNumberOfFreeNetworkBuffers(), uxCurrentCount ) );
- }
-
- #if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
- {
- uxCurrentCount = uxGetMinimumIPQueueSpace();
- if( uxLastMinQueueSpace != uxCurrentCount )
- {
- /* The logging produced below may be helpful
- while tuning +TCP: see how many buffers are in use. */
- uxLastMinQueueSpace = uxCurrentCount;
- FreeRTOS_printf( ( "Queue space: lowest %lu\n", uxCurrentCount ) );
- }
- }
- #endif /* ipconfigCHECK_IP_QUEUE_SPACE */
-
- /* Run the state-machine of the ksz8851 driver. */
- ksz8851snl_update();
-
- if( ( ulISREvents & EMAC_IF_ALL_EVENT ) == 0 )
- {
- /* No events to process now, wait for the next. */
- ulTaskNotifyTake( pdTRUE, ulMaxBlockTime );
- }
-
- if( ( xTaskGetTickCount() - xLoggingTime ) > 10000 )
- {
- xLoggingTime += 10000;
- FreeRTOS_printf( ( "Now Tx/Rx %7d /%7d\n",
- xMicrelDevice.ul_total_tx, xMicrelDevice.ul_total_rx ) );
- }
-
- if( ( ulISREvents & EMAC_IF_RX_EVENT ) != 0 )
- {
- ulISREvents &= ~EMAC_IF_RX_EVENT;
-
- /* Wait for the EMAC interrupt to indicate that another packet has been
- received. */
- xResult = prvEMACRxPoll();
- }
-
- if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0 )
- {
- /* Future extension: code to release TX buffers if zero-copy is used. */
- ulISREvents &= ~EMAC_IF_TX_EVENT;
- }
-
- if( ( ulISREvents & EMAC_IF_ERR_EVENT ) != 0 )
- {
- /* Future extension: logging about errors that occurred. */
- ulISREvents &= ~EMAC_IF_ERR_EVENT;
- }
-
- if( xResult > 0 )
- {
- /* As long as packets are being received, assume that
- the Link Status is high. */
- ulPHYLinkStatus |= BMSR_LINK_STATUS;
- /* A packet was received. No need to check for the PHY status now,
- but set a timer to check it later on. */
- vTaskSetTimeOutState( &xPhyTime );
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- xResult = 0;
- }
- else if( ( xTaskCheckForTimeOut( &xPhyTime, &xPhyRemTime ) != pdFALSE ) &&
- ( xMicrelDevice.ul_spi_pdc_status == SPI_PDC_IDLE ) )
- {
- /* Check the link status again. */
- xStatus = ulReadMDIO( PHY_REG_01_BMSR );
-
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != ( xStatus & BMSR_LINK_STATUS ) )
- {
- ulPHYLinkStatus = xStatus;
- FreeRTOS_printf( ( "prvEMACHandlerTask: PHY LS now %d\n", ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 ) );
- }
-
- vTaskSetTimeOutState( &xPhyTime );
- if( ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0 )
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_HIGH_CHECK_TIME_MS );
- }
- else
- {
- xPhyRemTime = pdMS_TO_TICKS( PHY_LS_LOW_CHECK_TIME_MS );
- }
- }
- }
-}
-/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.c
deleted file mode 100755
index 9a4001c..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.c
+++ /dev/null
@@ -1,610 +0,0 @@
-/**
- *
- * \file
- *
- * \brief KS8851SNL driver for SAM.
- *
- * Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-/*
- * Support and FAQ: visit Atmel Support
- */
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-
-#include "spi_master.h"
-#include "ksz8851snl.h"
-#include "ksz8851snl_reg.h"
-#include "delay.h"
-#include "pio.h"
-#include "pio_handler.h"
-#include "pdc.h"
-#include "conf_eth.h"
-
-/* Clock polarity. */
-#define SPI_CLK_POLARITY 0
-
-/* Clock phase. */
-#define SPI_CLK_PHASE 1
-
-/* SPI PDC register base. */
-Pdc *g_p_spi_pdc = 0;
-
-int lUDPLoggingPrintf( const char *pcFormatString, ... );
-
-/* Temporary buffer for PDC reception. */
-uint8_t tmpbuf[1536] __attribute__ ((aligned (16)));
-
-union {
- uint64_t ul[2];
- uint8_t uc[16];
-} cmdBuf, respBuf;
-
-void dbg_add_line( const char *pcFormat, ... );
-
-static void spi_clear_ovres( void );
-
-/**
- * \brief Read register content, set bitmask and write back to register.
- *
- * \param reg the register address to modify.
- * \param bits_to_set bitmask to apply.
- */
-void ksz8851_reg_setbits(uint16_t reg, uint16_t bits_to_set)
-{
- uint16_t temp;
-
- temp = ksz8851_reg_read(reg);
- temp |= bits_to_set;
- ksz8851_reg_write(reg, temp);
-}
-
-/**
- * \brief Read register content, clear bitmask and write back to register.
- *
- * \param reg the register address to modify.
- * \param bits_to_set bitmask to apply.
- */
-void ksz8851_reg_clrbits(uint16_t reg, uint16_t bits_to_clr)
-{
- uint16_t temp;
-
- temp = ksz8851_reg_read(reg);
- temp &= ~(uint32_t) bits_to_clr;
- ksz8851_reg_write(reg, temp);
-}
-
-/**
- * \brief Configure the INTN interrupt.
- */
-void configure_intn(void (*p_handler) (uint32_t, uint32_t))
-{
-// gpio_configure_pin(KSZ8851SNL_INTN_GPIO, PIO_INPUT);
-// pio_set_input(PIOA, PIO_PA11_IDX, PIO_PULLUP);
-
- /* Configure PIO clock. */
- pmc_enable_periph_clk(INTN_ID);
-
- /* Adjust PIO debounce filter parameters, uses 10 Hz filter. */
- pio_set_debounce_filter(INTN_PIO, INTN_PIN_MSK, 10);
-
- /* Initialize PIO interrupt handlers, see PIO definition in board.h. */
- pio_handler_set(INTN_PIO, INTN_ID, INTN_PIN_MSK,
- INTN_ATTR, p_handler);
-
- /* Enable NVIC interrupts. */
- NVIC_SetPriority(INTN_IRQn, INT_PRIORITY_PIO);
- NVIC_EnableIRQ((IRQn_Type)INTN_ID);
-
- /* Enable PIO interrupts. */
- pio_enable_interrupt(INTN_PIO, INTN_PIN_MSK);
-}
-
-/**
- * \brief Read a register value.
- *
- * \param reg the register address to modify.
- *
- * \return the register value.
- */
-uint16_t ksz8851_reg_read(uint16_t reg)
-{
-pdc_packet_t g_pdc_spi_tx_packet;
-pdc_packet_t g_pdc_spi_rx_packet;
-uint16_t cmd = 0;
-uint16_t res = 0;
-int iTryCount = 3;
-
- while( iTryCount-- > 0 )
- {
- uint32_t ulStatus;
-
- spi_clear_ovres();
- /* Move register address to cmd bits 9-2, make 32-bit address. */
- cmd = (reg << 2) & REG_ADDR_MASK;
-
- /* Last 2 bits still under "don't care bits" handled with byte enable. */
- /* Select byte enable for command. */
- if (reg & 2) {
- /* Odd word address writes bytes 2 and 3 */
- cmd |= (0xc << 10);
- } else {
- /* Even word address write bytes 0 and 1 */
- cmd |= (0x3 << 10);
- }
-
- /* Add command read code. */
- cmd |= CMD_READ;
- cmdBuf.uc[0] = cmd >> 8;
- cmdBuf.uc[1] = cmd & 0xff;
- cmdBuf.uc[2] = CONFIG_SPI_MASTER_DUMMY;
- cmdBuf.uc[3] = CONFIG_SPI_MASTER_DUMMY;
-
- /* Prepare PDC transfer. */
- g_pdc_spi_tx_packet.ul_addr = (uint32_t) cmdBuf.uc;
- g_pdc_spi_tx_packet.ul_size = 4;
- g_pdc_spi_rx_packet.ul_addr = (uint32_t) tmpbuf;
- g_pdc_spi_rx_packet.ul_size = 4;
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, NULL);
- pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, NULL);
- gpio_set_pin_low(KSZ8851SNL_CSN_GPIO);
-
- spi_disable_interrupt( KSZ8851SNL_SPI, ~0ul );
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
- for( ;; )
- {
- ulStatus = spi_read_status( KSZ8851SNL_SPI );
- if( ( ulStatus & ( SPI_SR_OVRES | SPI_SR_ENDRX ) ) != 0 )
- {
- break;
- }
- }
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
- if( ( ulStatus & SPI_SR_OVRES ) == 0 )
- {
- break;
- }
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- lUDPLoggingPrintf( "ksz8851_reg_read: SPI_SR_OVRES\n" );
- }
-
- res = (tmpbuf[3] << 8) | tmpbuf[2];
- return res;
-}
-
-/**
- * \brief Write a register value.
- *
- * \param reg the register address to modify.
- * \param wrdata the new register value.
- */
-void ksz8851_reg_write(uint16_t reg, uint16_t wrdata)
-{
-pdc_packet_t g_pdc_spi_tx_packet;
-pdc_packet_t g_pdc_spi_rx_packet;
-uint16_t cmd = 0;
-int iTryCount = 3;
-
- while( iTryCount-- > 0 )
- {
- uint32_t ulStatus;
-
-
- spi_clear_ovres();
- /* Move register address to cmd bits 9-2, make 32-bit address. */
- cmd = (reg << 2) & REG_ADDR_MASK;
-
- /* Last 2 bits still under "don't care bits" handled with byte enable. */
- /* Select byte enable for command. */
- if (reg & 2) {
- /* Odd word address writes bytes 2 and 3 */
- cmd |= (0xc << 10);
- } else {
- /* Even word address write bytes 0 and 1 */
- cmd |= (0x3 << 10);
- }
-
- /* Add command write code. */
- cmd |= CMD_WRITE;
- cmdBuf.uc[0] = cmd >> 8;
- cmdBuf.uc[1] = cmd & 0xff;
- cmdBuf.uc[2] = wrdata & 0xff;
- cmdBuf.uc[3] = wrdata >> 8;
-
- /* Prepare PDC transfer. */
- g_pdc_spi_tx_packet.ul_addr = (uint32_t) cmdBuf.uc;
- g_pdc_spi_tx_packet.ul_size = 4;
- g_pdc_spi_rx_packet.ul_addr = (uint32_t) tmpbuf;
- g_pdc_spi_rx_packet.ul_size = 4;
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, NULL);
- pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, NULL);
- gpio_set_pin_low(KSZ8851SNL_CSN_GPIO);
-
- spi_disable_interrupt( KSZ8851SNL_SPI, ~0ul );
-
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
- for( ;; )
- {
- ulStatus = spi_read_status( KSZ8851SNL_SPI );
- if( ( ulStatus & ( SPI_SR_OVRES | SPI_SR_ENDRX ) ) != 0 )
- {
- break;
- }
- }
- gpio_set_pin_high( KSZ8851SNL_CSN_GPIO );
- if( ( ulStatus & SPI_SR_OVRES ) == 0 )
- {
- break;
- }
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- lUDPLoggingPrintf( "ksz8851_reg_write: SPI_SR_OVRES\n" );
- }
-}
-
-static void spi_clear_ovres( void )
-{
-volatile uint32_t rc;
- rc = KSZ8851SNL_SPI->SPI_RDR;
-
- spi_read_status( KSZ8851SNL_SPI );
-}
-
-/**
- * \brief Read internal fifo buffer.
- *
- * \param buf the buffer to store the data from the fifo buffer.
- * \param len the amount of data to read.
- */
-void ksz8851_fifo_read(uint8_t *buf, uint32_t len)
-{
- pdc_packet_t g_pdc_spi_tx_packet;
- pdc_packet_t g_pdc_spi_rx_packet;
- pdc_packet_t g_pdc_spi_tx_npacket;
- pdc_packet_t g_pdc_spi_rx_npacket;
-
- memset( cmdBuf.uc, '\0', sizeof cmdBuf );
- cmdBuf.uc[0] = FIFO_READ;
- spi_clear_ovres();
-
- /* Prepare PDC transfer. */
- g_pdc_spi_tx_packet.ul_addr = (uint32_t) cmdBuf.uc;
- g_pdc_spi_tx_packet.ul_size = 9;
- g_pdc_spi_rx_packet.ul_addr = (uint32_t) respBuf.uc;
- g_pdc_spi_rx_packet.ul_size = 9;
-
- g_pdc_spi_tx_npacket.ul_addr = (uint32_t) buf;
- g_pdc_spi_tx_npacket.ul_size = len;
- g_pdc_spi_rx_npacket.ul_addr = (uint32_t) buf;
- g_pdc_spi_rx_npacket.ul_size = len;
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, &g_pdc_spi_tx_npacket);
- pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, &g_pdc_spi_rx_npacket);
-
-spi_enable_interrupt(KSZ8851SNL_SPI, SPI_IER_RXBUFF | SPI_IER_OVRES);
-
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
-}
-
-/**
- * \brief Write internal fifo buffer.
- *
- * \param buf the buffer to send to the fifo buffer.
- * \param ulActualLength the total amount of data to write.
- * \param ulFIFOLength the size of the first pbuf to write from the pbuf chain.
- */
-void ksz8851_fifo_write(uint8_t *buf, uint32_t ulActualLength, uint32_t ulFIFOLength)
-{
- static uint8_t frameID = 0;
-
- pdc_packet_t g_pdc_spi_tx_packet;
- pdc_packet_t g_pdc_spi_rx_packet;
- pdc_packet_t g_pdc_spi_tx_npacket;
- pdc_packet_t g_pdc_spi_rx_npacket;
-
- /* Prepare control word and byte count. */
- cmdBuf.uc[0] = FIFO_WRITE;
- cmdBuf.uc[1] = frameID++ & 0x3f;
- cmdBuf.uc[2] = 0;
- cmdBuf.uc[3] = ulActualLength & 0xff;
- cmdBuf.uc[4] = ulActualLength >> 8;
-
- spi_clear_ovres();
-
- /* Prepare PDC transfer. */
- g_pdc_spi_tx_packet.ul_addr = (uint32_t) cmdBuf.uc;
- g_pdc_spi_tx_packet.ul_size = 5;
-
- g_pdc_spi_rx_packet.ul_addr = (uint32_t) respBuf.uc;
- g_pdc_spi_rx_packet.ul_size = 5;
-
- g_pdc_spi_tx_npacket.ul_addr = (uint32_t) buf;
- g_pdc_spi_tx_npacket.ul_size = ulFIFOLength;
-
- g_pdc_spi_rx_npacket.ul_addr = (uint32_t) tmpbuf;
- g_pdc_spi_rx_npacket.ul_size = ulFIFOLength;
-
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, &g_pdc_spi_tx_npacket);
- #if( TX_USES_RECV == 1 )
- pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, &g_pdc_spi_rx_npacket);
- spi_enable_interrupt(KSZ8851SNL_SPI, SPI_IER_ENDRX | SPI_IER_OVRES);
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
- #else
- spi_enable_interrupt(KSZ8851SNL_SPI, SPI_SR_TXBUFE | SPI_IER_OVRES);
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_TXTEN);
- #endif
-}
-
-/**
- * \brief Write dummy data to the internal fifo buffer.
- *
- * \param len the amount of dummy data to write.
- */
-void ksz8851_fifo_dummy(uint32_t len)
-{
- pdc_packet_t g_pdc_spi_tx_packet;
- pdc_packet_t g_pdc_spi_rx_packet;
-
- /* Prepare PDC transfer. */
- g_pdc_spi_tx_packet.ul_addr = (uint32_t) tmpbuf;
- g_pdc_spi_tx_packet.ul_size = len;
- g_pdc_spi_rx_packet.ul_addr = (uint32_t) tmpbuf;
- g_pdc_spi_rx_packet.ul_size = len;
- pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS);
- pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, NULL);
- pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, NULL);
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
-
- while (!(spi_read_status(KSZ8851SNL_SPI) & SPI_SR_ENDRX))
- ;
-}
-
-void ksz8851snl_set_registers(void)
-{
- /* Init step2-4: write QMU MAC address (low, middle then high). */
- ksz8851_reg_write(REG_MAC_ADDR_0, (ETHERNET_CONF_ETHADDR4 << 8) | ETHERNET_CONF_ETHADDR5);
- ksz8851_reg_write(REG_MAC_ADDR_2, (ETHERNET_CONF_ETHADDR2 << 8) | ETHERNET_CONF_ETHADDR3);
- ksz8851_reg_write(REG_MAC_ADDR_4, (ETHERNET_CONF_ETHADDR0 << 8) | ETHERNET_CONF_ETHADDR1);
-
- /* Init step5: enable QMU Transmit Frame Data Pointer Auto Increment. */
- ksz8851_reg_write(REG_TX_ADDR_PTR, ADDR_PTR_AUTO_INC);
-
- /* Init step6: configure QMU transmit control register. */
- ksz8851_reg_write(REG_TX_CTRL,
- TX_CTRL_ICMP_CHECKSUM |
- TX_CTRL_UDP_CHECKSUM |
- TX_CTRL_TCP_CHECKSUM |
- TX_CTRL_IP_CHECKSUM |
- TX_CTRL_FLOW_ENABLE |
- TX_CTRL_PAD_ENABLE |
- TX_CTRL_CRC_ENABLE
- );
-
- /* Init step7: enable QMU Receive Frame Data Pointer Auto Increment. */
- ksz8851_reg_write(REG_RX_ADDR_PTR, ADDR_PTR_AUTO_INC);
-
- /* Init step8: configure QMU Receive Frame Threshold for one frame. */
- ksz8851_reg_write(REG_RX_FRAME_CNT_THRES, 1);
-
- /* Init step9: configure QMU receive control register1. */
- ksz8851_reg_write(REG_RX_CTRL1,
- RX_CTRL_UDP_CHECKSUM |
- RX_CTRL_TCP_CHECKSUM |
- RX_CTRL_IP_CHECKSUM |
- RX_CTRL_MAC_FILTER |
- RX_CTRL_FLOW_ENABLE |
- RX_CTRL_BROADCAST |
- RX_CTRL_ALL_MULTICAST|
- RX_CTRL_UNICAST);
-// ksz8851_reg_write(REG_RX_CTRL1,
-// RX_CTRL_UDP_CHECKSUM |
-// RX_CTRL_TCP_CHECKSUM |
-// RX_CTRL_IP_CHECKSUM |
-// RX_CTRL_FLOW_ENABLE |
-// RX_CTRL_PROMISCUOUS);
-
- ksz8851_reg_write(REG_RX_CTRL2,
- RX_CTRL_IPV6_UDP_NOCHECKSUM |
- RX_CTRL_UDP_LITE_CHECKSUM |
- RX_CTRL_ICMP_CHECKSUM |
- RX_CTRL_BURST_LEN_FRAME);
-
-
-//#define RXQ_TWOBYTE_OFFSET (0x0200) /* Enable adding 2-byte before frame header for IP aligned with DWORD */
-#warning Remember to try the above option to get a 2-byte offset
-
- /* Init step11: configure QMU receive queue: trigger INT and auto-dequeue frame. */
- ksz8851_reg_write( REG_RXQ_CMD, RXQ_CMD_CNTL | RXQ_TWOBYTE_OFFSET );
-
- /* Init step12: adjust SPI data output delay. */
- ksz8851_reg_write(REG_BUS_CLOCK_CTRL, BUS_CLOCK_166 | BUS_CLOCK_DIVIDEDBY_1);
-
- /* Init step13: restart auto-negotiation. */
- ksz8851_reg_setbits(REG_PORT_CTRL, PORT_AUTO_NEG_RESTART);
-
- /* Init step13.1: force link in half duplex if auto-negotiation failed. */
- if ((ksz8851_reg_read(REG_PORT_CTRL) & PORT_AUTO_NEG_RESTART) != PORT_AUTO_NEG_RESTART)
- {
- ksz8851_reg_clrbits(REG_PORT_CTRL, PORT_FORCE_FULL_DUPLEX);
- }
-
- /* Init step14: clear interrupt status. */
- ksz8851_reg_write(REG_INT_STATUS, 0xFFFF);
-
- /* Init step15: set interrupt mask. */
- ksz8851_reg_write(REG_INT_MASK, INT_RX);
-
- /* Init step16: enable QMU Transmit. */
- ksz8851_reg_setbits(REG_TX_CTRL, TX_CTRL_ENABLE);
-
- /* Init step17: enable QMU Receive. */
- ksz8851_reg_setbits(REG_RX_CTRL1, RX_CTRL_ENABLE);
-}
-/**
- * \brief KSZ8851SNL initialization function.
- *
- * \return 0 on success, 1 on communication error.
- */
-uint32_t ksz8851snl_init(void)
-{
-uint32_t count = 10;
-uint16_t dev_id = 0;
-uint8_t id_ok = 0;
-
- /* Configure the SPI peripheral. */
- spi_enable_clock(KSZ8851SNL_SPI);
- spi_disable(KSZ8851SNL_SPI);
- spi_reset(KSZ8851SNL_SPI);
- spi_set_master_mode(KSZ8851SNL_SPI);
- spi_disable_mode_fault_detect(KSZ8851SNL_SPI);
- spi_set_peripheral_chip_select_value(KSZ8851SNL_SPI, ~(uint32_t)(1UL << KSZ8851SNL_CS_PIN));
-spi_set_fixed_peripheral_select(KSZ8851SNL_SPI);
-//spi_disable_peripheral_select_decode(KSZ8851SNL_SPI);
-
- spi_set_clock_polarity(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN, SPI_CLK_POLARITY);
- spi_set_clock_phase(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN, SPI_CLK_PHASE);
- spi_set_bits_per_transfer(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN,
- SPI_CSR_BITS_8_BIT);
- spi_set_baudrate_div(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN, (sysclk_get_cpu_hz() / KSZ8851SNL_CLOCK_SPEED));
-// spi_set_transfer_delay(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN, CONFIG_SPI_MASTER_DELAY_BS,
-// CONFIG_SPI_MASTER_DELAY_BCT);
-
-
- spi_set_transfer_delay(KSZ8851SNL_SPI, KSZ8851SNL_CS_PIN, 0, 0);
-
- spi_enable(KSZ8851SNL_SPI);
-
- /* Get pointer to UART PDC register base. */
- g_p_spi_pdc = spi_get_pdc_base(KSZ8851SNL_SPI);
- pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
-
- /* Control RSTN and CSN pin from the driver. */
- gpio_configure_pin(KSZ8851SNL_CSN_GPIO, KSZ8851SNL_CSN_FLAGS);
- gpio_set_pin_high(KSZ8851SNL_CSN_GPIO);
- gpio_configure_pin(KSZ8851SNL_RSTN_GPIO, KSZ8851SNL_RSTN_FLAGS);
-
- /* Reset the Micrel in a proper state. */
- while( count-- )
- {
- /* Perform hardware reset with respect to the reset timing from the datasheet. */
- gpio_set_pin_low(KSZ8851SNL_RSTN_GPIO);
- vTaskDelay(2);
- gpio_set_pin_high(KSZ8851SNL_RSTN_GPIO);
- vTaskDelay(2);
-
- /* Init step1: read chip ID. */
- dev_id = ksz8851_reg_read(REG_CHIP_ID);
- if( ( dev_id & 0xFFF0 ) == CHIP_ID_8851_16 )
- {
- id_ok = 1;
- break;
- }
- }
- if( id_ok != 0 )
- {
- ksz8851snl_set_registers();
- }
-
- return id_ok ? 1 : -1;
-}
-
-uint32_t ksz8851snl_reinit(void)
-{
-uint32_t count = 10;
-uint16_t dev_id = 0;
-uint8_t id_ok = 0;
- /* Reset the Micrel in a proper state. */
- while( count-- )
- {
- /* Perform hardware reset with respect to the reset timing from the datasheet. */
- gpio_set_pin_low(KSZ8851SNL_RSTN_GPIO);
- vTaskDelay(2);
- gpio_set_pin_high(KSZ8851SNL_RSTN_GPIO);
- vTaskDelay(2);
-
- /* Init step1: read chip ID. */
- dev_id = ksz8851_reg_read(REG_CHIP_ID);
- if( ( dev_id & 0xFFF0 ) == CHIP_ID_8851_16 )
- {
- id_ok = 1;
- break;
- }
- }
- if( id_ok != 0 )
- {
- ksz8851snl_set_registers();
- }
-
- return id_ok ? 1 : -1;
-}
-
-uint32_t ksz8851snl_reset_rx( void )
-{
-uint16_t usValue;
-
- usValue = ksz8851_reg_read(REG_RX_CTRL1);
-
- usValue &= ~( ( uint16_t ) RX_CTRL_ENABLE | RX_CTRL_FLUSH_QUEUE );
-
- ksz8851_reg_write( REG_RX_CTRL1, usValue ); vTaskDelay( 2 );
- ksz8851_reg_write( REG_RX_CTRL1, usValue | RX_CTRL_FLUSH_QUEUE ); vTaskDelay( 1 );
- ksz8851_reg_write( REG_RX_CTRL1, usValue ); vTaskDelay( 1 );
- ksz8851_reg_write( REG_RX_CTRL1, usValue | RX_CTRL_ENABLE ); vTaskDelay( 1 );
-
- return ( uint32_t )usValue;
-}
-
-uint32_t ksz8851snl_reset_tx( void )
-{
-uint16_t usValue;
-
- usValue = ksz8851_reg_read( REG_TX_CTRL );
-
- usValue &= ~( ( uint16_t ) TX_CTRL_ENABLE | TX_CTRL_FLUSH_QUEUE );
-
- ksz8851_reg_write( REG_TX_CTRL, usValue ); vTaskDelay( 2 );
- ksz8851_reg_write( REG_TX_CTRL, usValue | TX_CTRL_FLUSH_QUEUE ); vTaskDelay( 1 );
- ksz8851_reg_write( REG_TX_CTRL, usValue ); vTaskDelay( 1 );
- ksz8851_reg_write( REG_TX_CTRL, usValue | TX_CTRL_ENABLE ); vTaskDelay( 1 );
-
- return ( uint32_t )usValue;
-}
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.h
deleted file mode 100755
index 30b1cc5..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- *
- * \file
- *
- * \brief KS8851SNL driver for SAM.
- *
- * Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-/*
- * Support and FAQ: visit Atmel Support
- */
-
-#ifndef KSZ8851SNL_H_INCLUDED
-#define KSZ8851SNL_H_INCLUDED
-
-#include "gpio.h"
-
-void configure_intn(void (*p_handler) (uint32_t, uint32_t));
-void ksz8851_reg_setbits(uint16_t reg, uint16_t bits_to_set);
-void ksz8851_reg_clrbits(uint16_t reg, uint16_t bits_to_clr);
-void ksz8851_fifo_read(uint8_t *buf, uint32_t len);
-void ksz8851_fifo_write(uint8_t *buf, uint32_t ulActualLength, uint32_t ulFIFOLength);
-void ksz8851_fifo_dummy(uint32_t len);
-void ksz8851_reg_write(uint16_t reg, uint16_t wrdata);
-uint16_t ksz8851_reg_read(uint16_t reg);
-uint32_t ksz8851snl_init(void);
-uint32_t ksz8851snl_reinit(void);
-
-uint32_t ksz8851snl_reset_rx( void );
-uint32_t ksz8851snl_reset_tx( void );
-
-#endif /* KSZ8851SNL_H_INCLUDED */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl_reg.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl_reg.h
deleted file mode 100755
index 58ce6b0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/ksz8851snl_reg.h
+++ /dev/null
@@ -1,473 +0,0 @@
-/**
- *
- * \file
- *
- * \brief KS8851SNL registers definitions.
- *
- * Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
-/*
- * Support and FAQ: visit Atmel Support
- */
-
-#ifndef KSZ8851SNL_REG_H_INCLUDED
-#define KSZ8851SNL_REG_H_INCLUDED
-
-#define REG_ADDR_MASK (0x3F0) /* Register address mask */
-#define OPCODE_MASK (3 << 14)
-#define CMD_READ (0 << 14)
-#define CMD_WRITE (1 << 14)
-#define FIFO_READ (0x80)
-#define FIFO_WRITE (0xC0)
-
-/*
- * MAC Registers
- * (Offset 0x00 - 0x25)
- */
-#define REG_BUS_ERROR_STATUS (0x06) /* BESR */
-#define BUS_ERROR_IBEC (0x8000)
-#define BUS_ERROR_IBECV_MASK (0x7800) /* Default IPSec clock at 166Mhz */
-
-#define REG_CHIP_CFG_STATUS (0x08) /* CCFG */
-#define LITTLE_ENDIAN_BUS_MODE (0x0400) /* Bus in little endian mode */
-#define EEPROM_PRESENCE (0x0200) /* External EEPROM is used */
-#define SPI_BUS_MODE (0x0100) /* In SPI bus mode */
-#define DATA_BUS_8BIT (0x0080) /* In 8-bit bus mode operation */
-#define DATA_BUS_16BIT (0x0040) /* In 16-bit bus mode operation */
-#define DATA_BUS_32BIT (0x0020) /* In 32-bit bus mode operation */
-#define MULTIPLEX_MODE (0x0010) /* Data and address bus are shared */
-#define CHIP_PACKAGE_128PIN (0x0008) /* 128-pin package */
-#define CHIP_PACKAGE_80PIN (0x0004) /* 80-pin package */
-#define CHIP_PACKAGE_48PIN (0x0002) /* 48-pin package */
-#define CHIP_PACKAGE_32PIN (0x0001) /* 32-pin package for SPI host interface only */
-
-#define REG_MAC_ADDR_0 (0x10) /* MARL */
-#define REG_MAC_ADDR_1 (0x11) /* MARL */
-#define REG_MAC_ADDR_2 (0x12) /* MARM */
-#define REG_MAC_ADDR_3 (0x13) /* MARM */
-#define REG_MAC_ADDR_4 (0x14) /* MARH */
-#define REG_MAC_ADDR_5 (0x15) /* MARH */
-
-#define REG_BUS_CLOCK_CTRL (0x20) /* OBCR */
-#define BUS_CLOCK_166 (0x0004) /* 166 MHz on-chip bus clock (defaul is 125MHz) */
-#define BUS_CLOCK_DIVIDEDBY_5 (0x0003) /* Bus clock devided by 5 */
-#define BUS_CLOCK_DIVIDEDBY_3 (0x0002) /* Bus clock devided by 3 */
-#define BUS_CLOCK_DIVIDEDBY_2 (0x0001) /* Bus clock devided by 2 */
-#define BUS_CLOCK_DIVIDEDBY_1 (0x0000) /* Bus clock devided by 1 */
-#define BUS_CLOCK_DIVIDED_MASK (0x0003) /* Bus clock devider mask */
-
-#define BUS_SPEED_166_MHZ (0x0004) /* Set bus speed to 166 MHz */
-#define BUS_SPEED_125_MHZ (0x0000) /* Set bus speed to 125 MHz */
-#define BUS_SPEED_83_MHZ (0x0005) /* Set bus speed to 83 MHz (166/2)*/
-#define BUS_SPEED_62_5_MHZ (0x0001) /* Set bus speed to 62.5 MHz (125/2) */
-#define BUS_SPEED_53_3_MHZ (0x0006) /* Set bus speed to 53.3 MHz (166/3) */
-#define BUS_SPEED_41_7_MHZ (0x0002) /* Set bus speed to 41.67 MHz (125/3) */
-#define BUS_SPEED_33_2_MHZ (0x0007) /* Set bus speed to 33.2 MHz (166/5) */
-#define BUS_SPEED_25_MHZ (0x0003) /* Set bus speed to 25 MHz (125/5) */
-
-#define REG_EEPROM_CTRL (0x22) /* EEPCR */
-#define EEPROM_ACCESS_ENABLE (0x0010) /* Enable software to access EEPROM through bit 3 to bit 0 */
-#define EEPROM_DATA_IN (0x0008) /* Data receive from EEPROM (EEDI pin) */
-#define EEPROM_DATA_OUT (0x0004) /* Data transmit to EEPROM (EEDO pin) */
-#define EEPROM_SERIAL_CLOCK (0x0002) /* Serial clock (EESK pin) */
-#define EEPROM_CHIP_SELECT (0x0001) /* EEPROM chip select (EECS pin) */
-
-#define REG_MEM_BIST_INFO (0x24) /* MBIR */
-#define TX_MEM_TEST_FINISHED (0x1000) /* TX memeory BIST test finish */
-#define TX_MEM_TEST_FAILED (0x0800) /* TX memory BIST test fail */
-#define TX_MEM_TEST_FAILED_COUNT (0x0700) /* TX memory BIST test fail count */
-#define RX_MEM_TEST_FINISHED (0x0010) /* RX memory BIST test finish */
-#define RX_MEM_TEST_FAILED (0x0008) /* RX memory BIST test fail */
-#define RX_MEM_TEST_FAILED_COUNT (0x0003) /* RX memory BIST test fail count */
-
-#define REG_RESET_CTRL (0x26) /* GRR */
-#define QMU_SOFTWARE_RESET (0x0002) /* QMU soft reset (clear TxQ, RxQ) */
-#define GLOBAL_SOFTWARE_RESET (0x0001) /* Global soft reset (PHY, MAC, QMU) */
-
-/*
- * Wake On Lan Control Registers
- * (Offset 0x2A - 0x6B)
- */
-#define REG_WOL_CTRL (0x2A) /* WFCR */
-#define WOL_MAGIC_ENABLE (0x0080) /* Enable the magic packet pattern detection */
-#define WOL_FRAME3_ENABLE (0x0008) /* Enable the wake up frame 3 pattern detection */
-#define WOL_FRAME2_ENABLE (0x0004) /* Enable the wake up frame 2 pattern detection */
-#define WOL_FRAME1_ENABLE (0x0002) /* Enable the wake up frame 1 pattern detection */
-#define WOL_FRAME0_ENABLE (0x0001) /* Enable the wake up frame 0 pattern detection */
-
-#define REG_WOL_FRAME0_CRC0 (0x30) /* WF0CRC0 */
-#define REG_WOL_FRAME0_CRC1 (0x32) /* WF0CRC1 */
-#define REG_WOL_FRAME0_BYTE_MASK0 (0x34) /* WF0BM0 */
-#define REG_WOL_FRAME0_BYTE_MASK1 (0x36) /* WF0BM1 */
-#define REG_WOL_FRAME0_BYTE_MASK2 (0x38) /* WF0BM2 */
-#define REG_WOL_FRAME0_BYTE_MASK3 (0x3A) /* WF0BM3 */
-
-#define REG_WOL_FRAME1_CRC0 (0x40) /* WF1CRC0 */
-#define REG_WOL_FRAME1_CRC1 (0x42) /* WF1CRC1 */
-#define REG_WOL_FRAME1_BYTE_MASK0 (0x44) /* WF1BM0 */
-#define REG_WOL_FRAME1_BYTE_MASK1 (0x46) /* WF1BM1 */
-#define REG_WOL_FRAME1_BYTE_MASK2 (0x48) /* WF1BM2 */
-#define REG_WOL_FRAME1_BYTE_MASK3 (0x4A) /* WF1BM3 */
-
-#define REG_WOL_FRAME2_CRC0 (0x50) /* WF2CRC0 */
-#define REG_WOL_FRAME2_CRC1 (0x52) /* WF2CRC1 */
-#define REG_WOL_FRAME2_BYTE_MASK0 (0x54) /* WF2BM0 */
-#define REG_WOL_FRAME2_BYTE_MASK1 (0x56) /* WF2BM1 */
-#define REG_WOL_FRAME2_BYTE_MASK2 (0x58) /* WF2BM2 */
-#define REG_WOL_FRAME2_BYTE_MASK3 (0x5A) /* WF2BM3 */
-
-#define REG_WOL_FRAME3_CRC0 (0x60) /* WF3CRC0 */
-#define REG_WOL_FRAME3_CRC1 (0x62) /* WF3CRC1 */
-#define REG_WOL_FRAME3_BYTE_MASK0 (0x64) /* WF3BM0 */
-#define REG_WOL_FRAME3_BYTE_MASK1 (0x66) /* WF3BM1 */
-#define REG_WOL_FRAME3_BYTE_MASK2 (0x68) /* WF3BM2 */
-#define REG_WOL_FRAME3_BYTE_MASK3 (0x6A) /* WF3BM3 */
-
-/*
- * Transmit/Receive Control Registers
- * (Offset 0x70 - 0x9F)
- */
-
-/* Transmit Frame Header */
-#define REG_QDR_DUMMY (0x00) /* Dummy address to access QMU RxQ, TxQ */
-#define TX_CTRL_INTERRUPT_ON (0x8000) /* Transmit Interrupt on Completion */
-
-#define REG_TX_CTRL (0x70) /* TXCR */
-#define TX_CTRL_ICMP_CHECKSUM (0x0100) /* Enable ICMP frame checksum generation */
-#define TX_CTRL_UDP_CHECKSUM (0x0080) /* Enable UDP frame checksum generation */
-#define TX_CTRL_TCP_CHECKSUM (0x0040) /* Enable TCP frame checksum generation */
-#define TX_CTRL_IP_CHECKSUM (0x0020) /* Enable IP frame checksum generation */
-#define TX_CTRL_FLUSH_QUEUE (0x0010) /* Clear transmit queue, reset tx frame pointer */
-#define TX_CTRL_FLOW_ENABLE (0x0008) /* Enable transmit flow control */
-#define TX_CTRL_PAD_ENABLE (0x0004) /* Eanble adding a padding to a packet shorter than 64 bytes */
-#define TX_CTRL_CRC_ENABLE (0x0002) /* Enable adding a CRC to the end of transmit frame */
-#define TX_CTRL_ENABLE (0x0001) /* Enable tranmsit */
-
-#define REG_TX_STATUS (0x72) /* TXSR */
-#define TX_STAT_LATE_COL (0x2000) /* Tranmsit late collision occurs */
-#define TX_STAT_MAX_COL (0x1000) /* Tranmsit maximum collision is reached */
-#define TX_FRAME_ID_MASK (0x003F) /* Transmit frame ID mask */
-#define TX_STAT_ERRORS ( TX_STAT_MAX_COL | TX_STAT_LATE_COL )
-
-#define REG_RX_CTRL1 (0x74) /* RXCR1 */
-#define RX_CTRL_FLUSH_QUEUE (0x8000) /* Clear receive queue, reset rx frame pointer */
-#define RX_CTRL_UDP_CHECKSUM (0x4000) /* Enable UDP frame checksum verification */
-#define RX_CTRL_TCP_CHECKSUM (0x2000) /* Enable TCP frame checksum verification */
-#define RX_CTRL_IP_CHECKSUM (0x1000) /* Enable IP frame checksum verification */
-#define RX_CTRL_MAC_FILTER (0x0800) /* Receive with address that pass MAC address filtering */
-#define RX_CTRL_FLOW_ENABLE (0x0400) /* Enable receive flow control */
-#define RX_CTRL_BAD_PACKET (0x0200) /* Eanble receive CRC error frames */
-#define RX_CTRL_MULTICAST (0x0100) /* Receive multicast frames that pass the CRC hash filtering */
-#define RX_CTRL_BROADCAST (0x0080) /* Receive all the broadcast frames */
-#define RX_CTRL_ALL_MULTICAST (0x0040) /* Receive all the multicast frames (including broadcast frames) */
-#define RX_CTRL_UNICAST (0x0020) /* Receive unicast frames that match the device MAC address */
-#define RX_CTRL_PROMISCUOUS (0x0010) /* Receive all incoming frames, regardless of frame's DA */
-#define RX_CTRL_STRIP_CRC (0x0008) /* Enable strip CRC on the received frames */
-#define RX_CTRL_INVERSE_FILTER (0x0002) /* Receive with address check in inverse filtering mode */
-#define RX_CTRL_ENABLE (0x0001) /* Enable receive */
-
-/* Address filtering scheme mask */
-#define RX_CTRL_FILTER_MASK ( RX_CTRL_INVERSE_FILTER | RX_CTRL_PROMISCUOUS | RX_CTRL_MULTICAST | RX_CTRL_MAC_FILTER )
-
-#define REG_RX_CTRL2 (0x76) /* RXCR2 */
-#define RX_CTRL_IPV6_UDP_NOCHECKSUM (0x0010) /* No checksum generation and verification if IPv6 UDP is fragment */
-#define RX_CTRL_IPV6_UDP_CHECKSUM (0x0008) /* Receive pass IPv6 UDP frame with UDP checksum is zero */
-#define RX_CTRL_UDP_LITE_CHECKSUM (0x0004) /* Enable UDP Lite frame checksum generation and verification */
-#define RX_CTRL_ICMP_CHECKSUM (0x0002) /* Enable ICMP frame checksum verification */
-#define RX_CTRL_BLOCK_MAC (0x0001) /* Receive drop frame if the SA is same as device MAC address */
-#define RX_CTRL_BURST_LEN_MASK (0x00e0) /* SRDBL SPI Receive Data Burst Length */
-#define RX_CTRL_BURST_LEN_4 (0x0000)
-#define RX_CTRL_BURST_LEN_8 (0x0020)
-#define RX_CTRL_BURST_LEN_16 (0x0040)
-#define RX_CTRL_BURST_LEN_32 (0x0060)
-#define RX_CTRL_BURST_LEN_FRAME (0x0080)
-
-#define REG_TX_MEM_INFO (0x78) /* TXMIR */
-#define TX_MEM_AVAILABLE_MASK (0x1FFF) /* The amount of memory available in TXQ */
-
-#define REG_RX_FHR_STATUS (0x7C) /* RXFHSR */
-#define RX_VALID (0x8000) /* Frame in the receive packet memory is valid */
-#define RX_ICMP_ERROR (0x2000) /* ICMP checksum field doesn't match */
-#define RX_IP_ERROR (0x1000) /* IP checksum field doesn't match */
-#define RX_TCP_ERROR (0x0800) /* TCP checksum field doesn't match */
-#define RX_UDP_ERROR (0x0400) /* UDP checksum field doesn't match */
-#define RX_BROADCAST (0x0080) /* Received frame is a broadcast frame */
-#define RX_MULTICAST (0x0040) /* Received frame is a multicast frame */
-#define RX_UNICAST (0x0020) /* Received frame is a unicast frame */
-#define RX_PHY_ERROR (0x0010) /* Received frame has runt error */
-#define RX_FRAME_ETHER (0x0008) /* Received frame is an Ethernet-type frame */
-#define RX_TOO_LONG (0x0004) /* Received frame length exceeds max size 0f 2048 bytes */
-#define RX_RUNT_ERROR (0x0002) /* Received frame was demaged by a collision */
-#define RX_BAD_CRC (0x0001) /* Received frame has a CRC error */
-#define RX_ERRORS ( RX_BAD_CRC | RX_TOO_LONG | RX_RUNT_ERROR | RX_PHY_ERROR | \
- RX_ICMP_ERROR | RX_IP_ERROR | RX_TCP_ERROR | RX_UDP_ERROR )
-
-#define REG_RX_FHR_BYTE_CNT (0x7E) /* RXFHBCR */
-#define RX_BYTE_CNT_MASK (0x0FFF) /* Received frame byte size mask */
-
-#define REG_TXQ_CMD (0x80) /* TXQCR */
-#define TXQ_AUTO_ENQUEUE (0x0004) /* Enable enqueue tx frames from tx buffer automatically */
-#define TXQ_MEM_AVAILABLE_INT (0x0002) /* Enable generate interrupt when tx memory is available */
-#define TXQ_ENQUEUE (0x0001) /* Enable enqueue tx frames one frame at a time */
-
-#define REG_RXQ_CMD (0x82) /* RXQCR */
-#define RXQ_STAT_TIME_INT (0x1000) /* RX interrupt is occured by timer duration */
-#define RXQ_STAT_BYTE_CNT_INT (0x0800) /* RX interrupt is occured by byte count threshold */
-#define RXQ_STAT_FRAME_CNT_INT (0x0400) /* RX interrupt is occured by frame count threshold */
-#define RXQ_TWOBYTE_OFFSET (0x0200) /* Enable adding 2-byte before frame header for IP aligned with DWORD */
-#define RXQ_TIME_INT (0x0080) /* Enable RX interrupt by timer duration */
-#define RXQ_BYTE_CNT_INT (0x0040) /* Enable RX interrupt by byte count threshold */
-#define RXQ_FRAME_CNT_INT (0x0020) /* Enable RX interrupt by frame count threshold */
-#define RXQ_AUTO_DEQUEUE (0x0010) /* Enable release rx frames from rx buffer automatically */
-#define RXQ_START (0x0008) /* Start QMU transfer operation */
-#define RXQ_CMD_FREE_PACKET (0x0001) /* Manual dequeue (release the current frame from RxQ) */
-
-#define RXQ_CMD_CNTL (RXQ_FRAME_CNT_INT|RXQ_AUTO_DEQUEUE)
-
-#define REG_TX_ADDR_PTR (0x84) /* TXFDPR */
-#define REG_RX_ADDR_PTR (0x86) /* RXFDPR */
-#define ADDR_PTR_AUTO_INC (0x4000) /* Enable Frame data pointer increments automatically */
-#define ADDR_PTR_MASK (0x03ff) /* Address pointer mask */
-
-#define REG_RX_TIME_THRES (0x8C) /* RXDTTR */
-#define RX_TIME_THRESHOLD_MASK (0xFFFF) /* Set receive timer duration threshold */
-
-#define REG_RX_BYTE_CNT_THRES (0x8E) /* RXDBCTR */
-#define RX_BYTE_THRESHOLD_MASK (0xFFFF) /* Set receive byte count threshold */
-
-#define REG_INT_MASK (0x90) /* IER */
-#define INT_PHY (0x8000) /* Enable link change interrupt */
-#define INT_TX (0x4000) /* Enable transmit done interrupt */
-#define INT_RX (0x2000) /* Enable receive interrupt */
-#define INT_RX_OVERRUN (0x0800) /* Enable receive overrun interrupt */
-#define INT_TX_STOPPED (0x0200) /* Enable transmit process stopped interrupt */
-#define INT_RX_STOPPED (0x0100) /* Enable receive process stopped interrupt */
-#define INT_TX_SPACE (0x0040) /* Enable transmit space available interrupt */
-#define INT_RX_WOL_FRAME (0x0020) /* Enable WOL on receive wake-up frame detect interrupt */
-#define INT_RX_WOL_MAGIC (0x0010) /* Enable WOL on receive magic packet detect interrupt */
-#define INT_RX_WOL_LINKUP (0x0008) /* Enable WOL on link up detect interrupt */
-#define INT_RX_WOL_ENERGY (0x0004) /* Enable WOL on energy detect interrupt */
-#define INT_RX_SPI_ERROR (0x0002) /* Enable receive SPI bus error interrupt */
-#define INT_RX_WOL_DELAY_ENERGY (0x0001) /* Enable WOL on delay energy detect interrupt */
-#define INT_MASK ( INT_RX | INT_TX | INT_PHY )
-
-#define REG_INT_STATUS (0x92) /* ISR */
-
-#define REG_RX_FRAME_CNT_THRES (0x9C) /* RXFCTFC */
-#define RX_FRAME_CNT_MASK (0xFF00) /* Received frame count mask */
-#define RX_FRAME_THRESHOLD_MASK (0x00FF) /* Set receive frame count threshold mask */
-
-#define REG_TX_TOTAL_FRAME_SIZE (0x9E) /* TXNTFSR */
-#define TX_TOTAL_FRAME_SIZE_MASK (0xFFFF) /* Set next total tx frame size mask */
-
-/*
- * MAC Address Hash Table Control Registers
- * (Offset 0xA0 - 0xA7)
- */
-#define REG_MAC_HASH_0 (0xA0) /* MAHTR0 */
-#define REG_MAC_HASH_1 (0xA1)
-
-#define REG_MAC_HASH_2 (0xA2) /* MAHTR1 */
-#define REG_MAC_HASH_3 (0xA3)
-
-#define REG_MAC_HASH_4 (0xA4) /* MAHTR2 */
-#define REG_MAC_HASH_5 (0xA5)
-
-#define REG_MAC_HASH_6 (0xA6) /* MAHTR3 */
-#define REG_MAC_HASH_7 (0xA7)
-
-/*
- * QMU Receive Queue Watermark Control Registers
- * (Offset 0xB0 - 0xB5)
- */
-#define REG_RX_LOW_WATERMARK (0xB0) /* FCLWR */
-#define RX_LOW_WATERMARK_MASK (0x0FFF) /* Set QMU RxQ low watermark mask */
-
-#define REG_RX_HIGH_WATERMARK (0xB2) /* FCHWR */
-#define RX_HIGH_WATERMARK_MASK (0x0FFF) /* Set QMU RxQ high watermark mask */
-
-#define REG_RX_OVERRUN_WATERMARK (0xB4) /* FCOWR */
-#define RX_OVERRUN_WATERMARK_MASK (0x0FFF) /* Set QMU RxQ overrun watermark mask */
-
-/*
- * Global Control Registers
- * (Offset 0xC0 - 0xD3)
- */
-#define REG_CHIP_ID (0xC0) /* CIDER */
-#define CHIP_ID_MASK (0xFFF0) /* Family ID and chip ID mask */
-#define REVISION_MASK (0x000E) /* Chip revision mask */
-#define CHIP_ID_SHIFT (4)
-#define REVISION_SHIFT (1)
-#define CHIP_ID_8851_16 (0x8870) /* KS8851-16/32MQL chip ID */
-
-#define REG_LED_CTRL (0xC6) /* CGCR */
-#define LED_CTRL_SEL1 (0x8000) /* Select LED3/LED2/LED1/LED0 indication */
-#define LED_CTRL_SEL0 (0x0200) /* Select LED3/LED2/LED1/LED0 indication */
-
-#define REG_IND_IACR (0xC8) /* IACR */
-#define TABLE_READ (0x1000) /* Indirect read */
-#define TABLE_MIB (0x0C00) /* Select MIB counter table */
-#define TABLE_ENTRY_MASK (0x001F) /* Set table entry to access */
-
-#define REG_IND_DATA_LOW (0xD0) /* IADLR */
-#define REG_IND_DATA_HIGH (0xD2) /* IADHR */
-
-/*
- * Power Management Control Registers
- * (Offset 0xD4 - 0xD7)
- */
-#define REG_POWER_CNTL (0xD4) /* PMECR */
-#define PME_DELAY_ENABLE (0x4000) /* Enable the PME output pin assertion delay */
-#define PME_ACTIVE_HIGHT (0x1000) /* PME output pin is active high */
-#define PME_FROM_WKFRAME (0x0800) /* PME asserted when wake-up frame is detected */
-#define PME_FROM_MAGIC (0x0400) /* PME asserted when magic packet is detected */
-#define PME_FROM_LINKUP (0x0200) /* PME asserted when link up is detected */
-#define PME_FROM_ENERGY (0x0100) /* PME asserted when energy is detected */
-#define PME_EVENT_MASK (0x0F00) /* PME asserted event mask */
-#define WAKEUP_AUTO_ENABLE (0x0080) /* Enable auto wake-up in energy mode */
-#define WAKEUP_NORMAL_AUTO_ENABLE (0x0040) /* Enable auto goto normal mode from energy detecion mode */
-#define WAKEUP_FROM_WKFRAME (0x0020) /* Wake-up from wake-up frame event detected */
-#define WAKEUP_FROM_MAGIC (0x0010) /* Wake-up from magic packet event detected */
-#define WAKEUP_FROM_LINKUP (0x0008) /* Wake-up from link up event detected */
-#define WAKEUP_FROM_ENERGY (0x0004) /* Wake-up from energy event detected */
-#define WAKEUP_EVENT_MASK (0x003C) /* Wake-up event mask */
-#define POWER_STATE_D1 (0x0003) /* Power saving mode */
-#define POWER_STATE_D3 (0x0002) /* Power down mode */
-#define POWER_STATE_D2 (0x0001) /* Power detection mode */
-#define POWER_STATE_D0 (0x0000) /* Normal operation mode (default) */
-#define POWER_STATE_MASK (0x0003) /* Power management mode mask */
-
-#define REG_WAKEUP_TIME (0xD6) /* GSWUTR */
-#define WAKEUP_TIME (0xFF00) /* Min time (sec) wake-uo after detected energy */
-#define GOSLEEP_TIME (0x00FF) /* Min time (sec) before goto sleep when in energy mode */
-
-/*
- * PHY Control Registers
- * (Offset 0xD8 - 0xF9)
- */
-#define REG_PHY_RESET (0xD8) /* PHYRR */
-#define PHY_RESET (0x0001) /* Reset PHY */
-
-#define REG_PHY_CNTL (0xE4) /* P1MBCR */
-#define PHY_SPEED_100MBIT (0x2000) /* Force PHY 100Mbps */
-#define PHY_AUTO_NEG_ENABLE (0x1000) /* Enable PHY auto-negotiation */
-#define PHY_POWER_DOWN (0x0800) /* Set PHY power-down */
-#define PHY_AUTO_NEG_RESTART (0x0200) /* Restart PHY auto-negotiation */
-#define PHY_FULL_DUPLEX (0x0100) /* Force PHY in full duplex mode */
-#define PHY_HP_MDIX (0x0020) /* Set PHY in HP auto MDI-X mode */
-#define PHY_FORCE_MDIX (0x0010) /* Force MDI-X */
-#define PHY_AUTO_MDIX_DISABLE (0x0008) /* Disable auto MDI-X */
-#define PHY_TRANSMIT_DISABLE (0x0002) /* Disable PHY transmit */
-#define PHY_LED_DISABLE (0x0001) /* Disable PHY LED */
-
-#define REG_PHY_STATUS (0xE6) /* P1MBSR */
-#define PHY_100BT4_CAPABLE (0x8000) /* 100 BASE-T4 capable */
-#define PHY_100BTX_FD_CAPABLE (0x4000) /* 100BASE-TX full duplex capable */
-#define PHY_100BTX_CAPABLE (0x2000) /* 100BASE-TX half duplex capable */
-#define PHY_10BT_FD_CAPABLE (0x1000) /* 10BASE-TX full duplex capable */
-#define PHY_10BT_CAPABLE (0x0800) /* 10BASE-TX half duplex capable */
-#define PHY_AUTO_NEG_ACKNOWLEDGE (0x0020) /* Auto-negotiation complete */
-#define PHY_AUTO_NEG_CAPABLE (0x0008) /* Auto-negotiation capable */
-#define PHY_LINK_UP (0x0004) /* PHY link is up */
-#define PHY_EXTENDED_CAPABILITY (0x0001) /* PHY extended register capable */
-
-#define REG_PHY_ID_LOW (0xE8) /* PHY1ILR */
-#define REG_PHY_ID_HIGH (0xEA) /* PHY1IHR */
-
-#define REG_PHY_AUTO_NEGOTIATION (0xEC) /* P1ANAR */
-#define PHY_AUTO_NEG_SYM_PAUSE (0x0400) /* Advertise pause capability */
-#define PHY_AUTO_NEG_100BTX_FD (0x0100) /* Advertise 100 full-duplex capability */
-#define PHY_AUTO_NEG_100BTX (0x0080) /* Advertise 100 half-duplex capability */
-#define PHY_AUTO_NEG_10BT_FD (0x0040) /* Advertise 10 full-duplex capability */
-#define PHY_AUTO_NEG_10BT (0x0020) /* Advertise 10 half-duplex capability */
-#define PHY_AUTO_NEG_SELECTOR (0x001F) /* Selector field mask */
-#define PHY_AUTO_NEG_802_3 (0x0001) /* 802.3 */
-
-#define REG_PHY_REMOTE_CAPABILITY (0xEE) /* P1ANLPR */
-#define PHY_REMOTE_SYM_PAUSE (0x0400) /* Link partner pause capability */
-#define PHY_REMOTE_100BTX_FD (0x0100) /* Link partner 100 full-duplex capability */
-#define PHY_REMOTE_100BTX (0x0080) /* Link partner 100 half-duplex capability */
-#define PHY_REMOTE_10BT_FD (0x0040) /* Link partner 10 full-duplex capability */
-#define PHY_REMOTE_10BT (0x0020) /* Link partner 10 half-duplex capability */
-
-#define REG_PORT_LINK_MD (0xF4) /* P1SCLMD */
-#define PORT_CABLE_10M_SHORT (0x8000) /* Cable length is less than 10m short */
-#define PORT_CABLE_STAT_FAILED (0x6000) /* Cable diagnostic test fail */
-#define PORT_CABLE_STAT_SHORT (0x4000) /* Short condition detected in the cable */
-#define PORT_CABLE_STAT_OPEN (0x2000) /* Open condition detected in the cable */
-#define PORT_CABLE_STAT_NORMAL (0x0000) /* Normal condition */
-#define PORT_CABLE_DIAG_RESULT (0x6000) /* Cable diagnostic test result mask */
-#define PORT_START_CABLE_DIAG (0x1000) /* Enable cable diagnostic test */
-#define PORT_FORCE_LINK (0x0800) /* Enable force link pass */
-#define PORT_POWER_SAVING (0x0400) /* Disable power saving */
-#define PORT_REMOTE_LOOPBACK (0x0200) /* Enable remote loopback at PHY */
-#define PORT_CABLE_FAULT_COUNTER (0x01FF) /* Cable length distance to the fault */
-
-#define REG_PORT_CTRL (0xF6) /* P1CR */
-#define PORT_LED_OFF (0x8000) /* Turn off all the port LEDs (LED3/LED2/LED1/LED0) */
-#define PORT_TX_DISABLE (0x4000) /* Disable port transmit */
-#define PORT_AUTO_NEG_RESTART (0x2000) /* Restart auto-negotiation */
-#define PORT_POWER_DOWN (0x0800) /* Set port power-down */
-#define PORT_AUTO_MDIX_DISABLE (0x0400) /* Disable auto MDI-X */
-#define PORT_FORCE_MDIX (0x0200) /* Force MDI-X */
-#define PORT_AUTO_NEG_ENABLE (0x0080) /* Enable auto-negotiation */
-#define PORT_FORCE_100_MBIT (0x0040) /* Force PHY 100Mbps */
-#define PORT_FORCE_FULL_DUPLEX (0x0020) /* Force PHY in full duplex mode */
-#define PORT_AUTO_NEG_SYM_PAUSE (0x0010) /* Advertise pause capability */
-#define PORT_AUTO_NEG_100BTX_FD (0x0008) /* Advertise 100 full-duplex capability */
-#define PORT_AUTO_NEG_100BTX (0x0004) /* Advertise 100 half-duplex capability */
-#define PORT_AUTO_NEG_10BT_FD (0x0002) /* Advertise 10 full-duplex capability */
-#define PORT_AUTO_NEG_10BT (0x0001) /* Advertise 10 half-duplex capability */
-
-#define REG_PORT_STATUS (0xF8) /* P1SR */
-#define PORT_HP_MDIX (0x8000) /* Set PHY in HP auto MDI-X mode */
-#define PORT_REVERSED_POLARITY (0x2000) /* Polarity is reversed */
-#define PORT_RX_FLOW_CTRL (0x1000) /* Reeive flow control feature is active */
-#define PORT_TX_FLOW_CTRL (0x0800) /* Transmit flow control feature is active */
-#define PORT_STAT_SPEED_100MBIT (0x0400) /* Link is 100Mbps */
-#define PORT_STAT_FULL_DUPLEX (0x0200) /* Link is full duplex mode */
-#define PORT_MDIX_STATUS (0x0080) /* Is MDI */
-#define PORT_AUTO_NEG_COMPLETE (0x0040) /* Auto-negotiation complete */
-#define PORT_STATUS_LINK_GOOD (0x0020) /* PHY link is up */
-#define PORT_REMOTE_SYM_PAUSE (0x0010) /* Link partner pause capability */
-#define PORT_REMOTE_100BTX_FD (0x0008) /* Link partner 100 full-duplex capability */
-#define PORT_REMOTE_100BTX (0x0004) /* Link partner 100 half-duplex capability */
-#define PORT_REMOTE_10BT_FD (0x0002) /* Link partner 10 full-duplex capability */
-#define PORT_REMOTE_10BT (0x0001) /* Link partner 10 half-duplex capability */
-
-#endif /* KSZ8851SNL_REG_H_INCLUDED */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/readme.txt
deleted file mode 100755
index 65e5e2b..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/readme.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-Contains the files that implement FreeRTOS+TCP.
-
-User documentation, including an API reference is available on:
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/
-
-A description of the source code organisation is available on:
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Networking_Tutorial.html
-
-The porting guide is available on:
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_Porting.html
-
-License information is available on:
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_Plus_TCP_License.html
-
-At this time it is recommended to use BufferAllocation_2.c in which case it is
-essential to use the heap_4.c memory allocation scheme:
-http://www.FreeRTOS.org/a00111.html
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcHardwarePort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcHardwarePort.h
deleted file mode 100755
index 1b47e69..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcHardwarePort.h
+++ /dev/null
@@ -1,478 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcHardwarePort.h
- *
- * The hardware abstraction layer for the trace recorder.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_HARDWARE_PORT_H
-#define TRC_HARDWARE_PORT_H
-
-#include "trcPortDefines.h"
-
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)
- #error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"
-#endif
-
-/*******************************************************************************
- * TRC_IRQ_PRIORITY_ORDER
- *
- * Macro which should be defined as an integer of 0 or 1.
- *
- * This should be 0 if lower IRQ priority values implies higher priority
- * levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,
- * if higher IRQ priority values means higher priority, this should be 1.
- *
- * This setting is not critical. It is used only to sort and colorize the
- * interrupts in priority order, in case you record interrupts using
- * the vTraceStoreISRBegin and vTraceStoreISREnd routines.
- *
- ******************************************************************************
- *
- * HWTC Macros
- *
- * These macros provides a hardware isolation layer representing the
- * hardware timer/counter used for the event timestamping.
- *
- * TRC_HWTC_COUNT: How to read the current value of the timer/counter.
- *
- * TRC_HWTC_TYPE: Tells the type of timer/counter used for TRC_HWTC_COUNT:
- *
- * - TRC_FREE_RUNNING_32BIT_INCR:
- * Free-running 32-bit timer/counter, counting upwards from 0.
- *
- * - TRC_FREE_RUNNING_32BIT_DECR
- * Free-running 32-bit timer/counter, counting downwards from 0xFFFFFFFF.
- *
- * - TRC_OS_TIMER_INCR
- * Periodic timer that drives the OS tick interrupt, counting upwards
- * from 0 until (TRC_HWTC_PERIOD-1).
- *
- * - TRC_OS_TIMER_DECR
- * Periodic timer that drives the OS tick interrupt, counting downwards
- * from TRC_HWTC_PERIOD-1 until 0.
- *
- * - TRC_CUSTOM_TIMER_INCR
- * A custom timer or counter independent of the OS tick, counting
- * downwards from TRC_HWTC_PERIOD-1 until 0. (Currently only supported
- * in streaming mode).
- *
- * - TRC_CUSTOM_TIMER_DECR
- * A custom timer independent of the OS tick, counting downwards
- * from TRC_HWTC_PERIOD-1 until 0. (Currently only supported
- * in streaming mode).
- *
- * TRC_HWTC_PERIOD: The number of HWTC_COUNT ticks until the timer wraps
- * around. If using TRC_FREE_RUNNING_32BIT_INCR/DECR, this should be 0.
- *
- * TRC_HWTC_FREQ_HZ: The clock rate of the TRC_HWTC_COUNT counter in Hz. If using
- * TRC_OS_TIMER_INCR/DECR, this is should be TRC_HWTC_PERIOD * TRACE_TICK_RATE_HZ.
- * If using a free-running timer, this is often TRACE_CPU_CLOCK_HZ (if running at
- * the core clock rate). If using TRC_CUSTOM_TIMER_INCR/DECR, this should match
- * the clock rate of your custom timer (i.e., TRC_HWTC_COUNT). If the default value
- * of TRC_HWTC_FREQ_HZ is incorrect for your setup, you can override it by calling
- * vTraceSetFrequency before calling vTraceEnable.
- *
- * TRC_HWTC_DIVISOR (used in snapshot mode only):
- * In snapshot mode, the timestamp resolution is TRC_HWTC_FREQ_HZ/TRC_HWTC_DIVISOR.
- * If the timer frequency is very high (hundreds of MHz), we recommend increasing
- * the TRC_HWTC_DIVISOR prescaler, to reduce the bandwidth needed to store
- * timestamps. This since extra "XTS" events are inserted if the time since the
- * previous event exceeds a certain limit (255 or 65535 depending on event type).
- * It is advised to keep the time between most events below 65535 native ticks
- * (after division by TRC_HWTC_DIVISOR) to avoid frequent XTS events.
- ******************************************************************************/
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)
- #error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"
-#endif
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)
- /* This can be used as a template for any free-running 32-bit counter */
- #define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR
- #define TRC_HWTC_COUNT (ulGetRunTimeCounterValue())
- #define TRC_HWTC_PERIOD 0
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ 100000
-
- #define TRC_IRQ_PRIORITY_ORDER 1
-
- #define TRC_PORT_SPECIFIC_INIT()
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_HWIndependent)
- /* Timestamping by OS tick only (typically 1 ms resolution) */
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT 0
- #define TRC_HWTC_PERIOD 1
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ TRACE_TICK_RATE_HZ
-
- /* Set the meaning of IRQ priorities in ISR tracing - see above */
- #define TRC_IRQ_PRIORITY_ORDER NOT_SET
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)
-
- #ifndef __CORTEX_M
- #error "Can't find the CMSIS API. Please include your processor's header file in trcConfig.h"
- #endif
-
- /**************************************************************************
- * For Cortex-M3, M4 and M7, the DWT cycle counter is used for timestamping.
- * For Cortex-M0 and M0+, the SysTick timer is used since DWT is not
- * available. Systick timestamping can also be forced on Cortex-M3, M4 and
- * M7 by defining the preprocessor directive TRC_CFG_ARM_CM_USE_SYSTICK,
- * either directly below or in trcConfig.h.
- *
- * #define TRC_CFG_ARM_CM_USE_SYSTICK
- **************************************************************************/
-
- #if ((__CORTEX_M >= 0x03) && (! defined TRC_CFG_ARM_CM_USE_SYSTICK))
-
- void prvTraceInitCortexM(void);
-
- #define TRC_REG_DEMCR (*(volatile uint32_t*)0xE000EDFC)
- #define TRC_REG_DWT_CTRL (*(volatile uint32_t*)0xE0001000)
- #define TRC_REG_DWT_CYCCNT (*(volatile uint32_t*)0xE0001004)
- #define TRC_REG_DWT_EXCCNT (*(volatile uint32_t*)0xE000100C)
-
- #define TRC_REG_ITM_LOCKACCESS (*(volatile uint32_t*)0xE0001FB0)
- #define TRC_ITM_LOCKACCESS_UNLOCK (0xC5ACCE55)
-
- /* Bit mask for TRCENA bit in DEMCR - Global enable for DWT and ITM */
- #define TRC_DEMCR_TRCENA (1 << 24)
-
- /* Bit mask for NOPRFCNT bit in DWT_CTRL. If 1, DWT_EXCCNT is not supported */
- #define TRC_DWT_CTRL_NOPRFCNT (1 << 24)
-
- /* Bit mask for NOCYCCNT bit in DWT_CTRL. If 1, DWT_CYCCNT is not supported */
- #define TRC_DWT_CTRL_NOCYCCNT (1 << 25)
-
- /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_EXCCNT */
- #define TRC_DWT_CTRL_EXCEVTENA (1 << 18)
-
- /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_CYCCNT */
- #define TRC_DWT_CTRL_CYCCNTENA (1)
-
- #define TRC_PORT_SPECIFIC_INIT() prvTraceInitCortexM()
-
- #define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR
- #define TRC_HWTC_COUNT TRC_REG_DWT_CYCCNT
- #define TRC_HWTC_PERIOD 0
- #define TRC_HWTC_DIVISOR 4
- #define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ
- #define TRC_IRQ_PRIORITY_ORDER 0
-
- #else
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT (*((volatile uint32_t*)0xE000E018))
- #define TRC_HWTC_PERIOD ((*((volatile uint32_t*)0xE000E014)) + 1)
- #define TRC_HWTC_DIVISOR 4
- #define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ
- #define TRC_IRQ_PRIORITY_ORDER 0
-
- #endif
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Renesas_RX600)
-
- #include "iodefine.h"
-
- #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT (CMT0.CMCNT)
-
- #elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-
- /* Decreasing counters better for Tickless Idle? */
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT (CMT0.CMCOR - CMT0.CMCNT)
-
- #endif
-
- #define TRC_HWTC_PERIOD (CMT0.CMCOR + 1)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 1
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32)
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT (TMR1)
- #define TRC_HWTC_PERIOD (PR1 + 1)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48)
-
- #define TRC_RTIFRC0 *((uint32_t *)0xFFFFFC10)
- #define TRC_RTICOMP0 *((uint32_t *)0xFFFFFC50)
- #define TRC_RTIUDCP0 *((uint32_t *)0xFFFFFC54)
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT (TRC_RTIFRC0 - (TRC_RTICOMP0 - TRC_RTIUDCP0))
- #define TRC_HWTC_PERIOD (TRC_RTIUDCP0)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_AT91SAM7)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))
- #define TRC_HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 1
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_UC3A0)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO*/
-
- /* For Atmel AVR32 (AT32UC3A) */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))
- #define TRC_HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 1
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NXP_LPC210X)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
-
- /* Tested with LPC2106, but should work with most LPC21XX chips. */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT *((uint32_t *)0xE0004008 )
- #define TRC_HWTC_PERIOD *((uint32_t *)0xE0004018 )
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT (TA0R)
- #define TRC_HWTC_PERIOD (((uint16_t)TACCR0)+1)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 1
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC405)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT mfspr(0x3db)
- #define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC440)
-
- /* UNOFFICIAL PORT */
-
- /* This should work with most PowerPC chips */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT mfspr(0x016)
- #define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)
- #define TRC_HWTC_DIVISOR 1
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_MICROBLAZE)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
-
- /* This should work with most Microblaze configurations.
- * It uses the AXI Timer 0 - the tick interrupt source.
- * If an AXI Timer 0 peripheral is available on your hardware platform, no modifications are required.
- */
- #include "xtmrctr_l.h"
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )
- #define TRC_HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR, 0) + 1)
- #define TRC_HWTC_DIVISOR 16
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Altera_NiosII)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
-
- #include "system.h"
- #include "sys/alt_timestamp.h"
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
- #define TRC_HWTC_COUNT (uint32_t)alt_timestamp()
- #define TRC_HWTC_PERIOD 0xFFFFFFFF
- #define TRC_HWTC_FREQ_HZ TIMESTAMP_TIMER_FREQ
- #define TRC_HWTC_DIVISOR 1
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_CORTEX_A9)
-
- /* INPUT YOUR PERIPHERAL BASE ADDRESS HERE */
- #define TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS 0xSOMETHING
-
- #define TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET 0x0600
- #define TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x00))
- #define TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x04))
- #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x08))
-
- #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK 0x0000FF00
- #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT 8
- #define TRC_CA9_MPCORE_PRIVCTR_PRESCALER (((TRC_CA9_MPCORE_PRIVCTR_CONTROL_REG & TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK) >> TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT) + 1)
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- #define TRC_HWTC_COUNT TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG
- #define TRC_HWTC_PERIOD (TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG + 1)
-
- /****************************************************************************************
- NOTE: The private timer ticks with a very high frequency (half the core-clock usually),
- depending on the prescaler used. If a low prescaler is used, the number of HW ticks between
- the trace events gets large, and thereby inefficient to store (sometimes extra events are
- needed). To improve efficiency, you may use the TRC_HWTC_DIVISOR as an additional prescaler.
- *****************************************************************************************/
- #define TRC_HWTC_DIVISOR 1
-
- #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
- #define TRC_IRQ_PRIORITY_ORDER 0
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_POWERPC_Z4)
-
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
-
- #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
- //#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
- #define TRC_HWTC_COUNT PIT.TIMER[configTICK_PIT_CHANNEL].CVAL.R // must be the PIT channel used for the systick
- #define TRC_HWTC_PERIOD ((configPIT_CLOCK_HZ / configTICK_RATE_HZ) - 1U) // TODO FIXME or maybe not -1? what's the right "period" value?
- #define TRC_HWTC_FREQ_HZ configPIT_CLOCK_HZ
- #define TRC_HWTC_DIVISOR 1
- #define TRC_IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
-
-#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_APPLICATION_DEFINED)
-
- #if !( defined (TRC_HWTC_TYPE) && defined (TRC_HWTC_COUNT) && defined (TRC_HWTC_PERIOD) && defined (TRC_HWTC_FREQ_HZ) && defined (TRC_IRQ_PRIORITY_ORDER) )
- #error "The hardware port is not completely defined!"
- #endif
-
-#elif (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)
-
- #error "TRC_CFG_HARDWARE_PORT had unsupported value!"
- #define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET
-
-#endif
-
-#ifndef TRC_HWTC_DIVISOR
- #define TRC_HWTC_DIVISOR 1
-#endif
-
-#ifndef TRC_PORT_SPECIFIC_INIT
- #define TRC_PORT_SPECIFIC_INIT()
-#endif
-
-/* If Win32 port */
-#ifdef WIN32
-
- #undef _WIN32_WINNT
- #define _WIN32_WINNT 0x0600
-
- /* Standard includes. */
- #include
- #include
- #include
-
- /***************************************************************************
- * The Win32 port by default saves the trace to file and then kills the
- * program when the recorder is stopped, to facilitate quick, simple tests
- * of the recorder.
- ***************************************************************************/
- #define WIN32_PORT_SAVE_WHEN_STOPPED 1
- #define WIN32_PORT_EXIT_WHEN_STOPPED 1
-
-#endif
-
-#if (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)
-
- #ifndef TRC_HWTC_TYPE
- #error "TRC_HWTC_TYPE is not set!"
- #endif
-
- #ifndef TRC_HWTC_COUNT
- #error "TRC_HWTC_COUNT is not set!"
- #endif
-
- #ifndef TRC_HWTC_PERIOD
- #error "TRC_HWTC_PERIOD is not set!"
- #endif
-
- #ifndef TRC_HWTC_DIVISOR
- #error "TRC_HWTC_DIVISOR is not set!"
- #endif
-
- #ifndef TRC_IRQ_PRIORITY_ORDER
- #error "TRC_IRQ_PRIORITY_ORDER is not set!"
- #elif (TRC_IRQ_PRIORITY_ORDER != 0) && (TRC_IRQ_PRIORITY_ORDER != 1)
- #error "TRC_IRQ_PRIORITY_ORDER has bad value!"
- #endif
-
- #if (TRC_HWTC_DIVISOR < 1)
- #error "TRC_HWTC_DIVISOR must be a non-zero positive value!"
- #endif
-
- #ifndef TRC_HWTC_FREQ_HZ
- #error "TRC_HWTC_FREQ_HZ not defined!"
- #endif
-
-#endif
-
-#endif /*TRC_SNAPSHOT_HARDWARE_PORT_H*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcKernelPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcKernelPort.h
deleted file mode 100755
index f7f6ca0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcKernelPort.h
+++ /dev/null
@@ -1,2565 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * FreeRTOS-specific definitions needed by the trace recorder
- *
- *
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_KERNEL_PORT_H
-#define TRC_KERNEL_PORT_H
-
-#include "FreeRTOS.h" /* Defines configUSE_TRACE_FACILITY */
-#include "trcPortDefines.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define TRC_USE_TRACEALYZER_RECORDER configUSE_TRACE_FACILITY
-
-/*** FreeRTOS version codes **************************************************/
-#define FREERTOS_VERSION_NOT_SET 0
-#define TRC_FREERTOS_VERSION_7_3 1 /* v7.3 is earliest supported.*/
-#define TRC_FREERTOS_VERSION_7_4 2
-#define TRC_FREERTOS_VERSION_7_5_OR_7_6 3
-#define TRC_FREERTOS_VERSION_8_X 4 /* Any v8.x.x*/
-#define TRC_FREERTOS_VERSION_9_0_0 5
-#define TRC_FREERTOS_VERSION_9_0_1 6
-#define TRC_FREERTOS_VERSION_9_0_2 7
-#define TRC_FREERTOS_VERSION_10_0_0 8 /* If using FreeRTOS v10.0.0 or later version */
-
-#define TRC_FREERTOS_VERSION_9_X 42 /* Not allowed anymore */
-
-#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X)
-/* This setting for TRC_CFG_FREERTOS_VERSION is no longer allowed as v9.0.1 needs special handling. */
-#error "Please specify your exact FreeRTOS version in trcConfig.h, from the options listed above."
-#endif
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-#define prvGetStreamBufferType(x) ((( StreamBuffer_t * )x )->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER)
-#else
-#define prvGetStreamBufferType(x) 0
-#endif
-
-/* Added mainly for our internal testing. This makes it easier to create test applications that
- runs on multiple FreeRTOS versions. */
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X)
- /* FreeRTOS v7.0 and later */
- #define STRING_CAST(x) ( (signed char*) x )
- #define TickType portTickType
-#else
- /* FreeRTOS v8.0 and later */
- #define STRING_CAST(x) x
- #define TickType TickType_t
-#endif
-
-#if (defined(TRC_USE_TRACEALYZER_RECORDER)) && (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-/*******************************************************************************
- * INCLUDE_xTaskGetCurrentTaskHandle must be set to 1 for tracing to work properly
- ******************************************************************************/
-#undef INCLUDE_xTaskGetCurrentTaskHandle
-#define INCLUDE_xTaskGetCurrentTaskHandle 1
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-/*******************************************************************************
- * vTraceSetQueueName(void* object, const char* name)
- *
- * Parameter object: pointer to the Queue that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Queue objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetQueueName(void* object, const char* name);
-
-/*******************************************************************************
- * vTraceSetSemaphoreName(void* object, const char* name)
- *
- * Parameter object: pointer to the Semaphore that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Semaphore objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetSemaphoreName(void* object, const char* name);
-
-/*******************************************************************************
- * vTraceSetMutexName(void* object, const char* name)
- *
- * Parameter object: pointer to the Mutex that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Semaphore objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetMutexName(void* object, const char* name);
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1)
-/*******************************************************************************
-* vTraceSetEventGroupName(void* object, const char* name)
-*
-* Parameter object: pointer to the EventGroup that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for EventGroup objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetEventGroupName(void* object, const char* name);
-#else /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1) */
-#define vTraceSetEventGroupName(object, name) /* Do nothing */
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1)
-/*******************************************************************************
-* vTraceSetStreamBufferName(void* object, const char* name)
-*
-* Parameter object: pointer to the StreamBuffer that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for StreamBuffer objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetStreamBufferName(void* object, const char* name);
-#else /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-#define vTraceSetStreamBufferName(object, name) /* Do nothing */
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1)
-/*******************************************************************************
- * vTraceSetMessageBufferName(void* object, const char* name)
- *
- * Parameter object: pointer to the MessageBuffer that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for MessageBuffer objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetMessageBufferName(void* object, const char* name);
-#else /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-#define vTraceSetMessageBufferName(object, name) /* Do nothing */
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-
-#else /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-#define vTraceSetQueueName(object, name) /* Do nothing */
-#define vTraceSetSemaphoreName(object, name) /* Do nothing */
-#define vTraceSetMutexName(object, name) /* Do nothing */
-#define vTraceSetEventGroupName(object, name) /* Do nothing */
-#define vTraceSetStreamBufferName(object, name) /* Do nothing */
-#define vTraceSetMessageBufferName(object, name) /* Do nothing */
-
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-/*******************************************************************************
- * Note: Setting names for event groups is difficult to support, this has been
- * excluded intentionally. This since we don't know if event_groups.c is
- * included in the build, so referencing it from the recorder may cause errors.
- ******************************************************************************/
-
-/* Gives the currently executing task (wrapper for RTOS-specific function) */
-void* prvTraceGetCurrentTaskHandle(void);
-
-#if (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING))
-/* Tells if the scheduler currently is suspended (task-switches can't occur) */
-unsigned char prvTraceIsSchedulerSuspended(void);
-
-/*******************************************************************************
- * INCLUDE_xTaskGetSchedulerState must be set to 1 for tracing to work properly
- ******************************************************************************/
-#undef INCLUDE_xTaskGetSchedulerState
-#define INCLUDE_xTaskGetSchedulerState 1
-
-#endif /* (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)) */
-
-#define TRACE_KERNEL_VERSION 0x1AA1
-#define TRACE_TICK_RATE_HZ configTICK_RATE_HZ /* Defined in "FreeRTOS.h" */
-#define TRACE_CPU_CLOCK_HZ configCPU_CLOCK_HZ /* Defined in "FreeRTOSConfig.h" */
-#define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()
-
-#define TRACE_GET_OS_TICKS() (uiTraceTickCount) /* Streaming only */
-
-/* If using dynamic allocation of snapshot trace buffer... */
-#define TRACE_MALLOC(size) pvPortMalloc(size)
-
-#if defined(configUSE_TIMERS)
-#if (configUSE_TIMERS == 1)
-#undef INCLUDE_xTimerGetTimerDaemonTaskHandle
-#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
-#endif /* configUSE_TIMERS == 1*/
-#endif /* configUSE_TIMERS */
-
-/* For ARM Cortex-M devices - assumes the ARM CMSIS API is available */
-#if (defined (__CORTEX_M))
- #define TRACE_ALLOC_CRITICAL_SECTION() uint32_t __irq_status;
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = __get_PRIMASK(); __set_PRIMASK(1);} /* PRIMASK disables ALL interrupts - allows for tracing in any ISR */
- #define TRACE_EXIT_CRITICAL_SECTION() {__set_PRIMASK(__irq_status);}
-#endif
-
-#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_CORTEX_A9) || (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Renesas_RX600) || (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32) || (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Altera_NiosII))
- #define TRACE_ALLOC_CRITICAL_SECTION() int __irq_status;
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}
- #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}
-#endif
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)
- /* In the Win32 port, there are no real interrupts, so we can use the normal critical sections */
- #define TRACE_ALLOC_CRITICAL_SECTION()
- #define TRACE_ENTER_CRITICAL_SECTION() portENTER_CRITICAL()
- #define TRACE_EXIT_CRITICAL_SECTION() portEXIT_CRITICAL()
-#endif
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_POWERPC_Z4)
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
- /* FreeRTOS v8.0 or later */
- #define TRACE_ALLOC_CRITICAL_SECTION() UBaseType_t __irq_status;
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}
- #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}
-#else
- /* FreeRTOS v7.x */
- #define TRACE_ALLOC_CRITICAL_SECTION() unsigned portBASE_TYPE __irq_status;
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}
- #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}
-#endif
-#endif
-
-#ifndef TRACE_ENTER_CRITICAL_SECTION
- #error "This hardware port has no definition for critical sections! See http://percepio.com/2014/10/27/how-to-define-critical-sections-for-the-recorder/"
-#endif
-
-
-#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_0_1)
- /******************************************************************************
- * Fix for FreeRTOS v9.0.1 to correctly identify xQueuePeek events.
- *
- * In FreeRTOS v9.0.1, the below trace hooks are incorrectly used from three
- * different functions. This as the earlier function xQueueGenericReceive
- * has been replaced by xQueuePeek, xQueueSemaphoreTake and xQueueReceive.
- *
- * xQueueGenericReceive had a parameter "xJustPeeking", used by the trace hooks
- * to tell between xQueuePeek events and others. This is no longer present, so
- * we need another way to correctly identify peek events. Since all three
- * functions call the same trace macros, the context of these macro is unknown.
- *
- * We therefore check the __LINE__ macro inside of the trace macros. This gives
- * the line number of queue.c, where the macros are used. This can be used to
- * tell if the context is xQueuePeek or another function.
- * __LINE__ is a standard compiler feature since ancient times, so it should
- * work on all common compilers.
- *
- * This might seem as a quite brittle and unusual solution, but works in this
- * particular case and is only for FreeRTOS v9.0.1.
- * Future versions of FreeRTOS should not need this fix, as we have submitted
- * a correction of queue.c with individual trace macros for each function.
- ******************************************************************************/
-#define isQueueReceiveHookActuallyPeek (__LINE__ > 1674) /* Half way between the closes trace points */
-
-#elif (TRC_CFG_FREERTOS_VERSION <= TRC_FREERTOS_VERSION_9_0_0)
-#define isQueueReceiveHookActuallyPeek xJustPeeking
-
-#elif (TRC_CFG_FREERTOS_VERSION > TRC_FREERTOS_VERSION_9_0_1)
-#define isQueueReceiveHookActuallyPeek (__LINE__ < 0) /* instead of pdFALSE to fix a warning of "constant condition" */
-
-#endif
-
-extern uint16_t CurrentFilterMask;
-
-extern uint16_t CurrentFilterGroup;
-
-uint8_t prvTraceGetQueueType(void* handle);
-
-uint16_t prvTraceGetTaskNumberLow16(void* handle);
-uint16_t prvTraceGetTaskNumberHigh16(void* handle);
-void prvTraceSetTaskNumberLow16(void* handle, uint16_t value);
-void prvTraceSetTaskNumberHigh16(void* handle, uint16_t value);
-
-uint16_t prvTraceGetQueueNumberLow16(void* handle);
-uint16_t prvTraceGetQueueNumberHigh16(void* handle);
-void prvTraceSetQueueNumberLow16(void* handle, uint16_t value);
-void prvTraceSetQueueNumberHigh16(void* handle, uint16_t value);
-
-#if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-uint16_t prvTraceGetTimerNumberLow16(void* handle);
-uint16_t prvTraceGetTimerNumberHigh16(void* handle);
-void prvTraceSetTimerNumberLow16(void* handle, uint16_t value);
-void prvTraceSetTimerNumberHigh16(void* handle, uint16_t value);
-#endif /* (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-uint16_t prvTraceGetEventGroupNumberLow16(void* handle);
-uint16_t prvTraceGetEventGroupNumberHigh16(void* handle);
-void prvTraceSetEventGroupNumberLow16(void* handle, uint16_t value);
-void prvTraceSetEventGroupNumberHigh16(void* handle, uint16_t value);
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-uint16_t prvTraceGetStreamBufferNumberLow16(void* handle);
-uint16_t prvTraceGetStreamBufferNumberHigh16(void* handle);
-void prvTraceSetStreamBufferNumberLow16(void* handle, uint16_t value);
-void prvTraceSetStreamBufferNumberHigh16(void* handle, uint16_t value);
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#define TRACE_GET_TASK_FILTER(pxTask) prvTraceGetTaskNumberHigh16((void*)pxTask)
-#define TRACE_SET_TASK_FILTER(pxTask, group) prvTraceSetTaskNumberHigh16((void*)pxTask, group)
-
-#define TRACE_GET_QUEUE_FILTER(pxObject) prvTraceGetQueueNumberHigh16((void*)pxObject)
-#define TRACE_SET_QUEUE_FILTER(pxObject, group) prvTraceSetQueueNumberHigh16((void*)pxObject, group)
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-#define TRACE_GET_EVENTGROUP_FILTER(pxObject) prvTraceGetEventGroupNumberHigh16((void*)pxObject)
-#define TRACE_SET_EVENTGROUP_FILTER(pxObject, group) prvTraceSetEventGroupNumberHigh16((void*)pxObject, group)
-#else /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-/* FreeRTOS versions before v10.0 does not support filtering for event groups */
-#define TRACE_GET_EVENTGROUP_FILTER(pxObject) 1
-#define TRACE_SET_EVENTGROUP_FILTER(pxObject, group)
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-#define TRACE_GET_TIMER_FILTER(pxObject) prvTraceGetTimerNumberHigh16((void*)pxObject)
-#define TRACE_SET_TIMER_FILTER(pxObject, group) prvTraceSetTimerNumberHigh16((void*)pxObject, group)
-#else /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-/* FreeRTOS versions before v10.0 does not support filtering for timers */
-#define TRACE_GET_TIMER_FILTER(pxObject) 1
-#define TRACE_SET_TIMER_FILTER(pxObject, group)
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#define TRACE_GET_STREAMBUFFER_FILTER(pxObject) prvTraceGetStreamBufferNumberHigh16((void*)pxObject)
-#define TRACE_SET_STREAMBUFFER_FILTER(pxObject, group) prvTraceSetStreamBufferNumberHigh16((void*)pxObject, group)
-
-/* We can only support filtering if FreeRTOS is at least v7.4 */
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_4)
-#define TRACE_GET_OBJECT_FILTER(CLASS, pxObject) TRACE_GET_##CLASS##_FILTER(pxObject)
-#define TRACE_SET_OBJECT_FILTER(CLASS, pxObject, group) TRACE_SET_##CLASS##_FILTER(pxObject, group)
-#else /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_4) */
-#define TRACE_GET_OBJECT_FILTER(CLASS, pxObject) 1
-#define TRACE_SET_OBJECT_FILTER(CLASS, pxObject, group)
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_4) */
-
-/******************************************************************************/
-/*** Definitions for Snapshot mode ********************************************/
-/******************************************************************************/
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-
-/*** The object classes *******************************************************/
-
-#define TRACE_NCLASSES 9
-#define TRACE_CLASS_QUEUE ((traceObjectClass)0)
-#define TRACE_CLASS_SEMAPHORE ((traceObjectClass)1)
-#define TRACE_CLASS_MUTEX ((traceObjectClass)2)
-#define TRACE_CLASS_TASK ((traceObjectClass)3)
-#define TRACE_CLASS_ISR ((traceObjectClass)4)
-#define TRACE_CLASS_TIMER ((traceObjectClass)5)
-#define TRACE_CLASS_EVENTGROUP ((traceObjectClass)6)
-#define TRACE_CLASS_STREAMBUFFER ((traceObjectClass)7)
-#define TRACE_CLASS_MESSAGEBUFFER ((traceObjectClass)8)
-
-/*** Definitions for Object Table ********************************************/
-#define TRACE_KERNEL_OBJECT_COUNT ((TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP) + (TRC_CFG_NSTREAMBUFFER) + (TRC_CFG_NMESSAGEBUFFER))
-
-/* Queue properties (except name): current number of message in queue */
-#define PropertyTableSizeQueue ((TRC_CFG_NAME_LEN_QUEUE) + 1)
-
-/* Semaphore properties (except name): state (signaled = 1, cleared = 0) */
-#define PropertyTableSizeSemaphore ((TRC_CFG_NAME_LEN_SEMAPHORE) + 1)
-
-/* Mutex properties (except name): owner (task handle, 0 = free) */
-#define PropertyTableSizeMutex ((TRC_CFG_NAME_LEN_MUTEX) + 1)
-
-/* Task properties (except name): Byte 0: Current priority
- Byte 1: state (if already active)
- Byte 2: legacy, not used
- Byte 3: legacy, not used */
-#define PropertyTableSizeTask ((TRC_CFG_NAME_LEN_TASK) + 4)
-
-/* ISR properties: Byte 0: priority
- Byte 1: state (if already active) */
-#define PropertyTableSizeISR ((TRC_CFG_NAME_LEN_ISR) + 2)
-
-/* TRC_CFG_NTIMER properties: Byte 0: state (unused for now) */
-#define PropertyTableSizeTimer ((TRC_CFG_NAME_LEN_TIMER) + 1)
-
-/* TRC_CFG_NEVENTGROUP properties: Byte 0-3: state (unused for now)*/
-#define PropertyTableSizeEventGroup ((TRC_CFG_NAME_LEN_EVENTGROUP) + 4)
-
-/* TRC_CFG_NSTREAMBUFFER properties: Byte 0-3: state (unused for now)*/
-#define PropertyTableSizeStreamBuffer ((TRC_CFG_NAME_LEN_STREAMBUFFER) + 4)
-
-/* TRC_CFG_NMESSAGEBUFFER properties: Byte 0-3: state (unused for now)*/
-#define PropertyTableSizeMessageBuffer ((TRC_CFG_NAME_LEN_MESSAGEBUFFER) + 4)
-
-
-/* The layout of the byte array representing the Object Property Table */
-#define StartIndexQueue (0)
-#define StartIndexSemaphore (StartIndexQueue + (TRC_CFG_NQUEUE) * PropertyTableSizeQueue)
-#define StartIndexMutex (StartIndexSemaphore + (TRC_CFG_NSEMAPHORE) * PropertyTableSizeSemaphore)
-#define StartIndexTask (StartIndexMutex + (TRC_CFG_NMUTEX) * PropertyTableSizeMutex)
-#define StartIndexISR (StartIndexTask + (TRC_CFG_NTASK) * PropertyTableSizeTask)
-#define StartIndexTimer (StartIndexISR + (TRC_CFG_NISR) * PropertyTableSizeISR)
-#define StartIndexEventGroup (StartIndexTimer + (TRC_CFG_NTIMER) * PropertyTableSizeTimer)
-#define StartIndexStreamBuffer (StartIndexEventGroup + (TRC_CFG_NEVENTGROUP) * PropertyTableSizeEventGroup)
-#define StartIndexMessageBuffer (StartIndexStreamBuffer + (TRC_CFG_NSTREAMBUFFER) * PropertyTableSizeStreamBuffer)
-
-/* Number of bytes used by the object table */
-#define TRACE_OBJECT_TABLE_SIZE (StartIndexMessageBuffer + (TRC_CFG_NMESSAGEBUFFER) * PropertyTableSizeMessageBuffer)
-
-/* Flag to tell the context of tracePEND_FUNC_CALL_FROM_ISR */
-extern int uiInEventGroupSetBitsFromISR;
-
-/* Initialization of the object property table */
-void vTraceInitObjectPropertyTable(void);
-
-/* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */
-void vTraceInitObjectHandleStack(void);
-
-/* Returns the "Not enough handles" error message for the specified object class */
-const char* pszTraceGetErrorNotEnoughHandles(traceObjectClass objectclass);
-
-void* prvTraceGetCurrentTaskHandle(void);
-
-/******************************************************************************
- * TraceQueueClassTable
- * Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).
- * Has one entry for each QueueType, gives TRACE_CLASS ID.
- ******************************************************************************/
-extern traceObjectClass TraceQueueClassTable[5];
-
-
-/*** Event codes for snapshot mode - must match Tracealyzer config files ******/
-
-#define NULL_EVENT (0x00UL)
-
-/*******************************************************************************
- * EVENTGROUP_DIV
- *
- * Miscellaneous events.
- ******************************************************************************/
-#define EVENTGROUP_DIV (NULL_EVENT + 1UL) /*0x01*/
-#define DIV_XPS (EVENTGROUP_DIV + 0UL) /*0x01*/
-#define DIV_TASK_READY (EVENTGROUP_DIV + 1UL) /*0x02*/
-#define DIV_NEW_TIME (EVENTGROUP_DIV + 2UL) /*0x03*/
-
-/*******************************************************************************
- * EVENTGROUP_TS
- *
- * Events for storing task-switches and interrupts. The RESUME events are
- * generated if the task/interrupt is already marked active.
- ******************************************************************************/
-#define EVENTGROUP_TS (EVENTGROUP_DIV + 3UL) /*0x04*/
-#define TS_ISR_BEGIN (EVENTGROUP_TS + 0UL) /*0x04*/
-#define TS_ISR_RESUME (EVENTGROUP_TS + 1UL) /*0x05*/
-#define TS_TASK_BEGIN (EVENTGROUP_TS + 2UL) /*0x06*/
-#define TS_TASK_RESUME (EVENTGROUP_TS + 3UL) /*0x07*/
-
-/*******************************************************************************
- * EVENTGROUP_OBJCLOSE_NAME
- *
- * About Close Events
- * When an object is evicted from the object property table (object close), two
- * internal events are stored (EVENTGROUP_OBJCLOSE_NAME and
- * EVENTGROUP_OBJCLOSE_PROP), containing the handle-name mapping and object
- * properties valid up to this point.
- ******************************************************************************/
-#define EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS (EVENTGROUP_TS + 4UL) /*0x08*/
-
-/*******************************************************************************
- * EVENTGROUP_OBJCLOSE_PROP
- *
- * The internal event carrying properties of deleted objects
- * The handle and object class of the closed object is not stored in this event,
- * but is assumed to be the same as in the preceding CLOSE event. Thus, these
- * two events must be generated from within a critical section.
- * When queues are closed, arg1 is the "state" property (i.e., number of
- * buffered messages/signals).
- * When actors are closed, arg1 is priority, arg2 is handle of the "instance
- * finish" event, and arg3 is event code of the "instance finish" event.
- * In this case, the lower three bits is the object class of the instance finish
- * handle. The lower three bits are not used (always zero) when queues are
- * closed since the queue type is given in the previous OBJCLOSE_NAME event.
- ******************************************************************************/
-#define EVENTGROUP_OBJCLOSE_PROP_TRCSUCCESS (EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS + 8UL) /*0x10*/
-
-/*******************************************************************************
- * EVENTGROUP_CREATE
- *
- * The events in this group are used to log Kernel object creations.
- * The lower three bits in the event code gives the object class, i.e., type of
- * create operation (task, queue, semaphore, etc).
- ******************************************************************************/
-#define EVENTGROUP_CREATE_OBJ_TRCSUCCESS (EVENTGROUP_OBJCLOSE_PROP_TRCSUCCESS + 8UL) /*0x18*/
-
-/*******************************************************************************
- * EVENTGROUP_SEND
- *
- * The events in this group are used to log Send/Give events on queues,
- * semaphores and mutexes The lower three bits in the event code gives the
- * object class, i.e., what type of object that is operated on (queue, semaphore
- * or mutex).
- ******************************************************************************/
-#define EVENTGROUP_SEND_TRCSUCCESS (EVENTGROUP_CREATE_OBJ_TRCSUCCESS + 8UL) /*0x20*/
-
-/*******************************************************************************
- * EVENTGROUP_RECEIVE
- *
- * The events in this group are used to log Receive/Take events on queues,
- * semaphores and mutexes. The lower three bits in the event code gives the
- * object class, i.e., what type of object that is operated on (queue, semaphore
- * or mutex).
- ******************************************************************************/
-#define EVENTGROUP_RECEIVE_TRCSUCCESS (EVENTGROUP_SEND_TRCSUCCESS + 8UL) /*0x28*/
-
-/* Send/Give operations, from ISR */
-#define EVENTGROUP_SEND_FROM_ISR_TRCSUCCESS \
- (EVENTGROUP_RECEIVE_TRCSUCCESS + 8UL) /*0x30*/
-
-/* Receive/Take operations, from ISR */
-#define EVENTGROUP_RECEIVE_FROM_ISR_TRCSUCCESS \
- (EVENTGROUP_SEND_FROM_ISR_TRCSUCCESS + 8UL) /*0x38*/
-
-/* "Failed" event type versions of above (timeout, failed allocation, etc) */
-#define EVENTGROUP_KSE_TRCFAILED \
- (EVENTGROUP_RECEIVE_FROM_ISR_TRCSUCCESS + 8UL) /*0x40*/
-
-/* Failed create calls - memory allocation failed */
-#define EVENTGROUP_CREATE_OBJ_TRCFAILED (EVENTGROUP_KSE_TRCFAILED) /*0x40*/
-
-/* Failed send/give - timeout! */
-#define EVENTGROUP_SEND_TRCFAILED (EVENTGROUP_CREATE_OBJ_TRCFAILED + 8UL) /*0x48*/
-
-/* Failed receive/take - timeout! */
-#define EVENTGROUP_RECEIVE_TRCFAILED (EVENTGROUP_SEND_TRCFAILED + 8UL) /*0x50*/
-
-/* Failed non-blocking send/give - queue full */
-#define EVENTGROUP_SEND_FROM_ISR_TRCFAILED (EVENTGROUP_RECEIVE_TRCFAILED + 8UL) /*0x58*/
-
-/* Failed non-blocking receive/take - queue empty */
-#define EVENTGROUP_RECEIVE_FROM_ISR_TRCFAILED \
- (EVENTGROUP_SEND_FROM_ISR_TRCFAILED + 8UL) /*0x60*/
-
-/* Events when blocking on receive/take */
-#define EVENTGROUP_RECEIVE_TRCBLOCK \
- (EVENTGROUP_RECEIVE_FROM_ISR_TRCFAILED + 8UL) /*0x68*/
-
-/* Events when blocking on send/give */
-#define EVENTGROUP_SEND_TRCBLOCK (EVENTGROUP_RECEIVE_TRCBLOCK + 8UL) /*0x70*/
-
-/* Events on queue peek (receive) */
-#define EVENTGROUP_PEEK_TRCSUCCESS (EVENTGROUP_SEND_TRCBLOCK + 8UL) /*0x78*/
-
-/* Events on object delete (vTaskDelete or vQueueDelete) */
-#define EVENTGROUP_DELETE_OBJ_TRCSUCCESS (EVENTGROUP_PEEK_TRCSUCCESS + 8UL) /*0x80*/
-
-/* Other events - object class is implied: TASK */
-#define EVENTGROUP_OTHERS (EVENTGROUP_DELETE_OBJ_TRCSUCCESS + 8UL) /*0x88*/
-#define TASK_DELAY_UNTIL (EVENTGROUP_OTHERS + 0UL) /*0x88*/
-#define TASK_DELAY (EVENTGROUP_OTHERS + 1UL) /*0x89*/
-#define TASK_SUSPEND (EVENTGROUP_OTHERS + 2UL) /*0x8A*/
-#define TASK_RESUME (EVENTGROUP_OTHERS + 3UL) /*0x8B*/
-#define TASK_RESUME_FROM_ISR (EVENTGROUP_OTHERS + 4UL) /*0x8C*/
-#define TASK_PRIORITY_SET (EVENTGROUP_OTHERS + 5UL) /*0x8D*/
-#define TASK_PRIORITY_INHERIT (EVENTGROUP_OTHERS + 6UL) /*0x8E*/
-#define TASK_PRIORITY_DISINHERIT (EVENTGROUP_OTHERS + 7UL) /*0x8F*/
-
-#define EVENTGROUP_MISC_PLACEHOLDER (EVENTGROUP_OTHERS + 8UL) /*0x90*/
-#define PEND_FUNC_CALL (EVENTGROUP_MISC_PLACEHOLDER+0UL) /*0x90*/
-#define PEND_FUNC_CALL_FROM_ISR (EVENTGROUP_MISC_PLACEHOLDER+1UL) /*0x91*/
-#define PEND_FUNC_CALL_TRCFAILED (EVENTGROUP_MISC_PLACEHOLDER+2UL) /*0x92*/
-#define PEND_FUNC_CALL_FROM_ISR_TRCFAILED (EVENTGROUP_MISC_PLACEHOLDER+3UL) /*0x93*/
-#define MEM_MALLOC_SIZE (EVENTGROUP_MISC_PLACEHOLDER+4UL) /*0x94*/
-#define MEM_MALLOC_ADDR (EVENTGROUP_MISC_PLACEHOLDER+5UL) /*0x95*/
-#define MEM_FREE_SIZE (EVENTGROUP_MISC_PLACEHOLDER+6UL) /*0x96*/
-#define MEM_FREE_ADDR (EVENTGROUP_MISC_PLACEHOLDER+7UL) /*0x97*/
-
-/* User events */
-#define EVENTGROUP_USEREVENT (EVENTGROUP_MISC_PLACEHOLDER + 8UL) /*0x98*/
-#define USER_EVENT (EVENTGROUP_USEREVENT + 0UL)
-
-/* Allow for 0-15 arguments (the number of args is added to event code) */
-#define USER_EVENT_LAST (EVENTGROUP_USEREVENT + 15UL) /*0xA7*/
-
-/*******************************************************************************
- * XTS Event - eXtended TimeStamp events
- * The timestamps used in the recorder are "differential timestamps" (DTS), i.e.
- * the time since the last stored event. The DTS fields are either 1 or 2 bytes
- * in the other events, depending on the bytes available in the event struct.
- * If the time since the last event (the DTS) is larger than allowed for by
- * the DTS field of the current event, an XTS event is inserted immediately
- * before the original event. The XTS event contains up to 3 additional bytes
- * of the DTS value - the higher bytes of the true DTS value. The lower 1-2
- * bytes are stored in the normal DTS field.
- * There are two types of XTS events, XTS8 and XTS16. An XTS8 event is stored
- * when there is only room for 1 byte (8 bit) DTS data in the original event,
- * which means a limit of 0xFF (255UL). The XTS16 is used when the original event
- * has a 16 bit DTS field and thereby can handle values up to 0xFFFF (65535UL).
- *
- * Using a very high frequency time base can result in many XTS events.
- * Preferably, the time between two OS ticks should fit in 16 bits, i.e.,
- * at most 65535. If your time base has a higher frequency, you can define
- * the TRACE
- ******************************************************************************/
-
-#define EVENTGROUP_SYS (EVENTGROUP_USEREVENT + 16UL) /*0xA8*/
-#define XTS8 (EVENTGROUP_SYS + 0UL) /*0xA8*/
-#define XTS16 (EVENTGROUP_SYS + 1UL) /*0xA9*/
-#define EVENT_BEING_WRITTEN (EVENTGROUP_SYS + 2UL) /*0xAA*/
-#define RESERVED_DUMMY_CODE (EVENTGROUP_SYS + 3UL) /*0xAB*/
-#define LOW_POWER_BEGIN (EVENTGROUP_SYS + 4UL) /*0xAC*/
-#define LOW_POWER_END (EVENTGROUP_SYS + 5UL) /*0xAD*/
-#define XID (EVENTGROUP_SYS + 6UL) /*0xAE*/
-#define XTS16L (EVENTGROUP_SYS + 7UL) /*0xAF*/
-
-#define EVENTGROUP_TIMER (EVENTGROUP_SYS + 8UL) /*0xB0*/
-#define TIMER_CREATE (EVENTGROUP_TIMER + 0UL) /*0xB0*/
-#define TIMER_START (EVENTGROUP_TIMER + 1UL) /*0xB1*/
-#define TIMER_RST (EVENTGROUP_TIMER + 2UL) /*0xB2*/
-#define TIMER_STOP (EVENTGROUP_TIMER + 3UL) /*0xB3*/
-#define TIMER_CHANGE_PERIOD (EVENTGROUP_TIMER + 4UL) /*0xB4*/
-#define TIMER_DELETE_OBJ (EVENTGROUP_TIMER + 5UL) /*0xB5*/
-#define TIMER_START_FROM_ISR (EVENTGROUP_TIMER + 6UL) /*0xB6*/
-#define TIMER_RESET_FROM_ISR (EVENTGROUP_TIMER + 7UL) /*0xB7*/
-#define TIMER_STOP_FROM_ISR (EVENTGROUP_TIMER + 8UL) /*0xB8*/
-
-#define TIMER_CREATE_TRCFAILED (EVENTGROUP_TIMER + 9UL) /*0xB9*/
-#define TIMER_START_TRCFAILED (EVENTGROUP_TIMER + 10UL) /*0xBA*/
-#define TIMER_RESET_TRCFAILED (EVENTGROUP_TIMER + 11UL) /*0xBB*/
-#define TIMER_STOP_TRCFAILED (EVENTGROUP_TIMER + 12UL) /*0xBC*/
-#define TIMER_CHANGE_PERIOD_TRCFAILED (EVENTGROUP_TIMER + 13UL) /*0xBD*/
-#define TIMER_DELETE_TRCFAILED (EVENTGROUP_TIMER + 14UL) /*0xBE*/
-#define TIMER_START_FROM_ISR_TRCFAILED (EVENTGROUP_TIMER + 15UL) /*0xBF*/
-#define TIMER_RESET_FROM_ISR_TRCFAILED (EVENTGROUP_TIMER + 16UL) /*0xC0*/
-#define TIMER_STOP_FROM_ISR_TRCFAILED (EVENTGROUP_TIMER + 17UL) /*0xC1*/
-
-#define EVENTGROUP_EG (EVENTGROUP_TIMER + 18UL) /*0xC2*/
-#define EVENT_GROUP_CREATE (EVENTGROUP_EG + 0UL) /*0xC2*/
-#define EVENT_GROUP_CREATE_TRCFAILED (EVENTGROUP_EG + 1UL) /*0xC3*/
-#define EVENT_GROUP_SYNC_TRCBLOCK (EVENTGROUP_EG + 2UL) /*0xC4*/
-#define EVENT_GROUP_SYNC_END (EVENTGROUP_EG + 3UL) /*0xC5*/
-#define EVENT_GROUP_WAIT_BITS_TRCBLOCK (EVENTGROUP_EG + 4UL) /*0xC6*/
-#define EVENT_GROUP_WAIT_BITS_END (EVENTGROUP_EG + 5UL) /*0xC7*/
-#define EVENT_GROUP_CLEAR_BITS (EVENTGROUP_EG + 6UL) /*0xC8*/
-#define EVENT_GROUP_CLEAR_BITS_FROM_ISR (EVENTGROUP_EG + 7UL) /*0xC9*/
-#define EVENT_GROUP_SET_BITS (EVENTGROUP_EG + 8UL) /*0xCA*/
-#define EVENT_GROUP_DELETE_OBJ (EVENTGROUP_EG + 9UL) /*0xCB*/
-#define EVENT_GROUP_SYNC_END_TRCFAILED (EVENTGROUP_EG + 10UL) /*0xCC*/
-#define EVENT_GROUP_WAIT_BITS_END_TRCFAILED (EVENTGROUP_EG + 11UL) /*0xCD*/
-#define EVENT_GROUP_SET_BITS_FROM_ISR (EVENTGROUP_EG + 12UL) /*0xCE*/
-#define EVENT_GROUP_SET_BITS_FROM_ISR_TRCFAILED (EVENTGROUP_EG + 13UL) /*0xCF*/
-
-#define TASK_INSTANCE_FINISHED_NEXT_KSE (EVENTGROUP_EG + 14UL) /*0xD0*/
-#define TASK_INSTANCE_FINISHED_DIRECT (EVENTGROUP_EG + 15UL) /*0xD1*/
-
-#define TRACE_TASK_NOTIFY_GROUP (EVENTGROUP_EG + 16UL) /*0xD2*/
-#define TRACE_TASK_NOTIFY (TRACE_TASK_NOTIFY_GROUP + 0UL) /*0xD2*/
-#define TRACE_TASK_NOTIFY_TAKE (TRACE_TASK_NOTIFY_GROUP + 1UL) /*0xD3*/
-#define TRACE_TASK_NOTIFY_TAKE_TRCBLOCK (TRACE_TASK_NOTIFY_GROUP + 2UL) /*0xD4*/
-#define TRACE_TASK_NOTIFY_TAKE_TRCFAILED (TRACE_TASK_NOTIFY_GROUP + 3UL) /*0xD5*/
-#define TRACE_TASK_NOTIFY_WAIT (TRACE_TASK_NOTIFY_GROUP + 4UL) /*0xD6*/
-#define TRACE_TASK_NOTIFY_WAIT_TRCBLOCK (TRACE_TASK_NOTIFY_GROUP + 5UL) /*0xD7*/
-#define TRACE_TASK_NOTIFY_WAIT_TRCFAILED (TRACE_TASK_NOTIFY_GROUP + 6UL) /*0xD8*/
-#define TRACE_TASK_NOTIFY_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 7UL) /*0xD9*/
-#define TRACE_TASK_NOTIFY_GIVE_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 8UL) /*0xDA*/
-
-#define TIMER_EXPIRED (TRACE_TASK_NOTIFY_GROUP + 9UL) /* 0xDB */
-
- /* Events on queue peek (receive) */
-#define EVENTGROUP_PEEK_TRCBLOCK (TRACE_TASK_NOTIFY_GROUP + 10UL) /*0xDC*/
-/* peek block on queue: 0xDC */
-/* peek block on semaphore: 0xDD */
-/* peek block on mutex: 0xDE */
-
-/* Events on queue peek (receive) */
-#define EVENTGROUP_PEEK_TRCFAILED (EVENTGROUP_PEEK_TRCBLOCK + 3UL) /*0xDF*/
-/* peek failed on queue: 0xDF */
-/* peek failed on semaphore: 0xE0 */
-/* peek failed on mutex: 0xE1 */
-
-#define EVENTGROUP_STREAMBUFFER_DIV (EVENTGROUP_PEEK_TRCFAILED + 3UL) /*0xE2*/
-#define TRACE_STREAMBUFFER_RESET (EVENTGROUP_STREAMBUFFER_DIV + 0) /*0xE2*/
-#define TRACE_MESSAGEBUFFER_RESET (EVENTGROUP_STREAMBUFFER_DIV + 1UL) /*0xE3*/
-#define TRACE_STREAMBUFFER_OBJCLOSE_NAME_TRCSUCCESS (EVENTGROUP_STREAMBUFFER_DIV + 2UL) /*0xE4*/
-#define TRACE_MESSAGEBUFFER_OBJCLOSE_NAME_TRCSUCCESS (EVENTGROUP_STREAMBUFFER_DIV + 3UL) /*0xE5*/
-#define TRACE_STREAMBUFFER_OBJCLOSE_PROP_TRCSUCCESS (EVENTGROUP_STREAMBUFFER_DIV + 4UL) /*0xE6*/
-#define TRACE_MESSAGEBUFFER_OBJCLOSE_PROP_TRCSUCCESS (EVENTGROUP_STREAMBUFFER_DIV + 5UL) /*0xE7*/
-
-/* The following are using previously "lost" event codes */
-#define TRACE_STREAMBUFFER_CREATE_OBJ_TRCSUCCESS (EVENTGROUP_CREATE_OBJ_TRCSUCCESS + 4UL) /*0x1C*/
-#define TRACE_STREAMBUFFER_CREATE_OBJ_TRCFAILED (EVENTGROUP_CREATE_OBJ_TRCFAILED + 4UL) /*0x44*/
-#define TRACE_STREAMBUFFER_DELETE_OBJ_TRCSUCCESS (EVENTGROUP_DELETE_OBJ_TRCSUCCESS + 4UL) /*0x84*/
-#define TRACE_STREAMBUFFER_SEND_TRCSUCCESS (EVENTGROUP_SEND_TRCSUCCESS + 3UL) /*0x23*/
-#define TRACE_STREAMBUFFER_SEND_TRCBLOCK (EVENTGROUP_SEND_TRCBLOCK + 3UL) /*0x73*/
-#define TRACE_STREAMBUFFER_SEND_TRCFAILED (EVENTGROUP_SEND_TRCFAILED + 3UL) /*0x4B*/
-#define TRACE_STREAMBUFFER_RECEIVE_TRCSUCCESS (EVENTGROUP_RECEIVE_TRCSUCCESS + 3UL) /*0x2B*/
-#define TRACE_STREAMBUFFER_RECEIVE_TRCBLOCK (EVENTGROUP_RECEIVE_TRCBLOCK + 3UL) /*0x6B*/
-#define TRACE_STREAMBUFFER_RECEIVE_TRCFAILED (EVENTGROUP_RECEIVE_TRCFAILED + 3UL) /*0x53*/
-#define TRACE_STREAMBUFFER_SEND_FROM_ISR_TRCSUCCESS (EVENTGROUP_SEND_FROM_ISR_TRCSUCCESS + 3UL) /*0x33*/
-#define TRACE_STREAMBUFFER_SEND_FROM_ISR_TRCFAILED (EVENTGROUP_SEND_FROM_ISR_TRCFAILED + 3UL) /*0x5B*/
-#define TRACE_STREAMBUFFER_RECEIVE_FROM_ISR_TRCSUCCESS (EVENTGROUP_RECEIVE_FROM_ISR_TRCSUCCESS + 3UL) /*0x3B*/
-#define TRACE_STREAMBUFFER_RECEIVE_FROM_ISR_TRCFAILED (EVENTGROUP_RECEIVE_FROM_ISR_TRCFAILED + 3UL) /*0x63*/
-
-/* The following are using previously "lost" event codes. These macros aren't even directly referenced, instead we do (equivalent STREAMBUFFER code) + 1. */
-#define TRACE_MESSAGEBUFFER_CREATE_OBJ_TRCSUCCESS (EVENTGROUP_CREATE_OBJ_TRCSUCCESS + 5UL) /*0x1D*/
-#define TRACE_MESSAGEBUFFER_CREATE_OBJ_TRCFAILED (EVENTGROUP_CREATE_OBJ_TRCFAILED + 5UL) /*0x45*/
-#define TRACE_MESSAGEBUFFER_DELETE_OBJ_TRCSUCCESS (EVENTGROUP_DELETE_OBJ_TRCSUCCESS + 5UL) /*0x85*/
-#define TRACE_MESSAGEBUFFER_SEND_TRCSUCCESS (EVENTGROUP_SEND_TRCSUCCESS + 4UL) /*0x24*/
-#define TRACE_MESSAGEBUFFER_SEND_TRCBLOCK (EVENTGROUP_SEND_TRCBLOCK + 4UL) /*0x74*/
-#define TRACE_MESSAGEBUFFER_SEND_TRCFAILED (EVENTGROUP_SEND_TRCFAILED + 4UL) /*0x4C*/
-#define TRACE_MESSAGEBUFFER_RECEIVE_TRCSUCCESS (EVENTGROUP_RECEIVE_TRCSUCCESS + 4UL) /*0x2C*/
-#define TRACE_MESSAGEBUFFER_RECEIVE_TRCBLOCK (EVENTGROUP_RECEIVE_TRCBLOCK + 4UL) /*0x6C*/
-#define TRACE_MESSAGEBUFFER_RECEIVE_TRCFAILED (EVENTGROUP_RECEIVE_TRCFAILED + 4UL) /*0x54*/
-#define TRACE_MESSAGEBUFFER_SEND_FROM_ISR_TRCSUCCESS (EVENTGROUP_SEND_FROM_ISR_TRCSUCCESS + 4UL) /*0x34*/
-#define TRACE_MESSAGEBUFFER_SEND_FROM_ISR_TRCFAILED (EVENTGROUP_SEND_FROM_ISR_TRCFAILED + 4UL) /*0x5C*/
-#define TRACE_MESSAGEBUFFER_RECEIVE_FROM_ISR_TRCSUCCESS (EVENTGROUP_RECEIVE_FROM_ISR_TRCSUCCESS + 4UL) /*0x3C*/
-#define TRACE_MESSAGEBUFFER_RECEIVE_FROM_ISR_TRCFAILED (EVENTGROUP_RECEIVE_FROM_ISR_TRCFAILED + 4UL) /*0x64*/
-
-/* LAST EVENT (0xE7) */
-
-/****************************
-* MACROS TO GET TRACE CLASS *
-****************************/
-#define TRACE_GET_TRACE_CLASS_FROM_TASK_CLASS(kernelClass) (TRACE_CLASS_TASK)
-#define TRACE_GET_TRACE_CLASS_FROM_TASK_OBJECT(pxObject) (TRACE_CLASS_TASK)
-
-#define TRACE_GET_TRACE_CLASS_FROM_QUEUE_CLASS(kernelClass) TraceQueueClassTable[kernelClass]
-#define TRACE_GET_TRACE_CLASS_FROM_QUEUE_OBJECT(pxObject) TRACE_GET_TRACE_CLASS_FROM_QUEUE_CLASS(prvTraceGetQueueType(pxObject))
-
-#define TRACE_GET_TRACE_CLASS_FROM_TIMER_CLASS(kernelClass) (TRACE_CLASS_TIMER)
-#define TRACE_GET_TRACE_CLASS_FROM_TIMER_OBJECT(pxObject) (TRACE_CLASS_TIMER)
-
-#define TRACE_GET_TRACE_CLASS_FROM_EVENTGROUP_CLASS(kernelClass) (TRACE_CLASS_EVENTGROUP)
-#define TRACE_GET_TRACE_CLASS_FROM_EVENTGROUP_OBJECT(pxObject) (TRACE_CLASS_EVENTGROUP)
-
-/* TRACE_GET_TRACE_CLASS_FROM_STREAMBUFFER_CLASS can only be accessed with a parameter indicating if it is a MessageBuffer */
-#define TRACE_GET_TRACE_CLASS_FROM_STREAMBUFFER_CLASS(xIsMessageBuffer) (xIsMessageBuffer == 1 ? TRACE_CLASS_MESSAGEBUFFER : TRACE_CLASS_STREAMBUFFER)
-#define TRACE_GET_TRACE_CLASS_FROM_STREAMBUFFER_OBJECT(pxObject) (prvGetStreamBufferType(pxObject) == 1 ? TRACE_CLASS_MESSAGEBUFFER : TRACE_CLASS_STREAMBUFFER)
-
-/* Generic versions */
-#define TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass) TRACE_GET_TRACE_CLASS_FROM_##CLASS##_CLASS(kernelClass)
-#define TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject) TRACE_GET_TRACE_CLASS_FROM_##CLASS##_OBJECT(pxObject)
-
-/******************************
-* MACROS TO GET OBJECT NUMBER *
-******************************/
-#define TRACE_GET_TASK_NUMBER(pxTCB) (traceHandle)(prvTraceGetTaskNumberLow16(pxTCB))
-#define TRACE_SET_TASK_NUMBER(pxTCB) prvTraceSetTaskNumberLow16(pxTCB, prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(TASK, pxTCB)));
-
-#define TRACE_GET_QUEUE_NUMBER(queue) ( ( traceHandle ) prvTraceGetQueueNumberLow16(queue) )
-#define TRACE_SET_QUEUE_NUMBER(queue) prvTraceSetQueueNumberLow16(queue, (uint16_t)prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, queue)));
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-#define TRACE_GET_TIMER_NUMBER(tmr) ( ( traceHandle ) prvTraceGetTimerNumberLow16(tmr) )
-#define TRACE_SET_TIMER_NUMBER(tmr) prvTraceSetTimerNumberLow16(tmr, (uint16_t)prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(TIMER, tmr)));
-#else /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-#define TRACE_GET_TIMER_NUMBER(tmr) ( ( traceHandle ) ((Timer_t*)tmr)->uxTimerNumber )
-#define TRACE_SET_TIMER_NUMBER(tmr) ((Timer_t*)tmr)->uxTimerNumber = prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(TIMER, tmr));
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-#define TRACE_GET_EVENTGROUP_NUMBER(eg) ( ( traceHandle ) prvTraceGetEventGroupNumberLow16(eg) )
-#define TRACE_SET_EVENTGROUP_NUMBER(eg) prvTraceSetEventGroupNumberLow16(eg, (uint16_t)prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(EVENTGROUP, eg)));
-#else /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-#define TRACE_GET_EVENTGROUP_NUMBER(eg) ( ( traceHandle ) uxEventGroupGetNumber(eg) )
-#define TRACE_SET_EVENTGROUP_NUMBER(eg) ((EventGroup_t*)eg)->uxEventGroupNumber = prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(EVENTGROUP, eg));
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-
-#define TRACE_GET_STREAMBUFFER_NUMBER(sb) ( ( traceHandle ) prvTraceGetStreamBufferNumberLow16(sb) )
-#define TRACE_SET_STREAMBUFFER_NUMBER(sb) prvTraceSetStreamBufferNumberLow16(sb, (uint16_t)prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(STREAMBUFFER, sb)));
-
-/* Generic versions */
-#define TRACE_GET_OBJECT_NUMBER(CLASS, pxObject) TRACE_GET_##CLASS##_NUMBER(pxObject)
-#define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) TRACE_SET_##CLASS##_NUMBER(pxObject)
-
-/******************************
-* MACROS TO GET EVENT CODES *
-******************************/
-#define TRACE_GET_TASK_CLASS_EVENT_CODE(SERVICE, RESULT, kernelClass) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_CLASS_TRACE_CLASS(TASK, kernelClass))
-#define TRACE_GET_QUEUE_CLASS_EVENT_CODE(SERVICE, RESULT, kernelClass) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_CLASS_TRACE_CLASS(QUEUE, kernelClass))
-#define TRACE_GET_TIMER_CLASS_EVENT_CODE(SERVICE, RESULT, kernelClass) -- THIS IS NOT USED --
-#define TRACE_GET_EVENTGROUP_CLASS_EVENT_CODE(SERVICE, RESULT, kernelClass) -- THIS IS NOT USED --
-#define TRACE_GET_STREAMBUFFER_CLASS_EVENT_CODE(SERVICE, RESULT, isMessageBuffer) (uint8_t)(TRACE_STREAMBUFFER_##SERVICE##_##RESULT + (uint8_t)isMessageBuffer)
-
-#define TRACE_GET_TASK_OBJECT_EVENT_CODE(SERVICE, RESULT, pxTCB) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_CLASS_TASK)
-#define TRACE_GET_QUEUE_OBJECT_EVENT_CODE(SERVICE, RESULT, pxObject) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, pxObject))
-#define TRACE_GET_TIMER_OBJECT_EVENT_CODE(SERVICE, RESULT, UNUSED) -- THIS IS NOT USED --
-#define TRACE_GET_EVENTGROUP_OBJECT_EVENT_CODE(SERVICE, RESULT, UNUSED) -- THIS IS NOT USED --
-#define TRACE_GET_STREAMBUFFER_OBJECT_EVENT_CODE(SERVICE, RESULT, pxObject) (uint8_t)(TRACE_STREAMBUFFER_##SERVICE##_##RESULT + prvGetStreamBufferType(pxObject))
-
-/* Generic versions */
-#define TRACE_GET_CLASS_EVENT_CODE(SERVICE, RESULT, CLASS, kernelClass) TRACE_GET_##CLASS##_CLASS_EVENT_CODE(SERVICE, RESULT, kernelClass)
-#define TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject) TRACE_GET_##CLASS##_OBJECT_EVENT_CODE(SERVICE, RESULT, pxObject)
-
-/******************************
-* SPECIAL MACROS FOR TASKS *
-******************************/
-#define TRACE_GET_TASK_PRIORITY(pxTCB) ((uint8_t)pxTCB->uxPriority)
-#define TRACE_GET_TASK_NAME(pxTCB) ((char*)pxTCB->pcTaskName)
-
-/*** The trace macros for snapshot mode **************************************/
-
-/* A macro that will update the tick count when returning from tickless idle */
-#undef traceINCREASE_TICK_COUNT
-#define traceINCREASE_TICK_COUNT( xCount )
-
-/* Called for each task that becomes ready */
-#undef traceMOVED_TASK_TO_READY_STATE
-#define traceMOVED_TASK_TO_READY_STATE( pxTCB ) \
- trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB);
-
-/* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */
-#undef traceTASK_INCREMENT_TICK
-
-#if (TRC_CFG_FREERTOS_VERSION <= TRC_FREERTOS_VERSION_7_4)
-
-#define traceTASK_INCREMENT_TICK( xTickCount ) \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxMissedTicks == 0) { trcKERNEL_HOOKS_INCREMENT_TICK(); } \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE) { trcKERNEL_HOOKS_NEW_TIME(DIV_NEW_TIME, xTickCount + 1); }
-
-#else
-
-#define traceTASK_INCREMENT_TICK( xTickCount ) \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxPendedTicks == 0) { trcKERNEL_HOOKS_INCREMENT_TICK(); } \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE) { trcKERNEL_HOOKS_NEW_TIME(DIV_NEW_TIME, xTickCount + 1); }
-
-#endif
-
-/* Called on each task-switch */
-#undef traceTASK_SWITCHED_IN
-#define traceTASK_SWITCHED_IN() \
- trcKERNEL_HOOKS_TASK_SWITCH(TRACE_GET_CURRENT_TASK());
-
-/* Called on vTaskCreate */
-#undef traceTASK_CREATE
-#define traceTASK_CREATE(pxNewTCB) \
- if (pxNewTCB != NULL) \
- { \
- trcKERNEL_HOOKS_TASK_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE_OBJ, TRCSUCCESS, TASK, pxNewTCB), TASK, pxNewTCB); \
- }
-
-/* Called in vTaskCreate, if it fails (typically if the stack can not be allocated) */
-#undef traceTASK_CREATE_FAILED
-#define traceTASK_CREATE_FAILED() \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TRACE_GET_CLASS_EVENT_CODE(CREATE_OBJ, TRCFAILED, TASK, NOT_USED), 0);
-
-/* Called on vTaskDelete */
-#undef traceTASK_DELETE
-#define traceTASK_DELETE( pxTaskToDelete ) \
- { TRACE_ALLOC_CRITICAL_SECTION(); \
- TRACE_ENTER_CRITICAL_SECTION(); \
- trcKERNEL_HOOKS_TASK_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE_OBJ, TRCSUCCESS, TASK, pxTaskToDelete), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, TASK, pxTaskToDelete), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, TASK, pxTaskToDelete), pxTaskToDelete); \
- TRACE_EXIT_CRITICAL_SECTION(); }
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-
-#if defined(configUSE_TICKLESS_IDLE)
-#if (configUSE_TICKLESS_IDLE != 0)
-
-#undef traceLOW_POWER_IDLE_BEGIN
-#define traceLOW_POWER_IDLE_BEGIN() \
- { \
- extern uint32_t trace_disable_timestamp; \
- prvTraceStoreLowPower(0); \
- trace_disable_timestamp = 1; \
- }
-
-#undef traceLOW_POWER_IDLE_END
-#define traceLOW_POWER_IDLE_END() \
- { \
- extern uint32_t trace_disable_timestamp; \
- trace_disable_timestamp = 0; \
- prvTraceStoreLowPower(1); \
- }
-
-#endif /* (configUSE_TICKLESS_IDLE != 0) */
-#endif /* defined(configUSE_TICKLESS_IDLE) */
-
-/* Called on vTaskSuspend */
-#undef traceTASK_SUSPEND
-#define traceTASK_SUSPEND( pxTaskToSuspend ) \
- trcKERNEL_HOOKS_TASK_SUSPEND(TASK_SUSPEND, pxTaskToSuspend);
-
-/* Called from special case with timer only */
-#undef traceTASK_DELAY_SUSPEND
-#define traceTASK_DELAY_SUSPEND( pxTaskToSuspend ) \
- trcKERNEL_HOOKS_TASK_SUSPEND(TASK_SUSPEND, pxTaskToSuspend); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-
-/* Called on vTaskDelay - note the use of FreeRTOS variable xTicksToDelay */
-#undef traceTASK_DELAY
-#define traceTASK_DELAY() \
- trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY, pxCurrentTCB, xTicksToDelay); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-
-/* Called on vTaskDelayUntil - note the use of FreeRTOS variable xTimeToWake */
-#undef traceTASK_DELAY_UNTIL
-#if TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0
-#define traceTASK_DELAY_UNTIL(xTimeToWake) \
- trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY_UNTIL, pxCurrentTCB, xTimeToWake); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_DELAY_UNTIL() \
- trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY_UNTIL, pxCurrentTCB, xTimeToWake); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-
-/* Called in xQueueCreate, and thereby for all other object based on queues, such as semaphores. */
-#undef traceQUEUE_CREATE
-#define traceQUEUE_CREATE( pxNewQueue ) \
- trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE_OBJ, TRCSUCCESS, QUEUE, pxNewQueue), QUEUE, pxNewQueue);
-
-/* Called in xQueueCreate, if the queue creation fails */
-#undef traceQUEUE_CREATE_FAILED
-#define traceQUEUE_CREATE_FAILED( queueType ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TRACE_GET_CLASS_EVENT_CODE(CREATE_OBJ, TRCFAILED, QUEUE, queueType), 0);
-
-/* Called on vQueueDelete */
-#undef traceQUEUE_DELETE
-#define traceQUEUE_DELETE( pxQueue ) \
- { TRACE_ALLOC_CRITICAL_SECTION(); \
- TRACE_ENTER_CRITICAL_SECTION(); \
- trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE_OBJ, TRCSUCCESS, QUEUE, pxQueue), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, QUEUE, pxQueue), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- TRACE_EXIT_CRITICAL_SECTION(); }
-
-/* This macro is not necessary as of FreeRTOS v9.0.0 */
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0)
-/* Called in xQueueCreateMutex, and thereby also from xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex */
-#undef traceCREATE_MUTEX
-#define traceCREATE_MUTEX( pxNewQueue ) \
- trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE_OBJ, TRCSUCCESS, QUEUE, pxNewQueue), QUEUE, pxNewQueue);
-
-/* Called in xQueueCreateMutex when the operation fails (when memory allocation fails) */
-#undef traceCREATE_MUTEX_FAILED
-#define traceCREATE_MUTEX_FAILED() \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TRACE_GET_CLASS_EVENT_CODE(CREATE_OBJ, TRCFAILED, QUEUE, queueQUEUE_TYPE_MUTEX), 0);
-#endif /* (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0) */
-
-/* Called when the Mutex can not be given, since not holder */
-#undef traceGIVE_MUTEX_RECURSIVE_FAILED
-#define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, QUEUE, pxMutex), QUEUE, pxMutex);
-
-/* Called when a message is sent to a queue */ /* CS IS NEW ! */
-#undef traceQUEUE_SEND
-#define traceQUEUE_SEND( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(QUEUE, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, pxQueue) == TRACE_CLASS_MUTEX ? (uint8_t)0 : (uint8_t)(pxQueue->uxMessagesWaiting + 1));
-
-/* Called when a message failed to be sent to a queue (timeout) */
-#undef traceQUEUE_SEND_FAILED
-#define traceQUEUE_SEND_FAILED( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue);
-
-/* Called when the task is blocked due to a send operation on a full queue */
-#undef traceBLOCKING_ON_QUEUE_SEND
-#define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCBLOCK, QUEUE, pxQueue), QUEUE, pxQueue);
-
-/* Called when a message is received from a queue */
-#undef traceQUEUE_RECEIVE
-#define traceQUEUE_RECEIVE( pxQueue ) \
- if (isQueueReceiveHookActuallyPeek) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- } \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(QUEUE, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, pxQueue) == TRACE_CLASS_MUTEX ? (uint8_t)TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()) : (uint8_t)(pxQueue->uxMessagesWaiting - 1));
-
-/* Called when a receive operation on a queue fails (timeout) */
-#undef traceQUEUE_RECEIVE_FAILED
-#define traceQUEUE_RECEIVE_FAILED( pxQueue ) \
- if (isQueueReceiveHookActuallyPeek) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue); \
- }
-
-/* Called when the task is blocked due to a receive operation on an empty queue */
-#undef traceBLOCKING_ON_QUEUE_RECEIVE
-#define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) \
- if (isQueueReceiveHookActuallyPeek) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCBLOCK, QUEUE, pxQueue), QUEUE, pxQueue); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, QUEUE, pxQueue), QUEUE, pxQueue); \
- } \
- if (TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, pxQueue) != TRACE_CLASS_MUTEX) \
- { \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED(); \
- }
-
-/* Called on xQueuePeek */
-#undef traceQUEUE_PEEK
-#define traceQUEUE_PEEK( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue);
-
-/* Called on xQueuePeek fail/timeout (added in FreeRTOS v9.0.2) */
-#undef traceQUEUE_PEEK_FAILED
-#define traceQUEUE_PEEK_FAILED( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue);
-
-/* Called on xQueuePeek blocking (added in FreeRTOS v9.0.2) */
-#undef traceBLOCKING_ON_QUEUE_PEEK
-#define traceBLOCKING_ON_QUEUE_PEEK( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(PEEK, TRCBLOCK, QUEUE, pxQueue), QUEUE, pxQueue); \
- if (TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, pxQueue) != TRACE_CLASS_MUTEX) \
- { \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED(); \
- }
-
-/* Called when a message is sent from interrupt context, e.g., using xQueueSendFromISR */
-#undef traceQUEUE_SEND_FROM_ISR
-#define traceQUEUE_SEND_FROM_ISR( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(SEND_FROM_ISR, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(QUEUE, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting + 1));
-
-/* Called when a message send from interrupt context fails (since the queue was full) */
-#undef traceQUEUE_SEND_FROM_ISR_FAILED
-#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(SEND_FROM_ISR, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue);
-
-/* Called when a message is received in interrupt context, e.g., using xQueueReceiveFromISR */
-#undef traceQUEUE_RECEIVE_FROM_ISR
-#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE_FROM_ISR, TRCSUCCESS, QUEUE, pxQueue), QUEUE, pxQueue); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(QUEUE, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting - 1));
-
-/* Called when a message receive from interrupt context fails (since the queue was empty) */
-#undef traceQUEUE_RECEIVE_FROM_ISR_FAILED
-#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE_FROM_ISR, TRCFAILED, QUEUE, pxQueue), QUEUE, pxQueue);
-
-#undef traceQUEUE_REGISTRY_ADD
-#define traceQUEUE_REGISTRY_ADD(object, name) prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(QUEUE, object), TRACE_GET_OBJECT_NUMBER(QUEUE, object), name);
-
-/* Called in vTaskPrioritySet */
-#undef traceTASK_PRIORITY_SET
-#define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) \
- trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_SET, pxTask, uxNewPriority);
-
-/* Called in vTaskPriorityInherit, which is called by Mutex operations */
-#undef traceTASK_PRIORITY_INHERIT
-#define traceTASK_PRIORITY_INHERIT( pxTask, uxNewPriority ) \
- trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_INHERIT, pxTask, uxNewPriority);
-
-/* Called in vTaskPriorityDisinherit, which is called by Mutex operations */
-#undef traceTASK_PRIORITY_DISINHERIT
-#define traceTASK_PRIORITY_DISINHERIT( pxTask, uxNewPriority ) \
- trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_DISINHERIT, pxTask, uxNewPriority);
-
-/* Called in vTaskResume */
-#undef traceTASK_RESUME
-#define traceTASK_RESUME( pxTaskToResume ) \
- trcKERNEL_HOOKS_TASK_RESUME(TASK_RESUME, pxTaskToResume);
-
-/* Called in vTaskResumeFromISR */
-#undef traceTASK_RESUME_FROM_ISR
-#define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) \
- trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR(TASK_RESUME_FROM_ISR, pxTaskToResume);
-
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-
-#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1)
-
-extern void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t size);
-
-/* MALLOC and FREE are always stored, no matter if they happen inside filtered task */
-#undef traceMALLOC
-#define traceMALLOC( pvAddress, uiSize ) \
- if (pvAddress != 0) \
- vTraceStoreMemMangEvent(MEM_MALLOC_SIZE, ( uint32_t ) pvAddress, (int32_t)uiSize);
-
-#undef traceFREE
-#define traceFREE( pvAddress, uiSize ) \
- vTraceStoreMemMangEvent(MEM_FREE_SIZE, ( uint32_t ) pvAddress, -((int32_t)uiSize));
-
-#endif /* (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1)
-
-/* Called in timer.c - xTimerCreate */
-#undef traceTIMER_CREATE
-#define traceTIMER_CREATE(tmr) \
- trcKERNEL_HOOKS_OBJECT_CREATE(TIMER_CREATE, TIMER, tmr);
-
-#undef traceTIMER_CREATE_FAILED
-#define traceTIMER_CREATE_FAILED() \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TIMER_CREATE_TRCFAILED, 0);
-
-/* Note that xCommandID can never be tmrCOMMAND_EXECUTE_CALLBACK (-1) since the trace macro is not called in that case */
-#undef traceTIMER_COMMAND_SEND
-#define traceTIMER_COMMAND_SEND(tmr, xCommandID, xOptionalValue, xReturn) \
- if (xCommandID > tmrCOMMAND_START_DONT_TRACE) \
- { \
- if (xCommandID == tmrCOMMAND_CHANGE_PERIOD) \
- { \
- if (xReturn == pdPASS) { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TIMER_CHANGE_PERIOD, TIMER, tmr, xOptionalValue); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TIMER_CHANGE_PERIOD_TRCFAILED, TIMER, tmr, xOptionalValue); \
- } \
- } \
- else if ((xCommandID == tmrCOMMAND_DELETE) && (xReturn == pdPASS)) \
- { \
- trcKERNEL_HOOKS_OBJECT_DELETE(TIMER_DELETE_OBJ, EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS + TRACE_GET_OBJECT_TRACE_CLASS(TIMER, tmr), EVENTGROUP_OBJCLOSE_PROP_TRCSUCCESS + TRACE_GET_OBJECT_TRACE_CLASS(TIMER, tmr), TIMER, tmr); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENTGROUP_TIMER + (uint32_t)xCommandID + ((xReturn == pdPASS) ? 0 : (TIMER_CREATE_TRCFAILED - TIMER_CREATE)), TIMER, tmr, xOptionalValue); \
- }\
- }
-
-#undef traceTIMER_EXPIRED
-#define traceTIMER_EXPIRED(tmr) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TIMER_EXPIRED, TIMER, tmr);
-
-#endif /* (TRC_CFG_INCLUDE_TIMER_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS == 1)
-
-#undef tracePEND_FUNC_CALL
-#define tracePEND_FUNC_CALL(func, arg1, arg2, ret) \
- if (ret == pdPASS){ \
- trcKERNEL_HOOKS_KERNEL_SERVICE(PEND_FUNC_CALL, TASK, xTimerGetTimerDaemonTaskHandle() ); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE(PEND_FUNC_CALL_TRCFAILED, TASK, xTimerGetTimerDaemonTaskHandle() ); \
- }
-
-#undef tracePEND_FUNC_CALL_FROM_ISR
-#define tracePEND_FUNC_CALL_FROM_ISR(func, arg1, arg2, ret) \
- if (! uiInEventGroupSetBitsFromISR) \
- prvTraceStoreKernelCall(PEND_FUNC_CALL_FROM_ISR, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(xTimerGetTimerDaemonTaskHandle()) ); \
- uiInEventGroupSetBitsFromISR = 0;
-
-#endif /* (TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS == 1) */
-
-#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1)
-
-#undef traceEVENT_GROUP_CREATE
-#define traceEVENT_GROUP_CREATE(eg) \
- trcKERNEL_HOOKS_OBJECT_CREATE(EVENT_GROUP_CREATE, EVENTGROUP, eg);
-
-#undef traceEVENT_GROUP_CREATE_FAILED
-#define traceEVENT_GROUP_CREATE_FAILED() \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(EVENT_GROUP_CREATE_TRCFAILED, 0);
-
-#undef traceEVENT_GROUP_DELETE
-#define traceEVENT_GROUP_DELETE(eg) \
- { TRACE_ALLOC_CRITICAL_SECTION(); \
- TRACE_ENTER_CRITICAL_SECTION(); \
- trcKERNEL_HOOKS_OBJECT_DELETE(EVENT_GROUP_DELETE_OBJ, EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS + TRACE_GET_OBJECT_TRACE_CLASS(EVENTGROUP, eg), EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS + TRACE_GET_OBJECT_TRACE_CLASS(EVENTGROUP, eg), EVENTGROUP, eg); \
- TRACE_EXIT_CRITICAL_SECTION(); }
-
-#undef traceEVENT_GROUP_SYNC_BLOCK
-#define traceEVENT_GROUP_SYNC_BLOCK(eg, bitsToSet, bitsToWaitFor) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_SYNC_TRCBLOCK, EVENTGROUP, eg, bitsToWaitFor);
-
-#undef traceEVENT_GROUP_SYNC_END
-#define traceEVENT_GROUP_SYNC_END(eg, bitsToSet, bitsToWaitFor, wasTimeout) \
- if (wasTimeout) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_SYNC_END_TRCFAILED, EVENTGROUP, eg, bitsToWaitFor); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_SYNC_END, EVENTGROUP, eg, bitsToWaitFor); \
- }
-
-#undef traceEVENT_GROUP_WAIT_BITS_BLOCK
-#define traceEVENT_GROUP_WAIT_BITS_BLOCK(eg, bitsToWaitFor) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_WAIT_BITS_TRCBLOCK, EVENTGROUP, eg, bitsToWaitFor); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-
-#undef traceEVENT_GROUP_WAIT_BITS_END
-#define traceEVENT_GROUP_WAIT_BITS_END(eg, bitsToWaitFor, wasTimeout) \
- if (wasTimeout) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_WAIT_BITS_END_TRCFAILED, EVENTGROUP, eg, bitsToWaitFor); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_WAIT_BITS_END, EVENTGROUP, eg, bitsToWaitFor); \
- }
-
-#undef traceEVENT_GROUP_CLEAR_BITS
-#define traceEVENT_GROUP_CLEAR_BITS(eg, bitsToClear) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_CLEAR_BITS, EVENTGROUP, eg, bitsToClear);
-
-#undef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR
-#define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(eg, bitsToClear) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR(EVENT_GROUP_CLEAR_BITS_FROM_ISR, EVENTGROUP, eg, bitsToClear);
-
-#undef traceEVENT_GROUP_SET_BITS
-#define traceEVENT_GROUP_SET_BITS(eg, bitsToSet) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(EVENT_GROUP_SET_BITS, EVENTGROUP, eg, bitsToSet);
-
-#undef traceEVENT_GROUP_SET_BITS_FROM_ISR
-#define traceEVENT_GROUP_SET_BITS_FROM_ISR(eg, bitsToSet) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR(EVENT_GROUP_SET_BITS_FROM_ISR, EVENTGROUP, eg, bitsToSet); \
- uiInEventGroupSetBitsFromISR = 1;
-
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1) */
-
-#undef traceTASK_NOTIFY_TAKE
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0)
-#define traceTASK_NOTIFY_TAKE() \
- if (pxCurrentTCB->eNotifyState == eNotified){ \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TRACE_TASK_NOTIFY_TAKE, TASK, pxCurrentTCB, xTicksToWait); \
- } \
- else{ \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TRACE_TASK_NOTIFY_TAKE_TRCFAILED, TASK, pxCurrentTCB, xTicksToWait); \
- }
-#else /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_NOTIFY_TAKE() \
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED){ \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TRACE_TASK_NOTIFY_TAKE, TASK, pxCurrentTCB, xTicksToWait); \
- }else{ \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TRACE_TASK_NOTIFY_TAKE_TRCFAILED, TASK, pxCurrentTCB, xTicksToWait);}
-#endif /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0 */
-
-#undef traceTASK_NOTIFY_TAKE_BLOCK
-#define traceTASK_NOTIFY_TAKE_BLOCK() \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(TRACE_TASK_NOTIFY_TAKE_TRCBLOCK, TASK, pxCurrentTCB, xTicksToWait); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-
-#undef traceTASK_NOTIFY_WAIT
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0)
-#define traceTASK_NOTIFY_WAIT() \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxCurrentTCB) & CurrentFilterMask) \
- { \
- if (pxCurrentTCB->eNotifyState == eNotified) \
- prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxCurrentTCB), xTicksToWait); \
- else \
- prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_TRCFAILED, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxCurrentTCB), xTicksToWait); \
- }
-#else /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_NOTIFY_WAIT() \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxCurrentTCB) & CurrentFilterMask) \
- { \
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \
- prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxCurrentTCB), xTicksToWait); \
- else \
- prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_TRCFAILED, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxCurrentTCB), xTicksToWait); \
- }
-#endif /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0 */
-
-#undef traceTASK_NOTIFY_WAIT_BLOCK
-#define traceTASK_NOTIFY_WAIT_BLOCK() \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxCurrentTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_TRCBLOCK, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxCurrentTCB), xTicksToWait); \
- trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
-
-#undef traceTASK_NOTIFY
-#define traceTASK_NOTIFY() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreKernelCall(TRACE_TASK_NOTIFY, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(xTaskToNotify));
-
-#undef traceTASK_NOTIFY_FROM_ISR
-#define traceTASK_NOTIFY_FROM_ISR() \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreKernelCall(TRACE_TASK_NOTIFY_FROM_ISR, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(xTaskToNotify));
-
-#undef traceTASK_NOTIFY_GIVE_FROM_ISR
-#define traceTASK_NOTIFY_GIVE_FROM_ISR() \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreKernelCall(TRACE_TASK_NOTIFY_GIVE_FROM_ISR, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(xTaskToNotify));
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1)
-
-#undef traceSTREAM_BUFFER_CREATE
-#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ) \
- trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE_OBJ, TRCSUCCESS, STREAMBUFFER, pxStreamBuffer), STREAMBUFFER, pxStreamBuffer);
-
-#undef traceSTREAM_BUFFER_CREATE_FAILED
-#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TRACE_GET_CLASS_EVENT_CODE(CREATE_OBJ, TRCFAILED, STREAMBUFFER, xIsMessageBuffer), 0);
-
-#undef traceSTREAM_BUFFER_CREATE_STATIC_FAILED
-#define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ) \
- traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
-
-#undef traceSTREAM_BUFFER_DELETE
-#define traceSTREAM_BUFFER_DELETE( xStreamBuffer ) \
- trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE_OBJ, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RESET
-#define traceSTREAM_BUFFER_RESET( xStreamBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(prvGetStreamBufferType(xStreamBuffer) > 0 ? TRACE_MESSAGEBUFFER_RESET : TRACE_STREAMBUFFER_RESET, STREAMBUFFER, xStreamBuffer); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(STREAMBUFFER, xStreamBuffer, 0);
-
-#undef traceSTREAM_BUFFER_SEND
-#define traceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(STREAMBUFFER, xStreamBuffer, prvBytesInBuffer(xStreamBuffer));
-
-#undef traceBLOCKING_ON_STREAM_BUFFER_SEND
-#define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCBLOCK, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_SEND_FAILED
-#define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RECEIVE
-#define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(STREAMBUFFER, xStreamBuffer, prvBytesInBuffer(xStreamBuffer));
-
-
-#undef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE
-#define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RECEIVE_FAILED
-#define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ) \
- trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_SEND_FROM_ISR
-#define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn ) \
- if( xReturn > ( size_t ) 0 ) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(SEND_FROM_ISR, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(STREAMBUFFER, xStreamBuffer, prvBytesInBuffer(xStreamBuffer)); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(SEND_FROM_ISR, TRCFAILED, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- }
-
-#undef traceSTREAM_BUFFER_RECEIVE_FROM_ISR
-#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ) \
- if( xReceivedLength > ( size_t ) 0 ) \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE_FROM_ISR, TRCSUCCESS, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- trcKERNEL_HOOKS_SET_OBJECT_STATE(STREAMBUFFER, xStreamBuffer, prvBytesInBuffer(xStreamBuffer)); \
- } \
- else \
- { \
- trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE_FROM_ISR, TRCFAILED, STREAMBUFFER, xStreamBuffer), STREAMBUFFER, xStreamBuffer); \
- }
-
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-#endif /*#if TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT */
-
-/******************************************************************************/
-/*** Definitions for Streaming mode *******************************************/
-/******************************************************************************/
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-/*******************************************************************************
-* vTraceStoreKernelObjectName
-*
-* Set the name for a kernel object (defined by its address).
-******************************************************************************/
-void vTraceStoreKernelObjectName(void* object, const char* name);
-
-/*******************************************************************************
-* prvIsNewTCB
-*
-* Tells if this task is already executing, or if there has been a task-switch.
-* Assumed to be called within a trace hook in kernel context.
-*******************************************************************************/
-uint32_t prvIsNewTCB(void* pNewTCB);
-
-#define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()
-
-/*************************************************************************/
-/* KERNEL SPECIFIC OBJECT CONFIGURATION */
-/*************************************************************************/
-
-/*******************************************************************************
- * The event codes - should match the offline config file.
- ******************************************************************************/
-
-/*** Event codes for streaming - should match the Tracealyzer config file *****/
-#define PSF_EVENT_NULL_EVENT 0x00
-
-#define PSF_EVENT_TRACE_START 0x01
-#define PSF_EVENT_TS_CONFIG 0x02
-#define PSF_EVENT_OBJ_NAME 0x03
-#define PSF_EVENT_TASK_PRIORITY 0x04
-#define PSF_EVENT_TASK_PRIO_INHERIT 0x05
-#define PSF_EVENT_TASK_PRIO_DISINHERIT 0x06
-#define PSF_EVENT_DEFINE_ISR 0x07
-
-#define PSF_EVENT_TASK_CREATE 0x10
-#define PSF_EVENT_QUEUE_CREATE 0x11
-#define PSF_EVENT_SEMAPHORE_BINARY_CREATE 0x12
-#define PSF_EVENT_MUTEX_CREATE 0x13
-#define PSF_EVENT_TIMER_CREATE 0x14
-#define PSF_EVENT_EVENTGROUP_CREATE 0x15
-#define PSF_EVENT_SEMAPHORE_COUNTING_CREATE 0x16
-#define PSF_EVENT_MUTEX_RECURSIVE_CREATE 0x17
-#define PSF_EVENT_STREAMBUFFER_CREATE 0x18
-#define PSF_EVENT_MESSAGEBUFFER_CREATE 0x19
-
-#define PSF_EVENT_TASK_DELETE 0x20
-#define PSF_EVENT_QUEUE_DELETE 0x21
-#define PSF_EVENT_SEMAPHORE_DELETE 0x22
-#define PSF_EVENT_MUTEX_DELETE 0x23
-#define PSF_EVENT_TIMER_DELETE 0x24
-#define PSF_EVENT_EVENTGROUP_DELETE 0x25
-#define PSF_EVENT_STREAMBUFFER_DELETE 0x28
-#define PSF_EVENT_MESSAGEBUFFER_DELETE 0x29
-
-#define PSF_EVENT_TASK_READY 0x30
-#define PSF_EVENT_NEW_TIME 0x31
-#define PSF_EVENT_NEW_TIME_SCHEDULER_SUSPENDED 0x32
-#define PSF_EVENT_ISR_BEGIN 0x33
-#define PSF_EVENT_ISR_RESUME 0x34
-#define PSF_EVENT_TS_BEGIN 0x35
-#define PSF_EVENT_TS_RESUME 0x36
-#define PSF_EVENT_TASK_ACTIVATE 0x37
-
-#define PSF_EVENT_MALLOC 0x38
-#define PSF_EVENT_FREE 0x39
-
-#define PSF_EVENT_LOWPOWER_BEGIN 0x3A
-#define PSF_EVENT_LOWPOWER_END 0x3B
-
-#define PSF_EVENT_IFE_NEXT 0x3C
-#define PSF_EVENT_IFE_DIRECT 0x3D
-
-#define PSF_EVENT_TASK_CREATE_FAILED 0x40
-#define PSF_EVENT_QUEUE_CREATE_FAILED 0x41
-#define PSF_EVENT_SEMAPHORE_BINARY_CREATE_FAILED 0x42
-#define PSF_EVENT_MUTEX_CREATE_FAILED 0x43
-#define PSF_EVENT_TIMER_CREATE_FAILED 0x44
-#define PSF_EVENT_EVENTGROUP_CREATE_FAILED 0x45
-#define PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED 0x46
-#define PSF_EVENT_MUTEX_RECURSIVE_CREATE_FAILED 0x47
-#define PSF_EVENT_STREAMBUFFER_CREATE_FAILED 0x49
-#define PSF_EVENT_MESSAGEBUFFER_CREATE_FAILED 0x4A
-
-#define PSF_EVENT_TIMER_DELETE_FAILED 0x48
-
-#define PSF_EVENT_QUEUE_SEND 0x50
-#define PSF_EVENT_SEMAPHORE_GIVE 0x51
-#define PSF_EVENT_MUTEX_GIVE 0x52
-
-#define PSF_EVENT_QUEUE_SEND_FAILED 0x53
-#define PSF_EVENT_SEMAPHORE_GIVE_FAILED 0x54
-#define PSF_EVENT_MUTEX_GIVE_FAILED 0x55
-
-#define PSF_EVENT_QUEUE_SEND_BLOCK 0x56
-#define PSF_EVENT_SEMAPHORE_GIVE_BLOCK 0x57
-#define PSF_EVENT_MUTEX_GIVE_BLOCK 0x58
-
-#define PSF_EVENT_QUEUE_SEND_FROMISR 0x59
-#define PSF_EVENT_SEMAPHORE_GIVE_FROMISR 0x5A
-
-#define PSF_EVENT_QUEUE_SEND_FROMISR_FAILED 0x5C
-#define PSF_EVENT_SEMAPHORE_GIVE_FROMISR_FAILED 0x5D
-
-#define PSF_EVENT_QUEUE_RECEIVE 0x60
-#define PSF_EVENT_SEMAPHORE_TAKE 0x61
-#define PSF_EVENT_MUTEX_TAKE 0x62
-
-#define PSF_EVENT_QUEUE_RECEIVE_FAILED 0x63
-#define PSF_EVENT_SEMAPHORE_TAKE_FAILED 0x64
-#define PSF_EVENT_MUTEX_TAKE_FAILED 0x65
-
-#define PSF_EVENT_QUEUE_RECEIVE_BLOCK 0x66
-#define PSF_EVENT_SEMAPHORE_TAKE_BLOCK 0x67
-#define PSF_EVENT_MUTEX_TAKE_BLOCK 0x68
-
-#define PSF_EVENT_QUEUE_RECEIVE_FROMISR 0x69
-#define PSF_EVENT_SEMAPHORE_TAKE_FROMISR 0x6A
-
-#define PSF_EVENT_QUEUE_RECEIVE_FROMISR_FAILED 0x6C
-#define PSF_EVENT_SEMAPHORE_TAKE_FROMISR_FAILED 0x6D
-
-#define PSF_EVENT_QUEUE_PEEK 0x70
-#define PSF_EVENT_SEMAPHORE_PEEK 0x71
-#define PSF_EVENT_MUTEX_PEEK 0x72
-
-#define PSF_EVENT_QUEUE_PEEK_FAILED 0x73
-#define PSF_EVENT_SEMAPHORE_PEEK_FAILED 0x74
-#define PSF_EVENT_MUTEX_PEEK_FAILED 0x75
-
-#define PSF_EVENT_QUEUE_PEEK_BLOCK 0x76
-#define PSF_EVENT_SEMAPHORE_PEEK_BLOCK 0x77
-#define PSF_EVENT_MUTEX_PEEK_BLOCK 0x78
-
-#define PSF_EVENT_TASK_DELAY_UNTIL 0x79
-#define PSF_EVENT_TASK_DELAY 0x7A
-#define PSF_EVENT_TASK_SUSPEND 0x7B
-#define PSF_EVENT_TASK_RESUME 0x7C
-#define PSF_EVENT_TASK_RESUME_FROMISR 0x7D
-
-#define PSF_EVENT_TIMER_PENDFUNCCALL 0x80
-#define PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR 0x81
-#define PSF_EVENT_TIMER_PENDFUNCCALL_FAILED 0x82
-#define PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR_FAILED 0x83
-
-#define PSF_EVENT_USER_EVENT 0x90
-
-#define PSF_EVENT_TIMER_START 0xA0
-#define PSF_EVENT_TIMER_RESET 0xA1
-#define PSF_EVENT_TIMER_STOP 0xA2
-#define PSF_EVENT_TIMER_CHANGEPERIOD 0xA3
-#define PSF_EVENT_TIMER_START_FROMISR 0xA4
-#define PSF_EVENT_TIMER_RESET_FROMISR 0xA5
-#define PSF_EVENT_TIMER_STOP_FROMISR 0xA6
-#define PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR 0xA7
-#define PSF_EVENT_TIMER_START_FAILED 0xA8
-#define PSF_EVENT_TIMER_RESET_FAILED 0xA9
-#define PSF_EVENT_TIMER_STOP_FAILED 0xAA
-#define PSF_EVENT_TIMER_CHANGEPERIOD_FAILED 0xAB
-#define PSF_EVENT_TIMER_START_FROMISR_FAILED 0xAC
-#define PSF_EVENT_TIMER_RESET_FROMISR_FAILED 0xAD
-#define PSF_EVENT_TIMER_STOP_FROMISR_FAILED 0xAE
-#define PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR_FAILED 0xAF
-
-#define PSF_EVENT_EVENTGROUP_SYNC 0xB0
-#define PSF_EVENT_EVENTGROUP_WAITBITS 0xB1
-#define PSF_EVENT_EVENTGROUP_CLEARBITS 0xB2
-#define PSF_EVENT_EVENTGROUP_CLEARBITS_FROMISR 0xB3
-#define PSF_EVENT_EVENTGROUP_SETBITS 0xB4
-#define PSF_EVENT_EVENTGROUP_SETBITS_FROMISR 0xB5
-#define PSF_EVENT_EVENTGROUP_SYNC_BLOCK 0xB6
-#define PSF_EVENT_EVENTGROUP_WAITBITS_BLOCK 0xB7
-#define PSF_EVENT_EVENTGROUP_SYNC_FAILED 0xB8
-#define PSF_EVENT_EVENTGROUP_WAITBITS_FAILED 0xB9
-
-#define PSF_EVENT_QUEUE_SEND_FRONT 0xC0
-#define PSF_EVENT_QUEUE_SEND_FRONT_FAILED 0xC1
-#define PSF_EVENT_QUEUE_SEND_FRONT_BLOCK 0xC2
-#define PSF_EVENT_QUEUE_SEND_FRONT_FROMISR 0xC3
-#define PSF_EVENT_QUEUE_SEND_FRONT_FROMISR_FAILED 0xC4
-#define PSF_EVENT_MUTEX_GIVE_RECURSIVE 0xC5
-#define PSF_EVENT_MUTEX_GIVE_RECURSIVE_FAILED 0xC6
-#define PSF_EVENT_MUTEX_TAKE_RECURSIVE 0xC7
-#define PSF_EVENT_MUTEX_TAKE_RECURSIVE_FAILED 0xC8
-
-#define PSF_EVENT_TASK_NOTIFY 0xC9
-#define PSF_EVENT_TASK_NOTIFY_TAKE 0xCA
-#define PSF_EVENT_TASK_NOTIFY_TAKE_BLOCK 0xCB
-#define PSF_EVENT_TASK_NOTIFY_TAKE_FAILED 0xCC
-#define PSF_EVENT_TASK_NOTIFY_WAIT 0xCD
-#define PSF_EVENT_TASK_NOTIFY_WAIT_BLOCK 0xCE
-#define PSF_EVENT_TASK_NOTIFY_WAIT_FAILED 0xCF
-#define PSF_EVENT_TASK_NOTIFY_FROM_ISR 0xD0
-#define PSF_EVENT_TASK_NOTIFY_GIVE_FROM_ISR 0xD1
-
-#define PSF_EVENT_TIMER_EXPIRED 0xD2
-
-#define PSF_EVENT_STREAMBUFFER_SEND 0xD3
-#define PSF_EVENT_STREAMBUFFER_SEND_BLOCK 0xD4
-#define PSF_EVENT_STREAMBUFFER_SEND_FAILED 0xD5
-#define PSF_EVENT_STREAMBUFFER_RECEIVE 0xD6
-#define PSF_EVENT_STREAMBUFFER_RECEIVE_BLOCK 0xD7
-#define PSF_EVENT_STREAMBUFFER_RECEIVE_FAILED 0xD8
-#define PSF_EVENT_STREAMBUFFER_SEND_FROM_ISR 0xD9
-#define PSF_EVENT_STREAMBUFFER_SEND_FROM_ISR_FAILED 0xDA
-#define PSF_EVENT_STREAMBUFFER_RECEIVE_FROM_ISR 0xDB
-#define PSF_EVENT_STREAMBUFFER_RECEIVE_FROM_ISR_FAILED 0xDC
-#define PSF_EVENT_STREAMBUFFER_RESET 0xDD
-
-#define PSF_EVENT_MESSAGEBUFFER_SEND 0xDE
-#define PSF_EVENT_MESSAGEBUFFER_SEND_BLOCK 0xDF
-#define PSF_EVENT_MESSAGEBUFFER_SEND_FAILED 0xE0
-#define PSF_EVENT_MESSAGEBUFFER_RECEIVE 0xE1
-#define PSF_EVENT_MESSAGEBUFFER_RECEIVE_BLOCK 0xE2
-#define PSF_EVENT_MESSAGEBUFFER_RECEIVE_FAILED 0xE3
-#define PSF_EVENT_MESSAGEBUFFER_SEND_FROM_ISR 0xE4
-#define PSF_EVENT_MESSAGEBUFFER_SEND_FROM_ISR_FAILED 0xE5
-#define PSF_EVENT_MESSAGEBUFFER_RECEIVE_FROM_ISR 0xE6
-#define PSF_EVENT_MESSAGEBUFFER_RECEIVE_FROM_ISR_FAILED 0xE7
-#define PSF_EVENT_MESSAGEBUFFER_RESET 0xE8
-
-/*** The trace macros for streaming ******************************************/
-
-/* A macro that will update the tick count when returning from tickless idle */
-#undef traceINCREASE_TICK_COUNT
-/* Note: This can handle time adjustments of max 2^32 ticks, i.e., 35 seconds at 120 MHz. Thus, tick-less idle periods longer than 2^32 ticks will appear "compressed" on the time line.*/
-#define traceINCREASE_TICK_COUNT( xCount ) { extern uint32_t uiTraceTickCount; uiTraceTickCount += xCount; }
-
-#if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)
-#define OS_TICK_EVENT(uxSchedulerSuspended, xTickCount) if (uxSchedulerSuspended == (unsigned portBASE_TYPE) pdFALSE) { prvTraceStoreEvent1(PSF_EVENT_NEW_TIME, (uint32_t)(xTickCount + 1)); }
-#else
-#define OS_TICK_EVENT(uxSchedulerSuspended, xTickCount)
-#endif
-
-/* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */
-#undef traceTASK_INCREMENT_TICK
-#if TRC_CFG_FREERTOS_VERSION <= TRC_FREERTOS_VERSION_7_4
-#define traceTASK_INCREMENT_TICK( xTickCount ) \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxMissedTicks == 0) { extern uint32_t uiTraceTickCount; uiTraceTickCount++; } \
- OS_TICK_EVENT(uxSchedulerSuspended, xTickCount)
-#else
-#define traceTASK_INCREMENT_TICK( xTickCount ) \
- if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxPendedTicks == 0) { extern uint32_t uiTraceTickCount; uiTraceTickCount++; } \
- OS_TICK_EVENT(uxSchedulerSuspended, xTickCount)
-#endif /* TRC_CFG_FREERTOS_VERSION <= TRC_FREERTOS_VERSION_7_4 */
-
-/* Called on each task-switch */
-#undef traceTASK_SWITCHED_IN
-#define traceTASK_SWITCHED_IN() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- { \
- if (prvIsNewTCB(pxCurrentTCB)) \
- { \
- prvTraceStoreEvent2(PSF_EVENT_TASK_ACTIVATE, (uint32_t)pxCurrentTCB, pxCurrentTCB->uxPriority); \
- } \
- }
-
-/* Called for each task that becomes ready */
-#if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
-#undef traceMOVED_TASK_TO_READY_STATE
-#define traceMOVED_TASK_TO_READY_STATE( pxTCB ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_READY, (uint32_t)pxTCB);
-#endif
-
-#undef traceTASK_CREATE
-#if TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0
-#define traceTASK_CREATE(pxNewTCB) \
- if (pxNewTCB != NULL) \
- { \
- prvTraceSaveSymbol(pxNewTCB, pxNewTCB->pcTaskName); \
- prvTraceSaveObjectData(pxNewTCB, pxNewTCB->uxPriority); \
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, pxNewTCB->pcTaskName, pxNewTCB); \
- TRACE_SET_OBJECT_FILTER(TASK, pxNewTCB, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxNewTCB) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)pxNewTCB, pxNewTCB->uxPriority); \
- }
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_CREATE(pxNewTCB) \
- if (pxNewTCB != NULL) \
- { \
- prvTraceSaveSymbol(pxNewTCB, (const char*)pcName); \
- prvTraceSaveObjectData(pxNewTCB, uxPriority); \
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, (const char*)pcName, pxNewTCB); \
- TRACE_SET_OBJECT_FILTER(TASK, pxNewTCB, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxNewTCB) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)pxNewTCB, uxPriority); \
- }
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-
-/* Called in vTaskCreate, if it fails (typically if the stack can not be allocated) */
-#undef traceTASK_CREATE_FAILED
-#define traceTASK_CREATE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent0(PSF_EVENT_TASK_CREATE_FAILED);
-
-/* Called on vTaskDelete */
-#undef traceTASK_DELETE // We don't allow for filtering out "delete" events. They are important and not very frequent. Moreover, we can't exclude create events, so this should be symmetrical.
-#define traceTASK_DELETE( pxTaskToDelete ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTaskToDelete) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_DELETE, (uint32_t)pxTaskToDelete, (pxTaskToDelete != NULL) ? (pxTaskToDelete->uxPriority) : 0); \
- prvTraceDeleteSymbol(pxTaskToDelete); \
- prvTraceDeleteObjectData(pxTaskToDelete);
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-
-#if (defined(configUSE_TICKLESS_IDLE) && configUSE_TICKLESS_IDLE != 0)
-
-#undef traceLOW_POWER_IDLE_BEGIN
-#define traceLOW_POWER_IDLE_BEGIN() \
- { \
- prvTraceStoreEvent1(PSF_EVENT_LOWPOWER_BEGIN, xExpectedIdleTime); \
- }
-
-#undef traceLOW_POWER_IDLE_END
-#define traceLOW_POWER_IDLE_END() \
- { \
- prvTraceStoreEvent0(PSF_EVENT_LOWPOWER_END); \
- }
-
-#endif /* (defined(configUSE_TICKLESS_IDLE) && configUSE_TICKLESS_IDLE != 0) */
-
-/* Called on vTaskSuspend */
-#undef traceTASK_SUSPEND
-#define traceTASK_SUSPEND( pxTaskToSuspend ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTaskToSuspend) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_SUSPEND, (uint32_t)pxTaskToSuspend);
-
-/* Called on vTaskDelay - note the use of FreeRTOS variable xTicksToDelay */
-#undef traceTASK_DELAY
-#define traceTASK_DELAY() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY, xTicksToDelay);
-
-/* Called on vTaskDelayUntil - note the use of FreeRTOS variable xTimeToWake */
-#undef traceTASK_DELAY_UNTIL
-#if TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0
-#define traceTASK_DELAY_UNTIL(xTimeToWake) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY_UNTIL, (uint32_t)xTimeToWake);
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_DELAY_UNTIL() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY_UNTIL, (uint32_t)xTimeToWake);
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0)
-#define traceQUEUE_CREATE_HELPER() \
- case queueQUEUE_TYPE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE, (uint32_t)pxNewQueue); \
- break; \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECURSIVE_CREATE, (uint32_t)pxNewQueue); \
- break;
-#else
-#define traceQUEUE_CREATE_HELPER()
-#endif /* (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0) */
-
-/* Called in xQueueCreate, and thereby for all other object based on queues, such as semaphores. */
-#undef traceQUEUE_CREATE
-#define traceQUEUE_CREATE( pxNewQueue )\
- TRACE_SET_OBJECT_FILTER(QUEUE, pxNewQueue, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- { \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxNewQueue) & CurrentFilterMask) \
- { \
- switch (pxNewQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(PSF_EVENT_QUEUE_CREATE, (uint32_t)pxNewQueue, uxQueueLength); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- prvTraceStoreEvent1(PSF_EVENT_SEMAPHORE_BINARY_CREATE, (uint32_t)pxNewQueue); \
- break; \
- traceQUEUE_CREATE_HELPER() \
- } \
- } \
- }
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0)
-#define traceQUEUE_CREATE_FAILED_HELPER() \
- case queueQUEUE_TYPE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE_FAILED, 0); \
- break; \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECURSIVE_CREATE_FAILED, 0); \
- break;
-#else
-#define traceQUEUE_CREATE_FAILED_HELPER()
-#endif /* (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0) */
-
-/* Called in xQueueCreate, if the queue creation fails */
-#undef traceQUEUE_CREATE_FAILED
-#define traceQUEUE_CREATE_FAILED( queueType ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- { \
- switch (queueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(PSF_EVENT_QUEUE_CREATE_FAILED, 0, uxQueueLength); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- prvTraceStoreEvent1(PSF_EVENT_SEMAPHORE_BINARY_CREATE_FAILED, 0); \
- break; \
- traceQUEUE_CREATE_FAILED_HELPER() \
- } \
- }
-
-#undef traceQUEUE_DELETE // We don't allow for filtering out "delete" events. They are important and not very frequent. Moreover, we can't exclude create events, so this should be symmetrical.
-#define traceQUEUE_DELETE( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- { \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- { \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(PSF_EVENT_QUEUE_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent2(PSF_EVENT_MUTEX_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \
- break; \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \
- break; \
- } \
- } \
- } \
- prvTraceDeleteSymbol(pxQueue);
-
-/* Called in xQueueCreateCountingSemaphore, if the queue creation fails */
-#undef traceCREATE_COUNTING_SEMAPHORE
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-#define traceCREATE_COUNTING_SEMAPHORE() \
- TRACE_SET_OBJECT_FILTER(QUEUE, xHandle, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, xHandle) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)xHandle, uxMaxCount)
-#elif (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_5_OR_7_6)
-#define traceCREATE_COUNTING_SEMAPHORE() \
- TRACE_SET_OBJECT_FILTER(QUEUE, xHandle, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, xHandle) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)xHandle, uxInitialCount);
-#elif (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_4)
-#define traceCREATE_COUNTING_SEMAPHORE() \
- TRACE_SET_OBJECT_FILTER(QUEUE, xHandle, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, xHandle) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)xHandle, uxCountValue);
-#else
-#define traceCREATE_COUNTING_SEMAPHORE() \
- TRACE_SET_OBJECT_FILTER(QUEUE, pxHandle, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxHandle) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)pxHandle, uxCountValue);
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X */
-
-#undef traceCREATE_COUNTING_SEMAPHORE_FAILED
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-#define traceCREATE_COUNTING_SEMAPHORE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED, 0, uxMaxCount);
-#elif (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_5_OR_7_6)
-#define traceCREATE_COUNTING_SEMAPHORE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED, 0, uxInitialCount);
-#elif (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_7_4)
-#define traceCREATE_COUNTING_SEMAPHORE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED, 0, uxCountValue);
-#else
-#define traceCREATE_COUNTING_SEMAPHORE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED, 0, uxCountValue);
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X */
-
-
-/* This macro is not necessary as of FreeRTOS v9.0.0 */
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0)
-/* Called in xQueueCreateMutex, and thereby also from xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex */
-#undef traceCREATE_MUTEX
-#define traceCREATE_MUTEX( pxNewQueue ) \
- TRACE_SET_OBJECT_FILTER(QUEUE, pxNewQueue, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- { \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxNewQueue) & CurrentFilterMask) \
- { \
- switch (pxNewQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE, (uint32_t)pxNewQueue); \
- break; \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECURSIVE_CREATE, (uint32_t)pxNewQueue); \
- break; \
- } \
- }\
- }
-
-/* Called in xQueueCreateMutex when the operation fails (when memory allocation fails) */
-#undef traceCREATE_MUTEX_FAILED
-#define traceCREATE_MUTEX_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE_FAILED, 0);
-#endif /* (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_0_0) */
-
-/* Called when a message is sent to a queue */ /* CS IS NEW ! */
-#undef traceQUEUE_SEND
-#define traceQUEUE_SEND( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND : PSF_EVENT_QUEUE_SEND_FRONT, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE, (uint32_t)pxQueue); \
- break; \
- }
-
-/* Called when a message failed to be sent to a queue (timeout) */
-#undef traceQUEUE_SEND_FAILED
-#define traceQUEUE_SEND_FAILED( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FAILED : PSF_EVENT_QUEUE_SEND_FRONT_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_FAILED, (uint32_t)pxQueue); \
- break; \
- }
-
-/* Called when the task is blocked due to a send operation on a full queue */
-#undef traceBLOCKING_ON_QUEUE_SEND
-#define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_BLOCK : PSF_EVENT_QUEUE_SEND_FRONT_BLOCK, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_BLOCK, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_BLOCK, (uint32_t)pxQueue); \
- break; \
- }
-
-/**************************************************************************/
-/* Makes sure xQueueGiveFromISR also has a xCopyPosition parameter */
-/**************************************************************************/
-/* Helpers needed to correctly expand names */
-#define TZ__CAT2(a,b) a ## b
-#define TZ__CAT(a,b) TZ__CAT2(a, b)
-
-/* Expands name if this header is included... uxQueueType must be a macro that only exists in queue.c or whatever, and it must expand to nothing or to something that's valid in identifiers */
-#define xQueueGiveFromISR(a,b) TZ__CAT(xQueueGiveFromISR__, uxQueueType) (a,b)
-
-/* If in queue.c, the "uxQueueType" macro expands to "pcHead". queueSEND_TO_BACK is the value we need to send in */
-#define xQueueGiveFromISR__pcHead(__a, __b) MyWrapper(__a, __b, const BaseType_t xCopyPosition); \
-BaseType_t xQueueGiveFromISR(__a, __b) { return MyWrapper(xQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK); } \
-BaseType_t MyWrapper(__a, __b, const BaseType_t xCopyPosition)
-
-/* If not in queue.c, "uxQueueType" isn't expanded */
-#define xQueueGiveFromISR__uxQueueType(__a, __b) xQueueGiveFromISR(__a,__b)
-
-/**************************************************************************/
-/* End of xQueueGiveFromISR fix */
-/**************************************************************************/
-
-/* Called when a message is sent from interrupt context, e.g., using xQueueSendFromISR */
-#undef traceQUEUE_SEND_FROM_ISR
-#define traceQUEUE_SEND_FROM_ISR( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FROMISR : PSF_EVENT_QUEUE_SEND_FRONT_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \
- break; \
- }
-
-/* Called when a message send from interrupt context fails (since the queue was full) */
-#undef traceQUEUE_SEND_FROM_ISR_FAILED
-#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FROMISR_FAILED : PSF_EVENT_QUEUE_SEND_FRONT_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- }
-
-/* Called when a message is received from a queue */
-#undef traceQUEUE_RECEIVE
-#define traceQUEUE_RECEIVE( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- if (isQueueReceiveHookActuallyPeek) \
- prvTraceStoreEvent3(PSF_EVENT_QUEUE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \
- else\
- prvTraceStoreEvent3(PSF_EVENT_QUEUE_RECEIVE, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- if (isQueueReceiveHookActuallyPeek) \
- prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \
- else \
- prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_TAKE, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- if (isQueueReceiveHookActuallyPeek) \
- prvTraceStoreEvent2(PSF_EVENT_MUTEX_PEEK, (uint32_t)pxQueue, xTicksToWait); \
- else \
- prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE, (uint32_t)pxQueue, xTicksToWait); \
- break; \
- }
-
-/* Called when a receive operation on a queue fails (timeout) */
-#undef traceQUEUE_RECEIVE_FAILED
-#define traceQUEUE_RECEIVE_FAILED( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent3(isQueueReceiveHookActuallyPeek ? PSF_EVENT_QUEUE_PEEK_FAILED : PSF_EVENT_QUEUE_RECEIVE_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent3(isQueueReceiveHookActuallyPeek ? PSF_EVENT_SEMAPHORE_PEEK_FAILED : PSF_EVENT_SEMAPHORE_TAKE_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent2(isQueueReceiveHookActuallyPeek ? PSF_EVENT_MUTEX_PEEK_FAILED : PSF_EVENT_MUTEX_TAKE_FAILED, (uint32_t)pxQueue, xTicksToWait); \
- break; \
- }
-
-/* Called when the task is blocked due to a receive operation on an empty queue */
-#undef traceBLOCKING_ON_QUEUE_RECEIVE
-#define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent3(isQueueReceiveHookActuallyPeek ? PSF_EVENT_QUEUE_PEEK_BLOCK : PSF_EVENT_QUEUE_RECEIVE_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent3(isQueueReceiveHookActuallyPeek ? PSF_EVENT_SEMAPHORE_PEEK_BLOCK : PSF_EVENT_SEMAPHORE_TAKE_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent2(isQueueReceiveHookActuallyPeek ? PSF_EVENT_MUTEX_PEEK_BLOCK : PSF_EVENT_MUTEX_TAKE_BLOCK, (uint32_t)pxQueue, xTicksToWait); \
- break; \
- }
-
-#if (TRC_CFG_FREERTOS_VERSION > TRC_FREERTOS_VERSION_9_0_1)
-/* Called when a peek operation on a queue fails (timeout) */
-#undef traceQUEUE_PEEK_FAILED
-#define traceQUEUE_PEEK_FAILED( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent3(PSF_EVENT_QUEUE_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent2(PSF_EVENT_MUTEX_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait); \
- break; \
- }
-
-/* Called when the task is blocked due to a peek operation on an empty queue */
-#undef traceBLOCKING_ON_QUEUE_PEEK
-#define traceBLOCKING_ON_QUEUE_PEEK( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent3(PSF_EVENT_QUEUE_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent2(PSF_EVENT_MUTEX_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait); \
- break; \
- }
-
-#endif /* (TRC_CFG_FREERTOS_VERSION > TRC_FREERTOS_VERSION_9_0_1) */
-
-/* Called when a message is received in interrupt context, e.g., using xQueueReceiveFromISR */
-#undef traceQUEUE_RECEIVE_FROM_ISR
-#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(PSF_EVENT_QUEUE_RECEIVE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting - 1); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_TAKE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting - 1); \
- break; \
- }
-
-/* Called when a message receive from interrupt context fails (since the queue was empty) */
-#undef traceQUEUE_RECEIVE_FROM_ISR_FAILED
-#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent2(PSF_EVENT_QUEUE_RECEIVE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_TAKE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \
- break; \
- }
-
-/* Called on xQueuePeek */
-#undef traceQUEUE_PEEK
-#define traceQUEUE_PEEK( pxQueue ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(QUEUE, pxQueue) & CurrentFilterMask) \
- switch (pxQueue->ucQueueType) \
- { \
- case queueQUEUE_TYPE_BASE: \
- prvTraceStoreEvent3(PSF_EVENT_QUEUE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_BINARY_SEMAPHORE: \
- case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \
- prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \
- break; \
- case queueQUEUE_TYPE_MUTEX: \
- case queueQUEUE_TYPE_RECURSIVE_MUTEX: \
- prvTraceStoreEvent1(PSF_EVENT_MUTEX_PEEK, (uint32_t)pxQueue); \
- break; \
- }
-
-/* Called in vTaskPrioritySet */
-#undef traceTASK_PRIORITY_SET
-#define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) \
- prvTraceSaveObjectData(pxTask, uxNewPriority); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTask) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_PRIORITY, (uint32_t)pxTask, uxNewPriority);
-
-/* Called in vTaskPriorityInherit, which is called by Mutex operations */
-#undef traceTASK_PRIORITY_INHERIT
-#define traceTASK_PRIORITY_INHERIT( pxTask, uxNewPriority ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTask) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_INHERIT, (uint32_t)pxTask, uxNewPriority);
-
-/* Called in vTaskPriorityDisinherit, which is called by Mutex operations */
-#undef traceTASK_PRIORITY_DISINHERIT
-#define traceTASK_PRIORITY_DISINHERIT( pxTask, uxNewPriority ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTask) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_DISINHERIT, (uint32_t)pxTask, uxNewPriority);
-
-/* Called in vTaskResume */
-#undef traceTASK_RESUME
-#define traceTASK_RESUME( pxTaskToResume ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTaskToResume) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_RESUME, (uint32_t)pxTaskToResume);
-
-/* Called in vTaskResumeFromISR */
-#undef traceTASK_RESUME_FROM_ISR
-#define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTaskToResume) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_RESUME_FROMISR, (uint32_t)pxTaskToResume);
-
-#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1)
-
-#undef traceMALLOC
-#define traceMALLOC( pvAddress, uiSize ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_MALLOC, (uint32_t)pvAddress, uiSize);
-
-#undef traceFREE
-#define traceFREE( pvAddress, uiSize ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_FREE, (uint32_t)pvAddress, (uint32_t)(0 - uiSize)); /* "0 -" instead of just "-" to get rid of a warning... */
-
-#endif /* (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1)
-
-/* Called in timer.c - xTimerCreate */
-#undef traceTIMER_CREATE
-#define traceTIMER_CREATE(tmr) \
- TRACE_SET_OBJECT_FILTER(TIMER, tmr, CurrentFilterGroup); \
- prvTraceSaveSymbol(tmr, tmr->pcTimerName); \
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, tmr->pcTimerName, tmr); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TIMER, tmr) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TIMER_CREATE, (uint32_t)tmr, tmr->xTimerPeriodInTicks);
-
-#undef traceTIMER_CREATE_FAILED
-#define traceTIMER_CREATE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent0(PSF_EVENT_TIMER_CREATE_FAILED);
-
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-#define traceTIMER_COMMAND_SEND_8_0_CASES(tmr) \
- case tmrCOMMAND_RESET: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_RESET : PSF_EVENT_TIMER_RESET_FAILED, (uint32_t)tmr, xOptionalValue); \
- break; \
- case tmrCOMMAND_START_FROM_ISR: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_START_FROMISR : PSF_EVENT_TIMER_START_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \
- break; \
- case tmrCOMMAND_RESET_FROM_ISR: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_RESET_FROMISR : PSF_EVENT_TIMER_RESET_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \
- break; \
- case tmrCOMMAND_STOP_FROM_ISR: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_STOP_FROMISR : PSF_EVENT_TIMER_STOP_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \
- break; \
- case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR : PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \
- break;
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X */
-#define traceTIMER_COMMAND_SEND_8_0_CASES(tmr)
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X */
-
-/* Note that xCommandID can never be tmrCOMMAND_EXECUTE_CALLBACK (-1) since the trace macro is not called in that case */
-#undef traceTIMER_COMMAND_SEND
-#define traceTIMER_COMMAND_SEND(tmr, xCommandID, xOptionalValue, xReturn) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TIMER, tmr) & CurrentFilterMask) \
- switch(xCommandID) \
- { \
- case tmrCOMMAND_START: \
- prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_START : PSF_EVENT_TIMER_START_FAILED, (uint32_t)tmr); \
- break; \
- case tmrCOMMAND_STOP: \
- prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_STOP : PSF_EVENT_TIMER_STOP_FAILED, (uint32_t)tmr); \
- break; \
- case tmrCOMMAND_CHANGE_PERIOD: \
- prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_CHANGEPERIOD : PSF_EVENT_TIMER_CHANGEPERIOD_FAILED, (uint32_t)tmr, xOptionalValue); \
- break; \
- case tmrCOMMAND_DELETE: \
- prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_DELETE : PSF_EVENT_TIMER_DELETE_FAILED, (uint32_t)tmr); \
- break; \
- traceTIMER_COMMAND_SEND_8_0_CASES(tmr) \
- }
-
-#undef traceTIMER_EXPIRED
-#define traceTIMER_EXPIRED(tmr) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TIMER, tmr) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TIMER_EXPIRED, (uint32_t)tmr->pxCallbackFunction, (uint32_t)tmr->pvTimerID);
-
-#endif /* #if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1) */
-
-
-#if (TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS == 1)
-
-#undef tracePEND_FUNC_CALL
-#define tracePEND_FUNC_CALL(func, arg1, arg2, ret) \
- prvTraceStoreEvent1((ret == pdPASS) ? PSF_EVENT_TIMER_PENDFUNCCALL : PSF_EVENT_TIMER_PENDFUNCCALL_FAILED, (uint32_t)func);
-
-#undef tracePEND_FUNC_CALL_FROM_ISR
-#define tracePEND_FUNC_CALL_FROM_ISR(func, arg1, arg2, ret) \
- prvTraceStoreEvent1((ret == pdPASS) ? PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR : PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR_FAILED, (uint32_t)func);
-
-#endif /* (TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS == 1) */
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1)
-
-#undef traceEVENT_GROUP_CREATE
-#define traceEVENT_GROUP_CREATE(eg) \
- TRACE_SET_OBJECT_FILTER(EVENTGROUP, eg, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_EVENTGROUP_CREATE, (uint32_t)eg);
-
-#undef traceEVENT_GROUP_DELETE
-#define traceEVENT_GROUP_DELETE(eg) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_EVENTGROUP_DELETE, (uint32_t)eg); \
- prvTraceDeleteSymbol(eg);
-
-#undef traceEVENT_GROUP_CREATE_FAILED
-#define traceEVENT_GROUP_CREATE_FAILED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent0(PSF_EVENT_EVENTGROUP_CREATE_FAILED);
-
-#undef traceEVENT_GROUP_SYNC_BLOCK
-#define traceEVENT_GROUP_SYNC_BLOCK(eg, bitsToSet, bitsToWaitFor) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SYNC_BLOCK, (uint32_t)eg, bitsToWaitFor);
-
-#undef traceEVENT_GROUP_SYNC_END
-#define traceEVENT_GROUP_SYNC_END(eg, bitsToSet, bitsToWaitFor, wasTimeout) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2((wasTimeout != pdTRUE) ? PSF_EVENT_EVENTGROUP_SYNC : PSF_EVENT_EVENTGROUP_SYNC_FAILED, (uint32_t)eg, bitsToWaitFor);
-
-#undef traceEVENT_GROUP_WAIT_BITS_BLOCK
-#define traceEVENT_GROUP_WAIT_BITS_BLOCK(eg, bitsToWaitFor) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_WAITBITS_BLOCK, (uint32_t)eg, bitsToWaitFor);
-
-#undef traceEVENT_GROUP_WAIT_BITS_END
-#define traceEVENT_GROUP_WAIT_BITS_END(eg, bitsToWaitFor, wasTimeout) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2((wasTimeout != pdTRUE) ? PSF_EVENT_EVENTGROUP_WAITBITS : PSF_EVENT_EVENTGROUP_WAITBITS_FAILED, (uint32_t)eg, bitsToWaitFor);
-
-#undef traceEVENT_GROUP_CLEAR_BITS
-#define traceEVENT_GROUP_CLEAR_BITS(eg, bitsToClear) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_CLEARBITS, (uint32_t)eg, bitsToClear);
-
-#undef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR
-#define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(eg, bitsToClear) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_CLEARBITS_FROMISR, (uint32_t)eg, bitsToClear);
-
-#undef traceEVENT_GROUP_SET_BITS
-#define traceEVENT_GROUP_SET_BITS(eg, bitsToSet) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SETBITS, (uint32_t)eg, bitsToSet);
-
-#undef traceEVENT_GROUP_SET_BITS_FROM_ISR
-#define traceEVENT_GROUP_SET_BITS_FROM_ISR(eg, bitsToSet) \
- if (TRACE_GET_OBJECT_FILTER(EVENTGROUP, eg) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SETBITS_FROMISR, (uint32_t)eg, bitsToSet);
-
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1) */
-
-#undef traceTASK_NOTIFY_TAKE
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0)
-#define traceTASK_NOTIFY_TAKE() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask){ \
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE, (uint32_t)pxCurrentTCB, xTicksToWait); \
- else \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);}
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_NOTIFY_TAKE() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask){ \
- if (pxCurrentTCB->eNotifyState == eNotified) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE, (uint32_t)pxCurrentTCB, xTicksToWait); \
- else \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);}
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-
-#undef traceTASK_NOTIFY_TAKE_BLOCK
-#define traceTASK_NOTIFY_TAKE_BLOCK() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_BLOCK, (uint32_t)pxCurrentTCB, xTicksToWait);
-
-#undef traceTASK_NOTIFY_WAIT
-#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0)
-#define traceTASK_NOTIFY_WAIT() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask){ \
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT, (uint32_t)pxCurrentTCB, xTicksToWait); \
- else \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);}
-#else /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-#define traceTASK_NOTIFY_WAIT() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask){ \
- if (pxCurrentTCB->eNotifyState == eNotified) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT, (uint32_t)pxCurrentTCB, xTicksToWait); \
- else \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);}
-#endif /* TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_9_0_0 */
-
-#undef traceTASK_NOTIFY_WAIT_BLOCK
-#define traceTASK_NOTIFY_WAIT_BLOCK() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_BLOCK, (uint32_t)pxCurrentTCB, xTicksToWait);
-
-#undef traceTASK_NOTIFY
-#define traceTASK_NOTIFY() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY, (uint32_t)xTaskToNotify);
-
-#undef traceTASK_NOTIFY_FROM_ISR
-#define traceTASK_NOTIFY_FROM_ISR() \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY_FROM_ISR, (uint32_t)xTaskToNotify);
-
-#undef traceTASK_NOTIFY_GIVE_FROM_ISR
-#define traceTASK_NOTIFY_GIVE_FROM_ISR() \
- if (TRACE_GET_OBJECT_FILTER(TASK, xTaskToNotify) & CurrentFilterMask) \
- prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY_GIVE_FROM_ISR, (uint32_t)xTaskToNotify);
-
-#undef traceQUEUE_REGISTRY_ADD
-#define traceQUEUE_REGISTRY_ADD(object, name) \
- prvTraceSaveSymbol(object, (const char*)name); \
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, name, object);
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1)
-
-#undef traceSTREAM_BUFFER_CREATE
-#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ) \
- TRACE_SET_OBJECT_FILTER(STREAMBUFFER, pxStreamBuffer, CurrentFilterGroup); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, pxStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent2(xIsMessageBuffer == 1 ? PSF_EVENT_MESSAGEBUFFER_CREATE : PSF_EVENT_STREAMBUFFER_CREATE, (uint32_t)pxStreamBuffer, xBufferSizeBytes);
-
-#undef traceSTREAM_BUFFER_CREATE_FAILED
-#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreEvent2(xIsMessageBuffer == 1 ? PSF_EVENT_MESSAGEBUFFER_CREATE_FAILED : PSF_EVENT_STREAMBUFFER_CREATE_FAILED, 0 , xBufferSizeBytes);
-
-#undef traceSTREAM_BUFFER_CREATE_STATIC_FAILED
-#define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ) \
- traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
-
-#undef traceSTREAM_BUFFER_DELETE
-#define traceSTREAM_BUFFER_DELETE( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, pxStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_DELETE : PSF_EVENT_STREAMBUFFER_DELETE, (uint32_t)xStreamBuffer, prvBytesInBuffer(xStreamBuffer)); \
- prvTraceDeleteSymbol(xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RESET
-#define traceSTREAM_BUFFER_RESET( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RESET : PSF_EVENT_STREAMBUFFER_RESET, (uint32_t)xStreamBuffer, 0);
-
-#undef traceSTREAM_BUFFER_SEND
-#define traceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_SEND : PSF_EVENT_STREAMBUFFER_SEND, (uint32_t)xStreamBuffer, prvBytesInBuffer(xStreamBuffer));
-
-#undef traceBLOCKING_ON_STREAM_BUFFER_SEND
-#define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_SEND_BLOCK : PSF_EVENT_STREAMBUFFER_SEND_BLOCK, (uint32_t)xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_SEND_FAILED
-#define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_SEND_FAILED : PSF_EVENT_STREAMBUFFER_SEND_FAILED, (uint32_t)xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RECEIVE
-#define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RECEIVE: PSF_EVENT_STREAMBUFFER_RECEIVE, (uint32_t)xStreamBuffer, prvBytesInBuffer(xStreamBuffer));
-
-#undef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE
-#define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RECEIVE_BLOCK: PSF_EVENT_STREAMBUFFER_RECEIVE_BLOCK, (uint32_t)xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_RECEIVE_FAILED
-#define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RECEIVE_FAILED: PSF_EVENT_STREAMBUFFER_RECEIVE_FAILED, (uint32_t)xStreamBuffer);
-
-#undef traceSTREAM_BUFFER_SEND_FROM_ISR
-#define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn ) \
- if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- { \
- if ( xReturn > ( size_t ) 0 ) \
- { \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_SEND_FROM_ISR : PSF_EVENT_STREAMBUFFER_SEND_FROM_ISR, (uint32_t)xStreamBuffer, prvBytesInBuffer(xStreamBuffer)); \
- } \
- else \
- { \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_SEND_FROM_ISR_FAILED : PSF_EVENT_STREAMBUFFER_SEND_FROM_ISR_FAILED, (uint32_t)xStreamBuffer); \
- } \
- }
-
-#undef traceSTREAM_BUFFER_RECEIVE_FROM_ISR
-#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ) \
-if (TRACE_GET_OBJECT_FILTER(STREAMBUFFER, xStreamBuffer) & CurrentFilterMask) \
- { \
- if ( xReceivedLength > ( size_t ) 0 ) \
- { \
- prvTraceStoreEvent2(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RECEIVE_FROM_ISR : PSF_EVENT_STREAMBUFFER_RECEIVE_FROM_ISR, (uint32_t)xStreamBuffer, prvBytesInBuffer(xStreamBuffer)); \
- } \
- else \
- { \
- prvTraceStoreEvent1(prvGetStreamBufferType(xStreamBuffer) > 0 ? PSF_EVENT_MESSAGEBUFFER_RECEIVE_FROM_ISR_FAILED : PSF_EVENT_STREAMBUFFER_RECEIVE_FROM_ISR_FAILED, (uint32_t)xStreamBuffer); \
- } \
- }
-
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1) */
-
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
-
-#else /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
-
-/* When recorder is disabled */
-#define vTraceSetQueueName(object, name)
-#define vTraceSetSemaphoreName(object, name)
-#define vTraceSetMutexName(object, name)
-#define vTraceSetEventGroupName(object, name)
-#define vTraceSetStreamBufferName(object, name)
-#define vTraceSetMessageBufferName(object, name)
-
-#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_KERNEL_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcPortDefines.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcPortDefines.h
deleted file mode 100755
index 30858c9..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcPortDefines.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcPortDefines.h
- *
- * Some common defines for the trace recorder.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_PORTDEFINES_H
-#define TRC_PORTDEFINES_H
-
-#define TRC_FREE_RUNNING_32BIT_INCR 1
-#define TRC_FREE_RUNNING_32BIT_DECR 2
-#define TRC_OS_TIMER_INCR 3
-#define TRC_OS_TIMER_DECR 4
-#define TRC_CUSTOM_TIMER_INCR 5
-#define TRC_CUSTOM_TIMER_DECR 6
-
-/* Start options for vTraceEnable. */
-#define TRC_INIT 0
-#define TRC_START 1
-#define TRC_START_AWAIT_HOST 2
-
-/* Command codes for TzCtrl task */
-#define CMD_SET_ACTIVE 1 /* Start (param1 = 1) or Stop (param1 = 0) */
-
-/* The final command code, used to validate commands. */
-#define CMD_LAST_COMMAND 1
-
-#define TRC_RECORDER_MODE_SNAPSHOT 0
-#define TRC_RECORDER_MODE_STREAMING 1
-
-#define TRC_RECORDER_BUFFER_ALLOCATION_STATIC (0x00)
-#define TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC (0x01)
-#define TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM (0x02)
-
-/* Filter Groups */
-#define FilterGroup0 (uint16_t)0x0001
-#define FilterGroup1 (uint16_t)0x0002
-#define FilterGroup2 (uint16_t)0x0004
-#define FilterGroup3 (uint16_t)0x0008
-#define FilterGroup4 (uint16_t)0x0010
-#define FilterGroup5 (uint16_t)0x0020
-#define FilterGroup6 (uint16_t)0x0040
-#define FilterGroup7 (uint16_t)0x0080
-#define FilterGroup8 (uint16_t)0x0100
-#define FilterGroup9 (uint16_t)0x0200
-#define FilterGroup10 (uint16_t)0x0400
-#define FilterGroup11 (uint16_t)0x0800
-#define FilterGroup12 (uint16_t)0x1000
-#define FilterGroup13 (uint16_t)0x2000
-#define FilterGroup14 (uint16_t)0x4000
-#define FilterGroup15 (uint16_t)0x8000
-
-/******************************************************************************
- * Supported ports
- *
- * TRC_HARDWARE_PORT_HWIndependent
- * A hardware independent fallback option for event timestamping. Provides low
- * resolution timestamps based on the OS tick.
- * This may be used on the Win32 port, but may also be used on embedded hardware
- * platforms. All time durations will be truncated to the OS tick frequency,
- * typically 1 KHz. This means that a task or ISR that executes in less than
- * 1 ms get an execution time of zero.
- *
- * TRC_HARDWARE_PORT_APPLICATION_DEFINED
- * Allows for defining the port macros in other source code files.
- *
- * TRC_HARDWARE_PORT_Win32
- * "Accurate" timestamping based on the Windows performance counter for Win32
- * builds. Note that this gives the host machine time, not the kernel time.
- *
- * Hardware specific ports
- * To get accurate timestamping, a hardware timer is necessary. Below are the
- * available ports. Some of these are "unofficial", meaning that
- * they have not yet been verified by Percepio but have been contributed by
- * external developers. They should work, otherwise let us know by emailing
- * support@percepio.com. Some work on any OS platform, while other are specific
- * to a certain operating system.
- *****************************************************************************/
-
-/****** Port Name ************************************* Code ** Official ** OS Platform *********/
-#define TRC_HARDWARE_PORT_APPLICATION_DEFINED 98 /* - - */
-#define TRC_HARDWARE_PORT_NOT_SET 99 /* - - */
-#define TRC_HARDWARE_PORT_HWIndependent 0 /* Yes Any */
-#define TRC_HARDWARE_PORT_Win32 1 /* Yes FreeRTOS on Win32 */
-#define TRC_HARDWARE_PORT_Atmel_AT91SAM7 2 /* No Any */
-#define TRC_HARDWARE_PORT_Atmel_UC3A0 3 /* No Any */
-#define TRC_HARDWARE_PORT_ARM_Cortex_M 4 /* Yes Any */
-#define TRC_HARDWARE_PORT_Renesas_RX600 6 /* Yes Any */
-#define TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32 7 /* Yes Any */
-#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48 8 /* Yes Any */
-#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430 9 /* No Any */
-#define TRC_HARDWARE_PORT_XILINX_PPC405 11 /* No FreeRTOS */
-#define TRC_HARDWARE_PORT_XILINX_PPC440 12 /* No FreeRTOS */
-#define TRC_HARDWARE_PORT_XILINX_MICROBLAZE 13 /* No Any */
-#define TRC_HARDWARE_PORT_NXP_LPC210X 14 /* No Any */
-#define TRC_HARDWARE_PORT_ARM_CORTEX_A9 15 /* Yes Any */
-#define TRC_HARDWARE_PORT_POWERPC_Z4 16 /* No FreeRTOS */
-#define TRC_HARDWARE_PORT_Altera_NiosII 17 /* No Any */
-#endif /*TRC_PORTDEFINES_H*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcRecorder.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcRecorder.h
deleted file mode 100755
index 38e5ef7..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcRecorder.h
+++ /dev/null
@@ -1,1789 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcRecorder.h
- *
- * The public API of the trace recorder.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_RECORDER_H
-#define TRC_RECORDER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-#include
-
-#include "trcConfig.h"
-#include "trcPortDefines.h"
-
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-typedef uint16_t traceString;
-typedef uint8_t traceUBChannel;
-typedef uint8_t traceObjectClass;
-
-#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
-typedef uint16_t traceHandle;
-#else
-typedef uint8_t traceHandle;
-#endif
-
-#include "trcHardwarePort.h"
-#include "trcKernelPort.h"
-
-// Not available in snapshot mode
-#define vTraceConsoleChannelPrintF(fmt, ...)
-
-#endif
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-typedef const char* traceString;
-typedef const void* traceHandle;
-
-#include "trcHardwarePort.h"
-#include "trcStreamingPort.h"
-#include "trcKernelPort.h"
-
-#endif
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-/* The user event channel for recorder warnings, must be defined in trcKernelPort.c */
-extern traceString trcWarningChannel;
-
-#define TRACE_GET_LOW16(value) ((uint16_t)((value) & 0x0000FFFF))
-#define TRACE_GET_HIGH16(value) ((uint16_t)(((value) >> 16) & 0x0000FFFF))
-#define TRACE_SET_LOW16(current, value) (((current) & 0xFFFF0000) | (value))
-#define TRACE_SET_HIGH16(current, value) (((current) & 0x0000FFFF) | (((uint32_t)(value)) << 16))
-
-/******************************************************************************/
-/*** Common API - both Snapshot and Streaming mode ****************************/
-/******************************************************************************/
-
-/******************************************************************************
-* vTraceEnable(int startOption);
-*
-* Initializes and optionally starts the trace, depending on the start option.
-* To use the trace recorder, the startup must call vTraceEnable before any RTOS
-* calls are made (including "create" calls). Three start options are provided:
-*
-* TRC_START: Starts the tracing directly. In snapshot mode this allows for
-* starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)
-* has been called in the startup.
-* Can also be used for streaming without Tracealyzer control, e.g. to a local
-* flash file system (assuming such a "stream port", see trcStreamingPort.h).
-*
-* TRC_START_AWAIT_HOST: For streaming mode only. Initializes the trace recorder
-* if necessary and waits for a Start command from Tracealyzer ("Start Recording"
-* button). This call is intentionally blocking! By calling vTraceEnable with
-* this option from the startup code, you start tracing at this point and capture
-* the early events.
-*
-* TRC_INIT: Initializes the trace recorder, but does not start the tracing.
-* In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime
-* later.
-*
-* Usage examples:
-*
-* Snapshot trace, from startup:
-*
-* vTraceEnable(TRC_START);
-*
-*
-* Snapshot trace, from a later point:
-*
-* vTraceEnable(TRC_INIT);
-*
-* ...
-* vTraceEnable(TRC_START); // e.g., in task context, at some relevant event
-*
-* Streaming trace, from startup:
-*
-* vTraceEnable(TRC_START_AWAIT_HOST); // Blocks!
-*
-*
-* Streaming trace, from a later point:
-*
-* vTraceEnable(TRC_INIT);
-*
-*
-******************************************************************************/
-void vTraceEnable(int startOption);
-
-/******************************************************************************
- * vTracePrintF
- *
- * Generates "User Events", with formatted text and data, similar to a "printf".
- * User Events can be used for very efficient logging from your application code.
- * It is very fast since the actual string formatting is done on the host side,
- * when the trace is displayed. The execution time is just some microseconds on
- * a 32-bit MCU.
- *
- * User Events are shown as yellow labels in the main trace view of $PNAME.
- *
- * An advantage of User Events is that data can be plotted in the "User Event
- * Signal Plot" view, visualizing any data you log as User Events, discrete
- * states or control system signals (e.g. system inputs or outputs).
- *
- * You may group User Events into User Event Channels. The yellow User Event
- * labels show the logged string, preceded by the channel name within brackets.
- *
- * Example:
- *
- * "[MyChannel] Hello World!"
- *
- * The User Event Channels are shown in the View Filter, which makes it easy to
- * select what User Events you wish to display. User Event Channels are created
- * using xTraceRegisterString().
- *
- * Example:
- *
- * traceString adc_uechannel = xTraceRegisterString("ADC User Events");
- * ...
- * vTracePrintF(adc_uechannel,
- * "ADC channel %d: %d volts",
- * ch, adc_reading);
- *
- * The following format specifiers are supported in both modes:
- * %d - signed integer.
- * %u - unsigned integer.
- * %X - hexadecimal, uppercase.
- * %x - hexadecimal, lowercase.
- * %s - string (see comment below)
- *
- * For integer formats (%d, %u, %x, %X) you may also use width and padding.
- * If using -42 as data argument, two examples are:
- * "%05d" -> "-0042"
- * "%5d" -> " -42".
- *
- * String arguments are supported in both snapshot and streaming, but in streaming
- * mode you need to use xTraceRegisterString and use the returned traceString as
- * the argument. In snapshot you simply provide a char* as argument.
- *
- * Snapshot: vTracePrintF(myChn, "my string: %s", str);
- * Streaming: vTracePrintF(myChn, "my string: %s", xTraceRegisterString(str));
- *
- * In snapshot mode you can specify 8-bit or 16-bit arguments to reduce RAM usage:
- * %hd -> 16 bit (h) signed integer (d).
- * %bu -> 8 bit (b) unsigned integer (u).
- *
- * However, in streaming mode all data arguments are assumed to be 32 bit wide.
- * Width specifiers (e.g. %hd) are accepted but ignored (%hd treated like %d).
- *
- * The maximum event size also differs between the modes. In streaming this is
- * limited by a maximum payload size of 52 bytes, including format string and
- * data arguments. So if using one data argument, the format string is limited
- * to 48 byte, etc. If this is exceeded, the format string is truncated and you
- * get a warning in Tracealyzer.
- *
- * In snapshot mode you are limited to maximum 15 arguments, that must not exceed
- * 32 bytes in total (not counting the format string). If exceeded, the recorder
- * logs an internal error (displayed when opening the trace) and stops recording.
- ******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
-void vTracePrintF(traceString chn, const char* fmt, ...);
-#else
-#define vTracePrintF(chn, ...) (void)chn
-#endif
-
- /******************************************************************************
-* vTracePrint
-*
-* A faster version of vTracePrintF, that only allows for logging a string.
-*
-* Example:
-*
-* traceString chn = xTraceRegisterString("MyChannel");
-* ...
-* vTracePrint(chn, "Hello World!");
-******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
-void vTracePrint(traceString chn, const char* str);
-#else
-#define vTracePrint(chn, ...) (void)chn
-#endif
-
-
-/*******************************************************************************
-* vTraceConsoleChannelPrintF
-*
-* Wrapper for vTracePrint, using the default channel. Can be used as a drop-in
-* replacement for printf and similar functions, e.g. in a debug logging macro.
-*
-* Example:
-*
-* // Old: #define LogString debug_console_printf
-*
-* // New, log to Tracealyzer instead:
-* #define LogString vTraceConsoleChannelPrintF
-* ...
-* LogString("My value is: %d", myValue);
-******************************************************************************/
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-void vTraceConsoleChannelPrintF(const char* fmt, ...);
-#endif
-
-/*******************************************************************************
-* xTraceRegisterString
-*
-* Register strings in the recorder, e.g. for names of user event channels.
-*
-* Example:
-* myEventHandle = xTraceRegisterString("MyUserEvent");
-* ...
-* vTracePrintF(myEventHandle, "My value is: %d", myValue);
-******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
-traceString xTraceRegisterString(const char* name);
-#else
-#define xTraceRegisterString(x) (x)
-#endif
-
-/*******************************************************************************
- * vTraceSet...Name(void* object, const char* name)
- *
- * Parameter object: pointer to the kernel object that shall be named
- * Parameter name: the name to set
- *
- * Kernel-specific functions for setting names of kernel objects, for display in
- * Tracealyzer.
- ******************************************************************************/
-/* See trcKernelPort.h for details (kernel-specific) */
-
-/*******************************************************************************
- * xTraceSetISRProperties
- *
- * Stores a name and priority level for an Interrupt Service Routine, to allow
- * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
-traceHandle xTraceSetISRProperties(const char* name, uint8_t priority);
-
-/*******************************************************************************
- * vTraceStoreISRBegin
- *
- * Registers the beginning of an Interrupt Service Routine, using a traceHandle
- * provided by xTraceSetISRProperties.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
-void vTraceStoreISRBegin(traceHandle handle);
-
-/*******************************************************************************
- * vTraceStoreISREnd
- *
- * Registers the end of an Interrupt Service Routine.
- *
- * The parameter pendingISR indicates if the interrupt has requested a
- * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the
- * interrupt is assumed to return to the previous context.
- *
- * Example:
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
- * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder
- * ...
- * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(traceHandleIsrTimer1);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
-void vTraceStoreISREnd(int isTaskSwitchRequired);
-
-/*******************************************************************************
- * vTraceInstanceFinishNow
- *
- * Creates an event that ends the current task instance at this very instant.
- * This makes the viewer to splits the current fragment at this point and begin
- * a new actor instance, even if no task-switch has occurred.
- *****************************************************************************/
-void vTraceInstanceFinishedNow(void);
-
-/*******************************************************************************
- * vTraceInstanceFinishedNext
- *
- * Marks the current "task instance" as finished on the next kernel call.
- *
- * If that kernel call is blocking, the instance ends after the blocking event
- * and the corresponding return event is then the start of the next instance.
- * If the kernel call is not blocking, the viewer instead splits the current
- * fragment right before the kernel call, which makes this call the first event
- * of the next instance.
- *****************************************************************************/
-void vTraceInstanceFinishedNext(void);
-
-/*******************************************************************************
- * xTraceGetLastError
- *
- * Returns the last error or warning as a string, or NULL if none.
- *****************************************************************************/
-const char* xTraceGetLastError(void);
-
-/*******************************************************************************
- * vTraceClearError
- *
- * Clears any errors.
- *****************************************************************************/
-void vTraceClearError(void);
-
-/*******************************************************************************
-* vTraceStop
-*
-* Stops the recording. Intended for snapshot mode or if streaming without
-* Tracealyzer control (e.g., to a device file system).
-******************************************************************************/
-void vTraceStop(void);
-
-/******************************************************************************
-* vTraceSetFrequency
-*
-* Registers the clock rate of the time source for the event timestamping.
-* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)
-* should be incorrect for your setup, you can override it using this function.
-*
-* Must be called prior to vTraceEnable, and the time source is assumed to
-* have a fixed clock frequency after the startup.
-*
-* Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.
-* This is a software "prescaler" that is also applied on the timestamps.
-*****************************************************************************/
-void vTraceSetFrequency(uint32_t frequency);
-
-/*******************************************************************************
-* vTraceSetRecorderDataBuffer
-*
-* The trcConfig.h setting TRC_CFG_RECORDER_BUFFER_ALLOCATION allows for selecting
-* custom allocation (TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), which allows you to
-* control where the recorder trace buffer is allocated.
-*
-* When custom allocation is selected, use TRC_ALLOC_CUSTOM_BUFFER to make the
-* allocation (in global context) and then call vTraceSetRecorderDataBuffer to
-* register the allocated buffer. This supports both snapshot and streaming,
-* and has no effect if using other allocation modes than CUSTOM.
-*
-* NOTE: vTraceSetRecorderDataBuffer must be called before vTraceEnable.
-******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
-void vTraceSetRecorderDataBuffer(void* pRecorderData);
-#else
-#define vTraceSetRecorderDataBuffer(pRecorderData)
-#endif
-
-
-/*******************************************************************************
-* TRC_ALLOC_CUSTOM_BUFFER
-*
-* If using custom allocation of the trace buffer (i.e., your trcConfig.h has the
-* setting TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), this macro allows you to declare
-* the trace buffer in a portable way that works both in snapshot and streaming.
-*
-* This macro has no effect if using another allocation mode, so you can easily
-* switch between different recording modes and configurations, using the same
-* initialization code.
-*
-* This translates to a single static allocation, on which you can apply linker
-* directives to place it in a particular memory region.
-*
-* - Snapshot mode: "RecorderDataType "
-*
-* - Streaming mode: "char []",
-* where is defined in trcStreamingConfig.h.
-*
-* Example:
-*
-* // GCC example: place myTraceBuffer in section .tz, defined in the .ld file.
-* TRC_ALLOC_CUSTOM_BUFFER(myTraceBuffer) __attribute__((section(".tz")));
-*
-* int main(void)
-* {
-* ...
-* vTraceSetRecorderDataBuffer(&myTraceBuffer); // Note the "&"
-* ...
-* vTraceEnable(TRC_INIT); // Initialize the data structure
-******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
- #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
- #define TRC_ALLOC_CUSTOM_BUFFER(bufname) RecorderDataType bufname;
- #elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
- #ifdef TRC_CFG_RTT_BUFFER_SIZE_UP /* J-Link RTT */
- #define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Not static in this case, since declared in user code */
- #else
- #define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];
- #endif
- #endif
-#else
- #define TRC_ALLOC_CUSTOM_BUFFER(bufname)
-#endif
-
-/******************************************************************************
-* xTraceIsRecordingEnabled
-*
-* Returns true (1) if the recorder is enabled (i.e. is recording), otherwise 0.
-******************************************************************************/
-int xTraceIsRecordingEnabled(void);
-
-/*******************************************************************************
-* vTraceSetFilterGroup
-*
-* Sets the "filter group" to assign when creating RTOS objects, such as tasks,
-* queues, semaphores and mutexes. This together with vTraceSetFilterMask
-* allows you to control what events that are recorded, based on the
-* objects they refer to.
-*
-* There are 16 filter groups named FilterGroup0 .. FilterGroup15.
-*
-* Note: We don't recommend filtering out the Idle task, so make sure to call
-* vTraceSetFilterGroup just before initializing the RTOS, in order to assign
-* such "default" objects to the right Filter Group (typically group 0).
-*
-* Example:
-*
-* // Assign tasks T1 to FilterGroup0 (default)
-*
-*
-* // Assign Q1 and Q2 to FilterGroup1
-* vTraceSetFilterGroup(FilterGroup1);
-*
-*
-*
-* // Assigns Q3 to FilterGroup2
-* vTraceSetFilterGroup(FilterGroup2);
-*
-*
-* // Only include FilterGroup0 and FilterGroup2, exclude FilterGroup1 (Q1 and Q2) from the trace
-* vTraceSetFilterMask( FilterGroup0 | FilterGroup2 );
-*
-* // Assign the default RTOS objects (e.g. Idle task) to FilterGroup0
-* vTraceSetFilterGroup(FilterGroup0);
-*
-*
-* Note that you may define your own names for the filter groups using
-* preprocessor definitions, to make the code easier to understand.
-*
-* Example:
-*
-* #define BASE FilterGroup0
-* #define USB_EVENTS FilterGroup1
-* #define CAN_EVENTS FilterGroup2
-*
-* Note that filtering per event type (regardless of object) is also available
-* in trcConfig.h.
-******************************************************************************/
-void vTraceSetFilterGroup(uint16_t filterGroup);
-
-/******************************************************************************
-* vTraceSetFilterMask
-*
-* Sets the "filter mask" that is used to filter the events by object. This can
-* be used to reduce the trace data rate, i.e., if your streaming interface is
-* a bottleneck or if you want longer snapshot traces without increasing the
-* buffer size.
-*
-* Note: There are two kinds of filters in the recorder. The other filter type
-* excludes all events of certain kinds (e.g., OS ticks). See trcConfig.h.
-*
-* The filtering is based on bitwise AND with the Filter Group ID, assigned
-* to RTOS objects such as tasks, queues, semaphores and mutexes.
-* This together with vTraceSetFilterGroup allows you to control what
-* events that are recorded, based on the objects they refer to.
-*
-* See example for vTraceSetFilterGroup.
-******************************************************************************/
-void vTraceSetFilterMask(uint16_t filterMask);
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-
-/******************************************************************************/
-/*** Extended API for Snapshot mode *******************************************/
-/******************************************************************************/
-
-/******************************************************************************
-* TRACE_STOP_HOOK - Hook Pointer Data Type
-*
-* Declares a data type for a call back function that will be invoked whenever
-* the recorder is stopped.
-*
-* Snapshot mode only!
-******************************************************************************/
-typedef void(*TRACE_STOP_HOOK)(void);
-
-/*******************************************************************************
-* vTraceStopHookPtr
-*
-* Points to a call back function that is called from vTraceStop().
-*
-* Snapshot mode only!
-******************************************************************************/
-extern TRACE_STOP_HOOK vTraceStopHookPtr;
-
-/*******************************************************************************
-* vTraceSetStopHook
-*
-* Sets a function to be called when the recorder is stopped.
-*
-* Snapshot mode only!
-******************************************************************************/
-void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);
-
-/*******************************************************************************
-* uiTraceStart
-*
-* [DEPRECATED] Use vTraceEnable instead.
-*
-* Starts the recorder. The recorder will not be started if an error has been
-* indicated using prvTraceError, e.g. if any of the Nx constants in
-* trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).
-*
-* Returns 1 if the recorder was started successfully.
-* Returns 0 if the recorder start was prevented due to a previous internal
-* error. In that case, check xTraceGetLastError to get the error message.
-* Any error message is also presented when opening a trace file.
-*
-* Snapshot mode only!
-******************************************************************************/
-uint32_t uiTraceStart(void);
-
-/*******************************************************************************
-* vTraceStart
-*
-* [DEPRECATED] Use vTraceEnable instead.
-*
-* Starts the recorder. The recorder will not be started if an error has been
-* indicated using prvTraceError, e.g. if any of the Nx constants in
-* trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).
-*
-* Snapshot mode only!
-******************************************************************************/
-void vTraceStart(void);
-
-/*******************************************************************************
-* vTraceClear
-*
-* Resets the recorder. Only necessary if a restart is desired - this is not
-* needed in the startup initialization.
-*
-* Snapshot mode only!
-******************************************************************************/
-void vTraceClear(void);
-
-
-/*****************************************************************************/
-/*** INTERNAL SNAPSHOT FUNCTIONS *********************************************/
-/*****************************************************************************/
-
-#define TRC_UNUSED
-
-#ifndef TRC_CFG_INCLUDE_OBJECT_DELETE
-#define TRC_CFG_INCLUDE_OBJECT_DELETE 0
-#endif
-
-#ifndef TRC_CFG_INCLUDE_READY_EVENTS
-#define TRC_CFG_INCLUDE_READY_EVENTS 1
-#endif
-
-#ifndef TRC_CFG_INCLUDE_OSTICK_EVENTS
-#define TRC_CFG_INCLUDE_OSTICK_EVENTS 0
-#endif
-
-/* This macro will create a task in the object table */
-#undef trcKERNEL_HOOKS_TASK_CREATE
-#define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \
- TRACE_SET_OBJECT_NUMBER(TASK, pxTCB); \
- TRACE_SET_OBJECT_FILTER(TASK, pxTCB, CurrentFilterGroup); \
- prvTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \
- prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
-
-/* This macro will remove the task and store it in the event buffer */
-#undef trcKERNEL_HOOKS_TASK_DELETE
-#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, pxTCB) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
- prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
- prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
- prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
- prvTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \
- prvTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
-
-
-/* This macro will setup a task in the object table */
-#undef trcKERNEL_HOOKS_OBJECT_CREATE
-#define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\
- TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\
- TRACE_SET_OBJECT_FILTER(CLASS, pxObject, CurrentFilterGroup); \
- prvMarkObjectAsUsed(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
- prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);
-
-/* This macro will remove the object and store it in the event buffer */
-#undef trcKERNEL_HOOKS_OBJECT_DELETE
-#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, CLASS, pxObject) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
- prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
- prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
- prvTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE
-#define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, CLASS, pxObject) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
-
-/* This macro will create a call to a kernel service with a certain result, with a null object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT(SERVICE, TRACECLASS) \
- if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACECLASS, 0);
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(SERVICE, CLASS, pxObject, param) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);
-
-/* This macro will create a call to a kernel service with a certain result, with a null object and other value as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM(SERVICE, TRACECLASS, param) \
- if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreKernelCallWithParam(SERVICE, TRACECLASS, 0, param);
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(SERVICE, param) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(SERVICE, CLASS, pxObject) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR(SERVICE, CLASS, pxObject, param) \
- if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
- prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);
-
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR
-#define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR(SERVICE, param) \
- prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);
-
-/* This macro will set the state for an object */
-#undef trcKERNEL_HOOKS_SET_OBJECT_STATE
-#define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \
- prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint8_t)STATE);
-
-/* This macro will flag a certain task as a finished instance */
-#undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED
-#define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- prvTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));
-
-#if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
-/* This macro will create an event to indicate that a task became Ready */
-#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
-#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));
-#else /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/
-#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
-#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)
-#endif /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/
-
-/* This macro will update the internal tick counter and call prvTracePortGetTimeStamp(0) to update the internal counters */
-#undef trcKERNEL_HOOKS_INCREMENT_TICK
-#define trcKERNEL_HOOKS_INCREMENT_TICK() \
- { \
- extern uint32_t uiTraceTickCount; \
- uiTraceTickCount++; \
- prvTracePortGetTimeStamp(0); \
- }
-
-#if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)
-/* This macro will create an event indicating that the OS tick count has increased */
-#undef trcKERNEL_HOOKS_NEW_TIME
-#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \
- prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);
-#else /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/
-#undef trcKERNEL_HOOKS_NEW_TIME
-#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)
-#endif /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/
-
-/* This macro will create a task switch event to the currently executing task */
-#undef trcKERNEL_HOOKS_TASK_SWITCH
-#define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));
-
-/* This macro will create an event to indicate that the task has been suspended */
-#undef trcKERNEL_HOOKS_TASK_SUSPEND
-#define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
- prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));
-
-/* This macro will create an event to indicate that a task has called a wait/delay function */
-#undef trcKERNEL_HOOKS_TASK_DELAY
-#define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- { \
- prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \
- prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB)); \
- }
-
-/* This macro will create an event to indicate that a task has gotten its priority changed */
-#undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE
-#define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- { \
- prvTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), prvTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\
- prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority); \
- }
-
-/* This macro will create an event to indicate that the task has been resumed */
-#undef trcKERNEL_HOOKS_TASK_RESUME
-#define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \
- if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
-
-#undef trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR
-#define trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR(SERVICE, pxTCB) \
- if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
- prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
-
-#if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1
- void prvTraceSetReadyEventsEnabled(int status);
- void prvTraceStoreTaskReady(traceHandle handle);
-#else
- #define prvTraceSetReadyEventsEnabled(status)
-#endif
-
-void prvTraceStoreLowPower(uint32_t flag);
-
-void prvTraceStoreTaskswitch(traceHandle task_handle);
-
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-
-void prvTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);
-
-void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param);
-
-void prvTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,
- uint32_t objectNumber, uint32_t param);
-#else
-
-#define prvTraceStoreKernelCall(eventcode, objectClass, byteParam) {}
-#define prvTraceStoreKernelCallWithNumericParamOnly(evtcode, param) {}
-#define prvTraceStoreKernelCallWithParam(evtcode, objectClass, objectNumber, param) {}
-
-#endif
-
-void prvTraceSetTaskInstanceFinished(traceHandle handle);
-
-void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value);
-
-uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id);
-
-void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value);
-
-void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle);
-
-void prvTraceStoreObjectNameOnCloseEvent(uint8_t evtcode, traceHandle handle,
- traceObjectClass objectclass);
-
-void prvTraceStoreObjectPropertiesOnCloseEvent(uint8_t evtcode, traceHandle handle,
- traceObjectClass objectclass);
-
-/* Internal constants for task state */
-#define TASK_STATE_INSTANCE_NOT_ACTIVE 0
-#define TASK_STATE_INSTANCE_ACTIVE 1
-
-
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 0)
-
-#undef vTraceSetISRProperties
-#define vTraceSetISRProperties(handle, name, priority)
-
-#undef vTraceStoreISRBegin
-#define vTraceStoreISRBegin(x) (void)x
-
-#undef vTraceStoreISREnd
-#define vTraceStoreISREnd(x) (void)x
-
-#undef xTraceSetISRProperties
-#define xTraceSetISRProperties(name, priority) 0
-
-#endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/
-
-/*******************************************************************************
- * xTraceGetTraceBuffer
- *
- * Returns a pointer to the recorder data structure. Use this together with
- * uiTraceGetTraceBufferSize if you wish to implement an own store/upload
- * solution, e.g., in case a debugger connection is not available for uploading
- * the data.
- ******************************************************************************/
-void* xTraceGetTraceBuffer(void);
-
-/*******************************************************************************
- * uiTraceGetTraceBufferSize
- *
- * Gets the size of the recorder data structure. For use together with
- * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,
- * e.g., in case a debugger connection is not available for uploading the data.
- ******************************************************************************/
-uint32_t uiTraceGetTraceBufferSize(void);
-
-#if (TRC_CFG_SCHEDULING_ONLY == 1)
-#undef TRC_CFG_INCLUDE_USER_EVENTS
-#define TRC_CFG_INCLUDE_USER_EVENTS 0
-#endif /*(TRC_CFG_SCHEDULING_ONLY == 1)*/
-
-#if ((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))
-
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
-traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr);
-void vTraceUBData(traceUBChannel channel, ...);
-void vTraceUBEvent(traceUBChannel channel);
-#endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/
-
-#else /*((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))*/
-
-#undef vTracePrint
-#define vTracePrint(chn, ...) (void)chn
-#undef vTracePrintF
-#define vTracePrintF(chn, ...) (void)chn
-#undef xTraceRegisterString
-#define xTraceRegisterString(x) 0; (void)x;
-#undef xTraceRegisterChannelFormat
-#define xTraceRegisterChannelFormat(eventLabel, formatStr) 0
-#undef vTraceUBData
-#define vTraceUBData(label, ...) {}
-#undef vTraceChannelPrint
-#define vTraceChannelPrint(label) {}
-
-#endif /*(TRC_CFG_INCLUDE_USER_EVENTS == 1)*/
-
-#define NEventCodes 0x100
-
-/* Our local critical sections for the recorder */
-#define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}
-#define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)
- #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY TRACE_ALLOC_CRITICAL_SECTION
- #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN
- #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END
-#else
- #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY() {}
- #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;
- #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;
-#endif
-
-/******************************************************************************
- * ObjectHandleStack
- * This data-structure is used to provide a mechanism for 1-byte trace object
- * handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)
- * when storing a reference to an object. This allows for up to 255 objects of
- * each object class active at any given moment. There can be more "historic"
- * objects, that have been deleted - that number is only limited by the size of
- * the symbol table.
- *
- * Note that handle zero (0) is not used, it is a code for an invalid handle.
- *
- * This data structure keeps track of the FREE handles, not the handles in use.
- * This data structure contains one stack per object class. When a handle is
- * allocated to an object, the next free handle is popped from the stack. When
- * a handle is released (on object delete), it is pushed back on the stack.
- * Note that there is no initialization code that pushed the free handles
- * initially, that is not necessary due to the following optimization:
- *
- * The stack of handles (objectHandles) is initially all zeros. Since zero
- * is not a valid handle, that is a signal of additional handles needed.
- * If a zero is received when popping a new handle, it is replaced by the
- * index of the popped handle instead.
- *****************************************************************************/
-typedef struct
-{
- /* For each object class, the index of the next handle to allocate */
- uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];
-
- /* The lowest index of this class (constant) */
- uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];
-
- /* The highest index of this class (constant) */
- uint16_t highestIndexOfClass[ TRACE_NCLASSES ];
-
- /* The highest use count for this class (for statistics) */
- uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];
-
- /* The free object handles - a set of stacks within this array */
- traceHandle objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];
-
-} objectHandleStackType;
-
-extern objectHandleStackType objectHandleStacks;
-
-/******************************************************************************
- * Object Property Table
- * The Object Table contains name and other properties of the objects (tasks,
- * queues, mutexes, etc). The below data structures defines the properties of
- * each object class and are used to cast the byte buffer into a cleaner format.
- *
- * The values in the object table are continuously overwritten and always
- * represent the current state. If a property is changed during runtime, the OLD
- * value should be stored in the trace buffer, not the new value (since the new
- * value is found in the Object Property Table).
- *
- * For close events this mechanism is the old names are stored in the symbol
- * table), for "priority set" (the old priority is stored in the event data)
- * and for "isActive", where the value decides if the task switch event type
- * should be "new" or "resume".
- ******************************************************************************/
-
-typedef struct
-{
- /* = NCLASSES */
- uint32_t NumberOfObjectClasses;
-
- uint32_t ObjectPropertyTableSizeInBytes;
-
- /* This is used to calculate the index in the dynamic object table
- (handle - 1 - nofStaticObjects = index)*/
-#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
- traceHandle NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];
-#else
- traceHandle NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];
-#endif
-
- /* Allocation size rounded up to the closest multiple of 4 */
- uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
-
- uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
-
- /* Allocation size rounded up to the closest multiple of 2 */
- uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];
-
- /* The actual handles issued, should be Initiated to all zeros */
- uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];
-} ObjectPropertyTableType;
-
-/* Symbol table data structure */
-typedef struct
-{
- /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */
- uint32_t symTableSize;
-
- /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/
- uint32_t nextFreeSymbolIndex;
-
- /* Size rounded up to closest multiple of 4, to avoid alignment issues*/
- uint8_t symbytes[4*(((TRC_CFG_SYMBOL_TABLE_SIZE)+3)/4)];
-
- /* Used for lookups - Up to 64 linked lists within the symbol table
- connecting all entries with the same 6 bit checksum.
- This field holds the current list heads. Should be initiated to zeros */
- uint16_t latestEntryOfChecksum[64];
-} symbolTableType;
-
-
-/*******************************************************************************
- * The data structures of the different events, all 4 bytes long
- ******************************************************************************/
-
-typedef struct
-{
- uint8_t type;
- uint8_t objHandle;
- uint16_t dts; /* differential timestamp - time since last event */
-} TSEvent, TREvent;
-
-typedef struct
-{
- uint8_t type;
- uint8_t dummy;
- uint16_t dts; /* differential timestamp - time since last event */
-} LPEvent;
-
-typedef struct
-{
- uint8_t type;
- uint8_t objHandle;
- uint16_t dts; /* differential timestamp - time since last event */
-} KernelCall;
-
-typedef struct
-{
- uint8_t type;
- uint8_t objHandle;
- uint8_t param;
- uint8_t dts; /* differential timestamp - time since last event */
-} KernelCallWithParamAndHandle;
-
-typedef struct
-{
- uint8_t type;
- uint8_t dts; /* differential timestamp - time since last event */
- uint16_t param;
-} KernelCallWithParam16;
-
-typedef struct
-{
- uint8_t type;
- uint8_t objHandle; /* the handle of the closed object */
- uint16_t symbolIndex; /* the name of the closed object */
-} ObjCloseNameEvent;
-
-typedef struct
-{
- uint8_t type;
- uint8_t arg1;
- uint8_t arg2;
- uint8_t arg3;
-} ObjClosePropEvent;
-
-typedef struct
-{
- uint8_t type;
- uint8_t unused1;
- uint8_t unused2;
- uint8_t dts;
-} TaskInstanceStatusEvent;
-
-typedef struct
-{
- uint8_t type;
- uint8_t dts;
- uint16_t payload; /* the name of the user event */
-} UserEvent;
-
-typedef struct
-{
- uint8_t type;
-
- /* 8 bits extra for storing DTS, if it does not fit in ordinary event
- (this one is always MSB if used) */
- uint8_t xts_8;
-
- /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */
- uint16_t xts_16;
-} XTSEvent;
-
-typedef struct
-{
- uint8_t type;
-
- uint8_t xps_8;
- uint16_t xps_16;
-} XPSEvent;
-
-typedef struct{
- uint8_t type;
- uint8_t dts;
- uint16_t size;
-} MemEventSize;
-
-typedef struct{
- uint8_t type;
- uint8_t addr_high;
- uint16_t addr_low;
-} MemEventAddr;
-
-/*******************************************************************************
- * The separate user event buffer structure. Can be enabled in trcConfig.h.
- ******************************************************************************/
-
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
-typedef struct
-{
- traceString name;
- traceString defaultFormat;
-} ChannelFormatPair;
-
-typedef struct
-{
- uint16_t bufferID;
- uint16_t version;
- uint32_t wraparoundCounter;
- uint32_t numberOfSlots;
- uint32_t nextSlotToWrite;
- uint8_t numberOfChannels;
- uint8_t padding1;
- uint8_t padding2;
- uint8_t padding3;
- ChannelFormatPair channels[(TRC_CFG_UB_CHANNELS)+1];
- uint8_t channelBuffer[((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */
- uint8_t dataBuffer[(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) * 4]; /* 4 bytes per slot */
-
-} UserEventBuffer;
-#endif
-
-/*******************************************************************************
- * The main data structure, read by Tracealyzer from the RAM dump
- ******************************************************************************/
-
-typedef struct
-{
- volatile uint8_t startmarker0; /* Volatile is important, see init code. */
- volatile uint8_t startmarker1;
- volatile uint8_t startmarker2;
- volatile uint8_t startmarker3;
- volatile uint8_t startmarker4;
- volatile uint8_t startmarker5;
- volatile uint8_t startmarker6;
- volatile uint8_t startmarker7;
- volatile uint8_t startmarker8;
- volatile uint8_t startmarker9;
- volatile uint8_t startmarker10;
- volatile uint8_t startmarker11;
-
- /* Used to determine Kernel and Endianess */
- uint16_t version;
-
- /* Currently 5 */
- uint8_t minor_version;
-
- /* This should be 0 if lower IRQ priority values implies higher priority
- levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,
- if higher IRQ priority values means higher priority, this should be 1. */
- uint8_t irq_priority_order;
-
- /* sizeof(RecorderDataType) - just for control */
- uint32_t filesize;
-
- /* Current number of events recorded */
- uint32_t numEvents;
-
- /* The buffer size, in number of event records */
- uint32_t maxEvents;
-
- /* The event buffer index, where to write the next event */
- uint32_t nextFreeIndex;
-
- /* 1 if the buffer is full, 0 otherwise */
- uint32_t bufferIsFull;
-
- /* The frequency of the clock/timer/counter used as time base */
- uint32_t frequency;
-
- /* The absolute timestamp of the last stored event, in the native
- timebase, modulo frequency! */
- uint32_t absTimeLastEvent;
-
- /* The number of seconds in total - lasts for 136 years */
- uint32_t absTimeLastEventSecond;
-
- /* 1 if the recorder has been started, 0 if not yet started or stopped.
- This is a 32 bit variable due to alignment issues. */
- uint32_t recorderActive;
-
- /* If > 0, tells the maximum time between two traced ISRs that execute
- back-to-back. If the time between vTraceStoreISREnd and a directly
- following vTraceISRBegin is above isrTailchainingThreshold, we assume a
- return to the previous context in between the ISRs, otherwise we assume
- the have executed back-to-back and don't show any fragment of the previous
- context in between. */
- uint32_t isrTailchainingThreshold;
-
- /* Not used, remains for compatibility and future use */
- uint8_t notused[24];
-
- /* The amount of heap memory remaining at the last malloc or free event */
- uint32_t heapMemUsage;
-
- /* 0xF0F0F0F0 - for control only */
- int32_t debugMarker0;
-
- /* Set to value of TRC_CFG_USE_16BIT_OBJECT_HANDLES */
- uint32_t isUsing16bitHandles;
-
- /* The Object Property Table holds information about currently active
- tasks, queues, and other recorded objects. This is updated on each
- create call and includes object name and other properties. */
- ObjectPropertyTableType ObjectPropertyTable;
-
- /* 0xF1F1F1F1 - for control only */
- int32_t debugMarker1;
-
- /* The Symbol Table stores strings for User Events and is also used to
- store names of deleted objects, which still may be in the trace but no
- longer are available. */
- symbolTableType SymbolTable;
-
- /* For inclusion of float support, and for endian detection of floats.
- The value should be (float)1 or (uint32_t)0 */
-#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)
- float exampleFloatEncoding;
-#else
- uint32_t exampleFloatEncoding;
-#endif
- /* This is non-zero if an internal error occurred in the recorder, e.g., if
- one of the Nxxx constants was too small. The systemInfo string will then
- contain an error message that is displayed when attempting to view the
- trace file. */
- uint32_t internalErrorOccured;
-
- /* 0xF2F2F2F2 - for control only */
- int32_t debugMarker2;
-
- /* Error messages from the recorder. */
- char systemInfo[80];
-
- /* 0xF3F3F3F3 - for control only */
- int32_t debugMarker3;
-
- /* The event data, in 4-byte records */
- uint8_t eventData[ (TRC_CFG_EVENT_BUFFER_SIZE) * 4 ];
-
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
- UserEventBuffer userEventBuffer;
-#endif
-
- /* This should always be 0 */
- uint32_t endOfSecondaryBlocks;
-
- uint8_t endmarker0;
- uint8_t endmarker1;
- uint8_t endmarker2;
- uint8_t endmarker3;
- uint8_t endmarker4;
- uint8_t endmarker5;
- uint8_t endmarker6;
- uint8_t endmarker7;
- uint8_t endmarker8;
- uint8_t endmarker9;
- uint8_t endmarker10;
- uint8_t endmarker11;
-} RecorderDataType;
-
-extern RecorderDataType* RecorderDataPtr;
-
-/* Internal functions */
-
-/* Signal an error. */
-void prvTraceError(const char* msg);
-
-/*******************************************************************************
- * prvTracePortGetTimeStamp
- *
- * Returns the current time based on the HWTC macros which provide a hardware
- * isolation layer towards the hardware timer/counter.
- *
- * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue
- * or the trace recorder library. Typically you should not need to change
- * the code of prvTracePortGetTimeStamp if using the HWTC macros.
- *
- ******************************************************************************/
-void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);
-
-traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass);
-
-void prvTraceFreeObjectHandle(traceObjectClass objectclass,
- traceHandle handle);
-
-/* Private function. Use the public functions in trcKernelPort.h */
-void prvTraceSetObjectName(traceObjectClass objectclass,
- traceHandle handle,
- const char* name);
-
-/* Internal macros */
-
-#define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \
-(const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \
-[uiIndexOfObject(objecthandle, objectclass)])
-
-#define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \
-RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
-+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]
-
-#define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \
-RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
-+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]
-
-/* DEBUG ASSERTS */
-#if defined TRC_CFG_USE_TRACE_ASSERT && TRC_CFG_USE_TRACE_ASSERT != 0
-#define TRACE_ASSERT(eval, msg, defRetVal) \
-if (!(eval)) \
-{ \
- prvTraceError("TRACE_ASSERT: " msg); \
- return defRetVal; \
-}
-#else
-#define TRACE_ASSERT(eval, msg, defRetVal)
-#endif
-
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-/******************************************************************************
- * Default values for STREAM PORT macros
- *
- * As a normal user, this is nothing you don't need to bother about. This is
- * only important if you want to define your own custom streaming interface.
- *
- * You may override these in your own trcStreamingPort.h to create a custom
- * stream port, and thereby stream the trace on any host-target interface.
- * These default values are suitable for most cases, except the J-Link port.
- ******************************************************************************/
-
-/******************************************************************************
- * TRC_STREAM_PORT_USE_INTERNAL_BUFFER
- *
- * There are two kinds of stream ports, those that store the event to the
- * internal buffer (with periodic flushing by the TzCtrl task) and those that
- * write directly to the streaming interface. Most stream ports use the
- * recorder's internal buffer, except for the SEGGER J-Link port (also uses a
- * RAM buffer, but one defined in the SEGGER code).
- *
- * If the stream port (trcStreamingPort.h) defines this as zero (0), it is
- * expected to transmit the data directly using TRC_STREAM_PORT_COMMIT_EVENT.
- * Otherwise it is expected that the trace data is stored in the internal buffer
- * and the TzCtrl task will then send the buffer pages when they become full.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_USE_INTERNAL_BUFFER
-#define TRC_STREAM_PORT_USE_INTERNAL_BUFFER 1
-#endif
-
- /******************************************************************************
- * TRC_STREAM_PORT_ON_TRACE_BEGIN
- *
- * Defining any actions needed in the stream port when the recording is activated.
- *******************************************************************************/
-#ifndef TRC_STREAM_PORT_ON_TRACE_BEGIN
- #define TRC_STREAM_PORT_ON_TRACE_BEGIN() /* Do nothing */
-#endif
-
- /******************************************************************************
- * TRC_STREAM_PORT_ON_TRACE_BEGIN
- *
- * Defining any actions needed in the stream port when the tracing stops.
- * Empty by default.
- *******************************************************************************/
-#ifndef TRC_STREAM_PORT_ON_TRACE_END
-#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */
-#endif
-
- /******************************************************************************
- * TRC_STREAM_PORT_ALLOCATE_EVENT
- *
- * This macro is used to allocate memory for each event record, just before
- * assigning the record fields.
- * Depending on "TRC_STREAM_PORT_USE_INTERNAL_BUFFER", this either allocates
- * space in the paged event buffer, or on the local stack. In the latter case,
- * the COMMIT event is used to write the data to the streaming interface.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_ALLOCATE_EVENT
-#if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)
- #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);
-#else
- #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type _tmpArray[_size / sizeof(_type)]; _type* _ptrData = _tmpArray;
-#endif
-#endif
-
- /******************************************************************************
- * TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT
- *
- * This macro is used to allocate memory for each event record, just before
- * assigning the record fields.
- * This has the same purpose as TRC_STREAM_PORT_ALLOCATE_EVENT and by default
- * it has the same definition as TRC_STREAM_PORT_ALLOCATE_EVENT. This is used
- * for events carrying variable-sized payload, such as strings.
- * In the SEGGER RTT port, we need this in order to make a worst-case
- * allocation on the stack.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT
-#if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)
- #define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) /* We do the same thing as for non-dynamic event sizes */
-#else
- #define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) _type _tmpArray[sizeof(largestEventType) / sizeof(_type)]; _type* _ptrData = _tmpArray;
-#endif
-#endif
-
- /******************************************************************************
- * TRC_STREAM_PORT_COMMIT_EVENT
- *
- * The COMMIT macro is used to write a single event record directly to the
- * streaming inteface, without first storing the event in the internal buffer.
- * This is currently only used in the SEGGER J-Link RTT port.
- *
- * This relies on the TRC_STREAM_PORT_WRITE_DATA macro, defined in by the
- * stream port in trcStreamingPort.h. The COMMIT macro calls
- * prvTraceWarning(TRC_STREAM_PORT_WRITE_DATA) if a non-zero value is returned
- * from TRC_STREAM_PORT_WRITE_DATA. If zero (0) is returned, it is assumed
- * that all data was successfully written.
- *
- * In ports using the internal buffer, this macro has no purpose as the events
- * are written to the internal buffer instead. They are then flushed to the
- * streaming interface in the TzCtrl task using TRC_STREAM_PORT_WRITE_DATA.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_COMMIT_EVENT
-#if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)
- #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) /* Not used */
-#else
- #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) \
- { \
- if (TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, 0) != 0)\
- prvTraceWarning(PSF_WARNING_STREAM_PORT_WRITE); \
- }
-#endif
-#endif
-
-/******************************************************************************
- * TRC_STREAM_PORT_READ_DATA (defined in trcStreamingPort.h)
- *
- * Defining how to read data from host (commands from Tracealyzer).
- *
- * If there is no direct interface to host (e.g., if streaming to a file
- * system) this should be defined as 0. Instead use vTraceEnable(TRC_START) and
- * vTraceStop() to control the recording from target.
- *
- * Parameters:
- *
- * - _ptrData: a pointer to a data buffer, where the received data shall be
- * stored (TracealyzerCommandType*).
- *
- * - _size: the number of bytes to read (int).
- *
- * - _ptrBytesRead: a pointer to an integer (int), that should be assigned
- * with the number of bytes that was received.
- *
- * Example:
- *
- * int32_t myRead(void* ptrData, uint32_t size, int32_t* ptrBytesRead);
- *
- * #define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) \
- * myRead(_ptrData, _size, _ptrBytesRead)
- *
- * Your "myRead" function should return 0 if successful, i.e. if at least some
- * bytes were received. A non-zero value should be returned if the streaming
- * interface returned an error (e.g. a closed socket), which results in the
- * recorder calling prvTraceWarning with the error code
- * PSF_WARNING_STREAM_PORT_WRITE.
- *
- * If developing your own custom stream port and using the default internal
- * buffer, it is important that the _ptrBytesRead parameter is assigned
- * correctly by "myRead", i.e. with the number of bytes actually written.
- * Otherwise the data stream may get out of sync in case the streaming interface
- * can't swallow all data at once.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_READ_DATA
-#error "No definition for TRC_STREAM_PORT_READ_DATA (should be in trcStreamingPort.h)"
-#endif
-
-/******************************************************************************
- * TRC_STREAM_PORT_WRITE_DATA (defined in trcStreamingPort.h)
- *
- * Defining how to write trace data to the streaming interface.
- *
- * Parameters:
- *
- * - _ptrData: a pointer (void*) to the data to write.
- *
- * - _size: the number of bytes to write (uint32_t).
- *
- * - _ptrBytesWritten: a pointer to an integer (int32_t), that should be
- * assigned with the number of bytes actually written.
- *
- * Example:
- *
- * int32_t myWrite(void* ptrData, uint32_t size, int32_t* ptrBytesWritten);
- *
- * #define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesWritten) \
- * myWrite(_ptrData, _size, _ptrBytesWritten)
- *
- * Your "myWrite" function should return 0 if successful, i.e. if at least some
- * bytes were sent. A non-zero value should be returned if the streaming interface
- * returned an error (e.g. a closed socket), which results in the recorder calling
- * prvTraceWarning with the error code PSF_WARNING_STREAM_PORT_WRITE.
- *
- * If developing your own custom stream port and using the default internal
- * buffer, it is important that the _ptrBytesWritten parameter is assigned
- * correctly by "myWrite", i.e. with the number of bytes actually written.
- * Otherwise the data stream may get out of sync in case the streaming interface
- * can't swallow all data at once.
- *
- * Assuming TRC_STREAM_PORT_USE_INTERNAL_BUFFER is 1 (default), the TzCtrl task
- * will use this macro to send one buffer page at a time. In case all data can't
- * be written at once (if _ptrBytesWritten is less than _size), the TzCtrl task
- * is smart enough to make repeated calls (with updated parameters) in order to
- * send the remaining data.
- *
- * However, if TRC_STREAM_PORT_USE_INTERNAL_BUFFER is 0, this is used from the
- * COMMIT macro, directly in the "event functions". In that case, the
- * _ptrBytesWritten parameter will be NULL and should be ignored by the write
- * function. In this case, it is assumed that all data can be sent in a single
- * call, otherwise the write function should return a non-zero error code.
- ******************************************************************************/
-#ifndef TRC_STREAM_PORT_WRITE_DATA
-#error "No definition for TRC_STREAM_PORT_WRITE_DATA (should be in trcStreamingPort.h)"
-#endif
-
-/******************************************************************************
-* Data structure declaration, depending on TRC_CFG_RECORDER_BUFFER_ALLOCATION
-*******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)
-
- /* Static allocation. */
-
- /* If not defined in trcStreamingPort.h */
- #ifndef TRC_STREAM_PORT_ALLOCATE_FIELDS
- #define TRC_STREAM_PORT_ALLOCATE_FIELDS() \
- char _TzTraceData[(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];
- extern char _TzTraceData[(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];
- #endif
-
- /* If not defined in trcStreamingPort.h */
- #ifndef TRC_STREAM_PORT_MALLOC
- #define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
- #endif
-#else
- /* For Dynamic or Custom Allocation mode */
-
- /* If not defined in trcStreamingPort.h */
- #ifndef TRC_STREAM_PORT_ALLOCATE_FIELDS
- #define TRC_STREAM_PORT_ALLOCATE_FIELDS() char* _TzTraceData = NULL;
- extern char* _TzTraceData;
- #endif
-
- /* If not defined in trcStreamingPort.h */
- #ifndef TRC_STREAM_PORT_MALLOC
- #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)
- #define TRC_STREAM_PORT_MALLOC() \
- _TzTraceData = TRC_PORT_MALLOC((TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE));
- extern char* _TzTraceData;
- #else
- #define TRC_STREAM_PORT_MALLOC() /* Custom allocation. Not used. */
- #endif
- #endif
-#endif
-
-#ifndef TRC_STREAM_PORT_INIT
- #define TRC_STREAM_PORT_INIT() \
- TRC_STREAM_PORT_MALLOC(); /* Empty if static allocation mode */ \
- prvPagedEventBufferInit(_TzTraceData);
-#endif
-
-
-/* Signal an error. */
-void prvTraceError(int errCode);
-
-/* Signal an warning (does not stop the recorder). */
-void prvTraceWarning(int errCode);
-
-/******************************************************************************/
-/*** ERROR AND WARNING CODES (check using xTraceGetLastError) *****************/
-/******************************************************************************/
-
-#define PSF_ERROR_NONE 0
-#define PSF_ERROR_EVENT_CODE_TOO_LARGE 1
-#define PSF_ERROR_ISR_NESTING_OVERFLOW 2
-#define PSF_ERROR_DWT_NOT_SUPPORTED 3
-#define PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED 4
-#define PSF_ERROR_TZCTRLTASK_NOT_CREATED 5
-
-#define PSF_WARNING_SYMBOL_TABLE_SLOTS 101
-#define PSF_WARNING_SYMBOL_MAX_LENGTH 102
-#define PSF_WARNING_OBJECT_DATA_SLOTS 103
-#define PSF_WARNING_STRING_TOO_LONG 104
-#define PSF_WARNING_STREAM_PORT_READ 105
-#define PSF_WARNING_STREAM_PORT_WRITE 106
-
-/******************************************************************************/
-/*** INTERNAL STREAMING FUNCTIONS *********************************************/
-/******************************************************************************/
-
-/* Saves a symbol name (task name etc.) in symbol table */
-void prvTraceSaveSymbol(const void *address, const char *name);
-
-/* Deletes a symbol name (task name etc.) from symbol table */
-void prvTraceDeleteSymbol(void *address);
-
-/* Saves an object data entry (task base priority) in object data table */
-void prvTraceSaveObjectData(const void *address, uint32_t data);
-
-/* Removes an object data entry (task base priority) from object data table */
-void prvTraceDeleteObjectData(void *address);
-
-/* Store an event with zero parameters (event ID only) */
-void prvTraceStoreEvent0(uint16_t eventID);
-
-/* Store an event with one 32-bit parameter (pointer address or an int) */
-void prvTraceStoreEvent1(uint16_t eventID,
- uint32_t param1);
-
-/* Store an event with two 32-bit parameters */
-void prvTraceStoreEvent2(uint16_t eventID,
- uint32_t param1,
- uint32_t param2);
-
-/* Store an event with three 32-bit parameters */
-void prvTraceStoreEvent3(uint16_t eventID,
- uint32_t param1,
- uint32_t param2,
- uint32_t param3);
-
-/* Stores an event with 32-bit integer parameters */
-void prvTraceStoreEvent(int nParam, uint16_t EventID, ...);
-
-/* Stories an event with a string and 32-bit integer parameters */
-void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...);
-
-/* Initializes the paged event buffer used by certain stream ports */
-void prvPagedEventBufferInit(char* buffer);
-
-/* Retrieve a pointer to the paged event buffer */
-void* prvPagedEventBufferGetWritePointer(int sizeOfEvent);
-
-/* Transfer a full buffer page */
-uint32_t prvPagedEventBufferTransfer(void);
-
-/* The data structure for commands (a bit overkill) */
-typedef struct
-{
- unsigned char cmdCode;
- unsigned char param1;
- unsigned char param2;
- unsigned char param3;
- unsigned char param4;
- unsigned char param5;
- unsigned char checksumLSB;
- unsigned char checksumMSB;
-} TracealyzerCommandType;
-
-/* Checks if the provided command is a valid command */
-int prvIsValidCommand(TracealyzerCommandType* cmd);
-
-/* Executed the received command (Start or Stop) */
-void prvProcessCommand(TracealyzerCommandType* cmd);
-
-#define vTraceSetStopHook(x)
-
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
-
-#else /* when TRC_USE_TRACEALYZER_RECORDER == 0 */
-
-#define vTraceEnable(x)
-#define xTraceRegisterString(x) 0; (void)x;
-#define vTracePrint(chn, ...) (void)chn
-#define vTracePrintF(chn, ...) (void)chn
-#define vTraceInstanceFinishedNow()
-#define vTraceInstanceFinishedNext()
-#define vTraceStoreISRBegin(x) (void)x
-#define vTraceStoreISREnd(x) (void)x
-#define xTraceSetISRProperties(a, b) 0
-#define vTraceStoreKernelObjectName(a, b)
-#define xTraceRegisterChannelFormat(eventLabel, formatStr) 0
-#define vTraceChannelPrint(label)
-#define vTraceUBData(label, ...)
-
-#define vTraceSetFilterGroup(x)
-#define vTraceSetFilterMask(x)
-
-#define prvTraceSetReadyEventsEnabled(status)
-
-#define vTraceExcludeTask(handle)
-
-#define uiTraceStart() (1)
-#define vTraceStart()
-#define vTraceStop()
-
-#ifndef vTraceSetRecorderDataBuffer
-#define vTraceSetRecorderDataBuffer(pRecorderData)
-#endif
-
-#define vTraceConsoleChannelPrintF(fmt, ...)
-
-#ifndef TRC_ALLOC_CUSTOM_BUFFER
-#define TRC_ALLOC_CUSTOM_BUFFER(bufname)
-#endif
-
-#define xTraceIsRecordingEnabled() (0)
-
-#define vTraceSetStopHook(x)
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_RECORDER_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/ReadMe.url b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/ReadMe.url
deleted file mode 100755
index d12e889..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/ReadMe.url
+++ /dev/null
@@ -1,5 +0,0 @@
-[InternetShortcut]
-URL=http://www.freertos.org/trace
-IDList=
-[{000214A0-0000-0000-C000-000000000046}]
-Prop3=19,2
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcConfig.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcConfig.h
deleted file mode 100755
index 3f89326..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcConfig.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.4
- * Percepio AB, www.percepio.com
- *
- * trcConfig.h
- *
- * Main configuration parameters for the trace recorder library.
- * More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.
- *
- * Read more at http://percepio.com/2016/10/05/rtos-tracing/
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_CONFIG_H
-#define TRC_CONFIG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "trcPortDefines.h"
-
-/******************************************************************************
- * Include of processor header file
- *
- * Here you may need to include the header file for your processor. This is
- * required at least for the ARM Cortex-M port, that uses the ARM CMSIS API.
- * Try that in case of build problems. Otherwise, remove the #error line below.
- *****************************************************************************/
-#error "Trace Recorder: Please include your processor's header file here and remove this line."
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_HARDWARE_PORT
- *
- * Specify what hardware port to use (i.e., the "timestamping driver").
- *
- * All ARM Cortex-M MCUs are supported by "TRC_HARDWARE_PORT_ARM_Cortex_M".
- * This port uses the DWT cycle counter for Cortex-M3/M4/M7 devices, which is
- * available on most such devices. In case your device don't have DWT support,
- * you will get an error message opening the trace. In that case, you may
- * force the recorder to use SysTick timestamping instead, using this define:
- *
- * #define TRC_CFG_ARM_CM_USE_SYSTICK
- *
- * For ARM Cortex-M0/M0+ devices, SysTick mode is used automatically.
- *
- * See trcHardwarePort.h for available ports and information on how to
- * define your own port, if not already present.
- ******************************************************************************/
-#define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RECORDER_MODE
- *
- * Specify what recording mode to use. Snapshot means that the data is saved in
- * an internal RAM buffer, for later upload. Streaming means that the data is
- * transferred continuously to the host PC.
- *
- * For more information, see http://percepio.com/2016/10/05/rtos-tracing/
- * and the Tracealyzer User Manual.
- *
- * Values:
- * TRC_RECORDER_MODE_SNAPSHOT
- * TRC_RECORDER_MODE_STREAMING
- ******************************************************************************/
-#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT
-
-/******************************************************************************
- * TRC_CFG_FREERTOS_VERSION
- *
- * Specify what version of FreeRTOS that is used (don't change unless using the
- * trace recorder library with an older version of FreeRTOS).
- *
- * TRC_FREERTOS_VERSION_7_3 If using FreeRTOS v7.3.x
- * TRC_FREERTOS_VERSION_7_4 If using FreeRTOS v7.4.x
- * TRC_FREERTOS_VERSION_7_5_OR_7_6 If using FreeRTOS v7.5.0 - v7.6.0
- * TRC_FREERTOS_VERSION_8_X If using FreeRTOS v8.X.X
- * TRC_FREERTOS_VERSION_9_0_0 If using FreeRTOS v9.0.0
- * TRC_FREERTOS_VERSION_9_0_1 If using FreeRTOS v9.0.1
- * TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2
- * TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0 or later
- *****************************************************************************/
-#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_0_0
-
-/*******************************************************************************
- * TRC_CFG_SCHEDULING_ONLY
- *
- * Macro which should be defined as an integer value.
- *
- * If this setting is enabled (= 1), only scheduling events are recorded.
- * If disabled (= 0), all events are recorded (unless filtered in other ways).
- *
- * Default value is 0 (= include additional events).
- ******************************************************************************/
-#define TRC_CFG_SCHEDULING_ONLY 0
-
- /******************************************************************************
- * TRC_CFG_INCLUDE_MEMMANG_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * This controls if malloc and free calls should be traced. Set this to zero (0)
- * to exclude malloc/free calls, or one (1) to include such events in the trace.
- *
- * Default value is 1.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1
-
- /******************************************************************************
- * TRC_CFG_INCLUDE_USER_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), all code related to User Events is excluded in order
- * to reduce code size. Any attempts of storing User Events are then silently
- * ignored.
- *
- * User Events are application-generated events, like "printf" but for the
- * trace log, generated using vTracePrint and vTracePrintF.
- * The formatting is done on host-side, by Tracealyzer. User Events are
- * therefore much faster than a console printf and can often be used
- * in timing critical code without problems.
- *
- * Note: In streaming mode, User Events are used to provide error messages
- * and warnings from the recorder (in case of incorrect configuration) for
- * display in Tracealyzer. Disabling user events will also disable these
- * warnings. You can however still catch them by calling xTraceGetLastError
- * or by putting breakpoints in prvTraceError and prvTraceWarning.
- *
- * Default value is 1.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_USER_EVENTS 1
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_ISR_TRACING
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the code for recording Interrupt Service Routines is
- * excluded, in order to reduce code size.
- *
- * Default value is 1.
- *
- * Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin
- * and vTraceStoreISREnd in your interrupt handlers.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_ISR_TRACING 1
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_READY_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If one (1), events are recorded when tasks enter scheduling state "ready".
- * This allows Tracealyzer to show the initial pending time before tasks enter
- * the execution state, and present accurate response times.
- * If zero (0), "ready events" are not created, which allows for recording
- * longer traces in the same amount of RAM.
- *
- * Default value is 1.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_READY_EVENTS 1
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_OSTICK_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is one (1), events will be generated whenever the OS clock is
- * increased. If zero (0), OS tick events are not generated, which allows for
- * recording longer traces in the same amount of RAM.
- *
- * Default value is 1.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the trace will exclude any "event group" events.
- *
- * Default value is 0 (excluded) since dependent on event_groups.c
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 0
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_TIMER_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the trace will exclude any Timer events.
- *
- * Default value is 0 since dependent on timers.c
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_TIMER_EVENTS 0
-
- /*****************************************************************************
- * TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the trace will exclude any "pending function call"
- * events, such as xTimerPendFunctionCall().
- *
- * Default value is 0 since dependent on timers.c
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 0
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the trace will exclude any stream buffer or message
- * buffer events.
- *
- * Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
- ******************************************************************************/
-#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 0
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RECORDER_BUFFER_ALLOCATION
- *
- * Specifies how the recorder buffer is allocated (also in case of streaming, in
- * port using the recorder's internal temporary buffer)
- *
- * Values:
- * TRC_RECORDER_BUFFER_ALLOCATION_STATIC - Static allocation (internal)
- * TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC - Malloc in vTraceEnable
- * TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM - Use vTraceSetRecorderDataBuffer
- *
- * Static and dynamic mode does the allocation for you, either in compile time
- * (static) or in runtime (malloc).
- * The custom mode allows you to control how and where the allocation is made,
- * for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().
- ******************************************************************************/
-#define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC
-
-/******************************************************************************
- * TRC_CFG_MAX_ISR_NESTING
- *
- * Defines how many levels of interrupt nesting the recorder can handle, in
- * case multiple ISRs are traced and ISR nesting is possible. If this
- * is exceeded, the particular ISR will not be traced and the recorder then
- * logs an error message. This setting is used to allocate an internal stack
- * for keeping track of the previous execution context (4 byte per entry).
- *
- * This value must be a non-zero positive constant, at least 1.
- *
- * Default value: 8
- *****************************************************************************/
-#define TRC_CFG_MAX_ISR_NESTING 8
-
-/* Specific configuration, depending on Streaming/Snapshot mode */
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-#include "trcSnapshotConfig.h"
-#elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-#include "trcStreamingConfig.h"
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TRC_CONFIG_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcSnapshotConfig.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcSnapshotConfig.h
deleted file mode 100755
index ba9078c..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcSnapshotConfig.h
+++ /dev/null
@@ -1,377 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.4
- * Percepio AB, www.percepio.com
- *
- * trcSnapshotConfig.h
- *
- * Configuration parameters for trace recorder library in snapshot mode.
- * Read more at http://percepio.com/2016/10/05/rtos-tracing/
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_SNAPSHOT_CONFIG_H
-#define TRC_SNAPSHOT_CONFIG_H
-
-#define TRC_SNAPSHOT_MODE_RING_BUFFER (0x01)
-#define TRC_SNAPSHOT_MODE_STOP_WHEN_FULL (0x02)
-
-/******************************************************************************
- * TRC_CFG_SNAPSHOT_MODE
- *
- * Macro which should be defined as one of:
- * - TRC_SNAPSHOT_MODE_RING_BUFFER
- * - TRC_SNAPSHOT_MODE_STOP_WHEN_FULL
- * Default is TRC_SNAPSHOT_MODE_RING_BUFFER.
- *
- * With TRC_CFG_SNAPSHOT_MODE set to TRC_SNAPSHOT_MODE_RING_BUFFER, the
- * events are stored in a ring buffer, i.e., where the oldest events are
- * overwritten when the buffer becomes full. This allows you to get the last
- * events leading up to an interesting state, e.g., an error, without having
- * to store the whole run since startup.
- *
- * When TRC_CFG_SNAPSHOT_MODE is TRC_SNAPSHOT_MODE_STOP_WHEN_FULL, the
- * recording is stopped when the buffer becomes full. This is useful for
- * recording events following a specific state, e.g., the startup sequence.
- *****************************************************************************/
-#define TRC_CFG_SNAPSHOT_MODE TRC_SNAPSHOT_MODE_RING_BUFFER
-
-/*******************************************************************************
- * TRC_CFG_EVENT_BUFFER_SIZE
- *
- * Macro which should be defined as an integer value.
- *
- * This defines the capacity of the event buffer, i.e., the number of records
- * it may store. Most events use one record (4 byte), although some events
- * require multiple 4-byte records. You should adjust this to the amount of RAM
- * available in the target system.
- *
- * Default value is 1000, which means that 4000 bytes is allocated for the
- * event buffer.
- ******************************************************************************/
-#define TRC_CFG_EVENT_BUFFER_SIZE 1000
-
-/*******************************************************************************
- * TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...
- *
- * A group of macros which should be defined as integer values, zero or larger.
- *
- * These define the capacity of the Object Property Table, i.e., the maximum
- * number of objects active at any given point, within each object class (e.g.,
- * task, queue, semaphore, ...).
- *
- * If tasks or other objects are deleted in your system, this
- * setting does not limit the total amount of objects created, only the number
- * of objects that have been successfully created but not yet deleted.
- *
- * Using too small values will cause vTraceError to be called, which stores an
- * error message in the trace that is shown when opening the trace file. The
- * error message can also be retrieved using xTraceGetLastError.
- *
- * It can be wise to start with large values for these constants,
- * unless you are very confident on these numbers. Then do a recording and
- * check the actual usage by selecting View menu -> Trace Details ->
- * Resource Usage -> Object Table.
- ******************************************************************************/
-#define TRC_CFG_NTASK 15
-#define TRC_CFG_NISR 5
-#define TRC_CFG_NQUEUE 10
-#define TRC_CFG_NSEMAPHORE 10
-#define TRC_CFG_NMUTEX 10
-#define TRC_CFG_NTIMER 5
-#define TRC_CFG_NEVENTGROUP 5
-#define TRC_CFG_NSTREAMBUFFER 5
-#define TRC_CFG_NMESSAGEBUFFER 5
-
-/******************************************************************************
- * TRC_CFG_INCLUDE_FLOAT_SUPPORT
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If this is zero (0), the support for logging floating point values in
- * vTracePrintF is stripped out, in case floating point values are not used or
- * supported by the platform used.
- *
- * Floating point values are only used in vTracePrintF and its subroutines, to
- * allow for storing float (%f) or double (%lf) arguments.
- *
- * vTracePrintF can be used with integer and string arguments in either case.
- *
- * Default value is 0.
- *****************************************************************************/
-#define TRC_CFG_INCLUDE_FLOAT_SUPPORT 0
-
-/*******************************************************************************
- * TRC_CFG_SYMBOL_TABLE_SIZE
- *
- * Macro which should be defined as an integer value.
- *
- * This defines the capacity of the symbol table, in bytes. This symbol table
- * stores User Events labels and names of deleted tasks, queues, or other kernel
- * objects. If you don't use User Events or delete any kernel
- * objects you set this to a very low value. The minimum recommended value is 4.
- * A size of zero (0) is not allowed since a zero-sized array may result in a
- * 32-bit pointer, i.e., using 4 bytes rather than 0.
- *
- * Default value is 800.
- ******************************************************************************/
-#define TRC_CFG_SYMBOL_TABLE_SIZE 800
-
-#if (TRC_CFG_SYMBOL_TABLE_SIZE == 0)
-#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"
-#endif
-
-/******************************************************************************
- * TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...
- *
- * Macros that specify the maximum lengths (number of characters) for names of
- * kernel objects, such as tasks and queues. If longer names are used, they will
- * be truncated when stored in the recorder.
- *****************************************************************************/
-#define TRC_CFG_NAME_LEN_TASK 15
-#define TRC_CFG_NAME_LEN_ISR 15
-#define TRC_CFG_NAME_LEN_QUEUE 15
-#define TRC_CFG_NAME_LEN_SEMAPHORE 15
-#define TRC_CFG_NAME_LEN_MUTEX 15
-#define TRC_CFG_NAME_LEN_TIMER 15
-#define TRC_CFG_NAME_LEN_EVENTGROUP 15
-#define TRC_CFG_NAME_LEN_STREAMBUFFER 15
-#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 15
-
-/******************************************************************************
- *** ADVANCED SETTINGS ********************************************************
- ******************************************************************************
- * The remaining settings are not necessary to modify but allows for optimizing
- * the recorder setup for your specific needs, e.g., to exclude events that you
- * are not interested in, in order to get longer traces.
- *****************************************************************************/
-
-/******************************************************************************
-* TRC_CFG_HEAP_SIZE_BELOW_16M
-*
-* An integer constant that can be used to reduce the buffer usage of memory
-* allocation events (malloc/free). This value should be 1 if the heap size is
-* below 16 MB (2^24 byte), and you can live with reported addresses showing the
-* lower 24 bits only. If 0, you get the full 32-bit addresses.
-*
-* Default value is 0.
-******************************************************************************/
-#define TRC_CFG_HEAP_SIZE_BELOW_16M 0
-
-/******************************************************************************
- * TRC_CFG_USE_IMPLICIT_IFE_RULES
- *
- * Macro which should be defined as either zero (0) or one (1).
- * Default is 1.
- *
- * Tracealyzer groups the events into "instances" based on Instance Finish
- * Events (IFEs), produced either by default rules or calls to the recorder
- * functions vTraceInstanceFinishedNow and vTraceInstanceFinishedNext.
- *
- * If TRC_CFG_USE_IMPLICIT_IFE_RULES is one (1), the default IFE rules is
- * used, resulting in a "typical" grouping of events into instances.
- * If these rules don't give appropriate instances in your case, you can
- * override the default rules using vTraceInstanceFinishedNow/Next for one
- * or several tasks. The default IFE rules are then disabled for those tasks.
- *
- * If TRC_CFG_USE_IMPLICIT_IFE_RULES is zero (0), the implicit IFE rules are
- * disabled globally. You must then call vTraceInstanceFinishedNow or
- * vTraceInstanceFinishedNext to manually group the events into instances,
- * otherwise the tasks will appear a single long instance.
- *
- * The default IFE rules count the following events as "instance finished":
- * - Task delay, delay until
- * - Task suspend
- * - Blocking on "input" operations, i.e., when the task is waiting for the
- * next a message/signal/event. But only if this event is blocking.
- *
- * For details, see trcSnapshotKernelPort.h and look for references to the
- * macro trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED.
- *****************************************************************************/
-#define TRC_CFG_USE_IMPLICIT_IFE_RULES 1
-
-/******************************************************************************
- * TRC_CFG_USE_16BIT_OBJECT_HANDLES
- *
- * Macro which should be defined as either zero (0) or one (1).
- *
- * If set to 0 (zero), the recorder uses 8-bit handles to identify kernel
- * objects such as tasks and queues. This limits the supported number of
- * concurrently active objects to 255 of each type (tasks, queues, mutexes,
- * etc.) Note: 255, not 256, since handle 0 is reserved.
- *
- * If set to 1 (one), the recorder uses 16-bit handles to identify kernel
- * objects such as tasks and queues. This limits the supported number of
- * concurrent objects to 65535 of each type (object class). However, since the
- * object property table is limited to 64 KB, the practical limit is about
- * 3000 objects in total.
- *
- * Default is 0 (8-bit handles)
- *
- * NOTE: An object with handle above 255 will use an extra 4-byte record in
- * the event buffer whenever the object is referenced. Moreover, some internal
- * tables in the recorder gets slightly larger when using 16-bit handles.
- *****************************************************************************/
-#define TRC_CFG_USE_16BIT_OBJECT_HANDLES 0
-
-/******************************************************************************
- * TRC_CFG_USE_TRACE_ASSERT
- *
- * Macro which should be defined as either zero (0) or one (1).
- * Default is 1.
- *
- * If this is one (1), the TRACE_ASSERT macro (used at various locations in the
- * trace recorder) will verify that a relevant condition is true.
- * If the condition is false, prvTraceError() will be called, which stops the
- * recording and stores an error message that is displayed when opening the
- * trace in Tracealyzer.
- *
- * This is used on several places in the recorder code for sanity checks on
- * parameters. Can be switched off to reduce the footprint of the tracing, but
- * we recommend to have it enabled initially.
- *****************************************************************************/
-#define TRC_CFG_USE_TRACE_ASSERT 1
-
-/*******************************************************************************
- * TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER
- *
- * Macro which should be defined as an integer value.
- *
- * Set TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER to 1 to enable the
- * separate user event buffer (UB).
- * In this mode, user events are stored separately from other events,
- * e.g., RTOS events. Thereby you can get a much longer history of
- * user events as they don't need to share the buffer space with more
- * frequent events.
- *
- * The UB is typically used with the snapshot ring-buffer mode, so the
- * recording can continue when the main buffer gets full. And since the
- * main buffer then overwrites the earliest events, Tracealyzer displays
- * "Unknown Actor" instead of task scheduling for periods with UB data only.
- *
- * In UB mode, user events are structured as UB channels, which contains
- * a channel name and a default format string. Register a UB channel using
- * xTraceRegisterUBChannel.
- *
- * Events and data arguments are written using vTraceUBEvent and
- * vTraceUBData. They are designed to provide efficient logging of
- * repeating events, using the same format string within each channel.
- *
- * Examples:
- *
- * traceString chn1 = xTraceRegisterString("Channel 1");
- * traceString fmt1 = xTraceRegisterString("Event!");
- * traceUBChannel UBCh1 = xTraceRegisterUBChannel(chn1, fmt1);
- *
- * traceString chn2 = xTraceRegisterString("Channel 2");
- * traceString fmt2 = xTraceRegisterString("X: %d, Y: %d");
- * traceUBChannel UBCh2 = xTraceRegisterUBChannel(chn2, fmt2);
- *
- * // Result in "[Channel 1] Event!"
- * vTraceUBEvent(UBCh1);
- *
- * // Result in "[Channel 2] X: 23, Y: 19"
- * vTraceUBData(UBCh2, 23, 19);
- *
- * You can also use the other user event functions, like vTracePrintF.
- * as they are then rerouted to the UB instead of the main event buffer.
- * vTracePrintF then looks up the correct UB channel based on the
- * provided channel name and format string, or creates a new UB channel
- * if no match is found. The format string should therefore not contain
- * "random" messages but mainly format specifiers. Random strings should
- * be stored using %s and with the string as an argument.
- *
- * // Creates a new UB channel ("Channel 2", "%Z: %d")
- * vTracePrintF(chn2, "%Z: %d", value1);
- *
- * // Finds the existing UB channel
- * vTracePrintF(chn2, "%Z: %d", value2);
-
- ******************************************************************************/
-#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0
-
-/*******************************************************************************
- * TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE
- *
- * Macro which should be defined as an integer value.
- *
- * This defines the capacity of the user event buffer (UB), in number of slots.
- * A single user event can use multiple slots, depending on the arguments.
- *
- * Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.
- ******************************************************************************/
-#define TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE 200
-
-/*******************************************************************************
- * TRC_CFG_UB_CHANNELS
- *
- * Macro which should be defined as an integer value.
- *
- * This defines the number of User Event Buffer Channels (UB channels).
- * These are used to structure the events when using the separate user
- * event buffer, and contains both a User Event Channel (the name) and
- * a default format string for the channel.
- *
- * Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.
- ******************************************************************************/
-#define TRC_CFG_UB_CHANNELS 32
-
-/*******************************************************************************
- * TRC_CFG_ISR_TAILCHAINING_THRESHOLD
- *
- * Macro which should be defined as an integer value.
- *
- * If tracing multiple ISRs, this setting allows for accurate display of the
- * context-switching also in cases when the ISRs execute in direct sequence.
- *
- * vTraceStoreISREnd normally assumes that the ISR returns to the previous
- * context, i.e., a task or a preempted ISR. But if another traced ISR
- * executes in direct sequence, Tracealyzer may incorrectly display a minimal
- * fragment of the previous context in between the ISRs.
- *
- * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
- * however a threshold value that must be measured for your specific setup.
- * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
- *
- * The default setting is 0, meaning "disabled" and that you may get an
- * extra fragments of the previous context in between tail-chained ISRs.
- *
- * Note: This setting has separate definitions in trcSnapshotConfig.h and
- * trcStreamingConfig.h, since it is affected by the recorder mode.
- ******************************************************************************/
-#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
-
-#endif /*TRC_SNAPSHOT_CONFIG_H*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcStreamingConfig.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcStreamingConfig.h
deleted file mode 100755
index d3d088a..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/config/trcStreamingConfig.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.4
- * Percepio AB, www.percepio.com
- *
- * trcStreamingConfig.h
- *
- * Configuration parameters for the trace recorder library in streaming mode.
- * Read more at http://percepio.com/2016/10/05/rtos-tracing/
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_CONFIG_H
-#define TRC_STREAMING_CONFIG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_SYMBOL_TABLE_SLOTS
- *
- * The maximum number of symbols names that can be stored. This includes:
- * - Task names
- * - Named ISRs (vTraceSetISRProperties)
- * - Named kernel objects (vTraceStoreKernelObjectName)
- * - User event channels (xTraceRegisterString)
- *
- * If this value is too small, not all symbol names will be stored and the
- * trace display will be affected. In that case, there will be warnings
- * (as User Events) from TzCtrl task, that monitors this.
- ******************************************************************************/
-#define TRC_CFG_SYMBOL_TABLE_SLOTS 40
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_SYMBOL_MAX_LENGTH
- *
- * The maximum length of symbol names, including:
- * - Task names
- * - Named ISRs (vTraceSetISRProperties)
- * - Named kernel objects (vTraceStoreKernelObjectName)
- * - User event channel names (xTraceRegisterString)
- *
- * If longer symbol names are used, they will be truncated by the recorder,
- * which will affect the trace display. In that case, there will be warnings
- * (as User Events) from TzCtrl task, that monitors this.
- ******************************************************************************/
-#define TRC_CFG_SYMBOL_MAX_LENGTH 25
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_OBJECT_DATA_SLOTS
- *
- * The maximum number of object data entries (used for task priorities) that can
- * be stored at the same time. Must be sufficient for all tasks, otherwise there
- * will be warnings (as User Events) from TzCtrl task, that monitors this.
- ******************************************************************************/
-#define TRC_CFG_OBJECT_DATA_SLOTS 40
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_CTRL_TASK_STACK_SIZE
- *
- * The stack size of the TzCtrl task, that receive commands.
- * We are aiming to remove this extra task in future versions.
- ******************************************************************************/
-#define TRC_CFG_CTRL_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE * 2)
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_CTRL_TASK_PRIORITY
- *
- * The priority of the TzCtrl task, that receive commands from Tracealyzer.
- * Most stream ports also rely on the TzCtrl task to transmit the data from the
- * internal buffer to the stream interface (all except for the J-Link port).
- * For such ports, make sure the TzCtrl priority is high enough to ensure
- * reliable periodic execution and transfer of the data.
- ******************************************************************************/
-#define TRC_CFG_CTRL_TASK_PRIORITY 1
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_CTRL_TASK_DELAY
- *
- * The delay between every loop of the TzCtrl task. A high delay will reduce the
- * CPU load, but may cause missed events if the TzCtrl task is performing the
- * trace transfer.
- ******************************************************************************/
-#define TRC_CFG_CTRL_TASK_DELAY ((10 * configTICK_RATE_HZ) / 1000)
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT
- *
- * Specifies the number of pages used by the paged event buffer.
- * This may need to be increased if there are a lot of missed events.
- *
- * Note: not used by the J-Link RTT stream port (see trcStreamingPort.h instead)
- ******************************************************************************/
-#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT 2
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE
- *
- * Specifies the size of each page in the paged event buffer. This can be tuned
- * to match any internal low-level buffers used by the streaming interface, like
- * the Ethernet MTU (Maximum Transmission Unit).
- *
- * Note: not used by the J-Link RTT stream port (see trcStreamingPort.h instead)
- ******************************************************************************/
-#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE 2500
-
-/*******************************************************************************
- * TRC_CFG_ISR_TAILCHAINING_THRESHOLD
- *
- * Macro which should be defined as an integer value.
- *
- * If tracing multiple ISRs, this setting allows for accurate display of the
- * context-switching also in cases when the ISRs execute in direct sequence.
- *
- * vTraceStoreISREnd normally assumes that the ISR returns to the previous
- * context, i.e., a task or a preempted ISR. But if another traced ISR
- * executes in direct sequence, Tracealyzer may incorrectly display a minimal
- * fragment of the previous context in between the ISRs.
- *
- * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
- * however a threshold value that must be measured for your specific setup.
- * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
- *
- * The default setting is 0, meaning "disabled" and that you may get an
- * extra fragments of the previous context in between tail-chained ISRs.
- *
- * Note: This setting has separate definitions in trcSnapshotConfig.h and
- * trcStreamingConfig.h, since it is affected by the recorder mode.
- ******************************************************************************/
-#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_CONFIG_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/readme.txt
deleted file mode 100755
index 668e01c..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/readme.txt
+++ /dev/null
@@ -1,152 +0,0 @@
--------------------------------------------------------------------------------
- Tracealyzer for FreeRTOS - Trace Recorder Library v3.1.1
--------------------------------------------------------------------------------
-
-Tracealyzer for FreeRTOS is a sophisticated tool for tracing and visualization
-of FreeRTOS-based systems. Tracealyzer gives an unprecedented insight into the
-runtime behavior, which speeds up debugging, validation and optimization.
-
-To learn more about this, see
-
- - Getting Started (videos etc): http://percepio.com/gettingstarted/tz-freertos/
-
- - User Manual (incl. Recorder API): http://percepio.com/docs/FreeRTOS/manual
-
- - FAQ: http://percepio.com/category/faq/
-
-In case you have any questions, don't hesitate to contact support@percepio.com
-
--------------------------------------------------------------------------------
-
-Changes, v3.1.1 -> v3.1.2
-
-- Fixed two bugs related to User Events, one in vTracePrintF and other in vTracePrint.
-
-- Fixed a build problem related to a single reference of the old FreeRTOS type "xTaskHandle", in trcKernelPort.c.
- Changed to "TaskHandle_t", unless if using an older FreeRTOS kernel or the "compatibility mode".
-
-- Removed traceCREATE_MUTEX hook for FreeRTOS v9 or later (no longer required)
-
-- Updated the User Manual regarding snapshot trace via IAR Embedded Workbench.
-
-- Renamed vTraceGetTraceBuffer to xTraceGetTraceBuffer, since returning a pointer.
-
--------------------------------------------------------------------------------
-
-Changes, v3.1.0 -> v3.1.1
-
-After the major changes in the v3.1.0 trace recorder library, this update
-corrects a number of minor issues. Only minor functional improvements.
-
-- You can now use TRC_ALLOC_CUSTOM_BUFFER to declare a trace buffer on a custom
- location (using linker directives).
- The related function vTraceSetRecorderDataBuffer has been promoted to the
- Common API (previously only supported in snapshot mode, but custom allocation
- is now generally supported also in streaming mode).
-
-- Removed TRC_CFG_USE_LINKER_PRAGMA. No longer necessary thanks to the custom
- allocation mode.
-
-- Added support for timestamping from custom periodic timers, required for
- accurate timestamping on Cortex-M0/M0+ devices when using tickless idle.
- Only for streaming mode so far. See TRC_CUSTOM_TIMER_INCR / DECR.
-
-- ARM Cortex-M port: Made sure the DWT unit is initialized properly, in case
- the debugger doesn't handle this.
-
-- ARM Cortex-M port: Added possibility to use Systick timestamping also on
- Cortex-M3/M4/M7 devices (that otherwise use DWT timestamping by default).
- To use this option, define the macro TRC_CFG_ARM_CM_USE_SYSTICK.
-
-- J-Link streaming: The default RTT buffer has been changed from 0 to 1.
-
-- J-Link streaming: The RTT buffer settings for buffer 1 and higher, are now
- found in trcStreamingPort.h. Note: These settings don't apply to buffer 0.
-
-- vTracePrint has been optimized for better performance in string logging.
-
-- Minor performance improvement related to symbol table transfer in streaming mode.
-
-- Timer names now registered also in streaming mode.
-
-- Timer start and stop event are now traced.
-
-- Implemented support for queue registry (traceQUEUE_REGISTRY_ADD) also for streaming.
-
-- Fixed a bug related to repeated calls of vTraceEnable.
-
-- Fixed a bug where task-switches seemed to occur even though the scheduler was disabled.
-
-- Renamed HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48, added prefix TRC.
-
-- Fixed several language issues in the comments and documentation.
-
-- Fixed several minor issues and warnings from different compilers
- (including PowerPC/gcc) and configurations.
-
--------------------------------------------------------------------------------
-
-Changes, v3.0.9 -> v3.1.0
-
-- Merge of previously separated snapshot and streaming recorders into a single
- recorder supporting both streaming and snapshot as different modes.
-
-- New common API for supporting both streaming and snapshot modes.
-
-- New integration guide, see the User Manual.
-
-- Major improvement of API documentation in source files and User Manual.
-
-- New concept of "stream ports", giving a better structure defining streaming
- interfaces, and restructured the J-Link and TCP/IP streaming as stream ports.
-
-- Added a stream port for USB CDC connections, with STM32 as example.
- Since Tracealyzer now can receive serial data on Windows COM ports, this is
- really easy to use.
-
-- Added a warning (#error) for cases where FreeRTOS tickless idle mode is used
- together with timestamping using SysTick or other periodic interrupt timers,
- Tracing with tickless idle requires an independent time source to correctly
- capture the length of the idle periods.
-
-- Major changes in the recorder API. Important examples are:
-
- * Some configuration macros have changed names, e.g. for "hardware port".
- Make sure to remove any old "trcConfig.h" files if upgrading from an
- earlier version!
-
- * Recorder configuration in trcConfig.h has been minimized and now only
- includes the important settings that are independent of recorder mode.
- Advanced settings for each mode are found in trcSnapshotConfig.h and
- trcStreamingConfig.h.
-
- * vTraceEnable replaces Trace_Init and vTraceInitTraceData, as well as
- vTraceStart and uiTraceStart.
-
- * vTraceStop now part of the common API and thereby available also in
- streaming. And since vTraceEnable can start the streaming directly
- you have the option control the tracing from target, e.g., for
- streaming to a device file system.
-
- * vTraceStoreKernelObjectName from old streaming recorder has been replaced
- by vTraceSetQueueName, vTraceSetSemaphoreName, etc.
-
- * vTraceSetISRProperties now returns a "traceHandle" that should be passed as
- parameter to vTraceStoreISRBegin and vTraceStoreISREnd.
-
- * xTraceRegisterString has replaced the old functions xTraceOpenLabel and
- vTraceStoreUserEventChannelName. This now returns a "traceString" for use
- as "channel" parameter in vTracePrintF, and in other places where strings
- are stored.
-
- * Removed vTraceStoreISREndManual and vTraceStoreISREndAuto, use
- vTraceStoreISREnd instead.
-
- * Renamed the functions for saving User Events in a separate buffer:
- - xTraceRegisterChannelFormat -> xTraceRegisterUBChannel
- - vTraceChannelPrintF -> vTraceUBData
- - vTraceChannelUserEvent -> vTraceUBEvent
-
-
--------------------------------------------------------------------------------
-Copyright Percepio AB, 2017.
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Keil-uVision-Tracealyzer-ITM-Exporter.ini b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Keil-uVision-Tracealyzer-ITM-Exporter.ini
deleted file mode 100755
index c1dd7fc..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Keil-uVision-Tracealyzer-ITM-Exporter.ini
+++ /dev/null
@@ -1,52 +0,0 @@
-/************************************************************
-* Percepio Tracealyzer - ITM Trace Exporter for Keil uVision
-* Copyright (c) 2018, Percepio AB.
-* https://percepio.com
-************************************************************/
-
-FUNC void tzSetEnable(int enable)
-{
- if (enable == 1)
- {
- printf("Starting Tracealyzer recorder\n");
-
- // Forward the ITM data to file
- exec("ITMLOG 1 > .\\tracealyzer.psf");
-
- // Send start command to Tracealyzer (not required if using vTraceEnable(TRC_START))
- exec("E CHAR tz_host_command_data = 1, 1, 0, 0, 0, 0, 0xFD, 0xFF");
- exec("tz_host_command_bytes_to_read = 8");
- }
- else if (enable == 0)
- {
- printf("Stopping Tracealyzer recorder...\n");
-
- // Send stop command to Tracealyzer, to stop writing ITM data.
- exec("E CHAR tz_host_command_data = 1, 0, 0, 0, 0, 0, 0xFE, 0xFF");
- exec("tz_host_command_bytes_to_read = 8");
-
- _sleep_(2000); // Wait a while to let all data be written the host file.
-
- // Stop forwarding the ITM data to file and close the file.
- exec("ITMLOG 1 OFF");
-
- printf("Tracealyzer recorder stopped.\n");
-
- }
- else printf("Usage: tzSetEnable(0 or 1), where 0 is disable (stops recorder) and 1 enable (starts recording)");
-
-}
-
-
-// The Tracealyzer ITM stream port for Keil µVision can be used in two ways.
-//
-// 1. Start tracing directly from startup.
-// Make sure tzSetEnable(1) is called below and vTraceEnable(TRC_START) in your target startup.
-//
-// 2. Start the trace manually, using the "Start Recording" button in Keil µVision.
-// In this case, comment out the below call to tzSetEnable and make sure you call vTraceEnable(TRC_INIT) in your target startup (not TRC_START).
-
-tzSetEnable(1);
-
-DEFINE BUTTON "Start Recording", "tzSetEnable(1)";
-DEFINE BUTTON "Stop Recording", "tzSetEnable(0)";
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Readme-ARM_ITM.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Readme-ARM_ITM.txt
deleted file mode 100755
index f0000ad..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/Readme-ARM_ITM.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-Tracealyzer Stream Port for ARM Cortex-M ITM
---------------------------------------------
-2018-05-04
-
-This directory contains a "stream port" for the Tracealyzer recorder library,
-i.e., the specific code needed to use a particular interface for streaming a
-Tracealyzer RTOS trace. The stream port is defined by a set of macros in
-trcStreamingPort.h, found in the "include" directory.
-
-This particular stream port targets ARM's ITM interface, which together with
-a fast debug probe such as a Keil ULINKpro or ULINKplus provides excellent
-performance. This stream port does not use any RAM buffer for the trace, but
-writes the data directly to the ITM registers. This is very fast.
-
-To setup Keil uVision for ITM tracing with a Keil ULINKpro (or ULINKplus),
-see Percepio Application Note PA-021 https://percepio.com/2018/05/04/keil-itm-support/
-
-Learning more:
- - Tracealyzer User Manual (Help -> User Manual)
- - https://percepio.com/gettingstarted
- - Percepio Application Note PA-021 https://percepio.com/2018/05/04/keil-itm-support/
- - About ITM trace, https://percepio.com/2016/06/09/arm-itm/
- - About the recorder and custom streaming, http://percepio.com/2016/10/05/rtos-tracing
-
-For questions, please contact support@percepio.com
-
-Percepio AB
-www.percepio.com
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/include/trcStreamingPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/include/trcStreamingPort.h
deleted file mode 100755
index f68d152..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/include/trcStreamingPort.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.h
- *
- * The interface definitions for trace streaming ("stream ports").
- * This "stream port" sets up the recorder to use ARM ITM as streaming channel.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_PORT_H
-#define TRC_STREAMING_PORT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-int32_t itm_write(void* ptrData, uint32_t size, int32_t* ptrBytesWritten);
-int32_t read_from_host(void* ptrData, uint32_t size, int32_t* ptrBytesRead);
-
-/*******************************************************************************
- * TRC_CFG_ITM_PORT
- *
- * Possible values: 0 - 31
- *
- * What ITM port to use for the ITM software events. Make sure the IDE is
- * configured for the same channel.
- *
- * Default: 1 (0 is typically terminal output and 31 is used by Keil)
- *
- ******************************************************************************/
-#define TRC_CFG_ITM_PORT 1
-
-#if (TRC_CFG_ITM_PORT < 0) || (TRC_CFG_ITM_PORT > 31)
-#error "Bad ITM port selected."
-#endif
-
-// Not used for ITM - no RAM buffer...
-#define TRC_STREAM_PORT_ALLOCATE_FIELDS()
-
-// Not used for ITM - assume the IDE configures the ITM setup
-#define TRC_STREAM_PORT_INIT()
-
-/* Important for the ITM port - no RAM buffer, direct writes. In most other ports this can be skipped (default is 1) */
-#define TRC_STREAM_PORT_USE_INTERNAL_BUFFER 0
-
-#define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesWritten) itm_write(_ptrData, _size, _ptrBytesWritten)
-
-#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) read_from_host(_ptrData, _size, _ptrBytesRead)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/trcStreamingPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/trcStreamingPort.c
deleted file mode 100755
index 667e642..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/ARM_ITM/trcStreamingPort.c
+++ /dev/null
@@ -1,71 +0,0 @@
-
-#include "trcRecorder.h"
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-static void itm_write_32(uint32_t data);
-
-volatile int32_t tz_host_command_bytes_to_read = 0; // This is set by the Tracealyzer host application (to the number of bytes written), after having written to tz_host_commands. Set to zero by the read function after the message in tz_host_commands has been read.
-volatile char tz_host_command_data[32];
-
-/* This reads "command" data from a RAM buffer, written by a host macro in the debugger */
-int32_t read_from_host(void* ptrData, uint32_t size, int32_t* ptrBytesRead)
-{
- if ( tz_host_command_bytes_to_read > 0)
- {
- int i;
- uint8_t * bytesBuffer = (uint8_t*) ptrData;
-
- if (ptrBytesRead != NULL)
- *ptrBytesRead = (int32_t)tz_host_command_bytes_to_read;
-
- if (tz_host_command_bytes_to_read != size)
- {
- return -1;
- }
-
- for (i=0; i < tz_host_command_bytes_to_read; i++)
- {
- bytesBuffer[i] = tz_host_command_data[i];
- }
-
- tz_host_command_bytes_to_read = 0;
- }
-
- return 0;
-}
-
-static void itm_write_32(uint32_t data)
-{
- if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && // Trace enabled
- (ITM->TCR & ITM_TCR_ITMENA_Msk) && // ITM enabled
- (ITM->TER & (1UL << TRC_CFG_ITM_PORT))) // ITM port enabled
- {
- while (ITM->PORT[TRC_CFG_ITM_PORT].u32 == 0); // Block until room in ITM FIFO - This stream port is always in "blocking mode", since intended for high-speed ITM!
- ITM->PORT[TRC_CFG_ITM_PORT].u32 = data; // Write the data
- }
-}
-
-/* This is assumed to execute from within the recorder, with interrupts disabled */
-int32_t itm_write(void* ptrData, uint32_t size, int32_t* ptrBytesWritten)
-{
- uint32_t bytesWritten = 0;
- uint32_t* ptr32 = (uint32_t*)ptrData;
-
- if (size % 4 != 0) return -2;
-
- while(bytesWritten < size)
- {
- itm_write_32(*ptr32);
- ptr32++;
- bytesWritten += 4;
- }
-
- *ptrBytesWritten = bytesWritten;
-
- return 0;
-}
-
-#endif
-#endif
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/Readme-Streamport.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/Readme-Streamport.txt
deleted file mode 100755
index c88517e..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/Readme-Streamport.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-Tracealyzer Stream Port for Files
--------------------------------------------------
-
-This directory contains a "stream port" for the Tracealyzer recorder library,
-i.e., the specific code needed to use a particular interface for streaming a
-Tracealyzer RTOS trace. The stream port is defined by a set of macros in
-trcStreamingPort.h, found in the "include" directory.
-
-This particular stream port is for streaming to a file via stdio.h (fwrite).
-
-To use this stream port, make sure that include/trcStreamingPort.h is found
-by the compiler (i.e., add this folder to your project's include paths) and
-add all included source files to your build. Make sure no other versions of
-trcStreamingPort.h are included by mistake!
-
-See also http://percepio.com/2016/10/05/rtos-tracing.
-
-Percepio AB
-www.percepio.com
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/include/trcStreamingPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/include/trcStreamingPort.h
deleted file mode 100755
index e202159..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/include/trcStreamingPort.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.h
- *
- * The interface definitions for trace streaming ("stream ports").
- * This "stream port" sets up the recorder to stream the trace to file.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_PORT_H
-#define TRC_STREAMING_PORT_H
-
-#include
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t writeToFile(void* data, uint32_t size, int32_t *ptrBytesWritten);
-
-void closeFile(void);
-
-void openFile(char* fileName);
-
-/* This define will determine whether to use the internal PagedEventBuffer or not.
-If file writing creates additional trace events (i.e. it uses semaphores or mutexes),
-then the paged event buffer must be enabled to avoid infinite recursion. */
-#define TRC_STREAM_PORT_USE_INTERNAL_BUFFER 1
-
-#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) 0 /* Does not read commands from Tz (yet) */
-
-#define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesSent) writeToFile(_ptrData, _size, _ptrBytesSent)
-
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)
-#define TRC_STREAM_PORT_MALLOC() \
- _TzTraceData = TRC_PORT_MALLOC((TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE));
-extern char* _TzTraceData;
-#else
-#define TRC_STREAM_PORT_MALLOC() /* Custom or static allocation. Not used. */
-#endif
-#define TRC_STREAM_PORT_INIT() \
- TRC_STREAM_PORT_MALLOC(); \
- openFile("trace.psf")
-
-#define TRC_STREAM_PORT_ON_TRACE_END() closeFile()
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c
deleted file mode 100755
index 09a388d..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.c
- *
- * Supporting functions for trace streaming, used by the "stream ports"
- * for reading and writing data to the interface.
- * Existing ports can easily be modified to fit another setup, e.g., a
- * different TCP/IP stack, or to define your own stream port.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#include "trcRecorder.h"
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-FILE* traceFile = NULL;
-
-void openFile(char* fileName)
-{
- if (traceFile == NULL)
- {
- errno_t err = fopen_s(&traceFile, fileName, "wb");
- if (err != 0)
- {
- printf("Could not open trace file, error code %d.\n", err);
- exit(-1);
- }
- else {
- printf("Trace file created.\n");
- }
- }
-}
-
-int32_t writeToFile(void* data, uint32_t size, int32_t *ptrBytesWritten)
-{
- int32_t written = 0;
- if (traceFile != NULL)
- {
- written = fwrite(data, 1, size, traceFile);
- }
- else
- {
- written = 0;
- }
-
- if (ptrBytesWritten != 0)
- *ptrBytesWritten = written;
-
- if ((int32_t)size == written)
- return 0;
- else
- return -1;
-}
-
-void closeFile(void)
-{
- if (traceFile != NULL)
- {
- fclose(traceFile);
- traceFile = NULL;
- printf("Trace file closed.\n");
- }
-}
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/Readme-Streamport.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/Readme-Streamport.txt
deleted file mode 100755
index 0dcd159..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/Readme-Streamport.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Tracealyzer Stream Port for SEGGER J-Link
------------------------------------------
-
-This directory contains a "stream port" for the Tracealyzer recorder library,
-i.e., the specific code needed to use a particular interface for streaming a
-Tracealyzer RTOS trace. The stream port is defined by a set of macros in
-trcStreamingPort.h, found in the "include" directory.
-
-This particular stream port targets SEGGER J-Link debug probes, using the RTT
-interface provided by SEGGER.
-
-To use this stream port, make sure that include/trcStreamingPort.h is found
-by the compiler (i.e., add this folder to your project's include paths) and
-add all included source files to your build. Make sure no other versions of
-trcStreamingPort.h are included by mistake!
-
-Note that this stream port also contains SEGGER's RTT driver.
-
-See also http://percepio.com/2016/10/05/rtos-tracing.
-
-Percepio AB
-www.percepio.com
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/SEGGER_RTT.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/SEGGER_RTT.c
deleted file mode 100755
index b1b8d28..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/SEGGER_RTT.c
+++ /dev/null
@@ -1,1447 +0,0 @@
-/*********************************************************************
-* SEGGER MICROCONTROLLER GmbH & Co. KG *
-* Solutions for real time microcontroller applications *
-**********************************************************************
-* *
-* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
-* *
-* www.segger.com Support: support@segger.com *
-* *
-**********************************************************************
-* *
-* SEGGER RTT * Real Time Transfer for embedded targets *
-* *
-**********************************************************************
-* *
-* All rights reserved. *
-* *
-* * This software may in its unmodified form be freely redistributed *
-* in source, linkable, or executable form. *
-* * The source code may be modified, provided the source code *
-* retains the above copyright notice, this list of conditions and *
-* the following disclaimer. *
-* * Modified versions of this software in source, executable, or *
-* linkable form may not be distributed without prior consent of *
-* SEGGER. *
-* * This software may only be used for communication with SEGGER *
-* J-Link debug probes. *
-* *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
-* DAMAGE. *
-* *
-**********************************************************************
-* *
-* RTT version: 6.00e *
-* *
-**********************************************************************
----------------------------END-OF-HEADER------------------------------
-File : SEGGER_RTT.c
-Purpose : Implementation of SEGGER real-time transfer (RTT) which
- allows real-time communication on targets which support
- debugger memory accesses while the CPU is running.
-Revision: $Rev: 4079 $
-
-Additional information:
- Type "int" is assumed to be 32-bits in size
- H->T Host to target communication
- T->H Target to host communication
-
- RTT channel 0 is always present and reserved for Terminal usage.
- Name is fixed to "Terminal"
-
- Effective buffer size: SizeOfBuffer - 1
-
- WrOff == RdOff: Buffer is empty
- WrOff == (RdOff - 1): Buffer is full
- WrOff > RdOff: Free space includes wrap-around
- WrOff < RdOff: Used space includes wrap-around
- (WrOff == (SizeOfBuffer - 1)) && (RdOff == 0):
- Buffer full and wrap-around after next byte
-
-
-----------------------------------------------------------------------
-*/
-
-#include "SEGGER_RTT.h"
-
-#include // for memcpy
-
-/*********************************************************************
-*
-* Configuration, default values
-*
-**********************************************************************
-*/
-
-#ifndef BUFFER_SIZE_UP
- #define BUFFER_SIZE_UP 1024 // Size of the buffer for terminal output of target, up to host
-#endif
-
-#ifndef BUFFER_SIZE_DOWN
- #define BUFFER_SIZE_DOWN 16 // Size of the buffer for terminal input to target from host (Usually keyboard input)
-#endif
-
-#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS
- #define SEGGER_RTT_MAX_NUM_UP_BUFFERS 2 // Number of up-buffers (T->H) available on this target
-#endif
-
-#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
- #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS 2 // Number of down-buffers (H->T) available on this target
-#endif
-
-#ifndef SEGGER_RTT_BUFFER_SECTION
- #if defined(SEGGER_RTT_SECTION)
- #define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION
- #endif
-#endif
-
-#ifndef SEGGER_RTT_ALIGNMENT
- #define SEGGER_RTT_ALIGNMENT 0
-#endif
-
-#ifndef SEGGER_RTT_BUFFER_ALIGNMENT
- #define SEGGER_RTT_BUFFER_ALIGNMENT 0
-#endif
-
-#ifndef SEGGER_RTT_MODE_DEFAULT
- #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP
-#endif
-
-#ifndef SEGGER_RTT_LOCK
- #define SEGGER_RTT_LOCK()
-#endif
-
-#ifndef SEGGER_RTT_UNLOCK
- #define SEGGER_RTT_UNLOCK()
-#endif
-
-#ifndef STRLEN
- #define STRLEN(a) strlen((a))
-#endif
-
-#ifndef MEMCPY
- #define MEMCPY(pDest, pSrc, NumBytes) memcpy((pDest), (pSrc), (NumBytes))
-#endif
-
-#ifndef MIN
- #define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#ifndef MAX
- #define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-//
-// For some environments, NULL may not be defined until certain headers are included
-//
-#ifndef NULL
- #define NULL 0
-#endif
-
-/*********************************************************************
-*
-* Defines, fixed
-*
-**********************************************************************
-*/
-#if (defined __ICCARM__) || (defined __ICCRX__)
- #define RTT_PRAGMA(P) _Pragma(#P)
-#endif
-
-#if SEGGER_RTT_ALIGNMENT || SEGGER_RTT_BUFFER_ALIGNMENT
- #if (defined __GNUC__)
- #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment)))
- #elif (defined __ICCARM__) || (defined __ICCRX__)
- #define PRAGMA(A) _Pragma(#A)
-#define SEGGER_RTT_ALIGN(Var, Alignment) RTT_PRAGMA(data_alignment=Alignment) \
- Var
- #elif (defined __CC_ARM__)
- #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment)))
- #else
- #error "Alignment not supported for this compiler."
- #endif
-#else
- #define SEGGER_RTT_ALIGN(Var, Alignment) Var
-#endif
-
-#if defined(SEGGER_RTT_SECTION) || defined (SEGGER_RTT_BUFFER_SECTION)
- #if (defined __GNUC__)
- #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section))) Var
- #elif (defined __ICCARM__) || (defined __ICCRX__)
-#define SEGGER_RTT_PUT_SECTION(Var, Section) RTT_PRAGMA(location=Section) \
- Var
- #elif (defined __CC_ARM__)
- #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section), zero_init)) Var
- #else
- #error "Section placement not supported for this compiler."
- #endif
-#else
- #define SEGGER_RTT_PUT_SECTION(Var, Section) Var
-#endif
-
-
-#if SEGGER_RTT_ALIGNMENT
- #define SEGGER_RTT_CB_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_ALIGNMENT)
-#else
- #define SEGGER_RTT_CB_ALIGN(Var) Var
-#endif
-
-#if SEGGER_RTT_BUFFER_ALIGNMENT
- #define SEGGER_RTT_BUFFER_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_BUFFER_ALIGNMENT)
-#else
- #define SEGGER_RTT_BUFFER_ALIGN(Var) Var
-#endif
-
-
-#if defined(SEGGER_RTT_SECTION)
- #define SEGGER_RTT_PUT_CB_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_SECTION)
-#else
- #define SEGGER_RTT_PUT_CB_SECTION(Var) Var
-#endif
-
-#if defined(SEGGER_RTT_BUFFER_SECTION)
- #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_BUFFER_SECTION)
-#else
- #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) Var
-#endif
-
-/*********************************************************************
-*
-* Static const data
-*
-**********************************************************************
-*/
-
-static unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
-/*********************************************************************
-*
-* Static data
-*
-**********************************************************************
-*/
-//
-// RTT Control Block and allocate buffers for channel 0
-//
-SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT));
-
-SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer [BUFFER_SIZE_UP]));
-SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN]));
-
-static char _ActiveTerminal;
-
-/*********************************************************************
-*
-* Static functions
-*
-**********************************************************************
-*/
-
-/*********************************************************************
-*
-* _DoInit()
-*
-* Function description
-* Initializes the control block an buffers.
-* May only be called via INIT() to avoid overriding settings.
-*
-*/
-#define INIT() do { \
- if (_SEGGER_RTT.acID[0] == '\0') { _DoInit(); } \
- } while (0)
-static void _DoInit(void) {
- SEGGER_RTT_CB* p;
- //
- // Initialize control block
- //
- p = &_SEGGER_RTT;
- p->MaxNumUpBuffers = SEGGER_RTT_MAX_NUM_UP_BUFFERS;
- p->MaxNumDownBuffers = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS;
- //
- // Initialize up buffer 0
- //
- p->aUp[0].sName = "Terminal";
- p->aUp[0].pBuffer = _acUpBuffer;
- p->aUp[0].SizeOfBuffer = sizeof(_acUpBuffer);
- p->aUp[0].RdOff = 0u;
- p->aUp[0].WrOff = 0u;
- p->aUp[0].Flags = SEGGER_RTT_MODE_DEFAULT;
- //
- // Initialize down buffer 0
- //
- p->aDown[0].sName = "Terminal";
- p->aDown[0].pBuffer = _acDownBuffer;
- p->aDown[0].SizeOfBuffer = sizeof(_acDownBuffer);
- p->aDown[0].RdOff = 0u;
- p->aDown[0].WrOff = 0u;
- p->aDown[0].Flags = SEGGER_RTT_MODE_DEFAULT;
- //
- // Finish initialization of the control block.
- // Copy Id string in three steps to make sure "SEGGER RTT" is not found
- // in initializer memory (usually flash) by J-Link
- //
- strcpy(&p->acID[7], "RTT");
- strcpy(&p->acID[0], "SEGGER");
- p->acID[6] = ' ';
-}
-
-/*********************************************************************
-*
-* _WriteBlocking()
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT ring buffer
-* and updates the associated write pointer which is periodically
-* read by the host.
-* The caller is responsible for managing the write chunk sizes as
-* _WriteBlocking() will block until all data has been posted successfully.
-*
-* Parameters
-* pRing Ring buffer to post to.
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Return value
-* >= 0 - Number of bytes written into buffer.
-*/
-static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer, unsigned NumBytes) {
- unsigned NumBytesToWrite;
- unsigned NumBytesWritten;
- unsigned RdOff;
- unsigned WrOff;
- //
- // Write data to buffer and handle wrap-around if necessary
- //
- NumBytesWritten = 0u;
- WrOff = pRing->WrOff;
- do {
- RdOff = pRing->RdOff; // May be changed by host (debug probe) in the meantime
- if (RdOff > WrOff) {
- NumBytesToWrite = RdOff - WrOff - 1u;
- } else {
- NumBytesToWrite = pRing->SizeOfBuffer - (WrOff - RdOff + 1u);
- }
- NumBytesToWrite = MIN(NumBytesToWrite, (pRing->SizeOfBuffer - WrOff)); // Number of bytes that can be written until buffer wrap-around
- NumBytesToWrite = MIN(NumBytesToWrite, NumBytes);
- memcpy(pRing->pBuffer + WrOff, pBuffer, NumBytesToWrite);
- NumBytesWritten += NumBytesToWrite;
- pBuffer += NumBytesToWrite;
- NumBytes -= NumBytesToWrite;
- WrOff += NumBytesToWrite;
- if (WrOff == pRing->SizeOfBuffer) {
- WrOff = 0u;
- }
- pRing->WrOff = WrOff;
- } while (NumBytes);
- //
- return NumBytesWritten;
-}
-
-/*********************************************************************
-*
-* _WriteNoCheck()
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT ring buffer
-* and updates the associated write pointer which is periodically
-* read by the host.
-* It is callers responsibility to make sure data actually fits in buffer.
-*
-* Parameters
-* pRing Ring buffer to post to.
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Notes
-* (1) If there might not be enough space in the "Up"-buffer, call _WriteBlocking
-*/
-static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsigned NumBytes) {
- unsigned NumBytesAtOnce;
- unsigned WrOff;
- unsigned Rem;
-
- WrOff = pRing->WrOff;
- Rem = pRing->SizeOfBuffer - WrOff;
- if (Rem > NumBytes) {
- //
- // All data fits before wrap around
- //
- memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
- pRing->WrOff = WrOff + NumBytes;
- } else {
- //
- // We reach the end of the buffer, so need to wrap around
- //
- NumBytesAtOnce = Rem;
- memcpy(pRing->pBuffer + WrOff, pData, NumBytesAtOnce);
- NumBytesAtOnce = NumBytes - Rem;
- memcpy(pRing->pBuffer, pData + Rem, NumBytesAtOnce);
- pRing->WrOff = NumBytesAtOnce;
- }
-}
-
-/*********************************************************************
-*
-* _PostTerminalSwitch()
-*
-* Function description
-* Switch terminal to the given terminal ID. It is the caller's
-* responsibility to ensure the terminal ID is correct and there is
-* enough space in the buffer for this to complete successfully.
-*
-* Parameters
-* pRing Ring buffer to post to.
-* TerminalId Terminal ID to switch to.
-*/
-static void _PostTerminalSwitch(SEGGER_RTT_BUFFER_UP* pRing, unsigned char TerminalId) {
- char ac[2];
-
- ac[0] = 0xFFu;
- ac[1] = _aTerminalId[TerminalId]; // Caller made already sure that TerminalId does not exceed our terminal limit
- _WriteBlocking(pRing, ac, 2u);
-}
-
-/*********************************************************************
-*
-* _GetAvailWriteSpace()
-*
-* Function description
-* Returns the number of bytes that can be written to the ring
-* buffer without blocking.
-*
-* Parameters
-* pRing Ring buffer to check.
-*
-* Return value
-* Number of bytes that are free in the buffer.
-*/
-static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) {
- unsigned RdOff;
- unsigned WrOff;
- unsigned r;
- //
- // Avoid warnings regarding volatile access order. It's not a problem
- // in this case, but dampen compiler enthusiasm.
- //
- RdOff = pRing->RdOff;
- WrOff = pRing->WrOff;
- if (RdOff <= WrOff) {
- r = pRing->SizeOfBuffer - 1u - WrOff + RdOff;
- } else {
- r = RdOff - WrOff - 1u;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* Public code
-*
-**********************************************************************
-*/
-/*********************************************************************
-*
-* SEGGER_RTT_ReadNoLock()
-*
-* Function description
-* Reads characters from SEGGER real-time-terminal control block
-* which have been previously stored by the host.
-* Do not lock against interrupts and multiple access.
-*
-* Parameters
-* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.
-* BufferSize Size of the target application buffer.
-*
-* Return value
-* Number of bytes that have been read.
-*/
-unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) {
- unsigned NumBytesRem;
- unsigned NumBytesRead;
- unsigned RdOff;
- unsigned WrOff;
- unsigned char* pBuffer;
- SEGGER_RTT_BUFFER_DOWN* pRing;
- //
- INIT();
- pRing = &_SEGGER_RTT.aDown[BufferIndex];
- pBuffer = (unsigned char*)pData;
- RdOff = pRing->RdOff;
- WrOff = pRing->WrOff;
- NumBytesRead = 0u;
- //
- // Read from current read position to wrap-around of buffer, first
- //
- if (RdOff > WrOff) {
- NumBytesRem = pRing->SizeOfBuffer - RdOff;
- NumBytesRem = MIN(NumBytesRem, BufferSize);
- memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
- NumBytesRead += NumBytesRem;
- pBuffer += NumBytesRem;
- BufferSize -= NumBytesRem;
- RdOff += NumBytesRem;
- //
- // Handle wrap-around of buffer
- //
- if (RdOff == pRing->SizeOfBuffer) {
- RdOff = 0u;
- }
- }
- //
- // Read remaining items of buffer
- //
- NumBytesRem = WrOff - RdOff;
- NumBytesRem = MIN(NumBytesRem, BufferSize);
- if (NumBytesRem > 0u) {
- memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
- NumBytesRead += NumBytesRem;
- pBuffer += NumBytesRem;
- BufferSize -= NumBytesRem;
- RdOff += NumBytesRem;
- }
- if (NumBytesRead) {
- pRing->RdOff = RdOff;
- }
- //
- return NumBytesRead;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_Read
-*
-* Function description
-* Reads characters from SEGGER real-time-terminal control block
-* which have been previously stored by the host.
-*
-* Parameters
-* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.
-* BufferSize Size of the target application buffer.
-*
-* Return value
-* Number of bytes that have been read.
-*/
-unsigned SEGGER_RTT_Read(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) {
- unsigned NumBytesRead;
- //
- SEGGER_RTT_LOCK();
- //
- // Call the non-locking read function
- //
- NumBytesRead = SEGGER_RTT_ReadNoLock(BufferIndex, pBuffer, BufferSize);
- //
- // Finish up.
- //
- SEGGER_RTT_UNLOCK();
- //
- return NumBytesRead;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_WriteWithOverwriteNoLock
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT
-* control block.
-* SEGGER_RTT_WriteWithOverwriteNoLock does not lock the application
-* and overwrites data if the data does not fit into the buffer.
-*
-* Parameters
-* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Notes
-* (1) If there is not enough space in the "Up"-buffer, data is overwritten.
-* (2) For performance reasons this function does not call Init()
-* and may only be called after RTT has been initialized.
-* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
-* (3) Do not use SEGGER_RTT_WriteWithOverwriteNoLock if a J-Link
-* connection reads RTT data.
-*/
-void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
- const char* pData;
- SEGGER_RTT_BUFFER_UP* pRing;
- unsigned Avail;
-
- pData = (const char *)pBuffer;
- //
- // Get "to-host" ring buffer and copy some elements into local variables.
- //
- pRing = &_SEGGER_RTT.aUp[BufferIndex];
- //
- // Check if we will overwrite data and need to adjust the RdOff.
- //
- if (pRing->WrOff == pRing->RdOff) {
- Avail = pRing->SizeOfBuffer - 1u;
- } else if ( pRing->WrOff < pRing->RdOff) {
- Avail = pRing->RdOff - pRing->WrOff - 1u;
- } else {
- Avail = pRing->RdOff - pRing->WrOff - 1u + pRing->SizeOfBuffer;
- }
- if (NumBytes > Avail) {
- pRing->RdOff += (NumBytes - Avail);
- while (pRing->RdOff >= pRing->SizeOfBuffer) {
- pRing->RdOff -= pRing->SizeOfBuffer;
- }
- }
- //
- // Write all data, no need to check the RdOff, but possibly handle multiple wrap-arounds
- //
- Avail = pRing->SizeOfBuffer - pRing->WrOff;
- do {
- if (Avail > NumBytes) {
- //
- // Last round
- //
-#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
- char* pDst;
- pDst = pRing->pBuffer + pRing->WrOff;
- pRing->WrOff += NumBytes;
- do {
- *pDst++ = *pData++;
- } while (--NumBytes);
-#else
- memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
- pRing->WrOff += NumBytes;
-#endif
- break; //Alternatively: NumBytes = 0;
- } else {
- //
- // Wrap-around necessary, write until wrap-around and reset WrOff
- //
- memcpy(pRing->pBuffer + pRing->WrOff, pData, Avail);
- pData += Avail;
- pRing->WrOff = 0;
- NumBytes -= Avail;
- Avail = (pRing->SizeOfBuffer - 1);
- }
- } while (NumBytes);
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_WriteSkipNoLock
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT
-* control block which is then read by the host.
-* SEGGER_RTT_WriteSkipNoLock does not lock the application and
-* skips all data, if the data does not fit into the buffer.
-*
-* Parameters
-* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Return value
-* Number of bytes which have been stored in the "Up"-buffer.
-*
-* Notes
-* (1) If there is not enough space in the "Up"-buffer, all data is dropped.
-* (2) For performance reasons this function does not call Init()
-* and may only be called after RTT has been initialized.
-* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
-*/
-unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
- const char* pData;
- SEGGER_RTT_BUFFER_UP* pRing;
- unsigned Avail;
- unsigned RdOff;
- unsigned WrOff;
- unsigned Rem;
-
- pData = (const char *)pBuffer;
- //
- // Get "to-host" ring buffer and copy some elements into local variables.
- //
- pRing = &_SEGGER_RTT.aUp[BufferIndex];
- RdOff = pRing->RdOff;
- WrOff = pRing->WrOff;
- //
- // Handle the most common cases fastest.
- // Which is:
- // RdOff <= WrOff -> Space until wrap around is free.
- // AND
- // WrOff + NumBytes < SizeOfBuffer -> No Wrap around necessary.
- //
- // OR
- //
- // RdOff > WrOff -> Space until RdOff - 1 is free.
- // AND
- // WrOff + NumBytes < RdOff -> Data fits into buffer
- //
- if (RdOff <= WrOff) {
- //
- // Get space until WrOff will be at wrap around.
- //
- Avail = pRing->SizeOfBuffer - 1u - WrOff ;
- if (Avail >= NumBytes) {
-#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
- char* pDst;
- pDst = pRing->pBuffer + WrOff;
- WrOff += NumBytes;
- do {
- *pDst++ = *pData++;
- } while (--NumBytes);
- pRing->WrOff = WrOff + NumBytes;
-#else
- memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
- pRing->WrOff = WrOff + NumBytes;
-#endif
- return 1;
- }
- //
- // If data did not fit into space until wrap around calculate complete space in buffer.
- //
- Avail += RdOff;
- //
- // If there is still no space for the whole of this output, don't bother.
- //
- if (Avail >= NumBytes) {
- //
- // OK, we have enough space in buffer. Copy in one or 2 chunks
- //
- Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer
- if (Rem > NumBytes) {
- memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
- pRing->WrOff = WrOff + NumBytes;
- } else {
- //
- // We reach the end of the buffer, so need to wrap around
- //
- memcpy(pRing->pBuffer + WrOff, pData, Rem);
- memcpy(pRing->pBuffer, pData + Rem, NumBytes - Rem);
- pRing->WrOff = NumBytes - Rem;
- }
- return 1;
- }
- } else {
- Avail = RdOff - WrOff - 1u;
- if (Avail >= NumBytes) {
- memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
- pRing->WrOff = WrOff + NumBytes;
- return 1;
- }
- }
- //
- // If we reach this point no data has been written
- //
- return 0;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_WriteNoLock
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT
-* control block which is then read by the host.
-* SEGGER_RTT_WriteNoLock does not lock the application.
-*
-* Parameters
-* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Return value
-* Number of bytes which have been stored in the "Up"-buffer.
-*
-* Notes
-* (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
-* (2) For performance reasons this function does not call Init()
-* and may only be called after RTT has been initialized.
-* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
-*/
-unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
- unsigned Status;
- unsigned Avail;
- const char* pData;
- SEGGER_RTT_BUFFER_UP* pRing;
-
- pData = (const char *)pBuffer;
- //
- // Get "to-host" ring buffer.
- //
- pRing = &_SEGGER_RTT.aUp[BufferIndex];
- //
- // How we output depends upon the mode...
- //
- switch (pRing->Flags) {
- case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
- //
- // If we are in skip mode and there is no space for the whole
- // of this output, don't bother.
- //
- Avail = _GetAvailWriteSpace(pRing);
- if (Avail < NumBytes) {
- Status = 0u;
- } else {
- Status = NumBytes;
- _WriteNoCheck(pRing, pData, NumBytes);
- }
- break;
- case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
- //
- // If we are in trim mode, trim to what we can output without blocking.
- //
- Avail = _GetAvailWriteSpace(pRing);
- Status = Avail < NumBytes ? Avail : NumBytes;
- _WriteNoCheck(pRing, pData, Status);
- break;
- case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
- //
- // If we are in blocking mode, output everything.
- //
- Status = _WriteBlocking(pRing, pData, NumBytes);
- break;
- default:
- Status = 0u;
- break;
- }
- //
- // Finish up.
- //
- return Status;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_Write
-*
-* Function description
-* Stores a specified number of characters in SEGGER RTT
-* control block which is then read by the host.
-*
-* Parameters
-* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
-* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
-* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
-*
-* Return value
-* Number of bytes which have been stored in the "Up"-buffer.
-*
-* Notes
-* (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
-*/
-unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
- unsigned Status;
- //
- INIT();
- SEGGER_RTT_LOCK();
- //
- // Call the non-locking write function
- //
- Status = SEGGER_RTT_WriteNoLock(BufferIndex, pBuffer, NumBytes);
- //
- // Finish up.
- //
- SEGGER_RTT_UNLOCK();
- //
- return Status;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_WriteString
-*
-* Function description
-* Stores string in SEGGER RTT control block.
-* This data is read by the host.
-*
-* Parameters
-* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
-* s Pointer to string.
-*
-* Return value
-* Number of bytes which have been stored in the "Up"-buffer.
-*
-* Notes
-* (1) If there is not enough space in the "Up"-buffer, depending on configuration,
-* remaining characters may be dropped or RTT module waits until there is more space in the buffer.
-* (2) String passed to this function has to be \0 terminated
-* (3) \0 termination character is *not* stored in RTT buffer
-*/
-unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) {
- unsigned Len;
-
- Len = STRLEN(s);
- return SEGGER_RTT_Write(BufferIndex, s, Len);
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_GetKey
-*
-* Function description
-* Reads one character from the SEGGER RTT buffer.
-* Host has previously stored data there.
-*
-* Return value
-* < 0 - No character available (buffer empty).
-* >= 0 - Character which has been read. (Possible values: 0 - 255)
-*
-* Notes
-* (1) This function is only specified for accesses to RTT buffer 0.
-*/
-int SEGGER_RTT_GetKey(void) {
- char c;
- int r;
-
- r = (int)SEGGER_RTT_Read(0u, &c, 1u);
- if (r == 1) {
- r = (int)(unsigned char)c;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_WaitKey
-*
-* Function description
-* Waits until at least one character is avaible in the SEGGER RTT buffer.
-* Once a character is available, it is read and this function returns.
-*
-* Return value
-* >=0 - Character which has been read.
-*
-* Notes
-* (1) This function is only specified for accesses to RTT buffer 0
-* (2) This function is blocking if no character is present in RTT buffer
-*/
-int SEGGER_RTT_WaitKey(void) {
- int r;
-
- do {
- r = SEGGER_RTT_GetKey();
- } while (r < 0);
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_HasKey
-*
-* Function description
-* Checks if at least one character for reading is available in the SEGGER RTT buffer.
-*
-* Return value
-* == 0 - No characters are available to read.
-* == 1 - At least one character is available.
-*
-* Notes
-* (1) This function is only specified for accesses to RTT buffer 0
-*/
-int SEGGER_RTT_HasKey(void) {
- unsigned RdOff;
- int r;
-
- INIT();
- RdOff = _SEGGER_RTT.aDown[0].RdOff;
- if (RdOff != _SEGGER_RTT.aDown[0].WrOff) {
- r = 1;
- } else {
- r = 0;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_HasData
-*
-* Function description
-* Check if there is data from the host in the given buffer.
-*
-* Return value:
-* ==0: No data
-* !=0: Data in buffer
-*
-*/
-unsigned SEGGER_RTT_HasData(unsigned BufferIndex) {
- SEGGER_RTT_BUFFER_DOWN* pRing;
- unsigned v;
-
- pRing = &_SEGGER_RTT.aDown[BufferIndex];
- v = pRing->WrOff;
- return v - pRing->RdOff;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_AllocDownBuffer
-*
-* Function description
-* Run-time configuration of the next down-buffer (H->T).
-* The next buffer, which is not used yet is configured.
-* This includes: Buffer address, size, name, flags, ...
-*
-* Parameters
-* sName Pointer to a constant name string.
-* pBuffer Pointer to a buffer to be used.
-* BufferSize Size of the buffer.
-* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).
-*
-* Return value
-* >= 0 - O.K. Buffer Index
-* < 0 - Error
-*/
-int SEGGER_RTT_AllocDownBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
- int BufferIndex;
-
- INIT();
- SEGGER_RTT_LOCK();
- BufferIndex = 0;
- do {
- if (_SEGGER_RTT.aDown[BufferIndex].pBuffer == NULL) {
- break;
- }
- BufferIndex++;
- } while (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers);
- if (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers) {
- _SEGGER_RTT.aDown[BufferIndex].sName = sName;
- _SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;
- _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
- _SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;
- _SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;
- _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
- } else {
- BufferIndex = -1;
- }
- SEGGER_RTT_UNLOCK();
- return BufferIndex;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_AllocUpBuffer
-*
-* Function description
-* Run-time configuration of the next up-buffer (T->H).
-* The next buffer, which is not used yet is configured.
-* This includes: Buffer address, size, name, flags, ...
-*
-* Parameters
-* sName Pointer to a constant name string.
-* pBuffer Pointer to a buffer to be used.
-* BufferSize Size of the buffer.
-* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).
-*
-* Return value
-* >= 0 - O.K. Buffer Index
-* < 0 - Error
-*/
-int SEGGER_RTT_AllocUpBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
- int BufferIndex;
-
- INIT();
- SEGGER_RTT_LOCK();
- BufferIndex = 0;
- do {
- if (_SEGGER_RTT.aUp[BufferIndex].pBuffer == NULL) {
- break;
- }
- BufferIndex++;
- } while (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers);
- if (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers) {
- _SEGGER_RTT.aUp[BufferIndex].sName = sName;
- _SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;
- _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
- _SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;
- _SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;
- _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
- } else {
- BufferIndex = -1;
- }
- SEGGER_RTT_UNLOCK();
- return BufferIndex;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_ConfigUpBuffer
-*
-* Function description
-* Run-time configuration of a specific up-buffer (T->H).
-* Buffer to be configured is specified by index.
-* This includes: Buffer address, size, name, flags, ...
-*
-* Parameters
-* BufferIndex Index of the buffer to configure.
-* sName Pointer to a constant name string.
-* pBuffer Pointer to a buffer to be used.
-* BufferSize Size of the buffer.
-* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).
-*
-* Return value
-* >= 0 - O.K.
-* < 0 - Error
-*
-* Additional information
-* Buffer 0 is configured on compile-time.
-* May only be called once per buffer.
-* Buffer name and flags can be reconfigured using the appropriate functions.
-*/
-int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
- SEGGER_RTT_LOCK();
- if (BufferIndex > 0u) {
- _SEGGER_RTT.aUp[BufferIndex].sName = sName;
- _SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;
- _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
- _SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;
- _SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;
- }
- _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_ConfigDownBuffer
-*
-* Function description
-* Run-time configuration of a specific down-buffer (H->T).
-* Buffer to be configured is specified by index.
-* This includes: Buffer address, size, name, flags, ...
-*
-* Parameters
-* BufferIndex Index of the buffer to configure.
-* sName Pointer to a constant name string.
-* pBuffer Pointer to a buffer to be used.
-* BufferSize Size of the buffer.
-* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error
-*
-* Additional information
-* Buffer 0 is configured on compile-time.
-* May only be called once per buffer.
-* Buffer name and flags can be reconfigured using the appropriate functions.
-*/
-int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
- SEGGER_RTT_LOCK();
- if (BufferIndex > 0u) {
- _SEGGER_RTT.aDown[BufferIndex].sName = sName;
- _SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;
- _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
- _SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;
- _SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;
- }
- _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_SetNameUpBuffer
-*
-* Function description
-* Run-time configuration of a specific up-buffer name (T->H).
-* Buffer to be configured is specified by index.
-*
-* Parameters
-* BufferIndex Index of the buffer to renamed.
-* sName Pointer to a constant name string.
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error
-*/
-int SEGGER_RTT_SetNameUpBuffer(unsigned BufferIndex, const char* sName) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
- SEGGER_RTT_LOCK();
- _SEGGER_RTT.aUp[BufferIndex].sName = sName;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_SetNameDownBuffer
-*
-* Function description
-* Run-time configuration of a specific Down-buffer name (T->H).
-* Buffer to be configured is specified by index.
-*
-* Parameters
-* BufferIndex Index of the buffer to renamed.
-* sName Pointer to a constant name string.
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error
-*/
-int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
- SEGGER_RTT_LOCK();
- _SEGGER_RTT.aDown[BufferIndex].sName = sName;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_SetFlagsUpBuffer
-*
-* Function description
-* Run-time configuration of specific up-buffer flags (T->H).
-* Buffer to be configured is specified by index.
-*
-* Parameters
-* BufferIndex Index of the buffer.
-* Flags Flags to set for the buffer.
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error
-*/
-int SEGGER_RTT_SetFlagsUpBuffer(unsigned BufferIndex, unsigned Flags) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
- SEGGER_RTT_LOCK();
- _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_SetFlagsDownBuffer
-*
-* Function description
-* Run-time configuration of specific Down-buffer flags (T->H).
-* Buffer to be configured is specified by index.
-*
-* Parameters
-* BufferIndex Index of the buffer to renamed.
-* Flags Flags to set for the buffer.
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error
-*/
-int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) {
- int r;
-
- INIT();
- if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
- SEGGER_RTT_LOCK();
- _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
- SEGGER_RTT_UNLOCK();
- r = 0;
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_Init
-*
-* Function description
-* Initializes the RTT Control Block.
-* Should be used in RAM targets, at start of the application.
-*
-*/
-void SEGGER_RTT_Init (void) {
- _DoInit();
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_SetTerminal
-*
-* Function description
-* Sets the terminal to be used for output on channel 0.
-*
-* Parameters
-* TerminalId Index of the terminal.
-*
-* Return value
-* >= 0 O.K.
-* < 0 Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id)
-*/
-int SEGGER_RTT_SetTerminal (char TerminalId) {
- char ac[2];
- SEGGER_RTT_BUFFER_UP* pRing;
- unsigned Avail;
- int r;
- //
- INIT();
- //
- r = 0;
- ac[0] = 0xFFU;
- if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels
- ac[1] = _aTerminalId[(unsigned char)TerminalId];
- pRing = &_SEGGER_RTT.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
- SEGGER_RTT_LOCK(); // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing
- if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
- _ActiveTerminal = TerminalId;
- _WriteBlocking(pRing, ac, 2u);
- } else { // Skipping mode or trim mode? => We cannot trim this command so handling is the same for both modes
- Avail = _GetAvailWriteSpace(pRing);
- if (Avail >= 2) {
- _ActiveTerminal = TerminalId; // Only change active terminal in case of success
- _WriteNoCheck(pRing, ac, 2u);
- } else {
- r = -1;
- }
- }
- SEGGER_RTT_UNLOCK();
- } else {
- r = -1;
- }
- return r;
-}
-
-/*********************************************************************
-*
-* SEGGER_RTT_TerminalOut
-*
-* Function description
-* Writes a string to the given terminal
-* without changing the terminal for channel 0.
-*
-* Parameters
-* TerminalId Index of the terminal.
-* s String to be printed on the terminal.
-*
-* Return value
-* >= 0 - Number of bytes written.
-* < 0 - Error.
-*
-*/
-int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
- int Status;
- unsigned FragLen;
- unsigned Avail;
- SEGGER_RTT_BUFFER_UP* pRing;
- //
- INIT();
- //
- // Validate terminal ID.
- //
- if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels
- //
- // Get "to-host" ring buffer.
- //
- pRing = &_SEGGER_RTT.aUp[0];
- //
- // Need to be able to change terminal, write data, change back.
- // Compute the fixed and variable sizes.
- //
- FragLen = strlen(s);
- //
- // How we output depends upon the mode...
- //
- SEGGER_RTT_LOCK();
- Avail = _GetAvailWriteSpace(pRing);
- switch (pRing->Flags & SEGGER_RTT_MODE_MASK) {
- case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
- //
- // If we are in skip mode and there is no space for the whole
- // of this output, don't bother switching terminals at all.
- //
- if (Avail < (FragLen + 4u)) {
- Status = 0;
- } else {
- _PostTerminalSwitch(pRing, TerminalId);
- Status = (int)_WriteBlocking(pRing, s, FragLen);
- _PostTerminalSwitch(pRing, _ActiveTerminal);
- }
- break;
- case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
- //
- // If we are in trim mode and there is not enough space for everything,
- // trim the output but always include the terminal switch. If no room
- // for terminal switch, skip that totally.
- //
- if (Avail < 4u) {
- Status = -1;
- } else {
- _PostTerminalSwitch(pRing, TerminalId);
- Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u));
- _PostTerminalSwitch(pRing, _ActiveTerminal);
- }
- break;
- case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
- //
- // If we are in blocking mode, output everything.
- //
- _PostTerminalSwitch(pRing, TerminalId);
- Status = (int)_WriteBlocking(pRing, s, FragLen);
- _PostTerminalSwitch(pRing, _ActiveTerminal);
- break;
- default:
- Status = -1;
- break;
- }
- //
- // Finish up.
- //
- SEGGER_RTT_UNLOCK();
- } else {
- Status = -1;
- }
- return Status;
-}
-
-
-/*************************** End of file ****************************/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT.h
deleted file mode 100755
index f2bd1ee..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*********************************************************************
-* SEGGER MICROCONTROLLER GmbH & Co. KG *
-* Solutions for real time microcontroller applications *
-**********************************************************************
-* *
-* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
-* *
-* www.segger.com Support: support@segger.com *
-* *
-**********************************************************************
-* *
-* SEGGER RTT * Real Time Transfer for embedded targets *
-* *
-**********************************************************************
-* *
-* All rights reserved. *
-* *
-* * This software may in its unmodified form be freely redistributed *
-* in source, linkable, or executable form. *
-* * The source code may be modified, provided the source code *
-* retains the above copyright notice, this list of conditions and *
-* the following disclaimer. *
-* * Modified versions of this software in source, executable, or *
-* linkable form may not be distributed without prior consent of *
-* SEGGER. *
-* * This software may only be used for communication with SEGGER *
-* J-Link debug probes. *
-* *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
-* DAMAGE. *
-* *
-**********************************************************************
-* *
-* RTT version: 6.00e *
-* *
-**********************************************************************
----------------------------END-OF-HEADER------------------------------
-File : SEGGER_RTT.h
-Purpose : Implementation of SEGGER real-time transfer which allows
- real-time communication on targets which support debugger
- memory accesses while the CPU is running.
-Revision: $Rev: 4079 $
-----------------------------------------------------------------------
-*/
-
-#ifndef SEGGER_RTT_H
-#define SEGGER_RTT_H
-
-#include "SEGGER_RTT_Conf.h"
-
-/*********************************************************************
-*
-* Defines, fixed
-*
-**********************************************************************
-*/
-
-/*********************************************************************
-*
-* Types
-*
-**********************************************************************
-*/
-
-//
-// Description for a circular buffer (also called "ring buffer")
-// which is used as up-buffer (T->H)
-//
-typedef struct {
- const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
- char* pBuffer; // Pointer to start of buffer
- unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
- unsigned WrOff; // Position of next item to be written by either target.
- volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
- unsigned Flags; // Contains configuration flags
-} SEGGER_RTT_BUFFER_UP;
-
-//
-// Description for a circular buffer (also called "ring buffer")
-// which is used as down-buffer (H->T)
-//
-typedef struct {
- const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
- char* pBuffer; // Pointer to start of buffer
- unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
- volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
- unsigned RdOff; // Position of next item to be read by target (down-buffer).
- unsigned Flags; // Contains configuration flags
-} SEGGER_RTT_BUFFER_DOWN;
-
-//
-// RTT control block which describes the number of buffers available
-// as well as the configuration for each buffer
-//
-//
-typedef struct {
- char acID[16]; // Initialized to "SEGGER RTT"
- int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
- int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
- SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
- SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
-} SEGGER_RTT_CB;
-
-/*********************************************************************
-*
-* Global data
-*
-**********************************************************************
-*/
-extern SEGGER_RTT_CB _SEGGER_RTT;
-
-/*********************************************************************
-*
-* RTT API functions
-*
-**********************************************************************
-*/
-#ifdef __cplusplus
- extern "C" {
-#endif
-int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int SEGGER_RTT_GetKey (void);
-unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
-int SEGGER_RTT_HasKey (void);
-void SEGGER_RTT_Init (void);
-unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
-unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
-int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
-int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
-int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
-int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
-int SEGGER_RTT_WaitKey (void);
-unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
-void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-//
-// Function macro for performance optimization
-//
-#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
-
-/*********************************************************************
-*
-* RTT "Terminal" API functions
-*
-**********************************************************************
-*/
-int SEGGER_RTT_SetTerminal (char TerminalId);
-int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
-
-/*********************************************************************
-*
-* RTT printf functions (require SEGGER_RTT_printf.c)
-*
-**********************************************************************
-*/
-int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
-#ifdef __cplusplus
- }
-#endif
-
-/*********************************************************************
-*
-* Defines
-*
-**********************************************************************
-*/
-
-//
-// Operating modes. Define behavior if buffer is full (not enough space for entire message)
-//
-#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)
-#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.
-#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.
-#define SEGGER_RTT_MODE_MASK (3U)
-
-//
-// Control sequences, based on ANSI.
-// Can be used to control color, and clear the screen
-//
-#define RTT_CTRL_RESET "[0m" // Reset to default colors
-#define RTT_CTRL_CLEAR "[2J" // Clear screen, reposition cursor to top left
-
-#define RTT_CTRL_TEXT_BLACK "[2;30m"
-#define RTT_CTRL_TEXT_RED "[2;31m"
-#define RTT_CTRL_TEXT_GREEN "[2;32m"
-#define RTT_CTRL_TEXT_YELLOW "[2;33m"
-#define RTT_CTRL_TEXT_BLUE "[2;34m"
-#define RTT_CTRL_TEXT_MAGENTA "[2;35m"
-#define RTT_CTRL_TEXT_CYAN "[2;36m"
-#define RTT_CTRL_TEXT_WHITE "[2;37m"
-
-#define RTT_CTRL_TEXT_BRIGHT_BLACK "[1;30m"
-#define RTT_CTRL_TEXT_BRIGHT_RED "[1;31m"
-#define RTT_CTRL_TEXT_BRIGHT_GREEN "[1;32m"
-#define RTT_CTRL_TEXT_BRIGHT_YELLOW "[1;33m"
-#define RTT_CTRL_TEXT_BRIGHT_BLUE "[1;34m"
-#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "[1;35m"
-#define RTT_CTRL_TEXT_BRIGHT_CYAN "[1;36m"
-#define RTT_CTRL_TEXT_BRIGHT_WHITE "[1;37m"
-
-#define RTT_CTRL_BG_BLACK "[24;40m"
-#define RTT_CTRL_BG_RED "[24;41m"
-#define RTT_CTRL_BG_GREEN "[24;42m"
-#define RTT_CTRL_BG_YELLOW "[24;43m"
-#define RTT_CTRL_BG_BLUE "[24;44m"
-#define RTT_CTRL_BG_MAGENTA "[24;45m"
-#define RTT_CTRL_BG_CYAN "[24;46m"
-#define RTT_CTRL_BG_WHITE "[24;47m"
-
-#define RTT_CTRL_BG_BRIGHT_BLACK "[4;40m"
-#define RTT_CTRL_BG_BRIGHT_RED "[4;41m"
-#define RTT_CTRL_BG_BRIGHT_GREEN "[4;42m"
-#define RTT_CTRL_BG_BRIGHT_YELLOW "[4;43m"
-#define RTT_CTRL_BG_BRIGHT_BLUE "[4;44m"
-#define RTT_CTRL_BG_BRIGHT_MAGENTA "[4;45m"
-#define RTT_CTRL_BG_BRIGHT_CYAN "[4;46m"
-#define RTT_CTRL_BG_BRIGHT_WHITE "[4;47m"
-
-
-#endif
-
-/*************************** End of file ****************************/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT_Conf.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT_Conf.h
deleted file mode 100755
index f3d906f..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/SEGGER_RTT_Conf.h
+++ /dev/null
@@ -1,259 +0,0 @@
-/*********************************************************************
-* SEGGER MICROCONTROLLER GmbH & Co. KG *
-* Solutions for real time microcontroller applications *
-**********************************************************************
-* *
-* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
-* *
-* www.segger.com Support: support@segger.com *
-* *
-**********************************************************************
-* *
-* SEGGER RTT * Real Time Transfer for embedded targets *
-* *
-**********************************************************************
-* *
-* All rights reserved. *
-* *
-* * This software may in its unmodified form be freely redistributed *
-* in source, linkable, or executable form. *
-* * The source code may be modified, provided the source code *
-* retains the above copyright notice, this list of conditions and *
-* the following disclaimer. *
-* * Modified versions of this software in source, executable, or *
-* linkable form may not be distributed without prior consent of *
-* SEGGER. *
-* * This software may only be used for communication with SEGGER *
-* J-Link debug probes. *
-* *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
-* DAMAGE. *
-* *
-**********************************************************************
-* *
-* RTT version: 6.00e *
-* *
-**********************************************************************
-----------------------------------------------------------------------
-File : SEGGER_RTT_Conf.h
-Purpose : Implementation of SEGGER real-time transfer (RTT) which
- allows real-time communication on targets which support
- debugger memory accesses while the CPU is running.
-Revision: $Rev: 3892 $
----------------------------END-OF-HEADER------------------------------
-*/
-
-#ifndef SEGGER_RTT_CONF_H
-#define SEGGER_RTT_CONF_H
-
-#ifdef __IAR_SYSTEMS_ICC__
- #include
-#endif
-
-/*********************************************************************
-*
-* Defines, configurable
-*
-**********************************************************************
-*/
-
-#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
-#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
-
-#define BUFFER_SIZE_UP (64) // Size of the buffer for terminal output of target, up to host (Default: 1k)
-#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
-
-#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
-
-#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
-
-//
-// Target is not allowed to perform other RTT operations while string still has not been stored completely.
-// Otherwise we would probably end up with a mixed string in the buffer.
-// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
-//
-// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
-// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
-// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
-// (Higher priority = lower priority number)
-// Default value for embOS: 128u
-// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
-// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
-// or define SEGGER_RTT_LOCK() to completely disable interrupts.
-//
-
-#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
-
-/*********************************************************************
-*
-* RTT lock configuration for SEGGER Embedded Studio,
-* Rowley CrossStudio and GCC
-*/
-#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
- #ifdef __ARM_ARCH_6M__
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- __asm volatile ("mrs %0, primask \n\t" \
- "mov r1, $1 \n\t" \
- "msr primask, r1 \n\t" \
- : "=r" (LockState) \
- : \
- : "r1" \
- );
-
- #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
- : \
- : "r" (LockState) \
- : \
- ); \
- }
-
- #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
- #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
- #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
- #endif
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- __asm volatile ("mrs %0, basepri \n\t" \
- "mov r1, %1 \n\t" \
- "msr basepri, r1 \n\t" \
- : "=r" (LockState) \
- : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
- : "r1" \
- );
-
- #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
- : \
- : "r" (LockState) \
- : \
- ); \
- }
-
- #elif defined(__ARM_ARCH_7A__)
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- __asm volatile ("mrs r1, CPSR \n\t" \
- "mov %0, r1 \n\t" \
- "orr r1, r1, #0xC0 \n\t" \
- "msr CPSR_c, r1 \n\t" \
- : "=r" (LockState) \
- : \
- : "r1" \
- );
-
- #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
- "mrs r1, CPSR \n\t" \
- "bic r1, r1, #0xC0 \n\t" \
- "and r0, r0, #0xC0 \n\t" \
- "orr r1, r1, r0 \n\t" \
- "msr CPSR_c, r1 \n\t" \
- : \
- : "r" (LockState) \
- : "r0", "r1" \
- ); \
- }
-#else
- #define SEGGER_RTT_LOCK()
- #define SEGGER_RTT_UNLOCK()
- #endif
-#endif
-
-/*********************************************************************
-*
-* RTT lock configuration for IAR EWARM
-*/
-#ifdef __ICCARM__
- #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- LockState = __get_PRIMASK(); \
- __set_PRIMASK(1);
-
- #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
- }
- #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
- #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
- #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
- #endif
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- LockState = __get_BASEPRI(); \
- __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
-
- #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
- }
- #endif
-#endif
-
-/*********************************************************************
-*
-* RTT lock configuration for IAR RX
-*/
-#ifdef __ICCRX__
- #define SEGGER_RTT_LOCK() { \
- unsigned long LockState; \
- LockState = __get_interrupt_state(); \
- __disable_interrupt();
-
- #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
- }
-#endif
-
-/*********************************************************************
-*
-* RTT lock configuration for KEIL ARM
-*/
-#ifdef __CC_ARM
- #if (defined __TARGET_ARCH_6S_M)
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- register unsigned char PRIMASK __asm( "primask"); \
- LockState = PRIMASK; \
- PRIMASK = 1u; \
- __schedule_barrier();
-
- #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
- __schedule_barrier(); \
- }
- #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
- #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
- #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
- #endif
- #define SEGGER_RTT_LOCK() { \
- unsigned int LockState; \
- register unsigned char BASEPRI __asm( "basepri"); \
- LockState = BASEPRI; \
- BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
- __schedule_barrier();
-
- #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
- __schedule_barrier(); \
- }
- #endif
-#endif
-
-/*********************************************************************
-*
-* RTT lock configuration fallback
-*/
-#ifndef SEGGER_RTT_LOCK
- #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
-#endif
-
-#ifndef SEGGER_RTT_UNLOCK
- #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
-#endif
-
-#endif
-/*************************** End of file ****************************/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/trcStreamingPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/trcStreamingPort.h
deleted file mode 100755
index be9c569..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/include/trcStreamingPort.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.h
- *
- * The interface definitions for trace streaming ("stream ports").
- * This "stream port" sets up the recorder to use SEGGER RTT as streaming channel.
- *
- * Note that this stream port is more complex than the typical case, since
- * the J-Link interface uses a separate RAM buffer in SEGGER_RTT.c, instead
- * of the default buffer included in the recorder core. The other stream ports
- * offer more typical examples of how to define a custom streaming interface.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_PORT_H
-#define TRC_STREAMING_PORT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_UP
- *
- * Defines the size of the "up" RTT buffer (target -> host) to use for writing
- * the trace data, for RTT buffer 1 or higher.
- *
- * This setting is ignored for RTT buffer 0, which can't be reconfigured
- * in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.
- *
- * Default buffer size for Tracealyzer is 5000 bytes.
- *
- * If you have a stand-alone J-Link probe, the can be decreased to around 1 KB.
- * But integrated J-Link OB interfaces are slower and needs about 5-10 KB,
- * depending on the amount of data produced.
- ******************************************************************************/
-#define TRC_CFG_RTT_BUFFER_SIZE_UP 5000
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_DOWN
- *
- * Defines the size of the "down" RTT buffer (host -> target) to use for reading
- * commands from Tracealyzer, for RTT buffer 1 or higher.
- *
- * Default buffer size for Tracealyzer is 32 bytes.
- *
- * This setting is ignored for RTT buffer 0, which can't be reconfigured
- * in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.
- ******************************************************************************/
-#define TRC_CFG_RTT_BUFFER_SIZE_DOWN 32
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RTT_UP_BUFFER_INDEX
- *
- * Defines the RTT buffer to use for writing the trace data. Make sure that
- * the PC application has the same setting (File->Settings).
- *
- * Default: 1
- *
- * We don't recommend using RTT buffer 0, since mainly intended for terminals.
- * If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h.
- ******************************************************************************/
-#define TRC_CFG_RTT_UP_BUFFER_INDEX 1
-
-/*******************************************************************************
- * Configuration Macro: TRC_CFG_RTT_DOWN_BUFFER_INDEX
- *
- * Defines the RTT buffer to use for reading the trace data. Make sure that
- * the PC application has the same setting (File->Settings).
- *
- * Default: 1
- *
- * We don't recommend using RTT buffer 0, since mainly intended for terminals.
- * If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h.
- ******************************************************************************/
-#define TRC_CFG_RTT_DOWN_BUFFER_INDEX 1
-
-/*******************************************************************************
- * TRC_CFG_RTT_MODE
- * This stream port for J-Link streaming relies on SEGGER RTT, that contains an
- * internal RAM buffer read by the J-Link probes during execution.
- *
- * Possible values:
- * - SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
- * - SEGGER_RTT_MODE_NO_BLOCK_SKIP (default)
- *
- * Using SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL ensure that you get a
- * complete and valid trace. This may however cause blocking if your streaming
- * interface isn't fast enough, which may disturb the real-time behavior.
- *
- * We therefore recommend SEGGER_RTT_MODE_NO_BLOCK_SKIP. In this mode,
- * Tracealyzer will report lost events if the transfer is not
- * fast enough. In that case, try increasing the size of the "up buffer".
- ******************************************************************************/
-#define TRC_CFG_RTT_MODE SEGGER_RTT_MODE_NO_BLOCK_SKIP
-
-#include "SEGGER_RTT_Conf.h"
-#include "SEGGER_RTT.h"
-
-#if (TRC_CFG_RTT_UP_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_UP_BUFFERS)
-#error "TRC_CFG_RTT_UP_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_UP_BUFFERS"
-#endif
-
-#if (TRC_CFG_RTT_DOWN_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_DOWN_BUFFERS)
-#error "TRC_CFG_RTT_DOWN_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_DOWN_BUFFERS"
-#endif
-
-/* If index is defined as 0, the internal RTT buffers will be used instead of this. */
-#if TRC_CFG_RTT_UP_BUFFER_INDEX == 0
-#define TRC_RTT_ALLOC_UP() static char* _TzTraceData = NULL; /* Not actually used. Ignore allocation method. */
-#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
-#else
-#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC
-#define TRC_RTT_ALLOC_UP() char _TzTraceData[TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Static allocation */
-#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
-#endif
-#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC
-#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Dynamic allocation */
-#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_CFG_RTT_BUFFER_SIZE_UP);
-#endif
-#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM
-#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Custom allocation, user needs to call vTraceSetRecorderDataBuffer before vTraceEnable, to assign this */
-#define TRC_STREAM_PORT_MALLOC() /* Not used in custom mode */
-#endif
-#endif
-
-/* Down-buffer. If index is defined as 0, the internal RTT buffers will be used instead of this. */ \
-#if TRC_CFG_RTT_DOWN_BUFFER_INDEX == 0
-#define TRC_RTT_ALLOC_DOWN() static char* _TzCtrlData = NULL; /* Not actually used. Ignore allocation method. */
-#else
-#define TRC_RTT_ALLOC_DOWN() static char _TzCtrlData[TRC_CFG_RTT_BUFFER_SIZE_DOWN]; /* Always static allocation, since usually small. */
-#endif
-
-#define TRC_STREAM_PORT_ALLOCATE_FIELDS() \
- TRC_RTT_ALLOC_UP() /* Macro that will result in proper UP buffer allocation */ \
- TRC_RTT_ALLOC_DOWN() /* Macro that will result in proper DOWN buffer allocation */
-
-int32_t readFromRTT(void* ptrData, uint32_t size, int32_t* ptrBytesRead);
-
-int32_t writeToRTT(void* ptrData, uint32_t size, int32_t* ptrBytesWritten);
-
-
-#define TRC_STREAM_PORT_INIT() \
- TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \
- SEGGER_RTT_ConfigUpBuffer(TRC_CFG_RTT_UP_BUFFER_INDEX, "TzData", _TzTraceData, TRC_CFG_RTT_BUFFER_SIZE_UP, TRC_CFG_RTT_MODE ); \
- SEGGER_RTT_ConfigDownBuffer(TRC_CFG_RTT_DOWN_BUFFER_INDEX, "TzCtrl", _TzCtrlData, TRC_CFG_RTT_BUFFER_SIZE_DOWN, TRC_CFG_RTT_MODE);
-
-/* Important for the J-Link port, in most other ports this can be skipped (default is 1) */
-#define TRC_STREAM_PORT_USE_INTERNAL_BUFFER 0
-
-#define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesWritten) writeToRTT(_ptrData, _size, _ptrBytesWritten)
-
-#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) readFromRTT(_ptrData, _size, _ptrBytesRead)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/trcStreamingPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/trcStreamingPort.c
deleted file mode 100755
index 29b7b22..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/Jlink_RTT/trcStreamingPort.c
+++ /dev/null
@@ -1,44 +0,0 @@
-
-#include "trcRecorder.h"
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-int32_t readFromRTT(void* ptrData, uint32_t size, int32_t* ptrBytesRead)
-{
- uint32_t bytesRead = 0;
-
- if (SEGGER_RTT_HASDATA(TRC_CFG_RTT_DOWN_BUFFER_INDEX))
- {
- bytesRead = SEGGER_RTT_Read((TRC_CFG_RTT_DOWN_BUFFER_INDEX), (char*)ptrData, size);
-
- if (ptrBytesRead != NULL)
- *ptrBytesRead = (int32_t)bytesRead;
-
- if (bytesRead != size)
- {
- return -1;
- }
-
- }
-
- return 0;
-}
-
-int32_t writeToRTT(void* ptrData, uint32_t size, int32_t* ptrBytesWritten)
-{
- uint32_t bytesWritten = SEGGER_RTT_Write((TRC_CFG_RTT_UP_BUFFER_INDEX), (const char*)ptrData, size);
-
- if (ptrBytesWritten != NULL)
- *ptrBytesWritten = (int32_t)bytesWritten;
-
- if (bytesWritten != size)
- {
- return -1;
- }
-
- return 0;
-}
-
-#endif
-#endif
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/Readme-Streamport.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/Readme-Streamport.txt
deleted file mode 100755
index 0239366..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/Readme-Streamport.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Tracealyzer Stream Port for TCP/IP (lwIP example)
--------------------------------------------------
-
-This directory contains a "stream port" for the Tracealyzer recorder library,
-i.e., the specific code needed to use a particular interface for streaming a
-Tracealyzer RTOS trace. The stream port is defined by a set of macros in
-trcStreamingPort.h, found in the "include" directory.
-
-This particular stream port targets TCP/IP. This example assumes lwIP but is
-easy to modify for other TCP/IP stacks.
-
-To use this stream port, make sure that include/trcStreamingPort.h is found
-by the compiler (i.e., add this folder to your project's include paths) and
-add all included source files to your build. Make sure no other versions of
-trcStreamingPort.h are included by mistake!
-
-Note that lwIP is not included, but assumed to exist in the project already.
-
-See also http://percepio.com/2016/10/05/rtos-tracing.
-
-Percepio AB
-www.percepio.com
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/include/trcStreamingPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/include/trcStreamingPort.h
deleted file mode 100755
index 992e744..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/include/trcStreamingPort.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.h
- *
- * The interface definitions for trace streaming ("stream ports").
- * This "stream port" sets up the recorder to use TCP/IP as streaming channel.
- * The example is for lwIP.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_PORT_H
-#define TRC_STREAMING_PORT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead);
-
-int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten);
-
-#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcTcpRead(_ptrData, _size, _ptrBytesRead)
-
-#define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesSent) trcTcpWrite(_ptrData, _size, _ptrBytesSent)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/trcStreamingPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/trcStreamingPort.c
deleted file mode 100755
index 058e854..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/TCPIP/trcStreamingPort.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.c
- *
- * Supporting functions for trace streaming, used by the "stream ports"
- * for reading and writing data to the interface.
- * Existing ports can easily be modified to fit another setup, e.g., a
- * different TCP/IP stack, or to define your own stream port.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#include "trcRecorder.h"
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-/* TCP/IP includes - for lwIP in this case */
-#include "lwip/tcpip.h"
-#include "lwip/sockets.h"
-
-int errno;
-
-#define TRC_TCPIP_PORT 12000
-
-int sock = -1, new_sd = -1;
-int flags = 0;
-int remoteSize;
-struct sockaddr_in address, remote;
-
-int32_t trcSocketSend( void* data, int32_t size, int32_t* bytesWritten )
-{
- if (new_sd < 0)
- return -1;
-
- if (bytesWritten == NULL)
- return -1;
-
- *bytesWritten = send( new_sd, data, size, 0 );
- if (*bytesWritten < 0)
- {
- /* EWOULDBLOCK may be expected when buffers are full */
- if (errno != 0 && errno != EWOULDBLOCK)
- {
- closesocket(new_sd);
- new_sd = -1;
- return -1;
- }
- else
- *bytesWritten = 0;
- }
-
- return 0;
-}
-
-int32_t trcSocketReceive( void* data, int32_t size, int32_t* bytesRead )
-{
- if (new_sd < 0)
- return -1;
-
- *bytesRead = recv( new_sd, data, size, 0 );
- if ( *bytesRead < 0 )
- {
- /* EWOULDBLOCK may be expected when there is no data to receive */
- if (errno != 0 && errno != EWOULDBLOCK)
- {
- closesocket(new_sd);
- new_sd = -1;
- return -1;
- }
- else
- *bytesRead = 0;
- }
-
- return 0;
-}
-
-int32_t trcSocketInitializeListener()
-{
- if (sock >= 0)
- return 0;
-
- sock = lwip_socket(AF_INET, SOCK_STREAM, 0);
-
- if (sock < 0)
- return -1;
-
- address.sin_family = AF_INET;
- address.sin_port = htons( TRC_TCPIP_PORT );
- address.sin_addr.s_addr = INADDR_ANY;
-
- if (bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0)
- {
- closesocket(sock);
- sock = -1;
- return -1;
- }
-
- if (lwip_listen(sock, 5) < 0)
- {
- closesocket(sock);
- sock = -1;
- return -1;
- }
-
- return 0;
-}
-
-int32_t trcSocketAccept()
-{
- if (sock < 0)
- return -1;
-
- if (new_sd >= 0)
- return 0;
-
- remoteSize = sizeof( remote );
- new_sd = accept( sock, (struct sockaddr *)&remote, (socklen_t*)&remoteSize );
-
- flags = fcntl( new_sd, F_GETFL, 0 );
- fcntl( new_sd, F_SETFL, flags | O_NONBLOCK );
-
- if( new_sd < 0 )
- {
- closesocket(new_sd);
- new_sd = -1;
- closesocket(sock);
- sock = -1;
- return -1;
- }
-
- return 0;
-}
-/************** MODIFY THE ABOVE PART TO USE YOUR TPC/IP STACK ****************/
-
-int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten)
-{
- return trcSocketSend(data, size, ptrBytesWritten);
-}
-
-int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead)
-{
- trcSocketInitializeListener();
-
- trcSocketAccept();
-
- return trcSocketReceive(data, size, ptrBytesRead);
-}
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/Readme-Streamport.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/Readme-Streamport.txt
deleted file mode 100755
index a231518..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/Readme-Streamport.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-Tracealyzer Stream Port for USB CDC (STM32 example)
----------------------------------------------------
-
-This directory contains a "stream port" for the Tracealyzer recorder library,
-i.e., the specific code needed to use a particular interface for streaming a
-Tracealyzer RTOS trace. The stream port is defined by a set of macros in
-trcStreamingPort.h, found in the "include" directory.
-
-This particular stream port targets USB CDC. This is an example for the STM32 USB
-stack (from the STM32CubeMX code generation tool, v1.4.1) and has been tested on
-a STM32F767ZI device on a Nucleo board. See this blog post:
-
-http://percepio.com/2017/02/03/usb-trace-streaming-st-nucleo-f767zi-board/
-
-However, it should be straight-forward to modify this for other USB stacks.
-
-To use this stream port, make sure that include/trcStreamingPort.h is found
-by the compiler (i.e., add this folder to your project's include paths) and
-add all included source files to your build. Make sure no other versions of
-trcStreamingPort.h are included by mistake!
-
-Note that the USB stack not included, but assumed to exist in the project already.
-
-See also http://percepio.com/2016/10/05/rtos-tracing.
-
-Percepio AB
-www.percepio.com
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/include/trcStreamingPort.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/include/trcStreamingPort.h
deleted file mode 100755
index 663e8b2..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/include/trcStreamingPort.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingPort.h
- *
- * The interface definitions for trace streaming ("stream ports").
- * This "stream port" sets up the recorder to use USB CDC as streaming channel.
- * The example is for STM32 using STM32Cube.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#ifndef TRC_STREAMING_PORT_H
-#define TRC_STREAMING_PORT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */
-#include "usb_device.h"
-#include "usbd_cdc.h"
-#include "usbd_CDC_if.h"
-#include "usb_device.h"
-
-/* Tested on STM32 devices using Keil/CMSIS USB stack */
-
-extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
-
-uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
-
-int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes);
-
-int32_t trcCDCTransmit(void* data, uint32_t size, int32_t * noOfBytesSent );
-
-#define TRC_STREAM_PORT_INIT() \
- MX_USB_DEVICE_Init(); \
- TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */
-
-#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcCDCReceive(_ptrData, _size, _ptrBytesRead)
-
-#define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesSent) trcCDCTransmit(_ptrData, _size, _ptrBytesSent)
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TRC_STREAMING_PORT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/trcStreamingPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/trcStreamingPort.c
deleted file mode 100755
index 256c59b..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/USB_CDC/trcStreamingPort.c
+++ /dev/null
@@ -1,246 +0,0 @@
-
-#include "trcRecorder.h"
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-#include "stdint.h"
-
-/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */
-#include "usb_device.h"
-#include "usbd_cdc.h"
-#include "usbd_CDC_if.h"
-#include "usb_device.h"
-
-#define BUFSIZE 64
-
-typedef struct{
- uint32_t idx;
- uint8_t data[BUFSIZE];
-}recBuf;
-
-/* Define size for the receive and transmit buffer over CDC */
-#define APP_RX_DATA_SIZE 8
-#define APP_TX_DATA_SIZE 64
-
-/* Received Data over USB are stored in this buffer */
-uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
-
-/* Send Data over USB CDC are stored in this buffer */
-uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
-
-extern USBD_HandleTypeDef hUsbDeviceFS;
-
-extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
-
-recBuf commandBuffer;
-
-static int8_t CDC_Init_FS (void);
-static int8_t CDC_DeInit_FS (void);
-static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length);
-static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len);
-
-USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
-{
- CDC_Init_FS,
- CDC_DeInit_FS,
- CDC_Control_FS,
- CDC_Receive_FS
-};
-
-/* Private functions ---------------------------------------------------------*/
-/**
- * @brief CDC_Init_FS
- * Initializes the CDC media low layer over the FS USB IP
- * @param None
- * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Init_FS(void)
-{
- /* Set Application Buffers */
- USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
- USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
- return (USBD_OK);
-}
-
-/**
- * @brief CDC_DeInit_FS
- * DeInitializes the CDC media low layer
- * @param None
- * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_DeInit_FS(void)
-{
- return (USBD_OK);
-}
-
-/**
- * @brief CDC_Control_FS
- * Manage the CDC class requests
- * @param cmd: Command code
- * @param pbuf: Buffer containing command data (request parameters)
- * @param length: Number of data to be sent (in bytes)
- * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
-{
- switch (cmd)
- {
- case CDC_SEND_ENCAPSULATED_COMMAND:
- break;
-
- case CDC_GET_ENCAPSULATED_RESPONSE:
- break;
-
- case CDC_SET_COMM_FEATURE:
- break;
-
- case CDC_GET_COMM_FEATURE:
- break;
-
- case CDC_CLEAR_COMM_FEATURE:
- break;
-
- /*******************************************************************************/
- /* Line Coding Structure */
- /*-----------------------------------------------------------------------------*/
- /* Offset | Field | Size | Value | Description */
- /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
- /* 4 | bCharFormat | 1 | Number | Stop bits */
- /* 0 - 1 Stop bit */
- /* 1 - 1.5 Stop bits */
- /* 2 - 2 Stop bits */
- /* 5 | bParityType | 1 | Number | Parity */
- /* 0 - None */
- /* 1 - Odd */
- /* 2 - Even */
- /* 3 - Mark */
- /* 4 - Space */
- /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
- /*******************************************************************************/
- case CDC_SET_LINE_CODING:
- break;
-
- case CDC_GET_LINE_CODING:
- break;
-
- case CDC_SET_CONTROL_LINE_STATE:
- break;
-
- case CDC_SEND_BREAK:
- break;
-
- default:
- break;
- }
- return (USBD_OK);
-}
-
-/**
- * @brief CDC_Receive_FS
- * Data received over USB OUT endpoint are sent over CDC interface
- * through this function.
- *
- * @note
- * This function will block any OUT packet reception on USB endpoint
- * until exiting this function. If you exit this function before transfer
- * is complete on CDC interface (i.e. using DMA controller) it will result
- * in receiving more data while previous ones are still not sent.
- *
- * @param Buf: Buffer of data to be received
- * @param Len: Number of data received (in bytes)
- * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
-{
- for( uint32_t i=0;i<* Len;i++)
- {
- commandBuffer.data[commandBuffer.idx]=Buf[i];
- commandBuffer.idx++;
- }
- USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
- USBD_CDC_ReceivePacket(&hUsbDeviceFS);
-
- return (USBD_OK);
-}
-
-/**
- * @brief CDC_Transmit_FS
- * Data send over USB IN endpoint are sent over CDC interface
- * through this function.
- * @note
- *
- *
- * @param Buf: Buffer of data to be send
- * @param Len: Number of data to be send (in bytes)
- * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
- */
-uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
-{
- uint8_t result = USBD_OK;
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
- if (hcdc->TxState != 0){
- return USBD_BUSY;
- }
- USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
- result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
- return result;
-}
-
-/* The READ function, used in trcStreamingPort.h */
-int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes)
-{
- uint32_t i,diff;
-
- if(commandBuffer.idx>0)
- {
- if (size >= commandBuffer.idx) // more than what is stored, number of bytes will be .idx
- {
- memcpy(data,commandBuffer.data, commandBuffer.idx);
- *NumBytes=commandBuffer.idx;
- commandBuffer.idx=0; // Make the buffer ready for a new command
- }
- else //If some data in the buffer is not read
- {
- diff = commandBuffer.idx-size;
- memcpy(data,commandBuffer.data, size);
- for(i=0;i v4.1.5
-
-- Fixed a bug in the ITM stream port, that required Port 0 to be enabled.
-- Added missing include of stdio.h (needed by vTraceConsoleChannelPrintF).
-- Moved standard includes from trcRecorder.h into the .c files needing them.
-
--------------------------------------------------------------------------------
-
-Changes, v4.1.2 -> v4.1.4
-
-- Fixed a compile error when certain FreeRTOS settings were used
-- Disabled filter support for FreeRTOS v7.3 since it uses "char" for object id
-
--------------------------------------------------------------------------------
-
-Changes, v4.1.0 -> v4.1.2
-
-- Added vTraceConsoleChannelPrintF(...)
-
--------------------------------------------------------------------------------
-
-Changes, v4.0.3 -> v4.1.0
-
-- Improved performance of User Events
-- Fixed handling of format strings ending with '%'
-- Improved handling of creative user configuration macros
-
--------------------------------------------------------------------------------
-
-Changes, v4.0.2 -> v4.0.3
-
-- Minor fix for TCP/IP stream port.
-- Corrected default RTT mode setting.
-
--------------------------------------------------------------------------------
-
-Changes, v4.0.1 -> v4.0.2
-
-- Memory allocation trace events now ignore filters.
-
--------------------------------------------------------------------------------
-
-Changes, v4.0.0 -> v4.0.1
-
-- Minor fixes to default values.
-
--------------------------------------------------------------------------------
-
-Changes, v3.3.0 -> v4.0.0
-
-- Fixed some issues with filters.
-
--------------------------------------------------------------------------------
-
-Changes, v3.2.0 -> v3.3.0
-
-- Added support for FreeRTOS v10, including the new object types Message Buffer
- and Stream Buffer.
-
-- Improved the object-level filtering to also support Timer, Event Group,
- Message Buffer and Stream Buffer objects.
-
-- Fixed a few remaining build problems with older FreeRTOS versions (v7.x).
-
-- vTraceStoreISRBegin now reports an error on invalid handles, i.e., if the
- initialization of the handle (xTraceSetISRProperties) had not been made.
-
--------------------------------------------------------------------------------
-
-Changes, v3.1.2 -> v3.2.0
-
-- Added new filtering system - that works in both snapshot and streaming mode.
- Filtering was previously not supported in streaming mode, but can be very
- useful for slower streaming interfaces. By exluding irrelevant events, the
- amount of data produced can be reduced a lot.
-
- * New functions vTraceSetFilterGroup and vTraceSetFilterMask allows for
- excluding all events from specific objects (like a semaphore or queue).
-
- * Added new "generic" filters (preprocessor level) to trcConfig.h, that
- exclude all events of a particular types.
- - TRC_CFG_INCLUDE_NOTIFY_EVENTS
- - TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
- - TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
- - TRC_CFG_INCLUDE_TIMER_EVENTS
-
- * Upgraded some previous filters from "Snapshot only" to the Common API
- and thereby moved them from trcSnapshotConfig.h to trcConfig.h.
- - TRC_CFG_SCHEDULING_ONLY
- - TRC_CFG_INCLUDE_MEMMANG_EVENTS
- - TRC_CFG_INCLUDE_USER_EVENTS
- - TRC_CFG_INCLUDE_ISR_TRACING
- - TRC_CFG_INCLUDE_READY_EVENTS
- - TRC_CFG_INCLUDE_OSTICK_EVENTS
-
- * Removed the old filter system from trcSnapshotRecorder.c.
-
-- Improved streaming interface - Now only two (2) macros are needed to be
- defined in most cases, read and write. This makes it a lot easier to make
- custom stream ports.
-
- * Many definitions that were identical in most stream ports, have been
- replaced by default definitions in the recorder core. If needed, they
- can be overriden by custom definitions in trcStreamingPort.h.
-
- * Stream ports are now assumed to use recorder's internal event buffer.
- Other stream ports that writes directly to the streaming interface
- (like J-Link) should define TRC_STREAM_PORT_USE_INTERNAL_BUFFER
- as zero (0) to make it work correctly.
-
- * Macro TRC_STREAM_PORT_PERIODIC_SEND_DATA has been replaced by
- TRC_STREAM_PORT_WRITE_DATA. Together with TRC_STREAM_PORT_READ_DATA,
- this is all that is necessary for a typical stream port.
-
- * Return values from the stream port macros READ_DATA and WRITE_DATA are
- now checked. Expects 0 on success, anything else produces a warning
- that can be retrived using xTraceGetLastError() and also seen in
- Tracealyzer if a trace was produced.
-
- * Stream ports should no longer call prvPagedEventBufferInit explicitly
- (e.g. in TRC_STREAM_PORT_ON_TRACE_BEGIN). This is now called
- automatically if TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1.
-
- * Macros TRC_STREAM_PORT_ON_TRACE_BEGIN and TRC_STREAM_PORT_ON_TRACE_END
- are now unused by default and don't need to be defined.
- You can however use them to hook in some own function at these events.
-
-- Added two new stream ports
-
- * TCPIP-Win32: allows for testing the streaming on Windows ports of your
- RTOS, using Winsock.
-
- * File: example of streaming to a local file system (tested on Windows,
- but easy to modify).
-
-- Added support for FreeRTOS v9.0.1
-
- * Replaced FreeRTOS version code TRC_FREERTOS_VERSION_9_X with
- - TRC_FREERTOS_VERSION_9_0_0
- - TRC_FREERTOS_VERSION_9_0_1
-
- * Using TRC_FREERTOS_VERSION_9_X is no longer allowed.
-
-- Added additional events for xQueuePeek, for blocking and timeouts events.
-
-- Added event for traceTIMER_EXPIRED, showing when the timer callback
- function is called.
-
-- Improved diagnostics in streaming mode, in case of errors in the recorder.
-
- * Added prvTraceWarning() - registers a "warning" error code, without
- stopping the recorder. Called if READ_DATA or WRITE_DATA returns a
- non-zero value, and in several other cases where the recorder
- configuration is incorrect (e.g., too small symbol table).
-
- * Added several new warning codes (PSF_WARNING_XYZ), corresponding to the
- issues detected by prvCheckRecorderStatus.
-
- * Fixed duplicate definitions of warning messages, so the warnings reported
- to Tracealyzer are the same as those provided in xTraceGetLastError().
-
- * Added better explainations of warning/error messages in the body of
- xTraceGetLastError (in streaming mode).
-
-- Added xTraceIsRecordingEnabled() to Common API.
-
-- Added "unofficial" hardware port for Altera Nios-II.
- This is a user contribition, not yet verified by Percerpio.
-
-- Fixed bug in vTraceEnable - option TRC_START_AWAIT_HOST was ignored if already initialized.
-
-- Fixed a few remaining compiler warnings.
-
-- Changed order of some settings in trcConfig.h - moved advanced stuff to the
- bottom.
-
-- Removed SEGGER_RTT_Printf.c from the J-Link stream port since not required
- for Tracealyzer.
-
--------------------------------------------------------------------------------
-
-Changes, v3.1.1 -> v3.1.2
-- Fixed two bugs related to User Events, one in vTracePrintF and other in vTracePrint.
-
-- Fixed a build problem related to a single reference of the old FreeRTOS type "xTaskHandle", in trcKernelPort.c.
- Changed to "TaskHandle_t", unless if using an older FreeRTOS kernel or the "compatibility mode".
-
-- Removed traceCREATE_MUTEX hook for FreeRTOS v9 or later (no longer required)
-
-- Updated the User Manual regarding snapshot trace via IAR Embedded Workbench.
-
-- Renamed vTraceGetTraceBuffer to xTraceGetTraceBuffer, since returning a pointer.
-
--------------------------------------------------------------------------------
-
-Changes, v3.1.0 -> v3.1.1
-
-After the major changes in the v3.1.0 trace recorder library, this update
-corrects a number of minor issues. Only minor functional improvements.
-
-- You can now use TRC_ALLOC_CUSTOM_BUFFER to declare a trace buffer on a custom
- location (using linker directives).
- The related function vTraceSetRecorderDataBuffer has been promoted to the
- Common API (previously only supported in snapshot mode, but custom allocation
- is now generally supported also in streaming mode).
-
-- Removed TRC_CFG_USE_LINKER_PRAGMA. No longer necessary thanks to the custom
- allocation mode.
-
-- Added support for timestamping from custom periodic timers, required for
- accurate timestamping on Cortex-M0/M0+ devices when using tickless idle.
- Only for streaming mode so far. See TRC_CUSTOM_TIMER_INCR / DECR.
-
-- ARM Cortex-M port: Made sure the DWT unit is initialized properly, in case
- the debugger doesn't handle this.
-
-- ARM Cortex-M port: Added possibility to use Systick timestamping also on
- Cortex-M3/M4/M7 devices (that otherwise use DWT timestamping by default).
- To use this option, define the macro TRC_CFG_ARM_CM_USE_SYSTICK.
-
-- J-Link streaming: The default RTT buffer has been changed from 0 to 1.
-
-- J-Link streaming: The RTT buffer settings for buffer 1 and higher, are now
- found in trcStreamingPort.h. Note: These settings don't apply to buffer 0.
-
-- vTracePrint has been optimized for better performance in string logging.
-
-- Minor performance improvement related to symbol table transfer in streaming mode.
-
-- Timer names now registered also in streaming mode.
-
-- Timer start and stop event are now traced.
-
-- Implemented support for queue registry (traceQUEUE_REGISTRY_ADD) also for streaming.
-
-- Fixed a bug related to repeated calls of vTraceEnable.
-
-- Fixed a bug where task-switches seemed to occur even though the scheduler was disabled.
-
-- Renamed HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48, added prefix TRC.
-
-- Fixed several language issues in the comments and documentation.
-
-- Fixed several minor issues and warnings from different compilers
- (including PowerPC/gcc) and configurations.
-
--------------------------------------------------------------------------------
-
-Changes, v3.0.9 -> v3.1.0
-
-- Merge of previously separated snapshot and streaming recorders into a single
- recorder supporting both streaming and snapshot as different modes.
-
-- New common API for supporting both streaming and snapshot modes.
-
-- New integration guide, see the User Manual.
-
-- Major improvement of API documentation in source files and User Manual.
-
-- New concept of "stream ports", giving a better structure defining streaming
- interfaces, and restructured the J-Link and TCP/IP streaming as stream ports.
-
-- Added a stream port for USB CDC connections, with STM32 as example.
- Since Tracealyzer now can receive serial data on Windows COM ports, this is
- really easy to use.
-
-- Added a warning (#error) for cases where FreeRTOS tickless idle mode is used
- together with timestamping using SysTick or other periodic interrupt timers,
- Tracing with tickless idle requires an independent time source to correctly
- capture the length of the idle periods.
-
-- Major changes in the recorder API. Important examples are:
-
- * Some configuration macros have changed names, e.g. for "hardware port".
- Make sure to remove any old "trcConfig.h" files if upgrading from an
- earlier version!
-
- * Recorder configuration in trcConfig.h has been minimized and now only
- includes the important settings that are independent of recorder mode.
- Advanced settings for each mode are found in trcSnapshotConfig.h and
- trcStreamingConfig.h.
-
- * vTraceEnable replaces Trace_Init and vTraceInitTraceData, as well as
- vTraceStart and uiTraceStart.
-
- * vTraceStop now part of the common API and thereby available also in
- streaming. And since vTraceEnable can start the streaming directly
- you have the option control the tracing from target, e.g., for
- streaming to a device file system.
-
- * vTraceStoreKernelObjectName from old streaming recorder has been replaced
- by vTraceSetQueueName, vTraceSetSemaphoreName, etc.
-
- * vTraceSetISRProperties now returns a "traceHandle" that should be passed as
- parameter to vTraceStoreISRBegin and vTraceStoreISREnd.
-
- * xTraceRegisterString has replaced the old functions xTraceOpenLabel and
- vTraceStoreUserEventChannelName. This now returns a "traceString" for use
- as "channel" parameter in vTracePrintF, and in other places where strings
- are stored.
-
- * Removed vTraceStoreISREndManual and vTraceStoreISREndAuto, use
- vTraceStoreISREnd instead.
-
- * Renamed the functions for saving User Events in a separate buffer:
- - xTraceRegisterChannelFormat -> xTraceRegisterUBChannel
- - vTraceChannelPrintF -> vTraceUBData
- - vTraceChannelUserEvent -> vTraceUBEvent
-
-
--------------------------------------------------------------------------------
-Copyright Percepio AB, 2018.
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcKernelPort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcKernelPort.c
deleted file mode 100755
index a2b3140..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcKernelPort.c
+++ /dev/null
@@ -1,833 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcKernelPort.c
- *
- * The FreeRTOS-specific parts of the trace recorder
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#include "FreeRTOS.h"
-
-#if (!defined(TRC_USE_TRACEALYZER_RECORDER) && configUSE_TRACE_FACILITY == 1)
-#error Trace Recorder: You need to include trcRecorder.h at the end of your FreeRTOSConfig.h!
-#endif
-
-#if (defined(TRC_USE_TRACEALYZER_RECORDER) && TRC_USE_TRACEALYZER_RECORDER == 1)
-
-#ifndef TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
- /* TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS is missing in trcConfig.h. */
-#error "TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS must be defined in trcConfig.h."
-#endif
-
-#ifndef TRC_CFG_INCLUDE_TIMER_EVENTS
- /* TRC_CFG_INCLUDE_TIMER_EVENTS is missing in trcConfig.h. */
-#error "TRC_CFG_INCLUDE_TIMER_EVENTS must be defined in trcConfig.h."
-#endif
-
-#ifndef TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
- /* TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS is missing in trcConfig.h. */
-#error "TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS must be defined in trcConfig.h."
-#endif
-
-#ifndef TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
- /* TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS is missing in trcConfig.h. Define this as 1 if using FreeRTOS v10 or later and like to trace stream buffer or message buffer events, otherwise 0. */
-#error "TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS must be defined in trcConfig.h."
-#endif
-
-#if (configUSE_TICKLESS_IDLE != 0 && (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))
- /*
- The below error message is to alert you on the following issue:
-
- The hardware port selected in trcConfig.h uses the operating system timer for the
- timestamping, i.e., the periodic interrupt timer that drives the OS tick interrupt.
-
- When using "tickless idle" mode, the recorder needs an independent time source in
- order to correctly record the durations of the idle times. Otherwise, the trace may appear
- to have a different length than in reality, and the reported CPU load is also affected.
-
- You may override this warning by defining the TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING
- macro in your trcConfig.h file. But then the time scale may be incorrect during
- tickless idle periods.
-
- To get this correct, override the default timestamping by setting TRC_CFG_HARDWARE_PORT
- in trcConfig.h to TRC_HARDWARE_PORT_APPLICATION_DEFINED and define the HWTC macros
- accordingly, using a free running counter or an independent periodic interrupt timer.
- See trcHardwarePort.h for details.
-
- For ARM Cortex-M3, M4 and M7 MCUs this is not an issue, since the recorder uses the
- DWT cycle counter for timestamping in these cases.
- */
-
- #ifndef TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING
- #error Trace Recorder: This timestamping mode is not recommended with Tickless Idle.
- #endif
-#endif /* (configUSE_TICKLESS_IDLE != 0 && (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)) */
-
-#include "task.h"
-#include "queue.h"
-
-#if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-/* If the project does not include the FreeRTOS timers, TRC_CFG_INCLUDE_TIMER_EVENTS must be set to 0 */
-#include "timers.h"
-#endif /* (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-/* If the project does not include the FreeRTOS event groups, TRC_CFG_INCLUDE_TIMER_EVENTS must be set to 0 */
-#include "event_groups.h"
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-/* If the project does not include the FreeRTOS stream buffers, TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS must be set to 0 */
-#include "stream_buffer.h"
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-uint32_t prvTraceGetQueueNumber(void* handle);
-
-#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X)
-
-extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );
-extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );
-extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );
-
-uint32_t prvTraceGetQueueNumber(void* handle)
-{
- return (uint32_t)ucQueueGetQueueNumber(handle);
-}
-#else
-uint32_t prvTraceGetQueueNumber(void* handle)
-{
- return (uint32_t)uxQueueGetQueueNumber(handle);
-}
-#endif /* (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X) */
-
-uint8_t prvTraceGetQueueType(void* handle)
-{
- // This is either declared in header file in FreeRTOS 8 and later, or as extern above
- return ucQueueGetQueueType(handle);
-}
-
-/* Tasks */
-uint16_t prvTraceGetTaskNumberLow16(void* handle)
-{
- return TRACE_GET_LOW16(uxTaskGetTaskNumber(handle));
-}
-
-uint16_t prvTraceGetTaskNumberHigh16(void* handle)
-{
- return TRACE_GET_HIGH16(uxTaskGetTaskNumber(handle));
-}
-
-void prvTraceSetTaskNumberLow16(void* handle, uint16_t value)
-{
- vTaskSetTaskNumber(handle, TRACE_SET_LOW16(uxTaskGetTaskNumber(handle), value));
-}
-
-void prvTraceSetTaskNumberHigh16(void* handle, uint16_t value)
-{
- vTaskSetTaskNumber(handle, TRACE_SET_HIGH16(uxTaskGetTaskNumber(handle), value));
-}
-
-uint16_t prvTraceGetQueueNumberLow16(void* handle)
-{
- return TRACE_GET_LOW16(prvTraceGetQueueNumber(handle));
-}
-
-uint16_t prvTraceGetQueueNumberHigh16(void* handle)
-{
- return TRACE_GET_HIGH16(prvTraceGetQueueNumber(handle));
-}
-
-void prvTraceSetQueueNumberLow16(void* handle, uint16_t value)
-{
- vQueueSetQueueNumber(handle, TRACE_SET_LOW16(prvTraceGetQueueNumber(handle), value));
-}
-
-void prvTraceSetQueueNumberHigh16(void* handle, uint16_t value)
-{
- vQueueSetQueueNumber(handle, TRACE_SET_HIGH16(prvTraceGetQueueNumber(handle), value));
-}
-
-#if (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-
-uint16_t prvTraceGetTimerNumberLow16(void* handle)
-{
- return TRACE_GET_LOW16(uxTimerGetTimerNumber(handle));
-}
-
-uint16_t prvTraceGetTimerNumberHigh16(void* handle)
-{
- return TRACE_GET_HIGH16(uxTimerGetTimerNumber(handle));
-}
-
-void prvTraceSetTimerNumberLow16(void* handle, uint16_t value)
-{
- vTimerSetTimerNumber(handle, TRACE_SET_LOW16(uxTimerGetTimerNumber(handle), value));
-}
-
-void prvTraceSetTimerNumberHigh16(void* handle, uint16_t value)
-{
- vTimerSetTimerNumber(handle, TRACE_SET_HIGH16(uxTimerGetTimerNumber(handle), value));
-}
-#endif /* (TRC_CFG_INCLUDE_TIMER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-
-uint16_t prvTraceGetEventGroupNumberLow16(void* handle)
-{
- return TRACE_GET_LOW16(uxEventGroupGetNumber(handle));
-}
-
-uint16_t prvTraceGetEventGroupNumberHigh16(void* handle)
-{
- return TRACE_GET_HIGH16(uxEventGroupGetNumber(handle));
-}
-
-void prvTraceSetEventGroupNumberLow16(void* handle, uint16_t value)
-{
- vEventGroupSetNumber(handle, TRACE_SET_LOW16(uxEventGroupGetNumber(handle), value));
-}
-
-void prvTraceSetEventGroupNumberHigh16(void* handle, uint16_t value)
-{
- vEventGroupSetNumber(handle, TRACE_SET_HIGH16(uxEventGroupGetNumber(handle), value));
-}
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-
-uint16_t prvTraceGetStreamBufferNumberLow16(void* handle)
-{
- return TRACE_GET_LOW16(uxStreamBufferGetStreamBufferNumber(handle));
-}
-
-uint16_t prvTraceGetStreamBufferNumberHigh16(void* handle)
-{
- return TRACE_GET_HIGH16(uxStreamBufferGetStreamBufferNumber(handle));
-}
-
-void prvTraceSetStreamBufferNumberLow16(void* handle, uint16_t value)
-{
- vStreamBufferSetStreamBufferNumber(handle, TRACE_SET_LOW16(uxStreamBufferGetStreamBufferNumber(handle), value));
-}
-
-void prvTraceSetStreamBufferNumberHigh16(void* handle, uint16_t value)
-{
- vStreamBufferSetStreamBufferNumber(handle, TRACE_SET_HIGH16(uxStreamBufferGetStreamBufferNumber(handle), value));
-}
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-static void* pCurrentTCB = NULL;
-#if (defined(configENABLE_BACKWARD_COMPATIBILITY) && configENABLE_BACKWARD_COMPATIBILITY == 0)
-/* We're explicitly not using compatibility mode */
-static TaskHandle_t HandleTzCtrl = NULL; /* TzCtrl task TCB */
-#else
-/* We're using compatibility mode, or we're running an old kernel */
-static xTaskHandle HandleTzCtrl = NULL; /* TzCtrl task TCB */
-#endif
-
-#if defined(configSUPPORT_STATIC_ALLOCATION)
-#if (configSUPPORT_STATIC_ALLOCATION == 1)
-static StackType_t stackTzCtrl[TRC_CFG_CTRL_TASK_STACK_SIZE];
-static StaticTask_t tcbTzCtrl;
-#endif
-#endif
-
-/* Monitored by TzCtrl task, that give warnings as User Events */
-extern volatile uint32_t NoRoomForSymbol;
-extern volatile uint32_t NoRoomForObjectData;
-extern volatile uint32_t LongestSymbolName;
-extern volatile uint32_t MaxBytesTruncated;
-
-/* Keeps track of previous values, to only react on changes. */
-static uint32_t NoRoomForSymbol_last = 0;
-static uint32_t NoRoomForObjectData_last = 0;
-static uint32_t LongestSymbolName_last = 0;
-static uint32_t MaxBytesTruncated_last = 0;
-
-/* User Event Channel for giving warnings regarding NoRoomForSymbol etc. */
-traceString trcWarningChannel;
-
-#define TRC_PORT_MALLOC(size) pvPortMalloc(size)
-
-TRC_STREAM_PORT_ALLOCATE_FIELDS()
-
-/* Called by TzCtrl task periodically (Normally every 100 ms) */
-static void prvCheckRecorderStatus(void);
-
-extern void prvTraceWarning(int errCode);
-
-/* The TzCtrl task - receives commands from Tracealyzer (start/stop) */
-static portTASK_FUNCTION( TzCtrl, pvParameters );
-
-/*******************************************************************************
- * vTraceEnable
- *
- * Function that enables the tracing and creates the control task. It will halt
- * execution until a Start command has been received if haltUntilStart is true.
- *
- ******************************************************************************/
-void vTraceEnable(int startOption)
-{
- int32_t bytes = 0;
- int32_t status;
- extern uint32_t RecorderEnabled;
- TracealyzerCommandType msg;
-
- /* Only do this first time...*/
- if (HandleTzCtrl == NULL)
- {
- TRC_STREAM_PORT_INIT();
-
- /* Note: Requires that TRC_CFG_INCLUDE_USER_EVENTS is 1. */
- trcWarningChannel = xTraceRegisterString("Warnings from Recorder");
-
- /* Creates the TzCtrl task - receives trace commands (start, stop, ...) */
- #if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
- HandleTzCtrl = xTaskCreateStatic(TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, stackTzCtrl, &tcbTzCtrl);
- #else
- xTaskCreate( TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, &HandleTzCtrl );
- #endif
-
- if (HandleTzCtrl == NULL)
- {
- prvTraceError(PSF_ERROR_TZCTRLTASK_NOT_CREATED);
- }
- }
-
- if (startOption == TRC_START_AWAIT_HOST)
- {
- /* We keep trying to read commands until the recorder has been started */
- do
- {
- bytes = 0;
-
- status = TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), (int32_t*)&bytes);
-
- if (status != 0)
- {
- prvTraceWarning(PSF_WARNING_STREAM_PORT_READ);
- }
-
- if ((status == 0) && (bytes == sizeof(TracealyzerCommandType)))
- {
- if (prvIsValidCommand(&msg))
- {
- if (msg.cmdCode == CMD_SET_ACTIVE && msg.param1 == 1)
- {
- /* On start, init and reset the timestamping */
- TRC_PORT_SPECIFIC_INIT();
- }
-
- prvProcessCommand(&msg);
- }
- }
- }
- while (RecorderEnabled == 0);
- }
- else if (startOption == TRC_START)
- {
- /* We start streaming directly - this assumes that the interface is ready! */
- TRC_PORT_SPECIFIC_INIT();
-
- msg.cmdCode = CMD_SET_ACTIVE;
- msg.param1 = 1;
- prvProcessCommand(&msg);
- }
- else
- {
- /* On TRC_INIT */
- TRC_PORT_SPECIFIC_INIT();
- }
-}
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-/*******************************************************************************
- * vTraceSetQueueName(void* object, const char* name)
- *
- * Parameter object: pointer to the Queue that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Queue objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetQueueName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-
-/*******************************************************************************
- * vTraceSetSemaphoreName(void* object, const char* name)
- *
- * Parameter object: pointer to the Semaphore that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Semaphore objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetSemaphoreName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-
-/*******************************************************************************
- * vTraceSetMutexName(void* object, const char* name)
- *
- * Parameter object: pointer to the Mutex that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Mutex objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetMutexName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-/*******************************************************************************
-* vTraceSetEventGroupName(void* object, const char* name)
-*
-* Parameter object: pointer to the vTraceSetEventGroupName that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for EventGroup objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetEventGroupName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-/*******************************************************************************
-* vTraceSetStreamBufferName(void* object, const char* name)
-*
-* Parameter object: pointer to the StreamBuffer that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for StreamBuffer objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetStreamBufferName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-
-/*******************************************************************************
-* vTraceSetMessageBufferName(void* object, const char* name)
-*
-* Parameter object: pointer to the MessageBuffer that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for MessageBuffer objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetMessageBufferName(void* object, const char* name)
-{
- vTraceStoreKernelObjectName(object, name);
-}
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-/*******************************************************************************
- * prvGetCurrentTaskHandle
- *
- * Function that returns the handle to the currently executing task.
- *
- ******************************************************************************/
-void* prvTraceGetCurrentTaskHandle(void)
-{
- return xTaskGetCurrentTaskHandle();
-}
-
-/*******************************************************************************
- * prvIsNewTCB
- *
- * Tells if this task is already executing, or if there has been a task-switch.
- * Assumed to be called within a trace hook in kernel context.
- ******************************************************************************/
-uint32_t prvIsNewTCB(void* pNewTCB)
-{
- if (pCurrentTCB != pNewTCB)
- {
- pCurrentTCB = pNewTCB;
- return 1;
- }
- return 0;
-}
-
-/*******************************************************************************
- * prvTraceIsSchedulerSuspended
- *
- * Returns true if the RTOS scheduler currently is disabled, thus preventing any
- * task-switches from occurring. Only called from vTraceStoreISREnd.
- ******************************************************************************/
-unsigned char prvTraceIsSchedulerSuspended(void)
-{
- /* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,
- INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in
- FreeRTOSConfig.h for this function to be available. */
-
- return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;
-}
-
-
-/*******************************************************************************
- * prvCheckRecorderStatus
- *
- * Called by TzCtrl task periodically (every 100 ms - seems reasonable).
- * Checks a number of diagnostic variables and give warnings as user events,
- * in most cases including a suggested solution.
- ******************************************************************************/
-static void prvCheckRecorderStatus(void)
-{
- if (NoRoomForSymbol > NoRoomForSymbol_last)
- {
- if (NoRoomForSymbol > 0)
- {
- prvTraceWarning(PSF_WARNING_SYMBOL_TABLE_SLOTS);
- }
- NoRoomForSymbol_last = NoRoomForSymbol;
- }
-
- if (NoRoomForObjectData > NoRoomForObjectData_last)
- {
- if (NoRoomForObjectData > 0)
- {
- prvTraceWarning(PSF_WARNING_OBJECT_DATA_SLOTS);
- }
- NoRoomForObjectData_last = NoRoomForObjectData;
- }
-
- if (LongestSymbolName > LongestSymbolName_last)
- {
- if (LongestSymbolName > (TRC_CFG_SYMBOL_MAX_LENGTH))
- {
- prvTraceWarning(PSF_WARNING_SYMBOL_MAX_LENGTH);
- }
- LongestSymbolName_last = LongestSymbolName;
- }
-
- if (MaxBytesTruncated > MaxBytesTruncated_last)
- {
- if (MaxBytesTruncated > 0)
- {
- prvTraceWarning(PSF_WARNING_STRING_TOO_LONG);
- }
- MaxBytesTruncated_last = MaxBytesTruncated;
- }
-}
-
-/*******************************************************************************
- * TzCtrl
- *
- * Task for sending the trace data from the internal buffer to the stream
- * interface (assuming TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1) and for
- * receiving commands from Tracealyzer. Also does some diagnostics.
- ******************************************************************************/
-static portTASK_FUNCTION( TzCtrl, pvParameters )
-{
- TracealyzerCommandType msg;
- int32_t bytes = 0;
- int32_t status = 0;
- (void)pvParameters;
-
- while (1)
- {
- do
- {
- /* Listen for new commands */
- bytes = 0;
- status = TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), (int32_t*)&bytes);
-
- if (status != 0)
- {
- prvTraceWarning(PSF_WARNING_STREAM_PORT_READ);
- }
-
- if ((status == 0) && (bytes == sizeof(TracealyzerCommandType)))
- {
- if (prvIsValidCommand(&msg))
- {
- prvProcessCommand(&msg); /* Start or Stop currently... */
- }
- }
-
-/* If the internal buffer is disabled, the COMMIT macro instead sends the data directly
- from the "event functions" (using TRC_STREAM_PORT_WRITE_DATA). */
-#if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)
- /* If there is a buffer page, this sends it to the streaming interface using TRC_STREAM_PORT_WRITE_DATA. */
- bytes = prvPagedEventBufferTransfer();
-#endif
-
- /* If there was data sent or received (bytes != 0), loop around and repeat, if there is more data to send or receive.
- Otherwise, step out of this loop and sleep for a while. */
-
- } while (bytes != 0);
-
- prvCheckRecorderStatus();
-
- vTaskDelay(TRC_CFG_CTRL_TASK_DELAY);
- }
-}
-
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
-
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-
-/* Internal flag to tell the context of tracePEND_FUNC_CALL_FROM_ISR */
-int uiInEventGroupSetBitsFromISR = 0;
-
-/******************************************************************************
- * TraceQueueClassTable
- * Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).
- * Has one entry for each QueueType, gives TRACE_CLASS ID.
- ******************************************************************************/
-traceObjectClass TraceQueueClassTable[5] = {
- TRACE_CLASS_QUEUE,
- TRACE_CLASS_MUTEX,
- TRACE_CLASS_SEMAPHORE,
- TRACE_CLASS_SEMAPHORE,
- TRACE_CLASS_MUTEX
-};
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-/*******************************************************************************
- * vTraceSetQueueName(void* object, const char* name)
- *
- * Parameter object: pointer to the Queue that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Queue objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetQueueName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_QUEUE, TRACE_GET_OBJECT_NUMBER(QUEUE, object), name);
-}
-
-/*******************************************************************************
- * vTraceSetSemaphoreName(void* object, const char* name)
- *
- * Parameter object: pointer to the Semaphore that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Semaphore objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetSemaphoreName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_SEMAPHORE, TRACE_GET_OBJECT_NUMBER(QUEUE, object), name);
-}
-
-/*******************************************************************************
- * vTraceSetMutexName(void* object, const char* name)
- *
- * Parameter object: pointer to the Mutex that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for Semaphore objects for display in Tracealyzer.
- ******************************************************************************/
-void vTraceSetMutexName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_MUTEX, TRACE_GET_OBJECT_NUMBER(QUEUE, object), name);
-}
-
-#if (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)
-/*******************************************************************************
-* vTraceSetEventGroupName(void* object, const char* name)
-*
-* Parameter object: pointer to the EventGroup that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for EventGroup objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetEventGroupName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_EVENTGROUP, TRACE_GET_OBJECT_NUMBER(EVENTGROUP, object), name);
-}
-#endif /* (TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */
-
-#if (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0)
-/*******************************************************************************
-* vTraceSetStreamBufferName(void* object, const char* name)
-*
-* Parameter object: pointer to the StreamBuffer that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for StreamBuffer objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetStreamBufferName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_STREAMBUFFER, TRACE_GET_OBJECT_NUMBER(STREAMBUFFER, object), name);
-}
-
-/*******************************************************************************
-* vTraceSetMessageBufferName(void* object, const char* name)
-*
-* Parameter object: pointer to the MessageBuffer that shall be named
-* Parameter name: the name to set (const string literal)
-*
-* Sets a name for MessageBuffer objects for display in Tracealyzer.
-******************************************************************************/
-void vTraceSetMessageBufferName(void* object, const char* name)
-{
- prvTraceSetObjectName(TRACE_CLASS_MESSAGEBUFFER, TRACE_GET_OBJECT_NUMBER(STREAMBUFFER, object), name);
-}
-#endif /* (TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS == 1 && TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_10_0_0) */
-
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
-
-void* prvTraceGetCurrentTaskHandle()
-{
- return xTaskGetCurrentTaskHandle();
-}
-
-/* Initialization of the object property table */
-void vTraceInitObjectPropertyTable()
-{
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectClasses = TRACE_NCLASSES;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[0] = TRC_CFG_NQUEUE;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[1] = TRC_CFG_NSEMAPHORE;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[2] = TRC_CFG_NMUTEX;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[3] = TRC_CFG_NTASK;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[4] = TRC_CFG_NISR;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[5] = TRC_CFG_NTIMER;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[6] = TRC_CFG_NEVENTGROUP;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[7] = TRC_CFG_NSTREAMBUFFER;
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[8] = TRC_CFG_NMESSAGEBUFFER;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[0] = TRC_CFG_NAME_LEN_QUEUE;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[1] = TRC_CFG_NAME_LEN_SEMAPHORE;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[2] = TRC_CFG_NAME_LEN_MUTEX;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[3] = TRC_CFG_NAME_LEN_TASK;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[4] = TRC_CFG_NAME_LEN_ISR;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[5] = TRC_CFG_NAME_LEN_TIMER;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[6] = TRC_CFG_NAME_LEN_EVENTGROUP;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[7] = TRC_CFG_NAME_LEN_STREAMBUFFER;
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[8] = TRC_CFG_NAME_LEN_MESSAGEBUFFER;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[0] = PropertyTableSizeQueue;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[1] = PropertyTableSizeSemaphore;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[2] = PropertyTableSizeMutex;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[3] = PropertyTableSizeTask;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[4] = PropertyTableSizeISR;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[5] = PropertyTableSizeTimer;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[6] = PropertyTableSizeEventGroup;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[7] = PropertyTableSizeStreamBuffer;
- RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[8] = PropertyTableSizeMessageBuffer;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[0] = StartIndexQueue;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[1] = StartIndexSemaphore;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[2] = StartIndexMutex;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[3] = StartIndexTask;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[4] = StartIndexISR;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[5] = StartIndexTimer;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[6] = StartIndexEventGroup;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[7] = StartIndexStreamBuffer;
- RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[8] = StartIndexMessageBuffer;
- RecorderDataPtr->ObjectPropertyTable.ObjectPropertyTableSizeInBytes = TRACE_OBJECT_TABLE_SIZE;
-}
-
-/* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */
-void vTraceInitObjectHandleStack()
-{
- objectHandleStacks.indexOfNextAvailableHandle[0] = objectHandleStacks.lowestIndexOfClass[0] = 0;
- objectHandleStacks.indexOfNextAvailableHandle[1] = objectHandleStacks.lowestIndexOfClass[1] = (TRC_CFG_NQUEUE);
- objectHandleStacks.indexOfNextAvailableHandle[2] = objectHandleStacks.lowestIndexOfClass[2] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE);
- objectHandleStacks.indexOfNextAvailableHandle[3] = objectHandleStacks.lowestIndexOfClass[3] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX);
- objectHandleStacks.indexOfNextAvailableHandle[4] = objectHandleStacks.lowestIndexOfClass[4] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK);
- objectHandleStacks.indexOfNextAvailableHandle[5] = objectHandleStacks.lowestIndexOfClass[5] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR);
- objectHandleStacks.indexOfNextAvailableHandle[6] = objectHandleStacks.lowestIndexOfClass[6] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER);
- objectHandleStacks.indexOfNextAvailableHandle[7] = objectHandleStacks.lowestIndexOfClass[7] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP);
- objectHandleStacks.indexOfNextAvailableHandle[8] = objectHandleStacks.lowestIndexOfClass[8] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP) + (TRC_CFG_NSTREAMBUFFER);
-
- objectHandleStacks.highestIndexOfClass[0] = (TRC_CFG_NQUEUE) - 1;
- objectHandleStacks.highestIndexOfClass[1] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) - 1;
- objectHandleStacks.highestIndexOfClass[2] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) - 1;
- objectHandleStacks.highestIndexOfClass[3] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) - 1;
- objectHandleStacks.highestIndexOfClass[4] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) - 1;
- objectHandleStacks.highestIndexOfClass[5] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) - 1;
- objectHandleStacks.highestIndexOfClass[6] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP) - 1;
- objectHandleStacks.highestIndexOfClass[7] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP) + (TRC_CFG_NSTREAMBUFFER) - 1;
- objectHandleStacks.highestIndexOfClass[8] = (TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NTASK) + (TRC_CFG_NISR) + (TRC_CFG_NTIMER) + (TRC_CFG_NEVENTGROUP) + (TRC_CFG_NSTREAMBUFFER) + (TRC_CFG_NMESSAGEBUFFER) - 1;
-}
-
-/* Returns the "Not enough handles" error message for this object class */
-const char* pszTraceGetErrorNotEnoughHandles(traceObjectClass objectclass)
-{
- switch(objectclass)
- {
- case TRACE_CLASS_TASK:
- return "Not enough TASK handles - increase TRC_CFG_NTASK in trcSnapshotConfig.h";
- case TRACE_CLASS_ISR:
- return "Not enough ISR handles - increase TRC_CFG_NISR in trcSnapshotConfig.h";
- case TRACE_CLASS_SEMAPHORE:
- return "Not enough SEMAPHORE handles - increase TRC_CFG_NSEMAPHORE in trcSnapshotConfig.h";
- case TRACE_CLASS_MUTEX:
- return "Not enough MUTEX handles - increase TRC_CFG_NMUTEX in trcSnapshotConfig.h";
- case TRACE_CLASS_QUEUE:
- return "Not enough QUEUE handles - increase TRC_CFG_NQUEUE in trcSnapshotConfig.h";
- case TRACE_CLASS_TIMER:
- return "Not enough TIMER handles - increase TRC_CFG_NTIMER in trcSnapshotConfig.h";
- case TRACE_CLASS_EVENTGROUP:
- return "Not enough EVENTGROUP handles - increase TRC_CFG_NEVENTGROUP in trcSnapshotConfig.h";
- case TRACE_CLASS_STREAMBUFFER:
- return "Not enough STREAMBUFFER handles - increase TRC_CFG_NSTREAMBUFFER in trcSnapshotConfig.h";
- case TRACE_CLASS_MESSAGEBUFFER:
- return "Not enough MESSAGEBUFFER handles - increase TRC_CFG_NMESSAGEBUFFER in trcSnapshotConfig.h";
- default:
- return "pszTraceGetErrorHandles: Invalid objectclass!";
- }
-}
-
-/*******************************************************************************
- * prvTraceIsSchedulerSuspended
- *
- * Returns true if the RTOS scheduler currently is disabled, thus preventing any
- * task-switches from occurring. Only called from vTraceStoreISREnd.
- ******************************************************************************/
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
-unsigned char prvTraceIsSchedulerSuspended(void)
-{
- /* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,
- INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in
- FreeRTOSConfig.h for this function to be available. */
-
- return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;
-}
-#endif
-
-#endif /* Snapshot mode */
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c
deleted file mode 100755
index 2f82ab0..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c
+++ /dev/null
@@ -1,3105 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcSnapshotRecorder.c
- *
- * The generic core of the trace recorder's snapshot mode.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#include "trcRecorder.h"
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-#include
-#include
-#include
-
-#if ((TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR))
- #error "CUSTOM timestamping mode is not (yet) supported in snapshot mode!"
-#endif
-
-/* DO NOT CHANGE */
-#define TRACE_MINOR_VERSION 5
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
-static traceHandle isrstack[TRC_CFG_MAX_ISR_NESTING];
-int32_t isPendingContextSwitch = 0;
-#endif /* (TRC_CFG_INCLUDE_ISR_TRACING == 1) */
-
-#if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1
-static int readyEventsEnabled = 1;
-#endif /*!defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1*/
-
-/*******************************************************************************
- * uiTraceTickCount
- *
- * This variable is should be updated by the Kernel tick interrupt. This does
- * not need to be modified when developing a new timer port. It is preferred to
- * keep any timer port changes in the HWTC macro definitions, which typically
- * give sufficient flexibility.
- ******************************************************************************/
-uint32_t uiTraceTickCount = 0;
-
-uint32_t trace_disable_timestamp = 0;
-
-static uint32_t last_timestamp = 0;
-
-/* Flag that shows if inside a critical section of the recorder */
-volatile int recorder_busy = 0;
-
-/* Holds the value set by vTraceSetFrequency */
-uint32_t timestampFrequency = 0;
-
-/* The last error message of the recorder. NULL if no error message. */
-const char* traceErrorMessage = NULL;
-
-int8_t nISRactive = 0;
-
-traceHandle handle_of_last_logged_task = 0;
-
-/* Called when the recorder is stopped, set by vTraceSetStopHook. */
-TRACE_STOP_HOOK vTraceStopHookPtr = (TRACE_STOP_HOOK)0;
-
-uint16_t CurrentFilterMask = 0xFFFF;
-
-uint16_t CurrentFilterGroup = FilterGroup0;
-
-extern int8_t nISRactive;
-
-extern traceHandle handle_of_last_logged_task;
-
-/*************** Private Functions *******************************************/
-static void prvStrncpy(char* dst, const char* src, uint32_t maxLength);
-static uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id);
-static void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength);
-static void* prvTraceNextFreeEventBufferSlot(void);
-static uint16_t prvTraceGetDTS(uint16_t param_maxDTS);
-static traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel);
-static void prvTraceUpdateCounters(void);
-
-void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size);
-
-#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
-static void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nEntries);
-#endif
-
-static traceString prvTraceCreateSymbolTableEntry(const char* name,
- uint8_t crc6,
- uint8_t len,
- traceString channel);
-
-static traceString prvTraceLookupSymbolTableEntry(const char* name,
- uint8_t crc6,
- uint8_t len,
- traceString channel);
-
-
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 0)
-/* ISR tracing is turned off */
-void prvTraceIncreaseISRActive(void);
-void prvTraceDecreaseISRActive(void);
-#endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/
-
-#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
-static uint8_t prvTraceGet8BitHandle(traceHandle handle);
-#else
-#define prvTraceGet8BitHandle(x) ((uint8_t)x)
-#endif
-
-
-#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)
-static uint32_t heapMemUsage = 0;
-#endif
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-static uint32_t prvTraceGetParam(uint32_t, uint32_t);
-#endif
-
-/*******************************************************************************
- * prvTraceInitTraceData
- *
- * Allocates and initializes the recorder data structure, based on the constants
- * in trcConfig.h. This allows for allocating the data on the heap, instead of
- * using a static declaration.
- ******************************************************************************/
-static void prvTraceInitTraceData(void);
-
-/*******************************************************************************
- * prvTracePortGetTimeStamp
- *
- * Returns the current time based on the HWTC macros which provide a hardware
- * isolation layer towards the hardware timer/counter.
- *
- * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue
- * or the trace recorder library. Typically you should not need to change
- * the code of prvTracePortGetTimeStamp if using the HWTC macros.
- *
- ******************************************************************************/
-void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);
-
-static void prvTraceTaskInstanceFinish(int8_t direct);
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-static void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list vl);
-
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
-static void vTraceUBData_Helper(traceUBChannel channelPair, va_list vl);
-static void prvTraceUBHelper1(traceUBChannel channel, traceString eventLabel, traceString formatLabel, va_list vl);
-static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t noOfSlots);
-#endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/
-#endif /* ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)) */
-
-/********* Public Functions **************************************************/
-
-uint16_t uiIndexOfObject(traceHandle objecthandle, uint8_t objectclass);
-
-/*******************************************************************************
- * prvTraceError
- *
- * Called by various parts in the recorder. Stops the recorder and stores a
- * pointer to an error message, which is printed by the monitor task.
- ******************************************************************************/
-void prvTraceError(const char* msg);
-
-/******************************************************************************
-* vTraceEnable(int startOption) - snapshot mode
-*
-* Initializes and optionally starts the trace, depending on the start option.
-* To use the trace recorder, the startup must call vTraceEnable before any RTOS
-* calls are made (including "create" calls). Three start options are provided:
-*
-* TRC_START: Starts the tracing directly. In snapshot mode this allows for
-* starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)
-* has been called in the startup.
-* Can also be used for streaming without Tracealyzer control, e.g. to a local
-* flash file system (assuming such a "stream port", see trcStreamingPort.h).
-*
-* TRC_INIT: Initializes the trace recorder, but does not start the tracing.
-* In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime
-* later.
-*
-* Usage examples, in snapshot mode:
-*
-* Snapshot trace, from startup:
-*
-* vTraceEnable(TRC_START);
-*
-*
-* Snapshot trace, from a later point:
-*
-* vTraceEnable(TRC_INIT);
-*
-* ...
-* vTraceEnable(TRC_START); // e.g., in task context, at some relevant event
-*
-*
-* Note: See other implementation of vTraceEnable in trcStreamingRecorder.c
-******************************************************************************/
-void vTraceEnable(int startOption)
-{
- prvTraceInitTraceData();
-
- if (startOption == TRC_START)
- {
- vTraceStart();
- }
- else if (startOption == TRC_START_AWAIT_HOST)
- {
- prvTraceError("vTraceEnable(TRC_START_AWAIT_HOST) not allowed in Snapshot mode");
- }
- else if (startOption != TRC_INIT)
- {
- prvTraceError("Unexpected argument to vTraceEnable (snapshot mode)");
- }
-}
-
-/*******************************************************************************
- * vTraceSetRecorderDataBuffer
- *
- * If custom allocation is used, this function must be called so the recorder
- * library knows where to save the trace data.
- ******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
-void vTraceSetRecorderDataBuffer(void* pRecorderData)
-{
- TRACE_ASSERT(pRecorderData != NULL, "vTraceSetRecorderDataBuffer, pRecorderData == NULL", TRC_UNUSED);
- RecorderDataPtr = pRecorderData;
-}
-#endif
-
-/*******************************************************************************
- * vTraceSetStopHook
- *
- * Sets a function to be called when the recorder is stopped. This can be used
- * to save the trace to a file system, if available. This is only implemented
- * for snapshot mode.
- ******************************************************************************/
-void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction)
-{
- vTraceStopHookPtr = stopHookFunction;
-}
-
-/*******************************************************************************
- * vTraceClear
- *
- * Resets the recorder. Only necessary if a restart is desired - this is not
- * needed in the startup initialization.
- ******************************************************************************/
-void vTraceClear(void)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
- trcCRITICAL_SECTION_BEGIN();
- RecorderDataPtr->absTimeLastEventSecond = 0;
- RecorderDataPtr->absTimeLastEvent = 0;
- RecorderDataPtr->nextFreeIndex = 0;
- RecorderDataPtr->numEvents = 0;
- RecorderDataPtr->bufferIsFull = 0;
- traceErrorMessage = NULL;
- RecorderDataPtr->internalErrorOccured = 0;
- (void)memset(RecorderDataPtr->eventData, 0, RecorderDataPtr->maxEvents * 4);
- handle_of_last_logged_task = 0;
- trcCRITICAL_SECTION_END();
-}
-
-/*******************************************************************************
- * uiTraceStart
- *
- * Starts the recorder. The recorder will not be started if an error has been
- * indicated using prvTraceError, e.g. if any of the Nx constants in trcConfig.h
- * has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).
- *
- * Returns 1 if the recorder was started successfully.
- * Returns 0 if the recorder start was prevented due to a previous internal
- * error. In that case, check xTraceGetLastError to get the error message.
- * Any error message is also presented when opening a trace file.
- *
- * This function is obsolete, but has been saved for backwards compatibility.
- * We recommend using vTraceEnable instead.
- ******************************************************************************/
-uint32_t uiTraceStart(void)
-{
- traceHandle handle;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- handle = 0;
-
- if (RecorderDataPtr == NULL)
- {
- TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized. Use vTraceEnable() instead!", 0);
- return 0;
- }
-
- if (RecorderDataPtr->recorderActive == 1)
- return 1; /* Already running */
-
- if (traceErrorMessage == NULL)
- {
- trcCRITICAL_SECTION_BEGIN();
- RecorderDataPtr->recorderActive = 1;
-
- handle = TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK());
- if (handle == 0)
- {
- /* This occurs if the scheduler is not yet started.
- This creates a dummy "(startup)" task entry internally in the
- recorder */
- handle = prvTraceGetObjectHandle(TRACE_CLASS_TASK);
- prvTraceSetObjectName(TRACE_CLASS_TASK, handle, "(startup)");
-
- prvTraceSetPriorityProperty(TRACE_CLASS_TASK, handle, 0);
- }
-
- prvTraceStoreTaskswitch(handle); /* Register the currently running task */
- trcCRITICAL_SECTION_END();
- }
-
- return RecorderDataPtr->recorderActive;
-}
-
-/*******************************************************************************
- * vTraceStart
- *
- * Starts the recorder. The recorder will not be started if an error has been
- * indicated using prvTraceError, e.g. if any of the Nx constants in trcConfig.h
- * has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).
- *
- * This function is obsolete, but has been saved for backwards compatibility.
- * We recommend using vTraceEnable instead.
- ******************************************************************************/
-void vTraceStart(void)
-{
- (void)uiTraceStart();
-}
-
-/*******************************************************************************
- * vTraceStop
- *
- * Stops the recorder. The recording can be resumed by calling vTraceStart.
- * This does not reset the recorder. Use vTraceClear if that is desired.
- ******************************************************************************/
-void vTraceStop(void)
-{
- if (RecorderDataPtr != NULL)
- {
- RecorderDataPtr->recorderActive = 0;
- }
-
- if (vTraceStopHookPtr != (TRACE_STOP_HOOK)0)
- {
- (*vTraceStopHookPtr)(); /* An application call-back function. */
- }
-}
-
-/*******************************************************************************
-* xTraceIsRecordingEnabled
-* Returns true (1) if the recorder is enabled (i.e. is recording), otherwise 0.
-******************************************************************************/
-int xTraceIsRecordingEnabled(void)
-{
- if (RecorderDataPtr != NULL)
- {
- return (int)RecorderDataPtr->recorderActive;
- }
- else
- {
- return 0;
- }
-}
-
-/*******************************************************************************
- * xTraceGetLastError
- *
- * Gives the last error message, if any. NULL if no error message is stored.
- * Any error message is also presented when opening a trace file.
- ******************************************************************************/
-const char* xTraceGetLastError(void)
-{
- return traceErrorMessage;
-}
-
-/*******************************************************************************
-* vTraceClearError
-*
-* Removes any previous error message generated by recorder calling prvTraceError.
-* By calling this function, it may be possible to start/restart the trace
-* despite errors in the recorder, but there is no guarantee that the trace
-* recorder will work correctly in that case, depending on the type of error.
-******************************************************************************/
-void vTraceClearError(void)
-{
- traceErrorMessage = NULL;
- if (RecorderDataPtr != NULL)
- {
- RecorderDataPtr->internalErrorOccured = 0;
- }
-}
-
-/*******************************************************************************
- * xTraceGetTraceBuffer
- *
- * Returns a pointer to the recorder data structure. Use this together with
- * uiTraceGetTraceBufferSize if you wish to implement an own store/upload
- * solution, e.g., in case a debugger connection is not available for uploading
- * the data.
- ******************************************************************************/
-void* xTraceGetTraceBuffer(void)
-{
- return RecorderDataPtr;
-}
-
-/*******************************************************************************
- * uiTraceGetTraceBufferSize
- *
- * Gets the size of the recorder data structure. For use together with
- * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,
- * e.g., in case a debugger connection is not available for uploading the data.
- ******************************************************************************/
-uint32_t uiTraceGetTraceBufferSize(void)
-{
- return sizeof(RecorderDataType);
-}
-
-/******************************************************************************
- * prvTraceTaskInstanceFinish
- *
- * Private common function for the vTraceTaskInstanceFinishXXX functions.
- *****************************************************************************/
-static void prvTraceTaskInstanceFinish(int8_t direct)
-{
- TaskInstanceStatusEvent* tis;
- uint8_t dts45;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- dts45 = (uint8_t)prvTraceGetDTS(0xFF);
- tis = (TaskInstanceStatusEvent*) prvTraceNextFreeEventBufferSlot();
- if (tis != NULL)
- {
- if (direct == 0)
- tis->type = TASK_INSTANCE_FINISHED_NEXT_KSE;
- else
- tis->type = TASK_INSTANCE_FINISHED_DIRECT;
-
- tis->dts = dts45;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-
-/******************************************************************************
- * vTraceInstanceFinishedNext(void)
- *
- * Marks the current task instance as finished on the next kernel call.
- *
- * If that kernel call is blocking, the instance ends after the blocking event
- * and the corresponding return event is then the start of the next instance.
- * If the kernel call is not blocking, the viewer instead splits the current
- * fragment right before the kernel call, which makes this call the first event
- * of the next instance.
- *
- * See also TRC_CFG_USE_IMPLICIT_IFE_RULES in trcConfig.h
- *
- * Example:
- *
- * while(1)
- * {
- * xQueueReceive(CommandQueue, &command, timeoutDuration);
- * processCommand(command);
- * vTraceInstanceFinishedNext();
- * }
- *****************************************************************************/
-void vTraceInstanceFinishedNext(void)
-{
- prvTraceTaskInstanceFinish(0);
-}
-
-/******************************************************************************
- * vTraceInstanceFinishedNow(void)
- *
- * Marks the current task instance as finished at this very instant.
- * This makes the viewer to splits the current fragment at this point and begin
- * a new actor instance.
- *
- * See also TRC_CFG_USE_IMPLICIT_IFE_RULES in trcConfig.h
- *
- * Example:
- *
- * This example will generate two instances for each loop iteration.
- * The first instance ends at vTraceInstanceFinishedNow(), while the second
- * instance ends at the next xQueueReceive call.
- *
- * while (1)
- * {
- * xQueueReceive(CommandQueue, &command, timeoutDuration);
- * ProcessCommand(command);
- * vTraceInstanceFinishedNow();
- * DoSometingElse();
- * vTraceInstanceFinishedNext();
- * }
- *****************************************************************************/
-void vTraceInstanceFinishedNow(void)
-{
- prvTraceTaskInstanceFinish(1);
-}
-
-/*******************************************************************************
- * Interrupt recording functions
- ******************************************************************************/
-
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
-
-/*******************************************************************************
- * xTraceSetISRProperties
- *
- * Stores a name and priority level for an Interrupt Service Routine, to allow
- * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
- traceHandle xTraceSetISRProperties(const char* name, uint8_t priority)
-{
- static traceHandle handle = 0;
- TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "xTraceSetISRProperties: Invalid value for handle", 0);
- TRACE_ASSERT(name != NULL, "xTraceSetISRProperties: name == NULL", 0);
-
- handle++;
-
- prvTraceSetObjectName(TRACE_CLASS_ISR, handle, name);
- prvTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);
-
- return handle;
-}
-
-/*******************************************************************************
- * vTraceStoreISRBegin
- *
- * Registers the beginning of an Interrupt Service Routine, using a traceHandle
- * provided by xTraceSetISRProperties.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
-void vTraceStoreISRBegin(traceHandle handle)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("vTraceStoreISRBegin - recorder busy! See code comment.");
- return;
- }
- trcCRITICAL_SECTION_BEGIN();
-
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- uint16_t dts4;
-
- TRACE_ASSERT(handle != 0, "vTraceStoreISRBegin: Invalid ISR handle (NULL)", TRC_UNUSED);
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid ISR handle (> NISR)", TRC_UNUSED);
-
- dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);
-
- if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
- {
- if (nISRactive < TRC_CFG_MAX_ISR_NESTING)
- {
- TSEvent* ts;
- uint8_t hnd8 = prvTraceGet8BitHandle(handle);
- isrstack[nISRactive] = handle;
- nISRactive++;
- ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();
- if (ts != NULL)
- {
- ts->type = TS_ISR_BEGIN;
- ts->dts = dts4;
- ts->objHandle = hnd8;
- prvTraceUpdateCounters();
- }
- }
- else
- {
- /* This should not occur unless something is very wrong */
- prvTraceError("Too many nested interrupts!");
- }
- }
- }
- trcCRITICAL_SECTION_END();
-}
-
-/*******************************************************************************
- * vTraceStoreISREnd
- *
- * Registers the end of an Interrupt Service Routine.
- *
- * The parameter pendingISR indicates if the interrupt has requested a
- * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the
- * interrupt is assumed to return to the previous context.
- *
- * Example:
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
- * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder
- * ...
- * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(traceHandleIsrTimer1);
- * ...
- * vTraceStoreISREnd(0);
- * }
- ******************************************************************************/
-void vTraceStoreISREnd(int pendingISR)
-{
- TSEvent* ts;
- uint16_t dts5;
- uint8_t hnd8 = 0, type = 0;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- if (! RecorderDataPtr->recorderActive || ! handle_of_last_logged_task)
- {
- return;
- }
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("vTraceStoreISREnd - recorder busy! See code comment.");
- return;
- }
-
- if (nISRactive == 0)
- {
- prvTraceError("Unmatched call to vTraceStoreISREnd (nISRactive == 0, expected > 0)");
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- isPendingContextSwitch |= pendingISR; /* Is there a pending context switch right now? */
- nISRactive--;
- if (nISRactive > 0)
- {
- /* Return to another ISR */
- type = TS_ISR_RESUME;
- hnd8 = prvTraceGet8BitHandle(isrstack[nISRactive - 1]); /* isrstack[nISRactive] is the handle of the ISR we're currently exiting. isrstack[nISRactive - 1] is the handle of the ISR that was executing previously. */
- }
- else if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended()))
- {
- /* Return to interrupted task, if no context switch will occur in between. */
- type = TS_TASK_RESUME;
- hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);
- }
-
- if (type != 0)
- {
- dts5 = (uint16_t)prvTraceGetDTS(0xFFFF);
- ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();
- if (ts != NULL)
- {
- ts->type = type;
- ts->objHandle = hnd8;
- ts->dts = dts5;
- prvTraceUpdateCounters();
- }
- }
-
- trcCRITICAL_SECTION_END();
-}
-
-#else
-
-/* ISR tracing is turned off */
-void prvTraceIncreaseISRActive(void)
-{
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- nISRactive++;
-}
-
-void prvTraceDecreaseISRActive(void)
-{
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- nISRactive--;
-}
-#endif /* (TRC_CFG_INCLUDE_ISR_TRACING == 1)*/
-
-
-/********************************************************************************/
-/* User Event functions */
-/********************************************************************************/
-
-#define MAX_ARG_SIZE (4+32)
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value)
-{
- TRACE_ASSERT(buffer != NULL, "writeInt8: buffer == NULL", 0);
-
- if (i >= MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint8_t*)buffer)[i] = value;
-
- if (i + 1 > MAX_ARG_SIZE)
- {
- return 255;
- }
-
- return ((uint8_t) (i + 1));
-}
-#endif
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value)
-{
- TRACE_ASSERT(buffer != NULL, "writeInt16: buffer == NULL", 0);
-
- /* Align to multiple of 2 */
- while ((i % 2) != 0)
- {
- if (i >= MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint8_t*)buffer)[i] = 0;
- i++;
- }
-
- if (i + 2 > MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint16_t*)buffer)[i/2] = value;
-
- return ((uint8_t) (i + 2));
-}
-#endif
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value)
-{
- TRACE_ASSERT(buffer != NULL, "writeInt32: buffer == NULL", 0);
-
- /* A 32 bit value should begin at an even 4-byte address */
- while ((i % 4) != 0)
- {
- if (i >= MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint8_t*)buffer)[i] = 0;
- i++;
- }
-
- if (i + 4 > MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint32_t*)buffer)[i/4] = value;
-
- return ((uint8_t) (i + 4));
-}
-#endif
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_INCLUDE_FLOAT_SUPPORT))
-static uint8_t writeFloat(void * buffer, uint8_t i, float value)
-{
- TRACE_ASSERT(buffer != NULL, "writeFloat: buffer == NULL", 0);
-
- /* A 32 bit value should begin at an even 4-byte address */
- while ((i % 4) != 0)
- {
- if (i >= MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint8_t*)buffer)[i] = 0;
- i++;
- }
-
- if (i + 4 > MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((float*)buffer)[i/4] = value;
-
- return i + 4;
-}
-#endif
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_INCLUDE_FLOAT_SUPPORT))
-static uint8_t writeDouble(void * buffer, uint8_t i, double value)
-{
- uint32_t * dest;
- uint32_t * src = (uint32_t*)&value;
-
- TRACE_ASSERT(buffer != NULL, "writeDouble: buffer == NULL", 0);
-
- /* The double is written as two 32 bit values, and should begin at an even
- 4-byte address (to avoid having to align with 8 byte) */
- while (i % 4 != 0)
- {
- if (i >= MAX_ARG_SIZE)
- {
- return 255;
- }
-
- ((uint8_t*)buffer)[i] = 0;
- i++;
- }
-
- if (i + 8 > MAX_ARG_SIZE)
- {
- return 255;
- }
-
- dest = &(((uint32_t *)buffer)[i/4]);
-
- dest[0] = src[0];
- dest[1] = src[1];
-
- return i + 8;
-}
-#endif
-
-/*******************************************************************************
- * prvTraceUserEventFormat
- *
- * Parses the format string and stores the arguments in the buffer.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-static uint8_t prvTraceUserEventFormat(const char* formatStr, va_list vl, uint8_t* buffer, uint8_t byteOffset)
-{
- uint16_t formatStrIndex = 0;
- uint8_t argCounter = 0;
- uint8_t i = byteOffset;
-
- while (formatStr[formatStrIndex] != '\0')
- {
- if (formatStr[formatStrIndex] == '%')
- {
- argCounter++;
-
- if (argCounter > 15)
- {
- prvTraceError("vTracePrintF - Too many arguments, max 15 allowed!");
- return 0;
- }
-
- formatStrIndex++;
-
- while ((formatStr[formatStrIndex] >= '0' && formatStr[formatStrIndex] <= '9') || formatStr[formatStrIndex] == '#' || formatStr[formatStrIndex] == '.')
- formatStrIndex++;
-
- if (formatStr[formatStrIndex] != '\0')
- {
- switch (formatStr[formatStrIndex])
- {
- case 'd': i = writeInt32( buffer,
- i,
- (uint32_t)va_arg(vl, uint32_t));
- break;
- case 'x':
- case 'X':
- case 'u': i = writeInt32( buffer,
- i,
- (uint32_t)va_arg(vl, uint32_t));
- break;
- case 's': i = writeInt16( buffer,
- i,
- xTraceRegisterString((char*)va_arg(vl, char*)));
- break;
-
-#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT)
- /* Yes, "double" as type also in the float
- case. This since "float" is promoted into "double"
- by the va_arg stuff. */
- case 'f': i = writeFloat( buffer,
- i,
- (float)va_arg(vl, double));
- break;
-#else
- /* No support for floats, but attempt to store a float user event
- avoid a possible crash due to float reference. Instead store the
- data on uint_32 format (will not be displayed anyway). This is just
- to keep va_arg and i consistent. */
-
- case 'f': i = writeInt32( buffer,
- i,
- (uint32_t)va_arg(vl, double));
- break;
-#endif
- case 'l':
- formatStrIndex++;
- switch (formatStr[formatStrIndex])
- {
-#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT)
- case 'f': i = writeDouble(buffer,
- i,
- (double)va_arg(vl, double));
- break;
-#else
- /* No support for floats, but attempt to store a float user event
- avoid a possible crash due to float reference. Instead store the
- data on uint_32 format (will not be displayed anyway). This is just
- to keep va_arg and i consistent. */
- case 'f': i = writeInt32( buffer, /* In this case, the value will not be shown anyway */
- i,
- (uint32_t)va_arg(vl, double));
-
- i = writeInt32( buffer, /* Do it twice, to write in total 8 bytes */
- i,
- (uint32_t)va_arg(vl, double));
- break;
-#endif
-
- }
- break;
- case 'h':
- formatStrIndex++;
- switch (formatStr[formatStrIndex])
- {
- case 'd': i = writeInt16( buffer,
- i,
- (uint16_t)va_arg(vl, uint32_t));
- break;
- case 'u': i = writeInt16( buffer,
- i,
- (uint16_t)va_arg(vl, uint32_t));
- break;
- }
- break;
- case 'b':
- formatStrIndex++;
- switch (formatStr[formatStrIndex])
- {
- case 'd': i = writeInt8( buffer,
- i,
- (uint8_t)va_arg(vl, uint32_t));
- break;
-
- case 'u': i = writeInt8( buffer,
- i,
- (uint8_t)va_arg(vl, uint32_t));
- break;
- }
- break;
- }
- }
- else
- break;
- }
- formatStrIndex++;
- if (i == 255)
- {
- prvTraceError("vTracePrintF - Too large arguments, max 32 byte allowed!");
- return 0;
- }
- }
- return (uint8_t)(i+3)/4;
-}
-#endif
-
-/*******************************************************************************
- * prvTraceClearChannelBuffer
- *
- * Clears a number of items in the channel buffer, starting from nextSlotToWrite.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-static void prvTraceClearChannelBuffer(uint32_t count)
-{
- uint32_t slots;
-
- TRACE_ASSERT((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) >= count,
- "prvTraceClearChannelBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);
-
- /* Check if we're close to the end of the buffer */
- if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE))
- {
- slots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, slots);
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[0], 0, (count - slots));
- }
- else
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, count);
-}
-#endif
-
-/*******************************************************************************
- * prvTraceCopyToDataBuffer
- *
- * Copies a number of items to the data buffer, starting from nextSlotToWrite.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-static void prvTraceCopyToDataBuffer(uint32_t* data, uint32_t count)
-{
- uint32_t slots;
-
- TRACE_ASSERT(data != NULL,
- "prvTraceCopyToDataBuffer: data == NULL.", TRC_UNUSED);
- TRACE_ASSERT(count <= (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE),
- "prvTraceCopyToDataBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);
- /* Check if we're close to the end of the buffer */
- if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE))
- {
- slots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, slots * 4);
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[0], data + slots, (count - slots) * 4);
- }
- else
- {
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, count * 4);
- }
-}
-#endif
-
-/*******************************************************************************
- * prvTraceUBHelper1
- *
- * Calls on prvTraceUserEventFormat() to do the actual formatting, then goes on
- * to the next helper function.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-static void prvTraceUBHelper1(traceUBChannel channel, traceString eventLabel, traceString formatLabel, va_list vl)
-{
- uint32_t data[(3 + MAX_ARG_SIZE) / 4];
- uint8_t byteOffset = 4; /* Need room for timestamp */
- uint8_t noOfSlots;
-
- if (channel == 0)
- {
- /* We are dealing with an unknown channel format pair */
- byteOffset = (uint8_t)(byteOffset + 4); /* Also need room for channel and format */
- ((uint16_t*)data)[2] = eventLabel;
- ((uint16_t*)data)[3] = formatLabel;
- }
-
- noOfSlots = prvTraceUserEventFormat((char*)&(RecorderDataPtr->SymbolTable.symbytes[formatLabel+4]), vl, (uint8_t*)data, byteOffset);
-
- prvTraceUBHelper2(channel, data, noOfSlots);
-}
-#endif
-
-/*******************************************************************************
- * prvTraceUBHelper2
- *
- * This function simply copies the data buffer to the actual user event buffer.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t noOfSlots)
-{
- static uint32_t old_timestamp = 0;
- uint32_t old_nextSlotToWrite = 0;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) >= noOfSlots, "prvTraceUBHelper2: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);
-
- trcCRITICAL_SECTION_BEGIN();
- /* Store the timestamp */
- prvTracePortGetTimeStamp(data);
-
- if (*data < old_timestamp)
- {
- RecorderDataPtr->userEventBuffer.wraparoundCounter++;
- }
-
- old_timestamp = *data;
-
- /* Start by erasing any information in the channel buffer */
- prvTraceClearChannelBuffer(noOfSlots);
-
- prvTraceCopyToDataBuffer(data, noOfSlots); /* Will wrap around the data if necessary */
-
- old_nextSlotToWrite = RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Save the index that we want to write the channel data at when we're done */
- RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE); /* Make sure we never end up outside the buffer */
-
- /* Write to the channel buffer to indicate that this user event is ready to be used */
- if (channel != 0)
- {
- RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = channel;
- }
- else
- {
- /* 0xFF indicates that this is not a normal channel id */
- RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = (traceUBChannel)0xFF;
- }
- trcCRITICAL_SECTION_END();
-}
-#endif
-
-/*******************************************************************************
- * xTraceRegisterUBChannel
- *
- * Registers a channel for Separated User Events, i.e., those stored in the
- * separate user event buffer.
- *
- * Note: Only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is enabled in
- * trcSnapshotConfig.h
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr)
-{
- uint8_t i;
- traceUBChannel retVal = 0;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(formatStr != 0, "xTraceRegisterChannelFormat: formatStr == 0", (traceUBChannel)0);
-
- trcCRITICAL_SECTION_BEGIN();
- for (i = 1; i <= (TRC_CFG_UB_CHANNELS); i++) /* Size of the channels buffer is TRC_CFG_UB_CHANNELS + 1. Index 0 is unused. */
- {
- if(RecorderDataPtr->userEventBuffer.channels[i].name == 0 && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == 0)
- {
- /* Found empty slot */
- RecorderDataPtr->userEventBuffer.channels[i].name = channel;
- RecorderDataPtr->userEventBuffer.channels[i].defaultFormat = formatStr;
- retVal = (traceUBChannel)i;
- break;
- }
-
- if (RecorderDataPtr->userEventBuffer.channels[i].name == channel && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == formatStr)
- {
- /* Found a match */
- retVal = (traceUBChannel)i;
- break;
- }
- }
- trcCRITICAL_SECTION_END();
-
- return retVal;
-}
-#endif
-
-/******************************************************************************
- * vTraceUBData
- *
- * Slightly faster version of vTracePrintF() due to no lookups.
- *
- * Note: This is only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is
- * enabled in trcSnapshotConfig.h
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-void vTraceUBData(traceUBChannel channelPair, ...)
-{
- va_list vl;
-
- TRACE_ASSERT(channelPair != 0, "vTraceUBData: Not a valid traceUBChannel!", TRC_UNUSED);
-
- va_start(vl, channelPair);
- vTraceUBData_Helper(channelPair, vl);
- va_end(vl);
-}
-#endif
-
-/* Extracts the channel name and format string from the traceUBChannel, then calls prvTraceUBHelper1. */
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-void vTraceUBData_Helper(traceUBChannel channelPair, va_list vl)
-{
- traceString channel;
- traceString formatStr;
-
- TRACE_ASSERT(channelPair != 0, "vTraceUBData_Helper: channelPair == 0", TRC_UNUSED);
- TRACE_ASSERT(channelPair <= (TRC_CFG_UB_CHANNELS), "vTraceUBData_Helper: ", TRC_UNUSED);
-
- channel = RecorderDataPtr->userEventBuffer.channels[channelPair].name;
- formatStr = RecorderDataPtr->userEventBuffer.channels[channelPair].defaultFormat;
-
- prvTraceUBHelper1(channelPair, channel, formatStr, vl);
-}
-#endif
-
-/******************************************************************************
- * vTraceUBEvent
- *
- * Slightly faster version of ... due to no lookups.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))
-void vTraceUBEvent(traceUBChannel channelPair)
-{
- uint32_t data[(3 + MAX_ARG_SIZE) / 4];
-
- TRACE_ASSERT(channelPair != 0, "vTraceUBEvent: channelPair == 0", TRC_UNUSED);
- TRACE_ASSERT(channelPair <= (TRC_CFG_UB_CHANNELS), "vTraceUBEvent: ", TRC_UNUSED);
-
- prvTraceUBHelper2(channelPair, data, 1); /* Only need one slot for timestamp */
-}
-#endif
-
-/******************************************************************************
- * vTracePrintF
- *
- * Generates User Event with formatted text and data, similar to a "printf".
- * It is very fast compared to a normal "printf" since this function only
- * stores the arguments. The actual formatting is done
- * on the host PC when the trace is displayed in the viewer tool.
- *
- * User Event labels are created using xTraceRegisterString.
- * Example:
- *
- * traceString adc_uechannel = xTraceRegisterString("ADC User Events");
- * ...
- * vTracePrintF(adc_uechannel,
- * "ADC channel %d: %lf volts",
- * ch, (double)adc_reading/(double)scale);
- *
- * This can be combined into one line, if desired, but this is slower:
- *
- * vTracePrintF(xTraceRegisterString("ADC User Events"),
- * "ADC channel %d: %lf volts",
- * ch, (double)adc_reading/(double)scale);
- *
- * Calling xTraceRegisterString multiple times will not create duplicate entries, but
- * it is of course faster to just do it once, and then keep the handle for later
- * use. If you don't have any data arguments, only a text label/string, it is
- * better to use vTracePrint - it is faster.
- *
- * Format specifiers supported:
- * %d - 32 bit signed integer
- * %u - 32 bit unsigned integer
- * %f - 32 bit float
- * %s - string (is copied to the recorder symbol table)
- * %hd - 16 bit signed integer
- * %hu - 16 bit unsigned integer
- * %bd - 8 bit signed integer
- * %bu - 8 bit unsigned integer
- * %lf - double-precision float (Note! See below...)
- *
- * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.
- * In case this is exceeded, the user event is changed into an error message.
- *
- * The data is stored in trace buffer, and is packed to allow storing multiple
- * smaller data entries in the same 4-byte record, e.g., four 8-bit values.
- * A string requires two bytes, as the symbol table is limited to 64K. Storing
- * a double (%lf) uses two records, so this is quite costly. Use float (%f)
- * unless the higher precision is really necessary.
- *
- * Note that the double-precision float (%lf) assumes a 64 bit double
- * representation. This does not seem to be the case on e.g. PIC24 and PIC32.
- * Before using a %lf argument on a 16-bit MCU, please verify that
- * "sizeof(double)" actually gives 8 as expected. If not, use %f instead.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-void vTracePrintF(traceString eventLabel, const char* formatStr, ...)
-{
- va_list vl;
-
- va_start(vl, formatStr);
- vTracePrintF_Helper(eventLabel, formatStr, vl);
- va_end(vl);
-}
-#endif
-
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list vl)
-{
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 0)
- uint32_t noOfSlots;
- UserEvent* ue1;
- uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(formatStr != NULL, "vTracePrintF_Helper: formatStr == NULL", TRC_UNUSED);
-
- trcCRITICAL_SECTION_BEGIN();
-
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- /* First, write the "primary" user event entry in the local buffer, but
- let the event type be "EVENT_BEING_WRITTEN" for now...*/
-
- ue1 = (UserEvent*)(&tempDataBuffer[0]);
-
- ue1->type = EVENT_BEING_WRITTEN; /* Update this as the last step */
-
- noOfSlots = prvTraceUserEventFormat(formatStr, vl, (uint8_t*)tempDataBuffer, 4);
-
- /* Store the format string, with a reference to the channel symbol */
- ue1->payload = prvTraceOpenSymbol(formatStr, eventLabel);
-
- ue1->dts = (uint8_t)prvTraceGetDTS(0xFF);
-
- /* prvTraceGetDTS might stop the recorder in some cases... */
- if (RecorderDataPtr->recorderActive)
- {
-
- /* If the data does not fit in the remaining main buffer, wrap around to
- 0 if allowed, otherwise stop the recorder and quit). */
- if (RecorderDataPtr->nextFreeIndex + noOfSlots > RecorderDataPtr->maxEvents)
- {
- #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- (void)memset(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
- 0,
- (RecorderDataPtr->maxEvents - RecorderDataPtr->nextFreeIndex)*4);
- RecorderDataPtr->nextFreeIndex = 0;
- RecorderDataPtr->bufferIsFull = 1;
- #else
-
- /* Stop recorder, since the event data will not fit in the
- buffer and not circular buffer in this case... */
- vTraceStop();
- #endif
- }
-
- /* Check if recorder has been stopped (i.e., vTraceStop above) */
- if (RecorderDataPtr->recorderActive)
- {
- /* Check that the buffer to be overwritten does not contain any user
- events that would be partially overwritten. If so, they must be "killed"
- by replacing the user event and following data with NULL events (i.e.,
- using a memset to zero).*/
- #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- prvCheckDataToBeOverwrittenForMultiEntryEvents((uint8_t)noOfSlots);
- #endif
- /* Copy the local buffer to the main buffer */
- (void)memcpy(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
- tempDataBuffer,
- noOfSlots * 4);
-
- /* Update the event type, i.e., number of data entries following the
- main USER_EVENT entry (Note: important that this is after the memcpy,
- but within the critical section!)*/
- RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4] =
- (uint8_t) ( USER_EVENT + noOfSlots - 1 );
-
- /* Update the main buffer event index (already checked that it fits in
- the buffer, so no need to check for wrapping)*/
-
- RecorderDataPtr->nextFreeIndex += noOfSlots;
- RecorderDataPtr->numEvents += noOfSlots;
-
- if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))
- {
- #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- /* We have reached the end, but this is a ring buffer. Start from the beginning again. */
- RecorderDataPtr->bufferIsFull = 1;
- RecorderDataPtr->nextFreeIndex = 0;
- #else
- /* We have reached the end so we stop. */
- vTraceStop();
- #endif
- }
- }
-
- #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- /* Make sure the next entry is cleared correctly */
- prvCheckDataToBeOverwrittenForMultiEntryEvents(1);
- #endif
-
- }
- }
- trcCRITICAL_SECTION_END();
-
-#elif (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
- /* Use the separate user event buffer */
- traceString formatLabel;
- traceUBChannel channel;
-
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- formatLabel = xTraceRegisterString(formatStr);
-
- channel = xTraceRegisterUBChannel(eventLabel, formatLabel);
-
- prvTraceUBHelper1(channel, eventLabel, formatLabel, vl);
- }
-#endif
-}
-#endif
-
-/******************************************************************************
- * vTracePrint
- *
- * Basic user event
- *
- * Generates a User Event with a text label. The label is created/looked up
- * in the symbol table using xTraceRegisterString.
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-void vTracePrint(traceString chn, const char* str)
-{
-#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 0)
- UserEvent* ue;
- uint8_t dts1;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- dts1 = (uint8_t)prvTraceGetDTS(0xFF);
- ue = (UserEvent*) prvTraceNextFreeEventBufferSlot();
- if (ue != NULL)
- {
- ue->dts = dts1;
- ue->type = USER_EVENT;
- ue->payload = prvTraceOpenSymbol(str, chn);
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-
-#elif (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
- traceUBChannel channel;
- uint32_t noOfSlots = 1;
- uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- traceString trcStr = prvTraceOpenSymbol(str, chn);
- channel = xTraceRegisterUBChannel(chn, trcStr);
-
- if (channel == 0)
- {
- /* We are dealing with an unknown channel format pair */
- noOfSlots++; /* Also need room for channel and format */
- ((uint16_t*)tempDataBuffer)[2] = chn;
- ((uint16_t*)tempDataBuffer)[3] = trcStr;
- }
-
- prvTraceUBHelper2(channel, tempDataBuffer, noOfSlots);
- }
-#endif
-}
-#endif
-
-/*******************************************************************************
- * xTraceRegisterString
- *
- * Register strings in the recorder, e.g. for names of user event channels.
- *
- * Example:
- * myEventHandle = xTraceRegisterString("MyUserEvent");
- * ...
- * vTracePrintF(myEventHandle, "My value is: %d", myValue);
- ******************************************************************************/
-#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))
-traceString xTraceRegisterString(const char* label)
-{
- TRACE_ASSERT(label != NULL, "xTraceRegisterString: label == NULL", (traceString)0);
- TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);
- return prvTraceOpenSymbol(label, 0);
-}
-#endif
-
-
-#if ((!defined TRC_CFG_INCLUDE_READY_EVENTS) || (TRC_CFG_INCLUDE_READY_EVENTS == 1))
-
-void prvTraceSetReadyEventsEnabled(int status)
-{
- readyEventsEnabled = status;
-}
-
-/*******************************************************************************
- * prvTraceStoreTaskReady
- *
- * This function stores a ready state for the task handle sent in as parameter.
- ******************************************************************************/
-void prvTraceStoreTaskReady(traceHandle handle)
-{
- uint16_t dts3;
- TREvent* tr;
- uint8_t hnd8;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- if (handle == 0)
- {
- /* On FreeRTOS v7.3.0, this occurs when creating tasks due to a bad
- placement of the trace macro. In that case, the events are ignored. */
- return;
- }
-
- if (! readyEventsEnabled)
- {
- /* When creating tasks, ready events are also created. If creating
- a "hidden" (not traced) task, we must therefore disable recording
- of ready events to avoid an undesired ready event... */
- return;
- }
-
- TRACE_ASSERT(handle <= (TRC_CFG_NTASK), "prvTraceStoreTaskReady: Invalid value for handle", TRC_UNUSED);
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("Recorder busy - high priority ISR using syscall? (1)");
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
- {
- dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);
- hnd8 = prvTraceGet8BitHandle(handle);
- tr = (TREvent*)prvTraceNextFreeEventBufferSlot();
- if (tr != NULL)
- {
- tr->type = DIV_TASK_READY;
- tr->dts = dts3;
- tr->objHandle = hnd8;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-#endif
-
-/*******************************************************************************
- * prvTraceStoreLowPower
- *
- * This function stores a low power state.
- ******************************************************************************/
-void prvTraceStoreLowPower(uint32_t flag)
-{
- uint16_t dts;
- LPEvent* lp;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(flag <= 1, "prvTraceStoreLowPower: Invalid flag value", TRC_UNUSED);
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("Recorder busy - high priority ISR using syscall? (1)");
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive)
- {
- dts = (uint16_t)prvTraceGetDTS(0xFFFF);
- lp = (LPEvent*)prvTraceNextFreeEventBufferSlot();
- if (lp != NULL)
- {
- lp->type = (uint8_t) (LOW_POWER_BEGIN + ( uint8_t ) flag); /* BEGIN or END depending on flag */
- lp->dts = dts;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-
-/*******************************************************************************
- * vTraceStoreMemMangEvent
- *
- * This function stores malloc and free events. Each call requires two records,
- * for size and address respectively. The event code parameter (ecode) is applied
- * to the first record (size) and the following address record gets event
- * code "ecode + 1", so make sure this is respected in the event code table.
- * Note: On "free" calls, the signed_size parameter should be negative.
- ******************************************************************************/
-#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1)
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size)
-{
- uint8_t dts1;
- MemEventSize * ms;
- MemEventAddr * ma;
- uint16_t size_low;
- uint16_t addr_low;
- uint8_t addr_high;
- uint32_t size;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- if (RecorderDataPtr == NULL)
- {
- /* Occurs in vTraceInitTraceData, if using dynamic allocation. */
- return;
- }
-
- if (signed_size < 0)
- size = (uint32_t)(- signed_size);
- else
- size = (uint32_t)(signed_size);
-
- trcCRITICAL_SECTION_BEGIN();
-
- heapMemUsage = heapMemUsage + (uint32_t)signed_size;
-
- if (RecorderDataPtr->recorderActive)
- {
- dts1 = (uint8_t)prvTraceGetDTS(0xFF);
- size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);
- ms = (MemEventSize *)prvTraceNextFreeEventBufferSlot();
-
- if (ms != NULL)
- {
- ms->dts = dts1;
- ms->type = NULL_EVENT; /* Updated when all events are written */
- ms->size = size_low;
- prvTraceUpdateCounters();
-
- /* Storing a second record with address (signals "failed" if null) */
- #if (TRC_CFG_HEAP_SIZE_BELOW_16M)
- /* If the heap address range is within 16 MB, i.e., the upper 8 bits
- of addresses are constant, this optimization avoids storing an extra
- event record by ignoring the upper 8 bit of the address */
- addr_low = address & 0xFFFF;
- addr_high = (address >> 16) & 0xFF;
- #else
- /* The whole 32 bit address is stored using a second event record
- for the upper 16 bit */
- addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);
- addr_high = 0;
- #endif
-
- ma = (MemEventAddr *) prvTraceNextFreeEventBufferSlot();
- if (ma != NULL)
- {
- ma->addr_low = addr_low;
- ma->addr_high = addr_high;
- ma->type = (uint8_t) (ecode + 1); /* Note this! */
- ms->type = (uint8_t) ecode;
- prvTraceUpdateCounters();
- RecorderDataPtr->heapMemUsage = heapMemUsage;
- }
- }
- }
- trcCRITICAL_SECTION_END();
-}
-#endif /* TRC_CFG_SCHEDULING_ONLY */
-#endif
-
-/*******************************************************************************
- * prvTraceStoreKernelCall
- *
- * This is the main integration point for storing kernel calls, and
- * is called by the hooks in trcKernelHooks.h (see trcKernelPort.h for event codes).
- ******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-void prvTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint32_t objectNumber)
-{
- KernelCall * kse;
- uint16_t dts1;
- uint8_t hnd8;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(ecode < 0xFF, "prvTraceStoreKernelCall: ecode >= 0xFF", TRC_UNUSED);
- TRACE_ASSERT(objectClass < TRACE_NCLASSES, "prvTraceStoreKernelCall: objectClass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "prvTraceStoreKernelCall: Invalid value for objectNumber", TRC_UNUSED);
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("Recorder busy - high priority ISR using syscall? (2)");
- return;
- }
-
- if (handle_of_last_logged_task == 0)
- {
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive)
- {
- dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);
- hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);
- kse = (KernelCall*) prvTraceNextFreeEventBufferSlot();
- if (kse != NULL)
- {
- kse->dts = dts1;
- kse->type = (uint8_t)ecode;
- kse->objHandle = hnd8;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-#endif /* TRC_CFG_SCHEDULING_ONLY */
-
-/*******************************************************************************
- * prvTraceStoreKernelCallWithParam
- *
- * Used for storing kernel calls with a handle and a numeric parameter. If the
- * numeric parameter does not fit in one byte, and extra XPS event is inserted
- * before the kernel call event containing the three upper bytes.
- ******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-void prvTraceStoreKernelCallWithParam(uint32_t evtcode,
- traceObjectClass objectClass,
- uint32_t objectNumber,
- uint32_t param)
-{
- KernelCallWithParamAndHandle * kse;
- uint8_t dts2;
- uint8_t hnd8;
- uint8_t p8;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(evtcode < 0xFF, "prvTraceStoreKernelCallWithParam: evtcode >= 0xFF", TRC_UNUSED);
- TRACE_ASSERT(objectClass < TRACE_NCLASSES, "prvTraceStoreKernelCallWithParam: objectClass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "prvTraceStoreKernelCallWithParam: Invalid value for objectNumber", TRC_UNUSED);
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("Recorder busy - high priority ISR using syscall? (3)");
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- dts2 = (uint8_t)prvTraceGetDTS(0xFF);
- p8 = (uint8_t) prvTraceGetParam(0xFF, param);
- hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);
- kse = (KernelCallWithParamAndHandle*) prvTraceNextFreeEventBufferSlot();
- if (kse != NULL)
- {
- kse->dts = dts2;
- kse->type = (uint8_t)evtcode;
- kse->objHandle = hnd8;
- kse->param = p8;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-#endif /* TRC_CFG_SCHEDULING_ONLY */
-
-
-/*******************************************************************************
- * prvTraceGetParam
- *
- * Used for storing extra bytes for kernel calls with numeric parameters.
- *
- * May only be called within a critical section!
- ******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-static uint32_t prvTraceGetParam(uint32_t param_max, uint32_t param)
-{
- XPSEvent* xps;
-
- TRACE_ASSERT(param_max == 0xFF || param_max == 0xFFFF,
- "prvTraceGetParam: Invalid value for param_max", param);
-
- if (param <= param_max)
- {
- return param;
- }
- else
- {
- xps = (XPSEvent*) prvTraceNextFreeEventBufferSlot();
- if (xps != NULL)
- {
- xps->type = DIV_XPS;
- xps->xps_8 = (uint8_t)((param & (0xFF00 & ~param_max)) >> 8);
- xps->xps_16 = (uint16_t)((param & (0xFFFF0000 & ~param_max)) >> 16);
- prvTraceUpdateCounters();
- }
-
- return param & param_max;
- }
-}
-#endif
-
-/*******************************************************************************
- * prvTraceStoreKernelCallWithNumericParamOnly
- *
- * Used for storing kernel calls with numeric parameters only. This is
- * only used for traceTASK_DELAY and traceDELAY_UNTIL at the moment.
- ******************************************************************************/
-#if (TRC_CFG_SCHEDULING_ONLY == 0)
-void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param)
-{
- KernelCallWithParam16 * kse;
- uint8_t dts6;
- uint16_t restParam;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- restParam = 0;
-
- TRACE_ASSERT(evtcode < 0xFF, "prvTraceStoreKernelCallWithNumericParamOnly: Invalid value for evtcode", TRC_UNUSED);
-
- if (recorder_busy)
- {
- /*************************************************************************
- * This occurs if an ISR calls a trace function, preempting a previous
- * trace call that is being processed in a different ISR or task.
- * If this occurs, there is probably a problem in the definition of the
- * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and
- * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt
- * and any other ISRs that calls the trace recorder directly or via
- * traced kernel functions. The ARM port disables all interrupts using the
- * PRIMASK register to avoid this issue.
- *************************************************************************/
- prvTraceError("Recorder busy - high priority ISR using syscall? (4)");
- return;
- }
-
- trcCRITICAL_SECTION_BEGIN();
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
- {
- dts6 = (uint8_t)prvTraceGetDTS(0xFF);
- restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);
- kse = (KernelCallWithParam16*) prvTraceNextFreeEventBufferSlot();
- if (kse != NULL)
- {
- kse->dts = dts6;
- kse->type = (uint8_t)evtcode;
- kse->param = restParam;
- prvTraceUpdateCounters();
- }
- }
- trcCRITICAL_SECTION_END();
-}
-#endif /* TRC_CFG_SCHEDULING_ONLY */
-
-/*******************************************************************************
- * prvTraceStoreTaskswitch
- * Called by the scheduler from the SWITCHED_OUT hook, and by uiTraceStart.
- * At this point interrupts are assumed to be disabled!
- ******************************************************************************/
-void prvTraceStoreTaskswitch(traceHandle task_handle)
-{
- uint16_t dts3;
- TSEvent* ts;
- uint8_t hnd8;
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
- extern int32_t isPendingContextSwitch;
-#endif
- trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY();
-
- TRACE_ASSERT(task_handle <= (TRC_CFG_NTASK),
- "prvTraceStoreTaskswitch: Invalid value for task_handle", TRC_UNUSED);
-
- trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY();
-
- if ((task_handle != handle_of_last_logged_task) && (RecorderDataPtr->recorderActive))
- {
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
- isPendingContextSwitch = 0;
-#endif
-
- dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);
- handle_of_last_logged_task = task_handle;
- hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);
- ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();
-
- if (ts != NULL)
- {
- if (prvTraceGetObjectState(TRACE_CLASS_TASK,
- handle_of_last_logged_task) == TASK_STATE_INSTANCE_ACTIVE)
- {
- ts->type = TS_TASK_RESUME;
- }
- else
- {
- ts->type = TS_TASK_BEGIN;
- }
-
- ts->dts = dts3;
- ts->objHandle = hnd8;
-
- prvTraceSetObjectState(TRACE_CLASS_TASK,
- handle_of_last_logged_task,
- TASK_STATE_INSTANCE_ACTIVE);
-
- prvTraceUpdateCounters();
- }
- }
-
- trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY();
-}
-
-/*******************************************************************************
- * prvTraceStoreObjectNameOnCloseEvent
- *
- * Updates the symbol table with the name of this object from the dynamic
- * objects table and stores a "close" event, holding the mapping between handle
- * and name (a symbol table handle). The stored name-handle mapping is thus the
- * "old" one, valid up until this point.
- ******************************************************************************/
-void prvTraceStoreObjectNameOnCloseEvent(uint8_t evtcode, traceHandle handle,
- traceObjectClass objectclass)
-{
- ObjCloseNameEvent * ce;
- const char * name;
- traceString idx;
-
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceStoreObjectNameOnCloseEvent: objectclass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceStoreObjectNameOnCloseEvent: Invalid value for handle", TRC_UNUSED);
-
- if (RecorderDataPtr->recorderActive)
- {
- uint8_t hnd8 = prvTraceGet8BitHandle(handle);
- name = TRACE_PROPERTY_NAME_GET(objectclass, handle);
- idx = prvTraceOpenSymbol(name, 0);
-
- // Interrupt disable not necessary, already done in trcHooks.h macro
- ce = (ObjCloseNameEvent*) prvTraceNextFreeEventBufferSlot();
- if (ce != NULL)
- {
- ce->type = (uint8_t) evtcode;
- ce->objHandle = hnd8;
- ce->symbolIndex = idx;
- prvTraceUpdateCounters();
- }
- }
-}
-
-void prvTraceStoreObjectPropertiesOnCloseEvent(uint8_t evtcode, traceHandle handle,
- traceObjectClass objectclass)
-{
- ObjClosePropEvent * pe;
-
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceStoreObjectPropertiesOnCloseEvent: objectclass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceStoreObjectPropertiesOnCloseEvent: Invalid value for handle", TRC_UNUSED);
-
- if (RecorderDataPtr->recorderActive)
- {
- // Interrupt disable not necessary, already done in trcHooks.h macro
- pe = (ObjClosePropEvent*) prvTraceNextFreeEventBufferSlot();
- if (pe != NULL)
- {
- if (objectclass == TRACE_CLASS_TASK)
- {
- pe->arg1 = TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle);
- }
- else
- {
- pe->arg1 = TRACE_PROPERTY_OBJECT_STATE(objectclass, handle);
- }
- pe->type = evtcode;
- prvTraceUpdateCounters();
- }
- }
-}
-
-void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value)
-{
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceSetPriorityProperty: objectclass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceSetPriorityProperty: Invalid value for id", TRC_UNUSED);
-
- TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id) = value;
-}
-
-uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id)
-{
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceGetPriorityProperty: objectclass >= TRACE_NCLASSES", 0);
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceGetPriorityProperty: Invalid value for id", 0);
-
- return TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id);
-}
-
-void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value)
-{
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceSetObjectState: objectclass >= TRACE_NCLASSES", TRC_UNUSED);
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceSetObjectState: Invalid value for id", TRC_UNUSED);
-
- TRACE_PROPERTY_OBJECT_STATE(objectclass, id) = value;
-}
-
-uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id)
-{
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceGetObjectState: objectclass >= TRACE_NCLASSES", 0);
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceGetObjectState: Invalid value for id", 0);
-
- return TRACE_PROPERTY_OBJECT_STATE(objectclass, id);
-}
-
-void prvTraceSetTaskInstanceFinished(traceHandle handle)
-{
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_TASK],
- "prvTraceSetTaskInstanceFinished: Invalid value for handle", TRC_UNUSED);
-
-#if (TRC_CFG_USE_IMPLICIT_IFE_RULES == 1)
- TRACE_PROPERTY_OBJECT_STATE(TRACE_CLASS_TASK, handle) = 0;
-#endif
-}
-
-/*******************************************************************************
- * Static data initializations
- ******************************************************************************/
-
-/* A set of stacks that keeps track of available object handles for each class.
-The stacks are empty initially, meaning that allocation of new handles will be
-based on a counter (for each object class). Any delete operation will
-return the handle to the corresponding stack, for reuse on the next allocate.*/
-objectHandleStackType objectHandleStacks = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };
-
-/* Initial TRC_HWTC_COUNT value, for detecting if the time-stamping source is
-enabled. If using the OS periodic timer for time-stamping, this might not
-have been configured on the earliest events during the startup. */
-uint32_t init_hwtc_count;
-
-/*******************************************************************************
- * RecorderData
- *
- * The main data structure in snapshot mode, when using the default static memory
- * allocation (TRC_RECORDER_BUFFER_ALLOCATION_STATIC). The recorder uses a pointer
- * RecorderDataPtr to access the data, to also allow for dynamic or custom data
- * allocation (see TRC_CFG_RECORDER_BUFFER_ALLOCATION).
- ******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)
-RecorderDataType RecorderData;
-#endif
-
-/*******************************************************************************
- * RecorderDataPtr
- *
- * Pointer to the main data structure, when in snapshot mode.
- ******************************************************************************/
-RecorderDataType* RecorderDataPtr = NULL;
-
-/* This version of the function dynamically allocates the trace data */
-void prvTraceInitTraceData()
-{
-
- if (RecorderDataPtr == NULL)
- {
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)
- RecorderDataPtr = &RecorderData;
-#elif (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)
- RecorderDataPtr = (RecorderDataType*)TRACE_MALLOC(sizeof(RecorderDataType));
- if (! RecorderDataPtr)
- {
- prvTraceError("Failed allocating recorder buffer!");
- return;
- }
-#elif (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
- if (! RecorderDataPtr)
- {
- prvTraceError("Recorder data pointer not set! Use vTraceSetRecorderDataBuffer().");
- return;
- }
-#endif
- }
- else
- {
- if (RecorderDataPtr->startmarker0 == 1)
- {
- /* Already initialized */
- return;
- }
- }
-
- init_hwtc_count = TRC_HWTC_COUNT;
-
- (void)memset(RecorderDataPtr, 0, sizeof(RecorderDataType));
-
- RecorderDataPtr->version = TRACE_KERNEL_VERSION;
- RecorderDataPtr->minor_version = TRACE_MINOR_VERSION;
- RecorderDataPtr->irq_priority_order = TRC_IRQ_PRIORITY_ORDER;
- RecorderDataPtr->filesize = sizeof(RecorderDataType);
- RecorderDataPtr->maxEvents = (TRC_CFG_EVENT_BUFFER_SIZE);
- RecorderDataPtr->debugMarker0 = (int32_t) 0xF0F0F0F0;
- RecorderDataPtr->isUsing16bitHandles = TRC_CFG_USE_16BIT_OBJECT_HANDLES;
- RecorderDataPtr->isrTailchainingThreshold = TRC_CFG_ISR_TAILCHAINING_THRESHOLD;
-
- /* This function is kernel specific */
- vTraceInitObjectPropertyTable();
-
- RecorderDataPtr->debugMarker1 = (int32_t)0xF1F1F1F1;
- RecorderDataPtr->SymbolTable.symTableSize = (TRC_CFG_SYMBOL_TABLE_SIZE);
- RecorderDataPtr->SymbolTable.nextFreeSymbolIndex = 1;
-#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)
- RecorderDataPtr->exampleFloatEncoding = 1.0f; /* otherwise already zero */
-#endif
- RecorderDataPtr->debugMarker2 = (int32_t)0xF2F2F2F2;
- prvStrncpy(RecorderDataPtr->systemInfo, "Trace Recorder Demo", 80);
- RecorderDataPtr->debugMarker3 = (int32_t)0xF3F3F3F3;
- RecorderDataPtr->endmarker0 = 0x0A;
- RecorderDataPtr->endmarker1 = 0x0B;
- RecorderDataPtr->endmarker2 = 0x0C;
- RecorderDataPtr->endmarker3 = 0x0D;
- RecorderDataPtr->endmarker4 = 0x71;
- RecorderDataPtr->endmarker5 = 0x72;
- RecorderDataPtr->endmarker6 = 0x73;
- RecorderDataPtr->endmarker7 = 0x74;
- RecorderDataPtr->endmarker8 = 0xF1;
- RecorderDataPtr->endmarker9 = 0xF2;
- RecorderDataPtr->endmarker10 = 0xF3;
- RecorderDataPtr->endmarker11 = 0xF4;
-
-#if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER
- RecorderDataPtr->userEventBuffer.bufferID = 1;
- RecorderDataPtr->userEventBuffer.version = 0;
- RecorderDataPtr->userEventBuffer.numberOfSlots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE);
- RecorderDataPtr->userEventBuffer.numberOfChannels = (TRC_CFG_UB_CHANNELS) + 1;
-#endif
-
- /* Kernel specific initialization of the objectHandleStacks variable */
- vTraceInitObjectHandleStack();
-
-
- /* Finally, the 12-byte "start markers" are initialized, allowing for
- Tracealyzer to find the trace data in a larger RAM dump.
-
- The start and end markers must be unique, but without proper precautions there
- might be a risk of accidental duplicates of the start/end markers, e.g., due to
- compiler optimizations.
-
- The below initialization of the start marker is therefore made in reverse order
- and the fields are volatile to ensure this assignment order. This to avoid any
- chance of accidental duplicates of this elsewhere in memory.
-
- Moreover, the fields are set byte-by-byte to avoid endian issues.*/
-
- RecorderDataPtr->startmarker11 = 0xF4;
- RecorderDataPtr->startmarker10 = 0xF3;
- RecorderDataPtr->startmarker9 = 0xF2;
- RecorderDataPtr->startmarker8 = 0xF1;
- RecorderDataPtr->startmarker7 = 0x74;
- RecorderDataPtr->startmarker6 = 0x73;
- RecorderDataPtr->startmarker5 = 0x72;
- RecorderDataPtr->startmarker4 = 0x71;
- RecorderDataPtr->startmarker3 = 0x04;
- RecorderDataPtr->startmarker2 = 0x03;
- RecorderDataPtr->startmarker1 = 0x02;
- RecorderDataPtr->startmarker0 = 0x01;
-
- if (traceErrorMessage != NULL)
- {
- // An error was detected before vTraceEnable was called, make sure this is stored in the trace data.
- prvStrncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);
- RecorderDataPtr->internalErrorOccured = 1;
- vTraceStop();
- }
-
-
-
-#ifdef TRC_PORT_SPECIFIC_INIT
- TRC_PORT_SPECIFIC_INIT();
-#endif
-}
-
-
-void* prvTraceNextFreeEventBufferSlot(void)
-{
- if (! RecorderDataPtr->recorderActive)
- {
- /* If an XTS or XPS event prior to the main event has filled the buffer
- before saving the main event, and store mode is "stop when full". */
- return NULL;
- }
-
- if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))
- {
- prvTraceError("Attempt to index outside event buffer!");
- return NULL;
- }
- return (void*)(&RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex*4]);
-}
-
-uint16_t uiIndexOfObject(traceHandle objecthandle, uint8_t objectclass)
-{
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "uiIndexOfObject: Invalid value for objectclass", 0);
- TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "uiIndexOfObject: Invalid value for objecthandle", 0);
-
- if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) &&
- (objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass]))
- {
- return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] +
- (RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[objectclass] * (objecthandle-1)));
- }
-
- prvTraceError("Object table lookup with invalid object handle or object class!");
- return 0;
-}
-
-traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass)
-{
- traceHandle handle;
- static int indexOfHandle;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);
-
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceGetObjectHandle: Invalid value for objectclass", (traceHandle)0);
-
- trcCRITICAL_SECTION_BEGIN();
- indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];
- if (objectHandleStacks.objectHandles[indexOfHandle] == 0)
- {
- /* Zero is used to indicate a never before used handle, i.e.,
- new slots in the handle stack. The handle slot needs to
- be initialized here (starts at 1). */
- objectHandleStacks.objectHandles[indexOfHandle] =
- (traceHandle)(1 + indexOfHandle -
- objectHandleStacks.lowestIndexOfClass[objectclass]);
- }
-
- handle = objectHandleStacks.objectHandles[indexOfHandle];
-
- if (objectHandleStacks.indexOfNextAvailableHandle[objectclass]
- > objectHandleStacks.highestIndexOfClass[objectclass])
- {
- prvTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));
- handle = 0;
- }
- else
- {
- int hndCount;
- objectHandleStacks.indexOfNextAvailableHandle[objectclass]++;
-
- hndCount = objectHandleStacks.indexOfNextAvailableHandle[objectclass] -
- objectHandleStacks.lowestIndexOfClass[objectclass];
-
- if (hndCount >
- objectHandleStacks.handleCountWaterMarksOfClass[objectclass])
- {
- objectHandleStacks.handleCountWaterMarksOfClass[objectclass] =
- (traceHandle)hndCount;
- }
- }
- trcCRITICAL_SECTION_END();
-
- return handle;
-}
-
-void prvTraceFreeObjectHandle(traceObjectClass objectclass, traceHandle handle)
-{
- int indexOfHandle;
-
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,
- "prvTraceFreeObjectHandle: Invalid value for objectclass", TRC_UNUSED);
- TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
- "prvTraceFreeObjectHandle: Invalid value for handle", TRC_UNUSED);
-
- /* Check that there is room to push the handle on the stack */
- if ((objectHandleStacks.indexOfNextAvailableHandle[objectclass] - 1) <
- objectHandleStacks.lowestIndexOfClass[objectclass])
- {
- /* Error */
- prvTraceError("Attempt to free more handles than allocated!");
- }
- else
- {
- objectHandleStacks.indexOfNextAvailableHandle[objectclass]--;
- indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];
- objectHandleStacks.objectHandles[indexOfHandle] = handle;
- }
-}
-
-/*******************************************************************************
- * prvMarkObjectAsUsed
- *
- * Sets an "is used flag" on object creation, using the first byte of the name
- * field. This allows for counting the number of used Object Table slots, even
- * if no names have been set.
- ******************************************************************************/
-void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle)
-{
- uint16_t idx = uiIndexOfObject(handle, objectclass);
- RecorderDataPtr->ObjectPropertyTable.objbytes[idx] = 1;
-}
-
-/*******************************************************************************
- * prvStrncpy
- *
- * Private string copy function, to improve portability between compilers.
- ******************************************************************************/
-static void prvStrncpy(char* dst, const char* src, uint32_t maxLength)
-{
- uint32_t i;
- for (i = 0; i < maxLength; i++)
- {
- dst[i] = src[i];
- if (src[i] == 0)
- break;
- }
-}
-
-/*******************************************************************************
- * prvTraceSetObjectName
- *
- * Registers the names of queues, semaphores and other kernel objects in the
- * recorder's Object Property Table, at the given handle and object class.
- ******************************************************************************/
-void prvTraceSetObjectName(traceObjectClass objectclass,
- traceHandle handle,
- const char* name)
-{
- static uint16_t idx;
-
- TRACE_ASSERT(name != NULL, "prvTraceSetObjectName: name == NULL", TRC_UNUSED);
-
- if (objectclass >= TRACE_NCLASSES)
- {
- prvTraceError("Illegal object class in prvTraceSetObjectName");
- return;
- }
-
- if (handle == 0)
- {
- prvTraceError("Illegal handle (0) in prvTraceSetObjectName.");
- return;
- }
-
- if (handle > RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass])
- {
- /* ERROR */
- prvTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));
- }
- else
- {
- idx = uiIndexOfObject(handle, objectclass);
-
- if (traceErrorMessage == NULL)
- {
- prvStrncpy((char*)&(RecorderDataPtr->ObjectPropertyTable.objbytes[idx]),
- name,
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[ objectclass ]);
- }
- }
-}
-
-traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel)
-{
- uint16_t result;
- uint8_t len;
- uint8_t crc;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- len = 0;
- crc = 0;
-
- TRACE_ASSERT(name != NULL, "prvTraceOpenSymbol: name == NULL", (traceString)0);
-
- prvTraceGetChecksum(name, &crc, &len);
-
- trcCRITICAL_SECTION_BEGIN();
- result = prvTraceLookupSymbolTableEntry(name, crc, len, userEventChannel);
- if (!result)
- {
- result = prvTraceCreateSymbolTableEntry(name, crc, len, userEventChannel);
- }
- trcCRITICAL_SECTION_END();
-
- return result;
-}
-
-
-/******************************************************************************
-* vTraceSetFrequency
-*
-* Registers the clock rate of the time source for the event timestamping.
-* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)
-* should be incorrect for your setup, you can override it using this function.
-*
-* Must be called prior to vTraceEnable, and the time source is assumed to
-* have a fixed clock frequency after the startup.
-*
-* Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.
-* This is a software "prescaler" that is also applied on the timestamps.
-*****************************************************************************/
-void vTraceSetFrequency(uint32_t frequency)
-{
- timestampFrequency = frequency;
-}
-
-/*******************************************************************************
- * Supporting functions
- ******************************************************************************/
-
-/*******************************************************************************
- * prvTraceError
- *
- * Called by various parts in the recorder. Stops the recorder and stores a
- * pointer to an error message, which is printed by the monitor task.
- * If you are not using the monitor task, you may use xTraceGetLastError()
- * from your application to check if the recorder is OK.
- *
- * Note: If a recorder error is registered before vTraceStart is called, the
- * trace start will be aborted. This can occur if any of the Nxxxx constants
- * (e.g., TRC_CFG_NTASK) in trcConfig.h is too small.
- ******************************************************************************/
-void prvTraceError(const char* msg)
-{
- /* Stop the recorder */
- if (RecorderDataPtr != NULL)
- {
- vTraceStop();
- }
-
- /* If first error only... */
- if (traceErrorMessage == NULL)
- {
- traceErrorMessage = (char*)(intptr_t) msg;
- if (RecorderDataPtr != NULL)
- {
- prvStrncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);
- RecorderDataPtr->internalErrorOccured = 1;
- }
- }
-}
-
-void vTraceSetFilterMask(uint16_t filterMask)
-{
- CurrentFilterMask = filterMask;
-}
-
-void vTraceSetFilterGroup(uint16_t filterGroup)
-{
- CurrentFilterGroup = filterGroup;
-}
-
-/******************************************************************************
- * prvCheckDataToBeOverwrittenForMultiEntryEvents
- *
- * This checks if the next event to be overwritten is a multi-entry user event,
- * i.e., a USER_EVENT followed by data entries.
- * Such data entries do not have an event code at byte 0, as other events.
- * All 4 bytes are user data, so the first byte of such data events must
- * not be interpreted as type field. The number of data entries following
- * a USER_EVENT is given in the event code of the USER_EVENT.
- * Therefore, when overwriting a USER_EVENT (when using in ring-buffer mode)
- * any data entries following must be replaced with NULL events (code 0).
- *
- * This is assumed to execute within a critical section...
- *****************************************************************************/
-
-#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
-void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)
-{
- /* Generic "int" type is desired - should be 16 bit variable on 16 bit HW */
- unsigned int i = 0;
- unsigned int e = 0;
-
- TRACE_ASSERT(nofEntriesToCheck != 0,
- "prvCheckDataToBeOverwrittenForMultiEntryEvents: nofEntriesToCheck == 0", TRC_UNUSED);
-
- while (i < nofEntriesToCheck)
- {
- e = RecorderDataPtr->nextFreeIndex + i;
- if ((RecorderDataPtr->eventData[e*4] > USER_EVENT) &&
- (RecorderDataPtr->eventData[e*4] < USER_EVENT + 16))
- {
- uint8_t nDataEvents = (uint8_t)(RecorderDataPtr->eventData[e*4] - USER_EVENT);
- if ((e + nDataEvents) < RecorderDataPtr->maxEvents)
- {
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, (size_t) (4 + 4 * nDataEvents));
- }
- }
- else if (RecorderDataPtr->eventData[e*4] == DIV_XPS)
- {
- if ((e + 1) < RecorderDataPtr->maxEvents)
- {
- /* Clear 8 bytes */
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4);
- }
- else
- {
- /* Clear 8 bytes, 4 first and 4 last */
- (void)memset(& RecorderDataPtr->eventData[0], 0, 4);
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4);
- }
- }
- i++;
- }
-}
-#endif
-
-/*******************************************************************************
- * prvTraceUpdateCounters
- *
- * Updates the index of the event buffer.
- ******************************************************************************/
-void prvTraceUpdateCounters(void)
-{
- if (RecorderDataPtr->recorderActive == 0)
- {
- return;
- }
-
- RecorderDataPtr->numEvents++;
-
- RecorderDataPtr->nextFreeIndex++;
-
- if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))
- {
-#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- RecorderDataPtr->bufferIsFull = 1;
- RecorderDataPtr->nextFreeIndex = 0;
-#else
- vTraceStop();
-#endif
- }
-
-#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)
- prvCheckDataToBeOverwrittenForMultiEntryEvents(1);
-#endif
-}
-
-/******************************************************************************
- * prvTraceGetDTS
- *
- * Returns a differential timestamp (DTS), i.e., the time since
- * last event, and creates an XTS event if the DTS does not fit in the
- * number of bits given. The XTS event holds the MSB bytes of the DTS.
- *
- * The parameter param_maxDTS should be 0xFF for 8-bit dts or 0xFFFF for
- * events with 16-bit dts fields.
- *****************************************************************************/
-uint16_t prvTraceGetDTS(uint16_t param_maxDTS)
-{
- static uint32_t old_timestamp = 0;
- XTSEvent* xts = 0;
- uint32_t dts = 0;
- uint32_t timestamp = 0;
-
- TRACE_ASSERT(param_maxDTS == 0xFF || param_maxDTS == 0xFFFF, "prvTraceGetDTS: Invalid value for param_maxDTS", 0);
-
-
- if (RecorderDataPtr->frequency == 0)
- {
- if (timestampFrequency != 0)
- {
- /* If to override default TRC_HWTC_FREQ_HZ value with value set by vTraceSetFrequency */
- RecorderDataPtr->frequency = timestampFrequency / (TRC_HWTC_DIVISOR);
- }
- else if (init_hwtc_count != (TRC_HWTC_COUNT))
- {
- /* If using default value and timer has been started.
- Note: If the default frequency value set here would be incorrect, e.g.,
- if the timer has actually not been configured yet, override this
- with vTraceSetFrequency.
- */
- RecorderDataPtr->frequency = (TRC_HWTC_FREQ_HZ) / (TRC_HWTC_DIVISOR);
- }
- /* If no override (vTraceSetFrequency) and timer inactive -> no action */
- }
-
- /**************************************************************************
- * The below statements read the timestamp from the timer port module.
- * If necessary, whole seconds are extracted using division while the rest
- * comes from the modulo operation.
- **************************************************************************/
-
- prvTracePortGetTimeStamp(×tamp);
-
- /***************************************************************************
- * Since dts is unsigned the result will be correct even if timestamp has
- * wrapped around.
- ***************************************************************************/
- dts = timestamp - old_timestamp;
- old_timestamp = timestamp;
-
- if (RecorderDataPtr->frequency > 0)
- {
- /* Check if dts > 1 second */
- if (dts > RecorderDataPtr->frequency)
- {
- /* More than 1 second has passed */
- RecorderDataPtr->absTimeLastEventSecond += dts / RecorderDataPtr->frequency;
- /* The part that is not an entire second is added to absTimeLastEvent */
- RecorderDataPtr->absTimeLastEvent += dts % RecorderDataPtr->frequency;
- }
- else
- {
- RecorderDataPtr->absTimeLastEvent += dts;
- }
-
- /* Check if absTimeLastEvent >= 1 second */
- if (RecorderDataPtr->absTimeLastEvent >= RecorderDataPtr->frequency)
- {
- /* RecorderDataPtr->absTimeLastEvent is more than or equal to 1 second, but always less than 2 seconds */
- RecorderDataPtr->absTimeLastEventSecond++;
- RecorderDataPtr->absTimeLastEvent -= RecorderDataPtr->frequency;
- /* RecorderDataPtr->absTimeLastEvent is now less than 1 second */
- }
- }
- else
- {
- /* Special case if the recorder has not yet started (frequency may be uninitialized, i.e., zero) */
- RecorderDataPtr->absTimeLastEvent = timestamp;
- }
-
- /* If the dts (time since last event) does not fit in event->dts (only 8 or 16 bits) */
- if (dts > param_maxDTS)
- {
- /* Create an XTS event (eXtended TimeStamp) containing the higher dts bits*/
- xts = (XTSEvent*) prvTraceNextFreeEventBufferSlot();
-
- if (xts != NULL)
- {
- if (param_maxDTS == 0xFFFF)
- {
- xts->type = XTS16;
- xts->xts_16 = (uint16_t)((dts / 0x10000) & 0xFFFF);
- xts->xts_8 = 0;
- }
- else if (param_maxDTS == 0xFF)
- {
- xts->type = XTS8;
- xts->xts_16 = (uint16_t)((dts / 0x100) & 0xFFFF);
- xts->xts_8 = (uint8_t)((dts / 0x1000000) & 0xFF);
- }
- else
- {
- prvTraceError("Bad param_maxDTS in prvTraceGetDTS");
- }
- prvTraceUpdateCounters();
- }
- }
-
- return (uint16_t)dts & param_maxDTS;
-}
-
-/*******************************************************************************
- * prvTraceLookupSymbolTableEntry
- *
- * Find an entry in the symbol table, return 0 if not present.
- *
- * The strings are stored in a byte pool, with four bytes of "meta-data" for
- * every string.
- * byte 0-1: index of next entry with same checksum (for fast lookup).
- * byte 2-3: reference to a symbol table entry, a label for vTracePrintF
- * format strings only (the handle of the destination channel).
- * byte 4..(4 + length): the string (object name or user event label), with
- * zero-termination
- ******************************************************************************/
-traceString prvTraceLookupSymbolTableEntry(const char* name,
- uint8_t crc6,
- uint8_t len,
- traceString chn)
-{
- uint16_t i = RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ];
-
- TRACE_ASSERT(name != NULL, "prvTraceLookupSymbolTableEntry: name == NULL", (traceString)0);
- TRACE_ASSERT(len != 0, "prvTraceLookupSymbolTableEntry: len == 0", (traceString)0);
-
- while (i != 0)
- {
- if (RecorderDataPtr->SymbolTable.symbytes[i + 2] == (chn & 0x00FF))
- {
- if (RecorderDataPtr->SymbolTable.symbytes[i + 3] == (chn / 0x100))
- {
- if (RecorderDataPtr->SymbolTable.symbytes[i + 4 + len] == '\0')
- {
- if (strncmp((char*)(& RecorderDataPtr->SymbolTable.symbytes[i + 4]), name, len) == 0)
- {
- break; /* found */
- }
- }
- }
- }
- i = (uint16_t)(RecorderDataPtr->SymbolTable.symbytes[i] + (RecorderDataPtr->SymbolTable.symbytes[i + 1] * 0x100));
- }
- return i;
-}
-
-/*******************************************************************************
- * prvTraceCreateSymbolTableEntry
- *
- * Creates an entry in the symbol table, independent if it exists already.
- *
- * The strings are stored in a byte pool, with four bytes of "meta-data" for
- * every string.
- * byte 0-1: index of next entry with same checksum (for fast lookup).
- * byte 2-3: reference to a symbol table entry, a label for vTracePrintF
- * format strings only (the handle of the destination channel).
- * byte 4..(4 + length): the string (object name or user event label), with
- * zero-termination
- ******************************************************************************/
-uint16_t prvTraceCreateSymbolTableEntry(const char* name,
- uint8_t crc6,
- uint8_t len,
- traceString channel)
-{
- uint16_t ret = 0;
-
- TRACE_ASSERT(name != NULL, "prvTraceCreateSymbolTableEntry: name == NULL", 0);
- TRACE_ASSERT(len != 0, "prvTraceCreateSymbolTableEntry: len == 0", 0);
-
- if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= (TRC_CFG_SYMBOL_TABLE_SIZE))
- {
- prvTraceError("Symbol table full. Increase TRC_CFG_SYMBOL_TABLE_SIZE in trcConfig.h");
- ret = 0;
- }
- else
- {
-
- RecorderDataPtr->SymbolTable.symbytes
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex] =
- (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] & 0x00FF);
-
- RecorderDataPtr->SymbolTable.symbytes
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 1] =
- (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] / 0x100);
-
- RecorderDataPtr->SymbolTable.symbytes
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 2] =
- (uint8_t)(channel & 0x00FF);
-
- RecorderDataPtr->SymbolTable.symbytes
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 3] =
- (uint8_t)(channel / 0x100);
-
- /* set name (bytes 4...4+len-1) */
- prvStrncpy((char*)&(RecorderDataPtr->SymbolTable.symbytes
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4]), name, len);
-
- /* Set zero termination (at offset 4+len) */
- RecorderDataPtr->SymbolTable.symbytes
- [RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4 + len] = '\0';
-
- /* store index of entry (for return value, and as head of LL[crc6]) */
- RecorderDataPtr->SymbolTable.latestEntryOfChecksum
- [ crc6 ] = (uint16_t)RecorderDataPtr->SymbolTable.nextFreeSymbolIndex;
-
- RecorderDataPtr->SymbolTable.nextFreeSymbolIndex += (uint32_t) (len + 5);
-
- ret = (uint16_t)(RecorderDataPtr->SymbolTable.nextFreeSymbolIndex - (uint8_t)(len + 5));
- }
-
- return ret;
-}
-
-
-/*******************************************************************************
- * prvTraceGetChecksum
- *
- * Calculates a simple 6-bit checksum from a string, used to index the string
- * for fast symbol table lookup.
- ******************************************************************************/
-void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength)
-{
- unsigned char c;
- int length = 1; /* Should be 1 to account for '\0' */
- int crc = 0;
-
- TRACE_ASSERT(pname != NULL, "prvTraceGetChecksum: pname == NULL", TRC_UNUSED);
- TRACE_ASSERT(pcrc != NULL, "prvTraceGetChecksum: pcrc == NULL", TRC_UNUSED);
- TRACE_ASSERT(plength != NULL, "prvTraceGetChecksum: plength == NULL", TRC_UNUSED);
-
- if (pname != (const char *) 0)
- {
- for (; (c = (unsigned char) *pname++) != '\0';)
- {
- crc += c;
- length++;
- }
- }
- *pcrc = (uint8_t)(crc & 0x3F);
- *plength = (uint8_t)length;
-}
-
-#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
-
-static void prvTraceStoreXID(traceHandle handle);
-
-/******************************************************************************
- * prvTraceStoreXID
- *
- * Stores an XID (eXtended IDentifier) event.
- * This is used if an object/task handle is larger than 255.
- * The parameter "handle" is the full (16 bit) handle, assumed to be 256 or
- * larger. Handles below 256 should not use this function.
- *
- * NOTE: this function MUST be called from within a critical section.
- *****************************************************************************/
-static void prvTraceStoreXID(traceHandle handle)
-{
- XPSEvent* xid;
-
- TRACE_ASSERT(handle >= 256, "prvTraceStoreXID: Handle < 256", TRC_UNUSED);
-
- xid = (XPSEvent*)prvTraceNextFreeEventBufferSlot();
-
- if (xid != NULL)
- {
- xid->type = XID;
-
- /* This function is (only) used when traceHandle is 16 bit... */
- xid->xps_16 = handle;
-
- prvTraceUpdateCounters();
- }
-}
-
-static uint8_t prvTraceGet8BitHandle(traceHandle handle)
-{
- if (handle > 255)
- {
- prvTraceStoreXID(handle);
- /* The full handle (16 bit) is stored in the XID event.
- This code (255) is used instead of zero (which is an error code).*/
- return 255;
- }
- return (uint8_t)(handle & 0xFF);
-}
-#endif /*(TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)*/
-
-
-/* If using DWT timestamping (default on ARM Cortex-M3, M4 and M7), make sure the DWT unit is initialized. */
-#ifndef TRC_CFG_ARM_CM_USE_SYSTICK
-#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M) && (defined (__CORTEX_M) && (__CORTEX_M >= 0x03)))
-void prvTraceInitCortexM()
-{
- /* Ensure that the DWT registers are unlocked and can be modified. */
- TRC_REG_ITM_LOCKACCESS = TRC_ITM_LOCKACCESS_UNLOCK;
-
- /* Make sure DWT is enabled, if supported */
- TRC_REG_DEMCR |= TRC_DEMCR_TRCENA;
-
- do{
- /* Verify that DWT is supported */
- if (TRC_REG_DEMCR == 0)
- {
- /* This function is called on Cortex-M3, M4 and M7 devices to initialize
- the DWT unit, assumed present. The DWT cycle counter is used for timestamping.
-
- If the below error is produced, the DWT unit does not seem to be available.
-
- In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build
- to use SysTick timestamping instead, or define your own timestamping by
- setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED
- and make the necessary definitions, as explained in trcHardwarePort.h.*/
-
- prvTraceError("DWT unit not available, see code comment.");
- break;
- }
-
- /* Verify that DWT_CYCCNT is supported */
- if (TRC_REG_DWT_CTRL & TRC_DWT_CTRL_NOCYCCNT)
- {
- /* This function is called on Cortex-M3, M4 and M7 devices to initialize
- the DWT unit, assumed present. The DWT cycle counter is used for timestamping.
-
- If the below error is produced, the cycle counter does not seem to be available.
-
- In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build
- to use SysTick timestamping instead, or define your own timestamping by
- setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED
- and make the necessary definitions, as explained in trcHardwarePort.h.*/
-
- prvTraceError("DWT_CYCCNT not available, see code comment.");
- break;
- }
-
- /* Reset the cycle counter */
- TRC_REG_DWT_CYCCNT = 0;
-
- /* Enable the cycle counter */
- TRC_REG_DWT_CTRL |= TRC_DWT_CTRL_CYCCNTENA;
-
- }while(0); /* breaks above jump here */
-}
-#endif
-#endif
-
-/******************************************************************************
- * prvTracePortGetTimeStamp
- *
- * Returns the current time based on the HWTC macros which provide a hardware
- * isolation layer towards the hardware timer/counter.
- *
- * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue
- * or the trace recorder library. Typically you should not need to change
- * the code of prvTracePortGetTimeStamp if using the HWTC macros.
- *
- ******************************************************************************/
-void prvTracePortGetTimeStamp(uint32_t *pTimestamp)
-{
- static uint32_t last_hwtc_count = 0;
- uint32_t hwtc_count = 0;
-
-#if TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR
- /* systick based timer */
- static uint32_t last_traceTickCount = 0;
- uint32_t traceTickCount = 0;
-#else /*TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR*/
- /* Free running timer */
- static uint32_t last_hwtc_rest = 0;
- uint32_t diff = 0;
- uint32_t diff_scaled = 0;
-#endif /*TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR*/
-
- if (trace_disable_timestamp == 1)
- {
- if (pTimestamp)
- *pTimestamp = last_timestamp;
- return;
- }
-
- /* Retrieve TRC_HWTC_COUNT only once since the same value should be used all throughout this function. */
-#if (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR)
- /* Get the increasing tick count */
- hwtc_count = (TRC_HWTC_COUNT);
-#elif (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR)
- /* Convert decreasing tick count into increasing tick count */
- hwtc_count = (TRC_HWTC_PERIOD) - (TRC_HWTC_COUNT);
-#else
- #error "TRC_HWTC_TYPE has unexpected value"
-#endif
-
-#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)
- /* The Win32 port uses ulGetRunTimeCounterValue for timestamping, which in turn
- uses QueryPerformanceCounter. That function is not always reliable when used over
- multiple threads. We must therefore handle rare cases where the timestamp is less
- than the previous. In practice, this should "never" roll over since the
- performance counter is 64 bit wide. */
-
- if (last_hwtc_count > hwtc_count)
- {
- hwtc_count = last_hwtc_count;
- }
-#endif
-
-#if (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)
- /* Timestamping is based on a timer that wraps at TRC_HWTC_PERIOD */
- if (last_traceTickCount - uiTraceTickCount - 1 < 0x80000000)
- {
- /* This means last_traceTickCount is higher than uiTraceTickCount,
- so we have previously compensated for a missed tick.
- Therefore we use the last stored value because that is more accurate. */
- traceTickCount = last_traceTickCount;
- }
- else
- {
- /* Business as usual */
- traceTickCount = uiTraceTickCount;
- }
-
- /* Check for overflow. May occur if the update of uiTraceTickCount has been
- delayed due to disabled interrupts. */
- if (traceTickCount == last_traceTickCount && hwtc_count < last_hwtc_count)
- {
- /* A trace tick has occurred but not been executed by the kernel, so we compensate manually. */
- traceTickCount++;
- }
-
- /* Check if the return address is OK, then we perform the calculation. */
- if (pTimestamp)
- {
- /* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */
- last_timestamp = traceTickCount * ((TRC_HWTC_PERIOD) / (TRC_HWTC_DIVISOR));
- /* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / TRC_HWTC_DIVISOR. */
- last_timestamp += (hwtc_count + traceTickCount * ((TRC_HWTC_PERIOD) % (TRC_HWTC_DIVISOR))) / (TRC_HWTC_DIVISOR);
- }
- /* Store the previous value */
- last_traceTickCount = traceTickCount;
-
-#else /*(TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)*/
-
- /* Timestamping is based on a free running timer */
- /* This part handles free running clocks that can be scaled down to avoid too large DTS values.
- Without this, the scaled timestamp will incorrectly wrap at (2^32 / TRC_HWTC_DIVISOR) ticks.
- The scaled timestamp returned from this function is supposed to go from 0 -> 2^32, which in real time would represent (0 -> 2^32 * TRC_HWTC_DIVISOR) ticks. */
-
- /* First we see how long time has passed since the last timestamp call, and we also add the ticks that was lost when we scaled down the last time. */
- diff = (hwtc_count - last_hwtc_count) + last_hwtc_rest;
-
- /* Scale down the diff */
- diff_scaled = diff / (TRC_HWTC_DIVISOR);
-
- /* Find out how many ticks were lost when scaling down, so we can add them the next time */
- last_hwtc_rest = diff % (TRC_HWTC_DIVISOR);
-
- /* We increase the scaled timestamp by the scaled amount */
- last_timestamp += diff_scaled;
-#endif /*(TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)*/
-
- /* Is anyone interested in the results? */
- if (pTimestamp)
- *pTimestamp = last_timestamp;
-
- /* Store the previous value */
- last_hwtc_count = hwtc_count;
-}
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
-
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c
deleted file mode 100755
index 2946a7e..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c
+++ /dev/null
@@ -1,1896 +0,0 @@
-/*******************************************************************************
- * Trace Recorder Library for Tracealyzer v4.1.5
- * Percepio AB, www.percepio.com
- *
- * trcStreamingRecorder.c
- *
- * The generic core of the trace recorder's streaming mode.
- *
- * Terms of Use
- * This file is part of the trace recorder library (RECORDER), which is the
- * intellectual property of Percepio AB (PERCEPIO) and provided under a
- * license as follows.
- * The RECORDER may be used free of charge for the purpose of recording data
- * intended for analysis in PERCEPIO products. It may not be used or modified
- * for other purposes without explicit permission from PERCEPIO.
- * You may distribute the RECORDER in its original source code form, assuming
- * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
- * allowed to distribute the RECORDER with minor modifications intended for
- * configuration or porting of the RECORDER, e.g., to allow using it on a
- * specific processor, processor family or with a specific communication
- * interface. Any such modifications should be documented directly below
- * this comment block.
- *
- * Disclaimer
- * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
- * as to its use or performance. PERCEPIO does not and cannot warrant the
- * performance or results you may obtain by using the RECORDER or documentation.
- * PERCEPIO make no warranties, express or implied, as to noninfringement of
- * third party rights, merchantability, or fitness for any particular purpose.
- * In no event will PERCEPIO, its technology partners, or distributors be liable
- * to you for any consequential, incidental or special damages, including any
- * lost profits or lost savings, even if a representative of PERCEPIO has been
- * advised of the possibility of such damages, or for any claim by any third
- * party. Some jurisdictions do not allow the exclusion or limitation of
- * incidental, consequential or special damages, or the exclusion of implied
- * warranties or limitations on how long an implied warranty may last, so the
- * above limitations may not apply to you.
- *
- * Tabs are used for indent in this file (1 tab = 4 spaces)
- *
- * Copyright Percepio AB, 2018.
- * www.percepio.com
- ******************************************************************************/
-
-#include "trcRecorder.h"
-
-#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
-
-#if (TRC_USE_TRACEALYZER_RECORDER == 1)
-
-#include
-#include
-
-typedef struct{
- uint16_t EventID;
- uint16_t EventCount;
- uint32_t TS;
-} BaseEvent;
-
-typedef struct{
- BaseEvent base;
- uint32_t param1;
-} EventWithParam_1;
-
-typedef struct{
- BaseEvent base;
- uint32_t param1;
- uint32_t param2;
-} EventWithParam_2;
-
-typedef struct{
- BaseEvent base;
- uint32_t param1;
- uint32_t param2;
- uint32_t param3;
-} EventWithParam_3;
-
-/* Used in event functions with variable number of parameters. */
-typedef struct
-{
- BaseEvent base;
- uint32_t data[15]; /* maximum payload size */
-} largestEventType;
-
-typedef struct{
- uint32_t psf;
- uint16_t version;
- uint16_t platform;
- uint32_t options;
- uint16_t symbolSize;
- uint16_t symbolCount;
- uint16_t objectDataSize;
- uint16_t objectDataCount;
-} PSFHeaderInfo;
-
-
-/* The size of each slot in the Symbol Table */
-#define SYMBOL_TABLE_SLOT_SIZE (sizeof(uint32_t) + (((TRC_CFG_SYMBOL_MAX_LENGTH)+(sizeof(uint32_t)-1))/sizeof(uint32_t))*sizeof(uint32_t))
-
-#define OBJECT_DATA_SLOT_SIZE (sizeof(uint32_t) + sizeof(uint32_t))
-
-/* The total size of the Symbol Table */
-#define SYMBOL_TABLE_BUFFER_SIZE ((TRC_CFG_SYMBOL_TABLE_SLOTS) * SYMBOL_TABLE_SLOT_SIZE)
-
-/* The total size of the Object Data Table */
-#define OBJECT_DATA_TABLE_BUFFER_SIZE ((TRC_CFG_OBJECT_DATA_SLOTS) * OBJECT_DATA_SLOT_SIZE)
-
-/* The Symbol Table type - just a byte array */
-typedef struct{
- union
- {
- uint32_t pSymbolTableBufferUINT32[SYMBOL_TABLE_BUFFER_SIZE / sizeof(uint32_t)];
- uint8_t pSymbolTableBufferUINT8[SYMBOL_TABLE_BUFFER_SIZE];
- } SymbolTableBuffer;
-} SymbolTable;
-
-/* The Object Data Table type - just a byte array */
-typedef struct{
- union
- {
- uint32_t pObjectDataTableBufferUINT32[OBJECT_DATA_TABLE_BUFFER_SIZE / sizeof(uint32_t)];
- uint8_t pObjectDataTableBufferUINT8[OBJECT_DATA_TABLE_BUFFER_SIZE];
- } ObjectDataTableBuffer;
-} ObjectDataTable;
-
-typedef struct{
- uint16_t Status; /* 16 bit to avoid implicit padding (warnings) */
- uint16_t BytesRemaining;
- char* WritePointer;
-} PageType;
-
-/* Code used for "task address" when no task has started. (NULL = idle task) */
-#define HANDLE_NO_TASK 2
-
-#define PAGE_STATUS_FREE 0
-#define PAGE_STATUS_WRITE 1
-#define PAGE_STATUS_READ 2
-
-#define PSF_ASSERT(_assert, _err) if (! (_assert)){ prvTraceError(_err); return; }
-
-/* Part of the PSF format - encodes the number of 32-bit params in an event */
-#define PARAM_COUNT(n) ((n & 0xF) << 12)
-
-/* The Symbol Table instance - keeps names of tasks and other named objects. */
-static SymbolTable symbolTable = { { { 0 } } };
-
-/* This points to the first unused entry in the symbol table. */
-static uint32_t firstFreeSymbolTableIndex = 0;
-
-/* The Object Data Table instance - keeps initial priorities of tasks. */
-static ObjectDataTable objectDataTable = { { { 0 } } };
-
-/* This points to the first unused entry in the object data table. */
-static uint32_t firstFreeObjectDataTableIndex = 0;
-
-/* Keeps track of ISR nesting */
-static uint32_t ISR_stack[TRC_CFG_MAX_ISR_NESTING];
-
-/* Keeps track of ISR nesting */
-static int8_t ISR_stack_index = -1;
-
-/* Any error that occurred in the recorder (also creates User Event) */
-static int errorCode = 0;
-
-/* Counts the number of trace sessions (not yet used) */
-static uint32_t SessionCounter = 0u;
-
-/* Master switch for recording (0 => Disabled, 1 => Enabled) */
-uint32_t RecorderEnabled = 0u;
-
-/* Used to determine endian of data (big/little) */
-static uint32_t PSFEndianessIdentifier = 0x50534600;
-
-/* Used to interpret the data format */
-static uint16_t FormatVersion = 0x0004;
-
-/* The number of events stored. Used as event sequence number. */
-static uint32_t eventCounter = 0;
-
-/* Remembers if an earlier ISR in a sequence of adjacent ISRs has triggered a task switch.
-In that case, vTraceStoreISREnd does not store a return to the previously executing task. */
-int32_t isPendingContextSwitch = 0;
-
-uint32_t uiTraceTickCount = 0;
-uint32_t timestampFrequency = 0;
-uint32_t DroppedEventCounter = 0;
-uint32_t TotalBytesRemaining_LowWaterMark = (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
-uint32_t TotalBytesRemaining = (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
-
-PageType PageInfo[TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT];
-
-char* EventBuffer = NULL;
-
-/*******************************************************************************
- * NoRoomForSymbol
- *
- * Incremented on prvTraceSaveSymbol if no room for saving the symbol name. This
- * is used for storing the names of:
- * - Tasks
- * - Named ISRs (xTraceSetISRProperties)
- * - Named kernel objects (vTraceStoreKernelObjectName)
- * - User event channels (xTraceRegisterString)
- *
- * This variable should be zero. If not, it shows the number of missing slots so
- * far. In that case, increment SYMBOL_TABLE_SLOTS with (at least) this value.
- ******************************************************************************/
-volatile uint32_t NoRoomForSymbol = 0;
-
-/*******************************************************************************
- * NoRoomForObjectData
- *
- * Incremented on prvTraceSaveObjectData if no room for saving the object data,
- * i.e., the base priorities of tasks. There must be one slot for each task.
- * If not, this variable will show the difference.
- *
- * This variable should be zero. If not, it shows the number of missing slots so
- * far. In that case, increment OBJECT_DATA_SLOTS with (at least) this value.
- ******************************************************************************/
-volatile uint32_t NoRoomForObjectData = 0;
-
-/*******************************************************************************
- * LongestSymbolName
- *
- * Updated in prvTraceSaveSymbol. Should not exceed TRC_CFG_SYMBOL_MAX_LENGTH,
- * otherwise symbol names will be truncated. In that case, set
- * TRC_CFG_SYMBOL_MAX_LENGTH to (at least) this value.
- ******************************************************************************/
-volatile uint32_t LongestSymbolName = 0;
-
-/*******************************************************************************
- * MaxBytesTruncated
- *
- * Set in prvTraceStoreStringEvent if the total data payload exceeds 60 bytes,
- * including data arguments and the string. For user events, that is 52 bytes
- * for string and data arguments. In that is exceeded, the event is truncated
- * (usually only the string, unless more than 15 parameters) and this variable
- * holds the maximum number of truncated bytes, from any event.
- ******************************************************************************/
-volatile uint32_t MaxBytesTruncated = 0;
-
-uint16_t CurrentFilterMask = 0xFFFF;
-
-uint16_t CurrentFilterGroup = FilterGroup0;
-
-/* Internal common function for storing string events */
-static void prvTraceStoreStringEventHelper( int nArgs,
- uint16_t eventID,
- traceString userEvtChannel,
- int len,
- const char* str,
- va_list* vl);
-
-/* Not static to avoid warnings from SysGCC/PPC */
-void prvTraceStoreSimpleStringEventHelper(traceString userEvtChannel,
- const char* str);
-
-
-/* Stores the header information on Start */
-static void prvTraceStoreHeader(void);
-
-/* Stores the symbol table on Start */
-static void prvTraceStoreSymbolTable(void);
-
-/* Stores the object table on Start */
-static void prvTraceStoreObjectDataTable(void);
-
-/* Store the Timestamp Config on Start */
-static void prvTraceStoreTSConfig(void);
-
-/* Store the current warnings */
-static void prvTraceStoreWarnings(void);
-
-/* Internal function for starting/stopping the recorder. */
-static void prvSetRecorderEnabled(uint32_t isEnabled);
-
-/* Mark the page read as complete. */
-static void prvPageReadComplete(int pageIndex);
-
-/* Retrieve a buffer page to write to. */
-static int prvAllocateBufferPage(int prevPage);
-
-/* Get the current buffer page index (return value) and the number
-of valid bytes in the buffer page (bytesUsed). */
-static int prvGetBufferPage(int32_t* bytesUsed);
-
-/* Performs timestamping using definitions in trcHardwarePort.h */
-static uint32_t prvGetTimestamp32(void);
-
-/* Signal an error. */
-void prvTraceError(int errCode);
-
-/* Signal an warning (does not stop the recorder). */
-void prvTraceWarning(int errCode);
-
-/******************************************************************************
- * vTraceInstanceFinishedNow
- *
- * Creates an event that ends the current task instance at this very instant.
- * This makes the viewer to splits the current fragment at this point and begin
- * a new actor instance, even if no task-switch has occurred.
- *****************************************************************************/
-void vTraceInstanceFinishedNow(void)
-{
- prvTraceStoreEvent0(PSF_EVENT_IFE_DIRECT);
-}
-
-/******************************************************************************
- * vTraceInstanceFinishedNext
- *
- * Marks the current "task instance" as finished on the next kernel call.
- *
- * If that kernel call is blocking, the instance ends after the blocking event
- * and the corresponding return event is then the start of the next instance.
- * If the kernel call is not blocking, the viewer instead splits the current
- * fragment right before the kernel call, which makes this call the first event
- * of the next instance.
- *****************************************************************************/
-void vTraceInstanceFinishedNext(void)
-{
- prvTraceStoreEvent0(PSF_EVENT_IFE_NEXT);
-}
-
-/*******************************************************************************
- * vTraceStoreKernelObjectName
- *
- * Parameter object: pointer to the Event Group that shall be named
- * Parameter name: the name to set (const string literal)
- *
- * Sets a name for a kernel object for display in Tracealyzer.
- ******************************************************************************/
-void vTraceStoreKernelObjectName(void* object, const char* name)
-{
- /* Always save in symbol table, if the recording has not yet started */
- prvTraceSaveSymbol(object, name);
-
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, name, (uint32_t)object);
-}
-
-
-/******************************************************************************
-* vTraceSetFrequency
-*
-* Registers the clock rate of the time source for the event timestamping.
-* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)
-* should be incorrect for your setup, you can override it using this function.
-*
-* Must be called prior to vTraceEnable, and the time source is assumed to
-* have a fixed clock frequency after the startup.
-*****************************************************************************/
-void vTraceSetFrequency(uint32_t frequency)
-{
- timestampFrequency = frequency;
-}
-
-#if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
-
-/*******************************************************************************
-* xTraceRegisterString
-*
-* Stores a name for a user event channel, returns the handle.
-******************************************************************************/
-traceString xTraceRegisterString(const char* name)
-{
- prvTraceSaveSymbol((const void*)name, name);
-
- /* Always save in symbol table, if the recording has not yet started */
- prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, (const char*)name, (uint32_t)name);
-
- return (traceString)name;
-}
-
-/******************************************************************************
- * vTracePrint
- *
- * Generates "User Events", with unformatted text.
- *
- * User Events can be used for very efficient application logging, and are shown
- * as yellow labels in the main trace view.
- *
- * You may group User Events into User Event Channels. The yellow User Event
- * labels shows the logged string, preceded by the channel name within
- * brackets. For example:
- *
- * "[MyChannel] Hello World!"
- *
- * The User Event Channels are shown in the View Filter, which makes it easy to
- * select what User Events you wish to display. User Event Channels are created
- * using xTraceRegisterString().
- *
- * Example:
- *
- * traceString chn = xTraceRegisterString("MyChannel");
- * ...
- * vTracePrint(chn, "Hello World!");
- *
- ******************************************************************************/
-void vTracePrint(traceString chn, const char* str)
-{
- prvTraceStoreSimpleStringEventHelper(chn, str);
-}
-
-
-/*******************************************************************************
-* vTraceConsoleChannelPrintF
-*
-* Wrapper for vTracePrint, using the default channel. Can be used as a drop-in
-* replacement for printf and similar functions, e.g. in a debug logging macro.
-*
-* Example:
-*
-* // Old: #define LogString debug_console_printf
-*
-* // New, log to Tracealyzer instead:
-* #define LogString vTraceConsoleChannelPrintF
-* ...
-* LogString("My value is: %d", myValue);
-******************************************************************************/
-void vTraceConsoleChannelPrintF(const char* fmt, ...)
-{
- va_list vl;
- char tempBuf[60];
- static traceString consoleChannel = NULL;
-
- if (consoleChannel == NULL)
- consoleChannel = xTraceRegisterString("Debug Console");
-
- va_start(vl, fmt);
- vsnprintf(tempBuf, 60, fmt, vl);
- vTracePrint(consoleChannel, tempBuf);
- va_end(vl);
-}
-
-/******************************************************************************
- * vTracePrintF
- *
- * Generates "User Events", with formatted text and data, similar to a "printf".
- * It is very fast since the actual formatting is done on the host side when the
- * trace is displayed.
- *
- * User Events can be used for very efficient application logging, and are shown
- * as yellow labels in the main trace view.
- * An advantage of User Events is that data can be plotted in the "User Event
- * Signal Plot" view, visualizing any data you log as User Events, discrete
- * states or control system signals (e.g. system inputs or outputs).
- *
- * You may group User Events into User Event Channels. The yellow User Event
- * labels show the logged string, preceded by the channel name within brackets.
- *
- * Example:
- *
- * "[MyChannel] Hello World!"
- *
- * The User Event Channels are shown in the View Filter, which makes it easy to
- * select what User Events you wish to display. User Event Channels are created
- * using xTraceRegisterString().
- *
- * Example:
- *
- * traceString adc_uechannel = xTraceRegisterString("ADC User Events");
- * ...
- * vTracePrintF(adc_uechannel,
- * "ADC channel %d: %d volts",
- * ch, adc_reading);
- *
- * All data arguments are assumed to be 32 bit wide. The following formats are
- * supported:
- * %d - signed integer. The following width and padding format is supported: "%05d" -> "-0042" and "%5d" -> " -42"
- * %u - unsigned integer. The following width and padding format is supported: "%05u" -> "00042" and "%5u" -> " 42"
- * %X - hexadecimal (uppercase). The following width and padding format is supported: "%04X" -> "002A" and "%4X" -> " 2A"
- * %x - hexadecimal (lowercase). The following width and padding format is supported: "%04x" -> "002a" and "%4x" -> " 2a"
- * %s - string (currently, this must be an earlier stored symbol name)
- *
- * Up to 15 data arguments are allowed, with a total size of maximum 60 byte
- * including 8 byte for the base event fields and the format string. So with
- * one data argument, the maximum string length is 48 chars. If this is exceeded
- * the string is truncated (4 bytes at a time).
- *
- ******************************************************************************/
-void vTracePrintF(traceString chn, const char* fmt, ...)
-{
- va_list vl;
- int i = 0;
-
- int nArgs = 0;
-
- /* Count the number of arguments in the format string (e.g., %d) */
- for (i = 0; (fmt[i] != 0) && (i < 52); i++)
- {
- if (fmt[i] == '%')
- {
- if (fmt[i + 1] != 0 && fmt[i + 1] != '%')
- {
- nArgs++; /* Found an argument */
- }
-
- i++; /* Move past format specifier or non-argument '%' */
- }
- }
-
- va_start(vl, fmt);
-
- if (chn != NULL)
- {
- prvTraceStoreStringEventHelper(nArgs, (uint16_t)(PSF_EVENT_USER_EVENT + nArgs + 1), chn, i, fmt, &vl);
- }
- else
- {
- prvTraceStoreStringEventHelper(nArgs, (uint16_t)(PSF_EVENT_USER_EVENT + nArgs), chn, i, fmt, &vl);
- }
- va_end(vl);
-}
-#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) */
-
-/*******************************************************************************
- * xTraceSetISRProperties
- *
- * Stores a name and priority level for an Interrupt Service Routine, to allow
- * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- *
- ******************************************************************************/
-traceHandle xTraceSetISRProperties(const char* name, uint8_t priority)
-{
- /* Save object data in object data table */
- prvTraceSaveObjectData((const void*)name, priority);
-
- /* Note: "name" is used both as a string argument, and the address as ID */
- prvTraceStoreStringEvent(2, PSF_EVENT_DEFINE_ISR, name, name, priority);
-
- /* Always save in symbol table, if the recording has not yet started */
- prvTraceSaveSymbol((const void*)name, name);
-
- return (traceHandle)name;
-}
-
-/*******************************************************************************
- * vTraceStoreISRBegin
- *
- * Registers the beginning of an Interrupt Service Routine, using a traceHandle
- * provided by xTraceSetISRProperties.
- *
- * Example:
- * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt
- * ...
- * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(Timer1Handle);
- * ...
- * vTraceStoreISREnd(0);
- * }
- *
- ******************************************************************************/
-void vTraceStoreISRBegin(traceHandle handle)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- /* We are at the start of a possible ISR chain.
- No context switches should have been triggered now. */
- if (ISR_stack_index == -1)
- isPendingContextSwitch = 0;
-
- if (ISR_stack_index < (TRC_CFG_MAX_ISR_NESTING) - 1)
- {
- ISR_stack_index++;
- ISR_stack[ISR_stack_index] = (uint32_t)handle;
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
- prvTraceStoreEvent1(PSF_EVENT_ISR_BEGIN, (uint32_t)handle);
-#endif
- TRACE_EXIT_CRITICAL_SECTION();
- }
- else
- {
- TRACE_EXIT_CRITICAL_SECTION();
- prvTraceError(PSF_ERROR_ISR_NESTING_OVERFLOW);
- }
-}
-
-/*******************************************************************************
- * vTraceStoreISREnd
- *
- * Registers the end of an Interrupt Service Routine.
- *
- * The parameter pendingISR indicates if the interrupt has requested a
- * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the
- * interrupt is assumed to return to the previous context.
- *
- * Example:
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
- * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder
- * ...
- * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);
- * ...
- * void ISR_handler()
- * {
- * vTraceStoreISRBegin(traceHandleIsrTimer1);
- * ...
- * vTraceStoreISREnd(0);
- * }
- *
- ******************************************************************************/
-void vTraceStoreISREnd(int isTaskSwitchRequired)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- (void)ISR_stack;
-
- /* Is there a pending task-switch? (perhaps from an earlier ISR) */
- isPendingContextSwitch |= isTaskSwitchRequired;
-
- if (ISR_stack_index > 0)
- {
- ISR_stack_index--;
-
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
- /* Store return to interrupted ISR (if nested ISRs)*/
- prvTraceStoreEvent1(PSF_EVENT_ISR_RESUME, (uint32_t)ISR_stack[ISR_stack_index]);
-#endif
- }
- else
- {
- ISR_stack_index--;
-
- /* Store return to interrupted task, if no context switch will occur in between. */
- if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended()))
- {
-#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
- prvTraceStoreEvent1(PSF_EVENT_TS_RESUME, (uint32_t)TRACE_GET_CURRENT_TASK());
-#endif
- }
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-
-/*******************************************************************************
- * xTraceGetLastError
- *
- * Returns the last error or warning, as a string, or NULL if none.
- *****************************************************************************/
-const char* xTraceGetLastError(void)
-{
- /* Note: the error messages are short, in order to fit in a User Event.
- Instead, the users can read more in the below comments.*/
-
- switch (errorCode)
- {
-
- case PSF_WARNING_SYMBOL_TABLE_SLOTS:
- /* There was not enough symbol table slots for storing symbol names.
- The number of missing slots is counted by NoRoomForSymbol. Inspect this
- variable and increase TRC_CFG_SYMBOL_TABLE_SLOTS by at least that value. */
-
- return "Exceeded SYMBOL_TABLE_SLOTS (see xTraceGetLastError)";
-
- case PSF_WARNING_SYMBOL_MAX_LENGTH:
- /* A symbol name exceeded TRC_CFG_SYMBOL_MAX_LENGTH in length.
- Make sure the symbol names are at most TRC_CFG_SYMBOL_MAX_LENGTH,
- or inspect LongestSymbolName and increase TRC_CFG_SYMBOL_MAX_LENGTH
- to at least this value. */
-
- return "Exceeded SYMBOL_MAX_LENGTH (see xTraceGetLastError)";
-
- case PSF_WARNING_OBJECT_DATA_SLOTS:
- /* There was not enough symbol object table slots for storing object
- properties, such as task priorites. The number of missing slots is
- counted by NoRoomForObjectData. Inspect this variable and increase
- TRC_CFG_OBJECT_DATA_SLOTS by at least that value. */
-
- return "Exceeded OBJECT_DATA_SLOTS (see xTraceGetLastError)";
-
- case PSF_WARNING_STRING_TOO_LONG:
- /* Some string argument was longer than the maximum payload size
- and has been truncated by "MaxBytesTruncated" bytes.
-
- This may happen for the following functions:
- - vTracePrint
- - vTracePrintF
- - vTraceStoreKernelObjectName
- - xTraceRegisterString
- - vTraceSetISRProperties
-
- A PSF event may store maximum 60 bytes payload, including data
- arguments and string characters. For User Events, also the User
- Event Channel (4 bytes) must be squeezed in, if a channel is
- specified (can be NULL). */
-
- return "String too long (see xTraceGetLastError)";
-
- case PSF_WARNING_STREAM_PORT_READ:
- /* TRC_STREAM_PORT_READ_DATA is expected to return 0 when completed successfully.
- This means there is an error in the communication with host/Tracealyzer. */
-
- return "TRC_STREAM_PORT_READ_DATA returned error (!= 0).";
-
- case PSF_WARNING_STREAM_PORT_WRITE:
- /* TRC_STREAM_PORT_WRITE_DATA is expected to return 0 when completed successfully.
- This means there is an error in the communication with host/Tracealyzer. */
-
- return "TRC_STREAM_PORT_WRITE_DATA returned error (!= 0).";
-
- case PSF_ERROR_EVENT_CODE_TOO_LARGE:
- /* The highest allowed event code is 4095, anything higher is an unexpected error.
- Please contact support@percepio.com for assistance.*/
-
- return "Invalid event code (see xTraceGetLastError)";
-
- case PSF_ERROR_ISR_NESTING_OVERFLOW:
- /* Nesting of ISR trace calls exceeded the limit (TRC_CFG_MAX_ISR_NESTING).
- If this is unlikely, make sure that you call vTraceStoreISRExit in the end
- of all ISR handlers. Or increase TRC_CFG_MAX_ISR_NESTING. */
-
- return "Exceeded ISR nesting (see xTraceGetLastError)";
-
- case PSF_ERROR_DWT_NOT_SUPPORTED:
- /* On ARM Cortex-M only - failed to initialize DWT Cycle Counter since not supported by this chip.
- DWT timestamping is selected automatically for ART Cortex-M3, M4 and higher, based on the __CORTEX_M
- macro normally set by ARM's CMSIS library, since typically available. You can however select
- SysTick timestamping instead by defining adding "#define TRC_CFG_ARM_CM_USE_SYSTICK".*/
-
- return "DWT not supported (see xTraceGetLastError)";
-
- case PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED:
- /* On ARM Cortex-M only - failed to initialize DWT Cycle Counter since not supported by this chip.
- DWT timestamping is selected automatically for ART Cortex-M3, M4 and higher, based on the __CORTEX_M
- macro normally set by ARM's CMSIS library, since typically available. You can however select
- SysTick timestamping instead by defining adding "#define TRC_CFG_ARM_CM_USE_SYSTICK".*/
-
- return "DWT_CYCCNT not supported (see xTraceGetLastError)";
-
- case PSF_ERROR_TZCTRLTASK_NOT_CREATED:
- /* vTraceEnable failed creating the trace control task (TzCtrl) - incorrect parameters (priority?)
- or insufficient heap size? */
- return "Could not create TzCtrl (see xTraceGetLastError)";
-
- }
-
- return NULL;
-}
-
-/*******************************************************************************
- * vTraceClearError
- *
- * Clears any errors.
- *****************************************************************************/
-void vTraceClearError(void)
-{
- NoRoomForSymbol = 0;
- LongestSymbolName = 0;
- NoRoomForObjectData = 0;
- MaxBytesTruncated = 0;
- errorCode = PSF_ERROR_NONE;
-}
-
-/*******************************************************************************
- * vTraceStop
- *
- * Stops the tracing.
- *****************************************************************************/
-void vTraceStop(void)
-{
- prvSetRecorderEnabled(0);
-}
-
-/*******************************************************************************
- * vTraceSetRecorderDataBuffer
- *
- * If custom allocation is used, this function must be called so the recorder
- * library knows where to save the trace data.
- ******************************************************************************/
-#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
-
-extern char* _TzTraceData;
-
-void vTraceSetRecorderDataBuffer(void* pRecorderData)
-{
- _TzTraceData = pRecorderData;
-}
-#endif
-
-
-/*******************************************************************************
-* xTraceIsRecordingEnabled
-* Returns true (1) if the recorder is enabled (i.e. is recording), otherwise 0.
-******************************************************************************/
-int xTraceIsRecordingEnabled(void)
-{
- return (int)RecorderEnabled;
-}
-
-void vTraceSetFilterMask(uint16_t filterMask)
-{
- CurrentFilterMask = filterMask;
-}
-
-void vTraceSetFilterGroup(uint16_t filterGroup)
-{
- CurrentFilterGroup = filterGroup;
-}
-
-
-/******************************************************************************/
-/*** INTERNAL FUNCTIONS *******************************************************/
-/******************************************************************************/
-
-/* Internal function for starting/stopping the recorder. */
-static void prvSetRecorderEnabled(uint32_t isEnabled)
-{
- void* currentTask;
-
- TRACE_ALLOC_CRITICAL_SECTION();
-
- if (RecorderEnabled == isEnabled)
- {
- return;
- }
-
- currentTask = TRACE_GET_CURRENT_TASK();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- RecorderEnabled = isEnabled;
-
- if (currentTask == NULL)
- {
- currentTask = (void*)HANDLE_NO_TASK;
- }
-
- if (RecorderEnabled)
- {
- TRC_STREAM_PORT_ON_TRACE_BEGIN();
-
- #if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)
- prvPagedEventBufferInit(_TzTraceData);
- #endif
-
- eventCounter = 0;
- ISR_stack_index = -1;
- prvTraceStoreHeader();
- prvTraceStoreSymbolTable();
- prvTraceStoreObjectDataTable();
- prvTraceStoreEvent3( PSF_EVENT_TRACE_START,
- (uint32_t)TRACE_GET_OS_TICKS(),
- (uint32_t)currentTask,
- SessionCounter++);
- prvTraceStoreTSConfig();
- prvTraceStoreWarnings();
- }
- else
- {
- TRC_STREAM_PORT_ON_TRACE_END();
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Stores the symbol table on Start */
-static void prvTraceStoreSymbolTable(void)
-{
- uint32_t i = 0;
- uint32_t j = 0;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- for (i = 0; i < (sizeof(SymbolTable) / sizeof(uint32_t)); i += (SYMBOL_TABLE_SLOT_SIZE / sizeof(uint32_t)))
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(uint32_t, data, SYMBOL_TABLE_SLOT_SIZE);
- if (data != NULL)
- {
- for (j = 0; j < (SYMBOL_TABLE_SLOT_SIZE / sizeof(uint32_t)); j++)
- {
- data[j] = symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i+j];
- }
- TRC_STREAM_PORT_COMMIT_EVENT(data, SYMBOL_TABLE_SLOT_SIZE);
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Stores the object table on Start */
-static void prvTraceStoreObjectDataTable(void)
-{
- uint32_t i = 0;
- uint32_t j = 0;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- for (i = 0; i < (sizeof(ObjectDataTable) / sizeof(uint32_t)); i += (OBJECT_DATA_SLOT_SIZE / sizeof(uint32_t)))
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(uint32_t, data, OBJECT_DATA_SLOT_SIZE);
- if (data != NULL)
- {
- for (j = 0; j < (OBJECT_DATA_SLOT_SIZE / sizeof(uint32_t)); j++)
- {
- data[j] = objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i+j];
- }
- TRC_STREAM_PORT_COMMIT_EVENT(data, OBJECT_DATA_SLOT_SIZE);
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Stores the header information on Start */
-static void prvTraceStoreHeader(void)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(PSFHeaderInfo, header, sizeof(PSFHeaderInfo));
- if (header != NULL)
- {
- header->psf = PSFEndianessIdentifier;
- header->version = FormatVersion;
- header->platform = TRACE_KERNEL_VERSION;
- header->options = 0;
- /* Lowest bit used for TRC_IRQ_PRIORITY_ORDER */
- header->options = header->options | (TRC_IRQ_PRIORITY_ORDER << 0);
- header->symbolSize = SYMBOL_TABLE_SLOT_SIZE;
- header->symbolCount = (TRC_CFG_SYMBOL_TABLE_SLOTS);
- header->objectDataSize = 8;
- header->objectDataCount = (TRC_CFG_OBJECT_DATA_SLOTS);
- TRC_STREAM_PORT_COMMIT_EVENT(header, sizeof(PSFHeaderInfo));
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Store the current warnings */
-static void prvTraceStoreWarnings(void)
-{
- if (RecorderEnabled)
- {
- const char* errStr = xTraceGetLastError();
-
- if (errStr != NULL)
- {
- vTracePrint(trcWarningChannel, errStr);
- }
- }
-}
-
-/* Store an event with zero parameters (event ID only) */
-void prvTraceStoreEvent0(uint16_t eventID)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(BaseEvent, event, sizeof(BaseEvent));
- if (event != NULL)
- {
- event->EventID = eventID | PARAM_COUNT(0);
- event->EventCount = (uint16_t)eventCounter;
- event->TS = prvGetTimestamp32();
- TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(BaseEvent));
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Store an event with one 32-bit parameter (pointer address or an int) */
-void prvTraceStoreEvent1(uint16_t eventID, uint32_t param1)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_1, event, sizeof(EventWithParam_1));
- if (event != NULL)
- {
- event->base.EventID = eventID | PARAM_COUNT(1);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
- event->param1 = (uint32_t)param1;
- TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_1));
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Store an event with two 32-bit parameters */
-void prvTraceStoreEvent2(uint16_t eventID, uint32_t param1, uint32_t param2)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_2, event, sizeof(EventWithParam_2));
- if (event != NULL)
- {
- event->base.EventID = eventID | PARAM_COUNT(2);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
- event->param1 = (uint32_t)param1;
- event->param2 = param2;
- TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_2));
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Store an event with three 32-bit parameters */
-void prvTraceStoreEvent3( uint16_t eventID,
- uint32_t param1,
- uint32_t param2,
- uint32_t param3)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_3, event, sizeof(EventWithParam_3));
- if (event != NULL)
- {
- event->base.EventID = eventID | PARAM_COUNT(3);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
- event->param1 = (uint32_t)param1;
- event->param2 = param2;
- event->param3 = param3;
- TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_3));
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Stores an event with 32-bit integer parameters */
-void prvTraceStoreEvent(int nParam, uint16_t eventID, ...)
-{
- va_list vl;
- int i;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- int eventSize = (int)sizeof(BaseEvent) + nParam * (int)sizeof(uint32_t);
-
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);
- if (event != NULL)
- {
- event->base.EventID = eventID | (uint16_t)PARAM_COUNT(nParam);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
-
- va_start(vl, eventID);
- for (i = 0; i < nParam; i++)
- {
- uint32_t* tmp = (uint32_t*) &(event->data[i]);
- *tmp = va_arg(vl, uint32_t);
- }
- va_end(vl);
-
- TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);
- }
- }
- }
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Stories an event with a string and 32-bit integer parameters */
-void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...)
-{
- int len;
- va_list vl;
-
- for (len = 0; (str[len] != 0) && (len < 52); len++); /* empty loop */
-
- va_start(vl, str);
- prvTraceStoreStringEventHelper(nArgs, eventID, NULL, len, str, &vl);
- va_end(vl);
-}
-
-/* Internal common function for storing string events */
-static void prvTraceStoreStringEventHelper(int nArgs,
- uint16_t eventID,
- traceString userEvtChannel,
- int len,
- const char* str,
- va_list* vl)
-{
- int nWords;
- int nStrWords;
- int i;
- int offset = 0;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- /* The string length in multiples of 32 bit words (+1 for null character) */
- nStrWords = (len+1+3)/4;
-
- /* If a user event channel is specified, add in the list */
- if (userEvtChannel)
- nArgs++;
-
- offset = nArgs * 4;
-
- /* The total number of 32-bit words needed for the whole payload */
- nWords = nStrWords + nArgs;
-
- if (nWords > 15) /* if attempting to store more than 60 byte (= max) */
- {
- /* Truncate event if too large. The string characters are stored
- last, so usually only the string is truncated, unless there a lot
- of parameters... */
-
- /* Diagnostics ... */
- uint32_t bytesTruncated = (uint32_t)(nWords - 15) * 4;
-
- if (bytesTruncated > MaxBytesTruncated)
- {
- MaxBytesTruncated = bytesTruncated;
- }
-
- nWords = 15;
- len = 15 * 4 - offset;
- }
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- int eventSize = (int)sizeof(BaseEvent) + nWords * (int)sizeof(uint32_t);
-
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);
- if (event != NULL)
- {
- uint32_t* data32;
- uint8_t* data8;
- event->base.EventID = (eventID) | (uint16_t)PARAM_COUNT(nWords);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
-
- /* 32-bit write-pointer for the data argument */
- data32 = (uint32_t*) &(event->data[0]);
-
- for (i = 0; i < nArgs; i++)
- {
- if ((userEvtChannel != NULL) && (i == 0))
- {
- /* First, add the User Event Channel if not NULL */
- data32[i] = (uint32_t)userEvtChannel;
- }
- else
- {
- /* Add data arguments... */
- data32[i] = va_arg(*vl, uint32_t);
- }
- }
- data8 = (uint8_t*)&(event->data[0]);
- for (i = 0; i < len; i++)
- {
- data8[offset + i] = str[i];
- }
-
- if (len < (15 * 4 - offset))
- data8[offset + len] = 0; /* Only truncate if we don't fill up the buffer completely */
- TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);
- }
- }
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Internal common function for storing string events without additional arguments */
-void prvTraceStoreSimpleStringEventHelper(traceString userEvtChannel,
- const char* str)
-{
- int len;
- int nWords;
- int nStrWords;
- int i;
- int nArgs = 0;
- int offset = 0;
- uint16_t eventID = PSF_EVENT_USER_EVENT;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);
-
- for (len = 0; (str[len] != 0) && (len < 52); len++); /* empty loop */
-
- /* The string length in multiples of 32 bit words (+1 for null character) */
- nStrWords = (len+1+3)/4;
-
- /* If a user event channel is specified, add in the list */
- if (userEvtChannel)
- {
- nArgs++;
- eventID++;
- }
-
- offset = nArgs * 4;
-
- /* The total number of 32-bit words needed for the whole payload */
- nWords = nStrWords + nArgs;
-
- if (nWords > 15) /* if attempting to store more than 60 byte (= max) */
- {
- /* Truncate event if too large. The string characters are stored
- last, so usually only the string is truncated, unless there a lot
- of parameters... */
-
- /* Diagnostics ... */
- uint32_t bytesTruncated = (uint32_t)(nWords - 15) * 4;
-
- if (bytesTruncated > MaxBytesTruncated)
- {
- MaxBytesTruncated = bytesTruncated;
- }
-
- nWords = 15;
- len = 15 * 4 - offset;
- }
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- if (RecorderEnabled)
- {
- int eventSize = (int)sizeof(BaseEvent) + nWords * (int)sizeof(uint32_t);
-
- eventCounter++;
-
- {
- TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);
- if (event != NULL)
- {
- uint32_t* data32;
- uint8_t* data8;
- event->base.EventID = (eventID) | (uint16_t)PARAM_COUNT(nWords);
- event->base.EventCount = (uint16_t)eventCounter;
- event->base.TS = prvGetTimestamp32();
-
- /* 32-bit write-pointer for the data argument */
- data32 = (uint32_t*) &(event->data[0]);
-
- if (userEvtChannel != NULL)
- {
- /* First, add the User Event Channel if not NULL */
- data32[0] = (uint32_t)userEvtChannel;
- }
-
- data8 = (uint8_t*) &(event->data[0]);
- for (i = 0; i < len; i++)
- {
- data8[offset + i] = str[i];
- }
-
- if (len < (15 * 4 - offset))
- data8[offset + len] = 0; /* Only truncate if we don't fill up the buffer completely */
- TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);
- }
- }
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Saves a symbol name (task name etc.) in symbol table */
-void prvTraceSaveSymbol(const void *address, const char *name)
-{
- uint32_t i;
- uint32_t foundSlot;
- uint32_t *ptrAddress;
- uint8_t *ptrSymbol;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- foundSlot = firstFreeSymbolTableIndex;
-
- /* First look for previous entries using this address */
- for (i = 0; i < firstFreeSymbolTableIndex; i += SYMBOL_TABLE_SLOT_SIZE)
- {
- /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */
- ptrAddress = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i / sizeof(uint32_t)];
- if (*ptrAddress == (uint32_t)address)
- {
- foundSlot = i;
- break;
- }
- }
-
- if (foundSlot < SYMBOL_TABLE_BUFFER_SIZE)
- {
- /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */
- symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[foundSlot / sizeof(uint32_t)] = (uint32_t)address;
-
- /* We access the symbol table via the union member pSymbolTableBufferUINT8 to avoid strict-aliasing issues */
- ptrSymbol = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT8[foundSlot + sizeof(uint32_t)];
- for (i = 0; i < (TRC_CFG_SYMBOL_MAX_LENGTH); i++)
- {
- ptrSymbol[i] = (uint8_t)name[i]; /* We do this first to ensure we also get the 0 termination, if there is one */
-
- if (name[i] == 0)
- break;
- }
-
- /* Check the length of "name", if longer than SYMBOL_MAX_LENGTH */
- while ((name[i] != 0) && i < 128)
- {
- i++;
- }
-
- /* Remember the longest symbol name, for diagnostic purposes */
- if (i > LongestSymbolName)
- {
- LongestSymbolName = i;
- }
-
- /* Is this the last entry in the symbol table? */
- if (foundSlot == firstFreeSymbolTableIndex)
- {
- firstFreeSymbolTableIndex += SYMBOL_TABLE_SLOT_SIZE;
- }
- }
- else
- {
- NoRoomForSymbol++;
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Deletes a symbol name (task name etc.) from symbol table */
-void prvTraceDeleteSymbol(void *address)
-{
- uint32_t i, j;
- uint32_t *ptr, *lastEntryPtr;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- for (i = 0; i < firstFreeSymbolTableIndex; i += SYMBOL_TABLE_SLOT_SIZE)
- {
- /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */
- ptr = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i / sizeof(uint32_t)];
- if (*ptr == (uint32_t)address)
- {
- /* See if we have another entry in the table, and that this isn't already the last entry */
- if (firstFreeSymbolTableIndex > SYMBOL_TABLE_SLOT_SIZE && i != (firstFreeSymbolTableIndex - SYMBOL_TABLE_SLOT_SIZE))
- {
- /* Another entry is available, get pointer to the last one */
- /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */
- lastEntryPtr = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[(firstFreeSymbolTableIndex - SYMBOL_TABLE_SLOT_SIZE) / sizeof(uint32_t)];
-
- /* Copy last entry to this position */
- for (j = 0; j < (SYMBOL_TABLE_SLOT_SIZE) / sizeof(uint32_t); j++)
- {
- ptr[j] = lastEntryPtr[j];
- }
-
- /* For good measure we also zero out the original position */
- *lastEntryPtr = 0;
- }
- else
- *ptr = 0; /* No other entry found, or this is the last entry */
-
- /* Lower index */
- firstFreeSymbolTableIndex -= SYMBOL_TABLE_SLOT_SIZE;
-
- break;
- }
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Saves an object data entry (current task priority) in object data table */
-void prvTraceSaveObjectData(const void *address, uint32_t data)
-{
- uint32_t i;
- uint32_t foundSlot;
- uint32_t *ptr;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- foundSlot = firstFreeObjectDataTableIndex;
-
- /* First look for previous entries using this address */
- for (i = 0; i < firstFreeObjectDataTableIndex; i += OBJECT_DATA_SLOT_SIZE)
- {
- /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */
- ptr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i / sizeof(uint32_t)];
- if (*ptr == (uint32_t)address)
- {
- foundSlot = i;
- break;
- }
- }
-
- if (foundSlot < OBJECT_DATA_TABLE_BUFFER_SIZE)
- {
- /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */
- objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[foundSlot / sizeof(uint32_t)] = (uint32_t)address;
- objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[foundSlot / sizeof(uint32_t) + 1] = data;
-
- /* Is this the last entry in the object data table? */
- if (foundSlot == firstFreeObjectDataTableIndex)
- {
- firstFreeObjectDataTableIndex += OBJECT_DATA_SLOT_SIZE;
- }
- }
- else
- {
- NoRoomForObjectData++;
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Removes an object data entry (task base priority) from object data table */
-void prvTraceDeleteObjectData(void *address)
-{
- uint32_t i, j;
- uint32_t *ptr, *lastEntryPtr;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
-
- for (i = 0; i < firstFreeObjectDataTableIndex; i += OBJECT_DATA_SLOT_SIZE)
- {
- /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */
- ptr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i / sizeof(uint32_t)];
- if (*ptr == (uint32_t)address)
- {
- /* See if we have another entry in the table, and that this isn't already the last entry */
- if (firstFreeObjectDataTableIndex > OBJECT_DATA_SLOT_SIZE && i != (firstFreeObjectDataTableIndex - OBJECT_DATA_SLOT_SIZE))
- {
- /* Another entry is available, get pointer to the last one */
- /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */
- lastEntryPtr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[(firstFreeObjectDataTableIndex - OBJECT_DATA_SLOT_SIZE) / sizeof(uint32_t)];
-
- /* Copy last entry to this position */
- for (j = 0; j < (OBJECT_DATA_SLOT_SIZE) / sizeof(uint32_t); j++)
- {
- ptr[j] = lastEntryPtr[j];
- }
-
- /* For good measure we also zero out the original position */
- *lastEntryPtr = 0;
- }
- else
- *ptr = 0; /* No other entry found, or this is the last entry */
-
- /* Lower index */
- firstFreeObjectDataTableIndex -= OBJECT_DATA_SLOT_SIZE;
-
- break;
- }
- }
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Checks if the provided command is a valid command */
-int prvIsValidCommand(TracealyzerCommandType* cmd)
-{
- uint16_t checksum = (uint16_t)(0xFFFF - ( cmd->cmdCode +
- cmd->param1 +
- cmd->param2 +
- cmd->param3 +
- cmd->param4 +
- cmd->param5));
-
- if (cmd->checksumMSB != (unsigned char)(checksum >> 8))
- return 0;
-
- if (cmd->checksumLSB != (unsigned char)(checksum & 0xFF))
- return 0;
-
- if (cmd->cmdCode > CMD_LAST_COMMAND)
- return 0;
-
- return 1;
-}
-
-/* Executed the received command (Start or Stop) */
-void prvProcessCommand(TracealyzerCommandType* cmd)
-{
- switch(cmd->cmdCode)
- {
- case CMD_SET_ACTIVE:
- prvSetRecorderEnabled(cmd->param1);
- break;
- default:
- break;
- }
-}
-
-/* Called on warnings, when the recording can continue. */
-void prvTraceWarning(int errCode)
-{
- if (!errorCode)
- {
- errorCode = errCode;
- prvTraceStoreWarnings();
- }
-}
-
-/* Called on critical errors in the recorder. Stops the recorder! */
-void prvTraceError(int errCode)
-{
- if (! errorCode)
- {
- errorCode = errCode;
- prvTraceStoreWarnings();
- vTracePrintF(trcWarningChannel, "Recorder stopped in prvTraceError()");
-
- prvSetRecorderEnabled(0);
- }
-}
-
-/* If using DWT timestamping (default on ARM Cortex-M3, M4 and M7), make sure the DWT unit is initialized. */
-#ifndef TRC_CFG_ARM_CM_USE_SYSTICK
-#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M) && (defined (__CORTEX_M) && (__CORTEX_M >= 0x03)))
-
-void prvTraceInitCortexM()
-{
- /* Make sure the DWT registers are unlocked, in case the debugger doesn't do this. */
- TRC_REG_ITM_LOCKACCESS = TRC_ITM_LOCKACCESS_UNLOCK;
-
- /* Make sure DWT is enabled is enabled, if supported */
- TRC_REG_DEMCR |= TRC_DEMCR_TRCENA;
-
- do
- {
- /* Verify that DWT is supported */
- if (TRC_REG_DEMCR == 0)
- {
- /* This function is called on Cortex-M3, M4 and M7 devices to initialize
- the DWT unit, assumed present. The DWT cycle counter is used for timestamping.
-
- If the below error is produced, the DWT unit does not seem to be available.
-
- In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build
- to use SysTick timestamping instead, or define your own timestamping by
- setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED
- and make the necessary definitions, as explained in trcHardwarePort.h.*/
-
- prvTraceError(PSF_ERROR_DWT_NOT_SUPPORTED);
- break;
- }
-
- /* Verify that DWT_CYCCNT is supported */
- if (TRC_REG_DWT_CTRL & TRC_DWT_CTRL_NOCYCCNT)
- {
- /* This function is called on Cortex-M3, M4 and M7 devices to initialize
- the DWT unit, assumed present. The DWT cycle counter is used for timestamping.
-
- If the below error is produced, the cycle counter does not seem to be available.
-
- In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build
- to use SysTick timestamping instead, or define your own timestamping by
- setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED
- and make the necessary definitions, as explained in trcHardwarePort.h.*/
-
- prvTraceError(PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED);
- break;
- }
-
- /* Reset the cycle counter */
- TRC_REG_DWT_CYCCNT = 0;
-
- /* Enable the cycle counter */
- TRC_REG_DWT_CTRL |= TRC_DWT_CTRL_CYCCNTENA;
-
- } while(0); /* breaks above jump here */
-}
-#endif
-#endif
-
-/* Performs timestamping using definitions in trcHardwarePort.h */
-static uint32_t prvGetTimestamp32(void)
-{
-#if ((TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR) || (TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR))
- return TRC_HWTC_COUNT;
-#endif
-
-#if ((TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR))
- return TRC_HWTC_COUNT;
-#endif
-
-#if ((TRC_HWTC_TYPE == TRC_OS_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))
- uint32_t ticks = TRACE_GET_OS_TICKS();
- return ((TRC_HWTC_COUNT) & 0x00FFFFFFU) + ((ticks & 0x000000FFU) << 24);
-#endif
-}
-
-/* Store the Timestamp Config event */
-static void prvTraceStoreTSConfig(void)
-{
- /* If not overridden using vTraceSetFrequency, use default value */
- if (timestampFrequency == 0)
- {
- timestampFrequency = TRC_HWTC_FREQ_HZ;
- }
-
- #if (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR || TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR)
-
- prvTraceStoreEvent(5,
- PSF_EVENT_TS_CONFIG,
- (uint32_t)timestampFrequency,
- (uint32_t)(TRACE_TICK_RATE_HZ),
- (uint32_t)(TRC_HWTC_TYPE),
- (uint32_t)(TRC_CFG_ISR_TAILCHAINING_THRESHOLD),
- (uint32_t)(TRC_HWTC_PERIOD));
-
- #else
-
- prvTraceStoreEvent(4,
- PSF_EVENT_TS_CONFIG,
- (uint32_t)timestampFrequency,
- (uint32_t)(TRACE_TICK_RATE_HZ),
- (uint32_t)(TRC_HWTC_TYPE),
- (uint32_t)(TRC_CFG_ISR_TAILCHAINING_THRESHOLD));
- #endif
-}
-
-/* Retrieve a buffer page to write to. */
-static int prvAllocateBufferPage(int prevPage)
-{
- int index;
- int count = 0;
-
- index = (prevPage + 1) % (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT);
-
- while((PageInfo[index].Status != PAGE_STATUS_FREE) && (count ++ < (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT)))
- {
- index = (index + 1) % (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT);
- }
-
- if (PageInfo[index].Status == PAGE_STATUS_FREE)
- {
- return index;
- }
-
- return -1;
-}
-
-/* Mark the page read as complete. */
-static void prvPageReadComplete(int pageIndex)
-{
- TRACE_ALLOC_CRITICAL_SECTION();
-
- TRACE_ENTER_CRITICAL_SECTION();
- PageInfo[pageIndex].BytesRemaining = (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
- PageInfo[pageIndex].WritePointer = &EventBuffer[pageIndex * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];
- PageInfo[pageIndex].Status = PAGE_STATUS_FREE;
-
- TotalBytesRemaining += (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
-
- TRACE_EXIT_CRITICAL_SECTION();
-}
-
-/* Get the current buffer page index and remaining number of bytes. */
-static int prvGetBufferPage(int32_t* bytesUsed)
-{
- static int8_t lastPage = -1;
- int count = 0;
- int8_t index = (int8_t) ((lastPage + 1) % (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT));
-
- while((PageInfo[index].Status != PAGE_STATUS_READ) && (count++ < (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT)))
- {
- index = (int8_t)((index + 1) % (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT));
- }
-
- if (PageInfo[index].Status == PAGE_STATUS_READ)
- {
- *bytesUsed = (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE) - PageInfo[index].BytesRemaining;
- lastPage = index;
- return index;
- }
-
- *bytesUsed = 0;
-
- return -1;
-}
-
-/*******************************************************************************
- * uint32_t prvPagedEventBufferTransfer(void)
- *
- * Transfers one buffer page of trace data, if a full page is available, using
- * the macro TRC_STREAM_PORT_WRITE_DATA as defined in trcStreamingPort.h.
- *
- * This function is intended to be called the periodic TzCtrl task with a suitable
- * delay (e.g. 10-100 ms).
- *
- * Returns the number of bytes sent. If non-zero, it is good to call this
- * again, in order to send any additional data waiting in the buffer.
- * If zero, wait a while before calling again.
- *
- * In case of errors from the streaming interface, it registers a warning
- * (PSF_WARNING_STREAM_PORT_WRITE) provided by xTraceGetLastError().
- *
- *******************************************************************************/
-uint32_t prvPagedEventBufferTransfer(void)
-{
- int8_t pageToTransfer = -1;
- int32_t bytesTransferredTotal = 0;
- int32_t bytesTransferredNow = 0;
- int32_t bytesToTransfer;
-
- pageToTransfer = (int8_t)prvGetBufferPage(&bytesToTransfer);
-
- /* bytesToTransfer now contains the number of "valid" bytes in the buffer page, that should be transmitted.
- There might be some unused junk bytes in the end, that must be ignored. */
-
- if (pageToTransfer > -1)
- {
- while (1) /* Keep going until we have transferred all that we intended to */
- {
- if (TRC_STREAM_PORT_WRITE_DATA(
- &EventBuffer[pageToTransfer * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE) + bytesTransferredTotal],
- (uint32_t)(bytesToTransfer - bytesTransferredTotal),
- &bytesTransferredNow) == 0)
- {
- /* Write was successful. Update the number of transferred bytes. */
- bytesTransferredTotal += bytesTransferredNow;
-
- if (bytesTransferredTotal == bytesToTransfer)
- {
- /* All bytes have been transferred. Mark the buffer page as "Read Complete" (so it can be written to) and return OK. */
- prvPageReadComplete(pageToTransfer);
- return (uint32_t)bytesTransferredTotal;
- }
- }
- else
- {
- /* Some error from the streaming interface... */
- prvTraceWarning(PSF_WARNING_STREAM_PORT_WRITE);
- return 0;
- }
- }
- }
- return 0;
-}
-
-/*******************************************************************************
- * void* prvPagedEventBufferGetWritePointer(int sizeOfEvent)
- *
- * Returns a pointer to an available location in the buffer able to store the
- * requested size.
- *
- * Return value: The pointer.
- *
- * Parameters:
- * - sizeOfEvent: The size of the event that is to be placed in the buffer.
- *
-*******************************************************************************/
-void* prvPagedEventBufferGetWritePointer(int sizeOfEvent)
-{
- void* ret;
- static int currentWritePage = -1;
-
- if (currentWritePage == -1)
- {
- currentWritePage = prvAllocateBufferPage(currentWritePage);
- if (currentWritePage == -1)
- {
- DroppedEventCounter++;
- return NULL;
- }
- }
-
- if (PageInfo[currentWritePage].BytesRemaining - sizeOfEvent < 0)
- {
- PageInfo[currentWritePage].Status = PAGE_STATUS_READ;
-
- TotalBytesRemaining -= PageInfo[currentWritePage].BytesRemaining; // Last trailing bytes
-
- if (TotalBytesRemaining < TotalBytesRemaining_LowWaterMark)
- TotalBytesRemaining_LowWaterMark = TotalBytesRemaining;
-
- currentWritePage = prvAllocateBufferPage(currentWritePage);
- if (currentWritePage == -1)
- {
- DroppedEventCounter++;
- return NULL;
- }
- }
- ret = PageInfo[currentWritePage].WritePointer;
- PageInfo[currentWritePage].WritePointer += sizeOfEvent;
- PageInfo[currentWritePage].BytesRemaining = (uint16_t)(PageInfo[currentWritePage].BytesRemaining -sizeOfEvent);
-
- TotalBytesRemaining = (TotalBytesRemaining-(uint16_t)sizeOfEvent);
-
- if (TotalBytesRemaining < TotalBytesRemaining_LowWaterMark)
- TotalBytesRemaining_LowWaterMark = TotalBytesRemaining;
-
- return ret;
-}
-
-/*******************************************************************************
- * void prvPagedEventBufferInit(char* buffer)
- *
- * Assigns the buffer to use and initializes the PageInfo structure.
- *
- * Return value: void
- *
- * Parameters:
- * - char* buffer: pointer to the trace data buffer, allocated by the caller.
- *
-*******************************************************************************/
-void prvPagedEventBufferInit(char* buffer)
-{
- int i;
- TRACE_ALLOC_CRITICAL_SECTION();
-
- EventBuffer = buffer;
-
- TRACE_ENTER_CRITICAL_SECTION();
- for (i = 0; i < (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT); i++)
- {
- PageInfo[i].BytesRemaining = (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
- PageInfo[i].WritePointer = &EventBuffer[i * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];
- PageInfo[i].Status = PAGE_STATUS_FREE;
- }
- TRACE_EXIT_CRITICAL_SECTION();
-
-}
-
-#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
-
-#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/See also FreeRTOS+TCP.url b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/See also FreeRTOS+TCP.url
deleted file mode 100755
index 6617b60..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/See also FreeRTOS+TCP.url
+++ /dev/null
@@ -1,5 +0,0 @@
-[{000214A0-0000-0000-C000-000000000046}]
-Prop3=19,2
-[InternetShortcut]
-URL=http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
-IDList=
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/readme.txt
deleted file mode 100755
index bc35bc3..0000000
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/readme.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-FreeRTOS+UDP was removed in FreeRTOS V10.1.0 as it was replaced by FreeRTOS+TCP,
-which was brought into the main download in FreeRTOS V10.0.0. FreeRTOS+TCP can
-be configured as a UDP only stack, and FreeRTOS+UDP does not contain the patches
-applied to FreeRTOS+TCP.
\ No newline at end of file
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/CREDITS.txt b/FreeRTOS-Plus/Source/Reliance-Edge/CREDITS.txt
deleted file mode 100755
index 7b2f608..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/CREDITS.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-Reliance Edge Credits
-=====================
-
-This is a list (or partial list) of people who have made non-trivial or
-noteworthy contributions to the Reliance Edge project. It is sorted by name.
-Entries are formatted as below:
-
-Real Name (githubaccount)
-Short description of how Real Name contributed to Reliance Edge.
-
-The real name may be withheld by request and the GitHub account name might be
-missing if the contributor does not use GitHub.
-
-Credits
--------
-
-Jean-Christophe Dubois (jcdubois)
-Created a user-space Linux port of Reliance Edge, ported the open-source host
-tools (including the formatter and image builder) to Linux, and created a FUSE
-(File System in User Space) implementation for Reliance Edge.
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/LICENSE.txt b/FreeRTOS-Plus/Source/Reliance-Edge/LICENSE.txt
deleted file mode 100755
index 1f963da..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/LICENSE.txt
+++ /dev/null
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/README.md b/FreeRTOS-Plus/Source/Reliance-Edge/README.md
deleted file mode 100755
index 0c2e228..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/README.md
+++ /dev/null
@@ -1,123 +0,0 @@
-# Reliance Edge
-
-Reliance Edge is a small, portable, highly reliable power-fail safe file system
-for resource-constrained embedded systems like microcontrollers. It is written
-in C and provides a familiar POSIX-like file system API, making it easy to use
-in your application; or an alternate minimalist API if your application has
-simple storage needs. Reliance Edge is highly configurable and can be tuned to
-the precise needs of your application.
-
-## Getting Help
-
-You will find this section later in our readme as well - but we wanted to tell
-you up front: DATALIGHT WANTS TO HEAR FROM YOU! Whether it's just to make
-comments about the product, to suggest new features, or to tell us what you
-don't like - reach out! All comments and inquiries can be directed to
-.
-
-## Documentation
-
-The complete documentation for Reliance Edge is distributed separately. It
-includes an API reference and detailed discussions of various aspects of using
-Reliance Edge, including porting, building, configuring, and testing. This
-complete documentation, called the _Developer's Guide_, can be obtained for free
-from here:
-
-
-
-In addition this README, see doc/release_notes.md for a list of updates
-to Reliance Edge and a list of known issues. There is also a quick-start
-guide in the doc/ directory that describes step-by-step how to compile
-and run Reliance Edge in a simulated Windows environment.
-
-## Why Use Reliance Edge?
-
-Reliance Edge is ideal for small embedded systems with data storage
-requirements, especially if there is a chance of sudden power loss or other
-system failures. Compared to "raw" disk access, using a file system like
-Reliance Edge removes the burden of tracking which sectors belong to which
-objects, and allows data to be updated more reliably. Compared to the FAT file
-system, using Reliance Edge eliminates the possibility that file system data
-will be left in an inconsistent state, corrupting the disk; Reliance Edge does
-not need a fsck/CHKDSK utility. Compared to journaling file systems, Reliance
-Edge has less overhead and results in less storage media wear for longer device
-lifetimes.
-
-Reliance Edge uses a unique transactional model that not only prevents file
-system corruption but also allows a set of changes to be made in an atomic "all
-or nothing" fashion. This is very useful for applications that make sets of
-interrelated changes. By using the features of Reliance Edge, a set of changes
-can be incorporated into a single atomic transaction, which is committed in its
-entirety or not at all even if interrupted by power loss; this means the
-application does not need code to recover from partially-finished updates.
-
-## Hardware
-
-The typical hardware for Reliance Edge is a 32-bit microcontroller, but other
-targets are possible. In its typical configurations, Reliance Edge needs at
-least 4 KB to 5 KB of RAM, 11 to 18 KB of code space (on the ROM or NOR flash),
-and 500 to 700 bytes of stack.
-
-Reliance Edge is not designed for high-end embedded systems that run complicated
-operating systems like Linux or Windows Embedded Compact. Embedded systems of
-that variety are better served by other file systems, like Datalight's
-[Reliance Nitro](http://www.datalight.com/products/embedded-file-systems/reliance-nitro).
-
-## Getting Reliance Edge Working
-
-Before you can use Reliance Edge, it must be ported and configured. At a
-minimum, porting includes filling-in functions so that Reliance Edge can issue
-commands to your storage medium; depending on your needs, other functions may
-need to be filled in as well. These functions reside in a subdirectory in the
-os/ directory; see os/stub/ for a blank set of functions. Configuring includes
-creating a project directory (start by copying projects/newproj) and creating
-the two configuration files (redconf.h/redconf.c) using the Reliance Edge
-Configuration Utility (which can be downloaded from
-).
-
-These topics are covered in much greater detail in the _Developer's Guide_,
-linked above.
-
-## Using Reliance Edge
-
-Using Reliance Edge is a simple matter of including the primary Reliance Edge
-application header in your application (either include/redposix.h or
-include/redfse.h) and compiling and linking against Reliance Edge binaries.
-The Reliance Edge driver must be initialized before it is used (via the
-red\_init() or RedFseInit() functions) and then volumes can be mounted and file
-and directory functions invoked. The Reliance Edge API is documented in the
-_Developer's Guide_ (linked above) and also via comments in the source code.
-
-## Licensing
-
-Reliance Edge is an open-source project licensed under the GNU General Public
-License v2 (GPLv2). Businesses and individuals that for commercial or other
-reasons cannot comply with the terms of the GPLv2 license may obtain a
-commercial license before incorporating Reliance Edge into proprietary software
-for distribution in any form. Visit
-for more information. The commercial distribution also includes extra tests and
-tools not distributed with the GPLv2 version.
-
-See LICENSE.txt for the full license terms of this distribution of the product.
-
-## Getting Help
-
-If you need assistance using Reliance Edge, and you have already consulted the
-_Developer's Guide_, contact .
-
-In the near future, a community forum or message board will be set up to
-facilitate discussion of Reliance Edge and allow users to get help from
-Datalight and from each other. In the meantime, please use the email address
-given above.
-
-## Contributing
-
-Contributions to Reliance Edge are welcome. Our policy is that Datalight must
-own the copyright of all code incorporated into Reliance Edge; if contributing a
-significant amount of code, you will be asked to file a copyright assignment
-agreement. See CONTRIBUTING.txt for further details and contribution
-guidelines.
-
-To report bugs, please create a GitHub issue or contact
-.
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/README.txt b/FreeRTOS-Plus/Source/Reliance-Edge/README.txt
deleted file mode 100755
index 106d923..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/README.txt
+++ /dev/null
@@ -1,140 +0,0 @@
-
-
-RELIANCE EDGE
-
-
-Reliance Edge is a small, portable, highly reliable power-fail safe file
-system for resource-constrained embedded systems like microcontrollers.
-It is written in C and provides a familiar POSIX-like file system API,
-making it easy to use in your application; or an alternate minimalist
-API if your application has simple storage needs. Reliance Edge is
-highly configurable and can be tuned to the precise needs of your
-application.
-
-
-Getting Help
-
-You will find this section later in our readme as well - but we wanted
-to tell you up front: DATALIGHT WANTS TO HEAR FROM YOU! Whether it's
-just to make comments about the product, to suggest new features, or to
-tell us what you don't like - reach out! All comments and inquiries can
-be directed to RelianceEdgeSupport@datalight.com.
-
-
-Documentation
-
-The complete documentation for Reliance Edge is distributed separately.
-It includes an API reference and detailed discussions of various aspects
-of using Reliance Edge, including porting, building, configuring, and
-testing. This complete documentation, called the _Developer's Guide_,
-can be obtained for free from here:
-
-http://www.datalight.com/reliance-edge
-
-In addition this README, see doc/release_notes.md for a list of updates
-to Reliance Edge and a list of known issues. There is also a quick-start
-guide in the doc/ directory that describes step-by-step how to compile
-and run Reliance Edge in a simulated Windows environment.
-
-
-Why Use Reliance Edge?
-
-Reliance Edge is ideal for small embedded systems with data storage
-requirements, especially if there is a chance of sudden power loss or
-other system failures. Compared to "raw" disk access, using a file
-system like Reliance Edge removes the burden of tracking which sectors
-belong to which objects, and allows data to be updated more reliably.
-Compared to the FAT file system, using Reliance Edge eliminates the
-possibility that file system data will be left in an inconsistent state,
-corrupting the disk; Reliance Edge does not need a fsck/CHKDSK utility.
-Compared to journaling file systems, Reliance Edge has less overhead and
-results in less storage media wear for longer device lifetimes.
-
-Reliance Edge uses a unique transactional model that not only prevents
-file system corruption but also allows a set of changes to be made in an
-atomic "all or nothing" fashion. This is very useful for applications
-that make sets of interrelated changes. By using the features of
-Reliance Edge, a set of changes can be incorporated into a single atomic
-transaction, which is committed in its entirety or not at all even if
-interrupted by power loss; this means the application does not need code
-to recover from partially-finished updates.
-
-
-Hardware
-
-The typical hardware for Reliance Edge is a 32-bit microcontroller, but
-other targets are possible. In its typical configurations, Reliance Edge
-needs at least 4 KB to 5 KB of RAM, 11 to 18 KB of code space (on the
-ROM or NOR flash), and 500 to 700 bytes of stack.
-
-Reliance Edge is not designed for high-end embedded systems that run
-complicated operating systems like Linux or Windows Embedded Compact.
-Embedded systems of that variety are better served by other file
-systems, like Datalight's Reliance Nitro.
-
-
-Getting Reliance Edge Working
-
-Before you can use Reliance Edge, it must be ported and configured. At a
-minimum, porting includes filling-in functions so that Reliance Edge can
-issue commands to your storage medium; depending on your needs, other
-functions may need to be filled in as well. These functions reside in a
-subdirectory in the os/ directory; see os/stub/ for a blank set of
-functions. Configuring includes creating a project directory (start by
-copying projects/newproj) and creating the two configuration files
-(redconf.h/redconf.c) using the Reliance Edge Configuration Utility
-(which can be downloaded from http://www.datalight.com/reliance-edge).
-
-These topics are covered in much greater detail in the _Developer's
-Guide_, linked above.
-
-
-Using Reliance Edge
-
-Using Reliance Edge is a simple matter of including the primary Reliance
-Edge application header in your application (either include/redposix.h
-or include/redfse.h) and compiling and linking against Reliance Edge
-binaries. The Reliance Edge driver must be initialized before it is used
-(via the red_init() or RedFseInit() functions) and then volumes can be
-mounted and file and directory functions invoked. The Reliance Edge API
-is documented in the _Developer's Guide_ (linked above) and also via
-comments in the source code.
-
-
-Licensing
-
-Reliance Edge is an open-source project licensed under the GNU General
-Public License v2 (GPLv2). Businesses and individuals that for
-commercial or other reasons cannot comply with the terms of the GPLv2
-license may obtain a commercial license before incorporating Reliance
-Edge into proprietary software for distribution in any form. Visit
-http://www.datalight.com/reliance-edge for more information. The
-commercial distribution also includes extra tests and tools not
-distributed with the GPLv2 version.
-
-See LICENSE.txt for the full license terms of this distribution of the
-product.
-
-
-Getting Help
-
-If you need assistance using Reliance Edge, and you have already
-consulted the _Developer's Guide_, contact
-RelianceEdgeSupport@datalight.com.
-
-In the near future, a community forum or message board will be set up to
-facilitate discussion of Reliance Edge and allow users to get help from
-Datalight and from each other. In the meantime, please use the email
-address given above.
-
-
-Contributing
-
-Contributions to Reliance Edge are welcome. Our policy is that Datalight
-must own the copyright of all code incorporated into Reliance Edge; if
-contributing a significant amount of code, you will be asked to file a
-copyright assignment agreement. See CONTRIBUTING.txt for further details
-and contribution guidelines.
-
-To report bugs, please create a GitHub issue or contact
-RelianceEdgeSupport@datalight.com.
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/blockio.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/blockio.c
deleted file mode 100755
index 897143d..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/blockio.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements block device I/O using logical blocks as the units.
-
- The OS block device implementations operate on sectors. The core does I/O
- in terms of logical blocks: this module translates from logical blocks to
- sectors.
-
- If bBlockIoRetries is greater than 0 for the current volume, then this
- module will retry block device calls on failure up to the configured number
- of times. This behavior caters to the type of unreliable hardware and
- drivers that are sometimes found in the IoT world, where one operation may
- fail but the next may still succeed.
-*/
-#include
-#include
-
-
-/** @brief Read a range of logical blocks.
-
- @param bVolNum The volume whose block device is being read from.
- @param ulBlockStart The first block to read.
- @param ulBlockCount The number of blocks to read.
- @param pBuffer The buffer to populate with the data read.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-REDSTATUS RedIoRead(
- uint8_t bVolNum,
- uint32_t ulBlockStart,
- uint32_t ulBlockCount,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if( (bVolNum >= REDCONF_VOLUME_COUNT)
- || (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
- || ((gaRedVolume[bVolNum].ulBlockCount - ulBlockStart) < ulBlockCount)
- || (ulBlockCount == 0U)
- || (pBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
- uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
- uint32_t ulSectorCount = ulBlockCount << bSectorShift;
- uint8_t bRetryIdx;
-
- REDASSERT(bSectorShift < 32U);
- REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
-
- for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
- {
- ret = RedOsBDevRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
-
- if(ret == 0)
- {
- break;
- }
- }
- }
-
- CRITICAL_ASSERT(ret == 0);
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write a range of logical blocks.
-
- @param bVolNum The volume whose block device is being written to.
- @param ulBlockStart The first block to write.
- @param ulBlockCount The number of blocks to write.
- @param pBuffer The buffer containing the data to write.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-REDSTATUS RedIoWrite(
- uint8_t bVolNum,
- uint32_t ulBlockStart,
- uint32_t ulBlockCount,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if( (bVolNum >= REDCONF_VOLUME_COUNT)
- || (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
- || ((gaRedVolume[bVolNum].ulBlockCount - ulBlockStart) < ulBlockCount)
- || (ulBlockCount == 0U)
- || (pBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
- uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
- uint32_t ulSectorCount = ulBlockCount << bSectorShift;
- uint8_t bRetryIdx;
-
- REDASSERT(bSectorShift < 32U);
- REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
-
- for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
- {
- ret = RedOsBDevWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
-
- if(ret == 0)
- {
- break;
- }
- }
- }
-
- CRITICAL_ASSERT(ret == 0);
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedIoFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret = 0;
-
- if(bVolNum >= REDCONF_VOLUME_COUNT)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t bRetryIdx;
-
- for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
- {
- ret = RedOsBDevFlush(bVolNum);
-
- if(ret == 0)
- {
- break;
- }
- }
- }
-
- CRITICAL_ASSERT(ret == 0);
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/buffer.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/buffer.c
deleted file mode 100755
index 17717e0..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/buffer.c
+++ /dev/null
@@ -1,1212 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements the block device buffering system.
-
- This module implements the block buffer cache. It has a number of block
- sized buffers which are used to store data from a given block (identified
- by both block number and volume number: this cache is shared among all
- volumes). Block buffers may be either dirty or clean. Most I/O passes
- through this module. When a buffer is needed for a block which is not in
- the cache, a "victim" is selected via a simple LRU scheme.
-*/
-#include
-#include
-
-
-#if DINDIR_POINTERS > 0U
- #define INODE_META_BUFFERS 3U /* Inode, double indirect, indirect */
-#elif REDCONF_INDIRECT_POINTERS > 0U
- #define INODE_META_BUFFERS 2U /* Inode, indirect */
-#elif REDCONF_DIRECT_POINTERS == INODE_ENTRIES
- #define INODE_META_BUFFERS 1U /* Inode only */
-#endif
-
-#define INODE_BUFFERS (INODE_META_BUFFERS + 1U) /* Add data buffer */
-
-#if REDCONF_IMAP_EXTERNAL == 1
- #define IMAP_BUFFERS 1U
-#else
- #define IMAP_BUFFERS 0U
-#endif
-
-#if (REDCONF_READ_ONLY == 1) || (REDCONF_API_FSE == 1)
- /* Read, write, truncate, lookup: One inode all the way down, plus imap.
- */
- #define MINIMUM_BUFFER_COUNT (INODE_BUFFERS + IMAP_BUFFERS)
-#elif REDCONF_API_POSIX == 1
- #if REDCONF_API_POSIX_RENAME == 1
- #if REDCONF_RENAME_ATOMIC == 1
- /* Two parent directories all the way down. Source and destination inode
- buffer. One inode buffer for cyclic rename detection. Imap. The
- parent inode buffers are released before deleting the destination
- inode, so that does not increase the minimum.
- */
- #define MINIMUM_BUFFER_COUNT (INODE_BUFFERS + INODE_BUFFERS + 3U + IMAP_BUFFERS)
- #else
- /* Two parent directories all the way down. Source inode buffer. One
- inode buffer for cyclic rename detection. Imap.
- */
- #define MINIMUM_BUFFER_COUNT (INODE_BUFFERS + INODE_BUFFERS + 2U + IMAP_BUFFERS)
- #endif
- #else
- /* Link/create: Needs a parent inode all the way down, an extra inode
- buffer, and an imap buffer.
-
- Unlink is the same, since the parent inode buffers are released before
- the inode is deleted.
- */
- #define MINIMUM_BUFFER_COUNT (INODE_BUFFERS + 1U + IMAP_BUFFERS)
- #endif
-#endif
-
-#if REDCONF_BUFFER_COUNT < MINIMUM_BUFFER_COUNT
-#error "REDCONF_BUFFER_COUNT is too low for the configuration"
-#endif
-
-
-/* A note on the typecasts in the below macros: Operands to bitwise operators
- are subject to the "usual arithmetic conversions". This means that the
- flags, which have uint16_t values, are promoted to int. MISRA-C:2012 R10.1
- forbids using signed integers in bitwise operations, so we cast to uint32_t
- to avoid the integer promotion, then back to uint16_t to reflect the actual
- type.
-*/
-#define BFLAG_META_MASK (uint16_t)((uint32_t)BFLAG_META_MASTER | BFLAG_META_IMAP | BFLAG_META_INODE | BFLAG_META_INDIR | BFLAG_META_DINDIR)
-#define BFLAG_MASK (uint16_t)((uint32_t)BFLAG_DIRTY | BFLAG_NEW | BFLAG_META_MASK)
-
-
-/* An invalid block number. Used to indicate buffers which are not currently
- in use.
-*/
-#define BBLK_INVALID UINT32_MAX
-
-
-/** @brief Metadata stored for each block buffer.
-
- To make better use of CPU caching when searching the BUFFERHEAD array, this
- structure should be kept small.
-*/
-typedef struct
-{
- uint32_t ulBlock; /**< Block number the buffer is associated with; BBLK_INVALID if unused. */
- uint8_t bVolNum; /**< Volume the block resides on. */
- uint8_t bRefCount; /**< Number of references. */
- uint16_t uFlags; /**< Buffer flags: mask of BFLAG_* values. */
-} BUFFERHEAD;
-
-
-/** @brief State information for the block buffer module.
-*/
-typedef struct
-{
- /** Number of buffers which are referenced (have a bRefCount > 0).
- */
- uint16_t uNumUsed;
-
- /** MRU array. Each element of the array stores a buffer index; each buffer
- index appears in the array once and only once. The first element of the
- array is the most-recently-used (MRU) buffer, followed by the next most
- recently used, and so on, till the last element, which is the least-
- recently-used (LRU) buffer.
- */
- uint8_t abMRU[REDCONF_BUFFER_COUNT];
-
- /** Buffer heads, storing metadata for each buffer.
- */
- BUFFERHEAD aHead[REDCONF_BUFFER_COUNT];
-
- /** Array of memory for the block buffers themselves.
-
- Force 64-bit alignment of the aabBuffer array to ensure that it is safe
- to cast buffer pointers to node structure pointers.
- */
- ALIGNED_2D_BYTE_ARRAY(b, aabBuffer, REDCONF_BUFFER_COUNT, REDCONF_BLOCK_SIZE);
-} BUFFERCTX;
-
-
-static bool BufferIsValid(const uint8_t *pbBuffer, uint16_t uFlags);
-static bool BufferToIdx(const void *pBuffer, uint8_t *pbIdx);
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS BufferWrite(uint8_t bIdx);
-static REDSTATUS BufferFinalize(uint8_t *pbBuffer, uint16_t uFlags);
-#endif
-static void BufferMakeLRU(uint8_t bIdx);
-static void BufferMakeMRU(uint8_t bIdx);
-static bool BufferFind(uint32_t ulBlock, uint8_t *pbIdx);
-
-#ifdef REDCONF_ENDIAN_SWAP
-static void BufferEndianSwap(const void *pBuffer, uint16_t uFlags);
-static void BufferEndianSwapHeader(NODEHEADER *pHeader);
-static void BufferEndianSwapMaster(MASTERBLOCK *pMaster);
-static void BufferEndianSwapMetaRoot(METAROOT *pMetaRoot);
-static void BufferEndianSwapInode(INODE *pInode);
-static void BufferEndianSwapIndir(INDIR *pIndir);
-#endif
-
-
-static BUFFERCTX gBufCtx;
-
-
-/** @brief Initialize the buffers.
-*/
-void RedBufferInit(void)
-{
- uint8_t bIdx;
-
- RedMemSet(&gBufCtx, 0U, sizeof(gBufCtx));
-
- for(bIdx = 0U; bIdx < REDCONF_BUFFER_COUNT; bIdx++)
- {
- /* When the buffers have been freshly initialized, acquire the buffers
- in the order in which they appear in the array.
- */
- gBufCtx.abMRU[bIdx] = (uint8_t)((REDCONF_BUFFER_COUNT - bIdx) - 1U);
- gBufCtx.aHead[bIdx].ulBlock = BBLK_INVALID;
- }
-}
-
-
-/** @brief Acquire a buffer.
-
- @param ulBlock Block number to acquire.
- @param uFlags BFLAG_ values for the operation.
- @param ppBuffer On success, populated with the acquired buffer.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
- @retval -RED_EBUSY All buffers are referenced.
-*/
-REDSTATUS RedBufferGet(
- uint32_t ulBlock,
- uint16_t uFlags,
- void **ppBuffer)
-{
- REDSTATUS ret = 0;
- uint8_t bIdx;
-
- if((ulBlock >= gpRedVolume->ulBlockCount) || ((uFlags & BFLAG_MASK) != uFlags) || (ppBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- if(BufferFind(ulBlock, &bIdx))
- {
- /* Error if the buffer exists and BFLAG_NEW was specified, since
- the new flag is used when a block is newly allocated/created, so
- the block was previously free and and there should never be an
- existing buffer for a free block.
-
- Error if the buffer exists but does not have the same type as
- was requested.
- */
- if( ((uFlags & BFLAG_NEW) != 0U)
- || ((uFlags & BFLAG_META_MASK) != (gBufCtx.aHead[bIdx].uFlags & BFLAG_META_MASK)))
- {
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- }
- else if(gBufCtx.uNumUsed == REDCONF_BUFFER_COUNT)
- {
- /* The MINIMUM_BUFFER_COUNT is supposed to ensure that no operation
- ever runs out of buffers, so this should never happen.
- */
- CRITICAL_ERROR();
- ret = -RED_EBUSY;
- }
- else
- {
- BUFFERHEAD *pHead;
-
- /* Search for the least recently used buffer which is not
- referenced.
- */
- for(bIdx = (uint8_t)(REDCONF_BUFFER_COUNT - 1U); bIdx > 0U; bIdx--)
- {
- if(gBufCtx.aHead[gBufCtx.abMRU[bIdx]].bRefCount == 0U)
- {
- break;
- }
- }
-
- bIdx = gBufCtx.abMRU[bIdx];
- pHead = &gBufCtx.aHead[bIdx];
-
- if(pHead->bRefCount == 0U)
- {
- /* If the LRU buffer is valid and dirty, write it out before
- repurposing it.
- */
- if(((pHead->uFlags & BFLAG_DIRTY) != 0U) && (pHead->ulBlock != BBLK_INVALID))
- {
- #if REDCONF_READ_ONLY == 1
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- #else
- ret = BufferWrite(bIdx);
- #endif
- }
- }
- else
- {
- /* All the buffers are used, which should have been caught by
- checking gBufCtx.uNumUsed.
- */
- CRITICAL_ERROR();
- ret = -RED_EBUSY;
- }
-
- if(ret == 0)
- {
- if((uFlags & BFLAG_NEW) == 0U)
- {
- /* Invalidate the LRU buffer. If the read fails, we do not
- want the buffer head to continue to refer to the old
- block number, since the read, even if it fails, may have
- partially overwritten the buffer data (consider the case
- where block size exceeds sector size, and some but not
- all of the sectors are read successfully), and if the
- buffer were to be used subsequently with its partially
- erroneous contents, bad things could happen.
- */
- pHead->ulBlock = BBLK_INVALID;
-
- ret = RedIoRead(gbRedVolNum, ulBlock, 1U, gBufCtx.b.aabBuffer[bIdx]);
-
- if((ret == 0) && ((uFlags & BFLAG_META) != 0U))
- {
- if(!BufferIsValid(gBufCtx.b.aabBuffer[bIdx], uFlags))
- {
- /* A corrupt metadata node is usually a critical
- error. The master block is an exception since
- it might be invalid because the volume is not
- mounted; that condition is expected and should
- not result in an assertion.
- */
- CRITICAL_ASSERT((uFlags & BFLAG_META_MASTER) == BFLAG_META_MASTER);
- ret = -RED_EIO;
- }
- }
-
- #ifdef REDCONF_ENDIAN_SWAP
- if(ret == 0)
- {
- BufferEndianSwap(gBufCtx.b.aabBuffer[bIdx], uFlags);
- }
- #endif
- }
- else
- {
- RedMemSet(gBufCtx.b.aabBuffer[bIdx], 0U, REDCONF_BLOCK_SIZE);
- }
- }
-
- if(ret == 0)
- {
- pHead->bVolNum = gbRedVolNum;
- pHead->ulBlock = ulBlock;
- pHead->uFlags = 0U;
- }
- }
-
- /* Reference the buffer, update its flags, and promote it to MRU. This
- happens both when BufferFind() found an existing buffer for the
- block and when the LRU buffer was repurposed to create a buffer for
- the block.
- */
- if(ret == 0)
- {
- BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- pHead->bRefCount++;
-
- if(pHead->bRefCount == 1U)
- {
- gBufCtx.uNumUsed++;
- }
-
- /* BFLAG_NEW tells this function to zero the buffer instead of
- reading it from disk; it has no meaning later on, and thus is
- not saved.
- */
- pHead->uFlags |= (uFlags & (~BFLAG_NEW));
-
- BufferMakeMRU(bIdx);
-
- *ppBuffer = gBufCtx.b.aabBuffer[bIdx];
- }
- }
-
- return ret;
-}
-
-
-/** @brief Release a buffer.
-
- @param pBuffer The buffer to release.
- */
-void RedBufferPut(
- const void *pBuffer)
-{
- uint8_t bIdx;
-
- if(!BufferToIdx(pBuffer, &bIdx))
- {
- REDERROR();
- }
- else
- {
- REDASSERT(gBufCtx.aHead[bIdx].bRefCount > 0U);
- gBufCtx.aHead[bIdx].bRefCount--;
-
- if(gBufCtx.aHead[bIdx].bRefCount == 0U)
- {
- REDASSERT(gBufCtx.uNumUsed > 0U);
- gBufCtx.uNumUsed--;
- }
- }
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Flush all buffers for the active volume in the given range of blocks.
-
- @param ulBlockStart Starting block number to flush.
- @param ulBlockCount Count of blocks, starting at @p ulBlockStart, to flush.
- Must not be zero.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-REDSTATUS RedBufferFlush(
- uint32_t ulBlockStart,
- uint32_t ulBlockCount)
-{
- REDSTATUS ret = 0;
-
- if( (ulBlockStart >= gpRedVolume->ulBlockCount)
- || ((gpRedVolume->ulBlockCount - ulBlockStart) < ulBlockCount)
- || (ulBlockCount == 0U))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t bIdx;
-
- for(bIdx = 0U; bIdx < REDCONF_BUFFER_COUNT; bIdx++)
- {
- BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- if( (pHead->bVolNum == gbRedVolNum)
- && (pHead->ulBlock != BBLK_INVALID)
- && ((pHead->uFlags & BFLAG_DIRTY) != 0U)
- && (pHead->ulBlock >= ulBlockStart)
- && (pHead->ulBlock < (ulBlockStart + ulBlockCount)))
- {
- ret = BufferWrite(bIdx);
-
- if(ret == 0)
- {
- pHead->uFlags &= (~BFLAG_DIRTY);
- }
- else
- {
- break;
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Mark a buffer dirty
-
- @param pBuffer The buffer to mark dirty.
-*/
-void RedBufferDirty(
- const void *pBuffer)
-{
- uint8_t bIdx;
-
- if(!BufferToIdx(pBuffer, &bIdx))
- {
- REDERROR();
- }
- else
- {
- REDASSERT(gBufCtx.aHead[bIdx].bRefCount > 0U);
-
- gBufCtx.aHead[bIdx].uFlags |= BFLAG_DIRTY;
- }
-}
-
-
-/** @brief Branch a buffer, marking it dirty and assigning a new block number.
-
- @param pBuffer The buffer to branch.
- @param ulBlockNew The new block number for the buffer.
-*/
-void RedBufferBranch(
- const void *pBuffer,
- uint32_t ulBlockNew)
-{
- uint8_t bIdx;
-
- if( !BufferToIdx(pBuffer, &bIdx)
- || (ulBlockNew >= gpRedVolume->ulBlockCount))
- {
- REDERROR();
- }
- else
- {
- BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- REDASSERT(pHead->bRefCount > 0U);
- REDASSERT((pHead->uFlags & BFLAG_DIRTY) == 0U);
-
- pHead->uFlags |= BFLAG_DIRTY;
- pHead->ulBlock = ulBlockNew;
- }
-}
-
-
-#if (REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED
-/** @brief Discard a buffer, releasing it and marking it invalid.
-
- @param pBuffer The buffer to discard.
-*/
-void RedBufferDiscard(
- const void *pBuffer)
-{
- uint8_t bIdx;
-
- if(!BufferToIdx(pBuffer, &bIdx))
- {
- REDERROR();
- }
- else
- {
- REDASSERT(gBufCtx.aHead[bIdx].bRefCount == 1U);
- REDASSERT(gBufCtx.uNumUsed > 0U);
-
- gBufCtx.aHead[bIdx].bRefCount = 0U;
- gBufCtx.aHead[bIdx].ulBlock = BBLK_INVALID;
-
- gBufCtx.uNumUsed--;
-
- BufferMakeLRU(bIdx);
- }
-}
-#endif
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Discard a range of buffers, marking them invalid.
-
- @param ulBlockStart The starting block number to discard
- @param ulBlockCount The number of blocks, starting at @p ulBlockStart, to
- discard. Must not be zero.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL Invalid parameters.
- @retval -RED_EBUSY A block in the desired range is referenced.
-*/
-REDSTATUS RedBufferDiscardRange(
- uint32_t ulBlockStart,
- uint32_t ulBlockCount)
-{
- REDSTATUS ret = 0;
-
- if( (ulBlockStart >= gpRedVolume->ulBlockCount)
- || ((gpRedVolume->ulBlockCount - ulBlockStart) < ulBlockCount)
- || (ulBlockCount == 0U))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t bIdx;
-
- for(bIdx = 0U; bIdx < REDCONF_BUFFER_COUNT; bIdx++)
- {
- BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- if( (pHead->bVolNum == gbRedVolNum)
- && (pHead->ulBlock != BBLK_INVALID)
- && (pHead->ulBlock >= ulBlockStart)
- && (pHead->ulBlock < (ulBlockStart + ulBlockCount)))
- {
- if(pHead->bRefCount == 0U)
- {
- pHead->ulBlock = BBLK_INVALID;
-
- BufferMakeLRU(bIdx);
- }
- else
- {
- /* This should never happen. There are three general cases
- when this function is used:
-
- 1) Discarding every block, as happens during unmount
- and at the end of format. There should no longer be
- any referenced buffers at those points.
- 2) Discarding a block which has become free. All
- buffers for such blocks should be put or branched
- beforehand.
- 3) Discarding of blocks that were just written straight
- to disk, leaving stale data in the buffer. The write
- code should never reference buffers for these blocks,
- since they would not be needed or used.
- */
- CRITICAL_ERROR();
- ret = -RED_EBUSY;
- break;
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** Determine whether a metadata buffer is valid.
-
- This includes checking its signature, CRC, and sequence number.
-
- @param pbBuffer Pointer to the metadata buffer to validate.
- @param uFlags The buffer flags provided by the caller. Used to determine
- the expected signature.
-
- @return Whether the metadata buffer is valid.
-
- @retval true The metadata buffer is valid.
- @retval false The metadata buffer is invalid.
-*/
-static bool BufferIsValid(
- const uint8_t *pbBuffer,
- uint16_t uFlags)
-{
- bool fValid;
-
- if((pbBuffer == NULL) || ((uFlags & BFLAG_MASK) != uFlags))
- {
- REDERROR();
- fValid = false;
- }
- else
- {
- NODEHEADER buf;
- uint16_t uMetaFlags = uFlags & BFLAG_META_MASK;
-
- /* Casting pbBuffer to (NODEHEADER *) would run afoul MISRA-C:2012
- R11.3, so instead copy the fields out.
- */
- RedMemCpy(&buf.ulSignature, &pbBuffer[NODEHEADER_OFFSET_SIG], sizeof(buf.ulSignature));
- RedMemCpy(&buf.ulCRC, &pbBuffer[NODEHEADER_OFFSET_CRC], sizeof(buf.ulCRC));
- RedMemCpy(&buf.ullSequence, &pbBuffer[NODEHEADER_OFFSET_SEQ], sizeof(buf.ullSequence));
-
- #ifdef REDCONF_ENDIAN_SWAP
- buf.ulCRC = RedRev32(buf.ulCRC);
- buf.ulSignature = RedRev32(buf.ulSignature);
- buf.ullSequence = RedRev64(buf.ullSequence);
- #endif
-
- /* Make sure the signature is correct for the type of metadata block
- requested by the caller.
- */
- switch(buf.ulSignature)
- {
- case META_SIG_MASTER:
- fValid = (uMetaFlags == BFLAG_META_MASTER);
- break;
- #if REDCONF_IMAP_EXTERNAL == 1
- case META_SIG_IMAP:
- fValid = (uMetaFlags == BFLAG_META_IMAP);
- break;
- #endif
- case META_SIG_INODE:
- fValid = (uMetaFlags == BFLAG_META_INODE);
- break;
- #if DINDIR_POINTERS > 0U
- case META_SIG_DINDIR:
- fValid = (uMetaFlags == BFLAG_META_DINDIR);
- break;
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- case META_SIG_INDIR:
- fValid = (uMetaFlags == BFLAG_META_INDIR);
- break;
- #endif
- default:
- fValid = false;
- break;
- }
-
- if(fValid)
- {
- uint32_t ulComputedCrc;
-
- /* Check for disk corruption by comparing the stored CRC with one
- computed from the data.
-
- Also check the sequence number: if it is greater than the
- current sequence number, the block is from a previous format
- or the disk is writing blocks out of order. During mount,
- before the metaroots have been read, the sequence number will
- be unknown, and the check is skipped.
- */
- ulComputedCrc = RedCrcNode(pbBuffer);
- if(buf.ulCRC != ulComputedCrc)
- {
- fValid = false;
- }
- else if(gpRedVolume->fMounted && (buf.ullSequence >= gpRedVolume->ullSequence))
- {
- fValid = false;
- }
- else
- {
- /* Buffer is valid. No action, fValid is already true.
- */
- }
- }
- }
-
- return fValid;
-}
-
-
-/** @brief Derive the index of the buffer.
-
- @param pBuffer The buffer to derive the index of.
- @param pbIdx On success, populated with the index of the buffer.
-
- @return Boolean indicating result.
-
- @retval true Success.
- @retval false Failure. @p pBuffer is not a valid buffer pointer.
-*/
-static bool BufferToIdx(
- const void *pBuffer,
- uint8_t *pbIdx)
-{
- bool fRet = false;
-
- if((pBuffer != NULL) && (pbIdx != NULL))
- {
- uint8_t bIdx;
-
- /* pBuffer should be a pointer to one of the block buffers.
-
- A good compiler should optimize this loop into a bounds check and an
- alignment check, although GCC has been observed to not do so; if the
- number of buffers is small, it should not make much difference. The
- alternative is to use pointer comparisons, but this both deviates
- from MISRA-C:2012 and involves undefined behavior.
- */
- for(bIdx = 0U; bIdx < REDCONF_BUFFER_COUNT; bIdx++)
- {
- if(pBuffer == &gBufCtx.b.aabBuffer[bIdx][0U])
- {
- break;
- }
- }
-
- if( (bIdx < REDCONF_BUFFER_COUNT)
- && (gBufCtx.aHead[bIdx].ulBlock != BBLK_INVALID)
- && (gBufCtx.aHead[bIdx].bVolNum == gbRedVolNum))
- {
- *pbIdx = bIdx;
- fRet = true;
- }
- }
-
- return fRet;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write out a dirty buffer.
-
- @param bIdx The index of the buffer to write.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS BufferWrite(
- uint8_t bIdx)
-{
- REDSTATUS ret = 0;
-
- if(bIdx < REDCONF_BUFFER_COUNT)
- {
- const BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- REDASSERT((pHead->uFlags & BFLAG_DIRTY) != 0U);
-
- if((pHead->uFlags & BFLAG_META) != 0U)
- {
- ret = BufferFinalize(gBufCtx.b.aabBuffer[bIdx], pHead->uFlags);
- }
-
- if(ret == 0)
- {
- ret = RedIoWrite(pHead->bVolNum, pHead->ulBlock, 1U, gBufCtx.b.aabBuffer[bIdx]);
-
- #ifdef REDCONF_ENDIAN_SWAP
- BufferEndianSwap(gBufCtx.b.aabBuffer[bIdx], pHead->uFlags);
- #endif
- }
- }
- else
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
-
- return ret;
-}
-
-
-/** @brief Finalize a metadata buffer.
-
- This updates the CRC and the sequence number. It also sets the signature,
- though this is only truly needed if the buffer is new.
-
- @param pbBuffer Pointer to the metadata buffer to finalize.
- @param uFlags The associated buffer flags. Used to determine the expected
- signature.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL Invalid parameter; or maximum sequence number reached.
-*/
-static REDSTATUS BufferFinalize(
- uint8_t *pbBuffer,
- uint16_t uFlags)
-{
- REDSTATUS ret = 0;
-
- if((pbBuffer == NULL) || ((uFlags & BFLAG_MASK) != uFlags))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulSignature;
-
- switch(uFlags & BFLAG_META_MASK)
- {
- case BFLAG_META_MASTER:
- ulSignature = META_SIG_MASTER;
- break;
- #if REDCONF_IMAP_EXTERNAL == 1
- case BFLAG_META_IMAP:
- ulSignature = META_SIG_IMAP;
- break;
- #endif
- case BFLAG_META_INODE:
- ulSignature = META_SIG_INODE;
- break;
- #if DINDIR_POINTERS > 0U
- case BFLAG_META_DINDIR:
- ulSignature = META_SIG_DINDIR;
- break;
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- case BFLAG_META_INDIR:
- ulSignature = META_SIG_INDIR;
- break;
- #endif
- default:
- ulSignature = 0U;
- break;
- }
-
- if(ulSignature == 0U)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint64_t ullSeqNum = gpRedVolume->ullSequence;
-
- ret = RedVolSeqNumIncrement();
- if(ret == 0)
- {
- uint32_t ulCrc;
-
- RedMemCpy(&pbBuffer[NODEHEADER_OFFSET_SIG], &ulSignature, sizeof(ulSignature));
- RedMemCpy(&pbBuffer[NODEHEADER_OFFSET_SEQ], &ullSeqNum, sizeof(ullSeqNum));
-
- #ifdef REDCONF_ENDIAN_SWAP
- BufferEndianSwap(pbBuffer, uFlags);
- #endif
-
- ulCrc = RedCrcNode(pbBuffer);
- #ifdef REDCONF_ENDIAN_SWAP
- ulCrc = RedRev32(ulCrc);
- #endif
- RedMemCpy(&pbBuffer[NODEHEADER_OFFSET_CRC], &ulCrc, sizeof(ulCrc));
- }
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#ifdef REDCONF_ENDIAN_SWAP
-/** @brief Swap the byte order of a metadata buffer
-
- Does nothing if the buffer is not a metadata node. Also does nothing for
- meta roots, which don't go through the buffers anyways.
-
- @param pBuffer Pointer to the metadata buffer to swap
- @param uFlags The associated buffer flags. Used to determin the type of
- metadata node.
-*/
-static void BufferEndianSwap(
- void *pBuffer,
- uint16_t uFlags)
-{
- if((pBuffer == NULL) || ((uFlags & BFLAG_MASK) != uFlags))
- {
- REDERROR();
- }
- else if((uFlags & BFLAG_META_MASK) != 0)
- {
- BufferEndianSwapHeader(pBuffer);
-
- switch(uFlags & BFLAG_META_MASK)
- {
- case BFLAG_META_MASTER:
- BufferEndianSwapMaster(pBuffer);
- break;
- case BFLAG_META_INODE:
- BufferEndianSwapInode(pBuffer);
- break;
- #if DINDIR_POINTERS > 0U
- case BFLAG_META_DINDIR:
- BufferEndianSwapIndir(pBuffer);
- break;
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- case BFLAG_META_INDIR:
- BufferEndianSwapIndir(pBuffer);
- break;
- #endif
- default:
- break;
- }
- }
- else
- {
- /* File data buffers do not need to be swapped.
- */
- }
-}
-
-
-/** @brief Swap the byte order of a metadata node header
-
- @param pHeader Pointer to the metadata node header to swap
-*/
-static void BufferEndianSwapHeader(
- NODEHEADER *pHeader)
-{
- if(pHeader == NULL)
- {
- REDERROR();
- }
- else
- {
- pHeader->ulSignature = RedRev32(pHeader->ulSignature);
- pHeader->ulCRC = RedRev32(pHeader->ulCRC);
- pHeader->ullSequence = RedRev64(pHeader->ullSequence);
- }
-}
-
-
-/** @brief Swap the byte order of a master block
-
- @param pMaster Pointer to the master block to swap
-*/
-static void BufferEndianSwapMaster(
- MASTERBLOCK *pMaster)
-{
- if(pMaster == NULL)
- {
- REDERROR();
- }
- else
- {
- pMaster->ulVersion = RedRev32(pMaster->ulVersion);
- pMaster->ulFormatTime = RedRev32(pMaster->ulFormatTime);
- pMaster->ulInodeCount = RedRev32(pMaster->ulInodeCount);
- pMaster->ulBlockCount = RedRev32(pMaster->ulBlockCount);
- pMaster->uMaxNameLen = RedRev16(pMaster->uMaxNameLen);
- pMaster->uDirectPointers = RedRev16(pMaster->uDirectPointers);
- pMaster->uIndirectPointers = RedRev16(pMaster->uIndirectPointers);
- }
-}
-
-
-/** @brief Swap the byte order of an inode
-
- @param pInode Pointer to the inode to swap
-*/
-static void BufferEndianSwapInode(
- INODE *pInode)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else
- {
- uint32_t ulIdx;
-
- pInode->ullSize = RedRev64(pInode->ullSize);
-
- #if REDCONF_INODE_BLOCKS == 1
- pInode->ulBlocks = RedRev32(pInode->ulBlocks);
- #endif
-
- #if REDCONF_INODE_TIMESTAMPS == 1
- pInode->ulATime = RedRev32(pInode->ulATime);
- pInode->ulMTime = RedRev32(pInode->ulMTime);
- pInode->ulCTime = RedRev32(pInode->ulCTime);
- #endif
-
- pInode->uMode = RedRev16(pInode->uMode);
-
- #if (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
- pInode->uNLink = RedRev16(pInode->uNLink);
- #endif
-
- #if REDCONF_API_POSIX == 1
- pInode->ulPInode = RedRev32(pInode->ulPInode);
- #endif
-
- for(ulIdx = 0; ulIdx < INODE_ENTRIES; ulIdx++)
- {
- pInode->aulEntries[ulIdx] = RedRev32(pInode->aulEntries[ulIdx]);
- }
- }
-}
-
-
-#if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
-/** @brief Swap the byte order of an indirect or double indirect node
-
- @param pIndir Pointer to the node to swap
-*/
-static void BufferEndianSwapIndir(
- INDIR *pIndir)
-{
- if(pIndir == NULL)
- {
- REDERROR();
- }
- else
- {
- uint32_t ulIdx;
-
- pIndir->ulInode = RedRev32(pIndir->ulInode);
-
- for(ulIdx = 0; ulIdx < INDIR_ENTRIES; ulIdx++)
- {
- pIndir->aulEntries[ulIdx] = RedRev32(pIndir->aulEntries[ulIdx]);
- }
- }
-}
-
-#endif /* REDCONF_DIRECT_POINTERS < INODE_ENTRIES */
-#endif /* #ifdef REDCONF_ENDIAN_SWAP */
-
-
-/** @brief Mark a buffer as least recently used.
-
- @param bIdx The index of the buffer to make LRU.
-*/
-static void BufferMakeLRU(
- uint8_t bIdx)
-{
- if(bIdx >= REDCONF_BUFFER_COUNT)
- {
- REDERROR();
- }
- else if(bIdx != gBufCtx.abMRU[REDCONF_BUFFER_COUNT - 1U])
- {
- uint8_t bMruIdx;
-
- /* Find the current position of the buffer in the MRU array. We do not
- need to check the last slot, since we already know from the above
- check that the index is not there.
- */
- for(bMruIdx = 0U; bMruIdx < (REDCONF_BUFFER_COUNT - 1U); bMruIdx++)
- {
- if(bIdx == gBufCtx.abMRU[bMruIdx])
- {
- break;
- }
- }
-
- if(bMruIdx < (REDCONF_BUFFER_COUNT - 1U))
- {
- /* Move the buffer index to the back of the MRU array, making it
- the LRU buffer.
- */
- RedMemMove(&gBufCtx.abMRU[bMruIdx], &gBufCtx.abMRU[bMruIdx + 1U], REDCONF_BUFFER_COUNT - ((uint32_t)bMruIdx + 1U));
- gBufCtx.abMRU[REDCONF_BUFFER_COUNT - 1U] = bIdx;
- }
- else
- {
- REDERROR();
- }
- }
- else
- {
- /* Buffer already LRU, nothing to do.
- */
- }
-}
-
-
-/** @brief Mark a buffer as most recently used.
-
- @param bIdx The index of the buffer to make MRU.
-*/
-static void BufferMakeMRU(
- uint8_t bIdx)
-{
- if(bIdx >= REDCONF_BUFFER_COUNT)
- {
- REDERROR();
- }
- else if(bIdx != gBufCtx.abMRU[0U])
- {
- uint8_t bMruIdx;
-
- /* Find the current position of the buffer in the MRU array. We do not
- need to check the first slot, since we already know from the above
- check that the index is not there.
- */
- for(bMruIdx = 1U; bMruIdx < REDCONF_BUFFER_COUNT; bMruIdx++)
- {
- if(bIdx == gBufCtx.abMRU[bMruIdx])
- {
- break;
- }
- }
-
- if(bMruIdx < REDCONF_BUFFER_COUNT)
- {
- /* Move the buffer index to the front of the MRU array, making it
- the MRU buffer.
- */
- RedMemMove(&gBufCtx.abMRU[1U], &gBufCtx.abMRU[0U], bMruIdx);
- gBufCtx.abMRU[0U] = bIdx;
- }
- else
- {
- REDERROR();
- }
- }
- else
- {
- /* Buffer already MRU, nothing to do.
- */
- }
-}
-
-
-/** @brief Find a block in the buffers.
-
- @param ulBlock The block number to find.
- @param pbIdx If the block is buffered (true is returned), populated with
- the index of the buffer.
-
- @return Boolean indicating whether or not the block is buffered.
-
- @retval true @p ulBlock is buffered, and its index has been stored in
- @p pbIdx.
- @retval false @p ulBlock is not buffered.
-*/
-static bool BufferFind(
- uint32_t ulBlock,
- uint8_t *pbIdx)
-{
- bool ret = false;
-
- if((ulBlock >= gpRedVolume->ulBlockCount) || (pbIdx == NULL))
- {
- REDERROR();
- }
- else
- {
- uint8_t bIdx;
-
- for(bIdx = 0U; bIdx < REDCONF_BUFFER_COUNT; bIdx++)
- {
- const BUFFERHEAD *pHead = &gBufCtx.aHead[bIdx];
-
- if((pHead->bVolNum == gbRedVolNum) && (pHead->ulBlock == ulBlock))
- {
- *pbIdx = bIdx;
- ret = true;
- break;
- }
- }
- }
-
- return ret;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/core.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/core.c
deleted file mode 100755
index 4e61ba3..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/core.c
+++ /dev/null
@@ -1,1921 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements the entry-points to the core file system.
-*/
-#include
-#include
-#include
-
-
-/* Minimum number of blocks needed for metadata on any volume: the master
- block (1), the two metaroots (2), and one doubly-allocated inode (2),
- resulting in 1 + 2 + 2 = 5.
-*/
-#define MINIMUM_METADATA_BLOCKS (5U)
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-static REDSTATUS CoreCreate(uint32_t ulPInode, const char *pszName, bool fDir, uint32_t *pulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
-static REDSTATUS CoreLink(uint32_t ulPInode, const char *pszName, uint32_t ulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
-static REDSTATUS CoreUnlink(uint32_t ulPInode, const char *pszName);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_RENAME == 1)
-static REDSTATUS CoreRename(uint32_t ulSrcPInode, const char *pszSrcName, uint32_t ulDstPInode, const char *pszDstName);
-#endif
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS CoreFileWrite(uint32_t ulInode, uint64_t ullStart, uint32_t *pulLen, const void *pBuffer);
-#endif
-#if TRUNCATE_SUPPORTED
-static REDSTATUS CoreFileTruncate(uint32_t ulInode, uint64_t ullSize);
-#endif
-
-
-VOLUME gaRedVolume[REDCONF_VOLUME_COUNT];
-static COREVOLUME gaCoreVol[REDCONF_VOLUME_COUNT];
-
-const VOLCONF * CONST_IF_ONE_VOLUME gpRedVolConf = &gaRedVolConf[0U];
-VOLUME * CONST_IF_ONE_VOLUME gpRedVolume = &gaRedVolume[0U];
-COREVOLUME * CONST_IF_ONE_VOLUME gpRedCoreVol = &gaCoreVol[0U];
-METAROOT *gpRedMR = &gaCoreVol[0U].aMR[0U];
-
-CONST_IF_ONE_VOLUME uint8_t gbRedVolNum = 0;
-
-
-/** @brief Initialize the Reliance Edge file system driver.
-
- Prepares the Reliance Edge file system driver to be used. Must be the first
- Reliance Edge function to be invoked: no volumes can be mounted until the
- driver has been initialized.
-
- If this function is called when the Reliance Edge driver is already
- initialized, the behavior is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedCoreInit(void)
-{
- REDSTATUS ret = 0;
- uint8_t bVolNum;
- #if REDCONF_OUTPUT == 1
- static uint8_t bSignedOn = 0U; /* Whether the sign on has been printed. */
-
- if(bSignedOn == 0U)
- {
- RedSignOn();
- bSignedOn = 1U;
- }
- #else
- /* Call RedSignOn() even when output is disabled, to force the copyright
- text to be referenced and pulled into the program data.
- */
- RedSignOn();
- #endif
-
- RedMemSet(gaRedVolume, 0U, sizeof(gaRedVolume));
- RedMemSet(gaCoreVol, 0U, sizeof(gaCoreVol));
-
- RedBufferInit();
-
- for(bVolNum = 0U; bVolNum < REDCONF_VOLUME_COUNT; bVolNum++)
- {
- VOLUME *pVol = &gaRedVolume[bVolNum];
- COREVOLUME *pCoreVol = &gaCoreVol[bVolNum];
- const VOLCONF *pVolConf = &gaRedVolConf[bVolNum];
-
- if( (pVolConf->ulSectorSize < SECTOR_SIZE_MIN)
- || ((REDCONF_BLOCK_SIZE % pVolConf->ulSectorSize) != 0U)
- || (pVolConf->ulInodeCount == 0U))
- {
- ret = -RED_EINVAL;
- }
- #if REDCONF_API_POSIX == 1
- else if(pVolConf->pszPathPrefix == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- #if REDCONF_VOLUME_COUNT > 1U
- uint8_t bCmpVol;
-
- /* Ensure there are no duplicate path prefixes. Check against all
- previous volumes, which are already verified.
- */
- for(bCmpVol = 0U; bCmpVol < bVolNum; bCmpVol++)
- {
- const char *pszCmpPathPrefix = gaRedVolConf[bCmpVol].pszPathPrefix;
-
- if(RedStrCmp(pVolConf->pszPathPrefix, pszCmpPathPrefix) == 0)
- {
- ret = -RED_EINVAL;
- break;
- }
- }
- #endif
- }
- #endif
-
- if(ret == 0)
- {
- pVol->bBlockSectorShift = 0U;
- while((pVolConf->ulSectorSize << pVol->bBlockSectorShift) < REDCONF_BLOCK_SIZE)
- {
- pVol->bBlockSectorShift++;
- }
-
- /* This should always be true since the block size is confirmed to
- be a power of two (checked at compile time) and above we ensured
- that (REDCONF_BLOCK_SIZE % pVolConf->ulSectorSize) == 0.
- */
- REDASSERT((pVolConf->ulSectorSize << pVol->bBlockSectorShift) == REDCONF_BLOCK_SIZE);
-
- pVol->ulBlockCount = (uint32_t)(pVolConf->ullSectorCount >> pVol->bBlockSectorShift);
-
- if(pVol->ulBlockCount < MINIMUM_METADATA_BLOCKS)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- #if REDCONF_READ_ONLY == 0
- pVol->ulTransMask = REDCONF_TRANSACT_DEFAULT;
- #endif
-
- pVol->ullMaxInodeSize = INODE_SIZE_MAX;
-
- /* To understand the following code, note that the fixed-
- location metadata is located at the start of the disk, in
- the following order:
-
- - Master block (1 block)
- - Metaroots (2 blocks)
- - External imap blocks (variable * 2 blocks)
- - Inode blocks (pVolConf->ulInodeCount * 2 blocks)
- */
-
- /* The imap needs bits for all inode and allocable blocks. If
- that bitmap will fit into the metaroot, the inline imap is
- used and there are no imap nodes on disk. The minus 3 is
- there since the imap does not include bits for the master
- block or metaroots.
- */
- pCoreVol->fImapInline = (pVol->ulBlockCount - 3U) <= METAROOT_ENTRIES;
-
- if(pCoreVol->fImapInline)
- {
- #if REDCONF_IMAP_INLINE == 1
- pCoreVol->ulInodeTableStartBN = 3U;
- #else
- ret = -RED_EINVAL;
- #endif
- }
- else
- {
- #if REDCONF_IMAP_EXTERNAL == 1
- pCoreVol->ulImapStartBN = 3U;
-
- /* The imap does not include bits for itself, so add two to
- the number of imap entries for the two blocks of each
- imap node. This allows us to divide up the remaining
- space, making sure to round up so all data blocks are
- covered.
- */
- pCoreVol->ulImapNodeCount =
- ((pVol->ulBlockCount - 3U) + ((IMAPNODE_ENTRIES + 2U) - 1U)) / (IMAPNODE_ENTRIES + 2U);
-
- pCoreVol->ulInodeTableStartBN = pCoreVol->ulImapStartBN + (pCoreVol->ulImapNodeCount * 2U);
- #else
- ret = -RED_EINVAL;
- #endif
- }
- }
- }
-
- if(ret == 0)
- {
- pCoreVol->ulFirstAllocableBN = pCoreVol->ulInodeTableStartBN + (pVolConf->ulInodeCount * 2U);
-
- if(pCoreVol->ulFirstAllocableBN > pVol->ulBlockCount)
- {
- /* We can get here if there is not enough space for the number
- of configured inodes.
- */
- ret = -RED_EINVAL;
- }
- else
- {
- pVol->ulBlocksAllocable = pVol->ulBlockCount - pCoreVol->ulFirstAllocableBN;
- }
- }
-
- if(ret != 0)
- {
- break;
- }
- }
-
- /* Make sure the configured endianness is correct.
- */
- if(ret == 0)
- {
- uint16_t uValue = 0xFF00U;
- uint8_t abBytes[2U];
-
- RedMemCpy(abBytes, &uValue, sizeof(abBytes));
-
- #if REDCONF_ENDIAN_BIG == 1
- if(abBytes[0U] != 0xFFU)
- #else
- if(abBytes[0U] != 0x00U)
- #endif
- {
- ret = -RED_EINVAL;
- }
- }
-
- if(ret == 0)
- {
- ret = RedOsClockInit();
-
- #if REDCONF_TASK_COUNT > 1U
- if(ret == 0)
- {
- ret = RedOsMutexInit();
-
- if(ret != 0)
- {
- (void)RedOsClockUninit();
- }
- }
- #endif
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize the Reliance Edge file system driver.
-
- Tears down the Reliance Edge file system driver. Cannot be used until all
- Reliance Edge volumes are unmounted. A subsequent call to RedCoreInit()
- will initialize the driver again.
-
- The behavior of calling this function when the core is already uninitialized
- is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBUSY At least one volume is still mounted.
-*/
-REDSTATUS RedCoreUninit(void)
-{
- REDSTATUS ret;
-
- #if REDCONF_TASK_COUNT > 1U
- ret = RedOsMutexUninit();
-
- if(ret == 0)
- #endif
- {
- ret = RedOsClockUninit();
- }
-
- return ret;
-}
-
-
-/** @brief Set the current volume.
-
- All core APIs operate on the current volume. This call must precede all
- core accesses.
-
- @param bVolNum The volume number to access.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number.
-*/
-REDSTATUS RedCoreVolSetCurrent(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(bVolNum >= REDCONF_VOLUME_COUNT)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- #if REDCONF_VOLUME_COUNT > 1U
- gbRedVolNum = bVolNum;
- gpRedVolConf = &gaRedVolConf[bVolNum];
- gpRedVolume = &gaRedVolume[bVolNum];
- gpRedCoreVol = &gaCoreVol[bVolNum];
- gpRedMR = &gpRedCoreVol->aMR[gpRedCoreVol->bCurMR];
- #endif
-
- ret = 0;
- }
-
- return ret;
-}
-
-
-#if FORMAT_SUPPORTED
-/** @brief Format a file system volume.
-
- Uses the statically defined volume configuration. After calling this
- function, the volume needs to be mounted -- see RedCoreVolMount().
-
- An error is returned if the volume is mounted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBUSY Volume is mounted.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedCoreVolFormat(void)
-{
- return RedVolFormat();
-}
-#endif /* FORMAT_SUPPORTED */
-
-
-/** @brief Mount a file system volume.
-
- Prepares the file system volume to be accessed. Mount will fail if the
- volume has never been formatted, or if the on-disk format is inconsistent
- with the compile-time configuration.
-
- If the volume is already mounted, the behavior is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO Volume not formatted, improperly formatted, or corrupt.
-*/
-REDSTATUS RedCoreVolMount(void)
-{
- return RedVolMount();
-}
-
-
-/** @brief Unmount a file system volume.
-
- This function discards the in-memory state for the file system and marks it
- as unmounted. Subsequent attempts to access the volume will fail until the
- volume is mounted again.
-
- If unmount automatic transaction points are enabled, this function will
- commit a transaction point prior to unmounting. If unmount automatic
- transaction points are disabled, this function will unmount without
- transacting, effectively discarding the working state.
-
- If the volume is already unmounted, the behavior is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO I/O error during unmount automatic transaction point.
-*/
-REDSTATUS RedCoreVolUnmount(void)
-{
- REDSTATUS ret = 0;
-
- #if REDCONF_READ_ONLY == 0
- if(!gpRedVolume->fReadOnly && ((gpRedVolume->ulTransMask & RED_TRANSACT_UMOUNT) != 0U))
- {
- ret = RedVolTransact();
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedBufferDiscardRange(0U, gpRedVolume->ulBlockCount);
- }
-
- if(ret == 0)
- {
- ret = RedOsBDevClose(gbRedVolNum);
- }
-
- if(ret == 0)
- {
- gpRedVolume->fMounted = false;
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Commit a transaction point.
-
- Reliance Edge is a transactional file system. All modifications, of both
- metadata and filedata, are initially working state. A transaction point
- is a process whereby the working state atomically becomes the committed
- state, replacing the previous committed state. Whenever Reliance Edge is
- mounted, including after power loss, the state of the file system after
- mount is the most recent committed state. Nothing from the committed
- state is ever missing, and nothing from the working state is ever included.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The volume is not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedCoreVolTransact(void)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = RedVolTransact();
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#if REDCONF_API_POSIX == 1
-/** @brief Query file system status information.
-
- @param pStatFS The buffer to populate with volume information.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval -RED_EINVAL Volume is not mounted; or @p pStatFS is `NULL`.
-*/
-REDSTATUS RedCoreVolStat(
- REDSTATFS *pStatFS)
-{
- REDSTATUS ret;
-
- if((pStatFS == NULL) || (!gpRedVolume->fMounted))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- RedMemSet(pStatFS, 0U, sizeof(*pStatFS));
-
- pStatFS->f_bsize = REDCONF_BLOCK_SIZE;
- pStatFS->f_frsize = REDCONF_BLOCK_SIZE;
- pStatFS->f_blocks = gpRedVolume->ulBlockCount;
- #if RESERVED_BLOCKS > 0U
- pStatFS->f_bfree = (gpRedMR->ulFreeBlocks > RESERVED_BLOCKS) ? (gpRedMR->ulFreeBlocks - RESERVED_BLOCKS) : 0U;
- #else
- pStatFS->f_bfree = gpRedMR->ulFreeBlocks;
- #endif
- pStatFS->f_bavail = pStatFS->f_bfree;
- pStatFS->f_files = gpRedVolConf->ulInodeCount;
- pStatFS->f_ffree = gpRedMR->ulFreeInodes;
- pStatFS->f_favail = gpRedMR->ulFreeInodes;
-
- pStatFS->f_flag = RED_ST_NOSUID;
- #if REDCONF_READ_ONLY == 0
- if(gpRedVolume->fReadOnly)
- #endif
- {
- pStatFS->f_flag |= RED_ST_RDONLY;
- }
-
- pStatFS->f_namemax = REDCONF_NAME_MAX;
- pStatFS->f_maxfsize = INODE_SIZE_MAX;
- pStatFS->f_dev = gbRedVolNum;
-
- ret = 0;
- }
-
- return ret;
-}
-#endif /* REDCONF_API_POSIX == 1 */
-
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || (REDCONF_API_FSE_TRANSMASKSET == 1))
-/** @brief Update the transaction mask.
-
- The following events are available when using the FSE API:
-
- - #RED_TRANSACT_UMOUNT
- - #RED_TRANSACT_WRITE
- - #RED_TRANSACT_TRUNCATE
- - #RED_TRANSACT_VOLFULL
-
- The following events are available when using the POSIX-like API:
-
- - #RED_TRANSACT_UMOUNT
- - #RED_TRANSACT_CREAT
- - #RED_TRANSACT_UNLINK
- - #RED_TRANSACT_MKDIR
- - #RED_TRANSACT_RENAME
- - #RED_TRANSACT_LINK
- - #RED_TRANSACT_CLOSE
- - #RED_TRANSACT_WRITE
- - #RED_TRANSACT_FSYNC
- - #RED_TRANSACT_TRUNCATE
- - #RED_TRANSACT_VOLFULL
-
- The #RED_TRANSACT_MANUAL macro (by itself) may be used to disable all
- automatic transaction events. The #RED_TRANSACT_MASK macro is a bitmask of
- all transaction flags, excluding those representing excluded functionality.
-
- Attempting to enable events for excluded functionality will result in an
- error.
-
- @param ulEventMask A bitwise-OR'd mask of automatic transaction events to
- be set as the current transaction mode.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The volume is not mounted; or @p ulEventMask contains
- invalid bits.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedCoreTransMaskSet(
- uint32_t ulEventMask)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted || ((ulEventMask & RED_TRANSACT_MASK) != ulEventMask))
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- gpRedVolume->ulTransMask = ulEventMask;
- ret = 0;
- }
-
- return ret;
-}
-#endif
-
-
-#if (REDCONF_API_POSIX == 1) || (REDCONF_API_FSE_TRANSMASKGET == 1)
-/** @brief Read the transaction mask.
-
- If the volume is read-only, the returned event mask is always zero.
-
- @param pulEventMask Populated with a bitwise-OR'd mask of automatic
- transaction events which represent the current
- transaction mode for the volume.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The volume is not mounted; or @p pulEventMask is `NULL`.
-*/
-REDSTATUS RedCoreTransMaskGet(
- uint32_t *pulEventMask)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted || (pulEventMask == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- #if REDCONF_READ_ONLY == 1
- *pulEventMask = 0U;
- #else
- *pulEventMask = gpRedVolume->ulTransMask;
- #endif
- ret = 0;
- }
-
- return ret;
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-/** @brief Create a file or directory.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName A null-terminated name for the new inode.
- @param fDir Whether to create a directory (true) or file (false).
- @param pulInode On successful return, populated with the inode number of the
- new file or directory.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The volume is not mounted; or @p pszName is not
- a valid name; or @p pulInode is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EROFS The file system volume is read-only.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_EBADF @p ulPInode is not a valid inode.
- @retval -RED_ENOSPC There is not enough space on the volume to
- createthe new directory entry; or the directory
- is full.
- @retval -RED_ENFILE No available inode slots.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_EEXIST @p pszName already exists in @p ulPInode.
-*/
-REDSTATUS RedCoreCreate(
- uint32_t ulPInode,
- const char *pszName,
- bool fDir,
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreCreate(ulPInode, pszName, fDir, pulInode);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreCreate(ulPInode, pszName, fDir, pulInode);
- }
- }
-
- if(ret == 0)
- {
- if(fDir && ((gpRedVolume->ulTransMask & RED_TRANSACT_MKDIR) != 0U))
- {
- ret = RedVolTransact();
- }
- else if(!fDir && ((gpRedVolume->ulTransMask & RED_TRANSACT_CREAT) != 0U))
- {
- ret = RedVolTransact();
- }
- else
- {
- /* No automatic transaction for this operation.
- */
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Create a file or directory.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName A null-terminated name for the new inode.
- @param fDir Whether to create a directory (true) or file (false).
- @param pulInode On successful return, populated with the inode number of the
- new file or directory.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EROFS The file system volume is read-only.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_EBADF @p ulPInode is not a valid inode.
- @retval -RED_ENOSPC There is not enough space on the volume to
- create the new directory entry; or the directory
- is full.
- @retval -RED_ENFILE No available inode slots.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_EEXIST @p pszName already exists in @p ulPInode.
-*/
-static REDSTATUS CoreCreate(
- uint32_t ulPInode,
- const char *pszName,
- bool fDir,
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if(pulInode == NULL)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- CINODE pino;
-
- pino.ulInode = ulPInode;
- ret = RedInodeMount(&pino, FTYPE_DIR, false);
-
- if(ret == 0)
- {
- CINODE ino;
-
- ino.ulInode = INODE_INVALID;
- ret = RedInodeCreate(&ino, ulPInode, fDir ? RED_S_IFDIR : RED_S_IFREG);
-
- if(ret == 0)
- {
- ret = RedInodeBranch(&pino);
-
- if(ret == 0)
- {
- ret = RedDirEntryCreate(&pino, pszName, ino.ulInode);
- }
-
- if(ret == 0)
- {
- *pulInode = ino.ulInode;
- }
- else
- {
- REDSTATUS ret2;
-
- ret2 = RedInodeFree(&ino);
- CRITICAL_ASSERT(ret2 == 0);
- }
-
- RedInodePut(&ino, 0U);
- }
-
- RedInodePut(&pino, (ret == 0) ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) */
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
-/** @brief Create a hard link.
-
- This creates an additional name (link) for @p ulInode. The new name refers
- to the same file with the same contents. If a name is deleted, but the
- underlying file has other names, the file continues to exist. The link
- count (accessible via RedCoreStat()) indicates the number of names that a
- file has. All of a file's names are on equal footing: there is nothing
- special about the original name.
-
- If @p ulInode names a directory, the operation will fail.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName The null-terminated name for the new link.
- @param ulInode The inode to create a hard link to.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulPInode is not a valid inode; or @p ulInode
- is not a valid inode.
- @retval -RED_EEXIST @p pszName resolves to an existing file.
- @retval -RED_EINVAL The volume is not mounted; or @p pszName is
- `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EMLINK Creating the link would exceed the maximum link
- count of @p ulInode.
- @retval -RED_ENAMETOOLONG Attempting to create a link with a name that
- exceeds the maximum name length.
- @retval -RED_ENOSPC There is insufficient free space to expand the
- directory that would contain the link.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_EPERM @p ulInode is a directory.
- @retval -RED_EROFS The requested link requires writing in a
- directory on a read-only file system.
-*/
-REDSTATUS RedCoreLink(
- uint32_t ulPInode,
- const char *pszName,
- uint32_t ulInode)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreLink(ulPInode, pszName, ulInode);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreLink(ulPInode, pszName, ulInode);
- }
- }
-
- if((ret == 0) && ((gpRedVolume->ulTransMask & RED_TRANSACT_LINK) != 0U))
- {
- ret = RedVolTransact();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Create a hard link.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName The null-terminated name for the new link.
- @param ulInode The inode to create a hard link to.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulPInode is not a valid inode; or @p ulInode
- is not a valid inode.
- @retval -RED_EEXIST @p pszName resolves to an existing file.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EMLINK Creating the link would exceed the maximum link
- count of @p ulInode.
- @retval -RED_ENAMETOOLONG Attempting to create a link with a name that
- exceeds the maximum name length.
- @retval -RED_ENOSPC There is insufficient free space to expand the
- directory that would contain the link.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_EPERM @p ulInode is a directory.
- @retval -RED_EROFS The requested link requires writing in a
- directory on a read-only file system.
-*/
-static REDSTATUS CoreLink(
- uint32_t ulPInode,
- const char *pszName,
- uint32_t ulInode)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- CINODE pino;
-
- pino.ulInode = ulPInode;
- ret = RedInodeMount(&pino, FTYPE_DIR, false);
-
- if(ret == 0)
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_FILE, false);
-
- /* POSIX specifies EPERM as the errno thrown when link() is given a
- directory. Switch the errno returned if EISDIR was the return
- value.
- */
- if(ret == -RED_EISDIR)
- {
- ret = -RED_EPERM;
- }
-
- if(ret == 0)
- {
- if(ino.pInodeBuf->uNLink == UINT16_MAX)
- {
- ret = -RED_EMLINK;
- }
- else
- {
- ret = RedInodeBranch(&pino);
- }
-
- if(ret == 0)
- {
- ret = RedInodeBranch(&ino);
- }
-
- if(ret == 0)
- {
- ret = RedDirEntryCreate(&pino, pszName, ino.ulInode);
- }
-
- if(ret == 0)
- {
- ino.pInodeBuf->uNLink++;
- }
-
- RedInodePut(&ino, (ret == 0) ? IPUT_UPDATE_CTIME : 0U);
- }
-
- RedInodePut(&pino, (ret == 0) ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1) */
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
-/** @brief Delete a file or directory.
-
- The given name is deleted and the link count of the corresponding inode is
- decremented. If the link count falls to zero (no remaining hard links),
- the inode will be deleted.
-
- If the path names a directory which is not empty, the unlink will fail.
-
- If the deletion frees data in the committed state, it will not return to
- free space until after a transaction point. Similarly, if the inode was
- part of the committed state, the inode slot will not be available until
- after a transaction point.
-
- This function can fail when the disk is full. To fix this, transact and
- try again: Reliance Edge guarantees that it is possible to delete at least
- one file or directory after a transaction point. If disk full automatic
- transactions are enabled, this will happen automatically.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName The null-terminated name of the file or directory to
- delete.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulPInode is not a valid inode.
- @retval -RED_EINVAL The volume is not mounted; or @p pszName is
- `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_ENOENT @p pszName does not name an existing file or
- directory.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_ENOSPC The file system does not have enough space to
- modify the parent directory to perform the
- deletion.
- @retval -RED_ENOTEMPTY The inode refered to by @p pszName is a
- directory which is not empty.
-*/
-REDSTATUS RedCoreUnlink(
- uint32_t ulPInode,
- const char *pszName)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreUnlink(ulPInode, pszName);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreUnlink(ulPInode, pszName);
- }
- }
-
- if((ret == 0) && ((gpRedVolume->ulTransMask & RED_TRANSACT_UNLINK) != 0U))
- {
- ret = RedVolTransact();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Delete a file or directory.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName The null-terminated name of the file or directory to
- delete.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulPInode is not a valid inode.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_ENOENT @p pszName does not name an existing file or
- directory.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
- @retval -RED_ENOSPC The file system does not have enough space to
- modify the parent directory to perform the
- deletion.
- @retval -RED_ENOTEMPTY The inode refered to by @p pszName is a
- directory which is not empty.
-*/
-static REDSTATUS CoreUnlink(
- uint32_t ulPInode,
- const char *pszName)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- CINODE pino;
-
- pino.ulInode = ulPInode;
- ret = RedInodeMount(&pino, FTYPE_DIR, false);
-
- if(ret == 0)
- {
- uint32_t ulDeleteIdx;
- uint32_t ulInode;
-
- ret = RedDirEntryLookup(&pino, pszName, &ulDeleteIdx, &ulInode);
-
- if(ret == 0)
- {
- ret = RedInodeBranch(&pino);
- }
-
- if(ret == 0)
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_EITHER, false);
-
- if(ret == 0)
- {
- if(ino.fDirectory && (ino.pInodeBuf->ullSize > 0U))
- {
- ret = -RED_ENOTEMPTY;
- }
- else
- {
- #if RESERVED_BLOCKS > 0U
- gpRedCoreVol->fUseReservedBlocks = true;
- #endif
-
- ret = RedDirEntryDelete(&pino, ulDeleteIdx);
-
- #if RESERVED_BLOCKS > 0U
- gpRedCoreVol->fUseReservedBlocks = false;
- #endif
-
- if(ret == 0)
- {
- /* If the inode is deleted, buffers are needed to
- read all of the indirects and free the data
- blocks. Before doing that, to reduce the
- minimum number of buffers needed to complete the
- unlink, release the parent directory inode
- buffers which are no longer needed.
- */
- RedInodePutCoord(&pino);
-
- ret = RedInodeLinkDec(&ino);
- CRITICAL_ASSERT(ret == 0);
- }
- }
-
- RedInodePut(&ino, (ret == 0) ? IPUT_UPDATE_CTIME : 0U);
- }
- }
-
- RedInodePut(&pino, (ret == 0) ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1)) */
-
-
-#if REDCONF_API_POSIX == 1
-/** @brief Look up the inode number of a file or directory.
-
- @param ulPInode The inode number of the parent directory.
- @param pszName The null-terminated name of the file or directory to look
- up.
- @param pulInode On successful return, populated with the inode number named
- by @p pszName.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulPInode is not a valid inode.
- @retval -RED_EINVAL The volume is not mounted; @p pszName is `NULL`; or
- @p pulInode is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT @p pszName does not name an existing file or directory.
- @retval -RED_ENOTDIR @p ulPInode is not a directory.
-*/
-REDSTATUS RedCoreLookup(
- uint32_t ulPInode,
- const char *pszName,
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if((pulInode == NULL) || !gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulPInode;
- ret = RedInodeMount(&ino, FTYPE_DIR, false);
-
- if(ret == 0)
- {
- ret = RedDirEntryLookup(&ino, pszName, NULL, pulInode);
-
- RedInodePut(&ino, 0U);
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_API_POSIX == 1 */
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_RENAME == 1)
-/** @brief Rename a file or directory.
-
- If @p pszDstName names an existing file or directory, the behavior depends
- on the configuration. If #REDCONF_RENAME_ATOMIC is false, and if the
- destination name exists, this function always fails with -RED_EEXIST.
-
- If #REDCONF_RENAME_ATOMIC is true, and if the new name exists, then in one
- atomic operation, the destination name is unlinked and the source name is
- renamed to the destination name. Both names must be of the same type (both
- files or both directories). As with RedCoreUnlink(), if the destination
- name is a directory, it must be empty. The major exception to this
- behavior is that if both names are links to the same inode, then the rename
- does nothing and both names continue to exist.
-
- If the rename deletes the old destination, it may free data in the
- committed state, which will not return to free space until after a
- transaction point. Similarly, if the deleted inode was part of the
- committed state, the inode slot will not be available until after a
- transaction point.
-
- @param ulSrcPInode The inode number of the parent directory of the file or
- directory to rename.
- @param pszSrcName The name of the file or directory to rename.
- @param ulDstPInode The new parent directory inode number of the file or
- directory after the rename.
- @param pszDstName The new name of the file or directory after the rename.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulSrcPInode is not a valid inode number; or
- @p ulDstPInode is not a valid inode number.
- @retval -RED_EEXIST #REDCONF_RENAME_POSIX is false and the
- destination name exists.
- @retval -RED_EINVAL The volume is not mounted; @p pszSrcName is
- `NULL`; or @p pszDstName is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The destination name exists and is a directory,
- and the source name is a non-directory.
- @retval -RED_ENAMETOOLONG Either @p pszSrcName or @p pszDstName is longer
- than #REDCONF_NAME_MAX.
- @retval -RED_ENOENT The source name is not an existing entry; or
- either @p pszSrcName or @p pszDstName point to
- an empty string.
- @retval -RED_ENOTDIR @p ulSrcPInode is not a directory; or
- @p ulDstPInode is not a directory; or the source
- name is a directory and the destination name is
- a file.
- @retval -RED_ENOTEMPTY The destination name is a directory which is not
- empty.
- @retval -RED_ENOSPC The file system does not have enough space to
- extend the @p ulDstPInode directory.
- @retval -RED_EROFS The directory to be removed resides on a
- read-only file system.
-*/
-REDSTATUS RedCoreRename(
- uint32_t ulSrcPInode,
- const char *pszSrcName,
- uint32_t ulDstPInode,
- const char *pszDstName)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreRename(ulSrcPInode, pszSrcName, ulDstPInode, pszDstName);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreRename(ulSrcPInode, pszSrcName, ulDstPInode, pszDstName);
- }
- }
-
- if((ret == 0) && ((gpRedVolume->ulTransMask & RED_TRANSACT_RENAME) != 0U))
- {
- ret = RedVolTransact();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Rename a file or directory.
-
- @param ulSrcPInode The inode number of the parent directory of the file or
- directory to rename.
- @param pszSrcName The name of the file or directory to rename.
- @param ulDstPInode The new parent directory inode number of the file or
- directory after the rename.
- @param pszDstName The new name of the file or directory after the rename.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulSrcPInode is not a valid inode number; or
- @p ulDstPInode is not a valid inode number.
- @retval -RED_EEXIST #REDCONF_RENAME_POSIX is false and the
- destination name exists.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The destination name exists and is a directory,
- and the source name is a non-directory.
- @retval -RED_ENAMETOOLONG Either @p pszSrcName or @p pszDstName is longer
- than #REDCONF_NAME_MAX.
- @retval -RED_ENOENT The source name is not an existing entry; or
- either @p pszSrcName or @p pszDstName point to
- an empty string.
- @retval -RED_ENOTDIR @p ulSrcPInode is not a directory; or
- @p ulDstPInode is not a directory; or the source
- name is a directory and the destination name is
- a file.
- @retval -RED_ENOTEMPTY The destination name is a directory which is not
- empty.
- @retval -RED_ENOSPC The file system does not have enough space to
- extend the @p ulDstPInode directory.
- @retval -RED_EROFS The directory to be removed resides on a
- read-only file system.
-*/
-static REDSTATUS CoreRename(
- uint32_t ulSrcPInode,
- const char *pszSrcName,
- uint32_t ulDstPInode,
- const char *pszDstName)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- bool fUpdateTimestamps = false;
- CINODE SrcPInode;
-
- SrcPInode.ulInode = ulSrcPInode;
- ret = RedInodeMount(&SrcPInode, FTYPE_DIR, true);
-
- if(ret == 0)
- {
- CINODE DstPInode;
- CINODE *pDstPInode;
-
- if(ulSrcPInode == ulDstPInode)
- {
- pDstPInode = &SrcPInode;
- }
- else
- {
- pDstPInode = &DstPInode;
- DstPInode.ulInode = ulDstPInode;
- ret = RedInodeMount(pDstPInode, FTYPE_DIR, true);
- }
-
- if(ret == 0)
- {
- /* Initialize these to zero so we can unconditionally put them,
- even if RedDirEntryRename() fails before mounting them.
- */
- CINODE SrcInode = {0U};
- CINODE DstInode = {0U};
-
- ret = RedDirEntryRename(&SrcPInode, pszSrcName, &SrcInode, pDstPInode, pszDstName, &DstInode);
-
- #if REDCONF_RENAME_ATOMIC == 1
- if((ret == 0) && (DstInode.ulInode != INODE_INVALID) && (DstInode.ulInode != SrcInode.ulInode))
- {
- /* If the inode is deleted, buffers are needed to read all
- of the indirects and free the data blocks. Before doing
- that, to reduce the minimum number of buffers needed to
- complete the rename, release parent directory inode
- buffers which are no longer needed.
- */
- RedInodePutCoord(&SrcPInode);
- RedInodePutCoord(pDstPInode);
-
- ret = RedInodeLinkDec(&DstInode);
- CRITICAL_ASSERT(ret == 0);
- }
-
- if((ret == 0) && (DstInode.ulInode != SrcInode.ulInode))
- #else
- if(ret == 0)
- #endif
- {
- fUpdateTimestamps = true;
- }
-
- #if REDCONF_RENAME_ATOMIC == 1
- RedInodePut(&DstInode, 0U);
- #endif
-
- /* POSIX says updating ctime for the source inode is optional,
- but searching around it looks like this is common for Linux
- and other Unix file systems.
- */
- RedInodePut(&SrcInode, fUpdateTimestamps ? IPUT_UPDATE_CTIME : 0U);
- RedInodePut(pDstPInode, fUpdateTimestamps ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- RedInodePut(&SrcPInode, fUpdateTimestamps ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_RENAME == 1) */
-
-
-#if REDCONF_API_POSIX == 1
-/** @brief Get the status of a file or directory.
-
- See the ::REDSTAT type for the details of the information returned.
-
- @param ulInode The inode number of the file or directory whose information
- is to be retrieved.
- @param pStat Pointer to a ::REDSTAT buffer to populate.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode.
- @retval -RED_EINVAL The volume is not mounted; @p pStat is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedCoreStat(
- uint32_t ulInode,
- REDSTAT *pStat)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted || (pStat == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_EITHER, false);
- if(ret == 0)
- {
- RedMemSet(pStat, 0U, sizeof(*pStat));
-
- pStat->st_dev = gbRedVolNum;
- pStat->st_ino = ulInode;
- pStat->st_mode = ino.pInodeBuf->uMode;
- #if REDCONF_API_POSIX_LINK == 1
- pStat->st_nlink = ino.pInodeBuf->uNLink;
- #else
- pStat->st_nlink = 1U;
- #endif
- pStat->st_size = ino.pInodeBuf->ullSize;
- #if REDCONF_INODE_TIMESTAMPS == 1
- pStat->st_atime = ino.pInodeBuf->ulATime;
- pStat->st_mtime = ino.pInodeBuf->ulMTime;
- pStat->st_ctime = ino.pInodeBuf->ulCTime;
- #endif
- #if REDCONF_INODE_BLOCKS == 1
- pStat->st_blocks = ino.pInodeBuf->ulBlocks;
- #endif
-
- RedInodePut(&ino, 0U);
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_API_POSIX == 1 */
-
-
-#if REDCONF_API_FSE == 1
-/** @brief Get the size of a file.
-
- @param ulInode The inode number of the file whose size is to be retrieved.
- @param pullSize On successful exit, populated with the file size.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode.
- @retval -RED_EINVAL The volume is not mounted; @p pullSize is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR @p ulInode is a directory inode.
-*/
-REDSTATUS RedCoreFileSizeGet(
- uint32_t ulInode,
- uint64_t *pullSize)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted || (pullSize == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_FILE, false);
- if(ret == 0)
- {
- *pullSize = ino.pInodeBuf->ullSize;
-
- RedInodePut(&ino, 0U);
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_API_FSE == 1 */
-
-
-/** @brief Read from a file.
-
- Data which has not yet been written, but which is before the end-of-file
- (sparse data), shall read as zeroes. A short read -- where the number of
- bytes read is less than requested -- indicates that the requested read was
- partially or, if zero bytes were read, entirely beyond the end-of-file.
-
- If @p ullStart is at or beyond the maximum file size, it is treated like
- any other read entirely beyond the end-of-file: no data is read and
- @p pulLen is populated with zero.
-
- @param ulInode The inode number of the file to read.
- @param ullStart The file offset to read from.
- @param pulLen On entry, contains the number of bytes to read; on
- successful exit, contains the number of bytes actually
- read.
- @param pBuffer The buffer to populate with the data read. Must be big
- enough for the read request.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode number.
- @retval -RED_EINVAL The volume is not mounted; or @p pBuffer is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The inode is a directory inode.
-*/
-REDSTATUS RedCoreFileRead(
- uint32_t ulInode,
- uint64_t ullStart,
- uint32_t *pulLen,
- void *pBuffer)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted || (pulLen == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- #if (REDCONF_ATIME == 1) && (REDCONF_READ_ONLY == 0)
- bool fUpdateAtime = (*pulLen > 0U) && !gpRedVolume->fReadOnly;
- #else
- bool fUpdateAtime = false;
- #endif
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_FILE, fUpdateAtime);
- if(ret == 0)
- {
- ret = RedInodeDataRead(&ino, ullStart, pulLen, pBuffer);
-
- #if (REDCONF_ATIME == 1) && (REDCONF_READ_ONLY == 0)
- RedInodePut(&ino, ((ret == 0) && fUpdateAtime) ? IPUT_UPDATE_ATIME : 0U);
- #else
- RedInodePut(&ino, 0U);
- #endif
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write to a file.
-
- If the write extends beyond the end-of-file, the file size will be
- increased.
-
- A short write -- where the number of bytes written is less than requested
- -- indicates either that the file system ran out of space but was still
- able to write some of the request; or that the request would have caused
- the file to exceed the maximum file size, but some of the data could be
- written prior to the file size limit.
-
- If an error is returned, either none of the data was written or a critical
- error occurred (like an I/O error) and the file system volume will be
- read-only.
-
- @param ulInode The file number of the file to write.
- @param ullStart The file offset to write at.
- @param pulLen On entry, the number of bytes to write; on successful exit,
- the number of bytes actually written.
- @param pBuffer The buffer containing the data to be written. Must big
- enough for the write request.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid file number.
- @retval -RED_EFBIG No data can be written to the given file offset since
- the resulting file size would exceed the maximum file
- size.
- @retval -RED_EINVAL The volume is not mounted; or @p pBuffer is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The inode is a directory inode.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedCoreFileWrite(
- uint32_t ulInode,
- uint64_t ullStart,
- uint32_t *pulLen,
- const void *pBuffer)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreFileWrite(ulInode, ullStart, pulLen, pBuffer);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreFileWrite(ulInode, ullStart, pulLen, pBuffer);
- }
- }
-
- if((ret == 0) && ((gpRedVolume->ulTransMask & RED_TRANSACT_WRITE) != 0U))
- {
- ret = RedVolTransact();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Write to a file.
-
- @param ulInode The file number of the file to write.
- @param ullStart The file offset to write at.
- @param pulLen On entry, the number of bytes to write; on successful exit,
- the number of bytes actually written.
- @param pBuffer The buffer containing the data to be written. Must big
- enough for the write request.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid file number.
- @retval -RED_EFBIG No data can be written to the given file offset since
- the resulting file size would exceed the maximum file
- size.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The inode is a directory inode.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-static REDSTATUS CoreFileWrite(
- uint32_t ulInode,
- uint64_t ullStart,
- uint32_t *pulLen,
- const void *pBuffer)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_FILE, true);
- if(ret == 0)
- {
- ret = RedInodeDataWrite(&ino, ullStart, pulLen, pBuffer);
-
- RedInodePut(&ino, (ret == 0) ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#if TRUNCATE_SUPPORTED
-/** @brief Set the file size.
-
- Allows the file size to be increased, decreased, or to remain the same. If
- the file size is increased, the new area is sparse (will read as zeroes).
- If the file size is decreased, the data beyond the new end-of-file will
- return to free space once it is no longer part of the committed state
- (either immediately or after the next transaction point).
-
- @param ulInode The inode of the file to truncate.
- @param ullSize The new file size, in bytes.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode number.
- @retval -RED_EFBIG @p ullSize exceeds the maximum file size.
- @retval -RED_EINVAL The volume is not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The inode is a directory inode.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedCoreFileTruncate(
- uint32_t ulInode,
- uint64_t ullSize)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- ret = CoreFileTruncate(ulInode, ullSize);
-
- if( (ret == -RED_ENOSPC)
- && ((gpRedVolume->ulTransMask & RED_TRANSACT_VOLFULL) != 0U)
- && (gpRedCoreVol->ulAlmostFreeBlocks > 0U))
- {
- ret = RedVolTransact();
-
- if(ret == 0)
- {
- ret = CoreFileTruncate(ulInode, ullSize);
- }
- }
-
- if((ret == 0) && ((gpRedVolume->ulTransMask & RED_TRANSACT_TRUNCATE) != 0U))
- {
- ret = RedVolTransact();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Set the file size.
-
- @param ulInode The inode of the file to truncate.
- @param ullSize The new file size, in bytes.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode number.
- @retval -RED_EFBIG @p ullSize exceeds the maximum file size.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The inode is a directory inode.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-static REDSTATUS CoreFileTruncate(
- uint32_t ulInode,
- uint64_t ullSize)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fReadOnly)
- {
- ret = -RED_EROFS;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_FILE, true);
- if(ret == 0)
- {
- #if RESERVED_BLOCKS > 0U
- gpRedCoreVol->fUseReservedBlocks = (ullSize < ino.pInodeBuf->ullSize);
- #endif
-
- ret = RedInodeDataTruncate(&ino, ullSize);
-
- #if RESERVED_BLOCKS > 0U
- gpRedCoreVol->fUseReservedBlocks = false;
- #endif
-
- RedInodePut(&ino, (ret == 0) ? (uint8_t)(IPUT_UPDATE_MTIME | IPUT_UPDATE_CTIME) : 0U);
- }
- }
-
- return ret;
-}
-#endif /* TRUNCATE_SUPPORTED */
-
-
-#if (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_READDIR == 1)
-/** @brief Read from a directory.
-
- If files are added to the directory after it is opened, the new files may
- or may not be returned by this function. If files are deleted, the deleted
- files will not be returned.
-
- @param ulInode The directory inode to read from.
- @param pulPos A token which stores the position within the directory. To
- read from the beginning of the directory, populate with
- zero.
- @param pszName Pointer to a buffer which must be big enough to store a
- maximum size name, including a null terminator. On
- successful exit, populated with the name of the next
- directory entry.
- @param pulInode On successful return, populated with the inode number of the
- next directory entry.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode number.
- @retval -RED_EINVAL The volume is not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT There are no more entries in the directory.
- @retval -RED_ENOTDIR @p ulInode refers to a file.
-*/
-REDSTATUS RedCoreDirRead(
- uint32_t ulInode,
- uint32_t *pulPos,
- char *pszName,
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if(!gpRedVolume->fMounted)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- CINODE ino;
-
- ino.ulInode = ulInode;
- ret = RedInodeMount(&ino, FTYPE_DIR, false);
-
- if(ret == 0)
- {
- ret = RedDirEntryRead(&ino, pulPos, pszName, pulInode);
-
- #if (REDCONF_ATIME == 1) && (REDCONF_READ_ONLY == 0)
- if((ret == 0) && !gpRedVolume->fReadOnly)
- {
- ret = RedInodeBranch(&ino);
- }
-
- RedInodePut(&ino, ((ret == 0) && !gpRedVolume->fReadOnly) ? IPUT_UPDATE_ATIME : 0U);
- #else
- RedInodePut(&ino, 0U);
- #endif
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_READDIR == 1) */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/dir.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/dir.c
deleted file mode 100755
index 06fdac1..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/dir.c
+++ /dev/null
@@ -1,958 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements directory operations.
-*/
-#include
-
-#if REDCONF_API_POSIX == 1
-
-#include
-
-
-#define DIR_INDEX_INVALID UINT32_MAX
-
-#if (REDCONF_NAME_MAX % 4U) != 0U
-#define DIRENT_PADDING (4U - (REDCONF_NAME_MAX % 4U))
-#else
-#define DIRENT_PADDING (0U)
-#endif
-#define DIRENT_SIZE (4U + REDCONF_NAME_MAX + DIRENT_PADDING)
-#define DIRENTS_PER_BLOCK (REDCONF_BLOCK_SIZE / DIRENT_SIZE)
-#define DIRENTS_MAX (uint32_t)REDMIN(UINT32_MAX, UINT64_SUFFIX(1) * INODE_DATA_BLOCKS * DIRENTS_PER_BLOCK)
-
-
-/** @brief On-disk directory entry.
-*/
-typedef struct
-{
- /** The inode number that the directory entry points at. If the directory
- entry is available, this holds INODE_INVALID.
- */
- uint32_t ulInode;
-
- /** The name of the directory entry. For names shorter than
- REDCONF_NAME_MAX, unused bytes in the array are zeroed. For names of
- the maximum length, the string is not null terminated.
- */
- char acName[REDCONF_NAME_MAX];
-
- #if DIRENT_PADDING > 0U
- /** Unused padding so that ulInode is always aligned on a four-byte
- boundary.
- */
- uint8_t abPadding[DIRENT_PADDING];
- #endif
-} DIRENT;
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1)
-static REDSTATUS DirCyclicRenameCheck(uint32_t ulSrcInode, const CINODE *pDstPInode);
-#endif
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS DirEntryWrite(CINODE *pPInode, uint32_t ulIdx, uint32_t ulInode, const char *pszName, uint32_t ulNameLen);
-static uint64_t DirEntryIndexToOffset(uint32_t ulIdx);
-#endif
-static uint32_t DirOffsetToEntryIndex(uint64_t ullOffset);
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Create a new entry in a directory.
-
- @param pPInode A pointer to the cached inode structure of the directory
- to which the new entry will be added.
- @param pszName The name to be given to the new entry, terminated by a
- null or a path separator.
- @param ulInode The inode number the new name will point at.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC There is not enough space on the volume to
- create the new directory entry; or the directory
- is full.
- @retval -RED_ENOTDIR @p pPInode is not a directory.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_EEXIST @p pszName already exists in @p ulPInode.
- @retval -RED_EINVAL @p pPInode is not a mounted dirty cached inode
- structure; or @p pszName is not a valid name.
-*/
-REDSTATUS RedDirEntryCreate(
- CINODE *pPInode,
- const char *pszName,
- uint32_t ulInode)
-{
- REDSTATUS ret;
-
- if(!CINODE_IS_DIRTY(pPInode) || (pszName == NULL) || !INODE_IS_VALID(ulInode))
- {
- ret = -RED_EINVAL;
- }
- else if(!pPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- uint32_t ulNameLen = RedNameLen(pszName);
-
- if(ulNameLen == 0U)
- {
- ret = -RED_EINVAL;
- }
- else if(ulNameLen > REDCONF_NAME_MAX)
- {
- ret = -RED_ENAMETOOLONG;
- }
- else
- {
- uint32_t ulEntryIdx;
-
- ret = RedDirEntryLookup(pPInode, pszName, &ulEntryIdx, NULL);
- if(ret == 0)
- {
- ret = -RED_EEXIST;
- }
- else if(ret == -RED_ENOENT)
- {
- if(ulEntryIdx == DIR_INDEX_INVALID)
- {
- ret = -RED_ENOSPC;
- }
- else
- {
- ret = 0;
- }
- }
- else
- {
- /* Unexpected error, no action.
- */
- }
-
- if(ret == 0)
- {
- ret = DirEntryWrite(pPInode, ulEntryIdx, ulInode, pszName, ulNameLen);
- }
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#if DELETE_SUPPORTED
-/** @brief Delete an existing directory entry.
-
- @param pPInode A pointer to the cached inode structure of the directory
- containing the entry to be deleted.
- @param ulDeleteIdx Position within the directory of the entry to be
- deleted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC The file system does not have enough space to modify
- the parent directory to perform the deletion.
- @retval -RED_ENOTDIR @p pPInode is not a directory.
- @retval -RED_EINVAL @p pPInode is not a mounted dirty cached inode
- structure; or @p ulIdx is out of range.
-*/
-REDSTATUS RedDirEntryDelete(
- CINODE *pPInode,
- uint32_t ulDeleteIdx)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_DIRTY(pPInode) || (ulDeleteIdx >= DIRENTS_MAX))
- {
- ret = -RED_EINVAL;
- }
- else if(!pPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else if((DirEntryIndexToOffset(ulDeleteIdx) + DIRENT_SIZE) == pPInode->pInodeBuf->ullSize)
- {
- /* Start searching one behind the index to be deleted.
- */
- uint32_t ulTruncIdx = ulDeleteIdx - 1U;
- bool fDone = false;
-
- /* We are deleting the last dirent in the directory, so search
- backwards to find the last populated dirent, allowing us to truncate
- the directory to that point.
- */
- while((ret == 0) && (ulTruncIdx != UINT32_MAX) && !fDone)
- {
- ret = RedInodeDataSeekAndRead(pPInode, ulTruncIdx / DIRENTS_PER_BLOCK);
-
- if(ret == 0)
- {
- const DIRENT *pDirents = CAST_CONST_DIRENT_PTR(pPInode->pbData);
- uint32_t ulBlockIdx = ulTruncIdx % DIRENTS_PER_BLOCK;
-
- do
- {
- if(pDirents[ulBlockIdx].ulInode != INODE_INVALID)
- {
- fDone = true;
- break;
- }
-
- ulTruncIdx--;
- ulBlockIdx--;
- } while(ulBlockIdx != UINT32_MAX);
- }
- else if(ret == -RED_ENODATA)
- {
- ret = 0;
-
- REDASSERT((ulTruncIdx % DIRENTS_PER_BLOCK) == 0U);
- ulTruncIdx -= DIRENTS_PER_BLOCK;
- }
- else
- {
- /* Unexpected error, loop will terminate; nothing else
- to be done.
- */
- }
- }
-
- /* Currently ulTruncIdx represents the last valid dirent index, or
- UINT32_MAX if the directory is now empty. Increment it so that it
- represents the first invalid entry, which will be truncated.
- */
- ulTruncIdx++;
-
- /* Truncate the directory, deleting the requested entry and any empty
- dirents at the end of the directory.
- */
- if(ret == 0)
- {
- ret = RedInodeDataTruncate(pPInode, DirEntryIndexToOffset(ulTruncIdx));
- }
- }
- else
- {
- /* The dirent to delete is not the last entry in the directory, so just
- zero it.
- */
- ret = DirEntryWrite(pPInode, ulDeleteIdx, INODE_INVALID, "", 0U);
- }
-
- return ret;
-}
-#endif /* DELETE_SUPPORTED */
-
-
-/** @brief Perform a case-sensitive search of a directory for a given name.
-
- If found, then position of the entry within the directory and the inode
- number it points to are returned. As an optimization for directory entry
- creation, in the case where the requested entry does not exist, the position
- of the first available (unused) entry is returned.
-
- @param pPInode A pointer to the cached inode structure of the directory
- to search.
- @param pszName The name of the desired entry, terminated by either a
- null or a path separator.
- @param pulEntryIdx On successful return, meaning that the desired entry
- exists, populated with the position of the entry. If
- returning an -RED_ENOENT error, populated with the
- position of the first available entry, or set to
- DIR_INDEX_INVALID if the directory is full. Optional.
- @param pulInode On successful return, populated with the inode number
- that the name points to. Optional; may be `NULL`.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT @p pszName does not name an existing file or
- directory.
- @retval -RED_ENOTDIR @p pPInode is not a directory.
- @retval -RED_EINVAL @p pPInode is not a mounted cached inode
- structure; or @p pszName is not a valid name; or
- @p pulEntryIdx is `NULL`.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
-*/
-REDSTATUS RedDirEntryLookup(
- CINODE *pPInode,
- const char *pszName,
- uint32_t *pulEntryIdx,
- uint32_t *pulInode)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pPInode) || (pszName == NULL))
- {
- ret = -RED_EINVAL;
- }
- else if(!pPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- uint32_t ulNameLen = RedNameLen(pszName);
-
- if(ulNameLen == 0U)
- {
- ret = -RED_EINVAL;
- }
- else if(ulNameLen > REDCONF_NAME_MAX)
- {
- ret = -RED_ENAMETOOLONG;
- }
- else
- {
- uint32_t ulIdx = 0U;
- uint32_t ulDirentCount = DirOffsetToEntryIndex(pPInode->pInodeBuf->ullSize);
- uint32_t ulFreeIdx = DIR_INDEX_INVALID; /* Index of first free dirent. */
-
- /* Loop over the directory blocks, searching each block for a
- dirent that matches the given name.
- */
- while((ret == 0) && (ulIdx < ulDirentCount))
- {
- ret = RedInodeDataSeekAndRead(pPInode, ulIdx / DIRENTS_PER_BLOCK);
-
- if(ret == 0)
- {
- const DIRENT *pDirents = CAST_CONST_DIRENT_PTR(pPInode->pbData);
- uint32_t ulBlockLastIdx = REDMIN(DIRENTS_PER_BLOCK, ulDirentCount - ulIdx);
- uint32_t ulBlockIdx;
-
- for(ulBlockIdx = 0U; ulBlockIdx < ulBlockLastIdx; ulBlockIdx++)
- {
- const DIRENT *pDirent = &pDirents[ulBlockIdx];
-
- if(pDirent->ulInode != INODE_INVALID)
- {
- /* The name in the dirent will not be null
- terminated if it is of the maximum length, so
- use a bounded string compare and then make sure
- there is nothing more to the name.
- */
- if( (RedStrNCmp(pDirent->acName, pszName, ulNameLen) == 0)
- && ((ulNameLen == REDCONF_NAME_MAX) || (pDirent->acName[ulNameLen] == '\0')))
- {
- /* Found a matching dirent, stop and return its
- information.
- */
- if(pulInode != NULL)
- {
- *pulInode = pDirent->ulInode;
-
- #ifdef REDCONF_ENDIAN_SWAP
- *pulInode = RedRev32(*pulInode);
- #endif
- }
-
- ulIdx += ulBlockIdx;
- break;
- }
- }
- else if(ulFreeIdx == DIR_INDEX_INVALID)
- {
- ulFreeIdx = ulIdx + ulBlockIdx;
- }
- else
- {
- /* The directory entry is free, but we already found a free one, so there's
- nothing to do here.
- */
- }
- }
-
- if(ulBlockIdx < ulBlockLastIdx)
- {
- /* If we broke out of the for loop, we found a matching
- dirent and can stop the search.
- */
- break;
- }
-
- ulIdx += ulBlockLastIdx;
- }
- else if(ret == -RED_ENODATA)
- {
- if(ulFreeIdx == DIR_INDEX_INVALID)
- {
- ulFreeIdx = ulIdx;
- }
-
- ret = 0;
- ulIdx += DIRENTS_PER_BLOCK;
- }
- else
- {
- /* Unexpected error, let the loop terminate, no action
- here.
- */
- }
- }
-
- if(ret == 0)
- {
- /* If we made it all the way to the end of the directory
- without stopping, then the given name does not exist in the
- directory.
- */
- if(ulIdx == ulDirentCount)
- {
- /* If the directory had no sparse dirents, then the first
- free dirent is beyond the end of the directory. If the
- directory is already the maximum size, then there is no
- free dirent.
- */
- if((ulFreeIdx == DIR_INDEX_INVALID) && (ulDirentCount < DIRENTS_MAX))
- {
- ulFreeIdx = ulDirentCount;
- }
-
- ulIdx = ulFreeIdx;
-
- ret = -RED_ENOENT;
- }
-
- if(pulEntryIdx != NULL)
- {
- *pulEntryIdx = ulIdx;
- }
- }
- }
- }
-
- return ret;
-}
-
-
-#if (REDCONF_API_POSIX_READDIR == 1) || (REDCONF_CHECKER == 1)
-/** @brief Read the next entry from a directory, given a starting index.
-
- @param pPInode A pointer to the cached inode structure of the directory to
- read from.
- @param pulIdx On entry, the directory index to start reading from. On
- successful return, populated with the directory index to use
- for subsequent reads. On -RED_ENOENT return, populated with
- the directory index immediately following the last valid
- one.
- @param pszName On successful return, populated with the name of the next
- directory entry. Buffer must be at least
- REDCONF_NAME_MAX + 1 in size, to store the maximum name
- length plus a null terminator.
- @param pulInode On successful return, populated with the inode number
- pointed at by the next directory entry.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT There are no more entries in the directory.
- @retval -RED_ENOTDIR @p pPInode is not a directory.
- @retval -RED_EINVAL @p pPInode is not a mounted cached inode structure;
- or @p pszName is `NULL`; or @p pulIdx is `NULL`; or
- @p pulInode is `NULL`.
-*/
-REDSTATUS RedDirEntryRead(
- CINODE *pPInode,
- uint32_t *pulIdx,
- char *pszName,
- uint32_t *pulInode)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pPInode) || (pulIdx == NULL) || (pszName == NULL) || (pulInode == NULL))
- {
- ret = -RED_EINVAL;
- }
- else if(!pPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- uint32_t ulIdx = *pulIdx;
- uint32_t ulDirentCount = DirOffsetToEntryIndex(pPInode->pInodeBuf->ullSize);
-
- /* Starting either at the beginning of the directory or where we left
- off, loop over the directory blocks, searching each block for a
- non-sparse dirent to return as the next entry in the directory.
- */
- while((ret == 0) && (ulIdx < ulDirentCount))
- {
- uint32_t ulBlockOffset = ulIdx / DIRENTS_PER_BLOCK;
-
- ret = RedInodeDataSeekAndRead(pPInode, ulBlockOffset);
-
- if(ret == 0)
- {
- const DIRENT *pDirents = CAST_CONST_DIRENT_PTR(pPInode->pbData);
- uint32_t ulBlockLastIdx = REDMIN(DIRENTS_PER_BLOCK, ulDirentCount - (ulBlockOffset * DIRENTS_PER_BLOCK));
- uint32_t ulBlockIdx;
-
- for(ulBlockIdx = ulIdx % DIRENTS_PER_BLOCK; ulBlockIdx < ulBlockLastIdx; ulBlockIdx++)
- {
- if(pDirents[ulBlockIdx].ulInode != INODE_INVALID)
- {
- *pulIdx = ulIdx + 1U;
- RedStrNCpy(pszName, pDirents[ulBlockIdx].acName, REDCONF_NAME_MAX);
- pszName[REDCONF_NAME_MAX] = '\0';
-
- *pulInode = pDirents[ulBlockIdx].ulInode;
-
- #ifdef REDCONF_ENDIAN_SWAP
- *pulInode = RedRev32(*pulInode);
- #endif
- break;
- }
-
- ulIdx++;
- }
-
- if(ulBlockIdx < ulBlockLastIdx)
- {
- REDASSERT(ulIdx <= ulDirentCount);
- break;
- }
- }
- else if(ret == -RED_ENODATA)
- {
- ulIdx += DIRENTS_PER_BLOCK - (ulIdx % DIRENTS_PER_BLOCK);
- ret = 0;
- }
- else
- {
- /* Unexpected error, loop will terminate; nothing else to do.
- */
- }
-
- REDASSERT(ulIdx <= ulDirentCount);
- }
-
- if((ret == 0) && (ulIdx >= ulDirentCount))
- {
- *pulIdx = ulDirentCount;
- ret = -RED_ENOENT;
- }
- }
-
- return ret;
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1)
-/** Rename a directory entry.
-
- @param pSrcPInode The inode of the directory containing @p pszSrcName.
- @param pszSrcName The name of the directory entry to be renamed.
- @param pSrcInode On successful return, populated with the inode of the
- source entry.
- @param pDstPInode The inode of the directory in which @p pszDstName will
- be created or replaced.
- @param pszDstName The name of the directory entry to be created or
- replaced.
- @param pDstInode On successful return, if the destination previously
- existed, populated with the inode previously pointed to
- by the destination. This may be the same as the source
- inode. If the destination did not exist, populated with
- INODE_INVALID.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EEXIST #REDCONF_RENAME_ATOMIC is false and the
- destination name exists.
- @retval -RED_EINVAL @p pSrcPInode is not a mounted dirty cached
- inode structure; or @p pSrcInode is `NULL`; or
- @p pszSrcName is not a valid name; or
- @p pDstPInode is not a mounted dirty cached
- inode structure; or @p pDstInode is `NULL`; or
- @p pszDstName is not a valid name.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR The destination name exists and is a directory,
- and the source name is a non-directory.
- @retval -RED_ENAMETOOLONG Either @p pszSrcName or @p pszDstName is longer
- than #REDCONF_NAME_MAX.
- @retval -RED_ENOENT The source name is not an existing entry; or
- either @p pszSrcName or @p pszDstName point to
- an empty string.
- @retval -RED_ENOTDIR @p pSrcPInode is not a directory; or
- @p pDstPInode is not a directory; or the source
- name is a directory and the destination name is
- a file.
- @retval -RED_ENOTEMPTY The destination name is a directory which is not
- empty.
- @retval -RED_ENOSPC The file system does not have enough space to
- extend the @p ulDstPInode directory.
- @retval -RED_EROFS The directory to be removed resides on a
- read-only file system.
-*/
-REDSTATUS RedDirEntryRename(
- CINODE *pSrcPInode,
- const char *pszSrcName,
- CINODE *pSrcInode,
- CINODE *pDstPInode,
- const char *pszDstName,
- CINODE *pDstInode)
-{
- REDSTATUS ret;
-
- if( !CINODE_IS_DIRTY(pSrcPInode)
- || (pszSrcName == NULL)
- || (pSrcInode == NULL)
- || !CINODE_IS_DIRTY(pDstPInode)
- || (pszDstName == NULL)
- || (pDstInode == NULL))
- {
- ret = -RED_EINVAL;
- }
- else if(!pSrcPInode->fDirectory || !pDstPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- uint32_t ulDstIdx = 0U; /* Init'd to quiet warnings. */
- uint32_t ulSrcIdx;
-
- /* Look up the source and destination names.
- */
- ret = RedDirEntryLookup(pSrcPInode, pszSrcName, &ulSrcIdx, &pSrcInode->ulInode);
-
- if(ret == 0)
- {
- ret = RedDirEntryLookup(pDstPInode, pszDstName, &ulDstIdx, &pDstInode->ulInode);
-
- if(ret == -RED_ENOENT)
- {
- if(ulDstIdx == DIR_INDEX_INVALID)
- {
- ret = -RED_ENOSPC;
- }
- else
- {
- #if REDCONF_RENAME_ATOMIC == 1
- pDstInode->ulInode = INODE_INVALID;
- #endif
- ret = 0;
- }
- }
- #if REDCONF_RENAME_ATOMIC == 0
- else if(ret == 0)
- {
- ret = -RED_EEXIST;
- }
- else
- {
- /* Nothing to do here, just propagate the error.
- */
- }
- #endif
- }
-
- #if REDCONF_RENAME_ATOMIC == 1
- /* If both names point to the same inode, POSIX says to do nothing to
- either name.
- */
- if((ret == 0) && (pSrcInode->ulInode != pDstInode->ulInode))
- #else
- if(ret == 0)
- #endif
- {
- ret = RedInodeMount(pSrcInode, FTYPE_EITHER, true);
-
- #if REDCONF_RENAME_ATOMIC == 1
- if((ret == 0) && (pDstInode->ulInode != INODE_INVALID))
- {
- /* Source and destination must be the same type (file/dir).
- */
- ret = RedInodeMount(pDstInode, pSrcInode->fDirectory ? FTYPE_DIR : FTYPE_FILE, true);
-
- /* If renaming directories, the destination must be empty.
- */
- if((ret == 0) && pDstInode->fDirectory && (pDstInode->pInodeBuf->ullSize > 0U))
- {
- ret = -RED_ENOTEMPTY;
- }
- }
- #endif
-
- /* If we are renaming a directory, make sure the rename isn't
- cyclic (e.g., renaming "foo" into "foo/bar").
- */
- if((ret == 0) && pSrcInode->fDirectory)
- {
- ret = DirCyclicRenameCheck(pSrcInode->ulInode, pDstPInode);
- }
-
- if(ret == 0)
- {
- ret = DirEntryWrite(pDstPInode, ulDstIdx, pSrcInode->ulInode, pszDstName, RedNameLen(pszDstName));
- }
-
- if(ret == 0)
- {
- ret = RedDirEntryDelete(pSrcPInode, ulSrcIdx);
-
- if(ret == -RED_ENOSPC)
- {
- REDSTATUS ret2;
-
- /* If there was not enough space to branch the parent
- directory inode and data block containin the source
- entry, revert destination directory entry to its
- previous state.
- */
- #if REDCONF_RENAME_ATOMIC == 1
- if(pDstInode->ulInode != INODE_INVALID)
- {
- ret2 = DirEntryWrite(pDstPInode, ulDstIdx, pDstInode->ulInode, pszDstName, RedNameLen(pszDstName));
- }
- else
- #endif
- {
- ret2 = RedDirEntryDelete(pDstPInode, ulDstIdx);
- }
-
- if(ret2 != 0)
- {
- ret = ret2;
- CRITICAL_ERROR();
- }
- }
- }
-
- if(ret == 0)
- {
- pSrcInode->pInodeBuf->ulPInode = pDstPInode->ulInode;
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Check for a cyclic rename.
-
- A cyclic rename is renaming a directory into a subdirectory of itself. For
- example, renaming "a" into "a/b/c/d" is cyclic. These renames must not be
- allowed since they would corrupt the directory tree.
-
- @param ulSrcInode The inode number of the directory being renamed.
- @param pDstPInode A pointer to the cached inode structure of the directory
- into which the source is being renamed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL The rename is cyclic; or invalid parameters.
- @retval -RED_ENOTDIR @p pDstPInode is not a directory.
-*/
-static REDSTATUS DirCyclicRenameCheck(
- uint32_t ulSrcInode,
- const CINODE *pDstPInode)
-{
- REDSTATUS ret = 0;
-
- if(!INODE_IS_VALID(ulSrcInode) || !CINODE_IS_MOUNTED(pDstPInode))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(ulSrcInode == pDstPInode->ulInode)
- {
- ret = -RED_EINVAL;
- }
- else if(!pDstPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- CINODE NextParent;
- /* Used to prevent infinite loop in case of corrupted directory
- structure.
- */
- uint32_t ulIteration = 0U;
-
- NextParent.ulInode = pDstPInode->pInodeBuf->ulPInode;
-
- while( (NextParent.ulInode != ulSrcInode)
- && (NextParent.ulInode != INODE_ROOTDIR)
- && (NextParent.ulInode != INODE_INVALID)
- && (ulIteration < gpRedVolConf->ulInodeCount))
- {
- ret = RedInodeMount(&NextParent, FTYPE_DIR, false);
- if(ret != 0)
- {
- break;
- }
-
- NextParent.ulInode = NextParent.pInodeBuf->ulPInode;
-
- RedInodePut(&NextParent, 0U);
-
- ulIteration++;
- }
-
- if((ret == 0) && (ulIteration == gpRedVolConf->ulInodeCount))
- {
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
-
- if((ret == 0) && (ulSrcInode == NextParent.ulInode))
- {
- ret = -RED_EINVAL;
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1) */
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Update the contents of a directory entry.
-
- @param pPInode A pointer to the cached inode structure of the directory
- whose entry is being written.
- @param ulIdx The index of the directory entry to write.
- @param ulInode The inode number the directory entry is to point at.
- @param pszName The name of the directory entry.
- @param ulNameLen The length of @p pszName.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC There is not enough space on the volume to write the
- directory entry.
- @retval -RED_ENOTDIR @p pPInode is not a directory.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS DirEntryWrite(
- CINODE *pPInode,
- uint32_t ulIdx,
- uint32_t ulInode,
- const char *pszName,
- uint32_t ulNameLen)
-{
- REDSTATUS ret;
-
- if( !CINODE_IS_DIRTY(pPInode)
- || (ulIdx >= DIRENTS_MAX)
- || (!INODE_IS_VALID(ulInode) && (ulInode != INODE_INVALID))
- || (pszName == NULL)
- || (ulNameLen > REDCONF_NAME_MAX)
- || ((ulNameLen == 0U) != (ulInode == INODE_INVALID)))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(!pPInode->fDirectory)
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- uint64_t ullOffset = DirEntryIndexToOffset(ulIdx);
- uint32_t ulLen = DIRENT_SIZE;
- static DIRENT de;
-
- RedMemSet(&de, 0U, sizeof(de));
-
- de.ulInode = ulInode;
-
- #ifdef REDCONF_ENDIAN_SWAP
- de.ulInode = RedRev32(de.ulInode);
- #endif
-
- RedStrNCpy(de.acName, pszName, ulNameLen);
-
- ret = RedInodeDataWrite(pPInode, ullOffset, &ulLen, &de);
- }
-
- return ret;
-}
-
-
-/** @brief Convert a directory entry index to a byte offset.
-
- @param ulIdx Directory entry index.
-
- @return Byte offset in the directory corresponding with ulIdx.
-*/
-static uint64_t DirEntryIndexToOffset(
- uint32_t ulIdx)
-{
- uint32_t ulBlock = ulIdx / DIRENTS_PER_BLOCK;
- uint32_t ulOffsetInBlock = ulIdx % DIRENTS_PER_BLOCK;
- uint64_t ullOffset;
-
- REDASSERT(ulIdx < DIRENTS_MAX);
-
- ullOffset = (uint64_t)ulBlock << BLOCK_SIZE_P2;
- ullOffset += (uint64_t)ulOffsetInBlock * DIRENT_SIZE;
-
- return ullOffset;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Convert a byte offset to a directory entry index.
-
- @param ullOffset Byte offset in the directory.
-
- @return Directory entry index corresponding with @p ullOffset.
-*/
-static uint32_t DirOffsetToEntryIndex(
- uint64_t ullOffset)
-{
- uint32_t ulIdx;
-
- REDASSERT(ullOffset < INODE_SIZE_MAX);
- REDASSERT(((uint32_t)(ullOffset & (REDCONF_BLOCK_SIZE - 1U)) % DIRENT_SIZE) == 0U);
-
- /* Avoid doing any 64-bit divides.
- */
- ulIdx = (uint32_t)(ullOffset >> BLOCK_SIZE_P2) * DIRENTS_PER_BLOCK;
- ulIdx += (uint32_t)(ullOffset & (REDCONF_BLOCK_SIZE - 1U)) / DIRENT_SIZE;
-
- return ulIdx;
-}
-
-
-#endif /* REDCONF_API_POSIX == 1 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/format.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/format.c
deleted file mode 100755
index e237ab5..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/format.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements the Reliance Edge file system formatter.
-*/
-#include
-#include
-#include
-
-#if FORMAT_SUPPORTED
-
-
-/** @brief Format a file system volume.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBUSY Volume is mounted.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedVolFormat(void)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->fMounted)
- {
- ret = -RED_EBUSY;
- }
- else
- {
- ret = RedOsBDevOpen(gbRedVolNum, BDEV_O_RDWR);
- }
-
- if(ret == 0)
- {
- MASTERBLOCK *pMB;
- REDSTATUS ret2;
-
- /* Overwrite the master block with zeroes, so that if formatting is
- interrupted, the volume will not be mountable.
- */
- ret = RedBufferGet(BLOCK_NUM_MASTER, BFLAG_NEW | BFLAG_DIRTY, CAST_VOID_PTR_PTR(&pMB));
-
- if(ret == 0)
- {
- ret = RedBufferFlush(BLOCK_NUM_MASTER, 1U);
-
- RedBufferDiscard(pMB);
- }
-
- if(ret == 0)
- {
- ret = RedIoFlush(gbRedVolNum);
- }
-
- #if REDCONF_IMAP_EXTERNAL == 1
- if((ret == 0) && !gpRedCoreVol->fImapInline)
- {
- uint32_t ulImapBlock;
- uint32_t ulImapBlockLimit = gpRedCoreVol->ulImapStartBN + (gpRedCoreVol->ulImapNodeCount * 2U);
- uint16_t uImapFlags = (uint16_t)((uint32_t)BFLAG_META_IMAP | BFLAG_NEW | BFLAG_DIRTY);
-
- /* Technically it is only necessary to create one copy of each imap
- node (the copy the metaroot points at), but creating them both
- avoids headaches during disk image analysis from stale imaps
- left over from previous formats.
- */
- for(ulImapBlock = gpRedCoreVol->ulImapStartBN; ulImapBlock < ulImapBlockLimit; ulImapBlock++)
- {
- IMAPNODE *pImap;
-
- ret = RedBufferGet(ulImapBlock, uImapFlags, CAST_VOID_PTR_PTR(&pImap));
- if(ret != 0)
- {
- break;
- }
-
- RedBufferPut(pImap);
- }
- }
- #endif
-
- /* Write the first metaroot.
- */
- if(ret == 0)
- {
- RedMemSet(gpRedMR, 0U, sizeof(*gpRedMR));
-
- gpRedMR->ulFreeBlocks = gpRedVolume->ulBlocksAllocable;
- #if REDCONF_API_POSIX == 1
- gpRedMR->ulFreeInodes = gpRedVolConf->ulInodeCount;
- #endif
- gpRedMR->ulAllocNextBlock = gpRedCoreVol->ulFirstAllocableBN;
-
- /* The branched flag is typically set automatically when bits in
- the imap change. It is set here explicitly because the imap has
- only been initialized, not changed.
- */
- gpRedCoreVol->fBranched = true;
-
- ret = RedVolTransact();
- }
-
- #if REDCONF_API_POSIX == 1
- /* Create the root directory.
- */
- if(ret == 0)
- {
- CINODE rootdir;
-
- rootdir.ulInode = INODE_ROOTDIR;
- ret = RedInodeCreate(&rootdir, INODE_INVALID, RED_S_IFDIR);
-
- if(ret == 0)
- {
- RedInodePut(&rootdir, 0U);
- }
- }
- #endif
-
- #if REDCONF_API_FSE == 1
- /* The FSE API does not support creating or deletes files, so all the
- inodes are created during setup.
- */
- if(ret == 0)
- {
- uint32_t ulInodeIdx;
-
- for(ulInodeIdx = 0U; ulInodeIdx < gpRedVolConf->ulInodeCount; ulInodeIdx++)
- {
- CINODE ino;
-
- ino.ulInode = INODE_FIRST_FREE + ulInodeIdx;
- ret = RedInodeCreate(&ino, INODE_INVALID, RED_S_IFREG);
-
- if(ret == 0)
- {
- RedInodePut(&ino, 0U);
- }
- }
- }
- #endif
-
- /* Write the second metaroot.
- */
- if(ret == 0)
- {
- ret = RedVolTransact();
- }
-
- /* Populate and write out the master block.
- */
- if(ret == 0)
- {
- ret = RedBufferGet(BLOCK_NUM_MASTER, (uint16_t)((uint32_t)BFLAG_META_MASTER | BFLAG_NEW | BFLAG_DIRTY), CAST_VOID_PTR_PTR(&pMB));
- }
-
- if(ret == 0)
- {
- pMB->ulVersion = RED_DISK_LAYOUT_VERSION;
- RedStrNCpy(pMB->acBuildNum, RED_BUILD_NUMBER, sizeof(pMB->acBuildNum));
- pMB->ulFormatTime = RedOsClockGetTime();
- pMB->ulInodeCount = gpRedVolConf->ulInodeCount;
- pMB->ulBlockCount = gpRedVolume->ulBlockCount;
- pMB->uMaxNameLen = REDCONF_NAME_MAX;
- pMB->uDirectPointers = REDCONF_DIRECT_POINTERS;
- pMB->uIndirectPointers = REDCONF_INDIRECT_POINTERS;
- pMB->bBlockSizeP2 = BLOCK_SIZE_P2;
-
- #if REDCONF_API_POSIX == 1
- pMB->bFlags |= MBFLAG_API_POSIX;
- #endif
- #if REDCONF_INODE_TIMESTAMPS == 1
- pMB->bFlags |= MBFLAG_INODE_TIMESTAMPS;
- #endif
- #if REDCONF_INODE_BLOCKS == 1
- pMB->bFlags |= MBFLAG_INODE_BLOCKS;
- #endif
- #if (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
- pMB->bFlags |= MBFLAG_INODE_NLINK;
- #endif
-
- ret = RedBufferFlush(BLOCK_NUM_MASTER, 1U);
-
- RedBufferPut(pMB);
- }
-
- if(ret == 0)
- {
- ret = RedIoFlush(gbRedVolNum);
- }
-
- ret2 = RedOsBDevClose(gbRedVolNum);
- if(ret == 0)
- {
- ret = ret2;
- }
- }
-
- /* Discard the buffers so a subsequent format will not run into blocks it
- does not expect.
- */
- if(ret == 0)
- {
- ret = RedBufferDiscardRange(0U, gpRedVolume->ulBlockCount);
- }
-
- return ret;
-}
-
-
-#endif /* FORMAT_SUPPORTED */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imap.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imap.c
deleted file mode 100755
index 23bd508..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imap.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements allocation routines.
-
- This module implements routines for working with the imap, a bitmap which
- tracks which blocks are allocated or free. Some of the functionality is
- delegated to imapinline.c and imapextern.c.
-*/
-#include
-#include
-
-
-/** @brief Get the allocation bit of a block from either metaroot.
-
- Will pass the call down either to the inline imap or to the external imap
- implementation, whichever is appropriate for the current volume.
-
- @param bMR The metaroot index: either 0 or 1.
- @param ulBlock The block number to query.
- @param pfAllocated On successful return, populated with the allocation bit
- of the block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bMR is out of range; or @p ulBlock is out of range;
- or @p pfAllocated is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedImapBlockGet(
- uint8_t bMR,
- uint32_t ulBlock,
- bool *pfAllocated)
-{
- REDSTATUS ret;
-
- if( (bMR > 1U)
- || (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount)
- || (pfAllocated == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- #if (REDCONF_IMAP_INLINE == 1) && (REDCONF_IMAP_EXTERNAL == 1)
- if(gpRedCoreVol->fImapInline)
- {
- ret = RedImapIBlockGet(bMR, ulBlock, pfAllocated);
- }
- else
- {
- ret = RedImapEBlockGet(bMR, ulBlock, pfAllocated);
- }
- #elif REDCONF_IMAP_INLINE == 1
- ret = RedImapIBlockGet(bMR, ulBlock, pfAllocated);
- #else
- ret = RedImapEBlockGet(bMR, ulBlock, pfAllocated);
- #endif
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Set the allocation bit of a block in the working metaroot.
-
- Will pass the call down either to the inline imap or to the external imap
- implementation, whichever is appropriate for the current volume.
-
- @param ulBlock The block number to allocate or free.
- @param fAllocated Whether to allocate the block (true) or free it (false).
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulBlock is out of range; or @p ulBlock is allocable
- and @p fAllocated is 1.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedImapBlockSet(
- uint32_t ulBlock,
- bool fAllocated)
-{
- REDSTATUS ret;
-
- if( (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if( (ulBlock >= gpRedCoreVol->ulFirstAllocableBN)
- && ( (fAllocated && (gpRedMR->ulFreeBlocks == 0U))
- || ((!fAllocated) && (gpRedMR->ulFreeBlocks >= gpRedVolume->ulBlocksAllocable))))
- {
- /* Attempting either to free more blocks than are allocable, or
- allocate a block when there are none available. This could indicate
- metadata corruption.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- #if (REDCONF_IMAP_INLINE == 1) && (REDCONF_IMAP_EXTERNAL == 1)
- if(gpRedCoreVol->fImapInline)
- {
- ret = RedImapIBlockSet(ulBlock, fAllocated);
- }
- else
- {
- ret = RedImapEBlockSet(ulBlock, fAllocated);
- }
- #elif REDCONF_IMAP_INLINE == 1
- ret = RedImapIBlockSet(ulBlock, fAllocated);
- #else
- ret = RedImapEBlockSet(ulBlock, fAllocated);
- #endif
-
- /* Any change to the allocation state of a block indicates that the
- volume is now branched.
- */
- gpRedCoreVol->fBranched = true;
- }
-
- /* If a block was marked as no longer in use, discard it from the buffers.
- */
- if((ret == 0) && (!fAllocated))
- {
- ret = RedBufferDiscardRange(ulBlock, 1U);
- CRITICAL_ASSERT(ret == 0);
- }
-
- /* Adjust the free/almost free block count if the block was allocable.
- Discard the block if required.
- */
- if((ret == 0) && (ulBlock >= gpRedCoreVol->ulFirstAllocableBN))
- {
- if(fAllocated)
- {
- gpRedMR->ulFreeBlocks--;
- }
- else
- {
- bool fWasAllocated;
-
- /* Whether the block became free or almost free depends on its
- previous allocation state. If it was used, then it is now
- almost free. Otherwise, it was new and is now free.
- */
- ret = RedImapBlockGet(1U - gpRedCoreVol->bCurMR, ulBlock, &fWasAllocated);
- CRITICAL_ASSERT(ret == 0);
-
- if(ret == 0)
- {
- if(fWasAllocated)
- {
- gpRedCoreVol->ulAlmostFreeBlocks++;
- }
- else
- {
- gpRedMR->ulFreeBlocks++;
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Allocate one block.
-
- @param pulBlock On successful return, populated with the allocated block
- number.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pulBlock is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the allocation.
-*/
-REDSTATUS RedImapAllocBlock(
- uint32_t *pulBlock)
-{
- REDSTATUS ret;
-
- if(pulBlock == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(gpRedMR->ulFreeBlocks == 0U)
- {
- ret = -RED_ENOSPC;
- }
- else
- {
- uint32_t ulStopBlock = gpRedMR->ulAllocNextBlock;
- bool fAllocated = false;
-
- do
- {
- ALLOCSTATE state;
-
- ret = RedImapBlockState(gpRedMR->ulAllocNextBlock, &state);
- CRITICAL_ASSERT(ret == 0);
-
- if(ret == 0)
- {
- if(state == ALLOCSTATE_FREE)
- {
- ret = RedImapBlockSet(gpRedMR->ulAllocNextBlock, true);
- CRITICAL_ASSERT(ret == 0);
-
- *pulBlock = gpRedMR->ulAllocNextBlock;
- fAllocated = true;
- }
-
- /* Increment the next block number, wrapping it when the end of
- the volume is reached.
- */
- gpRedMR->ulAllocNextBlock++;
- if(gpRedMR->ulAllocNextBlock == gpRedVolume->ulBlockCount)
- {
- gpRedMR->ulAllocNextBlock = gpRedCoreVol->ulFirstAllocableBN;
- }
- }
- }
- while((ret == 0) && !fAllocated && (gpRedMR->ulAllocNextBlock != ulStopBlock));
-
- if((ret == 0) && !fAllocated)
- {
- /* The free block count was already determined to be non-zero, no
- error occurred while looking for free blocks, but no free blocks
- were found. This indicates metadata corruption.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Get the allocation state of a block.
-
- Takes into account the allocation bits from both metaroots, and returns one
- of four possible allocation state values:
-
- - ::ALLOCSTATE_FREE Free and may be allocated; writeable.
- - ::ALLOCSTATE_USED In-use and transacted; not writeable.
- - ::ALLOCSTATE_NEW In-use but not transacted; writeable.
- - ::ALLOCSTATE_AFREE Will become free after a transaction; not writeable.
-
- @param ulBlock The block number to query.
- @param pState On successful return, populated with the state of the block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulBlock is out of range; or @p pState is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedImapBlockState(
- uint32_t ulBlock,
- ALLOCSTATE *pState)
-{
- REDSTATUS ret;
-
- if( (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount)
- || (pState == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- bool fBitCurrent;
-
- ret = RedImapBlockGet(gpRedCoreVol->bCurMR, ulBlock, &fBitCurrent);
-
- if(ret == 0)
- {
- bool fBitOld;
-
- ret = RedImapBlockGet(1U - gpRedCoreVol->bCurMR, ulBlock, &fBitOld);
-
- if(ret == 0)
- {
- if(fBitCurrent)
- {
- if(fBitOld)
- {
- *pState = ALLOCSTATE_USED;
- }
- else
- {
- *pState = ALLOCSTATE_NEW;
- }
- }
- else
- {
- if(fBitOld)
- {
- *pState = ALLOCSTATE_AFREE;
- }
- else
- {
- *pState = ALLOCSTATE_FREE;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapextern.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapextern.c
deleted file mode 100755
index 4ce7371..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapextern.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements routines for the external imap.
-
- The external imap is used on volumes that are too big for the imap bitmap
- to be stored entirely in the metaroot, so instead the bitmap is stored in
- imap nodes on disk, and the metaroot bitmap is used to toggle between imap
- nodes.
-*/
-#include
-
-#if REDCONF_IMAP_EXTERNAL == 1
-
-#include
-
-
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS ImapNodeBranch(uint32_t ulImapNode, IMAPNODE **ppImap);
-static bool ImapNodeIsBranched(uint32_t ulImapNode);
-#endif
-
-
-/** @brief Get the allocation bit of a block from the imap as it exists in
- either metaroot.
-
- @param bMR The metaroot index: either 0 or 1.
- @param ulBlock The block number to query.
- @param pfAllocated On successful exit, populated with the allocation bit
- of the block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bMR is out of range; or @p ulBlock is out of range;
- or @p pfAllocated is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedImapEBlockGet(
- uint8_t bMR,
- uint32_t ulBlock,
- bool *pfAllocated)
-{
- REDSTATUS ret;
-
- if( gpRedCoreVol->fImapInline
- || (bMR > 1U)
- || (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount)
- || (pfAllocated == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulOffset = ulBlock - gpRedCoreVol->ulInodeTableStartBN;
- uint32_t ulImapNode = ulOffset / IMAPNODE_ENTRIES;
- uint8_t bMRToRead = bMR;
- IMAPNODE *pImap;
-
- #if REDCONF_READ_ONLY == 0
- /* If the imap node is not branched, then both copies of the imap are
- identical. If the old metaroot copy is requested, use the current
- copy instead, since it is more likely to be buffered.
- */
- if(bMR == (1U - gpRedCoreVol->bCurMR))
- {
- if(!ImapNodeIsBranched(ulImapNode))
- {
- bMRToRead = 1U - bMR;
- }
- }
- #endif
-
- ret = RedBufferGet(RedImapNodeBlock(bMRToRead, ulImapNode), BFLAG_META_IMAP, CAST_VOID_PTR_PTR(&pImap));
-
- if(ret == 0)
- {
- *pfAllocated = RedBitGet(pImap->abEntries, ulOffset % IMAPNODE_ENTRIES);
-
- RedBufferPut(pImap);
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Set the allocation bit of a block in the working-state imap.
-
- @param ulBlock The block number to allocate or free.
- @param fAllocated Whether to allocate the block (true) or free it (false).
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulBlock is out of range.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedImapEBlockSet(
- uint32_t ulBlock,
- bool fAllocated)
-{
- REDSTATUS ret;
-
- if( gpRedCoreVol->fImapInline
- || (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulOffset = ulBlock - gpRedCoreVol->ulInodeTableStartBN;
- uint32_t ulImapNode = ulOffset / IMAPNODE_ENTRIES;
- IMAPNODE *pImap;
-
- ret = ImapNodeBranch(ulImapNode, &pImap);
-
- if(ret == 0)
- {
- uint32_t ulImapEntry = ulOffset % IMAPNODE_ENTRIES;
-
- if(RedBitGet(pImap->abEntries, ulImapEntry) == fAllocated)
- {
- /* The driver shouldn't ever set a bit in the imap to its
- current value. That shouldn't ever be needed, and it
- indicates that the driver is doing unnecessary I/O, or
- that the imap is corrupt.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else if(fAllocated)
- {
- RedBitSet(pImap->abEntries, ulImapEntry);
- }
- else
- {
- RedBitClear(pImap->abEntries, ulImapEntry);
- }
-
- RedBufferPut(pImap);
- }
- }
-
- return ret;
-}
-
-
-/** @brief Branch an imap node and get a buffer for it.
-
- If the imap node is already branched, it can be overwritten in its current
- location, and this function just gets it buffered dirty. If the node is not
- already branched, the metaroot must be updated to toggle the imap node to
- its alternate location, thereby preserving the committed state copy of the
- imap node.
-
- @param ulImapNode The imap node to branch and buffer.
- @param ppImap On successful return, populated with the imap node
- buffer, which will be marked dirty.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulImapNode is out of range; or @p ppImap is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS ImapNodeBranch(
- uint32_t ulImapNode,
- IMAPNODE **ppImap)
-{
- REDSTATUS ret;
-
- if((ulImapNode >= gpRedCoreVol->ulImapNodeCount) || (ppImap == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(ImapNodeIsBranched(ulImapNode))
- {
- /* Imap node is already branched, so just get it buffered dirty.
- */
- ret = RedBufferGet(RedImapNodeBlock(gpRedCoreVol->bCurMR, ulImapNode), BFLAG_META_IMAP | BFLAG_DIRTY, CAST_VOID_PTR_PTR(ppImap));
- }
- else
- {
- uint32_t ulBlockCurrent;
- uint32_t ulBlockOld;
-
- /* The metaroot currently points to the committed state imap node.
- Toggle the metaroot to point at the alternate, writeable location.
- */
- if(RedBitGet(gpRedMR->abEntries, ulImapNode))
- {
- RedBitClear(gpRedMR->abEntries, ulImapNode);
- }
- else
- {
- RedBitSet(gpRedMR->abEntries, ulImapNode);
- }
-
- ulBlockCurrent = RedImapNodeBlock(gpRedCoreVol->bCurMR, ulImapNode);
- ulBlockOld = RedImapNodeBlock(1U - gpRedCoreVol->bCurMR, ulImapNode);
-
- ret = RedBufferDiscardRange(ulBlockCurrent, 1U);
-
- /* Buffer the committed copy then reassign the block number to the
- writeable location. This also dirties the buffer.
- */
- if(ret == 0)
- {
- ret = RedBufferGet(ulBlockOld, BFLAG_META_IMAP, CAST_VOID_PTR_PTR(ppImap));
-
- if(ret == 0)
- {
- RedBufferBranch(*ppImap, ulBlockCurrent);
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Determine whether an imap node is branched.
-
- If the imap node is branched, it can be overwritten in its current location.
-
- @param ulImapNode The imap node to examine.
-
- @return Whether the imap node is branched.
-*/
-static bool ImapNodeIsBranched(
- uint32_t ulImapNode)
-{
- bool fNodeBitSetInMetaroot0 = RedBitGet(gpRedCoreVol->aMR[0U].abEntries, ulImapNode);
- bool fNodeBitSetInMetaroot1 = RedBitGet(gpRedCoreVol->aMR[1U].abEntries, ulImapNode);
-
- /* If the imap node is not branched, both metaroots will point to the same
- copy of the node.
- */
- return fNodeBitSetInMetaroot0 != fNodeBitSetInMetaroot1;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Calculate the block number of the imap node location indicated by the
- given metaroot.
-
- An imap node has two locations on disk. A bit in the metaroot bitmap
- indicates which location is the valid one, according to that metaroot. This
- function returns the block number of the imap node which is valid in the
- given metaroot.
-
- @param bMR Which metaroot to examine.
- @param ulImapNode The imap node for which to calculate the block number.
-
- @return Block number of the imap node, as indicated by the given metaroot.
-*/
-uint32_t RedImapNodeBlock(
- uint8_t bMR,
- uint32_t ulImapNode)
-{
- uint32_t ulBlock;
-
- REDASSERT(ulImapNode < gpRedCoreVol->ulImapNodeCount);
-
- ulBlock = gpRedCoreVol->ulImapStartBN + (ulImapNode * 2U);
-
- if(bMR > 1U)
- {
- REDERROR();
- }
- else if(RedBitGet(gpRedCoreVol->aMR[bMR].abEntries, ulImapNode))
- {
- /* Bit is set, so point ulBlock at the second copy of the node.
- */
- ulBlock++;
- }
- else
- {
- /* ulBlock already points at the first copy of the node.
- */
- }
-
- return ulBlock;
-}
-
-#endif /* REDCONF_IMAP_EXTERNAL == 1 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapinline.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapinline.c
deleted file mode 100755
index 5e556ba..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/imapinline.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements routines for the inline imap.
-
- The inline imap is used on volumes that are small enough for the imap bitmap
- to be entirely contained within the metaroot.
-*/
-#include
-
-#if REDCONF_IMAP_INLINE == 1
-
-#include
-
-
-/** @brief Get the allocation bit of a block from either metaroot.
-
- @param bMR The metaroot index: either 0 or 1.
- @param ulBlock The block number to query.
- @param pfAllocated On successful return, populated with the allocation bit
- of the block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bMR is out of range; or @p ulBlock is out of range;
- @p pfAllocated is `NULL`; or the current volume does not
- use the inline imap.
-*/
-REDSTATUS RedImapIBlockGet(
- uint8_t bMR,
- uint32_t ulBlock,
- bool *pfAllocated)
-{
- REDSTATUS ret;
-
- if( (!gpRedCoreVol->fImapInline)
- || (bMR > 1U)
- || (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount)
- || (pfAllocated == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- *pfAllocated = RedBitGet(gpRedCoreVol->aMR[bMR].abEntries, ulBlock - gpRedCoreVol->ulInodeTableStartBN);
- ret = 0;
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Set the allocation bit of a block in the working metaroot.
-
- @param ulBlock The block number to allocate or free.
- @param fAllocated Whether to allocate the block (true) or free it (false).
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulBlock is out of range; or the current volume does
- not use the inline imap.
-*/
-REDSTATUS RedImapIBlockSet(
- uint32_t ulBlock,
- bool fAllocated)
-{
- REDSTATUS ret;
-
- if( (!gpRedCoreVol->fImapInline)
- || (ulBlock < gpRedCoreVol->ulInodeTableStartBN)
- || (ulBlock >= gpRedVolume->ulBlockCount))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulOffset = ulBlock - gpRedCoreVol->ulInodeTableStartBN;
-
- if(RedBitGet(gpRedMR->abEntries, ulOffset) == fAllocated)
- {
- /* The driver shouldn't ever set a bit in the imap to its current
- value. This is more of a problem with the external imap, but it
- is checked here for consistency.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else if(fAllocated)
- {
- RedBitSet(gpRedMR->abEntries, ulOffset);
- ret = 0;
- }
- else
- {
- RedBitClear(gpRedMR->abEntries, ulOffset);
- ret = 0;
- }
- }
-
- return ret;
-}
-#endif
-
-#endif /* REDCONF_IMAP_INLINE == 1 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inode.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inode.c
deleted file mode 100755
index 9ff5341..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inode.c
+++ /dev/null
@@ -1,1120 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements inode functions.
-*/
-#include
-#include
-
-
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS InodeIsBranched(uint32_t ulInode, bool *pfIsBranched);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-static REDSTATUS InodeFindFree(uint32_t *pulInode);
-#endif
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS InodeGetWriteableCopy(uint32_t ulInode, uint8_t *pbWhich);
-#endif
-static REDSTATUS InodeGetCurrentCopy(uint32_t ulInode, uint8_t *pbWhich);
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS InodeBitSet(uint32_t ulInode, uint8_t bWhich, bool fAllocated);
-#endif
-static uint32_t InodeBlock(uint32_t ulInode, uint8_t bWhich);
-
-
-/** @brief Mount an existing inode.
-
- Will populate all fields of the cached inode structure, except those which
- are populated during seek.
-
- @param pInode A pointer to the cached inode structure. The
- pInode->ulInode field must already be initialized with the
- inode number to mount. All other fields will be discarded.
- @param type The expected inode type.
- @param fBranch Whether to branch the inode.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL Invalid parameters.
- @retval -RED_EROFS @p fBranch is true but the driver is read-only.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EBADF The inode number is free; or the inode number is not
- valid.
- @retval -RED_EISDIR @p type is ::FTYPE_FILE and the inode is a directory.
- @retval -RED_ENOTDIR @p type is ::FTYPE_DIR and the inode is a file.
-*/
-REDSTATUS RedInodeMount(
- CINODE *pInode,
- FTYPE type,
- bool fBranch)
-{
- REDSTATUS ret = 0;
-
- if(pInode == NULL)
- {
- ret = -RED_EINVAL;
- }
- else if(!INODE_IS_VALID(pInode->ulInode))
- {
- ret = -RED_EBADF;
- }
- #if REDCONF_API_FSE == 1
- else if(type == FTYPE_DIR)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- #endif
- #if REDCONF_READ_ONLY == 1
- else if(fBranch)
- {
- REDERROR();
- ret = -RED_EROFS;
- }
- #endif
- else
- {
- uint32_t ulInode = pInode->ulInode;
- uint8_t bWhich = 0U; /* Init'd to quiet warnings. */
-
- RedMemSet(pInode, 0U, sizeof(*pInode));
- pInode->ulInode = ulInode;
-
- ret = InodeGetCurrentCopy(pInode->ulInode, &bWhich);
-
- if(ret == 0)
- {
- ret = RedBufferGet(InodeBlock(pInode->ulInode, bWhich), BFLAG_META_INODE, CAST_VOID_PTR_PTR(&pInode->pInodeBuf));
- }
-
- #if REDCONF_READ_ONLY == 0
- if(ret == 0)
- {
- ret = InodeIsBranched(pInode->ulInode, &pInode->fBranched);
- }
- #endif
-
- if(ret == 0)
- {
- if(RED_S_ISREG(pInode->pInodeBuf->uMode))
- {
- #if REDCONF_API_POSIX == 1
- pInode->fDirectory = false;
-
- if(type == FTYPE_DIR)
- {
- ret = -RED_ENOTDIR;
- }
- #endif
- }
- #if REDCONF_API_POSIX == 1
- else if(RED_S_ISDIR(pInode->pInodeBuf->uMode))
- {
- pInode->fDirectory = true;
-
- if(type == FTYPE_FILE)
- {
- ret = -RED_EISDIR;
- }
- }
- #endif
- else
- {
- /* Missing or unsupported inode type.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- }
-
- #if REDCONF_READ_ONLY == 0
- if((ret == 0) && fBranch)
- {
- ret = RedInodeBranch(pInode);
- }
- #endif
-
- if(ret != 0)
- {
- RedInodePut(pInode, 0U);
- }
- }
-
- return ret;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED)
-/** @brief Create an inode.
-
- @param pInode Pointer to the cached inode structure. If pInode->ulInode
- is #INODE_INVALID, a free inode will be found; otherwise,
- pInode->ulInode will be the inode number (an error will be
- returned if it is not free).
- @param ulPInode The parent inode number.
- @param uMode The inode mode.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF pInode->ulInode is an invalid inode number other than
- #INODE_INVALID.
- @retval -RED_EINVAL Invalid parameters.
- @retval -RED_EEXIST Tried to create an inode with an inode number that is
- already in use.
- @retval -RED_ENFILE All inode slots are already in use.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeCreate(
- CINODE *pInode,
- uint32_t ulPInode,
- uint16_t uMode)
-{
- REDSTATUS ret;
-
- #if REDCONF_API_POSIX == 1
- /* ulPInode must be a valid inode number, unless we are creating the root
- directory, in which case ulPInode must be INODE_INVALID (the root
- directory has no parent).
- */
- if( (pInode == NULL)
- || (!INODE_IS_VALID(ulPInode) && ((ulPInode != INODE_INVALID) || (pInode->ulInode != INODE_ROOTDIR))))
- #else
- if(pInode == NULL)
- #endif
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulInode = pInode->ulInode;
-
- RedMemSet(pInode, 0U, sizeof(*pInode));
-
- #if REDCONF_API_POSIX == 1
- if(ulInode == INODE_INVALID)
- {
- /* Caller requested that an inode number be allocated. Search for
- an unused inode number, error if there isn't one.
- */
- ret = InodeFindFree(&pInode->ulInode);
- }
- else
- #endif
- {
- /* Caller requested creation of a specific inode number. Make sure
- it's valid and doesn't already exist.
- */
- if(INODE_IS_VALID(ulInode))
- {
- bool fFree;
-
- ret = RedInodeIsFree(ulInode, &fFree);
- if(ret == 0)
- {
- if(fFree)
- {
- pInode->ulInode = ulInode;
- }
- else
- {
- ret = -RED_EEXIST;
- }
- }
- }
- else
- {
- ret = -RED_EBADF;
- }
- }
-
- if(ret == 0)
- {
- uint8_t bWriteableWhich;
-
- ret = InodeGetWriteableCopy(pInode->ulInode, &bWriteableWhich);
-
- if(ret == 0)
- {
- ret = RedBufferGet(InodeBlock(pInode->ulInode, bWriteableWhich),
- (uint16_t)((uint32_t)BFLAG_META_INODE | BFLAG_DIRTY | BFLAG_NEW), CAST_VOID_PTR_PTR(&pInode->pInodeBuf));
-
- if(ret == 0)
- {
- /* Mark the inode block as allocated.
- */
- ret = InodeBitSet(pInode->ulInode, bWriteableWhich, true);
-
- if(ret != 0)
- {
- RedBufferPut(pInode->pInodeBuf);
- }
- }
- }
- }
-
- if(ret == 0)
- {
- #if REDCONF_INODE_TIMESTAMPS == 1
- uint32_t ulNow = RedOsClockGetTime();
-
- pInode->pInodeBuf->ulATime = ulNow;
- pInode->pInodeBuf->ulMTime = ulNow;
- pInode->pInodeBuf->ulCTime = ulNow;
- #endif
-
- pInode->pInodeBuf->uMode = uMode;
-
- #if REDCONF_API_POSIX == 1
- #if REDCONF_API_POSIX_LINK == 1
- pInode->pInodeBuf->uNLink = 1U;
- #endif
- pInode->pInodeBuf->ulPInode = ulPInode;
- #else
- (void)ulPInode;
- #endif
-
- pInode->fBranched = true;
- pInode->fDirty = true;
-
- #if REDCONF_API_POSIX == 1
- gpRedMR->ulFreeInodes--;
- #endif
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED) */
-
-
-#if DELETE_SUPPORTED
-/** @brief Delete an inode.
-
- @param pInode Pointer to the cached inode structure.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF The inode is free.
- @retval -RED_EINVAL @p pInode is `NULL`; or pInode->pBuffer is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeDelete(
- CINODE *pInode)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- if(pInode->pInodeBuf->ullSize != 0U)
- {
- ret = RedInodeDataTruncate(pInode, UINT64_SUFFIX(0));
- }
-
- if(ret == 0)
- {
- ret = RedInodeFree(pInode);
- }
- }
-
- return ret;
-}
-
-
-/** @brief Decrement an inode link count and delete the inode if the link count
- falls to zero.
-
- @param pInode A pointer to the cached inode structure.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pInode is not a mounted cachde inode.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeLinkDec(
- CINODE *pInode)
-{
- REDSTATUS ret;
-
- if(!CINODE_IS_MOUNTED(pInode))
- {
- ret = -RED_EINVAL;
- }
- #if REDCONF_API_POSIX_LINK == 1
- else if(pInode->pInodeBuf->uNLink > 1U)
- {
- ret = RedInodeBranch(pInode);
-
- if(ret == 0)
- {
- pInode->pInodeBuf->uNLink--;
- }
- }
- #endif
- else
- {
- ret = RedInodeDelete(pInode);
- }
-
- return ret;
-}
-#endif /* DELETE_SUPPORTED */
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-/** @brief Free an inode.
-
- @param pInode Pointer to the cached inode structure.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF The inode is free.
- @retval -RED_EINVAL @p pInode is `NULL`; or pInode->pBuffer is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeFree(
- CINODE *pInode)
-{
- REDSTATUS ret;
-
- if(!CINODE_IS_MOUNTED(pInode))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- bool fSlot0Allocated;
-
- RedBufferDiscard(pInode->pInodeBuf);
- pInode->pInodeBuf = NULL;
-
- /* Determine which of the two slots for the inode is currently
- allocated, and free that slot.
- */
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, pInode->ulInode, 0U, &fSlot0Allocated);
-
- if(ret == 0)
- {
- bool fSlot1Allocated;
-
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, pInode->ulInode, 1U, &fSlot1Allocated);
-
- if(ret == 0)
- {
- if(fSlot0Allocated)
- {
- if(fSlot1Allocated)
- {
- /* Both inode slots should never be allocated at
- the same time.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- ret = InodeBitSet(pInode->ulInode, 0U, false);
- }
- }
- else
- {
- if(!fSlot1Allocated)
- {
- /* The inode in unallocated, which should have been
- caught when it was mounted.
- */
- CRITICAL_ERROR();
- ret = -RED_EBADF;
- }
- else
- {
- ret = InodeBitSet(pInode->ulInode, 1U, false);
- }
- }
- }
- }
-
- pInode->ulInode = INODE_INVALID;
-
- if(ret == 0)
- {
- if(gpRedMR->ulFreeInodes >= gpRedVolConf->ulInodeCount)
- {
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- gpRedMR->ulFreeInodes++;
- }
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) */
-
-
-/** @brief Put the cached inode structure.
-
- This puts all of the buffers in the ::CINODE structure. Also updates inode
- timestamp fields if requested.
-
- @param pInode The cached inode structure.
- @param bTimeFields The inode timestamp fields to update.
-*/
-void RedInodePut(
- CINODE *pInode,
- uint8_t bTimeFields)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else
- {
- RedInodePutCoord(pInode);
-
- if(pInode->pInodeBuf != NULL)
- {
- #if (REDCONF_READ_ONLY == 0) && (REDCONF_INODE_TIMESTAMPS == 1)
- if((bTimeFields & IPUT_UPDATE_MASK) != 0U)
- {
- if(!pInode->fBranched || !pInode->fDirty)
- {
- REDERROR();
- }
- else
- {
- uint32_t ulNow = RedOsClockGetTime();
-
- #if REDCONF_ATIME == 1
- if((bTimeFields & IPUT_UPDATE_ATIME) != 0U)
- {
- pInode->pInodeBuf->ulATime = ulNow;
- }
- #endif
-
- if((bTimeFields & IPUT_UPDATE_MTIME) != 0U)
- {
- pInode->pInodeBuf->ulMTime = ulNow;
- }
-
- if((bTimeFields & IPUT_UPDATE_CTIME) != 0U)
- {
- pInode->pInodeBuf->ulCTime = ulNow;
- }
- }
- }
- #else
- (void)bTimeFields;
- #endif
-
- RedBufferPut(pInode->pInodeBuf);
- pInode->pInodeBuf = NULL;
- }
- }
-}
-
-
-/** @brief Put all buffers in the cached inode structure except for the inode
- node buffer.
-
- @param pInode A pointer to the cached inode structure.
-*/
-void RedInodePutCoord(
- CINODE *pInode)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else
- {
- RedInodePutData(pInode);
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- RedInodePutIndir(pInode);
- #endif
- #if DINDIR_POINTERS > 0U
- RedInodePutDindir(pInode);
- #endif
- }
-}
-
-
-#if DINDIR_POINTERS > 0U
-/** @brief Put the double indirect buffer.
-
- @param pInode A pointer to the cached inode structure.
-*/
-void RedInodePutDindir(
- CINODE *pInode)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else if(pInode->pDindir != NULL)
- {
- RedBufferPut(pInode->pDindir);
- pInode->pDindir = NULL;
- }
- else
- {
- /* No double indirect buffer, nothing to put.
- */
- }
-}
-#endif
-
-
-#if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
-/** @brief Put the indirect buffer.
-
- @param pInode A pointer to the cached inode structure.
-*/
-void RedInodePutIndir(
- CINODE *pInode)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else if(pInode->pIndir != NULL)
- {
- RedBufferPut(pInode->pIndir);
- pInode->pIndir = NULL;
- }
- else
- {
- /* No indirect buffer, nothing to put.
- */
- }
-}
-#endif
-
-
-/** @brief Put the inode data buffer.
-
- @param pInode A pointer to the cached inode structure.
-*/
-void RedInodePutData(
- CINODE *pInode)
-{
- if(pInode == NULL)
- {
- REDERROR();
- }
- else if(pInode->pbData != NULL)
- {
- RedBufferPut(pInode->pbData);
- pInode->pbData = NULL;
- }
- else
- {
- /* No data buffer, nothing to put.
- */
- }
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Determine if an inode is branched.
-
- @param ulInode The inode number to examine.
- @param pfIsBranched On successful return, populated with whether the inode
- is branched.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pInode is `NULL`; or @p ulInode is not a valid inode
- number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS InodeIsBranched(
- uint32_t ulInode,
- bool *pfIsBranched)
-{
- REDSTATUS ret;
-
- if(!INODE_IS_VALID(ulInode) || (pfIsBranched == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ALLOCSTATE state;
-
- ret = RedImapBlockState(InodeBlock(ulInode, 0U), &state);
-
- if(ret == 0)
- {
- if(state == ALLOCSTATE_NEW)
- {
- *pfIsBranched = true;
- }
- else
- {
- ret = RedImapBlockState(InodeBlock(ulInode, 1U), &state);
-
- if(ret == 0)
- {
- if(state == ALLOCSTATE_NEW)
- {
- *pfIsBranched = true;
- }
- else
- {
- *pfIsBranched = false;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Branch an inode.
-
- A branched inode is one in which the allocation state for one copy is free
- or almost free, and the other copy is in the new state. The copy which is
- in the new state is the writeable copy, which is also buffered and dirty.
-
- @param pInode Pointer to the cached inode structure which has already been
- mounted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL Invalid parameters.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeBranch(
- CINODE *pInode)
-{
- REDSTATUS ret;
-
- if(!CINODE_IS_MOUNTED(pInode))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(!pInode->fBranched)
- {
- uint8_t bWhich;
-
- ret = InodeGetWriteableCopy(pInode->ulInode, &bWhich);
-
- if(ret == 0)
- {
- RedBufferBranch(pInode->pInodeBuf, InodeBlock(pInode->ulInode, bWhich));
- pInode->fBranched = true;
- pInode->fDirty = true;
- }
-
- /* Toggle the inode slots: the old slot block becomes almost free
- (still used by the committed state) and the new slot block becomes
- new.
- */
- if(ret == 0)
- {
- ret = InodeBitSet(pInode->ulInode, 1U - bWhich, false);
- }
-
- if(ret == 0)
- {
- ret = InodeBitSet(pInode->ulInode, bWhich, true);
- }
-
- CRITICAL_ASSERT(ret == 0);
- }
- else
- {
- RedBufferDirty(pInode->pInodeBuf);
- pInode->fDirty = true;
- ret = 0;
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-/** @brief Find a free inode number.
-
- @param pulInode On successful return, populated with a free inode number.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pulInode is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENFILE No available inode numbers.
-*/
-static REDSTATUS InodeFindFree(
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if(pulInode == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(gpRedMR->ulFreeInodes == 0U)
- {
- ret = -RED_ENFILE;
- }
- else
- {
- uint32_t ulInode;
-
- ret = 0;
-
- for(ulInode = INODE_FIRST_FREE; ulInode < (INODE_FIRST_VALID + gpRedVolConf->ulInodeCount); ulInode++)
- {
- bool fFree;
-
- ret = RedInodeIsFree(ulInode, &fFree);
-
- if((ret != 0) || fFree)
- {
- break;
- }
- }
-
- if(ret == 0)
- {
- if(ulInode < (INODE_FIRST_VALID + gpRedVolConf->ulInodeCount))
- {
- *pulInode = ulInode;
- }
- else
- {
- /* If gpRedMR->ulFreeInodes > 0, we should have found an inode.
- */
- CRITICAL_ERROR();
- ret = -RED_ENFILE;
- }
- }
- }
-
- return ret;
-}
-#endif
-
-
-#if ((REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED)) || (REDCONF_CHECKER == 1)
-/** @brief Determine whether an inode number is available.
-
- @param ulInode The node number to examine.
- @param pfFree On successful return, populated with whether the inode
- number is available (true) or in use (false).
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pfFree is `NULL`; or @p ulInode is not a valid inode
- number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeIsFree(
- uint32_t ulInode,
- bool *pfFree)
-{
- REDSTATUS ret;
-
- if(pfFree == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- bool fSlot0Allocated;
-
- *pfFree = false;
-
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, ulInode, 0U, &fSlot0Allocated);
- if((ret == 0) && !fSlot0Allocated)
- {
- bool fSlot1Allocated;
-
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, ulInode, 1U, &fSlot1Allocated);
- if((ret == 0) && !fSlot1Allocated)
- {
- *pfFree = true;
- }
- }
- }
-
- return ret;
-}
-#endif
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Determine which copy of the inode is currently writeable.
-
- @param ulInode The inode number to examine.
- @param pbWhich On successful return, populated with which copy of the inode
- (either 0 or 1) is writeable.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pbWhich is `NULL`; or ulInode is not a valid inode
- number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS InodeGetWriteableCopy(
- uint32_t ulInode,
- uint8_t *pbWhich)
-{
- REDSTATUS ret;
-
- if(pbWhich == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- bool fSlot0Allocated;
-
- /* The writeable inode slot is the one which is free in the committed
- state, so query the committed state metaroot.
- */
- ret = RedInodeBitGet(1U - gpRedCoreVol->bCurMR, ulInode, 0U, &fSlot0Allocated);
-
- if(ret == 0)
- {
- if(!fSlot0Allocated)
- {
- *pbWhich = 0U;
- }
- else
- {
- bool fSlot1Allocated;
-
- ret = RedInodeBitGet(1U - gpRedCoreVol->bCurMR, ulInode, 1U, &fSlot1Allocated);
-
- if(ret == 0)
- {
- if(!fSlot1Allocated)
- {
- *pbWhich = 1U;
- }
- else
- {
- /* Both inode slots were allocated, which should never
- happen.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- }
- }
- }
- }
-
- return ret;
-}
-#endif
-
-
-/** @brief Determine which copy of the inode is current.
-
- @param ulInode The inode number to examine.
- @param pbWhich On successful return, populated with which copy of the inode
- (either 0 or 1) is current.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is an unallocated inode number.
- @retval -RED_EINVAL @p pbWhich is `NULL`; or ulInode is not a valid inode
- number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS InodeGetCurrentCopy(
- uint32_t ulInode,
- uint8_t *pbWhich)
-{
- REDSTATUS ret;
-
- if(pbWhich == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- bool fSlot0Allocated;
-
- /* The current inode slot is the one which is allocated in the working
- state metaroot.
- */
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, ulInode, 0U, &fSlot0Allocated);
- if(ret == 0)
- {
- if(fSlot0Allocated)
- {
- *pbWhich = 0U;
- }
- else
- {
- bool fSlot1Allocated;
-
- ret = RedInodeBitGet(gpRedCoreVol->bCurMR, ulInode, 1U, &fSlot1Allocated);
- if(ret == 0)
- {
- if(fSlot1Allocated)
- {
- *pbWhich = 1U;
- }
- else
- {
- /* Neither slot for this inode was allocated, so the
- inode is actually free.
- */
- ret = -RED_EBADF;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Get whether a copy of an inode is allocated.
-
- @param bMR The metaroot index: either 0 or 1.
- @param ulInode The inode number.
- @param bWhich Which copy of the inode to get.
- @param pfAllocated On successful return, populated with whether the given
- copy of the inode is allocated.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bMR is not 1 or 0; @p ulInode is not a valid inode
- number; or @p bWhich is not 1 or 0; or @p pfAllocated is
- `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeBitGet(
- uint8_t bMR,
- uint32_t ulInode,
- uint8_t bWhich,
- bool *pfAllocated)
-{
- REDSTATUS ret;
-
- if(!INODE_IS_VALID(ulInode) || (bWhich > 1U))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedImapBlockGet(bMR, InodeBlock(ulInode, bWhich), pfAllocated);
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Set whether a copy of an inode is allocated.
-
- @param ulInode The inode number.
- @param bWhich Which copy of the inode to set.
- @param fAllocated If true, the inode is set to allocated; if false, the
- inode is set to free.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p ulInode is not a valid inode number; or @p bWhich is
- not 1 or 0.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS InodeBitSet(
- uint32_t ulInode,
- uint8_t bWhich,
- bool fAllocated)
-{
- REDSTATUS ret;
-
- if(!INODE_IS_VALID(ulInode) || (bWhich > 1U))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedImapBlockSet(InodeBlock(ulInode, bWhich), fAllocated);
- }
-
- return ret;
-}
-#endif
-
-
-/** @brief Determine the block number of an inode.
-
- @param ulInode The inode number.
- @param bWhich Which copy of the inode.
-
- @return The block number of the inode.
-*/
-static uint32_t InodeBlock(
- uint32_t ulInode,
- uint8_t bWhich)
-{
- REDASSERT(INODE_IS_VALID(ulInode));
- REDASSERT(bWhich <= 1U);
-
- return gpRedCoreVol->ulInodeTableStartBN + ((ulInode - INODE_FIRST_VALID) * 2U) + bWhich;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inodedata.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inodedata.c
deleted file mode 100755
index a5b9762..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/inodedata.c
+++ /dev/null
@@ -1,1917 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements inode I/O functions.
-*/
-#include
-#include
-
-
-/* This value is used to initialize the uIndirEntry and uDindirEntry members of
- the CINODE structure. After seeking, a value of COORD_ENTRY_INVALID in
- uIndirEntry indicates that there is no indirect node in the path through the
- file metadata structure, and a value of COORD_ENTRY_INVALID in uDindirEntry
- indicates that there is no double indirect node.
-*/
-#define COORD_ENTRY_INVALID (UINT16_MAX)
-
-/* This enumeration is used by the BranchBlock() and BranchBlockCost()
- functions to determine which blocks of the file metadata structure need to
- be branched, and which to ignore. DINDIR requires requires branching the
- double indirect only, INDIR requires branching the double indirect
- (if present) and the indirect, and FILE_DATA requires branching the indirect
- and double indirect (if present) and the file data block.
-*/
-typedef enum
-{
- BRANCHDEPTH_DINDIR = 0U,
- BRANCHDEPTH_INDIR = 1U,
- BRANCHDEPTH_FILE_DATA = 2U,
- BRANCHDEPTH_MAX = BRANCHDEPTH_FILE_DATA
-} BRANCHDEPTH;
-
-
-#if REDCONF_READ_ONLY == 0
-#if DELETE_SUPPORTED || TRUNCATE_SUPPORTED
-static REDSTATUS Shrink(CINODE *pInode, uint64_t ullSize);
-#if DINDIR_POINTERS > 0U
-static REDSTATUS TruncDindir(CINODE *pInode, bool *pfFreed);
-#endif
-#if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
-static REDSTATUS TruncIndir(CINODE *pInode, bool *pfFreed);
-#endif
-static REDSTATUS TruncDataBlock(const CINODE *pInode, uint32_t *pulBlock, bool fPropagate);
-#endif
-static REDSTATUS ExpandPrepare(CINODE *pInode);
-#endif
-static void SeekCoord(CINODE *pInode, uint32_t ulBlock);
-static REDSTATUS ReadUnaligned(CINODE *pInode, uint64_t ullStart, uint32_t ulLen, uint8_t *pbBuffer);
-static REDSTATUS ReadAligned(CINODE *pInode, uint32_t ulBlockStart, uint32_t ulBlockCount, uint8_t *pbBuffer);
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS WriteUnaligned(CINODE *pInode, uint64_t ullStart, uint32_t ulLen, const uint8_t *pbBuffer);
-static REDSTATUS WriteAligned(CINODE *pInode, uint32_t ulBlockStart, uint32_t *pulBlockCount, const uint8_t *pbBuffer);
-#endif
-static REDSTATUS GetExtent(CINODE *pInode, uint32_t ulBlockStart, uint32_t *pulExtentStart, uint32_t *pulExtentLen);
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS BranchBlock(CINODE *pInode, BRANCHDEPTH depth, bool fBuffer);
-static REDSTATUS BranchOneBlock(uint32_t *pulBlock, void **ppBuffer, uint16_t uBFlag);
-static REDSTATUS BranchBlockCost(const CINODE *pInode, BRANCHDEPTH depth, uint32_t *pulCost);
-static uint32_t FreeBlockCount(void);
-#endif
-
-
-/** @brief Read data from an inode.
-
- @param pInode A pointer to the cached inode structure of the inode from
- which to read.
- @param ullStart The file offset at which to read.
- @param pulLen On input, the number of bytes to attempt to read. On
- successful return, populated with the number of bytes
- actually read.
- @param pBuffer The buffer to read into.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL @p pInode is not a mounted cached inode pointer; or
- @p pulLen is `NULL`; or @p pBuffer is `NULL`.
-*/
-REDSTATUS RedInodeDataRead(
- CINODE *pInode,
- uint64_t ullStart,
- uint32_t *pulLen,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || (pulLen == NULL) || (pBuffer == NULL))
- {
- ret = -RED_EINVAL;
- }
- else if(ullStart >= pInode->pInodeBuf->ullSize)
- {
- *pulLen = 0U;
- }
- else if(*pulLen == 0U)
- {
- /* Do nothing, just return success.
- */
- }
- else
- {
- uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
- uint32_t ulReadIndex = 0U;
- uint32_t ulLen = *pulLen;
- uint32_t ulRemaining;
-
- /* Reading beyond the end of the file is not allowed. If the requested
- read extends beyond the end of the file, truncate the read length so
- that the read stops at the end of the file.
- */
- if((pInode->pInodeBuf->ullSize - ullStart) < ulLen)
- {
- ulLen = (uint32_t)(pInode->pInodeBuf->ullSize - ullStart);
- }
-
- ulRemaining = ulLen;
-
- /* Unaligned partial block at start.
- */
- if((ullStart & (REDCONF_BLOCK_SIZE - 1U)) != 0U)
- {
- uint32_t ulBytesInFirstBlock = REDCONF_BLOCK_SIZE - (uint32_t)(ullStart & (REDCONF_BLOCK_SIZE - 1U));
- uint32_t ulThisRead = REDMIN(ulRemaining, ulBytesInFirstBlock);
-
- ret = ReadUnaligned(pInode, ullStart, ulThisRead, pbBuffer);
-
- if(ret == 0)
- {
- ulReadIndex += ulThisRead;
- ulRemaining -= ulThisRead;
- }
- }
-
- /* Whole blocks.
- */
- if((ret == 0) && (ulRemaining >= REDCONF_BLOCK_SIZE))
- {
- uint32_t ulBlockOffset = (uint32_t)((ullStart + ulReadIndex) >> BLOCK_SIZE_P2);
- uint32_t ulBlockCount = ulRemaining >> BLOCK_SIZE_P2;
-
- REDASSERT(((ullStart + ulReadIndex) & (REDCONF_BLOCK_SIZE - 1U)) == 0U);
-
- ret = ReadAligned(pInode, ulBlockOffset, ulBlockCount, &pbBuffer[ulReadIndex]);
-
- if(ret == 0)
- {
- ulReadIndex += ulBlockCount << BLOCK_SIZE_P2;
- ulRemaining -= ulBlockCount << BLOCK_SIZE_P2;
- }
- }
-
- /* Aligned partial block at end.
- */
- if((ret == 0) && (ulRemaining > 0U))
- {
- REDASSERT(ulRemaining < REDCONF_BLOCK_SIZE);
- REDASSERT(((ullStart + ulReadIndex) & (REDCONF_BLOCK_SIZE - 1U)) == 0U);
-
- ret = ReadUnaligned(pInode, ullStart + ulReadIndex, ulRemaining, &pbBuffer[ulReadIndex]);
- }
-
- if(ret == 0)
- {
- *pulLen = ulLen;
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write to an inode.
-
- @param pInode A pointer to the cached inode structure of the inode into
- which to write.
- @param ullStart The file offset at which to write.
- @param pulLen On input, the number of bytes to attempt to write. On
- successful return, populated with the number of bytes
- actually written.
- @param pBuffer The buffer to write from.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EFBIG @p ullStart is greater than the maximum file size; or
- @p ullStart is equal to the maximum file size and the
- write length is non-zero.
- @retval -RED_EINVAL @p pInode is not a mounted cached inode pointer; or
- @p pulLen is `NULL`; or @p pBuffer is `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
-*/
-REDSTATUS RedInodeDataWrite(
- CINODE *pInode,
- uint64_t ullStart,
- uint32_t *pulLen,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_DIRTY(pInode) || (pulLen == NULL) || (pBuffer == NULL))
- {
- ret = -RED_EINVAL;
- }
- else if((ullStart > INODE_SIZE_MAX) || ((ullStart == INODE_SIZE_MAX) && (*pulLen > 0U)))
- {
- ret = -RED_EFBIG;
- }
- else if(*pulLen == 0U)
- {
- /* Do nothing, just return success.
- */
- }
- else
- {
- const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
- uint32_t ulWriteIndex = 0U;
- uint32_t ulLen = *pulLen;
- uint32_t ulRemaining;
-
- if((INODE_SIZE_MAX - ullStart) < ulLen)
- {
- ulLen = (uint32_t)(INODE_SIZE_MAX - ullStart);
- }
-
- ulRemaining = ulLen;
-
- /* If the write is beyond the current end of the file, and the current
- end of the file is not block-aligned, then there may be some data
- that needs to be zeroed in the last block.
- */
- if(ullStart > pInode->pInodeBuf->ullSize)
- {
- ret = ExpandPrepare(pInode);
- }
-
- /* Partial block at start.
- */
- if((ret == 0) && (((ullStart & (REDCONF_BLOCK_SIZE - 1U)) != 0U) || (ulRemaining < REDCONF_BLOCK_SIZE)))
- {
- uint32_t ulBytesInFirstBlock = REDCONF_BLOCK_SIZE - (uint32_t)(ullStart & (REDCONF_BLOCK_SIZE - 1U));
- uint32_t ulThisWrite = REDMIN(ulRemaining, ulBytesInFirstBlock);
-
- ret = WriteUnaligned(pInode, ullStart, ulThisWrite, pbBuffer);
-
- if(ret == 0)
- {
- ulWriteIndex += ulThisWrite;
- ulRemaining -= ulThisWrite;
- }
- }
-
- /* Whole blocks.
- */
- if((ret == 0) && (ulRemaining >= REDCONF_BLOCK_SIZE))
- {
- uint32_t ulBlockOffset = (uint32_t)((ullStart + ulWriteIndex) >> BLOCK_SIZE_P2);
- uint32_t ulBlockCount = ulRemaining >> BLOCK_SIZE_P2;
- uint32_t ulBlocksWritten = ulBlockCount;
-
- REDASSERT(((ullStart + ulWriteIndex) & (REDCONF_BLOCK_SIZE - 1U)) == 0U);
-
- ret = WriteAligned(pInode, ulBlockOffset, &ulBlocksWritten, &pbBuffer[ulWriteIndex]);
-
- if((ret == -RED_ENOSPC) && (ulWriteIndex > 0U))
- {
- ulBlocksWritten = 0U;
- ret = 0;
- }
-
- if(ret == 0)
- {
- ulWriteIndex += ulBlocksWritten << BLOCK_SIZE_P2;
- ulRemaining -= ulBlocksWritten << BLOCK_SIZE_P2;
-
- if(ulBlocksWritten < ulBlockCount)
- {
- ulRemaining = 0U;
- }
- }
- }
-
- /* Partial block at end.
- */
- if((ret == 0) && (ulRemaining > 0U))
- {
- REDASSERT(ulRemaining < REDCONF_BLOCK_SIZE);
- REDASSERT(((ullStart + ulWriteIndex) & (REDCONF_BLOCK_SIZE - 1U)) == 0U);
- REDASSERT(ulWriteIndex > 0U);
-
- ret = WriteUnaligned(pInode, ullStart + ulWriteIndex, ulRemaining, &pbBuffer[ulWriteIndex]);
-
- if(ret == -RED_ENOSPC)
- {
- ret = 0;
- }
- else if(ret == 0)
- {
- ulWriteIndex += ulRemaining;
-
- REDASSERT(ulWriteIndex == ulLen);
- }
- else
- {
- /* Unexpected error, return it.
- */
- }
- }
-
- if(ret == 0)
- {
- *pulLen = ulWriteIndex;
-
- if((ullStart + ulWriteIndex) > pInode->pInodeBuf->ullSize)
- {
- pInode->pInodeBuf->ullSize = ullStart + ulWriteIndex;
- }
- }
- }
-
- return ret;
-}
-
-
-#if DELETE_SUPPORTED || TRUNCATE_SUPPORTED
-/** @brief Change the size of an inode.
-
- @param pInode A pointer to the cached inode structure.
- @praam ullSize The new file size for the inode.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EFBIG @p ullSize is greater than the maximum file size.
- @retval -RED_EINVAL @p pInode is not a mounted cached inode pointer.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
-*/
-REDSTATUS RedInodeDataTruncate(
- CINODE *pInode,
- uint64_t ullSize)
-{
- REDSTATUS ret = 0;
-
- /* The inode does not need to be dirtied when it is being deleted, because
- the inode buffer will be discarded without ever being written to disk.
- Thus, we only check to see if it's mounted here.
- */
- if(!CINODE_IS_MOUNTED(pInode))
- {
- ret = -RED_EINVAL;
- }
- else if(ullSize > INODE_SIZE_MAX)
- {
- ret = -RED_EFBIG;
- }
- else
- {
- if(ullSize > pInode->pInodeBuf->ullSize)
- {
- ret = ExpandPrepare(pInode);
- }
- else if(ullSize < pInode->pInodeBuf->ullSize)
- {
- ret = Shrink(pInode, ullSize);
- }
- else
- {
- /* Size is staying the same, nothing to do.
- */
- }
-
- if(ret == 0)
- {
- pInode->pInodeBuf->ullSize = ullSize;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Free all file data beyond a specified point.
-
- @param pInode A pointer to the cached inode structure.
- @param ullSize The point beyond which to free all file data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS Shrink(
- CINODE *pInode,
- uint64_t ullSize)
-{
- REDSTATUS ret = 0;
-
- /* pInode->fDirty is checked explicitly here, instead of using the
- CINODE_IS_DIRTY() macro, to avoid a duplicate mount check.
- */
- if(!CINODE_IS_MOUNTED(pInode) || ((ullSize > 0U) && !pInode->fDirty))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulTruncBlock = (uint32_t)((ullSize + REDCONF_BLOCK_SIZE - 1U) >> BLOCK_SIZE_P2);
-
- RedInodePutData(pInode);
-
- #if REDCONF_DIRECT_POINTERS > 0U
- while(ulTruncBlock < REDCONF_DIRECT_POINTERS)
- {
- ret = TruncDataBlock(pInode, &pInode->pInodeBuf->aulEntries[ulTruncBlock], true);
-
- if(ret != 0)
- {
- break;
- }
-
- ulTruncBlock++;
- }
- #endif
-
- #if REDCONF_INDIRECT_POINTERS > 0U
- while((ret == 0) && (ulTruncBlock < (REDCONF_DIRECT_POINTERS + INODE_INDIR_BLOCKS)))
- {
- ret = RedInodeDataSeek(pInode, ulTruncBlock);
-
- if((ret == 0) || (ret == -RED_ENODATA))
- {
- bool fFreed;
-
- ret = TruncIndir(pInode, &fFreed);
-
- if(ret == 0)
- {
- if(fFreed)
- {
- pInode->pInodeBuf->aulEntries[pInode->uInodeEntry] = BLOCK_SPARSE;
- }
-
- /* The next seek will go to the beginning of the next
- indirect.
- */
- ulTruncBlock += (INDIR_ENTRIES - pInode->uIndirEntry);
- }
- }
- }
- #endif
-
- #if DINDIR_POINTERS > 0U
- while((ret == 0) && (ulTruncBlock < INODE_DATA_BLOCKS))
- {
- ret = RedInodeDataSeek(pInode, ulTruncBlock);
-
- if((ret == 0) || (ret == -RED_ENODATA))
- {
- bool fFreed;
-
- /* TruncDindir() invokes seek as it goes along, which will
- update the entry values (possibly all three of these);
- make a copy so we can compute things correctly after.
- */
- uint16_t uOrigInodeEntry = pInode->uInodeEntry;
- uint16_t uOrigDindirEntry = pInode->uDindirEntry;
- uint16_t uOrigIndirEntry = pInode->uIndirEntry;
-
- ret = TruncDindir(pInode, &fFreed);
-
- if(ret == 0)
- {
- if(fFreed)
- {
- pInode->pInodeBuf->aulEntries[uOrigInodeEntry] = BLOCK_SPARSE;
- }
-
- /* The next seek will go to the beginning of the next
- double indirect.
- */
- ulTruncBlock += (DINDIR_DATA_BLOCKS - (uOrigDindirEntry * INDIR_ENTRIES)) - uOrigIndirEntry;
- }
- }
- }
- #endif
- }
-
- return ret;
-}
-
-
-#if DINDIR_POINTERS > 0U
-/** @brief Truncate a double indirect.
-
- @param pInode A pointer to the cached inode, whose coordinates indicate
- the truncation boundary.
- @param pfFreed On successful return, populated with whether the double
- indirect node was freed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS TruncDindir(
- CINODE *pInode,
- bool *pfFreed)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || (pfFreed == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(pInode->pDindir == NULL)
- {
- *pfFreed = false;
- }
- else
- {
- bool fBranch = false;
- uint16_t uEntry;
-
- /* The double indirect is definitely going to be branched (instead of
- deleted) if any of its indirect pointers which are entirely prior to
- the truncation boundary are non-sparse.
- */
- for(uEntry = 0U; !fBranch && (uEntry < pInode->uDindirEntry); uEntry++)
- {
- fBranch = pInode->pDindir->aulEntries[uEntry] != BLOCK_SPARSE;
- }
-
- /* Unless we already know for a fact that the double indirect is going
- to be branched, examine the contents of the indirect pointer which
- straddles the truncation boundary. If the indirect is going to be
- deleted, we know this indirect pointer is going away, and that might
- mean the double indirect is going to be deleted also.
- */
- if(!fBranch && (pInode->pDindir->aulEntries[pInode->uDindirEntry] != BLOCK_SPARSE))
- {
- for(uEntry = 0U; !fBranch && (uEntry < pInode->uIndirEntry); uEntry++)
- {
- fBranch = pInode->pIndir->aulEntries[uEntry] != BLOCK_SPARSE;
- }
- }
-
- if(fBranch)
- {
- ret = BranchBlock(pInode, BRANCHDEPTH_DINDIR, false);
- }
-
- if(ret == 0)
- {
- uint32_t ulBlock = pInode->ulLogicalBlock;
- uint16_t uStart = pInode->uDindirEntry; /* pInode->uDindirEntry will change. */
-
- for(uEntry = uStart; uEntry < INDIR_ENTRIES; uEntry++)
- {
- /* Seek so that TruncIndir() has the correct indirect
- buffer and indirect entry.
- */
- ret = RedInodeDataSeek(pInode, ulBlock);
-
- if(ret == -RED_ENODATA)
- {
- ret = 0;
- }
-
- if((ret == 0) && (pInode->ulIndirBlock != BLOCK_SPARSE))
- {
- bool fIndirFreed;
-
- ret = TruncIndir(pInode, &fIndirFreed);
-
- if(ret == 0)
- {
- /* All of the indirects after the one which straddles
- the truncation boundary should definitely end up
- deleted.
- */
- REDASSERT((uEntry == uStart) || fIndirFreed);
-
- /* If the double indirect is being freed, all of the
- indirects should be freed too.
- */
- REDASSERT(fIndirFreed || fBranch);
-
- if(fBranch && fIndirFreed)
- {
- pInode->pDindir->aulEntries[uEntry] = BLOCK_SPARSE;
- }
- }
- }
-
- if(ret != 0)
- {
- break;
- }
-
- ulBlock += (INDIR_ENTRIES - pInode->uIndirEntry);
- }
-
- if(ret == 0)
- {
- *pfFreed = !fBranch;
-
- if(!fBranch)
- {
- RedInodePutDindir(pInode);
-
- ret = RedImapBlockSet(pInode->ulDindirBlock, false);
- }
- }
- }
- }
-
- return ret;
-}
-#endif /* DINDIR_POINTERS > 0U */
-
-
-#if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
-/** @brief Truncate a indirect.
-
- @param pInode A pointer to the cached inode, whose coordinates indicate
- the truncation boundary.
- @param pfFreed On successful return, populated with whether the indirect
- node was freed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS TruncIndir(
- CINODE *pInode,
- bool *pfFreed)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || (pfFreed == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(pInode->pIndir == NULL)
- {
- *pfFreed = false;
- }
- else
- {
- bool fBranch = false;
- uint16_t uEntry;
-
- /* Scan the range of entries which are not being truncated. If there
- is anything there, then the indirect will not be empty after the
- truncate, so it is branched and modified instead of deleted.
- */
- for(uEntry = 0U; !fBranch && (uEntry < pInode->uIndirEntry); uEntry++)
- {
- fBranch = pInode->pIndir->aulEntries[uEntry] != BLOCK_SPARSE;
- }
-
- if(fBranch)
- {
- ret = BranchBlock(pInode, BRANCHDEPTH_INDIR, false);
- }
-
- if(ret == 0)
- {
- for(uEntry = pInode->uIndirEntry; uEntry < INDIR_ENTRIES; uEntry++)
- {
- ret = TruncDataBlock(pInode, &pInode->pIndir->aulEntries[uEntry], fBranch);
-
- if(ret != 0)
- {
- break;
- }
- }
-
- if(ret == 0)
- {
- *pfFreed = !fBranch;
-
- if(!fBranch)
- {
- RedInodePutIndir(pInode);
-
- ret = RedImapBlockSet(pInode->ulIndirBlock, false);
- }
- }
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_DIRECT_POINTERS < INODE_ENTRIES */
-
-
-/** @brief Truncate a file data block.
-
- @param pInode A pointer to the cached inode structure.
- @param pulBlock On entry, contains the block to be truncated. On
- successful return, if @p fPropagate is true, populated
- with BLOCK_SPARSE, otherwise unmodified.
- @param fPropagate Whether the parent node is being branched.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS TruncDataBlock(
- const CINODE *pInode,
- uint32_t *pulBlock,
- bool fPropagate)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || (pulBlock == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(*pulBlock != BLOCK_SPARSE)
- {
- ret = RedImapBlockSet(*pulBlock, false);
-
- #if REDCONF_INODE_BLOCKS == 1
- if(ret == 0)
- {
- if(pInode->pInodeBuf->ulBlocks == 0U)
- {
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- pInode->pInodeBuf->ulBlocks--;
- }
- }
- #endif
-
- if((ret == 0) && fPropagate)
- {
- *pulBlock = BLOCK_SPARSE;
- }
- }
- else
- {
- /* Data block is sparse, nothing to truncate.
- */
- }
-
- return ret;
-}
-#endif /* DELETE_SUPPORTED || TRUNCATE_SUPPORTED */
-
-
-/** @brief Prepare to increase the file size.
-
- When the inode size is increased, a sparse region is created. It is
- possible that a prior shrink operation to an unaligned size left stale data
- beyond the end of the file in the last data block. That data is not zeroed
- while shrinking the inode in order to transfer the disk full burden from the
- shrink operation to the expand operation.
-
- @param pInode A pointer to the cached inode structure.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS ExpandPrepare(
- CINODE *pInode)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_DIRTY(pInode))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulOldSizeByteInBlock = (uint32_t)(pInode->pInodeBuf->ullSize & (REDCONF_BLOCK_SIZE - 1U));
-
- if(ulOldSizeByteInBlock != 0U)
- {
- ret = RedInodeDataSeek(pInode, (uint32_t)(pInode->pInodeBuf->ullSize >> BLOCK_SIZE_P2));
-
- if(ret == -RED_ENODATA)
- {
- ret = 0;
- }
- else if(ret == 0)
- {
- ret = BranchBlock(pInode, BRANCHDEPTH_FILE_DATA, true);
-
- if(ret == 0)
- {
- RedMemSet(&pInode->pbData[ulOldSizeByteInBlock], 0U, REDCONF_BLOCK_SIZE - ulOldSizeByteInBlock);
- }
- }
- else
- {
- REDERROR();
- }
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Seek to a given position within an inode, then buffer the data block.
-
- On successful return, pInode->pbData will be populated with a buffer
- corresponding to the @p ulBlock block offset.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlock The block offset to seek to and buffer.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_ENODATA The block offset is sparse.
- @retval -RED_EINVAL @p ulBlock is too large.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeDataSeekAndRead(
- CINODE *pInode,
- uint32_t ulBlock)
-{
- REDSTATUS ret;
-
- ret = RedInodeDataSeek(pInode, ulBlock);
-
- if((ret == 0) && (pInode->pbData == NULL))
- {
- REDASSERT(pInode->ulDataBlock != BLOCK_SPARSE);
-
- ret = RedBufferGet(pInode->ulDataBlock, 0U, CAST_VOID_PTR_PTR(&pInode->pbData));
- }
-
- return ret;
-}
-
-
-/** @brief Seek to a given position within an inode.
-
- On successful return, pInode->ulDataBlock will be populated with the
- physical block number corresponding to the @p ulBlock block offset.
-
- Note: Callers of this function depend on its parameter checking.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlock The block offset to seek to.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_ENODATA The block offset is sparse.
- @retval -RED_EINVAL @p ulBlock is too large; or @p pInode is not a
- mounted cached inode pointer.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedInodeDataSeek(
- CINODE *pInode,
- uint32_t ulBlock)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || (ulBlock >= INODE_DATA_BLOCKS))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- SeekCoord(pInode, ulBlock);
-
- #if DINDIR_POINTERS > 0U
- if(pInode->uDindirEntry != COORD_ENTRY_INVALID)
- {
- if(pInode->ulDindirBlock == BLOCK_SPARSE)
- {
- /* If the double indirect is unallocated, so is the indirect.
- */
- pInode->ulIndirBlock = BLOCK_SPARSE;
- }
- else
- {
- if(pInode->pDindir == NULL)
- {
- ret = RedBufferGet(pInode->ulDindirBlock, BFLAG_META_DINDIR, CAST_VOID_PTR_PTR(&pInode->pDindir));
- }
-
- if(ret == 0)
- {
- pInode->ulIndirBlock = pInode->pDindir->aulEntries[pInode->uDindirEntry];
- }
- }
- }
- #endif
-
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- if((ret == 0) && (pInode->uIndirEntry != COORD_ENTRY_INVALID))
- {
- if(pInode->ulIndirBlock == BLOCK_SPARSE)
- {
- /* If the indirect is unallocated, so is the data block.
- */
- pInode->ulDataBlock = BLOCK_SPARSE;
- }
- else
- {
- if(pInode->pIndir == NULL)
- {
- ret = RedBufferGet(pInode->ulIndirBlock, BFLAG_META_INDIR, CAST_VOID_PTR_PTR(&pInode->pIndir));
- }
-
- if(ret == 0)
- {
- pInode->ulDataBlock = pInode->pIndir->aulEntries[pInode->uIndirEntry];
- }
- }
- }
- #endif
-
- if((ret == 0) && (pInode->ulDataBlock == BLOCK_SPARSE))
- {
- ret = -RED_ENODATA;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Seek to the coordinates.
-
- Compute the new coordinates, and put any buffers which are not needed or are
- no longer appropriate.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlock The block offset to seek to.
-*/
-static void SeekCoord(
- CINODE *pInode,
- uint32_t ulBlock)
-{
- if(!CINODE_IS_MOUNTED(pInode) || (ulBlock >= INODE_DATA_BLOCKS))
- {
- REDERROR();
- }
- else if((pInode->ulLogicalBlock != ulBlock) || !pInode->fCoordInited)
- {
- RedInodePutData(pInode);
- pInode->ulLogicalBlock = ulBlock;
-
- #if REDCONF_DIRECT_POINTERS > 0U
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- if(ulBlock < REDCONF_DIRECT_POINTERS)
- #endif
- {
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- RedInodePutCoord(pInode);
- #endif
-
- pInode->uInodeEntry = (uint16_t)ulBlock;
- pInode->ulDataBlock = pInode->pInodeBuf->aulEntries[pInode->uInodeEntry];
-
- #if DINDIR_POINTERS > 0U
- pInode->uDindirEntry = COORD_ENTRY_INVALID;
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- pInode->uIndirEntry = COORD_ENTRY_INVALID;
- #endif
- }
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- else
- #endif
- #endif
- #if REDCONF_INDIRECT_POINTERS > 0U
- #if REDCONF_INDIRECT_POINTERS < INODE_ENTRIES
- if(ulBlock < (INODE_INDIR_BLOCKS + REDCONF_DIRECT_POINTERS))
- #endif
- {
- uint32_t ulIndirRangeOffset = ulBlock - REDCONF_DIRECT_POINTERS;
- uint16_t uInodeEntry = (uint16_t)((ulIndirRangeOffset / INDIR_ENTRIES) + REDCONF_DIRECT_POINTERS);
- uint16_t uIndirEntry = (uint16_t)(ulIndirRangeOffset % INDIR_ENTRIES);
-
- #if DINDIR_POINTERS > 0U
- RedInodePutDindir(pInode);
- #endif
-
- /* If the inode entry is not changing, then the previous indirect
- is still the correct one. Otherwise, the old indirect will be
- released and the new one will be read later.
- */
- if((pInode->uInodeEntry != uInodeEntry) || !pInode->fCoordInited)
- {
- RedInodePutIndir(pInode);
-
- pInode->uInodeEntry = uInodeEntry;
-
- pInode->ulIndirBlock = pInode->pInodeBuf->aulEntries[pInode->uInodeEntry];
- }
-
- #if DINDIR_POINTERS > 0U
- pInode->uDindirEntry = COORD_ENTRY_INVALID;
- #endif
- pInode->uIndirEntry = uIndirEntry;
-
- /* At this point, the following pInode members are needed but not
- yet populated:
-
- - pIndir
- - ulDataBlock
- */
- }
- #if DINDIR_POINTERS > 0U
- else
- #endif
- #endif
- #if DINDIR_POINTERS > 0U
- {
- uint32_t ulDindirRangeOffset = (ulBlock - REDCONF_DIRECT_POINTERS) - INODE_INDIR_BLOCKS;
- uint16_t uInodeEntry = (uint16_t)((ulDindirRangeOffset / DINDIR_DATA_BLOCKS) + REDCONF_DIRECT_POINTERS + REDCONF_INDIRECT_POINTERS);
- uint32_t ulDindirNodeOffset = ulDindirRangeOffset % DINDIR_DATA_BLOCKS;
- uint16_t uDindirEntry = (uint16_t)(ulDindirNodeOffset / INDIR_ENTRIES);
- uint16_t uIndirEntry = (uint16_t)(ulDindirNodeOffset % INDIR_ENTRIES);
-
- /* If the inode entry is not changing, then the previous double
- indirect is still the correct one. Otherwise, the old double
- indirect will be released and the new one will be read later.
- */
- if((pInode->uInodeEntry != uInodeEntry) || !pInode->fCoordInited)
- {
- RedInodePutIndir(pInode);
- RedInodePutDindir(pInode);
-
- pInode->uInodeEntry = uInodeEntry;
-
- pInode->ulDindirBlock = pInode->pInodeBuf->aulEntries[pInode->uInodeEntry];
- }
- /* If neither the inode entry nor double indirect entry are
- changing, then the previous indirect is still the correct one.
- Otherwise, it old indirect will be released and the new one will
- be read later.
- */
- else if(pInode->uDindirEntry != uDindirEntry)
- {
- RedInodePutIndir(pInode);
- }
- else
- {
- /* Data buffer has already been put, nothing to do.
- */
- }
-
- pInode->uDindirEntry = uDindirEntry;
- pInode->uIndirEntry = uIndirEntry;
-
- /* At this point, the following pInode members are needed but not
- yet populated:
-
- - pDindir
- - pIndir
- - ulIndirBlock
- - ulDataBlock
- */
- }
- #elif (REDCONF_DIRECT_POINTERS > 0U) && (REDCONF_INDIRECT_POINTERS > 0U)
- else
- {
- /* There are no double indirects, so the block should have been in
- the direct or indirect range.
- */
- REDERROR();
- }
- #endif
-
- pInode->fCoordInited = true;
- }
- else
- {
- /* Seeking to the current position, nothing to do.
- */
- }
-}
-
-
-/** @brief Read an unaligned portion of a block.
-
- @param pInode A pointer to the cached inode structure.
- @param ullStart The file offset at which to read.
- @param ulLen The number of bytes to read.
- @param pbBuffer The buffer to read into.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS ReadUnaligned(
- CINODE *pInode,
- uint64_t ullStart,
- uint32_t ulLen,
- uint8_t *pbBuffer)
-{
- REDSTATUS ret;
-
- /* This read should not cross a block boundary.
- */
- if( ((ullStart >> BLOCK_SIZE_P2) != (((ullStart + ulLen) - 1U) >> BLOCK_SIZE_P2))
- || (pbBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedInodeDataSeekAndRead(pInode, (uint32_t)(ullStart >> BLOCK_SIZE_P2));
-
- if(ret == 0)
- {
- RedMemCpy(pbBuffer, &pInode->pbData[ullStart & (REDCONF_BLOCK_SIZE - 1U)], ulLen);
- }
- else if(ret == -RED_ENODATA)
- {
- /* Sparse block, return zeroed data.
- */
- RedMemSet(pbBuffer, 0U, ulLen);
- ret = 0;
- }
- else
- {
- /* No action, just return the error.
- */
- }
- }
-
- return ret;
-}
-
-
-/** @brief Read one or more whole blocks.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlockStart The file block offset at which to read.
- @param ulBlockCount The number of blocks to read.
- @param pbBuffer The buffer to read into.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS ReadAligned(
- CINODE *pInode,
- uint32_t ulBlockStart,
- uint32_t ulBlockCount,
- uint8_t *pbBuffer)
-{
- REDSTATUS ret = 0;
-
- if(pbBuffer == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- uint32_t ulBlockIndex = 0U;
-
- /* Read the data from disk one contiguous extent at a time.
- */
- while((ret == 0) && (ulBlockIndex < ulBlockCount))
- {
- uint32_t ulExtentStart;
- uint32_t ulExtentLen = ulBlockCount - ulBlockIndex;
-
- ret = GetExtent(pInode, ulBlockStart + ulBlockIndex, &ulExtentStart, &ulExtentLen);
-
- if(ret == 0)
- {
- #if REDCONF_READ_ONLY == 0
- /* Before reading directly from disk, flush any dirty file data
- buffers in the range to avoid reading stale data.
- */
- ret = RedBufferFlush(ulExtentStart, ulExtentLen);
-
- if(ret == 0)
- #endif
- {
- ret = RedIoRead(gbRedVolNum, ulExtentStart, ulExtentLen, &pbBuffer[ulBlockIndex << BLOCK_SIZE_P2]);
-
- if(ret == 0)
- {
- ulBlockIndex += ulExtentLen;
- }
- }
- }
- else if(ret == -RED_ENODATA)
- {
- /* Sparse block, return zeroed data.
- */
- RedMemSet(&pbBuffer[ulBlockIndex << BLOCK_SIZE_P2], 0U, REDCONF_BLOCK_SIZE);
- ulBlockIndex++;
- ret = 0;
- }
- else
- {
- /* An unexpected error occurred; the loop will terminate.
- */
- }
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write an unaligned portion of a block.
-
- @param pInode A pointer to the cached inode structure.
- @param ullStart The file offset at which to write.
- @param ulLen The number of bytes to write.
- @param pbBuffer The buffer to write from.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS WriteUnaligned(
- CINODE *pInode,
- uint64_t ullStart,
- uint32_t ulLen,
- const uint8_t *pbBuffer)
-{
- REDSTATUS ret;
-
- /* This write should not cross a block boundary.
- */
- if( ((ullStart >> BLOCK_SIZE_P2) != (((ullStart + ulLen) - 1U) >> BLOCK_SIZE_P2))
- || (pbBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedInodeDataSeek(pInode, (uint32_t)(ullStart >> BLOCK_SIZE_P2));
-
- if((ret == 0) || (ret == -RED_ENODATA))
- {
- ret = BranchBlock(pInode, BRANCHDEPTH_FILE_DATA, true);
-
- if(ret == 0)
- {
- RedMemCpy(&pInode->pbData[ullStart & (REDCONF_BLOCK_SIZE - 1U)], pbBuffer, ulLen);
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Write one or more whole blocks.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlockStart The file block offset at which to write.
- @param pulBlockCount On entry, the number of blocks to attempt to write.
- On successful return, the number of blocks actually
- written.
- @param pbBuffer The buffer to write from.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS WriteAligned(
- CINODE *pInode,
- uint32_t ulBlockStart,
- uint32_t *pulBlockCount,
- const uint8_t *pbBuffer)
-{
- REDSTATUS ret = 0;
-
- if((pulBlockCount == NULL) || (pbBuffer == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- bool fFull = false;
- uint32_t ulBlockCount = *pulBlockCount;
- uint32_t ulBlockIndex;
-
- /* Branch all of the file data blocks in advance.
- */
- for(ulBlockIndex = 0U; (ulBlockIndex < ulBlockCount) && !fFull; ulBlockIndex++)
- {
- ret = RedInodeDataSeek(pInode, ulBlockStart + ulBlockIndex);
-
- if((ret == 0) || (ret == -RED_ENODATA))
- {
- ret = BranchBlock(pInode, BRANCHDEPTH_FILE_DATA, false);
-
- if(ret == -RED_ENOSPC)
- {
- if(ulBlockIndex > 0U)
- {
- ret = 0;
- }
-
- fFull = true;
- }
- }
-
- if(ret != 0)
- {
- break;
- }
- }
-
- ulBlockCount = ulBlockIndex;
- ulBlockIndex = 0U;
-
- if(fFull)
- {
- ulBlockCount--;
- }
-
- /* Write the data to disk one contiguous extent at a time.
- */
- while((ret == 0) && (ulBlockIndex < ulBlockCount))
- {
- uint32_t ulExtentStart;
- uint32_t ulExtentLen = ulBlockCount - ulBlockIndex;
-
- ret = GetExtent(pInode, ulBlockStart + ulBlockIndex, &ulExtentStart, &ulExtentLen);
-
- if(ret == 0)
- {
- ret = RedIoWrite(gbRedVolNum, ulExtentStart, ulExtentLen, &pbBuffer[ulBlockIndex << BLOCK_SIZE_P2]);
-
- if(ret == 0)
- {
- /* If there is any buffered file data for the extent we
- just wrote, those buffers are now stale.
- */
- ret = RedBufferDiscardRange(ulExtentStart, ulExtentLen);
- }
-
- if(ret == 0)
- {
- ulBlockIndex += ulExtentLen;
- }
- }
- }
-
- if(ret == 0)
- {
- *pulBlockCount = ulBlockCount;
- }
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-/** @brief Get the physical block number and count of contiguous blocks given a
- starting logical block number.
-
- @param pInode A pointer to the cached inode structure.
- @param ulBlockStart The file block offset for the start of the extent.
- @param pulExtentStart On successful return, the starting physical block
- number of the contiguous extent.
- @param pulExtentLen On entry, the maximum length of the extent; on
- successful return, the length of the contiguous
- extent.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENODATA The block offset is sparse.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS GetExtent(
- CINODE *pInode,
- uint32_t ulBlockStart,
- uint32_t *pulExtentStart,
- uint32_t *pulExtentLen)
-{
- REDSTATUS ret;
-
- if((pulExtentStart == NULL) || (pulExtentLen == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedInodeDataSeek(pInode, ulBlockStart);
-
- if(ret == 0)
- {
- uint32_t ulExtentLen = *pulExtentLen;
- uint32_t ulFirstBlock = pInode->ulDataBlock;
- uint32_t ulRunLen = 1U;
-
- while((ret == 0) && (ulRunLen < ulExtentLen))
- {
- ret = RedInodeDataSeek(pInode, ulBlockStart + ulRunLen);
-
- /* The extent ends when we find a sparse data block or when the
- data block is not contiguous with the preceding data block.
- */
- if((ret == -RED_ENODATA) || ((ret == 0) && (pInode->ulDataBlock != (ulFirstBlock + ulRunLen))))
- {
- ret = 0;
- break;
- }
-
- ulRunLen++;
- }
-
- if(ret == 0)
- {
- *pulExtentStart = ulFirstBlock;
- *pulExtentLen = ulRunLen;
- }
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Allocate or branch the file metadata path and data block if necessary.
-
- Optionally, can stop allocating/branching at a certain depth.
-
- @param pInode A pointer to the cached inode structure.
- @param depth A BRANCHDEPTH_ value indicating the lowest depth to branch.
- @param fBuffer Whether to buffer the data block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
-*/
-static REDSTATUS BranchBlock(
- CINODE *pInode,
- BRANCHDEPTH depth,
- bool fBuffer)
-{
- REDSTATUS ret;
- uint32_t ulCost = 0U; /* Init'd to quiet warnings. */
-
- ret = BranchBlockCost(pInode, depth, &ulCost);
-
- if((ret == 0) && (ulCost > FreeBlockCount()))
- {
- ret = -RED_ENOSPC;
- }
-
- if(ret == 0)
- {
- #if DINDIR_POINTERS > 0U
- if(pInode->uDindirEntry != COORD_ENTRY_INVALID)
- {
- ret = BranchOneBlock(&pInode->ulDindirBlock, CAST_VOID_PTR_PTR(&pInode->pDindir), BFLAG_META_DINDIR);
-
- if(ret == 0)
- {
- /* In case we just created the double indirect.
- */
- pInode->pDindir->ulInode = pInode->ulInode;
-
- pInode->pInodeBuf->aulEntries[pInode->uInodeEntry] = pInode->ulDindirBlock;
- }
- }
-
- if(ret == 0)
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- {
- if((pInode->uIndirEntry != COORD_ENTRY_INVALID) && (depth >= BRANCHDEPTH_INDIR))
- {
- ret = BranchOneBlock(&pInode->ulIndirBlock, CAST_VOID_PTR_PTR(&pInode->pIndir), BFLAG_META_INDIR);
-
- if(ret == 0)
- {
- /* In case we just created the indirect.
- */
- pInode->pIndir->ulInode = pInode->ulInode;
-
- #if DINDIR_POINTERS > 0U
- if(pInode->uDindirEntry != COORD_ENTRY_INVALID)
- {
- pInode->pDindir->aulEntries[pInode->uDindirEntry] = pInode->ulIndirBlock;
- }
- else
- #endif
- {
- pInode->pInodeBuf->aulEntries[pInode->uInodeEntry] = pInode->ulIndirBlock;
- }
- }
- }
- }
-
- if(ret == 0)
- #endif
- {
- if(depth == BRANCHDEPTH_FILE_DATA)
- {
- #if REDCONF_INODE_BLOCKS == 1
- bool fAllocedNew = (pInode->ulDataBlock == BLOCK_SPARSE);
- #endif
- void **ppBufPtr = (fBuffer || (pInode->pbData != NULL)) ? CAST_VOID_PTR_PTR(&pInode->pbData) : NULL;
-
- ret = BranchOneBlock(&pInode->ulDataBlock, ppBufPtr, 0U);
-
- if(ret == 0)
- {
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- if(pInode->uIndirEntry != COORD_ENTRY_INVALID)
- {
- pInode->pIndir->aulEntries[pInode->uIndirEntry] = pInode->ulDataBlock;
- }
- else
- #endif
- {
- pInode->pInodeBuf->aulEntries[pInode->uInodeEntry] = pInode->ulDataBlock;
- }
-
- #if REDCONF_INODE_BLOCKS == 1
- if(fAllocedNew)
- {
- if(pInode->pInodeBuf->ulBlocks < INODE_DATA_BLOCKS)
- {
- pInode->pInodeBuf->ulBlocks++;
- }
- else
- {
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- }
- #endif
- }
- }
- }
-
- CRITICAL_ASSERT(ret == 0);
- }
-
- return ret;
-}
-
-
-/** @brief Branch a block.
-
- The block can be a double indirect, indirect, or file data block.
-
- The caller should have already handled the disk full implications of
- branching this block.
-
- @param pulBlock On entry, the current block number, which may be
- BLOCK_SPARSE if the block is to be newly allocated. On
- successful return, populated with the new block number,
- which may be the same as the original block number if it
- was not BLOCK_SPARSE and the block was already branched.
- @param ppBuffer If NULL, indicates that the caller does not want to buffer
- the branched block. If non-NULL, the caller does want the
- branched block buffered, and the following is true: On
- entry, the current buffer for the block, if there is one, or
- NULL if there is no buffer. On successful exit, populated
- with a buffer for the block, which will be dirty. If the
- block number is initially BLOCK_SPARSE, there should be no
- buffer for the block.
- @param uBFlag The buffer type flags: BFLAG_META_DINDIR, BFLAG_META_INDIR,
- or zero for file data.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS BranchOneBlock(
- uint32_t *pulBlock,
- void **ppBuffer,
- uint16_t uBFlag)
-{
- REDSTATUS ret = 0;
-
- if(pulBlock == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ALLOCSTATE state = ALLOCSTATE_FREE;
- uint32_t ulPrevBlock = *pulBlock;
-
- if(ulPrevBlock != BLOCK_SPARSE)
- {
- ret = RedImapBlockState(ulPrevBlock, &state);
- }
-
- if(ret == 0)
- {
- if(state == ALLOCSTATE_NEW)
- {
- /* Block is already branched, so simply get it buffered dirty
- if requested.
- */
- if(ppBuffer != NULL)
- {
- if(*ppBuffer != NULL)
- {
- RedBufferDirty(*ppBuffer);
- }
- else
- {
- ret = RedBufferGet(ulPrevBlock, uBFlag | BFLAG_DIRTY, ppBuffer);
- }
- }
- }
- else
- {
- /* Block does not exist or is committed state, so allocate a
- new block for the branch.
- */
- ret = RedImapAllocBlock(pulBlock);
-
- if(ret == 0)
- {
- if(ulPrevBlock == BLOCK_SPARSE)
- {
- /* Block did not exist previously, so just get it
- buffered if requested.
- */
- if(ppBuffer != NULL)
- {
- if(*ppBuffer != NULL)
- {
- /* How could there be an existing buffer when
- the block did not exist?
- */
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ret = RedBufferGet(*pulBlock, (uint16_t)((uint32_t)uBFlag | BFLAG_NEW | BFLAG_DIRTY), ppBuffer);
- }
- }
- }
- else
- {
- /* Branch the buffer for the committed state block to
- the newly allocated location.
- */
- if(ppBuffer != NULL)
- {
- if(*ppBuffer == NULL)
- {
- ret = RedBufferGet(ulPrevBlock, uBFlag, ppBuffer);
- }
-
- if(ret == 0)
- {
- RedBufferBranch(*ppBuffer, *pulBlock);
- }
- }
-
- /* Mark the committed state block almost free.
- */
- if(ret == 0)
- {
- ret = RedImapBlockSet(ulPrevBlock, false);
- }
- }
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Compute the free space cost of branching a block.
-
- The caller must first use RedInodeDataSeek() to the block to be branched.
-
- @param pInode A pointer to the cached inode structure, whose coordinates
- indicate the block to be branched.
- @param depth A BRANCHDEPTH_ value indicating how much of the file
- metadata structure needs to be branched.
- @param pulCost On successful return, populated with the number of blocks
- that must be allocated from free space in order to branch
- the given block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EINVAL Invalid parameters.
-*/
-static REDSTATUS BranchBlockCost(
- const CINODE *pInode,
- BRANCHDEPTH depth,
- uint32_t *pulCost)
-{
- REDSTATUS ret = 0;
-
- if(!CINODE_IS_MOUNTED(pInode) || !pInode->fCoordInited || (depth > BRANCHDEPTH_MAX) || (pulCost == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else
- {
- ALLOCSTATE state;
-
- /* ulCost is initialized to the maximum number of blocks that could
- be branched, and decremented for every block we determine does not
- need to be branched.
- */
- #if DINDIR_POINTERS > 0U
- uint32_t ulCost = 3U;
- #elif REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- uint32_t ulCost = 2U;
- #else
- uint32_t ulCost = 1U;
- #endif
-
- #if DINDIR_POINTERS > 0U
- if(pInode->uDindirEntry != COORD_ENTRY_INVALID)
- {
- if(pInode->ulDindirBlock != BLOCK_SPARSE)
- {
- ret = RedImapBlockState(pInode->ulDindirBlock, &state);
-
- if((ret == 0) && (state == ALLOCSTATE_NEW))
- {
- /* Double indirect already branched.
- */
- ulCost--;
- }
- }
- }
- else
- {
- /* At this inode offset there are no double indirects.
- */
- ulCost--;
- }
-
- if(ret == 0)
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- {
- if((pInode->uIndirEntry != COORD_ENTRY_INVALID) && (depth >= BRANCHDEPTH_INDIR))
- {
- if(pInode->ulIndirBlock != BLOCK_SPARSE)
- {
- ret = RedImapBlockState(pInode->ulIndirBlock, &state);
-
- if((ret == 0) && (state == ALLOCSTATE_NEW))
- {
- /* Indirect already branched.
- */
- ulCost--;
- }
- }
- }
- else
- {
- /* Either not branching this deep, or at this inode offset
- there are no indirects.
- */
- ulCost--;
- }
- }
-
- if(ret == 0)
- #endif
- {
- if(depth == BRANCHDEPTH_FILE_DATA)
- {
- if(pInode->ulDataBlock != BLOCK_SPARSE)
- {
- ret = RedImapBlockState(pInode->ulDataBlock, &state);
-
- if((ret == 0) && (state == ALLOCSTATE_NEW))
- {
- /* File data block already branched.
- */
- ulCost--;
-
- /* If the file data block is branched, then its parent
- nodes should be branched as well.
- */
- REDASSERT(ulCost == 0U);
- }
- }
- }
- else
- {
- /* Not branching this deep.
- */
- ulCost--;
- }
- }
-
- if(ret == 0)
- {
- *pulCost = ulCost;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Yields the number of currently available free blocks.
-
- Accounts for reserved blocks, subtracting the number of reserved blocks if
- they are unavailable.
-
- @return Number of currently available free blocks.
-*/
-static uint32_t FreeBlockCount(void)
-{
- uint32_t ulFreeBlocks = gpRedMR->ulFreeBlocks;
-
- #if RESERVED_BLOCKS > 0U
- if(!gpRedCoreVol->fUseReservedBlocks)
- {
- if(ulFreeBlocks >= RESERVED_BLOCKS)
- {
- ulFreeBlocks -= RESERVED_BLOCKS;
- }
- else
- {
- ulFreeBlocks = 0U;
- }
- }
- #endif
-
- return ulFreeBlocks;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/volume.c b/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/volume.c
deleted file mode 100755
index 55e02d0..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/driver/volume.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements core volume operations.
-*/
-#include
-#include
-
-
-static bool MetarootIsValid(METAROOT *pMR, bool *pfSectorCRCIsValid);
-#ifdef REDCONF_ENDIAN_SWAP
-static void MetaRootEndianSwap(METAROOT *pMetaRoot);
-#endif
-
-
-/** @brief Mount a file system volume.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO Volume not formatted, improperly formatted, or corrupt.
-*/
-REDSTATUS RedVolMount(void)
-{
- REDSTATUS ret;
-
- #if REDCONF_READ_ONLY == 0
- ret = RedOsBDevOpen(gbRedVolNum, BDEV_O_RDWR);
- #else
- ret = RedOsBDevOpen(gbRedVolNum, BDEV_O_RDONLY);
- #endif
-
- if(ret == 0)
- {
- ret = RedVolMountMaster();
-
- if(ret == 0)
- {
- ret = RedVolMountMetaroot();
- }
-
- if(ret != 0)
- {
- /* If we fail to mount, invalidate the buffers to prevent any
- confusion that could be caused by stale or corrupt metadata.
- */
- (void)RedBufferDiscardRange(0U, gpRedVolume->ulBlockCount);
- (void)RedOsBDevClose(gbRedVolNum);
- }
- }
-
- return ret;
-}
-
-
-/** @brief Mount the master block.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO Master block missing, corrupt, or inconsistent with the
- compile-time driver settings.
-*/
-REDSTATUS RedVolMountMaster(void)
-{
- REDSTATUS ret;
- MASTERBLOCK *pMB;
-
- /* Read the master block, to ensure that the disk was formatted with
- Reliance Edge.
- */
- ret = RedBufferGet(BLOCK_NUM_MASTER, BFLAG_META_MASTER, CAST_VOID_PTR_PTR(&pMB));
-
- if(ret == 0)
- {
- /* Verify that the driver was compiled with the same settings that
- the disk was formatted with. If not, the user has made a
- mistake: either the driver settings are wrong, or the disk needs
- to be reformatted.
- */
- if( (pMB->ulVersion != RED_DISK_LAYOUT_VERSION)
- || (pMB->ulInodeCount != gpRedVolConf->ulInodeCount)
- || (pMB->ulBlockCount != gpRedVolume->ulBlockCount)
- || (pMB->uMaxNameLen != REDCONF_NAME_MAX)
- || (pMB->uDirectPointers != REDCONF_DIRECT_POINTERS)
- || (pMB->uIndirectPointers != REDCONF_INDIRECT_POINTERS)
- || (pMB->bBlockSizeP2 != BLOCK_SIZE_P2)
- || (((pMB->bFlags & MBFLAG_API_POSIX) != 0U) != (REDCONF_API_POSIX == 1))
- || (((pMB->bFlags & MBFLAG_INODE_TIMESTAMPS) != 0U) != (REDCONF_INODE_TIMESTAMPS == 1))
- || (((pMB->bFlags & MBFLAG_INODE_BLOCKS) != 0U) != (REDCONF_INODE_BLOCKS == 1)))
- {
- ret = -RED_EIO;
- }
- #if REDCONF_API_POSIX == 1
- else if(((pMB->bFlags & MBFLAG_INODE_NLINK) != 0U) != (REDCONF_API_POSIX_LINK == 1))
- {
- ret = -RED_EIO;
- }
- #else
- else if((pMB->bFlags & MBFLAG_INODE_NLINK) != 0U)
- {
- ret = -RED_EIO;
- }
- #endif
- else
- {
- /* Master block configuration is valid.
-
- Save the sequence number of the master block in the volume,
- since we need it later (see RedVolMountMetaroot()) and we do
- not want to re-buffer the master block.
- */
- gpRedVolume->ullSequence = pMB->hdr.ullSequence;
- }
-
- RedBufferPut(pMB);
- }
-
- return ret;
-}
-
-
-/** @brief Mount the latest metaroot.
-
- This function also populates the volume contexts.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO Both metaroots are missing or corrupt.
-*/
-REDSTATUS RedVolMountMetaroot(void)
-{
- REDSTATUS ret;
-
- ret = RedIoRead(gbRedVolNum, BLOCK_NUM_FIRST_METAROOT, 1U, &gpRedCoreVol->aMR[0U]);
-
- if(ret == 0)
- {
- ret = RedIoRead(gbRedVolNum, BLOCK_NUM_FIRST_METAROOT + 1U, 1U, &gpRedCoreVol->aMR[1U]);
- }
-
- /* Determine which metaroot is the most recent copy that was written
- completely.
- */
- if(ret == 0)
- {
- uint8_t bMR = UINT8_MAX;
- bool fSectorCRCIsValid;
-
- if(MetarootIsValid(&gpRedCoreVol->aMR[0U], &fSectorCRCIsValid))
- {
- bMR = 0U;
-
- #ifdef REDCONF_ENDIAN_SWAP
- MetaRootEndianSwap(&gpRedCoreVol->aMR[0U]);
- #endif
- }
- else if(gpRedVolConf->fAtomicSectorWrite && !fSectorCRCIsValid)
- {
- ret = -RED_EIO;
- }
- else
- {
- /* Metaroot is not valid, so it is ignored and there's nothing
- to do here.
- */
- }
-
- if(ret == 0)
- {
- if(MetarootIsValid(&gpRedCoreVol->aMR[1U], &fSectorCRCIsValid))
- {
- #ifdef REDCONF_ENDIAN_SWAP
- MetaRootEndianSwap(&gpRedCoreVol->aMR[1U]);
- #endif
-
- if((bMR != 0U) || (gpRedCoreVol->aMR[1U].hdr.ullSequence > gpRedCoreVol->aMR[0U].hdr.ullSequence))
- {
- bMR = 1U;
- }
- }
- else if(gpRedVolConf->fAtomicSectorWrite && !fSectorCRCIsValid)
- {
- ret = -RED_EIO;
- }
- else
- {
- /* Metaroot is not valid, so it is ignored and there's nothing
- to do here.
- */
- }
- }
-
- if(ret == 0)
- {
- if(bMR == UINT8_MAX)
- {
- /* Neither metaroot was valid.
- */
- ret = -RED_EIO;
- }
- else
- {
- gpRedCoreVol->bCurMR = bMR;
- gpRedMR = &gpRedCoreVol->aMR[bMR];
- }
- }
- }
-
- if(ret == 0)
- {
- /* Normally the metaroot contains the highest sequence number, but the
- master block is the last block written during format, so on a
- freshly formatted volume the master block sequence number (stored in
- gpRedVolume->ullSequence) will be higher than that in the metaroot.
- */
- if(gpRedMR->hdr.ullSequence > gpRedVolume->ullSequence)
- {
- gpRedVolume->ullSequence = gpRedMR->hdr.ullSequence;
- }
-
- /* gpRedVolume->ullSequence stores the *next* sequence number; to avoid
- giving the next node written to disk the same sequence number as the
- metaroot, increment it here.
- */
- ret = RedVolSeqNumIncrement();
- }
-
- if(ret == 0)
- {
- gpRedVolume->fMounted = true;
- #if REDCONF_READ_ONLY == 0
- gpRedVolume->fReadOnly = false;
- #endif
-
- #if RESERVED_BLOCKS > 0U
- gpRedCoreVol->fUseReservedBlocks = false;
- #endif
- gpRedCoreVol->ulAlmostFreeBlocks = 0U;
-
- gpRedCoreVol->aMR[1U - gpRedCoreVol->bCurMR] = *gpRedMR;
- gpRedCoreVol->bCurMR = 1U - gpRedCoreVol->bCurMR;
- gpRedMR = &gpRedCoreVol->aMR[gpRedCoreVol->bCurMR];
- }
-
- return ret;
-}
-
-
-/** @brief Determine whether the metaroot is valid.
-
- @param pMR The metaroot buffer.
- @param pfSectorCRCIsValid Populated with whether the first sector of the
- metaroot buffer is valid.
-
- @return Whether the metaroot is valid.
-
- @retval true The metaroot buffer is valid.
- @retval false The metaroot buffer is invalid.
-*/
-static bool MetarootIsValid(
- METAROOT *pMR,
- bool *pfSectorCRCIsValid)
-{
- bool fRet = false;
-
- if(pfSectorCRCIsValid == NULL)
- {
- REDERROR();
- }
- else if(pMR == NULL)
- {
- REDERROR();
- *pfSectorCRCIsValid = false;
- }
- #ifdef REDCONF_ENDIAN_SWAP
- else if(RedRev32(pMR->hdr.ulSignature) != META_SIG_METAROOT)
- #else
- else if(pMR->hdr.ulSignature != META_SIG_METAROOT)
- #endif
- {
- *pfSectorCRCIsValid = false;
- }
- else
- {
- const uint8_t *pbMR = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pMR);
- uint32_t ulSectorCRC = pMR->ulSectorCRC;
- uint32_t ulCRC;
-
- #ifdef REDCONF_ENDIAN_SWAP
- ulSectorCRC = RedRev32(ulSectorCRC);
- #endif
-
- /* The sector CRC was zero when the CRC was computed during the
- transaction, so it must be zero here.
- */
- pMR->ulSectorCRC = 0U;
-
- ulCRC = RedCrc32Update(0U, &pbMR[8U], gpRedVolConf->ulSectorSize - 8U);
-
- fRet = ulCRC == ulSectorCRC;
- *pfSectorCRCIsValid = fRet;
-
- if(fRet)
- {
- if(gpRedVolConf->ulSectorSize < REDCONF_BLOCK_SIZE)
- {
- ulCRC = RedCrc32Update(ulCRC, &pbMR[gpRedVolConf->ulSectorSize], REDCONF_BLOCK_SIZE - gpRedVolConf->ulSectorSize);
- }
-
- #ifdef REDCONF_ENDIAN_SWAP
- ulCRC = RedRev32(ulCRC);
- #endif
-
- fRet = ulCRC == pMR->hdr.ulCRC;
- }
- }
-
- return fRet;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Commit a transaction point.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedVolTransact(void)
-{
- REDSTATUS ret = 0;
-
- REDASSERT(!gpRedVolume->fReadOnly); /* Should be checked by caller. */
-
- if(gpRedCoreVol->fBranched)
- {
- gpRedMR->ulFreeBlocks += gpRedCoreVol->ulAlmostFreeBlocks;
- gpRedCoreVol->ulAlmostFreeBlocks = 0U;
-
- ret = RedBufferFlush(0U, gpRedVolume->ulBlockCount);
-
- if(ret == 0)
- {
- gpRedMR->hdr.ulSignature = META_SIG_METAROOT;
- gpRedMR->hdr.ullSequence = gpRedVolume->ullSequence;
-
- ret = RedVolSeqNumIncrement();
- }
-
- if(ret == 0)
- {
- const uint8_t *pbMR = CAST_VOID_PTR_TO_CONST_UINT8_PTR(gpRedMR);
- uint32_t ulSectorCRC;
-
- #ifdef REDCONF_ENDIAN_SWAP
- MetaRootEndianSwap(gpRedMR);
- #endif
-
- gpRedMR->ulSectorCRC = 0U;
-
- ulSectorCRC = RedCrc32Update(0U, &pbMR[8U], gpRedVolConf->ulSectorSize - 8U);
-
- if(gpRedVolConf->ulSectorSize < REDCONF_BLOCK_SIZE)
- {
- gpRedMR->hdr.ulCRC = RedCrc32Update(ulSectorCRC, &pbMR[gpRedVolConf->ulSectorSize], REDCONF_BLOCK_SIZE - gpRedVolConf->ulSectorSize);
- }
- else
- {
- gpRedMR->hdr.ulCRC = ulSectorCRC;
- }
-
- gpRedMR->ulSectorCRC = ulSectorCRC;
-
- #ifdef REDCONF_ENDIAN_SWAP
- gpRedMR->hdr.ulCRC = RedRev32(gpRedMR->hdr.ulCRC);
- gpRedMR->ulSectorCRC = RedRev32(gpRedMR->ulSectorCRC);
- #endif
-
- /* Flush the block device before writing the metaroot, so that all
- previously written blocks are guaranteed to be on the media before
- the metaroot is written. Otherwise, if the block device reorders
- the writes, the metaroot could reach the media before metadata it
- points at, creating a window for disk corruption if power is lost.
- */
- ret = RedIoFlush(gbRedVolNum);
- }
-
- if(ret == 0)
- {
- ret = RedIoWrite(gbRedVolNum, BLOCK_NUM_FIRST_METAROOT + gpRedCoreVol->bCurMR, 1U, gpRedMR);
-
- #ifdef REDCONF_ENDIAN_SWAP
- MetaRootEndianSwap(gpRedMR);
- #endif
- }
-
- /* Flush the block device to force the metaroot write to the media. This
- guarantees the transaction point is really complete before we return.
- */
- if(ret == 0)
- {
- ret = RedIoFlush(gbRedVolNum);
- }
-
- /* Toggle to the other metaroot buffer. The working state and committed
- state metaroot buffers exchange places.
- */
- if(ret == 0)
- {
- uint8_t bNextMR = 1U - gpRedCoreVol->bCurMR;
-
- gpRedCoreVol->aMR[bNextMR] = *gpRedMR;
- gpRedCoreVol->bCurMR = bNextMR;
-
- gpRedMR = &gpRedCoreVol->aMR[gpRedCoreVol->bCurMR];
-
- gpRedCoreVol->fBranched = false;
- }
-
- CRITICAL_ASSERT(ret == 0);
- }
-
- return ret;
-}
-#endif
-
-
-#ifdef REDCONF_ENDIAN_SWAP
-static void MetaRootEndianSwap(
- METAROOT *pMetaRoot)
-{
- if(pMetaRoot == NULL)
- {
- REDERROR();
- }
- else
- {
- pMetaRoot->ulSectorCRC = RedRev32(pMetaRoot->ulSectorCRC);
- pMetaRoot->ulFreeBlocks = RedRev32(pMetaRoot->ulFreeBlocks);
- #if REDCONF_API_POSIX == 1
- pMetaRoot->ulFreeInodes = RedRev32(pMetaRoot->ulFreeInodes);
- #endif
- pMetaRoot->ulAllocNextBlock = RedRev32(pMetaRoot->ulAllocNextBlock);
- }
-}
-#endif
-
-
-/** @brief Process a critical file system error.
-
- @param pszFileName The file in which the error occurred.
- @param ulLineNum The line number at which the error occurred.
-*/
-void RedVolCriticalError(
- const char *pszFileName,
- uint32_t ulLineNum)
-{
- #if REDCONF_OUTPUT == 1
- #if REDCONF_READ_ONLY == 0
- if(!gpRedVolume->fReadOnly)
- {
- RedOsOutputString("Critical file system error in Reliance Edge, setting volume to READONLY\n");
- }
- else
- #endif
- {
- RedOsOutputString("Critical file system error in Reliance Edge (volume already READONLY)\n");
- }
- #endif
-
- #if REDCONF_READ_ONLY == 0
- gpRedVolume->fReadOnly = true;
- #endif
-
- #if REDCONF_ASSERTS == 1
- RedOsAssertFail(pszFileName, ulLineNum);
- #else
- (void)pszFileName;
- (void)ulLineNum;
- #endif
-}
-
-
-/** @brief Increment the sequence number.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL Cannot increment sequence number: maximum value reached.
- This should not ever happen.
-*/
-REDSTATUS RedVolSeqNumIncrement(void)
-{
- REDSTATUS ret;
-
- if(gpRedVolume->ullSequence == UINT64_MAX)
- {
- /* In practice this should never, ever happen; to get here, there would
- need to be UINT64_MAX disk writes, which would take eons: longer
- than the lifetime of any product or storage media. If this assert
- fires and the current year is still written with four digits,
- suspect memory corruption.
- */
- CRITICAL_ERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- gpRedVolume->ullSequence++;
- ret = 0;
- }
-
- return ret;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcore.h b/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcore.h
deleted file mode 100755
index 031117f..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcore.h
+++ /dev/null
@@ -1,257 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDCORE_H
-#define REDCORE_H
-
-
-#include
-#include
-#include "rednodes.h"
-#include "redcoremacs.h"
-#include "redcorevol.h"
-
-
-#define META_SIG_MASTER (0x5453414DU) /* 'MAST' */
-#define META_SIG_METAROOT (0x4154454DU) /* 'META' */
-#define META_SIG_IMAP (0x50414D49U) /* 'IMAP' */
-#define META_SIG_INODE (0x444F4E49U) /* 'INOD' */
-#define META_SIG_DINDIR (0x494C4244U) /* 'DBLI' */
-#define META_SIG_INDIR (0x49444E49U) /* 'INDI' */
-
-
-REDSTATUS RedIoRead(uint8_t bVolNum, uint32_t ulBlockStart, uint32_t ulBlockCount, void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedIoWrite(uint8_t bVolNum, uint32_t ulBlockStart, uint32_t ulBlockCount, const void *pBuffer);
-REDSTATUS RedIoFlush(uint8_t bVolNum);
-#endif
-
-
-/** Indicates a block buffer is dirty (its contents are different than the
- contents of the corresponding block on disk); or, when passed into
- RedBufferGet(), indicates that the buffer should be marked dirty.
-*/
-#define BFLAG_DIRTY ((uint16_t) 0x0001U)
-
-/** Tells RedBufferGet() that the buffer is for a newly allocated block, and its
- contents should be zeroed instead of being read from disk. Always used in
- combination with BFLAG_DIRTY.
-*/
-#define BFLAG_NEW ((uint16_t) 0x0002U)
-
-/** Indicates that a block buffer is a master block (MASTERBLOCK) metadata node.
-*/
-#define BFLAG_META_MASTER ((uint16_t)(0x0004U | BFLAG_META))
-
-/** Indicates that a block buffer is an imap (IMAPNODE) metadata node.
-*/
-#define BFLAG_META_IMAP ((uint16_t)(0x0008U | BFLAG_META))
-
-/** Indicates that a block buffer is an inode (INODE) metadata node.
-*/
-#define BFLAG_META_INODE ((uint16_t)(0x0010U | BFLAG_META))
-
-/** Indicates that a block buffer is an indirect (INDIR) metadata node.
-*/
-#define BFLAG_META_INDIR ((uint16_t)(0x0020U | BFLAG_META))
-
-/** Indicates that a block buffer is a double indirect (DINDIR) metadata node.
-*/
-#define BFLAG_META_DINDIR ((uint16_t)(0x0040U | BFLAG_META))
-
-/** Indicates that a block buffer is a metadata node. Callers of RedBufferGet()
- should not use this flag; instead, use one of the BFLAG_META_* flags.
-*/
-#define BFLAG_META ((uint16_t) 0x8000U)
-
-
-void RedBufferInit(void);
-REDSTATUS RedBufferGet(uint32_t ulBlock, uint16_t uFlags, void **ppBuffer);
-void RedBufferPut(const void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedBufferFlush(uint32_t ulBlockStart, uint32_t ulBlockCount);
-void RedBufferDirty(const void *pBuffer);
-void RedBufferBranch(const void *pBuffer, uint32_t ulBlockNew);
-#if (REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED
-void RedBufferDiscard(const void *pBuffer);
-#endif
-#endif
-REDSTATUS RedBufferDiscardRange(uint32_t ulBlockStart, uint32_t ulBlockCount);
-
-
-/** @brief Allocation state of a block.
-*/
-typedef enum
-{
- ALLOCSTATE_FREE, /**< Free and may be allocated; writeable. */
- ALLOCSTATE_USED, /**< In-use and transacted; not writeable. */
- ALLOCSTATE_NEW, /**< In-use but not transacted; writeable. */
- ALLOCSTATE_AFREE /**< Will become free after a transaction; not writeable. */
-} ALLOCSTATE;
-
-REDSTATUS RedImapBlockGet(uint8_t bMR, uint32_t ulBlock, bool *pfAllocated);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedImapBlockSet(uint32_t ulBlock, bool fAllocated);
-REDSTATUS RedImapAllocBlock(uint32_t *pulBlock);
-#endif
-REDSTATUS RedImapBlockState(uint32_t ulBlock, ALLOCSTATE *pState);
-
-#if REDCONF_IMAP_INLINE == 1
-REDSTATUS RedImapIBlockGet(uint8_t bMR, uint32_t ulBlock, bool *pfAllocated);
-REDSTATUS RedImapIBlockSet(uint32_t ulBlock, bool fAllocated);
-#endif
-
-#if REDCONF_IMAP_EXTERNAL == 1
-REDSTATUS RedImapEBlockGet(uint8_t bMR, uint32_t ulBlock, bool *pfAllocated);
-REDSTATUS RedImapEBlockSet(uint32_t ulBlock, bool fAllocated);
-uint32_t RedImapNodeBlock(uint8_t bMR, uint32_t ulImapNode);
-#endif
-
-
-/** @brief Cached inode structure.
-*/
-typedef struct
-{
- uint32_t ulInode; /**< The inode number of the cached inode. */
- #if REDCONF_API_POSIX == 1
- bool fDirectory; /**< True if the inode is a directory. */
- #endif
- #if REDCONF_READ_ONLY == 0
- bool fBranched; /**< True if the inode is branched (writeable). */
- bool fDirty; /**< True if the inode buffer is dirty. */
- #endif
- bool fCoordInited; /**< True after the first seek. */
-
- INODE *pInodeBuf; /**< Pointer to the inode buffer. */
- #if DINDIR_POINTERS > 0U
- DINDIR *pDindir; /**< Pointer to the double indirect node buffer. */
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- INDIR *pIndir; /**< Pointer to the indirect node buffer. */
- #endif
- uint8_t *pbData; /**< Pointer to the data block buffer. */
-
- /* All the members below this point are part of the seek coordinates; see
- RedInodeDataSeek().
- */
- uint32_t ulLogicalBlock; /**< Logical block offset into the inode. */
- #if DINDIR_POINTERS > 0U
- uint32_t ulDindirBlock; /**< Physical block number of the double indirect node. */
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- uint32_t ulIndirBlock; /**< Physical block number of the indirect node. */
- #endif
- uint32_t ulDataBlock; /**< Physical block number of the file data block. */
-
- uint16_t uInodeEntry; /**< Which inode entry to traverse to reach ulLogicalBlock. */
- #if DINDIR_POINTERS > 0U
- uint16_t uDindirEntry; /**< Which double indirect entry to traverse to reach ulLogicalBlock. */
- #endif
- #if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
- uint16_t uIndirEntry; /**< Which indirect entry to traverse to reach ulLogicalBlock. */
- #endif
-} CINODE;
-
-#define CINODE_IS_MOUNTED(pInode) (((pInode) != NULL) && INODE_IS_VALID((pInode)->ulInode) && ((pInode)->pInodeBuf != NULL))
-#define CINODE_IS_DIRTY(pInode) (CINODE_IS_MOUNTED(pInode) && (pInode)->fDirty)
-
-
-#define IPUT_UPDATE_ATIME (0x01U)
-#define IPUT_UPDATE_MTIME (0x02U)
-#define IPUT_UPDATE_CTIME (0x04U)
-#define IPUT_UPDATE_MASK (IPUT_UPDATE_ATIME|IPUT_UPDATE_MTIME|IPUT_UPDATE_CTIME)
-
-
-REDSTATUS RedInodeMount(CINODE *pInode, FTYPE type, bool fBranch);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedInodeBranch(CINODE *pInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED)
-REDSTATUS RedInodeCreate(CINODE *pInode, uint32_t ulPInode, uint16_t uMode);
-#endif
-#if DELETE_SUPPORTED
-REDSTATUS RedInodeDelete(CINODE *pInode);
-REDSTATUS RedInodeLinkDec(CINODE *pInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-REDSTATUS RedInodeFree(CINODE *pInode);
-#endif
-void RedInodePut(CINODE *pInode, uint8_t bTimeFields);
-void RedInodePutCoord(CINODE *pInode);
-#if DINDIR_POINTERS > 0U
-void RedInodePutDindir(CINODE *pInode);
-#endif
-#if REDCONF_DIRECT_POINTERS < INODE_ENTRIES
-void RedInodePutIndir(CINODE *pInode);
-#endif
-void RedInodePutData(CINODE *pInode);
-#if ((REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || FORMAT_SUPPORTED)) || (REDCONF_CHECKER == 1)
-REDSTATUS RedInodeIsFree(uint32_t ulInode, bool *pfFree);
-#endif
-REDSTATUS RedInodeBitGet(uint8_t bMR, uint32_t ulInode, uint8_t bWhich, bool *pfAllocated);
-
-REDSTATUS RedInodeDataRead(CINODE *pInode, uint64_t ullStart, uint32_t *pulLen, void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedInodeDataWrite(CINODE *pInode, uint64_t ullStart, uint32_t *pulLen, const void *pBuffer);
-#if DELETE_SUPPORTED || TRUNCATE_SUPPORTED
-REDSTATUS RedInodeDataTruncate(CINODE *pInode, uint64_t ullSize);
-#endif
-#endif
-REDSTATUS RedInodeDataSeekAndRead(CINODE *pInode, uint32_t ulBlock);
-REDSTATUS RedInodeDataSeek(CINODE *pInode, uint32_t ulBlock);
-
-#if REDCONF_API_POSIX == 1
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedDirEntryCreate(CINODE *pPInode, const char *pszName, uint32_t ulInode);
-#endif
-#if DELETE_SUPPORTED
-REDSTATUS RedDirEntryDelete(CINODE *pPInode, uint32_t ulDeleteIdx);
-#endif
-REDSTATUS RedDirEntryLookup(CINODE *pPInode, const char *pszName, uint32_t *pulEntryIdx, uint32_t *pulInode);
-#if (REDCONF_API_POSIX_READDIR == 1) || (REDCONF_CHECKER == 1)
-REDSTATUS RedDirEntryRead(CINODE *pPInode, uint32_t *pulIdx, char *pszName, uint32_t *pulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1)
-REDSTATUS RedDirEntryRename(CINODE *pSrcPInode, const char *pszSrcName, CINODE *pSrcInode, CINODE *pDstPInode, const char *pszDstName, CINODE *pDstInode);
-#endif
-#endif
-
-REDSTATUS RedVolMount(void);
-REDSTATUS RedVolMountMaster(void);
-REDSTATUS RedVolMountMetaroot(void);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedVolTransact(void);
-#endif
-void RedVolCriticalError(const char *pszFileName, uint32_t ulLineNum);
-REDSTATUS RedVolSeqNumIncrement(void);
-
-#if FORMAT_SUPPORTED
-REDSTATUS RedVolFormat(void);
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcoremacs.h b/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcoremacs.h
deleted file mode 100755
index 2d1a433..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcoremacs.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDCOREMACS_H
-#define REDCOREMACS_H
-
-
-#define BLOCK_NUM_MASTER (0UL) /* Block number of the master block. */
-#define BLOCK_NUM_FIRST_METAROOT (1UL) /* Block number of the first metaroot. */
-
-#define BLOCK_SPARSE (0U)
-
-#define DINDIR_POINTERS ((INODE_ENTRIES - REDCONF_DIRECT_POINTERS) - REDCONF_INDIRECT_POINTERS)
-#define DINDIR_DATA_BLOCKS (INDIR_ENTRIES * INDIR_ENTRIES)
-
-#define INODE_INDIR_BLOCKS (REDCONF_INDIRECT_POINTERS * INDIR_ENTRIES)
-#define INODE_DINDIR_BLOCKS (DINDIR_POINTERS * DINDIR_DATA_BLOCKS)
-#define INODE_DATA_BLOCKS (REDCONF_DIRECT_POINTERS + INODE_INDIR_BLOCKS + INODE_DINDIR_BLOCKS)
-#define INODE_SIZE_MAX (UINT64_SUFFIX(1) * REDCONF_BLOCK_SIZE * INODE_DATA_BLOCKS)
-
-
-/* First inode number that can be allocated.
-*/
-#if REDCONF_API_POSIX == 1
-#define INODE_FIRST_FREE (INODE_FIRST_VALID + 1U)
-#else
-#define INODE_FIRST_FREE (INODE_FIRST_VALID)
-#endif
-
-/** @brief Determine if an inode number is valid.
-*/
-#define INODE_IS_VALID(INODENUM) (((INODENUM) >= INODE_FIRST_VALID) && ((INODENUM) < (INODE_FIRST_VALID + gpRedVolConf->ulInodeCount)))
-
-
-/* The number of blocks reserved to allow a truncate or delete operation to
- complete when the disk is otherwise full.
-
- The more expensive of the two operations is delete, which has to actually
- write to a file data block to remove the directory entry.
-*/
-#if REDCONF_READ_ONLY == 1
- #define RESERVED_BLOCKS 0U
-#elif (REDCONF_API_POSIX == 1) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
- #if DINDIR_POINTERS > 0U
- #define RESERVED_BLOCKS 3U
- #elif REDCONF_INDIRECT_POINTERS > 0U
- #define RESERVED_BLOCKS 2U
- #else
- #define RESERVED_BLOCKS 1U
- #endif
-#elif ((REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_FTRUNCATE == 1)) || ((REDCONF_API_FSE == 1) && (REDCONF_API_FSE_TRUNCATE == 1))
- #if DINDIR_POINTERS > 0U
- #define RESERVED_BLOCKS 2U
- #elif REDCONF_INDIRECT_POINTERS > 0U
- #define RESERVED_BLOCKS 1U
- #else
- #define RESERVED_BLOCKS 0U
- #endif
-#else
- #define RESERVED_BLOCKS 0U
-#endif
-
-
-#define CRITICAL_ASSERT(EXP) ((EXP) ? (void)0 : CRITICAL_ERROR())
-#define CRITICAL_ERROR() RedVolCriticalError(__FILE__, __LINE__)
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcorevol.h b/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcorevol.h
deleted file mode 100755
index 2b9ea7b..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/redcorevol.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDCOREVOL_H
-#define REDCOREVOL_H
-
-
-/** @brief Per-volume run-time data specific to the core.
-*/
-typedef struct
-{
- /** Whether this volume uses the inline imap (true) or external imap
- (false). Computed at initialization time based on the block count.
- */
- bool fImapInline;
-
-#if REDCONF_IMAP_EXTERNAL == 1
- /** First block number of the on-disk imap. Valid only when fImapInline
- is false.
- */
- uint32_t ulImapStartBN;
-
- /** The number of double-allocated imap nodes that make up the imap.
- */
- uint32_t ulImapNodeCount;
-#endif
-
- /** Block number where the inode table starts.
- */
- uint32_t ulInodeTableStartBN;
-
- /** First block number that can be allocated.
- */
- uint32_t ulFirstAllocableBN;
-
- /** The two metaroot structures, committed and working state.
- */
- METAROOT aMR[2U];
-
- /** The index of the current metaroot; must be 0 or 1.
- */
- uint8_t bCurMR;
-
- /** Whether the volume has been branched or not.
- */
- bool fBranched;
-
- /** The number of blocks which will become free after the next transaction.
- */
- uint32_t ulAlmostFreeBlocks;
-
- #if RESERVED_BLOCKS > 0U
- /** Whether to use the blocks reserved for operations that create free
- space.
- */
- bool fUseReservedBlocks;
- #endif
-} COREVOLUME;
-
-/* Pointer to the core volume currently being accessed; populated during
- RedCoreVolSetCurrent().
-*/
-extern COREVOLUME * CONST_IF_ONE_VOLUME gpRedCoreVol;
-
-/* Pointer to the metaroot currently being accessed; populated during
- RedCoreVolSetCurrent() and RedCoreVolTransact().
-*/
-extern METAROOT *gpRedMR;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/rednodes.h b/FreeRTOS-Plus/Source/Reliance-Edge/core/include/rednodes.h
deleted file mode 100755
index 34bc406..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/core/include/rednodes.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDNODES_H
-#define REDNODES_H
-
-
-#define NODEHEADER_SIZE (16U)
-#define NODEHEADER_OFFSET_SIG (0U)
-#define NODEHEADER_OFFSET_CRC (4U)
-#define NODEHEADER_OFFSET_SEQ (8U)
-
-/** @brief Common header for all metadata nodes.
-*/
-typedef struct
-{
- uint32_t ulSignature; /**< Value which uniquely identifies the metadata node type. */
- uint32_t ulCRC; /**< CRC-32 checksum of the node contents, starting after the CRC. */
- uint64_t ullSequence; /**< Current sequence number at the time the node was written to disk. */
-} NODEHEADER;
-
-
-/** Flag set in the master block when REDCONF_API_POSIX == 1. */
-#define MBFLAG_API_POSIX (0x01U)
-
-/** Flag set in the master block when REDCONF_INODE_TIMESTAMPS == 1. */
-#define MBFLAG_INODE_TIMESTAMPS (0x02U)
-
-/** Flag set in the master block when REDCONF_INODE_BLOCKS == 1. */
-#define MBFLAG_INODE_BLOCKS (0x04U)
-
-/** Flag set in the master block when (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1). */
-#define MBFLAG_INODE_NLINK (0x08U)
-
-
-/** @brief Node which identifies the volume and stores static volume information.
-*/
-typedef struct
-{
- NODEHEADER hdr; /**< Common node header. */
-
- uint32_t ulVersion; /**< On-disk layout version number. */
- char acBuildNum[8U]; /**< Build number of the product (not null terminated). */
- uint32_t ulFormatTime; /**< Date and time the volume was formatted. */
- uint32_t ulInodeCount; /**< Compile-time configured number of inodes. */
- uint32_t ulBlockCount; /**< Compile-time configured number of logical blocks. */
- uint16_t uMaxNameLen; /**< Compile-time configured maximum file name length. */
- uint16_t uDirectPointers; /**< Compile-time configured number of direct pointers per inode. */
- uint16_t uIndirectPointers; /**< Compile-time configured number of indirect pointers per inode. */
- uint8_t bBlockSizeP2; /**< Compile-time configured block size, expressed as a power of two. */
- uint8_t bFlags; /**< Compile-time booleans which affect on-disk structures. */
-} MASTERBLOCK;
-
-
-#if REDCONF_API_POSIX == 1
-#define METAROOT_HEADER_SIZE (NODEHEADER_SIZE + 16U) /* Size in bytes of the metaroot header fields. */
-#else
-#define METAROOT_HEADER_SIZE (NODEHEADER_SIZE + 12U) /* Size in bytes of the metaroot header fields. */
-#endif
-#define METAROOT_ENTRY_BYTES (REDCONF_BLOCK_SIZE - METAROOT_HEADER_SIZE) /* Number of bytes remaining in the metaroot block for entries. */
-#define METAROOT_ENTRIES (METAROOT_ENTRY_BYTES * 8U)
-
-/** @brief Metadata root node; each volume has two.
-*/
-typedef struct
-{
- NODEHEADER hdr; /**< Common node header. */
-
- uint32_t ulSectorCRC; /**< CRC-32 checksum of the first sector. */
- uint32_t ulFreeBlocks; /**< Number of allocable blocks that are free. */
- #if REDCONF_API_POSIX == 1
- uint32_t ulFreeInodes; /**< Number of inode slots that are free. */
- #endif
- uint32_t ulAllocNextBlock; /**< Forward allocation pointer. */
-
- /** Imap bitmap. With inline imaps, this is the imap bitmap that indicates
- which inode blocks are used and which allocable blocks are used.
- Otherwise, this bitmap toggles nodes in the external imap between one
- of two possible block locations.
- */
- uint8_t abEntries[METAROOT_ENTRY_BYTES];
-} METAROOT;
-
-
-#if REDCONF_IMAP_EXTERNAL == 1
-#define IMAPNODE_HEADER_SIZE (NODEHEADER_SIZE) /* Size in bytes of the imap node header fields. */
-#define IMAPNODE_ENTRY_BYTES (REDCONF_BLOCK_SIZE - IMAPNODE_HEADER_SIZE) /* Number of bytes remaining in the imap node for entries. */
-#define IMAPNODE_ENTRIES (IMAPNODE_ENTRY_BYTES * 8U)
-
-/** @brief One node of the external imap.
-*/
-typedef struct
-{
- NODEHEADER hdr; /**< Common node header. */
-
- /** Bitmap which indicates which inode blocks are used and which allocable
- blocks are used.
- */
- uint8_t abEntries[IMAPNODE_ENTRY_BYTES];
-} IMAPNODE;
-#endif
-
-
-#define INODE_HEADER_SIZE (NODEHEADER_SIZE + 8U + ((REDCONF_INODE_BLOCKS == 1) ? 4U : 0U) + \
- ((REDCONF_INODE_TIMESTAMPS == 1) ? 12U : 0U) + 4U + ((REDCONF_API_POSIX == 1) ? 4U : 0U))
-#define INODE_ENTRIES ((REDCONF_BLOCK_SIZE - INODE_HEADER_SIZE) / 4U)
-
-#if (REDCONF_DIRECT_POINTERS < 0) || (REDCONF_DIRECT_POINTERS > (INODE_ENTRIES - REDCONF_INDIRECT_POINTERS))
- #error "Configuration error: invalid value of REDCONF_DIRECT_POINTERS"
-#endif
-#if (REDCONF_INDIRECT_POINTERS < 0) || (REDCONF_INDIRECT_POINTERS > (INODE_ENTRIES - REDCONF_DIRECT_POINTERS))
- #error "Configuration error: invalid value of REDCONF_INDIRECT_POINTERS"
-#endif
-
-/** @brief Stores metadata for a file or directory.
-*/
-typedef struct
-{
- NODEHEADER hdr; /**< Common node header. */
-
- uint64_t ullSize; /**< Size of the inode, in bytes. */
-#if REDCONF_INODE_BLOCKS == 1
- uint32_t ulBlocks; /**< Total number file data blocks allocated to the inode. */
-#endif
-#if REDCONF_INODE_TIMESTAMPS == 1
- uint32_t ulATime; /**< Time of last access (seconds since January 1, 1970). */
- uint32_t ulMTime; /**< Time of last modification (seconds since January 1, 1970). */
- uint32_t ulCTime; /**< Time of last status change (seconds since January 1, 1970). */
-#endif
- uint16_t uMode; /**< Inode type (file or directory) and permissions (reserved). */
-#if (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
- uint16_t uNLink; /**< Link count, number of names pointing to the inode. */
-#else
- uint8_t abPadding[2]; /**< Padding to 32-bit align the next member. */
-#endif
-#if REDCONF_API_POSIX == 1
- uint32_t ulPInode; /**< Parent inode number. Only guaranteed to be accurate for directories. */
-#endif
-
- /** Block numbers for lower levels of the file metadata structure. Some
- fraction of these entries are for direct pointers (file data block
- numbers), some for indirect pointers, some for double-indirect
- pointers; the number allocated to each is static but user-configurable.
- For all types, an array slot is zero if the range is sparse or beyond
- the end of file.
- */
- uint32_t aulEntries[INODE_ENTRIES];
-} INODE;
-
-
-#define INDIR_HEADER_SIZE (NODEHEADER_SIZE + 4U)
-#define INDIR_ENTRIES ((REDCONF_BLOCK_SIZE - INDIR_HEADER_SIZE) / 4U)
-
-/** @brief Node for storing block pointers.
-*/
-typedef struct
-{
- NODEHEADER hdr; /**< Common node header. */
-
- uint32_t ulInode; /**< Inode which owns this indirect or double indirect. */
-
- /** For indirect nodes, stores block numbers of file data. For double
- indirect nodes, stores block numbers of indirect nodes. An array
- slot is zero if the corresponding block or indirect range is beyond
- the end of file or entirely sparse.
- */
- uint32_t aulEntries[INDIR_ENTRIES];
-} INDIR, DINDIR;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/doc/coding_style.txt b/FreeRTOS-Plus/Source/Reliance-Edge/doc/coding_style.txt
deleted file mode 100755
index 569c04e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/doc/coding_style.txt
+++ /dev/null
@@ -1,389 +0,0 @@
-Datalight Coding Style
-======================
-
-This is a description of the Datalight Coding Style intended for third parties
-who want to contribute code to Reliance Edge. This document is derived from the
-DDSS Coding Guidelines, but only contains a subset of the content which is most
-likely to be relevant to third party contributors.
-
-Reliance Edge complies with the MISRA-C:2012 coding guidelines, which includes
-many rules that affect coding style. Unfortunately the MISRA-C:2012 document is
-not freely available, and is much too long to be effectively summarized, but if
-you are familiar with the rules, adhere to them. A few important rules of
-thumb: avoid the goto and continue keywords; avoid using more than one break
-in a loop; and avoid having more than one return from a function (single point
-of exit); default cases in every switch statement; avoid recursion; and make
-generous use of parentheses. Outside of the file system driver, in tests and
-host tools, the MISRA-C rules are relaxed.
-
-Beyond MISRA-C, Datalight has a standard coding style. Most aspects of this
-style are matters of preference, but when contributing code to Datalight an
-effort should be made to use this style for the sake of consistency.
-
-Below is an example function, which illustrates several key points of Datalight
-Coding Style:
-
-/** @brief One-sentence description of what this function does.
-
- Additional description.
-
- @param ulFirstParameter Description of the parameter.
- @param pszPointer Description of the parameter.
-
- @return Describe the return value.
-
- @retval true Optional description of specific return value.
- @retval false Optional description of specific return value.
-*/
-bool ExampleFunction(
- uint32_t ulFirstParameter,
- char *pszPointer)
-{
- bool fStatus = true;
-
- /* This is a single-line comment.
- */
- if(ulFirstParameter > 0U)
- {
- /* This is a multi-line comment. Filler text: Lorem ipsum dolor sit
- amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
- ut labore et dolore magna aliqua.
- */
- FunctionCall();
-
- while(fStatus)
- {
- fStatus = AnotherFunction(ulFirstParameter, pszPointer);
- }
- }
-
- return fStatus;
-}
-
-Tab Stop Conventions
---------------------
-
-In all C code (.c/.h), use a tab width of four spaces, and use soft tabs (in
-other words, tabs are expanded to spaces). In Makefiles, use hard tabs and a
-tab width of 8.
-
-Naming
-------
-
-Datalight uses CamelCase for functions and variables. Type names are generally
-UPPERCASE, except for standard types like uint32_t. Preprocessor macros are
-UPPERCASE, with words separated by underscores (for example, INODE_INVALID).
-
-Doxygen Documentation
----------------------
-
-Doxygen is used to document functions (including static functions), along with
-types, structures, files, etc. For Doxygen tags, use '@' instead of a backslash
-(thus "@param" not "\param").
-
-Function Declarations
----------------------
-
-Multi-line function declarations are preferred, as they tend to be more
-readable. Use the following form:
-
-static bool ExampleFunctionDeclaration(
- uint32_t ulFirstParameter,
- char *pszPointer,
- uint8_t **ppbBuffer)
-{
- uint16_t uLocalVar; /* descriptive comment */
- uint8_t *pbBuffer = NULL; /* descriptive comment */
-
- Function body...
-}
-
-The following guidelines should be used:
-
-- Align both the data-type and the variable names, for parameters and locals, at
- the same level if practical.
-- For pointer types, the '*' belongs to the variable name---it's not part of the
- data-type, so keep it with the variable name.
-- If useful, single line comments may be used to describe local variables (not
- a requirement).
-- For functions with no parameters, the "void" declaration does not need to be
- on a separate line.
-- Generally each variable should be declared on a separate line. This promotes
- readability, and facilitates having a comment for each variable.
-
-Function declarations should be spaced apart by two blank lines between the
-closing brace which ends a function and the Doxygen comment which starts the
-next.
-
-Curly Braces
-------------
-
-Datalight lines up all curly braces vertically. As per MISRA-C, curly braces
-are never omitted, even if the braces contain only a single statement.
-
-For consistency, even structure declarations and initializations should use the
-same style, with the curly braces lined up vertically. One exception is for
-structure initializations where both the opening and closing curly braces can
-fit on the same line. If so, do it.
-
-Code Comments
--------------
-
-Datalight uses the standard C style /* comments */. C++ style comments (//) are
-never used. The Datalight standard comment style is shown below. This style
-applies to all general comments within the code.
-
-/* This is a single-line comment.
-*/
-if(ulFirstParameter > 0U)
-{
- /* This is a multi-line comment. Filler text: Lorem ipsum dolor sit amet,
- consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
- et dolore magna aliqua.
- */
- while(fStatus)
- {
- }
-}
-
-Note the characteristics:
-
-- The /* and */ align with the natural 4 character indentation.
-- The comment text is exactly indented another 4 characters.
-- The comment text starts on the same line as the opening /*.
-- The terminating */ is on its own line.
-- There is usually a single blank line preceding the comment, however if the
- preceding line is an opening curly brace, then an extra blank line is not
- necessary.
-- There is usually no blank line after the comment, but rather the closing */
- "attaches" the comment to the code about which the comment refers.
-- These comments should always fit with the standard 80 character margin.
-
-Comments where the /* and */ are on the same line may be used in a few places:
-
-- For variable or parameter descriptions, where the comment fits on the same
- line as the declaration.
-- For structure member declarations, where the comment fits on the same line as
- the declaration.
-- For macros or preprocessor logic, where the comment fits on the same line.
-
-It is OK for such comments to exceed the 80 character margin by a small amount,
-if necessary, as this sometimes promotes code readability.
-
-Indentation Style
------------------
-
-The general paradigm used in Datalight code is that curly braces line up
-vertically, and everything in between them is indented. This should include all
-comments, labels, and preprocessor symbols. The only things which are aligned
-at the left-most columns are:
-
-- Symbols, variables, declarations, and preprocessor logic which are at the
- module-scope (outside of a function)
-- Comments which are outside of a function
-- Function declarations
-- Function open and closing curly braces
-
-Typically comments are always lined up directly with the code to which they
-apply.
-
-Labels (when used; gotos are disallowed in driver code) are lined up two
-characters to the left of the code they reside in, to make them stand out, while
-as the same time, still remaining subservient to the level of curly braces in
-which they reside. For example:
-
-bool ExampleLabelUsage(void)
-{
- MutexLock();
-
- Lots of complicated code...
-
- Unlock:
-
- MutexUnlock();
-
- return fSuccess;
-}
-
-Preprocessor logic, such as controlling features which are conditionally
-compiled in or out, should not disrupt the flow of the code, but rather should
-be indented in similar fashion to the code it controls, but positioned two
-characters to the left. For example, consider the following code snippet. The
-preprocessor conditions are both indented relative to the outer curly braces,
-but do not disrupt the normal code flow.
-
-int32_t red_statvfs(
- const char *pszVolume,
- REDSTATFS *pStatvfs)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolStat(pStatvfs);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-Note that, like anything else between curly brackets, the contents of a switch
-statement are indented:
-
-switch(ulSignature)
-{
- case META_SIG_MASTER:
- fValid = (uFlags == BFLAG_META_MASTER);
- break;
- case META_SIG_IMAP:
- fValid = (uFlags == BFLAG_META_IMAP);
- break;
- case META_SIG_INODE:
- fValid = (uFlags == BFLAG_META_INODE);
- break;
- case META_SIG_DINDIR:
- fValid = (uFlags == BFLAG_META_DINDIR);
- break;
- case META_SIG_INDIR:
- fValid = (uFlags == BFLAG_META_INDIR);
- break;
- default:
- fValid = false;
- break;
-}
-
-Maximum Line Length
--------------------
-
-The maximum line length for code need not be rigidly limited to the traditional
-80 characters. Nevertheless the line lengths should be kept reasonable.
-Anything longer than 100 to 120 characters should probably be broken up. The
-most important consideration is readability---fitting on the screen is important
-for readability, but equally important is facilitating an easy understanding of
-the logical code flow.
-
-There are a few exceptions on both sides of the issue. Generally comments
-should be limited to 80 characters always. Some lines of code may exceed the
-120 character length by a large margin, if it makes the code more understandable
-and maintainable. This is especially true when dealing with code that generates
-output which needs to be lined up.
-
-Regardless of everything else, no lines should exceed 250 characters because
-some editors cannot handle anything larger.
-
-Maximum Display Output Line Length
-----------------------------------
-
-Any code which displays TTY style output, whether on a screen or a terminal,
-should be constructed so the output is readable and wraps properly on an 80
-character wide display. This primarily applies to the "standard" output from
-various tests and tools as well as syntax output for those tests and tools;
-debug output can violate this rule.
-
-Preprocessor Notation
----------------------
-
-Don't use preprocessor notation where the # is separated from the keyword by one
-or more white spaces. For example, don't do:
-
-#ifndef SYMBOL1
-# define SYMBOL1
-#endif
-
-Instead, do:
-
-#ifndef SYMBOL1
- #define SYMBOL1
-#endif
-
-Hexadecimal Notation
---------------------
-
-Use uppercase for any alphabetic hexadecimal digits, and lower case for the
-notational element. For example:
-
-#define HEXNUM 0x123abd /* Bad */
-#define HEXNUM 0X123ABD /* Bad */
-#define HEXNUM 0x123ABD /* Good */
-
-Hungarian Notation
-------------------
-
-Datalight uses Hungarian notation. The following type prefixes are used:
-
-Type Prefix | Meaning
------------ | -------
-c | char
-uc | unsigned char
-i | int
-n | unsigned int or size_t
-b | uint8_t
-u | uint16_t
-ul | uint32_t
-ull | uint64_t
-sz | array of char that will be null-terminated
-f | bool
-h | A handle
-fn | A function (always used with the "p" modifier)
-
-There is no official Hungarian for int8_t, int16_t, int32_t, or int64_t,
-although some code uses unofficial variants (like "ll" for int64_t).
-
-The following modifiers may be used in combination with the type prefixes
-defined above, or in combination with other types:
-
-Modifier | Meaning
--------- | -------
-a | An array
-p | A pointer
-g | A global variable
-
-Notes:
-
-- There is no standard Hungarian for structure declarations, however the use of
- the "a" and "p" modifiers is completely appropriate (and expected).
-- For those data types which do not have any standard defined Hungarian prefix,
- using none is preferable to misusing another prefix which would lead to
- confusion.
-- The "p" pointer modifier must be used such that a variable which is a pointer
- to a pointer uses multiple "p" prefixes. A general rule-of-thumb is that the
- variable name should have the same number of "p" prefixes as the declaration
- has asterisks. This allows pointer expressions to be easily decoded using
- cancellation.
-
-Variable Scope
---------------
-
-Declare a variable in the narrowest scope in which it is meaningful.
-Unnecessarily declaring all variables at the beginning of a function, where they
-may be physically far from where they are actually used, makes the code harder
-to maintain.
-
-When multiple blocks of code share a variable, but not its value, declare the
-variable separately for each code block.
-
-For example, if two separate blocks contain loops indexed by a variable ulIndex
-declare it separately in each block rather than declaring it once in a wider
-scope and using it in both places.
-
-Using distinct declarations in the two blocks allows the compiler to check for
-failure to initialize the variable in the second block. If there is a single
-declaration, the (now meaningless) value left over from the first block can be
-used erroneously in the second block.
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.md b/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.md
deleted file mode 100755
index 2a3d937..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.md
+++ /dev/null
@@ -1,135 +0,0 @@
-# Reliance Edge Release Notes
-
-This file contains a list of updates made to Reliance Edge over the course of
-recent releases and a list of known issues.
-
-## Release History and Changes
-
-### Reliance Edge v2.0, January 2017
-
-- Added support for Linux as a host environment
- - All "host" projects may now be built in either Windows or Linux using the
- `make` command. The formatter and image builder are built, and the checker
- and image copier are also built in the commercial kit.
- - An additional host tool has been added for Linux only: `redfuse`. It is a
- File System in User Space (FUSE) implementation, allowing a Reliance Edge
- volume to be mounted directly on Linux for easy access. It is built from
- the host project folder using the command `make redfuse`.
- - The OS-specific API test (commercial kit only) is now ported to run on Linux
- for the purpose of verifying the FUSE implementation.
-- Fixed a bug that could leave a directory in an invalid state after removing
- files. For example, an affected directory might report a non-zero length even
- after all files had been deleted.
-- Fixed a bug that would leave the driver in a bad state if a mount operation
- failed due to missing or corrupt metaroot blocks.
-
-### Reliance Edge v1.1 (Beta), November 2016
-
-- Added support for a discard (trim) interface in the commercial kit. While
- discards are not integral to the behavior of the filesystem, they allow
- certain types of Flash drivers and media to perform at optimal speed and
- efficiency. The commercial version of Reliance Edge now allows the user to
- implement this interface for compatible storage media.
- - This change added new fields to the configuration files redconf.h and
- redconf.c. The configuration utility has been updated to version 1.1 and
- existing configuration files must be updated using the updated utility.
-- The configuration utility now has keyboard shortcuts for opening and saving
- the configuration.
-- The configuration utility now adds version macros to easily identify when an
- outdated configuration file is used with Reliance Edge or vice versa.
-
-### Reliance Edge v1.0.4, July 2016
-
-- Added ARM mbed and ARM mbed OS support in the commercial kit, with an example
- projects for ARM mbed OS on the NXP FRDM-K64F board.
-- Some minor deficiencies in the POSIX-like API test suite have been addressed.
-
-### Reliance Edge v1.0.3, June 2016
-
-- Added support for static memory allocation configuration in FreeRTOS
- version 9. No common code changes.
-
-### Reliance Edge v1.0.2, February 2016
-
-#### Common Code Changes
-- A new per-volume configuration option has been added: users can specify a
- number of times to retry a block device read, write or flush operation before
- returning a failure. The configuration tool has been updated to version 1.0.2
- with this change.
- - This added a new field to the volume configuration in redconf.c: existing
- redconf.c files from v1.0.1 and earlier must be updated to work with v1.0.2.
- Open redconf.h and redconf.c with the configuration tool, enable
- "Retry block device I/O on failure" for any volumes if desired, and save the
- redconf files.
-
-#### FreeRTOS Port Changes
-- Added support for the STM32 HAL SD card driver in the FreeRTOS block device
- interface. Two boards are supported out-of-the-box: the STM324xG-EVAL and the
- STM32F746NG-Discovery. A sample project is included for the STM324xG-EVAL.
-
-#### MQX Port Changes
-- Fixed a bug which prevented Reliance Edge from compiling if the File System
- Essentials API was selected in the configuration.
-- Fixed a bug which would have returned an uninitialized value from
- `RedOsBDevFlush()` for block devices that support flushing.
-
-### Reliance Edge v1.0.1, October 2015
-
-- Added MQX RTOS support in the commercial kit, with example projects for
- the Kinetis Design Studio.
-- Bug fix in the F_DRIVER implementation of the FreeRTOS block device service.
-
-### Reliance Edge v1.0, July 2015
-
-#### Common Code Changes
-
-- First release of commercial kit and MISRA C:2012 Design Assurance Package.
- The commercial kit includes many new tools and tests which were not previously
- available.
-- Overhauled parsing of command-line parameters to be consistent for all tools
- and tests. Command-line tools now use Unix-style short and long options (such
- as `-H` and `--help`) instead of DOS-style switches (such as `/?`).
-- Renamed all os/\*/include/ostypes.h headers to os/\*/include/redostypes.h, so
- that all headers use the product prefix. If you created a port using v0.9,
- this header needs to be renamed and its header guard (#ifndef OSTYPES_H etc.)
- should also be updated.
-- Add a new header for OS-specific MISRA C:2012 deviation macros, located at
- os/\*/include/redosdeviations.h. If you created a port using v0.9, copy the
- template from os/stub/include/redosdeviations.h into the include directory.
-- Eliminated support for sector sizes less than 256. If using a smaller sector
- size (say for a RAM disk), this must now be emulated in the implementation of
- the block device OS service.
-- Added RedFseFormat() as an optional FSE API, allowing FSE applications to
- format the volume at run-time.
- - This added a new macro to redconf.h: existing redconf.h files from v0.9 must
- be updated to work with v1.0. Open redconf.h with the configuration tool,
- ignore the warning about the missing macro, and save it.
-- Internal restructuring has renamed the macros for the string and memory
- functions used in redconf.h. An existing redconf.h file from v0.9 will need
- to be updated; for a file containing the old names, the new config tool will
- default to using the (slow) Reliance Edge string/memory functions; to use the
- C library or custom versions, this will need to be selected in the
- configuration utility.
-- Fix a bug which would result in an error when attempting to create a name with
- one or more trailing path separators (such as `red_mkdir("/foo/bar/")`).
-- Fix a bug where an open handle for an inode on one volume would prevent the
- same inode number from being deleted on a different volume.
-
-#### FreeRTOS Port Changes
-
-- The implementation of the timestamp OS service no longer requires that
- `configUSE_TIMERS` be set to `1`.
-
-### Reliance Edge v0.9 (Beta), April 2015
-
-First public release.
-
-## Known Issues
-
-### Visual Studio 2005
-
-The Reliance Edge Win32 port (used for the host tools and the Win32 test
-project) cannot be compiled by Visual Studio 2005. This is not going to be
-fixed since VS2005 is an old toolset. Newer versions of Visual Studio, starting
-with Visual Studio 2008, work just fine.
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.txt b/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.txt
deleted file mode 100755
index 341eb5d..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/doc/release_notes.txt
+++ /dev/null
@@ -1,156 +0,0 @@
-
-
-RELIANCE EDGE RELEASE NOTES
-
-
-This file contains a list of updates made to Reliance Edge over the
-course of recent releases and a list of known issues.
-
-
-Release History and Changes
-
-Reliance Edge v2.0, January 2017
-
-- Added support for Linux as a host environment
-- All "host" projects may now be built in either Windows or Linux
- using the make command. The formatter and image builder are built,
- and the checker and image copier are also built in the
- commercial kit.
-- An additional host tool has been added for Linux only: redfuse. It
- is a File System in User Space (FUSE) implementation, allowing a
- Reliance Edge volume to be mounted directly on Linux for
- easy access. It is built from the host project folder using the
- command make redfuse.
-- The OS-specific API test (commercial kit only) is now ported to run
- on Linux for the purpose of verifying the FUSE implementation.
-- Fixed a bug that could leave a directory in an invalid state after
- removing files. For example, an affected directory might report a
- non-zero length even after all files had been deleted.
-- Fixed a bug that would leave the driver in a bad state if a mount
- operation failed due to missing or corrupt metaroot blocks.
-
-Reliance Edge v1.1 (Beta), November 2016
-
-- Added support for a discard (trim) interface in the commercial kit.
- While discards are not integral to the behavior of the filesystem,
- they allow certain types of Flash drivers and media to perform at
- optimal speed and efficiency. The commercial version of Reliance
- Edge now allows the user to implement this interface for compatible
- storage media.
-- This change added new fields to the configuration files redconf.h
- and redconf.c. The configuration utility has been updated to version
- 1.1 and existing configuration files must be updated using the
- updated utility.
-- The configuration utility now has keyboard shortcuts for opening and
- saving the configuration.
-- The configuration utility now adds version macros to easily identify
- when an outdated configuration file is used with Reliance Edge or
- vice versa.
-
-Reliance Edge v1.0.4, July 2016
-
-- Added ARM mbed and ARM mbed OS support in the commercial kit, with
- an example projects for ARM mbed OS on the NXP FRDM-K64F board.
-- Some minor deficiencies in the POSIX-like API test suite have
- been addressed.
-
-Reliance Edge v1.0.3, June 2016
-
-- Added support for static memory allocation configuration in FreeRTOS
- version 9. No common code changes.
-
-Reliance Edge v1.0.2, February 2016
-
-Common Code Changes
-
-- A new per-volume configuration option has been added: users can
- specify a number of times to retry a block device read, write or
- flush operation before returning a failure. The configuration tool
- has been updated to version 1.0.2 with this change.
-- This added a new field to the volume configuration in redconf.c:
- existing redconf.c files from v1.0.1 and earlier must be updated to
- work with v1.0.2. Open redconf.h and redconf.c with the
- configuration tool, enable "Retry block device I/O on failure" for
- any volumes if desired, and save the redconf files.
-
-FreeRTOS Port Changes
-
-- Added support for the STM32 HAL SD card driver in the FreeRTOS block
- device interface. Two boards are supported out-of-the-box: the
- STM324xG-EVAL and the STM32F746NG-Discovery. A sample project is
- included for the STM324xG-EVAL.
-
-MQX Port Changes
-
-- Fixed a bug which prevented Reliance Edge from compiling if the File
- System Essentials API was selected in the configuration.
-- Fixed a bug which would have returned an uninitialized value from
- RedOsBDevFlush() for block devices that support flushing.
-
-Reliance Edge v1.0.1, October 2015
-
-- Added MQX RTOS support in the commercial kit, with example projects
- for the Kinetis Design Studio.
-- Bug fix in the F_DRIVER implementation of the FreeRTOS block
- device service.
-
-Reliance Edge v1.0, July 2015
-
-Common Code Changes
-
-- First release of commercial kit and MISRA C:2012 Design
- Assurance Package. The commercial kit includes many new tools and
- tests which were not previously available.
-- Overhauled parsing of command-line parameters to be consistent for
- all tools and tests. Command-line tools now use Unix-style short and
- long options (such as -H and --help) instead of DOS-style switches
- (such as /?).
-- Renamed all os/*/include/ostypes.h headers to
- os/*/include/redostypes.h, so that all headers use the
- product prefix. If you created a port using v0.9, this header needs
- to be renamed and its header guard (#ifndef OSTYPES_H etc.) should
- also be updated.
-- Add a new header for OS-specific MISRA C:2012 deviation macros,
- located at os/*/include/redosdeviations.h. If you created a port
- using v0.9, copy the template from os/stub/include/redosdeviations.h
- into the include directory.
-- Eliminated support for sector sizes less than 256. If using a
- smaller sector size (say for a RAM disk), this must now be emulated
- in the implementation of the block device OS service.
-- Added RedFseFormat() as an optional FSE API, allowing FSE
- applications to format the volume at run-time.
-- This added a new macro to redconf.h: existing redconf.h files from
- v0.9 must be updated to work with v1.0. Open redconf.h with the
- configuration tool, ignore the warning about the missing macro, and
- save it.
-- Internal restructuring has renamed the macros for the string and
- memory functions used in redconf.h. An existing redconf.h file from
- v0.9 will need to be updated; for a file containing the old names,
- the new config tool will default to using the (slow) Reliance Edge
- string/memory functions; to use the C library or custom versions,
- this will need to be selected in the configuration utility.
-- Fix a bug which would result in an error when attempting to create a
- name with one or more trailing path separators (such as
- red_mkdir("/foo/bar/")).
-- Fix a bug where an open handle for an inode on one volume would
- prevent the same inode number from being deleted on a
- different volume.
-
-FreeRTOS Port Changes
-
-- The implementation of the timestamp OS service no longer requires
- that configUSE_TIMERS be set to 1.
-
-Reliance Edge v0.9 (Beta), April 2015
-
-First public release.
-
-
-Known Issues
-
-Visual Studio 2005
-
-The Reliance Edge Win32 port (used for the host tools and the Win32 test
-project) cannot be compiled by Visual Studio 2005. This is not going to
-be fixed since VS2005 is an old toolset. Newer versions of Visual
-Studio, starting with Visual Studio 2008, work just fine.
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/fse/fse.c b/FreeRTOS-Plus/Source/Reliance-Edge/fse/fse.c
deleted file mode 100755
index 1e629e5..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/fse/fse.c
+++ /dev/null
@@ -1,690 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implementation of the Reliance Edge FSE API.
-*/
-#include
-
-#if REDCONF_API_FSE == 1
-
-/** @defgroup red_group_fse The File System Essentials Interface
- @{
-*/
-
-#include
-#include
-#include
-
-
-static REDSTATUS FseEnter(uint8_t bVolNum);
-static void FseLeave(void);
-
-
-static bool gfFseInited; /* Whether driver is initialized. */
-
-
-/** @brief Initialize the Reliance Edge file system driver.
-
- Prepares the Reliance Edge file system driver to be used. Must be the first
- Reliance Edge function to be invoked: no volumes can be mounted until the
- driver has been initialized.
-
- If this function is called when the Reliance Edge driver is already
- initialized, it does nothing and returns success.
-
- This function is not thread safe: attempting to initialize from multiple
- threads could leave things in a bad state.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedFseInit(void)
-{
- REDSTATUS ret;
-
- if(gfFseInited)
- {
- ret = 0;
- }
- else
- {
- ret = RedCoreInit();
-
- if(ret == 0)
- {
- gfFseInited = true;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize the Reliance Edge file system driver.
-
- Tears down the Reliance Edge file system driver. Cannot be used until all
- Reliance Edge volumes are unmounted. A subsequent call to RedFseInit()
- will initialize the driver again.
-
- If this function is called when the Reliance Edge driver is already
- uninitialized, it does nothing and returns success.
-
- This function is not thread safe: attempting to uninitialize from multiple
- threads could leave things in a bad state.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBUSY At least one volume is still mounted.
-*/
-REDSTATUS RedFseUninit(void)
-{
- REDSTATUS ret = 0;
-
- if(!gfFseInited)
- {
- ret = 0;
- }
- else
- {
- uint8_t bVolNum;
-
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexAcquire();
- #endif
-
- for(bVolNum = 0U; bVolNum < REDCONF_VOLUME_COUNT; bVolNum++)
- {
- if(gaRedVolume[bVolNum].fMounted)
- {
- ret = -RED_EBUSY;
- break;
- }
- }
-
- if(ret == 0)
- {
- gfFseInited = false;
- }
-
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexRelease();
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreUninit();
- }
- }
-
- return ret;
-}
-
-
-/** @brief Mount a file system volume.
-
- Prepares the file system volume to be accessed. Mount will fail if the
- volume has never been formatted, or if the on-disk format is inconsistent
- with the compile-time configuration.
-
- If the volume is already mounted, this function does nothing and returns
- success.
-
- @param bVolNum The volume number of the volume to be mounted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number; or the driver is
- uninitialized.
- @retval -RED_EIO Volume not formatted, improperly formatted, or corrupt.
-*/
-REDSTATUS RedFseMount(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- if(!gpRedVolume->fMounted)
- {
- ret = RedCoreVolMount();
- }
-
- FseLeave();
- }
-
- return ret;
-}
-
-
-/** @brief Unmount a file system volume.
-
- This function discards the in-memory state for the file system and marks it
- as unmounted. Subsequent attempts to access the volume will fail until the
- volume is mounted again.
-
- If unmount automatic transaction points are enabled, this function will
- commit a transaction point prior to unmounting. If unmount automatic
- transaction points are disabled, this function will unmount without
- transacting, effectively discarding the working state.
-
- Before unmounting, this function will wait for any active file system
- thread to complete by acquiring the FS mutex. The volume will be marked as
- unmounted before the FS mutex is released, so subsequent FS threads will
- possibly block and then see an error when attempting to access a volume
- which is unmounting or unmounted.
-
- If the volume is already unmounted, this function does nothing and returns
- success.
-
- @param bVolNum The volume number of the volume to be unmounted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number; or the driver is
- uninitialized.
- @retval -RED_EIO I/O error during unmount automatic transaction point.
-*/
-REDSTATUS RedFseUnmount(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- if(gpRedVolume->fMounted)
- {
- ret = RedCoreVolUnmount();
- }
-
- FseLeave();
- }
-
- return ret;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_FORMAT == 1)
-/** @brief Format a file system volume.
-
- Uses the statically defined volume configuration. After calling this
- function, the volume needs to be mounted -- see RedFseMount().
-
- An error is returned if the volume is mounted.
-
- @param bVolNum The volume number of the volume to be formatted.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBUSY The volume is mounted.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number; or the driver is
- uninitialized.
- @retval -RED_EIO I/O error formatting the volume.
-*/
-REDSTATUS RedFseFormat(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- ret = RedCoreVolFormat();
-
- FseLeave();
- }
-
- return ret;
-}
-#endif
-
-
-/** @brief Read from a file.
-
- Data which has not yet been written, but which is before the end-of-file
- (sparse data), shall read as zeroes. A short read -- where the number of
- bytes read is less than requested -- indicates that the requested read was
- partially or, if zero bytes were read, entirely beyond the end-of-file.
-
- If @p ullFileOffset is at or beyond the maximum file size, it is treated
- like any other read entirely beyond the end-of-file: no data is read and
- zero is returned.
-
- @param bVolNum The volume number of the file to read.
- @param ulFileNum The file number of the file to read.
- @param ullFileOffset The file offset to read from.
- @param ulLength The number of bytes to read.
- @param pBuffer The buffer to populate with the data read. Must be
- at least ulLength bytes in size.
-
- @return The number of bytes read (nonnegative) or a negated ::REDSTATUS
- code indicating the operation result (negative).
-
- @retval >=0 The number of bytes read from the file.
- @retval -RED_EBADF @p ulFileNum is not a valid file number.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted;
- or @p pBuffer is `NULL`; or @p ulLength exceeds
- INT32_MAX and cannot be returned properly.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-int32_t RedFseRead(
- uint8_t bVolNum,
- uint32_t ulFileNum,
- uint64_t ullFileOffset,
- uint32_t ulLength,
- void *pBuffer)
-{
- int32_t ret;
-
- if(ulLength > (uint32_t)INT32_MAX)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = FseEnter(bVolNum);
- }
-
- if(ret == 0)
- {
- uint32_t ulReadLen = ulLength;
-
- ret = RedCoreFileRead(ulFileNum, ullFileOffset, &ulReadLen, pBuffer);
-
- FseLeave();
-
- if(ret == 0)
- {
- ret = (int32_t)ulReadLen;
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write to a file.
-
- If the write extends beyond the end-of-file, the file size will be
- increased.
-
- A short write -- where the number of bytes written is less than requested
- -- indicates either that the file system ran out of space but was still
- able to write some of the request; or that the request would have caused
- the file to exceed the maximum file size, but some of the data could be
- written prior to the file size limit.
-
- If an error is returned (negative return), either none of the data was
- written or a critical error occurred (like an I/O error) and the file
- system volume will be read-only.
-
- @param bVolNum The volume number of the file to write.
- @param ulFileNum The file number of the file to write.
- @param ullFileOffset The file offset to write at.
- @param ulLength The number of bytes to write.
- @param pBuffer The buffer containing the data to be written. Must
- be at least ulLength bytes in size.
-
- @return The number of bytes written (nonnegative) or a negated ::REDSTATUS
- code indicating the operation result (negative).
-
- @retval >0 The number of bytes written to the file.
- @retval -RED_EBADF @p ulFileNum is not a valid file number.
- @retval -RED_EFBIG No data can be written to the given file offset since
- the resulting file size would exceed the maximum file
- size.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted;
- or @p pBuffer is `NULL`; or @p ulLength exceeds
- INT32_MAX and cannot be returned properly.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC No data can be written because there is insufficient
- free space.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-int32_t RedFseWrite(
- uint8_t bVolNum,
- uint32_t ulFileNum,
- uint64_t ullFileOffset,
- uint32_t ulLength,
- const void *pBuffer)
-{
- int32_t ret;
-
- if(ulLength > (uint32_t)INT32_MAX)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = FseEnter(bVolNum);
- }
-
- if(ret == 0)
- {
- uint32_t ulWriteLen = ulLength;
-
- ret = RedCoreFileWrite(ulFileNum, ullFileOffset, &ulWriteLen, pBuffer);
-
- FseLeave();
-
- if(ret == 0)
- {
- ret = (int32_t)ulWriteLen;
- }
- }
-
- return ret;
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_TRUNCATE == 1)
-/** @brief Truncate a file (set the file size).
-
- Allows the file size to be increased, decreased, or to remain the same. If
- the file size is increased, the new area is sparse (will read as zeroes).
- If the file size is decreased, the data beyond the new end-of-file will
- return to free space once it is no longer part of the committed state
- (either immediately or after the next transaction point).
-
- This function can fail when the disk is full if @p ullNewFileSize is
- non-zero. If decreasing the file size, this can be fixed by transacting and
- trying again: Reliance Edge guarantees that it is possible to perform a
- truncate of at least one file that decreases the file size after a
- transaction point. If disk full transactions are enabled, this will happen
- automatically.
-
- @param bVolNum The volume number of the file to truncate.
- @param ulFileNum The file number of the file to truncate.
- @param ullNewFileSize The new file size, in bytes.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulFileNum is not a valid file number.
- @retval -RED_EFBIG @p ullNewFileSize exceeds the maximum file size.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOSPC Insufficient free space to perform the truncate.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedFseTruncate(
- uint8_t bVolNum,
- uint32_t ulFileNum,
- uint64_t ullNewFileSize)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- ret = RedCoreFileTruncate(ulFileNum, ullNewFileSize);
-
- FseLeave();
- }
-
- return ret;
-}
-#endif
-
-
-/** @brief Retrieve the size of a file.
-
- @param bVolNum The volume number of the file whose size is being read.
- @param ulFileNum The file number of the file whose size is being read.
-
- @return The size of the file (nonnegative) or a negated ::REDSTATUS code
- indicating the operation result (negative).
-
- @retval >=0 The size of the file.
- @retval -RED_EBADF @p ulFileNum is not a valid file number.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-int64_t RedFseSizeGet(
- uint8_t bVolNum,
- uint32_t ulFileNum)
-{
- int64_t ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- uint64_t ullSize;
-
- ret = RedCoreFileSizeGet(ulFileNum, &ullSize);
-
- FseLeave();
-
- if(ret == 0)
- {
- /* Unless there is an on-disk format change, the maximum file size
- is guaranteed to be less than INT64_MAX, and so it can be safely
- returned in an int64_t.
- */
- REDASSERT(ullSize < (uint64_t)INT64_MAX);
-
- ret = (int64_t)ullSize;
- }
- }
-
- return ret;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_TRANSMASKSET == 1)
-/** @brief Update the transaction mask.
-
- The following events are available:
-
- - #RED_TRANSACT_UMOUNT
- - #RED_TRANSACT_WRITE
- - #RED_TRANSACT_TRUNCATE
- - #RED_TRANSACT_VOLFULL
-
- The #RED_TRANSACT_MANUAL macro (by itself) may be used to disable all
- automatic transaction events. The #RED_TRANSACT_MASK macro is a bitmask of
- all transaction flags, excluding those representing excluded functionality.
-
- Attempting to enable events for excluded functionality will result in an
- error.
-
- @param bVolNum The volume number of the volume whose transaction mask
- is being changed.
- @param ulEventMask A bitwise-OR'd mask of automatic transaction events to
- be set as the current transaction mode.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted;
- or @p ulEventMask contains invalid bits.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedFseTransMaskSet(
- uint8_t bVolNum,
- uint32_t ulEventMask)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- ret = RedCoreTransMaskSet(ulEventMask);
-
- FseLeave();
- }
-
- return ret;
-}
-#endif
-
-
-#if REDCONF_API_FSE_TRANSMASKGET == 1
-/** @brief Read the transaction mask.
-
- If the volume is read-only, the returned event mask is always zero.
-
- @param bVolNum The volume number of the volume whose transaction mask
- is being retrieved.
- @param pulEventMask Populated with a bitwise-OR'd mask of automatic
- transaction events which represent the current
- transaction mode for the volume.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted;
- or @p pulEventMask is `NULL`.
-*/
-REDSTATUS RedFseTransMaskGet(
- uint8_t bVolNum,
- uint32_t *pulEventMask)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- ret = RedCoreTransMaskGet(pulEventMask);
-
- FseLeave();
- }
-
- return ret;
-}
-#endif
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Commit a transaction point.
-
- Reliance Edge is a transactional file system. All modifications, of both
- metadata and filedata, are initially working state. A transaction point
- is a process whereby the working state atomically becomes the committed
- state, replacing the previous committed state. Whenever Reliance Edge is
- mounted, including after power loss, the state of the file system after
- mount is the most recent committed state. Nothing from the committed
- state is ever missing, and nothing from the working state is ever included.
-
- @param bVolNum The volume number of the volume to transact.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number or not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EROFS The file system volume is read-only.
-*/
-REDSTATUS RedFseTransact(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- ret = FseEnter(bVolNum);
-
- if(ret == 0)
- {
- ret = RedCoreVolTransact();
-
- FseLeave();
- }
-
- return ret;
-}
-#endif
-
-/** @} */
-
-/** @brief Enter the file system driver.
-
- @param bVolNum The volume to be accessed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The file system driver is uninitialized; or @p bVolNum
- is not a valid volume number.
-*/
-static REDSTATUS FseEnter(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(gfFseInited)
- {
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexAcquire();
- #endif
-
- /* This also serves to range-check the volume number (even in single
- volume configurations).
- */
- ret = RedCoreVolSetCurrent(bVolNum);
-
- #if REDCONF_TASK_COUNT > 1U
- if(ret != 0)
- {
- RedOsMutexRelease();
- }
- #endif
- }
- else
- {
- ret = -RED_EINVAL;
- }
-
- return ret;
-}
-
-
-/** @brief Leave the file system driver.
-*/
-static void FseLeave(void)
-{
- REDASSERT(gfFseInited);
-
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexRelease();
- #endif
-}
-
-
-#endif /* REDCONF_API_FSE == 1 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redapimacs.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redapimacs.h
deleted file mode 100755
index 0871b4b..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redapimacs.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Defines macros used to interact with the Reliance Edge API.
-*/
-#ifndef REDAPIMACS_H
-#define REDAPIMACS_H
-
-
-/** Clear all events: manual transactions only. */
-#define RED_TRANSACT_MANUAL 0x00000000U
-
-/** Transact prior to unmounting in red_umount() or RedFseUnmount(). */
-#define RED_TRANSACT_UMOUNT 0x00000001U
-
-/** Transact after a successful red_open() which created a file. */
-#define RED_TRANSACT_CREAT 0x00000002U
-
-/** Transact after a successful red_unlink() or red_rmdir(). */
-#define RED_TRANSACT_UNLINK 0x00000004U
-
-/** Transact after a successful red_mkdir(). */
-#define RED_TRANSACT_MKDIR 0x00000008U
-
-/** Transact after a successful red_rename(). */
-#define RED_TRANSACT_RENAME 0x00000010U
-
-/** Transact after a successful red_link(). */
-#define RED_TRANSACT_LINK 0x00000020U
-
-/** Transact after a successful red_close(). */
-#define RED_TRANSACT_CLOSE 0x00000040U
-
-/** Transact after a successful red_write() or RedFseWrite(). */
-#define RED_TRANSACT_WRITE 0x00000080U
-
-/** Transact after a successful red_fsync(). */
-#define RED_TRANSACT_FSYNC 0x00000100U
-
-/** Transact after a successful red_ftruncate(), RedFseTruncate(), or red_open() with RED_O_TRUNC that actually truncates. */
-#define RED_TRANSACT_TRUNCATE 0x00000200U
-
-/** Transact to free space in disk full situations. */
-#define RED_TRANSACT_VOLFULL 0x00000400U
-
-#if REDCONF_READ_ONLY == 1
-
-/** Mask of all supported automatic transaction events. */
-#define RED_TRANSACT_MASK 0U
-
-#elif REDCONF_API_POSIX == 1
-
-/** @brief Mask of all supported automatic transaction events.
-*/
-#define RED_TRANSACT_MASK \
-( \
- RED_TRANSACT_UMOUNT | \
- RED_TRANSACT_CREAT | \
- ((REDCONF_API_POSIX_UNLINK == 1) ? RED_TRANSACT_UNLINK : 0U) | \
- ((REDCONF_API_POSIX_MKDIR == 1) ? RED_TRANSACT_MKDIR : 0U) | \
- ((REDCONF_API_POSIX_RENAME == 1) ? RED_TRANSACT_RENAME : 0U) | \
- ((REDCONF_API_POSIX_LINK == 1) ? RED_TRANSACT_LINK : 0U) | \
- RED_TRANSACT_CLOSE | \
- RED_TRANSACT_WRITE | \
- RED_TRANSACT_FSYNC | \
- ((REDCONF_API_POSIX_FTRUNCATE == 1) ? RED_TRANSACT_TRUNCATE : 0U) | \
- RED_TRANSACT_VOLFULL \
-)
-
-#else /* REDCONF_API_FSE == 1 */
-
-/** @brief Mask of all supported automatic transaction events.
-*/
-#define RED_TRANSACT_MASK \
-( \
- RED_TRANSACT_UMOUNT | \
- RED_TRANSACT_WRITE | \
- ((REDCONF_API_FSE_TRUNCATE == 1) ? RED_TRANSACT_TRUNCATE : 0U) | \
- RED_TRANSACT_VOLFULL \
-)
-
-#endif /* REDCONF_READ_ONLY */
-
-#if (REDCONF_TRANSACT_DEFAULT & RED_TRANSACT_MASK) != REDCONF_TRANSACT_DEFAULT
-#error "Configuration error: invalid value of REDCONF_TRANSACT_DEFAULT"
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redconfigchk.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redconfigchk.h
deleted file mode 100755
index 8576a42..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redconfigchk.h
+++ /dev/null
@@ -1,349 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Compile-time validity checks for the REDCONF macros.
-*/
-#ifndef REDCONFIGCHK_H
-#define REDCONFIGCHK_H
-
-#ifdef RED_CONFIG_MINCOMPAT_VER
- #if (RED_VERSION_VAL & 0xFFFFFF00U) < (RED_CONFIG_MINCOMPAT_VER & 0xFFFFFF00U)
- /* This indicates that your configuration files were generated by a
- version of the Reliance Edge Configuration Utility that is designed
- for a more recent version of Reliance Edge and is no longer compatible
- with this version. You can update to the most recent version of
- Reliance Edge or contact RelianceEdgeSupport@datalight.com to obtain
- the correct legacy version of the Configuration Utility.
- */
- #error "Your configuration is not compatible with this version of Reliance Edge. Please download the latest version of Reliance Edge or recreate your configuration with an older version of the Configuration Utility."
- #endif
-#endif
-
-#ifndef REDCONF_READ_ONLY
- #error "Configuration error: REDCONF_READ_ONLY must be defined."
-#endif
-#ifndef REDCONF_API_POSIX
- #error "Configuration error: REDCONF_API_POSIX must be defined."
-#endif
-#ifndef REDCONF_API_FSE
- #error "Configuration error: REDCONF_API_FSE must be defined."
-#endif
-
-#if REDCONF_API_POSIX == 1
- #ifndef REDCONF_API_POSIX_FORMAT
- #error "Configuration error: REDCONF_API_POSIX_FORMAT must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_UNLINK
- #error "Configuration error: REDCONF_API_POSIX_UNLINK must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_MKDIR
- #error "Configuration error: REDCONF_API_POSIX_MKDIR must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_RMDIR
- #error "Configuration error: REDCONF_API_POSIX_RMDIR must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_RENAME
- #error "Configuration error: REDCONF_API_POSIX_RENAME must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_LINK
- #error "Configuration error: REDCONF_API_POSIX_LINK must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_FTRUNCATE
- #error "Configuration error: REDCONF_API_POSIX_FTRUNCATE must be defined."
- #endif
- #ifndef REDCONF_API_POSIX_READDIR
- #error "Configuration error: REDCONF_API_POSIX_READDIR must be defined."
- #endif
- #ifndef REDCONF_NAME_MAX
- #error "Configuration error: REDCONF_NAME_MAX must be defined."
- #endif
- #ifndef REDCONF_PATH_SEPARATOR
- #error "Configuration error: REDCONF_PATH_SEPARATOR must be defined."
- #endif
- #ifndef REDCONF_RENAME_ATOMIC
- #error "Configuration error: REDCONF_RENAME_ATOMIC must be defined."
- #endif
- #ifndef REDCONF_HANDLE_COUNT
- #error "Configuration error: REDCONF_HANDLE_COUNT must be defined."
- #endif
-#endif
-#if REDCONF_API_FSE == 1
- #ifndef REDCONF_API_FSE_FORMAT
- #error "Configuration error: REDCONF_API_FSE_FORMAT must be defined."
- #endif
- #ifndef REDCONF_API_FSE_TRUNCATE
- #error "Configuration error: REDCONF_API_FSE_TRUNCATE must be defined."
- #endif
- #ifndef REDCONF_API_FSE_TRANSMASKSET
- #error "Configuration error: REDCONF_API_FSE_TRANSMASKSET must be defined."
- #endif
- #ifndef REDCONF_API_FSE_TRANSMASKGET
- #error "Configuration error: REDCONF_API_FSE_TRANSMASKGET must be defined."
- #endif
-#endif
-
-#ifndef REDCONF_TASK_COUNT
- #error "Configuration error: REDCONF_TASK_COUNT must be defined."
-#endif
-#ifndef REDCONF_ENDIAN_BIG
- #error "Configuration error: REDCONF_ENDIAN_BIG must be defined."
-#endif
-#ifndef REDCONF_ALIGNMENT_SIZE
- #error "Configuration error: REDCONF_ALIGNMENT_SIZE must be defined."
-#endif
-#ifndef REDCONF_CRC_ALGORITHM
- #error "Configuration error: REDCONF_CRC_ALGORITHM must be defined."
-#endif
-#ifndef REDCONF_INODE_TIMESTAMPS
- #error "Configuration error: REDCONF_INODE_TIMESTAMPS must be defined."
-#endif
-#ifndef REDCONF_ATIME
- #error "Configuration error: REDCONF_ATIME must be defined."
-#endif
-#ifndef REDCONF_DIRECT_POINTERS
- #error "Configuration error: REDCONF_DIRECT_POINTERS must be defined."
-#endif
-#ifndef REDCONF_INDIRECT_POINTERS
- #error "Configuration error: REDCONF_INDIRECT_POINTERS must be defined."
-#endif
-#ifndef REDCONF_INODE_BLOCKS
- #error "Configuration error: REDCONF_INODE_BLOCKS must be defined."
-#endif
-#ifndef REDCONF_IMAP_EXTERNAL
- #error "Configuration error: REDCONF_IMAP_EXTERNAL must be defined."
-#endif
-#ifndef REDCONF_IMAP_INLINE
- #error "Configuration error: REDCONF_IMAP_INLINE must be defined."
-#endif
-#ifndef REDCONF_OUTPUT
- #error "Configuration error: REDCONF_OUTPUT must be defined."
-#endif
-#ifndef REDCONF_ASSERTS
- #error "Configuration error: REDCONF_ASSERTS must be defined."
-#endif
-#ifndef REDCONF_TRANSACT_DEFAULT
- #error "Configuration error: REDCONF_TRANSACT_DEFAULT must be defined."
-#endif
-#ifndef REDCONF_BUFFER_COUNT
- #error "Configuration error: REDCONF_BUFFER_COUNT must be defined."
-#endif
-#ifndef REDCONF_BLOCK_SIZE
- #error "Configuration error: REDCONF_BLOCK_SIZE must be defined."
-#endif
-#ifndef REDCONF_VOLUME_COUNT
- #error "Configuration error: REDCONF_VOLUME_COUNT must be defined."
-#endif
-#ifndef REDCONF_DISCARDS
- /* Reliance Edge 1.0.5 and below did not have REDCONF_DISCARDS. You can
- fix this error by downloading the latest version of the Configuration
- Utility (assuming you are using the latest version of Reliance Edge)
- from http://www.datalight.com/reliance-edge, loading your redconf.c
- and redconf.h files, and saving them again, replacing the original
- files.
- */
- #error "Configuration error: your redconf.h is not compatible. Update your redconf files with a compatible version of the configuration utility."
-#endif
-#ifndef REDCONF_IMAGE_BUILDER
- #error "Configuration error: REDCONF_IMAGE_BUILDER must be defined."
-#endif
-#ifndef REDCONF_CHECKER
- #error "Configuration error: REDCONF_CHECKER must be defined."
-#endif
-
-
-#if (REDCONF_READ_ONLY != 0) && (REDCONF_READ_ONLY != 1)
- #error "Configuration error: REDCONF_READ_ONLY must be either 0 or 1"
-#endif
-
-#if (REDCONF_API_POSIX != 0) && (REDCONF_API_POSIX != 1)
- #error "Configuration error: REDCONF_API_POSIX must be either 0 or 1."
-#endif
-#if (REDCONF_API_FSE != 0) && (REDCONF_API_FSE != 1)
- #error "Configuration error: REDCONF_API_FSE must be either 0 or 1."
-#endif
-
-#if (REDCONF_API_FSE == 0) && (REDCONF_API_POSIX == 0)
- #error "Configuration error: either REDCONF_API_FSE or REDCONF_API_POSIX must be set to 1."
-#endif
-
-#if REDCONF_API_POSIX == 1
- #if REDCONF_API_FSE != 0
- #error "Configuration error: REDCONF_API_FSE must be 0 if REDCONF_API_POSIX is 1"
- #endif
-
- #if (REDCONF_API_POSIX_FORMAT != 0) && (REDCONF_API_POSIX_FORMAT != 1)
- #error "Configuration error: REDCONF_API_POSIX_FORMAT must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_UNLINK != 0) && (REDCONF_API_POSIX_UNLINK != 1)
- #error "Configuration error: REDCONF_API_POSIX_UNLINK must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_MKDIR != 0) && (REDCONF_API_POSIX_MKDIR != 1)
- #error "Configuration error: REDCONF_API_POSIX_MKDIR must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_RMDIR != 0) && (REDCONF_API_POSIX_RMDIR != 1)
- #error "Configuration error: REDCONF_API_POSIX_RMDIR must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_RENAME != 0) && (REDCONF_API_POSIX_RENAME != 1)
- #error "Configuration error: REDCONF_API_POSIX_RENAME must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_LINK != 0) && (REDCONF_API_POSIX_LINK != 1)
- #error "Configuration error: REDCONF_API_POSIX_LINK must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_FTRUNCATE != 0) && (REDCONF_API_POSIX_FTRUNCATE != 1)
- #error "Configuration error: REDCONF_API_POSIX_FTRUNCATE must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_POSIX_READDIR != 0) && (REDCONF_API_POSIX_READDIR != 1)
- #error "Configuration error: REDCONF_API_POSIX_READDIR must be either 0 or 1."
- #endif
-
- #if (REDCONF_NAME_MAX < 1U) || (REDCONF_NAME_MAX > (REDCONF_BLOCK_SIZE - 4U))
- #error "Configuration error: invalid value of REDCONF_NAME_MAX"
- #endif
-
- #if (REDCONF_PATH_SEPARATOR < 1) || (REDCONF_PATH_SEPARATOR > 127)
- #error "Configuration error: invalid value of REDCONF_PATH_SEPARATOR"
- #endif
-
- #if (REDCONF_RENAME_ATOMIC != 0) && (REDCONF_RENAME_ATOMIC != 1)
- #error "Configuration error: REDCONF_RENAME_ATOMIC must be either 0 or 1."
- #endif
-
- #if (REDCONF_HANDLE_COUNT < 1U) || (REDCONF_HANDLE_COUNT > 4096U)
- #error "Configuration error: invalid value of REDCONF_HANDLE_COUNT"
- #endif
-#endif
-#if REDCONF_API_FSE == 1
- #if (REDCONF_API_FSE_FORMAT != 0) && (REDCONF_API_FSE_FORMAT != 1)
- #error "Configuration error: REDCONF_API_FSE_FORMAT must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_FSE_TRUNCATE != 0) && (REDCONF_API_FSE_TRUNCATE != 1)
- #error "Configuration error: REDCONF_API_FSE_TRUNCATE must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_FSE_TRANSMASKSET != 0) && (REDCONF_API_FSE_TRANSMASKSET != 1)
- #error "Configuration error: REDCONF_API_FSE_TRANSMASKSET must be either 0 or 1."
- #endif
-
- #if (REDCONF_API_FSE_TRANSMASKGET != 0) && (REDCONF_API_FSE_TRANSMASKGET != 1)
- #error "Configuration error: REDCONF_API_FSE_TRANSMASKGET must be either 0 or 1."
- #endif
-#endif
-
-#if REDCONF_TASK_COUNT < 1U
- #error "Configuration error: invalid value of REDCONF_TASK_COUNT"
-#endif
-
-#if (REDCONF_ENDIAN_BIG != 0) && (REDCONF_ENDIAN_BIG != 1)
- #error "Configuration error: REDCONF_ENDIAN_BIG must be either 0 or 1."
-#endif
-
-#if (REDCONF_ALIGNMENT_SIZE != 1U) && (REDCONF_ALIGNMENT_SIZE != 2U) && (REDCONF_ALIGNMENT_SIZE != 4U) && (REDCONF_ALIGNMENT_SIZE != 8U)
- #error "Configuration error: invalid value REDCONF_ALIGNMENT_SIZE"
-#endif
-
-/* REDCONF_CRC_ALGORITHM checked in crc.c
-*/
-
-#if (REDCONF_INODE_TIMESTAMPS != 0) && (REDCONF_INODE_TIMESTAMPS != 1)
- #error "Configuration error: REDCONF_INODE_TIMESTAMPS must be either 0 or 1."
-#endif
-
-#if (REDCONF_ATIME != 0) && (REDCONF_ATIME != 1)
- #error "Configuration error: REDCONF_ATIME must be either 0 or 1."
-#endif
-
-#if (REDCONF_INODE_TIMESTAMPS == 0) && (REDCONF_ATIME == 1)
- #error "Configuration error: REDCONF_ATIME must be 0 when REDCONF_INODE_TIMESTAMPS is 0."
-#endif
-
-/* REDCONF_DIRECT_POINTERS and REDCONF_INDIRECT_POINTERS checked in rednodes.h
-*/
-
-#if (REDCONF_INODE_BLOCKS != 0) && (REDCONF_INODE_BLOCKS != 1)
- #error "Configuration error: REDCONF_INODE_BLOCKS must be either 0 or 1."
-#endif
-
-/* Further validity checking of imap specs done in RelCoreInit()
-*/
-#if (REDCONF_IMAP_EXTERNAL != 0) && (REDCONF_IMAP_EXTERNAL != 1)
- #error "Configuration error: REDCONF_IMAP_EXTERNAL must be either 0 or 1."
-#endif
-#if (REDCONF_IMAP_INLINE != 0) && (REDCONF_IMAP_INLINE != 1)
- #error "Configuration error: REDCONF_IMAP_INLINE must be either 0 or 1."
-#endif
-#if (REDCONF_IMAP_INLINE == 0) && (REDCONF_IMAP_EXTERNAL == 0)
- #error "Configuration error: At least one of REDCONF_IMAP_INLINE and REDCONF_IMAP_EXTERNAL must be set"
-#endif
-
-#if (REDCONF_OUTPUT != 0) && (REDCONF_OUTPUT != 1)
- #error "Configuration error: REDCONF_OUTPUT must be either 0 or 1."
-#endif
-
-#if (REDCONF_ASSERTS != 0) && (REDCONF_ASSERTS != 1)
- #error "Configuration error: REDCONF_ASSERTS must be either 0 or 1."
-#endif
-
-/* REDCONF_BLOCK_SIZE checked in redmacs.h
-*/
-
-#if (REDCONF_VOLUME_COUNT < 1U) || (REDCONF_VOLUME_COUNT > 255U)
- #error "REDCONF_VOLUME_COUNT must be an integer between 1 and 255"
-#endif
-
-#if (REDCONF_DISCARDS != 0) && (REDCONF_DISCARDS != 1)
- #error "Configuration error: REDCONF_DISCARDS must be either 0 or 1."
-#endif
-
-/* REDCONF_BUFFER_COUNT lower limit checked in buffer.c
-*/
-#if REDCONF_BUFFER_COUNT > 255U
- #error "REDCONF_BUFFER_COUNT cannot be greater than 255"
-#endif
-
-#if (REDCONF_IMAGE_BUILDER != 0) && (REDCONF_IMAGE_BUILDER != 1)
- #error "Configuration error: REDCONF_IMAGE_BUILDER must be either 0 or 1."
-#endif
-
-#if (REDCONF_CHECKER != 0) && (REDCONF_CHECKER != 1)
- #error "Configuration error: REDCONF_CHECKER must be either 0 or 1."
-#endif
-
-
-#if (REDCONF_DISCARDS == 1) && (RED_KIT == RED_KIT_GPL)
- #error "REDCONF_DISCARDS not supported in Reliance Edge under GPL. Contact sales@datalight.com to upgrade."
-#endif
-
-
-#endif
-
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redcoreapi.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redcoreapi.h
deleted file mode 100755
index 40ddbbb..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redcoreapi.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDCOREAPI_H
-#define REDCOREAPI_H
-
-
-#include
-
-
-REDSTATUS RedCoreInit(void);
-REDSTATUS RedCoreUninit(void);
-
-REDSTATUS RedCoreVolSetCurrent(uint8_t bVolNum);
-
-#if FORMAT_SUPPORTED
-REDSTATUS RedCoreVolFormat(void);
-#endif
-#if REDCONF_CHECKER == 1
-REDSTATUS RedCoreVolCheck(void);
-#endif
-REDSTATUS RedCoreVolMount(void);
-REDSTATUS RedCoreVolUnmount(void);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedCoreVolTransact(void);
-#endif
-#if REDCONF_API_POSIX == 1
-REDSTATUS RedCoreVolStat(REDSTATFS *pStatFS);
-#endif
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX == 1) || (REDCONF_API_FSE_TRANSMASKSET == 1))
-REDSTATUS RedCoreTransMaskSet(uint32_t ulEventMask);
-#endif
-#if (REDCONF_API_POSIX == 1) || (REDCONF_API_FSE_TRANSMASKGET == 1)
-REDSTATUS RedCoreTransMaskGet(uint32_t *pulEventMask);
-#endif
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1)
-REDSTATUS RedCoreCreate(uint32_t ulPInode, const char *pszName, bool fDir, uint32_t *pulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_LINK == 1)
-REDSTATUS RedCoreLink(uint32_t ulPInode, const char *pszName, uint32_t ulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
-REDSTATUS RedCoreUnlink(uint32_t ulPInode, const char *pszName);
-#endif
-#if REDCONF_API_POSIX == 1
-REDSTATUS RedCoreLookup(uint32_t ulPInode, const char *pszName, uint32_t *pulInode);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_RENAME == 1)
-REDSTATUS RedCoreRename(uint32_t ulSrcPInode, const char *pszSrcName, uint32_t ulDstPInode, const char *pszDstName);
-#endif
-#if REDCONF_API_POSIX == 1
-REDSTATUS RedCoreStat(uint32_t ulInode, REDSTAT *pStat);
-#endif
-#if REDCONF_API_FSE == 1
-REDSTATUS RedCoreFileSizeGet(uint32_t ulInode, uint64_t *pullSize);
-#endif
-
-REDSTATUS RedCoreFileRead(uint32_t ulInode, uint64_t ullStart, uint32_t *pulLen, void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedCoreFileWrite(uint32_t ulInode, uint64_t ullStart, uint32_t *pulLen, const void *pBuffer);
-#endif
-#if TRUNCATE_SUPPORTED
-REDSTATUS RedCoreFileTruncate(uint32_t ulInode, uint64_t ullSize);
-#endif
-
-#if (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_READDIR == 1)
-REDSTATUS RedCoreDirRead(uint32_t ulInode, uint32_t *pulPos, char *pszName, uint32_t *pulInode);
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/reddeviations.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/reddeviations.h
deleted file mode 100755
index 1726be6..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/reddeviations.h
+++ /dev/null
@@ -1,224 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief This header contains macros which deviate from MISRA C:2012
-*/
-#ifndef REDDEVIATIONS_H
-#define REDDEVIATIONS_H
-
-
-/** @brief Append a suffix to a constant so that it is an unsigned 64-bit value.
-
- Usages of this macro deviate from MISRA C:2012 Rule 1.2 (advisory). The
- rule prohibits the use of language extensions. The ULL suffix became part
- of the C standard with C99. Since this code base adheres to C89, use of
- this suffix is a language extension. Reliance Edge needs to deal with
- 64-bit quantities, which by convention are explicitly suffixed. In at
- least one case, with the INODE_SIZE_MAX macro, the code needs a way to force
- a constant to be 64-bits even though its value is not so large that it would
- be automatically promoted to 64-bits. Thus the need for this macro and the
- deviation. In practice, the ULL suffix has proven to be a nearly universal
- extension among C89 compilers.
-
- As rule 19.2 is advisory, a deviation record is not required. This notice
- is the only record of the deviation. PC-Lint does not issue an error for
- this deviation so there is no error inhibition option.
-
- Usages of this macro also deviate from MISRA C:2012 Rule 20.10 (advisory).
- The rule prohibits use of the ## preprocessor operator. The code is not
- obscure, and the operator is used only once, so this is deemed to be safe.
-
- As rule 20.10 is advisory, a deviation record is not required. This notice
- is the only record of the deviation.
-
- Consistent use of this macro, even in non MISRA C code, is encouraged to
- make it easier to search for 64-bit values.
-
-*/
-#define UINT64_SUFFIX(number) (number##ULL)
-
-
-/** @brief Append a suffix to a constant so that it is a signed 64-bit value.
-
- Usages of this macro deviate from MISRA C:2012 Rule 1.2 (advisory). See the
- description of UINT64_SUFFIX() for details.
-
- Usages of this macro deviate from MISRA C:2012 Rule 20.10 (advisory). See
- the description of UINT64_SUFFIX() for details.
-*/
-#define INT64_SUFFIX(number) (number##LL)
-
-
-/** @brief Cast a pointer to a const uint8_t pointer.
-
- All usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory).
- Because there are no alignment requirements for a uint8_t pointer, this is
- safe. However, it is technically a deviation from the rule.
-
- As Rule 11.5 is advisory, a deviation record is not required. This notice
- and the PC-Lint error inhibition option are the only records of the
- deviation.
-*/
-#define CAST_VOID_PTR_TO_CONST_UINT8_PTR(PTR) ((const uint8_t *)(PTR))
-
-
-/** @brief Cast a pointer to a uint8_t pointer.
-
- All usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory).
- Because there are no alignment requirements for a uint8_t pointer, this is
- safe. However, it is technically a deviation from the rule.
-
- As Rule 11.5 is advisory, a deviation record is not required. This notice
- and the PC-Lint error inhibition option are the only records of the
- deviation.
-*/
-#define CAST_VOID_PTR_TO_UINT8_PTR(PTR) ((uint8_t *)(PTR))
-
-
-/** @brief Cast a pointer to a const uint32_t pointer.
-
- Usages of this macro may deviate from MISRA C:2012 Rule 11.5 (advisory).
- It is only used in cases where the pointer is known to be aligned, and thus
- it is safe to do so.
-
- As Rule 11.5 is advisory, a deviation record is not required. This notice
- and the PC-Lint error inhibition option are the only records of the
- deviation.
-
- Usages of this macro may deviate from MISRA C:2012 Rule 11.3 (required).
- As Rule 11.3 is required, a separate deviation record is required.
-
- Regarding the cast to (const void *): this is there to placate some
- compilers which emit warnings when a type with lower alignment requirements
- (such as const uint8_t *) is cast to a type with higher alignment
- requirements. In the places where this macro is used, the pointer is
- checked to be of sufficient alignment.
-*/
-#define CAST_CONST_UINT32_PTR(PTR) ((const uint32_t *)(const void *)(PTR))
-
-
-/** @brief Cast a pointer to a pointer to (void **).
-
- Usages of this macro deviate from MISRA C:2012 Rule 11.3 (required).
- It is only used for populating a node structure pointer with a buffer
- pointer. Buffer pointers are 8-byte aligned, thus it is safe to do so.
-
- As Rule 11.3 is required, a separate deviation record is required.
-*/
-#define CAST_VOID_PTR_PTR(PTRPTR) ((void **)(PTRPTR))
-
-
-/** @brief Create a two-dimensional byte array which is safely aligned.
-
- Usages of this macro deviate from MISRA C:2012 Rule 19.2 (advisory).
- A union is required to force alignment of the block buffers, which are used
- to access metadata nodes, which must be safely aligned for 64-bit types.
-
- As rule 19.2 is advisory, a deviation record is not required. This notice
- and the PC-Lint error inhibition option are the only records of the
- deviation.
-*/
-#define ALIGNED_2D_BYTE_ARRAY(un, nam, size1, size2) \
- union \
- { \
- uint8_t nam[size1][size2]; \
- uint64_t DummyAlign; \
- } un
-
-
-/** @brief Determine whether RedMemMove() must copy memory in the forward
- direction, instead of in the reverse.
-
- In order to copy between overlapping memory regions, RedMemMove() must copy
- forward if the destination memory is lower, and backward if the destination
- memory is higher. Failure to do so would yield incorrect results.
-
- The only way to make this determination without gross inefficiency is to
- use pointer comparison. Pointer comparisons are undefined unless both
- pointers point within the same object or array (or one element past the end
- of the array); see section 6.3.8 of ANSI C89. While RedMemMove() is
- normally only used when memory regions overlap, which would not result in
- undefined behavior, it (like memmove()) is supposed to work even for non-
- overlapping regions, which would make this function invoke undefined
- behavior. Experience has shown the pointer comparisons of this sort behave
- intuitively on common platforms, even though the behavior is undefined. For
- those platforms where this is not the case, this implementation of memmove()
- should be replaced with an alternate one.
-
- Usages of this macro deviate from MISRA-C:2012 Rule 18.3 (required). As
- Rule 18.3 is required, a separate deviation record is required.
-*/
-#define MEMMOVE_MUST_COPY_FORWARD(dest, src) ((dest) < (src))
-
-
-/** @brief Cast a pointer to a (const DIRENT *).
-
- Usages of this macro deviate from MISRA-C:2012 Rule 11.3 (required).
- It is used for populating a directory entry structure pointer with a
- buffer pointer. Buffer pointers are 8-byte aligned, and DIRENT only
- requires 4-byte alignment, thus the typecast is safe.
-
- As Rule 11.3 is required, a separate deviation record is required.
-*/
-#define CAST_CONST_DIRENT_PTR(PTR) ((const DIRENT *)(PTR))
-
-
-/** @brief Determine whether a pointer is aligned.
-
- A pointer is aligned if its address is an even multiple of
- ::REDCONF_ALIGNMENT_SIZE.
-
- This is used in the slice-by-8 RedCrc32Update() function, which needs to
- know whether a pointer is aligned, since the slice-by-8 algorithm needs to
- access the memory in an aligned fashion, and if the pointer is not aligned,
- this can result in faults or suboptimal performance (depending on platform).
-
- There is no way to perform this check without deviating from MISRA C rules
- against casting pointers to integer types. Usage of this macro deviates
- from MISRA C:2012 Rule 11.4 (advisory). The main rationale the rule cites
- against converting pointers to integers is that the chosen integer type may
- not be able to represent the pointer; this is a non-issue here since we use
- uintptr_t. The text says the rule still applies when using uintptr_t due to
- concern about unaligned pointers, but that is not an issue here since the
- integer value of the pointer is not saved and not converted back into a
- pointer and dereferenced. The result of casting a pointer to a sufficiently
- large integer is implementation-defined, but macros similar to this one have
- been used by Datalight for a long time in a wide variety of environments and
- they have always worked as expected.
-
- As Rule 11.4 is advisory, a deviation record is not required. This notice
- and the PC-Lint error inhibition option are the only records of the
- deviation.
-
- @note PC-Lint also thinks this macro as it is used below violates Rule 11.6
- (required). This is a false positive, since Rule 11.6 only applies to
- void pointers. Below, we use it on a pointer-to-object (uint8_t *),
- which is covered by Rule 11.4.
-*/
-#define IS_ALIGNED_PTR(ptr) (((uintptr_t)(ptr) & (REDCONF_ALIGNMENT_SIZE - 1U)) == 0U)
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/rederrno.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/rederrno.h
deleted file mode 100755
index 9f462f7..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/rederrno.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Error values for Reliance Edge APIs
-*/
-#ifndef REDERRNO_H
-#define REDERRNO_H
-
-
-/** @brief Return type for Reliance Edge error values.
-*/
-typedef int32_t REDSTATUS;
-
-
-/* The errno numbers are the same as Linux.
-*/
-
-/** Operation not permitted. */
-#define RED_EPERM 1
-
-/** No such file or directory. */
-#define RED_ENOENT 2
-
-/** I/O error. */
-#define RED_EIO 5
-
-/** Bad file number. */
-#define RED_EBADF 9
-
-/** Out of memory */
-#define RED_ENOMEM 12
-
-/** Device or resource busy. */
-#define RED_EBUSY 16
-
-/** File exists. */
-#define RED_EEXIST 17
-
-/** Cross-device link. */
-#define RED_EXDEV 18
-
-/** Not a directory. */
-#define RED_ENOTDIR 20
-
-/** Is a directory. */
-#define RED_EISDIR 21
-
-/** Invalid argument. */
-#define RED_EINVAL 22
-
-/** File table overflow. */
-#define RED_ENFILE 23
-
-/** Too many open files. */
-#define RED_EMFILE 24
-
-/** File too large. */
-#define RED_EFBIG 27
-
-/** No space left on device. */
-#define RED_ENOSPC 28
-
-/** Read-only file system. */
-#define RED_EROFS 30
-
-/** Too many links. */
-#define RED_EMLINK 31
-
-/** Math result not representable. */
-#define RED_ERANGE 34
-
-/** File name too long. */
-#define RED_ENAMETOOLONG 36
-
-/** Function not implemented. */
-#define RED_ENOSYS 38
-
-/** Directory not empty. */
-#define RED_ENOTEMPTY 39
-
-/** No data available. */
-#define RED_ENODATA 61
-
-/** Too many users. */
-#define RED_EUSERS 87
-
-/** Nothing will be okay ever again. */
-#define RED_EFUBAR RED_EINVAL
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redexclude.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redexclude.h
deleted file mode 100755
index c62adb9..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redexclude.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDEXCLUDE_H
-#define REDEXCLUDE_H
-
-
-#define DELETE_SUPPORTED \
- ( \
- (REDCONF_READ_ONLY == 0) \
- && ( (REDCONF_API_POSIX == 1) \
- && ( (REDCONF_API_POSIX_RMDIR == 1) \
- || (REDCONF_API_POSIX_UNLINK == 1) \
- || ((REDCONF_API_POSIX_RENAME == 1) && (REDCONF_RENAME_ATOMIC == 1)))))
-
-#define TRUNCATE_SUPPORTED \
- ( \
- (REDCONF_READ_ONLY == 0) \
- && ( ((REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_FTRUNCATE == 1)) \
- || ((REDCONF_API_FSE == 1) && (REDCONF_API_FSE_TRUNCATE == 1))))
-
-#define FORMAT_SUPPORTED \
- ( \
- (REDCONF_READ_ONLY == 0) \
- && ( ((REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_FORMAT == 1)) \
- || ((REDCONF_API_FSE == 1) && (REDCONF_API_FSE_FORMAT == 1)) \
- || (REDCONF_IMAGE_BUILDER == 1)))
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redfs.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redfs.h
deleted file mode 100755
index 7392157..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redfs.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDFS_H
-#define REDFS_H
-
-
-#include
-#include "redver.h"
-#include "redconfigchk.h"
-#include
-#include "rederrno.h"
-#include "reddeviations.h"
-#include "redmacs.h"
-#include "redapimacs.h"
-#include "redutils.h"
-#include "redosserv.h"
-#include "redmisc.h"
-#include "redexclude.h"
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redfse.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redfse.h
deleted file mode 100755
index 83234f0..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redfse.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Interface for the Reliance Edge FSE API.
-
- The FSE (File Systems Essentials) API is a minimalist file system API
- intended for simple use cases with a fixed number of statically-defined
- files. It does not support creating or deleting files dynamically. Files
- are referenced by a fixed file number, rather than by name; there are no
- file names and no directories. There are also no file handles: files are
- not opened or closed, and file offsets are given explicitly.
-
- If the FSE API is too limited to meet the needs of your application,
- consider using the more feature-rich POSIX-like file system API instead.
-*/
-#ifndef REDFSE_H
-#define REDFSE_H
-
-/* This header is intended for application use; some applications are written
- in C++.
-*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#if REDCONF_API_FSE == 1
-
-#include
-#include "redapimacs.h"
-#include "rederrno.h"
-
-
-/** @brief First valid file number.
-
- This macro can be used to statically define file numbers for given files,
- as in the below example:
-
- ~~~{.c}
- #define LOG_FILE (RED_FILENUM_FIRST_VALID)
- #define DATABASE_FILE (RED_FILENUM_FIRST_VALID + 1U)
- #define ICON1_FILE (RED_FILENUM_FIRST_VALID + 2U)
- #define ICON2_FILE (RED_FILENUM_FIRST_VALID + 3U)
- ~~~
-*/
-#define RED_FILENUM_FIRST_VALID (2U)
-
-
-REDSTATUS RedFseInit(void);
-REDSTATUS RedFseUninit(void);
-REDSTATUS RedFseMount(uint8_t bVolNum);
-REDSTATUS RedFseUnmount(uint8_t bVolNum);
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_FORMAT == 1)
-REDSTATUS RedFseFormat(uint8_t bVolNum);
-#endif
-int32_t RedFseRead(uint8_t bVolNum, uint32_t ulFileNum, uint64_t ullFileOffset, uint32_t ulLength, void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-int32_t RedFseWrite(uint8_t bVolNum, uint32_t ulFileNum, uint64_t ullFileOffset, uint32_t ulLength, const void *pBuffer);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_TRUNCATE == 1)
-REDSTATUS RedFseTruncate(uint8_t bVolNum, uint32_t ulFileNum, uint64_t ullNewFileSize);
-#endif
-int64_t RedFseSizeGet(uint8_t bVolNum, uint32_t ulFileNum);
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE_TRANSMASKSET == 1)
-REDSTATUS RedFseTransMaskSet(uint8_t bVolNum, uint32_t ulEventMask);
-#endif
-#if REDCONF_API_FSE_TRANSMASKGET == 1
-REDSTATUS RedFseTransMaskGet(uint8_t bVolNum, uint32_t *pulEventMask);
-#endif
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedFseTransact(uint8_t bVolNum);
-#endif
-
-#endif /* REDCONF_API_FSE == 1 */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redgetopt.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redgetopt.h
deleted file mode 100755
index 96257c7..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redgetopt.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dieter Baron and Thomas Klausner.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-/** @file
- @brief Interfaces for getopt() and getopt_long() work-alike functions.
-
- This code was taken from FreeBSD and slightly modified, mostly to rename
- symbols with external linkage to avoid naming conflicts in systems where
- there are real getopt()/getopt_long() implementations. Changed to use
- fixed-width types to allow code using these interfaces to be consistent
- with the rest of the product.
-*/
-#ifndef REDGETOPT_H
-#define REDGETOPT_H
-
-
-#define red_no_argument 0
-#define red_required_argument 1
-#define red_optional_argument 2
-
-
-/** @brief Specifies a long option.
-*/
-typedef struct
-{
- /* name of long option */
- const char *name;
- /*
- * one of red_no_argument, red_required_argument, and red_optional_argument:
- * whether option takes an argument
- */
- int32_t has_arg;
- /* if not NULL, set *flag to val when option found */
- int32_t *flag;
- /* if flag not NULL, value to set *flag to; else return value */
- int32_t val;
-} REDOPTION;
-
-
-int32_t RedGetopt(int32_t nargc, char * const *nargv, const char *options);
-int32_t RedGetoptLong(int32_t nargc, char * const *nargv, const char *options, const REDOPTION *long_options, int32_t *idx);
-
-
-extern const char *red_optarg;
-extern int32_t red_optind;
-extern int32_t red_opterr;
-extern int32_t red_optopt;
-extern int32_t red_optreset;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redmacs.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redmacs.h
deleted file mode 100755
index 3b9d358..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redmacs.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDMACS_H
-#define REDMACS_H
-
-
-#ifndef NULL
-#define NULL ((void *)0)
-#endif
-
-#ifndef UINT8_MAX
-#define UINT8_MAX (0xFFU)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (0xFFFFU)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (0xFFFFFFFFU)
-#endif
-#ifndef UINT64_MAX
-#define UINT64_MAX UINT64_SUFFIX(0xFFFFFFFFFFFFFFFF)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (0x7FFFFFFF)
-#endif
-#ifndef INT64_MAX
-#define INT64_MAX INT64_SUFFIX(0x7FFFFFFFFFFFFFFF)
-#endif
-
-#ifndef true
-#define true (1)
-#endif
-#ifndef false
-#define false (0)
-#endif
-
-#define SECTOR_SIZE_MIN (256U)
-
-#if REDCONF_BLOCK_SIZE == 256U
-#define BLOCK_SIZE_P2 8U
-#elif REDCONF_BLOCK_SIZE == 512U
-#define BLOCK_SIZE_P2 9U
-#elif REDCONF_BLOCK_SIZE == 1024U
-#define BLOCK_SIZE_P2 10U
-#elif REDCONF_BLOCK_SIZE == 2048U
-#define BLOCK_SIZE_P2 11U
-#elif REDCONF_BLOCK_SIZE == 4096U
-#define BLOCK_SIZE_P2 12U
-#elif REDCONF_BLOCK_SIZE == 8192U
-#define BLOCK_SIZE_P2 13U
-#elif REDCONF_BLOCK_SIZE == 16384U
-#define BLOCK_SIZE_P2 14U
-#elif REDCONF_BLOCK_SIZE == 32768U
-#define BLOCK_SIZE_P2 15U
-#elif REDCONF_BLOCK_SIZE == 65536U
-#define BLOCK_SIZE_P2 16U
-#else
-#error "REDCONF_BLOCK_SIZE must be a power of two value between 256 and 65536"
-#endif
-
-#define REDMIN(a, b) (((a) < (b)) ? (a) : (b))
-
-#define INODE_INVALID (0U) /* General-purpose invalid inode number (must be zero). */
-#define INODE_FIRST_VALID (2U) /* First valid inode number. */
-#define INODE_ROOTDIR (INODE_FIRST_VALID) /* Inode number of the root directory. */
-
-/* Expands to a "const" qualifier when the volume count is one, otherwise
- expands to nothing. This is useful for variables that never change in
- single-volume configurations but do change in multi-volume configurations.
-*/
-#if REDCONF_VOLUME_COUNT == 1U
- #define CONST_IF_ONE_VOLUME const
-#else
- #define CONST_IF_ONE_VOLUME
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redmisc.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redmisc.h
deleted file mode 100755
index 018ba04..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redmisc.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDMISC_H
-#define REDMISC_H
-
-
-/** @brief Type of an inode or handle.
-
- Used to indicate the actual or expected type of an inode or handle.
-*/
-typedef enum
-{
- FTYPE_FILE, /**< Type is file. */
- FTYPE_DIR, /**< Type is directory. */
-
- /** Type is either file or directory: used only to indicate an expected
- type, never as an actual type.
- */
- FTYPE_EITHER
-} FTYPE;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redosserv.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redosserv.h
deleted file mode 100755
index 14d41d5..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redosserv.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDOSSERV_H
-#define REDOSSERV_H
-
-
-#include
-
-
-/** @brief Type of access requested when opening a block device.
-*/
-typedef enum
-{
- BDEV_O_RDONLY, /**< Open block device for read access. */
- BDEV_O_WRONLY, /**< Open block device for write access. */
- BDEV_O_RDWR /**< Open block device for read and write access. */
-} BDEVOPENMODE;
-
-REDSTATUS RedOsBDevOpen(uint8_t bVolNum, BDEVOPENMODE mode);
-REDSTATUS RedOsBDevClose(uint8_t bVolNum);
-REDSTATUS RedOsBDevRead(uint8_t bVolNum, uint64_t ullSectorStart, uint32_t ulSectorCount, void *pBuffer);
-
-#if REDCONF_READ_ONLY == 0
-REDSTATUS RedOsBDevWrite(uint8_t bVolNum, uint64_t ullSectorStart, uint32_t ulSectorCount, const void *pBuffer);
-REDSTATUS RedOsBDevFlush(uint8_t bVolNum);
-#endif
-
-/* Non-standard API: for host machines only.
-*/
-REDSTATUS RedOsBDevConfig(uint8_t bVolNum, const char *pszBDevSpec);
-
-
-#if REDCONF_TASK_COUNT > 1U
-REDSTATUS RedOsMutexInit(void);
-REDSTATUS RedOsMutexUninit(void);
-void RedOsMutexAcquire(void);
-void RedOsMutexRelease(void);
-#endif
-#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1)
-uint32_t RedOsTaskId(void);
-#endif
-
-REDSTATUS RedOsClockInit(void);
-REDSTATUS RedOsClockUninit(void);
-uint32_t RedOsClockGetTime(void);
-
-REDSTATUS RedOsTimestampInit(void);
-REDSTATUS RedOsTimestampUninit(void);
-REDTIMESTAMP RedOsTimestamp(void);
-uint64_t RedOsTimePassed(REDTIMESTAMP tsSince);
-
-#if REDCONF_OUTPUT == 1
-void RedOsOutputString(const char *pszString);
-#endif
-
-#if REDCONF_ASSERTS == 1
-void RedOsAssertFail(const char *pszFileName, uint32_t ulLineNum);
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redpath.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redpath.h
deleted file mode 100755
index 06f7c36..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redpath.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Interfaces of path utilities for the POSIX-like API layer.
-*/
-#ifndef REDPATH_H
-#define REDPATH_H
-
-
-REDSTATUS RedPathSplit(const char *pszPath, uint8_t *pbVolNum, const char **ppszLocalPath);
-REDSTATUS RedPathLookup(const char *pszLocalPath, uint32_t *pulInode);
-REDSTATUS RedPathToName(const char *pszLocalPath, uint32_t *pulPInode, const char **ppszName);
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redposix.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redposix.h
deleted file mode 100755
index 4de7150..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redposix.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Interface for the Reliance Edge POSIX-like API.
-
- The POSIX-like file system API is the primary file system API for
- Reliance Edge, which supports the full functionality of the file system.
- This API aims to be compatible with POSIX where reasonable, but it is
- simplified considerably to meet the needs of resource-constrained embedded
- systems. The API has also been extended to provide access to the unique
- features of Reliance Edge, and to cover areas (like mountins and formatting)
- which do not have APIs in the POSIX specification.
-*/
-#ifndef REDPOSIX_H
-#define REDPOSIX_H
-
-/* This header is intended for application use; some applications are written
- in C++.
-*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#if REDCONF_API_POSIX == 1
-
-#include
-#include "redapimacs.h"
-#include "rederrno.h"
-#include "redstat.h"
-
-/** Open for reading only. */
-#define RED_O_RDONLY 0x00000001U
-
-/** Open for writing only. */
-#define RED_O_WRONLY 0x00000002U
-
-/** Open for reading and writing. */
-#define RED_O_RDWR 0x00000004U
-
-/** File offset for all writes is end-of-file. */
-#define RED_O_APPEND 0x00000008U
-
-/** Create the file. */
-#define RED_O_CREAT 0x00000010U
-
-/** Error if path already exists. */
-#define RED_O_EXCL 0x00000020U
-
-/** Truncate file to size zero. */
-#define RED_O_TRUNC 0x00000040U
-
-
-/** @brief Last file system error (errno).
-
- Under normal circumstances, each task using the file system has an
- independent `red_errno` value. Applications do not need to worry about
- one task obliterating an error value that another task needed to read. The
- value is initially zero. When one of the POSIX-like APIs return an
- indication of error, `red_errno` is set to an error value.
-
- In some circumstances, `red_errno` will be a global errno location which
- is shared by multiple tasks. If the calling task is not registered as a
- file system user and all of the task slots are full, there can be no
- task-specific errno, so the global errno is used. Likewise, if the file
- system driver is uninitialized, there are no registered file system users
- and `red_errno` always refers to the global errno. Under these
- circumstances, multiple tasks manipulating `red_errno` could be
- problematic. When the task count is set to one, `red_errno` always refers
- to the global errno.
-
- Note that `red_errno` is usable as an lvalue; i.e., in addition to reading
- the error value, the error value can be set:
-
- ~~~{.c}
- red_errno = 0;
- ~~~
-*/
-#define red_errno (*red_errnoptr())
-
-
-/** @brief Positions from which to seek within a file.
-*/
-typedef enum
-{
- /* 0/1/2 are the traditional values for SET/CUR/END, respectively. Prior
- to the release of Unix System V in 1983, the SEEK_* symbols did not
- exist and C programs hard-coded the 0/1/2 values with those meanings.
- */
- RED_SEEK_SET = 0, /**< Set file offset to given offset. */
- RED_SEEK_CUR = 1, /**< Set file offset to current offset plus signed offset. */
- RED_SEEK_END = 2 /**< Set file offset to EOF plus signed offset. */
-} REDWHENCE;
-
-
-#if REDCONF_API_POSIX_READDIR == 1
-/** @brief Opaque directory handle.
-*/
-typedef struct sREDHANDLE REDDIR;
-
-
-/** @brief Directory entry information.
-*/
-typedef struct
-{
- uint32_t d_ino; /**< File serial number (inode number). */
- char d_name[REDCONF_NAME_MAX+1U]; /**< Name of entry. */
- REDSTAT d_stat; /**< File information (POSIX extension). */
-} REDDIRENT;
-#endif
-
-
-int32_t red_init(void);
-int32_t red_uninit(void);
-int32_t red_mount(const char *pszVolume);
-int32_t red_umount(const char *pszVolume);
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_FORMAT == 1)
-int32_t red_format(const char *pszVolume);
-#endif
-#if REDCONF_READ_ONLY == 0
-int32_t red_transact(const char *pszVolume);
-#endif
-#if REDCONF_READ_ONLY == 0
-int32_t red_settransmask(const char *pszVolume, uint32_t ulEventMask);
-#endif
-int32_t red_gettransmask(const char *pszVolume, uint32_t *pulEventMask);
-int32_t red_statvfs(const char *pszVolume, REDSTATFS *pStatvfs);
-int32_t red_open(const char *pszPath, uint32_t ulOpenMode);
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_UNLINK == 1)
-int32_t red_unlink(const char *pszPath);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_MKDIR == 1)
-int32_t red_mkdir(const char *pszPath);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RMDIR == 1)
-int32_t red_rmdir(const char *pszPath);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1)
-int32_t red_rename(const char *pszOldPath, const char *pszNewPath);
-#endif
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_LINK == 1)
-int32_t red_link(const char *pszPath, const char *pszHardLink);
-#endif
-int32_t red_close(int32_t iFildes);
-int32_t red_read(int32_t iFildes, void *pBuffer, uint32_t ulLength);
-#if REDCONF_READ_ONLY == 0
-int32_t red_write(int32_t iFildes, const void *pBuffer, uint32_t ulLength);
-#endif
-#if REDCONF_READ_ONLY == 0
-int32_t red_fsync(int32_t iFildes);
-#endif
-int64_t red_lseek(int32_t iFildes, int64_t llOffset, REDWHENCE whence);
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_FTRUNCATE == 1)
-int32_t red_ftruncate(int32_t iFildes, uint64_t ullSize);
-#endif
-int32_t red_fstat(int32_t iFildes, REDSTAT *pStat);
-#if REDCONF_API_POSIX_READDIR == 1
-REDDIR *red_opendir(const char *pszPath);
-REDDIRENT *red_readdir(REDDIR *pDirStream);
-void red_rewinddir(REDDIR *pDirStream);
-int32_t red_closedir(REDDIR *pDirStream);
-#endif
-REDSTATUS *red_errnoptr(void);
-
-#endif /* REDCONF_API_POSIX */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redstat.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redstat.h
deleted file mode 100755
index dbbdca3..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redstat.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDSTAT_H
-#define REDSTAT_H
-
-
-/** Mode bit for a directory. */
-#define RED_S_IFDIR 0x4000U
-
-/** Mode bit for a regular file. */
-#define RED_S_IFREG 0x8000U
-
-/** @brief Test for a directory.
-*/
-#define RED_S_ISDIR(m) (((m) & RED_S_IFDIR) != 0U)
-
-/** @brief Test for a regular file.
-*/
-#define RED_S_ISREG(m) (((m) & RED_S_IFREG) != 0U)
-
-
-/** File system is read-only. */
-#define RED_ST_RDONLY 0x00000001U
-
-/** File system ignores suid and sgid bits. */
-#define RED_ST_NOSUID 0x00000002U
-
-
-/** @brief Status information on an inode.
-*/
-typedef struct
-{
- uint8_t st_dev; /**< Volume number of volume containing file. */
- uint32_t st_ino; /**< File serial number (inode number). */
- uint16_t st_mode; /**< Mode of file. */
- uint16_t st_nlink; /**< Number of hard links to the file. */
- uint64_t st_size; /**< File size in bytes. */
- #if REDCONF_INODE_TIMESTAMPS == 1
- uint32_t st_atime; /**< Time of last access (seconds since 01-01-1970). */
- uint32_t st_mtime; /**< Time of last data modification (seconds since 01-01-1970). */
- uint32_t st_ctime; /**< Time of last status change (seconds since 01-01-1970). */
- #endif
- #if REDCONF_INODE_BLOCKS == 1
- uint32_t st_blocks; /**< Number of blocks allocated for this object. */
- #endif
-} REDSTAT;
-
-
-/** @brief Status information on a file system volume.
-*/
-typedef struct
-{
- uint32_t f_bsize; /**< File system block size. */
- uint32_t f_frsize; /**< Fundamental file system block size. */
- uint32_t f_blocks; /**< Total number of blocks on file system in units of f_frsize. */
- uint32_t f_bfree; /**< Total number of free blocks. */
- uint32_t f_bavail; /**< Number of free blocks available to non-privileged process. */
- uint32_t f_files; /**< Total number of file serial numbers. */
- uint32_t f_ffree; /**< Total number of free file serial numbers. */
- uint32_t f_favail; /**< Number of file serial numbers available to non-privileged process. */
- uint32_t f_fsid; /**< File system ID (useless, populated with zero). */
- uint32_t f_flag; /**< Bit mask of f_flag values. Includes read-only file system flag. */
- uint32_t f_namemax; /**< Maximum filename length. */
- uint64_t f_maxfsize; /**< Maximum file size (POSIX extension). */
- uint32_t f_dev; /**< Volume number (POSIX extension). */
-} REDSTATFS;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtests.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redtests.h
deleted file mode 100755
index 6cd7769..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtests.h
+++ /dev/null
@@ -1,265 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Prototypes for Reliance Edge test entry points.
-*/
-#ifndef REDTESTS_H
-#define REDTESTS_H
-
-#include
-#include "redtestutils.h"
-#include "redver.h"
-
-/* This macro is only defined by the error injection project.
-*/
-#ifdef REDCONF_ERROR_INJECTION
-#include
-#endif
-
-#define FSSTRESS_SUPPORTED \
- ( ((RED_KIT == RED_KIT_GPL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_PATH_SEPARATOR == '/') \
- && (REDCONF_API_POSIX == 1) && (REDCONF_API_POSIX_UNLINK == 1) && (REDCONF_API_POSIX_MKDIR == 1) \
- && (REDCONF_API_POSIX_RMDIR == 1) && (REDCONF_API_POSIX_RENAME == 1) && (REDCONF_API_POSIX_LINK == 1) \
- && (REDCONF_API_POSIX_FTRUNCATE == 1) && (REDCONF_API_POSIX_READDIR == 1))
-
-#define FSE_STRESS_TEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE == 1) \
- && (REDCONF_API_FSE_FORMAT == 1) && (REDCONF_API_FSE_TRANSMASKSET == 1) && (REDCONF_API_FSE_TRANSMASKGET == 1) \
- && (REDCONF_API_FSE_TRUNCATE == 1))
-
-#define POSIX_API_TEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) \
- && (REDCONF_API_POSIX_FORMAT == 1) && (REDCONF_API_POSIX_UNLINK == 1))
-
-#define FSE_API_TEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_API_FSE == 1) \
- && (REDCONF_API_FSE_FORMAT == 1))
-
-#define STOCH_POSIX_TEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) \
- && (REDCONF_API_POSIX_FORMAT == 1) && (REDCONF_API_POSIX_READDIR == 1) \
- && (REDCONF_API_POSIX_MKDIR == 1) && (REDCONF_API_POSIX_RMDIR == 1) && (REDCONF_API_POSIX_UNLINK == 1) \
- && (REDCONF_API_POSIX_RENAME == 1))
-
-#define FSIOTEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_API_POSIX == 1))
-
-#define BDEVTEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0))
-
-#define DISKFULL_TEST_SUPPORTED \
- ( ((RED_KIT == RED_KIT_COMMERCIAL) || (RED_KIT == RED_KIT_SANDBOX)) \
- && (REDCONF_OUTPUT == 1) && (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX == 1) \
- && (REDCONF_API_POSIX_FORMAT == 1) && (REDCONF_API_POSIX_FTRUNCATE == 1))
-
-
-typedef enum
-{
- PARAMSTATUS_OK, /* Parameters were good; continue. */
- PARAMSTATUS_BAD, /* Parameters were bad; stop. */
- PARAMSTATUS_HELP /* Help request; not an error, but stop. */
-} PARAMSTATUS;
-
-
-#if FSSTRESS_SUPPORTED
-typedef struct
-{
- bool fNoCleanup; /**< --no-cleanup */
- uint32_t ulLoops; /**< --loops */
- uint32_t ulNops; /**< --nops */
- bool fNamePad; /**< --namepad */
- uint32_t ulSeed; /**< --seed */
- bool fVerbose; /**< --verbose */
-} FSSTRESSPARAM;
-
-PARAMSTATUS FsstressParseParams(int argc, char *argv[], FSSTRESSPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void FsstressDefaultParams(FSSTRESSPARAM *pParam);
-int FsstressStart(const FSSTRESSPARAM *pParam);
-#endif
-
-#if STOCH_POSIX_TEST_SUPPORTED
-typedef struct
-{
- const char *pszVolume; /**< Volume path prefix. */
- uint32_t ulIterations; /**< --iterations */
- uint32_t ulFileListMax; /**< --files */
- uint32_t ulDirListMax; /**< --dirs */
- uint32_t ulOpenFileListMax; /**< --open-files */
- uint32_t ulOpenDirListMax; /**< --open-dirs */
- uint32_t ulRandomSeed; /**< --seed */
-} STOCHPOSIXPARAM;
-
-PARAMSTATUS RedStochPosixParseParams(int argc, char *argv[], STOCHPOSIXPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void RedStochPosixDefaultParams(STOCHPOSIXPARAM *pParam);
-int RedStochPosixStart(const STOCHPOSIXPARAM *pParam);
-#endif
-
-#if FSE_STRESS_TEST_SUPPORTED
-typedef struct
-{
- uint8_t bVolNum; /**< Volume number. */
- uint32_t ulFileCount; /**< --files */
- uint32_t ulMaxFileSize; /**< --max */
- uint32_t ulMaxOpSize; /**< --buffer-size */
- uint32_t ulNops; /**< --nops */
- uint32_t ulLoops; /**< --loops */
- uint32_t ulSampleRate; /**< --sample-rate */
- uint64_t ullSeed; /**< --seed */
-} FSESTRESSPARAM;
-
-PARAMSTATUS FseStressParseParams(int argc, char *argv[], FSESTRESSPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void FseStressDefaultParams(FSESTRESSPARAM *pParam);
-int FseStressStart(const FSESTRESSPARAM *pParam);
-#endif
-
-#if POSIX_API_TEST_SUPPORTED
-typedef struct
-{
- const char *pszVolume; /**< Volume path prefix. */
- bool fQuick; /**< --quick */
- bool fQuitOnFailure; /**< --quit-on-failure */
- bool fDebugErrors; /**< --debug */
-} POSIXTESTPARAM;
-
-PARAMSTATUS RedPosixTestParseParams(int argc, char *argv[], POSIXTESTPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void RedPosixTestDefaultParams(POSIXTESTPARAM *pParam);
-int RedPosixTestStart(const POSIXTESTPARAM *pParam);
-#endif
-
-
-#if POSIX_API_TEST_SUPPORTED
-typedef struct
-{
- const char *pszVolume; /**< Volume path prefix. */
- bool fQuick; /**< --quick */
- bool fVerbose; /**< --verbose */
- bool fQuitOnFailure; /**< --quit-on-failure */
- bool fDebugErrors; /**< --debug */
-} OSAPITESTPARAM;
-
-PARAMSTATUS RedOsApiTestParseParams(int argc, char *argv[], OSAPITESTPARAM *pParam, const char **ppszDevice);
-void RedOsApiTestDefaultParams(OSAPITESTPARAM *pParam);
-int RedOsApiTestStart(const OSAPITESTPARAM *pParam);
-#endif
-
-
-#if FSE_API_TEST_SUPPORTED
-typedef struct
-{
- uint8_t bVolNum; /**< Volume number. */
- bool fQuitOnFailure; /**< --quit-on-failure */
- bool fDebugErrors; /**< --debug */
-} FSETESTPARAM;
-
-PARAMSTATUS RedFseTestParseParams(int argc, char *argv[], FSETESTPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void RedFseTestDefaultParams(FSETESTPARAM *pParam);
-int RedFseTestStart(const FSETESTPARAM *pParam);
-#endif
-
-#if FSIOTEST_SUPPORTED
-typedef enum
-{
- TESTFS_RELEDGE, /* Datalight Reliance Edge */
- TESTFS_FATFS, /* ChaN's FatFs */
- TESTFS_FATSL /* FreeRTOS+FAT SL */
-} TESTFS;
-
-typedef struct
-{
- TESTFS testfs; /**< --fs */
- const char *pszVolume; /**< Volume path prefix. */
- bool fSeqRead; /**< --seq=r */
- bool fSeqWrite; /**< --seq=w */
- bool fSeqRewrite; /**< --seq=e */
- bool fRandomRead; /**< --rand=r */
- bool fRandomWrite; /**< --rand=w */
- bool fMixedWrite; /**< --mixed */
- bool fScanTest; /**< --scan */
- uint32_t ulFSBlockSize; /**< --block-size */
- uint32_t ulMaxFileSize; /**< --max */
- uint32_t ulRandomReadPasses; /**< --rand-pass=r:w (r part) */
- uint32_t ulRandomWritePasses; /**< --rand-pass=r:w (w part) */
- uint32_t ulMixedWritePasses; /**< --mixed-pass */
- int32_t iFlushOnWriteRatio; /**< --rand-fow */
- uint32_t ulBufferMin; /**< --start */
- uint32_t ulBufferSize; /**< --buffer-size */
- bool fWriteVerify; /**< --verify */
- uint32_t ulSampleRate; /**< --sample-rate */
- uint32_t ulScanCount; /**< --scan-files */
- uint64_t ullSeed; /**< --seed */
-} FSIOTESTPARAM;
-
-PARAMSTATUS FSIOTestParseParams(int argc, char *argv[], FSIOTESTPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void FSIOTestDefaultParams(FSIOTESTPARAM *pParam);
-int FSIOTestStart(const FSIOTESTPARAM *pParam);
-#endif
-
-#if BDEVTEST_SUPPORTED
-typedef struct
-{
- uint8_t bDrvNum; /**< Volume number (for sector size/count). */
- bool fSeqWrite; /**< --seq:w */
- bool fSeqRead; /**< --seq:r */
- bool fRandWrite; /**< --rand:w */
- bool fRandRead; /**< --rand:r */
- uint32_t ulSampleSecs; /**< --sample-rate */
- uint32_t ulPasses; /**< --passes */
- uint32_t ulMinIOSectors; /**< --count=min[:max] (min part) */
- uint32_t ulMaxIOSectors; /**< --count=min[:max] (max part) */
- uint32_t ulMaxSizeKB; /**< --max */
- uint32_t ulTestSeconds; /**< --time */
- bool fVerify; /**< --verify */
- bool fAsyncWrites; /**< --async */
- uint64_t ullSeed; /**< --seed */
-} BDEVTESTPARAM;
-
-PARAMSTATUS BDevTestParseParams(int argc, char *argv[], BDEVTESTPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void BDevTestDefaultParams(BDEVTESTPARAM *pParam);
-int BDevTestStart(const BDEVTESTPARAM *pParam);
-#endif
-
-#if DISKFULL_TEST_SUPPORTED
-typedef struct
-{
- const char *pszVolume; /**< Volume path prefix. */
- bool fQuitOnFailure; /**< --quit-on-failure */
- bool fDebugErrors; /**< --debug */
-} DISKFULLTESTPARAM;
-
-PARAMSTATUS DiskFullTestParseParams(int argc, char *argv[], DISKFULLTESTPARAM *pParam, uint8_t *pbVolNum, const char **ppszDevice);
-void DiskFullTestDefaultParams(DISKFULLTESTPARAM *pParam);
-int DiskFullTestStart(const DISKFULLTESTPARAM *pParam);
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtestutils.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redtestutils.h
deleted file mode 100755
index ca5e740..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtestutils.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Reliance Edge utilities only needed for tests.
-*/
-#ifndef REDTESTUTILS_H
-#define REDTESTUTILS_H
-
-
-#define ISDIGIT(c) (((c) >= '0') && ((c) <= '9'))
-
-
-void RedRandSeed(uint64_t ullSeed);
-uint64_t RedRand64(uint64_t *pullSeed);
-uint32_t RedRand32(uint32_t *pulSeed);
-
-char *RedRatio(char *pBuffer, uint32_t ulBufferLen, uint64_t ullDividend, uint64_t ullDivisor, uint32_t ulDecPlaces);
-uint64_t RedMulDiv64(uint64_t ullBase, uint32_t ulMultiplier, uint64_t ullDivisor);
-uint64_t RedUint64DivMod32(uint64_t ullDividend, uint32_t ulDivisor, uint32_t *pulRemainder);
-uint64_t RedUint64DivMod64(uint64_t ullDividend, uint64_t ullDivisor, uint64_t *pullRemainder);
-
-char *RedScaleBytes(uint32_t ulByteValue, char *pszBuffer, uint32_t ulBufferSize);
-char *RedScaleKB(uint32_t ulKBValue, char *pszBuffer, uint32_t ulBufferSize);
-uint32_t RedGetKBPerSecond(uint64_t ullKB, uint32_t ulMS);
-uint32_t RedGetKBPerSecondSectors(uint32_t ulBytesPerSector, uint64_t ullSectors, uint64_t ullUS);
-
-int32_t RedAtoI(const char *pszNum);
-const char *RedHtoUL(const char *pszNum, uint32_t *pulNum);
-const char *RedHtoULL(const char *pszNum, uint64_t *pullNum);
-const char *RedNtoUL(const char *pszNum, uint32_t *pulNum);
-const char *RedNtoULL(const char *pszNum, uint64_t *pullNum);
-const char *RedSizeToUL(const char *pszNum, uint32_t *pulResult);
-
-int32_t RedStrICmp(const char *pszStr1, const char *pszStr2);
-int32_t RedStrNICmp(const char *pszStr1, const char *pszStr2, uint32_t ulLen);
-char RedToLower(char c);
-
-#include
-
-#if REDCONF_OUTPUT == 1
-void RedPrintf(const char *pszFormat, ...);
-void RedVPrintf(const char *pszFormat, va_list arglist);
-#endif
-int32_t RedSNPrintf(char *pcBuffer, uint32_t ulBufferLen, const char *pszFormat, ...);
-int32_t RedVSNPrintf(char *pcBuffer, uint32_t ulBufferLen, const char *pszFormat, va_list arglist);
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtoolcmn.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redtoolcmn.h
deleted file mode 100755
index a89096e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtoolcmn.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Interfaces for common-code utilities for tools and tests.
-*/
-#ifndef REDTOOLCMN_H
-#define REDTOOLCMN_H
-
-
-uint8_t RedFindVolumeNumber(const char *pszVolume);
-bool RedConfirmOperation(const char *pszMessage);
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtools.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redtools.h
deleted file mode 100755
index f80ffb1..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redtools.h
+++ /dev/null
@@ -1,183 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-#ifndef REDTOOLS_H
-#define REDTOOLS_H
-
-
-#ifdef _WIN32
- #include
- #define HOST_PATH_MAX MAX_PATH
-#else
- #include
- #define HOST_PATH_MAX PATH_MAX
-#endif
-
-
-#if REDCONF_IMAGE_BUILDER == 1
-
-#define MACRO_NAME_MAX_LEN 32
-
-typedef struct
-{
- uint8_t bVolNumber;
- const char *pszInputDir;
- const char *pszOutputFile;
- #if REDCONF_API_POSIX == 1
- const char *pszVolName;
- #else
- const char *pszMapFile;
- const char *pszDefineFile;
- bool fNowarn;
- #endif
-} IMGBLDPARAM;
-
-
-void ImgbldParseParams(int argc, char *argv [], IMGBLDPARAM *pParam);
-int ImgbldStart(IMGBLDPARAM *pParam);
-
-
-typedef struct
-{
- #if REDCONF_API_POSIX == 1
- char asOutFilePath[HOST_PATH_MAX];
- #else
- uint32_t ulOutFileIndex;
- #endif
- char asInFilePath[HOST_PATH_MAX];
-} FILEMAPPING;
-
-
-extern void *gpCopyBuffer;
-extern uint32_t gulCopyBufferSize;
-
-
-/* Implemented in ibposix.c
-*/
-#if REDCONF_API_POSIX == 1
-REDSTATUS IbPosixCopyDir(const char *pszVolName, const char *pszInDir);
-int IbPosixCreateDir(const char *pszVolName, const char *pszFullPath, const char *pszBasePath);
-int IbConvertPath(const char *pszVolName, const char *pszFullPath, const char *pszBasePath, char *szOutPath);
-#endif
-
-
-/* Implemented in ibfse.c
-*/
-#if REDCONF_API_FSE == 1
-typedef struct sFILELISTENTRY FILELISTENTRY;
-struct sFILELISTENTRY
-{
- FILEMAPPING fileMapping;
- FILELISTENTRY *pNext;
-};
-
-
-void FreeFileList(FILELISTENTRY **ppsFileList);
-
-int IbFseGetFileList(const char *pszPath, const char *pszIndirPath, FILELISTENTRY **ppFileListHead);
-int IbFseOutputDefines(FILELISTENTRY *pFileList, const IMGBLDPARAM *pOptions);
-int IbFseCopyFiles(int volNum, const FILELISTENTRY *pFileList);
-#endif
-
-
-/* Implemented in os-specific space (ibwin.c and iblinux.c)
-*/
-#if REDCONF_API_POSIX == 1
-int IbPosixCopyDirRecursive(const char *pszVolName, const char *pszInDir);
-#endif
-#if REDCONF_API_FSE == 1
-int IbFseBuildFileList(const char *pszDirPath, FILELISTENTRY **ppFileListHead);
-#endif
-#if REDCONF_API_FSE == 1
-int IbSetRelativePath(char *pszPath, const char *pszParentPath);
-#endif
-bool IsRegularFile(const char *pszPath);
-
-
-/* Implemented in ibcommon.c
-*/
-int IbCopyFile(int volNum, const FILEMAPPING *pFileMapping);
-int IbCheckFileExists(const char *pszPath, bool *pfExists);
-
-
-/* Implemented separately in ibfse.c and ibposix.c
-*/
-int IbApiInit(void);
-int IbApiUninit(void);
-int IbWriteFile(int volNum, const FILEMAPPING *pFileMapping, uint64_t ullOffset, void *pData, uint32_t ulDataLen);
-
-#endif /* IMAGE_BUILDER */
-
-/* For image copier tool
-*/
-
-#ifdef _WIN32
- #define HOST_PSEP '\\'
- #if !__STDC__
- #define snprintf _snprintf
- #define stat _stat
- #define S_IFDIR _S_IFDIR
- #define rmdir _rmdir
- #endif
-#else
- #define HOST_PSEP '/'
-#endif
-
-typedef struct
-{
- uint8_t bVolNumber;
- const char *pszOutputDir;
- const char *pszBDevSpec;
- #if REDCONF_API_POSIX == 1
- const char *pszVolName;
- #endif
- bool fNoWarn;
-} IMGCOPYPARAM;
-
-typedef struct
-{
- #if REDCONF_API_POSIX == 1
- const char *pszVolume; /* Volume path prefix. */
- uint32_t ulVolPrefixLen; /* strlen(COPIER::pszVolume) */
- #else
- uint8_t bVolNum; /* Volume number. */
- #endif
- const char *pszOutputDir; /* Output directory path. */
- bool fNoWarn; /* If true, no warning to overwrite. */
- uint8_t *pbCopyBuffer; /* Buffer for copying file data. */
-} COPIER;
-
-
-void ImgcopyParseParams(int argc, char *argv [], IMGCOPYPARAM *pParam);
-int ImgcopyStart(IMGCOPYPARAM *pParam);
-
-/* Implemented separately in imgcopywin.c and imgcopylinux.c. These functions
- print an error message and abort on failure.
-*/
-void ImgcopyMkdir(const char *pszDir);
-void ImgcopyRecursiveRmdir(const char *pszDir);
-
-
-#endif /* REDTOOLS_H */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redutils.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redutils.h
deleted file mode 100755
index 35f8d2c..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redutils.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDUTILS_H
-#define REDUTILS_H
-
-
-#if REDCONF_ASSERTS == 1
-#define REDERROR() RedOsAssertFail(__FILE__, __LINE__)
-#define REDASSERT(EXP) ((EXP) ? (void)0 : REDERROR())
-#else
-#define REDERROR() ((void)0)
-#define REDASSERT(EXP) ((void)0)
-#endif
-
-
-void RedMemCpy(void *pDest, const void *pSrc, uint32_t ulLen);
-void RedMemMove(void *pDest, const void *pSrc, uint32_t ulLen);
-void RedMemSet(void *pDest, uint8_t bVal, uint32_t ulLen);
-int32_t RedMemCmp(const void *pMem1, const void *pMem2, uint32_t ulLen);
-
-uint32_t RedStrLen(const char *pszStr);
-int32_t RedStrCmp(const char *pszStr1, const char *pszStr2);
-int32_t RedStrNCmp(const char *pszStr1, const char *pszStr2, uint32_t ulLen);
-void RedStrNCpy(char *pszDst, const char *pszSrc, uint32_t ulLen);
-
-uint32_t RedCrc32Update(uint32_t ulInitCrc32, const void *pBuffer, uint32_t ulLength);
-uint32_t RedCrcNode(const void *pBuffer);
-
-#if REDCONF_API_POSIX == 1
-uint32_t RedNameLen(const char *pszName);
-#endif
-
-bool RedBitGet(const uint8_t *pbBitmap, uint32_t ulBit);
-void RedBitSet(uint8_t *pbBitmap, uint32_t ulBit);
-void RedBitClear(uint8_t *pbBitmap, uint32_t ulBit);
-
-#ifdef REDCONF_ENDIAN_SWAP
-uint64_t RedRev64(uint64_t ullToRev);
-uint32_t RedRev32(uint32_t ulToRev);
-uint16_t RedRev16(uint16_t uToRev);
-#endif
-
-void RedSignOn(void);
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redver.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redver.h
deleted file mode 100755
index 28793a6..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redver.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Macros for version numbers, build number, and product information.
-*/
-#ifndef REDVER_H
-#define REDVER_H
-
-
-/** @brief Consecutive number assigned to each automated build.
-
-
-*/
-#define RED_BUILD_NUMBER "700"
-
-#define RED_KIT_GPL 0U /* Open source GPL kit. */
-#define RED_KIT_COMMERCIAL 1U /* Commercially-licensed kit. */
-#define RED_KIT_SANDBOX 2U /* Not a kit: developer sandbox. */
-
-/** @brief Indicates the Reliance Edge kit.
-
-
-*/
-#define RED_KIT RED_KIT_GPL
-
-
-/** @brief Version number to display in output.
-*/
-#define RED_VERSION "v2.0"
-
-/** @brief Version number in hex.
-
- The most significant byte is the major version number, etc.
-*/
-#define RED_VERSION_VAL 0x02000000U
-
-/** @brief On-disk version number.
-
- This is incremented only when the on-disk layout is updated in such a way
- which is incompatible with previously released versions of the file system.
-*/
-#define RED_DISK_LAYOUT_VERSION 1U
-
-
-/** @brief Base name of the file system product.
-*/
-#define RED_PRODUCT_BASE_NAME "Reliance Edge"
-
-
-/* Specifies whether the product is in alpha stage, beta stage, or neither.
-*/
-#if 0
- #if 0
- #define ALPHABETA " (Alpha)"
- #else
- #define ALPHABETA " (Beta)"
- #endif
-#else
- #define ALPHABETA ""
-#endif
-
-/** @brief Full product name and version.
-*/
-#define RED_PRODUCT_NAME "Datalight " RED_PRODUCT_BASE_NAME " " RED_VERSION " Build " RED_BUILD_NUMBER ALPHABETA
-
-
-/** @brief Product copyright.
-*/
-#define RED_PRODUCT_LEGAL "Copyright (c) 2014-2017 Datalight, Inc. All Rights Reserved Worldwide."
-
-
-/** @brief Product patents.
-*/
-#define RED_PRODUCT_PATENT "Patents: US#7284101."
-
-
-/** @brief Product edition.
-*/
-#if RED_KIT == RED_KIT_GPL
-#define RED_PRODUCT_EDITION "Open-Source GPLv2 Edition -- Compiled " __DATE__ " at " __TIME__
-#elif RED_KIT == RED_KIT_COMMERCIAL
-#define RED_PRODUCT_EDITION "Commercial Edition -- Compiled " __DATE__ " at " __TIME__
-#else
-#define RED_PRODUCT_EDITION "Developer Sandbox -- Compiled " __DATE__ " at " __TIME__
-#endif
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/include/redvolume.h b/FreeRTOS-Plus/Source/Reliance-Edge/include/redvolume.h
deleted file mode 100755
index 266cf5e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/include/redvolume.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
-*/
-#ifndef REDVOLUME_H
-#define REDVOLUME_H
-
-
-/** @brief Per-volume configuration structure.
-
- Contains the configuration values that may differ between volumes. Must be
- declared in an array in redconf.c in the Reliance Edge project directory and
- statically initialized with values representing the volume configuration of
- the target system.
-*/
-typedef struct
-{
- /** The sector size for the block device underlying the volume: the basic
- unit for reading and writing to the storage media. Commonly ranges
- between 512 and 4096, but any power-of-two value not greater than the
- block size will work.
- */
- uint32_t ulSectorSize;
-
- /** The number of sectors in this file system volume.
- */
- uint64_t ullSectorCount;
-
- /** Whether a sector write on the block device underlying the volume is
- atomic. It is atomic if when the sector write is interrupted, the
- contents of the sector are guaranteed to be either all of the new data,
- or all of the old data. If unsure, leave as false.
- */
- bool fAtomicSectorWrite;
-
- /** This is the maximum number of inodes (files and directories). This
- number includes the root directory inode (inode 2; created during
- format), but does not include inodes 0 or 1, which do not exist on
- disk. The number of inodes cannot be less than 1.
- */
- uint32_t ulInodeCount;
-
- /** This is the maximum number of times a block device I/O operation will
- be retried. If a block device read, write, or flush fails, Reliance
- Edge will try again up to this number of times until the operation is
- successful. Set this to 0 to disable retries.
- */
- uint8_t bBlockIoRetries;
-
- #if REDCONF_API_POSIX == 1
- /** The path prefix for the volume; for example, "VOL1:", "FlashDisk", etc.
- */
- const char *pszPathPrefix;
- #endif
-} VOLCONF;
-
-extern const VOLCONF gaRedVolConf[REDCONF_VOLUME_COUNT];
-extern const VOLCONF * CONST_IF_ONE_VOLUME gpRedVolConf;
-
-
-/** @brief Per-volume run-time data.
-*/
-typedef struct
-{
- /** Whether the volume is currently mounted.
- */
- bool fMounted;
-
- #if REDCONF_READ_ONLY == 0
- /** Whether the volume is read-only.
- */
- bool fReadOnly;
-
- /** The active automatic transaction mask.
- */
- uint32_t ulTransMask;
- #endif
-
- /** The power of 2 difference between sector size and block size.
- */
- uint8_t bBlockSectorShift;
-
- /** The number of logical blocks in this file system volume. The unit here
- is the global block size.
- */
- uint32_t ulBlockCount;
-
- /** The total number of allocable blocks; Also the maximum count of free
- blocks.
- */
- uint32_t ulBlocksAllocable;
-
- /** The maximum number of bytes that an inode is capable of addressing.
- */
- uint64_t ullMaxInodeSize;
-
- /** The current metadata sequence number. This value is included in all
- metadata nodes and incremented every time a metadata node is written.
- It is assumed to never wrap around.
- */
- uint64_t ullSequence;
-} VOLUME;
-
-/* Array of VOLUME structures, populated at during RedCoreInit().
-*/
-extern VOLUME gaRedVolume[REDCONF_VOLUME_COUNT];
-
-/* Volume number currently being accessed; populated during
- RedCoreVolSetCurrent().
-*/
-extern CONST_IF_ONE_VOLUME uint8_t gbRedVolNum;
-
-/* Pointer to the volume currently being accessed; populated during
- RedCoreVolSetCurrent().
-*/
-extern VOLUME * CONST_IF_ONE_VOLUME gpRedVolume;
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redosdeviations.h b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redosdeviations.h
deleted file mode 100755
index cfde3a7..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redosdeviations.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Macros to encapsulate MISRA C:2012 deviations in OS-specific code.
-*/
-#ifndef REDOSDEVIATIONS_H
-#define REDOSDEVIATIONS_H
-
-
-#if REDCONF_OUTPUT == 1
-/* Needed for PRINT_ASSERT() and OUTPUT_CHARACTER().
-*/
-#include
-#endif
-
-
-#if (REDCONF_ASSERTS == 1) && (REDCONF_OUTPUT == 1)
-/** Print a formatted message for an assertion.
-
- Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). Using
- printf() is the most convenient way to output this information; and the risk
- of "unspecified, undefined and implementation-defined" behavior causing
- problems (as cited in the rationale for the rule) is small. The driver does
- not depend on this string being outputted correctly. Furthermore, use of
- printf() disappears when either asserts or output are disabled.
-
- As Rule 21.6 is required, a separate deviation record is required.
-*/
-#define PRINT_ASSERT(file, line) \
- printf("Assertion failed in \"%s\" at line %u\n\r", ((file) == NULL) ? "" : (file), (unsigned)(line))
-#endif
-
-
-/** Cast a value to unsigned long.
-
- Usages of this macro deviate from MISRA C:2012 Directive 4.6. This macro is
- used in two places to cast a uint64_t value (used by the block device
- abstraction for sector numbers) to unsigned long, since third-party code
- which is not under the control of this project uses unsigned long for sector
- numbers. The cast is guaranteed to not lose any information, since when the
- disk is opened the sector count is verified to be less than or equal to an
- unsigned long value. The text of the directive mentions that "it might be
- desirable not to apply this guideline when interfacing with ... code outside
- the project's control", which describes the situation for this deviation.
-
- As Directive 4.6 is advisory, a deviation record is not required. This
- notice is the only record of the deviation.
-*/
-#define CAST_ULONG(ull) ((unsigned long)(ull))
-
-
-/** Cast a const-qualified pointer to a pointer which is *not* const-qualified.
-
- Usages of this macro deviate from MISRA C:2012 Rule 11.8. This macro is
- used in exactly one place in order to cope with a poorly designed
- third-party interface. Reliance Edge, at every level of the stack, uses
- const-qualified pointers for buffers used in write operations, since the
- data is read from the buffer, and the buffer does not need to be modified
- (consistent with Rule 8.13). One of the third-party block device interfaces
- that Reliance Edge interfaces with does not follow this convention: it uses
- an unqualified pointer for the buffer parameter of its sector write
- function. This forces the need for the cast to avoid warnings. The
- implementation of the sector write function is provided by the user, so it
- is to be hoped that the buffer is not actually modified.
-
- As Rule 11.8 is required, a separate deviation record is required.
-*/
-#define CAST_AWAY_CONST(type, ptr) ((type *)(ptr))
-
-
-/** Allocate zero-initialized (cleared) memory.
-
- All usages of this macro deviate from MISRA C:2012 Directive 4.12 (required)
- and Rule 21.3 (required). In the context of the single place it is actually
- used, this macro also deviates from Rule 22.1 (required).
-
- This macro is used in the FreeRTOS block device code in order to allocate a
- RAM disk, when that implementation of the block device is selected. The
- primary rationale for all these deviations is that a) the RAM disk cannot be
- allocated statically (since the volume information is stored in a
- structure), and b) the RAM disk is primarily intended as a temporary testing
- tool for users who want to try out Reliance Edge before the real storage
- media is available. In most real systems, Reliance Edge is used with
- non-volatile storage like SD/MMC or eMMC, not with RAM disks.
-
- Rule 22.1 states that all resources which are allocated must also be
- explicitly freed. The RAM disk is allocated and never freed, deviating from
- that rule. This is done because the data in the RAM disk is emulating a
- non-volatile storage medium, and thus needs to persist even after the block
- device is closed, to allow the file system to be ormatted and then mounted,
- or unmounted and remounted in the course of a test. Thus the memory will
- remain allocated until the target device is rebooted. This is assumed to be
- acceptable for the primary purpose of the RAM disk, which is preliminary
- testing.
-
- As Directive 4.12, Rule 21.3, and Rule 22.1 are all required, separate
- deviation records are required.
-*/
-#define ALLOCATE_CLEARED_MEMORY(nelem, elsize) calloc(nelem, elsize)
-
-
-#if REDCONF_OUTPUT == 1
-/** Output a character to a serial port or other display device.
-
- Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required).
- FreeRTOS does not include a standard method of printing characters, so
- putchar() is the most convenient and portable way to accomplish the task.
- The risk of "unspecified, undefined and implementation-defined" behavior
- causing problems (as cited in the rationale for the rule) is small. The
- driver does not depend on the character being outputted correctly.
- Furthermore, use of putchar() disappears when output is disabled.
-
- As Rule 21.6 is required, a separate deviation record is required.
-*/
-#define OUTPUT_CHARACTER(ch) (void)putchar(ch)
-#endif
-
-
-#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1)
-/** Cast a TaskHandle_t (a pointer type) to uintptr_t.
-
- Usage of this macro deivate from MISRA-C:2012 Rule 11.4 (advisory). This
- macro is used for the FreeRTOS version of RedOsTaskId(). Some RTOSes
- natively use an integer for task IDs; others use pointers. RedOsTaskId()
- uses integers, FreeRTOS uses pointers; to reconcile this difference, the
- pointer must be cast to integer. This is fairly safe, since the resulting
- integer is never cast back to a pointer; and although the integer
- representation of a pointer is implementation-defined, the representation is
- irrelevant provided that unique pointers are converted to unique integers.
-
- As Rule 11.4 is advisory, a deviation record is not required. This notice
- is the only record of the deviation.
-*/
-#define CAST_TASK_PTR_TO_UINTPTR(taskptr) ((uintptr_t)(taskptr))
-#endif
-
-
-/** Ignore the return value of a function (cast to void)
-
- Usages of this macro deviate from MISRA C:2012 Directive 4.7, which states
- that error information must be checked immediately after a function returns
- potential error information.
-
- If asserts and output are enabled, then this macro is used to document that
- the return value of printf() is ignored. A failure of printf() does not
- impact the filesystem core, nor is there anything the filesystem can do to
- respond to such an error (especially since it occurs within an assert).
- Thus, the most reasonable action is to ignore the error.
-
- In the STM32 SDIO block device implementation, errors are also ignored in an
- IRQ interrupt handler. This is the most reasonable action to take for two
- reasons: (a) it would be dangerous to spend processor time responding to the
- error inside the IRQ handler; (b) it has been verified that the same error
- is propegated to the DiskRead/Write method, which does return the error to
- the core.
-
- In the Atmel SD/MMC block device implementation, error information from
- sd_mmc_read_capacity() is ignored. This is a reasonable action because all
- of the possible error conditions were eliminated by a previous check.
- sd_mmc_read_capacity() fails under the same conditions as
- sd_mmc_test_unit_ready(), which was checked ealier in the same function.
-
- In the mutex module, error information returned from the mutex release
- function is ignored when asserts are disabled. This is a reasonable action
- because the mutex release function (xSemaphoreGive) is documented only to
- fail if the mutex was not obtained correctly, which can be demonstrably
- avoided.
-
- As Directive 4.7 is required, a separate deviation record is required.
-*/
-#define IGNORE_ERRORS(fn) ((void) (fn))
-
-
-/** @brief Determine whether a pointer is aligned on a 32-bit boundary.
-
- This is used to determine whether a data buffer meets the requirements of
- the underlying block device implementation. When transferring data via
- DMA (Direct Memory Access) on an STM32 device, the data buffer must be cast
- as a uint32 pointer, and unexpected behavior may occur if the buffer is not
- aligned correctly.
-
- There is no way to perform this check without deviating from MISRA C rules
- against casting pointers to integer types. Usage of this macro deviates
- from MISRA C:2012 Rule 11.4 (advisory). The main rationale the rule cites
- against converting pointers to integers is that the chosen integer type may
- not be able to represent the pointer; this is a non-issue here since we use
- uintptr_t. The text says the rule still applies when using uintptr_t due to
- concern about unaligned pointers, but that is not an issue here since the
- integer value of the pointer is not saved and not converted back into a
- pointer and dereferenced. The result of casting a pointer to a sufficiently
- large integer is implementation-defined, but macros similar to this one have
- been used by Datalight for a long time in a wide variety of environments and
- they have always worked as expected.
-
- This deviation only occurs when using the STM32 SDIO block device
- implementation.
-
- As Rule 11.4 is advisory, a deviation record is not required. This notice
- is the only record of deviation.
-*/
-#define IS_UINT32_ALIGNED_PTR(ptr) (((uintptr_t)(ptr) & (sizeof(uint32_t) - 1U)) == 0U)
-
-
-/** @brief Cast a 32-bit aligned void pointer to a uint32 pointer.
-
- Usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory). A
- cast from a void pointer to an object pointer is discouraged because of
- potential alignment issues. However, this macro is only used to cast
- pointers that have already been tested to be 32-bit aligned, so the
- operation will be safe.
-
- This deviation only occurs when using the STM32 SDIO block device
- implementation.
-
- As rule 11.5 is advisory, a deviation record is not required. This notice
- is the only record of the deviation.
-*/
-#define CAST_UINT32_PTR(ptr) ((uint32_t *) (ptr))
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redostypes.h b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redostypes.h
deleted file mode 100755
index 1f15b42..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/include/redostypes.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Defines OS-specific types for use in common code.
-*/
-#ifndef REDOSTYPES_H
-#define REDOSTYPES_H
-
-
-/** @brief Implementation-defined timestamp type.
-
- This can be an integer, a structure, or a pointer: anything that is
- convenient for the implementation. Since the underlying type is not fixed,
- common code should treat this as an opaque type.
-*/
-typedef uint32_t REDTIMESTAMP;
-
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osassert.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osassert.c
deleted file mode 100755
index 9822caf..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osassert.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements assertion handling.
-*/
-#include
-
-#if REDCONF_ASSERTS == 1
-
-#include
-
-
-/** @brief Invoke the native assertion handler.
-
- @param pszFileName Null-terminated string containing the name of the file
- where the assertion fired.
- @param ulLineNum Line number in @p pszFileName where the assertion
- fired.
-*/
-void RedOsAssertFail(
- const char *pszFileName,
- uint32_t ulLineNum)
-{
- #if REDCONF_OUTPUT == 1
- IGNORE_ERRORS(PRINT_ASSERT(pszFileName, ulLineNum));
- #endif
-
- while(true)
- {
- }
-}
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osbdev.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osbdev.c
deleted file mode 100755
index bb42087..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osbdev.c
+++ /dev/null
@@ -1,1553 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements block device I/O.
-*/
-#include
-
-#include
-#include
-#include
-
-
-/*------------------------------------------------------------------------------
- Porting Note:
-
- Several example implementations of this module for FreeRTOS are available.
- If you are lucky, you can use one of these implementations; otherwise, these
- can serve as examples of how to implement this service.
-------------------------------------------------------------------------------*/
-
-/** @brief The F_DRIVER example implementation.
-
- This implementation is designed to reuse an existing block device driver
- that was written for FreeRTOS+FAT SL. If you have such a driver, with
- little work it can be "dropped in" and used for Reliance Edge. The only
- customization required is that gpfnRedOsBDevInit needs to be defined and
- pointed at the F_DRIVERINIT function. This can be done in this module or in
- another C file.
-
- The disadantage of using the FreeRTOS F_DRIVER functions is that they only
- support single-sector reads and writes. Reliance Edge will issue
- multi-sector requests, and servicing these one sector at a time will
- significantly slow down the file system.
-*/
-#define BDEV_F_DRIVER (0U)
-
-/** @brief The FatFs example implementation.
-
- This implementation is designed to reuse an existing block device driver
- that was written for FatFs. If you have such a driver, it can be linked
- in and used immediately. The FatFs `diskio.h` header must be in the include
- directory path.
-*/
-#define BDEV_FATFS (1U)
-
-/** @brief The Atmel Studio Framework SD/MMC driver example implementation.
-
- This implementation uses a modified version of the open source SD/MMC driver
- included in the Atmel Studio Framework (ASF) and will work as-is for many
- varieties of Atmel hardware. This example assumes relatively minor
- modifications to the ASF SD/MMC driver to make it support multi-sector read
- and write requests, which greatly improves performance. The modified driver
- is distributed with Reliance Edge and is included in FreeRTOS Atmel projects
- (such as in projects/freertos/atmel/sam4e-ek/src/ASF).
-
- This example can easily be modified to work with an unmodified version of
- the ASF SD/MMC driver. Simply replace sd_mmc_mem_2_ram_multi() and
- sd_mmc_ram_2_mem_multi() with sd_mmc_mem_2_ram() and sd_mmc_ram_2_mem()
- respectively, and add a for loop to loop over each sector in the request.
- However, as described in the manual, there are considerable performance
- advantages to issuing real multi-sector requests, so using the modified
- driver is recommended.
-*/
-#define BDEV_ATMEL_SDMMC (2U)
-
-/** @brief The ST Microelectronics STM32 SDIO driver example implementation.
-
- This implementation accesses the microSD card through the BSP utilities
- provided as part of the STM32Cube package, used with the STM32 HAL drivers.
- The STM3240G-EVAL and STM32F746NG-Discovery boards are currently supported.
-*/
-#define BDEV_STM32_SDIO (3U)
-
-/** @brief The RAM disk example implementation.
-
- This implementation uses a RAM disk. It will allow you to compile and test
- Reliance Edge even if your storage driver is not yet ready. On typical
- target hardware, the amount of spare RAM will be limited so generally only
- very small disks will be available.
-*/
-#define BDEV_RAM_DISK (4U)
-
-/** @brief Pick which example implementation is compiled.
-
- Must be one of:
- - #BDEV_F_DRIVER
- - #BDEV_FATFS
- - #BDEV_ATMEL_SDMMC
- - #BDEV_STM32_SDIO
- - #BDEV_RAM_DISK
-*/
-#define BDEV_EXAMPLE_IMPLEMENTATION BDEV_RAM_DISK
-
-
-static REDSTATUS DiskOpen(uint8_t bVolNum, BDEVOPENMODE mode);
-static REDSTATUS DiskClose(uint8_t bVolNum);
-static REDSTATUS DiskRead(uint8_t bVolNum, uint64_t ullSectorStart, uint32_t ulSectorCount, void *pBuffer);
-#if REDCONF_READ_ONLY == 0
-static REDSTATUS DiskWrite(uint8_t bVolNum, uint64_t ullSectorStart, uint32_t ulSectorCount, const void *pBuffer);
-static REDSTATUS DiskFlush(uint8_t bVolNum);
-#endif
-
-
-/** @brief Initialize a block device.
-
- This function is called when the file system needs access to a block
- device.
-
- Upon successful return, the block device should be fully initialized and
- ready to service read/write/flush/close requests.
-
- The behavior of calling this function on a block device which is already
- open is undefined.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedOsBDevOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- REDSTATUS ret;
-
- if(bVolNum >= REDCONF_VOLUME_COUNT)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = DiskOpen(bVolNum, mode);
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a block device.
-
- This function is called when the file system no longer needs access to a
- block device. If any resource were allocated by RedOsBDevOpen() to service
- block device requests, they should be freed at this time.
-
- Upon successful return, the block device must be in such a state that it
- can be opened again.
-
- The behavior of calling this function on a block device which is already
- closed is undefined.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number.
-*/
-REDSTATUS RedOsBDevClose(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(bVolNum >= REDCONF_VOLUME_COUNT)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = DiskClose(bVolNum);
- }
-
- return ret;
-}
-
-
-/** @brief Read sectors from a physical block device.
-
- The behavior of calling this function is undefined if the block device is
- closed or if it was opened with ::BDEV_O_WRONLY.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is
- `NULL`, or @p ullStartSector and/or @p ulSectorCount
- refer to an invalid range of sectors.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedOsBDevRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if( (bVolNum >= REDCONF_VOLUME_COUNT)
- || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount)
- || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount)
- || (pBuffer == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = DiskRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a physical block device.
-
- The behavior of calling this function is undefined if the block device is
- closed or if it was opened with ::BDEV_O_RDONLY.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is
- `NULL`, or @p ullStartSector and/or @p ulSectorCount
- refer to an invalid range of sectors.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedOsBDevWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
-
- if( (bVolNum >= REDCONF_VOLUME_COUNT)
- || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount)
- || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount)
- || (pBuffer == NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = DiskWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
- }
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- This function must synchronously flush all software and hardware caches
- beneath the file system, ensuring that all sectors written previously are
- committed to permanent storage.
-
- If the environment has no caching beneath the file system, the
- implementation of this function can do nothing and return success.
-
- The behavior of calling this function is undefined if the block device is
- closed or if it was opened with ::BDEV_O_RDONLY.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p bVolNum is an invalid volume number.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-REDSTATUS RedOsBDevFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(bVolNum >= REDCONF_VOLUME_COUNT)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = DiskFlush(bVolNum);
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#if BDEV_EXAMPLE_IMPLEMENTATION == BDEV_F_DRIVER
-
-#include
-
-
-/* This must be declared and initialized elsewere (e.g., in project code) to
- point at the initialization function for the F_DRIVER block device.
-*/
-extern const F_DRIVERINIT gpfnRedOsBDevInit;
-
-static F_DRIVER *gapFDriver[REDCONF_VOLUME_COUNT];
-
-
-/** @brief Initialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- REDSTATUS ret;
-
- (void)mode;
-
- if((gpfnRedOsBDevInit == NULL) || (gapFDriver[bVolNum] != NULL))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- F_DRIVER *pDriver;
-
- pDriver = gpfnRedOsBDevInit(bVolNum);
- if(pDriver != NULL)
- {
- F_PHY geom;
- int iErr;
-
- /* Validate that the geometry is consistent with the volume
- configuration.
- */
- iErr = pDriver->getphy(pDriver, &geom);
- if(iErr == 0)
- {
- if( (geom.bytes_per_sector != gaRedVolConf[bVolNum].ulSectorSize)
- || (geom.number_of_sectors < gaRedVolConf[bVolNum].ullSectorCount))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- gapFDriver[bVolNum] = pDriver;
- ret = 0;
- }
- }
- else
- {
- ret = -RED_EIO;
- }
-
- if(ret != 0)
- {
- pDriver->release(pDriver);
- }
- }
- else
- {
- ret = -RED_EIO;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskClose(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(gapFDriver[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- gapFDriver[bVolNum]->release(gapFDriver[bVolNum]);
- gapFDriver[bVolNum] = NULL;
-
- ret = 0;
- }
-
- return ret;
-}
-
-
-/** @brief Read sectors from a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
- F_DRIVER *pDriver = gapFDriver[bVolNum];
-
- if(pDriver == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint32_t ulSectorIdx;
- int iErr;
-
- for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
- {
- iErr = pDriver->readsector(pDriver, &pbBuffer[ulSectorIdx * ulSectorSize],
- CAST_ULONG(ullSectorStart + ulSectorIdx));
- if(iErr != 0)
- {
- ret = -RED_EIO;
- break;
- }
- }
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The block device is not open.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
- F_DRIVER *pDriver = gapFDriver[bVolNum];
-
- if(pDriver == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint32_t ulSectorIdx;
- int iErr;
-
- for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
- {
- /* We have to cast pbBuffer to non-const since the writesector
- prototype is flawed, using a non-const pointer for the buffer.
- */
- iErr = pDriver->writesector(pDriver, CAST_AWAY_CONST(uint8_t, &pbBuffer[ulSectorIdx * ulSectorSize]),
- CAST_ULONG(ullSectorStart + ulSectorIdx));
- if(iErr != 0)
- {
- ret = -RED_EIO;
- break;
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(gapFDriver[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- /* The F_DRIVER interface does not include a flush function, so to be
- reliable the F_DRIVER implementation must use synchronous writes.
- */
- ret = 0;
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_FATFS
-
-#include
-#include
-
-/* disk_read() and disk_write() use an unsigned 8-bit value to specify the
- sector count, so no transfer can be larger than 255 sectors.
-*/
-#define MAX_SECTOR_TRANSFER UINT8_MAX
-
-
-/** @brief Initialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- DSTATUS status;
- uint32_t ulTries;
- REDSTATUS ret = 0;
-
- /* With some implementations of disk_initialize(), such as the one
- implemented by Atmel for the ASF, the first time the disk is opened, the
- SD card can take a while to get ready, in which time disk_initialize()
- returns an error. Try numerous times, waiting half a second after each
- failure. Empirically, this has been observed to succeed on the second
- try, so trying 10x more than that provides a margin of error.
- */
- for(ulTries = 0U; ulTries < 20U; ulTries++)
- {
- /* Assuming that the volume number is also the correct drive number.
- If this is not the case in your environment, a static constant array
- can be declared to map volume numbers to the correct driver number.
- */
- status = disk_initialize(bVolNum);
- if(status == 0)
- {
- break;
- }
-
- vTaskDelay(500U / portTICK_PERIOD_MS);
- }
-
- if(status != 0)
- {
- ret = -RED_EIO;
- }
-
- /* Retrieve the sector size and sector count to ensure they are compatible
- with our compile-time geometry.
- */
- if(ret == 0)
- {
- WORD wSectorSize;
- DWORD dwSectorCount;
- DRESULT result;
-
- result = disk_ioctl(bVolNum, GET_SECTOR_SIZE, &wSectorSize);
- if(result == RES_OK)
- {
- result = disk_ioctl(bVolNum, GET_SECTOR_COUNT, &dwSectorCount);
- if(result == RES_OK)
- {
- if( (wSectorSize != gaRedVolConf[bVolNum].ulSectorSize)
- || (dwSectorCount < gaRedVolConf[bVolNum].ullSectorCount))
- {
- ret = -RED_EINVAL;
- }
- }
- else
- {
- ret = -RED_EIO;
- }
- }
- else
- {
- ret = -RED_EIO;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskClose(
- uint8_t bVolNum)
-{
- (void)bVolNum;
- return 0;
-}
-
-
-/** @brief Read sectors from a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
- uint32_t ulSectorIdx = 0U;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
-
- while(ulSectorIdx < ulSectorCount)
- {
- uint32_t ulTransfer = REDMIN(ulSectorCount - ulSectorIdx, MAX_SECTOR_TRANSFER);
- DRESULT result;
-
- result = disk_read(bVolNum, &pbBuffer[ulSectorIdx * ulSectorSize], (DWORD)(ullSectorStart + ulSectorIdx), (BYTE)ulTransfer);
- if(result != RES_OK)
- {
- ret = -RED_EIO;
- break;
- }
-
- ulSectorIdx += ulTransfer;
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
- uint32_t ulSectorIdx = 0U;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
-
- while(ulSectorIdx < ulSectorCount)
- {
- uint32_t ulTransfer = REDMIN(ulSectorCount - ulSectorIdx, MAX_SECTOR_TRANSFER);
- DRESULT result;
-
- result = disk_write(bVolNum, &pbBuffer[ulSectorIdx * ulSectorSize], (DWORD)(ullSectorStart + ulSectorIdx), (BYTE)ulTransfer);
- if(result != RES_OK)
- {
- ret = -RED_EIO;
- break;
- }
-
- ulSectorIdx += ulTransfer;
- }
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
- DRESULT result;
-
- result = disk_ioctl(bVolNum, CTRL_SYNC, NULL);
- if(result == RES_OK)
- {
- ret = 0;
- }
- else
- {
- ret = -RED_EIO;
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-
-#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_ATMEL_SDMMC
-
-#include
-
-#include
-#include
-#include
-#include
-
-/* sd_mmc_mem_2_ram_multi() and sd_mmc_ram_2_mem_multi() use an unsigned
- 16-bit value to specify the sector count, so no transfer can be larger
- than UINT16_MAX sectors.
-*/
-#define MAX_SECTOR_TRANSFER UINT16_MAX
-
-
-/** @brief Initialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EROFS The device is read-only media and write access was
- requested.
-*/
-static REDSTATUS DiskOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- REDSTATUS ret = 0;
- uint32_t ulTries;
- Ctrl_status cs;
-
- /* Note: Assuming the volume number is the same as the SD card slot. The
- ASF SD/MMC driver supports two SD slots. This implementation will need
- to be modified if multiple volumes share a single SD card.
- */
-
- /* The first time the disk is opened, the SD card can take a while to get
- ready, in which time sd_mmc_test_unit_ready() returns either CTRL_BUSY
- or CTRL_NO_PRESENT. Try numerous times, waiting half a second after
- each failure. Empirically, this has been observed to succeed on the
- second try, so trying 10x more than that provides a margin of error.
- */
- for(ulTries = 0U; ulTries < 20U; ulTries++)
- {
- cs = sd_mmc_test_unit_ready(bVolNum);
- if((cs != CTRL_NO_PRESENT) && (cs != CTRL_BUSY))
- {
- break;
- }
-
- vTaskDelay(500U / portTICK_PERIOD_MS);
- }
-
- if(cs == CTRL_GOOD)
- {
- #if REDCONF_READ_ONLY == 0
- if(mode != BDEV_O_RDONLY)
- {
- if(sd_mmc_wr_protect(bVolNum))
- {
- ret = -RED_EROFS;
- }
- }
-
- if(ret == 0)
- #endif
- {
- uint32_t ulSectorLast;
-
- IGNORE_ERRORS(sd_mmc_read_capacity(bVolNum, &ulSectorLast));
-
- /* The ASF SD/MMC driver only supports 512-byte sectors.
- */
- if( (gaRedVolConf[bVolNum].ulSectorSize != 512U)
- || (((uint64_t)ulSectorLast + 1U) < gaRedVolConf[bVolNum].ullSectorCount))
- {
- ret = -RED_EINVAL;
- }
- }
- }
- else
- {
- ret = -RED_EIO;
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskClose(
- uint8_t bVolNum)
-{
- (void)bVolNum;
- return 0;
-}
-
-
-/** @brief Read sectors from a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS ret = 0;
- uint32_t ulSectorIdx = 0U;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
-
- while(ulSectorIdx < ulSectorCount)
- {
- uint32_t ulTransfer = REDMIN(ulSectorCount - ulSectorIdx, MAX_SECTOR_TRANSFER);
- Ctrl_status cs;
-
- cs = sd_mmc_mem_2_ram_multi(bVolNum, (uint32_t)(ullSectorStart + ulSectorIdx),
- (uint16_t)ulTransfer, &pbBuffer[ulSectorIdx * ulSectorSize]);
- if(cs != CTRL_GOOD)
- {
- ret = -RED_EIO;
- break;
- }
-
- ulSectorIdx += ulTransfer;
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS ret = 0;
- uint32_t ulSectorIdx = 0U;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
-
- while(ulSectorIdx < ulSectorCount)
- {
- uint32_t ulTransfer = REDMIN(ulSectorCount - ulSectorIdx, MAX_SECTOR_TRANSFER);
- Ctrl_status cs;
-
- cs = sd_mmc_ram_2_mem_multi(bVolNum, (uint32_t)(ullSectorStart + ulSectorIdx),
- (uint16_t)ulTransfer, &pbBuffer[ulSectorIdx * ulSectorSize]);
- if(cs != CTRL_GOOD)
- {
- ret = -RED_EIO;
- break;
- }
-
- ulSectorIdx += ulTransfer;
- }
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
- Ctrl_status cs;
-
- /* The ASF SD/MMC driver appears to write sectors synchronously, so it
- should be fine to do nothing and return success. However, Atmel's
- implementation of the FatFs diskio.c file does the equivalent of the
- below when the disk is flushed. Just in case this is important for some
- non-obvious reason, do the same.
- */
- cs = sd_mmc_test_unit_ready(bVolNum);
- if(cs == CTRL_GOOD)
- {
- ret = 0;
- }
- else
- {
- ret = -RED_EIO;
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_STM32_SDIO
-
-#ifdef USE_STM324xG_EVAL
- #include
- #include
-#elif defined(USE_STM32746G_DISCO)
- #include
- #include
-#else
- /* If you are using a compatible STM32 device other than the two listed above
- and you have SD card driver headers, you can try adding them to the above
- list.
- */
- #error "Unsupported device."
-#endif
-
-#if REDCONF_VOLUME_COUNT > 1
- #error "The STM32 SDIO block device implementation does not support multiple volumes."
-#endif
-
-
-#ifndef USE_HAL_DRIVER
- #error "The STM32 StdPeriph driver is not supported. Please use the HAL driver or modify the Reliance Edge block device interface."
-#endif
-
-
-/** @brief Number of times to call BSP_SD_GetStatus() before timing out and
- returning an error.
-
- See ::CheckStatus().
-
- NOTE: Datalight has not observed a scenario where BSP_SD_GetStatus()
- returns SD_TRANSFER_BUSY after a transfer command returns successfully.
- Set SD_STATUS_TIMEOUT to 0U to skip checking BSP_SD_GetStatus().
-*/
-#define SD_STATUS_TIMEOUT (100000U)
-
-/** @brief 4-byte aligned buffer to use for DMA transfers when passed in
- an unaligned buffer.
-*/
-static uint32_t gaulAlignedBuffer[512U / sizeof(uint32_t)];
-
-
-#if SD_STATUS_TIMEOUT > 0U
-static REDSTATUS CheckStatus(void);
-#endif
-
-
-/** @brief Initialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO No SD card was found; or BSP_SD_Init() failed.
- @retval -RED_EINVAL The SD card's block size is not the same as the
- configured sector size; or the SD card is not large
- enough for the volume; or the volume size is above
- 4GiB, meaning that part of it cannot be accessed
- through the STM32 SDIO driver.
-*/
-static REDSTATUS DiskOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- REDSTATUS ret = 0;
- static bool fSdInitted = false;
-
- (void) mode;
-
- if(!fSdInitted)
- {
- if(BSP_SD_Init() == MSD_OK)
- {
- fSdInitted = true;
- }
- }
-
- if(!fSdInitted)
- {
- /* Above initialization attempt failed.
- */
- ret = -RED_EIO;
- }
- else if(BSP_SD_IsDetected() == SD_NOT_PRESENT)
- {
- ret = -RED_EIO;
- }
- else
- {
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- HAL_SD_CardInfoTypedef sdCardInfo = {{0}};
-
- BSP_SD_GetCardInfo(&sdCardInfo);
-
- /* Note: the actual card block size is sdCardInfo.CardBlockSize,
- but the interface only supports a 512 byte block size. Further,
- one card has been observed to report a 1024-byte block size,
- but it worked fine with a 512-byte Reliance Edge ulSectorSize.
- */
- if( (ulSectorSize != 512U)
- || (sdCardInfo.CardCapacity < (gaRedVolConf[bVolNum].ullSectorCount * ulSectorSize)))
- {
- ret = -RED_EINVAL;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskClose(
- uint8_t bVolNum)
-{
- (void)bVolNum;
- return 0;
-}
-
-
-/** @brief Read sectors from a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS redStat = 0;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint8_t bSdError;
-
- if(IS_UINT32_ALIGNED_PTR(pBuffer))
- {
- bSdError = BSP_SD_ReadBlocks_DMA(CAST_UINT32_PTR(pBuffer), ullSectorStart * ulSectorSize, ulSectorSize, ulSectorCount);
-
- if(bSdError != MSD_OK)
- {
- redStat = -RED_EIO;
- }
- #if SD_STATUS_TIMEOUT > 0U
- else
- {
- redStat = CheckStatus();
- }
- #endif
- }
- else
- {
- uint32_t ulSectorIdx;
-
- for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
- {
- bSdError = BSP_SD_ReadBlocks_DMA(gaulAlignedBuffer, (ullSectorStart + ulSectorIdx) * ulSectorSize, ulSectorSize, 1U);
-
- if(bSdError != MSD_OK)
- {
- redStat = -RED_EIO;
- }
- #if SD_STATUS_TIMEOUT > 0U
- else
- {
- redStat = CheckStatus();
- }
- #endif
-
- if(redStat == 0)
- {
- uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
-
- RedMemCpy(&pbBuffer[ulSectorIdx * ulSectorSize], gaulAlignedBuffer, ulSectorSize);
- }
- else
- {
- break;
- }
- }
- }
-
- return redStat;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS redStat = 0;
- uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
- uint8_t bSdError;
-
- if(IS_UINT32_ALIGNED_PTR(pBuffer))
- {
- bSdError = BSP_SD_WriteBlocks_DMA(CAST_UINT32_PTR(CAST_AWAY_CONST(void, pBuffer)), ullSectorStart * ulSectorSize,
- ulSectorSize, ulSectorCount);
-
- if(bSdError != MSD_OK)
- {
- redStat = -RED_EIO;
- }
- #if SD_STATUS_TIMEOUT > 0U
- else
- {
- redStat = CheckStatus();
- }
- #endif
- }
- else
- {
- uint32_t ulSectorIdx;
-
- for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
- {
- const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
-
- RedMemCpy(gaulAlignedBuffer, &pbBuffer[ulSectorIdx * ulSectorSize], ulSectorSize);
-
- bSdError = BSP_SD_WriteBlocks_DMA(gaulAlignedBuffer, (ullSectorStart + ulSectorIdx) * ulSectorSize, ulSectorSize, 1U);
-
- if(bSdError != MSD_OK)
- {
- redStat = -RED_EIO;
- }
- #if SD_STATUS_TIMEOUT > 0U
- else
- {
- redStat = CheckStatus();
- }
- #endif
-
- if(redStat != 0)
- {
- break;
- }
- }
- }
-
- return redStat;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskFlush(
- uint8_t bVolNum)
-{
- /* Disk transfer is synchronous; nothing to flush.
- */
- (void) bVolNum;
- return 0;
-}
-
-
-#if SD_STATUS_TIMEOUT > 0U
-/** @brief Wait until BSP_SD_GetStatus returns SD_TRANSFER_OK.
-
- This function calls BSP_SD_GetStatus repeatedly as long as it returns
- SD_TRANSFER_BUSY up to SD_STATUS_TIMEOUT times.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 SD_TRANSFER_OK was returned.
- @retval -RED_EIO SD_TRANSFER_ERROR received, or timed out waiting for
- SD_TRANSFER_OK.
-*/
-static REDSTATUS CheckStatus(void)
-{
- REDSTATUS redStat = 0;
- uint32_t ulTimeout = SD_STATUS_TIMEOUT;
- HAL_SD_TransferStateTypedef transferState;
-
- do
- {
- transferState = BSP_SD_GetStatus();
- ulTimeout--;
- } while((transferState == SD_TRANSFER_BUSY) && (ulTimeout > 0U));
-
- if(transferState != SD_TRANSFER_OK)
- {
- redStat = -RED_EIO;
- }
-
- return redStat;
-}
-#endif
-
-#endif /* REDCONF_READ_ONLY == 0 */
-
-#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_RAM_DISK
-
-#include /* For ALLOCATE_CLEARED_MEMORY(), which expands to calloc(). */
-
-
-static uint8_t *gapbRamDisk[REDCONF_VOLUME_COUNT];
-
-
-/** @brief Initialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- initialized.
- @param mode The open mode, indicating the type of access required.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS DiskOpen(
- uint8_t bVolNum,
- BDEVOPENMODE mode)
-{
- REDSTATUS ret = 0;
-
- (void)mode;
-
- if(gapbRamDisk[bVolNum] == NULL)
- {
- gapbRamDisk[bVolNum] = ALLOCATE_CLEARED_MEMORY(gaRedVolume[bVolNum].ulBlockCount, REDCONF_BLOCK_SIZE);
- if(gapbRamDisk[bVolNum] == NULL)
- {
- ret = -RED_EIO;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Uninitialize a disk.
-
- @param bVolNum The volume number of the volume whose block device is being
- uninitialized.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskClose(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(gapbRamDisk[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- /* This implementation uses dynamically allocated memory, but must
- retain previously written data after the block device is closed, and
- thus the memory cannot be freed and will remain allocated until
- reboot.
- */
- ret = 0;
- }
-
- return ret;
-}
-
-
-/** @brief Read sectors from a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being read from.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to read.
- @param pBuffer The buffer into which to read the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskRead(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- void *pBuffer)
-{
- REDSTATUS ret;
-
- if(gapbRamDisk[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- uint64_t ullByteOffset = ullSectorStart * gaRedVolConf[bVolNum].ulSectorSize;
- uint32_t ulByteCount = ulSectorCount * gaRedVolConf[bVolNum].ulSectorSize;
-
- RedMemCpy(pBuffer, &gapbRamDisk[bVolNum][ullByteOffset], ulByteCount);
-
- ret = 0;
- }
-
- return ret;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write sectors to a disk.
-
- @param bVolNum The volume number of the volume whose block device
- is being written to.
- @param ullSectorStart The starting sector number.
- @param ulSectorCount The number of sectors to write.
- @param pBuffer The buffer from which to write the sector data.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskWrite(
- uint8_t bVolNum,
- uint64_t ullSectorStart,
- uint32_t ulSectorCount,
- const void *pBuffer)
-{
- REDSTATUS ret;
-
- if(gapbRamDisk[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- uint64_t ullByteOffset = ullSectorStart * gaRedVolConf[bVolNum].ulSectorSize;
- uint32_t ulByteCount = ulSectorCount * gaRedVolConf[bVolNum].ulSectorSize;
-
- RedMemCpy(&gapbRamDisk[bVolNum][ullByteOffset], pBuffer, ulByteCount);
-
- ret = 0;
- }
-
- return ret;
-}
-
-
-/** @brief Flush any caches beneath the file system.
-
- @param bVolNum The volume number of the volume whose block device is being
- flushed.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-static REDSTATUS DiskFlush(
- uint8_t bVolNum)
-{
- REDSTATUS ret;
-
- if(gapbRamDisk[bVolNum] == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = 0;
- }
-
- return ret;
-}
-#endif /* REDCONF_READ_ONLY == 0 */
-
-#else
-
-#error "Invalid BDEV_EXAMPLE_IMPLEMENTATION value"
-
-#endif /* BDEV_EXAMPLE_IMPLEMENTATION == ... */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osclock.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osclock.c
deleted file mode 100755
index aaaf20c..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osclock.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements real-time clock functions.
-*/
-#include
-
-
-/** @brief Initialize the real time clock.
-
- The behavior of calling this function when the RTC is already initialized
- is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedOsClockInit(void)
-{
- return 0;
-}
-
-
-/** @brief Uninitialize the real time clock.
-
- The behavior of calling this function when the RTC is not initialized is
- undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedOsClockUninit(void)
-{
- return 0;
-}
-
-
-/** @brief Get the date/time.
-
- The behavior of calling this function when the RTC is not initialized is
- undefined.
-
- @return The number of seconds since January 1, 1970 excluding leap seconds
- (in other words, standard Unix time). If the resolution or epoch
- of the RTC is different than this, the implementation must convert
- it to the expected representation.
-*/
-uint32_t RedOsClockGetTime(void)
-{
- /* FreeRTOS does not provide an RTC abstraction since most of the systems
- it targets have no RTC hardware. If your hardware includes an RTC that
- you would like to use, this function must be customized.
- */
- return 0;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osmutex.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osmutex.c
deleted file mode 100755
index 68cd0ed..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osmutex.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements a synchronization object to provide mutual exclusion.
-*/
-#include
-#include
-
-#include
-#include
-
-#if REDCONF_TASK_COUNT > 1U
-
-
-static SemaphoreHandle_t xMutex;
-#if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
-static StaticSemaphore_t xMutexBuffer;
-#endif
-
-
-/** @brief Initialize the mutex.
-
- After initialization, the mutex is in the released state.
-
- The behavior of calling this function when the mutex is still initialized
- is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedOsMutexInit(void)
-{
- REDSTATUS ret = 0;
-
- #if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
- xMutex = xSemaphoreCreateMutexStatic(&xMutexBuffer);
-
- if(xMutex == NULL)
- {
- /* The only error case for xSemaphoreCreateMutexStatic is that the mutex
- buffer parameter is NULL, which is not the case.
- */
- REDERROR();
- ret = -RED_EINVAL;
- }
-
- #else
- xMutex = xSemaphoreCreateMutex();
- if(xMutex == NULL)
- {
- ret = -RED_ENOMEM;
- }
- #endif
-
- return ret;
-}
-
-
-/** @brief Uninitialize the mutex.
-
- The behavior of calling this function when the mutex is not initialized is
- undefined; likewise, the behavior of uninitializing the mutex when it is
- in the acquired state is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedOsMutexUninit(void)
-{
- vSemaphoreDelete(xMutex);
- xMutex = NULL;
-
- return 0;
-}
-
-
-/** @brief Acquire the mutex.
-
- The behavior of calling this function when the mutex is not initialized is
- undefined; likewise, the behavior of recursively acquiring the mutex is
- undefined.
-*/
-void RedOsMutexAcquire(void)
-{
- while(xSemaphoreTake(xMutex, portMAX_DELAY) != pdTRUE)
- {
- }
-}
-
-
-/** @brief Release the mutex.
-
- The behavior is undefined in the following cases:
-
- - Releasing the mutex when the mutex is not initialized.
- - Releasing the mutex when it is not in the acquired state.
- - Releasing the mutex from a task or thread other than the one which
- acquired the mutex.
-*/
-void RedOsMutexRelease(void)
-{
- BaseType_t xSuccess;
-
- xSuccess = xSemaphoreGive(xMutex);
- REDASSERT(xSuccess == pdTRUE);
- IGNORE_ERRORS(xSuccess);
-}
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osoutput.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osoutput.c
deleted file mode 100755
index 8a7fb1d..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/osoutput.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements outputting a character string.
-*/
-#include
-
-#if REDCONF_OUTPUT == 1
-
-#include
-
-
-/** @brief Write a string to a user-visible output location.
-
- Write a null-terminated string to the serial port, console, terminal, or
- other display device, such that the text is visible to the user.
-
- @param pszString A null-terminated string.
-*/
-void RedOsOutputString(
- const char *pszString)
-{
- if(pszString == NULL)
- {
- REDERROR();
- }
- else
- {
- uint32_t ulIdx = 0U;
-
- while(pszString[ulIdx] != '\0')
- {
- OUTPUT_CHARACTER(pszString[ulIdx]);
-
- /* Serial output often requires a \r to print newlines correctly.
- */
- if(pszString[ulIdx] == '\n')
- {
- OUTPUT_CHARACTER('\r');
- }
-
- ulIdx++;
- }
- }
-}
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostask.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostask.c
deleted file mode 100755
index 01bf382..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostask.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements task functions.
-*/
-#include
-#include
-
-#include
-
-#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1)
-
-#include
-
-#if INCLUDE_xTaskGetCurrentTaskHandle != 1
- #error "INCLUDE_xTaskGetCurrentTaskHandle must be 1 when REDCONF_TASK_COUNT > 1 and REDCONF_API_POSIX == 1"
-#endif
-
-
-/** @brief Get the current task ID.
-
- This task ID must be unique for all tasks using the file system.
-
- @return The task ID. Must not be 0.
-*/
-uint32_t RedOsTaskId(void)
-{
- /* Simply casting the xTaskGetCurrentTaskHandle() return value results in
- warnings from some compilers, so use variables.
- */
- TaskHandle_t xTask = xTaskGetCurrentTaskHandle();
- uintptr_t taskptr = CAST_TASK_PTR_TO_UINTPTR(xTask);
- uint32_t ulTaskPtr = (uint32_t)taskptr;
-
- /* Assert no information was lost casting from uintptr_t to uint32_t.
- */
- REDASSERT(ulTaskPtr == taskptr);
-
- /* NULL is a valid task handle in FreeRTOS, so add one to all task IDs.
- */
- REDASSERT((ulTaskPtr + 1U) != 0U);
- return ulTaskPtr + 1U;
-}
-
-#endif
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostimestamp.c b/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostimestamp.c
deleted file mode 100755
index 364813e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/os/freertos/services/ostimestamp.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements timestamp functions.
-
- The functionality implemented herein is not needed for the file system
- driver, only to provide accurate results with performance tests.
-*/
-#include
-#include
-
-#include
-
-
-/* configTICK_RATE_HZ is almost always 100, 250, 500, or 1000. If
- 1000000U % configTICK_RATE_HZ != 0, then RedOsTimePassed() will be a
- little inaccurate.
-*/
-#define MICROSECS_PER_TICK (1000000U / configTICK_RATE_HZ)
-
-
-/** @brief Initialize the timestamp service.
-
- The behavior of invoking this function when timestamps are already
- initialized is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_ENOSYS The timestamp service has not been implemented.
-*/
-REDSTATUS RedOsTimestampInit(void)
-{
- return 0;
-}
-
-
-/** @brief Uninitialize the timestamp service.
-
- The behavior of invoking this function when timestamps are not initialized
- is undefined.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
-*/
-REDSTATUS RedOsTimestampUninit(void)
-{
- return 0;
-}
-
-
-/** @brief Retrieve a timestamp.
-
- The behavior of invoking this function when timestamps are not initialized
- is undefined
-
- @return A timestamp which can later be passed to RedOsTimePassed() to
- determine the amount of time which passed between the two calls.
-*/
-REDTIMESTAMP RedOsTimestamp(void)
-{
- return xTaskGetTickCount();
-}
-
-
-/** @brief Determine how much time has passed since a timestamp was retrieved.
-
- The behavior of invoking this function when timestamps are not initialized
- is undefined.
-
- @param tsSince A timestamp acquired earlier via RedOsTimestamp().
-
- @return The number of microseconds which have passed since @p tsSince.
-*/
-uint64_t RedOsTimePassed(
- REDTIMESTAMP tsSince)
-{
- /* This works even if the tick count has wrapped around, provided it has
- only wrapped around once.
- */
- uint32_t ulTicksPassed = (uint32_t)xTaskGetTickCount() - tsSince;
- uint64_t ullMicrosecs = (uint64_t)ulTicksPassed * MICROSECS_PER_TICK;
-
- return ullMicrosecs;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/posix/path.c b/FreeRTOS-Plus/Source/Reliance-Edge/posix/path.c
deleted file mode 100755
index 4e4df2e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/posix/path.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements path utilities for the POSIX-like API layer.
-*/
-#include
-
-#if REDCONF_API_POSIX == 1
-
-#include
-#include
-#include
-#include
-
-
-static bool IsRootDir(const char *pszLocalPath);
-static bool PathHasMoreNames(const char *pszPathIdx);
-
-
-/** @brief Split a path into its component parts: a volume and a volume-local
- path.
-
- @param pszPath The path to split.
- @param pbVolNum On successful return, if non-NULL, populated with
- the volume number extracted from the path.
- @param ppszLocalPath On successful return, populated with the
- volume-local path: the path stripped of any volume
- path prefixing. If this parameter is NULL, that
- indicates there should be no local path, and any
- characters beyond the prefix (other than path
- separators) are treated as an error.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pszPath is `NULL`.
- @retval -RED_ENOENT @p pszPath could not be matched to any volume; or
- @p ppszLocalPath is NULL but @p pszPath includes a local
- path.
-*/
-REDSTATUS RedPathSplit(
- const char *pszPath,
- uint8_t *pbVolNum,
- const char **ppszLocalPath)
-{
- REDSTATUS ret = 0;
-
- if(pszPath == NULL)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- const char *pszLocalPath = pszPath;
- uint8_t bMatchVol = UINT8_MAX;
- uint32_t ulMatchLen = 0U;
- uint8_t bDefaultVolNum = UINT8_MAX;
- uint8_t bVolNum;
-
- for(bVolNum = 0U; bVolNum < REDCONF_VOLUME_COUNT; bVolNum++)
- {
- const char *pszPrefix = gaRedVolConf[bVolNum].pszPathPrefix;
- uint32_t ulPrefixLen = RedStrLen(pszPrefix);
-
- if(ulPrefixLen == 0U)
- {
- /* A volume with a path prefix of an empty string is the
- default volume, used when the path does not match the
- prefix of any other volume.
-
- The default volume should only be found once. During
- initialization, RedCoreInit() ensures that all volume
- prefixes are unique (including empty prefixes).
- */
- REDASSERT(bDefaultVolNum == UINT8_MAX);
- bDefaultVolNum = bVolNum;
- }
- /* For a path to match, it must either be the prefix exactly, or
- be followed by a path separator character. Thus, with a volume
- prefix of "/foo", both "/foo" and "/foo/bar" are matches, but
- "/foobar" is not.
- */
- else if( (RedStrNCmp(pszPath, pszPrefix, ulPrefixLen) == 0)
- && ((pszPath[ulPrefixLen] == '\0') || (pszPath[ulPrefixLen] == REDCONF_PATH_SEPARATOR)))
- {
- /* The length of this match should never exactly equal the
- length of a previous match: that would require a duplicate
- volume name, which should have been detected during init.
- */
- REDASSERT(ulPrefixLen != ulMatchLen);
-
- /* If multiple prefixes match, the longest takes precedence.
- Thus, if there are two prefixes "Flash" and "Flash/Backup",
- the path "Flash/Backup/" will not be erroneously matched
- with the "Flash" volume.
- */
- if(ulPrefixLen > ulMatchLen)
- {
- bMatchVol = bVolNum;
- ulMatchLen = ulPrefixLen;
- }
- }
- else
- {
- /* No match, keep looking.
- */
- }
- }
-
- if(bMatchVol != UINT8_MAX)
- {
- /* The path matched a volume path prefix.
- */
- bVolNum = bMatchVol;
- pszLocalPath = &pszPath[ulMatchLen];
- }
- else if(bDefaultVolNum != UINT8_MAX)
- {
- /* The path didn't match any of the prefixes, but one of the
- volumes has a path prefix of "", so an unprefixed path is
- assigned to that volume.
- */
- bVolNum = bDefaultVolNum;
- REDASSERT(pszLocalPath == pszPath);
- }
- else
- {
- /* The path cannot be assigned a volume.
- */
- ret = -RED_ENOENT;
- }
-
- if(ret == 0)
- {
- if(pbVolNum != NULL)
- {
- *pbVolNum = bVolNum;
- }
-
- if(ppszLocalPath != NULL)
- {
- *ppszLocalPath = pszLocalPath;
- }
- else
- {
- /* If no local path is expected, then the string should either
- terminate after the path prefix or the local path should name
- the root directory. Allowing path separators here means that
- red_mount("/data/") is OK with a path prefix of "/data".
- */
- if(pszLocalPath[0U] != '\0')
- {
- if(!IsRootDir(pszLocalPath))
- {
- ret = -RED_ENOENT;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Lookup the inode named by the given path.
-
- @param pszLocalPath The path to lookup; this is a local path, without any
- volume prefix.
- @param pulInode On successful return, populated with the number of the
- inode named by @p pszLocalPath.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pszLocalPath is `NULL`; or @p pulInode is
- `NULL`.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT @p pszLocalPath is an empty string; or
- @p pszLocalPath does not name an existing file
- or directory.
- @retval -RED_ENOTDIR A component of the path other than the last is
- not a directory.
- @retval -RED_ENAMETOOLONG The length of a component of @p pszLocalPath is
- longer than #REDCONF_NAME_MAX.
-*/
-REDSTATUS RedPathLookup(
- const char *pszLocalPath,
- uint32_t *pulInode)
-{
- REDSTATUS ret;
-
- if((pszLocalPath == NULL) || (pulInode == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(pszLocalPath[0U] == '\0')
- {
- ret = -RED_ENOENT;
- }
- else if(IsRootDir(pszLocalPath))
- {
- ret = 0;
- *pulInode = INODE_ROOTDIR;
- }
- else
- {
- uint32_t ulPInode;
- const char *pszName;
-
- ret = RedPathToName(pszLocalPath, &ulPInode, &pszName);
-
- if(ret == 0)
- {
- ret = RedCoreLookup(ulPInode, pszName, pulInode);
- }
- }
-
- return ret;
-}
-
-
-/** @brief Given a path, return the parent inode number and a pointer to the
- last component in the path (the name).
-
- @param pszLocalPath The path to examine; this is a local path, without any
- volume prefix.
- @param pulPInode On successful return, populated with the inode number of
- the parent directory of the last component in the path.
- For example, with the path "a/b/c", populated with the
- inode number of "b".
- @param ppszName On successful return, populated with a pointer to the
- last component in the path. For example, with the path
- "a/b/c", populated with a pointer to "c".
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p pszLocalPath is `NULL`; or @p pulPInode is
- `NULL`; or @p ppszName is `NULL`; or the path
- names the root directory.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENOENT @p pszLocalPath is an empty string; or a
- component of the path other than the last does
- not exist.
- @retval -RED_ENOTDIR A component of the path other than the last is
- not a directory.
- @retval -RED_ENAMETOOLONG The length of a component of @p pszLocalPath is
- longer than #REDCONF_NAME_MAX.
-*/
-REDSTATUS RedPathToName(
- const char *pszLocalPath,
- uint32_t *pulPInode,
- const char **ppszName)
-{
- REDSTATUS ret;
-
- if((pszLocalPath == NULL) || (pulPInode == NULL) || (ppszName == NULL))
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(IsRootDir(pszLocalPath))
- {
- ret = -RED_EINVAL;
- }
- else if(pszLocalPath[0U] == '\0')
- {
- ret = -RED_ENOENT;
- }
- else
- {
- uint32_t ulInode = INODE_ROOTDIR;
- uint32_t ulPInode = INODE_INVALID;
- uint32_t ulPathIdx = 0U;
- uint32_t ulLastNameIdx = 0U;
-
- ret = 0;
-
- do
- {
- uint32_t ulNameLen;
-
- /* Skip over path separators, to get pszLocalPath[ulPathIdx]
- pointing at the next name.
- */
- while(pszLocalPath[ulPathIdx] == REDCONF_PATH_SEPARATOR)
- {
- ulPathIdx++;
- }
-
- if(pszLocalPath[ulPathIdx] == '\0')
- {
- break;
- }
-
- /* Point ulLastNameIdx at the first character of the name; after
- we exit the loop, it will point at the first character of the
- last name in the path.
- */
- ulLastNameIdx = ulPathIdx;
-
- /* Point ulPInode at the parent inode: either the root inode
- (first pass) or the inode of the previous name. After we exit
- the loop, this will point at the parent inode of the last name.
- */
- ulPInode = ulInode;
-
- ulNameLen = RedNameLen(&pszLocalPath[ulPathIdx]);
-
- /* Lookup the inode of the name, unless we are at the last name in
- the path: we don't care whether the last name exists or not.
- */
- if(PathHasMoreNames(&pszLocalPath[ulPathIdx + ulNameLen]))
- {
- ret = RedCoreLookup(ulPInode, &pszLocalPath[ulPathIdx], &ulInode);
- }
-
- /* Move on to the next path element.
- */
- if(ret == 0)
- {
- ulPathIdx += ulNameLen;
- }
- }
- while(ret == 0);
-
- if(ret == 0)
- {
- *pulPInode = ulPInode;
- *ppszName = &pszLocalPath[ulLastNameIdx];
- }
- }
-
- return ret;
-}
-
-
-/** @brief Determine whether a path names the root directory.
-
- @param pszLocalPath The path to examine; this is a local path, without any
- volume prefix.
-
- @return Returns whether @p pszLocalPath names the root directory.
-
- @retval true @p pszLocalPath names the root directory.
- @retval false @p pszLocalPath does not name the root directory.
-*/
-static bool IsRootDir(
- const char *pszLocalPath)
-{
- bool fRet;
-
- if(pszLocalPath == NULL)
- {
- REDERROR();
- fRet = false;
- }
- else
- {
- uint32_t ulIdx = 0U;
-
- /* A string containing nothing but path separators (usually only one)
- names the root directory. An empty string does *not* name the root
- directory, since in POSIX empty strings typically elicit -RED_ENOENT
- errors.
- */
- while(pszLocalPath[ulIdx] == REDCONF_PATH_SEPARATOR)
- {
- ulIdx++;
- }
-
- fRet = (ulIdx > 0U) && (pszLocalPath[ulIdx] == '\0');
- }
-
- return fRet;
-}
-
-
-/** @brief Determine whether there are more names in a path.
-
- Example | Result
- ------- | ------
- "" false
- "/" false
- "//" false
- "a" true
- "/a" true
- "//a" true
-
- @param pszPathIdx The path to examine, incremented to the point of
- interest.
-
- @return Returns whether there are more names in @p pszPathIdx.
-
- @retval true @p pszPathIdx has more names.
- @retval false @p pszPathIdx has no more names.
-*/
-static bool PathHasMoreNames(
- const char *pszPathIdx)
-{
- bool fRet;
-
- if(pszPathIdx == NULL)
- {
- REDERROR();
- fRet = false;
- }
- else
- {
- uint32_t ulIdx = 0U;
-
- while(pszPathIdx[ulIdx] == REDCONF_PATH_SEPARATOR)
- {
- ulIdx++;
- }
-
- fRet = pszPathIdx[ulIdx] != '\0';
- }
-
- return fRet;
-}
-
-#endif /* REDCONF_API_POSIX */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/posix/posix.c b/FreeRTOS-Plus/Source/Reliance-Edge/posix/posix.c
deleted file mode 100755
index ef83395..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/posix/posix.c
+++ /dev/null
@@ -1,3088 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implementation of the the Reliance Edge POSIX-like API.
-*/
-
-#include
-
-#if REDCONF_API_POSIX == 1
-
-/** @defgroup red_group_posix The POSIX-like File System Interface
- @{
-*/
-
-#include
-#include
-#include
-#include
-
-
-/*-------------------------------------------------------------------
- File Descriptors
--------------------------------------------------------------------*/
-
-#define FD_GEN_BITS 11U /* File descriptor bits for mount generation. */
-#define FD_VOL_BITS 8U /* File descriptor bits for volume number. */
-#define FD_IDX_BITS 12U /* File descriptor bits for handle index. */
-
-/* 31 bits available: file descriptors are int32_t, but the sign bit must
- always be zero.
-*/
-#if (FD_GEN_BITS + FD_VOL_BITS + FD_IDX_BITS) > 31U
- #error "Internal error: too many file descriptor bits!"
-#endif
-
-/* Maximum values for file descriptor components.
-*/
-#define FD_GEN_MAX ((1UL << FD_GEN_BITS) - 1U)
-#define FD_VOL_MAX ((1UL << FD_VOL_BITS) - 1U)
-#define FD_IDX_MAX ((1UL << FD_IDX_BITS) - 1U)
-
-#if REDCONF_VOLUME_COUNT > FD_VOL_MAX
- #error "Error: Too many file system volumes!"
-#endif
-#if REDCONF_HANDLE_COUNT > (FD_IDX_MAX + 1U)
- #error "Error: Too many file system handles!"
-#endif
-
-/* File descriptors must never be negative; and must never be zero, one, or
- two, to avoid confusion with STDIN, STDOUT, and STDERR.
-*/
-#define FD_MIN (3)
-
-/*-------------------------------------------------------------------
- Handles
--------------------------------------------------------------------*/
-
-/* Mask of all RED_O_* values.
-*/
-#define RED_O_MASK (RED_O_RDONLY|RED_O_WRONLY|RED_O_RDWR|RED_O_APPEND|RED_O_CREAT|RED_O_EXCL|RED_O_TRUNC)
-
-#define HFLAG_DIRECTORY 0x01U /* Handle is for a directory. */
-#define HFLAG_READABLE 0x02U /* Handle is readable. */
-#define HFLAG_WRITEABLE 0x04U /* Handle is writeable. */
-#define HFLAG_APPENDING 0x08U /* Handle was opened in append mode. */
-
-/* @brief Handle structure, used to implement file descriptors and directory
- streams.
-*/
-typedef struct sREDHANDLE
-{
- uint32_t ulInode; /**< Inode number; 0 if handle is available. */
- uint8_t bVolNum; /**< Volume containing the inode. */
- uint8_t bFlags; /**< Handle flags (type and mode). */
- uint64_t ullOffset; /**< File or directory offset. */
- #if REDCONF_API_POSIX_READDIR == 1
- REDDIRENT dirent; /**< Dirent structure returned by red_readdir(). */
- #endif
-} REDHANDLE;
-
-/*-------------------------------------------------------------------
- Tasks
--------------------------------------------------------------------*/
-
-#if REDCONF_TASK_COUNT > 1U
-/* @brief Per-task information.
-*/
-typedef struct
-{
- uint32_t ulTaskId; /**< ID of the task which owns this slot; 0 if free. */
- REDSTATUS iErrno; /**< Last error value. */
-} TASKSLOT;
-#endif
-
-/*-------------------------------------------------------------------
- Local Prototypes
--------------------------------------------------------------------*/
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
-static REDSTATUS UnlinkSub(const char *pszPath, FTYPE type);
-#endif
-static REDSTATUS FildesOpen(const char *pszPath, uint32_t ulOpenMode, FTYPE type, int32_t *piFildes);
-static REDSTATUS FildesClose(int32_t iFildes);
-static REDSTATUS FildesToHandle(int32_t iFildes, FTYPE expectedType, REDHANDLE **ppHandle);
-static int32_t FildesPack(uint16_t uHandleIdx, uint8_t bVolNum);
-static void FildesUnpack(int32_t iFildes, uint16_t *puHandleIdx, uint8_t *pbVolNum, uint16_t *puGeneration);
-#if REDCONF_API_POSIX_READDIR == 1
-static bool DirStreamIsValid(const REDDIR *pDirStream);
-#endif
-static REDSTATUS PosixEnter(void);
-static void PosixLeave(void);
-static REDSTATUS ModeTypeCheck(uint16_t uMode, FTYPE expectedType);
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1) || ((REDCONF_API_POSIX_RENAME == 1) && (REDCONF_RENAME_ATOMIC == 1)))
-static REDSTATUS InodeUnlinkCheck(uint32_t ulInode);
-#endif
-#if REDCONF_TASK_COUNT > 1U
-static REDSTATUS TaskRegister(uint32_t *pulTaskIdx);
-#endif
-static int32_t PosixReturn(REDSTATUS iError);
-
-/*-------------------------------------------------------------------
- Globals
--------------------------------------------------------------------*/
-
-static bool gfPosixInited; /* Whether driver is initialized. */
-static REDHANDLE gaHandle[REDCONF_HANDLE_COUNT]; /* Array of all handles. */
-#if REDCONF_TASK_COUNT > 1U
-static TASKSLOT gaTask[REDCONF_TASK_COUNT]; /* Array of task slots. */
-#endif
-
-/* Array of volume mount "generations". These are incremented for a volume
- each time that volume is mounted. The generation number (along with the
- volume number) is incorporated into the file descriptors; a stale file
- descriptor from a previous mount can be detected since it will include a
- stale generation number.
-*/
-static uint16_t gauGeneration[REDCONF_VOLUME_COUNT];
-
-
-/*-------------------------------------------------------------------
- Public API
--------------------------------------------------------------------*/
-
-/** @brief Initialize the Reliance Edge file system driver.
-
- Prepares the Reliance Edge file system driver to be used. Must be the first
- Reliance Edge function to be invoked: no volumes can be mounted or formatted
- until the driver has been initialized.
-
- If this function is called when the Reliance Edge driver is already
- initialized, it does nothing and returns success.
-
- This function is not thread safe: attempting to initialize from multiple
- threads could leave things in a bad state.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: The volume path prefix configuration is invalid.
-*/
-int32_t red_init(void)
-{
- REDSTATUS ret;
-
- if(gfPosixInited)
- {
- ret = 0;
- }
- else
- {
- ret = RedCoreInit();
- if(ret == 0)
- {
- RedMemSet(gaHandle, 0U, sizeof(gaHandle));
-
- #if REDCONF_TASK_COUNT > 1U
- RedMemSet(gaTask, 0U, sizeof(gaTask));
- #endif
-
- gfPosixInited = true;
- }
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Uninitialize the Reliance Edge file system driver.
-
- Tears down the Reliance Edge file system driver. Cannot be used until all
- Reliance Edge volumes are unmounted. A subsequent call to red_init() will
- initialize the driver again.
-
- If this function is called when the Reliance Edge driver is already
- uninitialized, it does nothing and returns success.
-
- This function is not thread safe: attempting to uninitialize from multiple
- threads could leave things in a bad state.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: At least one volume is still mounted.
-*/
-int32_t red_uninit(void)
-{
- REDSTATUS ret;
-
- if(gfPosixInited)
- {
- ret = PosixEnter();
-
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- for(bVolNum = 0U; bVolNum < REDCONF_VOLUME_COUNT; bVolNum++)
- {
- if(gaRedVolume[bVolNum].fMounted)
- {
- ret = -RED_EBUSY;
- break;
- }
- }
-
- if(ret == 0)
- {
- /* All volumes are unmounted. Mark the driver as
- uninitialized before releasing the FS mutex, to avoid any
- race condition where a volume could be mounted and then the
- driver uninitialized with a mounted volume.
- */
- gfPosixInited = false;
- }
-
- /* The FS mutex must be released before we uninitialize the core,
- since the FS mutex needs to be in the released state when it
- gets uninitialized.
-
- Don't use PosixLeave(), since it asserts gfPosixInited is true.
- */
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexRelease();
- #endif
- }
-
- if(ret == 0)
- {
- ret = RedCoreUninit();
-
- /* Not good if the above fails, since things might be partly, but
- not entirely, torn down, and there might not be a way back to
- a valid driver state.
- */
- REDASSERT(ret == 0);
- }
- }
- else
- {
- ret = 0;
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Mount a file system volume.
-
- Prepares the file system volume to be accessed. Mount will fail if the
- volume has never been formatted, or if the on-disk format is inconsistent
- with the compile-time configuration.
-
- An error is returned if the volume is already mounted.
-
- @param pszVolume A path prefix identifying the volume to mount.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: Volume is already mounted.
- - #RED_EINVAL: @p pszVolume is `NULL`; or the driver is uninitialized.
- - #RED_EIO: Volume not formatted, improperly formatted, or corrupt.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_mount(
- const char *pszVolume)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
-
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- /* The core will return success if the volume is already mounted, so
- check for that condition here to propagate the error.
- */
- if((ret == 0) && gaRedVolume[bVolNum].fMounted)
- {
- ret = -RED_EBUSY;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolMount();
- }
-
- if(ret == 0)
- {
- /* Increment the mount generation, invalidating file descriptors
- from previous mounts. Note that while the generation numbers
- are stored in 16-bit values, we have less than 16-bits to store
- generations in the file descriptors, so we must wrap-around
- manually.
- */
- gauGeneration[bVolNum]++;
- if(gauGeneration[bVolNum] > FD_GEN_MAX)
- {
- /* Wrap-around to one, rather than zero. The generation is
- stored in the top bits of the file descriptor, and doing
- this means that low numbers are never valid file
- descriptors. This implements the requirement that 0, 1,
- and 2 are never valid file descriptors, thereby avoiding
- confusion with STDIN, STDOUT, and STDERR.
- */
- gauGeneration[bVolNum] = 1U;
- }
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Unmount a file system volume.
-
- This function discards the in-memory state for the file system and marks it
- as unmounted. Subsequent attempts to access the volume will fail until the
- volume is mounted again.
-
- If unmount automatic transaction points are enabled, this function will
- commit a transaction point prior to unmounting. If unmount automatic
- transaction points are disabled, this function will unmount without
- transacting, effectively discarding the working state.
-
- Before unmounting, this function will wait for any active file system
- thread to complete by acquiring the FS mutex. The volume will be marked as
- unmounted before the FS mutex is released, so subsequent FS threads will
- possibly block and then see an error when attempting to access a volume
- which is unmounting or unmounted. If the volume has open handles, the
- unmount will fail.
-
- An error is returned if the volume is already unmounted.
-
- @param pszVolume A path prefix identifying the volume to unmount.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: There are still open handles for this file system volume.
- - #RED_EINVAL: @p pszVolume is `NULL`; or the driver is uninitialized; or
- the volume is already unmounted.
- - #RED_EIO: I/O error during unmount automatic transaction point.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_umount(
- const char *pszVolume)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- /* The core will return success if the volume is already unmounted, so
- check for that condition here to propagate the error.
- */
- if((ret == 0) && !gaRedVolume[bVolNum].fMounted)
- {
- ret = -RED_EINVAL;
- }
-
- if(ret == 0)
- {
- uint16_t uHandleIdx;
-
- /* Do not unmount the volume if it still has open handles.
- */
- for(uHandleIdx = 0U; uHandleIdx < REDCONF_HANDLE_COUNT; uHandleIdx++)
- {
- const REDHANDLE *pHandle = &gaHandle[uHandleIdx];
-
- if((pHandle->ulInode != INODE_INVALID) && (pHandle->bVolNum == bVolNum))
- {
- ret = -RED_EBUSY;
- break;
- }
- }
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolUnmount();
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_FORMAT == 1)
-/** @brief Format a file system volume.
-
- Uses the statically defined volume configuration. After calling this
- function, the volume needs to be mounted -- see red_mount().
-
- An error is returned if the volume is mounted.
-
- @param pszVolume A path prefix identifying the volume to format.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: Volume is mounted.
- - #RED_EINVAL: @p pszVolume is `NULL`; or the driver is uninitialized.
- - #RED_EIO: I/O error formatting the volume.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_format(
- const char *pszVolume)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolFormat();
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Commit a transaction point.
-
- Reliance Edge is a transactional file system. All modifications, of both
- metadata and filedata, are initially working state. A transaction point
- is a process whereby the working state atomically becomes the committed
- state, replacing the previous committed state. Whenever Reliance Edge is
- mounted, including after power loss, the state of the file system after
- mount is the most recent committed state. Nothing from the committed
- state is ever missing, and nothing from the working state is ever included.
-
- @param pszVolume A path prefix identifying the volume to transact.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: Volume is not mounted; or @p pszVolume is `NULL`.
- - #RED_EIO: I/O error during the transaction point.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_transact(
- const char *pszVolume)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolTransact();
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Update the transaction mask.
-
- The following events are available:
-
- - #RED_TRANSACT_UMOUNT
- - #RED_TRANSACT_CREAT
- - #RED_TRANSACT_UNLINK
- - #RED_TRANSACT_MKDIR
- - #RED_TRANSACT_RENAME
- - #RED_TRANSACT_LINK
- - #RED_TRANSACT_CLOSE
- - #RED_TRANSACT_WRITE
- - #RED_TRANSACT_FSYNC
- - #RED_TRANSACT_TRUNCATE
- - #RED_TRANSACT_VOLFULL
-
- The #RED_TRANSACT_MANUAL macro (by itself) may be used to disable all
- automatic transaction events. The #RED_TRANSACT_MASK macro is a bitmask
- of all transaction flags, excluding those representing excluded
- functionality.
-
- Attempting to enable events for excluded functionality will result in an
- error.
-
- @param pszVolume The path prefix of the volume whose transaction mask is
- being changed.
- @param ulEventMask A bitwise-OR'd mask of automatic transaction events to
- be set as the current transaction mode.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: Volume is not mounted; or @p pszVolume is `NULL`; or
- @p ulEventMask contains invalid bits.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_settransmask(
- const char *pszVolume,
- uint32_t ulEventMask)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreTransMaskSet(ulEventMask);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-/** @brief Read the transaction mask.
-
- If the volume is read-only, the returned event mask is always zero.
-
- @param pszVolume The path prefix of the volume whose transaction mask is
- being retrieved.
- @param pulEventMask Populated with a bitwise-OR'd mask of automatic
- transaction events which represent the current
- transaction mode for the volume.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: Volume is not mounted; or @p pszVolume is `NULL`; or
- @p pulEventMask is `NULL`.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_gettransmask(
- const char *pszVolume,
- uint32_t *pulEventMask)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreTransMaskGet(pulEventMask);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Query file system status information.
-
- @p pszVolume should name a valid volume prefix or a valid root directory;
- this differs from POSIX statvfs, where any existing file or directory is a
- valid path.
-
- @param pszVolume The path prefix of the volume to query.
- @param pStatvfs The buffer to populate with volume information.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: Volume is not mounted; or @p pszVolume is `NULL`; or
- @p pStatvfs is `NULL`.
- - #RED_ENOENT: @p pszVolume is not a valid volume path prefix.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_statvfs(
- const char *pszVolume,
- REDSTATFS *pStatvfs)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszVolume, &bVolNum, NULL);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreVolStat(pStatvfs);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Open a file or directory.
-
- Exactly one file access mode must be specified:
-
- - #RED_O_RDONLY: Open for reading only.
- - #RED_O_WRONLY: Open for writing only.
- - #RED_O_RDWR: Open for reading and writing.
-
- Directories can only be opened with `RED_O_RDONLY`.
-
- The following flags may also be used:
-
- - #RED_O_APPEND: Set the file offset to the end-of-file prior to each
- write.
- - #RED_O_CREAT: Create the named file if it does not exist.
- - #RED_O_EXCL: In combination with `RED_O_CREAT`, return an error if the
- path already exists.
- - #RED_O_TRUNC: Truncate the opened file to size zero. Only supported when
- #REDCONF_API_POSIX_FTRUNCATE is true.
-
- #RED_O_CREAT, #RED_O_EXCL, and #RED_O_TRUNC are invalid with #RED_O_RDONLY.
- #RED_O_EXCL is invalid without #RED_O_CREAT.
-
- If the volume is read-only, #RED_O_RDONLY is the only valid open flag; use
- of any other flag will result in an error.
-
- If #RED_O_TRUNC frees data which is in the committed state, it will not
- return to free space until after a transaction point.
-
- The returned file descriptor must later be closed with red_close().
-
- Unlike POSIX open, there is no optional third argument for the permissions
- (which Reliance Edge does not use) and other open flags (like `O_SYNC`) are
- not supported.
-
- @param pszPath The path to the file or directory.
- @param ulOpenMode The open flags (mask of `RED_O_` values).
-
- @return On success, a nonnegative file descriptor is returned. On error,
- -1 is returned and #red_errno is set appropriately.
-
- Errno values
- - #RED_EEXIST: Using #RED_O_CREAT and #RED_O_EXCL, and the indicated path
- already exists.
- - #RED_EINVAL: @p ulOpenMode is invalid; or @p pszPath is `NULL`; or the
- volume containing the path is not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EISDIR: The path names a directory and @p ulOpenMode includes
- #RED_O_WRONLY or #RED_O_RDWR.
- - #RED_EMFILE: There are no available file descriptors.
- - #RED_ENAMETOOLONG: The length of a component of @p pszPath is longer than
- #REDCONF_NAME_MAX.
- - #RED_ENFILE: Attempting to create a file but the file system has used all
- available inode slots.
- - #RED_ENOENT: #RED_O_CREAT is not set and the named file does not exist; or
- #RED_O_CREAT is set and the parent directory does not exist; or the
- volume does not exist; or the @p pszPath argument, after removing the
- volume prefix, points to an empty string.
- - #RED_ENOSPC: The file does not exist and #RED_O_CREAT was specified, but
- there is insufficient free space to expand the directory or to create the
- new file.
- - #RED_ENOTDIR: A component of the prefix in @p pszPath does not name a
- directory.
- - #RED_EROFS: The path resides on a read-only file system and a write
- operation was requested.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_open(
- const char *pszPath,
- uint32_t ulOpenMode)
-{
- int32_t iFildes = -1; /* Init'd to quiet warnings. */
- REDSTATUS ret;
-
- #if REDCONF_READ_ONLY == 1
- if(ulOpenMode != RED_O_RDONLY)
- {
- ret = -RED_EROFS;
- }
- #else
- if( (ulOpenMode != (ulOpenMode & RED_O_MASK))
- || ((ulOpenMode & (RED_O_RDONLY|RED_O_WRONLY|RED_O_RDWR)) == 0U)
- || (((ulOpenMode & RED_O_RDONLY) != 0U) && ((ulOpenMode & (RED_O_WRONLY|RED_O_RDWR)) != 0U))
- || (((ulOpenMode & RED_O_WRONLY) != 0U) && ((ulOpenMode & (RED_O_RDONLY|RED_O_RDWR)) != 0U))
- || (((ulOpenMode & RED_O_RDWR) != 0U) && ((ulOpenMode & (RED_O_RDONLY|RED_O_WRONLY)) != 0U))
- || (((ulOpenMode & (RED_O_TRUNC|RED_O_CREAT|RED_O_EXCL)) != 0U) && ((ulOpenMode & RED_O_RDONLY) != 0U))
- || (((ulOpenMode & RED_O_EXCL) != 0U) && ((ulOpenMode & RED_O_CREAT) == 0U)))
- {
- ret = -RED_EINVAL;
- }
- #if REDCONF_API_POSIX_FTRUNCATE == 0
- else if((ulOpenMode & RED_O_TRUNC) != 0U)
- {
- ret = -RED_EINVAL;
- }
- #endif
- #endif
- else
- {
- ret = PosixEnter();
- }
-
- if(ret == 0)
- {
- ret = FildesOpen(pszPath, ulOpenMode, FTYPE_EITHER, &iFildes);
-
- PosixLeave();
- }
-
- if(ret != 0)
- {
- iFildes = PosixReturn(ret);
- }
-
- return iFildes;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_UNLINK == 1)
-/** @brief Delete a file or directory.
-
- The given name is deleted and the link count of the corresponding inode is
- decremented. If the link count falls to zero (no remaining hard links),
- the inode will be deleted.
-
- Unlike POSIX unlink, deleting a file or directory with open handles (file
- descriptors or directory streams) will fail with an #RED_EBUSY error. This
- only applies when deleting an inode with a link count of one; if a file has
- multiple names (hard links), all but the last name may be deleted even if
- the file is open.
-
- If the path names a directory which is not empty, the unlink will fail.
-
- If the deletion frees data in the committed state, it will not return to
- free space until after a transaction point.
-
- Unlike POSIX unlink, this function can fail when the disk is full. To fix
- this, transact and try again: Reliance Edge guarantees that it is possible
- to delete at least one file or directory after a transaction point. If disk
- full automatic transactions are enabled, this will happen automatically.
-
- @param pszPath The path of the file or directory to delete.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: @p pszPath points to an inode with open handles and a link
- count of one.
- - #RED_EINVAL: @p pszPath is `NULL`; or the volume containing the path is
- not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENAMETOOLONG: The length of a component of @p pszPath is longer than
- #REDCONF_NAME_MAX.
- - #RED_ENOENT: The path does not name an existing file; or the @p pszPath
- argument, after removing the volume prefix, points to an empty string.
- - #RED_ENOTDIR: A component of the path prefix is not a directory.
- - #RED_ENOTEMPTY: The path names a directory which is not empty.
- - #RED_ENOSPC: The file system does not have enough space to modify the
- parent directory to perform the deletion.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_unlink(
- const char *pszPath)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- ret = UnlinkSub(pszPath, FTYPE_EITHER);
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_MKDIR == 1)
-/** @brief Create a new directory.
-
- Unlike POSIX mkdir, this function has no second argument for the
- permissions (which Reliance Edge does not use).
-
- @param pszPath The name and location of the directory to create.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EEXIST: @p pszPath points to an existing file or directory.
- - #RED_EINVAL: @p pszPath is `NULL`; or the volume containing the path is
- not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENAMETOOLONG: The length of a component of @p pszPath is longer than
- #REDCONF_NAME_MAX.
- - #RED_ENOENT: A component of the path prefix does not name an existing
- directory; or the @p pszPath argument, after removing the volume prefix,
- points to an empty string.
- - #RED_ENOSPC: The file system does not have enough space for the new
- directory or to extend the parent directory of the new directory.
- - #RED_ENOTDIR: A component of the path prefix is not a directory.
- - #RED_EROFS: The parent directory resides on a read-only file system.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_mkdir(
- const char *pszPath)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- const char *pszLocalPath;
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszPath, &bVolNum, &pszLocalPath);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- const char *pszName;
- uint32_t ulPInode;
-
- ret = RedPathToName(pszLocalPath, &ulPInode, &pszName);
-
- if(ret == 0)
- {
- uint32_t ulInode;
-
- ret = RedCoreCreate(ulPInode, pszName, true, &ulInode);
- }
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RMDIR == 1)
-/** @brief Delete a directory.
-
- The given directory name is deleted and the corresponding directory inode
- will be deleted.
-
- Unlike POSIX rmdir, deleting a directory with open handles (file
- descriptors or directory streams) will fail with an #RED_EBUSY error.
-
- If the path names a directory which is not empty, the deletion will fail.
- If the path names the root directory of a file system volume, the deletion
- will fail.
-
- If the path names a regular file, the deletion will fail. This provides
- type checking and may be useful in cases where an application knows the
- path to be deleted should name a directory.
-
- If the deletion frees data in the committed state, it will not return to
- free space until after a transaction point.
-
- Unlike POSIX rmdir, this function can fail when the disk is full. To fix
- this, transact and try again: Reliance Edge guarantees that it is possible
- to delete at least one file or directory after a transaction point. If disk
- full automatic transactions are enabled, this will happen automatically.
-
- @param pszPath The path of the directory to delete.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: @p pszPath points to a directory with open handles.
- - #RED_EINVAL: @p pszPath is `NULL`; or the volume containing the path is
- not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENAMETOOLONG: The length of a component of @p pszPath is longer than
- #REDCONF_NAME_MAX.
- - #RED_ENOENT: The path does not name an existing directory; or the
- @p pszPath argument, after removing the volume prefix, points to an empty
- string.
- - #RED_ENOTDIR: A component of the path is not a directory.
- - #RED_ENOTEMPTY: The path names a directory which is not empty.
- - #RED_ENOSPC: The file system does not have enough space to modify the
- parent directory to perform the deletion.
- - #RED_EROFS: The directory to be removed resides on a read-only file
- system.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_rmdir(
- const char *pszPath)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- ret = UnlinkSub(pszPath, FTYPE_DIR);
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_RENAME == 1)
-/** @brief Rename a file or directory.
-
- Both paths must reside on the same file system volume. Attempting to use
- this API to move a file to a different volume will result in an error.
-
- If @p pszNewPath names an existing file or directory, the behavior depends
- on the configuration. If #REDCONF_RENAME_ATOMIC is false, and if the
- destination name exists, this function always fails and sets #red_errno to
- #RED_EEXIST. This behavior is contrary to POSIX.
-
- If #REDCONF_RENAME_ATOMIC is true, and if the new name exists, then in one
- atomic operation, @p pszNewPath is unlinked and @p pszOldPath is renamed to
- @p pszNewPath. Both @p pszNewPath and @p pszOldPath must be of the same
- type (both files or both directories). As with red_unlink(), if
- @p pszNewPath is a directory, it must be empty. The major exception to this
- behavior is that if both @p pszOldPath and @p pszNewPath are links to the
- same inode, then the rename does nothing and both names continue to exist.
- Unlike POSIX rename, if @p pszNewPath points to an inode with a link count
- of one and open handles (file descriptors or directory streams), the
- rename will fail with #RED_EBUSY.
-
- If the rename deletes the old destination, it may free data in the
- committed state, which will not return to free space until after a
- transaction point. Similarly, if the deleted inode was part of the
- committed state, the inode slot will not be available until after a
- transaction point.
-
- @param pszOldPath The path of the file or directory to rename.
- @param pszNewPath The new name and location after the rename.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBUSY: #REDCONF_RENAME_ATOMIC is true and @p pszNewPath points to an
- inode with open handles and a link count of one.
- - #RED_EEXIST: #REDCONF_RENAME_ATOMIC is false and @p pszNewPath exists.
- - #RED_EINVAL: @p pszOldPath is `NULL`; or @p pszNewPath is `NULL`; or the
- volume containing the path is not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EISDIR: The @p pszNewPath argument names a directory and the
- @p pszOldPath argument names a non-directory.
- - #RED_ENAMETOOLONG: The length of a component of either @p pszOldPath or
- @p pszNewPath is longer than #REDCONF_NAME_MAX.
- - #RED_ENOENT: The link named by @p pszOldPath does not name an existing
- entry; or either @p pszOldPath or @p pszNewPath, after removing the volume
- prefix, point to an empty string.
- - #RED_ENOTDIR: A component of either path prefix is not a directory; or
- @p pszOldPath names a directory and @p pszNewPath names a file.
- - #RED_ENOTEMPTY: The path named by @p pszNewPath is a directory which is
- not empty.
- - #RED_ENOSPC: The file system does not have enough space to extend the
- directory that would contain @p pszNewPath.
- - #RED_EROFS: The directory to be removed resides on a read-only file
- system.
- - #RED_EUSERS: Cannot become a file system user: too many users.
- - #RED_EXDEV: @p pszOldPath and @p pszNewPath are on different file system
- volumes.
-*/
-int32_t red_rename(
- const char *pszOldPath,
- const char *pszNewPath)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- const char *pszOldLocalPath;
- uint8_t bOldVolNum;
-
- ret = RedPathSplit(pszOldPath, &bOldVolNum, &pszOldLocalPath);
-
- if(ret == 0)
- {
- const char *pszNewLocalPath;
- uint8_t bNewVolNum;
-
- ret = RedPathSplit(pszNewPath, &bNewVolNum, &pszNewLocalPath);
-
- if((ret == 0) && (bOldVolNum != bNewVolNum))
- {
- ret = -RED_EXDEV;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bOldVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- const char *pszOldName;
- uint32_t ulOldPInode;
-
- ret = RedPathToName(pszOldLocalPath, &ulOldPInode, &pszOldName);
-
- if(ret == 0)
- {
- const char *pszNewName;
- uint32_t ulNewPInode;
-
- ret = RedPathToName(pszNewLocalPath, &ulNewPInode, &pszNewName);
-
- #if REDCONF_RENAME_ATOMIC == 1
- if(ret == 0)
- {
- uint32_t ulDestInode;
-
- ret = RedCoreLookup(ulNewPInode, pszNewName, &ulDestInode);
- if(ret == 0)
- {
- ret = InodeUnlinkCheck(ulDestInode);
- }
- else if(ret == -RED_ENOENT)
- {
- ret = 0;
- }
- else
- {
- /* Unexpected error, nothing to do.
- */
- }
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreRename(ulOldPInode, pszOldName, ulNewPInode, pszNewName);
- }
- }
- }
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_LINK == 1)
-/** @brief Create a hard link.
-
- This creates an additional name (link) for the file named by @p pszPath.
- The new name refers to the same file with the same contents. If a name is
- deleted, but the underlying file has other names, the file continues to
- exist. The link count (accessible via red_fstat()) indicates the number of
- names that a file has. All of a file's names are on equal footing: there
- is nothing special about the original name.
-
- If @p pszPath names a directory, the operation will fail.
-
- @param pszPath The path indicating the inode for the new link.
- @param pszHardLink The name and location for the new link.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EEXIST: @p pszHardLink resolves to an existing file.
- - #RED_EINVAL: @p pszPath or @p pszHardLink is `NULL`; or the volume
- containing the paths is not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EMLINK: Creating the link would exceed the maximum link count of the
- inode named by @p pszPath.
- - #RED_ENAMETOOLONG: The length of a component of either @p pszPath or
- @p pszHardLink is longer than #REDCONF_NAME_MAX.
- - #RED_ENOENT: A component of either path prefix does not exist; or the file
- named by @p pszPath does not exist; or either @p pszPath or
- @p pszHardLink, after removing the volume prefix, point to an empty
- string.
- - #RED_ENOSPC: There is insufficient free space to expand the directory that
- would contain the link.
- - #RED_ENOTDIR: A component of either path prefix is not a directory.
- - #RED_EPERM: The @p pszPath argument names a directory.
- - #RED_EROFS: The requested link requires writing in a directory on a
- read-only file system.
- - #RED_EUSERS: Cannot become a file system user: too many users.
- - #RED_EXDEV: @p pszPath and @p pszHardLink are on different file system
- volumes.
-*/
-int32_t red_link(
- const char *pszPath,
- const char *pszHardLink)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- const char *pszLocalPath;
- uint8_t bVolNum;
-
- ret = RedPathSplit(pszPath, &bVolNum, &pszLocalPath);
-
- if(ret == 0)
- {
- const char *pszLinkLocalPath;
- uint8_t bLinkVolNum;
-
- ret = RedPathSplit(pszHardLink, &bLinkVolNum, &pszLinkLocalPath);
-
- if((ret == 0) && (bVolNum != bLinkVolNum))
- {
- ret = -RED_EXDEV;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- uint32_t ulInode;
-
- ret = RedPathLookup(pszLocalPath, &ulInode);
-
- if(ret == 0)
- {
- const char *pszLinkName;
- uint32_t ulLinkPInode;
-
- ret = RedPathToName(pszLinkLocalPath, &ulLinkPInode, &pszLinkName);
-
- if(ret == 0)
- {
- ret = RedCoreLink(ulLinkPInode, pszLinkName, ulInode);
- }
- }
- }
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-/** @brief Close a file descriptor.
-
- @param iFildes The file descriptor to close.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBADF: @p iFildes is not a valid file descriptor.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_close(
- int32_t iFildes)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- ret = FildesClose(iFildes);
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-/** @brief Read from an open file.
-
- The read takes place at the file offset associated with @p iFildes and
- advances the file offset by the number of bytes actually read.
-
- Data which has not yet been written, but which is before the end-of-file
- (sparse data), will read as zeroes. A short read -- where the number of
- bytes read is less than requested -- indicates that the requested read was
- partially or, if zero bytes were read, entirely beyond the end-of-file.
-
- @param iFildes The file descriptor from which to read.
- @param pBuffer The buffer to populate with data read. Must be at least
- @p ulLength bytes in size.
- @param ulLength Number of bytes to attempt to read.
-
- @return On success, returns a nonnegative value indicating the number of
- bytes actually read. On error, -1 is returned and #red_errno is
- set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not a valid file descriptor open
- for reading.
- - #RED_EINVAL: @p pBuffer is `NULL`; or @p ulLength exceeds INT32_MAX and
- cannot be returned properly.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EISDIR: The @p iFildes is a file descriptor for a directory.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_read(
- int32_t iFildes,
- void *pBuffer,
- uint32_t ulLength)
-{
- uint32_t ulLenRead = 0U;
- REDSTATUS ret;
- int32_t iReturn;
-
- if(ulLength > (uint32_t)INT32_MAX)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = PosixEnter();
- }
-
- if(ret == 0)
- {
- REDHANDLE *pHandle;
-
- ret = FildesToHandle(iFildes, FTYPE_FILE, &pHandle);
-
- if((ret == 0) && ((pHandle->bFlags & HFLAG_READABLE) == 0U))
- {
- ret = -RED_EBADF;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ulLenRead = ulLength;
- ret = RedCoreFileRead(pHandle->ulInode, pHandle->ullOffset, &ulLenRead, pBuffer);
- }
-
- if(ret == 0)
- {
- REDASSERT(ulLenRead <= ulLength);
-
- pHandle->ullOffset += ulLenRead;
- }
-
- PosixLeave();
- }
-
- if(ret == 0)
- {
- iReturn = (int32_t)ulLenRead;
- }
- else
- {
- iReturn = PosixReturn(ret);
- }
-
- return iReturn;
-}
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Write to an open file.
-
- The write takes place at the file offset associated with @p iFildes and
- advances the file offset by the number of bytes actually written.
- Alternatively, if @p iFildes was opened with #RED_O_APPEND, the file offset
- is set to the end-of-file before the write begins, and likewise advances by
- the number of bytes actually written.
-
- A short write -- where the number of bytes written is less than requested
- -- indicates either that the file system ran out of space but was still
- able to write some of the request; or that the request would have caused
- the file to exceed the maximum file size, but some of the data could be
- written prior to the file size limit.
-
- If an error is returned (-1), either none of the data was written or a
- critical error occurred (like an I/O error) and the file system volume will
- be read-only.
-
- @param iFildes The file descriptor to write to.
- @param pBuffer The buffer containing the data to be written. Must be at
- least @p ulLength bytes in size.
- @param ulLength Number of bytes to attempt to write.
-
- @return On success, returns a nonnegative value indicating the number of
- bytes actually written. On error, -1 is returned and #red_errno is
- set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not a valid file descriptor open
- for writing. This includes the case where the file descriptor is for a
- directory.
- - #RED_EFBIG: No data can be written to the current file offset since the
- resulting file size would exceed the maximum file size.
- - #RED_EINVAL: @p pBuffer is `NULL`; or @p ulLength exceeds INT32_MAX and
- cannot be returned properly.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENOSPC: No data can be written because there is insufficient free
- space.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_write(
- int32_t iFildes,
- const void *pBuffer,
- uint32_t ulLength)
-{
- uint32_t ulLenWrote = 0U;
- REDSTATUS ret;
- int32_t iReturn;
-
- if(ulLength > (uint32_t)INT32_MAX)
- {
- ret = -RED_EINVAL;
- }
- else
- {
- ret = PosixEnter();
- }
-
- if(ret == 0)
- {
- REDHANDLE *pHandle;
-
- ret = FildesToHandle(iFildes, FTYPE_FILE, &pHandle);
- if(ret == -RED_EISDIR)
- {
- /* POSIX says that if a file descriptor is not writable, the
- errno should be -RED_EBADF. Directory file descriptors are
- never writable, and unlike for read(), the spec does not
- list -RED_EISDIR as an allowed errno. Therefore -RED_EBADF
- takes precedence.
- */
- ret = -RED_EBADF;
- }
-
- if((ret == 0) && ((pHandle->bFlags & HFLAG_WRITEABLE) == 0U))
- {
- ret = -RED_EBADF;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- if((ret == 0) && ((pHandle->bFlags & HFLAG_APPENDING) != 0U))
- {
- REDSTAT s;
-
- ret = RedCoreStat(pHandle->ulInode, &s);
- if(ret == 0)
- {
- pHandle->ullOffset = s.st_size;
- }
- }
-
- if(ret == 0)
- {
- ulLenWrote = ulLength;
- ret = RedCoreFileWrite(pHandle->ulInode, pHandle->ullOffset, &ulLenWrote, pBuffer);
- }
-
- if(ret == 0)
- {
- REDASSERT(ulLenWrote <= ulLength);
-
- pHandle->ullOffset += ulLenWrote;
- }
-
- PosixLeave();
- }
-
- if(ret == 0)
- {
- iReturn = (int32_t)ulLenWrote;
- }
- else
- {
- iReturn = PosixReturn(ret);
- }
-
- return iReturn;
-}
-#endif
-
-
-#if REDCONF_READ_ONLY == 0
-/** @brief Synchronizes changes to a file.
-
- Commits all changes associated with a file or directory (including file
- data, directory contents, and metadata) to permanent storage. This
- function will not return until the operation is complete.
-
- In the current implementation, this function has global effect. All dirty
- buffers are flushed and a transaction point is committed. Fsyncing one
- file effectively fsyncs all files.
-
- If fsync automatic transactions have been disabled, this function does
- nothing and returns success. In the current implementation, this is the
- only real difference between this function and red_transact(): this
- function can be configured to do nothing, whereas red_transact() is
- unconditional.
-
- Applications written for portability should avoid assuming red_fsync()
- effects all files, and use red_fsync() on each file that needs to be
- synchronized.
-
- Passing read-only file descriptors to this function is permitted.
-
- @param iFildes The file descriptor to synchronize.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not a valid file descriptor.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_fsync(
- int32_t iFildes)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- REDHANDLE *pHandle;
-
- ret = FildesToHandle(iFildes, FTYPE_EITHER, &pHandle);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- /* No core event for fsync, so this transaction flag needs to be
- implemented here.
- */
- if(ret == 0)
- {
- uint32_t ulTransMask;
-
- ret = RedCoreTransMaskGet(&ulTransMask);
-
- if((ret == 0) && ((ulTransMask & RED_TRANSACT_FSYNC) != 0U))
- {
- ret = RedCoreVolTransact();
- }
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-/** @brief Move the read/write file offset.
-
- The file offset of the @p iFildes file descriptor is set to @p llOffset,
- relative to some starting position. The available positions are:
-
- - ::RED_SEEK_SET Seek from the start of the file. In other words,
- @p llOffset becomes the new file offset.
- - ::RED_SEEK_CUR Seek from the current file offset. In other words,
- @p llOffset is added to the current file offset.
- - ::RED_SEEK_END Seek from the end-of-file. In other words, the new file
- offset is the file size plus @p llOffset.
-
- Since @p llOffset is signed (can be negative), it is possible to seek
- backward with ::RED_SEEK_CUR or ::RED_SEEK_END.
-
- It is permitted to seek beyond the end-of-file; this does not increase the
- file size (a subsequent red_write() call would).
-
- Unlike POSIX lseek, this function cannot be used with directory file
- descriptors.
-
- @param iFildes The file descriptor whose offset is to be updated.
- @param llOffset The new file offset, relative to @p whence.
- @param whence The location from which @p llOffset should be applied.
-
- @return On success, returns the new file position, measured in bytes from
- the beginning of the file. On error, -1 is returned and #red_errno
- is set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not an open file descriptor.
- - #RED_EINVAL: @p whence is not a valid `RED_SEEK_` value; or the resulting
- file offset would be negative or beyond the maximum file size.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EISDIR: The @p iFildes argument is a file descriptor for a directory.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int64_t red_lseek(
- int32_t iFildes,
- int64_t llOffset,
- REDWHENCE whence)
-{
- REDSTATUS ret;
- int64_t llReturn = -1; /* Init'd to quiet warnings. */
-
- ret = PosixEnter();
- if(ret == 0)
- {
- int64_t llFrom = 0; /* Init'd to quiet warnings. */
- REDHANDLE *pHandle;
-
- /* Unlike POSIX, we disallow lseek() on directory handles.
- */
- ret = FildesToHandle(iFildes, FTYPE_FILE, &pHandle);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- switch(whence)
- {
- /* Seek from the beginning of the file.
- */
- case RED_SEEK_SET:
- llFrom = 0;
- break;
-
- /* Seek from the current file offset.
- */
- case RED_SEEK_CUR:
- REDASSERT(pHandle->ullOffset <= (uint64_t)INT64_MAX);
- llFrom = (int64_t)pHandle->ullOffset;
- break;
-
- /* Seek from the end of the file.
- */
- case RED_SEEK_END:
- {
- REDSTAT s;
-
- ret = RedCoreStat(pHandle->ulInode, &s);
- if(ret == 0)
- {
- REDASSERT(s.st_size <= (uint64_t)INT64_MAX);
- llFrom = (int64_t)s.st_size;
- }
-
- break;
- }
-
- default:
- ret = -RED_EINVAL;
- break;
- }
- }
-
- if(ret == 0)
- {
- REDASSERT(llFrom >= 0);
-
- /* Avoid signed integer overflow from llFrom + llOffset with large
- values of llOffset and nonzero llFrom values. Underflow isn't
- possible since llFrom is nonnegative.
- */
- if((llOffset > 0) && (((uint64_t)llFrom + (uint64_t)llOffset) > (uint64_t)INT64_MAX))
- {
- ret = -RED_EINVAL;
- }
- else
- {
- int64_t llNewOffset = llFrom + llOffset;
-
- if((llNewOffset < 0) || ((uint64_t)llNewOffset > gpRedVolume->ullMaxInodeSize))
- {
- /* Invalid file offset.
- */
- ret = -RED_EINVAL;
- }
- else
- {
- pHandle->ullOffset = (uint64_t)llNewOffset;
- llReturn = llNewOffset;
- }
- }
- }
-
- PosixLeave();
- }
-
- if(ret != 0)
- {
- llReturn = PosixReturn(ret);
- }
-
- return llReturn;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_FTRUNCATE == 1)
-/** @brief Truncate a file to a specified length.
-
- Allows the file size to be increased, decreased, or to remain the same. If
- the file size is increased, the new area is sparse (will read as zeroes).
- If the file size is decreased, the data beyond the new end-of-file will
- return to free space once it is no longer part of the committed state
- (either immediately or after the next transaction point).
-
- The value of the file offset is not modified by this function.
-
- Unlike POSIX ftruncate, this function can fail when the disk is full if
- @p ullSize is non-zero. If decreasing the file size, this can be fixed by
- transacting and trying again: Reliance Edge guarantees that it is possible
- to perform a truncate of at least one file that decreases the file size
- after a transaction point. If disk full transactions are enabled, this will
- happen automatically.
-
- @param iFildes The file descriptor of the file to truncate.
- @param ullSize The new size of the file.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not a valid file descriptor open
- for writing. This includes the case where the file descriptor is for a
- directory.
- - #RED_EFBIG: @p ullSize exceeds the maximum file size.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENOSPC: Insufficient free space to perform the truncate.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_ftruncate(
- int32_t iFildes,
- uint64_t ullSize)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- REDHANDLE *pHandle;
-
- ret = FildesToHandle(iFildes, FTYPE_FILE, &pHandle);
- if(ret == -RED_EISDIR)
- {
- /* Similar to red_write() (see comment there), the RED_EBADF error
- for a non-writable file descriptor takes precedence.
- */
- ret = -RED_EBADF;
- }
-
- if((ret == 0) && ((pHandle->bFlags & HFLAG_WRITEABLE) == 0U))
- {
- ret = -RED_EBADF;
- }
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreFileTruncate(pHandle->ulInode, ullSize);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif
-
-
-/** @brief Get the status of a file or directory.
-
- See the ::REDSTAT type for the details of the information returned.
-
- @param iFildes An open file descriptor for the file whose information is
- to be retrieved.
- @param pStat Pointer to a ::REDSTAT buffer to populate.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBADF: The @p iFildes argument is not a valid file descriptor.
- - #RED_EINVAL: @p pStat is `NULL`.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_fstat(
- int32_t iFildes,
- REDSTAT *pStat)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- REDHANDLE *pHandle;
-
- ret = FildesToHandle(iFildes, FTYPE_EITHER, &pHandle);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- ret = RedCoreStat(pHandle->ulInode, pStat);
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-
-
-#if REDCONF_API_POSIX_READDIR == 1
-/** @brief Open a directory stream for reading.
-
- @param pszPath The path of the directory to open.
-
- @return On success, returns a pointer to a ::REDDIR object that can be used
- with red_readdir() and red_closedir(). On error, returns `NULL`
- and #red_errno is set appropriately.
-
- Errno values
- - #RED_EINVAL: @p pszPath is `NULL`; or the volume containing the path is
- not mounted.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_ENOENT: A component of @p pszPath does not exist; or the @p pszPath
- argument, after removing the volume prefix, points to an empty string.
- - #RED_ENOTDIR: A component of @p pszPath is a not a directory.
- - #RED_EMFILE: There are no available file descriptors.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-REDDIR *red_opendir(
- const char *pszPath)
-{
- int32_t iFildes;
- REDSTATUS ret;
- REDDIR *pDir = NULL;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- ret = FildesOpen(pszPath, RED_O_RDONLY, FTYPE_DIR, &iFildes);
- if(ret == 0)
- {
- uint16_t uHandleIdx;
-
- FildesUnpack(iFildes, &uHandleIdx, NULL, NULL);
- pDir = &gaHandle[uHandleIdx];
- }
-
- PosixLeave();
- }
-
- REDASSERT((pDir == NULL) == (ret != 0));
-
- if(pDir == NULL)
- {
- red_errno = -ret;
- }
-
- return pDir;
-}
-
-
-/** @brief Read from a directory stream.
-
- The ::REDDIRENT pointer returned by this function will be overwritten by
- subsequent calls on the same @p pDir. Calls with other ::REDDIR objects
- will *not* modify the returned ::REDDIRENT.
-
- If files are added to the directory after it is opened, the new files may
- or may not be returned by this function. If files are deleted, the deleted
- files will not be returned.
-
- This function (like its POSIX equivalent) returns `NULL` in two cases: on
- error and when the end of the directory is reached. To distinguish between
- these two cases, the application should set #red_errno to zero before
- calling this function, and if `NULL` is returned, check if #red_errno is
- still zero. If it is, the end of the directory was reached; otherwise,
- there was an error.
-
- @param pDirStream The directory stream to read from.
-
- @return On success, returns a pointer to a ::REDDIRENT object which is
- populated with directory entry information read from the directory.
- On error, returns `NULL` and #red_errno is set appropriately. If at
- the end of the directory, returns `NULL` but #red_errno is not
- modified.
-
- Errno values
- - #RED_EBADF: @p pDirStream is not an open directory stream.
- - #RED_EIO: A disk I/O error occurred.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-REDDIRENT *red_readdir(
- REDDIR *pDirStream)
-{
- REDSTATUS ret;
- REDDIRENT *pDirEnt = NULL;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- if(!DirStreamIsValid(pDirStream))
- {
- ret = -RED_EBADF;
- }
- #if REDCONF_VOLUME_COUNT > 1U
- else
- {
- ret = RedCoreVolSetCurrent(pDirStream->bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- uint32_t ulDirPosition;
-
- /* To save memory, the directory position is stored in the same
- location as the file offset. This would be a bit cleaner using
- a union, but MISRA-C:2012 Rule 19.2 disallows unions.
- */
- REDASSERT(pDirStream->ullOffset <= UINT32_MAX);
- ulDirPosition = (uint32_t)pDirStream->ullOffset;
-
- ret = RedCoreDirRead(pDirStream->ulInode, &ulDirPosition, pDirStream->dirent.d_name, &pDirStream->dirent.d_ino);
-
- pDirStream->ullOffset = ulDirPosition;
-
- if(ret == 0)
- {
- /* POSIX extension: return stat information with the dirent.
- */
- ret = RedCoreStat(pDirStream->dirent.d_ino, &pDirStream->dirent.d_stat);
- if(ret == 0)
- {
- pDirEnt = &pDirStream->dirent;
- }
- }
- else if(ret == -RED_ENOENT)
- {
- /* Reached the end of the directory; return NULL but do not set
- errno.
- */
- ret = 0;
- }
- else
- {
- /* Miscellaneous error; return NULL and set errno (done below).
- */
- }
- }
-
- PosixLeave();
- }
-
- if(ret != 0)
- {
- REDASSERT(pDirEnt == NULL);
-
- red_errno = -ret;
- }
-
- return pDirEnt;
-}
-
-
-/** @brief Rewind a directory stream to read it from the beginning.
-
- Similar to closing the directory object and opening it again, but without
- the need for the path.
-
- Since this function (like its POSIX equivalent) cannot return an error,
- it takes no action in error conditions, such as when @p pDirStream is
- invalid.
-
- @param pDirStream The directory stream to rewind.
-*/
-void red_rewinddir(
- REDDIR *pDirStream)
-{
- if(PosixEnter() == 0)
- {
- if(DirStreamIsValid(pDirStream))
- {
- pDirStream->ullOffset = 0U;
- }
-
- PosixLeave();
- }
-}
-
-
-/** @brief Close a directory stream.
-
- After calling this function, @p pDirStream should no longer be used.
-
- @param pDirStream The directory stream to close.
-
- @return On success, zero is returned. On error, -1 is returned and
- #red_errno is set appropriately.
-
- Errno values
- - #RED_EBADF: @p pDirStream is not an open directory stream.
- - #RED_EUSERS: Cannot become a file system user: too many users.
-*/
-int32_t red_closedir(
- REDDIR *pDirStream)
-{
- REDSTATUS ret;
-
- ret = PosixEnter();
- if(ret == 0)
- {
- if(DirStreamIsValid(pDirStream))
- {
- /* Mark this handle as unused.
- */
- pDirStream->ulInode = INODE_INVALID;
- }
- else
- {
- ret = -RED_EBADF;
- }
-
- PosixLeave();
- }
-
- return PosixReturn(ret);
-}
-#endif /* REDCONF_API_POSIX_READDIR */
-
-
-/** @brief Pointer to where the last file system error (errno) is stored.
-
- This function is intended to be used via the #red_errno macro, or a similar
- user-defined macro, that can be used both as an lvalue (writable) and an
- rvalue (readable).
-
- Under normal circumstances, the errno for each task is stored in a
- different location. Applications do not need to worry about one task
- obliterating an error value that another task needed to read. This task
- errno for is initially zero. When one of the POSIX-like APIs returns an
- indication of error, the location for the calling task will be populated
- with the error value.
-
- In some circumstances, this function will return a pointer to a global
- errno location which is shared by multiple tasks. If the calling task is
- not registered as a file system user and all of the task slots are full,
- there can be no task-specific errno, so the global pointer is returned.
- Likewise, if the file system driver is uninitialized, there are no
- registered file system users and this function always returns the pointer
- to the global errno. Under these circumstances, multiple tasks
- manipulating errno could be problematic.
-
- This function never returns `NULL` under any circumstances. The #red_errno
- macro unconditionally dereferences the return value from this function, so
- returning `NULL` could result in a fault.
-
- @return Pointer to where the errno value is stored for this task.
-*/
-REDSTATUS *red_errnoptr(void)
-{
- /* The global errno value, used in single-task configurations and when the
- caller is not (and cannot become) a file system user (which includes
- when the driver is uninitialized).
- */
- static REDSTATUS iGlobalErrno = 0;
-
- #if REDCONF_TASK_COUNT == 1U
-
- return &iGlobalErrno;
-
- #else
-
- REDSTATUS *piErrno;
-
- if(gfPosixInited)
- {
- uint32_t ulTaskId = RedOsTaskId();
- uint32_t ulIdx;
-
- REDASSERT(ulTaskId != 0U);
-
- /* If this task has used the file system before, it will already have
- a task slot, which includes the task-specific errno.
- */
- RedOsMutexAcquire();
-
- for(ulIdx = 0U; ulIdx < REDCONF_TASK_COUNT; ulIdx++)
- {
- if(gaTask[ulIdx].ulTaskId == ulTaskId)
- {
- break;
- }
- }
-
- RedOsMutexRelease();
-
- if(ulIdx == REDCONF_TASK_COUNT)
- {
- REDSTATUS ret;
-
- /* This task is not a file system user, so try to register it as
- one. This FS mutex must be held in order to register.
- */
- RedOsMutexAcquire();
-
- ret = TaskRegister(&ulIdx);
-
- RedOsMutexRelease();
-
- if(ret == 0)
- {
- REDASSERT(gaTask[ulIdx].ulTaskId == RedOsTaskId());
- REDASSERT(gaTask[ulIdx].iErrno == 0);
-
- piErrno = &gaTask[ulIdx].iErrno;
- }
- else
- {
- /* Unable to register; use the global errno.
- */
- piErrno = &iGlobalErrno;
- }
- }
- else
- {
- piErrno = &gaTask[ulIdx].iErrno;
- }
- }
- else
- {
- /* There are no registered file system tasks when the driver is
- uninitialized, so use the global errno.
- */
- piErrno = &iGlobalErrno;
- }
-
- /* This function is not allowed to return NULL.
- */
- REDASSERT(piErrno != NULL);
- return piErrno;
-
- #endif
-}
-/** @} */
-
-/*-------------------------------------------------------------------
- Helper Functions
--------------------------------------------------------------------*/
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1))
-
-/** @brief Remove a link to a file or directory.
-
- If the link count becomes zero, the file or directory is deleted.
-
- @param pszPath Path of the link to remove.
- @param type The expected type of the path: file, directory, or either.
- An error is returned if the expected type is file or
- directory and does not match the path.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval -RED_EBUSY @p pszPath points to an inode with open handles
- and a link count of one.
- @retval -RED_EINVAL @p pszPath is `NULL`; or the volume containing
- the path is not mounted.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_EISDIR @p type is ::FTYPE_FILE and the path names a
- directory.
- @retval -RED_ENAMETOOLONG @p pszName is too long.
- @retval -RED_ENOENT The path does not name an existing file; or
- @p pszPath, after removing the volume prefix,
- points to an empty string.
- @retval -RED_ENOTDIR @p type is ::FTYPE_DIR and the path does not
- name a directory.
- @retval -RED_ENOTEMPTY @p pszPath is a directory which is not empty.
- @retval -RED_ENOSPC The file system does not have enough space to
- modify the parent directory to perform the
- deletion.
-*/
-static REDSTATUS UnlinkSub(
- const char *pszPath,
- FTYPE type)
-{
- uint8_t bVolNum;
- const char *pszLocalPath;
- REDSTATUS ret;
-
- ret = RedPathSplit(pszPath, &bVolNum, &pszLocalPath);
-
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(bVolNum);
- }
- #endif
-
- if(ret == 0)
- {
- const char *pszName;
- uint32_t ulPInode;
-
- ret = RedPathToName(pszLocalPath, &ulPInode, &pszName);
-
- if(ret == 0)
- {
- uint32_t ulInode;
-
- ret = RedCoreLookup(ulPInode, pszName, &ulInode);
-
- /* ModeTypeCheck() always passes when the type is FTYPE_EITHER, so
- skip stat'ing the inode in that case.
- */
- if((ret == 0) && (type != FTYPE_EITHER))
- {
- REDSTAT InodeStat;
-
- ret = RedCoreStat(ulInode, &InodeStat);
- if(ret == 0)
- {
- ret = ModeTypeCheck(InodeStat.st_mode, type);
- }
- }
-
- if(ret == 0)
- {
- ret = InodeUnlinkCheck(ulInode);
- }
-
- if(ret == 0)
- {
- ret = RedCoreUnlink(ulPInode, pszName);
- }
- }
- }
-
- return ret;
-}
-#endif /* (REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1) */
-
-
-/** @brief Get a file descriptor for a path.
-
- @param pszPath Path to a file to open.
- @param ulOpenMode The RED_O_* flags the descriptor is opened with.
- @param type Indicates the expected descriptor type: file, directory,
- or either.
- @param piFildes On successful return, populated with the file
- descriptor.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL @p piFildes is `NULL`; or @p pszPath is `NULL`;
- or the volume is not mounted.
- @retval -RED_EMFILE There are no available handles.
- @retval -RED_EEXIST Using #RED_O_CREAT and #RED_O_EXCL, and the
- indicated path already exists.
- @retval -RED_EISDIR The path names a directory and @p ulOpenMode
- includes #RED_O_WRONLY or #RED_O_RDWR.
- @retval -RED_ENOENT #RED_O_CREAT is not set and the named file does
- not exist; or #RED_O_CREAT is set and the parent
- directory does not exist; or the volume does not
- exist; or the @p pszPath argument, after
- removing the volume prefix, points to an empty
- string.
- @retval -RED_EIO A disk I/O error occurred.
- @retval -RED_ENAMETOOLONG The length of a component of @p pszPath is
- longer than #REDCONF_NAME_MAX.
- @retval -RED_ENFILE Attempting to create a file but the file system
- has used all available inode slots.
- @retval -RED_ENOSPC The file does not exist and #RED_O_CREAT was
- specified, but there is insufficient free space
- to expand the directory or to create the new
- file.
- @retval -RED_ENOTDIR A component of the prefix in @p pszPath does not
- name a directory.
- @retval -RED_EROFS The path resides on a read-only file system and
- a write operation was requested.
-*/
-static REDSTATUS FildesOpen(
- const char *pszPath,
- uint32_t ulOpenMode,
- FTYPE type,
- int32_t *piFildes)
-{
- uint8_t bVolNum;
- const char *pszLocalPath;
- REDSTATUS ret;
-
- ret = RedPathSplit(pszPath, &bVolNum, &pszLocalPath);
-
- if(ret == 0)
- {
- if(piFildes == NULL)
- {
- ret = -RED_EINVAL;
- }
- #if REDCONF_READ_ONLY == 0
- else if(gaRedVolume[bVolNum].fReadOnly && (ulOpenMode != RED_O_RDONLY))
- {
- ret = -RED_EROFS;
- }
- #endif
- else
- {
- uint16_t uHandleIdx;
- REDHANDLE *pHandle = NULL;
-
- /* Search for an unused handle.
- */
- for(uHandleIdx = 0U; uHandleIdx < REDCONF_HANDLE_COUNT; uHandleIdx++)
- {
- if(gaHandle[uHandleIdx].ulInode == INODE_INVALID)
- {
- pHandle = &gaHandle[uHandleIdx];
- break;
- }
- }
-
- /* Error if all the handles are in use.
- */
- if(pHandle == NULL)
- {
- ret = -RED_EMFILE;
- }
- else
- {
- bool fCreated = false;
- uint16_t uMode = 0U;
- uint32_t ulInode = 0U; /* Init'd to quiet warnings. */
-
- #if REDCONF_VOLUME_COUNT > 1U
- ret = RedCoreVolSetCurrent(bVolNum);
- if(ret == 0)
- #endif
- {
- #if REDCONF_READ_ONLY == 0
- if((ulOpenMode & RED_O_CREAT) != 0U)
- {
- uint32_t ulPInode;
- const char *pszName;
-
- ret = RedPathToName(pszLocalPath, &ulPInode, &pszName);
- if(ret == 0)
- {
- ret = RedCoreCreate(ulPInode, pszName, false, &ulInode);
- if(ret == 0)
- {
- fCreated = true;
- }
- else if((ret == -RED_EEXIST) && ((ulOpenMode & RED_O_EXCL) == 0U))
- {
- /* If the path already exists and that's OK,
- lookup its inode number.
- */
- ret = RedCoreLookup(ulPInode, pszName, &ulInode);
- }
- else
- {
- /* No action, just propagate the error.
- */
- }
- }
- }
- else
- #endif
- {
- ret = RedPathLookup(pszLocalPath, &ulInode);
- }
- }
-
- /* If we created the inode, none of the below stuff is
- necessary. This is important from an error handling
- perspective -- we do not need code to delete the created
- inode on error.
- */
- if(!fCreated)
- {
- if(ret == 0)
- {
- REDSTAT s;
-
- ret = RedCoreStat(ulInode, &s);
- if(ret == 0)
- {
- uMode = s.st_mode;
- }
- }
-
- /* Error if the inode is not of the expected type.
- */
- if(ret == 0)
- {
- ret = ModeTypeCheck(uMode, type);
- }
-
- /* Directories must always be opened with O_RDONLY.
- */
- if((ret == 0) && RED_S_ISDIR(uMode) && ((ulOpenMode & RED_O_RDONLY) == 0U))
- {
- ret = -RED_EISDIR;
- }
-
- #if (REDCONF_READ_ONLY == 0) && (REDCONF_API_POSIX_FTRUNCATE == 1)
- if((ret == 0) && ((ulOpenMode & RED_O_TRUNC) != 0U))
- {
- ret = RedCoreFileTruncate(ulInode, UINT64_SUFFIX(0));
- }
- #endif
- }
-
- if(ret == 0)
- {
- int32_t iFildes;
-
- RedMemSet(pHandle, 0U, sizeof(*pHandle));
-
- /* Populate this handle, marking it as in use.
- */
- pHandle->ulInode = ulInode;
- pHandle->bVolNum = bVolNum;
-
- if(RED_S_ISDIR(uMode))
- {
- pHandle->bFlags |= HFLAG_DIRECTORY;
- }
-
- if(((ulOpenMode & RED_O_RDONLY) != 0U) || ((ulOpenMode & RED_O_RDWR) != 0U))
- {
- pHandle->bFlags |= HFLAG_READABLE;
- }
-
- #if REDCONF_READ_ONLY == 0
- if(((ulOpenMode & RED_O_WRONLY) != 0U) || ((ulOpenMode & RED_O_RDWR) != 0U))
- {
- pHandle->bFlags |= HFLAG_WRITEABLE;
- }
-
- if((ulOpenMode & RED_O_APPEND) != 0U)
- {
- pHandle->bFlags |= HFLAG_APPENDING;
- }
- #endif
-
- iFildes = FildesPack(uHandleIdx, bVolNum);
- if(iFildes == -1)
- {
- /* It should be impossible to get here, unless there
- is memory corruption.
- */
- REDERROR();
- ret = -RED_EFUBAR;
- }
- else
- {
- *piFildes = iFildes;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
-
-/** @brief Close a file descriptor.
-
- @param iFildes The file descriptor to close.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p iFildes is not a valid file descriptor.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS FildesClose(
- int32_t iFildes)
-{
- REDHANDLE *pHandle;
- REDSTATUS ret;
-
- ret = FildesToHandle(iFildes, FTYPE_EITHER, &pHandle);
-
- #if REDCONF_READ_ONLY == 0
- #if REDCONF_VOLUME_COUNT > 1U
- if(ret == 0)
- {
- ret = RedCoreVolSetCurrent(pHandle->bVolNum);
- }
- #endif
-
- /* No core event for close, so this transaction flag needs to be
- implemented here.
- */
- if(ret == 0)
- {
- uint32_t ulTransMask;
-
- ret = RedCoreTransMaskGet(&ulTransMask);
-
- if((ret == 0) && ((ulTransMask & RED_TRANSACT_CLOSE) != 0U))
- {
- ret = RedCoreVolTransact();
- }
- }
- #endif
-
- if(ret == 0)
- {
- /* Mark this handle as unused.
- */
- pHandle->ulInode = INODE_INVALID;
- }
-
- return ret;
-}
-
-
-/** @brief Convert a file descriptor into a handle pointer.
-
- Also validates the file descriptor.
-
- @param iFildes The file descriptor for which to get a handle.
- @param expectedType The expected type of the file descriptor: ::FTYPE_DIR,
- ::FTYPE_FILE, or ::FTYPE_EITHER.
- @param ppHandle On successful return, populated with a pointer to the
- handle associated with @p iFildes.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p iFildes is not a valid file descriptor.
- @retval -RED_EINVAL @p ppHandle is `NULL`.
- @retval -RED_EISDIR Expected a file, but the file descriptor is for a
- directory.
- @retval -RED_ENOTDIR Expected a directory, but the file descriptor is for
- a file.
-*/
-static REDSTATUS FildesToHandle(
- int32_t iFildes,
- FTYPE expectedType,
- REDHANDLE **ppHandle)
-{
- REDSTATUS ret;
-
- if(ppHandle == NULL)
- {
- REDERROR();
- ret = -RED_EINVAL;
- }
- else if(iFildes < FD_MIN)
- {
- ret = -RED_EBADF;
- }
- else
- {
- uint16_t uHandleIdx;
- uint8_t bVolNum;
- uint16_t uGeneration;
-
- FildesUnpack(iFildes, &uHandleIdx, &bVolNum, &uGeneration);
-
- if( (uHandleIdx >= REDCONF_HANDLE_COUNT)
- || (bVolNum >= REDCONF_VOLUME_COUNT)
- || (gaHandle[uHandleIdx].ulInode == INODE_INVALID)
- || (gaHandle[uHandleIdx].bVolNum != bVolNum)
- || (gauGeneration[bVolNum] != uGeneration))
- {
- ret = -RED_EBADF;
- }
- else if((expectedType == FTYPE_FILE) && ((gaHandle[uHandleIdx].bFlags & HFLAG_DIRECTORY) != 0U))
- {
- ret = -RED_EISDIR;
- }
- else if((expectedType == FTYPE_DIR) && ((gaHandle[uHandleIdx].bFlags & HFLAG_DIRECTORY) == 0U))
- {
- ret = -RED_ENOTDIR;
- }
- else
- {
- *ppHandle = &gaHandle[uHandleIdx];
- ret = 0;
- }
- }
-
- return ret;
-}
-
-
-/** @brief Pack a file descriptor.
-
- @param uHandleIdx The index of the file handle that will be associated
- with this file descriptor.
- @param bVolNum The volume which contains the file or directory this
- file descriptor was opened against.
-
- @return The packed file descriptor.
-*/
-static int32_t FildesPack(
- uint16_t uHandleIdx,
- uint8_t bVolNum)
-{
- int32_t iFildes;
-
- if((uHandleIdx >= REDCONF_HANDLE_COUNT) || (bVolNum >= REDCONF_VOLUME_COUNT))
- {
- REDERROR();
- iFildes = -1;
- }
- else
- {
- uint32_t ulFdBits;
-
- REDASSERT(gauGeneration[bVolNum] <= FD_GEN_MAX);
- REDASSERT(gauGeneration[bVolNum] != 0U);
-
- ulFdBits = gauGeneration[bVolNum];
- ulFdBits <<= FD_VOL_BITS;
- ulFdBits |= bVolNum;
- ulFdBits <<= FD_IDX_BITS;
- ulFdBits |= uHandleIdx;
-
- iFildes = (int32_t)ulFdBits;
-
- if(iFildes < FD_MIN)
- {
- REDERROR();
- iFildes = -1;
- }
- }
-
- return iFildes;
-}
-
-
-/** @brief Unpack a file descriptor.
-
- @param iFildes The file descriptor to unpack.
- @param puHandleIdx If non-NULL, populated with the handle index extracted
- from the file descriptor.
- @param pbVolNum If non-NULL, populated with the volume number extracted
- from the file descriptor.
- @param puGeneration If non-NULL, populated with the generation number
- extracted from the file descriptor.
-*/
-static void FildesUnpack(
- int32_t iFildes,
- uint16_t *puHandleIdx,
- uint8_t *pbVolNum,
- uint16_t *puGeneration)
-{
- uint32_t ulFdBits = (uint32_t)iFildes;
-
- REDASSERT(iFildes >= FD_MIN);
-
- if(puHandleIdx != NULL)
- {
- *puHandleIdx = (uint16_t)(ulFdBits & FD_IDX_MAX);
- }
-
- ulFdBits >>= FD_IDX_BITS;
-
- if(pbVolNum != NULL)
- {
- *pbVolNum = (uint8_t)(ulFdBits & FD_VOL_MAX);
- }
-
- ulFdBits >>= FD_VOL_BITS;
-
- if(puGeneration != NULL)
- {
- *puGeneration = (uint16_t)(ulFdBits & FD_GEN_MAX);
- }
-}
-
-
-#if REDCONF_API_POSIX_READDIR == 1
-/** @brief Validate a directory stream object.
-
- @param pDirStream The directory stream to validate.
-
- @return Whether the directory stream is valid.
-
- @retval true The directory stream object appears valid.
- @retval false The directory stream object is invalid.
-*/
-static bool DirStreamIsValid(
- const REDDIR *pDirStream)
-{
- bool fRet = true;
-
- if(pDirStream == NULL)
- {
- fRet = false;
- }
- else
- {
- uint16_t uHandleIdx;
-
- /* pDirStream should be a pointer to one of the handles.
-
- A good compiler will optimize this loop into a bounds check and an
- alignment check.
- */
- for(uHandleIdx = 0U; uHandleIdx < REDCONF_HANDLE_COUNT; uHandleIdx++)
- {
- if(pDirStream == &gaHandle[uHandleIdx])
- {
- break;
- }
- }
-
- if(uHandleIdx < REDCONF_HANDLE_COUNT)
- {
- /* The handle must be in use, have a valid volume number, and be a
- directory handle.
- */
- if( (pDirStream->ulInode == INODE_INVALID)
- || (pDirStream->bVolNum >= REDCONF_VOLUME_COUNT)
- || ((pDirStream->bFlags & HFLAG_DIRECTORY) == 0U))
- {
- fRet = false;
- }
- }
- else
- {
- /* pDirStream is a non-null pointer, but it is not a pointer to one
- of our handles.
- */
- fRet = false;
- }
- }
-
- return fRet;
-}
-#endif
-
-
-/** @brief Enter the file system driver.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EINVAL The file system driver is uninitialized.
- @retval -RED_EUSERS Cannot become a file system user: too many users.
-*/
-static REDSTATUS PosixEnter(void)
-{
- REDSTATUS ret;
-
- if(gfPosixInited)
- {
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexAcquire();
-
- ret = TaskRegister(NULL);
- if(ret != 0)
- {
- RedOsMutexRelease();
- }
- #else
- ret = 0;
- #endif
- }
- else
- {
- ret = -RED_EINVAL;
- }
-
- return ret;
-}
-
-
-/** @brief Leave the file system driver.
-*/
-static void PosixLeave(void)
-{
- /* If the driver was uninitialized, PosixEnter() should have failed and we
- should not be calling PosixLeave().
- */
- REDASSERT(gfPosixInited);
-
- #if REDCONF_TASK_COUNT > 1U
- RedOsMutexRelease();
- #endif
-}
-
-
-/** @brief Check that a mode is consistent with the given expected type.
-
- @param uMode An inode mode, indicating whether the inode is a file
- or a directory.
- @param expectedType The expected type: ::FTYPE_FILE, ::FTYPE_DIR, or
- ::FTYPE_EITHER.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EISDIR Expected type is file, actual type is directory.
- @retval -RED_ENOTDIR Expected type is directory, actual type is file.
-*/
-static REDSTATUS ModeTypeCheck(
- uint16_t uMode,
- FTYPE expectedType)
-{
- REDSTATUS ret;
-
- if((expectedType == FTYPE_FILE) && RED_S_ISDIR(uMode))
- {
- /* Expected file, found directory.
- */
- ret = -RED_EISDIR;
- }
- else if((expectedType == FTYPE_DIR) && RED_S_ISREG(uMode))
- {
- /* Expected directory, found file.
- */
- ret = -RED_ENOTDIR;
- }
- else
- {
- /* No expected type or found what we expected.
- */
- ret = 0;
- }
-
- return ret;
-}
-
-
-#if (REDCONF_READ_ONLY == 0) && ((REDCONF_API_POSIX_UNLINK == 1) || (REDCONF_API_POSIX_RMDIR == 1) || ((REDCONF_API_POSIX_RENAME == 1) && (REDCONF_RENAME_ATOMIC == 1)))
-/** @brief Check whether an inode can be unlinked.
-
- If an inode has a link count of 1 (meaning unlinking another name would
- result in the deletion of the inode) and open handles, it cannot be deleted
- since this would break open handles.
-
- @param ulInode The inode whose name is to be unlinked.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EBADF @p ulInode is not a valid inode.
- @retval -RED_EBUSY The inode has a link count of one and open handles.
- @retval -RED_EIO A disk I/O error occurred.
-*/
-static REDSTATUS InodeUnlinkCheck(
- uint32_t ulInode)
-{
- uint16_t uHandleIdx;
- REDSTATUS ret;
-
- #if REDCONF_API_POSIX_LINK == 0
- ret = 0;
- #else
- REDSTAT InodeStat;
-
- ret = RedCoreStat(ulInode, &InodeStat);
-
- /* We only need to check for open handles if the inode is down to its last
- link. If it has multiple links, the inode will continue to exist, so
- deleting the name will not break the open handles.
- */
- if((ret == 0) && (InodeStat.st_nlink == 1U))
- #endif
- {
- for(uHandleIdx = 0U; uHandleIdx < REDCONF_HANDLE_COUNT; uHandleIdx++)
- {
- if((gaHandle[uHandleIdx].ulInode == ulInode) && (gaHandle[uHandleIdx].bVolNum == gbRedVolNum))
- {
- ret = -RED_EBUSY;
- break;
- }
- }
- }
-
- return ret;
-}
-#endif
-
-
-#if REDCONF_TASK_COUNT > 1U
-/** @brief Register a task as a file system user, if it is not already
- registered as one.
-
- The caller must hold the FS mutex.
-
- @param pulTaskIdx On successful return, if non-NULL, populated with the
- index of the task slot assigned to the calling task.
- This is populated whether or not the task had already
- been registered.
-
- @return A negated ::REDSTATUS code indicating the operation result.
-
- @retval 0 Operation was successful.
- @retval -RED_EUSERS Cannot become a file system user: too many users.
-*/
-static REDSTATUS TaskRegister(
- uint32_t *pulTaskIdx)
-{
- uint32_t ulTaskId = RedOsTaskId();
- uint32_t ulFirstFreeIdx = REDCONF_TASK_COUNT;
- uint32_t ulIdx;
- REDSTATUS ret;
-
- REDASSERT(ulTaskId != 0U);
-
- /* Scan the task slots to determine if the task is registered as a file
- system task.
- */
- for(ulIdx = 0U; ulIdx < REDCONF_TASK_COUNT; ulIdx++)
- {
- if(gaTask[ulIdx].ulTaskId == ulTaskId)
- {
- break;
- }
-
- if((ulFirstFreeIdx == REDCONF_TASK_COUNT) && (gaTask[ulIdx].ulTaskId == 0U))
- {
- ulFirstFreeIdx = ulIdx;
- }
- }
-
- if(ulIdx == REDCONF_TASK_COUNT)
- {
- /* Task not already registered.
- */
- if(ulFirstFreeIdx == REDCONF_TASK_COUNT)
- {
- /* Cannot register task, no more slots.
- */
- ret = -RED_EUSERS;
- }
- else
- {
- /* Registering task.
- */
- ulIdx = ulFirstFreeIdx;
- gaTask[ulIdx].ulTaskId = ulTaskId;
- ret = 0;
- }
- }
- else
- {
- /* Task already registered.
- */
- ret = 0;
- }
-
- if((ret == 0) && (pulTaskIdx != NULL))
- {
- *pulTaskIdx = ulIdx;
- }
-
- return ret;
-}
-#endif /* REDCONF_TASK_COUNT > 1U */
-
-
-/** @brief Convert an error value into a simple 0 or -1 return.
-
- This function is simple, but what it does is needed in many places. It
- returns zero if @p iError is zero (meaning success) or it returns -1 if
- @p iError is nonzero (meaning error). Also, if @p iError is nonzero, it
- is saved in red_errno.
-
- @param iError The error value.
-
- @return Returns 0 if @p iError is 0; otherwise, returns -1.
-*/
-static int32_t PosixReturn(
- REDSTATUS iError)
-{
- int32_t iReturn;
-
- if(iError == 0)
- {
- iReturn = 0;
- }
- else
- {
- iReturn = -1;
-
- /* The errors should be negative, and errno positive.
- */
- REDASSERT(iError < 0);
- red_errno = -iError;
- }
-
- return iReturn;
-}
-
-
-#endif /* REDCONF_API_POSIX == 1 */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/fsstress.c b/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/fsstress.c
deleted file mode 100755
index abc2aa9..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/fsstress.c
+++ /dev/null
@@ -1,2050 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like. Any license provided herein, whether implied or
- * otherwise, applies only to this software file. Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
- */
-/** @file
- @brief File system stress test.
-
- This version of SGI fsstress has been modified to be single-threaded and to
- work with the Reliance Edge POSIX-like API.
-*/
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#if FSSTRESS_SUPPORTED
-
-#include "redposixcompat.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#if REDCONF_CHECKER == 1
-#include
-#endif
-
-
-/* Create POSIX types. Use #define to avoid name conflicts in those
- environments where the type names already exist.
-*/
-#define off_t int64_t
-#define off64_t off_t
-#define ino_t uint32_t
-#define mode_t uint16_t
-#define __int64_t int64_t
-
-
-/** @brief Generate a random number.
-
- @return A nonnegative random number.
-*/
-#define random() ((int)(RedRand32(NULL) & 0x7FFFFFFF))
-
-
-/** @brief Seed the random number generator.
-*/
-#define srandom(seed) RedRandSeed(seed)
-
-
-#define _exit(status) exit(status)
-#define getpagesize() 4096U
-#define getpid() 1
-
-
-/** @brief Determine the maximum file size.
-
- This is used for the MAXFSSIZE macro.
-*/
-static uint64_t MaxFileSize(void)
-{
- REDSTATFS info;
- int32_t iStatus;
- REDSTATUS errnoSave = errno;
- uint64_t ullMaxFileSize;
-
- iStatus = red_statvfs("", &info);
- if(iStatus == 0)
- {
- ullMaxFileSize = info.f_maxfsize;
- }
- else
- {
- /* This function does not change errno.
- */
- errno = errnoSave;
-
- ullMaxFileSize = 0x7FFFFFFFU;
- }
-
- return ullMaxFileSize;
-}
-
-
-/*-------------------------------------------------------------------
- Simulated current working directory support
--------------------------------------------------------------------*/
-
-
-/* Forward declaration for red_chdir().
-*/
-static int red_stat(const char *pszPath, REDSTAT *pStat);
-
-/* The simulated CWD functions.
-*/
-#undef chdir
-#undef getcwd
-#define chdir(path) red_chdir(path)
-#define getcwd(buf, size) red_getcwd(buf, size)
-
-
-/* Redefine the path-based APIs to call MakeFullPath() on their arguments
- since there is no CWD support in the red_*() APIs.
-*/
-#undef open
-#undef unlink
-#undef mkdir
-#undef rmdir
-#undef rename
-#undef link
-#undef opendir
-#define open(path, oflag) red_open(MakeFullPath(path), oflag)
-#define unlink(path) red_unlink(MakeFullPath(path))
-#define mkdir(path) red_mkdir(MakeFullPath(path))
-#define rmdir(path) red_rmdir(MakeFullPath(path))
-#define rename(old, new) red_rename(MakeFullPath(old), MakeFullPath(new))
-#define link(path, hardlink) red_link(MakeFullPath(path), MakeFullPath(hardlink))
-#define opendir(path) red_opendir(MakeFullPath(path))
-
-#define FSSTRESS_BUF_SIZE 1024U
-
-/* Stores the simulated current working directory.
-*/
-static char szLocalCwd[FSSTRESS_BUF_SIZE] = "/";
-
-
-/** @brief Change the current working directory.
-
- This function only supports a subset of what is possible with POSIX chdir().
-
- @param pszPath The new current working directory.
-
- @return Upon successful completion, 0 shall be returned. Otherwise, -1
- shall be returned, and errno shall be set to indicate the error.
-*/
-static int red_chdir(
- const char *pszPath)
-{
- uint32_t ulIdx;
- int iErrno = 0;
-
- if(strcmp(pszPath, "..") == 0)
- {
- uint32_t ulLastSlashIdx = 0U;
-
- /* Chop off the last path separator and everything after it, so that
- "/foo/bar/baz" becomes "/foo/bar", moving the CWD up one directory.
- */
- for(ulIdx = 0U; szLocalCwd[ulIdx] != '\0'; ulIdx++)
- {
- if(szLocalCwd[ulIdx] == '/')
- {
- ulLastSlashIdx = ulIdx;
- }
- }
-
- if(ulLastSlashIdx != 0U)
- {
- szLocalCwd[ulLastSlashIdx] = '\0';
- }
- }
- else
- {
- char szOldCwd[FSSTRESS_BUF_SIZE];
-
- /* chdir() must have no effect on the CWD if it fails, so save the CWD
- so we can revert it if necessary.
- */
- strcpy(szOldCwd, szLocalCwd);
-
- if(pszPath[0U] == '/')
- {
- if(strlen(pszPath) >= sizeof(szLocalCwd))
- {
- iErrno = RED_ENAMETOOLONG;
- }
- else
- {
- strcpy(szLocalCwd, pszPath);
- }
- }
- else
- {
- ulIdx = strlen(szLocalCwd);
-
- if((ulIdx + 1U + strlen(pszPath)) >= sizeof(szLocalCwd))
- {
- iErrno = RED_ENAMETOOLONG;
- }
- else
- {
- if(szLocalCwd[1U] != '\0')
- {
- szLocalCwd[ulIdx] = '/';
- ulIdx++;
- }
-
- strcpy(&szLocalCwd[ulIdx], pszPath);
- }
- }
-
- if(iErrno == 0)
- {
- REDSTAT s;
- int iStatus;
-
- iStatus = red_stat(szLocalCwd, &s);
- if(iStatus != 0)
- {
- iErrno = errno;
- }
- else if(!S_ISDIR(s.st_mode))
- {
- iErrno = RED_ENOTDIR;
- }
- else
- {
- /* No error, new CWD checks out.
- */
- }
- }
-
- if(iErrno != 0)
- {
- strcpy(szLocalCwd, szOldCwd);
- }
- }
-
- if(iErrno != 0)
- {
- errno = iErrno;
- }
-
- return iErrno == 0 ? 0 : -1;
-}
-
-
-/** @brief Retrieve the current working directory.
-
- @param pszBuf On successful return, populated with the current working
- directory. If NULL, memory will be allocated for the CWD
- and returned by this function.
- @param nSize The size of @p pszBuf.
-
- @return On success, if @p pszBuf was non-NULL, returns @p pszBuf; if
- @p pszBuf was NULL, returns an allocated buffer populated with the
- CWD which must be freed by the caller. On failure, returns NULL
- and errno will be set.
-*/
-static char *red_getcwd(
- char *pszBuf,
- size_t nSize)
-{
- char *pszRet;
-
- if(pszBuf == NULL)
- {
- pszRet = malloc(strlen(szLocalCwd) + 1U);
- if(pszRet == NULL)
- {
- errno = RED_ENOMEM;
- }
- else
- {
- strcpy(pszRet, szLocalCwd);
- }
- }
- else if(nSize < strlen(szLocalCwd) + 1U)
- {
- errno = RED_ERANGE;
- pszRet = NULL;
- }
- else
- {
- strcpy(pszBuf, szLocalCwd);
- pszRet = pszBuf;
- }
-
- return pszRet;
-}
-
-
-/** @brief Make a relative path into a fully qualified path.
-
- @param pszName The relative path.
-
- @return On success, a pointer to a fully qualified path. On error, NULL.
-*/
-static const char *MakeFullPath(
- const char *pszName)
-{
- #define MAXVOLNAME 64U /* Enough for most configs. */
- static char aszFullPath[2U][MAXVOLNAME + 1U + FSSTRESS_BUF_SIZE];
- static uint32_t ulWhich = 0U;
-
- char *pszFullPath = aszFullPath[ulWhich];
- const char *pszVolume = gpRedVolConf->pszPathPrefix;
- int32_t iLen;
-
- if(pszName[0U] == '/')
- {
- iLen = RedSNPrintf(pszFullPath, sizeof(aszFullPath[0U]), "%s%s", pszVolume, pszName);
- }
- else if(strcmp(pszName, ".") == 0U)
- {
- iLen = RedSNPrintf(pszFullPath, sizeof(aszFullPath[0U]), "%s%s", pszVolume, szLocalCwd);
- }
- else if((szLocalCwd[0U] == '/') && (szLocalCwd[1U] == '\0'))
- {
- iLen = RedSNPrintf(pszFullPath, sizeof(aszFullPath[0U]), "%s/%s", pszVolume, pszName);
- }
- else
- {
- iLen = RedSNPrintf(pszFullPath, sizeof(aszFullPath[0U]), "%s%s/%s", pszVolume, szLocalCwd, pszName);
- }
-
- if(iLen == -1)
- {
- /* Insufficient path buffer space.
- */
- pszFullPath = NULL;
- }
- else
- {
- /* Toggle between two full path arrays; a kluge to make rename() and
- link() work correctly.
- */
- ulWhich ^= 1U;
- }
-
- return pszFullPath;
-}
-
-
-/*-------------------------------------------------------------------
- POSIX functions not implemented by the RED POSIX-like API
--------------------------------------------------------------------*/
-
-#define stat(p, s) red_stat(p, s)
-#define stat64(p, s) stat(p, s)
-#define lstat(p, s) stat(p, s)
-#define lstat64(p, s) stat(p, s)
-#define truncate(p, s) red_truncate(p, s)
-#define truncate64(p, s) truncate(p, s)
-
-
-/** @brief Get the status of a file or directory.
-*/
-static int red_stat(
- const char *pszPath,
- REDSTAT *pStat)
-{
- int iFd;
- int iRet;
-
- iFd = open(pszPath, O_RDONLY);
- iRet = iFd;
- if(iFd != -1)
- {
- iRet = fstat(iFd, pStat);
-
- (void)close(iFd);
- }
-
- return iRet;
-}
-
-
-/** @brief Truncate a file to a specified length.
-*/
-static int red_truncate(
- const char *pszPath,
- off_t llSize)
-{
- int iFd;
- int iRet;
-
- iFd = open(pszPath, O_WRONLY);
- iRet = iFd;
- if(iFd != -1)
- {
- iRet = ftruncate(iFd, llSize);
-
- (void)close(iFd);
- }
-
- return iRet;
-}
-
-
-/*-------------------------------------------------------------------
- Begin ported fsstress code
--------------------------------------------------------------------*/
-
-/* Stuff from xfscompat.h */
-
-#define MAXNAMELEN (REDCONF_NAME_MAX+1U) /* Assumed to include NUL */
-
-struct dioattr {
- int d_miniosz, d_maxiosz, d_mem;
-};
-
-#define MIN(a,b) ((a)<(b) ? (a):(b))
-#define MAX(a,b) ((a)>(b) ? (a):(b))
-
-/* End xfscompat.h */
-
-
-typedef enum {
- OP_CREAT,
- OP_FDATASYNC,
- OP_FSYNC,
- OP_GETDENTS,
- OP_LINK,
- OP_MKDIR,
- OP_READ,
- OP_RENAME,
- OP_RMDIR,
- OP_STAT,
- OP_TRUNCATE,
- OP_UNLINK,
- OP_WRITE,
- #if REDCONF_CHECKER == 1
- OP_CHECK,
- #endif
- OP_LAST
-} opty_t;
-
-typedef void (*opfnc_t) (int, long);
-
-typedef struct opdesc {
- opty_t op;
- const char *name;
- opfnc_t func;
- int freq;
- int iswrite;
-} opdesc_t;
-
-typedef struct fent {
- int id;
- int parent;
-} fent_t;
-
-typedef struct flist {
- int nfiles;
- int nslots;
- int tag;
- fent_t *fents;
-} flist_t;
-
-typedef struct pathname {
- int len;
- char *path;
-} pathname_t;
-
-#define FT_DIR 0
-#define FT_DIRm (1 << FT_DIR)
-#define FT_REG 1
-#define FT_REGm (1 << FT_REG)
-#define FT_SYM 2
-#define FT_SYMm (1 << FT_SYM)
-#define FT_DEV 3
-#define FT_DEVm (1 << FT_DEV)
-#define FT_RTF 4
-#define FT_RTFm (1 << FT_RTF)
-#define FT_nft 5
-#define FT_ANYm ((1 << FT_nft) - 1)
-#define FT_REGFILE (FT_REGm | FT_RTFm)
-#define FT_NOTDIR (FT_ANYm & ~FT_DIRm)
-
-#define FLIST_SLOT_INCR 16
-#define NDCACHE 64
-
-#define MAXFSIZE MaxFileSize()
-
-static void creat_f(int opno, long r);
-static void fdatasync_f(int opno, long r);
-static void fsync_f(int opno, long r);
-static void getdents_f(int opno, long r);
-static void link_f(int opno, long r);
-static void mkdir_f(int opno, long r);
-static void read_f(int opno, long r);
-static void rename_f(int opno, long r);
-static void rmdir_f(int opno, long r);
-static void stat_f(int opno, long r);
-static void truncate_f(int opno, long r);
-static void unlink_f(int opno, long r);
-static void write_f(int opno, long r);
-#if REDCONF_CHECKER == 1
-static void check_f(int opno, long r);
-#endif
-
-static opdesc_t ops[] = {
- {OP_CREAT, "creat", creat_f, 4, 1},
- {OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1},
- {OP_FSYNC, "fsync", fsync_f, 1, 1},
- {OP_GETDENTS, "getdents", getdents_f, 1, 0},
- {OP_LINK, "link", link_f, 1, 1},
- {OP_MKDIR, "mkdir", mkdir_f, 2, 1},
- {OP_READ, "read", read_f, 1, 0},
- {OP_RENAME, "rename", rename_f, 2, 1},
- {OP_RMDIR, "rmdir", rmdir_f, 1, 1},
- {OP_STAT, "stat", stat_f, 1, 0},
- {OP_TRUNCATE, "truncate", truncate_f, 2, 1},
- {OP_UNLINK, "unlink", unlink_f, 1, 1},
- {OP_WRITE, "write", write_f, 4, 1},
- #if REDCONF_CHECKER == 1
- {OP_CHECK, "check", check_f, 1, 1},
- #endif
-}, *ops_end;
-
-static flist_t flist[FT_nft] = {
- {0, 0, 'd', NULL},
- {0, 0, 'f', NULL},
- {0, 0, 'l', NULL},
- {0, 0, 'c', NULL},
- {0, 0, 'r', NULL},
-};
-
-static int dcache[NDCACHE];
-static opty_t *freq_table;
-static int freq_table_size;
-static char *homedir;
-static int *ilist;
-static int ilistlen;
-static off64_t maxfsize;
-static int namerand;
-static int nameseq;
-static int nops;
-static int operations = 1;
-static int procid;
-static int rtpct;
-static unsigned long seed = 0;
-static ino_t top_ino;
-static int verbose = 0;
-
-static int delete_tree(const char *path);
-static void add_to_flist(int fd, int it, int parent);
-static void append_pathname(pathname_t *name, const char *str);
-static void check_cwd(void);
-static int creat_path(pathname_t *name, mode_t mode);
-static void dcache_enter(int dirid, int slot);
-static void dcache_init(void);
-static fent_t *dcache_lookup(int dirid);
-static void dcache_purge(int dirid);
-static void del_from_flist(int ft, int slot);
-static void doproc(void);
-static void fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep);
-static void fix_parent(int oldid, int newid);
-static void free_pathname(pathname_t *name);
-static int generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v);
-static int get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp, int *v);
-static void init_pathname(pathname_t *name);
-static int link_path(pathname_t *name1, pathname_t *name2);
-static int lstat64_path(pathname_t *name, REDSTAT *sbuf);
-static void make_freq_table(void);
-static int mkdir_path(pathname_t *name, mode_t mode);
-static void namerandpad(int id, char *buf, int len);
-static int open_path(pathname_t *name, int oflag);
-static DIR *opendir_path(pathname_t *name);
-static int rename_path(pathname_t *name1, pathname_t *name2);
-static int rmdir_path(pathname_t *name);
-static void separate_pathname(pathname_t *name, char *buf, pathname_t *newname);
-static int stat64_path(pathname_t *name, REDSTAT *sbuf);
-static int truncate64_path(pathname_t *name, off64_t length);
-static int unlink_path(pathname_t *name);
-static void usage(const char *progname);
-
-
-/** @brief Parse parameters for fsstress.
-
- @param argc The number of arguments from main().
- @param argv The vector of arguments from main().
- @param pParam Populated with the fsstress parameters.
- @param pbVolNum If non-NULL, populated with the volume number.
- @param ppszDevice If non-NULL, populated with the device name argument or
- NULL if no device argument is provided.
-
- @return The result of parsing the parameters.
-*/
-PARAMSTATUS FsstressParseParams(
- int argc,
- char *argv[],
- FSSTRESSPARAM *pParam,
- uint8_t *pbVolNum,
- const char **ppszDevice)
-{
- int c;
- uint8_t bVolNum;
- const REDOPTION aLongopts[] =
- {
- { "no-cleanup", red_no_argument, NULL, 'c' },
- { "loops", red_required_argument, NULL, 'l' },
- { "nops", red_required_argument, NULL, 'n' },
- { "namepad", red_no_argument, NULL, 'r' },
- { "seed", red_required_argument, NULL, 's' },
- { "verbose", red_no_argument, NULL, 'v' },
- { "dev", red_required_argument, NULL, 'D' },
- { "help", red_no_argument, NULL, 'H' },
- { NULL }
- };
-
- /* If run without parameters, treat as a help request.
- */
- if(argc <= 1)
- {
- goto Help;
- }
-
- /* Assume no device argument to start with.
- */
- if(ppszDevice != NULL)
- {
- *ppszDevice = NULL;
- }
-
- /* Set default parameters.
- */
- FsstressDefaultParams(pParam);
-
- while((c = RedGetoptLong(argc, argv, "cl:n:rs:vD:H", aLongopts, NULL)) != -1)
- {
- switch(c)
- {
- case 'c': /* --no-cleanup */
- pParam->fNoCleanup = true;
- break;
- case 'l': /* --loops */
- pParam->ulLoops = RedAtoI(red_optarg);
- break;
- case 'n': /* --nops */
- pParam->ulNops = RedAtoI(red_optarg);
- break;
- case 'r': /* --namepad */
- pParam->fNamePad = true;
- break;
- case 's': /* --seed */
- pParam->ulSeed = RedAtoI(red_optarg);
- break;
- case 'v': /* --verbose */
- pParam->fVerbose = true;
- break;
- case 'D': /* --dev */
- if(ppszDevice != NULL)
- {
- *ppszDevice = red_optarg;
- }
- break;
- case 'H': /* --help */
- goto Help;
- case '?': /* Unknown or ambiguous option */
- case ':': /* Option missing required argument */
- default:
- goto BadOpt;
- }
- }
-
- /* RedGetoptLong() has permuted argv to move all non-option arguments to
- the end. We expect to find a volume identifier.
- */
- if(red_optind >= argc)
- {
- RedPrintf("Missing volume argument\n");
- goto BadOpt;
- }
-
- bVolNum = RedFindVolumeNumber(argv[red_optind]);
- if(bVolNum == REDCONF_VOLUME_COUNT)
- {
- RedPrintf("Error: \"%s\" is not a valid volume identifier.\n", argv[red_optind]);
- goto BadOpt;
- }
-
- if(pbVolNum != NULL)
- {
- *pbVolNum = bVolNum;
- }
-
- red_optind++; /* Move past volume parameter. */
- if(red_optind < argc)
- {
- int32_t ii;
-
- for(ii = red_optind; ii < argc; ii++)
- {
- RedPrintf("Error: Unexpected command-line argument \"%s\".\n", argv[ii]);
- }
-
- goto BadOpt;
- }
-
- return PARAMSTATUS_OK;
-
- BadOpt:
-
- RedPrintf("%s - invalid parameters\n", argv[0U]);
- usage(argv[0U]);
- return PARAMSTATUS_BAD;
-
- Help:
-
- usage(argv[0U]);
- return PARAMSTATUS_HELP;
-}
-
-
-/** @brief Set default fsstress parameters.
-
- @param pParam Populated with the default fsstress parameters.
-*/
-void FsstressDefaultParams(
- FSSTRESSPARAM *pParam)
-{
- RedMemSet(pParam, 0U, sizeof(*pParam));
- pParam->ulLoops = 1U;
- pParam->ulNops = 10000U;
-}
-
-
-/** @brief Start fsstress.
-
- @param pParam fsstress parameters, either from FsstressParseParams() or
- constructed programatically.
-
- @return Zero on success, otherwise nonzero.
-*/
-int FsstressStart(
- const FSSTRESSPARAM *pParam)
-{
- char buf[10];
- int fd;
- int i;
- int cleanup;
- int loops;
- int loopcntr = 1;
-
- nops = sizeof(ops) / sizeof(ops[0]);
- ops_end = &ops[nops];
-
- /* Copy the already-parsed parameters into the traditional variables.
- */
- cleanup = pParam->fNoCleanup ? 1 : 0;
- loops = pParam->ulLoops;
- operations = pParam->ulNops;
- namerand = pParam->fNamePad ? 1 : 0;
- seed = pParam->ulSeed;
- verbose = pParam->fVerbose ? 1 : 0;
-
- make_freq_table();
-
- while ((loopcntr <= loops) || (loops == 0)) {
- RedSNPrintf(buf, sizeof(buf), "fss%x", getpid());
- fd = creat(buf, 0666);
- maxfsize = (off64_t) MAXFSIZE;
- dcache_init();
- if (!seed) {
- seed = (unsigned long)RedOsClockGetTime();
- RedPrintf("seed = %ld\n", seed);
- }
- close(fd);
- unlink(buf);
- procid = 0;
- doproc();
- if (cleanup == 0) {
- delete_tree("/");
- for (i = 0; i < FT_nft; i++) {
- flist[i].nslots = 0;
- flist[i].nfiles = 0;
- free(flist[i].fents);
- flist[i].fents = NULL;
- }
- }
- loopcntr++;
- }
- return 0;
-}
-
-static int delete_tree(const char *path)
-{
- REDSTAT sb;
- DIR *dp;
- REDDIRENT *dep;
- char *childpath;
- size_t len;
- int e;
-
- e = stat(path, &sb);
- if (e)
- return errno;
-
- if (!S_ISDIR(sb.st_mode))
- return unlink(path) ? errno : 0;
-
- dp = opendir(path);
- if (dp == NULL)
- return errno;
-
- while((dep = readdir(dp)) != NULL) {
- len = strlen(path) + 1 + strlen(dep->d_name) + 1;
- childpath = malloc(len);
-
- strcpy(childpath, path);
- if (childpath[strlen(childpath) - 1] != '/')
- strcat(childpath, "/");
- strcat(childpath, dep->d_name);
-
- e = delete_tree(childpath);
-
- free(childpath);
-
- if (e)
- break;
- }
-
- if (e == 0 && strcmp(path, "/") != 0) {
- e = rmdir(path) ? errno : 0;
- }
- closedir(dp);
- return e;
-}
-
-static void add_to_flist(int ft, int id, int parent)
-{
- fent_t *fep;
- flist_t *ftp;
-
- ftp = &flist[ft];
- if (ftp->nfiles == ftp->nslots) {
- ftp->nslots += FLIST_SLOT_INCR;
- ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
- }
- fep = &ftp->fents[ftp->nfiles++];
- fep->id = id;
- fep->parent = parent;
-}
-
-static void append_pathname(pathname_t *name, const char *str)
-{
- int len;
-
- len = strlen(str);
-#ifdef DEBUG
- if (len && *str == '/' && name->len == 0) {
- RedPrintf("fsstress: append_pathname failure\n");
- chdir(homedir);
- abort();
-
- }
-#endif
- name->path = realloc(name->path, name->len + 1 + len);
- strcpy(&name->path[name->len], str);
- name->len += len;
-}
-
-static void check_cwd(void)
-{
-#ifdef DEBUG
- REDSTAT statbuf;
-
- if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
- return;
- chdir(homedir);
- RedPrintf("fsstress: check_cwd failure\n");
- abort();
-
-#endif
-}
-
-static int creat_path(pathname_t *name, mode_t mode)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = creat(name->path, mode);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = creat_path(&newname, mode);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static void dcache_enter(int dirid, int slot)
-{
- dcache[dirid % NDCACHE] = slot;
-}
-
-static void dcache_init(void)
-{
- int i;
-
- for (i = 0; i < NDCACHE; i++)
- dcache[i] = -1;
-}
-
-static fent_t *dcache_lookup(int dirid)
-{
- fent_t *fep;
- int i;
-
- i = dcache[dirid % NDCACHE];
- if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
- return fep;
- return NULL;
-}
-
-static void dcache_purge(int dirid)
-{
- int *dcp;
-
- dcp = &dcache[dirid % NDCACHE];
- if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
- *dcp = -1;
-}
-
-static void del_from_flist(int ft, int slot)
-{
- flist_t *ftp;
-
- ftp = &flist[ft];
- if (ft == FT_DIR)
- dcache_purge(ftp->fents[slot].id);
- if (slot != ftp->nfiles - 1) {
- if (ft == FT_DIR)
- dcache_purge(ftp->fents[ftp->nfiles - 1].id);
- ftp->fents[slot] = ftp->fents[--ftp->nfiles];
- } else
- ftp->nfiles--;
-}
-
-static fent_t *dirid_to_fent(int dirid)
-{
- fent_t *efep;
- fent_t *fep;
- flist_t *flp;
-
- if ((fep = dcache_lookup(dirid)))
- return fep;
- flp = &flist[FT_DIR];
- for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
- if (fep->id == dirid) {
- dcache_enter(dirid, (int)(fep - flp->fents));
- return fep;
- }
- }
- return NULL;
-}
-
-static void doproc(void)
-{
- REDSTAT statbuf;
- char buf[10];
- int opno;
- opdesc_t *p;
-
- RedSNPrintf(buf, sizeof(buf), "p%x", procid);
- (void)mkdir(buf);
- if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
- perror(buf);
- _exit(1);
- }
- top_ino = statbuf.st_ino;
- homedir = getcwd(NULL, 0);
- seed += procid;
- srandom(seed);
- if (namerand)
- namerand = random();
- for (opno = 0; opno < operations; opno++) {
- p = &ops[freq_table[random() % freq_table_size]];
- if ((unsigned long)p->func < 4096)
- abort();
-
- p->func(opno, random());
- }
- free(homedir);
-}
-
-static void fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
-{
- char buf[MAXNAMELEN];
- int i;
- fent_t *pfep;
-
- if (fep == NULL)
- return;
- if (fep->parent != -1) {
- pfep = dirid_to_fent(fep->parent);
- fent_to_name(name, &flist[FT_DIR], pfep);
- append_pathname(name, "/");
- }
- i = RedSNPrintf(buf, sizeof(buf), "%c%x", flp->tag, fep->id);
- namerandpad(fep->id, buf, i);
- append_pathname(name, buf);
-}
-
-static void fix_parent(int oldid, int newid)
-{
- fent_t *fep;
- flist_t *flp;
- int i;
- int j;
-
- for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
- for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
- if (fep->parent == oldid)
- fep->parent = newid;
- }
- }
-}
-
-static void free_pathname(pathname_t *name)
-{
- if (name->path) {
- free(name->path);
- name->path = NULL;
- name->len = 0;
- }
-}
-
-static int generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
-{
- char buf[MAXNAMELEN];
- flist_t *flp;
- int id;
- int j;
- int len;
-
- flp = &flist[ft];
- len = RedSNPrintf(buf, sizeof(buf), "%c%x", flp->tag, id = nameseq++);
- namerandpad(id, buf, len);
- if (fep) {
- fent_to_name(name, &flist[FT_DIR], fep);
- append_pathname(name, "/");
- }
- append_pathname(name, buf);
- *idp = id;
- *v = verbose;
- for (j = 0; !*v && j < ilistlen; j++) {
- if (ilist[j] == id) {
- *v = 1;
- break;
- }
- }
- return 1;
-}
-
-static int
-get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp, int *v)
-{
- int c;
- fent_t *fep;
- flist_t *flp;
- int i;
- int j;
- int x;
-
- for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
- if (which & (1 << i))
- c += flp->nfiles;
- }
- if (c == 0) {
- if (flpp)
- *flpp = NULL;
- if (fepp)
- *fepp = NULL;
- *v = verbose;
- return 0;
- }
- x = (int)(r % c);
- for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
- if (which & (1 << i)) {
- if (x < c + flp->nfiles) {
- fep = &flp->fents[x - c];
- if (name)
- fent_to_name(name, flp, fep);
- if (flpp)
- *flpp = flp;
- if (fepp)
- *fepp = fep;
- *v = verbose;
- for (j = 0; !*v && j < ilistlen; j++) {
- if (ilist[j] == fep->id) {
- *v = 1;
- break;
- }
- }
- return 1;
- }
- c += flp->nfiles;
- }
- }
-#ifdef DEBUG
- RedPrintf("fsstress: get_fname failure\n");
- abort();
-#endif
- return -1;
-
-}
-
-static void init_pathname(pathname_t *name)
-{
- name->len = 0;
- name->path = NULL;
-}
-
-static int link_path(pathname_t *name1, pathname_t *name2)
-{
- char buf1[MAXNAMELEN];
- char buf2[MAXNAMELEN];
- int down1;
- pathname_t newname1;
- pathname_t newname2;
- int rval;
-
- rval = link(name1->path, name2->path);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name1, buf1, &newname1);
- separate_pathname(name2, buf2, &newname2);
- if (strcmp(buf1, buf2) == 0) {
- if (chdir(buf1) == 0) {
- rval = link_path(&newname1, &newname2);
- chdir("..");
- }
- } else {
- if (strcmp(buf1, "..") == 0)
- down1 = 0;
- else if (strcmp(buf2, "..") == 0)
- down1 = 1;
- else if (strlen(buf1) == 0)
- down1 = 0;
- else if (strlen(buf2) == 0)
- down1 = 1;
- else
- down1 = MAX(newname1.len, 3 + name2->len) <=
- MAX(3 + name1->len, newname2.len);
- if (down1) {
- free_pathname(&newname2);
- append_pathname(&newname2, "../");
- append_pathname(&newname2, name2->path);
- if (chdir(buf1) == 0) {
- rval = link_path(&newname1, &newname2);
- chdir("..");
- }
- } else {
- free_pathname(&newname1);
- append_pathname(&newname1, "../");
- append_pathname(&newname1, name1->path);
- if (chdir(buf2) == 0) {
- rval = link_path(&newname1, &newname2);
- chdir("..");
- }
- }
- }
- free_pathname(&newname1);
- free_pathname(&newname2);
- return rval;
-}
-
-static int lstat64_path(pathname_t *name, REDSTAT *sbuf)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = lstat64(name->path, sbuf);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = lstat64_path(&newname, sbuf);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static void make_freq_table(void)
-{
- int f;
- int i;
- opdesc_t *p;
-
- for (p = ops, f = 0; p < ops_end; p++)
- f += p->freq;
- freq_table = malloc(f * sizeof(*freq_table));
- freq_table_size = f;
- for (p = ops, i = 0; p < ops_end; p++) {
- for (f = 0; f < p->freq; f++, i++)
- freq_table[i] = p->op;
- }
-}
-
-static int mkdir_path(pathname_t *name, mode_t mode)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = mkdir(name->path);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = mkdir_path(&newname, mode);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static void namerandpad(int id, char *buf, int len)
-{
- int bucket;
- static int buckets[8] = {0};
- static int bucket_count = 0;
- int bucket_value;
- int i;
- int padlen;
- int padmod;
-
- if (namerand == 0)
- return;
-
- /* buckets[] used to be a statically initialized array with the following
- initializer: { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 }
-
- The problem is that with Reliance Edge, the maximum name length might be
- less than 128. So the below code populates buckets[] in a similar
- fashion but avoids name lengths longer than the maximum. For example,
- if the max name is 20, the resulting array is { 2, 4, 8, 16, 20 }.
- */
- if (!bucket_count) {
- bucket_count = sizeof(buckets) / sizeof(buckets[0]);
- bucket_value = 2;
- for (i = 0; i < bucket_count; i++) {
- if (bucket_value > 128 || bucket_value >= (int)MAXNAMELEN - 1)
- break;
- buckets[i] = bucket_value;
- bucket_value *= 2;
- }
- if (i < bucket_count) {
- buckets[i] = MAXNAMELEN - 1;
- i++;
- }
- bucket_count = i;
- }
-
- bucket = (id ^ namerand) % bucket_count;
- padmod = buckets[bucket] + 1 - len;
- if (padmod <= 0)
- return;
- padlen = (id ^ namerand) % padmod;
- if (padlen) {
- memset(&buf[len], 'X', padlen);
- buf[len + padlen] = '\0';
- }
-}
-
-static int open_path(pathname_t *name, int oflag)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = open(name->path, oflag);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = open_path(&newname, oflag);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static DIR *opendir_path(pathname_t *name)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- DIR *rval;
-
- rval = opendir(name->path);
- if (rval || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = opendir_path(&newname);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static int rename_path(pathname_t *name1, pathname_t *name2)
-{
- char buf1[MAXNAMELEN];
- char buf2[MAXNAMELEN];
- int down1;
- pathname_t newname1;
- pathname_t newname2;
- int rval;
-
- rval = rename(name1->path, name2->path);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name1, buf1, &newname1);
- separate_pathname(name2, buf2, &newname2);
- if (strcmp(buf1, buf2) == 0) {
- if (chdir(buf1) == 0) {
- rval = rename_path(&newname1, &newname2);
- chdir("..");
- }
- } else {
- if (strcmp(buf1, "..") == 0)
- down1 = 0;
- else if (strcmp(buf2, "..") == 0)
- down1 = 1;
- else if (strlen(buf1) == 0)
- down1 = 0;
- else if (strlen(buf2) == 0)
- down1 = 1;
- else
- down1 = MAX(newname1.len, 3 + name2->len) <=
- MAX(3 + name1->len, newname2.len);
- if (down1) {
- free_pathname(&newname2);
- append_pathname(&newname2, "../");
- append_pathname(&newname2, name2->path);
- if (chdir(buf1) == 0) {
- rval = rename_path(&newname1, &newname2);
- chdir("..");
- }
- } else {
- free_pathname(&newname1);
- append_pathname(&newname1, "../");
- append_pathname(&newname1, name1->path);
- if (chdir(buf2) == 0) {
- rval = rename_path(&newname1, &newname2);
- chdir("..");
- }
- }
- }
- free_pathname(&newname1);
- free_pathname(&newname2);
- return rval;
-}
-
-static int rmdir_path(pathname_t *name)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = rmdir(name->path);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = rmdir_path(&newname);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static void separate_pathname(pathname_t *name, char *buf, pathname_t *newname)
-{
- char *slash;
-
- init_pathname(newname);
- slash = strchr(name->path, '/');
- if (slash == NULL) {
- buf[0] = '\0';
- return;
- }
- *slash = '\0';
- strcpy(buf, name->path);
- *slash = '/';
- append_pathname(newname, slash + 1);
-}
-
-static int stat64_path(pathname_t *name, REDSTAT *sbuf)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = stat64(name->path, sbuf);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = stat64_path(&newname, sbuf);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static int truncate64_path(pathname_t *name, off64_t length)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = truncate64(name->path, length);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = truncate64_path(&newname, length);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static int unlink_path(pathname_t *name)
-{
- char buf[MAXNAMELEN];
- pathname_t newname;
- int rval;
-
- rval = unlink(name->path);
- if (rval >= 0 || errno != RED_ENAMETOOLONG)
- return rval;
- separate_pathname(name, buf, &newname);
- if (chdir(buf) == 0) {
- rval = unlink_path(&newname);
- chdir("..");
- }
- free_pathname(&newname);
- return rval;
-}
-
-static void usage(const char *progname)
-{
- RedPrintf("usage: %s VolumeID [Options]\n", progname);
- RedPrintf("File system stress test.\n\n");
- RedPrintf("Where:\n");
- RedPrintf(" VolumeID\n");
- RedPrintf(" A volume number (e.g., 2) or a volume path prefix (e.g., VOL1: or /data)\n");
- RedPrintf(" of the volume to test.\n");
- RedPrintf("And 'Options' are any of the following:\n");
- RedPrintf(" --no-cleanup, -c\n");
- RedPrintf(" Specifies not to remove files (cleanup) after execution\n");
- RedPrintf(" --loops=count, -l count\n");
- RedPrintf(" Specifies the number of times the entire test should loop. Use 0 for\n");
- RedPrintf(" infinite. Default 1.\n");
- RedPrintf(" --nops=count, -n count\n");
- RedPrintf(" Specifies the number of operations to run (default 10000).\n");
- RedPrintf(" --namepad, -r\n");
- RedPrintf(" Specifies to use random name padding (resulting in longer names).\n");
- RedPrintf(" --seed=value, -s value\n");
- RedPrintf(" Specifies the seed for the random number generator (default timestamp).\n");
- RedPrintf(" --verbose, -v\n");
- RedPrintf(" Specifies verbose mode (without this, test is very quiet).\n");
- RedPrintf(" --dev=devname, -D devname\n");
- RedPrintf(" Specifies the device name. This is typically only meaningful when\n");
- RedPrintf(" running the test on a host machine. This can be \"ram\" to test on a RAM\n");
- RedPrintf(" disk, the path and name of a file disk (e.g., red.bin); or an OS-specific\n");
- RedPrintf(" reference to a device (on Windows, a drive letter like G: or a device name\n");
- RedPrintf(" like \\\\.\\PhysicalDrive7).\n");
- RedPrintf(" --help, -H\n");
- RedPrintf(" Prints this usage text and exits.\n\n");
- RedPrintf("Warning: This test will format the volume -- destroying all existing data.\n\n");
-}
-
-static void creat_f(int opno, long r)
-{
- int e;
- int e1;
- pathname_t f;
- int fd;
- fent_t *fep;
- int id;
- int parid;
- int type;
- int v;
- int v1;
- int esz = 0;
-
- if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
- parid = -1;
- else
- parid = fep->id;
- init_pathname(&f);
- type = rtpct ? ((int)(random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
- e = generate_fname(fep, type, &f, &id, &v);
- v |= v1;
- if (!e) {
- if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
- RedPrintf("%d/%d: creat - no filename from %s\n",
- procid, opno, f.path);
- }
- free_pathname(&f);
- return;
- }
- fd = creat_path(&f, 0666);
- e = fd < 0 ? errno : 0;
- e1 = 0;
- check_cwd();
- esz = 0;
- if (fd >= 0) {
- add_to_flist(type, id, parid);
- close(fd);
- }
- if (v)
- RedPrintf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
- esz, e, e1);
- free_pathname(&f);
-}
-
-static void fdatasync_f(int opno, long r)
-{
- int e;
- pathname_t f;
- int fd;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: fdatasync - no filename\n",
- procid, opno);
- free_pathname(&f);
- return;
- }
- fd = open_path(&f, O_WRONLY);
- e = fd < 0 ? errno : 0;
- check_cwd();
- if (fd < 0) {
- if (v)
- RedPrintf("%d/%d: fdatasync - open %s failed %d\n",
- procid, opno, f.path, e);
- free_pathname(&f);
- return;
- }
- e = fdatasync(fd) < 0 ? errno : 0;
- if (v)
- RedPrintf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
- close(fd);
-}
-
-static void fsync_f(int opno, long r)
-{
- int e;
- pathname_t f;
- int fd;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: fsync - no filename\n", procid, opno);
- free_pathname(&f);
- return;
- }
- fd = open_path(&f, O_WRONLY);
- e = fd < 0 ? errno : 0;
- check_cwd();
- if (fd < 0) {
- if (v)
- RedPrintf("%d/%d: fsync - open %s failed %d\n",
- procid, opno, f.path, e);
- free_pathname(&f);
- return;
- }
- e = fsync(fd) < 0 ? errno : 0;
- if (v)
- RedPrintf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
- close(fd);
-}
-
-static void getdents_f(int opno, long r)
-{
- DIR *dir;
- pathname_t f;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
- append_pathname(&f, ".");
- dir = opendir_path(&f);
- check_cwd();
- if (dir == NULL) {
- if (v)
- RedPrintf("%d/%d: getdents - can't open %s\n",
- procid, opno, f.path);
- free_pathname(&f);
- return;
- }
- while (readdir64(dir) != NULL)
- continue;
- if (v)
- RedPrintf("%d/%d: getdents %s 0\n", procid, opno, f.path);
- free_pathname(&f);
- closedir(dir);
-}
-
-static void link_f(int opno, long r)
-{
- int e;
- pathname_t f;
- fent_t *fep;
- flist_t *flp;
- int id;
- pathname_t l;
- int parid;
- int v;
- int v1;
-
- init_pathname(&f);
- if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
- if (v1)
- RedPrintf("%d/%d: link - no file\n", procid, opno);
- free_pathname(&f);
- return;
- }
- if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
- parid = -1;
- else
- parid = fep->id;
- v |= v1;
- init_pathname(&l);
- e = generate_fname(fep, (int)(flp - flist), &l, &id, &v1);
- v |= v1;
- if (!e) {
- if (v) {
- fent_to_name(&l, &flist[FT_DIR], fep);
- RedPrintf("%d/%d: link - no filename from %s\n",
- procid, opno, l.path);
- }
- free_pathname(&l);
- free_pathname(&f);
- return;
- }
- e = link_path(&f, &l) < 0 ? errno : 0;
- check_cwd();
- if (e == 0)
- add_to_flist((int)(flp - flist), id, parid);
- if (v)
- RedPrintf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
- e);
- free_pathname(&l);
- free_pathname(&f);
-}
-
-static void mkdir_f(int opno, long r)
-{
- int e;
- pathname_t f;
- fent_t *fep;
- int id;
- int parid;
- int v;
- int v1;
-
- if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
- parid = -1;
- else
- parid = fep->id;
- init_pathname(&f);
- e = generate_fname(fep, FT_DIR, &f, &id, &v1);
- v |= v1;
- if (!e) {
- if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
- RedPrintf("%d/%d: mkdir - no filename from %s\n",
- procid, opno, f.path);
- }
- free_pathname(&f);
- return;
- }
- e = mkdir_path(&f, 0777) < 0 ? errno : 0;
- check_cwd();
- if (e == 0)
- add_to_flist(FT_DIR, id, parid);
- if (v)
- RedPrintf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
-}
-
-static void read_f(int opno, long r)
-{
- char *buf;
- int e;
- pathname_t f;
- int fd;
- uint32_t len;
- __int64_t lr;
- off64_t off;
- REDSTAT stb;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: read - no filename\n", procid, opno);
- free_pathname(&f);
- return;
- }
- fd = open_path(&f, O_RDONLY);
- e = fd < 0 ? errno : 0;
- check_cwd();
- if (fd < 0) {
- if (v)
- RedPrintf("%d/%d: read - open %s failed %d\n",
- procid, opno, f.path, e);
- free_pathname(&f);
- return;
- }
- if (fstat64(fd, &stb) < 0) {
- if (v)
- RedPrintf("%d/%d: read - fstat64 %s failed %d\n",
- procid, opno, f.path, errno);
- free_pathname(&f);
- close(fd);
- return;
- }
- if (stb.st_size == 0) {
- if (v)
- RedPrintf("%d/%d: read - %s zero size\n", procid, opno,
- f.path);
- free_pathname(&f);
- close(fd);
- return;
- }
- lr = ((__int64_t) random() << 32) + random();
- off = (off64_t) (lr % stb.st_size);
- lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 4)) + 1;
- buf = malloc(len);
- e = read(fd, buf, len) < 0 ? errno : 0;
- free(buf);
- if (v)
- RedPrintf("%d/%d: read %s [%lld,%ld] %d\n",
- procid, opno, f.path, (long long)off, (long int)len, e);
- free_pathname(&f);
- close(fd);
-}
-
-static void rename_f(int opno, long r)
-{
- fent_t *dfep;
- int e;
- pathname_t f;
- fent_t *fep;
- flist_t *flp;
- int id;
- pathname_t newf;
- int oldid;
- int parid;
- int v;
- int v1;
-
- init_pathname(&f);
- if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
- if (v1)
- RedPrintf("%d/%d: rename - no filename\n", procid, opno);
- free_pathname(&f);
- return;
- }
- if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
- parid = -1;
- else
- parid = dfep->id;
- v |= v1;
- init_pathname(&newf);
- e = generate_fname(dfep, (int)(flp - flist), &newf, &id, &v1);
- v |= v1;
- if (!e) {
- if (v) {
- fent_to_name(&f, &flist[FT_DIR], dfep);
- RedPrintf("%d/%d: rename - no filename from %s\n",
- procid, opno, f.path);
- }
- free_pathname(&newf);
- free_pathname(&f);
- return;
- }
- e = rename_path(&f, &newf) < 0 ? errno : 0;
- check_cwd();
- if (e == 0) {
- if (flp - flist == FT_DIR) {
- oldid = fep->id;
- fix_parent(oldid, id);
- }
- del_from_flist((int)(flp - flist), (int)(fep - flp->fents));
- add_to_flist((int)(flp - flist), id, parid);
- }
- if (v)
- RedPrintf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
- newf.path, e);
- free_pathname(&newf);
- free_pathname(&f);
-}
-
-static void rmdir_f(int opno, long r)
-{
- int e;
- pathname_t f;
- fent_t *fep;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
- if (v)
- RedPrintf("%d/%d: rmdir - no directory\n", procid, opno);
- free_pathname(&f);
- return;
- }
- e = rmdir_path(&f) < 0 ? errno : 0;
- check_cwd();
- if (e == 0)
- del_from_flist(FT_DIR, (int)(fep - flist[FT_DIR].fents));
- if (v)
- RedPrintf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
-}
-
-static void stat_f(int opno, long r)
-{
- int e;
- pathname_t f;
- REDSTAT stb;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: stat - no entries\n", procid, opno);
- free_pathname(&f);
- return;
- }
- e = lstat64_path(&f, &stb) < 0 ? errno : 0;
- check_cwd();
- if (v)
- RedPrintf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
-}
-
-static void truncate_f(int opno, long r)
-{
- int e;
- pathname_t f;
- __int64_t lr;
- off64_t off;
- REDSTAT stb;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: truncate - no filename\n", procid, opno);
- free_pathname(&f);
- return;
- }
- e = stat64_path(&f, &stb) < 0 ? errno : 0;
- check_cwd();
- if (e > 0) {
- if (v)
- RedPrintf("%d/%d: truncate - stat64 %s failed %d\n",
- procid, opno, f.path, e);
- free_pathname(&f);
- return;
- }
- lr = ((__int64_t) random() << 32) + random();
- off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
- off %= maxfsize;
- e = truncate64_path(&f, off) < 0 ? errno : 0;
- check_cwd();
- if (v)
- RedPrintf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
- (long long)off, e);
- free_pathname(&f);
-}
-
-static void unlink_f(int opno, long r)
-{
- int e;
- pathname_t f;
- fent_t *fep;
- flist_t *flp;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
- if (v)
- RedPrintf("%d/%d: unlink - no file\n", procid, opno);
- free_pathname(&f);
- return;
- }
- e = unlink_path(&f) < 0 ? errno : 0;
- check_cwd();
- if (e == 0)
- del_from_flist((int)(flp - flist), (int)(fep - flp->fents));
- if (v)
- RedPrintf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
- free_pathname(&f);
-}
-
-static void write_f(int opno, long r)
-{
- char *buf;
- int e;
- pathname_t f;
- int fd;
- uint32_t len;
- __int64_t lr;
- off64_t off;
- REDSTAT stb;
- int v;
-
- init_pathname(&f);
- if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
- if (v)
- RedPrintf("%d/%d: write - no filename\n", procid, opno);
- free_pathname(&f);
- return;
- }
- fd = open_path(&f, O_WRONLY);
- e = fd < 0 ? errno : 0;
- check_cwd();
- if (fd < 0) {
- if (v)
- RedPrintf("%d/%d: write - open %s failed %d\n",
- procid, opno, f.path, e);
- free_pathname(&f);
- return;
- }
- if (fstat64(fd, &stb) < 0) {
- if (v)
- RedPrintf("%d/%d: write - fstat64 %s failed %d\n",
- procid, opno, f.path, errno);
- free_pathname(&f);
- close(fd);
- return;
- }
- lr = ((__int64_t) random() << 32) + random();
- off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
- off %= maxfsize;
- lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 4)) + 1;
- buf = malloc(len);
- memset(buf, nameseq & 0xff, len);
- e = write(fd, buf, len) < 0 ? errno : 0;
- free(buf);
- if (v)
- RedPrintf("%d/%d: write %s [%lld,%ld] %d\n",
- procid, opno, f.path, (long long)off, (long int)len, e);
- free_pathname(&f);
- close(fd);
-}
-
-
-#if REDCONF_CHECKER == 1
-static void check_f(int opno, long r)
-{
- int32_t ret;
- const char *pszVolume = gpRedVolConf->pszPathPrefix;
-
- (void)r;
-
- errno = 0;
-
- ret = red_transact(pszVolume);
-
- if(ret == 0)
- {
- ret = red_umount(pszVolume);
-
- if(ret == 0)
- {
- int32_t ret2;
-
- errno = -RedCoreVolCheck();
- if(errno != 0)
- {
- ret = -1;
- }
-
- ret2 = red_mount(pszVolume);
-
- if(ret == 0)
- {
- ret = ret2;
- }
-
- if(ret2 != 0)
- {
- exit(1);
- }
- }
- }
-
- if (verbose)
- {
- RedPrintf("%d/%d: check %s %d\n", procid, opno, pszVolume, errno);
- }
-}
-#endif
-
-
-#endif /* FSSTRESS_SUPPORTED */
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/redposixcompat.h b/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/redposixcompat.h
deleted file mode 100755
index d800d1e..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/posix/redposixcompat.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Defines macros which make the Reliance Edge POSIX-like API look more
- like the actual POSIX API.
-
- This file is intended for porting POSIX file system tests; it is not
- intended for application use.
-*/
-#ifndef REDPOSIXCOMPAT_H
-#define REDPOSIXCOMPAT_H
-
-
-#ifndef assert
-#define assert(x) REDASSERT(x)
-#endif
-
-
-#undef O_RDONLY
-#undef O_WRONLY
-#undef O_RDWR
-#undef O_APPEND
-#undef O_CREAT
-#undef O_EXCL
-#undef O_TRUNC
-#define O_RDONLY RED_O_RDONLY
-#define O_WRONLY RED_O_WRONLY
-#define O_RDWR RED_O_RDWR
-#define O_APPEND RED_O_APPEND
-#define O_CREAT RED_O_CREAT
-#define O_EXCL RED_O_EXCL
-#define O_TRUNC RED_O_TRUNC
-
-#undef SEEK_SET
-#undef SEEK_CUR
-#undef SEEK_END
-#define SEEK_SET RED_SEEK_SET
-#define SEEK_CUR RED_SEEK_CUR
-#define SEEK_END RED_SEEK_END
-
-/* Old-fashioned Linux seek names.
-*/
-#undef L_SET
-#undef L_INCR
-#undef L_XTND
-#define L_SET SEEK_SET
-#define L_INCR SEEK_CUR
-#define L_XTND SEEK_END
-
-#undef S_IFDIR
-#undef S_IFREG
-#undef S_ISDIR
-#undef S_ISREG
-#define S_IFDIR RED_S_IFDIR
-#define S_IFREG RED_S_IFREG
-#define S_ISDIR(m) RED_S_ISDIR(m)
-#define S_ISREG(m) RED_S_ISREG(m)
-
-#undef ST_RDONLY
-#undef ST_NOSUID
-#define ST_RDONLY RED_ST_RDONLY
-#define ST_NOSUID RED_ST_NOSUID
-
-#undef open
-#undef creat
-#undef unlink
-#undef mkdir
-#undef rmdir
-#undef rename
-#undef link
-#undef close
-#undef read
-#undef write
-#undef fsync
-#undef fdatasync
-#undef lseek
-#undef ftruncate
-#undef fstat
-#undef opendir
-#undef readdir
-#undef rewinddir
-#undef closedir
-#define open(path, oflag) red_open(path, oflag)
-#define creat(path, mode) open(path, O_WRONLY|O_CREAT|O_TRUNC)
-#define unlink(path) red_unlink(path)
-#define mkdir(path) red_mkdir(path)
-#define rmdir(path) red_rmdir(path)
-#define rename(old, new) red_rename(old, new)
-#define link(path, hardlink) red_link(path, hardlink)
-#define close(fd) red_close(fd)
-#define read(fd, buf, len) red_read(fd, buf, len)
-#define write(fd, buf, len) red_write(fd, buf, len)
-#define fsync(fd) red_fsync(fd)
-#define fdatasync(fd) fsync(fd)
-#define lseek(fd, offset, whence) red_lseek(fd, offset, whence)
-#define lseek64(fd, offset, whence) lseek(fd, offset, whence)
-#define ftruncate(fd, size) red_ftruncate(fd, size)
-#define fstat(fd, stat) red_fstat(fd, stat)
-#define fstat64(fd, stat) fstat(fd, stat)
-#define opendir(path) red_opendir(path)
-#define readdir(dirp) red_readdir(dirp)
-#define readdir64(dirp) readdir(dirp)
-#define rewinddir(dirp) red_rewinddir(dirp)
-#define closedir(dirp) red_closedir(dirp)
-
-#undef DIR
-#define DIR REDDIR
-
-#undef errno
-#define errno (*(int *)red_errnoptr())
-
-#undef memcpy
-#undef memmove
-#undef memset
-#undef strlen
-#undef strncmp
-#undef strcmp
-#undef strncpy
-#define memcpy(d, s, l) RedMemCpy(d, s, (uint32_t)(l))
-#define memmove(d, s, l) RedMemMove(d, s, (uint32_t)(l))
-#define memset(d, c, l) RedMemSet(d, (uint8_t)(c), (uint32_t)(l))
-#define strlen(s) RedStrLen(s)
-#define strncmp(s1, s2, l) RedStrNCmp(s1, s2, (uint32_t)(l))
-#define strcmp(s1, s2) RedStrCmp(s1, s2)
-#define strncpy(d, s, l) RedStrNCpy(d, s, (uint32_t)(l))
-
-
-#endif
-
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/atoi.c b/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/atoi.c
deleted file mode 100755
index ec11e0a..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/atoi.c
+++ /dev/null
@@ -1,478 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements utilities that convert strings to numbers.
-*/
-#include
-#include
-
-
-#define ISHEXDIGITU(c) (((c) >= 'A') && ((c) <= 'F'))
-#define ISHEXDIGITL(c) (((c) >= 'a') && ((c) <= 'f'))
-#define ISHEXDIGIT(c) (ISHEXDIGITL(c) || ISHEXDIGITU(c))
-
-
-/** @brief Converts an ASCII number into an int32_t.
-
- Converts all decimal digit numbers up to the end of the string or to the
- first non-numerical character.
-
- @note This function does *not* ignore leading white space.
-
- @param pszNum Pointer to a constant array of characters.
-
- @return The integer represented in the string.
-*/
-int32_t RedAtoI(
- const char *pszNum)
-{
- int32_t lValue = 0;
- int32_t lNegative = 1;
- uint32_t ulIdx = 0U;
-
- if(pszNum[ulIdx] == '+')
- {
- ulIdx++;
- }
- else if(pszNum[ulIdx] == '-')
- {
- ulIdx++;
- lNegative = -1;
- }
- else
- {
- /* No sign, implicitly positive.
- */
- }
-
- while(ISDIGIT(pszNum[ulIdx]))
- {
- lValue *= 10;
- lValue += pszNum[ulIdx] - '0';
- ulIdx++;
- }
-
- lValue *= lNegative;
-
- return lValue;
-}
-
-
-/** @brief Convert a hexadecimal ASCII number into a uint32_t value.
-
- The function processes all hex digits up to a NUL-terminator, or to the
- first non-hex character. Only hexadecimal digits are processed, so leading
- white space, or a leading "0x" prefix are not allowed.
-
- If pachNum points to an empty string (points to a NUL), this function will
- return NULL, and the value at *pulNum will not be modified.
-
- @note This function does not check for overflow. If there are more
- significant digits than can be represented in a uint32_t variable, the
- output is unspecified.
-
- @param pszNum A pointer to a constant array of hex characters.
- @param pulNum A pointer to the location in which to store the uint32_t
- result. Upon return, this value will be modified ONLY if
- the function succeeds and the returned pointer is valid (not
- NULL).
-
- @return A pointer to the byte following the converted number or NULL to
- indicate failure.
-*/
-const char *RedHtoUL(
- const char *pszNum,
- uint32_t *pulNum)
-{
- uint64_t ullValue;
- const char *pszReturn;
-
- pszReturn = RedHtoULL(pszNum, &ullValue);
- if(pszReturn != NULL)
- {
- if(ullValue < UINT32_MAX)
- {
- *pulNum = (uint32_t)ullValue;
- }
- else
- {
- pszReturn = NULL;
- }
- }
-
- return pszReturn;
-}
-
-
-/** @brief Convert a hexadecimal ASCII number into a D_UINT64 value.
-
- The function processes all hex digits up to a NUL-terminator, or to the
- first non-hex character. Only hexadecimal digits are processed, so leading
- white space, or a leading "0x" prefix are not allowed.
-
- If pachNum points to an empty string (points to a NUL), this function will
- return NULL, and the value at *pulNum will not be modified.
-
- @note This function does not check for overflow. If there are more
- significant digits than can be represented in a uint64_t variable, the
- output is unspecified.
-
- @param pszNum A pointer to a constant array of hex characters.
- @param pullNum A pointer to the location in which to store the uint64_t
- result. Upon return, this value will be modified ONLY if
- the function succeeds and the returned pointer is valid (not
- NULL).
-
- @return A pointer to the byte following the converted number, or NULL to
- indicate failure.
-*/
-const char *RedHtoULL(
- const char *pszNum,
- uint64_t *pullNum)
-{
- uint64_t ullValue = 0U;
- const char *pszReturn = NULL;
- uint32_t ulIdx = 0U;
-
- REDASSERT(pszNum != NULL);
- REDASSERT(pullNum != NULL);
-
- while(pszNum[ulIdx] != '\0')
- {
- char cDigit = pszNum[ulIdx];
-
- if(ISDIGIT(cDigit))
- {
- cDigit -= '0';
- }
- else if(ISHEXDIGITU(cDigit))
- {
- cDigit -= ('A' - 10);
- }
- else if(ISHEXDIGITL(cDigit))
- {
- cDigit -= ('a' - 10);
- }
- else
- {
- break;
- }
-
- REDASSERT((ullValue & UINT64_SUFFIX(0xF000000000000000)) == 0U);
-
- ullValue <<= 4U;
- ullValue += cDigit;
-
- ulIdx++;
- pszReturn = &pszNum[ulIdx];
- }
-
- /* Modify the number returned only if we found one or more valid hex
- digits.
- */
- if(pszReturn != NULL)
- {
- *pullNum = ullValue;
- }
-
- return pszReturn;
-}
-
-
-/** @brief Convert the ASCII number to a uint32_t value.
-
- The number may be hex or decimal. Hex numbers must be prefixed by '0x', and
- they may be upper or lower case. The conversion process will stop with the
- first non hex or decimal digit.
-
- If the number is negative (the first character is a '-' sign), the value
- will be range checked and returned as the equivalent unsigned value.
-
- @note This function will NOT fail for numbers which exceed the size of a
- uint32_t value.
-
- @param pszNum A pointer to the ASCII number to convert
- @param pulNum A pointer to the uint32_t location to store the result.
- This value will be modified on return only if the function
- succeeds and the returned pointer is valid (not NULL).
-
- @return A pointer to the byte following the converted number, or NULL to
- indicate failure.
-*/
-const char *RedNtoUL(
- const char *pszNum,
- uint32_t *pulNum)
-{
- bool fNegative = false;
- uint32_t ulIdx = 0U;
- const char *pszReturn;
-
- REDASSERT(pszNum != NULL);
- REDASSERT(pulNum != NULL);
-
- if(pszNum[ulIdx] == '-')
- {
- fNegative = true;
- ulIdx++;
- }
-
- /* Hex numbers must be prefixed with '0x'.
- */
- if((pszNum[ulIdx] == '0') && ((pszNum[ulIdx + 1U] == 'x') || (pszNum[ulIdx + 1U] == 'X')))
- {
- ulIdx += 2U;
-
- if(ISDIGIT(pszNum[ulIdx]) || ISHEXDIGIT(pszNum[ulIdx]))
- {
- pszReturn = RedHtoUL(&pszNum[ulIdx], pulNum);
- }
- else
- {
- pszReturn = NULL;
- }
- }
- else if(ISDIGIT(pszNum[ulIdx]))
- {
- uint32_t ulTemp;
-
- ulTemp = RedAtoI(&pszNum[ulIdx]);
-
- while(ISDIGIT(pszNum[ulIdx]))
- {
- ulIdx++;
- }
-
- if(fNegative)
- {
- /* Fail if the number is out of range.
- */
- if(ulTemp > INT32_MAX)
- {
- pszReturn = NULL;
- }
- else
- {
- *pulNum = -((int32_t)ulTemp);
- pszReturn = &pszNum[ulIdx];
- }
- }
- else
- {
- *pulNum = ulTemp;
- pszReturn = &pszNum[ulIdx];
- }
- }
- else
- {
- /* Return an error if there is not at least one hex or decimal digit.
- */
- pszReturn = NULL;
- }
-
- return pszReturn;
-}
-
-
-/** @brief Convert the ASCII number pointed to by pachNum to a uint64_t value.
-
- The number may be hex or decimal. Hex numbers must be prefixed by '0x', and
- they may be upper or lower case. The conversion process will stop with the
- first non hex or decimal digit.
-
- If the number is negative (the first character is a '-' sign), the value
- will be range checked and returned as the equivalent unsigned value.
-
- @param pszNum A pointer to the ASCII number to convert.
- @param pullNum A pointer to the uint64_t location to store the result.
- This value will be modified on return only if the function
- succeeds and the returned pointer is valid (not NULL).
-
- @return A pointer to the byte following the converted number, or NULL to
- indicate failure.
-*/
-const char *RedNtoULL(
- const char *pszNum,
- uint64_t *pullNum)
-{
- bool fNegative = false;
- uint32_t ulIdx = 0U;
- const char *pszReturn;
-
- REDASSERT(pszNum != NULL);
- REDASSERT(pullNum != NULL);
-
- if(pszNum[ulIdx] == '-')
- {
- fNegative = true;
- ulIdx++;
- }
-
- /* Hex numbers must be prefixed with '0x'.
- */
- if((pszNum[ulIdx] == '0') && ((pszNum[ulIdx + 1U] == 'x') || (pszNum[ulIdx + 1U] == 'X')))
- {
- ulIdx += 2U;
-
- if(ISDIGIT(pszNum[ulIdx]) || ISHEXDIGIT(pszNum[ulIdx]))
- {
- pszReturn = RedHtoULL(&pszNum[ulIdx], pullNum);
- }
- else
- {
- pszReturn = NULL;
- }
- }
- else if(ISDIGIT(pszNum[ulIdx]))
- {
- uint64_t ullTemp = 0U;
-
- while(ISDIGIT(pszNum[ulIdx]))
- {
- ullTemp *= 10U;
- ullTemp += pszNum[ulIdx] - '0';
- ulIdx++;
- }
-
- if(fNegative)
- {
- /* Fail if the number is out of range.
- */
- if(ullTemp > INT64_MAX)
- {
- pszReturn = NULL;
- }
- else
- {
- *pullNum = (uint64_t)(-((int64_t)ullTemp));
- pszReturn = &pszNum[ulIdx];
- }
- }
- else
- {
- *pullNum = ullTemp;
- pszReturn = &pszNum[ulIdx];
- }
- }
- else
- {
- /* Return an error if there is not at least one hex or decimal digit.
- */
- pszReturn = NULL;
- }
-
- return pszReturn;
-}
-
-
-/** @brief Convert an ASCII hex or decimal number, which may may have a "B",
- "KB", or "MB" suffix (case insensitive), to a binary value.
-
- Hex numbers must be prefixed with "0x".
-
- @note If there is no postfix, KB is assumed!
-
- May fail due to bad formatting or overflow.
-
- @param pszNum A pointer to the ASCII number to convert.
- @param pulResult A pointer to a uint32_t in which to place the result.
-
- @return A pointer to the byte following the string, or NULL to indicate an
- error. In the event of an error, *pulResult will not be modified.
-*/
-const char *RedSizeToUL(
- const char *pszNum,
- uint32_t *pulResult)
-{
- uint32_t ulResult;
- const char *pszSuffix;
- const char *pszReturn;
- uint32_t ulIdx = 0U;
-
- REDASSERT(pszNum != NULL);
- REDASSERT(pulResult != NULL);
-
- /* Do the basic hex/decimal conversion
- */
- pszSuffix = RedNtoUL(pszNum, &ulResult);
- if(pszSuffix != NULL)
- {
- if((pszSuffix[ulIdx] == 'B') || (pszSuffix[ulIdx] == 'b'))
- {
- ulIdx++;
- pszReturn = &pszSuffix[ulIdx];
- }
- else if( ((pszSuffix[ulIdx] == 'M') || (pszSuffix[ulIdx] == 'm'))
- && ((pszSuffix[ulIdx + 1U] == 'B') || (pszSuffix[ulIdx + 1U] == 'b')))
- {
- ulIdx += 2U;
-
- if(ulResult > (UINT32_MAX / (1024U * 1024U)))
- {
- pszReturn = NULL;
- }
- else
- {
- ulResult *= 1024U * 1024U;
- pszReturn = &pszSuffix[ulIdx];
- }
- }
- else
- {
- /* The number is either postfixed with "KB" or something
- else (we don't care), but we must increment the pointer
- if it is something recognize.
- */
- if( ((pszSuffix[ulIdx] == 'K') || (pszSuffix[ulIdx] == 'k'))
- && ((pszSuffix[ulIdx + 1U] == 'B') || (pszSuffix[ulIdx + 1U] == 'b')))
- {
- ulIdx += 2U;
- }
-
- /* "B" or "MB" were not specified, so it must be "KB"
- */
- if(ulResult > (UINT32_MAX / 1024U))
- {
- pszReturn = NULL;
- }
- else
- {
- ulResult *= 1024UL;
- pszReturn = &pszSuffix[ulIdx];
- }
- }
-
- if(pszReturn != NULL)
- {
- *pulResult = ulResult;
- }
- }
- else
- {
- pszReturn = NULL;
- }
-
- return pszReturn;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/math.c b/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/math.c
deleted file mode 100755
index 00f6bc3..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/math.c
+++ /dev/null
@@ -1,641 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements routines for certain 64-bit math operations and simulated
- floating point.
-
- RedUint64DivMod32() and RedUint64DivMod64() are derived from code at
- http://www.hackersdelight.org. This web site states explicitly that "You
- are free to use, copy, and distribute any of the code on this web site,
- whether modified by you or not. You need not give attribution."
-*/
-#include
-#include
-
-
-static uint32_t nlz64(uint64_t ullValue);
-
-
-/** @brief Return a ratio value formatted as a floating point string accurate to
- the specified number of decimal places.
-
- The function exists to provide floating point style output without using
- any actual floating point types.
-
- This function may scale the numbers down to avoid overflow at the high end.
- Likewise, potential divide-by-zero errors are internally avoided. Here are
- some examples:
-
- Dividend | Divisor | DecPlaces | Result
- -------- | ------- | --------- | ------
- 12133 | 28545 | 2 | "0.42"
- 1539 | 506 | 2 | "3.04"
-
- To get a number formatted as a percentage, take the take the portion of the
- total (normally the smaller part), multiply it by 100, and pass it to this
- function as the Dividend, pass the "total" value to this function as the
- Divisor, and specify the desired number of decimal places.
-
- For example, if you have a disk format overhead value of N blocks out of a
- total of Y blocks on the disk, and you want to display the format overhead
- as a percentage, you would use a function call
- similar to:
-
- ~~~{.c}
- RedRatio(szBuffer, sizeof(szBuffer), N*100U, Y, 2U);
- ~~~
-
- If N=145, Y=4096, and decimal places is 2, the resulting output would be
- "3.54".
-
- The string returned will always be null-terminated, even if it means
- stomping on the least significant decimal digit.
-
- If either the dividend or divisor values are zero, the string "0.0" will be
- returned, with the prescribed number of decimal places.
-
- @note This function has "reasonable" limits which meet the needs of the
- various supplemental utilities which use this function. Extremely
- large ratios, or using many decimal places may not function as
- desired.
-
- Parameters:
- @param pBuffer A pointer to the buffer in which to store the null
- terminated results.
- @param ulBufferLen The length of the output buffer.
- @param ullDividend The "total" value to divide.
- @param ullDivisor The portion of ullDividend for which to calculate the
- ratio (may be greater than ulDividend).
- @param ulDecPlaces The number of decimal places to use, from 0 to 9.
-
- @return @p pBuffer.
-*/
-char *RedRatio(
- char *pBuffer,
- uint32_t ulBufferLen,
- uint64_t ullDividend,
- uint64_t ullDivisor,
- uint32_t ulDecPlaces)
-{
- REDASSERT(pBuffer != NULL);
- REDASSERT(ulBufferLen > 0U);
- REDASSERT(ulDecPlaces <= 9U); /* arbitrary */
-
- if((ullDivisor > 0U) && (ullDividend > 0U))
- {
- uint32_t ii;
- uint32_t ulFactor = 1U;
- uint64_t ullDecimal;
- uint64_t ullTemp;
-
- for(ii = 1U; ii <= ulDecPlaces; ii++)
- {
- ulFactor *= 10U;
- }
-
- ullDecimal = RedMulDiv64(ullDividend, ulFactor, ullDivisor);
-
- /* Shouldn't really be calling this function in a situation where we
- can overflow at this point...
- */
- REDASSERT(ullDecimal != UINT64_MAX);
-
- if(ullDivisor <= ullDividend)
- {
- uint32_t ulDecimal;
-
- (void)RedUint64DivMod32(ullDecimal, ulFactor, &ulDecimal);
- ullDecimal = ulDecimal;
- }
-
- ullTemp = RedUint64DivMod64(ullDividend, ullDivisor, NULL);
-
- if(ulDecPlaces > 0U)
- {
- RedSNPrintf(pBuffer, ulBufferLen, "%llu.%0*llu", (unsigned long long)ullTemp,
- (unsigned)ulDecPlaces, (unsigned long long)ullDecimal);
- }
- else
- {
- RedSNPrintf(pBuffer, ulBufferLen, "%llu", (unsigned long long)ullTemp);
- }
- }
- else
- {
- /* If either the dividend or divisor is zero, then just output a "0.0"
- string with the prescribed number of decimal places.
- */
- if(ulDecPlaces > 0U)
- {
- RedSNPrintf(pBuffer, ulBufferLen, "0.%0*u", (unsigned)ulDecPlaces, 0U);
- }
- else
- {
- RedStrNCpy(pBuffer, "0", ulBufferLen);
- }
- }
-
- /* Ensure the returned buffer is always null-terminated
- */
- pBuffer[ulBufferLen - 1U] = '\0';
-
- return pBuffer;
-}
-
-
-/** @brief Multiply 64-bit and 32-bit numbers, and divide by a 64-bit number,
- returning a 64-bit result.
-
- @note This function may return an approximate value if multiplying
- @p ullBase and @p ulMultplier results in a number larger than 64-bits
- _and_ this cannot be avoided by scaling.
-
- @param ullBase The base 64-bit number number.
- @param ulMultiplier The 32-bit number by which to multiply.
- @param ullDivisor The 64-bit number by which to divide.
-
- @return The 64-bit unsigned integer result. Always returns zero if either
- @p ullBase or @p ulMultiplier are zero (regardless what
- @p ullDivisor is). Returns UINT64_MAX if an overflow condition
- occurred, or if @p ullDivisor is zero.
-*/
-uint64_t RedMulDiv64(
- uint64_t ullBase,
- uint32_t ulMultiplier,
- uint64_t ullDivisor)
-{
- uint64_t ullTemp;
-
- /* Result would always be zero if either of these are zero. Specifically
- test this case before looking for a zero divisor.
- */
- if((ullBase == 0U) || (ulMultiplier == 0U))
- {
- return 0U;
- }
-
- if(ullDivisor == 0U)
- {
- return UINT64_MAX;
- }
-
- /* Since we don't have the ability (yet) to use 128-bit numbers, we jump
- through the following hoops (in order) to try to determine the proper
- results without losing precision:
-
- 1) Shift the divisor and one of the multiplicands as many times as is
- necessary to reduce the scale -- only if it can be done without
- losing precision.
- 2) Divide one of the multiplicands by the divisor first, but only if it
- divides evenly, preserving precision.
- 3) Same as #2, but try it for the other multiplicand.
- 4) Last ditch, divide the larger multiplicand by the divisor first, then
- do the multiply. This lose precision.
-
- These solutions are identified as CODE-PATHs #1-4 which are used to
- identify the matching tests in dltmain.c.
-
- Note that execution might partially include CODE-PATH #1 up until
- shifting can no longer be done without losing precision. In that case,
- one of the three remaining options will be used.
- */
-
- ullTemp = RedUint64DivMod32(UINT64_MAX, ulMultiplier, NULL);
- while(ullBase > ullTemp)
- {
- uint64_t ullMod;
- uint64_t ullBaseTemp;
- uint64_t ullWideMultiplier;
-
- /* CODE-PATH #1
- */
- /* So long as ulDivisor, and at least one of the other numbers, are
- evenly divisible by 2, we can scale the numbers so the result does
- not overflow the intermediate 64-bit value.
- */
- if((ullDivisor & 1U) == 0U)
- {
- if((ullBase & 1U) == 0U)
- {
- /* CODE-PATH #1a
- */
- ullDivisor >>= 1U;
- ullBase >>= 1U;
- continue;
- }
-
- if(((ulMultiplier & 1U) == 0U) && ((ullTemp & UINT64_SUFFIX(0x8000000000000000)) == 0U))
- {
- /* CODE-PATH #1b
- */
- ullDivisor >>= 1U;
- ulMultiplier >>= 1U;
- ullTemp <<= 1U;
- continue;
- }
- }
-
- /* If we get to this point, the above method (#1) cannot be used
- because not enough of the numbers are even long enough to scale the
- operands down. We'll see if either multiplicand is evenly divisble
- by ulDivisor, and if so, do the divide first, then the multiply.
- (Note that once we get to this point, we will never exercise the
- while{} loop anymore.)
- */
-
- /* CODE-PATH #2
- */
- ullBaseTemp = RedUint64DivMod64(ullBase, ullDivisor, &ullMod);
- if(ullMod == 0U)
- {
- /* Evenly divides, so check that we won't overflow, and finish up.
- */
- ullBase = ullBaseTemp;
- if(ullBase > ullTemp)
- {
- return UINT64_MAX;
- }
- else
- {
- /* We've validated that this will not overflow.
- */
- ullBase *= ulMultiplier;
- return ullBase;
- }
- }
-
- /* CODE-PATH #3
- */
- ullWideMultiplier = RedUint64DivMod64(ulMultiplier, ullDivisor, &ullMod);
- if(ullMod == 0U)
- {
- /* Evenly divides, so check that we won't overflow, and finish up.
- */
-
- /* Must recalculate ullTemp relative to ullBase
- */
- ullTemp = RedUint64DivMod64(UINT64_MAX, ullBase, NULL);
- if(ullWideMultiplier > ullTemp)
- {
- return UINT64_MAX;
- }
- else
- {
- uint32_t ulNarrowMultiplier = (uint32_t)ullWideMultiplier;
-
- /* We've validated that this will not overflow.
- */
- ullBase *= ulNarrowMultiplier;
- return ullBase;
- }
- }
-
- /* CODE-PATH #4
-
- Neither of the multipliers is evenly divisible by the divisor, so
- just punt and divide the larger number first, then do the final
- multiply.
-
- All the other attempts above would preserve precision -- this is the
- only case where precision may be lost.
- */
-
- /* If necessary reverse the ullBase and ulMultiplier operands so that
- ullBase contains the larger of the two values.
- */
- if(ullBase < ulMultiplier)
- {
- uint32_t ulTemp = ulMultiplier;
-
- ulMultiplier = (uint32_t)ullBase;
- ullBase = ulTemp;
- }
-
- ullBase = RedUint64DivMod64(ullBase, ullDivisor, NULL);
- ullTemp = RedUint64DivMod32(UINT64_MAX, ulMultiplier, NULL);
- if(ullBase > ullTemp)
- {
- return UINT64_MAX;
- }
- else
- {
- ullBase *= ulMultiplier;
- return ullBase;
- }
- }
-
- /* We only get to this point if either there was never any chance of
- overflow, or if the pure shifting mechanism succeeded in reducing
- the scale so overflow is not a problem.
- */
-
- ullBase *= ulMultiplier;
- ullBase = RedUint64DivMod64(ullBase, ullDivisor, NULL);
-
- return ullBase;
-}
-
-
-/** @brief Divide a 64-bit value by a 32-bit value, returning the quotient and
- the remainder.
-
- Essentially this function does the following:
-
- ~~~{.c}
- if(pulRemainder != NULL)
- {
- *pulRemainder = (uint32_t)(ullDividend % ulDivisor);
- }
- return ullDividend / ulDivisor;
- ~~~
-
- However, it does so without ever actually dividing/modulating a 64-bit
- value, since such operations are not allowed in all environments.
-
- @param ullDividend The value to divide.
- @param ulDivisor The value to divide by.
- @param pulRemainder Populated with the remainder; may be NULL.
-
- @return The quotient (result of the division).
-*/
-uint64_t RedUint64DivMod32(
- uint64_t ullDividend,
- uint32_t ulDivisor,
- uint32_t *pulRemainder)
-{
- uint64_t ullQuotient;
- uint32_t ulResultRemainder;
-
- /* Check for divide by zero.
- */
- if(ulDivisor == 0U)
- {
- REDERROR();
-
- /* Nonsense value if no asserts.
- */
- ullQuotient = UINT64_SUFFIX(0xFFFFFFFFFFFFFBAD);
- ulResultRemainder = 0xFFFFFBADU;
- }
- else if(ullDividend <= UINT32_MAX)
- {
- uint32_t ulDividend = (uint32_t)ullDividend;
-
- ullQuotient = ulDividend / ulDivisor;
- ulResultRemainder = ulDividend % ulDivisor;
- }
- else
- {
- uint32_t ulResultHi;
- uint32_t ulResultLo;
- uint32_t ulRemainder;
- uint8_t bIndex;
- uint32_t ulThisDivision;
- uint32_t ulMask;
- uint8_t ucNextValue;
- uint32_t ulInterimHi, ulInterimLo;
- uint32_t ulLowDword = (uint32_t)ullDividend;
- uint32_t ulHighDword = (uint32_t)(ullDividend >> 32U);
-
- /* Compute the high part and get the remainder
- */
- ulResultHi = ulHighDword / ulDivisor;
- ulResultLo = 0U;
- ulRemainder = ulHighDword % ulDivisor;
-
- /* Compute the low part
- */
- ulMask = 0xFF000000U;
- for(bIndex = 0U; bIndex < sizeof(uint32_t); bIndex++)
- {
- ucNextValue = (uint8_t)((ulLowDword & ulMask) >> ((sizeof(uint32_t) - 1U - bIndex) * 8U));
- ulInterimHi = ulRemainder >> 24U;
- ulInterimLo = (ulRemainder << 8U) | ucNextValue;
- ulThisDivision = 0U;
- while(ulInterimHi != 0U)
- {
- uint64_t ullInterim = ((uint64_t)ulInterimHi << 32U) + ulInterimLo;
-
- ullInterim -= ulDivisor;
- ulThisDivision++;
-
- ulInterimHi = (uint32_t)(ullInterim >> 32U);
- ulInterimLo = (uint32_t)ullInterim;
- }
- ulThisDivision += ulInterimLo / ulDivisor;
- ulRemainder = ulInterimLo % ulDivisor;
- ulResultLo <<= 8U;
- ulResultLo += ulThisDivision;
- ulMask >>= 8U;
- }
-
- ullQuotient = ((uint64_t)ulResultHi << 32U) + ulResultLo;
- ulResultRemainder = (uint32_t)(ullDividend - (ullQuotient * ulDivisor));
- }
-
- if(pulRemainder != NULL)
- {
- *pulRemainder = ulResultRemainder;
- }
-
- return ullQuotient;
-}
-
-
-/** @brief Divide a 64-bit value by a 64-bit value, returning the quotient and
- the remainder.
-
- Essentially this function does the following:
-
- ~~~{.c}
- if(pullRemainder != NULL)
- {
- *pullRemainder = ullDividend % ullDivisor;
- }
- return ullDividend / ullDivisor;
- ~~~
-
- However, it does so without ever actually dividing/modulating a 64-bit
- value, since such operations are not allowed in all environments.
-
- @param ullDividend The value to divide.
- @param ullDivisor The value to divide by.
- @param pullRemainder Populated with the remainder; may be NULL.
-
- @return The quotient (result of the division).
-*/
-uint64_t RedUint64DivMod64(
- uint64_t ullDividend,
- uint64_t ullDivisor,
- uint64_t *pullRemainder)
-{
- /* The variables u0, u1, etc. take on only 32-bit values, but they are
- declared uint64_t to avoid some compiler warning messages and to avoid
- some unnecessary EXTRs that the compiler would put in, to convert
- uint64_ts to ints.
- */
- uint64_t u0;
- uint64_t u1;
- uint64_t q0;
- uint64_t q1;
- uint64_t ullQuotient;
-
- /* First the procedure takes care of the case in which the divisor is a
- 32-bit quantity. There are two subcases: (1) If the left half of the
- dividend is less than the divisor, one execution of RedUint64DivMod32()
- is all that is required (overflow is not possible). (2) Otherwise it
- does two divisions, using the grade school method.
- */
-
- if((ullDivisor >> 32U) == 0U)
- {
- if((ullDividend >> 32U) < ullDivisor)
- {
- /* If ullDividend/ullDivisor cannot overflow, just do one division.
- */
- ullQuotient = RedUint64DivMod32(ullDividend, (uint32_t)ullDivisor, NULL);
- }
- else
- {
- uint32_t k;
-
- /* If ullDividend/ullDivisor would overflow:
- */
-
- /* Break ullDividend up into two halves.
- */
- u1 = ullDividend >> 32U;
- u0 = ullDividend & 0xFFFFFFFFU;
-
- /* First quotient digit and first remainder.
- */
- q1 = RedUint64DivMod32(u1, (uint32_t)ullDivisor, &k);
-
- /* 2nd quot. digit.
- */
- q0 = RedUint64DivMod32(((uint64_t)k << 32U) + u0, (uint32_t)ullDivisor, NULL);
-
- ullQuotient = (q1 << 32U) + q0;
- }
- }
- else
- {
- uint64_t n;
- uint64_t v1;
-
- n = nlz64(ullDivisor); /* 0 <= n <= 31. */
- v1 = (ullDivisor << n) >> 32U; /* Normalize the divisor so its MSB is 1. */
- u1 = ullDividend >> 1U; /* To ensure no overflow. */
-
- /* Get quotient from divide unsigned insn.
- */
- q1 = RedUint64DivMod32(u1, (uint32_t)v1, NULL);
-
- q0 = (q1 << n) >> 31U; /* Undo normalization and division of ullDividend by 2. */
-
- /* Make q0 correct or too small by 1.
- */
- if(q0 != 0U)
- {
- q0--;
- }
-
- if((ullDividend - (q0 * ullDivisor)) >= ullDivisor)
- {
- q0++; /* Now q0 is correct. */
- }
-
- ullQuotient = q0;
- }
-
- if(pullRemainder != NULL)
- {
- *pullRemainder = ullDividend - (ullQuotient * ullDivisor);
- }
-
- return ullQuotient;
-}
-
-
-/** @brief Compute the number of leading zeroes in a 64-bit value.
-
- @param ullValue The value for which to compute the NLZ.
-
- @return The number of leading zeroes in @p ullValue.
-*/
-static uint32_t nlz64(
- uint64_t ullValue)
-{
- uint32_t n;
-
- if(ullValue == 0U)
- {
- n = 64U;
- }
- else
- {
- uint64_t x = ullValue;
-
- n = 0U;
-
- if(x <= UINT64_SUFFIX(0x00000000FFFFFFFF))
- {
- n += 32U;
- x <<= 32U;
- }
-
- if(x <= UINT64_SUFFIX(0x0000FFFFFFFFFFFF))
- {
- n += 16U;
- x <<= 16U;
- }
-
- if(x <= UINT64_SUFFIX(0x00FFFFFFFFFFFFFF))
- {
- n += 8U;
- x <<= 8U;
- }
-
- if(x <= UINT64_SUFFIX(0x0FFFFFFFFFFFFFFF))
- {
- n += 4U;
- x <<= 4U;
- }
-
- if(x <= UINT64_SUFFIX(0x3FFFFFFFFFFFFFFF))
- {
- n += 2U;
- x <<= 2U;
- }
-
- if(x <= UINT64_SUFFIX(0x7FFFFFFFFFFFFFFF))
- {
- n += 1;
- }
- }
-
- return n;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/printf.c b/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/printf.c
deleted file mode 100755
index 6df0cf4..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/printf.c
+++ /dev/null
@@ -1,1265 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements functions for printing.
-
- These functions are intended to be used in portable test code, which cannot
- assume the standard I/O functions will be available. Similar to their ANSI
- C counterparts, these functions allow formatting text strings and (if the
- configuration allows it) outputing formatted text. The latter ability
- relies on the RedOsOutputString() OS service function.
-
- Do *not* use these functions in code which can safely assume the standard
- I/O functions are available (e.g., in host tools code).
-
- Do *not* use these functions from within the file system driver. These
- functions use variable arguments and thus are not MISRA-C:2012 compliant.
-*/
-#include
-#include
-#include
-#include
-
-
-/** @brief Maximum number of bytes of output supported by RedPrintf().
-
- Typically only Datalight code uses these functions, and that could should be
- written to respect this limit, so it should not normally be necessary to
- adjust this value.
-*/
-#define OUTPUT_BUFFER_SIZE 256U
-
-
-typedef enum
-{
- PRFMT_UNKNOWN = 0,
- PRFMT_CHAR,
- PRFMT_ANSISTRING,
- PRFMT_SIGNED8BIT,
- PRFMT_UNSIGNED8BIT,
- PRFMT_SIGNED16BIT,
- PRFMT_UNSIGNED16BIT,
- PRFMT_SIGNED32BIT,
- PRFMT_UNSIGNED32BIT,
- PRFMT_SIGNED64BIT,
- PRFMT_UNSIGNED64BIT,
- PRFMT_HEX8BIT,
- PRFMT_HEX16BIT,
- PRFMT_HEX32BIT,
- PRFMT_HEX64BIT,
- PRFMT_POINTER,
- PRFMT_DOUBLEPERCENT
-} PRINTTYPE;
-
-typedef struct
-{
- PRINTTYPE type; /* The PRFMT_* type found */
- uint32_t ulSpecifierIdx; /* Returns a pointer to the % sign */
- uint32_t ulFillLen;
- char cFillChar;
- bool fLeftJustified;
- bool fHasIllegalType; /* TRUE if an illegal sequence was skipped over */
- bool fHasVarWidth;
-} PRINTFORMAT;
-
-
-/* Our output handlers are written for standard fixed width data types. Map
- the standard ANSI C data types onto our handlers. Currently this code has
- the following requirements:
-
- 1) shorts must be either 16 or 32 bits
- 2) ints must be either 16 or 32 bits
- 3) longs must be between 32 or 64 bits
- 4) long longs must be 64 bits
-*/
-#if (USHRT_MAX == 0xFFFFU)
- #define MAPSHORT PRFMT_SIGNED16BIT
- #define MAPUSHORT PRFMT_UNSIGNED16BIT
- #define MAPHEXUSHORT PRFMT_HEX16BIT
-#elif (USHRT_MAX == 0xFFFFFFFFU)
- #define MAPSHORT PRFMT_SIGNED32BIT
- #define MAPUSHORT PRFMT_UNSIGNED32BIT
- #define MAPHEXUSHORT PRFMT_HEX32BIT
-#else
- #error "The 'short' data type does not have a 16 or 32-bit width"
-#endif
-
-#if (UINT_MAX == 0xFFFFU)
- #define MAPINT PRFMT_SIGNED16BIT
- #define MAPUINT PRFMT_UNSIGNED16BIT
- #define MAPHEXUINT PRFMT_HEX16BIT
-#elif (UINT_MAX == 0xFFFFFFFFU)
- #define MAPINT PRFMT_SIGNED32BIT
- #define MAPUINT PRFMT_UNSIGNED32BIT
- #define MAPHEXUINT PRFMT_HEX32BIT
-#else
- #error "The 'int' data type does not have a 16 or 32-bit width"
-#endif
-
-#if (ULONG_MAX == 0xFFFFFFFFU)
- #define MAPLONG PRFMT_SIGNED32BIT
- #define MAPULONG PRFMT_UNSIGNED32BIT
- #define MAPHEXULONG PRFMT_HEX32BIT
-#elif (ULONG_MAX <= UINT64_SUFFIX(0xFFFFFFFFFFFFFFFF))
- /* We've run into unusual environments where "longs" are 40-bits wide.
- In this event, map them to 64-bit types so no data is lost.
- */
- #define MAPLONG PRFMT_SIGNED64BIT
- #define MAPULONG PRFMT_UNSIGNED64BIT
- #define MAPHEXULONG PRFMT_HEX64BIT
-#else
- #error "The 'long' data type is not between 32 and 64 bits wide"
-#endif
-
-#if defined(ULLONG_MAX) && (ULLONG_MAX != UINT64_SUFFIX(0xFFFFFFFFFFFFFFFF))
- #error "The 'long long' data type is not 64 bits wide"
-#else
- #define MAPLONGLONG PRFMT_SIGNED64BIT
- #define MAPULONGLONG PRFMT_UNSIGNED64BIT
- #define MAPHEXULONGLONG PRFMT_HEX64BIT
-#endif
-
-
-static uint32_t ProcessFormatSegment(char *pcBuffer, uint32_t ulBufferLen, const char *pszFormat, PRINTFORMAT *pFormat, uint32_t *pulSpecifierLen);
-static uint32_t ParseFormatSpecifier(char const *pszFormat, PRINTFORMAT *pFormatType);
-static PRINTTYPE ParseFormatType(const char *pszFormat, uint32_t *pulTypeLen);
-static uint32_t LtoA(char *pcBuffer, uint32_t ulBufferLen, int32_t lNum, uint32_t ulFillLen, char cFill);
-static uint32_t LLtoA(char *pcBuffer, uint32_t ulBufferLen, int64_t llNum, uint32_t ulFillLen, char cFill);
-static uint32_t ULtoA(char *pcBuffer, uint32_t ulBufferLen, uint32_t ulNum, bool fHex, uint32_t ulFillLen, char cFill);
-static uint32_t ULLtoA(char *pcBuffer, uint32_t ulBufferLen, uint64_t ullNum, bool fHex, uint32_t ulFillLen, char cFill);
-static uint32_t FinishToA(const char *pcDigits, uint32_t ulDigits, char *pcOutBuffer, uint32_t ulBufferLen, uint32_t ulFillLen, char cFill);
-
-
-/* Digits for the *LtoA() routines.
-*/
-static const char gacDigits[] = "0123456789ABCDEF";
-
-
-#if REDCONF_OUTPUT == 1
-/** @brief Print formatted data with a variable length argument list.
-
- This function provides a subset of the ANSI C printf() functionality with
- several extensions to support fixed size data types.
-
- See RedVSNPrintf() for the list of supported types.
-
- @param pszFormat A pointer to the null-terminated format string.
- @param ... The variable length argument list.
-*/
-void RedPrintf(
- const char *pszFormat,
- ...)
-{
- va_list arglist;
-
- va_start(arglist, pszFormat);
-
- RedVPrintf(pszFormat, arglist);
-
- va_end(arglist);
-}
-
-
-/** @brief Print formatted data using a pointer to a variable length argument
- list.
-
- This function provides a subset of the ANSI C vprintf() functionality.
-
- See RedVSNPrintf() for the list of supported types.
-
- This function accommodates a maximum output length of #OUTPUT_BUFFER_SIZE.
- If this function must truncate the output, and the original string was
- \n terminated, the truncated output will be \n terminated as well.
-
- @param pszFormat A pointer to the null-terminated format string.
- @param arglist The variable length argument list.
-*/
-void RedVPrintf(
- const char *pszFormat,
- va_list arglist)
-{
- char achBuffer[OUTPUT_BUFFER_SIZE];
-
- if(RedVSNPrintf(achBuffer, sizeof(achBuffer), pszFormat, arglist) == -1)
- {
- /* Ensture the buffer is null terminated.
- */
- achBuffer[sizeof(achBuffer) - 1U] = '\0';
-
- /* If the original string was \n terminated and the new one is not, due to
- truncation, stuff a \n into the new one.
- */
- if(pszFormat[RedStrLen(pszFormat) - 1U] == '\n')
- {
- achBuffer[sizeof(achBuffer) - 2U] = '\n';
- }
- }
-
- RedOsOutputString(achBuffer);
-}
-#endif /* #if REDCONF_OUTPUT == 1 */
-
-
-/** @brief Format arguments into a string using a subset of the ANSI C
- vsprintf() functionality.
-
- This function is modeled after the Microsoft _snprint() extension to the
- ANSI C sprintf() function, and allows a buffer length to be specified so
- that overflow is avoided.
-
- See RedVSNPrintf() for the list of supported types.
-
- @param pcBuffer A pointer to the output buffer
- @param ulBufferLen The output buffer length
- @param pszFormat A pointer to the null terminated format string
- @param ... Variable argument list
-
- @return The length output, or -1 if the buffer filled up. If -1 is
- returned, the output buffer may not be null-terminated.
-*/
-int32_t RedSNPrintf(
- char *pcBuffer,
- uint32_t ulBufferLen,
- const char *pszFormat,
- ...)
-{
- int32_t iLen;
- va_list arglist;
-
- va_start(arglist, pszFormat);
-
- iLen = RedVSNPrintf(pcBuffer, ulBufferLen, pszFormat, arglist);
-
- va_end(arglist);
-
- return iLen;
-}
-
-
-/** @brief Format arguments into a string using a subset of the ANSI C
- vsprintf() functionality.
-
- This function is modeled after the Microsoft _vsnprint() extension to the
- ANSI C vsprintf() function, and requires a buffer length to be specified so
- that overflow is avoided.
-
- The following ANSI C standard formatting codes are supported:
-
- | Code | Meaning |
- | ---- | ---------------------------------- |
- | %c | Format a character |
- | %s | Format a null-terminated C string |
- | %hd | Format a signed short |
- | %hu | Format an unsigned short |
- | %d | Format a signed integer |
- | %u | Format an unsigned integer |
- | %ld | Format a signed long |
- | %lu | Format an unsigned long |
- | %lld | Format a signed long long |
- | %llu | Format an unsigned long long |
- | %hx | Format a short in hex |
- | %x | Format an integer in hex |
- | %lx | Format a long in hex |
- | %llx | Format a long long in hex |
- | %p | Format a pointer (hex value) |
-
- @note All formatting codes are case-sensitive.
-
- Fill characters and field widths are supported per the ANSI standard, as is
- left justification with the '-' character.
-
- The only supported fill characters are '0', ' ', and '_'.
-
- '*' is supported to specify variable length field widths.
-
- Hexidecimal numbers are always displayed in upper case. Formatting codes
- which specifically request upper case (e.g., "%lX") are not supported.
-
- Unsupported behaviors:
- - Precision is not supported.
- - Floating point is not supported.
-
- Errata:
- - There is a subtle difference in the return value for this function versus
- the Microsoft implementation. In the Microsoft version, if the buffer
- exactly fills up, but there is no room for a null-terminator, the return
- value will be the length of the buffer. In this code, -1 will be returned
- when this happens.
- - When using left justified strings, the only supported fill character is a
- space, regardless of what may be specified. It is not clear if this is
- ANSI standard or just the way the Microsoft function works, but we emulate
- the Microsoft behavior.
-
- @param pcBuffer A pointer to the output buffer.
- @param ulBufferLen The output buffer length.
- @param pszFormat A pointer to the null terminated ANSI format string.
- @param arglist Variable argument list.
-
- @return The length output, or -1 if the buffer filled up. If -1 is
- returned, the output buffer may not be null-terminated.
-*/
-int32_t RedVSNPrintf(
- char *pcBuffer,
- uint32_t ulBufferLen,
- const char *pszFormat,
- va_list arglist)
-{
- uint32_t ulBufIdx = 0U;
- uint32_t ulFmtIdx = 0U;
- int32_t iLen;
-
- while((pszFormat[ulFmtIdx] != '\0') && (ulBufIdx < ulBufferLen))
- {
- PRINTFORMAT fmt;
- uint32_t ulSpecifierLen;
- uint32_t ulWidth;
-
- /* Process the next segment of the format string, outputting
- any non-format specifiers, as output buffer space allows,
- and return information about the next format specifier.
- */
- ulWidth = ProcessFormatSegment(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, &pszFormat[ulFmtIdx], &fmt, &ulSpecifierLen);
- if(ulWidth)
- {
- REDASSERT(ulWidth <= (ulBufferLen - ulBufIdx));
-
- ulBufIdx += ulWidth;
- }
-
- /* If no specifier was found, or if the output buffer is
- full, we're done -- get out.
- */
- if((ulSpecifierLen == 0U) || (ulBufIdx == ulBufferLen))
- {
- break;
- }
-
- /* Otherwise, the math should add up for these things...
- */
- REDASSERT(&pszFormat[fmt.ulSpecifierIdx] == &pszFormat[ulWidth]);
-
- /* Point past the specifier, to the next piece of the format string.
- */
- ulFmtIdx = ulFmtIdx + fmt.ulSpecifierIdx + ulSpecifierLen;
-
- if(fmt.fHasVarWidth)
- {
- int iFillLen = va_arg(arglist, int);
-
- if(iFillLen >= 0)
- {
- fmt.ulFillLen = (uint32_t)iFillLen;
- }
- else
- {
- /* Bogus fill length. Ignore.
- */
- fmt.ulFillLen = 0U;
- }
- }
-
- switch(fmt.type)
- {
- case PRFMT_DOUBLEPERCENT:
- {
- /* Nothing to do. A single percent has already been output,
- and we just finished skipping past the second percent.
- */
- break;
- }
-
- /*-----------------> Small int handling <------------------
- *
- * Values smaller than "int" will be promoted to "int" by
- * the compiler, so we must retrieve them using "int" when
- * calling va_arg(). Once we've done that, we immediately
- * put the value into the desired data type.
- *---------------------------------------------------------*/
-
- case PRFMT_CHAR:
- {
- pcBuffer[ulBufIdx] = (char)va_arg(arglist, int);
- ulBufIdx++;
- break;
- }
- case PRFMT_SIGNED8BIT:
- {
- int8_t num = (int8_t)va_arg(arglist, int);
-
- ulBufIdx += LtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, num, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_UNSIGNED8BIT:
- {
- uint8_t bNum = (uint8_t)va_arg(arglist, unsigned);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, bNum, false, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_HEX8BIT:
- {
- uint8_t bNum = (uint8_t)va_arg(arglist, unsigned);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, bNum, true, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_SIGNED16BIT:
- {
- int16_t num = (int16_t)va_arg(arglist, int);
-
- ulBufIdx += LtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, num, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_UNSIGNED16BIT:
- {
- uint16_t uNum = (uint16_t)va_arg(arglist, unsigned);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, uNum, false, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_HEX16BIT:
- {
- uint16_t uNum = (uint16_t)va_arg(arglist, unsigned);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, uNum, true, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_SIGNED32BIT:
- {
- int32_t lNum = va_arg(arglist, int32_t);
-
- ulBufIdx += LtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, lNum, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_UNSIGNED32BIT:
- {
- uint32_t ulNum = va_arg(arglist, uint32_t);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ulNum, false, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_HEX32BIT:
- {
- uint32_t ulNum = va_arg(arglist, uint32_t);
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ulNum, true, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_SIGNED64BIT:
- {
- int64_t llNum = va_arg(arglist, int64_t);
-
- ulBufIdx += LLtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, llNum, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_UNSIGNED64BIT:
- {
- uint64_t ullNum = va_arg(arglist, uint64_t);
-
- ulBufIdx += ULLtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ullNum, false, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_HEX64BIT:
- {
- uint64_t ullNum = va_arg(arglist, uint64_t);
-
- ulBufIdx += ULLtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ullNum, true, fmt.ulFillLen, fmt.cFillChar);
- break;
- }
- case PRFMT_POINTER:
- {
- const void *ptr = va_arg(arglist, const void *);
-
- /* Assert our assumption.
- */
- REDASSERT(sizeof(void *) <= 8U);
-
- /* Format as either a 64-bit or a 32-bit value.
- */
- if(sizeof(void *) > 4U)
- {
- /* Attempt to quiet warnings.
- */
- uintptr_t ptrval = (uintptr_t)ptr;
- uint64_t ullPtrVal = (uint64_t)ptrval;
-
- ulBufIdx += ULLtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ullPtrVal, true, fmt.ulFillLen, fmt.cFillChar);
- }
- else
- {
- /* Attempt to quiet warnings.
- */
- uintptr_t ptrval = (uintptr_t)ptr;
- uint32_t ulPtrVal = (uint32_t)ptrval;
-
- ulBufIdx += ULtoA(&pcBuffer[ulBufIdx], ulBufferLen - ulBufIdx, ulPtrVal, true, fmt.ulFillLen, fmt.cFillChar);
- }
-
- break;
- }
- case PRFMT_ANSISTRING:
- {
- const char *pszArg = va_arg(arglist, const char *);
- uint32_t ulArgIdx = 0U;
-
- if(pszArg == NULL)
- {
- pszArg = "null";
- }
-
- if(fmt.ulFillLen > 0U)
- {
- if(!fmt.fLeftJustified)
- {
- uint32_t ulLen = RedStrLen(pszArg);
-
- /* So long as we are not left justifying, fill as many
- characters as is necessary to make the string right
- justified.
- */
- while(((ulBufferLen - ulBufIdx) > 0U) && (fmt.ulFillLen > ulLen))
- {
- pcBuffer[ulBufIdx] = fmt.cFillChar;
- ulBufIdx++;
- fmt.ulFillLen--;
- }
- }
-
- /* Move as many characters as we have space for into the
- output buffer.
- */
- while(((ulBufferLen - ulBufIdx) > 0U) && (pszArg[ulArgIdx] != '\0'))
- {
- pcBuffer[ulBufIdx] = pszArg[ulArgIdx];
- ulBufIdx++;
- ulArgIdx++;
- if(fmt.ulFillLen > 0U)
- {
- fmt.ulFillLen--;
- }
- }
-
- /* If there is any space left to fill, do it (the string
- must have been left justified).
- */
- while(((ulBufferLen - ulBufIdx) > 0U) && (fmt.ulFillLen > 0U))
- {
- /* This is NOT a typo -- when using left justified
- strings, spaces are the only allowed fill character.
- See the errata.
- */
- pcBuffer[ulBufIdx] = ' ';
- ulBufIdx++;
- fmt.ulFillLen--;
- }
- }
- else
- {
- /* No fill characters, just move up to as many
- characters as we have space for in the output
- buffer.
- */
- while(((ulBufferLen - ulBufIdx) > 0U) && (pszArg[ulArgIdx] != '\0'))
- {
- pcBuffer[ulBufIdx] = pszArg[ulArgIdx];
- ulBufIdx++;
- ulArgIdx++;
- }
- }
- break;
- }
- default:
- {
- REDERROR();
- break;
- }
- }
- }
-
- /* If there is space, tack on a null and return the output length
- processed, not including the null.
- */
- if(ulBufIdx < ulBufferLen)
- {
- pcBuffer[ulBufIdx] = '\0';
- iLen = (int32_t)ulBufIdx;
- }
- else
- {
- /* Not enough space, just return -1, with no null termination
- */
- iLen = -1;
- }
-
- return iLen;
-}
-
-
-/** @brief Process the next segment of the format string, outputting any
- non-format specifiers, as output buffer space allows, and return
- information about the next format specifier.
-
- @note If the returned value is the same as the supplied @p ulBufferLen,
- the output buffer will not be null-terminated. In all other cases,
- the result will be null-terminated. The returned length will never
- include the null in the count.
-
- @param pcBuffer The output buffer.
- @param ulBufferLen The output buffer length.
- @param pszFormat The format string to process.
- @param pFormat The PRINTFORMAT structure to fill.
- @param pulSpecifierLen Returns the length of any format specifier string,
- or zero if no specifier was found.
-
- @return The count of characters from pszFormatt which were processed and
- copied to pcBuffer.
- - If zero is returned and *pulSpecifierLen is non-zero, then
- a format specifier string was found at the start of pszFmt.
- - If non-zero is returned and *pulSpecifierLen is zero, then
- no format specifier string was found, and the entire pszFmt
- string was copied to pBuffer (or as much as will fit).
-*/
-static uint32_t ProcessFormatSegment(
- char *pcBuffer,
- uint32_t ulBufferLen,
- const char *pszFormat,
- PRINTFORMAT *pFormat,
- uint32_t *pulSpecifierLen)
-{
- uint32_t ulWidth = 0U;
-
- /* Find the next format specifier string, and information about it.
- */
- *pulSpecifierLen = ParseFormatSpecifier(pszFormat, pFormat);
-
- if(*pulSpecifierLen == 0U)
- {
- /* If no specifier was found at all, then simply output the full length
- of the string, or as much as will fit.
- */
- ulWidth = REDMIN(ulBufferLen, RedStrLen(pszFormat));
-
- RedMemCpy(pcBuffer, pszFormat, ulWidth);
- }
- else
- {
- /* If we encountered a double percent, skip past one of them so it is
- copied into the output buffer.
- */
- if(pFormat->type == PRFMT_DOUBLEPERCENT)
- {
- pFormat->ulSpecifierIdx++;
-
- /* A double percent specifier always has a length of two. Since
- we're processing one of those percent signs, reduce the length
- to one. Assert it so.
- */
- REDASSERT(*pulSpecifierLen == 2U);
-
- (*pulSpecifierLen)--;
- }
-
- /* So long as the specifier is not the very first thing in the format
- string...
- */
- if(pFormat->ulSpecifierIdx != 0U)
- {
- /* A specifier was found, but there is other data preceding it.
- Copy as much as allowed to the output buffer.
- */
- ulWidth = REDMIN(ulBufferLen, pFormat->ulSpecifierIdx);
-
- RedMemCpy(pcBuffer, pszFormat, ulWidth);
- }
- }
-
- /* If there is room in the output buffer, null-terminate whatever is there.
- But note that the returned length never includes the null.
- */
- if(ulWidth < ulBufferLen)
- {
- pcBuffer[ulWidth] = 0U;
- }
-
- return ulWidth;
-}
-
-
-/** @brief Parse the specified format string for a valid RedVSNPrintf() format
- sequence, and return information about it.
-
- @param pszFormat The format string to process.
- @param pFormatType The PRINTFORMAT structure to fill. The data is only
- valid if a non-zero length is returned.
-
- @return The length of the full format specifier string, starting at
- pFormat->ulSpecifierIdx. Returns zero if a valid specifier was
- not found.
-*/
-static uint32_t ParseFormatSpecifier(
- char const *pszFormat,
- PRINTFORMAT *pFormatType)
-{
- bool fContainsIllegalSequence = false;
- uint32_t ulLen = 0U;
- uint32_t ulIdx = 0U;
-
- while(pszFormat[ulIdx] != '\0')
- {
- uint32_t ulTypeLen;
-
- /* general output
- */
- if(pszFormat[ulIdx] != '%')
- {
- ulIdx++;
- }
- else
- {
- RedMemSet(pFormatType, 0U, sizeof(*pFormatType));
-
- /* Record the location of the start of the format sequence
- */
- pFormatType->ulSpecifierIdx = ulIdx;
- ulIdx++;
-
- if(pszFormat[ulIdx] == '-')
- {
- pFormatType->fLeftJustified = true;
- ulIdx++;
- }
-
- if((pszFormat[ulIdx] == '0') || (pszFormat[ulIdx] == '_'))
- {
- pFormatType->cFillChar = pszFormat[ulIdx];
- ulIdx++;
- }
- else
- {
- pFormatType->cFillChar = ' ';
- }
-
- if(pszFormat[ulIdx] == '*')
- {
- pFormatType->fHasVarWidth = true;
- ulIdx++;
- }
- else if(ISDIGIT(pszFormat[ulIdx]))
- {
- pFormatType->ulFillLen = (uint32_t)RedAtoI(&pszFormat[ulIdx]);
- while(ISDIGIT(pszFormat[ulIdx]))
- {
- ulIdx++;
- }
- }
- else
- {
- /* No fill length.
- */
- }
-
- pFormatType->type = ParseFormatType(&pszFormat[ulIdx], &ulTypeLen);
- if(pFormatType->type != PRFMT_UNKNOWN)
- {
- /* Even though we are returning successfully, keep track of
- whether an illegal sequence was encountered and skipped.
- */
- pFormatType->fHasIllegalType = fContainsIllegalSequence;
-
- ulLen = (ulIdx - pFormatType->ulSpecifierIdx) + ulTypeLen;
- break;
- }
-
- /* In the case of an unrecognized type string, simply ignore
- it entirely. Reset the pointer to the position following
- the percent sign, so it is not found again.
- */
- fContainsIllegalSequence = false;
- ulIdx = pFormatType->ulSpecifierIdx + 1U;
- }
- }
-
- return ulLen;
-}
-
-
-/** @brief Parse a RedPrintf() format type string to determine the proper data
- type.
-
- @param pszFormat The format string to process. This must be a pointer to
- the character following any width or justification
- characters.
- @param pulTypeLen The location in which to store the type length. The
- value will be 0 if PRFMT_UNKNOWN is returned.
-
- @return Rhe PRFMT_* type value, or PRFMT_UNKNOWN if the type is not
- recognized.
-*/
-static PRINTTYPE ParseFormatType(
- const char *pszFormat,
- uint32_t *pulTypeLen)
-{
- PRINTTYPE fmtType = PRFMT_UNKNOWN;
- uint32_t ulIdx = 0U;
-
- switch(pszFormat[ulIdx])
- {
- case '%':
- fmtType = PRFMT_DOUBLEPERCENT;
- break;
- case 'c':
- fmtType = PRFMT_CHAR;
- break;
- case 's':
- fmtType = PRFMT_ANSISTRING;
- break;
- case 'p':
- fmtType = PRFMT_POINTER;
- break;
- case 'd':
- fmtType = MAPINT;
- break;
- case 'u':
- fmtType = MAPUINT;
- break;
- case 'x':
- fmtType = MAPHEXUINT;
- break;
- case 'h':
- {
- ulIdx++;
- switch(pszFormat[ulIdx])
- {
- case 'd':
- fmtType = MAPSHORT;
- break;
- case 'u':
- fmtType = MAPUSHORT;
- break;
- case 'x':
- fmtType = MAPHEXUSHORT;
- break;
- default:
- break;
- }
- break;
- }
- case 'l':
- {
- ulIdx++;
- switch(pszFormat[ulIdx])
- {
- case 'd':
- fmtType = MAPLONG;
- break;
- case 'u':
- fmtType = MAPULONG;
- break;
- case 'x':
- fmtType = MAPHEXULONG;
- break;
- case 'l':
- {
- ulIdx++;
- switch(pszFormat[ulIdx])
- {
- case 'd':
- fmtType = MAPLONGLONG;
- break;
- case 'u':
- fmtType = MAPULONGLONG;
- break;
- case 'x':
- case 'X':
- fmtType = MAPHEXULONGLONG;
- break;
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
-
- if(fmtType != PRFMT_UNKNOWN)
- {
- *pulTypeLen = ulIdx + 1U;
- }
- else
- {
- *pulTypeLen = 0U;
- }
-
- return fmtType;
-}
-
-
-/** @brief Format a signed 32-bit integer as a base 10 ASCII string.
-
- @note If the output buffer length is exhausted, the result will *not* be
- null-terminated.
-
- @note If the @p ulFillLen value is greater than or equal to the buffer
- length, the result will not be null-terminated, even if the
- formatted portion of the data is shorter than the buffer length.
-
- @param pcBuffer The output buffer
- @param ulBufferLen A pointer to the output buffer length
- @param lNum The 32-bit signed number to convert
- @param ulFillLen The fill length, if any
- @param cFill The fill character to use
-
- @return The length of the string.
-*/
-static uint32_t LtoA(
- char *pcBuffer,
- uint32_t ulBufferLen,
- int32_t lNum,
- uint32_t ulFillLen,
- char cFill)
-{
- uint32_t ulLen;
-
- if(pcBuffer == NULL)
- {
- REDERROR();
- ulLen = 0U;
- }
- else
- {
- char ach[12U]; /* big enough for a int32_t in base 10 */
- uint32_t ulDigits = 0U;
- uint32_t ulNum;
- bool fSign;
-
- if(lNum < 0)
- {
- fSign = true;
- ulNum = (uint32_t)-lNum;
- }
- else
- {
- fSign = false;
- ulNum = (uint32_t)lNum;
- }
-
- do
- {
- ach[ulDigits] = gacDigits[ulNum % 10U];
- ulNum = ulNum / 10U;
- ulDigits++;
- }
- while(ulNum);
-
- if(fSign)
- {
- ach[ulDigits] = '-';
- ulDigits++;
- }
-
- ulLen = FinishToA(ach, ulDigits, pcBuffer, ulBufferLen, ulFillLen, cFill);
- }
-
- return ulLen;
-}
-
-
-/** @brief Format a signed 64-bit integer as a base 10 ASCII string.
-
- @note If the output buffer length is exhausted, the result will *not* be
- null-terminated.
-
- @note If the @p ulFillLen value is greater than or equal to the buffer
- length, the result will not be null-terminated, even if the
- formatted portion of the data is shorter than the buffer length.
-
- @param pcBuffer The output buffer
- @param ulBufferLen A pointer to the output buffer length
- @param llNum The 64-bit signed number to convert
- @param ulFillLen The fill length, if any
- @param cFill The fill character to use
-
- @return The length of the string.
-*/
-static uint32_t LLtoA(
- char *pcBuffer,
- uint32_t ulBufferLen,
- int64_t llNum,
- uint32_t ulFillLen,
- char cFill)
-{
- uint32_t ulLen;
-
- if(pcBuffer == NULL)
- {
- REDERROR();
- ulLen = 0U;
- }
- else
- {
- char ach[12U]; /* big enough for a int32_t in base 10 */
- uint32_t ulDigits = 0U;
- uint64_t ullNum;
- bool fSign;
-
- if(llNum < 0)
- {
- fSign = true;
- ullNum = (uint64_t)-llNum;
- }
- else
- {
- fSign = false;
- ullNum = (uint64_t)llNum;
- }
-
- /* Not allowed to assume that 64-bit division is OK, so use a
- software division routine.
- */
- do
- {
- uint64_t ullQuotient;
- uint32_t ulRemainder;
-
- /* Note: RedUint64DivMod32() is smart enough to use normal division
- once ullNumericVal <= UINT32_MAX.
- */
- ullQuotient = RedUint64DivMod32(ullNum, 10U, &ulRemainder);
-
- ach[ulDigits] = gacDigits[ulRemainder];
- ullNum = ullQuotient;
- ulDigits++;
- }
- while(ullNum > 0U);
-
- if(fSign)
- {
- ach[ulDigits] = '-';
- ulDigits++;
- }
-
- ulLen = FinishToA(ach, ulDigits, pcBuffer, ulBufferLen, ulFillLen, cFill);
- }
-
- return ulLen;
-}
-
-
-/** @brief Format an unsigned 32-bit integer as an ASCII string as decimal or
- hex.
-
- @note If the output buffer length is exhausted, the result will *not* be
- null-terminated.
-
- @param pcBuffer The output buffer
- @param ulBufferLen The output buffer length
- @param ulNum The 32-bit unsigned number to convert
- @param fHex If true, format as hex; if false, decimal.
- @param ulFillLen The fill length, if any
- @param cFill The fill character to use
-
- @return The length of the string.
-*/
-static uint32_t ULtoA(
- char *pcBuffer,
- uint32_t ulBufferLen,
- uint32_t ulNum,
- bool fHex,
- uint32_t ulFillLen,
- char cFill)
-{
- uint32_t ulLen;
-
- if(pcBuffer == NULL)
- {
- REDERROR();
- ulLen = 0U;
- }
- else
- {
- char ach[11U]; /* Big enough for a uint32_t in radix 10 */
- uint32_t ulDigits = 0U;
- uint32_t ulNumericVal = ulNum;
- uint32_t ulRadix = fHex ? 16U : 10U;
-
- do
- {
- ach[ulDigits] = gacDigits[ulNumericVal % ulRadix];
- ulNumericVal = ulNumericVal / ulRadix;
- ulDigits++;
- }
- while(ulNumericVal > 0U);
-
- ulLen = FinishToA(ach, ulDigits, pcBuffer, ulBufferLen, ulFillLen, cFill);
- }
-
- return ulLen;
-}
-
-
-/** @brief Format an unsigned 64-bit integer as an ASCII string as decimal or
- hex.
-
- @note If the output buffer length is exhausted, the result will *not* be
- null-terminated.
-
- @param pcBuffer The output buffer.
- @param ulBufferLen The output buffer length.
- @param ullNum The unsigned 64-bit number to convert.
- @param fHex If true, format as hex; if false, decimal.
- @param ulFillLen The fill length, if any.
- @param cFill The fill character to use.
-
- @return The length of the string.
-*/
-static uint32_t ULLtoA(
- char *pcBuffer,
- uint32_t ulBufferLen,
- uint64_t ullNum,
- bool fHex,
- uint32_t ulFillLen,
- char cFill)
-{
- uint32_t ulLen;
-
- if(pcBuffer == NULL)
- {
- REDERROR();
- ulLen = 0U;
- }
- else
- {
-
- char ach[21U]; /* Big enough for a uint64_t in radix 10 */
- uint32_t ulDigits = 0U;
- uint64_t ullNumericVal = ullNum;
-
- if(fHex)
- {
- /* We can figure out the digits using bit operations.
- */
- do
- {
- ach[ulDigits] = gacDigits[ullNumericVal & 15U];
- ullNumericVal >>= 4U;
- ulDigits++;
- }
- while(ullNumericVal > 0U);
- }
- else
- {
- /* Not allowed to assume that 64-bit division is OK, so use a
- software division routine.
- */
- do
- {
- uint64_t ullQuotient;
- uint32_t ulRemainder;
-
- /* Note: RedUint64DivMod32() is smart enough to use normal division
- once ullNumericVal <= UINT32_MAX.
- */
- ullQuotient = RedUint64DivMod32(ullNumericVal, 10U, &ulRemainder);
-
- ach[ulDigits] = gacDigits[ulRemainder];
- ullNumericVal = ullQuotient;
- ulDigits++;
- }
- while(ullNumericVal > 0U);
- }
-
- ulLen = FinishToA(ach, ulDigits, pcBuffer, ulBufferLen, ulFillLen, cFill);
- }
-
- return ulLen;
-}
-
-
-/** @brief Finish converting a number into an ASCII string representing that
- number.
-
- This helper function contains common logic that needs to run at the end of
- all the "toA" functions. It adds the fill character and reverses the digits
- string.
-
- @param pcDigits The digits (and sign) for the ASCII string, in reverse
- order as they were computed.
- @param ulDigits The number of digit characters.
- @param pcOutBuffer The output buffer.
- @param ulBufferLen The length of the output buffer.
- @param ulFillLen The fill length. If the number string is shorter than
- this, the remaining bytes are filled with @p cFill.
- @param cFill The fill character.
-
- @return The length of @p pcOutBuffer.
-*/
-static uint32_t FinishToA(
- const char *pcDigits,
- uint32_t ulDigits,
- char *pcOutBuffer,
- uint32_t ulBufferLen,
- uint32_t ulFillLen,
- char cFill)
-{
- uint32_t ulIdx = 0U;
- uint32_t ulDigitIdx = ulDigits;
-
- /* user may have asked for a fill char
- */
- if(ulFillLen > ulDigits)
- {
- uint32_t ulFillRem = ulFillLen - ulDigits;
-
- while((ulFillRem > 0U) && (ulIdx < ulBufferLen))
- {
- pcOutBuffer[ulIdx] = cFill;
- ulIdx++;
- ulFillRem--;
- }
- }
-
- /* reverse the string
- */
- while((ulDigitIdx > 0) && (ulIdx < ulBufferLen))
- {
- ulDigitIdx--;
- pcOutBuffer[ulIdx] = pcDigits[ulDigitIdx];
- ulIdx++;
- }
-
- if(ulIdx < ulBufferLen)
- {
- pcOutBuffer[ulIdx] = '\0';
- }
-
- return ulIdx;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/rand.c b/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/rand.c
deleted file mode 100755
index 6dd4430..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/tests/util/rand.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
-
- Copyright (c) 2014-2015 Datalight, Inc.
- All Rights Reserved Worldwide.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; use version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* Businesses and individuals that for commercial or other reasons cannot
- comply with the terms of the GPLv2 license may obtain a commercial license
- before incorporating Reliance Edge into proprietary software for
- distribution in any form. Visit http://www.datalight.com/reliance-edge for
- more information.
-*/
-/** @file
- @brief Implements a random number generator.
-*/
-#include
-#include
-
-
-/* This is the global seed used by the random number generator when the caller
- has not provided a seed to either the RedRand32() or RedRand64() functions.
-*/
-static uint64_t ullGlobalRandomNumberSeed;
-
-/* Whether the above seed has been initialized.
-*/
-static bool fGlobalSeedInited;
-
-
-/** @brief Set the global seed used by the random number generator.
-
- The global seed gets used when RedRand64() or RedRand32() are called with
- a NULL seed argument.
-
- @param ullSeed The value to use as the global RNG seed.
-*/
-void RedRandSeed(
- uint64_t ullSeed)
-{
- ullGlobalRandomNumberSeed = ullSeed;
- fGlobalSeedInited = true;
-}
-
-
-/** @brief Generate a 64-bit pseudo-random number.
-
- The period of this random number generator is 2^64 (1.8 x 1019). These
- parameters are the same as the default one-stream SPRNG lcg64 generator and
- it satisfies the requirements for a maximal period.
-
- The tempering value is used and an AND mask and is specifically selected to
- favor the distribution of lower bits.
-
- @param pullSeed A pointer to the seed to use. Set this value to NULL to
- use the internal global seed value.
-
- @return A pseudo-random number in the range [0, UINT64_MAX].
-*/
-uint64_t RedRand64(
- uint64_t *pullSeed)
-{
- const uint64_t ullA = UINT64_SUFFIX(2862933555777941757);
- const uint64_t ullC = UINT64_SUFFIX(3037000493);
- const uint64_t ullT = UINT64_SUFFIX(4921441182957829599);
- uint64_t ullN;
- uint64_t *pullSeedPtr;
- uint64_t ullLocalSeed;
-
- if(pullSeed != NULL)
- {
- ullLocalSeed = *pullSeed;
- pullSeedPtr = pullSeed;
- }
- else
- {
- if(!fGlobalSeedInited)
- {
- /* Unfortunately, the Reliance Edge OS services don't give us much
- to work with to initialize the global seed. There is no entropy
- abstraction, no tick count abstraction, and the timestamp
- abstraction uses an opaque type which is not guaranteed to be an
- integer. The best we can do is use the RTC.
-
- Tests using the RNG should be supplying a seed anyway, for
- reproducibility.
- */
- RedRandSeed((uint64_t)RedOsClockGetTime());
- }
-
- ullLocalSeed = ullGlobalRandomNumberSeed;
- pullSeedPtr = &ullGlobalRandomNumberSeed;
- }
-
- ullN = (ullLocalSeed * ullA) + ullC;
-
- *pullSeedPtr = ullN;
-
- /* The linear congruential generator used above produces good psuedo-random
- 64-bit number sequences, however, as with any LCG, the period of the
- lower order bits is much shorter resulting in alternately odd/even pairs
- in bit zero.
-
- The result of the LGC above is tempered below with a series of XOR and
- shift operations to produce a more acceptable equidistribution of bits
- throughout the 64-bit range.
- */
- ullN ^= (ullN >> 21U) & ullT;
- ullN ^= (ullN >> 43U) & ullT;
- ullN ^= (ullN << 23U) & ~ullT;
- ullN ^= (ullN << 31U) & ~ullT;
-
- return ullN;
-}
-
-
-/** @brief Generate a 32-bit pseudo-random number.
-
- @note The 32-bit random number generator internally uses the 64-bit random
- number generator, returning the low 32-bits of the pseudo-random
- 64-bit value.
-
- @param pulSeed A pointer to the seed to use. Set this value to NULL to use
- the internal global seed value.
-
- @return A pseudo-random number in the range [0, UINT32_MAX].
-*/
-uint32_t RedRand32(
- uint32_t *pulSeed)
-{
- uint64_t ullN;
-
- if(pulSeed != NULL)
- {
- uint64_t ullLocalSeed;
-
- ullLocalSeed = *pulSeed;
- ullN = RedRand64(&ullLocalSeed);
- *pulSeed = (uint32_t)ullLocalSeed;
- }
- else
- {
- ullN = RedRand64(NULL);
- }
-
- return (uint32_t)ullN;
-}
-
diff --git a/FreeRTOS-Plus/Source/Reliance-Edge/toolcmn/getopt.c b/FreeRTOS-Plus/Source/Reliance-Edge/toolcmn/getopt.c
deleted file mode 100755
index 613d331..0000000
--- a/FreeRTOS-Plus/Source/Reliance-Edge/toolcmn/getopt.c
+++ /dev/null
@@ -1,559 +0,0 @@
-/*
- * Copyright (c) 2002 Todd C. Miller
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-/*-
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dieter Baron and Thomas Klausner.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-/** @file
- @brief Implementations of getopt() and getopt_long() work-alike functions.
-
- This code was taken from FreeBSD and slightly modified, mostly to rename
- symbols with external linkage to avoid naming conflicts in systems where
- there are real getopt()/getopt_long() implementations, and for portability.
-*/
-#include
-#include
-#include