20260324
This commit is contained in:
39
RTX5_20220316/main/General_type.h
Normal file
39
RTX5_20220316/main/General_type.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __GENERAL_TYPE_H
|
||||
#define __GENERAL_TYPE_H
|
||||
|
||||
typedef signed long s32;
|
||||
typedef signed short s16;
|
||||
typedef signed char s8;
|
||||
|
||||
typedef signed long const sc32; /* Read Only */
|
||||
typedef signed short const sc16; /* Read Only */
|
||||
typedef signed char const sc8; /* Read Only */
|
||||
|
||||
typedef volatile signed long vs32;
|
||||
typedef volatile signed short vs16;
|
||||
typedef volatile signed char vs8;
|
||||
|
||||
typedef volatile signed long const vsc32; /* Read Only */
|
||||
typedef volatile signed short const vsc16; /* Read Only */
|
||||
typedef volatile signed char const vsc8; /* Read Only */
|
||||
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef unsigned long const uc32; /* Read Only */
|
||||
typedef unsigned short const uc16; /* Read Only */
|
||||
typedef unsigned char const uc8; /* Read Only */
|
||||
|
||||
typedef volatile unsigned long vu32;
|
||||
typedef volatile unsigned short vu16;
|
||||
typedef volatile unsigned char vu8;
|
||||
|
||||
typedef volatile unsigned long const vuc32; /* Read Only */
|
||||
typedef volatile unsigned short const vuc16; /* Read Only */
|
||||
typedef volatile unsigned char const vuc8; /* Read Only */
|
||||
|
||||
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
|
||||
|
||||
#endif
|
||||
|
||||
775
RTX5_20220316/main/core_cmInstr.h
Normal file
775
RTX5_20220316/main/core_cmInstr.h
Normal file
@ -0,0 +1,775 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmInstr.h
|
||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
||||
* @version V2.01
|
||||
* @date 06. December 2010
|
||||
*
|
||||
* @note
|
||||
* Copyright (C) 2009-2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* ARM Limited (ARM) is supplying this software for use with Cortex-M
|
||||
* processor based microcontrollers. This file can be freely distributed
|
||||
* within development tools that are supporting such ARM based processors.
|
||||
*
|
||||
* @par
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
||||
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CORE_CMINSTR_H__
|
||||
#define __CORE_CMINSTR_H__
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------ RealView Compiler ----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
|
||||
/** \brief No Operation
|
||||
|
||||
No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
#define __NOP __nop
|
||||
|
||||
|
||||
/** \brief Wait For Interrupt
|
||||
|
||||
Wait For Interrupt is a hint instruction that suspends execution
|
||||
until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFI __wfi
|
||||
|
||||
|
||||
/** \brief Wait For Event
|
||||
|
||||
Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFE __wfe
|
||||
|
||||
|
||||
/** \brief Send Event
|
||||
|
||||
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
#define __SEV __sev
|
||||
|
||||
|
||||
/** \brief Instruction Synchronization Barrier
|
||||
|
||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||
so that all instructions following the ISB are fetched from cache or
|
||||
memory, after the instruction has been completed.
|
||||
*/
|
||||
#define __ISB() __isb(0xF)
|
||||
|
||||
|
||||
/** \brief Data Synchronization Barrier
|
||||
|
||||
This function acts as a special kind of Data Memory Barrier.
|
||||
It completes when all explicit memory accesses before this instruction complete.
|
||||
*/
|
||||
#define __DSB() __dsb(0xF)
|
||||
|
||||
|
||||
/** \brief Data Memory Barrier
|
||||
|
||||
This function ensures the apparent order of the explicit memory operations before
|
||||
and after the instruction, without ensuring their completion.
|
||||
*/
|
||||
#define __DMB() __dmb(0xF)
|
||||
|
||||
|
||||
/** \brief Reverse byte order (32 bit)
|
||||
|
||||
This function reverses the byte order in integer value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#define __REV __rev
|
||||
|
||||
|
||||
/** \brief Reverse byte order (16 bit)
|
||||
|
||||
This function reverses the byte order in two unsigned short values.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#if (__ARMCC_VERSION < 400677)
|
||||
extern uint32_t __REV16(uint32_t value);
|
||||
#else /* (__ARMCC_VERSION >= 400677) */
|
||||
static __INLINE __ASM uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
rev16 r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
|
||||
/** \brief Reverse byte order in signed short value
|
||||
|
||||
This function reverses the byte order in a signed short value with sign extension to integer.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#if (__ARMCC_VERSION < 400677)
|
||||
extern int32_t __REVSH(int32_t value);
|
||||
#else /* (__ARMCC_VERSION >= 400677) */
|
||||
static __INLINE __ASM int32_t __REVSH(int32_t value)
|
||||
{
|
||||
revsh r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03)
|
||||
|
||||
/** \brief Reverse bit order of value
|
||||
|
||||
This function reverses the bit order of the given value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#define __RBIT __rbit
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief STR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive STR command for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXB(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief STR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive STR command for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXH(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief STR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive STR command for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXW(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief Remove the exclusive lock
|
||||
|
||||
This function removes the exclusive lock which is created by LDREX.
|
||||
|
||||
*/
|
||||
#if (__ARMCC_VERSION < 400000)
|
||||
extern void __CLREX(void);
|
||||
#else /* (__ARMCC_VERSION >= 400000) */
|
||||
#define __CLREX __clrex
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
|
||||
/** \brief Signed Saturate
|
||||
|
||||
This function saturates a signed value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __SSAT __ssat
|
||||
|
||||
|
||||
/** \brief Unsigned Saturate
|
||||
|
||||
This function saturates an unsigned value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __USAT __usat
|
||||
|
||||
|
||||
/** \brief Count leading zeros
|
||||
|
||||
This function counts the number of leading zeros of a data value.
|
||||
|
||||
\param [in] value Value to count the leading zeros
|
||||
\return number of leading zeros in value
|
||||
*/
|
||||
#define __CLZ __clz
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) */
|
||||
|
||||
|
||||
|
||||
#elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
|
||||
#include <intrinsics.h> /* IAR Intrinsics */
|
||||
|
||||
#pragma diag_suppress=Pe940
|
||||
|
||||
/** \brief No Operation
|
||||
|
||||
No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
#define __NOP __no_operation
|
||||
|
||||
|
||||
/** \brief Wait For Interrupt
|
||||
|
||||
Wait For Interrupt is a hint instruction that suspends execution
|
||||
until one of a number of events occurs.
|
||||
*/
|
||||
static __INLINE void __WFI(void)
|
||||
{
|
||||
__ASM ("wfi");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Wait For Event
|
||||
|
||||
Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
static __INLINE void __WFE(void)
|
||||
{
|
||||
__ASM ("wfe");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Send Event
|
||||
|
||||
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
static __INLINE void __SEV(void)
|
||||
{
|
||||
__ASM ("sev");
|
||||
}
|
||||
|
||||
|
||||
/* intrinsic void __ISB(void) (see intrinsics.h) */
|
||||
/* intrinsic void __DSB(void) (see intrinsics.h) */
|
||||
/* intrinsic void __DMB(void) (see intrinsics.h) */
|
||||
/* intrinsic uint32_t __REV(uint32_t value) (see intrinsics.h) */
|
||||
/* intrinsic __SSAT (see intrinsics.h) */
|
||||
/* intrinsic __USAT (see intrinsics.h) */
|
||||
|
||||
|
||||
/** \brief Reverse byte order (16 bit)
|
||||
|
||||
This function reverses the byte order in two unsigned short values.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
static uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
__ASM("rev16 r0, r0");
|
||||
}
|
||||
|
||||
|
||||
/* intrinsic uint32_t __REVSH(uint32_t value) (see intrinsics.h */
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03)
|
||||
|
||||
/** \brief Reverse bit order of value
|
||||
|
||||
This function reverses the bit order of the given value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
static uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
__ASM("rbit r0, r0");
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
static uint8_t __LDREXB(volatile uint8_t *addr)
|
||||
{
|
||||
__ASM("ldrexb r0, [r0]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
static uint16_t __LDREXH(volatile uint16_t *addr)
|
||||
{
|
||||
__ASM("ldrexh r0, [r0]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
/* intrinsic unsigned long __LDREX(unsigned long *) (see intrinsics.h) */
|
||||
static uint32_t __LDREXW(volatile uint32_t *addr)
|
||||
{
|
||||
__ASM("ldrex r0, [r0]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive STR command for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
static uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
|
||||
{
|
||||
__ASM("strexb r0, r0, [r1]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive STR command for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
static uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
|
||||
{
|
||||
__ASM("strexh r0, r0, [r1]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive STR command for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
/* intrinsic unsigned long __STREX(unsigned long, unsigned long) (see intrinsics.h )*/
|
||||
static uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
|
||||
{
|
||||
__ASM("strex r0, r0, [r1]");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Remove the exclusive lock
|
||||
|
||||
This function removes the exclusive lock which is created by LDREX.
|
||||
|
||||
*/
|
||||
static __INLINE void __CLREX(void)
|
||||
{
|
||||
__ASM ("clrex");
|
||||
}
|
||||
|
||||
/* intrinsic unsigned char __CLZ( unsigned long ) (see intrinsics.h) */
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) */
|
||||
|
||||
#pragma diag_default=Pe940
|
||||
|
||||
|
||||
|
||||
#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
|
||||
/** \brief No Operation
|
||||
|
||||
No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __NOP(void)
|
||||
{
|
||||
__ASM volatile ("nop");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Wait For Interrupt
|
||||
|
||||
Wait For Interrupt is a hint instruction that suspends execution
|
||||
until one of a number of events occurs.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __WFI(void)
|
||||
{
|
||||
__ASM volatile ("wfi");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Wait For Event
|
||||
|
||||
Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __WFE(void)
|
||||
{
|
||||
__ASM volatile ("wfe");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Send Event
|
||||
|
||||
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __SEV(void)
|
||||
{
|
||||
__ASM volatile ("sev");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Instruction Synchronization Barrier
|
||||
|
||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||
so that all instructions following the ISB are fetched from cache or
|
||||
memory, after the instruction has been completed.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __ISB(void)
|
||||
{
|
||||
__ASM volatile ("isb");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Data Synchronization Barrier
|
||||
|
||||
This function acts as a special kind of Data Memory Barrier.
|
||||
It completes when all explicit memory accesses before this instruction complete.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __DSB(void)
|
||||
{
|
||||
__ASM volatile ("dsb");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Data Memory Barrier
|
||||
|
||||
This function ensures the apparent order of the explicit memory operations before
|
||||
and after the instruction, without ensuring their completion.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __DMB(void)
|
||||
{
|
||||
__ASM volatile ("dmb");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order (32 bit)
|
||||
|
||||
This function reverses the byte order in integer value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order (16 bit)
|
||||
|
||||
This function reverses the byte order in two unsigned short values.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order in signed short value
|
||||
|
||||
This function reverses the byte order in a signed short value with sign extension to integer.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE int32_t __REVSH(int32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03)
|
||||
|
||||
/** \brief Reverse bit order of value
|
||||
|
||||
This function reverses the bit order of the given value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint8_t __LDREXB(volatile uint8_t *addr)
|
||||
{
|
||||
uint8_t result;
|
||||
|
||||
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint16_t __LDREXH(volatile uint16_t *addr)
|
||||
{
|
||||
uint16_t result;
|
||||
|
||||
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive LDR command for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __LDREXW(volatile uint32_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (8 bit)
|
||||
|
||||
This function performs a exclusive STR command for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (16 bit)
|
||||
|
||||
This function performs a exclusive STR command for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (32 bit)
|
||||
|
||||
This function performs a exclusive STR command for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Remove the exclusive lock
|
||||
|
||||
This function removes the exclusive lock which is created by LDREX.
|
||||
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE void __CLREX(void)
|
||||
{
|
||||
__ASM volatile ("clrex");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Signed Saturate
|
||||
|
||||
This function saturates a signed value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __SSAT(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
|
||||
/** \brief Unsigned Saturate
|
||||
|
||||
This function saturates an unsigned value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __USAT(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
|
||||
/** \brief Count leading zeros
|
||||
|
||||
This function counts the number of leading zeros of a data value.
|
||||
|
||||
\param [in] value Value to count the leading zeros
|
||||
\return number of leading zeros in value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) static __INLINE uint8_t __CLZ(uint32_t value)
|
||||
{
|
||||
uint8_t result;
|
||||
|
||||
__ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) */
|
||||
|
||||
|
||||
|
||||
|
||||
#elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
|
||||
/* TASKING carm specific functions */
|
||||
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all instrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
#endif /* __CORE_CMINSTR_H__ */
|
||||
843
RTX5_20220316/main/main.c
Normal file
843
RTX5_20220316/main/main.c
Normal file
@ -0,0 +1,843 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
ͷ<>ļ<EFBFBD>
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include "RTE_Components.h"
|
||||
#include CMSIS_device_header
|
||||
//#include "cmsis_os2.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/**********************************************************************************************************
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
void USERTaskCreate (void);
|
||||
void USER_Task_LinkStatus(void *argument); //WIFI<46><49><EFBFBD><EFBFBD>״̬
|
||||
void USER_Task_WIFI(void *argument);//ESP8266
|
||||
void USER_Task_MSG(void *argument);//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||
void USERTaskStart(void *argument);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void USERTask_Process1(void *argument);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>й<EFBFBD><D0B9><EFBFBD>
|
||||
void USERTask_Resume(void *argument);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void User_Task_Test(void *argument);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t IsAppointmentRight(void);
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
ITStatus Wake_way=RESET;//<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѣ<EFBFBD>0<EFBFBD><30>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
||||
u8 Enable_SDI_RS232=0; //0ʹ<30><CAB9>SDI 1ʹ<31>ܴ<EFBFBD><DCB4><EFBFBD>232<33><32>esp8266<36>Ĵ<EFBFBD><C4B4><EFBFBD>232<33><32>
|
||||
u8 LinkStatus=0; //WIFI<46><49><EFBFBD><EFBFBD>״̬<D7B4><CCAC>2<EFBFBD><32><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>Ϊδ<CEAA><CEB4><EFBFBD><EFBFBD>
|
||||
u8 Creat_WIFI=0;
|
||||
u8 Creat_BC25=0;
|
||||
TASKRUNS TASKRUNSS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>־
|
||||
u32 wut_rtc_s=0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTCʱ<43><CAB1>
|
||||
TASKFISHED TASKFISHEDS;
|
||||
u8 WKUP_PIN_Status=0;//<2F><><EFBFBD><EFBFBD>״̬ 1<><31><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>0δ<30><CEB4><EFBFBD><EFBFBD>
|
||||
u8 Check_WKUP_key=0;
|
||||
u32 time__sta_bc25=0;//BC25<32><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
u32 time__sta_pro1=0;//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
char rtc_data[15]={0},rtc_time[15]={0},CLOSE_ALARM = 0;
|
||||
extern char name[],hhmmsss[],yymmddd[];
|
||||
char NOWtime[15];
|
||||
uint32_t appointment_y,appointment_s,NOW_y,NOW_s;
|
||||
|
||||
/*
|
||||
****************************************************************************************************
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
******************************************************************************************************
|
||||
*/
|
||||
const osThreadAttr_t ThreadLinkStatus_Attr =
|
||||
{
|
||||
.name = "LinkStatus",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 512,
|
||||
};
|
||||
const osThreadAttr_t ThreadStart_Attr =
|
||||
{
|
||||
.name = "ThreadStart",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 512,
|
||||
};
|
||||
|
||||
const osThreadAttr_t ThreadWIFI_Attr =
|
||||
{
|
||||
.name = "ThreadWIFI",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 1024,
|
||||
};
|
||||
|
||||
const osThreadAttr_t ThreadMSG_Attr =
|
||||
{
|
||||
.name = "ThreadMSG",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityNormal,
|
||||
.stack_size = 1024,
|
||||
};
|
||||
|
||||
const osThreadAttr_t ThreadTest_Attr =
|
||||
{
|
||||
.name = "ThreadTest",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 2048,
|
||||
};
|
||||
|
||||
static const osEventFlagsAttr_t EventFlagAttr_PROCESS = {
|
||||
.name = "PROCESS_Events",
|
||||
};
|
||||
static const osEventFlagsAttr_t EventFlagAttr_Start = {
|
||||
.name = "Start_Events",
|
||||
};
|
||||
static const osEventFlagsAttr_t EventFlagAttr_Fished = {
|
||||
.name = "Fished_Events",
|
||||
};
|
||||
|
||||
const osThreadAttr_t ThreadUSERTask_Resume_Attr =
|
||||
{
|
||||
.name = "ThreadUSERTask_Resume",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 1024,
|
||||
};
|
||||
const osThreadAttr_t ThreadPROCESS1_Attr =
|
||||
{
|
||||
.name = "ThreadPROCESS1",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 2048,
|
||||
};
|
||||
const osThreadAttr_t ThreadBC25_Attr =
|
||||
{
|
||||
.name = "ThreadBC25",
|
||||
.attr_bits = osThreadDetached,
|
||||
.priority = osPriorityHigh2,
|
||||
.stack_size = 2048,
|
||||
};
|
||||
|
||||
static const osMutexAttr_t WIFI_Mutex_Attr = {
|
||||
.name = "WIFI_Multiplex",
|
||||
};
|
||||
static const osMutexAttr_t SDI_Mutex_Attr = {
|
||||
.name = "SDI_Multiplex",
|
||||
};
|
||||
static const osMutexAttr_t TF_Mutex_Attr = {
|
||||
.name = "TF_Multiplex",
|
||||
//.attr_bits = osMutexRobust,
|
||||
};
|
||||
static const osSemaphoreAttr_t Proces1_Semaphore_Attr = {
|
||||
.name = "Proces1_Sem",
|
||||
};
|
||||
static const osSemaphoreAttr_t BC25_Semaphore_Attr = {
|
||||
.name = "BC25_Sem",
|
||||
};
|
||||
/*
|
||||
*********************************************************************************************
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
osThreadId_t ThreadIdSMSG = NULL;
|
||||
osThreadId_t ThreadIdTaskLinkStatus = NULL;
|
||||
osThreadId_t ThreadIdTaskBC25 = NULL;
|
||||
osThreadId_t ThreadIdWIFI = NULL;
|
||||
osThreadId_t ThreadIdStart = NULL;
|
||||
osThreadId_t ThreadIdProcsee1 = NULL;
|
||||
osThreadId_t ThreadIdUSERTask_Resume = NULL;
|
||||
osThreadId_t ThreadIdTest = NULL;
|
||||
|
||||
osSemaphoreId_t Process1ID_Semaphore; // semaphore id
|
||||
osSemaphoreId_t BC25ID_Semaphore; // semaphore id
|
||||
|
||||
osEventFlagsId_t EventFlagID_PROCESS=NULL; //<2F><><EFBFBD>̱<EFBFBD>־
|
||||
osEventFlagsId_t EventFlagID_Start=NULL;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||
osEventFlagsId_t EventFlagID_Fished=NULL;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||
osMutexId_t WIFI_MutexID=NULL;
|
||||
osMutexId_t SDI_MutexID=NULL;
|
||||
osMutexId_t TFcard_MutexID=NULL;
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>main()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int main (void) {
|
||||
|
||||
SCB->VTOR = FLASH_BASE | 0x10000; /* Vector Table Relocation in Internal FLASH. */
|
||||
// System Initialization
|
||||
SystemCoreClockUpdate();
|
||||
// ...
|
||||
|
||||
bsp_init();
|
||||
osKernelInitialize(); // Initialize CMSIS-RTOS
|
||||
EventFlagID_PROCESS = osEventFlagsNew(&EventFlagAttr_PROCESS);
|
||||
EventFlagID_Start = osEventFlagsNew(&EventFlagAttr_Start);
|
||||
EventFlagID_Fished = osEventFlagsNew(&EventFlagAttr_Fished);
|
||||
Process1ID_Semaphore = osSemaphoreNew(1, 1, &Proces1_Semaphore_Attr );
|
||||
BC25ID_Semaphore = osSemaphoreNew(1, 1, &BC25_Semaphore_Attr );
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
ThreadIdStart = osThreadNew(USERTaskStart, NULL, &ThreadStart_Attr);
|
||||
|
||||
osKernelStart(); // Start thread execution
|
||||
for (;;)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t IsAppointmentRight(void)
|
||||
{
|
||||
GetRTC(hhmmsss,yymmddd);
|
||||
NOWtime[0] = '2';
|
||||
NOWtime[1] = '0';
|
||||
memcpy(&NOWtime[2],yymmddd,6);
|
||||
NOW_y = atoi(NOWtime);
|
||||
memset(NOWtime,0,15);
|
||||
memcpy(NOWtime,hhmmsss,6);
|
||||
NOW_s = atoi(NOWtime);
|
||||
memset(NOWtime,0,15);
|
||||
memcpy(NOWtime,Init_Data_Equipment.appointment_time,8);
|
||||
appointment_y = atoi(NOWtime);
|
||||
memset(NOWtime,0,15);
|
||||
memcpy(NOWtime,&Init_Data_Equipment.appointment_time[8],6);
|
||||
appointment_s = atoi(NOWtime);
|
||||
if(NOW_y > appointment_y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(NOW_y < appointment_y)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(NOW_s > appointment_s)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USER_Task_BC25()
|
||||
*<2A><> <20>ܣ<EFBFBD>NBģ<42><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USER_Task_BC25(void *argument)
|
||||
{
|
||||
u8 i=0;
|
||||
u32 BC25_SIZE=0;
|
||||
osStatus_t BC25_Thread_status;
|
||||
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreAcquire(BC25ID_Semaphore, osWaitForever);
|
||||
time__sta_bc25=osKernelGetTickCount ();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
TASKRUNSS.BC25_RUN=1;
|
||||
BC25_Status.socket=0;
|
||||
//u5_printf("BC25_Start\r\n");
|
||||
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
BC25_Init();
|
||||
if(BC25_Status.netstatus==1)
|
||||
{
|
||||
i=6;
|
||||
BC25_CloseSocket();//<2F>ر<EFBFBD><D8B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BC25_CreateSokcet(Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(BC25_Status.cpin==0)//<2F><><EFBFBD><EFBFBD>ûװ<C3BB><D7B0><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
i=6;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+CGPADDR?\r\n");
|
||||
//delay_ms(500);
|
||||
//u5_printf("IP:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFread_BIT_5);
|
||||
if(osEventFlagsGet(EventFlagID_PROCESS)&EVENT_TFstore_BIT_6)
|
||||
{
|
||||
osDelay(3000);
|
||||
}
|
||||
if(BC25_Status.netstatus==1)
|
||||
{
|
||||
i=0;
|
||||
BC25_SIZE=0;
|
||||
while((BC25_SIZE<=30)&(i<50))
|
||||
{
|
||||
i++;
|
||||
delay_ms(5);
|
||||
BC25_SIZE=txt_size_read("BC25");
|
||||
}
|
||||
if(BC25_SIZE>30)
|
||||
{
|
||||
//u5_printf("BC25_txt_size:%ld\r\n",BC25_SIZE);
|
||||
FATFS_Read_TF("BC25",0,BC25_SIZE);//<2F><>ȡTF<54><46>¼<EFBFBD><C2BC><EFBFBD>ݣ<EFBFBD>ͨ<EFBFBD><CDA8>BC25<32><35><EFBFBD><EFBFBD>
|
||||
i=0;
|
||||
while(i<10)
|
||||
{
|
||||
osDelay(1000);
|
||||
if(strstr((char*)USART2_RX_BUF,"par")!=NULL)
|
||||
{
|
||||
USART2_Recieve_Ide();
|
||||
USART2_ReceiveBuff_Clear();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
//u5_printf("BC25.txt send finish\r\n");
|
||||
}
|
||||
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_TFread_BIT_5);
|
||||
BC25_POWEROFF();
|
||||
TASKRUNSS.BC25_RUN=0;
|
||||
//u5_printf("Terminate TaskBC25\r\n");
|
||||
i=0;
|
||||
osSemaphoreRelease(BC25ID_Semaphore);
|
||||
BC25_Thread_status=osThreadTerminate(ThreadIdTaskBC25);
|
||||
//u5_printf("Terminate TaskBC25............... fail\r\n");
|
||||
while((BC25_Thread_status!=osOK)&(i<10))
|
||||
{
|
||||
//u5_printf("BC25_Thread_status:%d\r\n",BC25_Thread_status);
|
||||
BC25_Thread_status=osThreadTerminate(ThreadIdTaskBC25);
|
||||
i++;
|
||||
|
||||
}
|
||||
//BC25_Thread_status=osThreadTerminate(ThreadIdTaskBC25);
|
||||
osDelay(500);
|
||||
}
|
||||
}
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USER_Task_LinkStatus()
|
||||
*<2A><> <20>ܣ<EFBFBD>WIFI<46><49>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>ͬʱ<CDAC>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>пͻ<D0BF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USER_Task_LinkStatus(void *argument)
|
||||
{
|
||||
u8 i=0;
|
||||
// osDelay(20000);//<2F>ӳٵȴ<D9B5><C8B4><EFBFBD><EFBFBD><EFBFBD>WIFI
|
||||
//osEventFlagsWait(EventFlagID_PROCESS,EVENT_WIFIcreat_BIT_9,osFlagsWaitAll,200000 );
|
||||
while(1)
|
||||
{
|
||||
|
||||
uint8_t Temp_LinkStatus=0;
|
||||
LinkStatus=2;
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
osMutexAcquire(WIFI_MutexID,osWaitForever);
|
||||
Temp_LinkStatus=ESP8266_Get_LinkStatus();
|
||||
if(Temp_LinkStatus==2)
|
||||
{
|
||||
i=0;
|
||||
ESP8266_SendString(DISABLE,"Heartbeat,*",11,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
osMutexRelease(WIFI_MutexID);
|
||||
osDelay(60000);
|
||||
//osDelay(30000);
|
||||
}
|
||||
//LinkStatus=0;
|
||||
if(LinkStatus!=2)
|
||||
{
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_LinkStatus_BIT_3);
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_WIFIcreat_BIT_9);
|
||||
osThreadTerminate(ThreadIdTaskLinkStatus);
|
||||
osThreadTerminate(ThreadIdWIFI);
|
||||
}
|
||||
osDelay(5);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USER_Task_WIFI()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>WIFI<46><49><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>ѯ<EFBFBD>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7>͵<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USER_Task_WIFI(void *argument)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(!(osEventFlagsGet(EventFlagID_PROCESS)&EVENT_WIFIcreat_BIT_9))
|
||||
{
|
||||
ESP8266_AP_TCPServer_Config(Init_Data_Equipment.ESP8266_AP_SSIDs,
|
||||
Init_Data_Equipment.ESP8266_AP_PWDs,
|
||||
Init_Data_Equipment.ESP8266_AP_Ports);
|
||||
// Creat_WIFI=1;
|
||||
PWR_CTRL5V_H; //<2F><><EFBFBD><EFBFBD>5V 9V<39><56>Դ
|
||||
//PWR_CTRL3V3_H;
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_WIFIcreat_BIT_9);
|
||||
__nop();
|
||||
}
|
||||
osMutexAcquire(WIFI_MutexID,osWaitForever);
|
||||
USART4_Recieve_Ide();
|
||||
osMutexRelease(WIFI_MutexID);
|
||||
osDelay(20);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USERTask_Process1()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ݲɼ<DDB2><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
void USERTask_Process1(void *argument)
|
||||
{
|
||||
u8 i=0;
|
||||
//char Process1_Buf[300]={'\0'};
|
||||
osStatus_t PRO1_Thread_status;
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreAcquire(Process1ID_Semaphore, osWaitForever);
|
||||
time__sta_pro1=osKernelGetTickCount ();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
TASKRUNSS.PROS1_RUN=1;
|
||||
GetRTC(rtc_time,rtc_data);
|
||||
sprintf(name,"%s_%s.txt",rtc_data,Init_Data_Equipment.Measure_Interval);
|
||||
if(IS_FIRST_SAVE)
|
||||
{
|
||||
memcpy(rtc_data,&Init_Data_Equipment.appointment_time[2],6);
|
||||
memcpy(rtc_time,&Init_Data_Equipment.appointment_time[8],6);
|
||||
IS_FIRST_SAVE = 0;
|
||||
}
|
||||
L76X_POWER_ON(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Դ
|
||||
|
||||
ADC15_POWERON(); //<2F><><EFBFBD><EFBFBD>ADC<44><43>Դ
|
||||
delay_ms(10); //<2F><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>͵<EFBFBD>ѹʱ<D1B9><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
PWR_CTRL5V_H; //<2F><><EFBFBD><EFBFBD>5V 9V<39><56>Դ
|
||||
|
||||
sdi12_process();
|
||||
ADC15_Process();
|
||||
|
||||
L76C_Process();
|
||||
Common_Data_Pack();//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
|
||||
if(osEventFlagsGet(EventFlagID_PROCESS)&EVENT_TFread_BIT_5)//BC25<32><35>Զ<EFBFBD><D4B6>
|
||||
{
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
//u5_printf("stroe wait\r\n");
|
||||
osEventFlagsWait(EventFlagID_PROCESS,EVENT_TFread2_BIT_7,osFlagsWaitAll,10000 );
|
||||
//u5_printf("TF data entry1\r\n");
|
||||
Data_Write_TF();
|
||||
//u5_printf("stroe finish\r\n");
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore2_BIT_8);
|
||||
}
|
||||
else
|
||||
{
|
||||
//u5_printf("TF data entry2\r\n");
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
|
||||
Data_Write_TF();
|
||||
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
//u5_printf("TF data quit2\r\n");
|
||||
}
|
||||
// if(LinkStatus == 2)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WIFI<46><49><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>͵<EFBFBD><CDB5><EFBFBD>λ<EFBFBD><CEBB>
|
||||
// {
|
||||
// sprintf(Process1_Buf,"%s%s%s,*","Pub,",data_common1.Pack_len,data_common1.Pack_data);
|
||||
// osMutexAcquire(WIFI_MutexID,osWaitForever);
|
||||
// ESP8266_SendString(DISABLE,Process1_Buf,strlen(Process1_Buf),0);
|
||||
// osMutexRelease(WIFI_MutexID);
|
||||
// }
|
||||
//u5_printf("Terminate Procsee1\r\n");
|
||||
// L76X_POWER_OFF();
|
||||
// ADC15_POWEROFF();
|
||||
// PWR_CTRL5V_L;
|
||||
osSemaphoreRelease(Process1ID_Semaphore);
|
||||
TASKRUNSS.PROS1_RUN=0;
|
||||
osThreadTerminate(ThreadIdProcsee1);
|
||||
//u5_printf("Terminate Procsee1 fail\r\n");
|
||||
PRO1_Thread_status=osThreadTerminate(ThreadIdProcsee1);
|
||||
while((PRO1_Thread_status!=osOK)&(i<10))
|
||||
{
|
||||
//u5_printf("PRO1_Thread_status:%d\r\n",PRO1_Thread_status);
|
||||
PRO1_Thread_status=osThreadTerminate(ThreadIdProcsee1);
|
||||
i++;
|
||||
}
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USERTask_Resume()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺ȫ<EBA3BA>ֱ<EFBFBD><D6B1><EFBFBD> MYITStatus1
|
||||
* ȫ<>ֱ<EFBFBD><D6B1><EFBFBD> WKUP_PIN_Status
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USERTask_Resume(void *argument)
|
||||
{
|
||||
u32 measurt_idv_set;
|
||||
osThreadState_t Thread_Stasus;
|
||||
while(1)
|
||||
{
|
||||
if(MYITStatus1.AlarmA_ITStatus == 1)
|
||||
{
|
||||
//u5_printf("TASKRUNSS.BC25_RUN:%d\r\n",TASKRUNSS.BC25_RUN);
|
||||
Thread_Stasus=osThreadGetState(ThreadIdTaskBC25);
|
||||
//u5_printf("Thread_Stasus_bc25:%d\r\n",Thread_Stasus);
|
||||
if((Thread_Stasus==osThreadError )||(TASKRUNSS.BC25_RUN!=1))
|
||||
{
|
||||
//u5_printf("USER_Task_BC25 creat\r\n");
|
||||
ThreadIdTaskBC25 = osThreadNew(USER_Task_BC25, NULL, &ThreadBC25_Attr);
|
||||
}
|
||||
//u5_printf("config AlarmA\r\n");
|
||||
MYITStatus1.AlarmA_ITStatus=0;
|
||||
RTC_AlarmAConfig(get_pubidv());
|
||||
}
|
||||
if(MYITStatus1.AlarmB_ITStatus == 1)
|
||||
{
|
||||
Thread_Stasus=osThreadGetState(ThreadIdProcsee1);
|
||||
//u5_printf("PROSS1_Thread_Stasus:%d\r\n",Thread_Stasus);
|
||||
if(Thread_Stasus==osThreadError )
|
||||
{
|
||||
//u5_printf("USERTask_Process1 creat\r\n");
|
||||
ThreadIdProcsee1 = osThreadNew(USERTask_Process1, NULL, &ThreadPROCESS1_Attr);
|
||||
}
|
||||
MYITStatus1.AlarmB_ITStatus=0;
|
||||
Measure_Ap_E();
|
||||
//Write_Equipment_Par(Init_Data_Equipment); //<2F>ػ<EFBFBD><D8BB>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
CLOSE_ALARM = 1;
|
||||
}
|
||||
if(MYITStatus1.WUT_ITStatus == 1)
|
||||
{
|
||||
//u5_printf("USERTask_Process1 start\r\n");
|
||||
Thread_Stasus=osThreadGetState(ThreadIdProcsee1);
|
||||
//u5_printf("PROSS1_Thread_Stasus:%d\r\n",Thread_Stasus);
|
||||
if((Thread_Stasus==osThreadError )||(TASKRUNSS.PROS1_RUN!=1))
|
||||
{
|
||||
//u5_printf("USERTask_Process1 creat\r\n");
|
||||
// Thread_Stasus=osThreadGetState(ThreadIdTaskBC25);
|
||||
// if(Thread_Stasus == 1)
|
||||
// {
|
||||
// osDelay(1000);
|
||||
// }
|
||||
ThreadIdProcsee1 = osThreadNew(USERTask_Process1, NULL, &ThreadPROCESS1_Attr);
|
||||
}
|
||||
MYITStatus1.WUT_ITStatus=0;
|
||||
|
||||
if(measurt_idv_set<1)
|
||||
{
|
||||
measurt_idv_set=1;
|
||||
}
|
||||
RtcWakeUpConfig(get_meaidv() - 1);
|
||||
// if(CLOSE_ALARM)
|
||||
// {
|
||||
// CLOSE_ALARM = 0;
|
||||
// RtcWakeUpConfig(get_meaidv() - 4);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// RtcWakeUpConfig(get_meaidv() - 2);
|
||||
// }
|
||||
|
||||
|
||||
wut_rtc_s=RTC_GetSeconds()+measurt_idv_set*60;
|
||||
if(wut_rtc_s>86400)wut_rtc_s-=86400;
|
||||
}
|
||||
if(1)//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>MYITStatus1.WKUP1_ITStatus == 1
|
||||
{
|
||||
//if(WKUP_PIN_Status==4)//<2F><><EFBFBD><EFBFBD>10S<30><53><EFBFBD>ϣ<EFBFBD><CFA3>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(key_time==200)//<2F><><EFBFBD><EFBFBD>10S<30><53><EFBFBD>ϣ<EFBFBD><CFA3>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
MYITStatus1.WKUP1_ITStatus =0;
|
||||
//u5_printf("WKUP_PIN_10S\r\n");
|
||||
Write_Factory_Par();
|
||||
}
|
||||
if((key_time>=30)|(Check_WKUP_key))//<2F><><EFBFBD><EFBFBD>3S<33><53><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>WIFI
|
||||
{
|
||||
Thread_Stasus=osThreadGetState(ThreadIdTaskLinkStatus);
|
||||
if(Thread_Stasus==osThreadError )
|
||||
{
|
||||
//u5_printf("Create Wifi Task\r\n");
|
||||
ThreadIdWIFI = osThreadNew(USER_Task_WIFI, NULL, &ThreadWIFI_Attr);
|
||||
ThreadIdTaskLinkStatus = osThreadNew(USER_Task_LinkStatus, NULL, &ThreadLinkStatus_Attr);
|
||||
}
|
||||
MYITStatus1.WKUP1_ITStatus =0;
|
||||
Check_WKUP_key=0;
|
||||
//u5_printf("WKUP_PIN_3S\r\n");
|
||||
|
||||
}
|
||||
}
|
||||
if(MYITStatus1.WKUP_POWBUTTON == 1)//<2F><>Դ<EFBFBD>ϵ<EFBFBD>
|
||||
{
|
||||
MYITStatus1.WKUP_POWBUTTON=0;
|
||||
|
||||
|
||||
if((Init_Data_Equipment.measure_mode[0]=='1') && (IsAppointmentRight()))//ģʽΪ1<CEAA><31>ԤԼ<D4A4><D4BC><EFBFBD><EFBFBD>,ֻ<><D6BB><EFBFBD><EFBFBD>ԤԼ<D4A4><D4BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
{
|
||||
Measure_Ap_S();
|
||||
TASKRUNSS.POW_RUN=0;//ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԤԼʱ<D4BC><CAB1>
|
||||
}else
|
||||
{
|
||||
Thread_Stasus=osThreadGetState(ThreadIdProcsee1);
|
||||
if(Thread_Stasus==osThreadError )
|
||||
{
|
||||
ThreadIdProcsee1 = osThreadNew(USERTask_Process1, NULL, &ThreadPROCESS1_Attr);
|
||||
}
|
||||
|
||||
RtcWakeUpConfig(get_meaidv() - 1);
|
||||
RTC_AlarmAConfig(get_pubidv());
|
||||
}
|
||||
|
||||
}
|
||||
if(MYITStatus1.WKUP_MEA_WIFI == 1)//WIFI<46><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
Thread_Stasus=osThreadGetState(ThreadIdProcsee1);
|
||||
if(Thread_Stasus==osThreadError )
|
||||
{
|
||||
ThreadIdProcsee1 = osThreadNew(USERTask_Process1, NULL, &ThreadPROCESS1_Attr);
|
||||
}
|
||||
MYITStatus1.WKUP_MEA_WIFI=0;
|
||||
}
|
||||
if(MYITStatus1.WKUP_Test_WIFI == 1)//WIFI<46><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
Thread_Stasus=osThreadGetState(ThreadIdTest);
|
||||
if((Thread_Stasus==osThreadError )||(!(osEventFlagsGet(EventFlagID_PROCESS)&EVENT_Test_BIT_10)))
|
||||
{
|
||||
|
||||
ThreadIdTest=osThreadNew(User_Task_Test,NULL,&ThreadTest_Attr);
|
||||
}
|
||||
MYITStatus1.WKUP_Test_WIFI=0;
|
||||
}
|
||||
osDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USER_Task_MSG()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>ģʽ
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USER_Task_MSG(void *argument)
|
||||
{
|
||||
osDelay(500);//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while(1)
|
||||
{
|
||||
if(osThreadGetState(ThreadIdTaskBC25)==osThreadError)
|
||||
{
|
||||
TASKFISHEDS.BC25_FIS=1;
|
||||
}
|
||||
else
|
||||
TASKFISHEDS.BC25_FIS=0;
|
||||
if(osThreadGetState(ThreadIdProcsee1)==osThreadError)
|
||||
{
|
||||
TASKFISHEDS.PROS1_FIS=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TASKFISHEDS.PROS1_FIS=0;
|
||||
}
|
||||
|
||||
if(osThreadGetState(ThreadIdTaskLinkStatus)==osThreadError)
|
||||
{
|
||||
TASKFISHEDS.WIFILink_FIS=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TASKFISHEDS.WIFILink_FIS=0;
|
||||
}
|
||||
//u5_printf("%d,%d,%d\r\n",TASKFISHEDS.PROS1_FIS,TASKFISHEDS.BC25_FIS,TASKFISHEDS.WIFILink_FIS);
|
||||
if(TASKFISHEDS.BC25_FIS &
|
||||
TASKFISHEDS.PROS1_FIS &
|
||||
TASKFISHEDS.WIFILink_FIS &
|
||||
(!MYITStatus1.WUT_ITStatus)&
|
||||
(!MYITStatus1.AlarmA_ITStatus&
|
||||
!WKUP_KD )
|
||||
)
|
||||
{
|
||||
if((Init_Data_Equipment.measure_mode[0]==0x31) && (IsAppointmentRight()))//<2F><><EFBFBD><EFBFBD>ģʽΪ1<CEAA><31>ԤԼ<D4A4><D4BC><EFBFBD><EFBFBD>
|
||||
{
|
||||
RTC_WakeUpCmd(DISABLE);//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>份<EFBFBD><E4BBBD><EFBFBD><EFBFBD><EFBFBD>ݲɼ<DDB2>
|
||||
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);//<2F><><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>
|
||||
}
|
||||
|
||||
//u5_printf("Procsee1_status:%d\r\n",osThreadGetState(ThreadIdProcsee1));
|
||||
//u5_printf("BC25_status:%d\r\n",osThreadGetState(ThreadIdTaskBC25));
|
||||
EXTI_ClearITPendingBit(EXTI_Line13);
|
||||
RTC_ClearITPendingBit(RTC_IT_WUT);
|
||||
EXTI_ClearITPendingBit(EXTI_Line20);
|
||||
RTC_ClearITPendingBit(RTC_IT_ALRB);
|
||||
RTC_ClearITPendingBit(RTC_IT_ALRA);
|
||||
EXTI_ClearITPendingBit(EXTI_Line17);
|
||||
|
||||
PWR_EnterSTANDBYMode();
|
||||
}
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void User_Task_Test(void *argument)
|
||||
{
|
||||
char Test_Buf[400];
|
||||
int len;
|
||||
char rtc_data_test[15]={0},rtc_time_test[15]={0};
|
||||
u32 tf_total,tf_free;
|
||||
while(1)
|
||||
{
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_Test_BIT_10);
|
||||
//u5_printf("User_Task_Test_start\r\n");
|
||||
//PWR_CTRL3V3_H; //<2F><><EFBFBD><EFBFBD>3.3V<EFBFBD>ܵ<EFBFBD>Դ
|
||||
osDelay(1000);
|
||||
TASKRUNSS.Test_RUN=1;
|
||||
GetRTC(rtc_time_test,rtc_data_test);
|
||||
/************************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD>ʼ******************************/
|
||||
|
||||
if(!TASKRUNSS.PROS1_RUN)
|
||||
{
|
||||
osSemaphoreAcquire(Process1ID_Semaphore, osWaitForever);
|
||||
GetRTC(rtc_time,rtc_data);
|
||||
L76X_POWER_ON(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Դ
|
||||
ADC15_POWERON(); //<2F><><EFBFBD><EFBFBD>ADC<44><43>Դ
|
||||
PWR_CTRL5V_H; //<2F><><EFBFBD><EFBFBD>5V 9V<39><56>Դ
|
||||
sdi12_process();
|
||||
ADC15_Process();
|
||||
L76C_Process();
|
||||
}
|
||||
else
|
||||
{
|
||||
osSemaphoreAcquire(Process1ID_Semaphore, osWaitForever);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
sprintf(rtc_data,"%s",rtc_data_test);
|
||||
sprintf(rtc_time,"%s",rtc_time_test);
|
||||
Common_Data_Pack();//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
/************************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD>*****************************/
|
||||
|
||||
/*************************Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD>ʼ*****************************/
|
||||
|
||||
if(!TASKRUNSS.BC25_RUN)
|
||||
{
|
||||
osSemaphoreAcquire(BC25ID_Semaphore, osWaitForever);
|
||||
BC25_Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
//osSemaphoreAcquire(BC25ID_Semaphore, osWaitForever);
|
||||
}
|
||||
|
||||
/*************************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*****************************/
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Pub,<2C><><EFBFBD>ȣ<EFBFBD><C8A3>豸<EFBFBD>ţ<EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>IOT_Cpin,IOT_Csq,IOT_Net,Tf_Tol,Tf_Free
|
||||
|
||||
if(osEventFlagsGet(EventFlagID_PROCESS)&EVENT_TFread_BIT_5)//BC25<32><35>Զ<EFBFBD><D4B6>
|
||||
{
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
//u5_printf("test stroe wait\r\n");
|
||||
osEventFlagsWait(EventFlagID_PROCESS,EVENT_TFread2_BIT_7,osFlagsWaitAll,10000 );
|
||||
//u5_printf("test TF data entry1\r\n");
|
||||
|
||||
exf_getfree("0", &tf_total, &tf_free);
|
||||
len = strlen(data_common1.Pack_data);
|
||||
sprintf(data_common1.Pack_data+len,",%d,%d,%d,%ld,%ld",BC25_Status.cpin,BC25_Status.CSQ,BC25_Status.netstatus,tf_total,tf_free);
|
||||
Write_Test();
|
||||
//u5_printf("test stroe finish\r\n");
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore2_BIT_8);
|
||||
}
|
||||
else
|
||||
{
|
||||
osEventFlagsSet(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
exf_getfree("0", &tf_total, &tf_free);
|
||||
len = strlen(data_common1.Pack_data);
|
||||
sprintf(data_common1.Pack_data+len,",%d,%d,%d,%ld,%ld",BC25_Status.cpin,BC25_Status.CSQ,BC25_Status.netstatus,tf_total,tf_free);
|
||||
Write_Test();
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_TFstore_BIT_6);
|
||||
}
|
||||
sprintf(Test_Buf,"%s%d,%s,*","Pub,",strlen(data_common1.Pack_data)+2,data_common1.Pack_data);
|
||||
//u5_printf("test_buf %s\r\n",Test_Buf);
|
||||
osMutexAcquire(WIFI_MutexID,osWaitForever);
|
||||
ESP8266_SendString(DISABLE,Test_Buf,strlen(Test_Buf),0);
|
||||
osMutexRelease(WIFI_MutexID);
|
||||
//<2F>ͷ<EFBFBD>
|
||||
osSemaphoreRelease(BC25ID_Semaphore);
|
||||
osSemaphoreRelease(Process1ID_Semaphore);
|
||||
TASKRUNSS.Test_RUN=0;
|
||||
osEventFlagsClear(EventFlagID_PROCESS,EVENT_Test_BIT_10);
|
||||
osThreadTerminate(ThreadIdTest);
|
||||
|
||||
/*************************Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD>*****************************/
|
||||
}
|
||||
|
||||
}
|
||||
/****************************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USERTaskCreate()
|
||||
*<2A><> <20>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><> <20>룺<EFBFBD><EBA3BA>
|
||||
*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void USERTaskCreate(void)
|
||||
{
|
||||
EEPROM_ReadBytes(110,(u8*)Init_Data_Equipment.Pub_Mode,1);
|
||||
WIFI_MutexID = osMutexNew(&WIFI_Mutex_Attr );
|
||||
SDI_MutexID = osMutexNew(&SDI_Mutex_Attr );
|
||||
TFcard_MutexID = osMutexNew(&TF_Mutex_Attr );
|
||||
ThreadIdUSERTask_Resume = osThreadNew(USERTask_Resume, NULL, &ThreadUSERTask_Resume_Attr);
|
||||
ThreadIdSMSG = osThreadNew(USER_Task_MSG, NULL, &ThreadMSG_Attr); //<2F><EFBFBD><CDB9><EFBFBD>
|
||||
}
|
||||
|
||||
/*********************************************************************************************************/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* <09><> <20><> <20><>: AppTaskStart()
|
||||
* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD>
|
||||
* <09><> <20><> <20><><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>time__sta_pro1
|
||||
* Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>time__sta_bc25
|
||||
* <20><> <20><> <20><><EFBFBD><EFBFBD>
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void USERTaskStart(void *argument)
|
||||
{
|
||||
u32 mea_idv_idl1,pub_idv_idl1;
|
||||
uint8_t i=0;
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
USERTaskCreate();
|
||||
while(1)
|
||||
{
|
||||
mea_idv_idl1=osKernelGetTickCount()-time__sta_pro1;
|
||||
pub_idv_idl1=osKernelGetTickCount()-time__sta_bc25;
|
||||
i++;
|
||||
if(i>=10)
|
||||
{
|
||||
//u5_printf("mea_idv_idl1:%d\r\npub_idv_idl1:%d\r\n",mea_idv_idl1,pub_idv_idl1);
|
||||
i=0;
|
||||
}
|
||||
if(LinkStatus == 2)
|
||||
{
|
||||
mea_idv_idl1=0;
|
||||
pub_idv_idl1=0;
|
||||
}
|
||||
if((mea_idv_idl1>(get_meaidv()*1000+200000))&(LinkStatus != 2))//û<><C3BB>WIFI<46><49><EFBFBD><EFBFBD>+<2B><>ʱ
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
if((pub_idv_idl1>(get_pubidv()*1000+7200000))&(LinkStatus != 2))//û<><C3BB>WIFI<46><49><EFBFBD><EFBFBD>+<2B><>ʱ
|
||||
{
|
||||
NVIC_SystemReset();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>λ
|
||||
}
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************** END OF FILE *********************************/
|
||||
|
||||
26
RTX5_20220316/main/main.c.txt
Normal file
26
RTX5_20220316/main/main.c.txt
Normal file
@ -0,0 +1,26 @@
|
||||
/******************** (C) COPYRIGHT 2018 Designed by Captain *********************
|
||||
* <20>ļ<EFBFBD><C4BC><EFBFBD> <20><>main.c
|
||||
* <20><><EFBFBD><EFBFBD> : AD<41>ɼ<EFBFBD>ʵ<EFBFBD><CAB5> PB14 ADC1_Channel 20 <20><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>ADC<44>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>9600
|
||||
* ʵ<><CAB5>ƽ̨<C6BD><CCA8>STM32L151C8T6/CBT6<54><36><EFBFBD>İ<EFBFBD>
|
||||
* <20><><EFBFBD>汾 <20><>ST1.0.0
|
||||
* ʱ<><CAB1> <20><>2019-7-26
|
||||
* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>AD<41>ɼ<EFBFBD><C9BC>ĵ<EFBFBD>ѹֵ PB14 PB15
|
||||
* <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>
|
||||
* <20>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>1 <20><>https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-17922877423.31.78385d6d9n5D9C&id=600155773306
|
||||
* <20>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>2 <20><>https://item.taobao.com/item.htm?spm=a230r.1.14.20.7b545e82MPRlaH&id=581331325422&ns=1&abbucket=19#detail
|
||||
**********************************************************************************/
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
//extern __IO uint16_t VREFINT_CAL;
|
||||
int main(void)
|
||||
{
|
||||
Equitment_Init();
|
||||
while(1)
|
||||
{
|
||||
process();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
17
RTX5_20220316/main/pbdata.h
Normal file
17
RTX5_20220316/main/pbdata.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _pbdata_H
|
||||
#define _pbdata_H
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "misc.h"
|
||||
#include "stm32l1xx.h"
|
||||
#include "stm32l1xx_usart.h"
|
||||
#include "stm32l1xx_tim.h"
|
||||
#include "stm32l1xx_gpio.h"
|
||||
#include "stm32l1xx_rcc.h"
|
||||
#include "stm32l1xx_adc.h"
|
||||
|
||||
#include "sys.h"
|
||||
#include "delay.h"
|
||||
|
||||
#endif
|
||||
6349
RTX5_20220316/main/stm32l1xx.h
Normal file
6349
RTX5_20220316/main/stm32l1xx.h
Normal file
File diff suppressed because it is too large
Load Diff
786
RTX5_20220316/main/stm32l1xx_clock_config.c
Normal file
786
RTX5_20220316/main/stm32l1xx_clock_config.c
Normal file
@ -0,0 +1,786 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l1xx_clock_config.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 24-January-2012
|
||||
* @brief This file provides firmware functions to configure the STM32L1xx
|
||||
* system clock frequency to MSI, HSI, HSE, 4 MHz, 8 MHz, 16 MHz and
|
||||
* 32 MHz.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* FOR MORE INFORMATION PLEASE READ CAREFULLY THE LICENSE AGREEMENT FILE
|
||||
* LOCATED IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l1xx_clock_config.h"
|
||||
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ErrorStatus HSEStartUpStatus;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (Default Value, 2MHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_2MHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (64KHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_64KHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 64KHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_0);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (128KHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_128KHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 128KHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_1);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (256KHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_256KHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 256KHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_2);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (512KHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_512KHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 512KHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_3);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (1MHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_1MHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 1MHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_4);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects MSI (4MHz) as System clock source and configure
|
||||
* HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToMSI_4MHz(void)
|
||||
{
|
||||
/* RCC system reset */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(ENABLE);
|
||||
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(ENABLE);
|
||||
|
||||
/* Flash 1 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_1);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 3 (1.2V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Set MSI clock range to 4MHz */
|
||||
RCC_MSIRangeConfig(RCC_MSIRange_6);
|
||||
|
||||
/* Select MSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x00)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects HSI as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToHSI(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSIStatus = 0;
|
||||
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSI */
|
||||
RCC_HSICmd(ENABLE);
|
||||
|
||||
/* Wait till HSI is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSIStatus = RCC_GetFlagStatus(RCC_FLAG_HSIRDY);
|
||||
StartUpCounter++;
|
||||
}
|
||||
while ((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));
|
||||
|
||||
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != RESET)
|
||||
{
|
||||
HSIStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSIStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSIStatus == 0x01)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 1 (1.8V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Select HSI as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
|
||||
|
||||
/* Wait till HSI is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x04)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSI fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKToHSE(void)
|
||||
{
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSE */
|
||||
RCC_HSEConfig(RCC_HSE_ON);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||
|
||||
if (HSEStartUpStatus == SUCCESS)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 2 (1.5V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Select HSE as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
|
||||
|
||||
/* Wait till HSE is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x08)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKTo4(void)
|
||||
{
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSE */
|
||||
RCC_HSEConfig(RCC_HSE_ON);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||
|
||||
if (HSEStartUpStatus == SUCCESS)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 2 (1.5V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK/2 */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div2);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Select HSE as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
|
||||
|
||||
/* Wait till HSE is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x08)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKTo8(void)
|
||||
{
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSE */
|
||||
RCC_HSEConfig(RCC_HSE_ON);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||
|
||||
if (HSEStartUpStatus == SUCCESS)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_0);
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(DISABLE);
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(DISABLE);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 2 (1.5V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* Select HSE as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
|
||||
|
||||
/* Wait till HSE is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x08)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects PLL as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKTo16(void)
|
||||
{
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSE */
|
||||
RCC_HSEConfig(RCC_HSE_ON);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||
|
||||
if (HSEStartUpStatus == SUCCESS)
|
||||
{
|
||||
/* Enable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(ENABLE);
|
||||
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(ENABLE);
|
||||
|
||||
/* Flash 1 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_1);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 2 (1.5V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK/2 */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div2);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PLL configuration: PLLCLK = (HSE * 12) / 3 = 32MHz */
|
||||
RCC_PLLConfig(RCC_PLLSource_HSE, RCC_PLLMul_12, RCC_PLLDiv_3);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC_PLLCmd(ENABLE);
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
|
||||
{}
|
||||
|
||||
/* Select PLL as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x0C)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects PLL as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SetHCLKTo32(void)
|
||||
{
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
|
||||
/* RCC system reset(for debug purpose) */
|
||||
RCC_DeInit();
|
||||
|
||||
/* Enable HSE */
|
||||
RCC_HSEConfig(RCC_HSE_ON);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||
|
||||
if (HSEStartUpStatus == SUCCESS)
|
||||
{
|
||||
/* Enable 64-bit access */
|
||||
FLASH_ReadAccess64Cmd(ENABLE);
|
||||
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(ENABLE);
|
||||
|
||||
/* Flash 1 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_1);
|
||||
|
||||
/* Enable the PWR APB1 Clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
/* Select the Voltage Range 1 (1.8V) */
|
||||
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
|
||||
{}
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
|
||||
/* PCLK2 = HCLK */
|
||||
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PCLK1 = HCLK */
|
||||
RCC_PCLK1Config(RCC_HCLK_Div1);
|
||||
|
||||
/* PLL configuration: PLLCLK = (HSE * 12) / 3 = 32MHz */
|
||||
RCC_PLLConfig(RCC_PLLSource_HSE, RCC_PLLMul_12, RCC_PLLDiv_3);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC_PLLCmd(ENABLE);
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
|
||||
{}
|
||||
|
||||
/* Select PLL as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while (RCC_GetSYSCLKSource() != 0x0C)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock configuration.
|
||||
User can add here some code to deal with this error */
|
||||
|
||||
/* Go to infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
|
||||
53
RTX5_20220316/main/stm32l1xx_clock_config.h
Normal file
53
RTX5_20220316/main/stm32l1xx_clock_config.h
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l1xx_clock_config.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 24-January-2012
|
||||
* @brief Header for stm32l1xx_clock_config.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* FOR MORE INFORMATION PLEASE READ CAREFULLY THE LICENSE AGREEMENT FILE
|
||||
* LOCATED IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L1xx_CLOCK_CONFIG_H
|
||||
#define __STM32L1xx_CLOCK_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l1xx.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void SetHCLKToMSI_2MHz(void);
|
||||
void SetHCLKToMSI_64KHz(void);
|
||||
void SetHCLKToMSI_128KHz(void);
|
||||
void SetHCLKToMSI_256KHz(void);
|
||||
void SetHCLKToMSI_512KHz(void);
|
||||
void SetHCLKToMSI_1MHz(void);
|
||||
void SetHCLKToMSI_4MHz(void);
|
||||
void SetHCLKToHSI(void);
|
||||
void SetHCLKToHSE(void);
|
||||
void SetHCLKTo4(void);
|
||||
void SetHCLKTo8(void);
|
||||
void SetHCLKTo16(void);
|
||||
void SetHCLKTo24(void);
|
||||
void SetHCLKTo32(void);
|
||||
|
||||
#endif /* __STM32L1xx_CLOCK_CONFIG_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
|
||||
173
RTX5_20220316/main/stm32l1xx_it.c
Normal file
173
RTX5_20220316/main/stm32l1xx_it.c
Normal file
@ -0,0 +1,173 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file TIM/TimeBase/stm32l1xx_it.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 31-December-2010
|
||||
* @brief Main Interrupt Service Routines.
|
||||
* This file provides template for all exceptions handler and peripherals
|
||||
* interrupt service routine.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l1xx_it.h"
|
||||
#include "stm32l1xx_tim.h"
|
||||
#include "stm32l1xx_usart.h"
|
||||
#include "general_type.h"
|
||||
#include "bsp.h"
|
||||
u8 flag;
|
||||
/** @addtogroup STM32L1xx_StdPeriph_Examples
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TIM_TimeBase
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint16_t capture = 0;
|
||||
extern __IO uint16_t CCR1_Val;
|
||||
extern __IO uint16_t CCR2_Val;
|
||||
extern __IO uint16_t CCR3_Val;
|
||||
extern __IO uint16_t CCR4_Val;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M3 Processor Exceptions Handlers */
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function handles NMI exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
|
||||
/* Go to infinite loop when Hard Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory Manage exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Memory Manage exception occurs */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Bus Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Bus Fault exception occurs */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Usage Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Usage Fault exception occurs */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug Monitor exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief This function handles SVCall exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function handles SysTick Handler.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32L1xx Peripherals Interrupt Handlers */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM2 global interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32L1xx Peripherals Interrupt Handlers */
|
||||
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
|
||||
/* available peripheral interrupt handler's name please refer to the startup */
|
||||
/* file (startup_stm32l1xx_xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles PPP interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
/*void PPP_IRQHandler(void)
|
||||
{
|
||||
}*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|
||||
47
RTX5_20220316/main/stm32l1xx_it.h
Normal file
47
RTX5_20220316/main/stm32l1xx_it.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file TIM/TimeBase/stm32l1xx_it.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 31-December-2010
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L1xx_IT_H
|
||||
#define __STM32L1xx_IT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l1xx.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void TIM2_IRQHandler(void);
|
||||
|
||||
#endif /* __STM32L1xx_IT_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|
||||
530
RTX5_20220316/main/system_stm32l1xx.c
Normal file
530
RTX5_20220316/main/system_stm32l1xx.c
Normal file
@ -0,0 +1,530 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32l1xx.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 24-January-2012
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
* This file contains the system clock configuration for STM32L1xx Ultra
|
||||
* Low Power devices, and is generated by the clock configuration
|
||||
* tool "STM32L1xx_Clock_Configuration_V1.1.0.xls".
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* and Divider factors, AHB/APBx prescalers and Flash settings),
|
||||
* depending on the configuration made in the clock xls tool.
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32l1xx_xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the MSI (2.1 MHz Range) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32l1xx_xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 3. If the system clock source selected by user fails to startup, the SystemInit()
|
||||
* function will do nothing and MSI still used as system clock source. User can
|
||||
* add some code to deal with this issue inside the SetSysClock() function.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
|
||||
* in "stm32l1xx.h" file. When HSE is used as system clock source, directly or
|
||||
* through PLL, and you are using different crystal you have to adapt the HSE
|
||||
* value to your own configuration.
|
||||
*
|
||||
* 5. This file configures the system clock as follows:
|
||||
*=============================================================================
|
||||
* System Clock Configuration
|
||||
*=============================================================================
|
||||
* System Clock source | PLL(HSE)
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK | 32000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK | 32000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB1 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* HSE Frequency | 8000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL DIV | 3
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL MUL | 12
|
||||
*-----------------------------------------------------------------------------
|
||||
* VDD | 3.3 V
|
||||
*-----------------------------------------------------------------------------
|
||||
* Vcore | 1.8 V (Range 1)
|
||||
*-----------------------------------------------------------------------------
|
||||
* Flash Latency | 1 WS
|
||||
*-----------------------------------------------------------------------------
|
||||
* SDIO clock (SDIOCLK) | 48000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB clock | Disabled
|
||||
*-----------------------------------------------------------------------------
|
||||
*=============================================================================
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* FOR MORE INFORMATION PLEASE READ CAREFULLY THE LICENSE AGREEMENT FILE
|
||||
* LOCATED IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32l1xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32l1xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM mounted
|
||||
on STM32L152D_EVAL board as data memory */
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table in
|
||||
Internal SRAM. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
uint32_t SystemCoreClock = 32000000;
|
||||
__I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void SetSysClock(void);
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L1xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
/*!< Set MSION bit */
|
||||
RCC->CR |= (uint32_t)0x00000100;
|
||||
|
||||
/*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */
|
||||
RCC->CFGR &= (uint32_t)0x88FFC00C;
|
||||
|
||||
/*!< Reset HSION, HSEON, CSSON and PLLON bits */
|
||||
RCC->CR &= (uint32_t)0xEEFEFFFE;
|
||||
|
||||
/*!< Reset HSEBYP bit */
|
||||
RCC->CR &= (uint32_t)0xFFFBFFFF;
|
||||
|
||||
/*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */
|
||||
RCC->CFGR &= (uint32_t)0xFF02FFFF;
|
||||
|
||||
/*!< Disable all interrupts */
|
||||
RCC->CIR = 0x00000000;
|
||||
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
|
||||
SetSysClock();
|
||||
|
||||
#ifdef VECT_TAB_SRAM
|
||||
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||
#else
|
||||
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock according to Clock Register Values
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI
|
||||
* value as defined by the MSI range.
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value
|
||||
* 16 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value
|
||||
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, msirange = 0;
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00: /* MSI used as system clock */
|
||||
msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13;
|
||||
SystemCoreClock = (32768 * (1 << (msirange + 1)));
|
||||
break;
|
||||
case 0x04: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x08: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x0C: /* PLL used as system clock */
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;
|
||||
plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;
|
||||
pllmul = PLLMulTable[(pllmul >> 18)];
|
||||
plldiv = (plldiv >> 22) + 1;
|
||||
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
|
||||
if (pllsource == 0x00)
|
||||
{
|
||||
/* HSI oscillator clock selected as PLL clock entry */
|
||||
SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* HSE selected as PLL clock entry */
|
||||
SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv);
|
||||
}
|
||||
break;
|
||||
default: /* MSI used as system clock */
|
||||
msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13;
|
||||
SystemCoreClock = (32768 * (1 << (msirange + 1)));
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK clock frequency --------------------------------------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the System clock frequency, AHB/APBx prescalers and Flash
|
||||
* settings.
|
||||
* @note This function should be called only once the RCC clock configuration
|
||||
* is reset to the default reset state (done in SystemInit() function).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
|
||||
/* Enable HSE */
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CR & RCC_CR_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* Enable 64-bit access */
|
||||
FLASH->ACR |= FLASH_ACR_ACC64;
|
||||
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH->ACR |= FLASH_ACR_PRFTEN;
|
||||
|
||||
/* Flash 1 wait state */
|
||||
FLASH->ACR |= FLASH_ACR_LATENCY;
|
||||
|
||||
/* Power enable */
|
||||
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
|
||||
|
||||
/* Select the Voltage Range 1 (1.8 V) */
|
||||
PWR->CR = PWR_CR_VOS_0;
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while((PWR->CSR & PWR_CSR_VOSF) != RESET)
|
||||
{
|
||||
}
|
||||
|
||||
/* HCLK = SYSCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
|
||||
|
||||
/* PCLK2 = HCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
|
||||
|
||||
/* PCLK1 = HCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
|
||||
|
||||
/* PLL configuration */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL |
|
||||
RCC_CFGR_PLLDIV));
|
||||
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMUL8 | RCC_CFGR_PLLDIV2);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CR & RCC_CR_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If HSE fails to start-up, the application will have wrong clock
|
||||
configuration. User can add here some code to deal with this error */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in SystemInit() function before jump to main.
|
||||
* This function configures the external SRAM mounted on STM32L152D_EVAL board
|
||||
* This SRAM will be used as program data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
/*-- GPIOs Configuration -----------------------------------------------------*/
|
||||
/*
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
+ SRAM pins assignment +
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
| PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 |
|
||||
| PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 |
|
||||
| PD4 <-> FSMC_NOE | PE7 <-> FSMC_D4 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 |
|
||||
| PD5 <-> FSMC_NWE | PE8 <-> FSMC_D5 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 |
|
||||
| PD8 <-> FSMC_D13 | PE9 <-> FSMC_D6 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 |
|
||||
| PD9 <-> FSMC_D14 | PE10 <-> FSMC_D7 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 |
|
||||
| PD10 <-> FSMC_D15 | PE11 <-> FSMC_D8 | PF12 <-> FSMC_A6 | PG10<-> FSMC_NE2 |
|
||||
| PD11 <-> FSMC_A16 | PE12 <-> FSMC_D9 | PF13 <-> FSMC_A7 |------------------+
|
||||
| PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 |
|
||||
| PD13 <-> FSMC_A18 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 |
|
||||
| PD14 <-> FSMC_D0 | PE15 <-> FSMC_D12 |------------------+
|
||||
| PD15 <-> FSMC_D1 |--------------------+
|
||||
+-------------------+
|
||||
*/
|
||||
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
|
||||
RCC->AHBENR = 0x000080D8;
|
||||
|
||||
/* Connect PDx pins to FSMC Alternate function */
|
||||
GPIOD->AFR[0] = 0x00CC00CC;
|
||||
GPIOD->AFR[1] = 0xCCCCCCCC;
|
||||
/* Configure PDx pins in Alternate function mode */
|
||||
GPIOD->MODER = 0xAAAA0A0A;
|
||||
/* Configure PDx pins speed to 40 MHz */
|
||||
GPIOD->OSPEEDR = 0xFFFF0F0F;
|
||||
/* Configure PDx pins Output type to push-pull */
|
||||
GPIOD->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PDx pins */
|
||||
GPIOD->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PEx pins to FSMC Alternate function */
|
||||
GPIOE->AFR[0] = 0xC00000CC;
|
||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
||||
/* Configure PEx pins in Alternate function mode */
|
||||
GPIOE->MODER = 0xAAAA800A;
|
||||
/* Configure PEx pins speed to 40 MHz */
|
||||
GPIOE->OSPEEDR = 0xFFFFC00F;
|
||||
/* Configure PEx pins Output type to push-pull */
|
||||
GPIOE->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PEx pins */
|
||||
GPIOE->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PFx pins to FSMC Alternate function */
|
||||
GPIOF->AFR[0] = 0x00CCCCCC;
|
||||
GPIOF->AFR[1] = 0xCCCC0000;
|
||||
/* Configure PFx pins in Alternate function mode */
|
||||
GPIOF->MODER = 0xAA000AAA;
|
||||
/* Configure PFx pins speed to 40 MHz */
|
||||
GPIOF->OSPEEDR = 0xFF000FFF;
|
||||
/* Configure PFx pins Output type to push-pull */
|
||||
GPIOF->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PFx pins */
|
||||
GPIOF->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PGx pins to FSMC Alternate function */
|
||||
GPIOG->AFR[0] = 0x00CCCCCC;
|
||||
GPIOG->AFR[1] = 0x00000C00;
|
||||
/* Configure PGx pins in Alternate function mode */
|
||||
GPIOG->MODER = 0x00200AAA;
|
||||
/* Configure PGx pins speed to 40 MHz */
|
||||
GPIOG->OSPEEDR = 0x00300FFF;
|
||||
/* Configure PGx pins Output type to push-pull */
|
||||
GPIOG->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PGx pins */
|
||||
GPIOG->PUPDR = 0x00000000;
|
||||
|
||||
/*-- FSMC Configuration ------------------------------------------------------*/
|
||||
/* Enable the FSMC interface clock */
|
||||
RCC->AHBENR = 0x400080D8;
|
||||
|
||||
/* Configure and enable Bank1_SRAM3 */
|
||||
FSMC_Bank1->BTCR[4] = 0x00001011;
|
||||
FSMC_Bank1->BTCR[5] = 0x00000300;
|
||||
FSMC_Bank1E->BWTR[4] = 0x0FFFFFFF;
|
||||
/*
|
||||
Bank1_SRAM3 is configured as follow:
|
||||
|
||||
p.FSMC_AddressSetupTime = 0;
|
||||
p.FSMC_AddressHoldTime = 0;
|
||||
p.FSMC_DataSetupTime = 3;
|
||||
p.FSMC_BusTurnAroundDuration = 0;
|
||||
p.FSMC_CLKDivision = 0;
|
||||
p.FSMC_DataLatency = 0;
|
||||
p.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||
|
||||
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
|
||||
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
||||
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
|
||||
|
||||
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
|
||||
|
||||
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
|
||||
*/
|
||||
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user