11 changed files with 368 additions and 0 deletions
-
19chip/chip.c
-
124chip/chip.h
-
33chip/delay.c
-
16chip/delay.h
-
6chip/iflytop_no_os.c
-
38chip/iflytop_no_os.h
-
33chip/log.c
-
54chip/log.h
-
45chip/marco.h
-
0components/log/log.c
-
0components/log/log.h
@ -0,0 +1,19 @@ |
|||||
|
|
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
uint8_t g_port_exit_critical_count; |
||||
|
|
||||
|
void sys_critical_enter(void) { |
||||
|
if (g_port_exit_critical_count == 0) { |
||||
|
__disable_irq(); |
||||
|
} |
||||
|
g_port_exit_critical_count++; |
||||
|
} |
||||
|
void sys_critical_exit(void) { |
||||
|
g_port_exit_critical_count--; |
||||
|
if (g_port_exit_critical_count == 0) { |
||||
|
__enable_irq(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,124 @@ |
|||||
|
#pragma once |
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
|
||||
|
#include "main.h" |
||||
|
|
||||
|
#ifdef HAL_CRYP_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_ADC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_CAN_MODULE_ENABLED |
||||
|
#include "can.h" |
||||
|
#endif |
||||
|
#ifdef HAL_CRC_MODULE_ENABLED |
||||
|
#include "crc.h" |
||||
|
#endif |
||||
|
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DAC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DCMI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DMA2D_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_ETH_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_NAND_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_NOR_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_PCCARD_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SRAM_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SDRAM_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_HASH_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_I2C_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_I2S_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_IWDG_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_LTDC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_RNG_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_RTC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SAI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SD_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_MMC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SPI_MODULE_ENABLED |
||||
|
#include "spi.h" |
||||
|
#endif |
||||
|
#ifdef HAL_TIM_MODULE_ENABLED |
||||
|
#include "tim.h" |
||||
|
#endif |
||||
|
#ifdef HAL_UART_MODULE_ENABLED |
||||
|
#include "usart.h" |
||||
|
#endif |
||||
|
#ifdef HAL_USART_MODULE_ENABLED |
||||
|
#include "usart.h" |
||||
|
#endif |
||||
|
#ifdef HAL_IRDA_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SMARTCARD_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SMBUS_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_WWDG_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_PCD_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_HCD_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DSI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_QSPI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_QSPI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_CEC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_FMPI2C_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_FMPSMBUS_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_SPDIFRX_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DFSDM_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_LPTIM_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_GPIO_MODULE_ENABLED |
||||
|
#include "gpio.h" |
||||
|
#endif |
||||
|
#ifdef HAL_EXTI_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_DMA_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_RCC_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_FLASH_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_PWR_MODULE_ENABLED |
||||
|
#endif |
||||
|
#ifdef HAL_CORTEX_MODULE_ENABLED |
||||
|
#endif |
||||
|
|
||||
|
void chip_critical_enter(void); |
||||
|
void chip_critical_exit(void); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,33 @@ |
|||||
|
|
||||
|
#include "delay.h" |
||||
|
#include <stdint.h> |
||||
|
|
||||
|
static TIM_HandleTypeDef *m_dhtim; |
||||
|
void chip_delay_init(TIM_HandleTypeDef *htim) { m_dhtim = htim; } |
||||
|
void chip_delay_us(uint32_t n) { |
||||
|
uint16_t counter = 0; |
||||
|
__HAL_TIM_SET_COUNTER(m_dhtim, 0); |
||||
|
HAL_TIM_Base_Start(m_dhtim); |
||||
|
while (counter < n) { |
||||
|
counter = __HAL_TIM_GET_COUNTER(m_dhtim); |
||||
|
} |
||||
|
HAL_TIM_Base_Stop(m_dhtim); |
||||
|
} |
||||
|
void chip_delay_ms(uint32_t n) { |
||||
|
uint32_t i; |
||||
|
for (i = 0; i < n; i++) { |
||||
|
chip_delay_us(1000); |
||||
|
} |
||||
|
} |
||||
|
uint32_t chip_get_ticket() { |
||||
|
uint32_t ticket = HAL_GetTick(); |
||||
|
return ticket; |
||||
|
} |
||||
|
|
||||
|
uint32_t haspassedms(uint32_t ticket) { |
||||
|
uint32_t nowticket = HAL_GetTick(); |
||||
|
if (nowticket >= ticket) { |
||||
|
return nowticket - ticket; |
||||
|
} |
||||
|
return UINT32_MAX - ticket + nowticket; |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#pragma once |
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
#include <stdint.h> |
||||
|
|
||||
|
#include "chip.h" |
||||
|
|
||||
|
void chip_delay_init(TIM_HandleTypeDef *htim); |
||||
|
void chip_delay_us(uint32_t n); |
||||
|
void chip_delay_ms(uint32_t n); |
||||
|
uint32_t chip_get_ticket(); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,6 @@ |
|||||
|
#include "iflytop_no_os.h" |
||||
|
|
||||
|
void iflytop_no_os_init(iflytop_no_os_cfg_t* os) { |
||||
|
chip_delay_init(os->delayhtim); |
||||
|
ifly_loggger_init(os->debuguart); |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
/** |
||||
|
* @file iflytop_no_os.h |
||||
|
* @author zhaohe (h_zhaohe@163.com) |
||||
|
* @brief |
||||
|
* @version 0.1 |
||||
|
* @date 2023-07-11 |
||||
|
* |
||||
|
* @copyright Copyright (c) 2023 |
||||
|
* |
||||
|
*/ |
||||
|
#pragma once |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
#include "marco.h" |
||||
|
// |
||||
|
#include "chip.h" |
||||
|
// |
||||
|
#include "delay.h" |
||||
|
// |
||||
|
#include "log.h" |
||||
|
// |
||||
|
typedef struct { |
||||
|
TIM_HandleTypeDef *delayhtim; |
||||
|
UART_HandleTypeDef *debuguart; |
||||
|
|
||||
|
} iflytop_no_os_cfg_t; |
||||
|
|
||||
|
void iflytop_no_os_init(iflytop_no_os_cfg_t *os); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,33 @@ |
|||||
|
#include "log.h" |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
#include <stddef.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
static UART_HandleTypeDef *m_huart; |
||||
|
|
||||
|
bool g_enable_log; |
||||
|
|
||||
|
/********************************************************************* |
||||
|
* @fn _write |
||||
|
* |
||||
|
* @brief Support Printf Function |
||||
|
* |
||||
|
* @param *buf - UART send Data. |
||||
|
* size - Data length |
||||
|
* |
||||
|
* @return size: Data length |
||||
|
*/ |
||||
|
__attribute__((used)) int _write(int fd, char *buf, int size) { |
||||
|
int i; |
||||
|
|
||||
|
for (i = 0; i < size; i++) { |
||||
|
uint8_t c = *buf++; |
||||
|
if (m_huart != NULL) HAL_UART_Transmit(m_huart, &c, 1, 100); |
||||
|
} |
||||
|
|
||||
|
return size; |
||||
|
} |
||||
|
|
||||
|
void ifly_loggger_init(UART_HandleTypeDef *huart) { m_huart = huart; } |
||||
|
void ifly_loggger_enable(bool enable) { g_enable_log = enable; } |
@ -0,0 +1,54 @@ |
|||||
|
#pragma once |
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
|
||||
|
#include "chip.h" |
||||
|
#include "delay.h" |
||||
|
/*********************************************************************************************************************** |
||||
|
* =======================================================鏃ュ織======================================================== * |
||||
|
***********************************************************************************************************************/ |
||||
|
extern bool g_enable_log; |
||||
|
#define ZLOG_RELEASE(TAG, fmt, ...) \ |
||||
|
if (g_enable_log) { \ |
||||
|
printf(TAG "" fmt "\n", ##__VA_ARGS__); \ |
||||
|
} |
||||
|
#define ZLOGI(TAG, fmt, ...) \ |
||||
|
if (g_enable_log) { \ |
||||
|
printf("%08u INFO [%-8s] " fmt "\n", ifly_get_ticket(), TAG, ##__VA_ARGS__); \ |
||||
|
} |
||||
|
#define ZLOGD(TAG, fmt, ...) \ |
||||
|
if (g_enable_log) { \ |
||||
|
printf("%08u DEBU [%-8s] " fmt "\n", ifly_get_ticket(), TAG, ##__VA_ARGS__); \ |
||||
|
} |
||||
|
#define ZLOGE(TAG, fmt, ...) \ |
||||
|
if (g_enable_log) { \ |
||||
|
printf("%08u ERRO [%-8s] " fmt "\n", ifly_get_ticket(), TAG, ##__VA_ARGS__); \ |
||||
|
} |
||||
|
|
||||
|
#define ZLOGI_HEX(TAG, hextable, table_size) \ |
||||
|
if (g_enable_log) { \ |
||||
|
printf("%08u INFO [%-8s] \t", ifly_get_ticket(), TAG); \ |
||||
|
for (int i = 0; i < table_size; i++) { \ |
||||
|
printf(" %02X", hextable[i]); \ |
||||
|
} \ |
||||
|
printf("\n"); \ |
||||
|
} |
||||
|
|
||||
|
#define ZASSERT(cond) \ |
||||
|
if (!(cond)) { \ |
||||
|
while (1) { \ |
||||
|
printf("ASSERT: %s [%s:%d]\n", #cond, __FILE__, __LINE__); \ |
||||
|
ifly_delay_ms(1000); \ |
||||
|
} \ |
||||
|
} |
||||
|
|
||||
|
void ifly_loggger_init(UART_HandleTypeDef *huart); |
||||
|
void ifly_loggger_enable(bool enable); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,45 @@ |
|||||
|
#pragma once |
||||
|
#ifndef ZARRAY_SIZE |
||||
|
#define ZARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) |
||||
|
#endif |
||||
|
#define ZMAX(a, b) ((a) > (b) ? (a) : (b)) |
||||
|
#define ZMIN(a, b) ((a) < (b) ? (a) : (b)) |
||||
|
|
||||
|
#ifndef INT8_MIN |
||||
|
#define INT8_MIN (-128) |
||||
|
#endif |
||||
|
#ifndef INT16_MIN |
||||
|
#define INT16_MIN (-32768) |
||||
|
#endif |
||||
|
#ifndef INT32_MIN |
||||
|
#define INT32_MIN (-2147483647 - 1) |
||||
|
#endif |
||||
|
#ifndef INT64_MIN |
||||
|
#define INT64_MIN (-9223372036854775807LL - 1) |
||||
|
#endif |
||||
|
|
||||
|
#ifndef INT8_MAX |
||||
|
#define INT8_MAX 127 |
||||
|
#endif |
||||
|
#ifndef INT16_MAX |
||||
|
#define INT16_MAX 32767 |
||||
|
#endif |
||||
|
#ifndef INT32_MAX |
||||
|
#define INT32_MAX 2147483647 |
||||
|
#endif |
||||
|
#ifndef INT64_MAX |
||||
|
#define INT64_MAX 9223372036854775807LL |
||||
|
#endif |
||||
|
|
||||
|
#ifndef UINT8_MAX |
||||
|
#define UINT8_MAX 255 |
||||
|
#endif |
||||
|
#ifndef UINT16_MAX |
||||
|
#define UINT16_MAX 65535 |
||||
|
#endif |
||||
|
#ifndef UINT32_MAX |
||||
|
#define UINT32_MAX 0xffffffffU /* 4294967295U */ |
||||
|
#endif |
||||
|
#ifndef UINT64_MAX |
||||
|
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ |
||||
|
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue