更新4G驱动
This commit is contained in:
parent
5a3b4fc846
commit
bc90218521
|
@ -15,6 +15,8 @@
|
|||
#include "kit_debug.h"
|
||||
#include "bsp_hmi.h"
|
||||
#include "drv_w5500.h"
|
||||
#include "drv_eg25gminipice.h"
|
||||
|
||||
#define APP_HMI_BUF_SIZE (1024 * 4)
|
||||
uint8_t hmi_buf[4][APP_HMI_BUF_SIZE] __attribute__((section (".CCM_RAM")));
|
||||
|
||||
|
@ -171,6 +173,7 @@ static void exter_can_rx_it_call(kit_ret_e res, void *data)
|
|||
bsp_queue_push_instance(&exter_can_queue, data);
|
||||
OS_TRACE_ISR_EXIT();
|
||||
}
|
||||
|
||||
/*********************************************MODBUS实例***************************************************/
|
||||
extern EEpromItem eeprom_item;
|
||||
GATE_STATIC_INIT2_CCM(modbus_gate, 200, (kEep_GateDataEnd - kEep_GateDataStart));
|
||||
|
@ -235,6 +238,13 @@ static void inter_uart_rx_it_call(kit_ret_e res, void *data)
|
|||
OS_TRACE_ISR_EXIT();
|
||||
}
|
||||
|
||||
static void sim_uart_rx_it_call(kit_ret_e res, void *data)
|
||||
{
|
||||
OS_TRACE_ISR_ENTER();
|
||||
drv_sim_push_data(&sim_item, data, 1);
|
||||
OS_TRACE_ISR_EXIT();
|
||||
}
|
||||
|
||||
static void exter_uart1_rx_it_call(kit_ret_e res, void *data)
|
||||
{
|
||||
OS_TRACE_ISR_ENTER();
|
||||
|
@ -249,6 +259,7 @@ static void exter_uart2_rx_it_call(kit_ret_e res, void *data)
|
|||
OS_TRACE_ISR_EXIT();
|
||||
}
|
||||
|
||||
|
||||
static void uart_tx_it_call(kit_ret_e res, void *data)
|
||||
{
|
||||
uint8_t dev = *(uint8_t *)data;
|
||||
|
@ -301,6 +312,9 @@ void bms_init_comm(void)
|
|||
drv_uart_set_interrupt(EXTER_UART1_PORT, kUartInterrupt_Rx, APP_CFG_INT_PRIO_UART2_RX, exter_uart1_rx_it_call);
|
||||
drv_uart_set_interrupt(EXTER_UART2_PORT, kUartInterrupt_Rx, APP_CFG_INT_PRIO_UART2_RX, exter_uart2_rx_it_call);
|
||||
|
||||
drv_uart_set_interrupt(SIM_UART_PORT, kUartInterrupt_Rx, APP_CFG_INT_PRIO_UART2_RX, sim_uart_rx_it_call);//#define SIM_UART_PORT kUartDev_2
|
||||
|
||||
|
||||
drv_can_init(INTER_CAN_PORT, 250, kGpioType_Can_Ch1_Rx, kGpioType_Can_Ch1_Tx);
|
||||
drv_can_set_interrupt(INTER_CAN_PORT, kcan_interrupt_e_Rx, APP_CFG_INT_PRIO_CAN1_RX, inter_can_rx_it_call);
|
||||
drv_can_set_interrupt(INTER_CAN_PORT, kcan_interrupt_e_Tx, APP_CFG_INT_PRIO_CAN1_TX, inter_can_tx_it_call);
|
||||
|
|
|
@ -14,9 +14,13 @@ extern "C" {
|
|||
//gary @update 调整顺序
|
||||
#define INTER_CAN_PORT kcan_dev_e_1
|
||||
#define EXTER_CAN_PORT kcan_dev_e_2
|
||||
|
||||
#define INTER_UART_PORT kUartDev_1
|
||||
#define EXTER_UART1_PORT kUartDev_3
|
||||
#define EXTER_UART2_PORT kUartDev_4
|
||||
#define SIM_UART_PORT kUartDev_2
|
||||
|
||||
|
||||
#define BMS_485_CHANNEL (3u)
|
||||
|
||||
#define W5500_MODBUS_NUM (8u)
|
||||
|
|
|
@ -1047,8 +1047,8 @@
|
|||
<TargetCommonOption>
|
||||
<Device>STM32F407VGTx</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F4xx_DFP.2.14.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<PackID>Keil.STM32F4xx_DFP.3.0.0</PackID>
|
||||
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
<StartupFile></StartupFile>
|
||||
|
|
|
@ -9,6 +9,25 @@
|
|||
#include "drv_eg25gminipice.h"
|
||||
|
||||
#define UART2_BAUDRATE 115200
|
||||
#define MAX_RETRY 3
|
||||
|
||||
//4G实例化
|
||||
static uint8_t sim_rec_buf[MAX_RECV_LEN] = {0};
|
||||
LTE4G_STATIC_INIT(sim_item, 1, 0, 0, 1024,sim_rec_buf);
|
||||
|
||||
|
||||
void drv_sim_push_data(Lte4GItem* item, uint8_t *buf, uint16_t len)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
if((item != NULL) && (item->buf_pos + len < item->buf_size))
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
item->buf[item->buf_pos++] = buf[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drv_uart2_Init(void)
|
||||
{
|
||||
|
@ -39,18 +58,48 @@ void drv_send_at_cmd(const char *cmd, int delay_ms)
|
|||
{
|
||||
drv_uart2_sendString(cmd);
|
||||
drv_uart2_sendString("\r\n"); // AT 指令以 "\r\n" 结尾
|
||||
for (volatile int i = 0; i < delay_ms * 1000; i++); // ¼òµ¥ÑÓʱ
|
||||
kit_time_dly_ms(30);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void drv_eg25g_init(void)
|
||||
{
|
||||
drv_send_at_cmd("AT", 500);
|
||||
drv_send_at_cmd("AT+CPIN?", 500);
|
||||
drv_send_at_cmd("AT+CREG?", 500);
|
||||
drv_send_at_cmd("AT+CGATT=1", 500);
|
||||
drv_send_at_cmd("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", 500);
|
||||
drv_send_at_cmd("AT+SAPBR=3,1,\"APN\",\"your_apn\"", 500);
|
||||
drv_send_at_cmd("AT+SAPBR=1,1", 2000);
|
||||
drv_send_at_cmd("AT", 500); // 1. 测试 AT 指令
|
||||
drv_send_at_cmd("AT+CPIN?", 500); // 2. 查询 SIM 卡状态
|
||||
drv_send_at_cmd("AT+COPS=0", 500); // 3. 让模块自动选择运营商
|
||||
drv_send_at_cmd("AT+CEREG?", 1000); // 4. 查询 4G 注册状态
|
||||
// drv_send_at_cmd("AT+CGDCONT=1,\"IP\",\"your_apn\"", 500); // 5. 设置 APN 如果支持自动识别则不需要设置apn
|
||||
drv_send_at_cmd("AT+CGACT=1,1", 1000); // 6. 激活 PDP(获取 IP)
|
||||
drv_send_at_cmd("AT+CGPADDR=1", 500); // 7. 查询分配的 IP 地址
|
||||
}
|
||||
|
||||
// 发送 AT 指令并等待返回值,可用于此优化初始化函数
|
||||
int drv_send_at_cmd2(const char *cmd, int delay_ms)
|
||||
{
|
||||
for (int i = 0; i < MAX_RETRY; i++) // 失败最多重试 MAX_RETRY 次
|
||||
{
|
||||
drv_uart2_sendString(cmd);
|
||||
drv_uart2_sendString("\r\n"); // AT 指令以 "\r\n" 结尾
|
||||
kit_time_dly_ms(30);
|
||||
|
||||
if (sim_item.buf_pos > 0 && strstr((const char*)sim_item.buf, "OK")) // 解析返回值
|
||||
{
|
||||
return 1; // 成功
|
||||
}
|
||||
}
|
||||
return 0; // 失败
|
||||
}
|
||||
|
||||
void drv_eg25g_init2(void)
|
||||
{
|
||||
if (!drv_send_at_cmd2("AT", 500)) return; // 1. 测试 AT 指令
|
||||
if (!drv_send_at_cmd2("AT+CPIN?", 500)) return; // 2. 查询 SIM 卡状态
|
||||
if (!drv_send_at_cmd2("AT+COPS=0", 500)) return; // 3. 让模块自动选择运营商
|
||||
if (!drv_send_at_cmd2("AT+CEREG?", 1000)) return; // 4. 查询 4G 注册状态
|
||||
if (!drv_send_at_cmd2("AT+CGDCONT=1,\"IP\",\"your_apn\"", 500)) return; // 5. 设置 APN
|
||||
if (!drv_send_at_cmd2("AT+CGACT=1,1", 1000)) return; // 6. 激活 PDP(获取 IP)
|
||||
if (!drv_send_at_cmd2("AT+CGPADDR=1", 500)) return; // 7. 查询分配的 IP 地址
|
||||
}
|
||||
|
||||
void drv_mqtt_connect(void)
|
||||
|
@ -67,7 +116,9 @@ void drv_mqtt_publish(const char *topic, const char *message)
|
|||
drv_send_at_cmd(cmd, 500);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
int main(void) {
|
||||
SystemInit();
|
||||
drv_uart2_Init();
|
||||
|
@ -80,5 +131,6 @@ int main(void) {
|
|||
for (volatile int i = 0; i < 10000000; i++); // 发送间隔
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
@ -17,6 +17,32 @@
|
|||
#include "kit_debug.h"
|
||||
|
||||
#include "ucos_ii.h"
|
||||
#include "string.h"
|
||||
|
||||
#define MAX_RECV_LEN 1024
|
||||
|
||||
|
||||
//¶¨ÒåÄ£×é4G½á¹¹
|
||||
typedef struct _Lte4GItem
|
||||
{
|
||||
uint8_t addr;
|
||||
uint8_t comm_dev;
|
||||
uint16_t buf_pos;
|
||||
uint16_t buf_size;
|
||||
uint8_t *buf;
|
||||
} Lte4GItem;
|
||||
|
||||
#define LTE4G_STATIC_INIT(_name, _addr, _comm_dev, _buf_pos, _buf_size,_recv) \
|
||||
Lte4GItem _name = \
|
||||
{ \
|
||||
(_addr), \
|
||||
(_comm_dev), \
|
||||
(_buf_pos),\
|
||||
(_buf_size),\
|
||||
(_recv),\
|
||||
}
|
||||
|
||||
extern Lte4GItem sim_item;
|
||||
|
||||
void drv_uart2_Init(void);
|
||||
void drv_uart2_sendbyte(char c);
|
||||
|
@ -25,8 +51,10 @@ void drv_send_at_cmd(const char *cmd, int delay_ms);
|
|||
void drv_eg25g_init(void);
|
||||
void drv_mqtt_connect(void);
|
||||
void drv_mqtt_publish(const char *topic, const char *message);
|
||||
|
||||
void drv_sim_push_data(Lte4GItem* item, uint8_t *buf, uint16_t len);
|
||||
|
||||
|
||||
|
||||
#endif //DRV_EG25GMINIPICE_H_
|
||||
|
||||
|
Loading…
Reference in New Issue