tinyusb
hal.h
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
39 #ifndef _TUSB_HAL_H_
40 #define _TUSB_HAL_H_
41 
42 //--------------------------------------------------------------------+
43 // INCLUDES
44 //--------------------------------------------------------------------+
45 #include "tusb_option.h"
46 #include "common/primitive_types.h"
47 #include "common/tusb_errors.h"
49 
50 // callback from tusb.h
51 extern void tusb_isr(uint8_t coreid);
52 
53 //--------------------------------------------------------------------+
54 // HAL API
55 //--------------------------------------------------------------------+
69 
75 static inline void hal_interrupt_enable(uint8_t coreid) ATTR_ALWAYS_INLINE;
76 
82 static inline void hal_interrupt_disable(uint8_t coreid) ATTR_ALWAYS_INLINE;
83 
84 //--------------------------------------------------------------------+
85 // INCLUDE DRIVEN
86 //--------------------------------------------------------------------+
87 #if TUSB_CFG_MCU == MCU_LPC11UXX
88  #include "hal_lpc11uxx.h"
89 #elif TUSB_CFG_MCU == MCU_LPC13UXX
90  #include "hal_lpc13uxx.h"
91 #elif TUSB_CFG_MCU == MCU_LPC43XX
92  #include "hal_lpc43xx.h"
93 #elif TUSB_CFG_MCU == MCU_LPC175X_6X
94  #include "hal_lpc175x_6x.h"
95 #else
96  #error MCU is not defined or supported yet
97 #endif
98 
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102 
103 
104 static inline bool hal_debugger_is_attached(void) ATTR_PURE ATTR_ALWAYS_INLINE;
105 static inline bool hal_debugger_is_attached(void)
106 {
107 // TODO check core M3/M4 defined instead
108 #if !defined(_TEST_) && !(TUSB_CFG_MCU==MCU_LPC11UXX)
109  return ( (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == CoreDebug_DHCSR_C_DEBUGEN_Msk );
110 #elif TUSB_CFG_DEBUG == 3
111  return true; // force to break into breakpoint with debug = 3
112 #else
113  return false
114 #endif
115 }
116 
117 static inline void hal_debugger_breakpoint(void) ATTR_ALWAYS_INLINE;
118 static inline void hal_debugger_breakpoint(void)
119 {
120 #ifndef _TEST_
121  if (hal_debugger_is_attached()) /* if there is debugger connected */
122  {
123  __asm("BKPT #0\n");
124  }
125 #endif
126 }
127 
128 #ifdef __cplusplus
129  }
130 #endif
131 
132 #endif /* _TUSB_HAL_H_ */
133 
#define ATTR_PURE
Many functions have no effects except the return value and their return value depends only on the par...
Definition: compiler_gcc.h:96
static void hal_interrupt_disable(uint8_t coreid) ATTR_ALWAYS_INLINE
Disable USB Interrupt on a specific USB Controller.
static void hal_interrupt_enable(uint8_t coreid) ATTR_ALWAYS_INLINE
Enable USB Interrupt on a specific USB Controller.
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100
void tusb_isr(uint8_t coreid)
USB interrupt handler.
Definition: tusb.c:71
#define ATTR_ALWAYS_INLINE
Generally, functions are not inlined unless optimization is specified. For functions declared inline...
Definition: compiler_gcc.h:89
tusb_error_t hal_init(void)
Initialize USB controller hardware.
Definition: hal_lpc11uxx.c:44