/*
 * Copyright 2022 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */


#ifndef __BOARD_INIT_H__
#define __BOARD_INIT_H__

#include <stdio.h>
#include <stdint.h>

#include "hal_common.h"
#include "hal_rcc.h"
#include "hal_uart.h"
#include "hal_enet.h"

#include "clock_init.h"
#include "pin_init.h"

/* DEBUG UART. */
#define BOARD_DEBUG_UART_PORT        UART1
#define BOARD_DEBUG_UART_BAUDRATE    9600u
#define BOARD_DEBUG_UART_FREQ        CLOCK_APB2_FREQ

/* ENET. */
#define BOARD_DEBUG_ENET_PORT        ENET
#define BOARD_DEBUG_ENET_IRQn        ENET_IRQn
#define BOARD_DEBUG_ENET_Handler     ENET_IRQHandler

/* initialization enet. */
#define ENET_PHY_ADDR                      0x01      /* Select PHY address. */
#define ENET_PHY_CONTROLREG                0u        /* PHY control register address. */
#define ENET_PHY_STATUSREG                 1u        /* PHY status register sddress. */
#define ENET_PHY_RESET                     0x8000    /* Set PHY reset, use in ENET_PHY_CR registers */
#define ENET_PHY_SPEED100M                 0x2000    /* Set PHY speed. */
#define ENET_PHY_FULLDUPLEX                0x0100    /* Set PHY duplex mode about full duplex. */
#define ENET_PHY_LINK                      0x0004    /* PHY link-up. */
#define ENET_PHY_UNIDIRECTIONAL            0x0080    /* PHY has the ability to encode and transmit data from PHY through MII interface, regardless of whether PHY has determined that an effective link has been connected and established. */
#define ENET_PHY_AUTONEGOTIATION           0x1000    /* PHY auto negotiation. */
#define ENET_TX_BUFLEN                     1518u     /* Tx buffer length. */
#define ENET_TX_NUM                        5u        /* The number of tx. */
#define ENET_RX_BUFLEN                     1518u     /* Configure the frame length of a received frame. */
#define ENET_RX_NUM                        5u        /* The configured number of received descriptor that can be used for receiving. */
#define ENET_ADDR_FILTER_NUM               1u         /* Select MAC address filter number from 0~5. */


#define BOARD_MAC_ADDR0   2u
#define BOARD_MAC_ADDR1   0u
#define BOARD_MAC_ADDR2   0u
#define BOARD_MAC_ADDR3   0u
#define BOARD_MAC_ADDR4   0u
#define BOARD_MAC_ADDR5   0u

#define BOARD_IP_ADDR0                    192u
#define BOARD_IP_ADDR1                    168u
#define BOARD_IP_ADDR2                    105u
#define BOARD_IP_ADDR3                    98u

#define BOARD_NETMASK_ADDR0               255u
#define BOARD_NETMASK_ADDR1               255u
#define BOARD_NETMASK_ADDR2               255u
#define BOARD_NETMASK_ADDR3                 0u

#define BOARD_GW_ADDR0                    192u
#define BOARD_GW_ADDR1                    168u
#define BOARD_GW_ADDR2                    105u
#define BOARD_GW_ADDR3                      1u

#define BOARD_TCP_SERVER_IPADDR0  192u
#define BOARD_TCP_SERVER_IPADDR1  168u
#define BOARD_TCP_SERVER_IPADDR2  105u
#define BOARD_TCP_SERVER_IPADDR3  85u

#define BOARD_TCP_SERVER_PORT 6800u

void BOARD_Init(void);

#endif /* __BOARD_INIT_H__ */

