dev.h 7.93 KB
#ifndef __DEV_H
#define __DEV_H	 
#include "stm32f4xx.h" 
#include "stm32f4xx_conf.h"

#include "stdio.h"
#include "stdbool.h"												     
#include "stdlib.h"
#include "string.h"


//CH395A(USART6)
#define		CH_TX_Pin				GPIO_Pin_7
#define		CH_TX_Port				GPIOC
#define		CH_RX_Pin				GPIO_Pin_6
#define		CH_RX_Port				GPIOC

//RS232(UART4)
#define		U232_RX_Pin				GPIO_Pin_11
#define		U232_RX_Port			GPIOC
#define		U232_TX_Pin				GPIO_Pin_10
#define		U232_TX_Port			GPIOC

//RS485(UART5)
#define		U485_RX_Pin				GPIO_Pin_2
#define		U485_RX_Port			GPIOD
#define		U485_TX_Pin				GPIO_Pin_12
#define		U485_TX_Port			GPIOC
#define		EN_485_Pin				GPIO_Pin_3
#define		EN_485_Port				GPIOD

//DEBUG(USART1)
#define		DBG_RXD_Pin				GPIO_Pin_9
#define		DBG_RXD_Port			GPIOA
#define		DBG_TXD_Pin				GPIO_Pin_10
#define		DBG_TXD_Port			GPIOA



//LED
#define		ARM_LED1_Pin			GPIO_Pin_8
#define		ARM_LED1_Port			GPIOA
#define		ARM_LED2_Pin			GPIO_Pin_8
#define		ARM_LED2_Port			GPIOG
#define		ARM_LED3_Pin			GPIO_Pin_7
#define		ARM_LED3_Port			GPIOG
#define		ARM_LED4_Pin			GPIO_Pin_6
#define		ARM_LED4_Port			GPIOG




//DI、DO
#define		IN1_Pin					GPIO_Pin_0	
#define		IN1_Port				GPIOB
#define		IN2_Pin					GPIO_Pin_1	
#define		IN2_Port				GPIOB
#define		CTRL1_Pin				GPIO_Pin_2	
#define		CTRL1_Port				GPIOC
#define		CTRL2_Pin				GPIO_Pin_3	
#define		CTRL2_Port				GPIOC


//RMII
#define		RMII_MDC_Pin			GPIO_Pin_1
#define		RMII_MDC_Port			GPIOC
#define		RMII_CLK_Pin			GPIO_Pin_1
#define		RMII_CLK_Port			GPIOA
#define		RMII_MDIO_Pin			GPIO_Pin_2
#define		RMII_MDIO_Port			GPIOA
#define		RMII_CRS_Pin			GPIO_Pin_7
#define		RMII_CRS_Port			GPIOA
#define		RMII_RXD0_Pin			GPIO_Pin_4
#define		RMII_RXD0_Port			GPIOC
#define		RMII_RXD1_Pin			GPIO_Pin_5
#define		RMII_RXD1_Port			GPIOC
#define		RMII_TXEN_Pin			GPIO_Pin_11
#define		RMII_TXEN_Port			GPIOG
#define		RMII_TXD0_Pin			GPIO_Pin_13
#define		RMII_TXD0_Port			GPIOG
#define		RMII_TXD1_Pin			GPIO_Pin_14
#define		RMII_TXD1_Port			GPIOG


//FSMC
#define		FSMC_A0_Pin				GPIO_Pin_0
#define		FSMC_A0_Port			GPIOF
#define		FSMC_A1_Pin				GPIO_Pin_1
#define		FSMC_A1_Port			GPIOF
#define		FSMC_A2_Pin				GPIO_Pin_2
#define		FSMC_A2_Port			GPIOF
#define		FSMC_A3_Pin				GPIO_Pin_3
#define		FSMC_A3_Port			GPIOF
#define		FSMC_A4_Pin				GPIO_Pin_4
#define		FSMC_A4_Port			GPIOF
#define		FSMC_A5_Pin				GPIO_Pin_5
#define		FSMC_A5_Port			GPIOF
#define		FSMC_A6_Pin				GPIO_Pin_12
#define		FSMC_A6_Port			GPIOF
#define		FSMC_A7_Pin				GPIO_Pin_13
#define		FSMC_A7_Port			GPIOF
#define		FSMC_A8_Pin				GPIO_Pin_14
#define		FSMC_A8_Port			GPIOF
#define		FSMC_A9_Pin				GPIO_Pin_15
#define		FSMC_A9_Port			GPIOF

