feat: 增加一些基础功能
This commit is contained in:
@@ -7,8 +7,8 @@ Language: Cpp
|
|||||||
###################################
|
###################################
|
||||||
|
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
IndentWidth: 4
|
IndentWidth: 2
|
||||||
TabWidth: 4
|
TabWidth: 2
|
||||||
ColumnLimit: 0
|
ColumnLimit: 0
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
NamespaceIndentation: All
|
NamespaceIndentation: All
|
||||||
|
|||||||
10
.clangd
Normal file
10
.clangd
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\arm-none-eabi\include\c++\10.2.1
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\arm-none-eabi\include\c++\10.2.1\arm-none-eabi
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\arm-none-eabi\include\c++\10.2.1\backward
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\lib\gcc\arm-none-eabi\10.2.1\include
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\lib\gcc\arm-none-eabi\10.2.1\include-fixed
|
||||||
|
- -Ic:\users\forgotdoge\.eide\tools\gcc_arm\arm-none-eabi\include
|
||||||
|
CompilationDatabase: ./build/Debug
|
||||||
|
Compiler: C:\Users\ForgotDoge\.eide\tools\gcc_arm\bin\arm-none-eabi-gcc.exe
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
"libraries/cmsis",
|
"libraries/cmsis",
|
||||||
"libraries/drivers",
|
"libraries/drivers",
|
||||||
"project",
|
"project",
|
||||||
"app"
|
"app",
|
||||||
|
"3rd-part"
|
||||||
],
|
],
|
||||||
"virtualFolder": {
|
"virtualFolder": {
|
||||||
"name": "<virtual_root>",
|
"name": "<virtual_root>",
|
||||||
@@ -67,7 +68,8 @@
|
|||||||
"libraries/cmsis/cm4/core_support",
|
"libraries/cmsis/cm4/core_support",
|
||||||
"libraries/cmsis/cm4/device_support",
|
"libraries/cmsis/cm4/device_support",
|
||||||
"project/inc",
|
"project/inc",
|
||||||
"libraries/drivers/inc"
|
"libraries/drivers/inc",
|
||||||
|
"3rd-part/lwprintf"
|
||||||
],
|
],
|
||||||
"libList": [],
|
"libList": [],
|
||||||
"sourceDirList": [],
|
"sourceDirList": [],
|
||||||
|
|||||||
400
3rd-part/lwprintf/.gitignore
vendored
Normal file
400
3rd-part/lwprintf/.gitignore
vendored
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
#Build Keil files
|
||||||
|
*.rar
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
*.crf
|
||||||
|
*.htm
|
||||||
|
*.dep
|
||||||
|
*.map
|
||||||
|
*.bak
|
||||||
|
*.axf
|
||||||
|
*.lnp
|
||||||
|
*.lst
|
||||||
|
*.ini
|
||||||
|
*.scvd
|
||||||
|
*.iex
|
||||||
|
*.sct
|
||||||
|
*.MajerleT
|
||||||
|
*.tjuln
|
||||||
|
*.tilen
|
||||||
|
*.dbgconf
|
||||||
|
*.uvguix
|
||||||
|
*.uvoptx
|
||||||
|
*.__i
|
||||||
|
*.i
|
||||||
|
*.txt
|
||||||
|
!docs/*.txt
|
||||||
|
!CMakeLists.txt
|
||||||
|
RTE/
|
||||||
|
|
||||||
|
*debug
|
||||||
|
|
||||||
|
# IAR Settings
|
||||||
|
**/settings/*.crun
|
||||||
|
**/settings/*.dbgdt
|
||||||
|
**/settings/*.cspy
|
||||||
|
**/settings/*.cspy.*
|
||||||
|
**/settings/*.xcl
|
||||||
|
**/settings/*.dni
|
||||||
|
**/settings/*.wsdt
|
||||||
|
**/settings/*.wspos
|
||||||
|
|
||||||
|
# IAR Debug Exe
|
||||||
|
**/Exe/*.sim
|
||||||
|
|
||||||
|
# IAR Debug Obj
|
||||||
|
**/Obj/*.pbd
|
||||||
|
**/Obj/*.pbd.*
|
||||||
|
**/Obj/*.pbi
|
||||||
|
**/Obj/*.pbi.*
|
||||||
|
|
||||||
|
*.TMP
|
||||||
|
/docs_src/x_Doxyfile.doxy
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
[Dd]ebug*/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
_build/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUNIT
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
**/Properties/launchSettings.json
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_i.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
*.out
|
||||||
|
*.sim
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
.idea/
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
# CodeRush
|
||||||
|
.cr/
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
log_file.txt
|
||||||
|
.metadata/
|
||||||
|
.mxproject
|
||||||
|
.settings/
|
||||||
|
project.ioc
|
||||||
|
mx.scratch
|
||||||
|
*.tilen majerle
|
||||||
|
|
||||||
|
|
||||||
|
# Altium
|
||||||
|
Project outputs*
|
||||||
|
History/
|
||||||
|
*.SchDocPreview
|
||||||
|
*.$$$Preview
|
||||||
|
|
||||||
|
# VSCode projects
|
||||||
|
project_vscode_compiled.exe
|
||||||
6
3rd-part/lwprintf/AUTHORS
Normal file
6
3rd-part/lwprintf/AUTHORS
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Tilen Majerle <tilen.majerle@gmail.com>
|
||||||
|
Tilen Majerle <tilen@majerle.eu>
|
||||||
|
Okarss <104319900+Okarss@users.noreply.github.com>
|
||||||
|
Dmitry Karasev <karasevsdmitry@yandex.ru>
|
||||||
|
Brian <bayuan@purdue.edu>
|
||||||
|
Peter Maxwell Warasila <madmaxwell@soundcomesout.com>
|
||||||
41
3rd-part/lwprintf/CHANGELOG.md
Normal file
41
3rd-part/lwprintf/CHANGELOG.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## Develop
|
||||||
|
|
||||||
|
- Add `lwprintf_debug` and `lwprintf_debug_cond` functions
|
||||||
|
|
||||||
|
## v1.0.5
|
||||||
|
|
||||||
|
- Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options
|
||||||
|
|
||||||
|
## v1.0.4
|
||||||
|
|
||||||
|
- Fix calculation for NULL terminated string and precision with 0 as an input
|
||||||
|
- Split CMakeLists.txt files between library and executable
|
||||||
|
- Fix missing break in switch statement
|
||||||
|
- Add support for manual mutual-exclusion setup in OS mode
|
||||||
|
- Change license year to 2022
|
||||||
|
- Update code style with astyle
|
||||||
|
- Add `.clang-format` draft
|
||||||
|
- Fix protection functions for when print mode is not used
|
||||||
|
|
||||||
|
## v1.0.3
|
||||||
|
|
||||||
|
- CMSIS-OS improvements for Kernel aware debuggers
|
||||||
|
|
||||||
|
## v1.0.2
|
||||||
|
|
||||||
|
- Fixed `float` output when engineering mode is disabled
|
||||||
|
|
||||||
|
## v1.0.1
|
||||||
|
|
||||||
|
- Fixed compiler error when engineering mode disabled but float enabled
|
||||||
|
- Properly handled `zero` float inputs
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
- First stable release
|
||||||
|
- Embedded systems optimized library
|
||||||
|
- Apply all modifiers except `%a`
|
||||||
|
- Extensive docs available
|
||||||
|
- Operating system ready with CMSIS-OS template
|
||||||
21
3rd-part/lwprintf/LICENSE
Normal file
21
3rd-part/lwprintf/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
29
3rd-part/lwprintf/README.md
Normal file
29
3rd-part/lwprintf/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Lightweight printf stdio manager
|
||||||
|
|
||||||
|
<h3>Read first: <a href="http://docs.majerle.eu/projects/lwprintf/">Documentation</a></h3>
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Written in C (C11), compatible with ``size_t`` and ``uintmax_t`` types for some specifiers
|
||||||
|
* Implements output functions compatible with ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf``
|
||||||
|
* Low-memory footprint, suitable for embedded systems
|
||||||
|
* Reentrant access to all API functions
|
||||||
|
* Operating-system ready
|
||||||
|
* Requires single output function to be implemented by user for ``printf``-like API calls
|
||||||
|
* With optional functions for operating systems to protect multiple threads printing to the same output stream
|
||||||
|
* Allows multiple output stream functions (unlike standard ``printf`` which supports only one) to separate parts of application
|
||||||
|
* Added additional specifiers vs original features
|
||||||
|
* User friendly MIT license
|
||||||
|
|
||||||
|
## Contribute
|
||||||
|
|
||||||
|
Fresh contributions are always welcome. Simple instructions to proceed:
|
||||||
|
|
||||||
|
1. Fork Github repository
|
||||||
|
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
|
||||||
|
3. Create a pull request to develop branch with new features or bug fixes
|
||||||
|
|
||||||
|
Alternatively you may:
|
||||||
|
|
||||||
|
1. Report a bug
|
||||||
|
2. Ask for a feature request
|
||||||
1274
3rd-part/lwprintf/lwprintf.c
Normal file
1274
3rd-part/lwprintf/lwprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
313
3rd-part/lwprintf/lwprintf.h
Normal file
313
3rd-part/lwprintf/lwprintf.h
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf.h
|
||||||
|
* \brief Lightweight stdio manager
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_HDR_H
|
||||||
|
#define LWPRINTF_HDR_H
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "lwprintf_opt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup LWPRINTF Lightweight stdio manager
|
||||||
|
* \brief Lightweight stdio manager
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Unused variable macro
|
||||||
|
* \param[in] x: Unused variable
|
||||||
|
*/
|
||||||
|
#define LWPRINTF_UNUSED(x) ((void)(x))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Calculate size of statically allocated array
|
||||||
|
* \param[in] x: Input array
|
||||||
|
* \return Number of array elements
|
||||||
|
*/
|
||||||
|
#define LWPRINTF_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Forward declaration for LwPRINTF instance
|
||||||
|
*/
|
||||||
|
struct lwprintf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Callback function for character output
|
||||||
|
* \param[in] ch: Character to print
|
||||||
|
* \param[in] lwobj: LwPRINTF instance
|
||||||
|
* \return `ch` on success, `0` to terminate further string processing
|
||||||
|
*/
|
||||||
|
typedef int (*lwprintf_output_fn)(int ch, struct lwprintf* lwobj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief LwPRINTF instance
|
||||||
|
*/
|
||||||
|
typedef struct lwprintf {
|
||||||
|
lwprintf_output_fn out_fn; /*!< Output function for direct print operations */
|
||||||
|
#if LWPRINTF_CFG_OS || __DOXYGEN__
|
||||||
|
LWPRINTF_CFG_OS_MUTEX_HANDLE mutex; /*!< OS mutex handle */
|
||||||
|
#endif /* LWPRINTF_CFG_OS || __DOXYGEN__ */
|
||||||
|
} lwprintf_t;
|
||||||
|
|
||||||
|
uint8_t lwprintf_init_ex(lwprintf_t* lwobj, lwprintf_output_fn out_fn);
|
||||||
|
int lwprintf_vprintf_ex(lwprintf_t* const lwobj, const char* format, va_list arg);
|
||||||
|
int lwprintf_printf_ex(lwprintf_t* const lwobj, const char* format, ...);
|
||||||
|
int lwprintf_vsnprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, va_list arg);
|
||||||
|
int lwprintf_snprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, ...);
|
||||||
|
uint8_t lwprintf_protect_ex(lwprintf_t* const lwobj);
|
||||||
|
uint8_t lwprintf_unprotect_ex(lwprintf_t* const lwobj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer
|
||||||
|
* \param[in,out] lwobj: LwPRINTF instance. Set to `NULL` to use default instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_sprintf_ex(lwobj, s, format, ...) lwprintf_snprintf_ex((lwobj), (s), SIZE_MAX, (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initialize default LwPRINTF instance
|
||||||
|
* \param[in] out_fn: Output function used for print operation
|
||||||
|
* \return `1` on success, `0` otherwise
|
||||||
|
* \sa lwprintf_init_ex
|
||||||
|
*/
|
||||||
|
#define lwprintf_init(out_fn) lwprintf_init_ex(NULL, (out_fn))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Print formatted data from variable argument list to the output with default LwPRINTF instance
|
||||||
|
* \param[in] format: C string that contains the text to be written to output
|
||||||
|
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
|
||||||
|
* `va_list` is a special type defined in `<cstdarg>`.
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_vprintf(format, arg) lwprintf_vprintf_ex(NULL, (format), (arg))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Print formatted data to the output with default LwPRINTF instance
|
||||||
|
* \param[in] format: C string that contains the text to be written to output
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_printf(format, ...) lwprintf_printf_ex(NULL, (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] n: Maximum number of bytes to be used in the buffer.
|
||||||
|
* The generated string has a length of at most `n - 1`,
|
||||||
|
* leaving space for the additional terminating null character
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
|
||||||
|
* `va_list` is a special type defined in `<cstdarg>`.
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_vsnprintf(s, n, format, arg) lwprintf_vsnprintf_ex(NULL, (s), (n), (format), (arg))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] n: Maximum number of bytes to be used in the buffer.
|
||||||
|
* The generated string has a length of at most `n - 1`,
|
||||||
|
* leaving space for the additional terminating null character
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_snprintf(s, n, format, ...) lwprintf_snprintf_ex(NULL, (s), (n), (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_sprintf(s, format, ...) lwprintf_sprintf_ex(NULL, (s), (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Manually enable mutual exclusion
|
||||||
|
* \return `1` if protected, `0` otherwise
|
||||||
|
*/
|
||||||
|
#define lwprintf_protect() lwprintf_protect_ex(NULL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Manually disable mutual exclusion
|
||||||
|
* \return `1` if protected, `0` otherwise
|
||||||
|
*/
|
||||||
|
#define lwprintf_unprotect() lwprintf_unprotect_ex(NULL)
|
||||||
|
|
||||||
|
#if LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_printf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_printf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwprintf lwprintf_printf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwvprintf lwprintf_vprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vsnprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vsnprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwvsnprintf lwprintf_vsnprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_snprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_snprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwsnprintf lwprintf_snprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_sprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_sprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwsprintf lwprintf_sprintf
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__ */
|
||||||
|
|
||||||
|
#if LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_printf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_printf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define printf lwprintf_printf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define vprintf lwprintf_vprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vsnprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vsnprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define vsnprintf lwprintf_vsnprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_snprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_snprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define snprintf lwprintf_snprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_sprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_sprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define sprintf lwprintf_sprintf
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__ */
|
||||||
|
|
||||||
|
/* Debug module */
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
/**
|
||||||
|
* \brief Debug output function
|
||||||
|
*
|
||||||
|
* Its purpose is to have a debug printout to the defined output,
|
||||||
|
* which will get disabled for the release build (when NDEBUG is defined).
|
||||||
|
*
|
||||||
|
* \note It calls \ref lwprintf_printf to execute the print
|
||||||
|
* \note Defined as empty when \ref NDEBUG is enabled
|
||||||
|
* \param[in] fmt: Format text
|
||||||
|
* \param[in] ...: Optional formatting parameters
|
||||||
|
*/
|
||||||
|
#define lwprintf_debug(fmt, ...) lwprintf_printf((fmt), ##__VA_ARGS__)
|
||||||
|
/**
|
||||||
|
* \brief Conditional debug output
|
||||||
|
*
|
||||||
|
* It prints the formatted text only if condition is true
|
||||||
|
*
|
||||||
|
* Its purpose is to have a debug printout to the defined output,
|
||||||
|
* which will get disabled for the release build (when NDEBUG is defined).
|
||||||
|
*
|
||||||
|
* \note It calls \ref lwprintf_debug to execute the print
|
||||||
|
* \note Defined as empty when \ref NDEBUG is enabled
|
||||||
|
* \param[in] cond: Condition to check before outputing the message
|
||||||
|
* \param[in] fmt: Format text
|
||||||
|
* \param[in] ...: Optional formatting parameters
|
||||||
|
*/
|
||||||
|
#define lwprintf_debug_cond(cond, fmt, ...) \
|
||||||
|
do { \
|
||||||
|
if ((cond)) { \
|
||||||
|
lwprintf_debug((fmt), ##__VA_ARGS__) \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define lwprintf_debug(fmt, ...) ((void)0)
|
||||||
|
#define lwprintf_debug_cond(cond, fmt, ...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_HDR_H */
|
||||||
191
3rd-part/lwprintf/lwprintf_opt.h
Normal file
191
3rd-part/lwprintf/lwprintf_opt.h
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf_opt.h
|
||||||
|
* \brief LwPRINTF options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_OPT_HDR_H
|
||||||
|
#define LWPRINTF_OPT_HDR_H
|
||||||
|
|
||||||
|
/* Uncomment to ignore user options (or set macro in compiler flags) */
|
||||||
|
/* #define LWPRINTF_IGNORE_USER_OPTS */
|
||||||
|
|
||||||
|
/* Include application options */
|
||||||
|
#ifndef LWPRINTF_IGNORE_USER_OPTS
|
||||||
|
#include "lwprintf_opts.h"
|
||||||
|
#endif /* LWPRINTF_IGNORE_USER_OPTS */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup LWPRINTF_OPT Configuration
|
||||||
|
* \brief LwPRINTF options
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` operating system support in the library
|
||||||
|
*
|
||||||
|
* \note When `LWPRINTF_CFG_OS` is enabled, user must implement functions in \ref LWPRINTF_SYS group.
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS
|
||||||
|
#define LWPRINTF_CFG_OS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mutex handle type
|
||||||
|
*
|
||||||
|
* \note This value must be set in case \ref LWPRINTF_CFG_OS is set to `1`.
|
||||||
|
* If data type is not known to compiler, include header file with
|
||||||
|
* definition before you define handle type
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS_MUTEX_HANDLE
|
||||||
|
#define LWPRINTF_CFG_OS_MUTEX_HANDLE void*
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` manual mutex lock.
|
||||||
|
*
|
||||||
|
* When this feature is enabled, together with \ref LWPRINTF_CFG_OS, behavior is as following:
|
||||||
|
* - System mutex is kept created during init phase
|
||||||
|
* - Calls to direct printing functions are not thread-safe by default anymore
|
||||||
|
* - Calls to sprintf (buffer functions) are kept thread-safe
|
||||||
|
* - User must manually call \ref lwprintf_protect or \ref lwprintf_protect_ex functions to protect direct printing operation
|
||||||
|
* - User must manually call \ref lwprintf_unprotect or \ref lwprintf_unprotect_ex functions to exit protected area
|
||||||
|
*
|
||||||
|
* \note If you prefer to completely disable locking mechanism with this library,
|
||||||
|
* turn off \ref LWPRINTF_CFG_OS and fully manually handle mutual exclusion for non-reentrant functions
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS_MANUAL_PROTECT
|
||||||
|
#define LWPRINTF_CFG_OS_MANUAL_PROTECT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `long long int` type, signed or unsigned.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_LONG_LONG
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_LONG_LONG 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for any specifier accepting any kind of integer types.
|
||||||
|
* This is enabling `%d, %b, %u, %o, %i, %x` specifiers
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_INT
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_INT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support `%p` pointer print type
|
||||||
|
*
|
||||||
|
* When enabled, architecture must support `uintptr_t` type, normally available with C11 standard
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_POINTER
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_POINTER 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support `%f` float type
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_FLOAT
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_FLOAT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%e` engineering output type for float numbers
|
||||||
|
*
|
||||||
|
* \note \ref LWPRINTF_CFG_SUPPORT_TYPE_FLOAT has to be enabled to use this feature
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%s` for string output
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_STRING
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_STRING 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%k` for hex byte array output
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Specifies default number of precision for floating number
|
||||||
|
*
|
||||||
|
* Represents number of digits to be used after comma if no precision
|
||||||
|
* is set with specifier itself
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION
|
||||||
|
#define LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` optional short names for LwPRINTF API functions.
|
||||||
|
*
|
||||||
|
* It adds functions for default instance: `lwprintf`, `lwsnprintf` and others
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_ENABLE_SHORTNAMES
|
||||||
|
#define LWPRINTF_CFG_ENABLE_SHORTNAMES 1
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` C standard API names
|
||||||
|
*
|
||||||
|
* Disabled by default not to interfere with compiler implementation.
|
||||||
|
* Application may need to remove standard C STDIO library from linkage
|
||||||
|
* to be able to properly compile LwPRINTF with this option enabled
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_ENABLE_STD_NAMES
|
||||||
|
#define LWPRINTF_CFG_ENABLE_STD_NAMES 0
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_OPT_HDR_H */
|
||||||
44
3rd-part/lwprintf/lwprintf_opts.h
Normal file
44
3rd-part/lwprintf/lwprintf_opts.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf_opts_template.h
|
||||||
|
* \brief LwPRINTF configuration file
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_OPTS_HDR_H
|
||||||
|
#define LWPRINTF_OPTS_HDR_H
|
||||||
|
|
||||||
|
/* Rename this file to "lwprintf_opts.h" for your application */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open "include/lwprintf/lwprintf_opt.h" and
|
||||||
|
* copy & replace here settings you want to change values
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_OPTS_HDR_H */
|
||||||
18
BC4D.ATWP
18
BC4D.ATWP
@@ -29,6 +29,12 @@
|
|||||||
<ModeSub name="Channel2 mode" value="Output_CH2"/>
|
<ModeSub name="Channel2 mode" value="Output_CH2"/>
|
||||||
<ModeSub name="Activated" value="TRUE"/>
|
<ModeSub name="Activated" value="TRUE"/>
|
||||||
</Mode>
|
</Mode>
|
||||||
|
<Parameters>
|
||||||
|
<ParametersSub name="DividerValue" value="287"/>
|
||||||
|
<ParametersSub name="Period" value="9999"/>
|
||||||
|
<ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
<ParametersSub name="OCMode_2" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
</Parameters>
|
||||||
</TMR1>
|
</TMR1>
|
||||||
<TMR3>
|
<TMR3>
|
||||||
<Mode>
|
<Mode>
|
||||||
@@ -38,6 +44,14 @@
|
|||||||
<ModeSub name="Channel4 mode" value="Output_CH4"/>
|
<ModeSub name="Channel4 mode" value="Output_CH4"/>
|
||||||
<ModeSub name="Activated" value="TRUE"/>
|
<ModeSub name="Activated" value="TRUE"/>
|
||||||
</Mode>
|
</Mode>
|
||||||
|
<Parameters>
|
||||||
|
<ParametersSub name="DividerValue" value="287"/>
|
||||||
|
<ParametersSub name="Period" value="9999"/>
|
||||||
|
<ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
<ParametersSub name="OCMode_2" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
<ParametersSub name="OCMode_3" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
<ParametersSub name="OCMode_4" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
|
||||||
|
</Parameters>
|
||||||
</TMR3>
|
</TMR3>
|
||||||
<USART2>
|
<USART2>
|
||||||
<Mode>
|
<Mode>
|
||||||
@@ -96,12 +110,12 @@
|
|||||||
</PINInfo>
|
</PINInfo>
|
||||||
<ProjectInfomation>
|
<ProjectInfomation>
|
||||||
<ProjectName>BC4D</ProjectName>
|
<ProjectName>BC4D</ProjectName>
|
||||||
<ProjectLocation>C:/Users/ForgotDoge/Desktop/BC2024/firmware</ProjectLocation>
|
<ProjectLocation>C:/Users/evan/Desktop/BC2024</ProjectLocation>
|
||||||
<ToolchainIDE>MDK_V5</ToolchainIDE>
|
<ToolchainIDE>MDK_V5</ToolchainIDE>
|
||||||
<KeepUserCode>true</KeepUserCode>
|
<KeepUserCode>true</KeepUserCode>
|
||||||
<MinHeapSize>0x200</MinHeapSize>
|
<MinHeapSize>0x200</MinHeapSize>
|
||||||
<MinStackSize>0x400</MinStackSize>
|
<MinStackSize>0x400</MinStackSize>
|
||||||
<UseFirmware>true</UseFirmware>
|
<UseFirmware>false</UseFirmware>
|
||||||
<PackageVersion>V2.1.4</PackageVersion>
|
<PackageVersion>V2.1.4</PackageVersion>
|
||||||
</ProjectInfomation>
|
</ProjectInfomation>
|
||||||
</Root>
|
</Root>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
"titleBar.activeBackground": "#1A4A07",
|
"titleBar.activeBackground": "#1A4A07",
|
||||||
"titleBar.activeForeground": "#F3FEEF"
|
"titleBar.activeForeground": "#F3FEEF"
|
||||||
},
|
},
|
||||||
"EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe",
|
"EIDE.OpenOCD.ExePath": "C:/toolchains/openocd-arterytek/bin/openocd.exe",
|
||||||
"cortex-debug.variableUseNaturalFormat": true
|
"cortex-debug.variableUseNaturalFormat": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,11 +52,11 @@ extern "C" {
|
|||||||
|
|
||||||
/* module define -------------------------------------------------------------*/
|
/* module define -------------------------------------------------------------*/
|
||||||
/*#define ADC_MODULE_ENABLED----------------------*/
|
/*#define ADC_MODULE_ENABLED----------------------*/
|
||||||
/*#define CAN_MODULE_ENABLED----------------------*/
|
#define CAN_MODULE_ENABLED
|
||||||
/*#define CMP_MODULE_ENABLED----------------------*/
|
/*#define CMP_MODULE_ENABLED----------------------*/
|
||||||
/*#define CRC_MODULE_ENABLED----------------------*/
|
/*#define CRC_MODULE_ENABLED----------------------*/
|
||||||
#define CRM_MODULE_ENABLED
|
#define CRM_MODULE_ENABLED
|
||||||
/*#define DEBUG_MODULE_ENABLED--------------------*/
|
#define DEBUG_MODULE_ENABLED
|
||||||
/*#define DMA_MODULE_ENABLED----------------------*/
|
/*#define DMA_MODULE_ENABLED----------------------*/
|
||||||
/*#define ERTC_MODULE_ENABLED---------------------*/
|
/*#define ERTC_MODULE_ENABLED---------------------*/
|
||||||
/*#define EXINT_MODULE_ENABLED--------------------*/
|
/*#define EXINT_MODULE_ENABLED--------------------*/
|
||||||
@@ -68,7 +68,7 @@ extern "C" {
|
|||||||
/*#define SDIO_MODULE_ENABLED---------------------*/
|
/*#define SDIO_MODULE_ENABLED---------------------*/
|
||||||
/*#define SPI_MODULE_ENABLED----------------------*/
|
/*#define SPI_MODULE_ENABLED----------------------*/
|
||||||
#define TMR_MODULE_ENABLED
|
#define TMR_MODULE_ENABLED
|
||||||
/*#define USART_MODULE_ENABLED--------------------*/
|
#define USART_MODULE_ENABLED
|
||||||
/*#define USB_MODULE_ENABLED----------------------*/
|
/*#define USB_MODULE_ENABLED----------------------*/
|
||||||
/*#define WDT_MODULE_ENABLED----------------------*/
|
/*#define WDT_MODULE_ENABLED----------------------*/
|
||||||
/*#define WWDT_MODULE_ENABLED---------------------*/
|
/*#define WWDT_MODULE_ENABLED---------------------*/
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ void SVC_Handler(void);
|
|||||||
void DebugMon_Handler(void);
|
void DebugMon_Handler(void);
|
||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
|
|
||||||
|
void CAN1_RX0_IRQHandler(void);
|
||||||
|
|
||||||
/* add user code begin exported functions */
|
/* add user code begin exported functions */
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,65 @@ extern "C" {
|
|||||||
|
|
||||||
/* add user code end exported macro */
|
/* add user code end exported macro */
|
||||||
|
|
||||||
|
/* add user code begin dma define */
|
||||||
|
/* user can only modify the dma define value */
|
||||||
|
//#define DMA1_CHANNEL1_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL1_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL1_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL2_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL2_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL2_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL3_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL3_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL3_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL4_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL4_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL4_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL5_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL5_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL5_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL6_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL6_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL6_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA1_CHANNEL7_BUFFER_SIZE 0
|
||||||
|
//#define DMA1_CHANNEL7_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA1_CHANNEL7_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL1_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL1_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL1_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL2_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL2_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL2_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL3_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL3_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL3_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL4_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL4_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL4_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL5_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL5_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL5_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL6_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL6_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL6_PERIPHERAL_BASE_ADDR 0
|
||||||
|
|
||||||
|
//#define DMA2_CHANNEL7_BUFFER_SIZE 0
|
||||||
|
//#define DMA2_CHANNEL7_MEMORY_BASE_ADDR 0
|
||||||
|
//#define DMA2_CHANNEL7_PERIPHERAL_BASE_ADDR 0
|
||||||
|
/* add user code end dma define */
|
||||||
|
|
||||||
/* exported functions ------------------------------------------------------- */
|
/* exported functions ------------------------------------------------------- */
|
||||||
/* system clock config. */
|
/* system clock config. */
|
||||||
void wk_system_clock_config(void);
|
void wk_system_clock_config(void);
|
||||||
@@ -62,9 +121,21 @@ extern "C" {
|
|||||||
/* config periph clock. */
|
/* config periph clock. */
|
||||||
void wk_periph_clock_config(void);
|
void wk_periph_clock_config(void);
|
||||||
|
|
||||||
|
/* init debug function. */
|
||||||
|
void wk_debug_config(void);
|
||||||
|
|
||||||
/* nvic config. */
|
/* nvic config. */
|
||||||
void wk_nvic_config(void);
|
void wk_nvic_config(void);
|
||||||
|
|
||||||
|
/* init gpio function. */
|
||||||
|
void wk_gpio_config(void);
|
||||||
|
|
||||||
|
/* init can1 function. */
|
||||||
|
void wk_can1_init(void);
|
||||||
|
|
||||||
|
/* init usart2 function. */
|
||||||
|
void wk_usart2_init(void);
|
||||||
|
|
||||||
/* init tmr1 function. */
|
/* init tmr1 function. */
|
||||||
void wk_tmr1_init(void);
|
void wk_tmr1_init(void);
|
||||||
|
|
||||||
|
|||||||
35
project/inc/by_debug.h
Normal file
35
project/inc/by_debug.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef _BY_DEBUG_H__
|
||||||
|
#define _BY_DEBUG_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "at32f415.h"
|
||||||
|
#include "lwprintf.h"
|
||||||
|
|
||||||
|
#define BY_DEBUG_USART_INDEX (USART2)
|
||||||
|
|
||||||
|
#define BY_DEBUG_LOG_MODE (2) // 0-not log, 1-no debug log, 2-all
|
||||||
|
|
||||||
|
#if (BY_DEBUG_LOG_MODE == 2)
|
||||||
|
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGD(format, ...) lwprintf("[DEBUG] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#elif (BY_DEBUG_LOG_MODE == 1)
|
||||||
|
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
|
||||||
|
#define LOGD(format, ...)
|
||||||
|
#elif (BY_DEBUG_LOG_MODE == 0)
|
||||||
|
#define LOGI(format, ...)
|
||||||
|
#define LOGW(format, ...)
|
||||||
|
#define LOGE(format, ...)
|
||||||
|
#define LOGD(format, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void by_debug_init(void);
|
||||||
|
extern void delay_init(void);
|
||||||
|
extern void delay_us(uint32_t nus);
|
||||||
|
extern void delay_ms(uint16_t nms);
|
||||||
|
extern void delay_sec(uint16_t sec);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -204,6 +204,21 @@ void PendSV_Handler(void)
|
|||||||
/* add user code end PendSV_IRQ 1 */
|
/* add user code end PendSV_IRQ 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this function handles CAN1 RX0 handler.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void CAN1_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* add user code begin CAN1_RX0_IRQ 0 */
|
||||||
|
|
||||||
|
/* add user code end CAN1_RX0_IRQ 0 */
|
||||||
|
/* add user code begin CAN1_RX0_IRQ 1 */
|
||||||
|
|
||||||
|
/* add user code end CAN1_RX0_IRQ 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/* add user code begin 1 */
|
/* add user code begin 1 */
|
||||||
|
|
||||||
/* add user code end 1 */
|
/* add user code end 1 */
|
||||||
|
|||||||
@@ -161,6 +161,23 @@ void wk_periph_clock_config(void)
|
|||||||
|
|
||||||
/* enable tmr3 periph clock */
|
/* enable tmr3 periph clock */
|
||||||
crm_periph_clock_enable(CRM_TMR3_PERIPH_CLOCK, TRUE);
|
crm_periph_clock_enable(CRM_TMR3_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* enable usart2 periph clock */
|
||||||
|
crm_periph_clock_enable(CRM_USART2_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* enable can1 periph clock */
|
||||||
|
crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init debug function.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void wk_debug_config(void)
|
||||||
|
{
|
||||||
|
/* jtag-dp disabled and sw-dp enabled */
|
||||||
|
gpio_pin_remap_config(SWJTAG_GMUX_010, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,6 +188,90 @@ void wk_periph_clock_config(void)
|
|||||||
void wk_nvic_config(void)
|
void wk_nvic_config(void)
|
||||||
{
|
{
|
||||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||||
|
|
||||||
|
nvic_irq_enable(CAN1_RX0_IRQn, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init gpio_input/gpio_output/gpio_analog/eventout function.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void wk_gpio_config(void)
|
||||||
|
{
|
||||||
|
/* add user code begin gpio_config 0 */
|
||||||
|
|
||||||
|
/* add user code end gpio_config 0 */
|
||||||
|
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* add user code begin gpio_config 1 */
|
||||||
|
|
||||||
|
/* add user code end gpio_config 1 */
|
||||||
|
|
||||||
|
/* gpio output config */
|
||||||
|
gpio_bits_reset(GPIOA, GPIO_PINS_10);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* add user code begin gpio_config 2 */
|
||||||
|
|
||||||
|
/* add user code end gpio_config 2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init usart2 function
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void wk_usart2_init(void)
|
||||||
|
{
|
||||||
|
/* add user code begin usart2_init 0 */
|
||||||
|
|
||||||
|
/* add user code end usart2_init 0 */
|
||||||
|
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* add user code begin usart2_init 1 */
|
||||||
|
|
||||||
|
/* add user code end usart2_init 1 */
|
||||||
|
|
||||||
|
/* configure the TX pin */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the RX pin */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure param */
|
||||||
|
usart_init(USART2, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
|
||||||
|
usart_transmitter_enable(USART2, TRUE);
|
||||||
|
usart_receiver_enable(USART2, TRUE);
|
||||||
|
usart_parity_selection_config(USART2, USART_PARITY_NONE);
|
||||||
|
|
||||||
|
usart_hardware_flow_control_set(USART2, USART_HARDWARE_FLOW_NONE);
|
||||||
|
|
||||||
|
usart_enable(USART2, TRUE);
|
||||||
|
|
||||||
|
/* add user code begin usart2_init 2 */
|
||||||
|
|
||||||
|
/* add user code end usart2_init 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,24 +311,8 @@ void wk_tmr1_init(void)
|
|||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH3 pin */
|
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
|
||||||
|
|
||||||
/* configure the CH4 pin */
|
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
|
||||||
|
|
||||||
/* configure counter settings */
|
/* configure counter settings */
|
||||||
tmr_base_init(TMR1, 65535, 0);
|
tmr_base_init(TMR1, 9999, 287);
|
||||||
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
|
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
|
||||||
tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
|
tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
|
||||||
tmr_repetition_counter_set(TMR1, 0);
|
tmr_repetition_counter_set(TMR1, 0);
|
||||||
@@ -238,7 +323,7 @@ void wk_tmr1_init(void)
|
|||||||
tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET);
|
tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET);
|
||||||
|
|
||||||
/* configure channel 1 output settings */
|
/* configure channel 1 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
@@ -249,8 +334,10 @@ void wk_tmr1_init(void)
|
|||||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0);
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
|
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
|
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
/* configure channel 2 output settings */
|
/* configure channel 2 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
@@ -261,29 +348,7 @@ void wk_tmr1_init(void)
|
|||||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0);
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
|
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
|
|
||||||
/* configure channel 3 output settings */
|
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
|
||||||
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
|
|
||||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_3, 0);
|
|
||||||
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_3, FALSE);
|
|
||||||
|
|
||||||
/* configure channel 4 output settings */
|
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
|
||||||
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
|
|
||||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_4, 0);
|
|
||||||
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_4, FALSE);
|
|
||||||
|
|
||||||
/* configure break and dead-time settings */
|
/* configure break and dead-time settings */
|
||||||
tmr_brkdt_struct.brk_enable = FALSE;
|
tmr_brkdt_struct.brk_enable = FALSE;
|
||||||
@@ -325,6 +390,22 @@ void wk_tmr3_init(void)
|
|||||||
|
|
||||||
/* add user code end tmr3_init 1 */
|
/* add user code end tmr3_init 1 */
|
||||||
|
|
||||||
|
/* configure the CH1 pin */
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the CH2 pin */
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH3 pin */
|
/* configure the CH3 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_0;
|
gpio_init_struct.gpio_pins = GPIO_PINS_0;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
@@ -342,7 +423,7 @@ void wk_tmr3_init(void)
|
|||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure counter settings */
|
/* configure counter settings */
|
||||||
tmr_base_init(TMR3, 65535, 0);
|
tmr_base_init(TMR3, 9999, 287);
|
||||||
tmr_cnt_dir_set(TMR3, TMR_COUNT_UP);
|
tmr_cnt_dir_set(TMR3, TMR_COUNT_UP);
|
||||||
tmr_clock_source_div_set(TMR3, TMR_CLOCK_DIV1);
|
tmr_clock_source_div_set(TMR3, TMR_CLOCK_DIV1);
|
||||||
tmr_period_buffer_enable(TMR3, FALSE);
|
tmr_period_buffer_enable(TMR3, FALSE);
|
||||||
@@ -351,8 +432,36 @@ void wk_tmr3_init(void)
|
|||||||
tmr_sub_sync_mode_set(TMR3, FALSE);
|
tmr_sub_sync_mode_set(TMR3, FALSE);
|
||||||
tmr_primary_mode_select(TMR3, TMR_PRIMARY_SEL_RESET);
|
tmr_primary_mode_select(TMR3, TMR_PRIMARY_SEL_RESET);
|
||||||
|
|
||||||
|
/* configure channel 1 output settings */
|
||||||
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
|
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
||||||
|
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_1, 0);
|
||||||
|
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
|
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
|
/* configure channel 2 output settings */
|
||||||
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
|
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
||||||
|
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_2, 0);
|
||||||
|
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
|
|
||||||
|
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
|
|
||||||
/* configure channel 3 output settings */
|
/* configure channel 3 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
@@ -363,8 +472,10 @@ void wk_tmr3_init(void)
|
|||||||
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, 0);
|
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_3, FALSE);
|
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_3, FALSE);
|
||||||
|
|
||||||
|
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_3, FALSE);
|
||||||
|
|
||||||
/* configure channel 4 output settings */
|
/* configure channel 4 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
@@ -375,6 +486,8 @@ void wk_tmr3_init(void)
|
|||||||
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, 0);
|
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_4, FALSE);
|
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_4, FALSE);
|
||||||
|
|
||||||
|
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_4, FALSE);
|
||||||
|
|
||||||
|
|
||||||
tmr_counter_enable(TMR3, TRUE);
|
tmr_counter_enable(TMR3, TRUE);
|
||||||
|
|
||||||
@@ -383,6 +496,92 @@ void wk_tmr3_init(void)
|
|||||||
/* add user code end tmr3_init 2 */
|
/* add user code end tmr3_init 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init can1 function.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void wk_can1_init(void)
|
||||||
|
{
|
||||||
|
/* add user code begin can1_init 0 */
|
||||||
|
|
||||||
|
/* add user code end can1_init 0 */
|
||||||
|
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
can_base_type can_base_struct;
|
||||||
|
can_baudrate_type can_baudrate_struct;
|
||||||
|
can_filter_init_type can_filter_init_struct;
|
||||||
|
|
||||||
|
/* add user code begin can1_init 1 */
|
||||||
|
|
||||||
|
/* add user code end can1_init 1 */
|
||||||
|
|
||||||
|
/*gpio-----------------------------------------------------------------------------*/
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the CAN1 TX pin */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_12;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the CAN1 RX pin */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
/*can_base_init--------------------------------------------------------------------*/
|
||||||
|
can_default_para_init(&can_base_struct);
|
||||||
|
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
||||||
|
can_base_struct.ttc_enable = FALSE;
|
||||||
|
can_base_struct.aebo_enable = TRUE;
|
||||||
|
can_base_struct.aed_enable = TRUE;
|
||||||
|
can_base_struct.prsf_enable = FALSE;
|
||||||
|
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
||||||
|
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
|
||||||
|
|
||||||
|
can_base_init(CAN1, &can_base_struct);
|
||||||
|
|
||||||
|
/*can_baudrate_setting-------------------------------------------------------------*/
|
||||||
|
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
|
||||||
|
can_baudrate_struct.baudrate_div = 18; /*value: 1~0xFFF*/
|
||||||
|
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
|
||||||
|
can_baudrate_struct.bts1_size = CAN_BTS1_6TQ; /*value: 1~16*/
|
||||||
|
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
|
||||||
|
can_baudrate_set(CAN1, &can_baudrate_struct);
|
||||||
|
|
||||||
|
/*can_filter_0_config--------------------------------------------------------------*/
|
||||||
|
can_filter_init_struct.filter_activate_enable = TRUE;
|
||||||
|
can_filter_init_struct.filter_number = 0;
|
||||||
|
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
||||||
|
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
||||||
|
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
||||||
|
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
||||||
|
can_filter_init_struct.filter_id_high = 0x0 << 5;
|
||||||
|
can_filter_init_struct.filter_id_low = 0x0 << 5;
|
||||||
|
can_filter_init_struct.filter_mask_high = 0x0 << 5;
|
||||||
|
can_filter_init_struct.filter_mask_low = 0x0 << 5;
|
||||||
|
|
||||||
|
can_filter_init(CAN1, &can_filter_init_struct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users need to configure CAN1 interrupt functions according to the actual application.
|
||||||
|
* 1. Call the below function to enable the corresponding CAN1 interrupt.
|
||||||
|
* --can_interrupt_enable(...)
|
||||||
|
* 2. Add the user's interrupt handler code into the below function in the at32f415_int.c file.
|
||||||
|
* --void CAN1_RX0_IRQHandler(void)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* add user code begin can1_init 2 */
|
||||||
|
|
||||||
|
/* add user code end can1_init 2 */
|
||||||
|
}
|
||||||
|
|
||||||
/* add user code begin 1 */
|
/* add user code begin 1 */
|
||||||
|
|
||||||
/* add user code end 1 */
|
/* add user code end 1 */
|
||||||
|
|||||||
98
project/src/by_debug.c
Normal file
98
project/src/by_debug.c
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "by_debug.h"
|
||||||
|
|
||||||
|
#include "at32f415.h"
|
||||||
|
#include "lwprintf.h"
|
||||||
|
|
||||||
|
/* delay macros */
|
||||||
|
#define STEP_DELAY_MS 50
|
||||||
|
|
||||||
|
/* delay variable */
|
||||||
|
static __IO uint32_t fac_us;
|
||||||
|
static __IO uint32_t fac_ms;
|
||||||
|
|
||||||
|
int lwprintf_out(int ch, lwprintf_t *lwp)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* May use printf to output it for test */
|
||||||
|
|
||||||
|
if (ch != '\0') {
|
||||||
|
while (usart_flag_get(BY_DEBUG_USART_INDEX, USART_TDC_FLAG) == RESET);
|
||||||
|
usart_data_transmit(BY_DEBUG_USART_INDEX, (char)ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_debug_init(void)
|
||||||
|
{
|
||||||
|
lwprintf_init(lwprintf_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay_init(void)
|
||||||
|
{
|
||||||
|
systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8);
|
||||||
|
crm_clocks_freq_type clocks;
|
||||||
|
crm_clocks_freq_get(&clocks);
|
||||||
|
fac_us = clocks.sclk_freq / (8000000U);
|
||||||
|
fac_ms = fac_us * (1000U);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief inserts a delay time.
|
||||||
|
* @param nus: specifies the delay time length, in microsecond.
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void delay_us(uint32_t nus)
|
||||||
|
{
|
||||||
|
uint32_t temp = 0;
|
||||||
|
SysTick->LOAD = (uint32_t)(nus * fac_us);
|
||||||
|
SysTick->VAL = 0x00;
|
||||||
|
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||||
|
do {
|
||||||
|
temp = SysTick->CTRL;
|
||||||
|
} while ((temp & 0x01) && !(temp & (1 << 16)));
|
||||||
|
|
||||||
|
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||||
|
SysTick->VAL = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief inserts a delay time.
|
||||||
|
* @param nms: specifies the delay time length, in milliseconds.
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void delay_ms(uint16_t nms)
|
||||||
|
{
|
||||||
|
uint32_t temp = 0;
|
||||||
|
while (nms) {
|
||||||
|
if (nms > STEP_DELAY_MS) {
|
||||||
|
SysTick->LOAD = (uint32_t)(STEP_DELAY_MS * fac_ms);
|
||||||
|
nms -= STEP_DELAY_MS;
|
||||||
|
} else {
|
||||||
|
SysTick->LOAD = (uint32_t)(nms * fac_ms);
|
||||||
|
nms = 0;
|
||||||
|
}
|
||||||
|
SysTick->VAL = 0x00;
|
||||||
|
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||||
|
do {
|
||||||
|
temp = SysTick->CTRL;
|
||||||
|
} while ((temp & 0x01) && !(temp & (1 << 16)));
|
||||||
|
|
||||||
|
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||||
|
SysTick->VAL = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief inserts a delay time.
|
||||||
|
* @param sec: specifies the delay time, in seconds.
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void delay_sec(uint16_t sec)
|
||||||
|
{
|
||||||
|
uint16_t index;
|
||||||
|
for (index = 0; index < sec; index++) {
|
||||||
|
delay_ms(500);
|
||||||
|
delay_ms(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
/* private includes ----------------------------------------------------------*/
|
/* private includes ----------------------------------------------------------*/
|
||||||
/* add user code begin private includes */
|
/* add user code begin private includes */
|
||||||
|
#include "by_debug.h"
|
||||||
/* add user code end private includes */
|
/* add user code end private includes */
|
||||||
|
|
||||||
/* private typedef -----------------------------------------------------------*/
|
/* private typedef -----------------------------------------------------------*/
|
||||||
@@ -79,17 +79,29 @@ int main(void)
|
|||||||
/* config periph clock. */
|
/* config periph clock. */
|
||||||
wk_periph_clock_config();
|
wk_periph_clock_config();
|
||||||
|
|
||||||
|
/* init debug function. */
|
||||||
|
wk_debug_config();
|
||||||
|
|
||||||
/* nvic config. */
|
/* nvic config. */
|
||||||
wk_nvic_config();
|
wk_nvic_config();
|
||||||
|
|
||||||
|
/* init usart2 function. */
|
||||||
|
wk_usart2_init();
|
||||||
|
|
||||||
/* init tmr1 function. */
|
/* init tmr1 function. */
|
||||||
wk_tmr1_init();
|
wk_tmr1_init();
|
||||||
|
|
||||||
/* init tmr3 function. */
|
/* init tmr3 function. */
|
||||||
wk_tmr3_init();
|
wk_tmr3_init();
|
||||||
|
|
||||||
/* add user code begin 2 */
|
/* init can1 function. */
|
||||||
|
wk_can1_init();
|
||||||
|
|
||||||
|
/* init gpio function. */
|
||||||
|
wk_gpio_config();
|
||||||
|
|
||||||
|
/* add user code begin 2 */
|
||||||
|
delay_init();
|
||||||
/* add user code end 2 */
|
/* add user code end 2 */
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user