aboutsummaryrefslogtreecommitdiffhomepage
path: root/workspace
diff options
context:
space:
mode:
authorBen V. Brown <[email protected]>2020-12-11 19:11:23 +1100
committerBen V. Brown <[email protected]>2020-12-11 19:11:23 +1100
commitb63f02d033af9154d768091154a85eb808cfd11f (patch)
tree702c611417e6c96cb50be422c93debf96f59c3e0 /workspace
parent120a0502d6065b0b4b6c598b1de4ce5b18a6596c (diff)
downloadIronOS-b63f02d033af9154d768091154a85eb808cfd11f.tar.gz
IronOS-b63f02d033af9154d768091154a85eb808cfd11f.zip
Reset some encodings
Diffstat (limited to 'workspace')
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP_Common.c0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP_Flash.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP_PD.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP_Power.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/BSP_QC.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/BSP/Defines.h0
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/NMSIS/Core/Include/riscv_bits.h88
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h106
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/gd32vf103v_eval.h48
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/nuclei_sdk_hal.h19
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/GCC/gcc_gd32vf103_flashxip.ld284
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/gd32vf103v_eval.c39
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/openocd_gd32vf103.cfg47
-rw-r--r--workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/pinecil/openocd_gd32vf103.cfg2
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/BMA223.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/BMA223.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/BMA223_defines.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Buttons.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Buttons.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/fusb302b.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/fusbpd.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/int_n.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/int_n.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/pd.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/pdb_conf.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/pdb_msg.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp1049
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/policy_engine.h241
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/protocol_rx.cpp221
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/protocol_rx.h53
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/protocol_tx.cpp383
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/FUSB302/protocol_tx.h116
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Font.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/I2CBB.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/I2CBB.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/I2C_Wrapper.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/LIS2DH12.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/LIS2DH12.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/LIS2DH12_defines.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/MMA8652FC.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/MMA8652FC.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/MMA8652FC_defines.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/OLED.cpp42
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/OLED.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/README.md0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Si7210.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Si7210.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/Si7210_defines.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/TipThermoModel.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Drivers/TipThermoModel.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/FreeRTOSHooks.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/QC3.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/Settings.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/Translation.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/configuration.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/expMovingAverage.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/gui.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/history.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/main.hpp2
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/power.hpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/stm32f1xx_hal_conf.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Inc/stm32f1xx_it.h0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/FreeRTOSHooks.c0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/QC3.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/Settings.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/freertos.c0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/gui.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/main.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/power.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Src/syscalls.c0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Threads/GUIThread.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Threads/MOVThread.cpp0
-rwxr-xr-x[-rw-r--r--]workspace/TS100/Core/Threads/PIDThread.cpp0
76 files changed, 1609 insertions, 1131 deletions
diff --git a/workspace/TS100/Core/BSP/BSP.h b/workspace/TS100/Core/BSP/BSP.h
index 6bce9d44..6bce9d44 100644..100755
--- a/workspace/TS100/Core/BSP/BSP.h
+++ b/workspace/TS100/Core/BSP/BSP.h
diff --git a/workspace/TS100/Core/BSP/BSP_Common.c b/workspace/TS100/Core/BSP/BSP_Common.c
index 67a76d18..67a76d18 100644..100755
--- a/workspace/TS100/Core/BSP/BSP_Common.c
+++ b/workspace/TS100/Core/BSP/BSP_Common.c
diff --git a/workspace/TS100/Core/BSP/BSP_Flash.h b/workspace/TS100/Core/BSP/BSP_Flash.h
index d03ecd33..d03ecd33 100644..100755
--- a/workspace/TS100/Core/BSP/BSP_Flash.h
+++ b/workspace/TS100/Core/BSP/BSP_Flash.h
diff --git a/workspace/TS100/Core/BSP/BSP_PD.h b/workspace/TS100/Core/BSP/BSP_PD.h
index c38f13c9..c38f13c9 100644..100755
--- a/workspace/TS100/Core/BSP/BSP_PD.h
+++ b/workspace/TS100/Core/BSP/BSP_PD.h
diff --git a/workspace/TS100/Core/BSP/BSP_Power.h b/workspace/TS100/Core/BSP/BSP_Power.h
index 5b277a21..5b277a21 100644..100755
--- a/workspace/TS100/Core/BSP/BSP_Power.h
+++ b/workspace/TS100/Core/BSP/BSP_Power.h
diff --git a/workspace/TS100/Core/BSP/BSP_QC.h b/workspace/TS100/Core/BSP/BSP_QC.h
index d1536a09..d1536a09 100644..100755
--- a/workspace/TS100/Core/BSP/BSP_QC.h
+++ b/workspace/TS100/Core/BSP/BSP_QC.h
diff --git a/workspace/TS100/Core/BSP/Defines.h b/workspace/TS100/Core/BSP/Defines.h
index 2392b7bf..2392b7bf 100644..100755
--- a/workspace/TS100/Core/BSP/Defines.h
+++ b/workspace/TS100/Core/BSP/Defines.h
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/NMSIS/Core/Include/riscv_bits.h b/workspace/TS100/Core/BSP/Pine64/Vendor/NMSIS/Core/Include/riscv_bits.h
index 1c8ba804..a18c1686 100644
--- a/workspace/TS100/Core/BSP/Pine64/Vendor/NMSIS/Core/Include/riscv_bits.h
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/NMSIS/Core/Include/riscv_bits.h
@@ -19,73 +19,71 @@
#define __RISCV_BITS_H__
#ifdef __cplusplus
-extern "C" {
+ extern "C" {
#endif
#if __riscv_xlen == 64
-#define SLL32 sllw
-#define STORE sd
-#define LOAD ld
-#define LWU lwu
-#define LOG_REGBYTES 3
+# define SLL32 sllw
+# define STORE sd
+# define LOAD ld
+# define LWU lwu
+# define LOG_REGBYTES 3
#else
-#define SLL32 sll
-#define STORE sw
-#define LOAD lw
-#define LWU lw
-#define LOG_REGBYTES 2
+# define SLL32 sll
+# define STORE sw
+# define LOAD lw
+# define LWU lw
+# define LOG_REGBYTES 2
#endif /* __riscv_xlen */
#define REGBYTES (1 << LOG_REGBYTES)
-#ifndef __riscv_flen
-#define __riscv_flen 32
-#endif
+
#if __riscv_flen == 64
-#define FPSTORE fsd
-#define FPLOAD fld
-#define LOG_FPREGBYTES 3
+# define FPSTORE fsd
+# define FPLOAD fld
+# define LOG_FPREGBYTES 3
#else
-#define FPSTORE fsw
-#define FPLOAD flw
-#define LOG_FPREGBYTES 2
+# define FPSTORE fsw
+# define FPLOAD flw
+# define LOG_FPREGBYTES 2
#endif /* __riscv_flen */
-#define FPREGBYTES (1 << LOG_FPREGBYTES)
+#define FPREGBYTES (1 << LOG_FPREGBYTES)
-#define __rv_likely(x) __builtin_expect((x), 1)
-#define __rv_unlikely(x) __builtin_expect((x), 0)
+#define __rv_likely(x) __builtin_expect((x), 1)
+#define __rv_unlikely(x) __builtin_expect((x), 0)
-#define __RV_ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
-#define __RV_ROUNDDOWN(a, b) ((a) / (b) * (b))
+#define __RV_ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b))
+#define __RV_ROUNDDOWN(a, b) ((a)/(b)*(b))
-#define __RV_MAX(a, b) ((a) > (b) ? (a) : (b))
-#define __RV_MIN(a, b) ((a) < (b) ? (a) : (b))
-#define __RV_CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
+#define __RV_MAX(a, b) ((a) > (b) ? (a) : (b))
+#define __RV_MIN(a, b) ((a) < (b) ? (a) : (b))
+#define __RV_CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
-#define __RV_EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
-#define __RV_INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
+#define __RV_EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
+#define __RV_INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
#ifdef __ASSEMBLY__
-#define _AC(X, Y) X
-#define _AT(T, X) X
+#define _AC(X,Y) X
+#define _AT(T,X) X
#else
-#define __AC(X, Y) (X##Y)
-#define _AC(X, Y) __AC(X, Y)
-#define _AT(T, X) ((T)(X))
+#define __AC(X,Y) (X##Y)
+#define _AC(X,Y) __AC(X,Y)
+#define _AT(T,X) ((T)(X))
#endif /* __ASSEMBLY__ */
-#define _UL(x) (_AC(x, UL))
-#define _ULL(x) (_AC(x, ULL))
+#define _UL(x) (_AC(x, UL))
+#define _ULL(x) (_AC(x, ULL))
-#define _BITUL(x) (_UL(1) << (x))
-#define _BITULL(x) (_ULL(1) << (x))
+#define _BITUL(x) (_UL(1) << (x))
+#define _BITULL(x) (_ULL(1) << (x))
-#define UL(x) (_UL(x))
-#define ULL(x) (_ULL(x))
+#define UL(x) (_UL(x))
+#define ULL(x) (_ULL(x))
-#define STR(x) XSTR(x)
-#define XSTR(x) #x
-#define __STR(s) #s
-#define STRINGIFY(s) __STR(s)
+#define STR(x) XSTR(x)
+#define XSTR(x) #x
+#define __STR(s) #s
+#define STRINGIFY(s) __STR(s)
#ifdef __cplusplus
}
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h b/workspace/TS100/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h
index a5da9514..d6429ee8 100644
--- a/workspace/TS100/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h
@@ -25,6 +25,7 @@
* 1 tab == 4 spaces!
*/
+
#ifndef PORTMACRO_H
#define PORTMACRO_H
@@ -45,92 +46,90 @@ extern "C" {
*/
/* Type definitions. */
-#define portCHAR char
-#define portFLOAT float
-#define portDOUBLE double
-#define portLONG long
-#define portSHORT short
-#define portSTACK_TYPE unsigned long
-#define portBASE_TYPE long
-#define portPOINTER_SIZE_TYPE unsigned long
+#define portCHAR char
+#define portFLOAT float
+#define portDOUBLE double
+#define portLONG long
+#define portSHORT short
+#define portSTACK_TYPE unsigned long
+#define portBASE_TYPE long
+#define portPOINTER_SIZE_TYPE unsigned long
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
-#if (configUSE_16_BIT_TICKS == 1)
-typedef uint16_t TickType_t;
-#define portMAX_DELAY (TickType_t)0xffff
+#if( configUSE_16_BIT_TICKS == 1 )
+ typedef uint16_t TickType_t;
+ #define portMAX_DELAY ( TickType_t )0xffff
#else
-/* RISC-V TIMER is 64-bit long */
-typedef uint64_t TickType_t;
-#define portMAX_DELAY (TickType_t)0xFFFFFFFFFFFFFFFFULL
+ /* RISC-V TIMER is 64-bit long */
+ typedef uint64_t TickType_t;
+ #define portMAX_DELAY ( TickType_t )0xFFFFFFFFFFFFFFFFULL
#endif
/*-----------------------------------------------------------*/
/* Architecture specifics. */
-#define portSTACK_GROWTH (-1)
-#define portTICK_PERIOD_MS ((TickType_t)1000 / configTICK_RATE_HZ)
-#define portBYTE_ALIGNMENT 8
+#define portSTACK_GROWTH ( -1 )
+#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
+#define portBYTE_ALIGNMENT 8
/*-----------------------------------------------------------*/
/* Scheduler utilities. */
-#define portYIELD() \
- { \
- /* Set a software interrupt(SWI) request to request a context switch. */ \
- SysTimer_SetSWIRQ(); \
- /* Barriers are normally not required but do ensure the code is completely \
- within the specified behaviour for the architecture. */ \
- __RWMB(); \
- }
-
-#define portEND_SWITCHING_ISR(xSwitchRequired) \
- if (xSwitchRequired != pdFALSE) \
- portYIELD()
-#define portYIELD_FROM_ISR(x) portEND_SWITCHING_ISR(x)
+#define portYIELD() \
+{ \
+ /* Set a software interrupt(SWI) request to request a context switch. */ \
+ SysTimer_SetSWIRQ(); \
+ /* Barriers are normally not required but do ensure the code is completely \
+ within the specified behaviour for the architecture. */ \
+ __RWMB(); \
+}
+
+#define portEND_SWITCHING_ISR( xSwitchRequired ) if ( xSwitchRequired != pdFALSE ) portYIELD()
+#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
/*-----------------------------------------------------------*/
/* Critical section management. */
-extern void vPortEnterCritical(void);
-extern void vPortExitCritical(void);
+extern void vPortEnterCritical( void );
+extern void vPortExitCritical( void );
-#define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
-#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
-#define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
-#define portENABLE_INTERRUPTS() vPortSetBASEPRI(0)
-#define portENTER_CRITICAL() vPortEnterCritical()
-#define portEXIT_CRITICAL() vPortExitCritical()
+#define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
+#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
+#define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
+#define portENABLE_INTERRUPTS() vPortSetBASEPRI(0)
+#define portENTER_CRITICAL() vPortEnterCritical()
+#define portEXIT_CRITICAL() vPortExitCritical()
/*-----------------------------------------------------------*/
/* Task function macros as described on the FreeRTOS.org WEB site. These are
not necessary for to use this port. They are defined so the common demo files
(which build with all the ports) will build. */
-#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters)
-#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void *pvParameters)
+#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
+#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
/*-----------------------------------------------------------*/
/* Tickless idle/low power functionality. */
#ifndef portSUPPRESS_TICKS_AND_SLEEP
-extern void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime);
-#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vPortSuppressTicksAndSleep(xExpectedIdleTime)
+ extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
+ #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )
#endif
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
#ifdef configASSERT
-extern void vPortValidateInterruptPriority(void);
-#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
+ extern void vPortValidateInterruptPriority( void );
+ #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
#endif
/* portNOP() is not required by this port. */
-#define portNOP() __NOP()
+#define portNOP() __NOP()
-#define portINLINE __inline
+#define portINLINE __inline
#ifndef portFORCE_INLINE
-#define portFORCE_INLINE inline __attribute__((always_inline))
+ #define portFORCE_INLINE inline __attribute__(( always_inline))
#endif
/* This variable should not be set in any of the FreeRTOS application
@@ -138,14 +137,16 @@ extern void vPortValidateInterruptPriority(void);
extern uint8_t uxMaxSysCallMTH;
/*-----------------------------------------------------------*/
-portFORCE_INLINE static void vPortRaiseBASEPRI(void) {
+portFORCE_INLINE static void vPortRaiseBASEPRI( void )
+{
ECLIC_SetMth(uxMaxSysCallMTH);
__RWMB();
}
/*-----------------------------------------------------------*/
-portFORCE_INLINE static uint8_t ulPortRaiseBASEPRI(void) {
+portFORCE_INLINE static uint8_t ulPortRaiseBASEPRI( void )
+{
uint8_t ulOriginalBASEPRI;
ulOriginalBASEPRI = ECLIC_GetMth();
@@ -158,17 +159,18 @@ portFORCE_INLINE static uint8_t ulPortRaiseBASEPRI(void) {
}
/*-----------------------------------------------------------*/
-portFORCE_INLINE static void vPortSetBASEPRI(uint8_t ulNewMaskValue) {
+portFORCE_INLINE static void vPortSetBASEPRI( uint8_t ulNewMaskValue )
+{
ECLIC_SetMth(ulNewMaskValue);
__RWMB();
}
/*-----------------------------------------------------------*/
-#define portMEMORY_BARRIER() __asm volatile("" :: \
- : "memory")
+#define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
#ifdef __cplusplus
}
#endif
#endif /* PORTMACRO_H */
+
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/gd32vf103v_eval.h b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/gd32vf103v_eval.h
new file mode 100644
index 00000000..88957f51
--- /dev/null
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/gd32vf103v_eval.h
@@ -0,0 +1,48 @@
+/*!
+ \file gd32vf103v_eval.h
+ \brief definitions for GD32VF103V_EVAL's leds, keys and COM ports hardware resources
+
+ \version 2019-6-5, V1.0.0, demo for GD32VF103
+*/
+
+/*
+ Copyright (c) 2019, GigaDevice Semiconductor Inc.
+
+ 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 the copyright holder 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.
+*/
+
+#ifndef GD32VF103V_EVAL_H
+#define GD32VF103V_EVAL_H
+
+#ifdef cplusplus
+ extern "C" {
+#endif
+
+#include "nuclei_sdk_soc.h"
+
+#ifdef cplusplus
+}
+#endif
+
+#endif /* GD32VF103V_EVAL_H */
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/nuclei_sdk_hal.h b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/nuclei_sdk_hal.h
new file mode 100644
index 00000000..fab446a7
--- /dev/null
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Include/nuclei_sdk_hal.h
@@ -0,0 +1,19 @@
+// See LICENSE for license details.
+#ifndef _NUCLEI_SDK_HAL_H
+#define _NUCLEI_SDK_HAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#include "gd32vf103v_eval.h"
+
+
+#ifndef NUCLEI_BANNER
+#define NUCLEI_BANNER 0
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/GCC/gcc_gd32vf103_flashxip.ld b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/GCC/gcc_gd32vf103_flashxip.ld
new file mode 100644
index 00000000..42b82a6d
--- /dev/null
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/GCC/gcc_gd32vf103_flashxip.ld
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2019 Nuclei Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/******************************************************************************
+ * @file gcc_Device.ld
+ * @brief GNU Linker Script for gd32vf103 based device
+ * @version V1.0.0
+ * @date 17. Dec 2019
+ ******************************************************************************/
+
+/*********** Use Configuration Wizard in Context Menu *************************/
+
+OUTPUT_ARCH( "riscv" )
+/********************* Flash Configuration ************************************
+ * <h> Flash Configuration
+ * <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
+ * <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
+ * </h>
+ */
+__ROM_BASE = 0x08000000;
+__ROM_SIZE = 0x00020000;
+
+/*--------------------- ILM RAM Configuration ---------------------------
+ * <h> ILM RAM Configuration
+ * <o0> ILM RAM Base Address <0x0-0xFFFFFFFF:8>
+ * <o1> ILM RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
+ * </h>
+ */
+__ILM_RAM_BASE = 0x80000000;
+__ILM_RAM_SIZE = 0x00010000;
+
+/*--------------------- Embedded RAM Configuration ---------------------------
+ * <h> RAM Configuration
+ * <o0> RAM Base Address <0x0-0xFFFFFFFF:8>
+ * <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
+ * </h>
+*/
+__RAM_BASE = 0x20000000;
+__RAM_SIZE = 0x00005000;
+
+/********************* Stack / Heap Configuration ****************************
+ * <h> Stack / Heap Configuration
+ * <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
+ * <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
+ * </h>
+ */
+__STACK_SIZE = 0x00000800;
+__HEAP_SIZE = 0x00000800;
+
+/**************************** end of configuration section ********************/
+
+/* Define base address and length of flash and ram */
+MEMORY
+{
+ flash (rxai!w) : ORIGIN = __ROM_BASE, LENGTH = __ROM_SIZE
+ ram (wxa!ri) : ORIGIN = __RAM_BASE, LENGTH = __RAM_SIZE
+}
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH,ILM and RAM.
+ * It references following symbols, which must be defined in code:
+ * _Start : Entry of reset handler
+ *
+ * It defines following symbols, which code can use without definition:
+ * _ilm_lma
+ * _ilm
+ * __etext
+ * _etext
+ * etext
+ * _eilm
+ * __preinit_array_start
+ * __preinit_array_end
+ * __init_array_start
+ * __init_array_end
+ * __fini_array_start
+ * __fini_array_end
+ * _data_lma
+ * _edata
+ * edata
+ * __data_end__
+ * __bss_start
+ * __fbss
+ * _end
+ * end
+ * __heap_end
+ * __StackLimit
+ * __StackTop
+ * __STACK_SIZE
+ */
+/* Define entry label of program */
+ENTRY(_start)
+SECTIONS
+{
+ __STACK_SIZE = DEFINED(__STACK_SIZE) ? __STACK_SIZE : 2K;
+
+ .init :
+ {
+ /* vector table locate at flash */
+ *(.vtable)
+ KEEP (*(SORT_NONE(.init)))
+ } >flash AT>flash
+
+ .ilalign :
+ {
+ . = ALIGN(4);
+ /* Create a section label as _ilm_lma which located at flash */
+ PROVIDE( _ilm_lma = . );
+ } >flash AT>flash
+
+ .ialign :
+ {
+ /* Create a section label as _ilm which located at flash */
+ PROVIDE( _ilm = . );
+ } >flash AT>flash
+
+ /* Code section located at flash */
+ .text :
+ {
+ *(.text.unlikely .text.unlikely.*)
+ *(.text.startup .text.startup.*)
+ *(.text .text.*)
+ *(.gnu.linkonce.t.*)
+ } >flash AT>flash
+
+ .rodata : ALIGN(4)
+ {
+ . = ALIGN(4);
+ *(.rdata)
+ *(.rodata .rodata.*)
+ /* section information for initial. */
+ . = ALIGN(4);
+ __rt_init_start = .;
+ KEEP(*(SORT(.rti_fn*)))
+ __rt_init_end = .;
+ /* section information for finsh shell */
+ . = ALIGN(4);
+ __fsymtab_start = .;
+ KEEP(*(FSymTab))
+ __fsymtab_end = .;
+ . = ALIGN(4);
+ __vsymtab_start = .;
+ KEEP(*(VSymTab))
+ __vsymtab_end = .;
+ *(.gnu.linkonce.r.*)
+ . = ALIGN(8);
+ *(.srodata.cst16)
+ *(.srodata.cst8)
+ *(.srodata.cst4)
+ *(.srodata.cst2)
+ *(.srodata .srodata.*)
+ } >flash AT>flash
+
+ .fini :
+ {
+ KEEP (*(SORT_NONE(.fini)))
+ } >flash AT>flash
+
+ . = ALIGN(4);
+
+ PROVIDE (__etext = .);
+ PROVIDE (_etext = .);
+ PROVIDE (etext = .);
+ PROVIDE( _eilm = . );
+
+
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ } >flash AT>flash
+
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
+ KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ } >flash AT>flash
+
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
+ KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ } >flash AT>flash
+
+ .ctors :
+ {
+ /* gcc uses crtbegin.o to find the start of
+ * the constructors, so we make sure it is
+ * first. Because this is a wildcard, it
+ * doesn't matter if the user does not
+ * actually link against crtbegin.o; the
+ * linker won't look for a file to match a
+ * wildcard. The wildcard also means that it
+ * doesn't matter which directory crtbegin.o
+ * is in.
+ */
+ KEEP (*crtbegin.o(.ctors))
+ KEEP (*crtbegin?.o(.ctors))
+ /* We don't want to include the .ctor section from
+ * the crtend.o file until after the sorted ctors.
+ * The .ctor section from the crtend file contains the
+ * end of ctors marker and it must be last
+ */
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ } >flash AT>flash
+
+ .dtors :
+ {
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*crtbegin?.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ } >flash AT>flash
+
+ .lalign :
+ {
+ . = ALIGN(4);
+ PROVIDE( _data_lma = . );
+ } >flash AT>flash
+
+ .dalign :
+ {
+ . = ALIGN(4);
+ PROVIDE( _data = . );
+ } >ram AT>flash
+
+ /* Define data section virtual address is ram and physical address is flash */
+ .data :
+ {
+ *(.data .data.*)
+ *(.gnu.linkonce.d.*)
+ . = ALIGN(8);
+ PROVIDE( __global_pointer$ = . + 0x800 );
+ *(.sdata .sdata.* .sdata*)
+ *(.gnu.linkonce.s.*)
+ } >ram AT>flash
+
+ . = ALIGN(4);
+ PROVIDE( _edata = . );
+ PROVIDE( edata = . );
+
+ PROVIDE( _fbss = . );
+ PROVIDE( __bss_start = . );
+ .bss :
+ {
+ *(.sbss*)
+ *(.gnu.linkonce.sb.*)
+ *(.bss .bss.*)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN(4);
+ } >ram AT>ram
+
+ . = ALIGN(8);
+ PROVIDE( _end = . );
+ PROVIDE( end = . );
+ /* Define stack and head location at ram */
+ .stack ORIGIN(ram) + LENGTH(ram) - __STACK_SIZE :
+ {
+ PROVIDE( _heap_end = . );
+ . = __STACK_SIZE;
+ PROVIDE( _sp = . );
+ } >ram AT>ram
+}
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/gd32vf103v_eval.c b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/gd32vf103v_eval.c
new file mode 100644
index 00000000..127b2078
--- /dev/null
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/Source/gd32vf103v_eval.c
@@ -0,0 +1,39 @@
+/*!
+ \file gd32vf103v_eval.c
+ \brief firmware functions to manage leds, keys, COM ports
+
+ \version 2019-6-5, V1.0.0, demo for GD32VF103
+*/
+
+/*
+ Copyright (c) 2019, GigaDevice Semiconductor Inc.
+
+ 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 the copyright holder 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.
+*/
+
+#include "nuclei_sdk_hal.h"
+#include "gd32vf103_usart.h"
+#include "gd32vf103_gpio.h"
+#include "gd32vf103_exti.h"
+
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/openocd_gd32vf103.cfg b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/openocd_gd32vf103.cfg
new file mode 100644
index 00000000..4dfe1fe0
--- /dev/null
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/gd32vf103v_eval/openocd_gd32vf103.cfg
@@ -0,0 +1,47 @@
+adapter_khz 1000
+reset_config srst_only
+adapter_nsrst_assert_width 100
+
+interface cmsis-dap
+
+transport select jtag
+
+autoexit true
+
+set _CHIPNAME riscv
+jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x1e200a6d
+
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME riscv -chain-position $_TARGETNAME
+$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size 20480 -work-area-backup 0
+
+# Work-area is a space in RAM used for flash programming
+if { [info exists WORKAREASIZE] } {
+ set _WORKAREASIZE $WORKAREASIZE
+} else {
+ set _WORKAREASIZE 0x5000
+}
+
+# Allow overriding the Flash bank size
+if { [info exists FLASH_SIZE] } {
+ set _FLASH_SIZE $FLASH_SIZE
+} else {
+ # autodetect size
+ set _FLASH_SIZE 0
+}
+
+# flash size will be probed
+set _FLASHNAME $_CHIPNAME.flash
+
+flash bank $_FLASHNAME gd32vf103 0x08000000 0 0 0 $_TARGETNAME
+
+# Expose Nuclei self-defined CSRS range 770-800,835-850,1984-2032,2064-2070
+# See https://github.com/riscv/riscv-gnu-toolchain/issues/319#issuecomment-358397306
+# Then user can view the csr register value in gdb using: info reg csr775 for CSR MTVT(0x307)
+riscv expose_csrs 770-800,835-850,1984-2032,2064-2070
+
+riscv set_reset_timeout_sec 1
+
+init
+
+halt
diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/pinecil/openocd_gd32vf103.cfg b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/pinecil/openocd_gd32vf103.cfg
index 4dfe1fe0..23970612 100644
--- a/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/pinecil/openocd_gd32vf103.cfg
+++ b/workspace/TS100/Core/BSP/Pine64/Vendor/SoC/gd32vf103/Board/pinecil/openocd_gd32vf103.cfg
@@ -1,4 +1,4 @@
-adapter_khz 1000
+adapter_khz 4000
reset_config srst_only
adapter_nsrst_assert_width 100
diff --git a/workspace/TS100/Core/Drivers/BMA223.cpp b/workspace/TS100/Core/Drivers/BMA223.cpp
index 7cd08530..7cd08530 100644..100755
--- a/workspace/TS100/Core/Drivers/BMA223.cpp
+++ b/workspace/TS100/Core/Drivers/BMA223.cpp
diff --git a/workspace/TS100/Core/Drivers/BMA223.hpp b/workspace/TS100/Core/Drivers/BMA223.hpp
index 85fa8576..85fa8576 100644..100755
--- a/workspace/TS100/Core/Drivers/BMA223.hpp
+++ b/workspace/TS100/Core/Drivers/BMA223.hpp
diff --git a/workspace/TS100/Core/Drivers/BMA223_defines.h b/workspace/TS100/Core/Drivers/BMA223_defines.h
index c7322a56..c7322a56 100644..100755
--- a/workspace/TS100/Core/Drivers/BMA223_defines.h
+++ b/workspace/TS100/Core/Drivers/BMA223_defines.h
diff --git a/workspace/TS100/Core/Drivers/Buttons.cpp b/workspace/TS100/Core/Drivers/Buttons.cpp
index e252ab8c..e252ab8c 100644..100755
--- a/workspace/TS100/Core/Drivers/Buttons.cpp
+++ b/workspace/TS100/Core/Drivers/Buttons.cpp
diff --git a/workspace/TS100/Core/Drivers/Buttons.hpp b/workspace/TS100/Core/Drivers/Buttons.hpp
index d894bf18..d894bf18 100644..100755
--- a/workspace/TS100/Core/Drivers/Buttons.hpp
+++ b/workspace/TS100/Core/Drivers/Buttons.hpp
diff --git a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h
index 1276e276..1276e276 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp b/workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp
index f8624fbe..f8624fbe 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp
diff --git a/workspace/TS100/Core/Drivers/FUSB302/fusbpd.h b/workspace/TS100/Core/Drivers/FUSB302/fusbpd.h
index b48dfc4e..b48dfc4e 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/fusbpd.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/fusbpd.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp
index 9250b4a0..9250b4a0 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp
diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.h b/workspace/TS100/Core/Drivers/FUSB302/int_n.h
index 69c460f7..69c460f7 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/int_n.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/pd.h b/workspace/TS100/Core/Drivers/FUSB302/pd.h
index 60cbd26a..60cbd26a 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/pd.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/pd.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/pdb_conf.h b/workspace/TS100/Core/Drivers/FUSB302/pdb_conf.h
index c2ca0f3f..c2ca0f3f 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/pdb_conf.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/pdb_conf.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/pdb_msg.h b/workspace/TS100/Core/Drivers/FUSB302/pdb_msg.h
index 2cfea250..2cfea250 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/pdb_msg.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/pdb_msg.h
diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp
index 5abd62a4..fb726a8f 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp
@@ -16,11 +16,11 @@
*/
#include "policy_engine.h"
-#include "fusb302b.h"
+#include <stdbool.h>
#include "int_n.h"
-#include "protocol_tx.h"
#include <pd.h>
-#include <stdbool.h>
+#include "protocol_tx.h"
+#include "fusb302b.h"
bool PolicyEngine::pdNegotiationComplete;
int PolicyEngine::current_voltage_mv;
int PolicyEngine::_requested_voltage;
@@ -39,621 +39,654 @@ union pd_msg PolicyEngine::tempMessage;
union pd_msg PolicyEngine::_last_dpm_request;
PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup;
StaticQueue_t PolicyEngine::xStaticQueue;
-uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
+uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE
+ * sizeof(union pd_msg)];
QueueHandle_t PolicyEngine::messagesWaiting = NULL;
EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL;
StaticEventGroup_t PolicyEngine::xCreatedEventGroup;
void PolicyEngine::init() {
- messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
- sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
- //Create static thread at PDB_PRIO_PE priority
- osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize,
- TaskBuffer, &TaskControlBlock);
- TaskHandle = osThreadCreate(osThread(PolEng), NULL);
- xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
+ messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
+ sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
+ //Create static thread at PDB_PRIO_PE priority
+ osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize,
+ TaskBuffer, &TaskControlBlock);
+ TaskHandle = osThreadCreate(osThread(PolEng), NULL);
+ xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
}
void PolicyEngine::notify(uint32_t notification) {
- if (xEventGroupHandle != NULL) {
- xEventGroupSetBits(xEventGroupHandle, notification);
- }
+ if (xEventGroupHandle != NULL) {
+ xEventGroupSetBits(xEventGroupHandle, notification);
+ }
}
void PolicyEngine::pe_task(const void *arg) {
- (void)arg;
- //Internal thread loop
- hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK;
- /* Initialize the old_tcc_match */
- _old_tcc_match = -1;
- /* Initialize the pps_index */
- _pps_index = 8;
- /* Initialize the last_pps */
- _last_pps = 8;
-
- for (;;) {
- //Loop based on state
- switch (state) {
-
- case PESinkStartup:
- state = pe_sink_startup();
- break;
- case PESinkDiscovery:
- state = pe_sink_discovery();
- break;
- case PESinkWaitCap:
- state = pe_sink_wait_cap();
- break;
- case PESinkEvalCap:
- state = pe_sink_eval_cap();
- break;
- case PESinkSelectCap:
- state = pe_sink_select_cap();
- break;
- case PESinkTransitionSink:
- state = pe_sink_transition_sink();
- break;
- case PESinkReady:
- state = pe_sink_ready();
- break;
- case PESinkGetSourceCap:
- state = pe_sink_get_source_cap();
- break;
- case PESinkGiveSinkCap:
- state = pe_sink_give_sink_cap();
- break;
- case PESinkHardReset:
- state = pe_sink_hard_reset();
- break;
- case PESinkTransitionDefault:
- state = pe_sink_transition_default();
- break;
- case PESinkSoftReset:
- state = pe_sink_soft_reset();
- break;
- case PESinkSendSoftReset:
- state = pe_sink_send_soft_reset();
- break;
- case PESinkSendNotSupported:
- state = pe_sink_send_not_supported();
- break;
- case PESinkChunkReceived:
- state = pe_sink_chunk_received();
- break;
- case PESinkSourceUnresponsive:
- state = pe_sink_source_unresponsive();
- break;
- case PESinkNotSupportedReceived:
- state = pe_sink_not_supported_received();
- break;
- default:
- state = PESinkStartup;
- break;
- }
- }
+ (void) arg;
+//Internal thread loop
+ hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK;
+ /* Initialize the old_tcc_match */
+ _old_tcc_match = -1;
+ /* Initialize the pps_index */
+ _pps_index = 8;
+ /* Initialize the last_pps */
+ _last_pps = 8;
+
+ for (;;) {
+ //Loop based on state
+ switch (state) {
+
+ case PESinkStartup:
+ state = pe_sink_startup();
+ break;
+ case PESinkDiscovery:
+ state = pe_sink_discovery();
+ break;
+ case PESinkWaitCap:
+ state = pe_sink_wait_cap();
+ break;
+ case PESinkEvalCap:
+ state = pe_sink_eval_cap();
+ break;
+ case PESinkSelectCap:
+ state = pe_sink_select_cap();
+ break;
+ case PESinkTransitionSink:
+ state = pe_sink_transition_sink();
+ break;
+ case PESinkReady:
+ state = pe_sink_ready();
+ break;
+ case PESinkGetSourceCap:
+ state = pe_sink_get_source_cap();
+ break;
+ case PESinkGiveSinkCap:
+ state = pe_sink_give_sink_cap();
+ break;
+ case PESinkHardReset:
+ state = pe_sink_hard_reset();
+ break;
+ case PESinkTransitionDefault:
+ state = pe_sink_transition_default();
+ break;
+ case PESinkSoftReset:
+ state = pe_sink_soft_reset();
+ break;
+ case PESinkSendSoftReset:
+ state = pe_sink_send_soft_reset();
+ break;
+ case PESinkSendNotSupported:
+ state = pe_sink_send_not_supported();
+ break;
+ case PESinkChunkReceived:
+ state = pe_sink_chunk_received();
+ break;
+ case PESinkSourceUnresponsive:
+ state = pe_sink_source_unresponsive();
+ break;
+ case PESinkNotSupportedReceived:
+ state = pe_sink_not_supported_received();
+ break;
+ default:
+ state = PESinkStartup;
+ break;
+ }
+ }
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_startup() {
- /* We don't have an explicit contract currently */
- _explicit_contract = false;
+ /* We don't have an explicit contract currently */
+ _explicit_contract = false;
- //If desired could send an alert that PD is starting
+//If desired could send an alert that PD is starting
- /* No need to reset the protocol layer here. There are two ways into this
+ /* No need to reset the protocol layer here. There are two ways into this
* state: startup and exiting hard reset. On startup, the protocol layer
* is reset by the startup procedure. When exiting hard reset, the
* protocol layer is reset by the hard reset state machine. Since it's
* already done somewhere else, there's no need to do it again here. */
- return PESinkDiscovery;
+ return PESinkDiscovery;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_discovery() {
- /* Wait for VBUS. Since it's our only power source, we already know that
+ /* Wait for VBUS. Since it's our only power source, we already know that
* we have it, so just move on. */
- return PESinkWaitCap;
+ return PESinkWaitCap;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
- /* Fetch a message from the protocol layer */
- eventmask_t evt = 0;
- if (readMessage()) {
- evt = PDB_EVT_PE_MSG_RX_PEND;
- } else {
- evt = waitForEvent(
- PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
- //Wait for cap timeout
- PD_T_TYPEC_SINK_WAIT_CAP);
- }
- /* If we timed out waiting for Source_Capabilities, send a hard reset */
- if (evt == 0) {
- return PESinkHardReset;
- }
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkWaitCap;
- }
- /* If we're too hot, we shouldn't negotiate power yet */
- if (evt & PDB_EVT_PE_I_OVRTEMP) {
- return PESinkWaitCap;
- }
-
- /* If we got a message */
- if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) {
- /* Get the message */
- while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
- /* If we got a Source_Capabilities message, read it. */
- if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
- /* First, determine what PD revision we're using */
- if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
- /* If the other end is using at least version 3.0, we'll
+ /* Fetch a message from the protocol layer */
+ eventmask_t evt = 0;
+ if (readMessage()) {
+ evt = PDB_EVT_PE_MSG_RX_PEND;
+ } else {
+ evt = waitForEvent(
+ PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
+ //Wait for cap timeout
+ PD_T_TYPEC_SINK_WAIT_CAP);
+ }
+ /* If we timed out waiting for Source_Capabilities, send a hard reset */
+ if (evt == 0) {
+ return PESinkHardReset;
+ }
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkWaitCap;
+ }
+ /* If we're too hot, we shouldn't negotiate power yet */
+ if (evt & PDB_EVT_PE_I_OVRTEMP) {
+ return PESinkWaitCap;
+ }
+
+ /* If we got a message */
+ if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) {
+ /* Get the message */
+ while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
+ /* If we got a Source_Capabilities message, read it. */
+ if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES
+ && PD_NUMOBJ_GET(&tempMessage) > 0) {
+ /* First, determine what PD revision we're using */
+ if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
+ /* If the other end is using at least version 3.0, we'll
* use version 3.0. */
- if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) {
- hdr_template |= PD_SPECREV_3_0;
- /* Otherwise, use 2.0. Don't worry about the 1.0 case
+ if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) {
+ hdr_template |= PD_SPECREV_3_0;
+ /* Otherwise, use 2.0. Don't worry about the 1.0 case
* because we don't have hardware for PD 1.0 signaling. */
- } else {
- hdr_template |= PD_SPECREV_2_0;
- }
- }
- return PESinkEvalCap;
- /* If the message was a Soft_Reset, do the soft reset procedure */
- }
- evt = 0;
- }
- return PESinkWaitCap; //wait for more messages?
- }
-
- /* If we failed to get a message, send a hard reset */
- return PESinkHardReset;
+ } else {
+ hdr_template |= PD_SPECREV_2_0;
+ }
+ }
+ return PESinkEvalCap;
+ /* If the message was a Soft_Reset, do the soft reset procedure */
+ }
+ evt = 0;
+ }
+ return PESinkWaitCap; //wait for more messages?
+
+ }
+
+ /* If we failed to get a message, send a hard reset */
+ return PESinkHardReset;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() {
- /* If we have a Source_Capabilities message, remember the index of the
+ /* If we have a Source_Capabilities message, remember the index of the
* first PPS APDO so we can check if the request is for a PPS APDO in
* PE_SNK_Select_Cap. */
- /* Start by assuming we won't find a PPS APDO (set the index greater
+ /* Start by assuming we won't find a PPS APDO (set the index greater
* than the maximum possible) */
- _pps_index = 8;
- /* Search for the first PPS APDO */
- for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) {
- if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
- _pps_index = i + 1;
- break;
- }
- }
- /* New capabilities also means we can't be making a request from the
+ _pps_index = 8;
+ /* Search for the first PPS APDO */
+ for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) {
+ if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
+ && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
+ _pps_index = i + 1;
+ break;
+ }
+ }
+ /* New capabilities also means we can't be making a request from the
* same PPS APDO */
- _last_pps = 8;
+ _last_pps = 8;
- /* Ask the DPM what to request */
- if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) {
+ /* Ask the DPM what to request */
+ if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) {
- return PESinkSelectCap;
- }
+ return PESinkSelectCap;
+ }
- return PESinkWaitCap;
+ return PESinkWaitCap;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
- /* Transmit the request */
- waitForEvent(0xFFFF, 0); //clear pending
- ProtocolTransmit::pushMessage(&_last_dpm_request);
- //Send indication that there is a message pending
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET || evt == 0) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a hard reset */
- if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) {
- return PESinkHardReset;
- }
-
- /* Wait for a response */
- evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
- PD_T_SENDER_RESPONSE);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If we didn't get a response before the timeout, send a hard reset */
- if (evt == 0) {
- return PESinkHardReset;
- }
-
- /* Get the response message */
- if (messageWaiting()) {
- readMessage();
- /* If the source accepted our request, wait for the new power */
- if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkTransitionSink;
- /* If the message was a Soft_Reset, do the soft reset procedure */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
- return PESinkSoftReset;
- /* If the message was Wait or Reject */
- } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) {
- /* If we don't have an explicit contract, wait for capabilities */
- if (!_explicit_contract) {
- return PESinkWaitCap;
- /* If we do have an explicit contract, go to the ready state */
- } else {
- return PESinkReady;
- }
- } else {
- return PESinkSendSoftReset;
- }
- }
- return PESinkHardReset;
+ /* Transmit the request */
+ waitForEvent(0xFFFF, 0); //clear pending
+ ProtocolTransmit::pushMessage(&_last_dpm_request);
+ //Send indication that there is a message pending
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET || evt == 0) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a hard reset */
+ if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) {
+ return PESinkHardReset;
+ }
+
+ /* Wait for a response */
+ evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
+ PD_T_SENDER_RESPONSE);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If we didn't get a response before the timeout, send a hard reset */
+ if (evt == 0) {
+ return PESinkHardReset;
+ }
+
+ /* Get the response message */
+ if (messageWaiting()) {
+ readMessage();
+ /* If the source accepted our request, wait for the new power */
+ if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkTransitionSink;
+ /* If the message was a Soft_Reset, do the soft reset procedure */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+ return PESinkSoftReset;
+ /* If the message was Wait or Reject */
+ } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT
+ || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT)
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+ /* If we don't have an explicit contract, wait for capabilities */
+ if (!_explicit_contract) {
+ return PESinkWaitCap;
+ /* If we do have an explicit contract, go to the ready state */
+ } else {
+ return PESinkReady;
+ }
+ } else {
+ return PESinkSendSoftReset;
+ }
+ }
+ return PESinkHardReset;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
- /* Wait for the PS_RDY message */
- eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
- PD_T_PS_TRANSITION);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If no message was received, send a hard reset */
- if (evt == 0) {
- return PESinkHardReset;
- }
-
- /* If we received a message, read it */
- if (messageWaiting()) {
- readMessage();
- /* If we got a PS_RDY, handle it */
- if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) {
- /* We just finished negotiating an explicit contract */
- _explicit_contract = true;
-
- /* Set the output appropriately */
- pdbs_dpm_transition_requested();
-
- return PESinkReady;
- /* If there was a protocol error, send a hard reset */
- } else {
- /* Turn off the power output before this hard reset to make sure we
+ /* Wait for the PS_RDY message */
+ eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
+ PD_T_PS_TRANSITION);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If no message was received, send a hard reset */
+ if (evt == 0) {
+ return PESinkHardReset;
+ }
+
+ /* If we received a message, read it */
+ if (messageWaiting()) {
+ readMessage();
+ /* If we got a PS_RDY, handle it */
+ if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+ /* We just finished negotiating an explicit contract */
+ _explicit_contract = true;
+
+ /* Set the output appropriately */
+ pdbs_dpm_transition_requested();
+
+ return PESinkReady;
+ /* If there was a protocol error, send a hard reset */
+ } else {
+ /* Turn off the power output before this hard reset to make sure we
* don't supply an incorrect voltage to the device we're powering.
*/
- pdbs_dpm_transition_default();
+ pdbs_dpm_transition_default();
- return PESinkHardReset;
- }
- }
+ return PESinkHardReset;
+ }
+ }
- return PESinkHardReset;
+ return PESinkHardReset;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
- eventmask_t evt;
-
- /* Wait for an event */
- evt = waitForEvent(
- PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
-
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
-
- /* If we overheated, send a hard reset */
- if (evt & PDB_EVT_PE_I_OVRTEMP) {
- return PESinkHardReset;
- }
-
- /* If we received a message */
- if (evt & PDB_EVT_PE_MSG_RX) {
- if (messageWaiting()) {
- readMessage();
- /* Ignore vendor-defined messages */
- if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) {
-
- return PESinkReady;
- /* Ignore Ping messages */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkReady;
- /* DR_Swap messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSendNotSupported;
- /* Get_Source_Cap messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSendNotSupported;
- /* PR_Swap messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSendNotSupported;
- /* VCONN_Swap messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSendNotSupported;
- /* Request messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) {
-
- return PESinkSendNotSupported;
- /* Sink_Capabilities messages are not supported */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
-
- return PESinkSendNotSupported;
- /* Handle GotoMin messages */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) {
- /* GiveBack is not supported */
- return PESinkSendNotSupported;
-
- /* Evaluate new Source_Capabilities */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
- /* Don't free the message: we need to keep the
+ eventmask_t evt;
+
+ /* Wait for an event */
+ evt = waitForEvent(
+ PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
+
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+
+ /* If we overheated, send a hard reset */
+ if (evt & PDB_EVT_PE_I_OVRTEMP) {
+ return PESinkHardReset;
+ }
+
+ /* If we received a message */
+ if (evt & PDB_EVT_PE_MSG_RX) {
+ if (messageWaiting()) {
+ readMessage();
+ /* Ignore vendor-defined messages */
+ if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED
+ && PD_NUMOBJ_GET(&tempMessage) > 0) {
+
+ return PESinkReady;
+ /* Ignore Ping messages */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkReady;
+ /* DR_Swap messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSendNotSupported;
+ /* Get_Source_Cap messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSendNotSupported;
+ /* PR_Swap messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSendNotSupported;
+ /* VCONN_Swap messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSendNotSupported;
+ /* Request messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST
+ && PD_NUMOBJ_GET(&tempMessage) > 0) {
+
+ return PESinkSendNotSupported;
+ /* Sink_Capabilities messages are not supported */
+ } else if (PD_MSGTYPE_GET(&tempMessage)
+ == PD_MSGTYPE_SINK_CAPABILITIES
+ && PD_NUMOBJ_GET(&tempMessage) > 0) {
+
+ return PESinkSendNotSupported;
+ /* Handle GotoMin messages */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+ /* GiveBack is not supported */
+ return PESinkSendNotSupported;
+
+ /* Evaluate new Source_Capabilities */
+ } else if (PD_MSGTYPE_GET(&tempMessage)
+ == PD_MSGTYPE_SOURCE_CAPABILITIES
+ && PD_NUMOBJ_GET(&tempMessage) > 0) {
+ /* Don't free the message: we need to keep the
* Source_Capabilities message so we can evaluate it. */
- return PESinkEvalCap;
- /* Give sink capabilities when asked */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkGiveSinkCap;
- /* If the message was a Soft_Reset, do the soft reset procedure */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSoftReset;
- /* PD 3.0 messges */
- } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
- /* If the message is a multi-chunk extended message, let it
+ return PESinkEvalCap;
+ /* Give sink capabilities when asked */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkGiveSinkCap;
+ /* If the message was a Soft_Reset, do the soft reset procedure */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSoftReset;
+ /* PD 3.0 messges */
+ } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
+ /* If the message is a multi-chunk extended message, let it
* time out. */
- if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) {
+ if ((tempMessage.hdr & PD_HDR_EXT)
+ && (PD_DATA_SIZE_GET(&tempMessage)
+ > PD_MAX_EXT_MSG_LEGACY_LEN)) {
- return PESinkChunkReceived;
- /* Tell the DPM a message we sent got a response of
+ return PESinkChunkReceived;
+ /* Tell the DPM a message we sent got a response of
* Not_Supported. */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) {
+ } else if (PD_MSGTYPE_GET(&tempMessage)
+ == PD_MSGTYPE_NOT_SUPPORTED
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
- return PESinkNotSupportedReceived;
- /* If we got an unknown message, send a soft reset */
- } else {
+ return PESinkNotSupportedReceived;
+ /* If we got an unknown message, send a soft reset */
+ } else {
- return PESinkSendSoftReset;
- }
- /* If we got an unknown message, send a soft reset ??? */
- } else {
+ return PESinkSendSoftReset;
+ }
+ /* If we got an unknown message, send a soft reset ??? */
+ } else {
- return PESinkSendSoftReset;
- }
- }
- }
+ return PESinkSendSoftReset;
+ }
+ }
+ }
- return PESinkReady;
+ return PESinkReady;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() {
- /* Get a message object */
- union pd_msg *get_source_cap = &tempMessage;
- /* Make a Get_Source_Cap message */
- get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0);
- /* Transmit the Get_Source_Cap */
- ProtocolTransmit::pushMessage(get_source_cap);
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
- /* Free the sent message */
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a hard reset */
- if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
- return PESinkHardReset;
- }
-
- return PESinkReady;
+ /* Get a message object */
+ union pd_msg *get_source_cap = &tempMessage;
+ /* Make a Get_Source_Cap message */
+ get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP
+ | PD_NUMOBJ(0);
+ /* Transmit the Get_Source_Cap */
+ ProtocolTransmit::pushMessage(get_source_cap);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+ /* Free the sent message */
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a hard reset */
+ if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
+ return PESinkHardReset;
+ }
+
+ return PESinkReady;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() {
- /* Get a message object */
- union pd_msg *snk_cap = &tempMessage;
- /* Get our capabilities from the DPM */
- pdbs_dpm_get_sink_capability(snk_cap);
-
- /* Transmit our capabilities */
- ProtocolTransmit::pushMessage(snk_cap);
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
-
- /* Free the Sink_Capabilities message */
-
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a hard reset */
- if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
- return PESinkHardReset;
- }
-
- return PESinkReady;
+ /* Get a message object */
+ union pd_msg *snk_cap = &tempMessage;
+ /* Get our capabilities from the DPM */
+ pdbs_dpm_get_sink_capability(snk_cap);
+
+ /* Transmit our capabilities */
+ ProtocolTransmit::pushMessage(snk_cap);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+
+ /* Free the Sink_Capabilities message */
+
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a hard reset */
+ if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
+ return PESinkHardReset;
+ }
+
+ return PESinkReady;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_hard_reset() {
- /* If we've already sent the maximum number of hard resets, assume the
+ /* If we've already sent the maximum number of hard resets, assume the
* source is unresponsive. */
- if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) {
- return PESinkSourceUnresponsive;
- }
- //So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU
- //So therefore we went get anywhere :)
- /* Increment HardResetCounter */
- _hard_reset_counter++;
-
- return PESinkTransitionDefault;
+ if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) {
+ return PESinkSourceUnresponsive;
+ }
+ //So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU
+ //So therefore we went get anywhere :)
+ /* Increment HardResetCounter */
+ _hard_reset_counter++;
+
+ return PESinkTransitionDefault;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_default() {
- _explicit_contract = false;
+ _explicit_contract = false;
- /* Tell the DPM to transition to default power */
- pdbs_dpm_transition_default();
+ /* Tell the DPM to transition to default power */
+ pdbs_dpm_transition_default();
- /* There is no local hardware to reset. */
- /* Since we never change our data role from UFP, there is no reason to set
+ /* There is no local hardware to reset. */
+ /* Since we never change our data role from UFP, there is no reason to set
* it here. */
- return PESinkStartup;
+ return PESinkStartup;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() {
- /* No need to explicitly reset the protocol layer here. It resets itself
+ /* No need to explicitly reset the protocol layer here. It resets itself
* when a Soft_Reset message is received. */
- /* Get a message object */
- union pd_msg accept;
- /* Make an Accept message */
- accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
- /* Transmit the Accept */
- ProtocolTransmit::pushMessage(&accept);
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
- /* Free the sent message */
-
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a hard reset */
- if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
- return PESinkHardReset;
- }
-
- return PESinkWaitCap;
+ /* Get a message object */
+ union pd_msg accept;
+ /* Make an Accept message */
+ accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
+ /* Transmit the Accept */
+ ProtocolTransmit::pushMessage(&accept);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+ /* Free the sent message */
+
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a hard reset */
+ if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
+ return PESinkHardReset;
+ }
+
+ return PESinkWaitCap;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
- /* No need to explicitly reset the protocol layer here. It resets itself
+ /* No need to explicitly reset the protocol layer here. It resets itself
* just before a Soft_Reset message is transmitted. */
- /* Get a message object */
- union pd_msg *softrst = &tempMessage;
- /* Make a Soft_Reset message */
- softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
- /* Transmit the soft reset */
- ProtocolTransmit::pushMessage(softrst);
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a hard reset */
- if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
- return PESinkHardReset;
- }
-
- /* Wait for a response */
- evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
- PD_T_SENDER_RESPONSE);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If we didn't get a response before the timeout, send a hard reset */
- if (evt == 0) {
- return PESinkHardReset;
- }
-
- /* Get the response message */
- if (messageWaiting()) {
- readMessage();
- /* If the source accepted our soft reset, wait for capabilities. */
- if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkWaitCap;
- /* If the message was a Soft_Reset, do the soft reset procedure */
- } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
-
- return PESinkSoftReset;
- /* Otherwise, send a hard reset */
- } else {
-
- return PESinkHardReset;
- }
- }
- return PESinkHardReset;
+ /* Get a message object */
+ union pd_msg *softrst = &tempMessage;
+ /* Make a Soft_Reset message */
+ softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
+ /* Transmit the soft reset */
+ ProtocolTransmit::pushMessage(softrst);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a hard reset */
+ if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
+ return PESinkHardReset;
+ }
+
+ /* Wait for a response */
+ evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
+ PD_T_SENDER_RESPONSE);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If we didn't get a response before the timeout, send a hard reset */
+ if (evt == 0) {
+ return PESinkHardReset;
+ }
+
+ /* Get the response message */
+ if (messageWaiting()) {
+ readMessage();
+ /* If the source accepted our soft reset, wait for capabilities. */
+ if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkWaitCap;
+ /* If the message was a Soft_Reset, do the soft reset procedure */
+ } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
+ && PD_NUMOBJ_GET(&tempMessage) == 0) {
+
+ return PESinkSoftReset;
+ /* Otherwise, send a hard reset */
+ } else {
+
+ return PESinkHardReset;
+ }
+ }
+ return PESinkHardReset;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
- /* Get a message object */
- union pd_msg *not_supported = &tempMessage;
-
- if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) {
- /* Make a Reject message */
- not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
- } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
- /* Make a Not_Supported message */
- not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0);
- }
-
- /* Transmit the message */
- ProtocolTransmit::pushMessage(not_supported);
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
- eventmask_t evt = waitForEvent(
- PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
-
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
- /* If the message transmission failed, send a soft reset */
- if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
- return PESinkSendSoftReset;
- }
-
- return PESinkReady;
+ /* Get a message object */
+ union pd_msg *not_supported = &tempMessage;
+
+ if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) {
+ /* Make a Reject message */
+ not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
+ } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
+ /* Make a Not_Supported message */
+ not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED
+ | PD_NUMOBJ(0);
+ }
+
+ /* Transmit the message */
+ ProtocolTransmit::pushMessage(not_supported);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
+
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
+ /* If the message transmission failed, send a soft reset */
+ if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
+ return PESinkSendSoftReset;
+ }
+
+ return PESinkReady;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
- /* Wait for tChunkingNotSupported */
- eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET,
- PD_T_CHUNKING_NOT_SUPPORTED);
- /* If we got reset signaling, transition to default */
- if (evt & PDB_EVT_PE_RESET) {
- return PESinkTransitionDefault;
- }
+ /* Wait for tChunkingNotSupported */
+ eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET,
+ PD_T_CHUNKING_NOT_SUPPORTED);
+ /* If we got reset signaling, transition to default */
+ if (evt & PDB_EVT_PE_RESET) {
+ return PESinkTransitionDefault;
+ }
- return PESinkSendNotSupported;
+ return PESinkSendNotSupported;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_not_supported_received() {
- /* Inform the Device Policy Manager that we received a Not_Supported
+ /* Inform the Device Policy Manager that we received a Not_Supported
* message. */
- return PESinkReady;
+ return PESinkReady;
}
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() {
- //Sit and chill, as PD is not working
- osDelay(PD_T_PD_DEBOUNCE);
+//Sit and chill, as PD is not working
+ osDelay(PD_T_PD_DEBOUNCE);
- return PESinkSourceUnresponsive;
+ return PESinkSourceUnresponsive;
}
uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
- return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE,
- ticksToWait);
+ return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE,
+ ticksToWait);
+
}
bool PolicyEngine::isPD3_0() {
- return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0;
+ return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0;
}
+
diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h
index e1b70ca2..74b6ca08 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h
@@ -34,166 +34,165 @@
#define PDB_EVT_PE_MSG_RX_PEND EVENT_MASK(7) /* Never SEND THIS DIRECTLY*/
class PolicyEngine {
- public:
- //Sets up internal state and registers the thread
- static void init();
- //Push an incoming message to the Policy Engine
- static void handleMessage(union pd_msg *msg);
- //Send a notification
- static void notify(uint32_t notification);
- //Returns true if headers indicate PD3.0 compliant
- static bool isPD3_0();
- static bool setupCompleteOrTimedOut() {
- if (pdNegotiationComplete)
- return true;
- if (state == policy_engine_state::PESinkSourceUnresponsive)
- return true;
- if (state == policy_engine_state::PESinkReady)
- return true;
- return false;
- }
- //Has pd negotiation completed
- static bool pdHasNegotiated() {
- return pdNegotiationComplete;
- }
-
- private:
- static bool pdNegotiationComplete;
- static int current_voltage_mv; //The current voltage PD is expecting
- static int _requested_voltage; //The voltage the unit wanted to requests
- static bool _unconstrained_power; // If the source is unconstrained
- //Current message being handled
- static union pd_msg currentMessage;
- /* PD message header template */
- static uint16_t hdr_template;
- /* Whether or not we have an explicit contract */
- static bool _explicit_contract;
- /* The number of hard resets we've sent */
- static int8_t _hard_reset_counter;
- /* The result of the last Type-C Current match comparison */
- static int8_t _old_tcc_match;
- /* The index of the first PPS APDO */
- static uint8_t _pps_index;
- /* The index of the just-requested PPS APDO */
- static uint8_t _last_pps;
- static void pe_task(const void *arg);
- enum policy_engine_state {
- PESinkStartup,
- PESinkDiscovery,
- PESinkWaitCap,
- PESinkEvalCap,
- PESinkSelectCap,
- PESinkTransitionSink,
- PESinkReady,
- PESinkGetSourceCap,
- PESinkGiveSinkCap,
- PESinkHardReset,
- PESinkTransitionDefault,
- PESinkSoftReset,
- PESinkSendSoftReset,
- PESinkSendNotSupported,
- PESinkChunkReceived,
- PESinkNotSupportedReceived,
- PESinkSourceUnresponsive
- };
- static enum policy_engine_state pe_sink_startup();
- static enum policy_engine_state pe_sink_discovery();
- static enum policy_engine_state pe_sink_wait_cap();
- static enum policy_engine_state pe_sink_eval_cap();
- static enum policy_engine_state pe_sink_select_cap();
- static enum policy_engine_state pe_sink_transition_sink();
- static enum policy_engine_state pe_sink_ready();
- static enum policy_engine_state pe_sink_get_source_cap();
- static enum policy_engine_state pe_sink_give_sink_cap();
- static enum policy_engine_state pe_sink_hard_reset();
- static enum policy_engine_state pe_sink_transition_default();
- static enum policy_engine_state pe_sink_soft_reset();
- static enum policy_engine_state pe_sink_send_soft_reset();
- static enum policy_engine_state pe_sink_send_not_supported();
- static enum policy_engine_state pe_sink_chunk_received();
- static enum policy_engine_state pe_sink_not_supported_received();
- static enum policy_engine_state pe_sink_source_unresponsive();
- static EventGroupHandle_t xEventGroupHandle;
- static StaticEventGroup_t xCreatedEventGroup;
- static uint32_t waitForEvent(uint32_t mask, TickType_t ticksToWait =
- portMAX_DELAY);
- //Task resources
- static osThreadId TaskHandle;
- static const size_t TaskStackSize = 2048 / 4;
- static uint32_t TaskBuffer[TaskStackSize];
- static osStaticThreadDef_t TaskControlBlock;
- static union pd_msg tempMessage;
- static union pd_msg _last_dpm_request;
- static policy_engine_state state;
- //queue of up to PDB_MSG_POOL_SIZE messages to send
- static StaticQueue_t xStaticQueue;
- /* The array to use as the queue's storage area. This must be at least
+public:
+ //Sets up internal state and registers the thread
+ static void init();
+ //Push an incoming message to the Policy Engine
+ static void handleMessage(union pd_msg *msg);
+ //Send a notification
+ static void notify(uint32_t notification);
+ //Returns true if headers indicate PD3.0 compliant
+ static bool isPD3_0();
+ static bool setupCompleteOrTimedOut() {
+ if (pdNegotiationComplete)
+ return true;
+ if (state == policy_engine_state::PESinkSourceUnresponsive)
+ return true;
+ if (state == policy_engine_state::PESinkReady)
+ return true;
+ return false;
+ }
+ //Has pd negotiation completed
+ static bool pdHasNegotiated() {
+ return pdNegotiationComplete;
+ }
+private:
+ static bool pdNegotiationComplete;
+ static int current_voltage_mv; //The current voltage PD is expecting
+ static int _requested_voltage; //The voltage the unit wanted to requests
+ static bool _unconstrained_power; // If the source is unconstrained
+ //Current message being handled
+ static union pd_msg currentMessage;
+ /* PD message header template */
+ static uint16_t hdr_template;
+ /* Whether or not we have an explicit contract */
+ static bool _explicit_contract;
+ /* The number of hard resets we've sent */
+ static int8_t _hard_reset_counter;
+ /* The result of the last Type-C Current match comparison */
+ static int8_t _old_tcc_match;
+ /* The index of the first PPS APDO */
+ static uint8_t _pps_index;
+ /* The index of the just-requested PPS APDO */
+ static uint8_t _last_pps;
+ static void pe_task(const void *arg);
+ enum policy_engine_state {
+ PESinkStartup,
+ PESinkDiscovery,
+ PESinkWaitCap,
+ PESinkEvalCap,
+ PESinkSelectCap,
+ PESinkTransitionSink,
+ PESinkReady,
+ PESinkGetSourceCap,
+ PESinkGiveSinkCap,
+ PESinkHardReset,
+ PESinkTransitionDefault,
+ PESinkSoftReset,
+ PESinkSendSoftReset,
+ PESinkSendNotSupported,
+ PESinkChunkReceived,
+ PESinkNotSupportedReceived,
+ PESinkSourceUnresponsive
+ };
+ static enum policy_engine_state pe_sink_startup();
+ static enum policy_engine_state pe_sink_discovery();
+ static enum policy_engine_state pe_sink_wait_cap();
+ static enum policy_engine_state pe_sink_eval_cap();
+ static enum policy_engine_state pe_sink_select_cap();
+ static enum policy_engine_state pe_sink_transition_sink();
+ static enum policy_engine_state pe_sink_ready();
+ static enum policy_engine_state pe_sink_get_source_cap();
+ static enum policy_engine_state pe_sink_give_sink_cap();
+ static enum policy_engine_state pe_sink_hard_reset();
+ static enum policy_engine_state pe_sink_transition_default();
+ static enum policy_engine_state pe_sink_soft_reset();
+ static enum policy_engine_state pe_sink_send_soft_reset();
+ static enum policy_engine_state pe_sink_send_not_supported();
+ static enum policy_engine_state pe_sink_chunk_received();
+ static enum policy_engine_state pe_sink_not_supported_received();
+ static enum policy_engine_state pe_sink_source_unresponsive();
+ static EventGroupHandle_t xEventGroupHandle;
+ static StaticEventGroup_t xCreatedEventGroup;
+ static uint32_t waitForEvent(uint32_t mask, TickType_t ticksToWait =
+ portMAX_DELAY);
+ //Task resources
+ static osThreadId TaskHandle;
+ static const size_t TaskStackSize = 2048 / 4;
+ static uint32_t TaskBuffer[TaskStackSize];
+ static osStaticThreadDef_t TaskControlBlock;
+ static union pd_msg tempMessage;
+ static union pd_msg _last_dpm_request;
+ static policy_engine_state state;
+ //queue of up to PDB_MSG_POOL_SIZE messages to send
+ static StaticQueue_t xStaticQueue;
+ /* The array to use as the queue's storage area. This must be at least
uxQueueLength * uxItemSize bytes. */
- static uint8_t ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
- static QueueHandle_t messagesWaiting;
- static bool messageWaiting();
- //Read a pending message into the temp message
- static bool readMessage();
+ static uint8_t ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
+ static QueueHandle_t messagesWaiting;
+ static bool messageWaiting();
+//Read a pending message into the temp message
+ static bool readMessage();
- // These callbacks are called to implement the logic for the iron to select the desired voltage
+ // These callbacks are called to implement the logic for the iron to select the desired voltage
- /*
+ /*
* Create a Request message based on the given Source_Capabilities message. If
* capabilities is NULL, the last non-null Source_Capabilities message passes
* is used. If none has been provided, the behavior is undefined.
*
* Returns true if sufficient power is available, false otherwise.
*/
- static bool pdbs_dpm_evaluate_capability(const union pd_msg *capabilities,
- union pd_msg *request);
+ static bool pdbs_dpm_evaluate_capability(const union pd_msg *capabilities,
+ union pd_msg *request);
- /*
+ /*
* Create a Sink_Capabilities message for our current capabilities.
*/
- static void pdbs_dpm_get_sink_capability(union pd_msg *cap);
+ static void pdbs_dpm_get_sink_capability(union pd_msg *cap);
- /*
+ /*
* Return whether or not GiveBack support is enabled.
*/
- static bool pdbs_dpm_giveback_enabled();
+ static bool pdbs_dpm_giveback_enabled();
- /*
+ /*
* Evaluate whether or not the currently offered Type-C Current can fulfill our
* power needs.
*
* Returns true if sufficient power is available, false otherwise.
*/
- static bool pdbs_dpm_evaluate_typec_current(enum fusb_typec_current tcc);
+ static bool pdbs_dpm_evaluate_typec_current(enum fusb_typec_current tcc);
- /*
+ /*
* Indicate that power negotiations are starting.
*/
- static void pdbs_dpm_pd_start();
+ static void pdbs_dpm_pd_start();
- /*
+ /*
* Transition the sink to default power.
*/
- static void pdbs_dpm_transition_default();
+ static void pdbs_dpm_transition_default();
- /*
+ /*
* Transition to the requested minimum current.
*/
- static void pdbs_dpm_transition_min();
+ static void pdbs_dpm_transition_min();
- /*
+ /*
* Transition to Sink Standby if necessary.
*/
- static void pdbs_dpm_transition_standby();
+ static void pdbs_dpm_transition_standby();
- /*
+ /*
* Transition to the requested power level
*/
- static void pdbs_dpm_transition_requested();
+ static void pdbs_dpm_transition_requested();
- /*
+ /*
* Transition to the Type-C Current power level
*/
- static void pdbs_dpm_transition_typec();
+ static void pdbs_dpm_transition_typec();
};
#endif /* PDB_POLICY_ENGINE_H */
diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp b/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp
index 4e65cf85..4e65cf85 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp
diff --git a/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.cpp b/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.cpp
index 1611cbc1..4ab58925 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.cpp
@@ -17,12 +17,12 @@
#include "protocol_rx.h"
-#include "fusb302b.h"
-#include "policy_engine.h"
-#include "protocol_tx.h"
+#include <stdlib.h>
#include "string.h"
#include <pd.h>
-#include <stdlib.h>
+#include "policy_engine.h"
+#include "protocol_tx.h"
+#include "fusb302b.h"
osThreadId ProtocolReceive::TaskHandle = NULL;
EventGroupHandle_t ProtocolReceive::xEventGroupHandle = NULL;
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
@@ -35,154 +35,155 @@ uint8_t ProtocolReceive::_tx_messageidcounter;
* PRL_Rx_Wait_for_PHY_Message state
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
- /* Wait for an event */
- _rx_messageid = 0;
- eventmask_t evt = waitForEvent(
- PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
-
- /* If we got a reset event, reset */
- if (evt & PDB_EVT_PRLRX_RESET) {
- waitForEvent(PDB_EVT_PRLRX_RESET, 0);
- return PRLRxWaitPHY;
- }
- /* If we got an I_GCRCSENT event, read the message and decide what to do */
- if (evt & PDB_EVT_PRLRX_I_GCRCSENT) {
- /* Get a buffer to read the message into. Guaranteed to not fail
+ /* Wait for an event */
+ _rx_messageid = 0;
+ eventmask_t evt = waitForEvent(
+ PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
+
+ /* If we got a reset event, reset */
+ if (evt & PDB_EVT_PRLRX_RESET) {
+ waitForEvent(PDB_EVT_PRLRX_RESET, 0);
+ return PRLRxWaitPHY;
+ }
+ /* If we got an I_GCRCSENT event, read the message and decide what to do */
+ if (evt & PDB_EVT_PRLRX_I_GCRCSENT) {
+ /* Get a buffer to read the message into. Guaranteed to not fail
* because we have a big enough pool and are careful. */
- union pd_msg *_rx_message = &tempMessage;
- memset(&tempMessage, 0, sizeof(tempMessage));
- /* Read the message */
- fusb_read_message(_rx_message);
- /* If it's a Soft_Reset, go to the soft reset state */
- if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(_rx_message) == 0) {
- return PRLRxReset;
- } else {
- /* Otherwise, check the message ID */
- return PRLRxCheckMessageID;
- }
- } else if (evt & PDB_EVT_PRLRX_I_RXPEND) {
- //There is an RX message pending that is not a Good CRC
- union pd_msg *_rx_message = &tempMessage;
- /* Read the message */
- fusb_read_message(_rx_message);
- return PRLRxWaitPHY;
- }
-
- return PRLRxWaitPHY;
+ union pd_msg *_rx_message = &tempMessage;
+ memset(&tempMessage, 0, sizeof(tempMessage));
+ /* Read the message */
+ fusb_read_message(_rx_message);
+ /* If it's a Soft_Reset, go to the soft reset state */
+ if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET
+ && PD_NUMOBJ_GET(_rx_message) == 0) {
+ return PRLRxReset;
+ } else {
+ /* Otherwise, check the message ID */
+ return PRLRxCheckMessageID;
+ }
+ } else if (evt & PDB_EVT_PRLRX_I_RXPEND) {
+ //There is an RX message pending that is not a Good CRC
+ union pd_msg *_rx_message = &tempMessage;
+ /* Read the message */
+ fusb_read_message(_rx_message);
+ return PRLRxWaitPHY;
+ }
+
+ return PRLRxWaitPHY;
}
/*
* PRL_Rx_Layer_Reset_for_Receive state
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
- /* Reset MessageIDCounter */
- _tx_messageidcounter = 0;
+ /* Reset MessageIDCounter */
+ _tx_messageidcounter = 0;
- /* Clear stored MessageID */
- _rx_messageid = -1;
+ /* Clear stored MessageID */
+ _rx_messageid = -1;
- /* TX transitions to its reset state */
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
- taskYIELD();
+ /* TX transitions to its reset state */
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
+ taskYIELD();
- /* If we got a RESET signal, reset the machine */
- if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) != 0) {
- return PRLRxWaitPHY;
- }
+ /* If we got a RESET signal, reset the machine */
+ if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) != 0) {
+ return PRLRxWaitPHY;
+ }
- /* Go to the Check_MessageID state */
- return PRLRxCheckMessageID;
+ /* Go to the Check_MessageID state */
+ return PRLRxCheckMessageID;
}
volatile uint32_t rxCounter = 0;
/*
* PRL_Rx_Check_MessageID state
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
- /* If we got a RESET signal, reset the machine */
- // if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
- // return PRLRxWaitPHY;
- // }
- /* If the message has the stored ID, we've seen this message before. Free
+ /* If we got a RESET signal, reset the machine */
+// if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
+// return PRLRxWaitPHY;
+// }
+ /* If the message has the stored ID, we've seen this message before. Free
* it and don't pass it to the policy engine. */
- /* Otherwise, there's either no stored ID or this message has an ID we
+ /* Otherwise, there's either no stored ID or this message has an ID we
* haven't just seen. Transition to the Store_MessageID state. */
- // if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
- // return PRLRxWaitPHY;
- // } else
- {
- rxCounter++;
- return PRLRxStoreMessageID;
- }
+// if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
+// return PRLRxWaitPHY;
+// } else
+ {
+ rxCounter++;
+ return PRLRxStoreMessageID;
+ }
}
/*
* PRL_Rx_Store_MessageID state
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() {
- /* Tell ProtocolTX to discard the message being transmitted */
+ /* Tell ProtocolTX to discard the message being transmitted */
- ProtocolTransmit::notify(
- ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
+ ProtocolTransmit::notify(
+ ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
- /* Update the stored MessageID */
- _rx_messageid = PD_MESSAGEID_GET(&tempMessage);
+ /* Update the stored MessageID */
+ _rx_messageid = PD_MESSAGEID_GET(&tempMessage);
- /* Pass the message to the policy engine. */
+ /* Pass the message to the policy engine. */
- PolicyEngine::handleMessage(&tempMessage);
- PolicyEngine::notify(PDB_EVT_PE_MSG_RX);
- taskYIELD();
- /* Don't check if we got a RESET because we'd do nothing different. */
+ PolicyEngine::handleMessage(&tempMessage);
+ PolicyEngine::notify(PDB_EVT_PE_MSG_RX);
+ taskYIELD();
+ /* Don't check if we got a RESET because we'd do nothing different. */
- return PRLRxWaitPHY;
+ return PRLRxWaitPHY;
}
void ProtocolReceive::init() {
- osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize,
- TaskBuffer, &TaskControlBlock);
- xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
- TaskHandle = osThreadCreate(osThread(protRX), NULL);
+ osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize,
+ TaskBuffer, &TaskControlBlock);
+ xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
+ TaskHandle = osThreadCreate(osThread(protRX), NULL);
}
void ProtocolReceive::thread(const void *args) {
- (void)args;
- ProtocolReceive::protocol_rx_state state = PRLRxWaitPHY;
-
- while (true) {
- switch (state) {
- case PRLRxWaitPHY:
- state = protocol_rx_wait_phy();
- break;
- case PRLRxReset:
- state = protocol_rx_reset();
- break;
- case PRLRxCheckMessageID:
- state = protocol_rx_check_messageid();
- break;
- case PRLRxStoreMessageID:
- state = protocol_rx_store_messageid();
- break;
- default:
- /* This is an error. It really shouldn't happen. We might
+ (void) args;
+ ProtocolReceive::protocol_rx_state state = PRLRxWaitPHY;
+
+ while (true) {
+ switch (state) {
+ case PRLRxWaitPHY:
+ state = protocol_rx_wait_phy();
+ break;
+ case PRLRxReset:
+ state = protocol_rx_reset();
+ break;
+ case PRLRxCheckMessageID:
+ state = protocol_rx_check_messageid();
+ break;
+ case PRLRxStoreMessageID:
+ state = protocol_rx_store_messageid();
+ break;
+ default:
+ /* This is an error. It really shouldn't happen. We might
* want to handle it anyway, though. */
- state = PRLRxWaitPHY;
- break;
- }
- }
+ state = PRLRxWaitPHY;
+ break;
+ }
+ }
}
void ProtocolReceive::notify(uint32_t notification) {
- if (xEventGroupHandle != NULL) {
- xEventGroupSetBits(xEventGroupHandle, notification);
- }
+ if (xEventGroupHandle != NULL) {
+ xEventGroupSetBits(xEventGroupHandle, notification);
+ }
}
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
- if (xEventGroupHandle != NULL) {
- return xEventGroupWaitBits(xEventGroupHandle, mask, mask,
- pdFALSE, ticksToWait);
- }
- return 0;
+ if (xEventGroupHandle != NULL) {
+ return xEventGroupWaitBits(xEventGroupHandle, mask, mask,
+ pdFALSE, ticksToWait);
+ }
+ return 0;
}
diff --git a/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.h b/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.h
index 1d3d0c14..7b9c6922 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/protocol_rx.h
@@ -28,40 +28,37 @@
#define PDB_EVT_PRLRX_I_RXPEND EVENT_MASK(2)
class ProtocolReceive {
- public:
- static void init();
- static void notify(uint32_t notification);
+public:
+ static void init();
+ static void notify(uint32_t notification);
+private:
+ static void thread(const void *args);
- private:
- static void thread(const void *args);
-
- static EventGroupHandle_t xEventGroupHandle;
- static StaticEventGroup_t xCreatedEventGroup;
- static osThreadId TaskHandle;
- static const size_t TaskStackSize = 1024 / 4;
- static uint32_t TaskBuffer[TaskStackSize];
- static osStaticThreadDef_t TaskControlBlock;
- /*
+ static EventGroupHandle_t xEventGroupHandle;
+ static StaticEventGroup_t xCreatedEventGroup;
+ static osThreadId TaskHandle;
+ static const size_t TaskStackSize = 1024 / 4;
+ static uint32_t TaskBuffer[TaskStackSize];
+ static osStaticThreadDef_t TaskControlBlock;
+ /*
* Protocol RX machine states
*
* There is no Send_GoodCRC state because the PHY sends the GoodCRC for us.
* All transitions that would go to that state instead go to Check_MessageID.
*/
- enum protocol_rx_state {
- PRLRxWaitPHY,
- PRLRxReset,
- PRLRxCheckMessageID,
- PRLRxStoreMessageID
- };
- static protocol_rx_state protocol_rx_store_messageid();
- static protocol_rx_state protocol_rx_check_messageid();
- static protocol_rx_state protocol_rx_reset();
- static protocol_rx_state protocol_rx_wait_phy();
- static union pd_msg tempMessage;
- static uint8_t _rx_messageid;
- static uint8_t _tx_messageidcounter;
- static uint32_t waitForEvent(uint32_t mask, TickType_t ticksToWait =
- portMAX_DELAY);
+ enum protocol_rx_state {
+ PRLRxWaitPHY, PRLRxReset, PRLRxCheckMessageID, PRLRxStoreMessageID
+ };
+ static protocol_rx_state protocol_rx_store_messageid();
+ static protocol_rx_state protocol_rx_check_messageid();
+ static protocol_rx_state protocol_rx_reset();
+ static protocol_rx_state protocol_rx_wait_phy();
+ static union pd_msg tempMessage;
+ static uint8_t _rx_messageid;
+ static uint8_t _tx_messageidcounter;
+ static uint32_t waitForEvent(uint32_t mask, TickType_t ticksToWait =
+ portMAX_DELAY);
+
};
#endif /* PDB_PROTOCOL_RX_H */
diff --git a/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.cpp b/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.cpp
index b68c14a3..9f014550 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.cpp
+++ b/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.cpp
@@ -16,18 +16,19 @@
*/
#include "protocol_tx.h"
-#include "fusb302b.h"
-#include "fusbpd.h"
+#include <pd.h>
#include "policy_engine.h"
#include "protocol_rx.h"
-#include <pd.h>
+#include "fusb302b.h"
+#include "fusbpd.h"
osThreadId ProtocolTransmit::TaskHandle = NULL;
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
StaticQueue_t ProtocolTransmit::xStaticQueue;
bool ProtocolTransmit::messageSending = false;
-uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
+uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE
+ * sizeof(union pd_msg)];
QueueHandle_t ProtocolTransmit::messagesWaiting = NULL;
uint8_t ProtocolTransmit::_tx_messageidcounter;
union pd_msg ProtocolTransmit::temp_msg;
@@ -37,253 +38,261 @@ StaticEventGroup_t ProtocolTransmit::xCreatedEventGroup;
* PRL_Tx_PHY_Layer_Reset state
*/
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
- /* Reset the PHY */
- fusb_reset();
+ /* Reset the PHY */
+ fusb_reset();
- /* If a message was pending when we got here, tell the policy engine that
+ /* If a message was pending when we got here, tell the policy engine that
* we failed to send it */
- if (messagePending()) {
- /* Tell the policy engine that we failed */
- PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
- /* Finish failing to send the message */
- while (messagePending()) {
- getMessage(); //Discard
- }
- }
-
- /* Wait for a message request */
- return PRLTxWaitMessage;
+ if (messagePending()) {
+ /* Tell the policy engine that we failed */
+ PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
+ /* Finish failing to send the message */
+ while (messagePending()) {
+ getMessage(); //Discard
+ }
+ }
+
+ /* Wait for a message request */
+ return PRLTxWaitMessage;
}
/*
* PRL_Tx_Wait_for_Message_Request state
*/
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() {
- /* Wait for an event */
- ProtocolTransmit::Notifications evt = waitForEvent(
- (uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_MSG_TX);
-
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
- return PRLTxPHYReset;
- }
-
- /* If the policy engine is trying to send a message */
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_MSG_TX) {
- /* Get the message */
- getMessage();
-
- /* If it's a Soft_Reset, reset the TX layer first */
- if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&(temp_msg)) == 0) {
- return PRLTxReset;
- /* Otherwise, just send the message */
- } else {
- return PRLTxConstructMessage;
- }
- }
-
- /* Silence the compiler warning */
- return PRLTxWaitMessage;
+ /* Wait for an event */
+ ProtocolTransmit::Notifications evt = waitForEvent(
+ (uint32_t) Notifications::PDB_EVT_PRLTX_RESET
+ | (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
+ | (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX);
+
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
+ return PRLTxPHYReset;
+ }
+
+ /* If the policy engine is trying to send a message */
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX) {
+ /* Get the message */
+ getMessage();
+
+ /* If it's a Soft_Reset, reset the TX layer first */
+ if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET
+ && PD_NUMOBJ_GET(&(temp_msg)) == 0) {
+ return PRLTxReset;
+ /* Otherwise, just send the message */
+ } else {
+ return PRLTxConstructMessage;
+ }
+ }
+
+ /* Silence the compiler warning */
+ return PRLTxWaitMessage;
}
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
- /* Clear MessageIDCounter */
- _tx_messageidcounter = 0;
+ /* Clear MessageIDCounter */
+ _tx_messageidcounter = 0;
- /* Tell the Protocol RX thread to reset */
- ProtocolReceive::notify(PDB_EVT_PRLRX_RESET);
- taskYIELD();
+ /* Tell the Protocol RX thread to reset */
+ ProtocolReceive::notify( PDB_EVT_PRLRX_RESET);
+ taskYIELD();
- return PRLTxConstructMessage;
+ return PRLTxConstructMessage;
}
/*
* PRL_Tx_Construct_Message state
*/
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
- /* Set the correct MessageID in the message */
- temp_msg.hdr &= ~PD_HDR_MESSAGEID;
- temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
-
- /* PD 3.0 collision avoidance */
- // if (PolicyEngine::isPD3_0()) {
- // /* If we're starting an AMS, wait for permission to transmit */
- // evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
- // 0);
- // if ((uint32_t) evt
- // & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
- // while (fusb_get_typec_current() != fusb_sink_tx_ok) {
- // osDelay(1);
- // }
- // }
- // }
- messageSending = true;
- /* Send the message to the PHY */
- fusb_send_message(&temp_msg);
-
- return PRLTxWaitResponse;
+ /* Set the correct MessageID in the message */
+ temp_msg.hdr &= ~PD_HDR_MESSAGEID;
+ temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
+
+ /* PD 3.0 collision avoidance */
+// if (PolicyEngine::isPD3_0()) {
+// /* If we're starting an AMS, wait for permission to transmit */
+// evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
+// 0);
+// if ((uint32_t) evt
+// & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
+// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
+// osDelay(1);
+// }
+// }
+// }
+ messageSending = true;
+ /* Send the message to the PHY */
+ fusb_send_message(&temp_msg);
+
+ return PRLTxWaitResponse;
}
/*
* PRL_Tx_Wait_for_PHY_Response state
*/
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() {
- /* Wait for an event. There is no need to run CRCReceiveTimer, since the
+ /* Wait for an event. There is no need to run CRCReceiveTimer, since the
* FUSB302B handles that as part of its retry mechanism. */
- ProtocolTransmit::Notifications evt = waitForEvent(
- (uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_I_TXSENT | (uint32_t)Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
-
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
- return PRLTxPHYReset;
- }
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD) {
- return PRLTxDiscardMessage;
- }
-
- /* If the message was sent successfully */
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_I_TXSENT) {
- return PRLTxMatchMessageID;
- }
- /* If the message failed to be sent */
- if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_I_RETRYFAIL) {
- return PRLTxTransmissionError;
- }
-
- /* Silence the compiler warning */
- return PRLTxDiscardMessage;
+ ProtocolTransmit::Notifications evt = waitForEvent(
+ (uint32_t) Notifications::PDB_EVT_PRLTX_RESET
+ | (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
+ | (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT
+ | (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
+
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
+ return PRLTxPHYReset;
+ }
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
+ return PRLTxDiscardMessage;
+ }
+
+ /* If the message was sent successfully */
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT) {
+ return PRLTxMatchMessageID;
+ }
+ /* If the message failed to be sent */
+ if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL) {
+ return PRLTxTransmissionError;
+ }
+
+ /* Silence the compiler warning */
+ return PRLTxDiscardMessage;
}
/*
* PRL_Tx_Match_MessageID state
*/
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_match_messageid() {
- union pd_msg goodcrc;
-
- /* Read the GoodCRC */
- fusb_read_message(&goodcrc);
-
- /* Check that the message is correct */
- if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC && PD_NUMOBJ_GET(&goodcrc) == 0 && PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
- return PRLTxMessageSent;
- } else {
- return PRLTxTransmissionError;
- }
+ union pd_msg goodcrc;
+
+ /* Read the GoodCRC */
+ fusb_read_message(&goodcrc);
+
+ /* Check that the message is correct */
+ if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC
+ && PD_NUMOBJ_GET(&goodcrc) == 0
+ && PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
+ return PRLTxMessageSent;
+ } else {
+ return PRLTxTransmissionError;
+ }
}
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_transmission_error() {
- /* Increment MessageIDCounter */
- _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
+ /* Increment MessageIDCounter */
+ _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
- /* Tell the policy engine that we failed */
- PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
+ /* Tell the policy engine that we failed */
+ PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
- return PRLTxWaitMessage;
+ return PRLTxWaitMessage;
}
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent() {
- messageSending = false;
- /* Increment MessageIDCounter */
- _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
+ messageSending = false;
+ /* Increment MessageIDCounter */
+ _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
- /* Tell the policy engine that we succeeded */
- PolicyEngine::notify(PDB_EVT_PE_TX_DONE);
+ /* Tell the policy engine that we succeeded */
+ PolicyEngine::notify( PDB_EVT_PE_TX_DONE);
- return PRLTxWaitMessage;
+ return PRLTxWaitMessage;
}
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_discard_message() {
- /* If we were working on sending a message, increment MessageIDCounter */
- if (messageSending) {
- _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
-
- return PRLTxPHYReset;
- } else {
- return PRLTxWaitMessage;
- }
+ /* If we were working on sending a message, increment MessageIDCounter */
+ if (messageSending) {
+ _tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
+
+ return PRLTxPHYReset;
+ } else {
+ return PRLTxWaitMessage;
+ }
}
void ProtocolTransmit::thread(const void *args) {
- (void)args;
- ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
-
- //Init the incoming message queue
-
- while (true) {
- switch (state) {
- case PRLTxPHYReset:
- state = protocol_tx_phy_reset();
- break;
- case PRLTxWaitMessage:
- state = protocol_tx_wait_message();
- break;
- case PRLTxReset:
- state = protocol_tx_reset();
- break;
- case PRLTxConstructMessage:
- state = protocol_tx_construct_message();
- break;
- case PRLTxWaitResponse:
- state = protocol_tx_wait_response();
- break;
- case PRLTxMatchMessageID:
- state = protocol_tx_match_messageid();
- break;
- case PRLTxTransmissionError:
- state = protocol_tx_transmission_error();
- break;
- case PRLTxMessageSent:
- state = protocol_tx_message_sent();
- break;
- case PRLTxDiscardMessage:
- state = protocol_tx_discard_message();
- break;
- default:
- state = PRLTxPHYReset;
- break;
- }
- }
+ (void) args;
+ ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
+
+ //Init the incoming message queue
+
+ while (true) {
+ switch (state) {
+ case PRLTxPHYReset:
+ state = protocol_tx_phy_reset();
+ break;
+ case PRLTxWaitMessage:
+ state = protocol_tx_wait_message();
+ break;
+ case PRLTxReset:
+ state = protocol_tx_reset();
+ break;
+ case PRLTxConstructMessage:
+ state = protocol_tx_construct_message();
+ break;
+ case PRLTxWaitResponse:
+ state = protocol_tx_wait_response();
+ break;
+ case PRLTxMatchMessageID:
+ state = protocol_tx_match_messageid();
+ break;
+ case PRLTxTransmissionError:
+ state = protocol_tx_transmission_error();
+ break;
+ case PRLTxMessageSent:
+ state = protocol_tx_message_sent();
+ break;
+ case PRLTxDiscardMessage:
+ state = protocol_tx_discard_message();
+ break;
+ default:
+ state = PRLTxPHYReset;
+ break;
+ }
+ }
}
void ProtocolTransmit::notify(ProtocolTransmit::Notifications notification) {
- if (xEventGroupHandle != NULL) {
- xEventGroupSetBits(xEventGroupHandle, (uint32_t)notification);
- }
+ if (xEventGroupHandle != NULL) {
+ xEventGroupSetBits(xEventGroupHandle, (uint32_t) notification);
+ }
}
void ProtocolTransmit::init() {
- messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
- sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
+ messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
+ sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
- osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
- TaskBuffer, &TaskControlBlock);
- TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
- xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
+ osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
+ TaskBuffer, &TaskControlBlock);
+ TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
+ xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
}
void ProtocolTransmit::pushMessage(union pd_msg *msg) {
- if (messagesWaiting) {
- xQueueSend(messagesWaiting, msg, 100);
- }
+ if (messagesWaiting) {
+ xQueueSend(messagesWaiting, msg, 100);
+ }
}
bool ProtocolTransmit::messagePending() {
- if (messagesWaiting) {
- return uxQueueMessagesWaiting(messagesWaiting) > 0;
- }
- return false;
+ if (messagesWaiting) {
+ return uxQueueMessagesWaiting(messagesWaiting) > 0;
+ }
+ return false;
}
void ProtocolTransmit::getMessage() {
- //Loads the pending message into the buffer
- if (messagesWaiting) {
- xQueueReceive(messagesWaiting, &temp_msg, 1);
- }
+ //Loads the pending message into the buffer
+ if (messagesWaiting) {
+ xQueueReceive(messagesWaiting, &temp_msg, 1);
+ }
}
ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask,
- TickType_t ticksToWait) {
- if (xEventGroupHandle) {
- return (Notifications)xEventGroupWaitBits(xEventGroupHandle, mask,
- mask,
- pdFALSE, ticksToWait);
- }
- return (Notifications)0;
+ TickType_t ticksToWait) {
+ if (xEventGroupHandle) {
+ return (Notifications) xEventGroupWaitBits(xEventGroupHandle, mask,
+ mask,
+ pdFALSE, ticksToWait);
+ }
+ return (Notifications)0;
}
diff --git a/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.h b/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.h
index 9ca49995..4ce1626d 100644..100755
--- a/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.h
+++ b/workspace/TS100/Core/Drivers/FUSB302/protocol_tx.h
@@ -18,80 +18,80 @@
#ifndef PDB_PROTOCOL_TX_H
#define PDB_PROTOCOL_TX_H
+#include <stdint.h>
#include "policy_engine.h"
#include "protocol_rx.h"
#include <pd.h>
-#include <stdint.h>
/* Events for the Protocol TX thread */
class ProtocolTransmit {
- public:
- static void init();
- //Push a message to the queue to be sent out the pd comms bus
- static void pushMessage(union pd_msg *msg);
+public:
+ static void init();
+ //Push a message to the queue to be sent out the pd comms bus
+ static void pushMessage(union pd_msg *msg);
- enum class Notifications {
+ enum class Notifications {
- PDB_EVT_PRLTX_RESET = EVENT_MASK(0), //
- PDB_EVT_PRLTX_I_TXSENT = EVENT_MASK(1), //
- PDB_EVT_PRLTX_I_RETRYFAIL = EVENT_MASK(2), //
- PDB_EVT_PRLTX_DISCARD = EVENT_MASK(3), //
- PDB_EVT_PRLTX_MSG_TX = EVENT_MASK(4), //
- PDB_EVT_PRLTX_START_AMS = EVENT_MASK(5), //
- };
- static void notify(Notifications notification);
-
- private:
- static void thread(const void *args);
- static EventGroupHandle_t xEventGroupHandle;
- static StaticEventGroup_t xCreatedEventGroup;
- static osThreadId TaskHandle;
- static const size_t TaskStackSize = 1024 / 4;
- static uint32_t TaskBuffer[TaskStackSize];
- static osStaticThreadDef_t TaskControlBlock;
- static bool messageSending;
- /*
+ PDB_EVT_PRLTX_RESET = EVENT_MASK(0), //
+ PDB_EVT_PRLTX_I_TXSENT = EVENT_MASK(1), //
+ PDB_EVT_PRLTX_I_RETRYFAIL = EVENT_MASK(2), //
+ PDB_EVT_PRLTX_DISCARD = EVENT_MASK(3), //
+ PDB_EVT_PRLTX_MSG_TX = EVENT_MASK(4), //
+ PDB_EVT_PRLTX_START_AMS = EVENT_MASK(5), //
+ };
+ static void notify(Notifications notification);
+private:
+ static void thread(const void *args);
+ static EventGroupHandle_t xEventGroupHandle;
+ static StaticEventGroup_t xCreatedEventGroup;
+ static osThreadId TaskHandle;
+ static const size_t TaskStackSize = 1024 / 4;
+ static uint32_t TaskBuffer[TaskStackSize];
+ static osStaticThreadDef_t TaskControlBlock;
+ static bool messageSending;
+ /*
* Protocol TX machine states
*
* Because the PHY can automatically send retries, the Check_RetryCounter state
* has been removed, transitions relating to it are modified appropriately, and
* we don't even keep a RetryCounter.
*/
- enum protocol_tx_state {
- PRLTxPHYReset,
- PRLTxWaitMessage,
- PRLTxReset,
- PRLTxConstructMessage,
- PRLTxWaitResponse,
- PRLTxMatchMessageID,
- PRLTxTransmissionError,
- PRLTxMessageSent,
- PRLTxDiscardMessage
- };
- //Internal states
- static protocol_tx_state protocol_tx_discard_message();
- static protocol_tx_state protocol_tx_message_sent();
- static protocol_tx_state protocol_tx_transmission_error();
- static protocol_tx_state protocol_tx_match_messageid();
- static protocol_tx_state protocol_tx_wait_response();
- static protocol_tx_state protocol_tx_construct_message();
- static protocol_tx_state protocol_tx_reset();
- static protocol_tx_state protocol_tx_wait_message();
- static protocol_tx_state protocol_tx_phy_reset();
- //queue of up to PDB_MSG_POOL_SIZE messages to send
- static StaticQueue_t xStaticQueue;
- /* The array to use as the queue's storage area. This must be at least
+ enum protocol_tx_state {
+ PRLTxPHYReset,
+ PRLTxWaitMessage,
+ PRLTxReset,
+ PRLTxConstructMessage,
+ PRLTxWaitResponse,
+ PRLTxMatchMessageID,
+ PRLTxTransmissionError,
+ PRLTxMessageSent,
+ PRLTxDiscardMessage
+ };
+ //Internal states
+ static protocol_tx_state protocol_tx_discard_message();
+ static protocol_tx_state protocol_tx_message_sent();
+ static protocol_tx_state protocol_tx_transmission_error();
+ static protocol_tx_state protocol_tx_match_messageid();
+ static protocol_tx_state protocol_tx_wait_response();
+ static protocol_tx_state protocol_tx_construct_message();
+ static protocol_tx_state protocol_tx_reset();
+ static protocol_tx_state protocol_tx_wait_message();
+ static protocol_tx_state protocol_tx_phy_reset();
+ //queue of up to PDB_MSG_POOL_SIZE messages to send
+ static StaticQueue_t xStaticQueue;
+ /* The array to use as the queue's storage area. This must be at least
uxQueueLength * uxItemSize bytes. */
- static uint8_t ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
- static QueueHandle_t messagesWaiting;
- static uint8_t _tx_messageidcounter;
- static bool messagePending();
- //Reads a message off the queue into the temp message
- static void getMessage();
- static union pd_msg temp_msg;
- static Notifications waitForEvent(uint32_t mask, TickType_t ticksToWait =
- portMAX_DELAY);
+ static uint8_t ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
+ static QueueHandle_t messagesWaiting;
+ static uint8_t _tx_messageidcounter;
+ static bool messagePending();
+ //Reads a message off the queue into the temp message
+ static void getMessage();
+ static union pd_msg temp_msg;
+ static Notifications waitForEvent(uint32_t mask, TickType_t ticksToWait =
+ portMAX_DELAY);
+
};
#endif /* PDB_PROTOCOL_TX_H */
diff --git a/workspace/TS100/Core/Drivers/Font.h b/workspace/TS100/Core/Drivers/Font.h
index 50932504..50932504 100644..100755
--- a/workspace/TS100/Core/Drivers/Font.h
+++ b/workspace/TS100/Core/Drivers/Font.h
diff --git a/workspace/TS100/Core/Drivers/I2CBB.cpp b/workspace/TS100/Core/Drivers/I2CBB.cpp
index 200fecfe..200fecfe 100644..100755
--- a/workspace/TS100/Core/Drivers/I2CBB.cpp
+++ b/workspace/TS100/Core/Drivers/I2CBB.cpp
diff --git a/workspace/TS100/Core/Drivers/I2CBB.hpp b/workspace/TS100/Core/Drivers/I2CBB.hpp
index 6d733c90..6d733c90 100644..100755
--- a/workspace/TS100/Core/Drivers/I2CBB.hpp
+++ b/workspace/TS100/Core/Drivers/I2CBB.hpp
diff --git a/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp b/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp
index 9d5996df..9d5996df 100644..100755
--- a/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp
+++ b/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp
diff --git a/workspace/TS100/Core/Drivers/LIS2DH12.cpp b/workspace/TS100/Core/Drivers/LIS2DH12.cpp
index 02aad5b6..02aad5b6 100644..100755
--- a/workspace/TS100/Core/Drivers/LIS2DH12.cpp
+++ b/workspace/TS100/Core/Drivers/LIS2DH12.cpp
diff --git a/workspace/TS100/Core/Drivers/LIS2DH12.hpp b/workspace/TS100/Core/Drivers/LIS2DH12.hpp
index e4cccd48..e4cccd48 100644..100755
--- a/workspace/TS100/Core/Drivers/LIS2DH12.hpp
+++ b/workspace/TS100/Core/Drivers/LIS2DH12.hpp
diff --git a/workspace/TS100/Core/Drivers/LIS2DH12_defines.hpp b/workspace/TS100/Core/Drivers/LIS2DH12_defines.hpp
index c233aca5..c233aca5 100644..100755
--- a/workspace/TS100/Core/Drivers/LIS2DH12_defines.hpp
+++ b/workspace/TS100/Core/Drivers/LIS2DH12_defines.hpp
diff --git a/workspace/TS100/Core/Drivers/MMA8652FC.cpp b/workspace/TS100/Core/Drivers/MMA8652FC.cpp
index fa8b91fe..fa8b91fe 100644..100755
--- a/workspace/TS100/Core/Drivers/MMA8652FC.cpp
+++ b/workspace/TS100/Core/Drivers/MMA8652FC.cpp
diff --git a/workspace/TS100/Core/Drivers/MMA8652FC.hpp b/workspace/TS100/Core/Drivers/MMA8652FC.hpp
index 9b5f44d1..9b5f44d1 100644..100755
--- a/workspace/TS100/Core/Drivers/MMA8652FC.hpp
+++ b/workspace/TS100/Core/Drivers/MMA8652FC.hpp
diff --git a/workspace/TS100/Core/Drivers/MMA8652FC_defines.h b/workspace/TS100/Core/Drivers/MMA8652FC_defines.h
index d3526c02..d3526c02 100644..100755
--- a/workspace/TS100/Core/Drivers/MMA8652FC_defines.h
+++ b/workspace/TS100/Core/Drivers/MMA8652FC_defines.h
diff --git a/workspace/TS100/Core/Drivers/OLED.cpp b/workspace/TS100/Core/Drivers/OLED.cpp
index 4a8906df..0fd6bb3c 100644..100755
--- a/workspace/TS100/Core/Drivers/OLED.cpp
+++ b/workspace/TS100/Core/Drivers/OLED.cpp
@@ -97,10 +97,12 @@ void OLED::initialize() {
// initialisation data to the OLED.
setDisplayState(DisplayState::ON);
- FRToSI2C::writeRegistersBulk(DEVICEADDR_OLED, OLED_Setup_Array, sizeof(OLED_Setup_Array) / sizeof(OLED_Setup_Array[0]));
-
+ for (int tries = 0; tries < 10; tries++) {
+ if (FRToSI2C::writeRegistersBulk(DEVICEADDR_OLED, OLED_Setup_Array, sizeof(OLED_Setup_Array) / sizeof(OLED_Setup_Array[0]))) {
+ return;
+ }
+ }
}
-
void OLED::setFramebuffer(uint8_t *buffer) {
if (buffer == NULL) {
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
@@ -176,13 +178,13 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
progress = OLED_WIDTH;
}
- // When forward, current contents move to the left out.
- // Otherwise the contents move to the right out.
+// When forward, current contents move to the left out.
+// Otherwise the contents move to the right out.
uint8_t oldStart = forwardNavigation ? 0 : progress;
uint8_t oldPrevious = forwardNavigation ? progress - offset : offset;
- // Content from the second framebuffer moves in from the right (forward)
- // or from the left (not forward).
+// Content from the second framebuffer moves in from the right (forward)
+// or from the left (not forward).
uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0;
uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress;
@@ -231,7 +233,7 @@ void OLED::setRotation(bool leftHanded) {
screenBuffer[5] = inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed
// mode as driver ram is 128 wide
- screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; // End address of the ram segment we are writing to (96 wide)
+ screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; // End address of the ram segment we are writing to (96 wide)
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
}
@@ -245,7 +247,7 @@ void OLED::print(const char *str) {
void OLED::setFont(uint8_t fontNumber) {
if (fontNumber == 1) {
- // small font
+// small font
currentFont = USER_FONT_6x8;
fontHeight = 8;
fontWidth = 6;
@@ -337,9 +339,9 @@ void OLED::drawSymbol(uint8_t symbolID) {
void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t *ptr) {
// Splat this from x->x+wide in two strides
if (x <= -wide)
- return; // cutoffleft
+ return; // cutoffleft
if (x > 96)
- return; // cutoff right
+ return; // cutoff right
uint8_t visibleStart = 0;
uint8_t visibleEnd = wide;
@@ -353,13 +355,13 @@ void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin
}
if (y == 0) {
- // Splat first line of data
+// Splat first line of data
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
firstStripPtr[xx + x] = ptr[xx];
}
}
if (y == 8 || height == 16) {
- // Splat the second line
+// Splat the second line
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
}
@@ -373,7 +375,7 @@ void OLED::drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height, co
if (x <= -wide)
return; // cutoffleft
if (x > 96)
- return; // cutoff right
+ return; // cutoff right
uint8_t visibleStart = 0;
uint8_t visibleEnd = wide;
@@ -387,14 +389,14 @@ void OLED::drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height, co
}
if (y == 0) {
- // Splat first line of data
+// Splat first line of data
for (uint8_t xx = visibleStart; xx < visibleEnd; xx += 2) {
firstStripPtr[xx + x] = ptr[xx + 1];
firstStripPtr[xx + x + 1] = ptr[xx];
}
}
if (y == 8 || height == 16) {
- // Splat the second line
+// Splat the second line
for (uint8_t xx = visibleStart; xx < visibleEnd; xx += 2) {
secondStripPtr[x + xx] = ptr[xx + 1 + (height == 16 ? wide : 0)];
secondStripPtr[x + xx + 1] = ptr[xx + (height == 16 ? wide : 0)];
@@ -407,7 +409,7 @@ void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin
if (x <= -wide)
return; // cutoffleft
if (x > 96)
- return; // cutoff right
+ return; // cutoff right
uint8_t visibleStart = 0;
uint8_t visibleEnd = wide;
@@ -421,13 +423,13 @@ void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin
}
if (y == 0) {
- // Splat first line of data
+// Splat first line of data
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
firstStripPtr[xx + x] = value;
}
}
if (y == 8 || height == 16) {
- // Splat the second line
+// Splat the second line
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
secondStripPtr[x + xx] = value;
}
@@ -473,7 +475,7 @@ void OLED::drawHeatSymbol(uint8_t state) {
// Draw symbol 14
// Then draw over it, the bottom 5 pixels always stay. 8 pixels above that are
// the levels masks the symbol nicely
- state /= 31; // 0-> 8 range
+ state /= 31; // 0-> 8 range
// Then we want to draw down (16-(5+state)
uint8_t cursor_x_temp = cursor_x;
drawSymbol(14);
diff --git a/workspace/TS100/Core/Drivers/OLED.hpp b/workspace/TS100/Core/Drivers/OLED.hpp
index 5e3238a7..5e3238a7 100644..100755
--- a/workspace/TS100/Core/Drivers/OLED.hpp
+++ b/workspace/TS100/Core/Drivers/OLED.hpp
diff --git a/workspace/TS100/Core/Drivers/README.md b/workspace/TS100/Core/Drivers/README.md
index 9b5ebf91..9b5ebf91 100644..100755
--- a/workspace/TS100/Core/Drivers/README.md
+++ b/workspace/TS100/Core/Drivers/README.md
diff --git a/workspace/TS100/Core/Drivers/Si7210.cpp b/workspace/TS100/Core/Drivers/Si7210.cpp
index b3eae4ae..b3eae4ae 100644..100755
--- a/workspace/TS100/Core/Drivers/Si7210.cpp
+++ b/workspace/TS100/Core/Drivers/Si7210.cpp
diff --git a/workspace/TS100/Core/Drivers/Si7210.h b/workspace/TS100/Core/Drivers/Si7210.h
index ed99ba2b..ed99ba2b 100644..100755
--- a/workspace/TS100/Core/Drivers/Si7210.h
+++ b/workspace/TS100/Core/Drivers/Si7210.h
diff --git a/workspace/TS100/Core/Drivers/Si7210_defines.h b/workspace/TS100/Core/Drivers/Si7210_defines.h
index a7123069..a7123069 100644..100755
--- a/workspace/TS100/Core/Drivers/Si7210_defines.h
+++ b/workspace/TS100/Core/Drivers/Si7210_defines.h
diff --git a/workspace/TS100/Core/Drivers/TipThermoModel.cpp b/workspace/TS100/Core/Drivers/TipThermoModel.cpp
index 18ab0a10..18ab0a10 100644..100755
--- a/workspace/TS100/Core/Drivers/TipThermoModel.cpp
+++ b/workspace/TS100/Core/Drivers/TipThermoModel.cpp
diff --git a/workspace/TS100/Core/Drivers/TipThermoModel.h b/workspace/TS100/Core/Drivers/TipThermoModel.h
index a4b0b368..a4b0b368 100644..100755
--- a/workspace/TS100/Core/Drivers/TipThermoModel.h
+++ b/workspace/TS100/Core/Drivers/TipThermoModel.h
diff --git a/workspace/TS100/Core/Inc/FreeRTOSHooks.h b/workspace/TS100/Core/Inc/FreeRTOSHooks.h
index 8dca47e6..8dca47e6 100644..100755
--- a/workspace/TS100/Core/Inc/FreeRTOSHooks.h
+++ b/workspace/TS100/Core/Inc/FreeRTOSHooks.h
diff --git a/workspace/TS100/Core/Inc/QC3.h b/workspace/TS100/Core/Inc/QC3.h
index 9ba9d5b4..9ba9d5b4 100644..100755
--- a/workspace/TS100/Core/Inc/QC3.h
+++ b/workspace/TS100/Core/Inc/QC3.h
diff --git a/workspace/TS100/Core/Inc/Settings.h b/workspace/TS100/Core/Inc/Settings.h
index e9ca84e9..e9ca84e9 100644..100755
--- a/workspace/TS100/Core/Inc/Settings.h
+++ b/workspace/TS100/Core/Inc/Settings.h
diff --git a/workspace/TS100/Core/Inc/Translation.h b/workspace/TS100/Core/Inc/Translation.h
index e090f06d..e090f06d 100644..100755
--- a/workspace/TS100/Core/Inc/Translation.h
+++ b/workspace/TS100/Core/Inc/Translation.h
diff --git a/workspace/TS100/Core/Inc/configuration.h b/workspace/TS100/Core/Inc/configuration.h
index a6ad04b1..a6ad04b1 100644..100755
--- a/workspace/TS100/Core/Inc/configuration.h
+++ b/workspace/TS100/Core/Inc/configuration.h
diff --git a/workspace/TS100/Core/Inc/expMovingAverage.h b/workspace/TS100/Core/Inc/expMovingAverage.h
index 374befb7..374befb7 100644..100755
--- a/workspace/TS100/Core/Inc/expMovingAverage.h
+++ b/workspace/TS100/Core/Inc/expMovingAverage.h
diff --git a/workspace/TS100/Core/Inc/gui.hpp b/workspace/TS100/Core/Inc/gui.hpp
index b199a376..b199a376 100644..100755
--- a/workspace/TS100/Core/Inc/gui.hpp
+++ b/workspace/TS100/Core/Inc/gui.hpp
diff --git a/workspace/TS100/Core/Inc/history.hpp b/workspace/TS100/Core/Inc/history.hpp
index c6dd8778..c6dd8778 100644..100755
--- a/workspace/TS100/Core/Inc/history.hpp
+++ b/workspace/TS100/Core/Inc/history.hpp
diff --git a/workspace/TS100/Core/Inc/main.hpp b/workspace/TS100/Core/Inc/main.hpp
index 990806f7..effe5a05 100644..100755
--- a/workspace/TS100/Core/Inc/main.hpp
+++ b/workspace/TS100/Core/Inc/main.hpp
@@ -12,7 +12,7 @@ extern "C" {
#endif
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
- signed portCHAR *pcTaskName);
+ signed portCHAR *pcTaskName);
//Threads
void startGUITask(void const *argument);
diff --git a/workspace/TS100/Core/Inc/power.hpp b/workspace/TS100/Core/Inc/power.hpp
index 8998f3de..8998f3de 100644..100755
--- a/workspace/TS100/Core/Inc/power.hpp
+++ b/workspace/TS100/Core/Inc/power.hpp
diff --git a/workspace/TS100/Core/Inc/stm32f1xx_hal_conf.h b/workspace/TS100/Core/Inc/stm32f1xx_hal_conf.h
index b3e68d1a..b3e68d1a 100644..100755
--- a/workspace/TS100/Core/Inc/stm32f1xx_hal_conf.h
+++ b/workspace/TS100/Core/Inc/stm32f1xx_hal_conf.h
diff --git a/workspace/TS100/Core/Inc/stm32f1xx_it.h b/workspace/TS100/Core/Inc/stm32f1xx_it.h
index c40b6bdf..c40b6bdf 100644..100755
--- a/workspace/TS100/Core/Inc/stm32f1xx_it.h
+++ b/workspace/TS100/Core/Inc/stm32f1xx_it.h
diff --git a/workspace/TS100/Core/Src/FreeRTOSHooks.c b/workspace/TS100/Core/Src/FreeRTOSHooks.c
index d801f9d9..d801f9d9 100644..100755
--- a/workspace/TS100/Core/Src/FreeRTOSHooks.c
+++ b/workspace/TS100/Core/Src/FreeRTOSHooks.c
diff --git a/workspace/TS100/Core/Src/QC3.cpp b/workspace/TS100/Core/Src/QC3.cpp
index 719f2c72..719f2c72 100644..100755
--- a/workspace/TS100/Core/Src/QC3.cpp
+++ b/workspace/TS100/Core/Src/QC3.cpp
diff --git a/workspace/TS100/Core/Src/Settings.cpp b/workspace/TS100/Core/Src/Settings.cpp
index 581a3f40..581a3f40 100644..100755
--- a/workspace/TS100/Core/Src/Settings.cpp
+++ b/workspace/TS100/Core/Src/Settings.cpp
diff --git a/workspace/TS100/Core/Src/freertos.c b/workspace/TS100/Core/Src/freertos.c
index dd171c8e..dd171c8e 100644..100755
--- a/workspace/TS100/Core/Src/freertos.c
+++ b/workspace/TS100/Core/Src/freertos.c
diff --git a/workspace/TS100/Core/Src/gui.cpp b/workspace/TS100/Core/Src/gui.cpp
index 616bb20c..616bb20c 100644..100755
--- a/workspace/TS100/Core/Src/gui.cpp
+++ b/workspace/TS100/Core/Src/gui.cpp
diff --git a/workspace/TS100/Core/Src/main.cpp b/workspace/TS100/Core/Src/main.cpp
index e9e3d62f..e9e3d62f 100644..100755
--- a/workspace/TS100/Core/Src/main.cpp
+++ b/workspace/TS100/Core/Src/main.cpp
diff --git a/workspace/TS100/Core/Src/power.cpp b/workspace/TS100/Core/Src/power.cpp
index 5620f50c..5620f50c 100644..100755
--- a/workspace/TS100/Core/Src/power.cpp
+++ b/workspace/TS100/Core/Src/power.cpp
diff --git a/workspace/TS100/Core/Src/syscalls.c b/workspace/TS100/Core/Src/syscalls.c
index 94e38850..94e38850 100644..100755
--- a/workspace/TS100/Core/Src/syscalls.c
+++ b/workspace/TS100/Core/Src/syscalls.c
diff --git a/workspace/TS100/Core/Threads/GUIThread.cpp b/workspace/TS100/Core/Threads/GUIThread.cpp
index 5af727c8..5af727c8 100644..100755
--- a/workspace/TS100/Core/Threads/GUIThread.cpp
+++ b/workspace/TS100/Core/Threads/GUIThread.cpp
diff --git a/workspace/TS100/Core/Threads/MOVThread.cpp b/workspace/TS100/Core/Threads/MOVThread.cpp
index 745c10fa..745c10fa 100644..100755
--- a/workspace/TS100/Core/Threads/MOVThread.cpp
+++ b/workspace/TS100/Core/Threads/MOVThread.cpp
diff --git a/workspace/TS100/Core/Threads/PIDThread.cpp b/workspace/TS100/Core/Threads/PIDThread.cpp
index 72f7606f..72f7606f 100644..100755
--- a/workspace/TS100/Core/Threads/PIDThread.cpp
+++ b/workspace/TS100/Core/Threads/PIDThread.cpp