#define		FSMC_A10_Pin			GPIO_Pin_0
#define		FSMC_A10_Port			GPIOG
#define		FSMC_A11_Pin			GPIO_Pin_1
#define		FSMC_A11_Port			GPIOG
#define		FSMC_A12_Pin			GPIO_Pin_2
#define		FSMC_A12_Port			GPIOG
#define		FSMC_A13_Pin			GPIO_Pin_3
#define		FSMC_A13_Port			GPIOG
#define		FSMC_A14_Pin			GPIO_Pin_4
#define		FSMC_A14_Port			GPIOG
#define		FSMC_A15_Pin			GPIO_Pin_5
#define		FSMC_A15_Port			GPIOG

#define		FSMC_A16_Pin			GPIO_Pin_11
#define		FSMC_A16_Port			GPIOD
#define		FSMC_A17_Pin			GPIO_Pin_12
#define		FSMC_A17_Port			GPIOD
#define		FSMC_A18_Pin			GPIO_Pin_13
#define		FSMC_A18_Port			GPIOD
#define		DB0_Pin					GPIO_Pin_14
#define		DB0_Port				GPIOD
#define		DB1_Pin					GPIO_Pin_15
#define		DB1_Port				GPIOD

#define		DB2_Pin					GPIO_Pin_0
#define		DB2_Port				GPIOD
#define		DB3_Pin					GPIO_Pin_1
#define		DB3_Port				GPIOD

#define		DB4_Pin					GPIO_Pin_7
#define		DB4_Port				GPIOE
#define		DB5_Pin					GPIO_Pin_8
#define		DB5_Port				GPIOE
#define		DB6_Pin					GPIO_Pin_9
#define		DB6_Port				GPIOE
#define		DB7_Pin					GPIO_Pin_10
#define		DB7_Port				GPIOE
#define		DB8_Pin					GPIO_Pin_11
#define		DB8_Port				GPIOE
#define		DB9_Pin					GPIO_Pin_12
#define		DB9_Port				GPIOE
#define		DB10_Pin				GPIO_Pin_13
#define		DB10_Port				GPIOE
#define		DB11_Pin				GPIO_Pin_14
#define		DB11_Port				GPIOE
#define		DB12_Pin				GPIO_Pin_15
#define		DB12_Port				GPIOE

#define		DB13_Pin				GPIO_Pin_8
#define		DB13_Port				GPIOD
#define		DB14_Pin				GPIO_Pin_9
#define		DB14_Port				GPIOD
#define		DB15_Pin				GPIO_Pin_10
#define		DB15_Port				GPIOD

#define		FSMC_BL1_Pin			GPIO_Pin_1
#define		FSMC_BL1_Port			GPIOE
#define		FSMC_BL0_Pin			GPIO_Pin_0
#define		FSMC_BL0_Port			GPIOE

#define		FSMC_NE_Pin				GPIO_Pin_7
#define		FSMC_NE_Port			GPIOD
#define		FSMC_NWE_Pin			GPIO_Pin_5
#define		FSMC_NWE_Port			GPIOD
#define		FSMC_NOE_Pin			GPIO_Pin_4
#define		FSMC_NOE_Port			GPIOD

#define		PHY_RESET_Pin			GPIO_Pin_0
#define		PHY_RESET_Port			GPIOC



//IIC(用于AI)
#define		SDA_Pin					GPIO_Pin_7
#define		SDA_Port				GPIOB
#define		SCL_Pin					GPIO_Pin_6
#define		SCL_Port				GPIOB


//SPI(外部EEPROM)
#define		SSPI1_MOSI_Pin			GPIO_Pin_5
#define		SSPI1_MOSI_Port			GBIOB
#define		SSPI1_MISO_Pin			GPIO_Pin_4
#define		SSPI1_MISO_Port			GBIOB
#define		SSPI1_SCK_Pin			GPIO_Pin_3
#define		SSPI1_SLK_Port			GBIOB
#define		SSPI1_SSEL_Pin			GPIO_Pin_15
#define		SSPI1_SSEL_Port			GBIOG

//CH395Q
#define		CH_MOSI_Pin				GPIO_Pin_15
#define		CH_MOSI_Port			GPIOB
#define		CH_MISO_Pin				GPIO_Pin_14
#define		CH_MISO_Port			GPIOB
#define		CH_SCK_Pin				GPIO_Pin_13
#define		CH_SCK_Port				GPIOB
#define		CH_CS_Pin				GPIO_Pin_12
#define		CH_CS_Port				GPIOB


