Browse Source

添加SN组件

transmit_disinfection
zhaohe 11 months ago
parent
commit
219877a3ae
  1. 40
      basic/sn.c
  2. 41
      basic/sn.h
  3. 1
      basic/zgpio.c
  4. 1
      basic/zlog.c
  5. 1
      zbasic.h

40
basic/sn.c

@ -0,0 +1,40 @@
#include "sn.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*******************************************************************************
* EXTERN *
*******************************************************************************/
static sn_t m_sn;
sn_t* xs_device_info_get() { //
sn_t* info = (sn_t*)DEVICE_INFO_START_ADD;
m_sn = *info;
if (m_sn.year < 0) {
m_sn.year = 0;
}
if (m_sn.weak < 0) {
m_sn.weak = 0;
}
if (m_sn.index < 0) {
m_sn.index = 0;
}
return &m_sn;
}
const char* sn_get_str() {
sn_t* info = xs_device_info_get();
static char sn_str[32];
sprintf(sn_str, "%s%02ld%02ld%04ld", "SN", info->year, info->weak, info->index);
return sn_str;
}

41
basic/sn.h

@ -0,0 +1,41 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "main.h"
#include "project_configs.h"
/**
* @brief
* STM32F407VETx 1024k
*
* index startAdd size
* 0 0x08000000 16k
* 1 0x08004000 16k
* 2 0x08008000 16k
* 3 0x0800C000 16k
* 4 0x08010000 64k
* 5 0x08020000 128k
* 6 0x08040000 128k
* 7 0x08060000 128k
* 8 0x08080000 128k
* 9 0x080A0000 128k
* 10 0x080C0000 128k
* 11 0x080E0000 128k
*
*
* @WARNING:
*/
#define DEVICE_INFO_START_ADD SDK_CFG__SN_FLASH_ADDR //
#pragma pack(1)
typedef struct {
uint8_t year;
uint8_t weak;
uint16_t index;
} sn_t;
#pragma pack()
sn_t* sn_get();
const char* sn_get_str();

1
basic/zgpio.c

@ -2,6 +2,7 @@
#include "zdelay.h"
#include "zlog.h"
#include "project_configs.h"
static bool gpio_enable_clock(GPIO_TypeDef *m_gpio) {
#ifdef GPIOA

1
basic/zlog.c

@ -1,5 +1,6 @@
#include "zlog.h"
#include "zbase.h"
#include "project_configs.h"
bool g_xs_enable_log = true;
extern UART_HandleTypeDef DEBUG_UART;

1
zbasic.h

@ -9,6 +9,7 @@ extern "C" {
#include "basic/zflash.h"
#include "basic/zgpio.h"
#include "basic/zlog.h"
#include "basic/sn.h"
#include "cmsis_version.h"
#include "cmsis_os.h"

Loading…
Cancel
Save