Backup before error handling refactoring
This commit is contained in:
354
USER/Ref/bmu-18s-firmware/UCOSIII/UCOS_BSP/bsp.c
Normal file
354
USER/Ref/bmu-18s-firmware/UCOSIII/UCOS_BSP/bsp.c
Normal file
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* Module name: BSP module
|
||||
* File name: BSP.c
|
||||
* Version: V1.0
|
||||
* Description: hardware driver collection
|
||||
*
|
||||
* Modify records:
|
||||
* Version date author description
|
||||
* v1.0 2015-08-17 JK.Woo ST firmware V1.0.2 version.
|
||||
*
|
||||
* Copyright (c), 2013-2014
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define BSP_MODULE
|
||||
#include "sys.h"
|
||||
#include "delay.h"
|
||||
#include "usart.h"
|
||||
#include "led.h"
|
||||
#include "iwdg.h"
|
||||
#include <bsp.h>
|
||||
|
||||
|
||||
void NVIC_Configuration(void);
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* REGISTERS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#define BSP_REG_DEM_CR (*(CPU_REG32 *)0xE000EDFC) //DEMCR register
|
||||
#define BSP_REG_DWT_CR (*(CPU_REG32 *)0xE0001000) //DWT control register
|
||||
#define BSP_REG_DWT_CYCCNT (*(CPU_REG32 *)0xE0001004) //DWT clock count register
|
||||
#define BSP_REG_DBGMCU_CR (*(CPU_REG32 *)0xE0042004)
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* REGISTER BITS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define BSP_DBGMCU_CR_TRACE_IOEN_MASK 0x10
|
||||
#define BSP_DBGMCU_CR_TRACE_MODE_ASYNC 0x00
|
||||
#define BSP_DBGMCU_CR_TRACE_MODE_SYNC_01 0x40
|
||||
#define BSP_DBGMCU_CR_TRACE_MODE_SYNC_02 0x80
|
||||
#define BSP_DBGMCU_CR_TRACE_MODE_SYNC_04 0xC0
|
||||
#define BSP_DBGMCU_CR_TRACE_MODE_MASK 0xC0
|
||||
|
||||
//DEMCR register 24th place, if you want to use the DWT ETM ITM and 24th position of the TPIU registers DEMCR 1
|
||||
#define BSP_BIT_DEM_CR_TRCENA DEF_BIT_24
|
||||
|
||||
//DWTCR Register No. 0, when 1 CYCCNT counter, use CYCCNT before the first class
|
||||
#define BSP_BIT_DWT_CR_CYCCNTENA DEF_BIT_00
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* Function name: bsp_Init
|
||||
* Function description: initialize hardware devices
|
||||
* Parameters: none
|
||||
* Return value: none
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void bsp_Init(void)
|
||||
{
|
||||
NVIC_Configuration(); /* Interrupt priority grouping configuration */
|
||||
|
||||
//#ifdef CONSOLE_DEBUG
|
||||
uart1_init(115200); // Serial port init
|
||||
|
||||
IWDG_ReloadCounter();
|
||||
|
||||
//#endif // #ifdef CONSOLE_DEBUG
|
||||
|
||||
IWDG_Init();
|
||||
IWDG_ReloadCounter();
|
||||
|
||||
DIO_Init(); // LED init
|
||||
|
||||
#ifdef TRACE_EN /* See project / compiler preprocessor options. */
|
||||
BSP_CPU_REG_DBGMCU_CR |= BSP_DBGMCU_CR_TRACE_IOEN_MASK; /* Enable tracing (see Note #2). */
|
||||
BSP_CPU_REG_DBGMCU_CR &= ~BSP_DBGMCU_CR_TRACE_MODE_MASK; /* Clr trace mode sel bits. */
|
||||
BSP_CPU_REG_DBGMCU_CR |= BSP_DBGMCU_CR_TRACE_MODE_SYNC_04; /* Cfg trace mode to synch 4-bit. */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* Function name: NVIC_Configuration
|
||||
* Function description: the interrupt priority configuration, here assigned to priority groups first, and then
|
||||
* specific modules which implement the priority configuration
|
||||
* Parameters: none
|
||||
* Return value: none
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void NVIC_Configuration(void)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* Set the Vector Table base location at 0x08020000 */
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x3000);
|
||||
|
||||
/* Set the NVIC priority preemptive priorities grouped into Group2:0-3, 0-3-response priority */
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
|
||||
|
||||
/* Enable the CAN1 Interrupt */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
//#ifdef CONSOLE_DEBUG
|
||||
/* Enable the USART1 Interrupt */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
//#endif // #ifdef CONSOLE_DEBUG
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* BSP_CPU_ClkFreq()
|
||||
* Description : Read CPU registers to determine the CPU clock frequency of the chip.
|
||||
* Argument(s) : none.
|
||||
* Return(s) : The CPU clock frequency, in Hz.
|
||||
* Caller(s) : Application.
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
CPU_INT32U BSP_CPU_ClkFreq (void)
|
||||
{
|
||||
RCC_ClocksTypeDef rcc_clocks;
|
||||
|
||||
RCC_GetClocksFreq(&rcc_clocks); //Gets the clock frequency
|
||||
|
||||
return ((CPU_INT32U)rcc_clocks.HCLK_Frequency); //Returns the HCLK clock frequency
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*$PAGE*/
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CPU_TS_TmrInit()
|
||||
* Description : Initialize & start CPU timestamp timer.
|
||||
* Argument(s) : none.
|
||||
* Return(s) : none.
|
||||
* Caller(s) : CPU_TS_Init().
|
||||
* This function is an INTERNAL CPU module function & MUST be implemented by application/
|
||||
* BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
|
||||
* Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
|
||||
* if either of the following CPU features is enabled :
|
||||
* (a) CPU timestamps
|
||||
* (b) CPU interrupts disabled time measurements
|
||||
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
|
||||
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
|
||||
* (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
|
||||
* data type.
|
||||
* (1) If timer has more bits, truncate timer values' higher-order bits greater
|
||||
* than the configured 'CPU_TS_TMR' timestamp timer data type word size.
|
||||
* (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
|
||||
* timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
|
||||
* configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
|
||||
* In other words, if timer size is not a binary-multiple of 8-bit octets
|
||||
* (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
|
||||
* octet word size SHOULD be configured (e.g. to 16-bits). However, the
|
||||
* minimum supported word size for CPU timestamp timers is 8-bits.
|
||||
* See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
|
||||
* & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
|
||||
* (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
|
||||
* (c) When applicable, timer period SHOULD be less than the typical measured time
|
||||
* but MUST be less than the maximum measured time; otherwise, timer resolution
|
||||
* inadequate to measure desired times.
|
||||
* See also 'CPU_TS_TmrRd() Note #2'.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
|
||||
void CPU_TS_TmrInit (void)
|
||||
{
|
||||
CPU_INT32U fclk_freq;
|
||||
|
||||
|
||||
fclk_freq = BSP_CPU_ClkFreq();
|
||||
|
||||
BSP_REG_DEM_CR |= (CPU_INT32U)BSP_BIT_DEM_CR_TRCENA; //Using DWT /* Enable Cortex-M4's DWT CYCCNT reg. */
|
||||
BSP_REG_DWT_CYCCNT = (CPU_INT32U)0u; //Initializes the CYCCNT register
|
||||
BSP_REG_DWT_CR |= (CPU_INT32U)BSP_BIT_DWT_CR_CYCCNTENA;//Open CYCCNT
|
||||
|
||||
CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ)fclk_freq);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*$PAGE*/
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CPU_TS_TmrRd()
|
||||
* Description : Get current CPU timestamp timer count value.
|
||||
* Argument(s) : none.
|
||||
* Return(s) : Timestamp timer count (see Notes #2a & #2b).
|
||||
* Caller(s) : CPU_TS_Init(),
|
||||
* CPU_TS_Get32(),
|
||||
* CPU_TS_Get64(),
|
||||
* CPU_IntDisMeasStart(),
|
||||
* CPU_IntDisMeasStop().
|
||||
* This function is an INTERNAL CPU module function & MUST be implemented by application/
|
||||
* BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
|
||||
* Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
|
||||
* if either of the following CPU features is enabled :
|
||||
* (a) CPU timestamps
|
||||
* (b) CPU interrupts disabled time measurements
|
||||
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
|
||||
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
|
||||
* (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
|
||||
* data type.
|
||||
* (1) If timer has more bits, truncate timer values' higher-order bits greater
|
||||
* than the configured 'CPU_TS_TMR' timestamp timer data type word size.
|
||||
* (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
|
||||
* timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
|
||||
* configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
|
||||
* In other words, if timer size is not a binary-multiple of 8-bit octets
|
||||
* (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
|
||||
* octet word size SHOULD be configured (e.g. to 16-bits). However, the
|
||||
* minimum supported word size for CPU timestamp timers is 8-bits.
|
||||
* See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
|
||||
* & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
|
||||
* (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
|
||||
* (1) If timer is a 'down' counter whose values decrease with each time count,
|
||||
* then the returned timer value MUST be ones-complemented.
|
||||
* (c) (1) When applicable, the amount of time measured by CPU timestamps is
|
||||
* calculated by either of the following equations :
|
||||
* (A) Time measured = Number timer counts * Timer period
|
||||
* where
|
||||
*
|
||||
* Number timer counts Number of timer counts measured
|
||||
* Timer period Timer's period in some units of
|
||||
* (fractional) seconds
|
||||
* Time measured Amount of time measured, in same
|
||||
* units of (fractional) seconds
|
||||
* as the Timer period
|
||||
*
|
||||
* Number timer counts
|
||||
* (B) Time measured = ---------------------
|
||||
* Timer frequency
|
||||
*
|
||||
* where
|
||||
*
|
||||
* Number timer counts Number of timer counts measured
|
||||
* Timer frequency Timer's frequency in some units
|
||||
* of counts per second
|
||||
* Time measured Amount of time measured, in seconds
|
||||
*
|
||||
* (2) Timer period SHOULD be less than the typical measured time but MUST be less
|
||||
* than the maximum measured time; otherwise, timer resolution inadequate to
|
||||
* measure desired times.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
|
||||
CPU_TS_TMR CPU_TS_TmrRd (void)
|
||||
{
|
||||
CPU_TS_TMR ts_tmr_cnts;
|
||||
|
||||
|
||||
ts_tmr_cnts = (CPU_TS_TMR)BSP_REG_DWT_CYCCNT;
|
||||
|
||||
return (ts_tmr_cnts);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*$PAGE*/
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CPU_TSxx_to_uSec()
|
||||
* Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
|
||||
* Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
|
||||
* Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
|
||||
* Caller(s) : Application.
|
||||
* This function is an (optional) CPU module application programming interface (API)
|
||||
* function which MAY be implemented by application/BSP function(s) [see Note #1] &
|
||||
* MAY be called by application function(s).
|
||||
* Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
|
||||
* optionally defined by the developer when either of the following CPU features is
|
||||
* enabled :
|
||||
* (a) CPU timestamps
|
||||
* (b) CPU interrupts disabled time measurements
|
||||
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
|
||||
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
|
||||
* (2) (a) The amount of time measured by CPU timestamps is calculated by either of
|
||||
* the following equations :
|
||||
*
|
||||
* 10^6 microseconds
|
||||
* (1) Time measured = Number timer counts * ------------------- * Timer period
|
||||
* 1 second
|
||||
*
|
||||
* Number timer counts 10^6 microseconds
|
||||
* (2) Time measured = --------------------- * -------------------
|
||||
* Timer frequency 1 second
|
||||
*
|
||||
* where
|
||||
*
|
||||
* (A) Number timer counts Number of timer counts measured
|
||||
* (B) Timer frequency Timer's frequency in some units
|
||||
* of counts per second
|
||||
* (C) Timer period Timer's period in some units of
|
||||
* (fractional) seconds
|
||||
* (D) Time measured Amount of time measured,
|
||||
* in microseconds
|
||||
*
|
||||
* (b) Timer period SHOULD be less than the typical measured time but MUST be less
|
||||
* than the maximum measured time; otherwise, timer resolution inadequate to
|
||||
* measure desired times.
|
||||
*
|
||||
* (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
|
||||
* -- up to 32 or 64, respectively -- into microseconds.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (CPU_CFG_TS_32_EN == DEF_ENABLED)
|
||||
CPU_INT64U CPU_TS32_to_uSec (CPU_TS32 ts_cnts)
|
||||
{
|
||||
CPU_INT64U ts_us;
|
||||
CPU_INT64U fclk_freq;
|
||||
|
||||
|
||||
fclk_freq = BSP_CPU_ClkFreq();
|
||||
ts_us = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
|
||||
|
||||
return (ts_us);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if (CPU_CFG_TS_64_EN == DEF_ENABLED)
|
||||
CPU_INT64U CPU_TS64_to_uSec (CPU_TS64 ts_cnts)
|
||||
{
|
||||
CPU_INT64U ts_us;
|
||||
CPU_INT64U fclk_freq;
|
||||
|
||||
|
||||
fclk_freq = BSP_CPU_ClkFreq();
|
||||
ts_us = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
|
||||
|
||||
return (ts_us);
|
||||
}
|
||||
#endif
|
||||
25
USER/Ref/bmu-18s-firmware/UCOSIII/UCOS_BSP/bsp.h
Normal file
25
USER/Ref/bmu-18s-firmware/UCOSIII/UCOS_BSP/bsp.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef BSP_PRESENT
|
||||
#define BSP_PRESENT
|
||||
|
||||
|
||||
#ifdef BSP_MODULE
|
||||
#define BSP_EXT
|
||||
#else
|
||||
#define BSP_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <cpu.h>
|
||||
#include <cpu_core.h>
|
||||
#include <lib_def.h>
|
||||
#include <lib_ascii.h>
|
||||
#include <stm32f10x_conf.h>
|
||||
|
||||
|
||||
void bsp_Init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user