You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.0 KiB
103 lines
3.0 KiB
#include "zport.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "zboard.h"
|
|
|
|
uint8_t g_port_exit_critical_count;
|
|
|
|
uint32_t sys_haspassedms(uint32_t ticket)
|
|
{
|
|
uint32_t nowticket = HAL_GetTick();
|
|
if (nowticket >= ticket)
|
|
{
|
|
return nowticket - ticket;
|
|
}
|
|
return UINT32_MAX - ticket + nowticket;
|
|
}
|
|
|
|
///**********************************************************************************************************************
|
|
// * ===================================================printf重定向=================================================== *
|
|
// **********************************************************************************************************************/
|
|
int fputc(int ch, FILE *stream)
|
|
{
|
|
uint8_t c = ch;
|
|
HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100);
|
|
return ch;
|
|
}
|
|
///***********************************************************************************************************************
|
|
// * ====================================================调试指示灯===================================================== *
|
|
// ***********************************************************************************************************************/
|
|
void port_do_debug_light_state(void)
|
|
{
|
|
static uint32_t lastprocess = 0;
|
|
if (sys_haspassedms(lastprocess) > 300)
|
|
{
|
|
lastprocess = HAL_GetTick();
|
|
HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN);
|
|
}
|
|
}
|
|
/***********************************************************************************************************************
|
|
* *******************************************************串口******************************************************** *
|
|
***********************************************************************************************************************/
|
|
static uart_t m_uarts[] = {
|
|
{&DEBUG_UART, 0}
|
|
// {&ENV_SENSOR_UART485, 0},
|
|
};
|
|
|
|
__weak void port_mock_on_uart_rx(uart_t *uart) {}
|
|
|
|
static void uarts_start_receive(uart_t *uart) { HAL_UART_Receive_IT(uart->uarthandler, &uart->rxbuf, 1); }
|
|
|
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
|
{
|
|
for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
|
|
{
|
|
if (m_uarts[i].uarthandler == huart)
|
|
{
|
|
port_mock_on_uart_rx(&m_uarts[i]);
|
|
uarts_start_receive(&m_uarts[i]);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
|
{
|
|
for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
|
|
{
|
|
if (m_uarts[i].uarthandler == huart)
|
|
{
|
|
uarts_start_receive(&m_uarts[i]);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// export
|
|
void port_uart_start_all_uart_receive(void)
|
|
{
|
|
for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
|
|
{
|
|
uarts_start_receive(&m_uarts[i]);
|
|
}
|
|
}
|
|
|
|
void sys_critical_enter(void)
|
|
{
|
|
if (g_port_exit_critical_count == 0)
|
|
{
|
|
// __disable_irq();
|
|
HAL_NVIC_DisableIRQ(USART1_IRQn);
|
|
}
|
|
g_port_exit_critical_count++;
|
|
}
|
|
void sys_critical_exit(void)
|
|
{
|
|
g_port_exit_critical_count--;
|
|
if (g_port_exit_critical_count == 0)
|
|
{
|
|
// __enable_irq();
|
|
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
|
}
|
|
}
|