//EC20
#define		GPRS_RST_Pin			GPIO_Pin_9
#define		GPRS_RST_Port			GPIOB
#define		GPRS_PWR_Pin			GPIO_Pin_8
#define		GPRS_PWR_Port			GPIOB
#define		GPRS_RX_Pin				GPIO_Pin_10
#define		GPRS_RX_Port			GPIOB
#define		GPRS_TX_Pin				GPIO_Pin_11
#define		GPRS_TX_Port			GPIOB


//CH395Q
#define		DATA_Pin				GPIO_Pin_2
#define		DATA_Port				GPIOE
#define		CH_RST_Pin				GPIO_Pin_9
#define		CH_RST_Port				GPIOC
#define		CH_IRQ_Pin				GPIO_Pin_8
#define		CH_IRQ_Port				GPIOC
#define		CH_TX_Pin				GPIO_Pin_7
#define		CH_TX_Port				GPIOC
#define		CH_RX_Pin				GPIO_Pin_6
#define		CH_RX_Port				GPIOC


//电源开关
typedef 	enum	power_switch
{
	OFF,
	ON
}power_switch;




#define 	IP_MAX_LENGTH           	30
#define 	GATEWAY_ID_MAX_LENGTH   	25
#define 	USERNAME_MAX_LENGTH     	15
#define 	PASSWORD_MAX_LENGTH    	 	15
#define 	CLIENT_ID_MAX_LENGTH 		26

typedef		struct mqtt_server
{
    char ip[IP_MAX_LENGTH];
    char port[6];
    char gateway_id[GATEWAY_ID_MAX_LENGTH];
	char client_id[CLIENT_ID_MAX_LENGTH];
	
    char user_name[USERNAME_MAX_LENGTH];
    char password[PASSWORD_MAX_LENGTH];
	short iot_id;	
}mqtt_server;



typedef		struct 	Gateway_struct
{
	uint8_t		dev_id;
	uint32_t 	mapping_id;
	
	char  		soft_version[9];	//软件版本V01.02.03
	uint32_t	temperature;		//芯片温度
	uint32_t	firmware_length;
	uint8_t 	net1_mac[6];		//网口1 Mac地址
	uint8_t		net2_mac[6];		//网口2 Mac地址
	uint8_t		ota_server_url[80];
	uint8_t 	ntp_server[30];
	
	mqtt_server mqtt_broker;
	
}Gateway_struct;

extern Gateway_struct 	dev_param;



//以下为汇编函数
void WFI_SET(void);			//执行WFI指令
void INTX_DISABLE(void);	//关闭所有中断
void INTX_ENABLE(void);		//开启所有中断
void MSR_MSP(u32 addr);		//设置堆栈地址 



#define		SRAM_INT_ADDR			0x20000000		//Internal SRAM基址
#define		SRAM_CCM_ADDR			0x10000000		//CCM基址
#define		SRAM_EXT_ADDR			0x68000000		//External SRAM基址

#define		BOOTLOADER_RUN			0x1234ABCD
#define		BOOTLOADER_LOAD			0x4567AABB
#define		BOOTLOADER_DEFAULT		0xFFFFFFFF

#define		PARAM_BASE_ADDR			0x08008000		//存储参数的基地址
#define		FLAG_BASE_ADDR			0x08004000		//Sector 3用于系统标志存储
#define		APP_RUN_ADDR			0x08010000		//运行
#define		APP_LOAD_ADDR			0x08040000		//更新

/**********************************************************
*  SECTOR	|			BLOCK BASE ADDR			|	SIZE
*
*  sector0 	|		0x0800 0000~0x0800 3FFF		|	16K		//BOOTLOADER
*
*  sector1	|		0x0800 4000~0x0800 7FFF		| 	16K		//FLAG
*
*  sector2	|		0x0800 8000~0x0800 BFFF		|	16K		//PARAM
*
*  sector3	|		0x0800 C000~0x0800 FFFF		|	16K		
*
*  sector4	|		0x0801 0000~0x0801 FFFF		| 	64K		//RUN APP
*	
*  sector5	|		0x0802 0000~0x0803 FFFF  	|	128K	
*
*  sector6	|		0x0804 0000~0x0805 FFFF		|	128K	//LOAD APP
*
*  sector7	|		0x0806 0000~0x0807 FFFF		|	128K	
*************************************************************/


#endif