2727#include "bsp/board.h"
2828#include "board.h"
2929
30- #include <registers/ft900_registers.h>
3130#include <ft900.h>
31+ #include <registers/ft900_registers.h>
3232
3333#if CFG_TUD_ENABLED
34- int8_t board_ft90x_vbus (void ); // Board specific implementation of VBUS detection for USB device.
35- extern void ft90x_usbd_pm_ISR (uint16_t pmcfg ); // Interrupt handler for USB device power management
34+ int8_t board_ft9xx_vbus (void ); // Board specific implementation of VBUS detection for USB device.
35+ extern void ft9xx_usbd_pm_ISR (uint16_t pmcfg ); // Interrupt handler for USB device power management
3636#endif
3737
38- #ifdef GPIO_REMOTE_WAKEUP
38+ #ifdef BOARD_GPIO_REMOTE_WAKEUP
3939void gpio_ISR (void );
4040#endif
4141void timer_ISR (void );
@@ -49,12 +49,17 @@ void board_pm_ISR(void);
4949void board_init (void )
5050{
5151 sys_reset_all ();
52+
5253 // Enable the UART Device.
5354 sys_enable (sys_device_uart0 );
54- // Set UART0 GPIO functions to UART0_TXD and UART0_RXD.
55- gpio_function (GPIO_UART0_TX , pad_uart0_txd ); /* UART0 TXD */
56- gpio_function (GPIO_UART0_RX , pad_uart0_rxd ); /* UART0 RXD */
57- uart_open (UART0 , /* Device */
55+ // Set BOARD_UART GPIO function pins for TXD and RXD.
56+ #ifdef BOARD_GPIO_UART_TX
57+ gpio_function (BOARD_GPIO_UART_TX , pad_uart0_txd ); /* UART0 TXD */
58+ #endif
59+ #ifdef BOARD_GPIO_UART_RX
60+ gpio_function (BOARD_GPIO_UART_RX , pad_uart0_rxd ); /* UART0 RXD */
61+ #endif
62+ uart_open (BOARD_UART , /* Device */
5863 1 , /* Prescaler = 1 */
5964 UART_DIVIDER_19200_BAUD , /* Divider = 1302 */
6065 uart_data_bits_8 , /* No. Data Bits */
@@ -64,12 +69,17 @@ void board_init(void)
6469 // Use sizeof to avoid pulling in strlen unnecessarily.
6570 board_uart_write (WELCOME_MSG , sizeof (WELCOME_MSG ));
6671
67- #if 0
68- // Ethernet LEDs
69- gpio_function (GPIO_ETH_LED0 , pad_gpio4 ); /* ETH LED0 */
70- gpio_dir (GPIO_ETH_LED0 , pad_dir_open_drain );
71- gpio_function (GPIO_ETH_LED1 , pad_gpio5 ); /* ETH LED1 */
72- gpio_dir (GPIO_ETH_LED1 , pad_dir_output );
72+ #ifdef BOARD_GPIO_LED
73+ gpio_function (BOARD_GPIO_LED , pad_func_0 );
74+ gpio_idrive (BOARD_GPIO_LED , pad_drive_12mA );
75+ gpio_dir (BOARD_GPIO_LED , pad_dir_output );
76+ #endif
77+
78+ #ifdef BOARD_GPIO_BUTTON
79+ gpio_function (BOARD_GPIO_BUTTON , pad_func_0 );
80+ // Pull up if active low. Down if active high.
81+ gpio_pull (BOARD_GPIO_BUTTON , (BOARD_GPIO_BUTTON_STATE_ACTIVE == 0 )?pad_pull_pullup :pad_pull_pulldown );
82+ gpio_dir (BOARD_GPIO_BUTTON , pad_dir_input );
7383#endif
7484
7585 sys_enable (sys_device_timer_wdt );
@@ -82,26 +92,26 @@ void board_init(void)
8292
8393 // Setup VBUS detect GPIO. If the device is connected then this
8494 // will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
85- gpio_interrupt_disable (USBD_VBUS_DTC_PIN );
86- gpio_function (USBD_VBUS_DTC_PIN , pad_vbus_dtc );
87- gpio_pull (USBD_VBUS_DTC_PIN , pad_pull_pulldown );
88- gpio_dir (USBD_VBUS_DTC_PIN , pad_dir_input );
95+ gpio_interrupt_disable (BOARD_USBD_VBUS_DTC_PIN );
96+ gpio_function (BOARD_USBD_VBUS_DTC_PIN , pad_vbus_dtc );
97+ gpio_pull (BOARD_USBD_VBUS_DTC_PIN , pad_pull_pulldown );
98+ gpio_dir (BOARD_USBD_VBUS_DTC_PIN , pad_dir_input );
8999
90100 interrupt_attach (interrupt_0 , (int8_t )interrupt_0 , board_pm_ISR );
91101
92- #ifdef GPIO_REMOTE_WAKEUP
93- //Configuring GPIO pin to wakeup.
102+ #ifdef BOARD_GPIO_REMOTE_WAKEUP
103+ // Configuring GPIO pin to wakeup.
94104 // Set up the wakeup pin.
95- gpio_dir (GPIO_REMOTE_WAKEUP_PIN , pad_dir_input );
96- gpio_pull (GPIO_REMOTE_WAKEUP_PIN , pad_pull_pullup );
105+ gpio_dir (BOARD_GPIO_REMOTE_WAKEUP , pad_dir_input );
106+ gpio_pull (BOARD_GPIO_REMOTE_WAKEUP , pad_pull_pullup );
97107
98108 // Attach an interrupt handler.
99109 interrupt_attach (interrupt_gpio , (uint8_t )interrupt_gpio , gpio_ISR );
100- gpio_interrupt_enable (GPIO_REMOTE_WAKEUP_PIN , gpio_int_edge_falling );
110+ gpio_interrupt_enable (BOARD_GPIO_REMOTE_WAKEUP , gpio_int_edge_falling );
101111#endif
102112
103- uart_disable_interrupt (UART0 , uart_interrupt_tx );
104- uart_disable_interrupt (UART0 , uart_interrupt_rx );
113+ uart_disable_interrupt (BOARD_UART , uart_interrupt_tx );
114+ uart_disable_interrupt (BOARD_UART , uart_interrupt_rx );
105115
106116 // Enable all peripheral interrupts.
107117 interrupt_enable_globally ();
@@ -117,10 +127,10 @@ void timer_ISR(void)
117127 }
118128}
119129
120- #ifdef GPIO_REMOTE_WAKEUP
130+ #ifdef BOARD_GPIO_REMOTE_WAKEUP
121131void gpio_ISR (void )
122132{
123- if (gpio_is_interrupted (GPIO_REMOTE_WAKEUP_PIN ))
133+ if (gpio_is_interrupted (BOARD_GPIO_REMOTE_WAKEUP ))
124134 {
125135 }
126136}
@@ -153,16 +163,16 @@ void board_pm_ISR(void)
153163 )
154164 {
155165#if CFG_TUD_ENABLED
156- ft90x_usbd_pm_ISR (pmcfg );
166+ ft9xx_usbd_pm_ISR (pmcfg );
157167#endif
158168 }
159169#endif
160170}
161171
162172#if CFG_TUD_ENABLED
163- int8_t board_ft90x_vbus (void )
173+ int8_t board_ft9xx_vbus (void )
164174{
165- return gpio_read (USBD_VBUS_DTC_PIN );
175+ return gpio_read (BOARD_USBD_VBUS_DTC_PIN );
166176}
167177#endif
168178
@@ -173,31 +183,48 @@ int8_t board_ft90x_vbus(void)
173183// Turn LED on or off
174184void board_led_write (bool state )
175185{
176- gpio_write (GPIO_ETH_LED0 , state );
186+ #ifdef BOARD_GPIO_LED
187+ gpio_write (BOARD_GPIO_LED , (state == 0 )?(BOARD_GPIO_LED_STATE_ON ?0 :1 ):BOARD_GPIO_LED_STATE_ON );
188+ #endif
177189}
178190
179191// Get the current state of button
180192// a '1' means active (pressed), a '0' means inactive.
181193uint32_t board_button_read (void )
182194{
183- return 0 ;
195+ uint32_t state = 0 ;
196+ #ifdef BOARD_GPIO_BUTTON
197+ state = (gpio_read (BOARD_GPIO_BUTTON ) == BOARD_GPIO_BUTTON_STATE_ACTIVE )?1 :0 ;
198+ #endif
199+ return state ;
184200}
185201
186202// Get characters from UART
187203int board_uart_read (uint8_t * buf , int len )
188204{
189- int r = uart_readn (UART0 , (uint8_t * )buf , len );
205+ int r = 0 ;
206+
207+ #ifdef BOARD_UART
208+ if (uart_rx_has_data (BOARD_UART ))
209+ {
210+ r = uart_readn (BOARD_UART , (uint8_t * )buf , len );
211+ }
212+ #endif
190213
191214 return r ;
192215}
193216
194217// Send characters to UART
195218int board_uart_write (void const * buf , int len )
196219{
220+ int r = 0 ;
221+
222+ #ifdef BOARD_UART
197223#pragma GCC diagnostic push
198224#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter.
199- int r = uart_writen (UART0 , (uint8_t * )((const void * )buf ), len );
225+ r = uart_writen (BOARD_UART , (uint8_t * )((const void * )buf ), len );
200226#pragma GCC diagnostic pop
227+ #endif
201228
202229 return r ;
203230}
@@ -213,3 +240,18 @@ uint32_t board_millis(void)
213240
214241 return safe_ms ;
215242}
243+
244+ // Restart the program
245+ // Called in the event of a watchdog timeout
246+ void chip_reboot (void )
247+ {
248+ // SOFT reset
249+ __asm__("call 0" );
250+ #if 0
251+ // HARD reset
252+ // Initiates data transfer from Flash Memory to Data Memory (DBG_CMDF2D3)
253+ // followed by a system reboot
254+ dbg_memory_copy (0xfe , 0 , 0 , 255 );
255+ #endif
256+ }
257+
0 commit comments