Initial commit: HC32F005 turning table firmware

Firmware (src/app):
- system state machine: IDLE / ROTATING / POWER_OFF
- button: 20 ms debounce, short/double/long classification, boot hold-off
- LED: idle slow blink, solid, speed/direction feedback patterns
- motor: 8-phase half-step drive with trapezoidal acceleration,
  speed levels 2.5/5/7.5/10 RPM, reversal via standstill
- power latch on P33 (push-pull, high = hold, low = cut) with
  decelerate-to-stop sequence before power-off (FR18)
- base timer mode-2 reload semantics (interval = 0x10000 - ARR)

Build: Makefile for arm-none-eabi-gcc, selective DDL compile,
vendor startup + linker script under src/.

Docs: FIRMWARE_REQUIREMENTS.md, STATE_MACHINE.md, README.md.
Vendor datasheet/RM/DDL references under docs/ are kept locally and
tracked in a separate shared repo.
This commit is contained in:
kyle committed 2026-11-06 08:14:55 +00:00
commit 66f5bfbf1a
65 files changed
+22452

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
# build output
build/
*.o
*.d
*.elf
*.bin
*.hex
*.map
*.lst
# vendor reference docs (kept locally, tracked in a separate shared repo)
docs/
# editor / OS cruft
.vscode/
.idea/
*.swp
*~
.DS_Store
# python
__pycache__/
*.pyc
+61
View File
@@ -0,0 +1,61 @@
# Firmware Requirements for Turning Table based on HC32 MCU
## 1. Overview
This document outlines the firmware requirements for a motorized turning table based on the HC32F005C6PA microcontroller. The system drives a 28BYJ-48 stepper motor and provides user control via a single button for speed and direction, with status feedback from a single LED.
## 2. Hardware Specifications
- **Microcontroller:** HC32F005C6PA (32MHz ARM Cortex-M0+ with 32KB Flash and 4KB RAM, 6 Timers, 2 UARTs, 1 I2C, 1 SPI, 1 9ch 12-bit ADC, 2 Analog Comparators)
- **Motor:** 28BYJ-48 Stepper Motor
- **Motor Driver:** ULN2003-based driver board
- **User Input:** 1x Tactile Button
- **Status Output:** 1x LED
- **Power Control:** External hardware circuit managed by a GPIO pin.
## 3. Functional Requirements
### 3.1. State Definitions
- **POWER_OFF:** The main power is off. This state is entered by firmware action but cannot be exited by firmware.
- **IDLE:** The system is powered on, but the motor is not rotating. This is the default state after power-on.
- **ROTATING:** The system is on and the motor is actively rotating.
### 3.2. Power Control
- **FR1:** The firmware does not control power-on. It assumes the system starts in the **IDLE** state when power is applied by the external circuit.
- **FR2:** The firmware shall hold the system power ON by driving pin **P33** high (output/push-pull).
- **FR3:** A "long press" on the button (held for > 2 seconds) shall trigger the **POWER_OFF** state by changing pin **P33** to output low.
- **FR18:** Before releasing the power latch (P33 low), the motor shall be decelerated to a full stop using the acceleration control defined in FR12. After the motor reaches standstill, the LED shall turn off (FR13), and only then shall the power latch be released. If the motor has not reached standstill within a bounded time (e.g. 2 seconds), the latch shall be released anyway so the power-off is never blocked.
### 3.3. Button Input Logic
- **FR4:** The button is connected to pin **P32**, which shall be configured as an input with its internal pull-up resistor enabled. A button press pulls the pin to ground. Software debouncing should be implemented.
- **FR5:** A "short press" is defined as a press-and-release cycle shorter than 1 second.
- **FR6:** A "long press" is defined as holding the button for more than 2 seconds.
- **FR7:** A "double press" is defined as two consecutive short presses where the interval between the first release and the second press is less than 300ms.
### 3.4. Motor Control
- **FR8:** From the **IDLE** state, a short press shall transition the system to the **ROTATING** state at Speed 1.
- **FR9:** While in the **ROTATING** state, a short press shall cycle through the four defined speed levels in the order: Speed 1 -> Speed 2 -> Speed 3 -> Speed 4 -> Speed 1...
- **FR10:** While in the **ROTATING** state, a double press shall reverse the motor's direction of rotation.
- **FR11:** The firmware shall drive the stepper motor in half-step mode to ensure smoother rotation.
- **FR12:** Rotation shall be continuous. Apply acceleration control when changing speed and direction to avoid skipping steps.
### 3.5. LED Indicator Logic
- **FR13:** In the **POWER_OFF** state, the LED is off.
- **FR14:** In the **IDLE** state, the LED shall blink slowly (0.5 Hz, 1 second on, 1 second off) to indicate the system is on and ready.
- **FR15:** In the **ROTATING** state, the LED shall be solid ON.
- **FR16:** As feedback for a speed change, the LED shall interrupt its solid ON state to blink N times corresponding to the new speed level (e.g., 3 blinks for Speed 3), then return to solid ON.
- **FR17:** As feedback for a direction change, the LED shall perform a quick double-blink, then return to solid ON.
## 4. Non-Functional Requirements
- **NFR1:** The firmware shall be written in C.
- **NFR2:** The target compiler and toolchain shall be ARM GCC.
- **NFR3:** The firmware must operate within the memory constraints of the HC32F005C6PA (32KB Flash, 4KB RAM).
## 5. Pin Assignments
| Pin | Function | Configuration | Notes |
|---|---|---|---|
| P02 | LED | Open-Drain Output | Active Low |
| P23 | Motor IN1 | Push-Pull Output | |
| P24 | Motor IN2 | Push-Pull Output | |
| P25 | Motor IN3 | Push-Pull Output | |
| P26 | Motor IN4 | Push-Pull Output | |
| P32 | Button | Input with Pull-up | Active Low |
| P33 | Power Latch | Push-Pull Output | |
+94
View File
@@ -0,0 +1,94 @@
# Makefile for the HC32F005C6PA turning-table firmware
# Toolchain: ARM GCC (arm-none-eabi-gcc)
TARGET := turntable
CROSS := arm-none-eabi-
CC := $(CROSS)gcc
AS := $(CROSS)gcc
LD := $(CROSS)gcc
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
SIZE := $(CROSS)size
BUILD := build
# ---- source selection (keep only the DDL modules in use, NFR3) ----
APP_SRCS := \
src/app/main.c \
src/app/button.c \
src/app/led.c \
src/app/motor.c \
src/app/power.c
DDL_SRCS := \
src/driver/src/gpio.c \
src/driver/src/bt.c \
src/driver/src/sysctrl.c \
src/driver/src/ddl.c
SYS_SRCS := \
src/common/system_hc32f005.c \
src/common/interrupts_hc32f005.c
ASM_SRCS := \
src/gcc/startup_hc32f005.S
SRCS := $(APP_SRCS) $(DDL_SRCS) $(SYS_SRCS)
# ---- includes ----
INCS := \
-Isrc/app \
-Isrc/common \
-Isrc/driver/inc \
-Isrc/cmsis
# ---- flags ----
CPU := -mcpu=cortex-m0plus -mthumb
# vendor DDL expects the external-crystal frequencies to be user-defined
# (see sysctrl.h note); defaults match the vendor documentation
DEFS := -DSYSTEM_XTH=32000000 -DSYSTEM_XTL=32768
CFLAGS := $(CPU) -Os -Wall -Wextra -std=c11 -Wno-main -Wno-unused-parameter \
-ffunction-sections -fdata-sections $(DEFS) $(INCS)
ASFLAGS := $(CPU)
LDFLAGS := $(CPU) -specs=nano.specs \
-Tsrc/gcc/hc32f005_flash.ld \
-Wl,--gc-sections \
-Wl,-Map=$(BUILD)/$(TARGET).map
OBJS := $(SRCS:%.c=$(BUILD)/%.o) $(ASM_SRCS:%.S=$(BUILD)/%.o)
DEPS := $(OBJS:.o=.d)
ELF := $(BUILD)/$(TARGET).elf
BIN := $(BUILD)/$(TARGET).bin
HEX := $(BUILD)/$(TARGET).hex
.PHONY: all clean size
all: $(ELF) $(BIN) $(HEX)
$(ELF): $(OBJS)
@mkdir -p $(dir $@)
$(LD) $(OBJS) $(LDFLAGS) -o $@
$(SIZE) $@
$(BUILD)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) -MMD -MP $< -o $@
$(BUILD)/%.o: %.S
@mkdir -p $(dir $@)
$(AS) -c $(ASFLAGS) $< -o $@
$(BIN): $(ELF)
$(OBJCOPY) -O binary $< $@
$(HEX): $(ELF)
$(OBJCOPY) -O ihex $< $@
size: $(ELF)
$(SIZE) $@
clean:
rm -rf $(BUILD)
-include $(DEPS)
+54
View File
@@ -0,0 +1,54 @@
# Turning Table Firmware (HC32F005C6PA)
Bare-metal C firmware for a motorized turning table. Drives a 28BYJ-48 stepper motor
(ULN2003 board, half-step, trapezoidal acceleration) and is controlled with a single button
plus one status LED. Power is held by a GPIO latch so the system can switch itself off.
## Hardware
| Pin | Function | Config |
|---|---|---|
| P02 | LED | open-drain output, active low |
| P23–P26 | Motor IN1–IN4 | push-pull output |
| P32 | Button | input, internal pull-up, active low |
| P33 | Power latch | push-pull output, high = hold power, low = cut power |
## Behavior
- Power-on → IDLE (LED slow blink 0.5 Hz). Holding the button at power-on is ignored.
- Short press in IDLE → rotate at Speed 1; short press again cycles Speed 1→2→3→4→1
(2.5 / 5 / 7.5 / 10 RPM), LED blinks N times as feedback.
- Double press → reverse direction (LED quick double-blink); speed changes and reversal ramp
smoothly to avoid skipped steps.
- Long press (> 2 s) → motor decelerates to a full stop, LED off, power cut via P33.
Full specification: `FIRMWARE_REQUIREMENTS.md`. State machine details: `STATE_MACHINE.md`.
## Repository layout
```
src/app/ application: main.c (system state machine), button.c, led.c, motor.c, power.c
src/driver/ vendor device driver library (gpio, bt, sysctrl, ...)
src/common/ vendor system headers, board pin map (board_stkhc32f005.h)
src/gcc/ startup code and linker script (32K flash / 4K RAM)
docs/ MCU datasheet, reference manual, DDL docs, vendor examples
```
## Build
Requires `arm-none-eabi-gcc` and `make`:
```
make # builds build/turntable.elf/.bin/.hex (~4.5K flash, ~2.1K RAM used)
make clean
```
Only the DDL modules in use are compiled. Flashing is done with your own SWD programmer
(no flash target is provided).
## Notes
- The base timers run in mode 2 (reload): interval = `0x10000 − ARR` with CNT primed to ARR
(HC32F005 reference manual §9) — see `TickInit()` and `Motor_ArrForSps()`.
- The 1 ms system tick (TIM0) drives button scanning and LED patterns; the stepper generator
(TIM1) runs autonomously in its own ISR.
+153
View File
@@ -0,0 +1,153 @@
# State Machines — HC32F005 Turning Table Firmware
This document describes every state machine in the firmware, how they interact, and which
requirement (FR) each behavior implements. Reference: `FIRMWARE_REQUIREMENTS.md`.
Implementation: `src/app/` (`main.c`, `button.c`, `led.c`, `motor.c`, `power.c`).
There are four state machines:
1. **System state machine** (`main.c`) — the three system states and button-driven transitions
2. **Button event machine** (`button.c`) — debouncing, press classification, boot hold-off
3. **LED pattern engine** (`led.c`) — idle blink, solid, feedback blinks
4. **Motor speed machine** (`motor.c`) — half-step sequencing with trapezoidal ramping
The button and LED machines run from the 1 ms system tick (TIM0 ISR); the motor machine runs
in the TIM1 step ISR. The main loop only dispatches button events into the system machine.
---
## 1. System state machine (`main.c`)
```mermaid
stateDiagram-v2
[*] --> IDLE : power applied (FR1)
IDLE --> ROTATING : SHORT or DOUBLE (FR8)
ROTATING --> ROTATING : SHORT, cycle speed 1-2-3-4-1 (FR9)
ROTATING --> ROTATING : DOUBLE, reverse direction (FR10)
IDLE --> POWER_OFF : LONG (FR3)
ROTATING --> POWER_OFF : LONG, decel to stop first (FR18)
POWER_OFF --> [*] : P33 low, power cut (FR3)
```
Behavior per state:
| State | Entry action | LED | Exit triggers |
|---|---|---|---|
| `STATE_IDLE` | power latch already held (P33 high, FR2) | slow blink 1 s on / 1 s off (FR14) | SHORT/DOUBLE → ROTATING; LONG → POWER_OFF |
| `STATE_ROTATING` | motor starts at speed 1, ramps up | solid on (FR15) | SHORT → next speed + N blinks (FR9/FR16); DOUBLE → reverse + double blink (FR10/FR17); LONG → decelerate → POWER_OFF |
| `STATE_POWER_OFF` | motor decelerated to standstill (FR18), LED off (FR13) | off | terminal: P33 low → power cut |
Power-off sequence (FR18/FR3): `MotorStopSmooth()` → wait for standstill (bounded, 2 s guard,
force-stop on timeout) → LED off → 50 ms visibility delay → P33 low → park forever.
---
## 2. Button event machine (`button.c`)
One scan per 1 ms from the TIM0 tick ISR. Timing constants: debounce 20 ms, short < 1 s (FR5),
long ≥ 2 s (FR6), double window 300 ms (FR7).
```mermaid
stateDiagram-v2
[*] --> BootGate : power-on, button sampled (held = arm)
BootGate --> Idle : stable release 20 ms (boot press swallowed)
Idle --> Pressed : press debounced 20 ms
Pressed --> Held : hold >= 2 s, fire LONG live (FR6)
Held --> Idle
Pressed --> Released : release
Released --> Window : hold < 1 s, arm 300 ms (FR5/FR7)
Released --> Idle : hold 1-2 s gray zone, no event
Window --> Windowed : second press inside window (FR7)
Window --> Idle : window expires, fire SHORT (FR5)
Windowed --> Window : second release < 1 s, fire DOUBLE (FR7)
```
Rules and rationale:
- **Boot gate**: if the button reads pressed at `ButtonInit()`, every event is swallowed until a
stable 20 ms raw release is seen (the power-on hold must not rotate, reverse, or power off).
- **LONG fires live while held** so power-off responds promptly; once fired, nothing else from
that hold generates events.
- **SHORT is delayed 300 ms** — necessary to distinguish a single press from the first half of a
double press (FR7). This dispatch latency is intentional.
- **Double press** consumes the window: only one DOUBLE per pair.
- **Gray zone (1 s ≤ hold < 2 s)** produces no event (spec defines only short <1 s and long >2 s).
---
## 3. LED pattern engine (`led.c`)
Stepped every 1 ms from the same tick ISR. Non-blocking: patterns overlay the base mode and
return to it automatically. LED is open-drain, active low (P02).
```mermaid
stateDiagram-v2
[*] --> Off
Off --> SlowBlink : STATE_IDLE (FR14)
Off --> Solid : STATE_ROTATING (FR15)
SlowBlink --> Solid : STATE_ROTATING (FR15)
SlowBlink --> Off : STATE_POWER_OFF (FR13)
Solid --> Pattern : blink(N) speed feedback (FR16)
Solid --> Pattern : blinkQuick double-blink feedback (FR17)
Pattern --> Solid : pattern sequence finished
Solid --> Off : STATE_POWER_OFF (FR13)
```
| Mode | Timing | Set by |
|---|---|---|
| Slow blink | 1000 ms on / 1000 ms off (0.5 Hz) | `LedSetState(STATE_IDLE)` |
| Solid | on | `LedSetState(STATE_ROTATING)` |
| Pattern (speed) | N × (150 ms on / 150 ms off) | `LedBlink(N)` on speed change |
| Pattern (direction) | 2 × (80 ms on / 80 ms off) | `LedBlinkQuick()` on reversal |
| Off | off | `LedSetState(STATE_POWER_OFF)` |
Feedback patterns only start while in Solid (rotating); a new request during a pattern is ignored.
---
## 4. Motor speed machine (`motor.c`)
Runs in the TIM1 step ISR. Speed is stepless (steps/s); levels 1–4 map to 171 / 341 / 512 / 683
steps/s (2.5 / 5 / 7.5 / 10 RPM at 4096 half-steps/rev). Accel/decel 500 steps/s², start speed
60 steps/s, 8-entry half-step table on P23–P26 (FR11).
```mermaid
stateDiagram-v2
[*] --> Stopped : coils released
Stopped --> Accel : start or new target (FR8/FR9)
Accel --> Steady : speed == target
Steady --> Accel : target raised (FR9)
Steady --> Decel : target lowered
Steady --> Decel : reversal requested (FR10)
Steady --> Decel : smooth stop requested (FR18)
Decel --> Accel : speed settles at new target
Decel --> Flip : speed == 0 and reversal pending (FR10)
Flip --> Accel : direction flipped, ramp to level speed
Decel --> Stopped : speed == 0, no reversal pending (FR18)
```
Ramp rule: each step applies `Δv = accel / v` (min 1 step/s) toward the target and recomputes the
timer reload, so the profile is trapezoidal and no steps are skipped on speed/direction changes
(FR12). Reversal deliberately passes through standstill (coils stay energized at zero speed, then
flip direction and ramp back up).
TIM0 note: timer mode 2 is a *reload* timer — the interval is `0x10000 − ARR` ticks with CNT
primed to ARR (HC32F005 RM §9).
---
## Cross-machine interaction
```
TIM0 ISR (1 ms) main loop TIM1 ISR
┌───────────────┐ BTN_EVT_* ┌───────────────┐ ┌──────────────┐
│ button scan │───────────────▶ │ system machine│────────▶ │ motor ramp │
│ LED patterns │◀─────────────── │ Led/Motor API │ │ half-step ISR│
└───────────────┘ LED commands └───────────────┘ └──────────────┘
```
- Button events are produced only by the button machine and consumed only by the main loop.
- LED state follows the system machine; feedback blinks are triggered by the same events that
change the motor.
- The motor machine is autonomous once a target is set — the main loop never waits on it, except
during the bounded power-off deceleration wait (FR18).
+57
View File
@@ -0,0 +1,57 @@
#ifndef __APP_H__
#define __APP_H__
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum en_app_state
{
STATE_IDLE = 0u,
STATE_ROTATING = 1u,
STATE_POWER_OFF = 2u,
} en_app_state_t;
typedef enum en_btn_event
{
BTN_EVT_NONE = 0u,
BTN_EVT_SHORT = 1u,
BTN_EVT_DOUBLE = 2u,
BTN_EVT_LONG = 3u,
} en_btn_event_t;
/* Button (FR4-FR7): scanned from the 1 ms tick */
void ButtonInit(void);
void ButtonScan1ms(void);
en_btn_event_t ButtonGetEvent(void);
/* LED patterns (FR13-FR17): stepped from the 1 ms tick */
void LedInit(void);
void Led1ms(void);
void LedSetState(en_app_state_t enState);
void LedBlink(uint8_t u8Times);
void LedBlinkQuick(void);
/* Motor (FR8-FR12): owns TIM1 as the step generator */
void MotorInit(void);
void MotorStart(void);
void MotorSpeedLevelSet(uint8_t u8Level);
void MotorReverse(void);
void MotorStop(void);
void MotorStopSmooth(void);
boolean_t MotorIsRunning(void);
void MotorStepIsr(void);
/* Power latch on P33 (FR2-FR3): high = hold power on, low = cut power */
void PowerInit(void);
void PowerHoldOn(void);
void PowerCut(void);
#ifdef __cplusplus
}
#endif
#endif /* __APP_H__ */
+152
View File
@@ -0,0 +1,152 @@
#include "app.h"
#include "gpio.h"
#include "board_stkhc32f005.h"
#define BTN_DEBOUNCE_MS 20u
#define BTN_SHORT_MAX_MS 1000u /* FR5: short press < 1 s */
#define BTN_LONG_MS 2000u /* FR6: long press > 2 s */
#define BTN_DOUBLE_WINDOW_MS 300u /* FR7: release-to-press gap < 300 ms */
static uint8_t s_u8DebCnt = 0u;
static uint8_t s_u8GateRelCnt = 0u;
static boolean_t s_bPressed = FALSE; /* debounced state, TRUE = pressed (active low) */
static boolean_t s_bWaitRelease = FALSE; /* boot gate: button held at power-on */
static boolean_t s_bLongFired = FALSE;
static boolean_t s_bMaybeDbl = FALSE;
static uint16_t s_u16HoldMs = 0u;
static uint16_t s_u16DblWndMs = 0u;
static en_btn_event_t s_enEvent = BTN_EVT_NONE;
void ButtonInit(void)
{
stc_gpio_cfg_t stcCfg;
stcCfg.enDir = GpioDirIn;
stcCfg.enDrv = GpioDrvL;
stcCfg.enPu = GpioPuEnable;
stcCfg.enPd = GpioPdDisable;
stcCfg.enOD = GpioOdDisable;
Gpio_Init(APP_BUTTON_PORT, APP_BUTTON_PIN, &stcCfg);
/* if the button is held at power-on, require a release before
any button event is recognized */
if (FALSE == Gpio_GetInputIO(APP_BUTTON_PORT, APP_BUTTON_PIN))
{
s_bWaitRelease = TRUE;
}
}
void ButtonScan1ms(void)
{
boolean_t bRaw;
boolean_t bPrev;
bRaw = (FALSE == Gpio_GetInputIO(APP_BUTTON_PORT, APP_BUTTON_PIN)) ? TRUE : FALSE;
/* debounce: track the debounced press state */
bPrev = s_bPressed;
if (bRaw == s_bPressed)
{
s_u8DebCnt = 0u;
}
else if (++s_u8DebCnt >= BTN_DEBOUNCE_MS)
{
s_u8DebCnt = 0u;
s_bPressed = bRaw;
}
/* boot gate: swallow every event until the button has been truly
released. The exit condition must be a stable raw release, not the
debounced state: s_bPressed is still FALSE on the first scans while
the power-on press is held. */
if (TRUE == s_bWaitRelease)
{
if (TRUE == bRaw) /* still pressed (active low) */
{
s_u8GateRelCnt = 0u;
}
else if (++s_u8GateRelCnt >= BTN_DEBOUNCE_MS)
{
s_u8GateRelCnt = 0u;
s_bWaitRelease = FALSE;
s_bPressed = FALSE; /* sync: next press is a clean edge */
s_u16HoldMs = 0u;
s_u16DblWndMs = 0u;
s_bMaybeDbl = FALSE;
s_bLongFired = FALSE;
}
return; /* no classification, no hold timing, no events */
}
/* debounced edge classification */
if (bPrev != s_bPressed)
{
if (TRUE == s_bPressed)
{
/* press edge */
s_u16HoldMs = 0u;
s_bLongFired = FALSE;
if (s_u16DblWndMs > 0u)
{
s_bMaybeDbl = TRUE;
}
}
else
{
/* release edge: classify this hold */
if (FALSE == s_bLongFired)
{
if (TRUE == s_bMaybeDbl)
{
/* second press of a candidate double */
s_bMaybeDbl = FALSE;
if (s_u16HoldMs < BTN_SHORT_MAX_MS)
{
s_enEvent = BTN_EVT_DOUBLE;
s_u16DblWndMs = 0u;
}
else
{
s_u16DblWndMs = 0u; /* second press invalid: discard pair */
}
}
else if (s_u16HoldMs < BTN_SHORT_MAX_MS)
{
/* short release: arm the double-press window, dispatch if it expires */
s_u16DblWndMs = BTN_DOUBLE_WINDOW_MS;
}
/* release after 1 s < hold < 2 s: spec gray zone, no event */
}
s_bLongFired = FALSE;
s_u16HoldMs = 0u;
}
}
if (TRUE == s_bPressed)
{
s_u16HoldMs++;
if ((FALSE == s_bLongFired) && (s_u16HoldMs >= BTN_LONG_MS))
{
s_bLongFired = TRUE;
s_enEvent = BTN_EVT_LONG; /* fired while still held */
s_u16DblWndMs = 0u;
s_bMaybeDbl = FALSE;
}
}
else if (s_u16DblWndMs > 0u)
{
s_u16DblWndMs--;
if (0u == s_u16DblWndMs)
{
s_enEvent = BTN_EVT_SHORT; /* window expired: single short press */
}
}
}
en_btn_event_t ButtonGetEvent(void)
{
en_btn_event_t enEvent = s_enEvent;
s_enEvent = BTN_EVT_NONE;
return enEvent;
}
+152
View File
@@ -0,0 +1,152 @@
#include "app.h"
#include "gpio.h"
#include "board_stkhc32f005.h"
#define LED_SLOW_ON_MS 1000u /* FR14 */
#define LED_SLOW_OFF_MS 1000u
#define LED_FEEDBACK_ON_MS 150u /* FR16 */
#define LED_FEEDBACK_OFF_MS 150u
#define LED_QUICK_ON_MS 80u /* FR17 */
#define LED_QUICK_OFF_MS 80u
typedef enum en_led_mode
{
LED_MODE_OFF = 0u,
LED_MODE_SLOW = 1u,
LED_MODE_SOLID = 2u,
LED_MODE_PATTERN = 3u,
} en_led_mode_t;
static en_led_mode_t s_enMode = LED_MODE_OFF;
static boolean_t s_bOn = FALSE; /* LED physical on state */
static uint16_t s_u16PhaseMs = 0u;
static uint8_t s_u8BlinksLeft = 0u;
static uint16_t s_u16OnMs = 0u;
static uint16_t s_u16OffMs = 0u;
static void Led_Write(boolean_t bOn)
{
/* open-drain output, active low: level 0 = on */
Gpio_WriteOutputIO(APP_LED_PORT, APP_LED_PIN, (TRUE == bOn) ? FALSE : TRUE);
s_bOn = bOn;
}
static void Led_PatternStart(uint8_t u8Blinks, uint16_t u16OnMs, uint16_t u16OffMs)
{
s_u8BlinksLeft = u8Blinks;
s_u16OnMs = u16OnMs;
s_u16OffMs = u16OffMs;
s_u16PhaseMs = 0u;
s_enMode = LED_MODE_PATTERN;
Led_Write(TRUE);
}
void LedInit(void)
{
stc_gpio_cfg_t stcCfg;
stcCfg.enDir = GpioDirOut;
stcCfg.enDrv = GpioDrvL;
stcCfg.enPu = GpioPuDisable;
stcCfg.enPd = GpioPdDisable;
stcCfg.enOD = GpioOdEnable; /* FR13 note: LED pin is open-drain */
Gpio_Init(APP_LED_PORT, APP_LED_PIN, &stcCfg);
s_enMode = LED_MODE_OFF;
Led_Write(FALSE);
}
void LedSetState(en_app_state_t enState)
{
switch (enState)
{
case STATE_IDLE:
s_enMode = LED_MODE_SLOW;
s_u16PhaseMs = 0u;
Led_Write(TRUE);
break;
case STATE_ROTATING:
s_enMode = LED_MODE_SOLID;
Led_Write(TRUE);
break;
case STATE_POWER_OFF:
default:
s_enMode = LED_MODE_OFF;
Led_Write(FALSE);
break;
}
}
void LedBlink(uint8_t u8Times)
{
if (LED_MODE_SOLID == s_enMode)
{
Led_PatternStart(u8Times, LED_FEEDBACK_ON_MS, LED_FEEDBACK_OFF_MS);
}
}
void LedBlinkQuick(void)
{
if (LED_MODE_SOLID == s_enMode)
{
Led_PatternStart(2u, LED_QUICK_ON_MS, LED_QUICK_OFF_MS);
}
}
void Led1ms(void)
{
switch (s_enMode)
{
case LED_MODE_SLOW:
s_u16PhaseMs++;
if (s_u16PhaseMs >= ((TRUE == s_bOn) ? LED_SLOW_ON_MS : LED_SLOW_OFF_MS))
{
s_u16PhaseMs = 0u;
Led_Write((TRUE == s_bOn) ? FALSE : TRUE);
}
break;
case LED_MODE_SOLID:
if (FALSE == s_bOn)
{
Led_Write(TRUE);
}
break;
case LED_MODE_PATTERN:
s_u16PhaseMs++;
if (TRUE == s_bOn)
{
if (s_u16PhaseMs >= s_u16OnMs)
{
s_u16PhaseMs = 0u;
Led_Write(FALSE);
}
}
else
{
if (s_u16PhaseMs >= s_u16OffMs)
{
s_u16PhaseMs = 0u;
s_u8BlinksLeft--;
Led_Write(TRUE);
if (0u == s_u8BlinksLeft)
{
s_enMode = LED_MODE_SOLID;
}
}
}
break;
case LED_MODE_OFF:
default:
if (TRUE == s_bOn)
{
Led_Write(FALSE);
}
break;
}
}
+174
View File
@@ -0,0 +1,174 @@
#include "ddl.h"
#include "bt.h"
#include "sysctrl.h"
#include "interrupts_hc32f005.h"
#include "app.h"
#define TICK_HZ 1000u
#define POWER_OFF_LED_MS 50u
#define POWER_OFF_DECEL_TIMEOUT_MS 2000u
static en_app_state_t s_enState = STATE_IDLE;
static uint8_t s_u8Level = 1u;
static volatile uint16_t s_u16TickMs = 0u;
static void PeripheralsInit(void)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);
Sysctrl_SetPeripheralGate(SysctrlPeripheralBt, TRUE);
}
static void TickInit(void)
{
stc_bt_cfg_t stcCfg;
uint32_t u32Pclk = Sysctrl_GetPClkFreq();
stcCfg.enGateP = BtPositive;
stcCfg.enGate = BtGateDisable;
stcCfg.enPRS = BtPCLKDiv16;
stcCfg.enTog = BtTogDisable;
stcCfg.enCT = BtTimer;
stcCfg.enMD = BtMode2;
Bt_Init(TIM0, &stcCfg);
/* Mode 2: CNT counts up to 0xFFFF, then reloads from ARR, so the
interval is (0x10000 - ARR) ticks and CNT must start at ARR */
{
uint32_t u32Ticks = u32Pclk / 16u / TICK_HZ;
uint16_t u16Arr;
if (u32Ticks < 2u)
{
u32Ticks = 2u;
}
if (u32Ticks > 0xFFF0u)
{
u32Ticks = 0xFFF0u;
}
u16Arr = (uint16_t)(0x10000u - u32Ticks);
Bt_ARRSet(TIM0, u16Arr);
Bt_Cnt16Set(TIM0, u16Arr);
}
Bt_ClearIntFlag(TIM0);
Bt_EnableIrq(TIM0);
EnableNvic(TIM0_IRQn, IrqLevel3, TRUE);
Bt_Run(TIM0);
}
/* 1 ms system tick: button scanning and LED pattern engine */
void Tim0_IRQHandler(void)
{
if (TRUE == Bt_GetIntFlag(TIM0))
{
Bt_ClearIntFlag(TIM0);
s_u16TickMs++;
ButtonScan1ms();
Led1ms();
}
}
/* stepper step generator */
void Tim1_IRQHandler(void)
{
if (TRUE == Bt_GetIntFlag(TIM1))
{
Bt_ClearIntFlag(TIM1);
MotorStepIsr();
}
}
static void PowerOff(void)
{
uint16_t u16T0;
/* FR12: decelerate to a full stop before cutting power.
The step ISR ramps the motor down and stops the timer at standstill. */
MotorStopSmooth();
u16T0 = s_u16TickMs;
while ((FALSE != MotorIsRunning()) &&
((uint16_t)(s_u16TickMs - u16T0) < POWER_OFF_DECEL_TIMEOUT_MS))
{
; /* motor ISR ramps down while we wait */
}
if (FALSE != MotorIsRunning())
{
MotorStop(); /* timeout guard: force a stop, then cut power anyway */
}
u16T0 = s_u16TickMs;
LedSetState(STATE_POWER_OFF); /* FR13 */
while ((uint16_t)(s_u16TickMs - u16T0) < POWER_OFF_LED_MS)
{
; /* let the LED-off state be visible before power collapses */
}
__disable_irq();
PowerCut(); /* FR3 */
for (;;)
{
; /* terminal: main power is being cut externally */
}
}
int32_t main(void)
{
en_btn_event_t enEvent;
PeripheralsInit();
PowerInit();
PowerHoldOn(); /* FR2 */
LedInit();
MotorInit();
ButtonInit();
TickInit();
s_enState = STATE_IDLE;
s_u8Level = 1u;
LedSetState(STATE_IDLE); /* FR14 */
while (1)
{
enEvent = ButtonGetEvent();
if (BTN_EVT_LONG == enEvent) /* FR3, FR6 */
{
s_enState = STATE_POWER_OFF;
PowerOff();
}
switch (s_enState)
{
case STATE_IDLE:
if ((BTN_EVT_SHORT == enEvent) || (BTN_EVT_DOUBLE == enEvent))
{
MotorStart(); /* FR8 */
s_enState = STATE_ROTATING;
s_u8Level = 1u;
LedSetState(STATE_ROTATING);
LedBlink(1u); /* FR16: feedback for Speed 1 */
}
break;
case STATE_ROTATING:
if (BTN_EVT_SHORT == enEvent) /* FR9, FR16 */
{
s_u8Level = (uint8_t)(((s_u8Level % 4u)) + 1u);
MotorSpeedLevelSet(s_u8Level);
LedBlink(s_u8Level);
}
else if (BTN_EVT_DOUBLE == enEvent) /* FR10, FR17 */
{
MotorReverse();
LedBlinkQuick();
}
break;
case STATE_POWER_OFF:
default:
break;
}
}
}
+282
View File
@@ -0,0 +1,282 @@
#include "app.h"
#include "bt.h"
#include "gpio.h"
#include "board_stkhc32f005.h"
#include "interrupts_hc32f005.h"
#define MOTOR_SPEED_NUM 4u
#define MOTOR_ACC_SPS2 500u /* ramp rate, steps/s^2 */
#define MOTOR_START_SPS 60u /* speed used for the first step from standstill */
#define MOTOR_PRESCALE_DIV 16u /* BtPCLKDiv16 */
/* Speed levels in half-steps/s (4096 half-steps/rev => 2.5 / 5 / 7.5 / 10 RPM) */
static const uint16_t s_au16SpeedSps[MOTOR_SPEED_NUM] = {171u, 341u, 512u, 683u};
/* Half-step excitation table, bit0..bit3 = IN1..IN4 */
static const uint8_t s_au8PhaseTable[8] =
{
0x01u, 0x03u, 0x02u, 0x06u, 0x04u, 0x0Cu, 0x08u, 0x09u
};
static uint32_t s_u32TimerHz = 0u;
static boolean_t s_bEnabled = FALSE;
static int8_t s_s8Dir = 1;
static uint8_t s_u8Phase = 0u;
static uint32_t s_u32CurSps = 0u;
static uint32_t s_u32TgtSps = 0u;
static uint8_t s_u8Level = 1u;
static boolean_t s_bRevPending = FALSE;
static void Motor_WritePhase(uint8_t u8Phase)
{
uint8_t u8Val = s_au8PhaseTable[u8Phase & 0x07u];
Gpio_WriteOutputIO(APP_MOTOR_IN1_PORT, APP_MOTOR_IN1_PIN, (u8Val & 0x01u) ? TRUE : FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN2_PORT, APP_MOTOR_IN2_PIN, (u8Val & 0x02u) ? TRUE : FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN3_PORT, APP_MOTOR_IN3_PIN, (u8Val & 0x04u) ? TRUE : FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN4_PORT, APP_MOTOR_IN4_PIN, (u8Val & 0x08u) ? TRUE : FALSE);
}
static void Motor_Release(void)
{
Gpio_WriteOutputIO(APP_MOTOR_IN1_PORT, APP_MOTOR_IN1_PIN, FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN2_PORT, APP_MOTOR_IN2_PIN, FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN3_PORT, APP_MOTOR_IN3_PIN, FALSE);
Gpio_WriteOutputIO(APP_MOTOR_IN4_PORT, APP_MOTOR_IN4_PIN, FALSE);
}
static uint16_t Motor_ArrForSps(uint32_t u32Sps)
{
uint32_t u32Ticks;
if (0u == u32Sps)
{
u32Sps = 1u;
}
/* Mode 2 reload mode: interval = (0x10000 - ARR) ticks */
u32Ticks = s_u32TimerHz / u32Sps;
if (u32Ticks < 2u)
{
u32Ticks = 2u;
}
if (u32Ticks > 0xFFF0u)
{
u32Ticks = 0xFFF0u; /* 16-bit counter capacity */
}
return (uint16_t)(0x10000u - u32Ticks);
}
static void Motor_TimerStart(void)
{
uint16_t u16Arr = Motor_ArrForSps(s_u32CurSps);
Bt_ARRSet(TIM1, u16Arr);
Bt_Cnt16Set(TIM1, u16Arr);
Bt_Run(TIM1);
s_bEnabled = TRUE;
}
static void Motor_TimerStop(void)
{
Bt_Stop(TIM1);
s_bEnabled = FALSE;
}
void MotorInit(void)
{
stc_gpio_cfg_t stcGpioCfg;
stc_bt_cfg_t stcBtCfg;
s_u32TimerHz = Sysctrl_GetPClkFreq() / MOTOR_PRESCALE_DIV;
stcGpioCfg.enDir = GpioDirOut;
stcGpioCfg.enDrv = GpioDrvL;
stcGpioCfg.enPu = GpioPuDisable;
stcGpioCfg.enPd = GpioPdDisable;
stcGpioCfg.enOD = GpioOdDisable;
Gpio_Init(APP_MOTOR_IN1_PORT, APP_MOTOR_IN1_PIN, &stcGpioCfg);
Gpio_Init(APP_MOTOR_IN2_PORT, APP_MOTOR_IN2_PIN, &stcGpioCfg);
Gpio_Init(APP_MOTOR_IN3_PORT, APP_MOTOR_IN3_PIN, &stcGpioCfg);
Gpio_Init(APP_MOTOR_IN4_PORT, APP_MOTOR_IN4_PIN, &stcGpioCfg);
Motor_Release();
stcBtCfg.enGateP = BtPositive;
stcBtCfg.enGate = BtGateDisable;
stcBtCfg.enPRS = BtPCLKDiv16;
stcBtCfg.enTog = BtTogDisable;
stcBtCfg.enCT = BtTimer;
stcBtCfg.enMD = BtMode2;
Bt_Init(TIM1, &stcBtCfg);
Bt_ClearIntFlag(TIM1);
Bt_EnableIrq(TIM1);
EnableNvic(TIM1_IRQn, IrqLevel3, TRUE);
s_bEnabled = FALSE;
s_s8Dir = 1;
s_u8Phase = 0u;
s_u32CurSps = 0u;
s_u32TgtSps = 0u;
s_bRevPending = FALSE;
}
void MotorStart(void)
{
if (FALSE != s_bEnabled)
{
return;
}
s_u8Phase = 0u;
s_s8Dir = 1;
s_u32CurSps = MOTOR_START_SPS;
s_u32TgtSps = s_au16SpeedSps[0];
s_u8Level = 1u;
s_bRevPending = FALSE;
Motor_WritePhase(s_u8Phase);
Motor_TimerStart();
}
void MotorSpeedLevelSet(uint8_t u8Level)
{
if (0u == u8Level)
{
return;
}
if (u8Level > MOTOR_SPEED_NUM)
{
u8Level = MOTOR_SPEED_NUM;
}
if (FALSE == s_bEnabled)
{
return;
}
s_u8Level = u8Level;
s_u32TgtSps = s_au16SpeedSps[u8Level - 1u];
}
void MotorReverse(void)
{
if (FALSE == s_bEnabled)
{
return;
}
if (0u == s_u32CurSps)
{
s_s8Dir = (int8_t)(-s_s8Dir);
}
else
{
/* decelerate to standstill first, then flip and ramp back up */
s_bRevPending = TRUE;
s_u32TgtSps = 0u;
}
}
void MotorStop(void)
{
Motor_TimerStop();
Motor_Release();
s_u32CurSps = 0u;
s_u32TgtSps = 0u;
s_bRevPending = FALSE;
}
void MotorStopSmooth(void)
{
if (FALSE == s_bEnabled)
{
return;
}
/* request deceleration; the step ISR ramps to standstill and stops
the timer itself when the target speed of 0 is reached (FR12) */
s_bRevPending = FALSE;
s_u32TgtSps = 0u;
}
boolean_t MotorIsRunning(void)
{
return s_bEnabled;
}
void MotorStepIsr(void)
{
uint32_t u32AccPerStep;
if (FALSE == s_bEnabled)
{
Motor_TimerStop();
return;
}
if (0u == s_u32CurSps)
{
/* at standstill: flip a pending reversal, otherwise park the timer */
if (TRUE == s_bRevPending)
{
s_s8Dir = (int8_t)(-s_s8Dir);
s_bRevPending = FALSE;
s_u32TgtSps = s_au16SpeedSps[s_u8Level - 1u];
}
else
{
Motor_TimerStop();
Motor_Release();
return;
}
}
else
{
/* advance half-step sequence */
s_u8Phase = (uint8_t)((s_u8Phase + s_s8Dir) & 0x07u);
Motor_WritePhase(s_u8Phase);
}
/* trapezoidal ramp toward target speed.
Note: restart speed must stay representable as a 16-bit interval */
if (0u == s_u32CurSps)
{
s_u32CurSps = MOTOR_START_SPS;
}
u32AccPerStep = ((uint32_t)MOTOR_ACC_SPS2 << 8) / s_u32CurSps;
if (u32AccPerStep < 256u)
{
u32AccPerStep = 256u; /* at least 1 step/s per step at high speed */
}
u32AccPerStep >>= 8;
if (s_u32CurSps < s_u32TgtSps)
{
s_u32CurSps += u32AccPerStep;
if (s_u32CurSps > s_u32TgtSps)
{
s_u32CurSps = s_u32TgtSps;
}
}
else if (s_u32CurSps > s_u32TgtSps)
{
uint32_t u32Rem = s_u32CurSps - s_u32TgtSps;
if (u32AccPerStep > u32Rem)
{
u32AccPerStep = u32Rem; /* never undershoot past the target */
}
s_u32CurSps -= u32AccPerStep;
}
if ((0u == s_u32CurSps) && (FALSE == s_bRevPending))
{
/* standstill reached (e.g. smooth power-off): park immediately */
Motor_TimerStop();
Motor_Release();
return;
}
{
uint16_t u16Arr = Motor_ArrForSps(s_u32CurSps);
Bt_ARRSet(TIM1, u16Arr);
Bt_Cnt16Set(TIM1, u16Arr);
}
}
+30
View File
@@ -0,0 +1,30 @@
#include "app.h"
#include "gpio.h"
#include "board_stkhc32f005.h"
/* Power latch polarity (FR2/FR3, updated spec):
* P33 HIGH (push-pull output) -> hold main power on
* P33 LOW (push-pull output) -> cut main power */
void PowerInit(void)
{
stc_gpio_cfg_t stcCfg;
stcCfg.enDir = GpioDirOut;
stcCfg.enDrv = GpioDrvL;
stcCfg.enPu = GpioPuDisable;
stcCfg.enPd = GpioPdDisable;
stcCfg.enOD = GpioOdDisable; /* push-pull */
Gpio_Init(APP_POWER_PORT, APP_POWER_PIN, &stcCfg);
}
void PowerHoldOn(void)
{
Gpio_WriteOutputIO(APP_POWER_PORT, APP_POWER_PIN, TRUE);
}
void PowerCut(void)
{
Gpio_WriteOutputIO(APP_POWER_PORT, APP_POWER_PIN, FALSE);
}
+265
View File
@@ -0,0 +1,265 @@
/**************************************************************************//**
* @file cmsis_compiler.h
* @brief CMSIS compiler generic header file
* @version V5.0.4
* @date 10. January 2018
******************************************************************************/
/*
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_COMPILER_H
#define __CMSIS_COMPILER_H
#include <stdint.h>
/*
* Arm Compiler 4/5
*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*
* Arm Compiler 6 (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armclang.h"
/*
* GNU Compiler
*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*
* IAR Compiler
*/
#elif defined ( __ICCARM__ )
#include <cmsis_iccarm.h>
/*
* TI Arm Compiler
*/
#elif defined ( __TI_ARM__ )
#include <cmsis_ccs.h>
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __attribute__((packed))
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __attribute__((packed))
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
/*
* TASKING Compiler
*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __packed__
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __packed__
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __packed__
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __packed__ T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __align(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
/*
* COSMIC Compiler
*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#ifndef __ASM
#define __ASM _asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
// NO RETURN is automatically detected hence no warning here
#define __NO_RETURN
#endif
#ifndef __USED
#warning No compiler specific solution for __USED. __USED is ignored.
#define __USED
#endif
#ifndef __WEAK
#define __WEAK __weak
#endif
#ifndef __PACKED
#define __PACKED @packed
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT @packed struct
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION @packed union
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
@packed struct T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
#else
#error Unknown compiler.
#endif
#endif /* __CMSIS_COMPILER_H */
File diff suppressed because it is too large. Load diff
+39
View File
@@ -0,0 +1,39 @@
/**************************************************************************//**
* @file cmsis_version.h
* @brief CMSIS Core(M) Version definitions
* @version V5.0.2
* @date 19. April 2017
******************************************************************************/
/*
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CMSIS_VERSION_H
#define __CMSIS_VERSION_H
/* CMSIS Version definitions */
#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
#define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */
#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
__CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
#endif
File diff suppressed because it is too large. Load diff
+147
View File
@@ -0,0 +1,147 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file base_types.h
**
** base type common define.
** @link SampleGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
#ifndef __BASE_TYPES_H__
#define __BASE_TYPES_H__
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
#ifndef TRUE
/** Value is true (boolean_t type) */
#define TRUE ((boolean_t) 1u)
#endif
#ifndef FALSE
/** Value is false (boolean_t type) */
#define FALSE ((boolean_t) 0u)
#endif
/** Returns the minimum value out of two values */
#define MINIMUM( X, Y ) ((X) < (Y) ? (X) : (Y))
/** Returns the maximum value out of two values */
#define MAXIMUM( X, Y ) ((X) > (Y) ? (X) : (Y))
/** Returns the dimension of an array */
#define ARRAY_SZ( X ) (sizeof(X) / sizeof((X)[0]))
#ifdef __DEBUG_ASSERT
#define ASSERT(x) do{ assert((x)> 0u) ; }while(0);
#else
#define ASSERT(x) {}
#endif
/******************************************************************************
* Global type definitions
******************************************************************************/
/** logical datatype (only values are TRUE and FALSE) */
typedef uint8_t boolean_t;
/** single precision floating point number (4 byte) */
typedef float float32_t;
/** double precision floating point number (8 byte) */
typedef double float64_t;
/** ASCII character for string generation (8 bit) */
typedef char char_t;
/** function pointer type to void/void function */
typedef void (*func_ptr_t)(void);
/** function pointer type to void/uint8_t function */
typedef void (*func_ptr_arg1_t)(uint8_t u8Param);
/** generic error codes */
typedef enum en_result
{
Ok = 0u, ///< No error
Error = 1u, ///< Non-specific error code
ErrorAddressAlignment = 2u, ///< Address alignment does not match
ErrorAccessRights = 3u, ///< Wrong mode (e.g. user/system) mode is set
ErrorInvalidParameter = 4u, ///< Provided parameter is not valid
ErrorOperationInProgress = 5u, ///< A conflicting or requested operation is still in progress
ErrorInvalidMode = 6u, ///< Operation not allowed in current mode
ErrorUninitialized = 7u, ///< Module (or part of it) was not initialized properly
ErrorBufferFull = 8u, ///< Circular buffer can not be written because the buffer is full
ErrorTimeout = 9u, ///< Time Out error occurred (e.g. I2C arbitration lost, Flash time-out, etc.)
ErrorNotReady = 10u, ///< A requested final state is not reached
OperationInProgress = 11u ///< Indicator for operation in progress
} en_result_t;
/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/
/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
#endif /* __BASE_TYPES_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+24
View File
@@ -0,0 +1,24 @@
#ifndef __BOARD_STKHC32F005_H__
#define __BOARD_STKHC32F005_H__
#include "hc32f005.h"
#define APP_LED_PORT GpioPort0
#define APP_LED_PIN GpioPin2
#define APP_MOTOR_IN1_PORT GpioPort2
#define APP_MOTOR_IN1_PIN GpioPin3
#define APP_MOTOR_IN2_PORT GpioPort2
#define APP_MOTOR_IN2_PIN GpioPin4
#define APP_MOTOR_IN3_PORT GpioPort2
#define APP_MOTOR_IN3_PIN GpioPin5
#define APP_MOTOR_IN4_PORT GpioPort2
#define APP_MOTOR_IN4_PIN GpioPin6
#define APP_BUTTON_PORT GpioPort3
#define APP_BUTTON_PIN GpioPin2
#define APP_POWER_PORT GpioPort3
#define APP_POWER_PIN GpioPin3
#endif /* __BOARD_STKHC32F005_H__ */
+7
View File
@@ -0,0 +1,7 @@
#ifndef __DDL_DEVICE_H__
#define __DDL_DEVICE_H__
#define DDL_DEVICE_SERIES DDL_DEVICE_SERIES_HC32F005
#define DDL_DEVICE_PACKAGE DDL_DEVICE_PACKAGE_HC_C
#endif /* __DDL_DEVICE_H__ */
File diff suppressed because it is too large. Load diff
+477
View File
@@ -0,0 +1,477 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file interrupts_hc32f005.c
**
** Interrupt management
** @link Driver Group Some description @endlink
**
** - 2018-04-15 1.0 Lux First version.
**
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/*******************************************************************************
* IRQ WEAK DEFINE
******************************************************************************/
__WEAK void SysTick_IRQHandler(void);
__WEAK void Port0_IRQHandler(void);
__WEAK void Port1_IRQHandler(void);
__WEAK void Port2_IRQHandler(void);
__WEAK void Port3_IRQHandler(void);
__WEAK void Dmac_IRQHandler(void);
__WEAK void Tim3_IRQHandler(void);
__WEAK void Uart0_IRQHandler(void);
__WEAK void Uart1_IRQHandler(void);
__WEAK void Spi_IRQHandler(void);
__WEAK void I2c_IRQHandler(void);
__WEAK void Tim0_IRQHandler(void);
__WEAK void Tim1_IRQHandler(void);
__WEAK void Tim2_IRQHandler(void);
__WEAK void Tim4_IRQHandler(void);
__WEAK void Tim5_IRQHandler(void);
__WEAK void Tim6_IRQHandler(void);
__WEAK void Pca_IRQHandler(void);
__WEAK void Wdt_IRQHandler(void);
__WEAK void Adc_IRQHandler(void);
__WEAK void Dac_IRQHandler(void);
__WEAK void Pcnt_IRQHandler(void);
__WEAK void Vc0_IRQHandler(void);
__WEAK void Vc1_IRQHandler(void);
__WEAK void Lvd_IRQHandler(void);
__WEAK void Flash_IRQHandler(void);
__WEAK void Ram_IRQHandler(void);
__WEAK void ClkTrim_IRQHandler(void);
/**
*******************************************************************************
** \brief NVIC 中断使能
**
** \param [in] enIrq 中断号枚举类型
** \param [in] enLevel 中断优先级枚举类型
** \param [in] bEn 中断开关
** \retval Ok 设置成功
** 其他值 设置失败
******************************************************************************/
void EnableNvic(IRQn_Type enIrq, en_irq_level_t enLevel, boolean_t bEn)
{
NVIC_ClearPendingIRQ(enIrq);
NVIC_SetPriority(enIrq, enLevel);
if (TRUE == bEn)
{
NVIC_EnableIRQ(enIrq);
}
else
{
NVIC_DisableIRQ(enIrq);
}
}
/**
*******************************************************************************
** \brief NVIC hardware fault 中断实现
**
**
** \retval
******************************************************************************/
void HardFault_Handler(void)
{
volatile int a = 0;
while( 0 == a)
{
;
}
}
/**
*******************************************************************************
** \brief NVIC SysTick 中断实现
**
** \retval
******************************************************************************/
void SysTick_Handler(void)
{
SysTick_IRQHandler();
}
/**
*******************************************************************************
** \brief GPIO Port0 中断处理函数
**
** \retval
******************************************************************************/
void PORT0_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PORT0)
Port0_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief GPIO Port1 中断处理函数
**
** \retval
******************************************************************************/
void PORT1_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PORT1)
Port1_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief GPIO Port2 中断处理函数
**
** \retval
******************************************************************************/
void PORT2_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PORT2)
Port2_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief GPIO Port3 中断处理函数
**
** \retval
******************************************************************************/
void PORT3_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PORT3)
Port3_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief DMAC 中断处理函数
**
** \retval
******************************************************************************/
void DMAC_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_DMAC)
Dmac_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM3 中断处理函数
**
** \retval
******************************************************************************/
void TIM3_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM3)
Tim3_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief UART0 中断处理函数
**
** \retval
******************************************************************************/
void UART0_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_UART0)
Uart0_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief UART1 中断处理函数
**
** \retval
******************************************************************************/
void UART1_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_UART1)
Uart1_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief SPI 中断处理函数
**
** \retval
******************************************************************************/
void SPI_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_SPI)
Spi_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief I2C 中断处理函数
**
** \retval
******************************************************************************/
void I2C_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_I2C)
I2c_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM0 中断处理函数
**
** \retval
******************************************************************************/
void TIM0_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM0)
Tim0_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM1 中断处理函数
**
** \retval
******************************************************************************/
void TIM1_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM1)
Tim1_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM2 中断处理函数
**
** \retval
******************************************************************************/
void TIM2_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM2)
Tim2_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM4 中断处理函数
**
** \retval
******************************************************************************/
void TIM4_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM4)
Tim4_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM5 中断处理函数
**
** \retval
******************************************************************************/
void TIM5_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM5)
Tim5_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief TIM6 中断处理函数
**
** \retval
******************************************************************************/
void TIM6_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_TIM6)
Tim6_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief PCA 中断处理函数
**
** \retval
******************************************************************************/
void PCA_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PCA)
Pca_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief WDT 中断处理函数
**
** \retval
******************************************************************************/
void WDT_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_WDT)
Wdt_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief ADC 中断处理函数
**
** \retval
******************************************************************************/
void ADC_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_ADC)
Adc_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief PCNT 中断处理函数
**
** \retval
******************************************************************************/
void PCNT_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_PCNT)
Pcnt_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief VC0 中断处理函数
**
** \retval
******************************************************************************/
void VC0_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_VC0)
Vc0_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief VC1 中断处理函数
**
** \retval
******************************************************************************/
void VC1_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_VC1)
Vc1_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief LVD 中断处理函数
**
** \retval
******************************************************************************/
void LVD_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_LVD)
Lvd_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief FLASH/RAM 中断处理函数
**
** \retval
******************************************************************************/
void FLASH_RAM_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_FLASH)
Flash_IRQHandler();
#endif
#if (INT_CALLBACK_ON == INT_CALLBACK_RAM)
Ram_IRQHandler();
#endif
}
/**
*******************************************************************************
** \brief CLKTRIM 中断处理函数
**
** \retval
******************************************************************************/
void CLKTRIM_IRQHandler(void)
{
#if (INT_CALLBACK_ON == INT_CALLBACK_CLKTRIM)
ClkTrim_IRQHandler();
#endif
}
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+136
View File
@@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file interrupts_hc32l13x.h
**
** Interrupt common define.
** @link IRQGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
#ifndef __INTERRUPTS_HC32F005_H__
#define __INTERRUPTS_HC32F005_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define DDL_IRQ_LEVEL_DEFAULT 3u
//<<此选项会打开interrupt_hc32xxx.c中的中断回调函数,用户如果需要实现中断服务函数,
//<<可在源码文件中定义该文件中用"__WEAK"声明的同名中断服务函数即可。
#define INT_CALLBACK_ON 1u //<<(默认值)
//<<此选项会关闭interrupt_hc32xxx.c中的中断回调函数,此时用户可在该文件中自行定义中断服务函数的实现。
#define INT_CALLBACK_OFF 0u
/******************************************************************************
* Global type definitions
******************************************************************************/
#define INT_CALLBACK_PORT0 INT_CALLBACK_ON
#define INT_CALLBACK_PORT1 INT_CALLBACK_ON
#define INT_CALLBACK_PORT2 INT_CALLBACK_ON
#define INT_CALLBACK_PORT3 INT_CALLBACK_ON
#define INT_CALLBACK_DMAC INT_CALLBACK_ON
#define INT_CALLBACK_TIM3 INT_CALLBACK_ON
#define INT_CALLBACK_UART0 INT_CALLBACK_ON
#define INT_CALLBACK_UART1 INT_CALLBACK_ON
#define INT_CALLBACK_SPI INT_CALLBACK_ON
#define INT_CALLBACK_I2C INT_CALLBACK_ON
#define INT_CALLBACK_TIM0 INT_CALLBACK_ON
#define INT_CALLBACK_TIM1 INT_CALLBACK_ON
#define INT_CALLBACK_TIM2 INT_CALLBACK_ON
#define INT_CALLBACK_TIM4 INT_CALLBACK_ON
#define INT_CALLBACK_TIM5 INT_CALLBACK_ON
#define INT_CALLBACK_TIM6 INT_CALLBACK_ON
#define INT_CALLBACK_PCA INT_CALLBACK_ON
#define INT_CALLBACK_WDT INT_CALLBACK_ON
#define INT_CALLBACK_ADC INT_CALLBACK_ON
#define INT_CALLBACK_PCNT INT_CALLBACK_ON
#define INT_CALLBACK_VC0 INT_CALLBACK_ON
#define INT_CALLBACK_VC1 INT_CALLBACK_ON
#define INT_CALLBACK_LVD INT_CALLBACK_ON
#define INT_CALLBACK_FLASH INT_CALLBACK_ON
#define INT_CALLBACK_RAM INT_CALLBACK_ON
#define INT_CALLBACK_CLKTRIM INT_CALLBACK_ON
/**
*******************************************************************************
** \brief 中断优先级数据类型定义
** \note
******************************************************************************/
typedef enum en_irq_level
{
IrqLevel0 = 0u, ///< 优先级0
IrqLevel1 = 1u, ///< 优先级1
IrqLevel2 = 2u, ///< 优先级2
IrqLevel3 = 3u, ///< 优先级3
} en_irq_level_t;
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 系统中断使能开关
extern void EnableNvic(IRQn_Type enIrq, en_irq_level_t enLevel, boolean_t bEn);
#ifdef __cplusplus
}
#endif
#endif /* __INTERRUPTS_HC32L13X_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+91
View File
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc32f005.c
**
** System clock initialization.
** @link SampleGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "base_types.h"
#include "hc32f005.h"
#include "system_hc32f005.h"
#include "sysctrl.h"
/**
******************************************************************************
** System Clock Frequency (Core Clock) Variable according CMSIS
******************************************************************************/
uint32_t SystemCoreClock = 4000000;
//add clock source.
void SystemCoreClockUpdate (void) // Update SystemCoreClock variable
{
SystemCoreClock = Sysctrl_GetHClkFreq();
}
/**
******************************************************************************
** \brief Setup the microcontroller system. Initialize the System and update
** the SystemCoreClock variable.
**
** \param none
** \return none
******************************************************************************/
void SystemInit(void)
{
SystemCoreClockUpdate();
}
+111
View File
@@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc3f005.h
**
** A detailed description is available at
** @link SampleGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
#ifndef __SYSTEM_HC32F005_H__
#define __SYSTEM_HC32F005_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('define') */
/******************************************************************************/
#define HWWD_DISABLE (1)
/**
******************************************************************************
** \brief Clock Setup macro definition
**
** - 0: CLOCK_SETTING_NONE - User provides own clock setting in application
** - 1: CLOCK_SETTING_CMSIS -
******************************************************************************/
#define CLOCK_SETTING_NONE 0u
#define CLOCK_SETTING_CMSIS 1u
/******************************************************************************/
/* */
/* START OF USER SETTINGS HERE */
/* =========================== */
/* */
/* All lines with '<<<' can be set by user. */
/* */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
extern void SystemInit (void); // Initialize the system
extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_HC32F005_H__ */
+369
View File
@@ -0,0 +1,369 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file adc.h
**
** Header file for AD Converter functions
** @link ADC Group Some description @endlink
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
#ifndef __ADC_H__
#define __ADC_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup AdcGroup AD Converter (ADC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global definitions
******************************************************************************/
#define ADC_SCAN_CH0_EN (0x1u) /*!< SCAN模式使用ADC CH0 */
#define ADC_SCAN_CH1_EN (0x1u<<1) /*!< SCAN模式使用ADC CH1 */
#define ADC_SCAN_CH2_EN (0x1u<<2) /*!< SCAN模式使用ADC CH2 */
#define ADC_SCAN_CH3_EN (0x1u<<3) /*!< SCAN模式使用ADC CH3 */
#define ADC_SCAN_CH4_EN (0x1u<<4) /*!< SCAN模式使用ADC CH4 */
#define ADC_SCAN_CH5_EN (0x1u<<5) /*!< SCAN模式使用ADC CH5 */
#define ADC_SCAN_CH6_EN (0x1u<<6) /*!< SCAN模式使用ADC CH6 */
#define ADC_SCAN_CH7_EN (0x1u<<7) /*!< SCAN模式使用ADC CH7 */
/******************************************************************************
** Global type definitions
*****************************************************************************/
/**
******************************************************************************
** \brief ADC采样模式
*****************************************************************************/
typedef enum en_adc_op_mode
{
AdcNormalMode = 0, /*!< 单输入通道单次采样模式 */
AdcContMode = 1, /*!< 单输入通道连续采样模式 */
AdcScanMode = 2, /*!< 多输入通道扫描采样模式*/
} en_adc_op_mode_t;
/**
******************************************************************************
** \brief ADC时钟选择
*****************************************************************************/
typedef enum en_adc_clk_sel
{
AdcClkSysTDiv1 = 0, /*!< PCLK */
AdcClkSysTDiv2 = 1, /*!< 1/2 PCLK */
AdcClkSysTDiv4 = 2, /*!< 1/4 PCLK */
AdcClkSysTDiv8 = 3, /*!< 1/8 PCLK */
} en_adc_clk_sel_t;
/**
******************************************************************************
** \brief ADC参考电压
*****************************************************************************/
typedef enum en_adc_ref_vol_sel
{
RefVolSelInBgr1p5 = 0, /*!<内部参考电压1.5V(SPS<=200kHz)*/
RefVolSelInBgr2p5 = 1, /*!<内部参考电压2.5V(avdd>3V,SPS<=200kHz)*/
RefVolSelExtern1 = 2, /*!<外部输入(max avdd) P3.6*/
RefVolSelAVDD = 3, /*!<AVDD*/
}en_adc_ref_vol_sel_t;
/**
******************************************************************************
** \brief ADC采样通道选择
*****************************************************************************/
typedef enum en_adc_samp_ch_sel
{
AdcExInputCH0 = 0, /*!<使用通道0输入P2.4*/
AdcExInputCH1 = 1, /*!<使用通道1输入P2.6*/
AdcExInputCH2 = 2, /*!<使用通道2输入P3.2*/
AdcExInputCH3 = 3, /*!<使用通道3输入P3.3*/
AdcExInputCH4 = 4, /*!<使用通道4输入P3.4*/
AdcExInputCH5 = 5, /*!<使用通道5输入P3.5*/
AdcExInputCH6 = 6, /*!<使用通道6输入P3.6*/
AdcExInputCH7 = 7, /*!<使用通道7输入P0.1*/
AdcExInputCH8 = 8, /*!<使用通道8输入P0.2*/
AdcAVccDiV3Input = 9, /*!<使用1/3 AVCC(必须使用输入增益)*/
AdcAiTsInput = 10, /*!<使用AI_TS(必须使用输入增益)*/
AdcVref1P2Input = 11, /*!<使用Vref1P2(必须使用输入增益)*/
}en_adc_samp_ch_sel_t;
/**
******************************************************************************
** \brief ADC采样周期数选择
*****************************************************************************/
typedef enum en_adc_samp_time_sel
{
AdcSampTime4Clk = 0, /*!<4个采样时钟*/
AdcSampTime6Clk = 1, /*!<6个采样时钟*/
AdcSampTime8Clk = 2, /*!<8个采样时钟*/
AdcSampTime12Clk = 3, /*!<12个采样时钟*/
}en_adc_samp_time_sel_t;
/**
******************************************************************************
** \brief ADC周边模块反射源选择
*****************************************************************************/
typedef enum en_adc_trig_sel
{
AdcTrigDisable = 0, /*!<禁用周边模块反射源*/
AdcTrigTimer0 = 1, /*!<选择timer0中断源,自动触发ADC采样*/
AdcTrigTimer1 = 2, /*!<选择timer1中断源,自动触发ADC采样*/
AdcTrigTimer2 = 3, /*!<选择timer2中断源,自动触发ADC采样*/
AdcTrigLptimer = 4, /*!<选择lptimer中断源,自动触发ADC采样*/
AdcTrigTimer4 = 5, /*!<选择timer4中断源,自动触发ADC采样*/
AdcTrigTimer5 = 6, /*!<选择timer5中断源,自动触发ADC采样*/
AdcTrigTimer6 = 7, /*!<选择timer6中断源,自动触发ADC采样*/
AdcTrigUart0 = 8, /*!<选择uart0中断源,自动触发ADC采样*/
AdcTrigUart1 = 9, /*!<选择uart1中断源,自动触发ADC采样*/
AdcTrigLpuart = 10, /*!<选择lpuart中断源,自动触发ADC采样*/
AdcTrigVC1 = 11, /*!<选择VC1中断源,自动触发ADC采样*/
AdcTrigVC2 = 12, /*!<选择VC2中断源,自动触发ADC采样*/
AdcTrigRTC = 13, /*!<选择RTC中断源,自动触发ADC采样*/
AdcTrigPCA = 14, /*!<选择PCA中断源,自动触发ADC采样*/
AdcTrigSPI = 15, /*!<选择SPI中断源,自动触发ADC采样*/
AdcTrigP01 = 16, /*!<选择P01中断源,自动触发ADC采样*/
AdcTrigP02 = 17, /*!<选择P02中断源,自动触发ADC采样*/
AdcTrigP03 = 18, /*!<选择P03中断源,自动触发ADC采样*/
AdcTrigP14 = 19, /*!<选择P14中断源,自动触发ADC采样*/
AdcTrigP15 = 20, /*!<选择P15中断源,自动触发ADC采样*/
AdcTrigP23 = 21, /*!<选择P23中断源,自动触发ADC采样*/
AdcTrigP24 = 22, /*!<选择P24中断源,自动触发ADC采样*/
AdcTrigP25 = 23, /*!<选择P25中断源,自动触发ADC采样*/
AdcTrigP26 = 24, /*!<选择P26中断源,自动触发ADC采样*/
AdcTrigP27 = 25, /*!<选择P27中断源,自动触发ADC采样*/
AdcTrigP31 = 26, /*!<选择P31中断源,自动触发ADC采样*/
AdcTrigP32 = 27, /*!<选择P32中断源,自动触发ADC采样*/
AdcTrigP33 = 28, /*!<选择P33中断源,自动触发ADC采样*/
AdcTrigP34 = 29, /*!<选择P34中断源,自动触发ADC采样*/
AdcTrigP35 = 30, /*!<选择P35中断源,自动触发ADC采样*/
AdcTrigP36 = 31, /*!<选择P36中断源,自动触发ADC采样*/
}en_adc_trig_sel_t;
/******************************************************************************
* Extern type definitions ('typedef') *
******************************************************************************/
/**
******************************************************************************
** \brief ADC配置
*****************************************************************************/
typedef struct stc_adc_cfg
{
/*! ADC操作模式*/
en_adc_op_mode_t enAdcOpMode;
/*! ADC时钟选择*/
en_adc_clk_sel_t enAdcClkSel;
/*! ADC采样时间*/
en_adc_samp_time_sel_t enAdcSampTimeSel;
/*! ADC参考电压*/
en_adc_ref_vol_sel_t enAdcRefVolSel;
/*! ADC输入增益使能*/
boolean_t bAdcInBufEn;
/*!ADC区间模式上限值*/
uint32_t u32AdcRegHighThd;
/*!ADC区间模式下限值*/
uint32_t u32AdcRegLowThd;
/*! ADC触发0选择*/
en_adc_trig_sel_t enAdcTrig0Sel;
/*! ADC触发1选择*/
en_adc_trig_sel_t enAdcTrig1Sel;
}stc_adc_cfg_t;
/**
******************************************************************************
** \brief ADC单次采样模式配置
*****************************************************************************/
typedef struct stc_adc_norm_cfg
{
/*! ADC通道选择*/
en_adc_samp_ch_sel_t enAdcNormModeCh;
/*! ADC结果累加使能*/
boolean_t bAdcResultAccEn;
}stc_adc_norm_cfg_t;
/**
******************************************************************************
** \brief ADC单通道连续采样模式配置
*****************************************************************************/
typedef struct stc_adc_cont_cfg
{
/*! ADC通道选择*/
en_adc_samp_ch_sel_t enAdcContModeCh;
/*! ADC采样次数*/
uint8_t u8AdcSampCnt;
/*! ADC结果累加使能*/
boolean_t bAdcResultAccEn;
}stc_adc_cont_cfg_t;
/**
******************************************************************************
** \brief ADC扫描采样模式配置
*****************************************************************************/
typedef struct stc_adc_scan_cfg
{
/*! ADC通道选择*/
uint8_t u8AdcScanModeCh;
/*! ADC采样次数*/
uint8_t u8AdcSampCnt;
}stc_adc_scan_cfg_t;
/**
******************************************************************************
** \brief ADC中断配置
*****************************************************************************/
typedef struct stc_adc_irq
{
/*!<ADC连续采样中断*/
boolean_t bAdcIrq;
/*!ADC区间*/
boolean_t bAdcRegCmp;
/*!ADC上超出区间*/
boolean_t bAdcHhtCmp;
/*!ADC下超出区间*/
boolean_t bAdcLltCmp;
}stc_adc_irq_t;
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//ADC initialization
en_result_t Adc_Init(stc_adc_cfg_t* pstcAdcConfig);
//ADC de-init
void Adc_DeInit(void);
//ADC conversion start
void Adc_Start(void);
//ADC conversion stop
void Adc_Stop(void);
//ADC conversion enable
void Adc_Enable(void);
//ADC conversion disable
void Adc_Disable(void);
//ADC normal mode configuration
en_result_t Adc_ConfigNormMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_norm_cfg_t* pstcAdcNormCfg);
//ADC continuous mode configuration
en_result_t Adc_ConfigContMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_cont_cfg_t* pstcAdcContCfg);
//ADC scan mode configuration
en_result_t Adc_ConfigScanMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_scan_cfg_t* pstcAdcScanCfg);
//ADC enable IRQ
void Adc_EnableIrq(void);
//ADC disable IRQ
void Adc_DisableIrq(void);
//ADC enable compare
void Adc_CmpCfg(stc_adc_irq_t* pstcAdcIrqCfg);
//ADC get IRQ state
void Adc_GetIrqState(stc_adc_irq_t* pstcAdcIrqState);
//ADC clear IRQ states
void Adc_ClrContIrqState(void);
void Adc_ClrRegIrqState(void);
void Adc_ClrHhtIrqState(void);
void Adc_ClrIrqLltState(void);
//查询ADC转换状态
boolean_t Adc_PollBusyState(void);
//获取采样值
en_result_t Adc_GetResult(uint16_t* pu16AdcResult);
//获取累加采样值
en_result_t Adc_GetAccResult(uint32_t* pu32AdcAccResult);
//clear ADC accumulated result
void Adc_ClrAccResult(void);
//get ADC scan channel result
en_result_t Adc_GetScanResult(uint8_t u8Channel, uint16_t* pu16AdcResult);
//获取通道8采样值
en_result_t Adc_GetCH8Result(uint16_t* pu16AdcResult);
en_result_t Adc_SetVref(en_adc_ref_vol_sel_t enAdcRefVolSel);
//@}
#ifdef __cplusplus
}
#endif
#endif /* __ADC_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+859
View File
@@ -0,0 +1,859 @@
/*******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file adt.h
**
** Headerfile for Advance Timer functions
** @link ADT Group Some description @endlink
**
** - 2018-04-19 Husj First Version
**
******************************************************************************/
#ifndef __ADT_H__
#define __ADT_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup AdtGroup Advance Timer (ADT)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief ADT CHx通道定义
*****************************************************************************/
typedef enum en_adt_CHxX_port
{
AdtCHxA = 0u, ///< CHx A通道
AdtCHxB = 1u, ///< CHx B通道
}en_adt_CHxX_port_t;
/**
******************************************************************************
** \brief ADT TRIG端口定义
*****************************************************************************/
typedef enum en_adt_trig_port
{
AdtTrigA = 0u, ///< TIMx 触发A端口
AdtTrigB = 1u, ///< TIMx 触发B端口
AdtTrigC = 2u, ///< TIMx 触发C端口
AdtTrigD = 3u, ///< TIMx 触发D端口
}en_adt_trig_port_t;
/**
******************************************************************************
** \brief ADT通用控制 - Z相输入屏蔽周期数
**
** \note
******************************************************************************/
typedef enum en_adt_gconr_zmsk
{
AdtZMaskDis = 0u, ///< Z相输入屏蔽功能无效
AdtZMask4Cyl = 1u, ///< 位置计数上溢后或下溢后的4个计数周期内的Z相输入被屏蔽
AdtZMask8Cyl = 2u, ///< 位置计数上溢后或下溢后的8个计数周期内的Z相输入被屏蔽
AdtZMask16Cyl = 3u, ///< 位置计数上溢后或下溢后的16个计数周期内的Z相输入被屏蔽
}en_adt_gconr_zmsk_t;
/**
******************************************************************************
** \brief ADT通用控制 - 计数时钟选择
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_ckdiv
{
AdtClkPClk0 = 0u, ///< PCLK0
AdtClkPClk0Div2 = 1u, ///< PCLK0/2
AdtClkPClk0Div4 = 2u, ///< PCLK0/4
AdtClkPClk0Div8 = 3u, ///< PCLK0/8
AdtClkPClk0Div16 = 4u, ///< PCLK0/16
AdtClkPClk0Div64 = 5u, ///< PCLK0/64
AdtClkPClk0Div256 = 6u, ///< PCLK0/256
AdtClkPClk0Div1024 = 7u, ///< PCLK0/1024
}en_adt_cnt_ckdiv_t;
/**
******************************************************************************
** \brief ADT计数模式
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_mode
{
AdtSawtoothMode = 0u, ///< 锯齿波模式
AdtTriangleModeA = 4u, ///< 三角波A模式
AdtTriangleModeB = 5u, ///< 三角波B模式
}en_adt_cnt_mode_t;
/**
******************************************************************************
** \brief ADT计数方向
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_dir
{
AdtCntDown = 0u, ///< 递减计数
AdtCntUp = 1u, ///< 递加计数
}en_adt_cnt_dir_t;
/**
******************************************************************************
** \brief ADT通用比较基准
**
** \note
******************************************************************************/
typedef enum en_adt_compare
{
AdtCompareA = 0u, ///< 通用比较基准A
AdtCompareB = 1u, ///< 通用比较基准B
AdtCompareC = 2u, ///< 通用比较基准C
AdtCompareD = 3u, ///< 通用比较基准D
}en_adt_compare_t;
/**
******************************************************************************
** \brief ADT专用比较基准
**
** \note
******************************************************************************/
typedef enum en_adt_special_compare
{
AdtSpclCompA = 0u, ///< 专用比较基准A
AdtSpclCompB = 1u, ///< 专用比较基准B
}en_adt_special_compare_t;
/**
******************************************************************************
** \brief ADT端口控制 - TIMx输出状态控制
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_disval
{
AdtTIMxDisValNorm = 0u, ///< 强制输出无效条件0~3中被选择的条件成立时,CHx端口正常输出
AdtTIMxDisValHiZ = 1u, ///< 强制输出无效条件0~3中被选择的条件成立时,CHx端口输出高阻态
AdtTIMxDisValLow = 2u, ///< 强制输出无效条件0~3中被选择的条件成立时,CHx端口输出低电平
AdtTIMxDisValHigh = 3u, ///< 强制输出无效条件0~3中被选择的条件成立时,CHx端口输出高电平
}en_adt_pconr_disval_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx强制输出无效条件选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_dissel
{
AdtCHxDisSel0 = 0u, ///< 选择强制输出无效条件0
AdtCHxDisSel1 = 1u, ///< 选择强制输出无效条件1
AdtCHxDisSel2 = 2u, ///< 选择强制输出无效条件2
AdtCHxDisSel3 = 3u, ///< 选择强制输出无效条件3
}en_adt_pconr_dissel_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx周期值匹配时端口状态设定
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_perc
{
AdtCHxPeriodLow = 0u, ///< 计数器计数值与周期值相等时,CHx端口输出保持为低电平
AdtCHxPeriodHigh = 1u, ///< 计数器计数值与周期值相等时,CHx端口输出设定为高电平
AdtCHxPeriodKeep = 2u, ///< 计数器计数值与周期值相等时,CHx端口输出设定为先前状态
AdtCHxPeriodInv = 3u, ///< 计数器计数值与周期值相等时,CHx端口输出设定为反转电平
}en_adt_pconr_perc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx比较值匹配时端口状态设定
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_cmpc
{
AdtCHxCompareLow = 0u, ///< 计数器计数值与GCMxR相等时,CHx端口输出保持为低电平
AdtCHxCompareHigh = 1u, ///< 计数器计数值与GCMxR相等时,CHx端口输出设定为高电平
AdtCHxCompareKeep = 2u, ///< 计数器计数值与GCMxR相等时,CHx端口输出设定为先前状态
AdtCHxCompareInv = 3u, ///< 计数器计数值与GCMxR相等时,CHx端口输出设定为反转电平
}en_adt_pconr_cmpc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx端口输出
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_port_out
{
AdtCHxPortOutLow = 0u, ///< CHx端口输出设定为低电平
AdtCHxPortOutHigh = 1u, ///< CHx端口输出设定为高电平
}en_adt_pconr_port_out_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx端口功能模式选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_capc
{
AdtCHxCompareOutput = 0u, ///< CHx端口设定为比较输出功能
AdtCHxCompareInput = 1u, ///< CHx端口设定为捕获输入功能
}en_adt_pconr_capc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx计数开始停止端口状态选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_stastps
{
AdtCHxStateSelSS = 0u, ///< 计数开始或停止时,CHx端口输出由STACB、STPCB决定
AdtCHxStateSelKeep = 1u, ///< 计数开始或停止时,CHx端口输出设定为先前状态
}en_adt_pconr_stastps_t;
/**
******************************************************************************
** \brief ADT死区控制 - CHx死区分离设定
**
** \note
******************************************************************************/
typedef enum en_adt_dconr_sepa
{
AdtCHxDtSeperate = 0u, ///< DTUAR和DTDAR分别设定
AdtCHxDtEqual = 1u, ///< DTDAR的值和DTUAR的值自动相等
}en_adt_dconr_sepa_t;
/**
******************************************************************************
** \brief ADT滤波控制 - TRIx/TIMxIx端口滤波采样基准时钟选择
**
** \note
******************************************************************************/
typedef enum en_adt_fconr_nofick
{
AdtFltClkPclk0 = 0u, ///< PCLK0
AdtFltClkPclk0Div4 = 1u, ///< PCLK0/4
AdtFltClkPclk0Div16 = 2u, ///< PCLK0/16
AdtFltClkPclk0Div64 = 3u, ///< PCLK0/64
}en_adt_fconr_nofick_t;
/**
******************************************************************************
** \brief ADT有效周期 - TIMx有效周期选择
**
** \note
******************************************************************************/
typedef enum en_adt_vperr_pcnts
{
AdtPeriodCnts0 = 0u, ///< 有效周期选择功能无效
AdtPeriodCnts1 = 1u, ///< 每隔1个周期有效一次
AdtPeriodCnts2 = 2u, ///< 每隔2个周期有效一次
AdtPeriodCnts3 = 3u, ///< 每隔3个周期有效一次
AdtPeriodCnts4 = 4u, ///< 每隔4个周期有效一次
AdtPeriodCnts5 = 5u, ///< 每隔5个周期有效一次
AdtPeriodCnts6 = 6u, ///< 每隔6个周期有效一次
AdtPeriodCnts7 = 7u, ///< 每隔7个周期有效一次
}en_adt_vperr_pcnts_t;
/**
******************************************************************************
** \brief ADT有效周期 - 计数条件选择
**
** \note
******************************************************************************/
typedef enum en_adt_vperr_pcnte
{
AdtPeriodCnteDisable = 0u, ///< 有效周期选择功能无效
AdtPeriodCnteMin = 1u, ///< 锯齿波计数上、下溢点或三角波波谷做为计数条件
AdtPeriodCnteMax = 2u, ///< 锯齿波计数上、下溢点或三角波波峰做为计数条件
AdtPeriodCnteBoth = 3u, ///< 锯齿波计数上、下溢点或三角波波峰,波谷做为计数条件
}en_adt_vperr_pcnte_t;
/**
******************************************************************************
** \brief ADT端口触发控制 - 触发源选择
**
** \note
******************************************************************************/
typedef enum en_adt_ttrig_trigxs
{
AdtTrigxSelP01 = 0u, ///< P01
AdtTrigxSelP02 = 1u, ///< P02
AdtTrigxSelP03 = 2u, ///< P03
AdtTrigxSelP14 = 3u, ///< P14
AdtTrigxSelP15 = 4u, ///< P15
AdtTrigxSelP23 = 5u, ///< P23
AdtTrigxSelP24 = 6u, ///< P24
AdtTrigxSelP25 = 7u, ///< P25
AdtTrigxSelP26 = 8u, ///< P26
AdtTrigxSelP27 = 9u, ///< P27
AdtTrigxSelP31 = 10u, ///< P31
AdtTrigxSelP32 = 11u, ///< P32
AdtTrigxSelP33 = 12u, ///< P33
AdtTrigxSelP34 = 13u, ///< P34
AdtTrigxSelP35 = 14u, ///< P35
AdtTrigxSelP36 = 15u, ///< P36
}en_adt_ttrig_trigxs_t;
/**
******************************************************************************
** \brief ADT AOS触发控制 - AOSx触发源选择
**
** \note
******************************************************************************/
typedef enum en_adt_itrig_iaosxs
{
AdtAosxTrigSelTim0Int = 0u, ///< TIM0_INT
AdtAosxTrigSelTim1Int = 1u, ///< TIM1_INT
AdtAosxTrigSelTim2Int = 2u, ///< TIM2_INT
AdtAosxTrigSelLpTimInt = 3u, ///< LPTIMER_INT
AdtAosxTrigSelTim4Int = 4u, ///< TIM4_INT
AdtAosxTrigSelTim5Int = 5u, ///< TIM5_INT
AdtAosxTrigSelTim6Int = 6u, ///< TIM6_INT
AdtAosxTrigSelUart0Int = 7u, ///< UART0_INT
AdtAosxTrigSelUart1Int = 8u, ///< UART1_INT
AdtAosxTrigSelLpUartInt = 9u, ///< LPUART_INT
AdtAosxTrigSelVc0Int = 10u, ///< VC0_INT
AdtAosxTrigSelVc1Int = 11u, ///< VC1_INT
AdtAosxTrigSelRtcInt = 12u, ///< RTC_INT
AdtAosxTrigSelPcaInt = 13u, ///< PCA_INT
AdtAosxTrigSelSpiInt = 14u, ///< SPI_INT
AdtAosxTrigSelAdcInt = 15u, ///< ADC_INT
}en_adt_itrig_iaosxs_t;
/**
******************************************************************************
** \brief ADT硬件(启动/停止/清零/捕获)事件触发选择
**
** \note
******************************************************************************/
typedef enum en_adt_hw_trig
{
AdtHwTrigAos0 = 0u, ///< 从AOS来的事件触发0有效
AdtHwTrigAos1 = 1u, ///< 从AOS来的事件触发1有效
AdtHwTrigAos2 = 2u, ///< 从AOS来的事件触发2有效
AdtHwTrigAos3 = 3u, ///< 从AOS来的事件触发3有效
AdtHwTrigCHxARise = 4u, ///< CHxA端口上采样到上升沿
AdtHwTrigCHxAFall = 5u, ///< CHxA端口上采样到下降沿
AdtHwTrigCHxBRise = 6u, ///< CHxB端口上采样到上升沿
AdtHwTrigCHxBFall = 7u, ///< CHxB端口上采样到下降沿
AdtHwTrigTimTriARise = 8u, ///< TIMTRIA端口上采样到上升沿
AdtHwTrigTimTriAFall = 9u, ///< TIMTRIA端口上采样到下降沿
AdtHwTrigTimTriBRise = 10u, ///< TIMTRIB端口上采样到上升沿
AdtHwTrigTimTriBFall = 11u, ///< TIMTRIB端口上采样到下降沿
AdtHwTrigTimTriCRise = 12u, ///< TIMTRIC端口上采样到上升沿
AdtHwTrigTimTriCFall = 13u, ///< TIMTRIC端口上采样到下降沿
AdtHwTrigTimTriDRise = 14u, ///< TIMTRID端口上采样到上升沿
AdtHwTrigTimTriDFall = 15u, ///< TIMTRID端口上采样到下降沿
AdtHwTrigEnd = 16u,
}en_adt_hw_trig_t;
/**
******************************************************************************
** \brief ADT硬件(递加/递减)事件触发选择
**
** \note
******************************************************************************/
typedef enum en_adt_hw_cnt
{
AdtHwCntCHxALowCHxBRise = 0u, ///< CHxA端口为低电平时,CHxB端口上采样到上升沿
AdtHwCntCHxALowCHxBFall = 1u, ///< CHxA端口为低电平时,CHxB端口上采样到下降沿
AdtHwCntCHxAHighCHxBRise = 2u, ///< CHxA端口为高电平时,CHxB端口上采样到上升沿
AdtHwCntCHxAHighCHxBFall = 3u, ///< CHxA端口为高电平时,CHxB端口上采样到下降沿
AdtHwCntCHxBLowCHxARise = 4u, ///< CHxB端口为低电平时,CHxA端口上采样到上升沿
AdtHwCntCHxBLowCHxAFall = 5u, ///< CHxB端口为低电平时,CHxA端口上采样到下降沿
AdtHwCntCHxBHighChxARise = 6u, ///< CHxB端口为高电平时,CHxA端口上采样到上升沿
AdtHwCntCHxBHighCHxAFall = 7u, ///< CHxB端口为高电平时,CHxA端口上采样到下降沿
AdtHwCntTimTriARise = 8u, ///< TIMTRIA端口上采样到上升沿
AdtHwCntTimTriAFall = 9u, ///< TIMTRIA端口上采样到下降沿
AdtHwCntTimTriBRise = 10u, ///< TIMTRIB端口上采样到上升沿
AdtHwCntTimTriBFall = 11u, ///< TIMTRIB端口上采样到下降沿
AdtHwCntTimTriCRise = 12u, ///< TIMTRIC端口上采样到上升沿
AdtHwCntTimTriCFall = 13u, ///< TIMTRIC端口上采样到下降沿
AdtHwCntTimTriDRise = 14u, ///< TIMTRID端口上采样到上升沿
AdtHwCntTimTriDFall = 15u, ///< TIMTRID端口上采样到下降沿
AdtHwCntAos0 = 16u, ///< 从AOS来的事件触发0有效
AdtHwCntAos1 = 17u, ///< 从AOS来的事件触发1有效
AdtHwCntAos2 = 18u, ///< 从AOS来的事件触发2有效
AdtHwCntAos3 = 19u, ///< 从AOS来的事件触发3有效
AdtHwCntMax = 20u,
}en_adt_hw_cnt_t;
/**
******************************************************************************
** \brief ADT端口刹车极性控制
**
** \note
******************************************************************************/
typedef enum en_adt_ptbrk_polarity
{
AdtPtBrkHigh = 0u, ///< 端口刹车极性高电平有效
AdtPtBrkLow = 1u, ///< 端口刹车极性低电平有效
}en_adt_ptbrk_polarity_t;
/**
******************************************************************************
** \brief ADT PWM展频计数选择
**
** \note
******************************************************************************/
typedef enum en_adt_pwm_dither_type
{
AdtPwmDitherUnderFlow = 0u, ///< PWM展频计数下溢出
AdtPwmDitherOverFlow = 1u, ///< PWM展频计数上溢出
}en_adt_pwm_dither_type_t;
/**
******************************************************************************
** \brief ADT中断类型
**
** \note
******************************************************************************/
typedef enum en_adt_irq_type
{
AdtCMAIrq = 0u, ///< 计数匹配A(或捕获输入)中断
AdtCMBIrq = 1u, ///< 计数匹配B(或捕获输入)中断
AdtCMCIrq = 2u, ///< 计数匹配C中断
AdtCMDIrq = 3u, ///< 计数匹配D中断
AdtOVFIrq = 6u, ///< 上溢匹配中断
AdtUDFIrq = 7u, ///< 下溢匹配中断
AdtDTEIrq = 8u, ///< 死区时间错误中断
}en_adt_irq_type_t;
typedef enum en_adt_state_type
{
AdtCMAF = 0, ///< 计数匹配A标志
AdtCMBF = 1, ///< 计数匹配B标志
AdtCMCF = 2, ///< 计数匹配C标志
AdtCMDF = 3, ///< 计数匹配D标志
AdtOVFF = 6, ///< 上溢匹配标志
AdtUDFF = 7, ///< 下溢匹配标志
AdtDTEF = 8, ///< 死区时间错误标志
AdtCntDir = 31, ///< 计数方向
}en_adt_state_type_t;
/**
******************************************************************************
** \brief ADT软件同步配置
** \note
******************************************************************************/
typedef struct stc_adt_sw_sync
{
boolean_t bAdTim4; ///< Timer 4
boolean_t bAdTim5; ///< Timer 5
boolean_t bAdTim6; ///< Timer 6
}stc_adt_sw_sync_t;
/**
******************************************************************************
** \brief ADT AOS触发配置
** \note
******************************************************************************/
typedef struct stc_adt_aos_trig_cfg
{
en_adt_itrig_iaosxs_t enAos0TrigSrc; ///< AOS0触发源选择
en_adt_itrig_iaosxs_t enAos1TrigSrc; ///< AOS1触发源选择
en_adt_itrig_iaosxs_t enAos2TrigSrc; ///< AOS2触发源选择
en_adt_itrig_iaosxs_t enAos3TrigSrc; ///< AOS3触发源选择
}stc_adt_aos_trig_cfg_t;
/**
******************************************************************************
** \brief ADT 中断触发配置
** \note
******************************************************************************/
typedef struct stc_adt_irq_trig_cfg
{
boolean_t bAdtUnderFlowTrigEn; ///< 下溢匹配使能触发ADC
boolean_t bAdtOverFlowTrigEn; ///< 上溢匹配使能触发ADC
boolean_t bAdtCntMatchDTrigEn; ///< 计数匹配D使能触发ADC
boolean_t bAdtCntMatchCTrigEn; ///< 计数匹配C使能触发ADC
boolean_t bAdtCntMatchBTrigEn; ///< 计数匹配B使能触发ADC
boolean_t bAdtCntMatchATrigEn; ///< 计数匹配A使能触发ADC
}stc_adt_irq_trig_cfg_t;
/**
******************************************************************************
** \brief ADT Trig端口配置
** \note
******************************************************************************/
typedef struct stc_adt_port_trig_cfg
{
en_adt_ttrig_trigxs_t enTrigSrc; ///< 触发源选择
boolean_t bFltEn; ///< 触发源捕获输入滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 滤波采样基准时钟
}stc_adt_port_trig_cfg_t;
/**
******************************************************************************
** \brief ADT Z相输入屏蔽功能配置
** \note
******************************************************************************/
typedef struct stc_adt_zmask_cfg
{
en_adt_gconr_zmsk_t enZMaskCycle; ///< Z相输入屏蔽计数周期选择
boolean_t bFltPosCntMaksEn; ///< Z相输入时的屏蔽周期内,位置计数器的清零功能不屏蔽(FALSE)或屏蔽(TRUE)
boolean_t bFltRevCntMaksEn; ///< Z相输入时的屏蔽周期内,公转计数器的计数功能不屏蔽(FALSE)或屏蔽(TRUE)
}stc_adt_zmask_cfg_t;
/**
******************************************************************************
** \brief ADT TIMxX端口配置
** \note
******************************************************************************/
typedef struct stc_adt_TIMxX_port_cfg
{
en_adt_pconr_capc_t enCap; ///< 端口功能模式
boolean_t bOutEn; ///< 输出使能
en_adt_pconr_perc_t enPerc; ///< 周期值匹配时端口状态
en_adt_pconr_cmpc_t enCmpc; ///< 比较值匹配时端口状态
en_adt_pconr_stastps_t enStaStp; ///< 计数开始停止端口状态选择
en_adt_pconr_port_out_t enStaOut; ///< 计数开始端口输出状态
en_adt_pconr_port_out_t enStpOut; ///< 计数停止端口输出状态
en_adt_pconr_disval_t enDisVal; ///< 强制输出无效时输出状态控制
en_adt_pconr_dissel_t enDisSel; ///< 强制输出无效条件选择
boolean_t bFltEn; ///< 端口捕获输入滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 端口滤波采样基准时钟
}stc_adt_CHxX_port_cfg_t;
/**
******************************************************************************
** \brief ADT刹车端口配置
** \note
******************************************************************************/
typedef struct stc_adt_break_port_cfg
{
boolean_t bPortEn; ///< 端口使能
en_adt_ptbrk_polarity_t enPol; ///< 极性选择
}stc_adt_break_port_cfg_t;
/**
******************************************************************************
** \brief ADT无效条件3配置
** \note
******************************************************************************/
typedef struct stc_adt_disable_3_cfg
{
stc_adt_break_port_cfg_t stcBrkPtCfg[16]; ///< 刹车端口配置
boolean_t bFltEn; ///< 刹车端口滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 滤波采样基准时钟
}stc_adt_disable_3_cfg_t;
/**
******************************************************************************
** \brief ADT无效条件1配置
** \note
******************************************************************************/
typedef struct stc_adt_disable_1_cfg
{
boolean_t bTim6OutSH; ///< TIM6输出同高
boolean_t bTim5OutSH; ///< TIM5输出同高
boolean_t bTim4OutSH; ///< TIM4输出同高
boolean_t bTim6OutSL; ///< TIM6输出同低
boolean_t bTim5OutSL; ///< TIM5输出同低
boolean_t bTim4OutSL; ///< TIM4输出同低
}stc_adt_disable_1_cfg_t;
/**
******************************************************************************
** \brief ADT PWM展频计数配置
** \note
******************************************************************************/
typedef struct stc_adt_pwm_dither_cfg
{
en_adt_pwm_dither_type_t enAdtPDType; ///< PWM展频计数选择
boolean_t bTimxBPDEn; ///< PWM通道B展频使能
boolean_t bTimxAPDEn; ///< PWM通道A展频使能
}stc_adt_pwm_dither_cfg_t;
/**
******************************************************************************
** \brief ADT基本计数配置
** \note
******************************************************************************/
typedef struct stc_adt_basecnt_cfg
{
en_adt_cnt_mode_t enCntMode; ///< 计数模式
en_adt_cnt_dir_t enCntDir; ///< 计数方向
en_adt_cnt_ckdiv_t enCntClkDiv; ///< 计数时钟选择
}stc_adt_basecnt_cfg_t;
/**
******************************************************************************
** \brief ADT计数状态
** \note
******************************************************************************/
typedef struct stc_adt_cntstate_cfg
{
uint16_t u16Counter; ///< 当前计数器的计数值
boolean_t enCntDir; ///< 计数方向
uint8_t u8ValidPeriod; ///< 有效周期计数
boolean_t bDTEF; ///< 死区时间错误标志
boolean_t bUDFF; ///< 下溢匹配标志
boolean_t bOVFF; ///< 上溢匹配标志
boolean_t bCMDF; ///< 计数匹配D标志
boolean_t bCMCF; ///< 计数匹配C标志
boolean_t bCMBF; ///< 计数匹配B标志
boolean_t bCMAF; ///< 计数匹配A标志
}stc_adt_cntstate_cfg_t;
/**
******************************************************************************
** \brief ADT有效计数周期
** \note
******************************************************************************/
typedef struct stc_adt_validper_cfg
{
en_adt_vperr_pcnts_t enValidCnt; ///< 有效周期选择
en_adt_vperr_pcnte_t enValidCdt; ///< 有效周期计数条件
boolean_t bPeriodD; ///< 通用信号有效周期选择D
boolean_t bPeriodC; ///< 通用信号有效周期选择C
boolean_t bPeriodB; ///< 通用信号有效周期选择B
boolean_t bPeriodA; ///< 通用信号有效周期选择A
}stc_adt_validper_cfg_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//配置硬件递加事件
en_result_t Adt_CfgHwCntUp(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_cnt_t enAdtHwCntUp);
//清除硬件递加事件
en_result_t Adt_ClearHwCntUp(M0P_ADTIM_TypeDef *ADTx);
//配置硬件递减事件
en_result_t Adt_CfgHwCntDwn(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_cnt_t enAdtHwCntDwn);
//清除硬件递减事件
en_result_t Adt_ClearHwCntDwn(M0P_ADTIM_TypeDef *ADTx);
//配置硬件启动事件
en_result_t Adt_CfgHwStart(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_trig_t enAdtHwStart);
//清除硬件启动事件
en_result_t Adt_ClearHwStart(M0P_ADTIM_TypeDef *ADTx);
//使能硬件启动事件
en_result_t Adt_EnableHwStart(M0P_ADTIM_TypeDef *ADTx);
//禁止硬件启动事件
en_result_t Adt_DisableHwStart(M0P_ADTIM_TypeDef *ADTx);
//配置硬件停止事件
en_result_t Adt_CfgHwStop(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_trig_t enAdtHwStop);
//清除硬件停止事件
en_result_t Adt_ClearHwStop(M0P_ADTIM_TypeDef *ADTx);
//使能硬件停止事件
en_result_t Adt_EnableHwStop(M0P_ADTIM_TypeDef *ADTx);
//禁止硬件停止事件
en_result_t Adt_DisableHwStop(M0P_ADTIM_TypeDef *ADTx);
//配置硬件清零事件
en_result_t Adt_CfgHwClear(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_trig_t enAdtHwClear);
//清除硬件清零事件
en_result_t Adt_ClearHwClear(M0P_ADTIM_TypeDef *ADTx);
//使能硬件清零事件
en_result_t Adt_EnableHwClear(M0P_ADTIM_TypeDef *ADTx);
//禁止硬件清零事件
en_result_t Adt_DisableHwClear(M0P_ADTIM_TypeDef *ADTx);
//配置A通道硬件捕获事件
en_result_t Adt_CfgHwCaptureA(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_trig_t enAdtHwCaptureA);
//清除A通道硬件捕获事件
en_result_t Adt_ClearHwCaptureA(M0P_ADTIM_TypeDef *ADTx);
//配置B通道硬件捕获事件
en_result_t Adt_CfgHwCaptureB(M0P_ADTIM_TypeDef *ADTx, en_adt_hw_trig_t enAdtHwCaptureB);
//清除B通道硬件捕获事件
en_result_t Adt_ClearHwCaptureB(M0P_ADTIM_TypeDef *ADTx);
//软件同步启动
en_result_t Adt_SwSyncStart(stc_adt_sw_sync_t* pstcAdtSwSyncStart);
//软件同步停止
en_result_t Adt_SwSyncStop(stc_adt_sw_sync_t* pstcAdtSwSyncStop);
//软件同步清零
en_result_t Adt_SwSyncClear(stc_adt_sw_sync_t* pstcAdtSwSyncClear);
//获取软件同步状态
en_result_t Adt_GetSwSyncState(stc_adt_sw_sync_t* pstcAdtSwSyncState);
//AOS触发配置
en_result_t Adt_AosTrigCfg(stc_adt_aos_trig_cfg_t* pstcAdtAosTrigCfg);
//中断触发配置
en_result_t Adt_IrqTrigCfg(M0P_ADTIM_TypeDef *ADTx,
stc_adt_irq_trig_cfg_t* pstcAdtIrqTrigCfg);
//端口触发配置
en_result_t Adt_PortTrigCfg(en_adt_trig_port_t enAdtTrigPort,
stc_adt_port_trig_cfg_t* pstcAdtPortTrigCfg);
//CHxX端口配置
en_result_t Adt_CHxXPortCfg(M0P_ADTIM_TypeDef *ADTx,
en_adt_CHxX_port_t enAdtCHxXPort,
stc_adt_CHxX_port_cfg_t* pstcAdtCHxXCfg);
//使能端口刹车
en_result_t Adt_EnableBrakePort(uint8_t port, stc_adt_break_port_cfg_t* pstcAdtBrkPtCfg);
//清除端口刹车
void Adt_ClearBrakePort(void);
//无效条件3配置(端口刹车)
en_result_t Adt_Disable3Cfg(stc_adt_disable_3_cfg_t* pstcAdtDisable3);
//软件刹车 Enable/Disable(仅适用于无效条件3使能的情况下)
en_result_t Adt_SwBrake(boolean_t bSwBrk);
//获取端口刹车标志
boolean_t Adt_GetPortBrakeFlag(void);
//清除端口刹车标志
void Adt_ClearPortBrakeFlag(void);
//无效条件1配置(同高同低刹车)
en_result_t Adt_Disable1Cfg(stc_adt_disable_1_cfg_t* pstcAdtDisable1);
//获取同高同低刹车标志
boolean_t Adt_GetSameBrakeFlag(void);
//清除同高同低刹车标志
void Adt_ClearSameBrakeFlag(void);
//PWM展频配置
en_result_t Adt_PwmDitherCfg(M0P_ADTIM_TypeDef *ADTx, stc_adt_pwm_dither_cfg_t* pstcAdtPwmDitherCfg);
//AdvTimer初始化
en_result_t Adt_Init(M0P_ADTIM_TypeDef *ADTx, stc_adt_basecnt_cfg_t* pstcAdtBaseCntCfg);
//AdvTimer去初始化
en_result_t Adt_DeInit(M0P_ADTIM_TypeDef *ADTx);
//AdvTimert启动
en_result_t Adt_StartCount(M0P_ADTIM_TypeDef *ADTx);
//AdvTimert停止
en_result_t Adt_StopCount(M0P_ADTIM_TypeDef *ADTx);
//设置计数值
en_result_t Adt_SetCount(M0P_ADTIM_TypeDef *ADTx, uint16_t u16Value);
//获取计数值
uint16_t Adt_GetCount(M0P_ADTIM_TypeDef *ADTx);
//清除计数值
en_result_t Adt_ClearCount(M0P_ADTIM_TypeDef *ADTx);
//获取有效周期计数值
uint8_t Adt_GetVperNum(M0P_ADTIM_TypeDef *ADTx);
//获取状态标志
boolean_t Adt_GetState(M0P_ADTIM_TypeDef *ADTx, en_adt_state_type_t enstate);
//配置计数周期
en_result_t Adt_SetPeriod(M0P_ADTIM_TypeDef *ADTx, uint16_t u16Period);
//配置计数周期缓冲
en_result_t Adt_SetPeriodBuf(M0P_ADTIM_TypeDef *ADTx, uint16_t u16PeriodBuf);
//清除计数周期缓冲
en_result_t Adt_ClearPeriodBuf(M0P_ADTIM_TypeDef *ADTx);
//配置有效计数周期
en_result_t Adt_SetValidPeriod(M0P_ADTIM_TypeDef *ADTx,
stc_adt_validper_cfg_t* pstcAdtValidPerCfg);
//配置比较输出计数基准值
en_result_t Adt_SetCompareValue(M0P_ADTIM_TypeDef *ADTx,
en_adt_compare_t enAdtCompare,
uint16_t u16Compare);
//配置通用比较值/捕获值的缓存传送
en_result_t Adt_EnableValueBuf(M0P_ADTIM_TypeDef *ADTx,
en_adt_CHxX_port_t enAdtCHxXPort,
boolean_t bCompareBufEn);
//清除比较输出计数值/捕获值缓存
en_result_t Adt_ClearValueBuf(M0P_ADTIM_TypeDef *ADTx,
en_adt_CHxX_port_t enAdtCHxXPort);
//获取捕获值
en_result_t Adt_GetCaptureValue(M0P_ADTIM_TypeDef *ADTx,
en_adt_CHxX_port_t enAdtCHxXPort,
uint16_t* pu16Capture);
//获取捕获缓存值
en_result_t Adt_GetCaptureBuf(M0P_ADTIM_TypeDef *ADTx,
en_adt_CHxX_port_t enAdtCHxXPort,
uint16_t* pu16CaptureBuf);
//设置死区时间上基准值
en_result_t Adt_SetDTUA(M0P_ADTIM_TypeDef *ADTx,
uint16_t u16Value);
//设置死区时间下基准值
en_result_t Adt_SetDTDA(M0P_ADTIM_TypeDef *ADTx,
uint16_t u16Value);
//配置死区时间功能
en_result_t Adt_CfgDT(M0P_ADTIM_TypeDef *ADTx,
boolean_t bDTEn,
boolean_t bEqual);
//配置中断
en_result_t Adt_CfgIrq(M0P_ADTIM_TypeDef *ADTx,
en_adt_irq_type_t enAdtIrq,
boolean_t bEn);
//获取中断标志
boolean_t Adt_GetIrqFlag(M0P_ADTIM_TypeDef *ADTx,
en_adt_irq_type_t enAdtIrq);
//清除中断标志
en_result_t Adt_ClearIrqFlag(M0P_ADTIM_TypeDef *ADTx,
en_adt_irq_type_t enAdtIrq);
//清除所有中断标志
en_result_t Adt_ClearAllIrqFlag(M0P_ADTIM_TypeDef *ADTx);
//Z相输入屏蔽设置
en_result_t Adt_CfgZMask(M0P_ADTIM_TypeDef *ADTx,
stc_adt_zmask_cfg_t* pstcAdtZMaskCfg);
//@} // ADT Group
#ifdef __cplusplus
}
#endif
#endif /* __ADT_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+109
View File
@@ -0,0 +1,109 @@
/******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file bgr.h
**
** BGR 数据结构及API声明.
**
** - 2018-04-21 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup BGR
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///<内部温度传感器使能/关闭
void Bgr_TempSensorEnable(void);
void Bgr_TempSensorDisable(void);
///<BGR使能/关闭
void Bgr_BgrEnable(void);
void Bgr_BgrDisable(void);
//@} // BGR Group
#ifdef __cplusplus
}
#endif
#endif /* __BGR_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+227
View File
@@ -0,0 +1,227 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file bt.h
**
** 基本定时器数据结构及API声明
** @link BT Group Some description @endlink
**
** History:
** - 2017-05-10 Lux V1.0
**
*****************************************************************************/
#ifndef __BT_H__
#define __BT_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup BtGroup Base Timer (BT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief 定时器选择数据类型重定义
*****************************************************************************/
typedef enum en_bt_unit
{
TIM0 = 0u, ///< Timer 0
TIM1 = 1u, ///< Timer 1
TIM2 = 2u, ///< Timer 2
}en_bt_unit_t;
/**
******************************************************************************
** \brief 极性控制数据类型重定义 (GATE_P)
*****************************************************************************/
typedef enum en_bt_gatep
{
BtPositive = 0u, ///< 高电平有效
BtOpposite = 1u, ///< 低电平有效
}en_bt_gatep_t;
/**
******************************************************************************
** \brief 定时器门控数据类型重定义 (GATE)
*****************************************************************************/
typedef enum en_bt_gate
{
BtGateDisable = 0u, ///< 无门控
BtGateEnable = 1u, ///< 门控使能
}en_bt_gate_t;
/**
******************************************************************************
** \brief TIM 预除频选择 (PRS)
*****************************************************************************/
typedef enum en_bt_timclkdiv
{
BtPCLKDiv1 = 0u, ///< Div 1
BtPCLKDiv2 = 1u, ///< Div 2
BtPCLKDiv4 = 2u, ///< Div 4
BtPCLKDiv8 = 3u, ///< Div 8
BtPCLKDiv16 = 4u, ///< Div 16
BtPCLKDiv32 = 5u, ///< Div 32
BtPCLKDiv64 = 6u, ///< Div 64
BtPCLKDiv256 = 7u, ///< Div 256
}en_bt_timclkdiv_t;
/**
******************************************************************************
** \brief 翻转输出使能数据类型重定义 (TOG_EN)
*****************************************************************************/
typedef enum en_bt_toggle
{
BtTogDisable = 0u, ///< 翻转输出禁止
BtTogEnable = 1u, ///< 翻转输出使能
}en_bt_toggle_t;
/**
******************************************************************************
** \brief 计数/定时器功能选择数据类型重定义 (CT)
*****************************************************************************/
typedef enum en_bt_function
{
BtTimer = 0u, ///< 定时器功能
BtCounter = 1u, ///< 计数器功能
}en_bt_function_t;
/**
******************************************************************************
** \brief 定时器工作模式数据类型重定义 (MD)
*****************************************************************************/
typedef enum en_bt_mode
{
BtMode1 = 0u, ///< 32位计数器/定时器
BtMode2 = 1u, ///< 自动重装载16位计数器/定时器
}en_bt_mode_t;
/**
******************************************************************************
** \brief 定时器运行控制数据类型重定义 (TR)
*****************************************************************************/
typedef enum en_bt_start
{
BtTRDisable = 0u, ///< 停止
BtTREnable = 1u, ///< 运行
}en_bt_start_t;
/**
******************************************************************************
** \brief Timer 配置结构体定义
*****************************************************************************/
typedef struct stc_bt_config
{
en_bt_gatep_t enGateP; ///< 门控极性控制
en_bt_gate_t enGate; ///< 门控使能
en_bt_timclkdiv_t enPRS; ///< 预除频配置
en_bt_toggle_t enTog; ///< 反转输出使能
en_bt_function_t enCT; ///< 定时/计数功能选择
en_bt_mode_t enMD; ///< 计数模式配置
}stc_bt_cfg_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//中断相关函数
//中断标志获取
boolean_t Bt_GetIntFlag(en_bt_unit_t enUnit);
//中断标志清除
en_result_t Bt_ClearIntFlag(en_bt_unit_t enUnit);
//中断使能/禁止
en_result_t Bt_EnableIrq (en_bt_unit_t enUnit);
en_result_t Bt_DisableIrq(en_bt_unit_t enUnit);
//初始化及相关功能操作
//timer配置及初始化
en_result_t Bt_Init(en_bt_unit_t enUnit, stc_bt_cfg_t* pstcCfg);
//Lptimer 启动/停止
en_result_t Bt_Run(en_bt_unit_t enUnit);
en_result_t Bt_Stop(en_bt_unit_t enUnit);
//重载值设置
en_result_t Bt_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data);
//16位计数值设置/获取
en_result_t Bt_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
uint16_t Bt_Cnt16Get(en_bt_unit_t enUnit);
//32位计数值设置/获取
en_result_t Bt_Cnt32Set(en_bt_unit_t enUnit, uint32_t u32Data);
uint32_t Bt_Cnt32Get(en_bt_unit_t enUnit);
//@} // BtGroup
#ifdef __cplusplus
#endif
#endif /* __BT_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+111
View File
@@ -0,0 +1,111 @@
/******************************************************************************
* Copyright (C) 2016, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file crc.h
**
** CRC 数据结构及API声明.
**
** - 2016-05-04 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup CrcGroup Cyclic Redundancy Check (CRC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//CRC16 编码值获取
uint16_t CRC16_Get8(uint8_t* pu8Data, uint32_t u32Len);
uint16_t CRC16_Get16(uint16_t* pu16Data, uint32_t u32Len);
uint16_t CRC16_Get32(uint32_t* pu32Data, uint32_t u32Len);
//CRC16 校验
en_result_t CRC16_Check8(uint8_t* pu8Data, uint32_t u32Len, uint16_t u16CRC);
en_result_t CRC16_Check16(uint16_t* pu16Data, uint32_t u32Len, uint16_t u16CRC);
en_result_t CRC16_Check32(uint32_t* pu32Data, uint32_t u32Len, uint16_t u16CRC);
//@} // CRC Group
#ifdef __cplusplus
}
#endif
#endif /* __CRC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+165
View File
@@ -0,0 +1,165 @@
/*******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl.h
**
** DDL common define.
** @link SampleGroup Some description @endlink
**
** - 2019-03-03 1.0 Lux First version.
**
******************************************************************************/
#ifndef __DDL_H__
#define __DDL_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "base_types.h"
#include "board_stkhc32f005.h"
#include "hc32f005.h"
#include "system_hc32f005.h"
#include "sysctrl.h"
#include "interrupts_hc32f005.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/* Macro for initializing local structures to zero */
/******************************************************************************/
#define DDL_ZERO_STRUCT(x) ddl_memclr((uint8_t*)&(x), (uint32_t)(sizeof(x)))
#define DEC2BCD(x) ((((x)/10)<<4) + ((x)%10))
#define BCD2DEC(x) ((((x)>>4)*10) + ((x)&0x0F))
/**
******************************************************************************
** Global Device Series List
******************************************************************************/
#define DDL_DEVICE_SERIES_HC32F005 (0u)
/**
******************************************************************************
** Global Device Package List
******************************************************************************/
// package definitions of HC device.
#define DDL_DEVICE_PACKAGE_HC_C (0x00u)
#define DDL_DEVICE_PACKAGE_HC_F (0x10u)
#define DDL_DEVICE_PACKAGE_HC_J (0x20u)
#define DDL_DEVICE_PACKAGE_HC_K (0x30u)
/******************************************************************************/
/* User Device Setting Include file */
/******************************************************************************/
#include "ddl_device.h" // MUST be included here!
/******************************************************************************/
/* Global type definitions ('typedef') */
/******************************************************************************/
/**
******************************************************************************
** \brief Level
**
** Specifies levels.
**
******************************************************************************/
typedef enum en_level
{
DdlLow = 0u, ///< Low level '0'
DdlHigh = 1u ///< High level '1'
} en_level_t;
/**
******************************************************************************
** \brief Generic Flag Code
**
** Specifies flags.
**
******************************************************************************/
typedef enum en_flag
{
DdlClr = 0u, ///< Flag clr '0'
DdlSet = 1u ///< Flag set '1'
} en_stat_flag_t, en_irq_flag_t;
/******************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
/*******************************************************************************
* Global function prototypes
******************************************************************************/
extern void ddl_memclr(void* pu8Address, uint32_t u32Count);
uint32_t Log2(uint32_t u32Val);
/**
*******************************************************************************
** This hook is part of wait loops.
******************************************************************************/
extern void DDL_WAIT_LOOP_HOOK(void);
void Debug_UartInit(void);
void delay1ms(uint32_t u32Cnt);
void delay100us(uint32_t u32Cnt);
void delay10us(uint32_t u32Cnt);
void SetBit(uint32_t addr, uint32_t offset, boolean_t bFlag);
void ClrBit(uint32_t addr, uint32_t offset);
boolean_t GetBit(uint32_t addr, uint32_t offset);
#ifdef __cplusplus
}
#endif
#endif /* __DDL_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+158
View File
@@ -0,0 +1,158 @@
/*************************************************************************************
* Copyright (C) 2016, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file flash.h
**
** FLASH 数据结构及API声明.
**
** - 2017-05-02 LuX V1.0
**
******************************************************************************/
#ifndef __FLASH_H__
#define __FLASH_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup FlashGroup Flash Controller (Flash)
**
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief Flash中断类型重定义
*****************************************************************************/
typedef enum en_flash_int_type
{
FlashPCInt = 0x01u, ///<擦写PC地址报警中断
FlashSlockInt = 0x02u, ///<擦写保护报警中断
} en_flash_int_type_t;
/**
******************************************************************************
** \brief Flash读等待周期类型重定义
*****************************************************************************/
typedef enum en_flash_waitcycle
{
FlashWaitCycle0 = 0u, ///< 读等待周期设置为0(当HCLK小于等于24MHz时)
FlashWaitCycle1 = 1u, ///< 读等待周期设置为1(当HCLK大于24MHz时必须至少为1)
} en_flash_waitcycle_t;
/**
******************************************************************************
** \brief Redefinition of FLASH register structure
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///<Flash 初始化配置(编程时间参数置)
en_result_t Flash_Init(uint8_t u8FreqCfg);
///<Flash 页/全片擦除
en_result_t Flash_SectorErase(uint32_t u32SectorAddr);
en_result_t Flash_ChipErase(void);
///<Flash 字节/半字/字写
en_result_t Flash_WriteByte(uint32_t u32Addr, uint8_t u8Data);
en_result_t Flash_WriteHalfWord(uint32_t u32Addr, uint16_t u16Data);
en_result_t Flash_WriteWord(uint32_t u32Addr, uint32_t u32Data);
///<Flash 编程保护加锁/解锁
void Flash_LockAll(void);
void Flash_UnlockAll(void);
en_result_t Flash_LockSet(uint32_t u32LockValue);
///<Flash 读等待周期设定
en_result_t Flash_WaitCycle(en_flash_waitcycle_t enWaitCycle);
///<中断相关函数
///<中断使能/禁止
en_result_t Flash_EnableIrq(en_flash_int_type_t enFlashIntType);
en_result_t Flash_DisableIrq(en_flash_int_type_t enFlashIntType);
///<中断标志获取
boolean_t Flash_GetIntFlag(en_flash_int_type_t enFlashIntType);
///<中断标志清除
en_result_t Flash_ClearIntFlag(en_flash_int_type_t enFlashIntType);
//@} // FlashGroup
#ifdef __cplusplus
}
#endif
#endif /* __FLASH_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+428
View File
@@ -0,0 +1,428 @@
/*******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file gpio.h
**
** GPIO driver
** @link GPIO Group Some description @endlink
**
** - 2018-04-18
**
******************************************************************************/
#ifndef __GPIO_H__
#define __GPIO_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup GpioGroup General Purpose I/O (GPIO)
**
**
******************************************************************************/
//@{
#define GPIO_GPSZ (0x40u)
/*******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief GPIO PORT类型定义
******************************************************************************/
typedef enum en_gpio_port
{
GpioPort0 = 0x00u, ///< GPIO PORT 0
GpioPort1 = 0x40u, ///< GPIO PORT 1
GpioPort2 = 0x80u, ///< GPIO PORT 2
GpioPort3 = 0xc0u, ///< GPIO PORT 3
}en_gpio_port_t;
/**
*******************************************************************************
** \brief GPIO PIN类型定义
******************************************************************************/
typedef enum en_gpio_pin
{
GpioPin0 = 0u, ///< GPIO PIN0
GpioPin1 = 1u, ///< GPIO PIN1
GpioPin2 = 2u, ///< GPIO PIN2
GpioPin3 = 3u, ///< GPIO PIN3
GpioPin4 = 4u, ///< GPIO PIN4
GpioPin5 = 5u, ///< GPIO PIN5
GpioPin6 = 6u, ///< GPIO PIN6
GpioPin7 = 7u, ///< GPIO PIN7
}en_gpio_pin_t;
/**
*******************************************************************************
** \brief GPIO 端口复用功能(AF-Alternate function)类型定义
** \note 具体功能及含义请参考用户手册GPIO复用表
******************************************************************************/
typedef enum en_gpio_af
{
GpioAf0 = 0u, ///< GPIO功能
GpioAf1 = 1u, ///< GPIO AF1:复用功能1
GpioAf2 = 2u, ///< GPIO AF2:复用功能2
GpioAf3 = 3u, ///< GPIO AF3:复用功能3
GpioAf4 = 4u, ///< GPIO AF4:复用功能4
GpioAf5 = 5u, ///< GPIO AF5:复用功能5
GpioAf6 = 6u, ///< GPIO AF6:复用功能6
GpioAf7 = 7u, ///< GPIO AF7:复用功能7
}en_gpio_af_t;
/**
*******************************************************************************
** \brief GPIO输入输出配置数据类型定义
******************************************************************************/
typedef enum en_gpio_dir
{
GpioDirOut = 0u, ///< GPIO 输出
GpioDirIn = 1u, ///< GPIO 输入
}en_gpio_dir_t;
/**
*******************************************************************************
** \brief GPIO端口上拉配置数据类型定义
******************************************************************************/
typedef enum en_gpio_pu
{
GpioPuDisable = 0u, ///< GPIO无上拉
GpioPuEnable = 1u, ///< GPIO上拉
}en_gpio_pu_t;
/**
*******************************************************************************
** \brief GPIO端口下拉配置数据类型定义
******************************************************************************/
typedef enum en_gpio_pd
{
GpioPdDisable = 0u, ///< GPIO无下拉
GpioPdEnable = 1u, ///< GPIO下拉
}en_gpio_pd_t;
/**
*******************************************************************************
** \brief GPIO端口输出驱动能力配置数据类型定义
******************************************************************************/
typedef enum en_gpio_drv
{
GpioDrvH = 0u, ///< GPIO高驱动能力
GpioDrvL = 1u, ///< GPIO低驱动能力
}en_gpio_drv_t;
/**
*******************************************************************************
** \brief GPIO端口开漏输出控制数据类型定义
******************************************************************************/
typedef enum en_gpio_od
{
GpioOdDisable = 0u, ///< GPIO开漏输出关闭
GpioOdEnable = 1u, ///< GPIO开漏输出使能
}en_gpio_od_t;
/**
*******************************************************************************
** \brief GPIO中断触发方式类型定义
******************************************************************************/
typedef enum en_gpio_irqtype
{
GpioIrqHigh = 0u, ///< GPIO高电平触发
GpioIrqLow = 1u, ///< GPIO低电平触发
GpioIrqRising = 2u, ///< GPIO上升沿触发
GpioIrqFalling = 3u, ///< GPIO下降沿触发
}en_gpio_irqtype_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)端口中断模式类型定义
******************************************************************************/
typedef enum en_gpio_sf_irqmode
{
GpioSfIrqDpslpMode = 1u, ///< Deep Sleep模式
GpioSfIrqActSlpMode = 0u, ///< Active/Sleep模式
}en_gpio_sf_irqmode_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)HCLK输出门控类型定义
******************************************************************************/
typedef enum en_gpio_sf_hclkout_g
{
GpioSfHclkOutDisable = 0u, ///< HCLK输出门控关闭
GpioSfHclkOutEnable = 1u, ///< HCLK输出门控使能
}en_gpio_sf_hclkout_g_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)HCLK输出分频选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_hclkout_div
{
GpioSfHclkOutDiv1 = 0u, ///< HCLK
GpioSfHclkOutDiv2 = 1u, ///< HCLK/2
GpioSfHclkOutDiv4 = 2u, ///< HCLK/4
GpioSfHclkOutDiv8 = 3u, ///< HCLK/8
}en_gpio_sf_hclkout_div_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)PCLK输出门控类型定义
******************************************************************************/
typedef enum en_gpio_sf_pclkout_g
{
GpioSfPclkOutDisable = 0u, ///< PCLK输出门控关闭
GpioSfPclkOutEnable = 1u, ///< PCLK输出门控使能
}en_gpio_sf_pclkout_g_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)PCLK输出分频选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_pclkout_div
{
GpioSfPclkOutDiv1 = 0u, ///< PCLK
GpioSfPclkOutDiv2 = 1u, ///< PCLK/2
GpioSfPclkOutDiv4 = 2u, ///< PCLK/4
GpioSfPclkOutDiv8 = 3u, ///< PCLK/8
}en_gpio_sf_pclkout_div_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)IR输出极性选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_irpol
{
GpioSfIrP = 0u, ///< IR正向输出
GpioSfIrN = 1u, ///< IR反向输出
}en_gpio_sf_irpol_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)SSN与外部时钟输入信号源选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_ssn_extclk
{
GpioSfSsnExtClkH = 0u, ///< 高电平
GpioSfSsnExtClkP35 = 1u, ///< P35
GpioSfSsnExtClkP36 = 2u, ///< P36
GpioSfSsnExtClkP01 = 3u, ///< P01
GpioSfSsnExtClkP02 = 4u, ///< P02
GpioSfSsnExtClkP03 = 5u, ///< P03
GpioSfSsnExtClkP15 = 6u, ///< P15
GpioSfSsnExtClkP14 = 7u, ///< P14
GpioSfSsnExtClkP23 = 8u, ///< P23
GpioSfSsnExtClkP24 = 9u, ///< P24
GpioSfSsnExtClkP25 = 10u, ///< P25
GpioSfSsnExtClkP26 = 11u, ///< P26
GpioSfSsnExtClkP27 = 12u, ///< P27
GpioSfSsnExtClkP31 = 13u, ///< P31
GpioSfSsnExtClkP32 = 14u, ///< P32
GpioSfSsnExtClkP33 = 15u, ///< P33
}en_gpio_sf_ssn_extclk_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)定时器互联功能选择类型定义
** \note 具体功能及含义请参考用户手册GPIO辅助寄存器描述
******************************************************************************/
typedef enum en_gpio_sf
{
GpioSf0 = 0u, ///< SF0:PX_SEL的配置功能
GpioSf1 = 1u, ///< SF1:辅助功能1
GpioSf2 = 2u, ///< SF2:辅助功能2
GpioSf3 = 3u, ///< SF3:辅助功能3
GpioSf4 = 4u, ///< SF4:辅助功能4
GpioSf5 = 5u, ///< SF5:辅助功能5
GpioSf6 = 6u, ///< SF6:辅助功能6
GpioSf7 = 7u, ///< SF7:辅助功能7
}en_gpio_sf_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)定时器门控类型选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_tim_g
{
GpioSfTim0G = 0u, ///<Tim0定时器GATE输入选择
GpioSfTim1G = 2u, ///<Tim1定时器GATE输入选择
GpioSfTim2G = 4u, ///<Tim2定时器GATE输入选择
GpioSfTim3G = 6u, ///<Tim3定时器GATE输入选择
}en_gpio_sf_tim_g_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)定时器ETR类型选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_tim_e
{
GpioSfTim0E = 0u, ///<Tim0定时器ETR输入选择
GpioSfTim1E = 3u, ///<Tim1定时器ETR输入选择
GpioSfTim2E = 6u, ///<Tim2定时器ETR输入选择
GpioSfTim3E = 9u, ///<Tim3定时器ETR输入选择
GpioSfLpTimE = 12u, ///<LPTim定时器ETR输入选择
}en_gpio_sf_tim_e_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)定时器捕获输入类型选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_tim_c
{
GpioSfTim4CB = 0u, ///<Tim4定时器CHB输入选择
GpioSfTim5CB = 2u, ///<Tim5定时器CHB输入选择
GpioSfTim6CB = 4u, ///<Tim6定时器CHB输入选择
GpioSfTim4CA = 6u, ///<Tim4定时器CHA输入选择
GpioSfTim5CA = 8u, ///<Tim5定时器CHA输入选择
GpioSfTim6CA = 10u, ///<Tim6定时器CHA输入选择
}en_gpio_sf_tim_c_t;
/**
*******************************************************************************
** \brief GPIO 辅助功能(SF-Secondary Function)PCA捕获选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_pca
{
GpioSfPcaCapCH0 = 0u, ///<PCA捕获通道0信号来源选择
GpioSfPcaCapCH1 = 2u, ///<PCA捕获通道1信号来源选择
GpioSfPcaCapCH2 = 4u, ///<PCA捕获通道2信号来源选择
GpioSfPcaCapCH3 = 6u, ///<PCA捕获通道3信号来源选择
GpioSfPcaCapCH4 = 8u, ///<PCA捕获通道4信号来源选择
}en_gpio_sf_pca_t;
/**
*******************************************************************************
** \brief GPIO 端口配置结构体定义
******************************************************************************/
typedef struct
{
boolean_t bOutputVal; ///< 默认端口输出电平
en_gpio_dir_t enDir; ///< 端口方向配置
en_gpio_drv_t enDrv; ///< 端口驱动能力配置
en_gpio_pu_t enPu; ///< 端口上拉配置
en_gpio_pd_t enPd; ///< 端口下拉配置
en_gpio_od_t enOD; ///< 端口开漏输出配置
}stc_gpio_cfg_t;
/*******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
Global function prototypes (definition in C source)
*******************************************************************************/
///< GPIO IO初始化/去初始化
en_result_t Gpio_Init(en_gpio_port_t enPort, en_gpio_pin_t enPin, stc_gpio_cfg_t *pstcGpioCfg);
///< GPIO 获取端口输入电平
boolean_t Gpio_GetInputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
uint16_t Gpio_GetInputData(en_gpio_port_t enPort);
///< GPIO 设置端口输出
///< GPIO 端口输出电平配置及获取
en_result_t Gpio_WriteOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin, boolean_t bVal);
boolean_t Gpio_ReadOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 设置端口为模拟功能
en_result_t Gpio_SetAnalogMode(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 设置端口为端口复用功能
en_result_t Gpio_SetAfMode(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_af_t enAf);
///< GPIO 端口中断控制功能使能/关闭
en_result_t Gpio_EnableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType);
en_result_t Gpio_DisableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType);
///< GPIO 中断状态获取
boolean_t Gpio_GetIrqStatus(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 中断标志清除
en_result_t Gpio_ClearIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 端口辅助功能配置
///< GPIO 中断模式配置
en_result_t Gpio_SfIrqModeCfg(en_gpio_sf_irqmode_t enIrqMode);
///< GPIO IR输出极性配置
en_result_t Gpio_SfIrPolCfg(en_gpio_sf_irpol_t enIrPolMode);
///< GPIO HCLK输出配置
en_result_t Gpio_SfHClkOutputCfg(en_gpio_sf_hclkout_g_t enGate, en_gpio_sf_hclkout_div_t enDiv);
///< GPIO PCLK输出配置
en_result_t Gpio_SfPClkOutputCfg(en_gpio_sf_pclkout_g_t enGate, en_gpio_sf_pclkout_div_t enDiv);
///< GPIO 外部时钟输入配置
en_result_t Gpio_SfExtClkCfg(en_gpio_sf_ssn_extclk_t enExtClk);
///< GPIO SPI SSN输入配置
en_result_t Gpio_SfSsnCfg(en_gpio_sf_ssn_extclk_t enSsn);
///< GPIO Timer 门控输入配置
en_result_t Gpio_SfTimGCfg(en_gpio_sf_tim_g_t enTimG, en_gpio_sf_t enSf);
///< GPIO Timer ETR选择配置
en_result_t Gpio_SfTimECfg(en_gpio_sf_tim_e_t enTimE, en_gpio_sf_t enSf);
///< GPIO Timer 捕获输入配置
en_result_t Gpio_SfTimCCfg(en_gpio_sf_tim_c_t enTimC, en_gpio_sf_t enSf);
///< GPIO PCA捕获选择配置
en_result_t Gpio_SfPcaCfg(en_gpio_sf_pca_t enPca, en_gpio_sf_t enSf);
//@} // GpioGroup
#ifdef __cplusplus
}
#endif
#endif /* __GPIO_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+148
View File
@@ -0,0 +1,148 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file i2c.h
**
** Headerfile for I2C functions
**
**
** History:
** - 2018-03-1 CJ First Version
**
*****************************************************************************/
#ifndef __I2C_H__
#define __I2C_H__
#include "ddl.h"
/**
*******************************************************************************
** \defgroup I2cGroup Inter-Integrated Circuit (I2C)
**
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief I2C功能配置
*****************************************************************************/
typedef enum en_i2c_func
{
I2cModule_En = 6u, ///<I2C模块使能
I2cStart_En = 5u, ///<开始信号
I2cStop_En = 4u, ///<结束信号
I2cAck_En = 2u, ///<应答信号
I2cHlm_En = 0u, ///<高速使能
}en_i2c_func_t;
/**
******************************************************************************
** \brief I2C模式配置
*****************************************************************************/
typedef enum en_i2c_mode
{
I2cMasterMode = 0x40u, ///<I2C主机模式
I2cSlaveMode = 0x44u, ///<I2C从机模式
}en_i2c_mode_t;
/**
******************************************************************************
** \brief I2C初始化配置结构
*****************************************************************************/
typedef struct stc_i2c_cfg
{
uint32_t u32Pclk; ///<Pclk 设置(Hz)
uint32_t u32Baud; ///<I2C通信波特率(Hz)
en_i2c_mode_t enMode; ///<I2C主从模式配置
uint8_t u8SlaveAddr; ///<从机地址配置(如果需要)
boolean_t bGc; ///<广播地址使能(如果需要)
}stc_i2c_cfg_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//I2C初始化函数
en_result_t I2C_Init(M0P_I2C_TypeDef* I2Cx,stc_i2c_cfg_t *pstcI2CCfg);
//设置波特率配置寄存器
en_result_t I2C_SetBaud(M0P_I2C_TypeDef* I2Cx,uint8_t u8Tm);
//I2C功能设置函数
en_result_t I2C_SetFunc(M0P_I2C_TypeDef* I2Cx,en_i2c_func_t enFunc);
//I2C功能清除函数
en_result_t I2C_ClearFunc(M0P_I2C_TypeDef* I2Cx,en_i2c_func_t enFunc);
//获取中断标记SI
boolean_t I2C_GetIrq(M0P_I2C_TypeDef* I2Cx);
//清除中断标记SI
en_result_t I2C_ClearIrq(M0P_I2C_TypeDef* I2Cx);
//获取状态
uint8_t I2C_GetState(M0P_I2C_TypeDef* I2Cx);
//字节写函数
en_result_t I2C_WriteByte(M0P_I2C_TypeDef* I2Cx,uint8_t u8Data);
//字节读函数
uint8_t I2C_ReadByte(M0P_I2C_TypeDef* I2Cx);
//@} // I2cGroup
#ifdef __cplusplus
#endif
#endif /* __I2C_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+106
View File
@@ -0,0 +1,106 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file lpm.h
**
** Lpm 数据结构及API声明
**
**
** History:
** - 2017-06-06 Lux V1.0
**
*****************************************************************************/
#ifndef __LPM_H__
#define __LPM_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup LpmGroup Low Power Management (LPM)
**
**
******************************************************************************/
//@{
/******************************************************************************
** Global pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
///<功能配置及操作函数
///<进入普通休眠模式
void Lpm_GotoSleep(boolean_t bOnExit);
///<进入深度休眠模式
void Lpm_GotoDeepSleep(boolean_t bOnExit);
//@} // LpmGroup
#ifdef __cplusplus
#endif
#endif /* __LPM_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+228
View File
@@ -0,0 +1,228 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lvd.h
**
** Headerfile for Low Voltage Detector functions
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
#ifndef __LVD_H__
#define __LVD_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup LvdGroup Low Voltage Detector (LVD)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief LVD监测电压源选择
**
** \note
******************************************************************************/
typedef enum en_lvd_input_src
{
LvdInputSrcMskVCC = 0u<<2, ///< Vcc
LvdInputSrcMskP03 = 1u<<2, ///< P03
LvdInputSrcMskP23 = 2u<<2, ///< P23
LvdInputSrcMskP25 = 3u<<2, ///< P25
}en_lvd_input_src_t;
/**
******************************************************************************
** \brief LVD阈值电压选择
**
** \note
******************************************************************************/
typedef enum en_lvd_threshold
{
LvdMskTH1_8V = 0u<<4, ///< 1.8V
LvdMskTH1_9V = 1u<<4, ///< 1.9V
LvdMskTH2_0V = 2u<<4, ///< 2.0V
LvdMskTH2_1V = 3u<<4, ///< 2.1V
LvdMskTH2_2V = 4u<<4, ///< 2.2V
LvdMskTH2_3V = 5u<<4, ///< 2.3V
LvdMskTH2_4V = 6u<<4, ///< 2.4V
LvdMskTH2_5V = 7u<<4, ///< 2.5V
LvdMskTH2_6V = 8u<<4, ///< 2.6V
LvdMskTH2_7V = 9u<<4, ///< 2.7V
LvdMskTH2_8V = 10u<<4, ///< 2.8V
LvdMskTH2_9V = 11u<<4, ///< 2.9V
LvdMskTH3_0V = 12u<<4, ///< 3.0V
LvdMskTH3_1V = 13u<<4, ///< 3.1V
LvdMskTH3_2V = 14u<<4, ///< 3.2V
LvdMskTH3_3V = 15u<<4, ///< 3.3V
}en_lvd_threshold_t;
/**
******************************************************************************
** \brief LVD输出滤波时间
**
** \note
******************************************************************************/
typedef enum en_lvd_filter_time
{
LvdFilterMsk7us = 0u<<9, ///< 7us
LvdFilterMsk14us = 1u<<9, ///< 14us
LvdFilterMsk28us = 2u<<9, ///< 28us
LvdFilterMsk112us = 3u<<9, ///< 112us
LvdFilterMsk450us = 4u<<9, ///< 450us
LvdFilterMsk1_8ms = 5u<<9, ///< 1.8ms
LvdFilterMsk7_2ms = 6u<<9, ///< 7.3ms
LvdFilterMsk28_8ms = 7u<<9, ///< 28.8ms
}en_lvd_filter_time_t;
/**
******************************************************************************
** \brief LVD中断触发方式
**
** \note
******************************************************************************/
typedef enum en_lvd_irq_type
{
LvdIrqMskRiseFall = 3u<<12, ///< 上升/下降沿触发
LvdIrqMskHigh = 1u<<14, ///< 高电平触发
LvdIrqMskRise = 1u<<13, ///< 上升沿触发
LvdIrqMskFall = 1u<<12, ///< 下降沿触发
}en_lvd_irq_type_t;
/**
******************************************************************************
** \brief LVD触发动作选择
**
** \note
******************************************************************************/
typedef enum en_lvd_act
{
LvdActMskReset = 1u<<1, ///< 系统复位
LvdActMskInt = 0u, ///< NVIC中断
}en_lvd_act_t;
/**
******************************************************************************
** \brief LVD数字滤波使能配置
**
** \note
******************************************************************************/
typedef enum en_lvd_filter
{
LvdFilterMskEnable = 1u<<8, ///< 数字滤波使能
LvdFilterMskDisable = 0u, ///< 数字滤波禁止
}en_lvd_filter_t;
/**
******************************************************************************
** \brief LVD配置
** \note
******************************************************************************/
typedef struct stc_lvd_cfg
{
en_lvd_act_t enAct; ///< LVD触发动作
en_lvd_input_src_t enInputSrc; ///< LVD输入电压源
en_lvd_threshold_t enThreshold; ///< LVD监测电压
en_lvd_filter_t enFilter; ///< 是否使用输出滤波
en_lvd_filter_time_t enFilterTime; ///< 输出滤波时间
en_lvd_irq_type_t enIrqType; ///< 中断触发方式
}stc_lvd_cfg_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//irq enable/disable
void Lvd_EnableIrq(void);
void Lvd_DisableIrq(void);
// irq function
void Lvd_ClearIrq(void);
boolean_t Lvd_GetIrqStat(void);
//init/deinit function
void Lvd_Init(stc_lvd_cfg_t *pstcCfg);
//LVD function enable/disable
void Lvd_Enable(void);
void Lvd_Disable(void);
//@} // LvdGroup
#ifdef __cplusplus
}
#endif
#endif /* __LVD_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+259
View File
@@ -0,0 +1,259 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file pca.h
**
** PCA(可编程计数阵列)数据结构及API声明
**
**
** History:
** - 2019-04-09 First version
**
*****************************************************************************/
#ifndef __PCA_H__
#define __PCA_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup PcaGroup Programmable Counter Array (PCA)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief PCA 模块选择
** \note
******************************************************************************/
typedef enum
{
PcaModule0 = 0, // PCA_0
PcaModule1 = 1, // PCA_1
PcaModule2 = 2, // PCA_2
PcaModule3 = 3, // PCA_3
PcaModule4 = 4 // PCA_4
}en_pca_module_t;
/**
*******************************************************************************
** \brief PCA 中断标志位 中断清除位
** \note PCA_CCON中的CCF0-CCF4与CF; PCA_ICLR中的CCF0-CCF4与CF
******************************************************************************/
typedef enum
{
PcaCcf0 = 0,
PcaCcf1 = 1,
PcaCcf2 = 2,
PcaCcf3 = 3,
PcaCcf4 = 4,
PcaCf = 7
}en_pca_ccficlr_t;
/**
*******************************************************************************
** \brief PCA 时钟分频选择及时钟源选择
** \note PCA_CMOD CPS[2:0]
******************************************************************************/
typedef enum
{
PcaPclkdiv32 = 0, // PCLK/32
PcaPclkdiv16 = 1, // PCLK/16
PcaPclkdiv8 = 2, // PCLK/8
PcaPclkdiv4 = 3, // PCLK/4
PcaPclkdiv2 = 4, // PCLK/2
PcaTim0ovf = 5, // timer0 overflow
PcaTim1ovf = 6, // timer1 overflow
PcaEci = 7 // ECI外部时钟
}en_pca_clksrc_t;
/**
*******************************************************************************
** \brief PCA 允许比较器功能控制
** \note PCA_CCAPMx ECOM
******************************************************************************/
typedef enum
{
PcaEcomDisable = 0,
PcaEcomEnable = 1
}en_pca_ecom_t;
/**
*******************************************************************************
** \brief PCA 正沿捕获控制位
** \note PCA_CCAPMx CAPP
******************************************************************************/
typedef enum
{
PcaCappDisable = 0,
PcaCappEnable = 1
}en_pca_capp_t;
/**
*******************************************************************************
** \brief PCA 负沿捕获控制位
** \note PCA_CCAPMx CAPN
******************************************************************************/
typedef enum
{
PcaCapnDisable = 0,
PcaCapnEnable = 1
}en_pca_capn_t;
/**
*******************************************************************************
** \brief PCA 匹配控制位
** \note PCA_CCAPMx MAT
******************************************************************************/
typedef enum
{
PcaMatDisable = 0,
PcaMatEnable = 1
}en_pca_mat_t;
/**
*******************************************************************************
** \brief PCA 翻转控制位
** \note PCA_CCAPMx TOG
******************************************************************************/
typedef enum
{
PcaTogDisable = 0,
PcaTogEnable = 1
}en_pca_tog_t;
/**
*******************************************************************************
** \brief PCA PWM控制位
** \note PCA_CCAPMx PWM
******************************************************************************/
typedef enum
{
PcaPwm8bitDisable = 0,
PcaPwm8bitEnable = 1
}en_pca_pwm8bit_t;
/**
*******************************************************************************
** \brief PCA EPWM控制位
** \note PCA_EPWM EPWM
******************************************************************************/
typedef enum
{
PcaEpwmDisable = 0,
PcaEpwmEnable = 1
}en_pca_epwm_t;
/**
*******************************************************************************
** \brief PCA 初始化配置的结构体
** \note
******************************************************************************/
typedef struct
{
en_pca_clksrc_t pca_clksrc; // PCA_CMOD CPS[2:0]
boolean_t pca_cidl; // PCA_CMOD CIDL
en_pca_ecom_t pca_ecom; // PCA_CCAPMx ECOM
en_pca_capp_t pca_capp; // PCA_CCAPMx CAPP
en_pca_capn_t pca_capn; // PCA_CCAPMx CAPN
en_pca_mat_t pca_mat; // PCA_CCAPMx MAT
en_pca_tog_t pca_tog; // PCA_CCAPMx TOG
en_pca_pwm8bit_t pca_pwm; // PCA_CCAPMx PWM
uint16_t pca_ccap; // PCA_CCAP
uint8_t pca_ccapl; // PCA_CCAPL PCA_CCAP的低字节
uint8_t pca_ccaph; // PCA_CCAPH PCA_CCAP的高字节
}stc_pcacfg_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
extern boolean_t Pca_GetItStatus(en_pca_ccficlr_t It_Src);
extern void Pca_ClrItStatus(en_pca_ccficlr_t It_Src);
extern void Pca_StartPca(boolean_t NewStatus);
extern void Pca_SetCidl(boolean_t NewStatus);
extern void Pca_Set4Wdte(boolean_t NewStatus);
extern void Pca_ConfPcaIt(boolean_t NewStatus);
extern void Pca_ConfModulexIt(en_pca_module_t Modulex, boolean_t NewStatus);
extern void Pca_M0Init(stc_pcacfg_t* InitStruct);
extern void Pca_M1Init(stc_pcacfg_t* InitStruct);
extern void Pca_M2Init(stc_pcacfg_t* InitStruct);
extern void Pca_M3Init(stc_pcacfg_t* InitStruct);
extern void Pca_M4Init(stc_pcacfg_t* InitStruct);
extern uint16_t Pca_GetCnt(void);
extern void Pca_SetCnt(uint16_t cnt);
extern boolean_t Pca_GetOut(en_pca_module_t Modulex);
extern void Pca_SetCcap(en_pca_module_t Modulex, uint16_t Value);
extern uint16_t Pca_GetCcap(en_pca_module_t Modulex);
extern void Pca_SetCcapHL(en_pca_module_t Modulex, uint8_t ValueH, uint8_t ValueL);
extern void Pca_GetCcapHL(en_pca_module_t Modulex, uint8_t *ValueH, uint8_t *ValueL);
//@} // PcaGroup
#ifdef __cplusplus
#endif
#endif /* __PCA_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+119
View File
@@ -0,0 +1,119 @@
/*************************************************************************************
* Copyright (C) 2016, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ram.h
**
** RAM 数据结构及API声明.
**
** - 2019-04-02 LuX V1.0
**
******************************************************************************/
#ifndef __RAM_H__
#define __RAM_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup RamGroup Ram Controller (Ram)
**
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief Redefinition of RAM register structure
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///<中断相关函数
///<中断使能/禁止
extern void Ram_EnableIrq (void);
extern void Ram_DisableIrq(void);
///<中断标志获取
extern boolean_t Ram_GetIntFlag(void);
///<中断标志清除
extern void Ram_ClearIntFlag(void);
///<奇偶校验出错地址获取
extern uint32_t Ram_ErrAddrGet(void);
//@} // RamGroup
#ifdef __cplusplus
}
#endif
#endif /* __RAM_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
+153
View File
@@ -0,0 +1,153 @@
/******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file reset.h
**
** Headerfile for reset functions
**
**
** History:
** - 2018-04-21 Lux First Version
**
******************************************************************************/
#ifndef __RESET_H__
#define __RESET_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup ResetGroup Reset (RST)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/*******************************************************************************
* Global definitions
******************************************************************************/
/**
*******************************************************************************
** \brief 外设复位控制类型定义
** \note
******************************************************************************/
typedef enum en_sysctrl_peripheral
{
ResetMskUart0 = 1u<<0u, ///< 串口0
ResetMskUart1 = 1u<<1u, ///< 串口1
ResetMskI2c = 1u<<4u, ///< I2C
ResetMskSpi = 1u<<6u, ///< SPI
ResetMskBaseTim = 1u<<8u, ///< 基础定时器TIM0/1/2
ResetMskAdvTim = 1u<<10u, ///< 高级定时器TIM4/5/6
ResetMskPca = 1u<<14u, ///< 可编程计数阵列
ResetMskAdcBgr = 1u<<16u, ///< ADC&BGR
ResetMskVcLvd = 1u<<17u, ///< VC和LVD
ResetMskTrim = 1u<<21u, ///< 时钟校准
ResetMskTick = 1u<<24u, ///< 系统定时器
ResetMskCrc = 1u<<26u, ///< CRC
ResetMskGpio = 1u<<28u, ///< GPIO
}en_reset_peripheral_t;
/**
*******************************************************************************
** \brief 复位源(标识)显示
**
** \note
******************************************************************************/
typedef enum en_reset_flag
{
ResetFlagMskPor5V = 1u<<0u, ///< 5V启动复位
ResetFlagMskPor1_5V = 1u<<1u, ///< 1.5V启动复位
ResetFlagMskLvd = 1u<<2u, ///< 低电压检测复位
ResetFlagMskWdt = 1u<<3u, ///< 看门狗复位
ResetFlagMskPca = 1u<<4u, ///< PCA复位
ResetFlagMskLockup = 1u<<5u, ///< 系统异常复位
ResetFlagMskSysreq = 1u<<6u, ///< 软件复位
ResetFlagMskRstb = 1u<<7u, ///< RESET脚 复位
}en_reset_flag_t;
/*******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 获得复位源状态
boolean_t Reset_GetFlag(en_reset_flag_t enRstFlg);
///< 清除复位源状态
void Reset_ClearFlag(en_reset_flag_t enRstFlg);
void Reset_ClearFlagAll(void);
///< 外设模块复位
void Reset_RstPeripheralAll(void);
void Reset_RstPeripheral(en_reset_peripheral_t enPeri);
//@} // ResetGroup
#ifdef __cplusplus
#endif
#endif /* __RESET_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+188
View File
@@ -0,0 +1,188 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED , ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file spi.h
**
** Headerfile for SPI functions
**
**
** History:
** - 2017-05-17 1.0 Devi First Version
**
*****************************************************************************/
#ifndef __SPI_H__
#define __SPI_H__
/******************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
//@{
/******************************************************************************
* Global type definitions
*****************************************************************************/
/**
******************************************************************************
** \brief SPI 功能通道选择设置
******************************************************************************/
/**
******************************************************************************
** \brief SPI 功能使能设置
******************************************************************************/
typedef enum en_spi_en
{
SpiMskEnable = 0x4u, ///< SPI模块使能
SpiMskDisable = 0u, ///< SPI模块禁止
}en_spi_en_t;
/**
******************************************************************************
** \brief SPI 模式配置
******************************************************************************/
typedef enum en_spi_mode
{
SpiMskMaster = 0x10u, ///<主机
SpiMskSlave = 0x00u, ///<从机
}en_spi_mode_t;
/**
******************************************************************************
** \brief SPI 时钟极性设置
******************************************************************************/
typedef enum en_spi_cpol
{
SpiMskcpollow = 0u, ///<极性为低
SpiMskcpolhigh = 0x08u, ///<极性为高
}en_spi_cpol_t;
/**
******************************************************************************
** \brief SPI 时钟相位设置
******************************************************************************/
typedef enum en_spi_cpha
{
SpiMskCphafirst = 0u, ///<第一边沿采样
SpiMskCphasecond = 0x4u, ///<第二边沿采样
}en_spi_cpha_t;
/**
******************************************************************************
** \brief SPI 时钟分频配置
*****************************************************************************/
typedef enum en_spi_clk_div
{
SpiClkMskDiv2 = 0x00u, ///<2分频
SpiClkMskDiv4 = 0x01u, ///<4分频
SpiClkMskDiv8 = 0x02u, ///<8分频
SpiClkMskDiv16 = 0x03u, ///<16分频
SpiClkMskDiv32 = 0x80u, ///<32分频
SpiClkMskDiv64 = 0x81u, ///<64分频
SpiClkMskDiv128 = 0x82u, ///<128分频
}en_spi_clk_div_t;
/**
******************************************************************************
** \brief SPI 片选脚电平选择
*****************************************************************************/
typedef enum en_spi_cspin
{
SpiCsLow = 0u, ///<片选低电平
SpiCsHigh = 1u, ///<片选高电平
}en_spi_cspin_t;
/**
******************************************************************************
** \brief SPI 状态
*****************************************************************************/
typedef enum en_spi_status
{
SpiIf = 0x80, ///<传输结束中断标志
SpiWcol = 0x40, ///<写冲突标志
SpiSserr = 0x20, ///<从机模式错误标志
SpiMdf = 0x10, ///<主机模式错误标志
}en_spi_status_t;
/**
******************************************************************************
** \brief SPI 总体配置结构体
*****************************************************************************/
typedef struct stc_spi_cfg
{
en_spi_mode_t enSpiMode; ///< 主从模式选择
en_spi_clk_div_t enPclkDiv; ///< PCLK分频系数(波特率分频)
en_spi_cpol_t enCPOL; ///< 时钟极性选择
en_spi_cpha_t enCPHA; ///< 时钟相位选择
}stc_spi_cfg_t;
//SPI 状态获取
boolean_t Spi_GetStatus(M0P_SPI_TypeDef* SPIx,en_spi_status_t enStatus);
///<SPI 中断使能/禁止
en_result_t Spi_IrqEnable(M0P_SPI_TypeDef* SPIx);
en_result_t Spi_IrqDisable(M0P_SPI_TypeDef* SPIx);
//SPI初始化函数
en_result_t Spi_Init(M0P_SPI_TypeDef* SPIx,stc_spi_cfg_t* pstcSpiCfg);
//SPI关闭函数
en_result_t Spi_DeInit(M0P_SPI_TypeDef* SPIx);
//SPI 配置主发送的电平
void Spi_SetCS(M0P_SPI_TypeDef* SPIx,boolean_t bFlag);
//SPI 数据发送
en_result_t Spi_SendData(M0P_SPI_TypeDef* SPIx, uint8_t u8Data);
//SPI 数据接收
uint8_t Spi_ReceiveData(M0P_SPI_TypeDef* SPIx);
//@} // Spi Group
#ifdef __cplusplus
}
#endif
#endif /* __SPI_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+307
View File
@@ -0,0 +1,307 @@
/*******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file sysctrl.h
**
** Headerfile for SYSCTRL functions
** @link SYSCTRL Group Some description @endlink
**
** History:
** - 2018-04-15 Lux First Version
**
******************************************************************************/
#ifndef __SYSCTRL_H__
#define __SYSCTRL_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup SysCtrlGroup (SYSCTRL)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief 系统时钟输入源类型定义
** \note
******************************************************************************/
typedef enum en_sysctrl_clk_source
{
SysctrlClkRCH = 0u, ///< 内部高速时钟
SysctrlClkXTH = 1u, ///< 外部高速时钟
SysctrlClkRCL = 2u, ///< 内部低速时钟
SysctrlClkXTL = 3u, ///< 外部低速时钟
}en_sysctrl_clk_source_t;
/**
*******************************************************************************
** \brief RCH频率值枚举类型定义
******************************************************************************/
typedef enum en_sysctrl_rch_freq
{
SysctrlRchFreq4MHz = 4u, ///< 4MHz
SysctrlRchFreq8MHz = 3u, ///< 8MHz
SysctrlRchFreq16MHz = 2u, ///< 16MHz
SysctrlRchFreq22_12MHz = 1u, ///< 22.12MHz
SysctrlRchFreq24MHz = 0u, ///< 24MHz
}en_sysctrl_rch_freq_t;
/**
*******************************************************************************
** \brief XTAL驱动能力类型定义
******************************************************************************/
typedef enum en_sysctrl_xtal_driver
{
SysctrlXtalDriver0 = 0u, ///< 最弱驱动能力
SysctrlXtalDriver1 = 1u, ///< 弱驱动能力
SysctrlXtalDriver2 = 2u, ///< 一般驱动能力
SysctrlXtalDriver3 = 3u, ///< 最强驱动能力
}en_sysctrl_xtal_driver_t;
/**
*******************************************************************************
** \brief XTH频率值范围选择类型定义
******************************************************************************/
typedef enum en_sysctrl_xth_freq
{
SysctrlXthFreq4_6MHz = 0u, ///< 4~6MHz
SysctrlXthFreq6_12MHz = 1u, ///< 6~12MHz
SysctrlXthFreq12_20MHz = 2u, ///< 12~20MHz
SysctrlXthFreq20_32MHz = 3u, ///< 20~32MHz
}en_sysctrl_xth_freq_t;
/**
*******************************************************************************
** \brief XTH时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_xth_cycle
{
SysctrlXthStableCycle256 = 0u, ///< 256 个周期数
SysctrlXthStableCycle1024 = 1u, ///< 1024 个周期数
SysctrlXthStableCycle4096 = 2u, ///< 4096 个周期数
SysctrlXthStableCycle16384 = 3u, ///< 16384 个周期数
}en_sysctrl_xth_cycle_t;
/**
*******************************************************************************
** \brief RCL频率值枚举类型定义
******************************************************************************/
typedef enum en_sysctrl_rcl_freq
{
SysctrlRclFreq32768 = 0x11u, ///< 32.768KHz
SysctrlRclFreq38400 = 0x10u, ///< 38.4KHz
}en_sysctrl_rcl_freq_t;
/**
*******************************************************************************
** \brief RCL时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_rcl_cycle
{
SysctrlRclStableCycle4 = 0u, ///< 4 个周期数
SysctrlRclStableCycle16 = 1u, ///< 16 个周期数
SysctrlRclStableCycle64 = 2u, ///< 64 个周期数
SysctrlRclStableCycle256 = 3u, ///< 256 个周期数
}en_sysctrl_rcl_cycle_t;
/**
*******************************************************************************
** \brief HCLK时钟分频系数类型定义
******************************************************************************/
typedef enum en_sysctrl_hclk_div
{
SysctrlHclkDiv1 = 0u, ///< SystemClk
SysctrlHclkDiv2 = 1u, ///< SystemClk/2
SysctrlHclkDiv4 = 2u, ///< SystemClk/4
SysctrlHclkDiv8 = 3u, ///< SystemClk/8
SysctrlHclkDiv16 = 4u, ///< SystemClk/16
SysctrlHclkDiv32 = 5u, ///< SystemClk/32
SysctrlHclkDiv64 = 6u, ///< SystemClk/64
SysctrlHclkDiv128 = 7u, ///< SystemClk/128
}en_sysctrl_hclk_div_t;
/**
*******************************************************************************
** \brief PCLK分频系数
******************************************************************************/
typedef enum en_sysctrl_pclk_div
{
SysctrlPclkDiv1 = 0u, ///< HCLK
SysctrlPclkDiv2 = 1u, ///< HCLK/2
SysctrlPclkDiv4 = 2u, ///< HCLK/4
SysctrlPclkDiv8 = 3u, ///< HCLK/8
}en_sysctrl_pclk_div_t;
/**
*******************************************************************************
** \brief 系统控制模块其他功能数据类型定义
******************************************************************************/
typedef enum en_sysctrl_func
{
SysctrlEXTHEn = 1u, ///< 使能外部高速时钟从输入引脚输入
SysctrlCMLockUpEn = 6u, ///< 使能后CPU执行无效指令会复位MCU
SysctrlSWDUseIOEn = 8u, ///< SWD端口设为IO功能
}en_sysctrl_func_t;
/**
*******************************************************************************
** \brief 外设时钟门控开关类型枚举
******************************************************************************/
typedef enum en_sysctrl_peripheral_gate
{
SysctrlPeripheralUart0 = 0u, ///< 串口0
SysctrlPeripheralUart1 = 1u, ///< 串口1
SysctrlPeripheralI2c = 4u, ///< I2C
SysctrlPeripheralSpi = 6u, ///< SPI
SysctrlPeripheralBt = 8u, ///< 基础时钟
SysctrlPeripheralAdvTim = 10u, ///< 高级时钟
SysctrlPeripheralPca = 14u, ///< 可编程计数阵列
SysctrlPeripheralWdt = 15u, ///< 看门狗
SysctrlPeripheralAdcBgr = 16u, ///< ADC
SysctrlPeripheralVcLvd = 17u, ///< 电压比较和低电压检测
SysctrlPeripheralTrim = 21u, ///< 时钟校准
SysctrlPeripheralTick = 24u, ///< 系统定时器
SysctrlPeripheralCrc = 26u, ///< CRC
SysctrlPeripheralGpio = 28u, ///< GPIO
SysctrlPeripheralFlash = 31u, ///< Flash
}en_sysctrl_peripheral_gate_t;
/**
*******************************************************************************
** \brief 时钟初始化配置结构体定义
******************************************************************************/
typedef struct
{
en_sysctrl_clk_source_t enClkSrc; ///< 时钟源选择
en_sysctrl_hclk_div_t enHClkDiv; ///< HCLK分频系数
en_sysctrl_pclk_div_t enPClkDiv; ///< PCLK分频系数
}stc_sysctrl_clk_cfg_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 系统时钟初始化API:用于上电后,系统工作之前对主频及外设时钟进行初始化;
///< 注意1:使用该初始化函数前需要根据系统,必须优先设置目标内部时钟源的TRIM值或外部时钟源的频率范围,
///< 注意2:XTH、XTL的频率范围设定,需要根据外部晶振决定,
///< 注意3:本驱动默认宏定义:SYSTEM_XTH=32MHz,SYSTEM_XTL=32768Hz,如使用其它外部晶振,必须修改这两个宏定义的值。
en_result_t Sysctrl_ClkInit(stc_sysctrl_clk_cfg_t *pstcCfg);
///< 系统时钟去初始化API:恢复为上电默认状态->PCLK=HCLK=SystemClk=RCH4MHz
en_result_t Sysctrl_ClkDeInit(void);
///< 系统时钟模块的基本功能设置
///< 注意:使能需要使用的时钟源之前,必须优先设置目标内部时钟源的TRIM值或外部时钟源的频率范围
en_result_t Sysctrl_ClkSourceEnable(en_sysctrl_clk_source_t enSource, boolean_t bFlag);
///<外部晶振驱动配置:系统初始化Sysctrl_ClkInit()之后,可根据需要配置外部晶振的驱动能力,时钟初始化Sysctrl_ClkInit()默认为最大值;
en_result_t Sysctrl_XTHDriverCfg(en_sysctrl_xtal_driver_t enDriver);
///<时钟稳定周期设置:系统初始化Sysctrl_ClkInit()之后,可根据需要配置时钟开启后的稳定之间,默认为最大值;
en_result_t Sysctrl_SetXTHStableTime(en_sysctrl_xth_cycle_t enCycle);
en_result_t Sysctrl_SetRCLStableTime(en_sysctrl_rcl_cycle_t enCycle);
///<系统时钟源切换并更新系统时钟:如果需要在系统时钟初始化Sysctrl_ClkInit()之后切换主频时钟源,则使用该函数;
///< 时钟切换前后,必须根据目标频率值设置Flash读等待周期,可配置插入周期为0、1、2,
///< 注意!!!:当HCLK大于24MHz时,FLASH等待周期插入必须至少为1,否则程序运行可能产生未知错误
en_result_t Sysctrl_SysClkSwitch(en_sysctrl_clk_source_t enSource);
///< 时钟源频率设定:根据系统情况,单独设置不同时钟源的频率值;
///< 时钟频率设置前,必须根据目标频率值设置Flash读等待周期,可配置插入周期为0、1、2,
///< 其中XTL的时钟由外部晶振决定,无需设置。
en_result_t Sysctrl_SetRCHTrim(en_sysctrl_rch_freq_t enRCHFreq);
en_result_t Sysctrl_SetRCLTrim(en_sysctrl_rcl_freq_t enRCLFreq);
en_result_t Sysctrl_SetXTHFreq(en_sysctrl_xth_freq_t enXTHFreq);
///< 时钟分频设置:根据系统情况,单独设置HCLK、PCLK的分配值;
en_result_t Sysctrl_SetHCLKDiv(en_sysctrl_hclk_div_t enHCLKDiv);
en_result_t Sysctrl_SetPCLKDiv(en_sysctrl_pclk_div_t enPCLKDiv);
///< 时钟频率获取:根据系统需要,获取当前HCLK及PCLK的频率值
uint32_t Sysctrl_GetHClkFreq(void);
uint32_t Sysctrl_GetPClkFreq(void);
///< 外设门控开关/状态获取:用于控制外设模块的使能,使用该模块的功能之前,必须使能该模块的门控时钟;
en_result_t Sysctrl_SetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral, boolean_t bFlag);
boolean_t Sysctrl_GetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral);
///< 系统功能配置:用于设置其他系统相关特殊功能;
en_result_t Sysctrl_SetFunc(en_sysctrl_func_t enFunc, boolean_t bFlag);
//@} // Sysctrl Group
#ifdef __cplusplus
#endif
#endif /* __SYSCTRL_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+182
View File
@@ -0,0 +1,182 @@
/******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file trim.h
**
** TRIM 数据结构及API声明
**
**
** History:
** - 2018-04-21 Lux V1.0
**
*****************************************************************************/
#ifndef __TRIM_H__
#define __TRIM_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup TrimGroup Clock Trimming (TRIM)
**
******************************************************************************/
//@{
/******************************************************************************
** Global pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief 监测模式使能枚举重定义 (MON_EN)
*****************************************************************************/
typedef enum en_trim_monitor
{
TrimMonDisable = 0u, ///< 禁止
TrimMonEnable = 0x40u, ///< 使能
}en_trim_monitor_t;
/**
******************************************************************************
** \brief 待校准/监测时钟选择枚举重定义 (CALCLK_SEL)
*****************************************************************************/
typedef enum en_trim_calclksel
{
TrimCalMskRCH = 0x000u, ///< RCH
TrimCalMskXTH = 0x010u, ///< XTH
TrimCalMskRCL = 0x020u, ///< RCL
TrimCalMskXTL = 0x030u, ///< XTL
}en_trim_calclksel_t;
/**
******************************************************************************
** \brief 参考时钟选择枚举重定义 (REFCLK_SEL)
*****************************************************************************/
typedef enum en_trim_refclksel
{
TrimRefMskRCH = 0x0u, ///< RCH
TrimRefMskXTH = 0x2u, ///< XTH
TrimRefMskRCL = 0x4u, ///< RCL
TrimRefMskXTL = 0x6u, ///< XTL
TrimRefMskIRC10K = 0x8u, ///< IRC10K
TrimRefMskExtClk = 0xau, ///< 外部输入时钟
}en_trim_refclksel_t;
/**
******************************************************************************
** \brief 中断标志类型枚举重定义
*****************************************************************************/
typedef enum en_trim_inttype
{
TrimStop = 0x01u, ///< 参考计数器停止标志
TrimCalCntOf = 0x02u, ///< 校准计数器溢出标志
TrimXTLFault = 0x04u, ///< XTL 失效标志
TrimXTHFault = 0x08u, ///< XTH 失效标志
}en_trim_inttype_t;
/**
******************************************************************************
** \brief TRIM 配置结构体定义
*****************************************************************************/
typedef struct stc_trim_cfg
{
en_trim_monitor_t enMON; ///< 监测模式使能
en_trim_calclksel_t enCALCLK; ///< 校准时钟选择
uint32_t u32CalCon; ///< 校准计数器溢出值配置
en_trim_refclksel_t enREFCLK; ///< 参考时钟选择
uint32_t u32RefCon; ///< 参考计数器初值配置
}stc_trim_cfg_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
///<<功能配置及操作函数
///<Trim 配置及初始化
en_result_t Trim_Init(stc_trim_cfg_t* pstcCfg);
///<校准/监测启动/停止
void Trim_Run(void);
void Trim_Stop(void);
///<参考计数器计数值获取
uint32_t Trim_RefCntGet(void);
///<校准计数器计数值获取
uint32_t Trim_CalCntGet(void);
///<中断操作相关函数
///中断使能/禁止
void Trim_EnableIrq(void);
void Trim_DisableIrq(void);
///<中断标志获取
boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType);
///<中断标志清除
en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType);
//@} // TrimGroup
#ifdef __cplusplus
#endif
#endif /* __TRIM_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+241
View File
@@ -0,0 +1,241 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file uart.h
**
** Headerfile for UART functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __UART_H__
#define __UART_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup UartGroup Universal Asynchronous Receiver/Transmitter (UART)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief uart多主机模式地址帧/数据帧或者奇偶校验
******************************************************************************/
typedef enum en_uart_mmdorck
{
UartData = 0u, ///<多主机模式时,数据帧TB8标记
UartAddr = 1u, ///<多主机模式时,地址帧TB8标记
}en_uart_mmdorck_t;
/**
******************************************************************************
** \brief uart奇偶校验
******************************************************************************/
typedef enum en_uart_check
{
UartEven = 0u, ///<偶校验
UartOdd = 1u, ///<奇校验
}en_uart_check_t;
/**
******************************************************************************
** \brief uart多主机模式配置
******************************************************************************/
typedef enum en_uart_multimode
{
UartNormal = 0u, ///<正常工作模式
UartMulti = 1u, ///<多主机工作模式
}en_uart_multimode_t;
/**
******************************************************************************
** \brief uart多主机模式及从机地址和地址掩码配置
******************************************************************************/
typedef struct stc_uart_multimode
{
uint8_t u8SlaveAddr; ///<从机地址
uint8_t u8SaddEn; ///<从及地址掩码
}stc_uart_multimode_t;
/**
******************************************************************************
** \brief uart 四种工作模式选择
******************************************************************************/
typedef enum en_uart_mode
{
UartMode0 = 0u, ///<模式0
UartMode1 = 1u, ///<模式1
UartMode2 = 2u, ///<模式2
UartMode3 = 3u, ///<模式3
} en_uart_mode_t;
/**
******************************************************************************
** \brief uart 发送接收功能使能
******************************************************************************/
typedef enum en_uart_func
{
UartRenFunc = 4u, ///<0-TX; ///<1-非mode0模式代表RX&TX ,mode0模式代表RX;
}en_uart_func_t;
/**
******************************************************************************
** \brief uart发送接收中断使能
******************************************************************************/
typedef enum en_uart_irq_sel
{
UartRxIrq = 0u, ///<接收中断使能
UartTxIrq = 1u, ///<发送中断使能
}en_uart_irq_sel_t;
/**
******************************************************************************
** \brief uart 状态标志位
******************************************************************************/
typedef enum en_uart_status
{
UartRC = 0u, ///<接收数据完成标记
UartTC = 1u, ///<发送数据完成标记
UartFE = 2u, ///<帧错误标记
}en_uart_status_t;
/**
******************************************************************************
** \brief uart 通道地址结构
******************************************************************************/
typedef struct stc_uart_instance_data
{
uint32_t u32Idx; ///< 通道号
M0P_UART_TypeDef *pstcInstance; ///< 通道寄存器地址
} stc_uart_instance_data_t;
/**
******************************************************************************
** \brief uart 通道波特率配置
******************************************************************************/
typedef struct stc_uart_baud_cfg
{
en_uart_mode_t enMode; ///<四种工作模式
boolean_t bDbaud; ///<是否双倍波特率
uint32_t u32Pclk; ///< PCLK
uint32_t u32Baud; ///<波特率
}stc_uart_baud_cfg_t;
/**
******************************************************************************
** \uart 总体配置
******************************************************************************/
typedef struct stc_uart_cfg
{
en_uart_mode_t enRunMode; ///<四种模式配置
} stc_uart_cfg_t;
//UART初始化
en_result_t Uart_Init(M0P_UART_TypeDef* UARTx, stc_uart_cfg_t* pstcCfg);
///<中断相关设置函数
en_result_t Uart_EnableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel);
en_result_t Uart_DisableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel);
// 初始化处理
en_result_t Uart_Init(M0P_UART_TypeDef* UARTx, stc_uart_cfg_t* pstcCfg);
// 波特率设置
uint16_t Uart_SetBaudRate(M0P_UART_TypeDef* UARTx,stc_uart_baud_cfg_t* pstcBaud);
///<UART模块多机模式设置函数
en_result_t Uart_SetMultiMode(M0P_UART_TypeDef* UARTx, stc_uart_multimode_t* pstcMultiCfg);
///< 发送或接收使能和禁止
en_result_t Uart_EnableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc);
en_result_t Uart_DisableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc);
///< 状态位的获取和清除
uint8_t Uart_GetIsr(M0P_UART_TypeDef* UARTx);
boolean_t Uart_GetStatus(M0P_UART_TypeDef* UARTx,en_uart_status_t enStatus);
en_result_t Uart_ClrIsr(M0P_UART_TypeDef* UARTx);
en_result_t Uart_ClrStatus(M0P_UART_TypeDef* UARTx,en_uart_status_t enStatus);
//数据收发操作
///< 数据查询模式发送
en_result_t Uart_SendDataPoll(M0P_UART_TypeDef* UARTx, uint8_t u8Data);
en_result_t Uart_SendDataPollTimeOut(M0P_UART_TypeDef* UARTx, uint8_t u8Data, uint32_t u32TimeOut);
///< 数据中断模式发送
en_result_t Uart_SendDataIt(M0P_UART_TypeDef* UARTx, uint8_t u8Data);
uint8_t Uart_ReceiveData(M0P_UART_TypeDef* UARTx);
///< 奇偶校验检查
en_result_t Uart_CheckEvenOrOdd(M0P_UART_TypeDef* UARTx, en_uart_check_t enCheck, uint8_t u8Recv);
///< 获取Rb8位
boolean_t Uart_GetRb8(M0P_UART_TypeDef* UARTx);
//< 设置TB8
en_result_t Uart_SetTb8(M0P_UART_TypeDef* UARTx, en_uart_check_t enCheck, uint8_t u8Data);
//@} // UartGroup
#ifdef __cplusplus
#endif
#endif /* __UART_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+288
View File
@@ -0,0 +1,288 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file vc.h
**
** Headerfile for Voltage Comparator functions
** @link VC Group Some description @endlink
**
** - 2019-04-10 First Version
**
******************************************************************************/
#ifndef __VC_H__
#define __VC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup VcGroup Voltage Comparator (VC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief VC通道
*****************************************************************************/
typedef enum en_vc_channel
{
VcChannel0 = 0u, // 通道0
VcChannel1 = 1u, // 通道1
}en_vc_channel_t;
/**
******************************************************************************
** \brief VC迟滞
*****************************************************************************/
typedef enum
{
VcDelayoff = 0u, // 迟滞关闭
VcDelay10mv = 1u, // 迟滞10mv
VcDelay20mv = 2u, // 迟滞20mv
VcDelay30mv = 3u, // 迟滞30mv
}en_vc_cmp_delay_t;
/**
******************************************************************************
** \brief VC偏置电流
*****************************************************************************/
typedef enum
{
VcBias300na = 0u, // 偏置电流300nA
VcBias1200na = 1u, // 偏置电流1.2uA
VcBias10ua = 2u, // 偏置电流10uA
VcBias20ua = 3u, // 偏置电流20uA
}en_vc_bias_current_t;
/**
******************************************************************************
** \brief VC输出滤波时间
*****************************************************************************/
typedef enum
{
VcFilter7us = 0u, // 输出滤波时间7us
VcFilter14us = 1u, // 输出滤波时间14us
VcFilter28us = 2u, // 输出滤波时间28us
VcFilter112us = 3u, // 输出滤波时间112us
VcFilter450us = 4u, // 输出滤波时间450us
VcFilter1800us = 5u, // 输出滤波时间1.8ms
VcFilter7200us = 6u, // 输出滤波时间7.2ms
VcFilter28800us = 7u, // 输出滤波时间28.8ms
}en_vc_resp_filter_t;
/**
******************************************************************************
** \brief VC P端输入
*****************************************************************************/
typedef enum en_vc_input_p_src
{
VcInPCh0, ///< 输入通道0 P2.3
VcInPCh1, ///< 输入通道1 P2.5
VcInPCh2, ///< 输入通道2 P3.2
VcInPCh3, ///< 输入通道3 P3.3
VcInPCh4, ///< 输入通道4 P3.4
VcInPCh5, ///< 输入通道5 P3.5
VcInPCh6, ///< 输入通道6 P3.6
VcInPCh7, ///< 输入通道7 P0.1
}en_vc_input_p_src_t;
/**
******************************************************************************
** \brief VC N端输入
*****************************************************************************/
typedef enum en_vc_input_n_src
{
VcInNCh0, ///< 输入通道0 P2.3
VcInNCh1, ///< 输入通道1 P2.5
VcInNCh2, ///< 输入通道2 P3.2
VcInNCh3, ///< 输入通道3 P3.3
VcInNCh4, ///< 输入通道4 P3.4
VcInNCh5, ///< 输入通道5 P3.5
VcInNCh6, ///< 输入通道6 P3.6
VcInNCh7, ///< 输入通道7 P0.1
ResDivOut, ///< Vcc分压
AiTs, ///< 温度传感器
AiBg1p2, ///< BGR 1.2V
AiVcRef2p5, ///< REF 2.5V
AiLdo, ///< LDO
}en_vc_input_n_src_t;
/**
******************************************************************************
** \brief VC中断触发方式
*****************************************************************************/
typedef enum en_vc_irq_sel
{
VcIrqNone = 0u, ///< 无中断
VcIrqRise = 1u, ///< 上升沿触发
VcIrqFall = 2u, ///< 下降沿触发
VcIrqHigh = 3u, ///< 高电平触发
}en_vc_irq_sel_t;
/**
******************************************************************************
** \brief VC状态 VC_IFR
*****************************************************************************/
typedef enum en_vc_stat
{
Vc0_Intf = 0u, // VC0中断标志
Vc1_Intf = 1u, // VC1中断标志
Vc0_Filter = 2u, // VC0 Filter 后的状态
Vc1_Filter = 3u, // VC1 Filter 后的状态
}en_vc_ifr_t;
/**
******************************************************************************
** \brief VC输出配置
*****************************************************************************/
typedef enum en_vc_output_cfg
{
VcOutInvTimer, ///< 结果输出负向到各Timer0,1,2,3
VcOutTm0Gate, ///< 结果使能输出到TM0 Gate
VcOutTm1Gate, ///< 结果使能输出到TM1 Gate
VcOutTm2Gate, ///< 结果使能输出到TM2 Gate
VcOutTm3Gate, ///< 结果使能输出到LPTIMER3 Gate
VcOutTm3ExtClk, ///< 结果使能输出到LPTIMER 外部时钟
VcOutInvPca, ///< 结果输出负向到PCA
VcOutPcaCap0, ///< 结果使能输出到PCA 捕获模式0
VcOutPcaExtClk, ///< 结果使能输出到PCA 外部时钟
VcOutInvTm4, ///< 结果输出负向到Timer4
VcOutTm4, ///< 结果使能输出到TM4 捕获模式
VcOutInvTm5, ///< 结果输出负向到Timer5
VcOutTm5, ///< 结果使能输出到TM5 捕获模式
VcOutInvTm6, ///< 结果输出负向到Timer6
VcOutTm6, ///< 结果使能输出到TM6 捕获模式
VcOutBrake, ///< 刹车控制
VcOutDisable, ///< 结果输出除能
}en_vc_output_cfg_t;
/**
******************************************************************************
** \brief VC DIV参考电压Vref选择
*****************************************************************************/
typedef enum en_vc_div_vref
{
VcDivVrefAvcc = 0u, ///< AVCC
VcDivVrefAdc = 1u, ///< ADC_CR0 SREF选择参考电压
}en_vc_div_vref_t;
/**
******************************************************************************
** \brief VC模块配置
*****************************************************************************/
typedef struct stc_vc_dac_cfg
{
boolean_t bDivEn; // VC_CR: VC_DIV_EN
uint8_t u8DivVal; // VC_CR: VC_DIV 范围:0-63
en_vc_div_vref_t enDivVref; // VC_CR: VC_REF2P5_SEL
}stc_vc_dac_cfg_t;
/**
******************************************************************************
** \brief VC通道配置
*****************************************************************************/
typedef struct stc_vc_channel_cfg
{
en_vc_channel_t enVcChannel; // VC通道选择
en_vc_cmp_delay_t enVcCmpDly; // VC迟滞
en_vc_bias_current_t enVcBiasCurrent; // VC功耗选择
en_vc_resp_filter_t enVcFilterTime; // 输出滤波时间
en_vc_input_p_src_t enVcInPin_P; // P端输入
en_vc_input_n_src_t enVcInPin_N; // N端输入
en_vc_output_cfg_t enVcOutCfg; // 输出配置
boolean_t bFlten; // 滤波输出使能
}stc_vc_channel_cfg_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
extern void Vc_CfgItType(en_vc_channel_t Channelx, en_vc_irq_sel_t ItType);
extern void Vc_ItCfg(en_vc_channel_t Channelx, boolean_t NewStatus);
extern boolean_t Vc_GetItStatus(en_vc_ifr_t Result);
extern void Vc_ClearItStatus(en_vc_ifr_t NewStatus);
extern en_result_t Vc_DacInit(stc_vc_dac_cfg_t *pstcDacCfg);
extern void Vc_Init(stc_vc_channel_cfg_t *pstcChannelCfg);
extern void Vc_Cmd(en_vc_channel_t enChannel, boolean_t NewStatus);
//@} // VcGroup
#ifdef __cplusplus
}
#endif
#endif /* __VC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+135
View File
@@ -0,0 +1,135 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file wdt.h
**
** Headerfile for WDT functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __WDT_H__
#define __WDT_H__
#include "ddl.h"
/**
******************************************************************************
** \defgroup WdtGroup Watchdog Timer (WDT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief wdt溢出后复位或中断配置
*****************************************************************************/
typedef enum en_wdt_func
{
WdtResetEn = 0, ///<复位使能
WdtIntEn = 1, ///<中断使能
}en_wdt_func_t;
/**
******************************************************************************
** \brief wdt当前运行时间配置数据类型定义
*****************************************************************************/
typedef enum en_wdt_time
{
WdtT1ms6 = 0u, ///<1.6ms
WdtT3ms2 = 1u, ///<3.2ms
WdtT6ms4 = 2u, ///<6.4ms
WdtT13ms = 3u, ///<13ms
WdtT26ms = 4u, ///<26ms
WdtT51ms = 5u, ///<51ms
WdtT102ms = 6u, ///<102ms
WdtT205ms = 7u, ///<205ms
WdtT500ms = 8u, ///<500ms
WdtT820ms = 9u, ///<820ms
WdtT1s64 = 10u, ///<1.64s
WdtT3s28 = 11u, ///<3.28s
WdtT6s55 = 12u, ///<6.55s
WdtT13s1 = 13u, ///<13.1s
WdtT26s2 = 14u, ///<26.2s
WdtT52s4 = 15u, ///<52.4s
}en_wdt_time_t;
//wdt初始化
en_result_t Wdt_Init(en_wdt_func_t enFunc, en_wdt_time_t enTime);
//wdt开始和停止
void Wdt_Start(void);
//喂狗处理
void Wdt_Feed(void);
//喂狗处理
void Wdt_IrqClr(void);
//wdt溢出时间设置
void Wdt_WriteWdtLoad(uint8_t u8LoadValue);
///< 当前计数时间获取
uint8_t Wdt_ReadWdtValue(void);
//< 中断状态获取
boolean_t Wdt_GetIrqStatus(void);
///< 运行状态获取
boolean_t Wdt_ReadwdtStatus(void);
//@} // WdtGroup
#ifdef __cplusplus
#endif
#endif /* __WDT_H__ */
+592
View File
@@ -0,0 +1,592 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file adc.c
**
** ADC driver API.
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "adc.h"
/**
******************************************************************************
** \addtogroup AdcGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
/**
* \brief
* 获取ADC中断状态
*
* \param [in] pstcAdcIrqState ADC中断状态指针
*
* \retval 无
*/
void Adc_GetIrqState(stc_adc_irq_t* pstcAdcIrqState)
{
pstcAdcIrqState->bAdcIrq = M0P_ADC->IFR_f.CONT_INTF;
pstcAdcIrqState->bAdcRegCmp = M0P_ADC->IFR_f.REG_INTF;
pstcAdcIrqState->bAdcHhtCmp = M0P_ADC->IFR_f.HHT_INTF;
pstcAdcIrqState->bAdcLltCmp = M0P_ADC->IFR_f.LLT_INTF;
}
/**
* \brief
* 清除ADC CONT中断状态
*
* \param 无
*
* \retval 无
*/
void Adc_ClrContIrqState(void)
{
M0P_ADC->ICLR = ~(1<<3);
}
/**
* \brief
* 清除ADC REG中断状态
*
* \param 无
*
* \retval 无
*/
void Adc_ClrRegIrqState(void)
{
M0P_ADC->ICLR = ~(1<<2);
}
/**
* \brief
* 清除ADC HHT中断状态
*
* \param 无
*
* \retval 无
*/
void Adc_ClrHhtIrqState(void)
{
M0P_ADC->ICLR = ~(1<<1);
}
/**
* \brief
* 清除ADC LLT中断状态
*
* \param 无
*
* \retval 无
*/
void Adc_ClrIrqLltState(void)
{
M0P_ADC->ICLR = ~1;
}
/**
* \brief
* ADC中断使能
*
* \param 无
*
* \retval 无
*/
void Adc_EnableIrq(void)
{
M0P_ADC->CR0_f.IE = 1u;
}
/**
* \brief
* ADC比较使能
*
* \param [in] pstcAdcIrqCfg ADC比较配置
*
* \retval 无
*/
void Adc_CmpCfg(stc_adc_irq_t* pstcAdcIrqCfg)
{
if (TRUE == pstcAdcIrqCfg->bAdcRegCmp)
{
M0P_ADC->CR1_f.REGCMP = 1u;
}
else
{
M0P_ADC->CR1_f.REGCMP = 0u;
}
if (TRUE == pstcAdcIrqCfg->bAdcHhtCmp)
{
M0P_ADC->CR1_f.HTCMP = 1u;
}
else
{
M0P_ADC->CR1_f.HTCMP = 0u;
}
if (TRUE == pstcAdcIrqCfg->bAdcLltCmp)
{
M0P_ADC->CR1_f.LTCMP = 1u;
}
else
{
M0P_ADC->CR1_f.LTCMP = 0u;
}
}
/**
* \brief
* ADC中断除能
*
* \param 无
*
* \retval 无
*/
void Adc_DisableIrq(void)
{
uint32_t u32Cr1;
M0P_ADC->CR0_f.IE = 0u;
u32Cr1 = M0P_ADC->CR1 | (1<<15); // must write 1 to bit 15 to avoid clear ADC_result_acc
u32Cr1 &= ~((1u<<12)|(1u<<13)|(1u<<14));
M0P_ADC->CR1 = u32Cr1;
}
/**
* \brief
* ADC初始化
*
* \param [in] pstcAdcConfig ADC配置指针
*
* \retval en_result_t Ok: 配置成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_Init(stc_adc_cfg_t* pstcAdcConfig)
{
if (NULL == pstcAdcConfig)
{
return ErrorInvalidParameter;
}
M0P_ADC->CR0_f.CLKSEL = pstcAdcConfig->enAdcClkSel;
M0P_ADC->CR0_f.SAM = pstcAdcConfig->enAdcSampTimeSel;
M0P_ADC->CR0_f.SREF = pstcAdcConfig->enAdcRefVolSel;
M0P_ADC->CR0_f.BUFEN = pstcAdcConfig->bAdcInBufEn;
M0P_ADC->HT_f.HT = pstcAdcConfig->u32AdcRegHighThd;
M0P_ADC->LT_f.LT = pstcAdcConfig->u32AdcRegLowThd;
M0P_ADC->CR1_f.TRIGS0 = pstcAdcConfig->enAdcTrig0Sel;
M0P_ADC->CR1_f.TRIGS1 = pstcAdcConfig->enAdcTrig1Sel;
M0P_ADC->CR0_f.IE = 0u;
M0P_ADC->CR1_f.REGCMP = 0u;
M0P_ADC->CR1_f.HTCMP = 0u;
M0P_ADC->CR1_f.LTCMP = 0u;
return Ok;
}
/**
* \brief
* ADC Deinit
*
* \param 无
*
* \retval 无
*/
void Adc_DeInit(void)
{
Adc_DisableIrq();
EnableNvic(ADC_IRQn, IrqLevel3, FALSE);
M0P_ADC->CR0_f.ADCEN = 0u;
M0P_ADC->CR0_f.IE = 0u;
M0P_ADC->CR1_f.REGCMP = 0u;
M0P_ADC->CR1_f.HTCMP = 0u;
M0P_ADC->CR1_f.LTCMP = 0u;
M0P_ADC->ICLR_f.CONT_INTC = 0u;
M0P_ADC->ICLR_f.REG_INTC = 0u;
M0P_ADC->ICLR_f.HHT_INTC = 0u;
M0P_ADC->ICLR_f.LLT_INTC = 0u;
M0P_ADC->CR0_f.CLKSEL = 0u;
M0P_ADC->CR0_f.SAM = 0x2u;
M0P_ADC->CR0_f.SREF = 0x3u;
M0P_ADC->CR0_f.SEL = 0xFu;
M0P_ADC->CR0_f.BUFEN = 0u;
M0P_ADC->HT_f.HT = 0xFFFu;
M0P_ADC->LT_f.LT = 0u;
M0P_ADC->CR1_f.TRIGS0 = 0u;
M0P_ADC->CR1_f.TRIGS1 = 0u;
}
/**
* \brief
* ADC转换开始
*
* \param 无
*
* \retval 无
*/
void Adc_Start(void)
{
M0P_ADC->ICLR_f.CONT_INTC = 0u;
M0P_ADC->CR0_f.STATERST = 1u;
M0P_ADC->CR0_f.START = 1u;
}
/**
* \brief
* ADC转换停止
*
* \param 无
*
* \retval 无
*/
void Adc_Stop(void)
{
M0P_ADC->CR0_f.START = 0u;
}
/**
* \brief
* ADC使能
*
* \param 无
*
* \retval 无
*/
void Adc_Enable(void)
{
M0P_ADC->CR0_f.ADCEN = 1u;
}
/**
* \brief
* ADC除能
*
* \param 无
*
* \retval 无
*/
void Adc_Disable(void)
{
M0P_ADC->CR0_f.ADCEN = 0u;
}
/**
* \brief
* 配置普通转换模式
*
* \param [in] pstcAdcConfig ADC配置指针
* \param [in] pstcAdcNormCfg 普通转换模式配置指针
*
* \retval en_result_t Ok: 配置成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_ConfigNormMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_norm_cfg_t* pstcAdcNormCfg)
{
if ((NULL == pstcAdcNormCfg) || (NULL == pstcAdcConfig))
{
return ErrorInvalidParameter;
}
pstcAdcConfig->enAdcOpMode = AdcNormalMode;
M0P_ADC->CR1_f.CT = 0u;
M0P_ADC->CR0_f.SEL = pstcAdcNormCfg->enAdcNormModeCh;
M0P_ADC->CR1_f.RACC_EN = pstcAdcNormCfg->bAdcResultAccEn;
return Ok;
}
/**
* \brief
* 配置连续转换模式
*
* \param [in] pstcAdcConfig ADC配置指针
* \param [in] pstcAdcNormCfg 连续转换模式配置指针
*
* \retval en_result_t Ok: 配置成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_ConfigContMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_cont_cfg_t* pstcAdcContCfg)
{
if ((NULL == pstcAdcContCfg) || (NULL == pstcAdcConfig))
{
return ErrorInvalidParameter;
}
pstcAdcConfig->enAdcOpMode = AdcContMode;
M0P_ADC->CR1_f.CT = 1u;
M0P_ADC->CR0_f.SEL = pstcAdcContCfg->enAdcContModeCh;
M0P_ADC->CR1_f.RACC_EN = pstcAdcContCfg->bAdcResultAccEn;
if (pstcAdcContCfg->bAdcResultAccEn)
{
M0P_ADC->CR1_f.RACC_CLR = 1u;
}
M0P_ADC->CR2 = 1<<pstcAdcContCfg->enAdcContModeCh;
M0P_ADC->CR2_f.ADCCNT = pstcAdcContCfg->u8AdcSampCnt;
return Ok;
}
/**
* \brief
* 配置扫描转换模式
*
* \param [in] pstcAdcConfig ADC配置指针
* \param [in] pstcAdcNormCfg 扫描转换模式配置指针
*
* \retval en_result_t Ok: 配置成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_ConfigScanMode(stc_adc_cfg_t* pstcAdcConfig, stc_adc_scan_cfg_t* pstcAdcScanCfg)
{
if ((NULL == pstcAdcScanCfg) || (NULL == pstcAdcConfig))
{
return ErrorInvalidParameter;
}
pstcAdcConfig->enAdcOpMode = AdcScanMode;
M0P_ADC->CR1_f.CT = 1u;
M0P_ADC->CR2 = pstcAdcScanCfg->u8AdcScanModeCh;
M0P_ADC->CR2_f.ADCCNT = pstcAdcScanCfg->u8AdcSampCnt;
return Ok;
}
/**
* \brief
* 查询ADC转换状态
*
* \param none
*
* \retval boolean_t TRUE: ADC转换中
* \retval boolean_t FALSE: ADC转换完成
*/
boolean_t Adc_PollBusyState(void)
{
return M0P_ADC->CR0_f.START;
}
/**
* \brief
* 获取采样值
*
* \param [out] pu16AdcResult 采样值指针
*
* \retval en_result_t Ok: 成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_GetResult(uint16_t* pu16AdcResult)
{
if (NULL == pu16AdcResult)
{
return ErrorInvalidParameter;
}
*pu16AdcResult = M0P_ADC->RESULT_f.RESULT;
return Ok;
}
/**
* \brief
* 获取累加采样值
*
* \param [out] pu32AdcAccResult 累加采样值指针
*
* \retval en_result_t Ok: 成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_GetAccResult(uint32_t* pu32AdcAccResult)
{
if (NULL == pu32AdcAccResult)
{
return ErrorInvalidParameter;
}
*pu32AdcAccResult = M0P_ADC->RESULT_ACC_f.RESULT_ACC;
return Ok;
}
/**
* \brief
* 清零累加采样值
*
* \param 无
*
* \retval 无
*/
void Adc_ClrAccResult(void)
{
M0P_ADC->CR1_f.RACC_CLR = 0u;
}
/**
* \brief
* 获取扫描采样模式下指定通道的采样值
*
* \param [in] u8Channel 通道号
* \param [out] pu16AdcResult 采样值指针
*
* \retval en_result_t Ok: 成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_GetScanResult(uint8_t u8Channel, uint16_t* pu16AdcResult)
{
if (NULL == pu16AdcResult)
{
return ErrorInvalidParameter;
}
switch (u8Channel)
{
case AdcExInputCH0:
*pu16AdcResult = M0P_ADC->RESULT0_f.RESULT0;
break;
case AdcExInputCH1:
*pu16AdcResult = M0P_ADC->RESULT1_f.RESULT1;
break;
case AdcExInputCH2:
*pu16AdcResult = M0P_ADC->RESULT2_f.RESULT2;
break;
case AdcExInputCH3:
*pu16AdcResult = M0P_ADC->RESULT3_f.RESULT3;
break;
case AdcExInputCH4:
*pu16AdcResult = M0P_ADC->RESULT4_f.RESULT4;
break;
case AdcExInputCH5:
*pu16AdcResult = M0P_ADC->RESULT5_f.RESULT5;
break;
case AdcExInputCH6:
*pu16AdcResult = M0P_ADC->RESULT6_f.RESULT6;
break;
case AdcExInputCH7:
*pu16AdcResult = M0P_ADC->RESULT7_f.RESULT7;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
* \brief
* 获取ch8的采样值
* \param [out] pu16AdcResult 采样值指针
*
* \retval en_result_t Ok: 成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_GetCH8Result(uint16_t* pu16AdcResult)
{
if (NULL == pu16AdcResult)
{
return ErrorInvalidParameter;
}
*pu16AdcResult = M0P_ADC->RESULT8_f.RESULT8;
return Ok;
}
/**
* \brief
* 设置ADC参考电压
*
* \param [in] enAdcRefVolSel ADC参考电压
*
* \retval en_result_t Ok: 配置成功
* \retval en_result_t ErrorInvalidParameter: 无效参数
*/
en_result_t Adc_SetVref(en_adc_ref_vol_sel_t enAdcRefVolSel)
{
if (enAdcRefVolSel > RefVolSelAVDD)
{
return ErrorInvalidParameter;
}
M0P_ADC->CR0_f.SREF = enAdcRefVolSel;
return Ok;
}
//@} // AdcGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+1618
View File
File diff suppressed because it is too large. Load diff
+143
View File
@@ -0,0 +1,143 @@
/******************************************************************************
*Copyright(C)2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file bgr.c
**
** Common API of bgr.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "bgr.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief BGR 使能
**
**
** \retval Null
*****************************************************************************/
void Bgr_BgrEnable(void)
{
M0P_BGR->CR |= 0x1u;
delay10us(2);
}
/**
*****************************************************************************
** \brief BGR 禁止
**
**
** \retval Null
*****************************************************************************/
void Bgr_BgrDisable(void)
{
M0P_BGR->CR &= 0x2u;
}
/**
*****************************************************************************
** \brief BGR 温度传感器使能(需要先开启BGR)
**
**
** \retval Null
*****************************************************************************/
void Bgr_TempSensorEnable(void)
{
M0P_BGR->CR |= 0x2u;
delay10us(2);
}
/**
*****************************************************************************
** \brief BGR 温度传感器禁止
**
**
** \retval Null
*****************************************************************************/
void Bgr_TempSensorDisable(void)
{
M0P_BGR->CR &= 0x1u;
}
//@} // BgrGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+529
View File
@@ -0,0 +1,529 @@
/******************************************************************************
*Copyright(C)2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file bt.c
**
** Common API of base timer.
** @link btGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "bt.h"
/**
*******************************************************************************
** \addtogroup BtGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_TIM(x) (TIM0 == (x) ||\
TIM1 == (x) ||\
TIM2 == (x))
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Base Timer 中断标志获取
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Bt_GetIntFlag(en_bt_unit_t enUnit)
{
boolean_t bRetVal = FALSE;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
bRetVal = M0P_TIM0->IFR_f.UIF ? TRUE : FALSE;
break;
case TIM1:
bRetVal = M0P_TIM1->IFR_f.UIF ? TRUE : FALSE;
break;
case TIM2:
bRetVal = M0P_TIM2->IFR_f.UIF ? TRUE : FALSE;
break;
default:
bRetVal = FALSE;
break;
}
return bRetVal;
}
/**
*****************************************************************************
** \brief Base Timer 中断标志清除
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_ClearIntFlag(en_bt_unit_t enUnit)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->ICLR_f.UIF = FALSE;
break;
case TIM1:
M0P_TIM1->ICLR_f.UIF = FALSE;;
break;
case TIM2:
M0P_TIM2->ICLR_f.UIF = FALSE;;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 中断使能
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_EnableIrq (en_bt_unit_t enUnit)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CR_f.UIE = TRUE;
break;
case TIM1:
M0P_TIM1->CR_f.UIE = TRUE;
break;
case TIM2:
M0P_TIM2->CR_f.UIE = TRUE;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 中断禁止
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_DisableIrq(en_bt_unit_t enUnit)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CR_f.UIE = FALSE;
break;
case TIM1:
M0P_TIM1->CR_f.UIE = FALSE;
break;
case TIM2:
M0P_TIM2->CR_f.UIE = FALSE;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 初始化配置
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
** \param [in] pstcCfg 初始化配置结构体指针
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_Init(en_bt_unit_t enUnit, stc_bt_cfg_t* pstcCfg)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
{
M0P_TIM0->CR_f.GATEP = pstcCfg->enGateP;
M0P_TIM0->CR_f.GATE = pstcCfg->enGate;
M0P_TIM0->CR_f.PRS = pstcCfg->enPRS;
M0P_TIM0->CR_f.TOGEN = pstcCfg->enTog;
M0P_TIM0->CR_f.CT = pstcCfg->enCT;
M0P_TIM0->CR_f.MD = pstcCfg->enMD;
}
break;
case TIM1:
{
M0P_TIM1->CR_f.GATEP = pstcCfg->enGateP;
M0P_TIM1->CR_f.GATE = pstcCfg->enGate;
M0P_TIM1->CR_f.PRS = pstcCfg->enPRS;
M0P_TIM1->CR_f.TOGEN = pstcCfg->enTog;
M0P_TIM1->CR_f.CT = pstcCfg->enCT;
M0P_TIM1->CR_f.MD = pstcCfg->enMD;
}
break;
case TIM2:
{
M0P_TIM2->CR_f.GATEP = pstcCfg->enGateP;
M0P_TIM2->CR_f.GATE = pstcCfg->enGate;
M0P_TIM2->CR_f.PRS = pstcCfg->enPRS;
M0P_TIM2->CR_f.TOGEN = pstcCfg->enTog;
M0P_TIM2->CR_f.CT = pstcCfg->enCT;
M0P_TIM2->CR_f.MD = pstcCfg->enMD;
}
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 启动运行
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_Run(en_bt_unit_t enUnit)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CR_f.CTEN = TRUE;
break;
case TIM1:
M0P_TIM1->CR_f.CTEN = TRUE;
break;
case TIM2:
M0P_TIM2->CR_f.CTEN = TRUE;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 停止运行
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_Stop(en_bt_unit_t enUnit)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CR_f.CTEN = FALSE;
break;
case TIM1:
M0P_TIM1->CR_f.CTEN = FALSE;
break;
case TIM2:
M0P_TIM2->CR_f.CTEN = FALSE;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 重载值设置
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
** \param [in] u16Data 16bits重载值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->ARR_f.ARR = u16Data;
break;
case TIM1:
M0P_TIM1->ARR_f.ARR = u16Data;
break;
case TIM2:
M0P_TIM2->ARR_f.ARR = u16Data;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 16位计数器初值设置
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
** \param [in] u16Data 16位初值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CNT_f.CNT = u16Data;
break;
case TIM1:
M0P_TIM1->CNT_f.CNT = u16Data;
break;
case TIM2:
M0P_TIM2->CNT_f.CNT = u16Data;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 16位计数值获取
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval 16bits计数值
*****************************************************************************/
uint16_t Bt_Cnt16Get(en_bt_unit_t enUnit)
{
uint16_t u16CntData = 0;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
u16CntData = M0P_TIM0->CNT_f.CNT;
break;
case TIM1:
u16CntData = M0P_TIM1->CNT_f.CNT;
break;
case TIM2:
u16CntData = M0P_TIM2->CNT_f.CNT;
break;
default:
u16CntData = 0;
break;
}
return u16CntData;
}
/**
*****************************************************************************
** \brief Base Timer 32位计数器初值设置
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
** \param [in] u32Data 32位初值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Bt_Cnt32Set(en_bt_unit_t enUnit, uint32_t u32Data)
{
en_result_t enResult = Ok;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
M0P_TIM0->CNT32_f.CNT32 = u32Data;
break;
case TIM1:
M0P_TIM1->CNT32_f.CNT32 = u32Data;
break;
case TIM2:
M0P_TIM2->CNT32_f.CNT32 = u32Data;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Base Timer 32位计数值获取
**
**
** \param [in] enUnit Timer通道选择(TIM0、TIM1、TIM2)
**
** \retval 32bits计数值
*****************************************************************************/
uint32_t Bt_Cnt32Get(en_bt_unit_t enUnit)
{
uint32_t u32CntData = 0;
ASSERT(IS_VALID_TIM(enUnit));
switch (enUnit)
{
case TIM0:
u32CntData = M0P_TIM0->CNT32_f.CNT32;
break;
case TIM1:
u32CntData = M0P_TIM1->CNT32_f.CNT32;
break;
case TIM2:
u32CntData = M0P_TIM2->CNT32_f.CNT32;
break;
default:
u32CntData = 0;
break;
}
return u32CntData;
}
//@} // BtGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+258
View File
@@ -0,0 +1,258 @@
/******************************************************************************
*Copyright(C)2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file crc.c
**
** Common API of crc.
** @link crcGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "crc.h"
/**
*******************************************************************************
** \addtogroup CrcGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief CRC16 编码(字节填充方式)
**
** 该函数主要用于生成CRC16编码.
**
** \param [in] pu8Data 待编码数据指针(字节方式输入)
** \param [in] u32Len 待编码数据长度(字节数)
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get8(uint8_t* pu8Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->RESULT = 0xFFFF;
for(u32Index = 0;u32Index<u32Len;u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 编码(半字填充方式)
**
** 该函数主要用于生成CRC16编码.
**
** \param [in] pu16Data 待编码数据指针(半字方式输入)
** \param [in] u32Len 待编码数据长度(半字数)
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get16(uint16_t* pu16Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 编码(字填充方式)
**
** 该函数主要用于生成CRC16编码.
**
** \param [in] pu32Data 待编码数据指针(字方式输入)
** \param [in] u32Len 待编码数据长度(字数)
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get32(uint32_t* pu32Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
M0P_CRC->DATA_f.DATA = pu32Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 校验(字节填充方式)
**
** 该函数主要用于对数据及CRC16值进行校验.
**
** \param [in] pu8Data 待校验数据指针(字节方式输入)
** \param [in] u32Len 待校验数据长度(字节数)
** \param [in] u16CRC 待校验CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check8(uint8_t* pu8Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((((uint32_t)u16CRC)>>0)&0xFF);
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)(((uint32_t)u16CRC>>8)&0xFF);
enResult = M0P_CRC->RESULT_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 校验(半字填充方式)
**
** 该函数主要用于对数据及CRC16值进行校验.
**
** \param [in] pu16Data 待校验数据指针(半字方式输入)
** \param [in] u32Len 待校验数据长度(半字数)
** \param [in] u16CRC 待校验CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check16(uint16_t* pu16Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = u16CRC;
enResult = M0P_CRC->RESULT_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 校验(字填充方式)
**
** 该函数主要用于对数据及CRC16值进行校验.
**
** \param [in] pu32Data 待校验数据指针(字方式输入)
** \param [in] u32Len 待校验数据长度(字数)
** \param [in] u16CRC 待校验CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check32(uint32_t* pu32Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = pu32Data[u32Index];
}
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = u16CRC;
enResult = M0P_CRC->RESULT_f.FLAG ? Ok : Error;
return (enResult);
}
//@} // CrcGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+377
View File
@@ -0,0 +1,377 @@
/*******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl.c
**
** Common API of DDL.
** @link ddlGroup Some description @endlink
**
** - 2019-03-03
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/**
******************************************************************************
** \addtogroup DDL Common Functions
******************************************************************************/
//@{
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************/
/* Global variable definitions (declared in header file with 'extern') */
/******************************************************************************/
/******************************************************************************/
/* Local type definitions ('typedef') */
/******************************************************************************/
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Function implementation - global ('extern') and local ('static') */
/******************************************************************************/
#ifndef __DEBUG
#define __DEBUG
//#define __CC_ARM
#endif
uint32_t Log2(uint32_t u32Val)
{
uint32_t u32V1 = 0;
if(0u == u32Val)
{
return 0;
}
while(u32Val > 1u)
{
u32V1++;
u32Val /=2;
}
return u32V1;
}
/**
*******************************************************************************
** \brief Memory clear function for DDL_ZERO_STRUCT()
******************************************************************************/
void ddl_memclr(void *pu8Address, uint32_t u32Count)
{
uint8_t *pu8Addr = (uint8_t *)pu8Address;
if(NULL == pu8Addr)
{
return;
}
while (u32Count--)
{
*pu8Addr++ = 0;
}
}
/**
*****************************************************************************
** \brief Hook function, which is called in polling loops
*****************************************************************************/
void DDL_WAIT_LOOP_HOOK(void)
{
// Place code for triggering Watchdog counters here, if needed
}
/**
*****************************************************************************
** \brief debug printf function.
*****************************************************************************/
void Debug_UartInit(void)
{
#ifdef __DEBUG
//uint32_t u32Pclk1 = 0;
//volatile uint32_t u32ReloadVal = 0;
//
//// UART0_TXD/P35, 19200bps
//M0P_GPIO->P3ADS_f.P35 = 0;
//M0P_GPIO->P35_SEL_f.SEL = 3;
//M0P_GPIO->P3DIR_f.P35 = 0;
//
//u32Pclk1 = Sysctrl_GetPClkFreq();
//u32ReloadVal = 65536 - u32Pclk1 * 2 / 19200 / 32;
//
//M0P_BT0->CR_f.CT = 0;
//M0P_BT0->CR_f.MD = 1;
//M0P_BT0->CR_f.TOG_EN = 1;
//M0P_BT0->ARR = u32ReloadVal;
//M0P_BT0->CNT = u32ReloadVal;
//M0P_BT0->CR_f.TR = 1;
//
//M0P_UART0->SCON_f.DBAUD = 1;
//M0P_UART0->SCON_f.SM01 = 1;
#endif
}
void Debug_Output(uint8_t u8Data)
{
//M0P_UART0->SCON_f.REN = 0;
//M0P_UART0->SBUF = u8Data;
//
//while (TRUE != M0P_UART0->ISR_f.TI)
//{
// ;
//}
//M0P_UART0->ICR_f.TICLR = 0;
}
//#ifdef __DEBUG
///**
// ******************************************************************************
// ** \brief Re-target putchar function
// ******************************************************************************/
//int fputc(int ch, FILE *f)
//{
// if (((uint8_t)ch) == '\n')
// {
// Debug_Output('\r');
// }
// Debug_Output(ch);
// return ch;
//}
//#endif
extern void Debug_UartInit(void);
extern void Debug_Output(uint8_t u8Data);
#if defined (__CC_ARM) //KEIL
#pragma import(__use_no_semihosting)
void _sys_exit(int x)
{
x = x;
}
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef?d in stdio.h. */
FILE __stdout;
#endif
#ifdef __DEBUG
/**
******************************************************************************
** \brief Re-target putchar function
******************************************************************************/
int fputc(int ch, FILE *f)
{
if (((uint8_t)ch) == '\n')
{
Debug_Output('\r');
}
Debug_Output(ch);
return ch;
}
#endif
void _ttywrch(int c)
{
}
int __backspace(void)
{
return 0;
}
/**
* \brief delay1ms
* delay approximately 1ms.
* \param [in] u32Cnt
* \retval void
*/
void delay1ms(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/1000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* \brief delay100us
* delay approximately 100us.
* \param [in] u32Cnt
* \retval void
*/
void delay100us(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/10000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* \brief delay10us
* delay approximately 10us.
* \param [in] u32Cnt
* \retval void
*/
void delay10us(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/100000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* \brief set register bit
*
* \param [in] addr
* \param [in] offset
* \retval void
*/
void SetBit(uint32_t addr, uint32_t offset, boolean_t bFlag)
{
if(TRUE == bFlag)
{
*((volatile uint32_t *)(addr)) |= ((1UL)<<(offset));
}
else
{
*((volatile uint32_t *)(addr)) &= (~(1UL<<(offset)));
}
}
/**
* \brief get register bit
*
* \param [in] addr
* \param [in] offset
* \retval void
*/
boolean_t GetBit(uint32_t addr, uint32_t offset)
{
return ((((*((volatile uint32_t *)(addr))) >> (offset)) & 1u) > 0) ? TRUE : FALSE;
}
//@} // DDL Functions
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+691
View File
@@ -0,0 +1,691 @@
/******************************************************************************
*Copyright(C)2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file flash.c
**
** Common API of flash.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "flash.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define FLASH_END_ADDR (0x00007FFFu)
#define FLASH_BYPASS() M0P_FLASH->BYPASS = 0x5A5A;\
M0P_FLASH->BYPASS = 0xA5A5;
#define FLASH_IE_TRUE (0x03)
#define FLASH_IE_FALSE (0x00)
#define FLASH_TIMEOUT_INIT (0xFFu)
#define FLASH_TIMEOUT_PGM (0xFFu)
#define FLASH_TIMEOUT_ERASE (0xFFu)
#define FLASH_LOCK_ALL (0u)
#define FLASH_UNLOCK_ALL (0xFFFFu)
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/**
******************************************************************************
** \brief FLASH OP
**
** Flash 操作控制数据类型重定义
******************************************************************************/
typedef enum en_flash_op
{
Read = 0u, ///<读配置值
Program = 1u, ///<编程配置值
SectorErase = 2u, ///<扇区擦除配置值
ChipErase = 3u, ///<全片擦除配置值
} en_flash_op_t;
/**
******************************************************************************
** \brief FLASH 编程时间参数配置
**
** FLASH编程时间参数配置数组定义 (4MHz)
******************************************************************************/
const uint32_t pu32PcgTimer4M[] = {
0x20u, //Tnvs
0x17u, //Tpgs
0x1Bu, //Tprog
0x4650u, //Tserase
0x222E0u, //Tmerase
0x18u, //Tprcv
0xF0u, //Tsrcv
0x3E8u //Tmrcv
};
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Flash中断标志获取
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Flash_GetIntFlag(en_flash_int_type_t enFlashIntType)
{
boolean_t bRetVal = FALSE;
if(M0P_FLASH->IFR & enFlashIntType)
{
bRetVal = TRUE;
}
return bRetVal;
}
/**
*****************************************************************************
** \brief Flash中断标志清除
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_ClearIntFlag(en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
M0P_FLASH->ICLR &= ~(uint32_t)enFlashIntType;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Flash中断使能
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_EnableIrq (en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
FLASH_BYPASS();
M0P_FLASH->CR_f.IE |= enFlashIntType;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Flash中断禁止
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_DisableIrq(en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
FLASH_BYPASS();
M0P_FLASH->CR_f.IE &= ~(uint32_t)enFlashIntType;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief FLASH 初始化函数——中断服务程序、编程时间配置及低功耗模式
**
** 该函数用于配置中断服务函数、低功耗模式、根据系统时钟配置FLASH编程时间相关寄存器.
**
** \param [in] u8FreqCfg FLASH编程时钟频率配置(根据HCLK的频率选择配置值):
** 1 - 4MHz;
** 2 - 8MHz;
** 4 - 16MHz;
** 6 - 24MHz;
** 8 - 32MHz;
** other - 无效值
** \param [in] bDpstbEn TRUE - 当系统进入DeepSleep模式,FLASH进入低功耗模式;
** FALSE - 当系统进入DeepSleep模式,FLASH不进入低功耗模式;
**
** \retval Ok 操作成功.
** \retval ErrorInvalidParameter 参数无效.
** \retval ErrorUninitialized 初始化失败。
*****************************************************************************/
en_result_t Flash_Init(uint8_t u8FreqCfg)
{
uint32_t u32Index = 0;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_INIT;
en_result_t enResult = Ok;
uint32_t u32PrgTimer[8] = {0};
volatile uint32_t *pu32PrgTimerReg = (volatile uint32_t*)M0P_FLASH;
if ((1 != u8FreqCfg) && (2 != u8FreqCfg) &&
(4 != u8FreqCfg) && (6 != u8FreqCfg) &&
(8 != u8FreqCfg))
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//flash时间参数配置值计算
for(u32Index=0; u32Index<8; u32Index++)
{
u32PrgTimer[u32Index] = u8FreqCfg * pu32PcgTimer4M[u32Index];
}
//flash时间参数寄存器配置
for(u32Index=0; u32Index<8; u32Index++)
{
u32TimeOut = FLASH_TIMEOUT_INIT;
while(pu32PrgTimerReg[u32Index] != u32PrgTimer[u32Index])
{
if(u32TimeOut--)
{
FLASH_BYPASS();
pu32PrgTimerReg[u32Index] = u32PrgTimer[u32Index];
}
else
{
return ErrorUninitialized;
}
}
}
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 字节写
**
** 用于向FLASH写入1字节数据.
**
** \param [in] u32Addr Flash地址
** \param [in] u8Data 1字节数据
**
** \retval Ok 写入成功.
** \retval ErrorInvalidParameter FLASH地址无效
** \retval ErrorTimeout 操作超时
*****************************************************************************/
en_result_t Flash_WriteByte(uint32_t u32Addr, uint8_t u8Data)
{
en_result_t enResult = Ok;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
if (FLASH_END_ADDR < u32Addr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//set OP
u32TimeOut = FLASH_TIMEOUT_PGM;
while(Program != M0P_FLASH->CR_f.OP)
{
if(u32TimeOut--)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
}
else
{
return ErrorTimeout;
}
}
//Flash 解锁
Flash_UnlockAll();
//write data
*((volatile uint8_t*)u32Addr) = u8Data;
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 加锁
Flash_LockAll();
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 半字写
**
** 用于向FLASH写入半字(2字节)数据.
**
** \param [in] u32Addr Flash地址
** \param [in] u16Data 半字(2字节)数据
**
** \retval Ok 写入成功.
** \retval ErrorInvalidParameter FLASH地址无效
** \retval ErrorTimeout 操作超时
*****************************************************************************/
en_result_t Flash_WriteHalfWord(uint32_t u32Addr, uint16_t u16Data)
{
en_result_t enResult = Ok;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
if (FLASH_END_ADDR < u32Addr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//set OP
u32TimeOut = FLASH_TIMEOUT_PGM;
while(Program != M0P_FLASH->CR_f.OP)
{
if(u32TimeOut--)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
}
else
{
return ErrorTimeout;
}
}
//Flash 解锁
Flash_UnlockAll();
//write data
*((volatile uint16_t*)u32Addr) = u16Data;
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 加锁
Flash_LockAll();
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 字写
**
** 用于向FLASH写入1个字的数据.
**
** \param [in] u32Addr Flash地址
** \param [in] u32Data 1个字数据
**
** \retval Ok 写入成功.
** \retval ErrorInvalidParameter FLASH地址无效
** \retval ErrorTimeout 操作超时
*****************************************************************************/
en_result_t Flash_WriteWord(uint32_t u32Addr, uint32_t u32Data)
{
en_result_t enResult = Ok;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
if (FLASH_END_ADDR < u32Addr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 解锁
Flash_UnlockAll();
//set OP
u32TimeOut = FLASH_TIMEOUT_PGM;
while(Program != M0P_FLASH->CR_f.OP)
{
if(u32TimeOut--)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
}
else
{
return ErrorTimeout;
}
}
//write data
*((volatile uint32_t*)u32Addr) = u32Data;
//busy?
u32TimeOut = FLASH_TIMEOUT_PGM;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 加锁
Flash_LockAll();
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 扇区擦除
**
** FLASH 扇区擦除.
**
** \param [in] u32SectorAddr 所擦除扇区内的地址
**
** \retval Ok 擦除成功.
** \retval ErrorInvalidParameter FLASH地址无效
** \retval ErrorTimeout 操作超时
*****************************************************************************/
en_result_t Flash_SectorErase(uint32_t u32SectorAddr)
{
en_result_t enResult = Ok;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_ERASE;
if (FLASH_END_ADDR < u32SectorAddr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//busy?
u32TimeOut = FLASH_TIMEOUT_ERASE;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 解锁
Flash_UnlockAll();
//set OP
u32TimeOut = FLASH_TIMEOUT_ERASE;
while(SectorErase != M0P_FLASH->CR_f.OP)
{
if(u32TimeOut--)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = SectorErase;
}
else
{
return ErrorTimeout;
}
}
//write data
*((volatile uint8_t*)u32SectorAddr) = 0;
//busy?
u32TimeOut = FLASH_TIMEOUT_ERASE;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 加锁
Flash_LockAll();
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 全片擦除(该函数仅限RAM中运行!!!)
**
** FLASH 全片擦除.
**
**
** \retval Ok 擦除成功.
** \retval ErrorTimeout 操作超时
**
*****************************************************************************/
en_result_t Flash_ChipErase(void)
{
en_result_t enResult = Ok;
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_ERASE;
//busy?
u32TimeOut = FLASH_TIMEOUT_ERASE;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//set OP
u32TimeOut = FLASH_TIMEOUT_ERASE;
while(ChipErase != M0P_FLASH->CR_f.OP)
{
if(u32TimeOut--)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = ChipErase;
}
else
{
return ErrorTimeout;
}
}
//Flash 解锁
Flash_UnlockAll();
//write data
*((volatile uint8_t*)0) = 0;
//busy?
u32TimeOut = FLASH_TIMEOUT_ERASE;
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
if(0 == u32TimeOut--)
{
return ErrorTimeout;
}
}
//Flash 加锁
Flash_LockAll();
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH 编程保护加锁
**
**
** \retval Null
*****************************************************************************/
void Flash_LockAll(void)
{
FLASH_BYPASS();
M0P_FLASH->SLOCK = FLASH_LOCK_ALL;
}
/**
*****************************************************************************
** \brief FLASH 编程保护解锁
**
**
** \retval Null
*****************************************************************************/
void Flash_UnlockAll(void)
{
FLASH_BYPASS();
M0P_FLASH->SLOCK = FLASH_UNLOCK_ALL;
}
/**
*****************************************************************************
** \brief FLASH 读等待周期设置
**
** \param [in] enWaitCycle 插入FLASH读等待周期数枚举类型
**
** \retval Ok 解锁成功
** \retval ErrorInvalidParameter 参数错误
*****************************************************************************/
en_result_t Flash_WaitCycle(en_flash_waitcycle_t enWaitCycle)
{
en_result_t enResult = Ok;
FLASH_BYPASS();
M0P_FLASH->CR_f.WAIT = enWaitCycle;
return enResult;
}
/**
*****************************************************************************
** \brief FLASH LOCK 设置
**
** \param [in] u32LockValue 32bits,对应bit=0:加锁,对应Sector不允许擦写;对应bit=1:解锁。
** \note 加解锁范围Sector:[i*4, i*4+3]
** (i表示u32LockValue的bit位置,0~31)
** 例如:u32LockValue = 0x00000002,
** 则加解锁范围为:[Sector8,Sector11]
** \retval Ok 解锁成功
** \retval ErrorInvalidParameter 参数错误
*****************************************************************************/
en_result_t Flash_LockSet(uint32_t u32LockValue)
{
FLASH_BYPASS();
M0P_FLASH->SLOCK = u32LockValue;
return Ok;
}
//@} // FlashGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+437
View File
@@ -0,0 +1,437 @@
/******************************************************************************
* Copyright (C) 2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file Gpio.c
**
** GPIO driver API.
** @link Driver Group Some description @endlink
**
** - 2018-04-22 1.0 Lux First version
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "gpio.h"
/**
*******************************************************************************
** \addtogroup GpioGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_PIN(port,pin) ( )
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern') *
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief GPIO 初始化
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] pstcGpioCfg IO 配置结构体指针
**
** \retval Ok 设置成功
** 其他值 设置失败
******************************************************************************/
en_result_t Gpio_Init(en_gpio_port_t enPort, en_gpio_pin_t enPin, stc_gpio_cfg_t *pstcGpioCfg)
{
//配置为默认值,GPIO功能
SetBit((uint32_t)&M0P_GPIO->P0ADS + enPort, enPin, FALSE);
*((uint32_t*)(((uint32_t)((&(M0P_GPIO->P01_SEL)) - 1u) + enPort) + (((uint32_t)enPin)<<2))) = GpioAf0;
//默认输出值配置
SetBit(((uint32_t)&M0P_GPIO->P0OUT + enPort), enPin, pstcGpioCfg->bOutputVal);
//方向配置
SetBit(((uint32_t)&M0P_GPIO->P0DIR + enPort), enPin, (boolean_t)(pstcGpioCfg->enDir));
//驱动能力配置
SetBit(((uint32_t)&M0P_GPIO->P0DR + enPort), enPin, (boolean_t)(pstcGpioCfg->enDrv));
//上拉/下拉配置
SetBit(((uint32_t)&M0P_GPIO->P0PU + enPort), enPin, (boolean_t)(pstcGpioCfg->enPu));
SetBit(((uint32_t)&M0P_GPIO->P0PD + enPort), enPin, (boolean_t)(pstcGpioCfg->enPd));
//开漏输出功能
SetBit(((uint32_t)&M0P_GPIO->P0OD + enPort), enPin, (boolean_t)(pstcGpioCfg->enOD));
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO输入值获取
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval boolean_t IO电平高低
******************************************************************************/
boolean_t Gpio_GetInputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return GetBit(((uint32_t)&M0P_GPIO->P0IN + enPort), enPin);
}
/**
*******************************************************************************
** \brief GPIO IO Port输入数据获取
**
** \param [in] enPort IO Port
**
** \retval boolean_t IO Port数据
******************************************************************************/
uint16_t Gpio_GetInputData(en_gpio_port_t enPort)
{
return (uint16_t)(*((uint32_t *)((uint32_t)&M0P_GPIO->P0IN + enPort)));
}
/**
*******************************************************************************
** \brief GPIO IO输出值写入
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [out] bVal 输出值
**
** \retval en_result_t Ok 设置成功
** 其他值 设置失败
******************************************************************************/
en_result_t Gpio_WriteOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin, boolean_t bVal)
{
SetBit(((uint32_t)&M0P_GPIO->P0OUT + enPort), enPin, bVal);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO输出值获取
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval boolean_t IO电平高低
******************************************************************************/
boolean_t Gpio_ReadOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return GetBit(((uint32_t)&M0P_GPIO->P0OUT + enPort), enPin);
}
/**
*******************************************************************************
** \brief GPIO IO配置为模拟功能模式
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval Ok 设置成功
** 其他值 设置失败
******************************************************************************/
en_result_t Gpio_SetAnalogMode(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
SetBit((uint32_t)&M0P_GPIO->P0ADS + enPort, enPin, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO复用功能设置
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enAf 复用功能枚举类型选择
** \retval Ok 设置成功
** 其他值 设置失败
******************************************************************************/
en_result_t Gpio_SetAfMode(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_af_t enAf)
{
*((uint32_t*)(((uint32_t)((&(M0P_GPIO->P01_SEL)) - 1u) + enPort) + (((uint32_t)enPin)<<2))) = enAf;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO中断使能
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enType 中断使能类型
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_EnableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
{
uint32_t u32PieAddr;
u32PieAddr = ((uint32_t)((&M0P_GPIO->P0HIE) + enType)) + enPort;
SetBit(u32PieAddr, enPin, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO中断关闭
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enType 中断使能类型
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_DisableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
{
uint32_t u32PieAddr;
u32PieAddr = ((uint32_t)((&M0P_GPIO->P0HIE) + enType)) + enPort;
SetBit(u32PieAddr, enPin, FALSE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 获得IO中断状态
**
** \param [in] u8Port IO Port口
** \param [in] u8Pin IO Pin脚
**
** \retval IO中断状态开关
******************************************************************************/
boolean_t Gpio_GetIrqStatus(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return GetBit((uint32_t)&M0P_GPIO->P0STAT + enPort, enPin);
}
/**
*******************************************************************************
** \brief GPIO 清除IO中断状态
**
** \param [in] u8Port IO Port口
** \param [in] u8Pin IO Pin脚
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_ClearIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
SetBit((uint32_t)&M0P_GPIO->P0ICLR + enPort, enPin, FALSE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——中断模式配置
**
** \param [in] enIrqMode 端口中断模式
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfIrqModeCfg(en_gpio_sf_irqmode_t enIrqMode)
{
M0P_GPIO->CTRL0_f.IESEL = enIrqMode;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——IR输出极性配置
**
** \param [in] enIrPolMode IR输出极性配置枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfIrPolCfg(en_gpio_sf_irpol_t enIrPolMode)
{
M0P_GPIO->CTRL1_f.IR_POL = enIrPolMode;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——HCLK输出配置
**
** \param [in] enGate HCLK输出使能
** \param [in] enDiv 输出分频枚举值
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfHClkOutputCfg(en_gpio_sf_hclkout_g_t enGate, en_gpio_sf_hclkout_div_t enDiv)
{
M0P_GPIO->CTRL1_f.HCLK_EN = enGate;
M0P_GPIO->CTRL1_f.HCLK_SEL = enDiv;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——PCLK输出配置
**
** \param [in] enGate PCLK输出使能
** \param [in] enDiv 输出分频枚举值
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfPClkOutputCfg(en_gpio_sf_pclkout_g_t enGate, en_gpio_sf_pclkout_div_t enDiv)
{
M0P_GPIO->CTRL1_f.PCLK_EN = enGate;
M0P_GPIO->CTRL1_f.PCLK_SEL = enDiv;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——外部时钟输入来源配置
**
** \param [in] enExtClk 外部时钟信号来源选择枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfExtClkCfg(en_gpio_sf_ssn_extclk_t enExtClk)
{
M0P_GPIO->CTRL1_f.EXT_CLK_SEL = enExtClk;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——SSN 通道信号来源配置
**
** \param [in] enSsn SSN 信号来源选择枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfSsnCfg(en_gpio_sf_ssn_extclk_t enSsn)
{
M0P_GPIO->CTRL1_f.SSN_SEL = enSsn;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——Timer 门控输入配置
**
** \param [in] enTimG Timer类型选择枚举
** \param [in] enSf Timer互联功能选择枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfTimGCfg(en_gpio_sf_tim_g_t enTimG, en_gpio_sf_t enSf)
{
M0P_GPIO->CTRL4 &= (uint32_t)(~(0x03U<<enTimG));
M0P_GPIO->CTRL4 |= (uint32_t)(enSf<<enTimG);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——Timer 捕获输入选择配置
**
** \param [in] enTimC Timer类型选择枚举
** \param [in] enSf Timer互联功能选择枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfTimCCfg(en_gpio_sf_tim_c_t enTimC, en_gpio_sf_t enSf)
{
M0P_GPIO->CTRL3 &= (uint32_t)(~(0x03u<<enTimC));
M0P_GPIO->CTRL3 |= (uint32_t)(enSf<<enTimC);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO 端口辅助功能配置——PCA 捕获输入选择配置
**
** \param [in] enPca PCA类型选择枚举
** \param [in] enSf PCA互联功能选择枚举
**
** \retval Ok 设置成功
******************************************************************************/
en_result_t Gpio_SfPcaCfg(en_gpio_sf_pca_t enPca, en_gpio_sf_t enSf)
{
M0P_GPIO->CTRL2 &= (uint32_t)(~(0x03u<<enPca));
M0P_GPIO->CTRL2 |= (uint32_t)(enSf<<enPca);
return Ok;
}
//@} // GpioGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+259
View File
@@ -0,0 +1,259 @@
/*************************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file I2C.c
**
** WDT function driver API.
** @link SampleGroup Some description @endlink
**
** - 2018-03-13 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "i2c.h"
/**
*******************************************************************************
** \addtogroup I2cGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief I2C设置波特率配置寄存器
**
** \param [in] u8Tm 波特率配置值
**
** \retval enRet 成功或失败
**
******************************************************************************/
en_result_t I2C_SetBaud(M0P_I2C_TypeDef* I2Cx, uint8_t u8Tm)
{
en_result_t enRet = Error;
I2Cx->TM = u8Tm;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C功能设置相关函数
**
** \param [in] enFunc功能参数
**
** \retval enRet 成功或失败
**
******************************************************************************/
en_result_t I2C_SetFunc(M0P_I2C_TypeDef* I2Cx, en_i2c_func_t enFunc)
{
en_result_t enRet = Error;
SetBit((uint32_t)&I2Cx->CR, enFunc, TRUE);
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C功能清除相关函数
**
** \param [in] enFunc功能参数
**
** \retval enRet 成功或失败
**
******************************************************************************/
en_result_t I2C_ClearFunc(M0P_I2C_TypeDef* I2Cx, en_i2c_func_t enFunc)
{
en_result_t enRet = Error;
SetBit((uint32_t)&I2Cx->CR, enFunc, FALSE);
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C获取中断标记函数
**
** \param 无
**
** \retval bIrq中断标记
**
******************************************************************************/
boolean_t I2C_GetIrq(M0P_I2C_TypeDef* I2Cx)
{
if(I2Cx->CR&0x8)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
******************************************************************************
** \brief I2C清除中断标记函数
**
** \param 无
**
** \retval bIrq中断标记
**
******************************************************************************/
en_result_t I2C_ClearIrq(M0P_I2C_TypeDef* I2Cx)
{
en_result_t enRet = Error;
I2Cx->CR &= ~0x8u;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C获取相关状态
**
** \param 无
**
** \retval I2C状态
**
******************************************************************************/
uint8_t I2C_GetState(M0P_I2C_TypeDef* I2Cx)
{
uint8_t u8State = 0;
u8State = I2Cx->STAT;
return u8State;
}
/**
******************************************************************************
** \brief 字节数据写函数
**
** \param u8Data写数据
**
** \retval 写数据是否成功
**
******************************************************************************/
en_result_t I2C_WriteByte(M0P_I2C_TypeDef* I2Cx, uint8_t u8Data)
{
en_result_t enRet = Error;
I2Cx->DATA = u8Data;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief 字节数据读函数
**
** \param 无
**
** \retval 读取数据
**
******************************************************************************/
uint8_t I2C_ReadByte(M0P_I2C_TypeDef* I2Cx)
{
uint8_t u8Data = 0;
u8Data = I2Cx->DATA;
return u8Data;
}
/**
******************************************************************************
** \brief I2C模块初始化
**
** \param pstcI2CCfg初始化配置结构体
**
** \retval 初始化是否成功
**
******************************************************************************/
en_result_t I2C_Init(M0P_I2C_TypeDef* I2Cx, stc_i2c_cfg_t *pstcI2CCfg)
{
en_result_t enRet = Error;
uint8_t u8Tm;
M0P_RESET->PERI_RESET &= ~(uint32_t)0x10u;
M0P_RESET->PERI_RESET |= (uint32_t)0x10u;
I2Cx->CR = 0;
I2Cx->CR = pstcI2CCfg->enMode;
if((pstcI2CCfg->u32Baud<<4) > pstcI2CCfg->u32Pclk)
{
return Error;
}
if(I2cMasterMode == pstcI2CCfg->enMode)
{
I2Cx->TMRUN = TRUE;
///< Fsck = Fpclk/8*(Tm+1)
u8Tm = ((pstcI2CCfg->u32Pclk / pstcI2CCfg->u32Baud) >> 3) - 1;
if(9 > u8Tm)
{
I2C_SetFunc(I2Cx,I2cHlm_En);
}
enRet = I2C_SetBaud(I2Cx, u8Tm);
}
else
{
I2Cx->TMRUN = FALSE;
pstcI2CCfg->u8SlaveAddr = (uint8_t)(((uint32_t)pstcI2CCfg->u8SlaveAddr<<1)|(pstcI2CCfg->bGc));
I2Cx->ADDR = pstcI2CCfg->u8SlaveAddr;
}
return enRet;
}
//@} // I2cGroup
+122
View File
@@ -0,0 +1,122 @@
/******************************************************************************
*Copyright(C)2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file lpm.c
**
** Common API of lpm.
** @link LpmGroup Some description @endlink
**
** - 2017-06-06
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "lpm.h"
/**
*******************************************************************************
** \addtogroup LpmGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief 进入深度睡眠模式
**
** \input bOnExit - TRUE:当退出异常处理后,自动再次进入休眠;
** FALSE:唤醒后不再自动进入休眠
**
** \retval NULL
*****************************************************************************/
void Lpm_GotoDeepSleep(boolean_t bOnExit)
{
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
SCB->SCR |= 1u<<bOnExit;
__WFI();
}
/**
*****************************************************************************
** \brief 进入普通睡眠模式
**
** \input bOnExit - TRUE:当退出异常处理后,自动再次进入休眠;
** FALSE:唤醒后不再自动进入休眠
**
** \retval NULL
*****************************************************************************/
void Lpm_GotoSleep(boolean_t bOnExit)
{
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
SCB->SCR |= 1u<<bOnExit;
__WFI();
}
//@} // LpmGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+205
View File
@@ -0,0 +1,205 @@
/******************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lvd.c
**
** Low Voltage Detect driver API.
** @link Lvd Group Some description @endlink
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "lvd.h"
/**
******************************************************************************
** \addtogroup LvdGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_INPUT(x) ( (x) <= LvdInputP25 )
#define IS_VALID_THRESHOLD(x) ( (x) <= LvdTH3p3V )
#define IS_VALID_FILTER(x) ( (x) <= LvdFilter29ms )
#define IS_VALID_IRQTYPE(x) ( (x) <= LvdIrqFall )
/******************************************************************************
* Global variable definitions (declared in header file with 'extern') *
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
// static void LvdEnableNvic(void);
// static void LvdDisableNvic(void);
// static en_result_t LvdEnable(en_lvd_type_t enType, boolean_t bFlag);
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
/**
* \brief
* 使能LVD中断
*
* \param [in] enType LVD中断类型
*
* \retval en_result_t Ok: 设置成功
* \retval en_result_t ErrorInvalidParameter: 无效类型
*/
void Lvd_EnableIrq(void)
{
M0P_LVD->CR_f.IE = TRUE;
}
/**
* \brief
* 除能LVD中断
*
* \param 无
*
* \retval 无
*/
void Lvd_DisableIrq(void)
{
M0P_LVD->CR_f.IE = FALSE;
}
/**
* \brief
* LVD初始化
*
* \param [in] pstcCfg LVD配置指针
*
* \retval 无
*/
void Lvd_Init(stc_lvd_cfg_t *pstcCfg)
{
M0P_LVD->CR = 0;
M0P_LVD->CR = (uint32_t)pstcCfg->enAct |
(uint32_t)pstcCfg->enFilter |
(uint32_t)pstcCfg->enFilterTime |
(uint32_t)pstcCfg->enInputSrc |
(uint32_t)pstcCfg->enIrqType |
(uint32_t)pstcCfg->enThreshold;
}
/**
* \brief
* 使能LVD
*
* \param 无
*
* \retval 无
*
*/
void Lvd_Enable(void)
{
M0P_LVD->CR_f.LVDEN = 1u;
}
/**
* \brief
* 除能LVD
*
* \param 无
*
* \retval 无
*/
void Lvd_Disable(void)
{
M0P_LVD->CR_f.LVDEN = 0u;
}
/**
* \brief
* 获取LVD中断标志
*
* \param 无
*
* \retval boolean_t 中断标志
*/
boolean_t Lvd_GetIrqStat(void)
{
return M0P_LVD->IFR_f.INTF;
}
/**
* \brief
* 清除LVD中断标志
*
* \param 无
*
* \retval 无
*/
void Lvd_ClearIrq(void)
{
M0P_LVD->IFR_f.INTF = 0u;
}
//@} // LvdGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+532
View File
@@ -0,0 +1,532 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file pca.c
**
** pca driver API.
** @link pcnt Group Some description @endlink
**
** - 2019-04-09 First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "pca.h"
/**
******************************************************************************
** \addtogroup PCNTGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/**
******************************************************************************
** \brief 获取中断源的标志位
** @param IT_Src : 中断源标志位
** \retval FALSE 或TRUE
**
******************************************************************************/
boolean_t Pca_GetItStatus(en_pca_ccficlr_t It_Src)
{
return (((M0P_PCA->CCON)>>It_Src) & 1) > 0? TRUE : FALSE;
}
/**
******************************************************************************
** \brief 清除中断源的标志位
** @param IT_Src : 中断源标志位
** \retval 无
**
******************************************************************************/
void Pca_ClrItStatus(en_pca_ccficlr_t It_Src)
{
M0P_PCA->ICLR &= ~(uint32_t)(1<<It_Src);
}
/**
******************************************************************************
** \brief PCA 计数器运行控制 PCA_CCON CR控制位
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Pca_StartPca(boolean_t NewStatus)
{
SetBit((uint32_t)(&(M0P_PCA->CCON)), 6, NewStatus);
}
/**
******************************************************************************
** \brief PCA 空闲模式IDLE下,PCA是否停止工作设置
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Pca_SetCidl(boolean_t NewStatus)
{
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 7, NewStatus);
}
/**
******************************************************************************
** \brief PCA 模块4的看门狗使能控制
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Pca_Set4Wdte(boolean_t NewStatus)
{
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 6, NewStatus);
}
/**
******************************************************************************
** \brief PCA 计数器中断控制PCA_CMOD中CFIE,对应的控制中断位PCA_CCON中的CF与PCA_ICLR中的CF
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Pca_ConfPcaIt(boolean_t NewStatus)
{
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 0, NewStatus);
}
/**
******************************************************************************
** \brief PCA 比较捕获中断使能控制 PCA_CCAPMx的CCIE
** @param Modulex : pca_module0~4
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Pca_ConfModulexIt(en_pca_module_t Modulex, boolean_t NewStatus)
{
switch(Modulex)
{
case PcaModule0:
SetBit((uint32_t)(&(M0P_PCA->CCAPM0)), 0, NewStatus);
break;
case PcaModule1:
SetBit((uint32_t)(&(M0P_PCA->CCAPM1)), 0, NewStatus);
break;
case PcaModule2:
SetBit((uint32_t)(&(M0P_PCA->CCAPM2)), 0, NewStatus);
break;
case PcaModule3:
SetBit((uint32_t)(&(M0P_PCA->CCAPM3)), 0, NewStatus);
break;
case PcaModule4:
SetBit((uint32_t)(&(M0P_PCA->CCAPM4)), 0, NewStatus);
break;
default:
break;
}
}
/**
******************************************************************************
** \brief PCA 模块0的初始化
** @param InitStruct : PCA初始化配置的结构体
** \retval 无
**
******************************************************************************/
void Pca_M0Init(stc_pcacfg_t* InitStruct)
{
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
M0P_PCA->CCAPM0_f.ECOM = InitStruct->pca_ecom;
M0P_PCA->CCAPM0_f.CAPP = InitStruct->pca_capp;
M0P_PCA->CCAPM0_f.CAPN = InitStruct->pca_capn;
M0P_PCA->CCAPM0_f.MAT = InitStruct->pca_mat;
M0P_PCA->CCAPM0_f.TOG = InitStruct->pca_tog;
M0P_PCA->CCAPM0_f.PWM = InitStruct->pca_pwm;
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
{
M0P_PCA->CCAP0L_f.CCAP0 = InitStruct->pca_ccapl;
M0P_PCA->CCAP0H_f.CCAP0 = InitStruct->pca_ccaph;
}
else
{
M0P_PCA->CCAP0_f.CCAP0 = InitStruct->pca_ccap;
}
}
/**
******************************************************************************
** \brief PCA 模块1的初始化
** @param InitStruct : PCA初始化配置的结构体
** \retval 无
**
******************************************************************************/
void Pca_M1Init(stc_pcacfg_t* InitStruct)
{
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
M0P_PCA->CCAPM1_f.ECOM = InitStruct->pca_ecom;
M0P_PCA->CCAPM1_f.CAPP = InitStruct->pca_capp;
M0P_PCA->CCAPM1_f.CAPN = InitStruct->pca_capn;
M0P_PCA->CCAPM1_f.MAT = InitStruct->pca_mat;
M0P_PCA->CCAPM1_f.TOG = InitStruct->pca_tog;
M0P_PCA->CCAPM1_f.PWM = InitStruct->pca_pwm;
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
{
M0P_PCA->CCAP1L_f.CCAP1 = InitStruct->pca_ccapl;
M0P_PCA->CCAP1H_f.CCAP1 = InitStruct->pca_ccaph;
}
else
{
M0P_PCA->CCAP1_f.CCAP1 = InitStruct->pca_ccap;
}
}
/**
******************************************************************************
** \brief PCA 模块2的初始化
** @param InitStruct : PCA初始化配置的结构体
** \retval 无
**
******************************************************************************/
void Pca_M2Init(stc_pcacfg_t* InitStruct)
{
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
M0P_PCA->CCAPM2_f.ECOM = InitStruct->pca_ecom;
M0P_PCA->CCAPM2_f.CAPP = InitStruct->pca_capp;
M0P_PCA->CCAPM2_f.CAPN = InitStruct->pca_capn;
M0P_PCA->CCAPM2_f.MAT = InitStruct->pca_mat;
M0P_PCA->CCAPM2_f.TOG = InitStruct->pca_tog;
M0P_PCA->CCAPM2_f.PWM = InitStruct->pca_pwm;
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
{
M0P_PCA->CCAP2L_f.CCAP2 = InitStruct->pca_ccapl;
M0P_PCA->CCAP2H_f.CCAP2 = InitStruct->pca_ccaph;
}
else
{
M0P_PCA->CCAP2_f.CCAP2 = InitStruct->pca_ccap;
}
}
/**
******************************************************************************
** \brief PCA 模块3的初始化
** @param InitStruct : PCA初始化配置的结构体
** \retval 无
**
******************************************************************************/
void Pca_M3Init(stc_pcacfg_t* InitStruct)
{
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
M0P_PCA->CCAPM3_f.ECOM = InitStruct->pca_ecom;
M0P_PCA->CCAPM3_f.CAPP = InitStruct->pca_capp;
M0P_PCA->CCAPM3_f.CAPN = InitStruct->pca_capn;
M0P_PCA->CCAPM3_f.MAT = InitStruct->pca_mat;
M0P_PCA->CCAPM3_f.TOG = InitStruct->pca_tog;
M0P_PCA->CCAPM3_f.PWM = InitStruct->pca_pwm;
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
{
M0P_PCA->CCAP3L_f.CCAP3 = InitStruct->pca_ccapl;
M0P_PCA->CCAP3H_f.CCAP3 = InitStruct->pca_ccaph;
}
else
{
M0P_PCA->CCAP3_f.CCAP3 = InitStruct->pca_ccap;
}
}
/**
******************************************************************************
** \brief PCA 模块4的初始化
** @param InitStruct : PCA初始化配置的结构体
** \retval 无
**
******************************************************************************/
void Pca_M4Init(stc_pcacfg_t* InitStruct)
{
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
M0P_PCA->CCAPM4_f.ECOM = InitStruct->pca_ecom;
M0P_PCA->CCAPM4_f.CAPP = InitStruct->pca_capp;
M0P_PCA->CCAPM4_f.CAPN = InitStruct->pca_capn;
M0P_PCA->CCAPM4_f.MAT = InitStruct->pca_mat;
M0P_PCA->CCAPM4_f.TOG = InitStruct->pca_tog;
M0P_PCA->CCAPM4_f.PWM = InitStruct->pca_pwm;
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
{
M0P_PCA->CCAP4L_f.CCAP4 = InitStruct->pca_ccapl;
M0P_PCA->CCAP4H_f.CCAP4 = InitStruct->pca_ccaph;
}
else
{
M0P_PCA->CCAP4_f.CCAP4 = InitStruct->pca_ccap;
}
}
/**
******************************************************************************
** \brief PCA 读取CNT寄存器的数值
** @param 无
** \retval CNT的低半字值
**
******************************************************************************/
uint16_t Pca_GetCnt(void)
{
return (uint16_t)(M0P_PCA->CNT);
}
/**
******************************************************************************
** \brief PCA 向CNT寄存器写入数值
** @param cnt : 所要写入的数值
** \retval 无
**
******************************************************************************/
void Pca_SetCnt(uint16_t cnt)
{
if(GetBit((uint32_t)(&(M0P_PCA->CCON)), 6)==TRUE)
{
Pca_StartPca(FALSE);
M0P_PCA->CNT_f.CNT = cnt;
Pca_StartPca(TRUE);
}
else
{
M0P_PCA->CNT_f.CNT = cnt;
}
}
/**
******************************************************************************
** \brief PCA 返回指定通道比较高速输出标志寄存器的值
** @param Modulex : 通道号x=0、1、2、3、4
** \retval TRUE 或 FALSE
**
******************************************************************************/
boolean_t Pca_GetOut(en_pca_module_t Modulex)
{
return GetBit((uint32_t)(&(M0P_PCA->CCAPO)), Modulex);
}
/**
******************************************************************************
** \brief PCA 设置比较捕获16位寄存器CCAPx数值
** @param Modulex : 通道号x=0、1、2、3、4
** @param Value: 所要设置的值
** \retval 无
**
******************************************************************************/
void Pca_SetCcap(en_pca_module_t Modulex, uint16_t Value)
{
switch(Modulex)
{
case 0:
M0P_PCA->CCAP0_f.CCAP0 = Value;
break;
case 1:
M0P_PCA->CCAP1_f.CCAP1 = Value;
break;
case 2:
M0P_PCA->CCAP2_f.CCAP2 = Value;
break;
case 3:
M0P_PCA->CCAP3_f.CCAP3 = Value;
break;
case 4:
M0P_PCA->CCAP4_f.CCAP4 = Value;
break;
default:
break;
}
}
/**
******************************************************************************
** \brief PCA 读取比较捕获16位寄存器CCAPx数值
** @param Modulex : 通道号x=0、1、2、3、4
** \retval CCAPx的值,x=0、1、2、3、4
**
******************************************************************************/
uint16_t Pca_GetCcap(en_pca_module_t Modulex)
{
uint16_t tmp;
switch(Modulex)
{
case 0:
tmp = M0P_PCA->CCAP0_f.CCAP0;
break;
case 1:
tmp = M0P_PCA->CCAP1_f.CCAP1;
break;
case 2:
tmp = M0P_PCA->CCAP2_f.CCAP2;
break;
case 3:
tmp = M0P_PCA->CCAP3_f.CCAP3;
break;
case 4:
tmp = M0P_PCA->CCAP4_f.CCAP4;
break;
default:
break;
}
return tmp;
}
/**
******************************************************************************
** \brief PCA 设置比较捕获寄存器的高8位和低8位
** @param Modulex : 通道号x=0、1、2、3、4
** @param ValueH : 要写入高8位的数值
** @param ValueL : 要写入低8位的数值
** \retval 无
**
******************************************************************************/
void Pca_SetCcapHL(en_pca_module_t Modulex, uint8_t ValueH, uint8_t ValueL)
{
switch(Modulex)
{
case 0:
M0P_PCA->CCAP0H_f.CCAP0 = ValueH;
M0P_PCA->CCAP0L_f.CCAP0 = ValueL;
break;
case 1:
M0P_PCA->CCAP1H_f.CCAP1 = ValueH;
M0P_PCA->CCAP1L_f.CCAP1 = ValueL;
break;
case 2:
M0P_PCA->CCAP2H_f.CCAP2 = ValueH;
M0P_PCA->CCAP2L_f.CCAP2 = ValueL;
break;
case 3:
M0P_PCA->CCAP3H_f.CCAP3 = ValueH;
M0P_PCA->CCAP3L_f.CCAP3 = ValueL;
break;
case 4:
M0P_PCA->CCAP4H_f.CCAP4 = ValueH;
M0P_PCA->CCAP4L_f.CCAP4 = ValueL;
break;
default:
break;
}
}
/**
******************************************************************************
** \brief PCA 读取比较捕获寄存器的高8位和低8位
** @param Modulex : 通道号x=0、1、2、3、4
** @param ValueH : CCAPx高8位的数值
** @param ValueL : CCAPx低8位的数值
** \retval 无
**
******************************************************************************/
void Pca_GetCcapHL(en_pca_module_t Modulex, uint8_t *ValueH, uint8_t *ValueL)
{
switch(Modulex)
{
case 0:
*ValueH = M0P_PCA->CCAP0H_f.CCAP0;
*ValueL = M0P_PCA->CCAP0L_f.CCAP0;
break;
case 1:
*ValueH = M0P_PCA->CCAP1H_f.CCAP1;
*ValueL = M0P_PCA->CCAP1L_f.CCAP1;
break;
case 2:
*ValueH = M0P_PCA->CCAP2H_f.CCAP2;
*ValueL = M0P_PCA->CCAP2L_f.CCAP2;
break;
case 3:
*ValueH = M0P_PCA->CCAP3H_f.CCAP3;
*ValueL = M0P_PCA->CCAP3L_f.CCAP3;
break;
case 4:
*ValueH = M0P_PCA->CCAP4H_f.CCAP4;
*ValueL = M0P_PCA->CCAP4L_f.CCAP4;
break;
default:
break;
}
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+156
View File
@@ -0,0 +1,156 @@
/******************************************************************************
*Copyright(C)2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file ram.c
**
** Common API of ram.
** @link RamGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "ram.h"
/**
*******************************************************************************
** \addtogroup ramGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Ram奇偶校验出错地址获取
**
**
** \retval ERROR ADDRESS
*****************************************************************************/
uint32_t Ram_ErrAddrGet(void)
{
return M0P_RAM->ERRADDR;
}
/**
*****************************************************************************
** \brief Ram中断标志获取
**
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Ram_GetIntFlag(void)
{
if(M0P_RAM->IFR & 0x1)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
*****************************************************************************
** \brief Ram中断标志清除
**
**
** \retval Null
*****************************************************************************/
void Ram_ClearIntFlag(void)
{
M0P_RAM->ICLR = 0u;
}
/**
*****************************************************************************
** \brief Ram中断使能
**
** \retval Null
*****************************************************************************/
void Ram_EnableIrq (void)
{
M0P_RAM->CR |= 0x2u;
}
/**
*****************************************************************************
** \brief ram中断禁止
**
** \retval Null
*****************************************************************************/
void Ram_DisableIrq(void)
{
M0P_RAM->CR &= 0x1;
}
//@} // RamGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+170
View File
@@ -0,0 +1,170 @@
/******************************************************************************
*Copyright(C)2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file reset.c
**
** Common API of reset.
** @link resetGroup Some description @endlink
**
** - 2017-05-04
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "reset.h"
/**
*******************************************************************************
** \addtogroup ResetGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief 获取复位源类型.
**
** \param [out] enRstFlg @ref en_reset_flag_t
**
** \retval TRUE or FALSE
******************************************************************************/
boolean_t Reset_GetFlag(en_reset_flag_t enRstFlg)
{
if(M0P_RESET->RESET_FLAG&enRstFlg)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
*******************************************************************************
** \brief 清除复位源类型.
**
** \param [in] pstcFlag @ref en_reset_flag_t
**
** \retval Null
******************************************************************************/
void Reset_ClearFlag(en_reset_flag_t enRstFlg)
{
M0P_RESET->RESET_FLAG &= ~(uint32_t)enRstFlg;
}
/**
*******************************************************************************
** \brief 清除所有复位源类型.
**
** \param Null
**
** \retval Null
******************************************************************************/
void Reset_ClearFlagAll(void)
{
M0P_RESET->RESET_FLAG = 0;
}
/**
*******************************************************************************
** \brief 所有模块进行一次复位.
**
**
** \retval Null
******************************************************************************/
void Reset_RstPeripheralAll(void)
{
M0P_RESET->PERI_RESET = 0u;
M0P_RESET->PERI_RESET = 0xFFFFFFFFu;
}
/**
*******************************************************************************
** \brief 对外设源模块进行一次复位.
**
** \param [in] enPeri @ref en_reset_peripheral_t
**
** \retval Null
******************************************************************************/
void Reset_RstPeripheral(en_reset_peripheral_t enPeri)
{
M0P_RESET->PERI_RESET &= ~(uint32_t)enPeri;
M0P_RESET->PERI_RESET |= (uint32_t)enPeri;
}
//@} // ResetGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+180
View File
@@ -0,0 +1,180 @@
/******************************************************************************
* Copyright (C) 2016, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with eaenCh copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file spi.c
**
** SPI driver API.
** @link Driver Group Some description @endlink
**
** - 2018-05-17 1.0 Devi First version for Device Driver Library of
** Module.
**
*****************************************************************************/
/******************************************************************************
* Include files
*****************************************************************************/
#include "spi.h"
/**
******************************************************************************
** \addtogroup SpiGroup
*****************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
*****************************************************************************/
#define IS_VALID_STAT(x) ( SpiIf == (x)||\
SpiWcol == (x)||\
SpiSserr == (x)||\
SpiMdf == (x) )
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local variable prototypes ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief SPI 请求状态获取
**
** \param [in]SPIx 通道, enStatus 获取请求
**
** \retval 请求状态
**
******************************************************************************/
boolean_t Spi_GetStatus(M0P_SPI_TypeDef* SPIx, en_spi_status_t enStatus)
{
ASSERT(IS_VALID_STAT(enStatus));
if(SPIx->STAT&enStatus)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
******************************************************************************
** \brief SPI 总体初始化函数
**
** \param [in] SPIx 通道
** \param [in] pstcSpiCfg 初始化结构
**
** \retval Ok初始化成功
** \retval ErrorInvalidParameter 初始化错误
******************************************************************************/
en_result_t Spi_Init(M0P_SPI_TypeDef* SPIx, stc_spi_cfg_t *pstcSpiCfg)
{
ASSERT(NULL != pstcSpiCfg);
SPIx->CR = 0;
SPIx->CR = (uint32_t)pstcSpiCfg->enSpiMode |
(uint32_t)pstcSpiCfg->enPclkDiv |
(uint32_t)pstcSpiCfg->enCPOL |
(uint32_t)pstcSpiCfg->enCPHA |
(uint32_t)0x40;
SPIx->STAT = 0x00;
return Ok;
}
/**
******************************************************************************
** \brief SPI 配置主发送的电平
**
** \param [in] SPIx 通道选择,bFlag高低电平
**
** \retval 无
**
******************************************************************************/
void Spi_SetCS(M0P_SPI_TypeDef* SPIx, boolean_t bFlag)
{
SPIx->SSN = bFlag;
}
/**
******************************************************************************
** \brief SPI 发送一字节函数
**
** \param [in] SPIx 通道选择,u8Data发送字节
**
** \retval Ok发送成功
**
******************************************************************************/
en_result_t Spi_SendData(M0P_SPI_TypeDef* SPIx, uint8_t u8Data)
{
SPIx->DATA = u8Data;
return Ok;
}
/**
******************************************************************************
** \brief SPI 接收一字节函数
**
** \param [in] SPIx接收通道
**
** \retval 接收一字节数据
**
******************************************************************************/
uint8_t Spi_ReceiveData(M0P_SPI_TypeDef* SPIx)
{
return SPIx->DATA;
}
//@} // SpiGroup
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
+542
View File
@@ -0,0 +1,542 @@
/******************************************************************************
*Copyright(C)2018, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file sysctrl.c
**
** Common API of sysctrl.
** @link SysctrlGroup Some description @endlink
**
** - 2018-04-22 Lux
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "sysctrl.h"
/**
*******************************************************************************
** \addtogroup SysctrlGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define CLK_TIMEOUT (1000000u)
#define IS_VALID_SRC(x) ( ClkRCH == (x)||\
ClkXTH == (x)||\
ClkRCL == (x)||\
ClkXTL == (x) )
#define IS_VALID_FUNC(x) ( ClkFuncWkupRCH == (x)||\
ClkFuncXTHEn == (x)||\
ClkFuncXTLEn == (x)||\
ClkFuncXTLAWSON == (x)||\
ClkFuncFaultEn == (x)||\
ClkFuncRtcLPWEn == (x)||\
ClkFuncLockUpEn == (x)||\
ClkFuncRstPinIOEn == (x)||\
ClkFuncSwdPinIOEn == (x) )
#define RC_TRIM_BASE_ADDR ((volatile uint16_t*) (0x00100C00ul))
#define RCH_CR_TRIM_24M_VAL (*((volatile uint16_t*) (0x00100C00ul)))
#define RCH_CR_TRIM_22_12M_VAL (*((volatile uint16_t*) (0x00100C02ul)))
#define RCH_CR_TRIM_16M_VAL (*((volatile uint16_t*) (0x00100C04ul)))
#define RCH_CR_TRIM_8M_VAL (*((volatile uint16_t*) (0x00100C06ul)))
#define RCH_CR_TRIM_4M_VAL (*((volatile uint16_t*) (0x00100C08ul)))
#define RCL_CR_TRIM_38400_VAL (*((volatile uint16_t*) (0x00100C20ul)))
#define RCL_CR_TRIM_32768_VAL (*((volatile uint16_t*) (0x00100C22ul)))
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
extern uint32_t SystemCoreClock;
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief SYSCTRL0\SYSCTRL1寄存器操作解锁
**
** \retval None
******************************************************************************/
static void _SysctrlUnlock(void)
{
M0P_SYSCTRL->SYSCTRL2 = 0x5A5A;
M0P_SYSCTRL->SYSCTRL2 = 0xA5A5;
}
/**
*******************************************************************************
** \brief 系统时钟源使能
** \param [in] enSource 目标时钟源
** \param [in] bFlag 使能1-开/0-关
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_ClkSourceEnable(en_sysctrl_clk_source_t enSource, boolean_t bFlag)
{
en_result_t enRet = Ok;
uint32_t u32Temp;
_SysctrlUnlock();
bFlag = !!bFlag;
u32Temp = M0P_SYSCTRL->PERI_CLKEN;
switch (enSource)
{
case SysctrlClkRCH:
M0P_SYSCTRL->SYSCTRL0_f.RCH_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->RCH_CR_f.STABLE))
{
;
}
break;
case SysctrlClkXTH:
M0P_SYSCTRL->PERI_CLKEN_f.GPIO = TRUE;
M0P_GPIO->P0ADS |= 0x06u;
M0P_SYSCTRL->SYSCTRL0_f.XTH_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->XTH_CR_f.STABLE))
{
;
}
break;
case SysctrlClkRCL:
M0P_SYSCTRL->SYSCTRL0_f.RCL_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->RCL_CR_f.STABLE))
{
;
}
break;
default:
enRet = ErrorInvalidParameter;
break;
}
M0P_SYSCTRL->PERI_CLKEN = u32Temp;
return enRet;
}
/**
*******************************************************************************
** \brief 外部高速晶振驱动配置
** \param [in] enFreq 外部高速晶振频率范围选择
** \param [in] enDriver 外部高速晶振驱动能力选择
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_XTHDriverCfg(en_sysctrl_xtal_driver_t enDriver)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.DRIVER = enDriver;
return enRet;
}
/**
*******************************************************************************
** \brief 外部高速时钟稳定周期配置
** \param [in] enCycle 外部高速时钟稳定周期设置
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetXTHStableTime(en_sysctrl_xth_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief 内部低速时钟稳定周期配置
** \param [in] enCycle 内部低速时钟稳定周期设置
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetRCLStableTime(en_sysctrl_rcl_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->RCL_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief 时钟源切换,该函数执行后会开启新时钟源
** \note 选择时钟源之前,需根据需要配置目标时钟源的频率/驱动参数/使能时钟源等
** \param [in] enSource 新时钟源
**
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SysClkSwitch(en_sysctrl_clk_source_t enSource)
{
en_result_t enRet = Ok;
en_sysctrl_clk_source_t ClkNew = enSource;
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.CLKSW = ClkNew;
//更新Core时钟(HCLK)
SystemCoreClockUpdate();
return enRet;
}
/**
*******************************************************************************
** \brief 获得系统时钟(HCLK)频率值
** \retval uint32_t HCLK频率值
**
******************************************************************************/
uint32_t Sysctrl_GetHClkFreq(void)
{
uint32_t u32Val = 0;
const uint32_t u32hcr_tbl[] = { 4000000, 8000000, 16000000, 22120000, 24000000};
const uint16_t u32lcr_tbl[] = { 32768, 38400};
en_sysctrl_clk_source_t enSrc;
uint16_t u16Trim[5] = {0};
u16Trim[4] = RCH_CR_TRIM_24M_VAL;
u16Trim[3] = RCH_CR_TRIM_22_12M_VAL;
u16Trim[2] = RCH_CR_TRIM_16M_VAL;
u16Trim[1] = RCH_CR_TRIM_8M_VAL;
u16Trim[0] = RCL_CR_TRIM_38400_VAL;
//获取当前系统时钟
enSrc = (en_sysctrl_clk_source_t)(M0P_SYSCTRL->SYSCTRL0_f.CLKSW);
switch (enSrc)
{
case SysctrlClkRCH:
{
if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[4]))
{
u32Val = u32hcr_tbl[4];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[3]))
{
u32Val = u32hcr_tbl[3];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[2]))
{
u32Val = u32hcr_tbl[2];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[1]))
{
u32Val = u32hcr_tbl[1];
}
else
{
u32Val = u32hcr_tbl[0];
}
}
break;
case SysctrlClkXTH:
u32Val = SYSTEM_XTH;
break;
case SysctrlClkRCL:
{
if(u16Trim[0] == (M0P_SYSCTRL->RCL_CR_f.TRIM))
{
u32Val = u32lcr_tbl[1];
}
else
{
u32Val = u32lcr_tbl[0];
}
}
break;
default:
u32Val = 0u;
break;
}
u32Val = (u32Val >> M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS);
return u32Val;
}
/**
*******************************************************************************
** \brief 获得外设时钟(PCLK)频率值
** \retval uint32_t PCLK频率值(Hz)
**
******************************************************************************/
uint32_t Sysctrl_GetPClkFreq(void)
{
uint32_t u32Val = 0;
u32Val = Sysctrl_GetHClkFreq();
u32Val = (u32Val >> (M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS));
return u32Val;
}
/**
*******************************************************************************
** \brief 时钟初始化函数
** \param [in] pstcCfg 初始化配置参数
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_ClkInit(stc_sysctrl_clk_cfg_t *pstcCfg)
{
en_result_t enRet = Ok;
//系统时钟参数配置
switch(pstcCfg->enClkSrc)
{
case SysctrlClkRCH:
break;
case SysctrlClkXTH:
Sysctrl_XTHDriverCfg(SysctrlXtalDriver3);
Sysctrl_SetXTHStableTime(SysctrlXthStableCycle16384);
break;
case SysctrlClkRCL:
Sysctrl_SetRCLStableTime(SysctrlRclStableCycle256);
break;
default:
enRet = ErrorInvalidParameter;
break;
}
//时钟源使能
Sysctrl_ClkSourceEnable(pstcCfg->enClkSrc, TRUE);
//时钟源切换
Sysctrl_SysClkSwitch(pstcCfg->enClkSrc);
//时钟分频设置
Sysctrl_SetHCLKDiv(pstcCfg->enHClkDiv);
Sysctrl_SetPCLKDiv(pstcCfg->enPClkDiv);
return enRet;
}
/**
*******************************************************************************
** \brief 时钟去初始化函数
** \param [in]
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_ClkDeInit(void)
{
en_result_t enRet = Ok;
//配置RCH为内部4Hz
Sysctrl_SetRCHTrim(SysctrlRchFreq4MHz);
//时钟源使能
Sysctrl_ClkSourceEnable(SysctrlClkRCH, TRUE);
//时钟源切换
Sysctrl_SysClkSwitch(SysctrlClkRCH);
//其它时钟源使能关闭
Sysctrl_ClkSourceEnable(SysctrlClkXTH, FALSE);
Sysctrl_ClkSourceEnable(SysctrlClkRCL, FALSE);
Sysctrl_ClkSourceEnable(SysctrlClkXTL, FALSE);
//时钟分频设置
Sysctrl_SetHCLKDiv(SysctrlHclkDiv1);
Sysctrl_SetPCLKDiv(SysctrlPclkDiv1);
return enRet;
}
/**
*******************************************************************************
** \brief 内部高速时钟频率TRIM值加载
** \param [in] enRCHFreq 设定的RCH目标频率值
** \retval Ok 设定成功
** 其他 设定失败或时钟未稳定
******************************************************************************/
en_result_t Sysctrl_SetRCHTrim(en_sysctrl_rch_freq_t enRCHFreq)
{
//加载RCH Trim值
M0P_SYSCTRL->RCH_CR_f.TRIM = *(RC_TRIM_BASE_ADDR + enRCHFreq);
return Ok;
}
/**
*******************************************************************************
** \brief 外部高速时钟频率范围设定
** \param [in] enXTHFreq 设定的频率值
** \retval Ok 设定成功
** 其他 设定失败或时钟未稳定
******************************************************************************/
en_result_t Sysctrl_SetXTHFreq(en_sysctrl_xth_freq_t enXTHFreq)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.XTH_FSEL = enXTHFreq;
return enRet;
}
/**
*******************************************************************************
** \brief 内部低速时钟频率TRIM值加载
** \param [in] enRCLFreq 设定的RCL目标频率值
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetRCLTrim(en_sysctrl_rcl_freq_t enRCLFreq)
{
M0P_SYSCTRL->RCL_CR_f.TRIM = *(RC_TRIM_BASE_ADDR + enRCLFreq);
return Ok;
}
/**
*******************************************************************************
** \brief 系统时钟(HCLK)分频设定
** \param [in] enHCLKDiv 分频设定值
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetHCLKDiv(en_sysctrl_hclk_div_t enHCLKDiv)
{
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS = enHCLKDiv;
return Ok;
}
/**
*******************************************************************************
** \brief 外设时钟(PCLK)分频设定
** \param [in] enPCLKDiv 分频设定值
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetPCLKDiv(en_sysctrl_pclk_div_t enPCLKDiv)
{
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS = enPCLKDiv;
return Ok;
}
/**
*******************************************************************************
** \brief 设置外设时钟门控开关
** \param [in] enPeripheral 目标外设
** \param [in] bFlag 使能开关
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral, boolean_t bFlag)
{
SetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN)), enPeripheral, bFlag);
return Ok;
}
/**
*******************************************************************************
** \brief 获得外设时钟门控开关状态
** \param [in] enPeripheral 目标外设
** \retval TRUE 开
** FALSE 关
******************************************************************************/
boolean_t Sysctrl_GetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral)
{
return GetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN)), enPeripheral);
}
/**
*******************************************************************************
** \brief 系统功能设定
** \param [in] enFunc 系统功能枚举类型
** \param [in] bFlag 1-开/0-关
** \retval Ok 设定成功
** 其他 设定失败
******************************************************************************/
en_result_t Sysctrl_SetFunc(en_sysctrl_func_t enFunc, boolean_t bFlag)
{
_SysctrlUnlock();
SetBit((uint32_t)(&(M0P_SYSCTRL->SYSCTRL1)), enFunc, bFlag);
return Ok;
}
//@} // SysctrlGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+247
View File
@@ -0,0 +1,247 @@
/******************************************************************************
*Copyright(C)2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file trim.c
**
** Common API of trim.
** @link trimGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "trim.h"
/**
*******************************************************************************
** \addtogroup TrimGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
#define IS_VALID_TRIMINT(x) (TrimStop == (x) ||\
TrimCalCntOf == (x) ||\
TrimXTLFault == (x) ||\
TrimXTHFault == (x))
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Trim中断标志获取
**
**
** \param [in] enIntType 中断类型(RefStop、CalCntOf、XTAL32KFault、XTAL32MFault)
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType)
{
ASSERT(IS_VALID_TRIMINT(enIntType));
if(M0P_CLK_TRIM->IFR&enIntType)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
*****************************************************************************
** \brief Trim中断标志清除
**
**
** \param [in] enIntType 中断类型(RefStop、CalCntOf、XTAL32KFault、XTAL32MFault)
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_TRIMINT(enIntType));
M0P_CLK_TRIM->ICLR &= ~(uint32_t)enIntType;
return enResult;
}
/**
*****************************************************************************
** \brief Trim中断使能
**
**
**
** \retval Null
*****************************************************************************/
void Trim_EnableIrq (void)
{
M0P_CLK_TRIM->CR_f.IE = TRUE;
}
/**
*****************************************************************************
** \brief Trim中断禁止
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
void Trim_DisableIrq(void)
{
M0P_CLK_TRIM->CR_f.IE = FALSE;
}
/**
*****************************************************************************
** \brief Trim初始化配置
**
**
** \param [in] pstcCfg Trim配置结构体指针
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_Init(stc_trim_cfg_t* pstcCfg)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR = 0;
M0P_CLK_TRIM->CR = (uint32_t)pstcCfg->enCALCLK |
(uint32_t)pstcCfg->enREFCLK |
(uint32_t)pstcCfg->enMON;
M0P_CLK_TRIM->REFCON = pstcCfg->u32RefCon;
M0P_CLK_TRIM->CALCON = pstcCfg->u32CalCon;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim校准/监测启动运行
**
**
**
** \retval Null
*****************************************************************************/
void Trim_Run(void)
{
M0P_CLK_TRIM->CR_f.TRIM_START = TRUE;
}
/**
*****************************************************************************
** \brief Trim校准/监测停止
**
**
**
**
** \retval Null
*****************************************************************************/
void Trim_Stop(void)
{
M0P_CLK_TRIM->CR_f.TRIM_START = FALSE;
}
/**
*****************************************************************************
** \brief Trim参考计数器计数值获取
**
**
** \retval u32Data 参考计数器计数值
*****************************************************************************/
uint32_t Trim_RefCntGet(void)
{
return (uint32_t)M0P_CLK_TRIM->REFCNT;
}
/**
*****************************************************************************
** \brief Trim校准计数器计数值获取
**
**
**
**
** \retval u32Data 校准计数器计数值
*****************************************************************************/
uint32_t Trim_CalCntGet(void)
{
return (uint32_t)M0P_CLK_TRIM->CALCNT;
}
//@} // TrimGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+497
View File
@@ -0,0 +1,497 @@
/*************************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file uart.c
**
** UART function driver API.
** @link SampleGroup Some description @endlink
**
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "uart.h"
/**
******************************************************************************
** \addtogroup UartGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define IS_VALID_CH(x) ((UARTCH0 == (x)) ||\
(UARTCH1 == (x)))
#define IS_VALID_IRQSEL(x) ((UartTxIrq == (x)) ||\
(UartRxIrq == (x)))
#define IS_VALID_MODE(x) ((UartMode0==(x))||\
(UartMode1==(x))||\
(UartMode2==(x))||\
(UartMode3==(x)))
#define IS_VALID_STATUS(x) ((UartRFRAMEError == (x))||\
(UartRxFull == (x))||\
(UartTxEmpty == (x)))
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief UART通信中断使能函数设置
**
** \param [in] UARTx通道号,enIrqSel发送or接收中断使能
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_EnableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel)
{
SetBit((uint32_t)(&(UARTx->SCON)), enIrqSel, TRUE);
return Ok;
}
/**
******************************************************************************
** \brief UART通信中断禁止函数设置
**
** \param [in] UARTx通道号,enIrqSel发送or接收中断禁止
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_DisableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel)
{
SetBit((uint32_t)(&(UARTx->SCON)), enIrqSel, FALSE);
return Ok;
}
/**
******************************************************************************
** \brief UART通道多主机模式配置
**
** \param [in] UARTx通道号,stcMultiCfg多主机模式结构
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_SetMultiMode(M0P_UART_TypeDef* UARTx, stc_uart_multimode_t* pstcMultiCfg)
{
if(NULL != pstcMultiCfg)
{
UARTx->SCON_f.SM2 = TRUE;
UARTx->SADDR = pstcMultiCfg->u8SlaveAddr;
UARTx->SADEN = pstcMultiCfg->u8SaddEn;
}
else
{
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief 计算接收字节奇偶校验是否正确
**
** \param u8Idx通道,enCheck奇偶校验方式,u8Recv校验数据
**
** \retval Error或者成功Ok
******************************************************************************/
en_result_t Uart_CheckEvenOrOdd(M0P_UART_TypeDef* UARTx, en_uart_check_t enCheck, uint8_t u8Recv)
{
uint8_t cnt=0,i;
for(i=0;i<8;i++)
{
if((u8Recv&0x80)==0x80)
{
cnt++;
}
u8Recv<<=1;
}
if(enCheck == UartEven)
{
if(cnt%2!=0)
{
if(UARTx->SCON_f.RB8 != 1)
{
return Error;
}
}
else
{
if(UARTx->SCON_f.RB8 != 0)
{
return Error;
}
}
}
else
{
if(cnt%2!=0)
{
if(UARTx->SCON_f.RB8 != 0)
{
return Error;
}
}
else
{
if(UARTx->SCON_f.RB8 != 1)
{
return Error;
}
}
}
return Ok;
}
/**
******************************************************************************
** \brief 获取RB8数值
**
** \param [in] UARTx通道号
**
** \retval RB8
******************************************************************************/
boolean_t Uart_GetRb8(M0P_UART_TypeDef* UARTx)
{
return (UARTx->SCON_f.RB8);
}
/**
******************************************************************************
** \brief UART通道多机模式发送数据/地址帧配置TB8
**
** \param [in] UARTx 通道号
** \param [in] TRUE-TB8为地址帧标志;FALSE-TB8为数据帧标志;
**
** \retval Null
******************************************************************************/
en_result_t Uart_SetTb8(M0P_UART_TypeDef* UARTx, en_uart_check_t enCheck, uint8_t u8Data)
{
uint8_t cnt=0,i;
for(i=0;i<8;i++)
{
if((u8Data&0x80)==0x80)
{
cnt++;
}
u8Data<<=1;
}
if(enCheck == UartEven)
{
if(cnt%2!=0)
{
UARTx->SCON_f.TB8 = 1;
}
else
{
UARTx->SCON_f.TB8 = 0;
}
}
else
{
if(cnt%2!=0)
{
UARTx->SCON_f.TB8 = 0;
}
else
{
UARTx->SCON_f.TB8 = 1;
}
}
return Ok;
}
/**
******************************************************************************
** \brief UART通道多主机模式从机地址配置函数
**
** \param [in] UARTx通道号,addr地址
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_SetSaddr(M0P_UART_TypeDef* UARTx,uint8_t u8Addr)
{
UARTx->SADDR = u8Addr;
return Ok;
}
/**
******************************************************************************
** \brief UART通道波特率配置
**
** \param [in] u8Idx通道号,u32pclk时钟源,stcBaud波特率配置结构
**
** \retval 定时器配置值
** \retval 0,获取值失败
******************************************************************************/
uint16_t Uart_SetBaudRate(M0P_UART_TypeDef* UARTx,stc_uart_baud_cfg_t* pstcBaud)
{
uint16_t u16tmload=0;
UARTx->SCON_f.DBAUD = pstcBaud->bDbaud;
switch(pstcBaud->enMode)
{
case UartMode0:
case UartMode2:
break;
case UartMode1:
case UartMode3:
u16tmload = 0x10000-((pstcBaud->u32Pclk*(pstcBaud->bDbaud+1))/(pstcBaud->u32Baud*32));//单双倍波特率,定时器配置
break;
default:
break;
}
return u16tmload;
}
/**
******************************************************************************
** \brief UART通道发送或接收使能设置
**
** \param [in] u8Idx通道号,enFunc发送或接收
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_EnableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc)
{
SetBit((uint32_t)(&(UARTx->SCON)), enFunc, TRUE);
return Ok;
}
/**
******************************************************************************
** \brief UART通道发送或接收等功能禁止设置
**
** \param [in] UARTx通道号,enFunc功能
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_DisableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc)
{
SetBit((uint32_t)(&(UARTx->SCON)), enFunc, FALSE);
return Ok;
}
/**
******************************************************************************
** \brief UART通道通信状态获取
**
** \param [in] UARTx通道号
**
** \retval 状态值
******************************************************************************/
uint8_t Uart_GetIsr(M0P_UART_TypeDef* UARTx)
{
return (UARTx->ISR);
}
/**
******************************************************************************
** \brief UART通道通信状态获取
**
** \param [in] UARTx通道号,enStatus获取哪个状态
**
** \retval 状态值
******************************************************************************/
boolean_t Uart_GetStatus(M0P_UART_TypeDef* UARTx, en_uart_status_t enStatus)
{
boolean_t bStatus = FALSE;
ASSERT(IS_VALID_STATUS(enStatus));
bStatus = GetBit((uint32_t)(&(UARTx->ISR)), enStatus);
return bStatus;
}
/**
******************************************************************************
** \brief UART通道通信状态清除
**
** \param [in] UARTx通道号
**
** \retval OK
** \retval ErrorInvalidParameter清除失败
******************************************************************************/
en_result_t Uart_ClrIsr(M0P_UART_TypeDef* UARTx)
{
UARTx->ICR = 0u;
return Ok;
}
/**
******************************************************************************
** \brief UART通道通信状态清除
**
** \param [in] UARTx通道号,enStatus清除哪个状态
**
** \retval OK
** \retval ErrorInvalidParameter清除失败
******************************************************************************/
en_result_t Uart_ClrStatus(M0P_UART_TypeDef* UARTx,en_uart_status_t enStatus)
{
ASSERT(IS_VALID_STATUS(enStatus));
SetBit((uint32_t)(&(UARTx->ICR)), enStatus, FALSE);
return Ok;
}
/**
******************************************************************************
** \brief UART通道发送数据函数,查询方式调用此函数,中断方式发送不适用
**
** \param [in] UARTx通道号,Data发送数据
**
** \retval Ok发送成功
** \retval ErrorInvalidParameter发送失败
******************************************************************************/
en_result_t Uart_SendDataPoll(M0P_UART_TypeDef* UARTx, uint8_t u8Data)
{
UARTx->SBUF_f.SBUF = u8Data;
while(FALSE == Uart_GetStatus(UARTx,UartTC))
{}
Uart_ClrStatus(UARTx,UartTC);
return Ok;
}
/**
******************************************************************************
** \brief UART通道发送数据函数,查询方式调用此函数,中断方式发送不适用
**
** \param [in] UARTx通道号,Data发送数据
**
** \retval @ref en_result_t
******************************************************************************/
en_result_t Uart_SendDataPollTimeOut(M0P_UART_TypeDef* UARTx, uint8_t u8Data, uint32_t u32TimeOut)
{
uint32_t u32Cnt = 0;
UARTx->SBUF_f.SBUF = u8Data;
while(FALSE == Uart_GetStatus(UARTx,UartTC))
{
if(u32Cnt > u32TimeOut)
{
return ErrorTimeout;
}
u32Cnt++;
}
Uart_ClrStatus(UARTx,UartTC);
return Ok;
}
/**
******************************************************************************
** \brief UART通道发送数据函数,中断方式调用此函数
**
** \param [in] UARTx通道号,Data发送数据
**
** \retval Ok发送成功
** \retval ErrorInvalidParameter发送失败
******************************************************************************/
en_result_t Uart_SendDataIt(M0P_UART_TypeDef* UARTx, uint8_t u8Data)
{
UARTx->SBUF_f.SBUF = u8Data;
return Ok;
}
/**
******************************************************************************
** \brief UART通道接收数据函数
**
** \param [in] UARTx通道号
**
** \retval 接收数据
******************************************************************************/
uint8_t Uart_ReceiveData(M0P_UART_TypeDef* UARTx)
{
return (UARTx->SBUF_f.SBUF);
}
/**
******************************************************************************
** \brief UART通道初始化函数
**
** \param [in] UARTx通道号,pstcCfg初始化结构体 @ref stc_uart_cfg_t
**
** \retval OK配置成功
** \retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t Uart_Init(M0P_UART_TypeDef* UARTx, stc_uart_cfg_t* pstcCfg)
{
UARTx->SCON_f.SM01 = pstcCfg->enRunMode;
Uart_EnableFunc(UARTx,UartRenFunc); ///<使能收发
return Ok;
}
//@} // UartGroup
+280
View File
@@ -0,0 +1,280 @@
/******************************************************************************
* Copyright (C) 2019, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file vc.c
**
** voltage comparator driver API.
** @link VC Group Some description @endlink
**
** - 2019-04-10 First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "vc.h"
/**
******************************************************************************
** \addtogroup VcGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
/**
******************************************************************************
** \brief 配置VC中断触发方式
**
** @param Channelx : VcChannelx x=0、1
** @param enSel : VcIrqRise、VcIrqFall、VcIrqHigh
** \retval 无
**
******************************************************************************/
void Vc_CfgItType(en_vc_channel_t Channelx, en_vc_irq_sel_t ItType)
{
stc_vc_vc0_cr_field_t *stcVcnCr;
switch(Channelx)
{
case VcChannel0:
stcVcnCr = (stc_vc_vc0_cr_field_t*)&M0P_VC->VC0_CR_f;
break;
case VcChannel1:
stcVcnCr = (stc_vc_vc0_cr_field_t*)&M0P_VC->VC1_CR_f;
break;
default:
break;
}
switch (ItType)
{
case VcIrqNone:
stcVcnCr->RISING = 0u;
stcVcnCr->FALLING = 0u;
stcVcnCr->LEVEL = 0u;
break;
case VcIrqRise:
stcVcnCr->RISING = 1u;
break;
case VcIrqFall:
stcVcnCr->FALLING = 1u;
break;
case VcIrqHigh:
stcVcnCr->LEVEL = 1u;
break;
default:
break;
}
}
/**
******************************************************************************
** \brief VC 中断使能与禁止
**
** @param Channelx : VcChannelx x=0、1
** @param NewStatus : TRUE 或 FALSE
** \retval 无
**
******************************************************************************/
void Vc_ItCfg(en_vc_channel_t Channelx, boolean_t NewStatus)
{
switch(Channelx)
{
case VcChannel0:
SetBit((uint32_t)(&(M0P_VC->VC0_CR)), 15, NewStatus);
break;
case VcChannel1:
SetBit((uint32_t)(&(M0P_VC->VC1_CR)), 15, NewStatus);
break;
default:
break;
}
}
/**
******************************************************************************
** \brief VC 比较结果获取,包含中断标志位和滤波结果
**
** @param Result : 所要读取的结果
** \retval TRUE 或 FALSE
**
******************************************************************************/
boolean_t Vc_GetItStatus(en_vc_ifr_t Result)
{
boolean_t bFlag;
bFlag = GetBit((uint32_t)(&(M0P_VC->IFR)), Result);
return bFlag;
}
/**
******************************************************************************
** \brief VC 清除中断标志位
**
** @param NewStatus : Vc0_Intf、Vc1_Intf、Vc2_Intf
** \retval 无
**
******************************************************************************/
void Vc_ClearItStatus(en_vc_ifr_t NewStatus)
{
SetBit((uint32_t)(&(M0P_VC->IFR)), NewStatus, 0);
}
/**
******************************************************************************
** \brief VC 配置DAC相关的内容 VC_CR中 VC_REF2P5_SEL VC_DIV_EN VC_DIV
**
** @param pstcDacCfg :
** \retval Ok 或 ErrorInvalidParameter
**
******************************************************************************/
en_result_t Vc_DacInit(stc_vc_dac_cfg_t *pstcDacCfg)
{
if (NULL == pstcDacCfg)
{
return ErrorInvalidParameter;
}
M0P_VC->CR_f.DIV_EN = pstcDacCfg->bDivEn;
M0P_VC->CR_f.REF2P5_SEL = pstcDacCfg->enDivVref;
if (pstcDacCfg->u8DivVal < 0x40)
{
M0P_VC->CR_f.DIV = pstcDacCfg->u8DivVal;
}
else
{
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief VC通道初始化
**
** @param pstcDacCfg :
** \retval 无
**
******************************************************************************/
void Vc_Init(stc_vc_channel_cfg_t *pstcChannelCfg)
{
if (VcChannel0 == pstcChannelCfg->enVcChannel)
{
M0P_VC->CR_f.VC0_HYS_SEL = pstcChannelCfg->enVcCmpDly;
M0P_VC->CR_f.VC0_BIAS_SEL = pstcChannelCfg->enVcBiasCurrent;
M0P_VC->VC0_CR_f.DEBOUNCE_TIME = pstcChannelCfg->enVcFilterTime;
M0P_VC->VC0_CR_f.P_SEL = pstcChannelCfg->enVcInPin_P;
M0P_VC->VC0_CR_f.N_SEL = pstcChannelCfg->enVcInPin_N;
M0P_VC->VC0_CR_f.FLTEN = pstcChannelCfg->bFlten;
M0P_VC->VC0_OUT_CFG = 1<<pstcChannelCfg->enVcOutCfg;
}
else if (VcChannel1 == pstcChannelCfg->enVcChannel)
{
M0P_VC->CR_f.VC1_HYS_SEL = pstcChannelCfg->enVcCmpDly;
M0P_VC->CR_f.VC1_BIAS_SEL = pstcChannelCfg->enVcBiasCurrent;
M0P_VC->VC1_CR_f.DEBOUNCE_TIME = pstcChannelCfg->enVcFilterTime;
M0P_VC->VC1_CR_f.P_SEL = pstcChannelCfg->enVcInPin_P;
M0P_VC->VC1_CR_f.N_SEL = pstcChannelCfg->enVcInPin_N;
M0P_VC->VC1_CR_f.FLTEN = pstcChannelCfg->bFlten;
M0P_VC->VC1_OUT_CFG = 1<<pstcChannelCfg->enVcOutCfg;
}
else
{
;
}
}
/**
******************************************************************************
** \brief VC 通道使能
**
** \param enChannel : 通道号VcChannel0 VcChannel1
** \param NewStatus : TRUE FALSE
** \retval NewStatus : TRUE FALSE
**
******************************************************************************/
void Vc_Cmd(en_vc_channel_t enChannel, boolean_t NewStatus)
{
switch(enChannel)
{
case VcChannel0:
SetBit((uint32_t)(&(M0P_VC->VC0_CR)), 0, NewStatus);
break;
case VcChannel1:
SetBit((uint32_t)(&(M0P_VC->VC1_CR)), 0, NewStatus);
break;
default:
break;
}
}
//@} // VcGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
+203
View File
@@ -0,0 +1,203 @@
/*************************************************************************************
* Copyright (C) 2017, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file wdt.c
**
** WDT function driver API.
** @link WdtGroup Some description @endlink
**
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "wdt.h"
/**
******************************************************************************
** \defgroup WdtGroup
**
******************************************************************************/
//@{
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief WDT溢出时间设置函数
**
** \param [in] u8LoadValue 溢出时间
**
** \retval 无
**
******************************************************************************/
void Wdt_WriteWdtLoad(uint8_t u8LoadValue)
{
M0P_WDT->CON_f.WOV = u8LoadValue;
}
/**
******************************************************************************
** \brief WDT初始化函数
**
** \param [in] enFunc @ref en_wdt_func_t
** \param [in] enTime @ref en_wdt_time_t
**
** \retval Ok
**
******************************************************************************/
en_result_t Wdt_Init(en_wdt_func_t enFunc, en_wdt_time_t enTime)
{
en_result_t enRet = Error;
Wdt_WriteWdtLoad(enTime);
M0P_WDT->CON_f.WINT_EN = enFunc;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief WDT复位及启动函数
**
** \param [in] 无
**
** \retval 无
**
******************************************************************************/
void Wdt_Start(void)
{
M0P_WDT->RST = 0x1E;
M0P_WDT->RST = 0xE1;
}
/**
******************************************************************************
** \brief WDT喂狗
**
** \param [in] 无
**
** \retval Ok
**
******************************************************************************/
void Wdt_Feed(void)
{
M0P_WDT->RST = 0x1E;
M0P_WDT->RST = 0xE1;
}
/**
******************************************************************************
** \brief WDT中断标志清除
**
** \param [in] 无
**
** \retval Ok
**
******************************************************************************/
void Wdt_IrqClr(void)
{
M0P_WDT->RST = 0x1E;
M0P_WDT->RST = 0xE1;
}
/**
******************************************************************************
** \brief WDT读取当前计数值函数
**
** \param [in] 无
**
** \retval 计数值
**
******************************************************************************/
uint8_t Wdt_ReadWdtValue(void)
{
uint8_t u8Count;
u8Count = M0P_WDT->CON_f.WCNTL;
return u8Count;
}
/**
******************************************************************************
** \brief WDT读取当前运行状态
**
** \param [in] 无
**
** \retval 状态值
**
******************************************************************************/
boolean_t Wdt_ReadwdtStatus(void)
{
if(M0P_WDT->CON&0x10u)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
*******************************************************************************
** \brief WDT 中断状态标记获取
**
**
** \retval 中断状态
******************************************************************************/
boolean_t Wdt_GetIrqStatus(void)
{
if(M0P_WDT->CON&0x80u)
{
return TRUE;
}
else
{
return FALSE;
}
}
//@} // WdtGroup
+167
View File
@@ -0,0 +1,167 @@
/*
*****************************************************************************
**
** File : LinkerScript.ld
**
** Abstract : Linker script for HC32F005 Device with
** 32KByte FLASH, 4KByte RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : HDSC HC32
**
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
** (c)Copyright Ac6.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Ac6 permit registered System Workbench for MCU users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the System Workbench for MCU toolchain.
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20001000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x400; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
+243
View File
@@ -0,0 +1,243 @@
.syntax unified
.cpu cortex-m0plus
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
ldr r0, =_estack
mov sp, r0 /* set stack pointer */
ApplicationStart:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2]
adds r2, r2, #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* From Vendor.*/
/* reset NVIC if in rom debug.*/
LDR R0, =0x20000000
LDR R2, =0x0
MOVS R1, #0
ADD R1, PC,#0
CMP R1, R0
BLS RAMCODE
/* ram code base address.*/
ADD R2, R0,R2
RAMCODE:
/* reset Vector table address.*/
LDR R0, =0xE000ED08
STR R2, [R0]
/* End From Vendor.*/
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call static constructors */
bl __libc_init_array
/* Call the application's entry point.*/
bl main
LoopForever:
b LoopForever
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
*
* @param None
* @retval : None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M0+. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word 0
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* external interrupts handler */
.word PORT0_IRQHandler
.word PORT1_IRQHandler
.word PORT2_IRQHandler
.word PORT3_IRQHandler
.word Dummy_Handler
.word Dummy_Handler
.word UART0_IRQHandler
.word UART1_IRQHandler
.word Dummy_Handler
.word Dummy_Handler
.word SPI_IRQHandler
.word Dummy_Handler
.word I2C_IRQHandler
.word Dummy_Handler
.word TIM0_IRQHandler
.word TIM1_IRQHandler
.word TIM2_IRQHandler
.word Dummy_Handler
.word TIM4_IRQHandler
.word TIM5_IRQHandler
.word TIM6_IRQHandler
.word PCA_IRQHandler
.word WDT_IRQHandler
.word Dummy_Handler
.word ADC_IRQHandler
.word Dummy_Handler
.word VC0_IRQHandler
.word VC1_IRQHandler
.word LVD_IRQHandler
.word Dummy_Handler
.word EF_RAM_IRQHandler
.word CLKTRIM_IRQHandler
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
/* external interrupts handler */
.weak PORT0_IRQHandler
.thumb_set PORT0_IRQHandler,Default_Handler
.weak PORT1_IRQHandler
.thumb_set PORT1_IRQHandler,Default_Handler
.weak PORT2_IRQHandler
.thumb_set PORT2_IRQHandler,Default_Handler
.weak PORT3_IRQHandler
.thumb_set PORT3_IRQHandler,Default_Handler
.weak UART0_IRQHandler
.thumb_set UART0_IRQHandler,Default_Handler
.weak UART1_IRQHandler
.thumb_set UART1_IRQHandler,Default_Handler
.weak SPI_IRQHandler
.thumb_set SPI_IRQHandler,Default_Handler
.weak I2C_IRQHandler
.thumb_set I2C_IRQHandler,Default_Handler
.weak TIM0_IRQHandler
.thumb_set TIM0_IRQHandler,Default_Handler
.weak TIM1_IRQHandler
.thumb_set TIM1_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak TIM4_IRQHandler
.thumb_set TIM4_IRQHandler,Default_Handler
.weak TIM5_IRQHandler
.thumb_set TIM5_IRQHandler,Default_Handler
.weak TIM6_IRQHandler
.thumb_set TIM6_IRQHandler,Default_Handler
.weak PCA_IRQHandler
.thumb_set PCA_IRQHandler,Default_Handler
.weak WDT_IRQHandler
.thumb_set WDT_IRQHandler,Default_Handler
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler
.weak VC0_IRQHandler
.thumb_set VC0_IRQHandler,Default_Handler
.weak VC1_IRQHandler
.thumb_set VC1_IRQHandler,Default_Handler
.weak LVD_IRQHandler
.thumb_set LVD_IRQHandler,Default_Handler
.weak EF_RAM_IRQHandler
.thumb_set EF_RAM_IRQHandler,Default_Handler
.weak CLKTRIM_IRQHandler
.thumb_set CLKTRIM_IRQHandler,Default_Handler
.weak Dummy_Handler
.thumb_set Dummy_Handler,Default_Handler