opt: rename uart1 config methods

This commit is contained in:
IOsetting 2022-01-09 19:26:52 +08:00
parent 470b0ec2f9
commit b5d2eac413
21 changed files with 144 additions and 26 deletions

View File

@ -44,7 +44,7 @@ void main(void)
{
SYS_SetClock();
// For debug print
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Set ADC1(GPIO P1.1) HIP
GPIO_P1_SetMode(GPIO_Pin_1, GPIO_Mode_Input_HIP);
// Channel: ADC1

View File

@ -64,7 +64,7 @@ void main(void)
{
SYS_SetClock();
// For debug print
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Channel: ADC1
ADC_SetChannel(0x01);
// ADC Clock = SYSCLK / 2 / (1+15) = SYSCLK / 32

View File

@ -34,7 +34,7 @@ void main(void)
uint16_t res;
SYS_SetClock();
// For debug print
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Set ADC1(GPIO P1.1) HIP
GPIO_P1_SetMode(GPIO_Pin_1, GPIO_Mode_Input_HIP);
// Channel: ADC1

View File

@ -34,7 +34,7 @@ void main(void)
uint8_t res;
SYS_SetClock();
// For debug print
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Set ADC1(GPIO P1.1) HIP
GPIO_P1_SetMode(GPIO_Pin_1, GPIO_Mode_Input_HIP);
// Channel: ADC1

View File

@ -27,7 +27,7 @@ void main(void)
{
SYS_SetClock();
// UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
MEM_ReadChipID(buff);
for (i = 0; i < 32; i++)

View File

@ -21,7 +21,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
// Set GPIO pin mode
GPIO_P3_SetMode(GPIO_Pin_2|GPIO_Pin_3, GPIO_Mode_Output_PP);

View File

@ -21,7 +21,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
// Set GPIO pin mode
GPIO_P3_SetMode(GPIO_Pin_2|GPIO_Pin_3, GPIO_Mode_Output_PP);

View File

@ -30,7 +30,7 @@ void main(void)
SYS_SetClock();
// UART1, baud 115200, baud source Timer2, 1T mode
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Set GPIO pins output mode
GPIO_P1_SetMode(GPIO_Pin_0|GPIO_Pin_1, GPIO_Mode_Output_PP);

View File

@ -46,7 +46,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer1, 1T mode
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
// Set GPIO pins output mode
GPIO_P1_SetMode(GPIO_Pin_0|GPIO_Pin_1, GPIO_Mode_Output_PP);

View File

@ -87,7 +87,7 @@ void main(void)
GPIO_Init();
// UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_TxString("UART Initialized\r\n");
SPI_Init();

View File

@ -110,7 +110,7 @@ void main(void)
// Set system clock. Remove this line if system clock is already set by STC-ISP
SYS_SetClock();
// UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
// Timer0 configuration: 16-bit auto-reload, interrupt enabled
TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000);
EXTI_Timer0_SetIntState(HAL_State_ON);

View File

@ -31,7 +31,7 @@ void main(void)
// Set system clock. Remove this line if system clock is already set by STC-ISP
SYS_SetClock();
// UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000);
EXTI_Timer0_SetIntState(HAL_State_ON);
EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High);

View File

@ -23,7 +23,7 @@ void main(void)
{
SYS_SetClock();
// UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
// 12T mode, prescaler:255+1, frequency: 1, interrupt: ON
TIM_Timer2_Config(HAL_State_OFF, 0xFF, 1);
EXTI_Timer2_SetIntState(HAL_State_ON);

View File

@ -30,7 +30,7 @@ void main(void)
{
SYS_SetClock();
// UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
// 1T mode, prescaler:255+1, frequency: 5, interrupt: ON
TIM_Timer2_Config(HAL_State_ON, 0xFF, 5);
EXTI_Timer2_SetIntState(HAL_State_ON);

View File

@ -18,7 +18,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
while(1)
{
UART1_TxChar('T');

View File

@ -25,7 +25,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer2, 1T mode, interrupt on
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_SetRxState(HAL_State_ON);
// Enable UART1 interrupt
EXTI_Global_SetIntState(HAL_State_ON);

View File

@ -18,7 +18,7 @@ void main(void)
{
SYS_SetClock();
// UART1, baud 115200, baud source Timer2, 1T mode, no interrupt
UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
while(1)
{
UART1_TxChar('T');

View File

@ -131,11 +131,20 @@ typedef enum
#define EXTI_INT_CompFall_ON SFR_SET(CMPCR1, 4)
#define EXTI_INT_CompFall_OFF SFR_RESET(CMPCR1, 4)
#define EXTI_I2C_SetMstIntState(__STATE__) SFR_ASSIGN(I2CMSCR, 7, __STATE__)
#define EXTI_I2C_SetSlvStartIntState(__STATE__) SFRX_SET(I2CSLCR, 6, __STATE__)
#define EXTI_I2C_SetSlvRecvIntState(__STATE__) SFRX_SET(I2CSLCR, 5, __STATE__)
#define EXTI_I2C_SetSlvSendIntState(__STATE__) SFRX_SET(I2CSLCR, 4, __STATE__)
#define EXTI_I2C_SetSlvStopIntState(__STATE__) SFRX_SET(I2CSLCR, 3, __STATE__)
#define EXTI_I2C_SetMstIntState(__STATE__) SFRX_ASSIGN(I2CMSCR, 7, __STATE__)
#define EXTI_I2C_SetSlvStartIntState(__STATE__) SFRX_ASSIGN(I2CSLCR, 6, __STATE__)
#define EXTI_I2C_SetSlvRecvIntState(__STATE__) SFRX_ASSIGN(I2CSLCR, 5, __STATE__)
#define EXTI_I2C_SetSlvSendIntState(__STATE__) SFRX_ASSIGN(I2CSLCR, 4, __STATE__)
#define EXTI_I2C_SetSlvStopIntState(__STATE__) SFRX_ASSIGN(I2CSLCR, 3, __STATE__)
#define EXTI_RTC_SetAlarmIntState(__STATE__) SFRX_ASSIGN(RTCIEN, 7, __STATE__)
#define EXTI_RTC_SetDayIntState(__STATE__) SFRX_ASSIGN(RTCIEN, 6, __STATE__)
#define EXTI_RTC_SetHourIntState(__STATE__) SFRX_ASSIGN(RTCIEN, 5, __STATE__)
#define EXTI_RTC_SetMinuteIntState(__STATE__) SFRX_ASSIGN(RTCIEN, 4, __STATE__)
#define EXTI_RTC_SetSecondIntState(__STATE__) SFRX_ASSIGN(RTCIEN, 3, __STATE__)
#define EXTI_RTC_SetSecondDiv2IntState(__STATE__) SFRX_ASSIGN(RTCIEN, 2, __STATE__)
#define EXTI_RTC_SetSecondDiv8IntState(__STATE__) SFRX_ASSIGN(RTCIEN, 1, __STATE__)
#define EXTI_RTC_SetSecondDiv32IntState(__STATE__) SFRX_ASSIGN(RTCIEN, 0, __STATE__)
#define EXTI_INT_PWMA_Break_ON SFRX_SET(PWMA_IER, 7)
#define EXTI_INT_PWMA_Break_OFF SFRX_RESET(PWMA_IER, 7)

View File

@ -18,6 +18,18 @@
#include "fw_conf.h"
#include "fw_types.h"
typedef enum
{
SYS_ExternalOSC_Clock = 0x00,
SYS_ExternalOSC_Crystal = 0x01,
} SYS_ExternalOSC_t;
typedef enum
{
SYS_SysClkOutputPort_P54 = 0x00,
SYS_SysClkOutputPort_P16 = 0x01,
} SYS_SysClkOutputPort_t;
/**
* STC8H Clock:
* MCKSEL ||===> MCLKODIV ==> MCLKO_S => P1.6/P5.4
@ -34,6 +46,103 @@
LIRTRIM = ((__LIRTRIM__) & 0x03); \
} while(0)
/**
* Enable high speed internal oscillator
*/
#define SYS_EnableOscillatorHSI() do { \
SFRX_ON(); \
(HIRCCR) = (HIRCCR) | (0x01 << 7); \
while (!(HIRCCR & 0x01)); \
SFRX_OFF(); \
} while(0)
/**
* Disable high speed internal oscillator
*/
#define SYS_DisableOscillatorHSI() do { \
SFRX_ON(); \
(HIRCCR) = (HIRCCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
/**
* Enable low speed internal oscillator
*/
#define SYS_EnableOscillatorLSI() do { \
SFRX_ON(); \
(IRC32KCR) = (IRC32KCR) | (0x01 << 7); \
while (!(IRC32KCR & 0x01)); \
SFRX_OFF(); \
} while(0)
/**
* Disable low speed internal oscillator
*/
#define SYS_DisableOscillatorLSI() do { \
SFRX_ON(); \
(IRC32KCR) = (IRC32KCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
/**
* Enable high speed external oscillator
*/
#define SYS_EnableOscillatorHSE() do { \
SFRX_ON(); \
(XOSCCR) = (XOSCCR) | (0x01 << 7); \
while (!(HIRCCR & 0x01)); \
SFRX_OFF(); \
} while(0)
/**
* Disable high speed external oscillator
*/
#define SYS_DisableOscillatorHSE() do { \
SFRX_ON(); \
(XOSCCR) = (XOSCCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
/**
* Set high speed external oscillator type
*/
#define SYS_SetExternalOscType(__TYPE__) SFRX_ASSIGN(XOSCCR, 6, (__TYPE__))
/**
* Enable low speed external oscillator
*/
#define SYS_EnableOscillatorLSE() do { \
SFRX_ON(); \
(X32KCR) = (X32KCR) | (0x01 << 7); \
while (!(X32KCR & 0x01)); \
SFRX_OFF(); \
} while(0)
/**
* Disable low speed external oscillator
*/
#define SYS_DisableOscillatorLSE() do { \
SFRX_ON(); \
(X32KCR) = (X32KCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
/**
* Set low speed external oscillator gain
*/
#define SYS_SetExternal32kHighGain(__STATE__) SFRX_ASSIGN(X32KCR, 6, (__STATE__))
/**
* System clock output
* 0:No output, Foutput = SYSCLK / __DIV__
*/
#define SYS_SetSysClockOutputDivider(__DIV__) do { \
SFRX_ON(); \
(MCLKOCR) = (MCLKOCR) & ~(0x7F) | (__DIV__); \
SFRX_OFF(); \
} while(0)
/**
* System clock output pin
* 0:P5.4, 1:P1.6
*/
#define SYS_SetClockOutputPin(__PORT__) SFRX_ASSIGN(MCLKOCR, 7, (__STATE__))
void SYS_SetClock(void);
void SYS_Delay(uint16_t t);
void SYS_DelayUs(uint16_t t);

View File

@ -73,11 +73,11 @@ typedef enum
/**
* Mode1: 8-bit UART, dynamic baud-rate, provided by Timer1 or Timer2
*/
void UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate);
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate);
/**
* Mode3: 9-bit UART, dynamic baud-rate, provided by Timer1 or Timer2
*/
void UART1_ConfigMode3Dyn9bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate);
void UART1_Config9bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate);
void UART1_InterruptHandler(void);

View File

@ -56,7 +56,7 @@ void _UART1_ConfigDynUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, in
TIM_Timer2_SetRunState(HAL_State_ON);
}
}
void UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
{
uint16_t init;
uint32_t sysclk;
@ -66,7 +66,7 @@ void UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1T
_UART1_ConfigDynUart(baudSource, _1TMode, init);
}
void UART1_ConfigMode3Dyn9bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
void UART1_Config9bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
{
uint16_t init;
uint32_t sysclk;