mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Format Pine code
This commit is contained in:
@@ -105,7 +105,8 @@ typedef struct {
|
|||||||
* ADC can be either disabled or enabled without conversion on going on regular group.
|
* ADC can be either disabled or enabled without conversion on going on regular group.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group.
|
uint32_t
|
||||||
|
Channel; /*!< Specifies the channel to configure into ADC regular group.
|
||||||
This parameter can be a value of @ref ADC_channels
|
This parameter can be a value of @ref ADC_channels
|
||||||
Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
|
Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
|
||||||
Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor)
|
Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor)
|
||||||
|
|||||||
@@ -69,13 +69,13 @@ extern "C" {
|
|||||||
* - For all except parameters 'ExternalTrigInjecConv': ADC enabled without conversion on going on injected group.
|
* - For all except parameters 'ExternalTrigInjecConv': ADC enabled without conversion on going on injected group.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t
|
uint32_t InjectedChannel; /*!< Selection of ADC channel to configure
|
||||||
InjectedChannel; /*!< Selection of ADC channel to configure
|
|
||||||
This parameter can be a value of @ref ADC_channels
|
This parameter can be a value of @ref ADC_channels
|
||||||
Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
|
Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
|
||||||
Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor)
|
Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor)
|
||||||
Note: On STM32F10xx8 and STM32F10xxB devices: A low-amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection
|
Note: On STM32F10xx8 and STM32F10xxB devices: A low-amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with
|
||||||
trigger. It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel. Refer to errata sheet of these devices for more details. */
|
injection trigger. It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel. Refer to errata
|
||||||
|
sheet of these devices for more details. */
|
||||||
uint32_t InjectedRank; /*!< Rank in the injected group sequencer
|
uint32_t InjectedRank; /*!< Rank in the injected group sequencer
|
||||||
This parameter must be a value of @ref ADCEx_injected_rank
|
This parameter must be a value of @ref ADCEx_injected_rank
|
||||||
Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel
|
Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle
|
|||||||
|
|
||||||
// 2 second filter (ADC is PID_TIM_HZ Hz)
|
// 2 second filter (ADC is PID_TIM_HZ Hz)
|
||||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
||||||
void resetWatchdog() {
|
void resetWatchdog() { fwdgt_counter_reload(); }
|
||||||
fwdgt_counter_reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getTipInstantTemperature() {
|
uint16_t getTipInstantTemperature() {
|
||||||
volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits
|
volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits
|
||||||
@@ -90,8 +88,7 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
|
|||||||
void unstick_I2C() {
|
void unstick_I2C() {
|
||||||
/* configure SDA/SCL for GPIO */
|
/* configure SDA/SCL for GPIO */
|
||||||
GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin;
|
GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin;
|
||||||
gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,
|
gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin);
|
||||||
SDA_Pin | SCL_Pin);
|
|
||||||
asm("nop");
|
asm("nop");
|
||||||
asm("nop");
|
asm("nop");
|
||||||
asm("nop");
|
asm("nop");
|
||||||
@@ -106,26 +103,18 @@ void unstick_I2C() {
|
|||||||
GPIO_BOP(GPIOB) |= SDA_Pin;
|
GPIO_BOP(GPIOB) |= SDA_Pin;
|
||||||
/* connect PB6 to I2C0_SCL */
|
/* connect PB6 to I2C0_SCL */
|
||||||
/* connect PB7 to I2C0_SDA */
|
/* connect PB7 to I2C0_SDA */
|
||||||
gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ,
|
gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin);
|
||||||
SDA_Pin | SCL_Pin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getButtonA() {
|
uint8_t getButtonA() { return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; }
|
||||||
return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0;
|
uint8_t getButtonB() { return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; }
|
||||||
}
|
|
||||||
uint8_t getButtonB() {
|
|
||||||
return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void reboot() {
|
void reboot() {
|
||||||
// Spin for watchdog
|
// Spin for watchdog
|
||||||
for (;;) {
|
for (;;) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delay_ms(uint16_t count) {
|
void delay_ms(uint16_t count) { delay_1ms(count); }
|
||||||
delay_1ms(count);
|
|
||||||
}
|
|
||||||
uint32_t __get_IPSR(void) {
|
uint32_t __get_IPSR(void) {
|
||||||
return 0; // To shut-up CMSIS
|
return 0; // To shut-up CMSIS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ void FRToSI2C::CpltCallback() {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); }
|
||||||
return Mem_Write(address, reg, &data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
||||||
uint8_t temp = 0;
|
uint8_t temp = 0;
|
||||||
@@ -195,9 +193,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b
|
|||||||
/* enable DMA0 channel5 */
|
/* enable DMA0 channel5 */
|
||||||
dma_channel_enable(DMA0, DMA_CH6);
|
dma_channel_enable(DMA0, DMA_CH6);
|
||||||
/* wait until BTC bit is set */
|
/* wait until BTC bit is set */
|
||||||
while (!dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) {
|
while (!dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) {}
|
||||||
|
|
||||||
}
|
|
||||||
/* send a stop condition to I2C bus*/
|
/* send a stop condition to I2C bus*/
|
||||||
i2c_stop_on_bus(I2C0);
|
i2c_stop_on_bus(I2C0);
|
||||||
}
|
}
|
||||||
@@ -343,12 +339,9 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu
|
|||||||
/* enable DMA0 channel5 */
|
/* enable DMA0 channel5 */
|
||||||
dma_channel_enable(DMA0, DMA_CH5);
|
dma_channel_enable(DMA0, DMA_CH5);
|
||||||
/* wait until BTC bit is set */
|
/* wait until BTC bit is set */
|
||||||
while (!dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) {
|
while (!dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) {}
|
||||||
|
|
||||||
}
|
|
||||||
/* wait until BTC bit is set */
|
/* wait until BTC bit is set */
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) {}
|
||||||
}
|
|
||||||
state = I2C_STOP;
|
state = I2C_STOP;
|
||||||
break;
|
break;
|
||||||
case I2C_STOP:
|
case I2C_STOP:
|
||||||
@@ -379,18 +372,14 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu
|
|||||||
return timedout == false;
|
return timedout == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); }
|
||||||
return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FRToSI2C::probe(uint16_t DevAddress) {
|
bool FRToSI2C::probe(uint16_t DevAddress) {
|
||||||
uint8_t temp[1];
|
uint8_t temp[1];
|
||||||
return Mem_Read(DevAddress, 0x00, temp, sizeof(temp));
|
return Mem_Read(DevAddress, 0x00, temp, sizeof(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRToSI2C::I2C_Unstick() {
|
void FRToSI2C::I2C_Unstick() { unstick_I2C(); }
|
||||||
unstick_I2C();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FRToSI2C::lock() {
|
bool FRToSI2C::lock() {
|
||||||
if (I2CSemaphore == nullptr) {
|
if (I2CSemaphore == nullptr) {
|
||||||
|
|||||||
@@ -119,8 +119,6 @@ void EXTI5_9_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// These are unused for now
|
// These are unused for now
|
||||||
void I2C0_EV_IRQHandler(void) {
|
void I2C0_EV_IRQHandler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
void I2C0_ER_IRQHandler(void) {
|
void I2C0_ER_IRQHandler(void) {}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "BSP_Power.h"
|
#include "BSP_Power.h"
|
||||||
|
#include "Model_Config.h"
|
||||||
|
#include "Pins.h"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Pins.h"
|
|
||||||
#include "fusbpd.h"
|
#include "fusbpd.h"
|
||||||
#include "Model_Config.h"
|
|
||||||
#include "policy_engine.h"
|
|
||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
|
#include "policy_engine.h"
|
||||||
bool FUSB302_present = false;
|
bool FUSB302_present = false;
|
||||||
|
|
||||||
void power_check() {
|
void power_check() {
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
* Created on: 29 May 2020
|
* Created on: 29 May 2020
|
||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
#include "gd32vf103_libopt.h"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "gd32vf103_libopt.h"
|
||||||
|
|
||||||
#ifdef POW_QC
|
#ifdef POW_QC
|
||||||
void QC_DPlusZero_Six() {
|
void QC_DPlusZero_Six() {
|
||||||
@@ -18,7 +18,6 @@ void QC_DPlusZero_Six() {
|
|||||||
void QC_DNegZero_Six() {
|
void QC_DNegZero_Six() {
|
||||||
gpio_bit_set(QC_DM_HIGH_GPIO_Port, QC_DM_HIGH_Pin);
|
gpio_bit_set(QC_DM_HIGH_GPIO_Port, QC_DM_HIGH_Pin);
|
||||||
gpio_bit_reset(QC_DM_LOW_GPIO_Port, QC_DM_LOW_Pin);
|
gpio_bit_reset(QC_DM_LOW_GPIO_Port, QC_DM_LOW_Pin);
|
||||||
|
|
||||||
}
|
}
|
||||||
void QC_DPlusThree_Three() {
|
void QC_DPlusThree_Three() {
|
||||||
// pull up D+
|
// pull up D+
|
||||||
@@ -28,12 +27,8 @@ void QC_DNegThree_Three() {
|
|||||||
gpio_bit_set(QC_DM_LOW_GPIO_Port, QC_DM_LOW_Pin);
|
gpio_bit_set(QC_DM_LOW_GPIO_Port, QC_DM_LOW_Pin);
|
||||||
gpio_bit_set(QC_DM_HIGH_GPIO_Port, QC_DM_HIGH_Pin);
|
gpio_bit_set(QC_DM_HIGH_GPIO_Port, QC_DM_HIGH_Pin);
|
||||||
}
|
}
|
||||||
void QC_DM_PullDown() {
|
void QC_DM_PullDown() { gpio_init(USB_DM_LOW_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, USB_DM_Pin); }
|
||||||
gpio_init(USB_DM_LOW_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, USB_DM_Pin);
|
void QC_DM_No_PullDown() { gpio_init(USB_DM_LOW_GPIO_Port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_2MHZ, USB_DM_Pin); }
|
||||||
}
|
|
||||||
void QC_DM_No_PullDown() {
|
|
||||||
gpio_init(USB_DM_LOW_GPIO_Port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_2MHZ, USB_DM_Pin);
|
|
||||||
}
|
|
||||||
void QC_Init_GPIO() {
|
void QC_Init_GPIO() {
|
||||||
// Setup any GPIO into the right states for QC
|
// Setup any GPIO into the right states for QC
|
||||||
// D+ pulldown as output
|
// D+ pulldown as output
|
||||||
@@ -45,12 +40,9 @@ void QC_Post_Probe_En() {
|
|||||||
// Make two D- pins outputs
|
// Make two D- pins outputs
|
||||||
gpio_init(QC_DM_LOW_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, QC_DM_LOW_Pin);
|
gpio_init(QC_DM_LOW_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, QC_DM_LOW_Pin);
|
||||||
gpio_init(QC_DM_HIGH_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, QC_DM_HIGH_Pin);
|
gpio_init(QC_DM_HIGH_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, QC_DM_HIGH_Pin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t QC_DM_PulledDown() {
|
uint8_t QC_DM_PulledDown() { return gpio_input_bit_get(USB_DM_LOW_GPIO_Port, USB_DM_Pin) == RESET ? 1 : 0; }
|
||||||
return gpio_input_bit_get(USB_DM_LOW_GPIO_Port, USB_DM_Pin) == RESET ? 1 : 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
void QC_resync() {
|
void QC_resync() {
|
||||||
#ifdef POW_QC
|
#ifdef POW_QC
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#define ADC_NORM_CHANNELS 2
|
#define ADC_NORM_CHANNELS 2
|
||||||
#define ADC_NORM_SAMPLES 32
|
#define ADC_NORM_SAMPLES 32
|
||||||
uint16_t ADCReadings[ADC_NORM_SAMPLES *
|
uint16_t ADCReadings[ADC_NORM_SAMPLES * ADC_NORM_CHANNELS]; // room for 32 lots of the pair of readings
|
||||||
ADC_NORM_CHANNELS]; // room for 32 lots of the pair of readings
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void setup_gpio();
|
void setup_gpio();
|
||||||
@@ -59,21 +58,16 @@ void setup_gpio() {
|
|||||||
gpio_init(KEY_A_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, KEY_A_Pin);
|
gpio_init(KEY_A_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, KEY_A_Pin);
|
||||||
gpio_init(KEY_B_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, KEY_B_Pin);
|
gpio_init(KEY_B_GPIO_Port, GPIO_MODE_IPD, GPIO_OSPEED_2MHZ, KEY_B_Pin);
|
||||||
// OLED reset as output
|
// OLED reset as output
|
||||||
gpio_init(OLED_RESET_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ,
|
gpio_init(OLED_RESET_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, OLED_RESET_Pin);
|
||||||
OLED_RESET_Pin);
|
|
||||||
gpio_bit_set(SDA_GPIO_Port, SDA_Pin);
|
gpio_bit_set(SDA_GPIO_Port, SDA_Pin);
|
||||||
gpio_bit_set(SDA_GPIO_Port, SCL_Pin);
|
gpio_bit_set(SDA_GPIO_Port, SCL_Pin);
|
||||||
// I2C as AF Open Drain
|
// I2C as AF Open Drain
|
||||||
gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_2MHZ,
|
gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_2MHZ, SDA_Pin | SCL_Pin);
|
||||||
SDA_Pin | SCL_Pin);
|
|
||||||
// PWM output as AF Push Pull
|
// PWM output as AF Push Pull
|
||||||
gpio_init(PWM_Out_GPIO_Port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ,
|
gpio_init(PWM_Out_GPIO_Port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, PWM_Out_Pin);
|
||||||
PWM_Out_Pin);
|
|
||||||
// Analog Inputs ... as analog inputs
|
// Analog Inputs ... as analog inputs
|
||||||
gpio_init(TMP36_INPUT_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ,
|
gpio_init(TMP36_INPUT_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ, TMP36_INPUT_Pin);
|
||||||
TMP36_INPUT_Pin);
|
gpio_init(TIP_TEMP_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ, TIP_TEMP_Pin);
|
||||||
gpio_init(TIP_TEMP_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ,
|
|
||||||
TIP_TEMP_Pin);
|
|
||||||
gpio_init(VIN_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ, VIN_Pin);
|
gpio_init(VIN_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ, VIN_Pin);
|
||||||
|
|
||||||
// Remap PB4 away from JTAG NJRST
|
// Remap PB4 away from JTAG NJRST
|
||||||
@@ -160,21 +154,15 @@ void setup_adc() {
|
|||||||
adc_channel_length_config(ADC0, ADC_INSERTED_CHANNEL, 4);
|
adc_channel_length_config(ADC0, ADC_INSERTED_CHANNEL, 4);
|
||||||
adc_channel_length_config(ADC1, ADC_INSERTED_CHANNEL, 4);
|
adc_channel_length_config(ADC1, ADC_INSERTED_CHANNEL, 4);
|
||||||
for (int rank = 0; rank < 4; rank++) {
|
for (int rank = 0; rank < 4; rank++) {
|
||||||
adc_inserted_channel_config(ADC0, rank, TIP_TEMP_ADC0_CHANNEL,
|
adc_inserted_channel_config(ADC0, rank, TIP_TEMP_ADC0_CHANNEL, ADC_SAMPLETIME_1POINT5);
|
||||||
ADC_SAMPLETIME_1POINT5);
|
adc_inserted_channel_config(ADC1, rank, TIP_TEMP_ADC1_CHANNEL, ADC_SAMPLETIME_1POINT5);
|
||||||
adc_inserted_channel_config(ADC1, rank, TIP_TEMP_ADC1_CHANNEL,
|
|
||||||
ADC_SAMPLETIME_1POINT5);
|
|
||||||
}
|
}
|
||||||
// Setup timer 1 channel 0 to trigger injected measurements
|
// Setup timer 1 channel 0 to trigger injected measurements
|
||||||
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL,
|
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||||
ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||||
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL,
|
|
||||||
ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
|
||||||
|
|
||||||
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL,
|
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||||
ADC0_1_EXTTRIG_REGULAR_NONE);
|
adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||||
adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL,
|
|
||||||
ADC0_1_EXTTRIG_REGULAR_NONE);
|
|
||||||
// Enable triggers for the ADC
|
// Enable triggers for the ADC
|
||||||
adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
|
adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
|
||||||
adc_external_trigger_config(ADC1, ADC_INSERTED_CHANNEL, ENABLE);
|
adc_external_trigger_config(ADC1, ADC_INSERTED_CHANNEL, ENABLE);
|
||||||
@@ -229,12 +217,9 @@ void setup_timers() {
|
|||||||
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
|
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
|
||||||
timer_channel_output_config(TIMER1, TIMER_CH_0, &timer_ocintpara);
|
timer_channel_output_config(TIMER1, TIMER_CH_0, &timer_ocintpara);
|
||||||
|
|
||||||
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_0,
|
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_0, powerPWM + holdoffTicks);
|
||||||
powerPWM + holdoffTicks);
|
timer_channel_output_mode_config(TIMER1, TIMER_CH_0, TIMER_OC_MODE_PWM1);
|
||||||
timer_channel_output_mode_config(TIMER1, TIMER_CH_0,
|
timer_channel_output_shadow_config(TIMER1, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
|
||||||
TIMER_OC_MODE_PWM1);
|
|
||||||
timer_channel_output_shadow_config(TIMER1, TIMER_CH_0,
|
|
||||||
TIMER_OC_SHADOW_DISABLE);
|
|
||||||
/* CH1 used for irq */
|
/* CH1 used for irq */
|
||||||
timer_channel_output_struct_para_init(&timer_ocintpara);
|
timer_channel_output_struct_para_init(&timer_ocintpara);
|
||||||
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
|
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
|
||||||
@@ -242,10 +227,8 @@ void setup_timers() {
|
|||||||
timer_channel_output_config(TIMER1, TIMER_CH_1, &timer_ocintpara);
|
timer_channel_output_config(TIMER1, TIMER_CH_1, &timer_ocintpara);
|
||||||
|
|
||||||
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1, 0);
|
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1, 0);
|
||||||
timer_channel_output_mode_config(TIMER1, TIMER_CH_1,
|
timer_channel_output_mode_config(TIMER1, TIMER_CH_1, TIMER_OC_MODE_PWM0);
|
||||||
TIMER_OC_MODE_PWM0);
|
timer_channel_output_shadow_config(TIMER1, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
|
||||||
timer_channel_output_shadow_config(TIMER1, TIMER_CH_1,
|
|
||||||
TIMER_OC_SHADOW_DISABLE);
|
|
||||||
// IRQ
|
// IRQ
|
||||||
timer_interrupt_enable(TIMER1, TIMER_INT_UP);
|
timer_interrupt_enable(TIMER1, TIMER_INT_UP);
|
||||||
timer_interrupt_enable(TIMER1, TIMER_INT_CH1);
|
timer_interrupt_enable(TIMER1, TIMER_INT_CH1);
|
||||||
@@ -276,10 +259,8 @@ void setup_timers() {
|
|||||||
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
|
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
|
||||||
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
|
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
|
||||||
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 0);
|
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 0);
|
||||||
timer_channel_output_mode_config(TIMER2, TIMER_CH_0,
|
timer_channel_output_mode_config(TIMER2, TIMER_CH_0, TIMER_OC_MODE_PWM0);
|
||||||
TIMER_OC_MODE_PWM0);
|
timer_channel_output_shadow_config(TIMER2, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
|
||||||
timer_channel_output_shadow_config(TIMER2, TIMER_CH_0,
|
|
||||||
TIMER_OC_SHADOW_DISABLE);
|
|
||||||
timer_auto_reload_shadow_enable(TIMER2);
|
timer_auto_reload_shadow_enable(TIMER2);
|
||||||
timer_enable(TIMER2);
|
timer_enable(TIMER2);
|
||||||
}
|
}
|
||||||
@@ -292,8 +273,7 @@ void setup_iwdg() {
|
|||||||
|
|
||||||
void setupFUSBIRQ() {
|
void setupFUSBIRQ() {
|
||||||
// Setup IRQ for USB-PD
|
// Setup IRQ for USB-PD
|
||||||
gpio_init(FUSB302_IRQ_GPIO_Port, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ,
|
gpio_init(FUSB302_IRQ_GPIO_Port, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ, FUSB302_IRQ_Pin);
|
||||||
FUSB302_IRQ_Pin);
|
|
||||||
eclic_irq_enable(EXTI5_9_IRQn, 1, 1);
|
eclic_irq_enable(EXTI5_9_IRQn, 1, 1);
|
||||||
/* connect key EXTI line to key GPIO pin */
|
/* connect key EXTI line to key GPIO pin */
|
||||||
gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOB, GPIO_PIN_SOURCE_5);
|
gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOB, GPIO_PIN_SOURCE_5);
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Scheduler includes. */
|
/* Scheduler includes. */
|
||||||
#include <stdio.h>
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
//#define ENABLE_KERNEL_DEBUG
|
//#define ENABLE_KERNEL_DEBUG
|
||||||
|
|
||||||
@@ -223,8 +223,7 @@ uint8_t uxMaxSysCallMTH = 255;
|
|||||||
* portTASK_RETURN_ADDRESS
|
* portTASK_RETURN_ADDRESS
|
||||||
* pxCode
|
* pxCode
|
||||||
*/
|
*/
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
|
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters) {
|
||||||
{
|
|
||||||
/* Simulate the stack frame as it would be created by a context switch
|
/* Simulate the stack frame as it would be created by a context switch
|
||||||
interrupt. */
|
interrupt. */
|
||||||
|
|
||||||
@@ -250,8 +249,7 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvTaskExitError( void )
|
static void prvTaskExitError(void) {
|
||||||
{
|
|
||||||
volatile uint32_t ulDummy = 0;
|
volatile uint32_t ulDummy = 0;
|
||||||
|
|
||||||
/* A function that implements a task must not exit or attempt to return to
|
/* A function that implements a task must not exit or attempt to return to
|
||||||
@@ -262,8 +260,7 @@ static void prvTaskExitError( void )
|
|||||||
defined, then stop here so application writers can catch the error. */
|
defined, then stop here so application writers can catch the error. */
|
||||||
configASSERT(uxCriticalNesting == ~0UL);
|
configASSERT(uxCriticalNesting == ~0UL);
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
while( ulDummy == 0 )
|
while (ulDummy == 0) {
|
||||||
{
|
|
||||||
/* This file calls prvTaskExitError() after the scheduler has been
|
/* This file calls prvTaskExitError() after the scheduler has been
|
||||||
started to remove a compiler warning about the function being defined
|
started to remove a compiler warning about the function being defined
|
||||||
but never called. ulDummy is used purely to quieten other warnings
|
but never called. ulDummy is used purely to quieten other warnings
|
||||||
@@ -277,8 +274,7 @@ static void prvTaskExitError( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static uint8_t prvCheckMaxSysCallPrio( uint8_t max_syscall_prio )
|
static uint8_t prvCheckMaxSysCallPrio(uint8_t max_syscall_prio) {
|
||||||
{
|
|
||||||
uint8_t nlbits = __ECLIC_GetCfgNlbits();
|
uint8_t nlbits = __ECLIC_GetCfgNlbits();
|
||||||
uint8_t intctlbits = __ECLIC_INTCTLBITS;
|
uint8_t intctlbits = __ECLIC_INTCTLBITS;
|
||||||
uint8_t lvlbits, temp;
|
uint8_t lvlbits, temp;
|
||||||
@@ -296,8 +292,7 @@ static uint8_t prvCheckMaxSysCallPrio( uint8_t max_syscall_prio )
|
|||||||
return max_syscall_prio;
|
return max_syscall_prio;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t prvCalcMaxSysCallMTH( uint8_t max_syscall_prio )
|
static uint8_t prvCalcMaxSysCallMTH(uint8_t max_syscall_prio) {
|
||||||
{
|
|
||||||
uint8_t nlbits = __ECLIC_GetCfgNlbits();
|
uint8_t nlbits = __ECLIC_GetCfgNlbits();
|
||||||
uint8_t intctlbits = __ECLIC_INTCTLBITS;
|
uint8_t intctlbits = __ECLIC_INTCTLBITS;
|
||||||
uint8_t lvlbits, lfabits;
|
uint8_t lvlbits, lfabits;
|
||||||
@@ -325,8 +320,7 @@ static uint8_t prvCalcMaxSysCallMTH( uint8_t max_syscall_prio )
|
|||||||
/*
|
/*
|
||||||
* See header file for description.
|
* See header file for description.
|
||||||
*/
|
*/
|
||||||
BaseType_t xPortStartScheduler( void )
|
BaseType_t xPortStartScheduler(void) {
|
||||||
{
|
|
||||||
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. */
|
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. */
|
||||||
configASSERT(configMAX_SYSCALL_INTERRUPT_PRIORITY);
|
configASSERT(configMAX_SYSCALL_INTERRUPT_PRIORITY);
|
||||||
|
|
||||||
@@ -367,16 +361,14 @@ BaseType_t xPortStartScheduler( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vPortEndScheduler( void )
|
void vPortEndScheduler(void) {
|
||||||
{
|
|
||||||
/* Not implemented in ports where there is nothing to return to.
|
/* Not implemented in ports where there is nothing to return to.
|
||||||
Artificially force an assert. */
|
Artificially force an assert. */
|
||||||
configASSERT(uxCriticalNesting == 1000UL);
|
configASSERT(uxCriticalNesting == 1000UL);
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vPortEnterCritical( void )
|
void vPortEnterCritical(void) {
|
||||||
{
|
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
uxCriticalNesting++;
|
uxCriticalNesting++;
|
||||||
|
|
||||||
@@ -385,26 +377,22 @@ void vPortEnterCritical( void )
|
|||||||
functions that end in "FromISR" can be used in an interrupt. Only assert if
|
functions that end in "FromISR" can be used in an interrupt. Only assert if
|
||||||
the critical nesting count is 1 to protect against recursive calls if the
|
the critical nesting count is 1 to protect against recursive calls if the
|
||||||
assert function also uses a critical section. */
|
assert function also uses a critical section. */
|
||||||
if( uxCriticalNesting == 1 )
|
if (uxCriticalNesting == 1) {
|
||||||
{
|
|
||||||
configASSERT((__ECLIC_GetMth() & portMTH_MASK) == uxMaxSysCallMTH);
|
configASSERT((__ECLIC_GetMth() & portMTH_MASK) == uxMaxSysCallMTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vPortExitCritical( void )
|
void vPortExitCritical(void) {
|
||||||
{
|
|
||||||
configASSERT(uxCriticalNesting);
|
configASSERT(uxCriticalNesting);
|
||||||
uxCriticalNesting--;
|
uxCriticalNesting--;
|
||||||
if( uxCriticalNesting == 0 )
|
if (uxCriticalNesting == 0) {
|
||||||
{
|
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vPortAssert( int32_t x )
|
void vPortAssert(int32_t x) {
|
||||||
{
|
|
||||||
TaskHandle_t th;
|
TaskHandle_t th;
|
||||||
if ((x) == 0) {
|
if ((x) == 0) {
|
||||||
taskDISABLE_INTERRUPTS();
|
taskDISABLE_INTERRUPTS();
|
||||||
@@ -422,9 +410,7 @@ void vPortAssert( int32_t x )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void xPortTaskSwitch(void) {
|
||||||
void xPortTaskSwitch( void )
|
|
||||||
{
|
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
/* Clear Software IRQ, A MUST */
|
/* Clear Software IRQ, A MUST */
|
||||||
SysTimer_ClearSWIRQ();
|
SysTimer_ClearSWIRQ();
|
||||||
@@ -433,8 +419,7 @@ void xPortTaskSwitch( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void xPortSysTickHandler( void )
|
void xPortSysTickHandler(void) {
|
||||||
{
|
|
||||||
/* The SysTick runs at the lowest interrupt priority, so when this interrupt
|
/* The SysTick runs at the lowest interrupt priority, so when this interrupt
|
||||||
executes all interrupts must be unmasked. There is therefore no need to
|
executes all interrupts must be unmasked. There is therefore no need to
|
||||||
save and then restore the interrupt mask value as its value is already
|
save and then restore the interrupt mask value as its value is already
|
||||||
@@ -443,8 +428,7 @@ void xPortSysTickHandler( void )
|
|||||||
{
|
{
|
||||||
SysTick_Reload(SYSTICK_TICK_CONST);
|
SysTick_Reload(SYSTICK_TICK_CONST);
|
||||||
/* Increment the RTOS tick. */
|
/* Increment the RTOS tick. */
|
||||||
if( xTaskIncrementTick() != pdFALSE )
|
if (xTaskIncrementTick() != pdFALSE) {
|
||||||
{
|
|
||||||
/* A context switch is required. Context switching is performed in
|
/* A context switch is required. Context switching is performed in
|
||||||
the SWI interrupt. Pend the SWI interrupt. */
|
the SWI interrupt. Pend the SWI interrupt. */
|
||||||
portYIELD();
|
portYIELD();
|
||||||
@@ -456,16 +440,14 @@ void xPortSysTickHandler( void )
|
|||||||
|
|
||||||
#if (configUSE_TICKLESS_IDLE == 1)
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
|
|
||||||
__attribute__((weak)) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__((weak)) void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
|
||||||
{
|
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
||||||
volatile TickType_t xModifiableIdleTime, xTickCountBeforeSleep, XLastLoadValue;
|
volatile TickType_t xModifiableIdleTime, xTickCountBeforeSleep, XLastLoadValue;
|
||||||
|
|
||||||
FREERTOS_PORT_DEBUG("Enter TickLess %d\n", (uint32_t)xExpectedIdleTime);
|
FREERTOS_PORT_DEBUG("Enter TickLess %d\n", (uint32_t)xExpectedIdleTime);
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )
|
if (xExpectedIdleTime > xMaximumPossibleSuppressedTicks) {
|
||||||
{
|
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,8 +461,7 @@ void xPortSysTickHandler( void )
|
|||||||
tick periods. -1 is used because this code will execute part way
|
tick periods. -1 is used because this code will execute part way
|
||||||
through one of the tick periods. */
|
through one of the tick periods. */
|
||||||
ulReloadValue = (ulTimerCountsForOneTick * (xExpectedIdleTime - 1UL));
|
ulReloadValue = (ulTimerCountsForOneTick * (xExpectedIdleTime - 1UL));
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
if (ulReloadValue > ulStoppedTimerCompensation) {
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,8 +471,7 @@ void xPortSysTickHandler( void )
|
|||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
to be unsuspended then abandon the low power entry. */
|
to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
|
||||||
{
|
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Restart from whatever is left in the count register to complete
|
||||||
this tick period. */
|
this tick period. */
|
||||||
/* Restart SysTick. */
|
/* Restart SysTick. */
|
||||||
@@ -504,9 +484,7 @@ void xPortSysTickHandler( void )
|
|||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
/* Re-enable interrupts - see comments above the cpsid instruction()
|
||||||
above. */
|
above. */
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
xTickCountBeforeSleep = xTaskGetTickCount();
|
xTickCountBeforeSleep = xTaskGetTickCount();
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
@@ -527,8 +505,7 @@ void xPortSysTickHandler( void )
|
|||||||
time variable must remain unmodified, so a copy is taken. */
|
time variable must remain unmodified, so a copy is taken. */
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING(xModifiableIdleTime);
|
configPRE_SLEEP_PROCESSING(xModifiableIdleTime);
|
||||||
if( xModifiableIdleTime > 0 )
|
if (xModifiableIdleTime > 0) {
|
||||||
{
|
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
configPOST_SLEEP_PROCESSING(xExpectedIdleTime);
|
configPOST_SLEEP_PROCESSING(xExpectedIdleTime);
|
||||||
@@ -558,16 +535,13 @@ void xPortSysTickHandler( void )
|
|||||||
/* Determine if SysTimer Interrupt is not yet happened,
|
/* Determine if SysTimer Interrupt is not yet happened,
|
||||||
(in which case an interrupt other than the SysTick
|
(in which case an interrupt other than the SysTick
|
||||||
must have brought the system out of sleep mode). */
|
must have brought the system out of sleep mode). */
|
||||||
if (SysTimer_GetLoadValue() >= (XLastLoadValue + ulReloadValue))
|
if (SysTimer_GetLoadValue() >= (XLastLoadValue + ulReloadValue)) {
|
||||||
{
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
function exits, the tick value maintained by the tick is stepped
|
function exits, the tick value maintained by the tick is stepped
|
||||||
forward by one less than the time spent waiting. */
|
forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
FREERTOS_PORT_DEBUG("TickLess - SysTimer Interrupt Entered!\n");
|
FREERTOS_PORT_DEBUG("TickLess - SysTimer Interrupt Entered!\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep.
|
||||||
Work out how long the sleep lasted rounded to complete tick
|
Work out how long the sleep lasted rounded to complete tick
|
||||||
periods (not the ulReload value which accounted for part
|
periods (not the ulReload value which accounted for part
|
||||||
@@ -607,16 +581,15 @@ void xPortSysTickHandler( void )
|
|||||||
* Setup the systick timer to generate the tick interrupts at the required
|
* Setup the systick timer to generate the tick interrupts at the required
|
||||||
* frequency.
|
* frequency.
|
||||||
*/
|
*/
|
||||||
__attribute__(( weak )) void vPortSetupTimerInterrupt( void )
|
__attribute__((weak)) void vPortSetupTimerInterrupt(void) {
|
||||||
{
|
|
||||||
/* Calculate the constants required to configure the tick interrupt. */
|
/* Calculate the constants required to configure the tick interrupt. */
|
||||||
#if (configUSE_TICKLESS_IDLE == 1)
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
{
|
{
|
||||||
ulTimerCountsForOneTick = (SYSTICK_TICK_CONST);
|
ulTimerCountsForOneTick = (SYSTICK_TICK_CONST);
|
||||||
xMaximumPossibleSuppressedTicks = portMAX_BIT_NUMBER / ulTimerCountsForOneTick;
|
xMaximumPossibleSuppressedTicks = portMAX_BIT_NUMBER / ulTimerCountsForOneTick;
|
||||||
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / (configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ);
|
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / (configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ);
|
||||||
FREERTOS_PORT_DEBUG("CountsForOneTick, SuppressedTicks and TimerCompensation: %u, %u, %u\n", \
|
FREERTOS_PORT_DEBUG("CountsForOneTick, SuppressedTicks and TimerCompensation: %u, %u, %u\n", (uint32_t)ulTimerCountsForOneTick, (uint32_t)xMaximumPossibleSuppressedTicks,
|
||||||
(uint32_t)ulTimerCountsForOneTick, (uint32_t)xMaximumPossibleSuppressedTicks, (uint32_t)ulStoppedTimerCompensation);
|
(uint32_t)ulStoppedTimerCompensation);
|
||||||
}
|
}
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
TickType_t ticks = SYSTICK_TICK_CONST;
|
TickType_t ticks = SYSTICK_TICK_CONST;
|
||||||
@@ -640,8 +613,7 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
|
|||||||
|
|
||||||
#if (configASSERT_DEFINED == 1)
|
#if (configASSERT_DEFINED == 1)
|
||||||
|
|
||||||
void vPortValidateInterruptPriority( void )
|
void vPortValidateInterruptPriority(void) {
|
||||||
{
|
|
||||||
uint32_t ulCurrentInterrupt;
|
uint32_t ulCurrentInterrupt;
|
||||||
uint8_t ucCurrentPriority;
|
uint8_t ucCurrentPriority;
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nuclei_sdk_hal.h"
|
|
||||||
#include "gd32vf103_usart.h"
|
|
||||||
#include "gd32vf103_gpio.h"
|
|
||||||
#include "gd32vf103_exti.h"
|
#include "gd32vf103_exti.h"
|
||||||
|
#include "gd32vf103_gpio.h"
|
||||||
|
#include "gd32vf103_usart.h"
|
||||||
|
#include "nuclei_sdk_hal.h"
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usb_core_reset (usb_core_regs *usb_regs)
|
static void usb_core_reset(usb_core_regs *usb_regs) {
|
||||||
{
|
|
||||||
/* enable core soft reset */
|
/* enable core soft reset */
|
||||||
usb_regs->gr->GRSTCTL |= GRSTCTL_CSRST;
|
usb_regs->gr->GRSTCTL |= GRSTCTL_CSRST;
|
||||||
|
|
||||||
/* wait for the core to be soft reset */
|
/* wait for the core to be soft reset */
|
||||||
while (usb_regs->gr->GRSTCTL & GRSTCTL_CSRST);
|
while (usb_regs->gr->GRSTCTL & GRSTCTL_CSRST)
|
||||||
|
;
|
||||||
|
|
||||||
/* wait for addtional 3 PHY clocks */
|
/* wait for addtional 3 PHY clocks */
|
||||||
usb_udelay(3);
|
usb_udelay(3);
|
||||||
@@ -61,10 +61,7 @@ static void usb_core_reset (usb_core_regs *usb_regs)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_basic_init (usb_core_basic *usb_basic,
|
usb_status usb_basic_init(usb_core_basic *usb_basic, usb_core_regs *usb_regs, usb_core_enum usb_core) {
|
||||||
usb_core_regs *usb_regs,
|
|
||||||
usb_core_enum usb_core)
|
|
||||||
{
|
|
||||||
uint32_t i = 0, reg_base = 0;
|
uint32_t i = 0, reg_base = 0;
|
||||||
|
|
||||||
/* config USB default transfer mode as FIFO mode */
|
/* config USB default transfer mode as FIFO mode */
|
||||||
@@ -117,31 +114,25 @@ usb_status usb_basic_init (usb_core_basic *usb_basic,
|
|||||||
usb_basic->low_power = USB_LOW_POWER;
|
usb_basic->low_power = USB_LOW_POWER;
|
||||||
|
|
||||||
/* assign main registers address */
|
/* assign main registers address */
|
||||||
*usb_regs = (usb_core_regs) {
|
*usb_regs = (usb_core_regs){.gr = (usb_gr *)(reg_base + USB_REG_OFFSET_CORE),
|
||||||
.gr = (usb_gr*) (reg_base + USB_REG_OFFSET_CORE),
|
|
||||||
.hr = (usb_hr *)(reg_base + USB_REG_OFFSET_HOST),
|
.hr = (usb_hr *)(reg_base + USB_REG_OFFSET_HOST),
|
||||||
.dr = (usb_dr *)(reg_base + USB_REG_OFFSET_DEV),
|
.dr = (usb_dr *)(reg_base + USB_REG_OFFSET_DEV),
|
||||||
|
|
||||||
.HPCS = (uint32_t *)(reg_base + USB_REG_OFFSET_PORT),
|
.HPCS = (uint32_t *)(reg_base + USB_REG_OFFSET_PORT),
|
||||||
.PWRCLKCTL = (uint32_t*) (reg_base + USB_REG_OFFSET_PWRCLKCTL)
|
.PWRCLKCTL = (uint32_t *)(reg_base + USB_REG_OFFSET_PWRCLKCTL)};
|
||||||
};
|
|
||||||
|
|
||||||
/* assign device endpoint registers address */
|
/* assign device endpoint registers address */
|
||||||
for (i = 0; i < usb_basic->num_ep; i++) {
|
for (i = 0; i < usb_basic->num_ep; i++) {
|
||||||
usb_regs->er_in[i] = (usb_erin *) \
|
usb_regs->er_in[i] = (usb_erin *)(reg_base + USB_REG_OFFSET_EP_IN + (i * USB_REG_OFFSET_EP));
|
||||||
(reg_base + USB_REG_OFFSET_EP_IN + (i * USB_REG_OFFSET_EP));
|
|
||||||
|
|
||||||
usb_regs->er_out[i] = (usb_erout *)\
|
usb_regs->er_out[i] = (usb_erout *)(reg_base + USB_REG_OFFSET_EP_OUT + (i * USB_REG_OFFSET_EP));
|
||||||
(reg_base + USB_REG_OFFSET_EP_OUT + (i * USB_REG_OFFSET_EP));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assign host pipe registers address */
|
/* assign host pipe registers address */
|
||||||
for (i = 0; i < usb_basic->num_pipe; i++) {
|
for (i = 0; i < usb_basic->num_pipe; i++) {
|
||||||
usb_regs->pr[i] = (usb_pr *) \
|
usb_regs->pr[i] = (usb_pr *)(reg_base + USB_REG_OFFSET_CH_INOUT + (i * USB_REG_OFFSET_CH));
|
||||||
(reg_base + USB_REG_OFFSET_CH_INOUT + (i * USB_REG_OFFSET_CH));
|
|
||||||
|
|
||||||
usb_regs->DFIFO[i] = (uint32_t *) \
|
usb_regs->DFIFO[i] = (uint32_t *)(reg_base + USB_DATA_FIFO_OFFSET + (i * USB_DATA_FIFO_SIZE));
|
||||||
(reg_base + USB_DATA_FIFO_OFFSET + (i * USB_DATA_FIFO_SIZE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_OK;
|
return USB_OK;
|
||||||
@@ -155,8 +146,7 @@ usb_status usb_basic_init (usb_core_basic *usb_basic,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_core_init (usb_core_basic usb_basic, usb_core_regs *usb_regs)
|
usb_status usb_core_init(usb_core_basic usb_basic, usb_core_regs *usb_regs) {
|
||||||
{
|
|
||||||
uint32_t reg_value = usb_regs->gr->GCCFG;
|
uint32_t reg_value = usb_regs->gr->GCCFG;
|
||||||
|
|
||||||
/* disable USB global interrupt */
|
/* disable USB global interrupt */
|
||||||
@@ -221,8 +211,7 @@ usb_status usb_core_init (usb_core_basic usb_basic, usb_core_regs *usb_regs)
|
|||||||
/* enable the USB wakeup and suspend interrupts */
|
/* enable the USB wakeup and suspend interrupts */
|
||||||
usb_regs->gr->GINTF = 0xBFFFFFFFU;
|
usb_regs->gr->GINTF = 0xBFFFFFFFU;
|
||||||
|
|
||||||
usb_regs->gr->GINTEN = GINTEN_WKUPIE | GINTEN_SPIE | \
|
usb_regs->gr->GINTEN = GINTEN_WKUPIE | GINTEN_SPIE | GINTEN_OTGIE | GINTEN_SESIE | GINTEN_CIDPSCIE;
|
||||||
GINTEN_OTGIE | GINTEN_SESIE | GINTEN_CIDPSCIE;
|
|
||||||
|
|
||||||
#endif /* USE_OTG_MODE */
|
#endif /* USE_OTG_MODE */
|
||||||
|
|
||||||
@@ -238,11 +227,7 @@ usb_status usb_core_init (usb_core_basic usb_basic, usb_core_regs *usb_regs)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_txfifo_write (usb_core_regs *usb_regs,
|
usb_status usb_txfifo_write(usb_core_regs *usb_regs, uint8_t *src_buf, uint8_t fifo_num, uint16_t byte_count) {
|
||||||
uint8_t *src_buf,
|
|
||||||
uint8_t fifo_num,
|
|
||||||
uint16_t byte_count)
|
|
||||||
{
|
|
||||||
uint32_t word_count = (byte_count + 3U) / 4U;
|
uint32_t word_count = (byte_count + 3U) / 4U;
|
||||||
|
|
||||||
__IO uint32_t *fifo = usb_regs->DFIFO[fifo_num];
|
__IO uint32_t *fifo = usb_regs->DFIFO[fifo_num];
|
||||||
@@ -264,8 +249,7 @@ usb_status usb_txfifo_write (usb_core_regs *usb_regs,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval void type pointer
|
\retval void type pointer
|
||||||
*/
|
*/
|
||||||
void *usb_rxfifo_read (usb_core_regs *usb_regs, uint8_t *dest_buf, uint16_t byte_count)
|
void *usb_rxfifo_read(usb_core_regs *usb_regs, uint8_t *dest_buf, uint16_t byte_count) {
|
||||||
{
|
|
||||||
uint32_t word_count = (byte_count + 3U) / 4U;
|
uint32_t word_count = (byte_count + 3U) / 4U;
|
||||||
|
|
||||||
__IO uint32_t *fifo = usb_regs->DFIFO[0];
|
__IO uint32_t *fifo = usb_regs->DFIFO[0];
|
||||||
@@ -286,12 +270,12 @@ void *usb_rxfifo_read (usb_core_regs *usb_regs, uint8_t *dest_buf, uint16_t byte
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_txfifo_flush (usb_core_regs *usb_regs, uint8_t fifo_num)
|
usb_status usb_txfifo_flush(usb_core_regs *usb_regs, uint8_t fifo_num) {
|
||||||
{
|
|
||||||
usb_regs->gr->GRSTCTL = ((uint32_t)fifo_num << 6U) | GRSTCTL_TXFF;
|
usb_regs->gr->GRSTCTL = ((uint32_t)fifo_num << 6U) | GRSTCTL_TXFF;
|
||||||
|
|
||||||
/* wait for Tx FIFO flush bit is set */
|
/* wait for Tx FIFO flush bit is set */
|
||||||
while (usb_regs->gr->GRSTCTL & GRSTCTL_TXFF);
|
while (usb_regs->gr->GRSTCTL & GRSTCTL_TXFF)
|
||||||
|
;
|
||||||
|
|
||||||
/* wait for 3 PHY clocks*/
|
/* wait for 3 PHY clocks*/
|
||||||
usb_udelay(3);
|
usb_udelay(3);
|
||||||
@@ -305,12 +289,12 @@ usb_status usb_txfifo_flush (usb_core_regs *usb_regs, uint8_t fifo_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_rxfifo_flush (usb_core_regs *usb_regs)
|
usb_status usb_rxfifo_flush(usb_core_regs *usb_regs) {
|
||||||
{
|
|
||||||
usb_regs->gr->GRSTCTL = GRSTCTL_RXFF;
|
usb_regs->gr->GRSTCTL = GRSTCTL_RXFF;
|
||||||
|
|
||||||
/* wait for Rx FIFO flush bit is set */
|
/* wait for Rx FIFO flush bit is set */
|
||||||
while (usb_regs->gr->GRSTCTL & GRSTCTL_RXFF);
|
while (usb_regs->gr->GRSTCTL & GRSTCTL_RXFF)
|
||||||
|
;
|
||||||
|
|
||||||
/* wait for 3 PHY clocks */
|
/* wait for 3 PHY clocks */
|
||||||
usb_udelay(3);
|
usb_udelay(3);
|
||||||
|
|||||||
@@ -31,41 +31,23 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
|
|||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "gd32vf103_libopt.h"
|
|
||||||
#include "drv_usb_hw.h"
|
|
||||||
#include "drv_usb_core.h"
|
|
||||||
#include "drv_usb_dev.h"
|
#include "drv_usb_dev.h"
|
||||||
|
#include "drv_usb_core.h"
|
||||||
|
#include "drv_usb_hw.h"
|
||||||
|
#include "gd32vf103_libopt.h"
|
||||||
|
|
||||||
/* endpoint 0 max packet length */
|
/* endpoint 0 max packet length */
|
||||||
static const uint8_t EP0_MAXLEN[4] = {
|
static const uint8_t EP0_MAXLEN[4] = {[DSTAT_EM_HS_PHY_30MHZ_60MHZ] = EP0MPL_64, [DSTAT_EM_FS_PHY_30MHZ_60MHZ] = EP0MPL_64, [DSTAT_EM_FS_PHY_48MHZ] = EP0MPL_64, [DSTAT_EM_LS_PHY_6MHZ] = EP0MPL_8};
|
||||||
[DSTAT_EM_HS_PHY_30MHZ_60MHZ] = EP0MPL_64,
|
|
||||||
[DSTAT_EM_FS_PHY_30MHZ_60MHZ] = EP0MPL_64,
|
|
||||||
[DSTAT_EM_FS_PHY_48MHZ] = EP0MPL_64,
|
|
||||||
[DSTAT_EM_LS_PHY_6MHZ] = EP0MPL_8
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef USB_FS_CORE
|
#ifdef USB_FS_CORE
|
||||||
|
|
||||||
/* USB endpoint Tx FIFO size */
|
/* USB endpoint Tx FIFO size */
|
||||||
static uint16_t USBFS_TX_FIFO_SIZE[USBFS_MAX_EP_COUNT] =
|
static uint16_t USBFS_TX_FIFO_SIZE[USBFS_MAX_EP_COUNT] = {(uint16_t)TX0_FIFO_FS_SIZE, (uint16_t)TX1_FIFO_FS_SIZE, (uint16_t)TX2_FIFO_FS_SIZE, (uint16_t)TX3_FIFO_FS_SIZE};
|
||||||
{
|
|
||||||
(uint16_t)TX0_FIFO_FS_SIZE,
|
|
||||||
(uint16_t)TX1_FIFO_FS_SIZE,
|
|
||||||
(uint16_t)TX2_FIFO_FS_SIZE,
|
|
||||||
(uint16_t)TX3_FIFO_FS_SIZE
|
|
||||||
};
|
|
||||||
|
|
||||||
#elif defined(USB_HS_CORE)
|
#elif defined(USB_HS_CORE)
|
||||||
|
|
||||||
uint16_t USBHS_TX_FIFO_SIZE[USBHS_MAX_EP_COUNT] =
|
uint16_t USBHS_TX_FIFO_SIZE[USBHS_MAX_EP_COUNT]
|
||||||
{
|
= {(uint16_t)TX0_FIFO_HS_SIZE, (uint16_t)TX1_FIFO_HS_SIZE, (uint16_t)TX2_FIFO_HS_SIZE, (uint16_t)TX3_FIFO_HS_SIZE, (uint16_t)TX4_FIFO_HS_SIZE, (uint16_t)TX5_FIFO_HS_SIZE};
|
||||||
(uint16_t)TX0_FIFO_HS_SIZE,
|
|
||||||
(uint16_t)TX1_FIFO_HS_SIZE,
|
|
||||||
(uint16_t)TX2_FIFO_HS_SIZE,
|
|
||||||
(uint16_t)TX3_FIFO_HS_SIZE,
|
|
||||||
(uint16_t)TX4_FIFO_HS_SIZE,
|
|
||||||
(uint16_t)TX5_FIFO_HS_SIZE
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* USBFS_CORE */
|
#endif /* USBFS_CORE */
|
||||||
|
|
||||||
@@ -75,8 +57,7 @@ uint16_t USBHS_TX_FIFO_SIZE[USBHS_MAX_EP_COUNT] =
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_devcore_init (usb_core_driver *udev)
|
usb_status usb_devcore_init(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t i, ram_addr = 0;
|
uint32_t i, ram_addr = 0;
|
||||||
|
|
||||||
/* force to peripheral mode */
|
/* force to peripheral mode */
|
||||||
@@ -102,8 +83,7 @@ usb_status usb_devcore_init (usb_core_driver *udev)
|
|||||||
udev->regs.gr->GRFLEN = RX_FIFO_FS_SIZE;
|
udev->regs.gr->GRFLEN = RX_FIFO_FS_SIZE;
|
||||||
|
|
||||||
/* set endpoint 0 Tx FIFO length and RAM address */
|
/* set endpoint 0 Tx FIFO length and RAM address */
|
||||||
udev->regs.gr->DIEP0TFLEN_HNPTFLEN = ((uint32_t)TX0_FIFO_FS_SIZE << 16) | \
|
udev->regs.gr->DIEP0TFLEN_HNPTFLEN = ((uint32_t)TX0_FIFO_FS_SIZE << 16) | ((uint32_t)RX_FIFO_FS_SIZE);
|
||||||
((uint32_t)RX_FIFO_FS_SIZE);
|
|
||||||
|
|
||||||
ram_addr = RX_FIFO_FS_SIZE;
|
ram_addr = RX_FIFO_FS_SIZE;
|
||||||
|
|
||||||
@@ -111,8 +91,7 @@ usb_status usb_devcore_init (usb_core_driver *udev)
|
|||||||
for (i = 1; i < USBFS_MAX_EP_COUNT; i++) {
|
for (i = 1; i < USBFS_MAX_EP_COUNT; i++) {
|
||||||
ram_addr += USBFS_TX_FIFO_SIZE[i - 1];
|
ram_addr += USBFS_TX_FIFO_SIZE[i - 1];
|
||||||
|
|
||||||
udev->regs.gr->DIEPTFLEN[i - 1] = ((uint32_t)USBFS_TX_FIFO_SIZE[i] << 16U) | \
|
udev->regs.gr->DIEPTFLEN[i - 1] = ((uint32_t)USBFS_TX_FIFO_SIZE[i] << 16U) | ram_addr;
|
||||||
ram_addr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -130,8 +109,7 @@ usb_status usb_devcore_init (usb_core_driver *udev)
|
|||||||
udev->regs.gr->GRFLEN |= RX_FIFO_HS_SIZE;
|
udev->regs.gr->GRFLEN |= RX_FIFO_HS_SIZE;
|
||||||
|
|
||||||
/* Set endpoint 0 Tx FIFO length and RAM address */
|
/* Set endpoint 0 Tx FIFO length and RAM address */
|
||||||
udev->regs.gr->DIEP0TFLEN_HNPTFLEN = ((uint32_t)TX0_FIFO_HS_SIZE << 16) | \
|
udev->regs.gr->DIEP0TFLEN_HNPTFLEN = ((uint32_t)TX0_FIFO_HS_SIZE << 16) | RX_FIFO_HS_SIZE;
|
||||||
RX_FIFO_HS_SIZE;
|
|
||||||
|
|
||||||
ram_addr = RX_FIFO_HS_SIZE;
|
ram_addr = RX_FIFO_HS_SIZE;
|
||||||
|
|
||||||
@@ -139,8 +117,7 @@ usb_status usb_devcore_init (usb_core_driver *udev)
|
|||||||
for (i = 1; i < USBHS_MAX_EP_COUNT; i++) {
|
for (i = 1; i < USBHS_MAX_EP_COUNT; i++) {
|
||||||
ram_addr += USBHS_TX_FIFO_SIZE[i - 1];
|
ram_addr += USBHS_TX_FIFO_SIZE[i - 1];
|
||||||
|
|
||||||
udev->regs.gr->DIEPTFLEN[i - 1] = ((uint32_t)USBHS_TX_FIFO_SIZE[i] << 16) | \
|
udev->regs.gr->DIEPTFLEN[i - 1] = ((uint32_t)USBHS_TX_FIFO_SIZE[i] << 16) | ram_addr;
|
||||||
ram_addr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -197,8 +174,7 @@ usb_status usb_devcore_init (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_devint_enable (usb_core_driver *udev)
|
usb_status usb_devint_enable(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
/* clear any pending USB OTG interrupts */
|
/* clear any pending USB OTG interrupts */
|
||||||
udev->regs.gr->GOTGINTF = 0xFFFFFFFFU;
|
udev->regs.gr->GOTGINTF = 0xFFFFFFFFU;
|
||||||
|
|
||||||
@@ -212,8 +188,7 @@ usb_status usb_devint_enable (usb_core_driver *udev)
|
|||||||
if (USB_USE_FIFO == udev->bp.transfer_mode) {
|
if (USB_USE_FIFO == udev->bp.transfer_mode) {
|
||||||
udev->regs.gr->GINTEN |= GINTEN_RXFNEIE;
|
udev->regs.gr->GINTEN |= GINTEN_RXFNEIE;
|
||||||
}
|
}
|
||||||
udev->regs.gr->GINTEN |= GINTEN_RSTIE | GINTEN_ENUMFIE | GINTEN_IEPIE |\
|
udev->regs.gr->GINTEN |= GINTEN_RSTIE | GINTEN_ENUMFIE | GINTEN_IEPIE | GINTEN_OEPIE | GINTEN_SOFIE | GINTEN_MFIE;
|
||||||
GINTEN_OEPIE | GINTEN_SOFIE | GINTEN_MFIE;
|
|
||||||
|
|
||||||
#ifdef VBUS_SENSING_ENABLED
|
#ifdef VBUS_SENSING_ENABLED
|
||||||
udev->regs.gr->GINTEN |= GINTEN_SESIE | GINTEN_OTGIE;
|
udev->regs.gr->GINTEN |= GINTEN_SESIE | GINTEN_OTGIE;
|
||||||
@@ -231,10 +206,7 @@ usb_status usb_devint_enable (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
void usb_dev_disconnect (usb_core_driver *udev)
|
void usb_dev_disconnect(usb_core_driver *udev) { udev->regs.dr->DCTL |= DCTL_SD; }
|
||||||
{
|
|
||||||
udev->regs.dr->DCTL |= DCTL_SD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief config the USB device to be connected
|
\brief config the USB device to be connected
|
||||||
@@ -242,10 +214,7 @@ void usb_dev_disconnect (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
void usb_dev_connect (usb_core_driver *udev)
|
void usb_dev_connect(usb_core_driver *udev) { udev->regs.dr->DCTL &= ~DCTL_SD; }
|
||||||
{
|
|
||||||
udev->regs.dr->DCTL &= ~DCTL_SD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set the USB device address
|
\brief set the USB device address
|
||||||
@@ -254,8 +223,7 @@ void usb_dev_connect (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
void usb_devaddr_set (usb_core_driver *udev, uint8_t dev_addr)
|
void usb_devaddr_set(usb_core_driver *udev, uint8_t dev_addr) {
|
||||||
{
|
|
||||||
udev->regs.dr->DCFG &= ~DCFG_DAR;
|
udev->regs.dr->DCFG &= ~DCFG_DAR;
|
||||||
udev->regs.dr->DCFG |= dev_addr << 4;
|
udev->regs.dr->DCFG |= dev_addr << 4;
|
||||||
}
|
}
|
||||||
@@ -267,8 +235,7 @@ void usb_devaddr_set (usb_core_driver *udev, uint8_t dev_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_active (usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_active(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
__IO uint32_t *reg_addr = NULL;
|
__IO uint32_t *reg_addr = NULL;
|
||||||
|
|
||||||
__IO uint32_t epinten = 0U;
|
__IO uint32_t epinten = 0U;
|
||||||
@@ -305,8 +272,7 @@ usb_status usb_transc_active (usb_core_driver *udev, usb_transc *transc)
|
|||||||
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
|
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
|
||||||
if ((ep_num == 1) && (udev->bp.core == USB_HS_CORE_ID)) {
|
if ((ep_num == 1) && (udev->bp.core == USB_HS_CORE_ID)) {
|
||||||
udev->regs.dr->DEP1INTEN |= epinten;
|
udev->regs.dr->DEP1INTEN |= epinten;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* enable the interrupts for this endpoint */
|
/* enable the interrupts for this endpoint */
|
||||||
@@ -323,8 +289,7 @@ usb_status usb_transc_active (usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_deactivate(usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_deactivate(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
uint32_t epinten = 0U;
|
uint32_t epinten = 0U;
|
||||||
|
|
||||||
uint8_t ep_num = transc->ep_addr.num;
|
uint8_t ep_num = transc->ep_addr.num;
|
||||||
@@ -343,8 +308,7 @@ usb_status usb_transc_deactivate(usb_core_driver *udev, usb_transc *transc)
|
|||||||
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
|
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
|
||||||
if ((ep_num == 1) && (udev->bp.core == USB_CORE_HS)) {
|
if ((ep_num == 1) && (udev->bp.core == USB_CORE_HS)) {
|
||||||
udev->regs.dr->DEP1INTEN &= ~epinten;
|
udev->regs.dr->DEP1INTEN &= ~epinten;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* disable the interrupts for this endpoint */
|
/* disable the interrupts for this endpoint */
|
||||||
@@ -361,8 +325,7 @@ usb_status usb_transc_deactivate(usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_inxfer (usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_inxfer(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
usb_status status = USB_OK;
|
usb_status status = USB_OK;
|
||||||
|
|
||||||
uint8_t ep_num = transc->ep_addr.num;
|
uint8_t ep_num = transc->ep_addr.num;
|
||||||
@@ -432,8 +395,7 @@ usb_status usb_transc_inxfer (usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_outxfer (usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_outxfer(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
usb_status status = USB_OK;
|
usb_status status = USB_OK;
|
||||||
|
|
||||||
uint8_t ep_num = transc->ep_addr.num;
|
uint8_t ep_num = transc->ep_addr.num;
|
||||||
@@ -490,8 +452,7 @@ usb_status usb_transc_outxfer (usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_stall (usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_stall(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
__IO uint32_t *reg_addr = NULL;
|
__IO uint32_t *reg_addr = NULL;
|
||||||
|
|
||||||
uint8_t ep_num = transc->ep_addr.num;
|
uint8_t ep_num = transc->ep_addr.num;
|
||||||
@@ -521,8 +482,7 @@ usb_status usb_transc_stall (usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
usb_status usb_transc_clrstall(usb_core_driver *udev, usb_transc *transc)
|
usb_status usb_transc_clrstall(usb_core_driver *udev, usb_transc *transc) {
|
||||||
{
|
|
||||||
__IO uint32_t *reg_addr = NULL;
|
__IO uint32_t *reg_addr = NULL;
|
||||||
|
|
||||||
uint8_t ep_num = transc->ep_addr.num;
|
uint8_t ep_num = transc->ep_addr.num;
|
||||||
@@ -550,8 +510,7 @@ usb_status usb_transc_clrstall(usb_core_driver *udev, usb_transc *transc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usb_oepintnum_read (usb_core_driver *udev)
|
uint32_t usb_oepintnum_read(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t value = udev->regs.dr->DAEPINT;
|
uint32_t value = udev->regs.dr->DAEPINT;
|
||||||
|
|
||||||
value &= udev->regs.dr->DAEPINTEN;
|
value &= udev->regs.dr->DAEPINTEN;
|
||||||
@@ -566,8 +525,7 @@ uint32_t usb_oepintnum_read (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usb_oepintr_read (usb_core_driver *udev, uint8_t ep_num)
|
uint32_t usb_oepintr_read(usb_core_driver *udev, uint8_t ep_num) {
|
||||||
{
|
|
||||||
uint32_t value = udev->regs.er_out[ep_num]->DOEPINTF;
|
uint32_t value = udev->regs.er_out[ep_num]->DOEPINTF;
|
||||||
|
|
||||||
value &= udev->regs.dr->DOEPINTEN;
|
value &= udev->regs.dr->DOEPINTEN;
|
||||||
@@ -581,8 +539,7 @@ uint32_t usb_oepintr_read (usb_core_driver *udev, uint8_t ep_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usb_iepintnum_read (usb_core_driver *udev)
|
uint32_t usb_iepintnum_read(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t value = udev->regs.dr->DAEPINT;
|
uint32_t value = udev->regs.dr->DAEPINT;
|
||||||
|
|
||||||
value &= udev->regs.dr->DAEPINTEN;
|
value &= udev->regs.dr->DAEPINTEN;
|
||||||
@@ -590,7 +547,6 @@ uint32_t usb_iepintnum_read (usb_core_driver *udev)
|
|||||||
return value & DAEPINT_IEPITB;
|
return value & DAEPINT_IEPITB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief read device IN endpoint interrupt flag register
|
\brief read device IN endpoint interrupt flag register
|
||||||
\param[in] udev: pointer to usb device
|
\param[in] udev: pointer to usb device
|
||||||
@@ -598,8 +554,7 @@ uint32_t usb_iepintnum_read (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usb_iepintr_read (usb_core_driver *udev, uint8_t ep_num)
|
uint32_t usb_iepintr_read(usb_core_driver *udev, uint8_t ep_num) {
|
||||||
{
|
|
||||||
uint32_t value = 0U, fifoemptymask = 0U, commonintmask = 0U;
|
uint32_t value = 0U, fifoemptymask = 0U, commonintmask = 0U;
|
||||||
|
|
||||||
commonintmask = udev->regs.dr->DIEPINTEN;
|
commonintmask = udev->regs.dr->DIEPINTEN;
|
||||||
@@ -619,8 +574,7 @@ uint32_t usb_iepintr_read (usb_core_driver *udev, uint8_t ep_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_ctlep_startout (usb_core_driver *udev)
|
void usb_ctlep_startout(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
/* set OUT endpoint 0 receive length to 24 bytes, 1 packet and 3 setup packets */
|
/* set OUT endpoint 0 receive length to 24 bytes, 1 packet and 3 setup packets */
|
||||||
udev->regs.er_out[0]->DOEPLEN = DOEP0_TLEN(8U * 3U) | DOEP0_PCNT(1U) | DOEP0_STPCNT(3U);
|
udev->regs.er_out[0]->DOEPLEN = DOEP0_TLEN(8U * 3U) | DOEP0_PCNT(1U) | DOEP0_STPCNT(3U);
|
||||||
|
|
||||||
@@ -638,8 +592,7 @@ void usb_ctlep_startout (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_rwkup_set (usb_core_driver *udev)
|
void usb_rwkup_set(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
if (udev->dev.pm.dev_remote_wakeup) {
|
if (udev->dev.pm.dev_remote_wakeup) {
|
||||||
/* enable remote wakeup signaling */
|
/* enable remote wakeup signaling */
|
||||||
udev->regs.dr->DCTL |= DCTL_RWKUP;
|
udev->regs.dr->DCTL |= DCTL_RWKUP;
|
||||||
@@ -652,8 +605,7 @@ void usb_rwkup_set (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_rwkup_reset (usb_core_driver *udev)
|
void usb_rwkup_reset(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
if (udev->dev.pm.dev_remote_wakeup) {
|
if (udev->dev.pm.dev_remote_wakeup) {
|
||||||
/* disable remote wakeup signaling */
|
/* disable remote wakeup signaling */
|
||||||
udev->regs.dr->DCTL &= ~DCTL_RWKUP;
|
udev->regs.dr->DCTL &= ~DCTL_RWKUP;
|
||||||
@@ -666,8 +618,7 @@ void usb_rwkup_reset (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_rwkup_active (usb_core_driver *udev)
|
void usb_rwkup_active(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
if (udev->dev.pm.dev_remote_wakeup) {
|
if (udev->dev.pm.dev_remote_wakeup) {
|
||||||
if (udev->regs.dr->DSTAT & DSTAT_SPST) {
|
if (udev->regs.dr->DSTAT & DSTAT_SPST) {
|
||||||
if (udev->bp.low_power) {
|
if (udev->bp.low_power) {
|
||||||
@@ -691,8 +642,7 @@ void usb_rwkup_active (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_clock_active (usb_core_driver *udev)
|
void usb_clock_active(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
if (udev->bp.low_power) {
|
if (udev->bp.low_power) {
|
||||||
if (udev->regs.dr->DSTAT & DSTAT_SPST) {
|
if (udev->regs.dr->DSTAT & DSTAT_SPST) {
|
||||||
/* un-gate USB Core clock */
|
/* un-gate USB Core clock */
|
||||||
@@ -707,8 +657,7 @@ void usb_clock_active (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_dev_suspend (usb_core_driver *udev)
|
void usb_dev_suspend(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
__IO uint32_t devstat = udev->regs.dr->DSTAT;
|
__IO uint32_t devstat = udev->regs.dr->DSTAT;
|
||||||
|
|
||||||
if ((udev->bp.low_power) && (devstat & DSTAT_SPST)) {
|
if ((udev->bp.low_power) && (devstat & DSTAT_SPST)) {
|
||||||
@@ -726,8 +675,7 @@ void usb_dev_suspend (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_dev_stop (usb_core_driver *udev)
|
void usb_dev_stop(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
udev->dev.cur_status = 1;
|
udev->dev.cur_status = 1;
|
||||||
|
|||||||
@@ -32,45 +32,29 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "drv_usb_hw.h"
|
|
||||||
#include "drv_usb_core.h"
|
|
||||||
#include "drv_usb_host.h"
|
#include "drv_usb_host.h"
|
||||||
|
#include "drv_usb_core.h"
|
||||||
|
#include "drv_usb_hw.h"
|
||||||
|
|
||||||
const uint32_t PIPE_DPID[] = {
|
const uint32_t PIPE_DPID[] = {PIPE_DPID_DATA0, PIPE_DPID_DATA1};
|
||||||
PIPE_DPID_DATA0,
|
|
||||||
PIPE_DPID_DATA1
|
|
||||||
};
|
|
||||||
|
|
||||||
//__STATIC_INLINE uint8_t usb_frame_even (usb_core_driver *pudev)
|
//__STATIC_INLINE uint8_t usb_frame_even (usb_core_driver *pudev)
|
||||||
uint32_t usb_frame_even (usb_core_driver *pudev)
|
uint32_t usb_frame_even(usb_core_driver *pudev) { return !(pudev->regs.hr->HFINFR & 0x01U); }
|
||||||
{
|
|
||||||
return !(pudev->regs.hr->HFINFR & 0x01U);
|
|
||||||
}
|
|
||||||
|
|
||||||
//__STATIC_INLINE void usb_phyclock_config (usb_core_driver *pudev, uint8_t clock)
|
//__STATIC_INLINE void usb_phyclock_config (usb_core_driver *pudev, uint8_t clock)
|
||||||
void usb_phyclock_config (usb_core_driver *pudev, uint8_t clock)
|
void usb_phyclock_config(usb_core_driver *pudev, uint8_t clock) {
|
||||||
{
|
|
||||||
pudev->regs.hr->HCTL &= ~HCTL_CLKSEL;
|
pudev->regs.hr->HCTL &= ~HCTL_CLKSEL;
|
||||||
pudev->regs.hr->HCTL |= clock;
|
pudev->regs.hr->HCTL |= clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
//__STATIC_INLINE uint32_t usb_port_read (usb_core_driver *pudev)
|
//__STATIC_INLINE uint32_t usb_port_read (usb_core_driver *pudev)
|
||||||
uint32_t usb_port_read (usb_core_driver *pudev)
|
uint32_t usb_port_read(usb_core_driver *pudev) { return *pudev->regs.HPCS & ~(HPCS_PE | HPCS_PCD | HPCS_PEDC); }
|
||||||
{
|
|
||||||
return *pudev->regs.HPCS & ~(HPCS_PE | HPCS_PCD | HPCS_PEDC);
|
|
||||||
}
|
|
||||||
|
|
||||||
//__STATIC_INLINE uint32_t usb_curspeed_get (usb_core_driver *pudev)
|
//__STATIC_INLINE uint32_t usb_curspeed_get (usb_core_driver *pudev)
|
||||||
|
|
||||||
uint32_t usb_curspeed_get (usb_core_driver *pudev)
|
uint32_t usb_curspeed_get(usb_core_driver *pudev) { return *pudev->regs.HPCS & HPCS_PS; }
|
||||||
{
|
|
||||||
return *pudev->regs.HPCS & HPCS_PS;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t usb_curframe_get (usb_core_driver *pudev)
|
uint32_t usb_curframe_get(usb_core_driver *pudev) { return (pudev->regs.hr->HFINFR & 0xFFFFU); }
|
||||||
{
|
|
||||||
return (pudev->regs.hr->HFINFR & 0xFFFFU);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief initializes USB core for host mode
|
\brief initializes USB core for host mode
|
||||||
@@ -78,8 +62,7 @@ uint32_t usb_curframe_get (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_host_init (usb_core_driver *pudev)
|
usb_status usb_host_init(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t i = 0, inten = 0U;
|
uint32_t i = 0, inten = 0U;
|
||||||
|
|
||||||
uint32_t nptxfifolen = 0U;
|
uint32_t nptxfifolen = 0U;
|
||||||
@@ -199,8 +182,7 @@ usb_status usb_host_init (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_portvbus_switch (usb_core_driver *pudev, uint8_t state)
|
void usb_portvbus_switch(usb_core_driver *pudev, uint8_t state) {
|
||||||
{
|
|
||||||
uint32_t port = 0U;
|
uint32_t port = 0U;
|
||||||
|
|
||||||
/* enable or disable the external charge pump */
|
/* enable or disable the external charge pump */
|
||||||
@@ -228,8 +210,7 @@ void usb_portvbus_switch (usb_core_driver *pudev, uint8_t state)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t usb_port_reset (usb_core_driver *pudev)
|
uint32_t usb_port_reset(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
__IO uint32_t port = usb_port_read(pudev);
|
__IO uint32_t port = usb_port_read(pudev);
|
||||||
|
|
||||||
*pudev->regs.HPCS = port | HPCS_PRST;
|
*pudev->regs.HPCS = port | HPCS_PRST;
|
||||||
@@ -250,8 +231,7 @@ uint32_t usb_port_reset (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_pipe_init (usb_core_driver *pudev, uint8_t pipe_num)
|
usb_status usb_pipe_init(usb_core_driver *pudev, uint8_t pipe_num) {
|
||||||
{
|
|
||||||
usb_status status = USB_OK;
|
usb_status status = USB_OK;
|
||||||
|
|
||||||
__IO uint32_t pp_ctl = 0U;
|
__IO uint32_t pp_ctl = 0U;
|
||||||
@@ -274,8 +254,7 @@ usb_status usb_pipe_init (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
switch (pp->ep.type) {
|
switch (pp->ep.type) {
|
||||||
case USB_EPTYPE_CTRL:
|
case USB_EPTYPE_CTRL:
|
||||||
case USB_EPTYPE_BULK:
|
case USB_EPTYPE_BULK:
|
||||||
pp_inten |= HCHINTEN_STALLIE | HCHINTEN_USBERIE \
|
pp_inten |= HCHINTEN_STALLIE | HCHINTEN_USBERIE | HCHINTEN_DTERIE | HCHINTEN_NAKIE;
|
||||||
| HCHINTEN_DTERIE | HCHINTEN_NAKIE;
|
|
||||||
|
|
||||||
if (!pp->ep.dir) {
|
if (!pp->ep.dir) {
|
||||||
pp_inten |= HCHINTEN_NYETIE;
|
pp_inten |= HCHINTEN_NYETIE;
|
||||||
@@ -287,8 +266,7 @@ usb_status usb_pipe_init (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_EPTYPE_INTR:
|
case USB_EPTYPE_INTR:
|
||||||
pp_inten |= HCHINTEN_STALLIE | HCHINTEN_USBERIE | HCHINTEN_DTERIE \
|
pp_inten |= HCHINTEN_STALLIE | HCHINTEN_USBERIE | HCHINTEN_DTERIE | HCHINTEN_NAKIE | HCHINTEN_REQOVRIE;
|
||||||
| HCHINTEN_NAKIE | HCHINTEN_REQOVRIE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_EPTYPE_ISOC:
|
case USB_EPTYPE_ISOC:
|
||||||
@@ -333,8 +311,7 @@ usb_status usb_pipe_init (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_pipe_xfer (usb_core_driver *pudev, uint8_t pipe_num)
|
usb_status usb_pipe_xfer(usb_core_driver *pudev, uint8_t pipe_num) {
|
||||||
{
|
|
||||||
usb_status status = USB_OK;
|
usb_status status = USB_OK;
|
||||||
|
|
||||||
uint16_t dword_len = 0U;
|
uint16_t dword_len = 0U;
|
||||||
@@ -429,8 +406,7 @@ usb_status usb_pipe_xfer (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_pipe_halt (usb_core_driver *pudev, uint8_t pipe_num)
|
usb_status usb_pipe_halt(usb_core_driver *pudev, uint8_t pipe_num) {
|
||||||
{
|
|
||||||
__IO uint32_t pp_ctl = pudev->regs.pr[pipe_num]->HCHCTL;
|
__IO uint32_t pp_ctl = pudev->regs.pr[pipe_num]->HCHCTL;
|
||||||
|
|
||||||
uint8_t ep_type = (pp_ctl & HCHCTL_EPTYPE) >> 18U;
|
uint8_t ep_type = (pp_ctl & HCHCTL_EPTYPE) >> 18U;
|
||||||
@@ -468,8 +444,7 @@ usb_status usb_pipe_halt (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_status usb_pipe_ping (usb_core_driver *pudev, uint8_t pipe_num)
|
usb_status usb_pipe_ping(usb_core_driver *pudev, uint8_t pipe_num) {
|
||||||
{
|
|
||||||
uint32_t pp_ctl = 0U;
|
uint32_t pp_ctl = 0U;
|
||||||
|
|
||||||
pudev->regs.pr[pipe_num]->HCHLEN = HCHLEN_PING | (HCHLEN_PCNT & (1U << 19U));
|
pudev->regs.pr[pipe_num]->HCHLEN = HCHLEN_PING | (HCHLEN_PCNT & (1U << 19U));
|
||||||
@@ -490,8 +465,7 @@ usb_status usb_pipe_ping (usb_core_driver *pudev, uint8_t pipe_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_host_stop (usb_core_driver *pudev)
|
void usb_host_stop(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
__IO uint32_t pp_ctl = 0U;
|
__IO uint32_t pp_ctl = 0U;
|
||||||
|
|
||||||
|
|||||||
@@ -45,12 +45,8 @@ static uint32_t usbd_int_suspend (usb_core_driver *udev);
|
|||||||
|
|
||||||
static uint32_t usbd_emptytxfifo_write(usb_core_driver *udev, uint32_t ep_num);
|
static uint32_t usbd_emptytxfifo_write(usb_core_driver *udev, uint32_t ep_num);
|
||||||
|
|
||||||
static const uint8_t USB_SPEED[4] = {
|
static const uint8_t USB_SPEED[4]
|
||||||
[DSTAT_EM_HS_PHY_30MHZ_60MHZ] = USB_SPEED_HIGH,
|
= {[DSTAT_EM_HS_PHY_30MHZ_60MHZ] = USB_SPEED_HIGH, [DSTAT_EM_FS_PHY_30MHZ_60MHZ] = USB_SPEED_FULL, [DSTAT_EM_FS_PHY_48MHZ] = USB_SPEED_FULL, [DSTAT_EM_LS_PHY_6MHZ] = USB_SPEED_LOW};
|
||||||
[DSTAT_EM_FS_PHY_30MHZ_60MHZ] = USB_SPEED_FULL,
|
|
||||||
[DSTAT_EM_FS_PHY_48MHZ] = USB_SPEED_FULL,
|
|
||||||
[DSTAT_EM_LS_PHY_6MHZ] = USB_SPEED_LOW
|
|
||||||
};
|
|
||||||
|
|
||||||
__IO uint8_t setupc_flag = 0U;
|
__IO uint8_t setupc_flag = 0U;
|
||||||
|
|
||||||
@@ -62,8 +58,7 @@ __IO uint8_t setupc_flag = 0U;
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev)
|
uint32_t USBD_OTG_EP1OUT_ISR_Handler(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t oepintr = 0U;
|
uint32_t oepintr = 0U;
|
||||||
uint32_t oeplen = 0U;
|
uint32_t oeplen = 0U;
|
||||||
|
|
||||||
@@ -71,18 +66,15 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev)
|
|||||||
oepintr &= udev->regs.dr->DOEP1INTEN;
|
oepintr &= udev->regs.dr->DOEP1INTEN;
|
||||||
|
|
||||||
/* Transfer complete */
|
/* Transfer complete */
|
||||||
if (oepintr & DOEPINTF_TF)
|
if (oepintr & DOEPINTF_TF) {
|
||||||
{
|
|
||||||
/* Clear the bit in DOEPINTn for this interrupt */
|
/* Clear the bit in DOEPINTn for this interrupt */
|
||||||
udev->regs.er_out[1]->DOEPINTF = DOEPINTF_TF;
|
udev->regs.er_out[1]->DOEPINTF = DOEPINTF_TF;
|
||||||
|
|
||||||
if (USB_USE_DMA == udev->bp.transfer_mode)
|
if (USB_USE_DMA == udev->bp.transfer_mode) {
|
||||||
{
|
|
||||||
oeplen = udev->regs.er_out[1]->DOEPLEN;
|
oeplen = udev->regs.er_out[1]->DOEPLEN;
|
||||||
|
|
||||||
/* ToDo : handle more than one single MPS size packet */
|
/* ToDo : handle more than one single MPS size packet */
|
||||||
udev->dev.transc_out[1].xfer_count = udev->dev.transc_out[1].usb_transc - \
|
udev->dev.transc_out[1].xfer_count = udev->dev.transc_out[1].usb_transc - oeplen & DEPLEN_TLEN;
|
||||||
oeplen & DEPLEN_TLEN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RX COMPLETE */
|
/* RX COMPLETE */
|
||||||
@@ -98,8 +90,7 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev)
|
uint32_t USBD_OTG_EP1IN_ISR_Handler(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t inten, intr, emptyen;
|
uint32_t inten, intr, emptyen;
|
||||||
|
|
||||||
inten = udev->regs.dr->DIEP1INTEN;
|
inten = udev->regs.dr->DIEP1INTEN;
|
||||||
@@ -109,8 +100,7 @@ uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev)
|
|||||||
|
|
||||||
intr = udev->regs.er_in[1]->DIEPINTF & inten;
|
intr = udev->regs.er_in[1]->DIEPINTF & inten;
|
||||||
|
|
||||||
if (intr & DIEPINTF_TF)
|
if (intr & DIEPINTF_TF) {
|
||||||
{
|
|
||||||
udev->regs.dr->DIEPFEINTEN &= ~(0x1 << 1);
|
udev->regs.dr->DIEPFEINTEN &= ~(0x1 << 1);
|
||||||
|
|
||||||
udev->regs.er_in[1]->DIEPINTF = DIEPINTF_TF;
|
udev->regs.er_in[1]->DIEPINTF = DIEPINTF_TF;
|
||||||
@@ -119,8 +109,7 @@ uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev)
|
|||||||
USBD_DCD_INT_fops->DataInStage(udev, 1);
|
USBD_DCD_INT_fops->DataInStage(udev, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intr & DIEPINTF_TXFE)
|
if (intr & DIEPINTF_TXFE) {
|
||||||
{
|
|
||||||
DCD_WriteEmptyTxFifo(udev, 1);
|
DCD_WriteEmptyTxFifo(udev, 1);
|
||||||
|
|
||||||
udev->regs.er_in[1]->DIEPINTF = DIEPINTF_TXFE;
|
udev->regs.er_in[1]->DIEPINTF = DIEPINTF_TXFE;
|
||||||
@@ -131,15 +120,13 @@ uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief USB device-mode interrupts global service routine handler
|
\brief USB device-mode interrupts global service routine handler
|
||||||
\param[in] udev: pointer to usb device instance
|
\param[in] udev: pointer to usb device instance
|
||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_isr (usb_core_driver *udev)
|
void usbd_isr(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
if (HOST_MODE != (udev->regs.gr->GINTF & GINTF_COPM)) {
|
if (HOST_MODE != (udev->regs.gr->GINTF & GINTF_COPM)) {
|
||||||
uint32_t intr = udev->regs.gr->GINTF & udev->regs.gr->GINTEN;
|
uint32_t intr = udev->regs.gr->GINTF & udev->regs.gr->GINTEN;
|
||||||
|
|
||||||
@@ -243,9 +230,7 @@ void usbd_isr (usb_core_driver *udev)
|
|||||||
|
|
||||||
/* OTG mode interrupt */
|
/* OTG mode interrupt */
|
||||||
if (intr & GINTF_OTGIF) {
|
if (intr & GINTF_OTGIF) {
|
||||||
if(udev->regs.gr->GOTGINTF & GOTGINTF_SESEND) {
|
if (udev->regs.gr->GOTGINTF & GOTGINTF_SESEND) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear OTG interrupt */
|
/* Clear OTG interrupt */
|
||||||
udev->regs.gr->GINTF = GINTF_OTGIF;
|
udev->regs.gr->GINTF = GINTF_OTGIF;
|
||||||
@@ -260,8 +245,7 @@ void usbd_isr (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_epout (usb_core_driver *udev)
|
static uint32_t usbd_int_epout(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t epintnum = 0U;
|
uint32_t epintnum = 0U;
|
||||||
uint32_t ep_num = 0U;
|
uint32_t ep_num = 0U;
|
||||||
|
|
||||||
@@ -277,8 +261,7 @@ static uint32_t usbd_int_epout (usb_core_driver *udev)
|
|||||||
if (USB_USE_DMA == udev->bp.transfer_mode) {
|
if (USB_USE_DMA == udev->bp.transfer_mode) {
|
||||||
__IO uint32_t eplen = udev->regs.er_out[ep_num]->DOEPLEN;
|
__IO uint32_t eplen = udev->regs.er_out[ep_num]->DOEPLEN;
|
||||||
|
|
||||||
udev->dev.transc_out[ep_num].xfer_count = udev->dev.transc_out[ep_num].max_len - \
|
udev->dev.transc_out[ep_num].xfer_count = udev->dev.transc_out[ep_num].max_len - eplen & DEPLEN_TLEN;
|
||||||
eplen & DEPLEN_TLEN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inform upper layer: data ready */
|
/* inform upper layer: data ready */
|
||||||
@@ -314,8 +297,7 @@ static uint32_t usbd_int_epout (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_epin (usb_core_driver *udev)
|
static uint32_t usbd_int_epin(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t epintnum = 0U;
|
uint32_t epintnum = 0U;
|
||||||
uint32_t ep_num = 0U;
|
uint32_t ep_num = 0U;
|
||||||
|
|
||||||
@@ -353,8 +335,7 @@ static uint32_t usbd_int_epin (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_rxfifo (usb_core_driver *udev)
|
static uint32_t usbd_int_rxfifo(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
usb_transc *transc = NULL;
|
usb_transc *transc = NULL;
|
||||||
|
|
||||||
uint8_t data_PID = 0;
|
uint8_t data_PID = 0;
|
||||||
@@ -421,8 +402,7 @@ static uint32_t usbd_int_rxfifo (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_reset (usb_core_driver *udev)
|
static uint32_t usbd_int_reset(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
/* clear the remote wakeup signaling */
|
/* clear the remote wakeup signaling */
|
||||||
@@ -458,21 +438,14 @@ static uint32_t usbd_int_reset (usb_core_driver *udev)
|
|||||||
/* clear USB reset interrupt */
|
/* clear USB reset interrupt */
|
||||||
udev->regs.gr->GINTF = GINTF_RST;
|
udev->regs.gr->GINTF = GINTF_RST;
|
||||||
|
|
||||||
udev->dev.transc_out[0] = (usb_transc) {
|
udev->dev.transc_out[0] = (usb_transc){.ep_type = USB_EPTYPE_CTRL, .max_len = USB_FS_EP0_MAX_LEN};
|
||||||
.ep_type = USB_EPTYPE_CTRL,
|
|
||||||
.max_len = USB_FS_EP0_MAX_LEN
|
|
||||||
};
|
|
||||||
|
|
||||||
usb_transc_active(udev, &udev->dev.transc_out[0]);
|
usb_transc_active(udev, &udev->dev.transc_out[0]);
|
||||||
|
|
||||||
udev->dev.transc_in[0] = (usb_transc) {
|
udev->dev.transc_in[0] = (usb_transc){.ep_addr = {.dir = 1},
|
||||||
.ep_addr = {
|
|
||||||
.dir = 1
|
|
||||||
},
|
|
||||||
|
|
||||||
.ep_type = USB_EPTYPE_CTRL,
|
.ep_type = USB_EPTYPE_CTRL,
|
||||||
.max_len = USB_FS_EP0_MAX_LEN
|
.max_len = USB_FS_EP0_MAX_LEN};
|
||||||
};
|
|
||||||
|
|
||||||
usb_transc_active(udev, &udev->dev.transc_in[0]);
|
usb_transc_active(udev, &udev->dev.transc_in[0]);
|
||||||
|
|
||||||
@@ -488,8 +461,7 @@ static uint32_t usbd_int_reset (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_enumfinish (usb_core_driver *udev)
|
static uint32_t usbd_int_enumfinish(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
uint8_t enum_speed = (uint8_t)((udev->regs.dr->DSTAT & DSTAT_ES) >> 1U);
|
uint8_t enum_speed = (uint8_t)((udev->regs.dr->DSTAT & DSTAT_ES) >> 1U);
|
||||||
|
|
||||||
udev->regs.dr->DCTL &= ~DCTL_CGINAK;
|
udev->regs.dr->DCTL &= ~DCTL_CGINAK;
|
||||||
@@ -520,8 +492,7 @@ static uint32_t usbd_int_enumfinish (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_int_suspend (usb_core_driver *udev)
|
static uint32_t usbd_int_suspend(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
__IO uint8_t low_power = udev->bp.low_power;
|
__IO uint8_t low_power = udev->bp.low_power;
|
||||||
__IO uint8_t suspend = (uint8_t)(udev->regs.dr->DSTAT & DSTAT_SPST);
|
__IO uint8_t suspend = (uint8_t)(udev->regs.dr->DSTAT & DSTAT_SPST);
|
||||||
__IO uint8_t is_configured = (udev->dev.cur_status == USBD_CONFIGURED) ? 1U : 0U;
|
__IO uint8_t is_configured = (udev->dev.cur_status == USBD_CONFIGURED) ? 1U : 0U;
|
||||||
@@ -550,8 +521,7 @@ static uint32_t usbd_int_suspend (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval status
|
\retval status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbd_emptytxfifo_write (usb_core_driver *udev, uint32_t ep_num)
|
static uint32_t usbd_emptytxfifo_write(usb_core_driver *udev, uint32_t ep_num) {
|
||||||
{
|
|
||||||
usb_transc *transc = NULL;
|
usb_transc *transc = NULL;
|
||||||
|
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
@@ -568,8 +538,7 @@ static uint32_t usbd_emptytxfifo_write (usb_core_driver *udev, uint32_t ep_num)
|
|||||||
|
|
||||||
word_count = (len + 3) / 4;
|
word_count = (len + 3) / 4;
|
||||||
|
|
||||||
while (((udev->regs.er_in[ep_num]->DIEPTFSTAT & DIEPTFSTAT_IEPTFS) > word_count) && \
|
while (((udev->regs.er_in[ep_num]->DIEPTFSTAT & DIEPTFSTAT_IEPTFS) > word_count) && (transc->xfer_count < transc->xfer_len)) {
|
||||||
(transc->xfer_count < transc->xfer_len)) {
|
|
||||||
len = transc->xfer_len - transc->xfer_count;
|
len = transc->xfer_len - transc->xfer_count;
|
||||||
|
|
||||||
if (len > transc->max_len) {
|
if (len > transc->max_len) {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "drv_usbh_int.h"
|
||||||
#include "drv_usb_core.h"
|
#include "drv_usb_core.h"
|
||||||
#include "drv_usb_host.h"
|
#include "drv_usb_host.h"
|
||||||
#include "drv_usbh_int.h"
|
|
||||||
|
|
||||||
#if defined(__GNUC__) /*!< GNU compiler */
|
#if defined(__GNUC__) /*!< GNU compiler */
|
||||||
#pragma GCC optimize("O0")
|
#pragma GCC optimize("O0")
|
||||||
@@ -47,11 +47,7 @@ static uint32_t usbh_int_pipe_out (usb_core_driver *pudev, uint32_t pp_num
|
|||||||
static uint32_t usbh_int_rxfifonoempty(usb_core_driver *pudev);
|
static uint32_t usbh_int_rxfifonoempty(usb_core_driver *pudev);
|
||||||
static uint32_t usbh_int_txfifoempty(usb_core_driver *pudev, usb_pipe_mode pp_mode);
|
static uint32_t usbh_int_txfifoempty(usb_core_driver *pudev, usb_pipe_mode pp_mode);
|
||||||
|
|
||||||
static inline void usb_pp_halt (usb_core_driver *pudev,
|
static inline void usb_pp_halt(usb_core_driver *pudev, uint8_t pp_num, uint32_t pp_int, usb_pipe_staus pp_status) {
|
||||||
uint8_t pp_num,
|
|
||||||
uint32_t pp_int,
|
|
||||||
usb_pipe_staus pp_status)
|
|
||||||
{
|
|
||||||
pudev->regs.pr[pp_num]->HCHINTEN |= HCHINTEN_CHIE;
|
pudev->regs.pr[pp_num]->HCHINTEN |= HCHINTEN_CHIE;
|
||||||
|
|
||||||
usb_pipe_halt(pudev, pp_num);
|
usb_pipe_halt(pudev, pp_num);
|
||||||
@@ -67,8 +63,7 @@ static inline void usb_pp_halt (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t usbh_isr (usb_core_driver *pudev)
|
uint32_t usbh_isr(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t Retval = 0U;
|
uint32_t Retval = 0U;
|
||||||
|
|
||||||
__IO uint32_t intr = 0U;
|
__IO uint32_t intr = 0U;
|
||||||
@@ -132,8 +127,7 @@ uint32_t usbh_isr (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbh_int_pipe (usb_core_driver *pudev)
|
static uint32_t usbh_int_pipe(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t pp_num = 0U;
|
uint32_t pp_num = 0U;
|
||||||
uint32_t retval = 0U;
|
uint32_t retval = 0U;
|
||||||
|
|
||||||
@@ -156,8 +150,7 @@ static uint32_t usbh_int_pipe (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbh_int_txfifoempty (usb_core_driver *pudev, usb_pipe_mode pp_mode)
|
static uint32_t usbh_int_txfifoempty(usb_core_driver *pudev, usb_pipe_mode pp_mode) {
|
||||||
{
|
|
||||||
uint8_t pp_num = 0U;
|
uint8_t pp_num = 0U;
|
||||||
uint16_t word_count = 0U, len = 0U;
|
uint16_t word_count = 0U, len = 0U;
|
||||||
__IO uint32_t *txfiforeg = 0U, txfifostate = 0U;
|
__IO uint32_t *txfiforeg = 0U, txfifostate = 0U;
|
||||||
@@ -209,8 +202,7 @@ static uint32_t usbh_int_txfifoempty (usb_core_driver *pudev, usb_pipe_mode pp_m
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbh_int_port (usb_core_driver *pudev)
|
static uint32_t usbh_int_port(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t retval = 0U;
|
uint32_t retval = 0U;
|
||||||
|
|
||||||
__IO uint32_t port_state = *pudev->regs.HPCS;
|
__IO uint32_t port_state = *pudev->regs.HPCS;
|
||||||
@@ -276,8 +268,7 @@ static uint32_t usbh_int_port (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t usbh_int_pipe_out (usb_core_driver *pudev, uint32_t pp_num)
|
uint32_t usbh_int_pipe_out(usb_core_driver *pudev, uint32_t pp_num) {
|
||||||
{
|
|
||||||
usb_pr *pp_reg = pudev->regs.pr[pp_num];
|
usb_pr *pp_reg = pudev->regs.pr[pp_num];
|
||||||
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
@@ -357,8 +348,7 @@ uint32_t usbh_int_pipe_out (usb_core_driver *pudev, uint32_t pp_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint32_t usbh_int_pipe_in (usb_core_driver *pudev, uint32_t pp_num)
|
uint32_t usbh_int_pipe_in(usb_core_driver *pudev, uint32_t pp_num) {
|
||||||
{
|
|
||||||
usb_pr *pp_reg = pudev->regs.pr[pp_num];
|
usb_pr *pp_reg = pudev->regs.pr[pp_num];
|
||||||
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
@@ -471,8 +461,7 @@ uint32_t usbh_int_pipe_in (usb_core_driver *pudev, uint32_t pp_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbh_int_rxfifonoempty (usb_core_driver *pudev)
|
static uint32_t usbh_int_rxfifonoempty(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint32_t count = 0U;
|
uint32_t count = 0U;
|
||||||
|
|
||||||
__IO uint8_t pp_num = 0U;
|
__IO uint8_t pp_num = 0U;
|
||||||
|
|||||||
@@ -31,13 +31,12 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
|
|||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "gd32vf103_libopt.h"
|
|
||||||
#include "drv_usb_hw.h"
|
#include "drv_usb_hw.h"
|
||||||
|
#include "gd32vf103_libopt.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#define TIM_MSEC_DELAY 0x01
|
#define TIM_MSEC_DELAY 0x01
|
||||||
#define TIM_USEC_DELAY 0x02
|
#define TIM_USEC_DELAY 0x02
|
||||||
|
|
||||||
@@ -58,8 +57,7 @@ static void hwp_delay (uint32_t ntime, uint8_t unit);
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_rcu_config (void)
|
void usb_rcu_config(void) {
|
||||||
{
|
|
||||||
uint32_t system_clock = rcu_clock_freq_get(CK_SYS);
|
uint32_t system_clock = rcu_clock_freq_get(CK_SYS);
|
||||||
|
|
||||||
if (system_clock == 48000000) {
|
if (system_clock == 48000000) {
|
||||||
@@ -85,8 +83,7 @@ void usb_rcu_config (void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_intr_config (void)
|
void usb_intr_config(void) {
|
||||||
{
|
|
||||||
ECLIC_SetLevelIRQ(USBFS_IRQn, 1);
|
ECLIC_SetLevelIRQ(USBFS_IRQn, 1);
|
||||||
ECLIC_SetPriorityIRQ(USBFS_IRQn, 0);
|
ECLIC_SetPriorityIRQ(USBFS_IRQn, 0);
|
||||||
ECLIC_EnableIRQ(USBFS_IRQn);
|
ECLIC_EnableIRQ(USBFS_IRQn);
|
||||||
@@ -113,15 +110,11 @@ void usb_intr_config (void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_vbus_drive (uint8_t state)
|
void usb_vbus_drive(uint8_t state) {
|
||||||
{
|
if (0 == state) {
|
||||||
if (0 == state)
|
|
||||||
{
|
|
||||||
/* DISABLE is needed on output of the Power Switch */
|
/* DISABLE is needed on output of the Power Switch */
|
||||||
gpio_bit_reset(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
|
gpio_bit_reset(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*ENABLE the Power Switch by driving the Enable LOW */
|
/*ENABLE the Power Switch by driving the Enable LOW */
|
||||||
gpio_bit_set(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
|
gpio_bit_set(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
|
||||||
}
|
}
|
||||||
@@ -133,8 +126,7 @@ void usb_vbus_drive (uint8_t state)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_vbus_config (void)
|
void usb_vbus_config(void) {
|
||||||
{
|
|
||||||
rcu_periph_clock_enable(HOST_POWERSW_PORT_RCC);
|
rcu_periph_clock_enable(HOST_POWERSW_PORT_RCC);
|
||||||
|
|
||||||
gpio_init(HOST_POWERSW_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, HOST_POWERSW_VBUS);
|
gpio_init(HOST_POWERSW_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, HOST_POWERSW_VBUS);
|
||||||
@@ -155,8 +147,7 @@ void usb_vbus_config (void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_timer_init (void)
|
void usb_timer_init(void) {
|
||||||
{
|
|
||||||
rcu_periph_clock_enable(RCU_TIMER2);
|
rcu_periph_clock_enable(RCU_TIMER2);
|
||||||
|
|
||||||
// eclic_irq_enable(TIMER2_IRQn, 2, 0);
|
// eclic_irq_enable(TIMER2_IRQn, 2, 0);
|
||||||
@@ -171,10 +162,7 @@ void usb_timer_init (void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_udelay (const uint32_t usec)
|
void usb_udelay(const uint32_t usec) { hwp_delay(usec, TIM_USEC_DELAY); }
|
||||||
{
|
|
||||||
hwp_delay(usec, TIM_USEC_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief delay in milli seconds
|
\brief delay in milli seconds
|
||||||
@@ -182,10 +170,7 @@ void usb_udelay (const uint32_t usec)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_mdelay (const uint32_t msec)
|
void usb_mdelay(const uint32_t msec) { hwp_delay(msec, TIM_MSEC_DELAY); }
|
||||||
{
|
|
||||||
hwp_delay(msec, TIM_MSEC_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief timer base IRQ
|
\brief timer base IRQ
|
||||||
@@ -193,8 +178,7 @@ void usb_mdelay (const uint32_t msec)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usb_timer_irq (void)
|
void usb_timer_irq(void) {
|
||||||
{
|
|
||||||
if (timer_interrupt_flag_get(TIMER2, TIMER_INT_UP) != RESET) {
|
if (timer_interrupt_flag_get(TIMER2, TIMER_INT_UP) != RESET) {
|
||||||
timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP);
|
timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP);
|
||||||
|
|
||||||
@@ -213,12 +197,12 @@ void usb_timer_irq (void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void hwp_delay(uint32_t ntime, uint8_t unit)
|
static void hwp_delay(uint32_t ntime, uint8_t unit) {
|
||||||
{
|
|
||||||
delay_time = ntime;
|
delay_time = ntime;
|
||||||
hwp_time_set(unit);
|
hwp_time_set(unit);
|
||||||
|
|
||||||
while(delay_time != 0);
|
while (delay_time != 0)
|
||||||
|
;
|
||||||
|
|
||||||
timer_disable(TIMER2);
|
timer_disable(TIMER2);
|
||||||
}
|
}
|
||||||
@@ -229,8 +213,7 @@ static void hwp_delay(uint32_t ntime, uint8_t unit)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void hwp_time_set(uint8_t unit)
|
static void hwp_time_set(uint8_t unit) {
|
||||||
{
|
|
||||||
timer_parameter_struct timer_basestructure;
|
timer_parameter_struct timer_basestructure;
|
||||||
|
|
||||||
timer_disable(TIMER2);
|
timer_disable(TIMER2);
|
||||||
@@ -262,4 +245,3 @@ static void hwp_time_set(uint8_t unit)
|
|||||||
/* timer2 enable counter */
|
/* timer2 enable counter */
|
||||||
timer_enable(TIMER2);
|
timer_enable(TIMER2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,7 @@ OF SUCH DAMAGE.
|
|||||||
#include "drv_usb_hw.h"
|
#include "drv_usb_hw.h"
|
||||||
|
|
||||||
/* endpoint type */
|
/* endpoint type */
|
||||||
const uint32_t ep_type[] = {
|
const uint32_t ep_type[] = {[USB_EP_ATTR_CTL] = USB_EPTYPE_CTRL, [USB_EP_ATTR_BULK] = USB_EPTYPE_BULK, [USB_EP_ATTR_INT] = USB_EPTYPE_INTR, [USB_EP_ATTR_ISO] = USB_EPTYPE_ISOC};
|
||||||
[USB_EP_ATTR_CTL] = USB_EPTYPE_CTRL,
|
|
||||||
[USB_EP_ATTR_BULK] = USB_EPTYPE_BULK,
|
|
||||||
[USB_EP_ATTR_INT] = USB_EPTYPE_INTR,
|
|
||||||
[USB_EP_ATTR_ISO] = USB_EPTYPE_ISOC
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief initailizes the USB device-mode stack and load the class driver
|
\brief initailizes the USB device-mode stack and load the class driver
|
||||||
@@ -51,8 +46,7 @@ const uint32_t ep_type[] = {
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_init (usb_core_driver *udev, usb_core_enum core, usb_class_core *class_core)
|
void usbd_init(usb_core_driver *udev, usb_core_enum core, usb_class_core *class_core) {
|
||||||
{
|
|
||||||
/* device descriptor, class and user callbacks */
|
/* device descriptor, class and user callbacks */
|
||||||
udev->dev.class_core = class_core;
|
udev->dev.class_core = class_core;
|
||||||
|
|
||||||
@@ -81,8 +75,7 @@ void usbd_init (usb_core_driver *udev, usb_core_enum core, usb_class_core *class
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_setup (usb_core_driver *udev, const usb_desc_ep *ep_desc)
|
uint32_t usbd_ep_setup(usb_core_driver *udev, const usb_desc_ep *ep_desc) {
|
||||||
{
|
|
||||||
usb_transc *transc;
|
usb_transc *transc;
|
||||||
|
|
||||||
uint8_t ep_addr = ep_desc->bEndpointAddress;
|
uint8_t ep_addr = ep_desc->bEndpointAddress;
|
||||||
@@ -119,8 +112,7 @@ uint32_t usbd_ep_setup (usb_core_driver *udev, const usb_desc_ep *ep_desc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_clear (usb_core_driver *udev, uint8_t ep_addr)
|
uint32_t usbd_ep_clear(usb_core_driver *udev, uint8_t ep_addr) {
|
||||||
{
|
|
||||||
usb_transc *transc;
|
usb_transc *transc;
|
||||||
|
|
||||||
if (EP_DIR(ep_addr)) {
|
if (EP_DIR(ep_addr)) {
|
||||||
@@ -135,7 +127,6 @@ uint32_t usbd_ep_clear (usb_core_driver *udev, uint8_t ep_addr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief endpoint prepare to receive data
|
\brief endpoint prepare to receive data
|
||||||
\param[in] udev: pointer to usb core instance
|
\param[in] udev: pointer to usb core instance
|
||||||
@@ -148,8 +139,7 @@ uint32_t usbd_ep_clear (usb_core_driver *udev, uint8_t ep_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_recev (usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, uint16_t len)
|
uint32_t usbd_ep_recev(usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, uint16_t len) {
|
||||||
{
|
|
||||||
usb_transc *transc = &udev->dev.transc_out[EP_ID(ep_addr)];
|
usb_transc *transc = &udev->dev.transc_out[EP_ID(ep_addr)];
|
||||||
|
|
||||||
/* setup the transfer */
|
/* setup the transfer */
|
||||||
@@ -179,8 +169,7 @@ uint32_t usbd_ep_recev (usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_send (usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, uint16_t len)
|
uint32_t usbd_ep_send(usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, uint16_t len) {
|
||||||
{
|
|
||||||
usb_transc *transc = &udev->dev.transc_in[EP_ID(ep_addr)];
|
usb_transc *transc = &udev->dev.transc_in[EP_ID(ep_addr)];
|
||||||
|
|
||||||
/* setup the transfer */
|
/* setup the transfer */
|
||||||
@@ -208,8 +197,7 @@ uint32_t usbd_ep_send (usb_core_driver *udev, uint8_t ep_addr, uint8_t *pbuf, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_stall (usb_core_driver *udev, uint8_t ep_addr)
|
uint32_t usbd_ep_stall(usb_core_driver *udev, uint8_t ep_addr) {
|
||||||
{
|
|
||||||
usb_transc *transc = NULL;
|
usb_transc *transc = NULL;
|
||||||
|
|
||||||
if (EP_DIR(ep_addr)) {
|
if (EP_DIR(ep_addr)) {
|
||||||
@@ -235,8 +223,7 @@ uint32_t usbd_ep_stall (usb_core_driver *udev, uint8_t ep_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_ep_stall_clear (usb_core_driver *udev, uint8_t ep_addr)
|
uint32_t usbd_ep_stall_clear(usb_core_driver *udev, uint8_t ep_addr) {
|
||||||
{
|
|
||||||
usb_transc *transc = NULL;
|
usb_transc *transc = NULL;
|
||||||
|
|
||||||
if (EP_DIR(ep_addr)) {
|
if (EP_DIR(ep_addr)) {
|
||||||
@@ -262,8 +249,7 @@ uint32_t usbd_ep_stall_clear (usb_core_driver *udev, uint8_t ep_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
uint32_t usbd_fifo_flush (usb_core_driver *udev, uint8_t ep_addr)
|
uint32_t usbd_fifo_flush(usb_core_driver *udev, uint8_t ep_addr) {
|
||||||
{
|
|
||||||
if (EP_DIR(ep_addr)) {
|
if (EP_DIR(ep_addr)) {
|
||||||
usb_txfifo_flush(&udev->regs, EP_ID(ep_addr));
|
usb_txfifo_flush(&udev->regs, EP_ID(ep_addr));
|
||||||
} else {
|
} else {
|
||||||
@@ -280,10 +266,7 @@ uint32_t usbd_fifo_flush (usb_core_driver *udev, uint8_t ep_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_addr_set (usb_core_driver *udev, uint8_t addr)
|
void usbd_addr_set(usb_core_driver *udev, uint8_t addr) { usb_devaddr_set(udev, addr); }
|
||||||
{
|
|
||||||
usb_devaddr_set(udev, addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the received data length
|
\brief get the received data length
|
||||||
@@ -292,10 +275,7 @@ void usbd_addr_set (usb_core_driver *udev, uint8_t addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
uint16_t usbd_rxcount_get (usb_core_driver *udev, uint8_t ep_num)
|
uint16_t usbd_rxcount_get(usb_core_driver *udev, uint8_t ep_num) { return udev->dev.transc_out[ep_num].xfer_count; }
|
||||||
{
|
|
||||||
return udev->dev.transc_out[ep_num].xfer_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief device connect
|
\brief device connect
|
||||||
@@ -303,8 +283,7 @@ uint16_t usbd_rxcount_get (usb_core_driver *udev, uint8_t ep_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_connect (usb_core_driver *udev)
|
void usbd_connect(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
#ifndef USE_OTG_MODE
|
#ifndef USE_OTG_MODE
|
||||||
/* connect device */
|
/* connect device */
|
||||||
usb_dev_connect(udev);
|
usb_dev_connect(udev);
|
||||||
@@ -319,8 +298,7 @@ void usbd_connect (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_disconnect (usb_core_driver *udev)
|
void usbd_disconnect(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
#ifndef USE_OTG_MODE
|
#ifndef USE_OTG_MODE
|
||||||
/* disconnect device for 3ms */
|
/* disconnect device for 3ms */
|
||||||
usb_dev_disconnect(udev);
|
usb_dev_disconnect(udev);
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ static uint8_t* _usb_config_desc_get (usb_core_driver *udev, uint8_t index, uin
|
|||||||
static uint8_t *_usb_str_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len);
|
static uint8_t *_usb_str_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len);
|
||||||
static uint8_t *_usb_bos_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len);
|
static uint8_t *_usb_bos_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len);
|
||||||
|
|
||||||
static usb_reqsta (*_std_dev_req[])(usb_core_driver *udev, usb_req *req) =
|
static usb_reqsta (*_std_dev_req[])(usb_core_driver *udev, usb_req *req) = {
|
||||||
{
|
|
||||||
[USB_GET_STATUS] = _usb_std_getstatus,
|
[USB_GET_STATUS] = _usb_std_getstatus,
|
||||||
[USB_CLEAR_FEATURE] = _usb_std_clearfeature,
|
[USB_CLEAR_FEATURE] = _usb_std_clearfeature,
|
||||||
[USB_RESERVED2] = _usb_std_reserved,
|
[USB_RESERVED2] = _usb_std_reserved,
|
||||||
@@ -71,11 +70,8 @@ static usb_reqsta (*_std_dev_req[])(usb_core_driver *udev, usb_req *req) =
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* get standard descriptor handler */
|
/* get standard descriptor handler */
|
||||||
static uint8_t* (*std_desc_get[])(usb_core_driver *udev, uint8_t index, uint16_t *len) = {
|
static uint8_t *(*std_desc_get[])(usb_core_driver *udev, uint8_t index, uint16_t *len)
|
||||||
[USB_DESCTYPE_DEV - 1] = _usb_dev_desc_get,
|
= {[USB_DESCTYPE_DEV - 1] = _usb_dev_desc_get, [USB_DESCTYPE_CONFIG - 1] = _usb_config_desc_get, [USB_DESCTYPE_STR - 1] = _usb_str_desc_get};
|
||||||
[USB_DESCTYPE_CONFIG - 1] = _usb_config_desc_get,
|
|
||||||
[USB_DESCTYPE_STR - 1] = _usb_str_desc_get
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief handle USB standard device request
|
\brief handle USB standard device request
|
||||||
@@ -84,10 +80,7 @@ static uint8_t* (*std_desc_get[])(usb_core_driver *udev, uint8_t index, uint16_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
usb_reqsta usbd_standard_request (usb_core_driver *udev, usb_req *req)
|
usb_reqsta usbd_standard_request(usb_core_driver *udev, usb_req *req) { return (*_std_dev_req[req->bRequest])(udev, req); }
|
||||||
{
|
|
||||||
return (*_std_dev_req[req->bRequest])(udev, req);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief handle USB device class request
|
\brief handle USB device class request
|
||||||
@@ -96,8 +89,7 @@ usb_reqsta usbd_standard_request (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
usb_reqsta usbd_class_request (usb_core_driver *udev, usb_req *req)
|
usb_reqsta usbd_class_request(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
if (USBD_CONFIGURED == udev->dev.cur_status) {
|
if (USBD_CONFIGURED == udev->dev.cur_status) {
|
||||||
if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) {
|
if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) {
|
||||||
/* call device class handle function */
|
/* call device class handle function */
|
||||||
@@ -115,8 +107,7 @@ usb_reqsta usbd_class_request (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
usb_reqsta usbd_vendor_request (usb_core_driver *udev, usb_req *req)
|
usb_reqsta usbd_vendor_request(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
/* added by user... */
|
/* added by user... */
|
||||||
|
|
||||||
return REQ_SUPP;
|
return REQ_SUPP;
|
||||||
@@ -129,8 +120,7 @@ usb_reqsta usbd_vendor_request (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_reserved (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_reserved(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
/* no operation... */
|
/* no operation... */
|
||||||
|
|
||||||
return REQ_NOTSUPP;
|
return REQ_NOTSUPP;
|
||||||
@@ -143,8 +133,7 @@ static usb_reqsta _usb_std_reserved (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] len: data length pointer
|
\param[out] len: data length pointer
|
||||||
\retval descriptor buffer pointer
|
\retval descriptor buffer pointer
|
||||||
*/
|
*/
|
||||||
static uint8_t* _usb_dev_desc_get (usb_core_driver *udev, uint8_t index, uint16_t *len)
|
static uint8_t *_usb_dev_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len) {
|
||||||
{
|
|
||||||
*len = udev->dev.desc.dev_desc[0];
|
*len = udev->dev.desc.dev_desc[0];
|
||||||
|
|
||||||
return udev->dev.desc.dev_desc;
|
return udev->dev.desc.dev_desc;
|
||||||
@@ -157,8 +146,7 @@ static uint8_t* _usb_dev_desc_get (usb_core_driver *udev, uint8_t index, uint16_
|
|||||||
\param[out] len: data length pointer
|
\param[out] len: data length pointer
|
||||||
\retval descriptor buffer pointer
|
\retval descriptor buffer pointer
|
||||||
*/
|
*/
|
||||||
static uint8_t* _usb_config_desc_get (usb_core_driver *udev, uint8_t index, uint16_t *len)
|
static uint8_t *_usb_config_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len) {
|
||||||
{
|
|
||||||
*len = udev->dev.desc.config_desc[2];
|
*len = udev->dev.desc.config_desc[2];
|
||||||
|
|
||||||
return udev->dev.desc.config_desc;
|
return udev->dev.desc.config_desc;
|
||||||
@@ -171,8 +159,7 @@ static uint8_t* _usb_config_desc_get (usb_core_driver *udev, uint8_t index, uint
|
|||||||
\param[out] len: data length pointer
|
\param[out] len: data length pointer
|
||||||
\retval descriptor buffer pointer
|
\retval descriptor buffer pointer
|
||||||
*/
|
*/
|
||||||
static uint8_t* _usb_bos_desc_get (usb_core_driver *udev, uint8_t index, uint16_t *len)
|
static uint8_t *_usb_bos_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len) {
|
||||||
{
|
|
||||||
*len = udev->dev.desc.bos_desc[2];
|
*len = udev->dev.desc.bos_desc[2];
|
||||||
|
|
||||||
return udev->dev.desc.bos_desc;
|
return udev->dev.desc.bos_desc;
|
||||||
@@ -185,8 +172,7 @@ static uint8_t* _usb_bos_desc_get (usb_core_driver *udev, uint8_t index, uint16_
|
|||||||
\param[out] len: pointer to string length
|
\param[out] len: pointer to string length
|
||||||
\retval descriptor buffer pointer
|
\retval descriptor buffer pointer
|
||||||
*/
|
*/
|
||||||
static uint8_t* _usb_str_desc_get (usb_core_driver *udev, uint8_t index, uint16_t *len)
|
static uint8_t *_usb_str_desc_get(usb_core_driver *udev, uint8_t index, uint16_t *len) {
|
||||||
{
|
|
||||||
uint8_t *desc = udev->dev.desc.strings[index];
|
uint8_t *desc = udev->dev.desc.strings[index];
|
||||||
|
|
||||||
*len = desc[0];
|
*len = desc[0];
|
||||||
@@ -201,8 +187,7 @@ static uint8_t* _usb_str_desc_get (usb_core_driver *udev, uint8_t index, uint16_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_getstatus (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_getstatus(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
uint8_t recp = BYTE_LOW(req->wIndex);
|
uint8_t recp = BYTE_LOW(req->wIndex);
|
||||||
|
|
||||||
usb_transc *transc = &udev->dev.transc_in[0];
|
usb_transc *transc = &udev->dev.transc_in[0];
|
||||||
@@ -211,8 +196,7 @@ static usb_reqsta _usb_std_getstatus (usb_core_driver *udev, usb_req *req)
|
|||||||
|
|
||||||
switch (req->bmRequestType & USB_RECPTYPE_MASK) {
|
switch (req->bmRequestType & USB_RECPTYPE_MASK) {
|
||||||
case USB_RECPTYPE_DEV:
|
case USB_RECPTYPE_DEV:
|
||||||
if ((USBD_ADDRESSED == udev->dev.cur_status) || \
|
if ((USBD_ADDRESSED == udev->dev.cur_status) || (USBD_CONFIGURED == udev->dev.cur_status)) {
|
||||||
(USBD_CONFIGURED == udev->dev.cur_status)) {
|
|
||||||
|
|
||||||
if (udev->dev.pm.power_mode) {
|
if (udev->dev.pm.power_mode) {
|
||||||
status[0] = USB_STATUS_SELF_POWERED;
|
status[0] = USB_STATUS_SELF_POWERED;
|
||||||
@@ -271,15 +255,12 @@ static usb_reqsta _usb_std_getstatus (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_clearfeature (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_clearfeature(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
uint8_t ep = 0;
|
uint8_t ep = 0;
|
||||||
|
|
||||||
switch(req->bmRequestType & USB_RECPTYPE_MASK)
|
switch (req->bmRequestType & USB_RECPTYPE_MASK) {
|
||||||
{
|
|
||||||
case USB_RECPTYPE_DEV:
|
case USB_RECPTYPE_DEV:
|
||||||
if ((USBD_ADDRESSED == udev->dev.cur_status) || \
|
if ((USBD_ADDRESSED == udev->dev.cur_status) || (USBD_CONFIGURED == udev->dev.cur_status)) {
|
||||||
(USBD_CONFIGURED == udev->dev.cur_status)) {
|
|
||||||
|
|
||||||
/* clear device remote wakeup feature */
|
/* clear device remote wakeup feature */
|
||||||
if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
|
if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
|
||||||
@@ -323,15 +304,12 @@ static usb_reqsta _usb_std_clearfeature (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_setfeature (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_setfeature(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
uint8_t ep = 0;
|
uint8_t ep = 0;
|
||||||
|
|
||||||
switch(req->bmRequestType & USB_RECPTYPE_MASK)
|
switch (req->bmRequestType & USB_RECPTYPE_MASK) {
|
||||||
{
|
|
||||||
case USB_RECPTYPE_DEV:
|
case USB_RECPTYPE_DEV:
|
||||||
if ((USBD_ADDRESSED == udev->dev.cur_status) || \
|
if ((USBD_ADDRESSED == udev->dev.cur_status) || (USBD_CONFIGURED == udev->dev.cur_status)) {
|
||||||
(USBD_CONFIGURED == udev->dev.cur_status)) {
|
|
||||||
/* set device remote wakeup feature */
|
/* set device remote wakeup feature */
|
||||||
if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
|
if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
|
||||||
udev->dev.pm.dev_remote_wakeup = 1U;
|
udev->dev.pm.dev_remote_wakeup = 1U;
|
||||||
@@ -372,8 +350,7 @@ static usb_reqsta _usb_std_setfeature (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_setaddress (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_setaddress(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
if ((0U == req->wIndex) && (0U == req->wLength)) {
|
if ((0U == req->wIndex) && (0U == req->wLength)) {
|
||||||
udev->dev.dev_addr = (uint8_t)(req->wValue) & 0x7FU;
|
udev->dev.dev_addr = (uint8_t)(req->wValue) & 0x7FU;
|
||||||
|
|
||||||
@@ -400,8 +377,7 @@ static usb_reqsta _usb_std_setaddress (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_getdescriptor (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_getdescriptor(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
uint8_t desc_type = 0;
|
uint8_t desc_type = 0;
|
||||||
uint8_t desc_index = 0;
|
uint8_t desc_index = 0;
|
||||||
|
|
||||||
@@ -481,8 +457,7 @@ static usb_reqsta _usb_std_getdescriptor (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_setdescriptor (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_setdescriptor(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
/* no handle... */
|
/* no handle... */
|
||||||
return REQ_SUPP;
|
return REQ_SUPP;
|
||||||
}
|
}
|
||||||
@@ -494,8 +469,7 @@ static usb_reqsta _usb_std_setdescriptor (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_getconfiguration (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_getconfiguration(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
usb_transc *transc = &udev->dev.transc_in[0];
|
usb_transc *transc = &udev->dev.transc_in[0];
|
||||||
|
|
||||||
switch (udev->dev.cur_status) {
|
switch (udev->dev.cur_status) {
|
||||||
@@ -531,8 +505,7 @@ static usb_reqsta _usb_std_getconfiguration (usb_core_driver *udev, usb_req *req
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_setconfiguration (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_setconfiguration(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
static uint8_t config;
|
static uint8_t config;
|
||||||
|
|
||||||
config = (uint8_t)(req->wValue);
|
config = (uint8_t)(req->wValue);
|
||||||
@@ -584,8 +557,7 @@ static usb_reqsta _usb_std_setconfiguration (usb_core_driver *udev, usb_req *req
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_getinterface (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_getinterface(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
switch (udev->dev.cur_status) {
|
switch (udev->dev.cur_status) {
|
||||||
case USBD_DEFAULT:
|
case USBD_DEFAULT:
|
||||||
break;
|
break;
|
||||||
@@ -618,8 +590,7 @@ static usb_reqsta _usb_std_getinterface (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_setinterface (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_setinterface(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
switch (udev->dev.cur_status) {
|
switch (udev->dev.cur_status) {
|
||||||
case USBD_DEFAULT:
|
case USBD_DEFAULT:
|
||||||
break;
|
break;
|
||||||
@@ -649,8 +620,7 @@ static usb_reqsta _usb_std_setinterface (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device request status
|
\retval USB device request status
|
||||||
*/
|
*/
|
||||||
static usb_reqsta _usb_std_synchframe (usb_core_driver *udev, usb_req *req)
|
static usb_reqsta _usb_std_synchframe(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
/* no handle... */
|
/* no handle... */
|
||||||
return REQ_SUPP;
|
return REQ_SUPP;
|
||||||
}
|
}
|
||||||
@@ -662,8 +632,7 @@ static usb_reqsta _usb_std_synchframe (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbd_enum_error (usb_core_driver *udev, usb_req *req)
|
void usbd_enum_error(usb_core_driver *udev, usb_req *req) {
|
||||||
{
|
|
||||||
usbd_ep_stall(udev, 0x80);
|
usbd_ep_stall(udev, 0x80);
|
||||||
usbd_ep_stall(udev, 0x00);
|
usbd_ep_stall(udev, 0x00);
|
||||||
|
|
||||||
@@ -678,8 +647,7 @@ void usbd_enum_error (usb_core_driver *udev, usb_req *req)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void int_to_unicode (uint32_t value, uint8_t *pbuf, uint8_t len)
|
void int_to_unicode(uint32_t value, uint8_t *pbuf, uint8_t len) {
|
||||||
{
|
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
|
|
||||||
for (index = 0; index < len; index++) {
|
for (index = 0; index < len; index++) {
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "usbd_enum.h"
|
|
||||||
#include "usbd_transc.h"
|
#include "usbd_transc.h"
|
||||||
|
#include "usbd_enum.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief USB send data in the control transaction
|
\brief USB send data in the control transaction
|
||||||
@@ -41,8 +41,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
usbd_status usbd_ctl_send (usb_core_driver *udev)
|
usbd_status usbd_ctl_send(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
usb_transc *transc = &udev->dev.transc_in[0];
|
usb_transc *transc = &udev->dev.transc_in[0];
|
||||||
|
|
||||||
usbd_ep_send(udev, 0U, transc->xfer_buf, transc->remain_len);
|
usbd_ep_send(udev, 0U, transc->xfer_buf, transc->remain_len);
|
||||||
@@ -62,8 +61,7 @@ usbd_status usbd_ctl_send (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
usbd_status usbd_ctl_recev (usb_core_driver *udev)
|
usbd_status usbd_ctl_recev(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
usb_transc *transc = &udev->dev.transc_out[0];
|
usb_transc *transc = &udev->dev.transc_out[0];
|
||||||
|
|
||||||
usbd_ep_recev(udev, 0U, transc->xfer_buf, transc->remain_len);
|
usbd_ep_recev(udev, 0U, transc->xfer_buf, transc->remain_len);
|
||||||
@@ -83,8 +81,7 @@ usbd_status usbd_ctl_recev (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
usbd_status usbd_ctl_status_send (usb_core_driver *udev)
|
usbd_status usbd_ctl_status_send(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
udev->dev.control.ctl_state = USB_CTL_STATUS_IN;
|
udev->dev.control.ctl_state = USB_CTL_STATUS_IN;
|
||||||
|
|
||||||
usbd_ep_send(udev, 0U, NULL, 0U);
|
usbd_ep_send(udev, 0U, NULL, 0U);
|
||||||
@@ -100,8 +97,7 @@ usbd_status usbd_ctl_status_send (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
usbd_status usbd_ctl_status_recev (usb_core_driver *udev)
|
usbd_status usbd_ctl_status_recev(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
udev->dev.control.ctl_state = USB_CTL_STATUS_OUT;
|
udev->dev.control.ctl_state = USB_CTL_STATUS_OUT;
|
||||||
|
|
||||||
usbd_ep_recev(udev, 0, NULL, 0);
|
usbd_ep_recev(udev, 0, NULL, 0);
|
||||||
@@ -117,8 +113,7 @@ usbd_status usbd_ctl_status_recev (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
uint8_t usbd_setup_transc (usb_core_driver *udev)
|
uint8_t usbd_setup_transc(usb_core_driver *udev) {
|
||||||
{
|
|
||||||
usb_reqsta reqstat = REQ_NOTSUPP;
|
usb_reqsta reqstat = REQ_NOTSUPP;
|
||||||
|
|
||||||
usb_req req = udev->dev.control.req;
|
usb_req req = udev->dev.control.req;
|
||||||
@@ -167,8 +162,7 @@ uint8_t usbd_setup_transc (usb_core_driver *udev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
uint8_t usbd_out_transc (usb_core_driver *udev, uint8_t ep_num)
|
uint8_t usbd_out_transc(usb_core_driver *udev, uint8_t ep_num) {
|
||||||
{
|
|
||||||
if (ep_num == 0) {
|
if (ep_num == 0) {
|
||||||
usb_transc *transc = &udev->dev.transc_out[0];
|
usb_transc *transc = &udev->dev.transc_out[0];
|
||||||
|
|
||||||
@@ -209,8 +203,7 @@ uint8_t usbd_out_transc (usb_core_driver *udev, uint8_t ep_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB device operation cur_status
|
\retval USB device operation cur_status
|
||||||
*/
|
*/
|
||||||
uint8_t usbd_in_transc (usb_core_driver *udev, uint8_t ep_num)
|
uint8_t usbd_in_transc(usb_core_driver *udev, uint8_t ep_num) {
|
||||||
{
|
|
||||||
if (0U == ep_num) {
|
if (0U == ep_num) {
|
||||||
usb_transc *transc = &udev->dev.transc_in[0];
|
usb_transc *transc = &udev->dev.transc_in[0];
|
||||||
|
|
||||||
|
|||||||
@@ -32,18 +32,15 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "drv_usb_hw.h"
|
|
||||||
#include "usbh_pipe.h"
|
|
||||||
#include "usbh_enum.h"
|
|
||||||
#include "usbh_core.h"
|
#include "usbh_core.h"
|
||||||
|
#include "drv_usb_hw.h"
|
||||||
#include "drv_usbh_int.h"
|
#include "drv_usbh_int.h"
|
||||||
|
#include "usbh_enum.h"
|
||||||
|
#include "usbh_pipe.h"
|
||||||
|
|
||||||
uint8_t usbh_sof(usb_core_driver *pudev);
|
uint8_t usbh_sof(usb_core_driver *pudev);
|
||||||
|
|
||||||
usbh_int_cb usbh_int_op =
|
usbh_int_cb usbh_int_op = {usbh_sof};
|
||||||
{
|
|
||||||
usbh_sof
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_int_cb *usbh_int_fop = &usbh_int_op;
|
usbh_int_cb *usbh_int_fop = &usbh_int_op;
|
||||||
|
|
||||||
@@ -55,8 +52,7 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost);
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_sof (usb_core_driver *pudev)
|
uint8_t usbh_sof(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
/* this callback could be used to implement a scheduler process */
|
/* this callback could be used to implement a scheduler process */
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
@@ -69,8 +65,7 @@ uint8_t usbh_sof (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
void usbh_init (usb_core_driver *pudev, usb_core_enum core, usbh_host *puhost)
|
void usbh_init(usb_core_driver *pudev, usb_core_enum core, usbh_host *puhost) {
|
||||||
{
|
|
||||||
uint8_t i = 0U;
|
uint8_t i = 0U;
|
||||||
|
|
||||||
/* host de-initializations */
|
/* host de-initializations */
|
||||||
@@ -107,8 +102,7 @@ void usbh_init (usb_core_driver *pudev, usb_core_enum core, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_deinit(usb_core_driver *pudev, usbh_host *puhost)
|
usbh_status usbh_deinit(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
/* software init */
|
/* software init */
|
||||||
puhost->cur_state = HOST_DEFAULT;
|
puhost->cur_state = HOST_DEFAULT;
|
||||||
puhost->backup_state = HOST_DEFAULT;
|
puhost->backup_state = HOST_DEFAULT;
|
||||||
@@ -133,8 +127,7 @@ usbh_status usbh_deinit(usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbh_core_task (usb_core_driver *pudev, usbh_host *puhost)
|
void usbh_core_task(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
volatile usbh_status status = USBH_FAIL;
|
volatile usbh_status status = USBH_FAIL;
|
||||||
|
|
||||||
/* check for host port events */
|
/* check for host port events */
|
||||||
@@ -176,18 +169,10 @@ void usbh_core_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
usb_port_reset(pudev);
|
usb_port_reset(pudev);
|
||||||
|
|
||||||
/* open IN control pipe */
|
/* open IN control pipe */
|
||||||
usbh_pipe_create (pudev,
|
usbh_pipe_create(pudev, &puhost->dev_prop, puhost->control.pipe_in_num, USB_EPTYPE_CTRL, puhost->control.max_len);
|
||||||
&puhost->dev_prop,
|
|
||||||
puhost->control.pipe_in_num,
|
|
||||||
USB_EPTYPE_CTRL,
|
|
||||||
puhost->control.max_len);
|
|
||||||
|
|
||||||
/* open OUT control pipe */
|
/* open OUT control pipe */
|
||||||
usbh_pipe_create (pudev,
|
usbh_pipe_create(pudev, &puhost->dev_prop, puhost->control.pipe_out_num, USB_EPTYPE_CTRL, puhost->control.max_len);
|
||||||
&puhost->dev_prop,
|
|
||||||
puhost->control.pipe_out_num,
|
|
||||||
USB_EPTYPE_CTRL,
|
|
||||||
puhost->control.max_len);
|
|
||||||
|
|
||||||
puhost->cur_state = HOST_ENUM;
|
puhost->cur_state = HOST_ENUM;
|
||||||
break;
|
break;
|
||||||
@@ -265,8 +250,7 @@ void usbh_core_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbh_error_handler (usbh_host *puhost, usbh_status err_type)
|
void usbh_error_handler(usbh_host *puhost, usbh_status err_type) {
|
||||||
{
|
|
||||||
/* error unrecovered or not supported device speed */
|
/* error unrecovered or not supported device speed */
|
||||||
if ((USBH_SPEED_UNKNOWN_ERROR == err_type) || (USBH_UNRECOVERED_ERROR == err_type)) {
|
if ((USBH_SPEED_UNKNOWN_ERROR == err_type) || (USBH_UNRECOVERED_ERROR == err_type)) {
|
||||||
puhost->usr_cb->dev_error();
|
puhost->usr_cb->dev_error();
|
||||||
@@ -287,8 +271,7 @@ void usbh_error_handler (usbh_host *puhost, usbh_status err_type)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
static usbh_status usbh_enum_task(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
uint8_t str_buf[64];
|
uint8_t str_buf[64];
|
||||||
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
@@ -306,18 +289,11 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
usb_port_reset(pudev);
|
usb_port_reset(pudev);
|
||||||
|
|
||||||
/* modify control channels configuration for maximum packet size */
|
/* modify control channels configuration for maximum packet size */
|
||||||
usbh_pipe_update (pudev,
|
usbh_pipe_update(pudev, puhost->control.pipe_out_num, 0U, 0U, puhost->control.max_len);
|
||||||
puhost->control.pipe_out_num,
|
|
||||||
0U, 0U,
|
|
||||||
puhost->control.max_len);
|
|
||||||
|
|
||||||
usbh_pipe_update (pudev,
|
usbh_pipe_update(pudev, puhost->control.pipe_in_num, 0U, 0U, puhost->control.max_len);
|
||||||
puhost->control.pipe_in_num,
|
|
||||||
0U, 0U,
|
|
||||||
puhost->control.max_len);
|
|
||||||
|
|
||||||
puhost->enum_state = ENUM_GET_DEV_DESC;
|
puhost->enum_state = ENUM_GET_DEV_DESC;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -345,15 +321,9 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
puhost->usr_cb->dev_address_set();
|
puhost->usr_cb->dev_address_set();
|
||||||
|
|
||||||
/* modify control channels to update device address */
|
/* modify control channels to update device address */
|
||||||
usbh_pipe_update (pudev,
|
usbh_pipe_update(pudev, puhost->control.pipe_in_num, puhost->dev_prop.addr, 0U, 0U);
|
||||||
puhost->control.pipe_in_num,
|
|
||||||
puhost->dev_prop.addr,
|
|
||||||
0U, 0U);
|
|
||||||
|
|
||||||
usbh_pipe_update (pudev,
|
usbh_pipe_update(pudev, puhost->control.pipe_out_num, puhost->dev_prop.addr, 0U, 0U);
|
||||||
puhost->control.pipe_out_num,
|
|
||||||
puhost->dev_prop.addr,
|
|
||||||
0U, 0U);
|
|
||||||
|
|
||||||
puhost->enum_state = ENUM_GET_CFG_DESC;
|
puhost->enum_state = ENUM_GET_CFG_DESC;
|
||||||
}
|
}
|
||||||
@@ -370,9 +340,7 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
/* get full config descriptor (config, interface, endpoints) */
|
/* get full config descriptor (config, interface, endpoints) */
|
||||||
if (USBH_OK == usbh_cfgdesc_get(pudev, puhost, puhost->dev_prop.cfg_desc.wTotalLength)) {
|
if (USBH_OK == usbh_cfgdesc_get(pudev, puhost, puhost->dev_prop.cfg_desc.wTotalLength)) {
|
||||||
/* user callback for configuration descriptors available */
|
/* user callback for configuration descriptors available */
|
||||||
puhost->usr_cb->dev_cfgdesc_assigned (&puhost->dev_prop.cfg_desc,
|
puhost->usr_cb->dev_cfgdesc_assigned(&puhost->dev_prop.cfg_desc, puhost->dev_prop.itf_desc, puhost->dev_prop.ep_desc[0]);
|
||||||
puhost->dev_prop.itf_desc,
|
|
||||||
puhost->dev_prop.ep_desc[0]);
|
|
||||||
|
|
||||||
puhost->enum_state = ENUM_GET_STR_DESC;
|
puhost->enum_state = ENUM_GET_STR_DESC;
|
||||||
}
|
}
|
||||||
@@ -380,11 +348,7 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
|
|
||||||
case ENUM_GET_STR_DESC:
|
case ENUM_GET_STR_DESC:
|
||||||
if (index_mfc_str) {
|
if (index_mfc_str) {
|
||||||
if (USBH_OK == usbh_strdesc_get (pudev,
|
if (USBH_OK == usbh_strdesc_get(pudev, puhost, puhost->dev_prop.dev_desc.iManufacturer, str_buf, 0xFFU)) {
|
||||||
puhost,
|
|
||||||
puhost->dev_prop.dev_desc.iManufacturer,
|
|
||||||
str_buf,
|
|
||||||
0xFFU)) {
|
|
||||||
/* user callback for manufacturing string */
|
/* user callback for manufacturing string */
|
||||||
puhost->usr_cb->dev_mfc_str(str_buf);
|
puhost->usr_cb->dev_mfc_str(str_buf);
|
||||||
|
|
||||||
@@ -393,22 +357,14 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
} else {
|
} else {
|
||||||
if (index_prod_str) {
|
if (index_prod_str) {
|
||||||
/* check that product string is available */
|
/* check that product string is available */
|
||||||
if (USBH_OK == usbh_strdesc_get (pudev,
|
if (USBH_OK == usbh_strdesc_get(pudev, puhost, puhost->dev_prop.dev_desc.iProduct, str_buf, 0xFFU)) {
|
||||||
puhost,
|
|
||||||
puhost->dev_prop.dev_desc.iProduct,
|
|
||||||
str_buf,
|
|
||||||
0xFFU)) {
|
|
||||||
puhost->usr_cb->dev_prod_str(str_buf);
|
puhost->usr_cb->dev_prod_str(str_buf);
|
||||||
|
|
||||||
index_prod_str = 0U;
|
index_prod_str = 0U;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (index_serial_str) {
|
if (index_serial_str) {
|
||||||
if (USBH_OK == usbh_strdesc_get (pudev,
|
if (USBH_OK == usbh_strdesc_get(pudev, puhost, puhost->dev_prop.dev_desc.iSerialNumber, str_buf, 0xFFU)) {
|
||||||
puhost,
|
|
||||||
puhost->dev_prop.dev_desc.iSerialNumber,
|
|
||||||
str_buf,
|
|
||||||
0xFFU)) {
|
|
||||||
puhost->usr_cb->dev_seral_str(str_buf);
|
puhost->usr_cb->dev_seral_str(str_buf);
|
||||||
puhost->enum_state = ENUM_SET_CONFIGURATION;
|
puhost->enum_state = ENUM_SET_CONFIGURATION;
|
||||||
|
|
||||||
@@ -422,9 +378,7 @@ static usbh_status usbh_enum_task (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ENUM_SET_CONFIGURATION:
|
case ENUM_SET_CONFIGURATION:
|
||||||
if (USBH_OK == usbh_setcfg (pudev,
|
if (USBH_OK == usbh_setcfg(pudev, puhost, puhost->dev_prop.cfg_desc.bConfigurationValue)) {
|
||||||
puhost,
|
|
||||||
puhost->dev_prop.cfg_desc.bConfigurationValue)) {
|
|
||||||
puhost->enum_state = ENUM_DEV_CONFIGURED;
|
puhost->enum_state = ENUM_DEV_CONFIGURED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "usbh_transc.h"
|
|
||||||
#include "usbh_enum.h"
|
#include "usbh_enum.h"
|
||||||
|
#include "usbh_transc.h"
|
||||||
|
|
||||||
static void usbh_devdesc_parse(usb_desc_dev *cfg_desc, uint8_t *buf, uint16_t len);
|
static void usbh_devdesc_parse(usb_desc_dev *cfg_desc, uint8_t *buf, uint16_t len);
|
||||||
static void usbh_cfgset_parse(usb_dev_prop *udev, uint8_t *buf);
|
static void usbh_cfgset_parse(usb_dev_prop *udev, uint8_t *buf);
|
||||||
@@ -42,7 +42,6 @@ static void usbh_itfdesc_parse (usb_desc_itf *itf_desc, uint8_t *buf);
|
|||||||
static void usbh_epdesc_parse(usb_desc_ep *ep_desc, uint8_t *buf);
|
static void usbh_epdesc_parse(usb_desc_ep *ep_desc, uint8_t *buf);
|
||||||
static void usbh_strdesc_parse(uint8_t *psrc, uint8_t *pdest, uint16_t len);
|
static void usbh_strdesc_parse(uint8_t *psrc, uint8_t *pdest, uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure USB control status parameters
|
\brief configure USB control status parameters
|
||||||
\param[in] puhost: pointer to usb host
|
\param[in] puhost: pointer to usb host
|
||||||
@@ -51,8 +50,7 @@ static void usbh_strdesc_parse (uint8_t *psrc, uint8_t *pdest, uint16_t len);
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usbh_ctlstate_config (usbh_host *puhost, uint8_t *buf, uint16_t len)
|
void usbh_ctlstate_config(usbh_host *puhost, uint8_t *buf, uint16_t len) {
|
||||||
{
|
|
||||||
/* prepare the transactions */
|
/* prepare the transactions */
|
||||||
puhost->control.buf = buf;
|
puhost->control.buf = buf;
|
||||||
puhost->control.ctl_len = len;
|
puhost->control.ctl_len = len;
|
||||||
@@ -68,20 +66,14 @@ void usbh_ctlstate_config (usbh_host *puhost, uint8_t *buf, uint16_t len)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_devdesc_get (usb_core_driver *pudev, usbh_host *puhost, uint8_t len)
|
usbh_status usbh_devdesc_get(usb_core_driver *pudev, usbh_host *puhost, uint8_t len) {
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req
|
||||||
.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD,
|
= (usb_req){.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD, .bRequest = USB_GET_DESCRIPTOR, .wValue = USBH_DESC(USB_DESCTYPE_DEV), .wIndex = 0U, .wLength = len};
|
||||||
.bRequest = USB_GET_DESCRIPTOR,
|
|
||||||
.wValue = USBH_DESC(USB_DESCTYPE_DEV),
|
|
||||||
.wIndex = 0U,
|
|
||||||
.wLength = len
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
||||||
}
|
}
|
||||||
@@ -104,20 +96,14 @@ usbh_status usbh_devdesc_get (usb_core_driver *pudev, usbh_host *puhost, uint8_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_cfgdesc_get (usb_core_driver *pudev, usbh_host *puhost, uint16_t len)
|
usbh_status usbh_cfgdesc_get(usb_core_driver *pudev, usbh_host *puhost, uint16_t len) {
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req
|
||||||
.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD,
|
= (usb_req){.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD, .bRequest = USB_GET_DESCRIPTOR, .wValue = USBH_DESC(USB_DESCTYPE_CONFIG), .wIndex = 0U, .wLength = len};
|
||||||
.bRequest = USB_GET_DESCRIPTOR,
|
|
||||||
.wValue = USBH_DESC(USB_DESCTYPE_CONFIG),
|
|
||||||
.wIndex = 0U,
|
|
||||||
.wLength = len
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
||||||
}
|
}
|
||||||
@@ -145,24 +131,14 @@ usbh_status usbh_cfgdesc_get (usb_core_driver *pudev, usbh_host *puhost, uint16_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_strdesc_get (usb_core_driver *pudev,
|
usbh_status usbh_strdesc_get(usb_core_driver *pudev, usbh_host *puhost, uint8_t str_index, uint8_t *buf, uint16_t len) {
|
||||||
usbh_host *puhost,
|
|
||||||
uint8_t str_index,
|
|
||||||
uint8_t *buf,
|
|
||||||
uint16_t len)
|
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req){
|
usb_ctl->setup.req = (usb_req){
|
||||||
.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD,
|
.bmRequestType = USB_TRX_IN | USB_RECPTYPE_DEV | USB_REQTYPE_STRD, .bRequest = USB_GET_DESCRIPTOR, .wValue = USBH_DESC(USB_DESCTYPE_STR) | str_index, .wIndex = 0x0409U, .wLength = len};
|
||||||
.bRequest = USB_GET_DESCRIPTOR,
|
|
||||||
.wValue = USBH_DESC(USB_DESCTYPE_STR) | str_index,
|
|
||||||
.wIndex = 0x0409U,
|
|
||||||
.wLength = len
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
usbh_ctlstate_config(puhost, pudev->host.rx_buf, len);
|
||||||
}
|
}
|
||||||
@@ -185,20 +161,13 @@ usbh_status usbh_strdesc_get (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_setaddress (usb_core_driver *pudev, usbh_host *puhost, uint8_t dev_addr)
|
usbh_status usbh_setaddress(usb_core_driver *pudev, usbh_host *puhost, uint8_t dev_addr) {
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req = (usb_req){.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_DEV | USB_REQTYPE_STRD, .bRequest = USB_SET_ADDRESS, .wValue = (uint16_t)dev_addr, .wIndex = 0U, .wLength = 0U};
|
||||||
.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_DEV | USB_REQTYPE_STRD,
|
|
||||||
.bRequest = USB_SET_ADDRESS,
|
|
||||||
.wValue = (uint16_t)dev_addr,
|
|
||||||
.wIndex = 0U,
|
|
||||||
.wLength = 0U
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, NULL, 0U);
|
usbh_ctlstate_config(puhost, NULL, 0U);
|
||||||
}
|
}
|
||||||
@@ -216,20 +185,13 @@ usbh_status usbh_setaddress (usb_core_driver *pudev, usbh_host *puhost, uint8_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_setcfg (usb_core_driver *pudev, usbh_host *puhost, uint16_t config_index)
|
usbh_status usbh_setcfg(usb_core_driver *pudev, usbh_host *puhost, uint16_t config_index) {
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req = (usb_req){.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_DEV | USB_REQTYPE_STRD, .bRequest = USB_SET_CONFIGURATION, .wValue = config_index, .wIndex = 0U, .wLength = 0U};
|
||||||
.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_DEV | USB_REQTYPE_STRD,
|
|
||||||
.bRequest = USB_SET_CONFIGURATION,
|
|
||||||
.wValue = config_index,
|
|
||||||
.wIndex = 0U,
|
|
||||||
.wLength = 0U
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, NULL, 0U);
|
usbh_ctlstate_config(puhost, NULL, 0U);
|
||||||
}
|
}
|
||||||
@@ -248,23 +210,13 @@ usbh_status usbh_setcfg (usb_core_driver *pudev, usbh_host *puhost, uint16_t con
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_setinterface (usb_core_driver *pudev,
|
usbh_status usbh_setinterface(usb_core_driver *pudev, usbh_host *puhost, uint8_t ep_num, uint8_t set) {
|
||||||
usbh_host *puhost,
|
|
||||||
uint8_t ep_num,
|
|
||||||
uint8_t set)
|
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req = (usb_req){.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_ITF | USB_REQTYPE_STRD, .bRequest = USB_SET_INTERFACE, .wValue = set, .wIndex = ep_num, .wLength = 0U};
|
||||||
.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_ITF | USB_REQTYPE_STRD,
|
|
||||||
.bRequest = USB_SET_INTERFACE,
|
|
||||||
.wValue = set,
|
|
||||||
.wIndex = ep_num,
|
|
||||||
.wLength = 0U
|
|
||||||
};
|
|
||||||
|
|
||||||
usbh_ctlstate_config(puhost, NULL, 0U);
|
usbh_ctlstate_config(puhost, NULL, 0U);
|
||||||
}
|
}
|
||||||
@@ -283,23 +235,13 @@ usbh_status usbh_setinterface (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_clrfeature (usb_core_driver *pudev,
|
usbh_status usbh_clrfeature(usb_core_driver *pudev, usbh_host *puhost, uint8_t ep_addr, uint8_t pp_num) {
|
||||||
usbh_host *puhost,
|
|
||||||
uint8_t ep_addr,
|
|
||||||
uint8_t pp_num)
|
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
usbh_control *usb_ctl = &puhost->control;
|
usbh_control *usb_ctl = &puhost->control;
|
||||||
|
|
||||||
if (CTL_IDLE == usb_ctl->ctl_state) {
|
if (CTL_IDLE == usb_ctl->ctl_state) {
|
||||||
usb_ctl->setup.req = (usb_req) {
|
usb_ctl->setup.req = (usb_req){.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_EP | USB_REQTYPE_STRD, .bRequest = USB_CLEAR_FEATURE, .wValue = FEATURE_SELECTOR_EP, .wIndex = ep_addr, .wLength = 0};
|
||||||
.bmRequestType = USB_TRX_OUT | USB_RECPTYPE_EP | USB_REQTYPE_STRD,
|
|
||||||
.bRequest = USB_CLEAR_FEATURE,
|
|
||||||
.wValue = FEATURE_SELECTOR_EP,
|
|
||||||
.wIndex = ep_addr,
|
|
||||||
.wLength = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (EP_DIR(ep_addr)) {
|
if (EP_DIR(ep_addr)) {
|
||||||
pudev->host.pipe[pp_num].data_toggle_in = 0U;
|
pudev->host.pipe[pp_num].data_toggle_in = 0U;
|
||||||
@@ -323,20 +265,14 @@ usbh_status usbh_clrfeature (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_devdesc_parse (usb_desc_dev *dev_desc, uint8_t *buf, uint16_t len)
|
static void usbh_devdesc_parse(usb_desc_dev *dev_desc, uint8_t *buf, uint16_t len) {
|
||||||
{
|
*dev_desc = (usb_desc_dev){.header = {.bLength = *(uint8_t *)(buf + 0U), .bDescriptorType = *(uint8_t *)(buf + 1U)},
|
||||||
*dev_desc = (usb_desc_dev) {
|
|
||||||
.header = {
|
|
||||||
.bLength = *(uint8_t *)(buf + 0U),
|
|
||||||
.bDescriptorType = *(uint8_t *)(buf + 1U)
|
|
||||||
},
|
|
||||||
|
|
||||||
.bcdUSB = BYTE_SWAP(buf + 2U),
|
.bcdUSB = BYTE_SWAP(buf + 2U),
|
||||||
.bDeviceClass = *(uint8_t *)(buf + 4U),
|
.bDeviceClass = *(uint8_t *)(buf + 4U),
|
||||||
.bDeviceSubClass = *(uint8_t *)(buf + 5U),
|
.bDeviceSubClass = *(uint8_t *)(buf + 5U),
|
||||||
.bDeviceProtocol = *(uint8_t *)(buf + 6U),
|
.bDeviceProtocol = *(uint8_t *)(buf + 6U),
|
||||||
.bMaxPacketSize0 = *(uint8_t *)(buf + 7U)
|
.bMaxPacketSize0 = *(uint8_t *)(buf + 7U)};
|
||||||
};
|
|
||||||
|
|
||||||
if (len > 8U) {
|
if (len > 8U) {
|
||||||
/* for 1st time after device connection, host may issue only 8 bytes for device descriptor length */
|
/* for 1st time after device connection, host may issue only 8 bytes for device descriptor length */
|
||||||
@@ -357,8 +293,7 @@ static void usbh_devdesc_parse (usb_desc_dev *dev_desc, uint8_t *buf, uint16_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_cfgdesc_parse (usb_desc_config *cfg_desc, uint8_t *buf)
|
static void usbh_cfgdesc_parse(usb_desc_config *cfg_desc, uint8_t *buf) {
|
||||||
{
|
|
||||||
/* parse configuration descriptor */
|
/* parse configuration descriptor */
|
||||||
*cfg_desc = (usb_desc_config) {
|
*cfg_desc = (usb_desc_config) {
|
||||||
.header = {
|
.header = {
|
||||||
@@ -382,8 +317,7 @@ static void usbh_cfgdesc_parse (usb_desc_config *cfg_desc, uint8_t *buf)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_cfgset_parse (usb_dev_prop *udev, uint8_t *buf)
|
static void usbh_cfgset_parse(usb_dev_prop *udev, uint8_t *buf) {
|
||||||
{
|
|
||||||
usb_desc_ep * ep = NULL;
|
usb_desc_ep * ep = NULL;
|
||||||
usb_desc_itf *itf = NULL, itf_value;
|
usb_desc_itf *itf = NULL, itf_value;
|
||||||
|
|
||||||
@@ -453,8 +387,7 @@ static void usbh_cfgset_parse (usb_dev_prop *udev, uint8_t *buf)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_itfdesc_parse (usb_desc_itf *itf_desc, uint8_t *buf)
|
static void usbh_itfdesc_parse(usb_desc_itf *itf_desc, uint8_t *buf) {
|
||||||
{
|
|
||||||
*itf_desc = (usb_desc_itf) {
|
*itf_desc = (usb_desc_itf) {
|
||||||
.header = {
|
.header = {
|
||||||
.bLength = *(uint8_t *)(buf + 0U),
|
.bLength = *(uint8_t *)(buf + 0U),
|
||||||
@@ -478,19 +411,13 @@ static void usbh_itfdesc_parse (usb_desc_itf *itf_desc, uint8_t *buf)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_epdesc_parse (usb_desc_ep *ep_desc, uint8_t *buf)
|
static void usbh_epdesc_parse(usb_desc_ep *ep_desc, uint8_t *buf) {
|
||||||
{
|
*ep_desc = (usb_desc_ep){.header = {.bLength = *(uint8_t *)(buf + 0U), .bDescriptorType = *(uint8_t *)(buf + 1U)},
|
||||||
*ep_desc = (usb_desc_ep) {
|
|
||||||
.header = {
|
|
||||||
.bLength = *(uint8_t *)(buf + 0U),
|
|
||||||
.bDescriptorType = *(uint8_t *)(buf + 1U)
|
|
||||||
},
|
|
||||||
|
|
||||||
.bEndpointAddress = *(uint8_t *)(buf + 2U),
|
.bEndpointAddress = *(uint8_t *)(buf + 2U),
|
||||||
.bmAttributes = *(uint8_t *)(buf + 3U),
|
.bmAttributes = *(uint8_t *)(buf + 3U),
|
||||||
.wMaxPacketSize = BYTE_SWAP(buf + 4U),
|
.wMaxPacketSize = BYTE_SWAP(buf + 4U),
|
||||||
.bInterval = *(uint8_t *)(buf + 6U)
|
.bInterval = *(uint8_t *)(buf + 6U)};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -501,8 +428,7 @@ static void usbh_epdesc_parse (usb_desc_ep *ep_desc, uint8_t *buf)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static void usbh_strdesc_parse (uint8_t *psrc, uint8_t *pdest, uint16_t len)
|
static void usbh_strdesc_parse(uint8_t *psrc, uint8_t *pdest, uint16_t len) {
|
||||||
{
|
|
||||||
uint16_t str_len = 0U, index = 0U;
|
uint16_t str_len = 0U, index = 0U;
|
||||||
|
|
||||||
/* the unicode string descriptor is not NULL-terminated. The string length is
|
/* the unicode string descriptor is not NULL-terminated. The string length is
|
||||||
@@ -536,8 +462,7 @@ static void usbh_strdesc_parse (uint8_t *psrc, uint8_t *pdest, uint16_t len)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usb_desc_header *usbh_nextdesc_get (uint8_t *pbuf, uint16_t *ptr)
|
usb_desc_header *usbh_nextdesc_get(uint8_t *pbuf, uint16_t *ptr) {
|
||||||
{
|
|
||||||
usb_desc_header *pnext;
|
usb_desc_header *pnext;
|
||||||
|
|
||||||
*ptr += ((usb_desc_header *)pbuf)->bLength;
|
*ptr += ((usb_desc_header *)pbuf)->bLength;
|
||||||
@@ -546,4 +471,3 @@ usb_desc_header *usbh_nextdesc_get (uint8_t *pbuf, uint16_t *ptr)
|
|||||||
|
|
||||||
return (pnext);
|
return (pnext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,7 @@ static uint16_t usbh_freepipe_get (usb_core_driver *pudev);
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_pipe_create (usb_core_driver *pudev,
|
uint8_t usbh_pipe_create(usb_core_driver *pudev, usb_dev_prop *udev, uint8_t pp_num, uint8_t ep_type, uint16_t ep_mpl) {
|
||||||
usb_dev_prop *udev,
|
|
||||||
uint8_t pp_num,
|
|
||||||
uint8_t ep_type,
|
|
||||||
uint16_t ep_mpl)
|
|
||||||
{
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
|
|
||||||
pp->dev_addr = udev->addr;
|
pp->dev_addr = udev->addr;
|
||||||
@@ -76,12 +71,7 @@ uint8_t usbh_pipe_create (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_pipe_update (usb_core_driver *pudev,
|
uint8_t usbh_pipe_update(usb_core_driver *pudev, uint8_t pp_num, uint8_t dev_addr, uint32_t dev_speed, uint16_t ep_mpl) {
|
||||||
uint8_t pp_num,
|
|
||||||
uint8_t dev_addr,
|
|
||||||
uint32_t dev_speed,
|
|
||||||
uint16_t ep_mpl)
|
|
||||||
{
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
|
|
||||||
if ((pp->dev_addr != dev_addr) && (dev_addr)) {
|
if ((pp->dev_addr != dev_addr) && (dev_addr)) {
|
||||||
@@ -108,8 +98,7 @@ uint8_t usbh_pipe_update (usb_core_driver *pudev,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_pipe_allocate (usb_core_driver *pudev, uint8_t ep_addr)
|
uint8_t usbh_pipe_allocate(usb_core_driver *pudev, uint8_t ep_addr) {
|
||||||
{
|
|
||||||
uint16_t pp_num = usbh_freepipe_get(pudev);
|
uint16_t pp_num = usbh_freepipe_get(pudev);
|
||||||
|
|
||||||
if (HC_ERROR != pp_num) {
|
if (HC_ERROR != pp_num) {
|
||||||
@@ -128,8 +117,7 @@ uint8_t usbh_pipe_allocate (usb_core_driver *pudev, uint8_t ep_addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_pipe_free (usb_core_driver *pudev, uint8_t pp_num)
|
uint8_t usbh_pipe_free(usb_core_driver *pudev, uint8_t pp_num) {
|
||||||
{
|
|
||||||
if (pp_num < HC_MAX) {
|
if (pp_num < HC_MAX) {
|
||||||
pudev->host.pipe[pp_num].in_used = 0U;
|
pudev->host.pipe[pp_num].in_used = 0U;
|
||||||
}
|
}
|
||||||
@@ -143,8 +131,7 @@ uint8_t usbh_pipe_free (usb_core_driver *pudev, uint8_t pp_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
uint8_t usbh_pipe_delete (usb_core_driver *pudev)
|
uint8_t usbh_pipe_delete(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint8_t pp_num = 0U;
|
uint8_t pp_num = 0U;
|
||||||
|
|
||||||
for (pp_num = 2U; pp_num < HC_MAX; pp_num++) {
|
for (pp_num = 2U; pp_num < HC_MAX; pp_num++) {
|
||||||
@@ -160,8 +147,7 @@ uint8_t usbh_pipe_delete (usb_core_driver *pudev)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint16_t usbh_freepipe_get (usb_core_driver *pudev)
|
static uint16_t usbh_freepipe_get(usb_core_driver *pudev) {
|
||||||
{
|
|
||||||
uint8_t pp_num = 0U;
|
uint8_t pp_num = 0U;
|
||||||
|
|
||||||
for (pp_num = 0U; pp_num < HC_MAX; pp_num++) {
|
for (pp_num = 0U; pp_num < HC_MAX; pp_num++) {
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
|
|||||||
OF SUCH DAMAGE.
|
OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "drv_usb_hw.h"
|
|
||||||
#include "usbh_transc.h"
|
#include "usbh_transc.h"
|
||||||
|
#include "drv_usb_hw.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief prepare a pipe and start a transfer
|
\brief prepare a pipe and start a transfer
|
||||||
@@ -42,8 +42,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
static uint32_t usbh_request_submit (usb_core_driver *pudev, uint8_t pp_num)
|
static uint32_t usbh_request_submit(usb_core_driver *pudev, uint8_t pp_num) {
|
||||||
{
|
|
||||||
pudev->host.pipe[pp_num].urb_state = URB_IDLE;
|
pudev->host.pipe[pp_num].urb_state = URB_IDLE;
|
||||||
pudev->host.pipe[pp_num].xfer_count = 0U;
|
pudev->host.pipe[pp_num].xfer_count = 0U;
|
||||||
|
|
||||||
@@ -58,8 +57,7 @@ static uint32_t usbh_request_submit (usb_core_driver *pudev, uint8_t pp_num)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_ctlsetup_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num)
|
usbh_status usbh_ctlsetup_send(usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num) {
|
||||||
{
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
|
|
||||||
pp->DPID = PIPE_DPID_SETUP;
|
pp->DPID = PIPE_DPID_SETUP;
|
||||||
@@ -78,8 +76,7 @@ usbh_status usbh_ctlsetup_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_data_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len)
|
usbh_status usbh_data_send(usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len) {
|
||||||
{
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
|
|
||||||
pp->xfer_buf = buf;
|
pp->xfer_buf = buf;
|
||||||
@@ -126,8 +123,7 @@ usbh_status usbh_data_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_data_recev (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len)
|
usbh_status usbh_data_recev(usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len) {
|
||||||
{
|
|
||||||
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
usb_pipe *pp = &pudev->host.pipe[pp_num];
|
||||||
|
|
||||||
pp->xfer_buf = buf;
|
pp->xfer_buf = buf;
|
||||||
@@ -171,8 +167,7 @@ usbh_status usbh_data_recev (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_nu
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval USB URB state
|
\retval USB URB state
|
||||||
*/
|
*/
|
||||||
static usb_urb_state usbh_urb_wait (usb_core_driver *pudev, usbh_host *puhost, uint8_t pp_num, uint32_t wait_time)
|
static usb_urb_state usbh_urb_wait(usb_core_driver *pudev, usbh_host *puhost, uint8_t pp_num, uint32_t wait_time) {
|
||||||
{
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
|
|
||||||
while (URB_DONE != (urb_status = usbh_urbstate_get(pudev, pp_num))) {
|
while (URB_DONE != (urb_status = usbh_urbstate_get(pudev, pp_num))) {
|
||||||
@@ -184,8 +179,7 @@ static usb_urb_state usbh_urb_wait (usb_core_driver *pudev, usbh_host *puhost, u
|
|||||||
} else if (URB_ERROR == urb_status) {
|
} else if (URB_ERROR == urb_status) {
|
||||||
puhost->control.ctl_state = CTL_ERROR;
|
puhost->control.ctl_state = CTL_ERROR;
|
||||||
break;
|
break;
|
||||||
} else if ((wait_time > 0U) && \
|
} else if ((wait_time > 0U) && ((usb_curframe_get(pudev) - puhost->control.timer) > wait_time)) {
|
||||||
((usb_curframe_get(pudev)- puhost->control.timer) > wait_time)) {
|
|
||||||
/* timeout for in transfer */
|
/* timeout for in transfer */
|
||||||
puhost->control.ctl_state = CTL_ERROR;
|
puhost->control.ctl_state = CTL_ERROR;
|
||||||
break;
|
break;
|
||||||
@@ -204,14 +198,11 @@ static usb_urb_state usbh_urb_wait (usb_core_driver *pudev, usbh_host *puhost, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usbh_setup_transc (usb_core_driver *pudev, usbh_host *puhost)
|
static void usbh_setup_transc(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
|
|
||||||
/* send a SETUP packet */
|
/* send a SETUP packet */
|
||||||
usbh_ctlsetup_send (pudev,
|
usbh_ctlsetup_send(pudev, puhost->control.setup.data, puhost->control.pipe_out_num);
|
||||||
puhost->control.setup.data,
|
|
||||||
puhost->control.pipe_out_num);
|
|
||||||
|
|
||||||
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_out_num, 0U);
|
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_out_num, 0U);
|
||||||
|
|
||||||
@@ -244,14 +235,10 @@ static void usbh_setup_transc (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usbh_data_in_transc (usb_core_driver *pudev, usbh_host *puhost)
|
static void usbh_data_in_transc(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
|
|
||||||
usbh_data_recev (pudev,
|
usbh_data_recev(pudev, puhost->control.buf, puhost->control.pipe_in_num, puhost->control.ctl_len);
|
||||||
puhost->control.buf,
|
|
||||||
puhost->control.pipe_in_num,
|
|
||||||
puhost->control.ctl_len);
|
|
||||||
|
|
||||||
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_in_num, DATA_STAGE_TIMEOUT);
|
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_in_num, DATA_STAGE_TIMEOUT);
|
||||||
|
|
||||||
@@ -269,16 +256,12 @@ static void usbh_data_in_transc (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usbh_data_out_transc (usb_core_driver *pudev, usbh_host *puhost)
|
static void usbh_data_out_transc(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
|
|
||||||
pudev->host.pipe[puhost->control.pipe_out_num].data_toggle_out = 1U;
|
pudev->host.pipe[puhost->control.pipe_out_num].data_toggle_out = 1U;
|
||||||
|
|
||||||
usbh_data_send (pudev,
|
usbh_data_send(pudev, puhost->control.buf, puhost->control.pipe_out_num, puhost->control.ctl_len);
|
||||||
puhost->control.buf,
|
|
||||||
puhost->control.pipe_out_num,
|
|
||||||
puhost->control.ctl_len);
|
|
||||||
|
|
||||||
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_out_num, DATA_STAGE_TIMEOUT);
|
urb_status = usbh_urb_wait(pudev, puhost, puhost->control.pipe_out_num, DATA_STAGE_TIMEOUT);
|
||||||
|
|
||||||
@@ -296,8 +279,7 @@ static void usbh_data_out_transc (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usbh_status_in_transc (usb_core_driver *pudev, usbh_host *puhost)
|
static void usbh_status_in_transc(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
uint8_t pp_num = puhost->control.pipe_in_num;
|
uint8_t pp_num = puhost->control.pipe_in_num;
|
||||||
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
@@ -318,8 +300,7 @@ static void usbh_status_in_transc (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void usbh_status_out_transc (usb_core_driver *pudev, usbh_host *puhost)
|
static void usbh_status_out_transc(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
uint8_t pp_num = puhost->control.pipe_out_num;
|
uint8_t pp_num = puhost->control.pipe_out_num;
|
||||||
|
|
||||||
usb_urb_state urb_status = URB_IDLE;
|
usb_urb_state urb_status = URB_IDLE;
|
||||||
@@ -342,8 +323,7 @@ static void usbh_status_out_transc (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval operation status
|
\retval operation status
|
||||||
*/
|
*/
|
||||||
usbh_status usbh_ctl_handler (usb_core_driver *pudev, usbh_host *puhost)
|
usbh_status usbh_ctl_handler(usb_core_driver *pudev, usbh_host *puhost) {
|
||||||
{
|
|
||||||
usbh_status status = USBH_BUSY;
|
usbh_status status = USBH_BUSY;
|
||||||
|
|
||||||
switch (puhost->control.ctl_state) {
|
switch (puhost->control.ctl_state) {
|
||||||
@@ -388,4 +368,3 @@ usbh_status usbh_ctl_handler (usb_core_driver *pudev, usbh_host *puhost)
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_deinit(uint32_t adc_periph)
|
void adc_deinit(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
switch (adc_periph) {
|
switch (adc_periph) {
|
||||||
case ADC0:
|
case ADC0:
|
||||||
/* reset ADC0 */
|
/* reset ADC0 */
|
||||||
@@ -99,8 +98,7 @@ void adc_deinit(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_mode_config(uint32_t adc_periph, uint32_t mode)
|
void adc_mode_config(uint32_t adc_periph, uint32_t mode) {
|
||||||
{
|
|
||||||
ADC_CTL0(adc_periph) &= ~(ADC_CTL0_SYNCM);
|
ADC_CTL0(adc_periph) &= ~(ADC_CTL0_SYNCM);
|
||||||
ADC_CTL0(adc_periph) |= mode;
|
ADC_CTL0(adc_periph) |= mode;
|
||||||
}
|
}
|
||||||
@@ -117,8 +115,7 @@ void adc_mode_config(uint32_t adc_periph, uint32_t mode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_special_function_config(uint32_t adc_periph, uint32_t function, ControlStatus newvalue)
|
void adc_special_function_config(uint32_t adc_periph, uint32_t function, ControlStatus newvalue) {
|
||||||
{
|
|
||||||
if (newvalue) {
|
if (newvalue) {
|
||||||
if (0U != (function & ADC_SCAN_MODE)) {
|
if (0U != (function & ADC_SCAN_MODE)) {
|
||||||
/* enable scan mode */
|
/* enable scan mode */
|
||||||
@@ -158,8 +155,7 @@ void adc_special_function_config(uint32_t adc_periph, uint32_t function, Control
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
|
void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment) {
|
||||||
{
|
|
||||||
if (ADC_DATAALIGN_RIGHT != data_alignment) {
|
if (ADC_DATAALIGN_RIGHT != data_alignment) {
|
||||||
/* MSB alignment */
|
/* MSB alignment */
|
||||||
ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
|
ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
|
||||||
@@ -175,8 +171,7 @@ void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_enable(uint32_t adc_periph)
|
void adc_enable(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
if (RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)) {
|
if (RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)) {
|
||||||
/* enable ADC */
|
/* enable ADC */
|
||||||
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
|
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
|
||||||
@@ -189,8 +184,7 @@ void adc_enable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_disable(uint32_t adc_periph)
|
void adc_disable(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
/* disable ADC */
|
/* disable ADC */
|
||||||
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
|
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
|
||||||
}
|
}
|
||||||
@@ -201,18 +195,15 @@ void adc_disable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_calibration_enable(uint32_t adc_periph)
|
void adc_calibration_enable(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
/* reset the selected ADC1 calibration registers */
|
/* reset the selected ADC1 calibration registers */
|
||||||
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_RSTCLB;
|
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_RSTCLB;
|
||||||
/* check the RSTCLB bit state */
|
/* check the RSTCLB bit state */
|
||||||
while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
|
while (RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)) {}
|
||||||
}
|
|
||||||
/* enable ADC calibration process */
|
/* enable ADC calibration process */
|
||||||
ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
|
ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
|
||||||
/* check the CLB bit state */
|
/* check the CLB bit state */
|
||||||
while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
|
while (RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -221,8 +212,7 @@ void adc_calibration_enable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_tempsensor_vrefint_enable(void)
|
void adc_tempsensor_vrefint_enable(void) {
|
||||||
{
|
|
||||||
/* enable the temperature sensor and Vrefint channel */
|
/* enable the temperature sensor and Vrefint channel */
|
||||||
ADC_CTL1(ADC0) |= ADC_CTL1_TSVREN;
|
ADC_CTL1(ADC0) |= ADC_CTL1_TSVREN;
|
||||||
}
|
}
|
||||||
@@ -233,8 +223,7 @@ void adc_tempsensor_vrefint_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_tempsensor_vrefint_disable(void)
|
void adc_tempsensor_vrefint_disable(void) {
|
||||||
{
|
|
||||||
/* disable the temperature sensor and Vrefint channel */
|
/* disable the temperature sensor and Vrefint channel */
|
||||||
ADC_CTL1(ADC0) &= ~ADC_CTL1_TSVREN;
|
ADC_CTL1(ADC0) &= ~ADC_CTL1_TSVREN;
|
||||||
}
|
}
|
||||||
@@ -245,8 +234,7 @@ void adc_tempsensor_vrefint_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_dma_mode_enable(uint32_t adc_periph)
|
void adc_dma_mode_enable(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
/* enable DMA request */
|
/* enable DMA request */
|
||||||
ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
|
ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
|
||||||
}
|
}
|
||||||
@@ -257,8 +245,7 @@ void adc_dma_mode_enable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_dma_mode_disable(uint32_t adc_periph)
|
void adc_dma_mode_disable(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
/* disable DMA request */
|
/* disable DMA request */
|
||||||
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
|
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
|
||||||
}
|
}
|
||||||
@@ -276,8 +263,7 @@ void adc_dma_mode_disable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_group, uint8_t length)
|
void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_group, uint8_t length) {
|
||||||
{
|
|
||||||
/* disable discontinuous mode of regular & inserted channel */
|
/* disable discontinuous mode of regular & inserted channel */
|
||||||
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISRC | ADC_CTL0_DISIC));
|
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISRC | ADC_CTL0_DISIC));
|
||||||
switch (adc_channel_group) {
|
switch (adc_channel_group) {
|
||||||
@@ -312,8 +298,7 @@ void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_grou
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t length)
|
void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t length) {
|
||||||
{
|
|
||||||
switch (adc_channel_group) {
|
switch (adc_channel_group) {
|
||||||
case ADC_REGULAR_CHANNEL:
|
case ADC_REGULAR_CHANNEL:
|
||||||
/* configure the length of regular channel group */
|
/* configure the length of regular channel group */
|
||||||
@@ -350,8 +335,7 @@ void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
|
void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time) {
|
||||||
{
|
|
||||||
uint32_t rsq, sampt;
|
uint32_t rsq, sampt;
|
||||||
|
|
||||||
/* ADC regular sequence config */
|
/* ADC regular sequence config */
|
||||||
@@ -418,8 +402,7 @@ void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_c
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
|
void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time) {
|
||||||
{
|
|
||||||
uint8_t inserted_length;
|
uint8_t inserted_length;
|
||||||
uint32_t isq, sampt;
|
uint32_t isq, sampt;
|
||||||
/* get inserted channel group length */
|
/* get inserted channel group length */
|
||||||
@@ -462,8 +445,7 @@ void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_channel, uint16_t offset)
|
void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_channel, uint16_t offset) {
|
||||||
{
|
|
||||||
uint8_t inserted_length;
|
uint8_t inserted_length;
|
||||||
uint32_t num = 0U;
|
uint32_t num = 0U;
|
||||||
|
|
||||||
@@ -508,8 +490,7 @@ void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_ch
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t external_trigger_source)
|
void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t external_trigger_source) {
|
||||||
{
|
|
||||||
switch (adc_channel_group) {
|
switch (adc_channel_group) {
|
||||||
case ADC_REGULAR_CHANNEL:
|
case ADC_REGULAR_CHANNEL:
|
||||||
/* configure ADC regular group external trigger source */
|
/* configure ADC regular group external trigger source */
|
||||||
@@ -537,8 +518,7 @@ void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group, ControlStatus newvalue)
|
void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group, ControlStatus newvalue) {
|
||||||
{
|
|
||||||
if (newvalue) {
|
if (newvalue) {
|
||||||
if (0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
|
if (0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
|
||||||
/* enable ADC regular channel group external trigger */
|
/* enable ADC regular channel group external trigger */
|
||||||
@@ -570,8 +550,7 @@ void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group)
|
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group) {
|
||||||
{
|
|
||||||
if (0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
|
if (0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
|
||||||
/* enable ADC regular channel group software trigger */
|
/* enable ADC regular channel group software trigger */
|
||||||
ADC_CTL1(adc_periph) |= ADC_CTL1_SWRCST;
|
ADC_CTL1(adc_periph) |= ADC_CTL1_SWRCST;
|
||||||
@@ -589,10 +568,7 @@ void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval the conversion value
|
\retval the conversion value
|
||||||
*/
|
*/
|
||||||
uint16_t adc_regular_data_read(uint32_t adc_periph)
|
uint16_t adc_regular_data_read(uint32_t adc_periph) { return (uint16_t)(ADC_RDATA(adc_periph)); }
|
||||||
{
|
|
||||||
return (uint16_t)(ADC_RDATA(adc_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief read ADC inserted group data register
|
\brief read ADC inserted group data register
|
||||||
@@ -606,8 +582,7 @@ uint16_t adc_regular_data_read(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval the conversion value
|
\retval the conversion value
|
||||||
*/
|
*/
|
||||||
uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel)
|
uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel) {
|
||||||
{
|
|
||||||
uint32_t idata;
|
uint32_t idata;
|
||||||
/* read the data of the selected channel */
|
/* read the data of the selected channel */
|
||||||
switch (inserted_channel) {
|
switch (inserted_channel) {
|
||||||
@@ -640,13 +615,11 @@ uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval the conversion value
|
\retval the conversion value
|
||||||
*/
|
*/
|
||||||
uint32_t adc_sync_mode_convert_value_read(void)
|
uint32_t adc_sync_mode_convert_value_read(void) {
|
||||||
{
|
|
||||||
/* return conversion value */
|
/* return conversion value */
|
||||||
return ADC_RDATA(ADC0);
|
return ADC_RDATA(ADC0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure ADC analog watchdog single channel
|
\brief configure ADC analog watchdog single channel
|
||||||
\param[in] adc_periph: ADCx, x=0,1
|
\param[in] adc_periph: ADCx, x=0,1
|
||||||
@@ -656,8 +629,7 @@ uint32_t adc_sync_mode_convert_value_read(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel)
|
void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel) {
|
||||||
{
|
|
||||||
ADC_CTL0(adc_periph) &= (uint32_t) ~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
|
ADC_CTL0(adc_periph) &= (uint32_t) ~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
|
||||||
/* analog watchdog channel select */
|
/* analog watchdog channel select */
|
||||||
ADC_CTL0(adc_periph) |= (uint32_t)adc_channel;
|
ADC_CTL0(adc_periph) |= (uint32_t)adc_channel;
|
||||||
@@ -675,8 +647,7 @@ void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_group)
|
void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_group) {
|
||||||
{
|
|
||||||
ADC_CTL0(adc_periph) &= (uint32_t) ~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
|
ADC_CTL0(adc_periph) &= (uint32_t) ~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
|
||||||
/* select the group */
|
/* select the group */
|
||||||
switch (adc_channel_group) {
|
switch (adc_channel_group) {
|
||||||
@@ -703,10 +674,7 @@ void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_watchdog_disable(uint32_t adc_periph)
|
void adc_watchdog_disable(uint32_t adc_periph) { ADC_CTL0(adc_periph) &= (uint32_t) ~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL); }
|
||||||
{
|
|
||||||
ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure ADC analog watchdog threshold
|
\brief configure ADC analog watchdog threshold
|
||||||
@@ -716,8 +684,7 @@ void adc_watchdog_disable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold, uint16_t high_threshold)
|
void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold, uint16_t high_threshold) {
|
||||||
{
|
|
||||||
ADC_WDLT(adc_periph) = (uint32_t)WDLT_WDLT(low_threshold);
|
ADC_WDLT(adc_periph) = (uint32_t)WDLT_WDLT(low_threshold);
|
||||||
ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
|
ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
|
||||||
}
|
}
|
||||||
@@ -735,8 +702,7 @@ void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag)
|
FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag) {
|
||||||
{
|
|
||||||
FlagStatus reval = RESET;
|
FlagStatus reval = RESET;
|
||||||
if (ADC_STAT(adc_periph) & adc_flag) {
|
if (ADC_STAT(adc_periph) & adc_flag) {
|
||||||
reval = SET;
|
reval = SET;
|
||||||
@@ -757,10 +723,7 @@ FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag)
|
void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag) { ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag); }
|
||||||
{
|
|
||||||
ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the bit state of ADCx software start conversion
|
\brief get the bit state of ADCx software start conversion
|
||||||
@@ -769,8 +732,7 @@ void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph)
|
FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
FlagStatus reval = RESET;
|
FlagStatus reval = RESET;
|
||||||
if ((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWRCST)) {
|
if ((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWRCST)) {
|
||||||
reval = SET;
|
reval = SET;
|
||||||
@@ -785,8 +747,7 @@ FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph)
|
FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph) {
|
||||||
{
|
|
||||||
FlagStatus reval = RESET;
|
FlagStatus reval = RESET;
|
||||||
if ((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWICST)) {
|
if ((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWICST)) {
|
||||||
reval = SET;
|
reval = SET;
|
||||||
@@ -805,8 +766,7 @@ FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
|
FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt) {
|
||||||
{
|
|
||||||
FlagStatus interrupt_flag = RESET;
|
FlagStatus interrupt_flag = RESET;
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
/* check the interrupt bits */
|
/* check the interrupt bits */
|
||||||
@@ -849,10 +809,7 @@ FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
|
void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt) { ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt); }
|
||||||
{
|
|
||||||
ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable ADC interrupt
|
\brief enable ADC interrupt
|
||||||
@@ -865,8 +822,7 @@ void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
|
void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt) {
|
||||||
{
|
|
||||||
/* enable ADC analog watchdog interrupt */
|
/* enable ADC analog watchdog interrupt */
|
||||||
if (0U != (adc_interrupt & ADC_INT_WDE)) {
|
if (0U != (adc_interrupt & ADC_INT_WDE)) {
|
||||||
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_WDEIE;
|
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_WDEIE;
|
||||||
@@ -892,8 +848,7 @@ void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt)
|
void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt) {
|
||||||
{
|
|
||||||
/* disable ADC analog watchdog interrupt */
|
/* disable ADC analog watchdog interrupt */
|
||||||
if (0U != (adc_interrupt & ADC_INT_WDE)) {
|
if (0U != (adc_interrupt & ADC_INT_WDE)) {
|
||||||
ADC_CTL0(adc_periph) &= ~(uint32_t)ADC_CTL0_WDEIE;
|
ADC_CTL0(adc_periph) &= ~(uint32_t)ADC_CTL0_WDEIE;
|
||||||
@@ -920,8 +875,7 @@ void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_resolution_config(uint32_t adc_periph, uint32_t resolution)
|
void adc_resolution_config(uint32_t adc_periph, uint32_t resolution) {
|
||||||
{
|
|
||||||
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_DRES);
|
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_DRES);
|
||||||
ADC_OVSCR(adc_periph) |= (uint32_t)resolution;
|
ADC_OVSCR(adc_periph) |= (uint32_t)resolution;
|
||||||
}
|
}
|
||||||
@@ -959,8 +913,7 @@ void adc_resolution_config(uint32_t adc_periph, uint32_t resolution)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shift,uint8_t ratio)
|
void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shift, uint8_t ratio) {
|
||||||
{
|
|
||||||
if (mode) {
|
if (mode) {
|
||||||
ADC_OVSCR(adc_periph) |= (uint32_t)ADC_OVSCR_TOVS;
|
ADC_OVSCR(adc_periph) |= (uint32_t)ADC_OVSCR_TOVS;
|
||||||
} else {
|
} else {
|
||||||
@@ -977,10 +930,7 @@ void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shif
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_oversample_mode_enable(uint32_t adc_periph)
|
void adc_oversample_mode_enable(uint32_t adc_periph) { ADC_OVSCR(adc_periph) |= ADC_OVSCR_OVSEN; }
|
||||||
{
|
|
||||||
ADC_OVSCR(adc_periph) |= ADC_OVSCR_OVSEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable ADC oversample mode
|
\brief disable ADC oversample mode
|
||||||
@@ -988,7 +938,4 @@ void adc_oversample_mode_enable(uint32_t adc_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void adc_oversample_mode_disable(uint32_t adc_periph)
|
void adc_oversample_mode_disable(uint32_t adc_periph) { ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_OVSEN); }
|
||||||
{
|
|
||||||
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_OVSEN);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_deinit(void)
|
void bkp_deinit(void) {
|
||||||
{
|
|
||||||
/* reset BKP domain register*/
|
/* reset BKP domain register*/
|
||||||
rcu_bkp_reset_enable();
|
rcu_bkp_reset_enable();
|
||||||
rcu_bkp_reset_disable();
|
rcu_bkp_reset_disable();
|
||||||
@@ -59,8 +58,7 @@ void bkp_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_data_write(bkp_data_register_enum register_number, uint16_t data)
|
void bkp_data_write(bkp_data_register_enum register_number, uint16_t data) {
|
||||||
{
|
|
||||||
if ((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)) {
|
if ((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)) {
|
||||||
BKP_DATA10_41(register_number - 1U) = data;
|
BKP_DATA10_41(register_number - 1U) = data;
|
||||||
} else if ((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)) {
|
} else if ((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)) {
|
||||||
@@ -78,8 +76,7 @@ void bkp_data_write(bkp_data_register_enum register_number, uint16_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval data of BKP data register
|
\retval data of BKP data register
|
||||||
*/
|
*/
|
||||||
uint16_t bkp_data_read(bkp_data_register_enum register_number)
|
uint16_t bkp_data_read(bkp_data_register_enum register_number) {
|
||||||
{
|
|
||||||
uint16_t data = 0U;
|
uint16_t data = 0U;
|
||||||
|
|
||||||
/* get the data from the BKP data register */
|
/* get the data from the BKP data register */
|
||||||
@@ -99,10 +96,7 @@ uint16_t bkp_data_read(bkp_data_register_enum register_number)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_calibration_output_enable(void)
|
void bkp_rtc_calibration_output_enable(void) { BKP_OCTL |= (uint16_t)BKP_OCTL_COEN; }
|
||||||
{
|
|
||||||
BKP_OCTL |= (uint16_t)BKP_OCTL_COEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable RTC clock calibration output
|
\brief disable RTC clock calibration output
|
||||||
@@ -110,10 +104,7 @@ void bkp_rtc_calibration_output_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_calibration_output_disable(void)
|
void bkp_rtc_calibration_output_disable(void) { BKP_OCTL &= (uint16_t)~BKP_OCTL_COEN; }
|
||||||
{
|
|
||||||
BKP_OCTL &= (uint16_t)~BKP_OCTL_COEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable RTC alarm or second signal output
|
\brief enable RTC alarm or second signal output
|
||||||
@@ -121,10 +112,7 @@ void bkp_rtc_calibration_output_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_signal_output_enable(void)
|
void bkp_rtc_signal_output_enable(void) { BKP_OCTL |= (uint16_t)BKP_OCTL_ASOEN; }
|
||||||
{
|
|
||||||
BKP_OCTL |= (uint16_t)BKP_OCTL_ASOEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable RTC alarm or second signal output
|
\brief disable RTC alarm or second signal output
|
||||||
@@ -132,10 +120,7 @@ void bkp_rtc_signal_output_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_signal_output_disable(void)
|
void bkp_rtc_signal_output_disable(void) { BKP_OCTL &= (uint16_t)~BKP_OCTL_ASOEN; }
|
||||||
{
|
|
||||||
BKP_OCTL &= (uint16_t)~BKP_OCTL_ASOEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief select RTC output
|
\brief select RTC output
|
||||||
@@ -146,8 +131,7 @@ void bkp_rtc_signal_output_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_output_select(uint16_t outputsel)
|
void bkp_rtc_output_select(uint16_t outputsel) {
|
||||||
{
|
|
||||||
uint16_t ctl = 0U;
|
uint16_t ctl = 0U;
|
||||||
|
|
||||||
/* configure BKP_OCTL_ROSEL with outputsel */
|
/* configure BKP_OCTL_ROSEL with outputsel */
|
||||||
@@ -164,8 +148,7 @@ void bkp_rtc_output_select(uint16_t outputsel)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_rtc_calibration_value_set(uint8_t value)
|
void bkp_rtc_calibration_value_set(uint8_t value) {
|
||||||
{
|
|
||||||
uint16_t ctl;
|
uint16_t ctl;
|
||||||
|
|
||||||
/* configure BKP_OCTL_RCCV with value */
|
/* configure BKP_OCTL_RCCV with value */
|
||||||
@@ -181,10 +164,7 @@ void bkp_rtc_calibration_value_set(uint8_t value)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_tamper_detection_enable(void)
|
void bkp_tamper_detection_enable(void) { BKP_TPCTL |= (uint16_t)BKP_TPCTL_TPEN; }
|
||||||
{
|
|
||||||
BKP_TPCTL |= (uint16_t)BKP_TPCTL_TPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable tamper detection
|
\brief disable tamper detection
|
||||||
@@ -192,10 +172,7 @@ void bkp_tamper_detection_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_tamper_detection_disable(void)
|
void bkp_tamper_detection_disable(void) { BKP_TPCTL &= (uint16_t)~BKP_TPCTL_TPEN; }
|
||||||
{
|
|
||||||
BKP_TPCTL &= (uint16_t)~BKP_TPCTL_TPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set tamper pin active level
|
\brief set tamper pin active level
|
||||||
@@ -206,8 +183,7 @@ void bkp_tamper_detection_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_tamper_active_level_set(uint16_t level)
|
void bkp_tamper_active_level_set(uint16_t level) {
|
||||||
{
|
|
||||||
uint16_t ctl = 0U;
|
uint16_t ctl = 0U;
|
||||||
|
|
||||||
/* configure BKP_TPCTL_TPAL with level */
|
/* configure BKP_TPCTL_TPAL with level */
|
||||||
@@ -223,10 +199,7 @@ void bkp_tamper_active_level_set(uint16_t level)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_interrupt_enable(void)
|
void bkp_interrupt_enable(void) { BKP_TPCS |= (uint16_t)BKP_TPCS_TPIE; }
|
||||||
{
|
|
||||||
BKP_TPCS |= (uint16_t)BKP_TPCS_TPIE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable tamper interrupt
|
\brief disable tamper interrupt
|
||||||
@@ -234,10 +207,7 @@ void bkp_interrupt_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_interrupt_disable(void)
|
void bkp_interrupt_disable(void) { BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE; }
|
||||||
{
|
|
||||||
BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get tamper flag state
|
\brief get tamper flag state
|
||||||
@@ -245,8 +215,7 @@ void bkp_interrupt_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus bkp_flag_get(void)
|
FlagStatus bkp_flag_get(void) {
|
||||||
{
|
|
||||||
if (RESET != (BKP_TPCS & BKP_FLAG_TAMPER)) {
|
if (RESET != (BKP_TPCS & BKP_FLAG_TAMPER)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -260,10 +229,7 @@ FlagStatus bkp_flag_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_flag_clear(void)
|
void bkp_flag_clear(void) { BKP_TPCS |= (uint16_t)(BKP_FLAG_TAMPER >> BKP_TAMPER_BITS_OFFSET); }
|
||||||
{
|
|
||||||
BKP_TPCS |= (uint16_t)(BKP_FLAG_TAMPER >> BKP_TAMPER_BITS_OFFSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get tamper interrupt flag state
|
\brief get tamper interrupt flag state
|
||||||
@@ -271,8 +237,7 @@ void bkp_flag_clear(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus bkp_interrupt_flag_get(void)
|
FlagStatus bkp_interrupt_flag_get(void) {
|
||||||
{
|
|
||||||
if (RESET != (BKP_TPCS & BKP_INT_FLAG_TAMPER)) {
|
if (RESET != (BKP_TPCS & BKP_INT_FLAG_TAMPER)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -286,7 +251,4 @@ FlagStatus bkp_interrupt_flag_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void bkp_interrupt_flag_clear(void)
|
void bkp_interrupt_flag_clear(void) { BKP_TPCS |= (uint16_t)(BKP_INT_FLAG_TAMPER >> BKP_TAMPER_BITS_OFFSET); }
|
||||||
{
|
|
||||||
BKP_TPCS |= (uint16_t)(BKP_INT_FLAG_TAMPER >> BKP_TAMPER_BITS_OFFSET);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "gd32vf103_can.h"
|
#include "gd32vf103_can.h"
|
||||||
|
|
||||||
#define CAN_ERROR_HANDLE(s) do{}while(1)
|
#define CAN_ERROR_HANDLE(s) \
|
||||||
|
do { \
|
||||||
|
} while (1)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief deinitialize CAN
|
\brief deinitialize CAN
|
||||||
@@ -43,8 +45,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_deinit(uint32_t can_periph)
|
void can_deinit(uint32_t can_periph) {
|
||||||
{
|
|
||||||
if (CAN0 == can_periph) {
|
if (CAN0 == can_periph) {
|
||||||
rcu_periph_reset_enable(RCU_CAN0RST);
|
rcu_periph_reset_enable(RCU_CAN0RST);
|
||||||
rcu_periph_reset_disable(RCU_CAN0RST);
|
rcu_periph_reset_disable(RCU_CAN0RST);
|
||||||
@@ -66,8 +67,7 @@ void can_deinit(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_struct_para_init(can_struct_type_enum type, void* p_struct)
|
void can_struct_para_init(can_struct_type_enum type, void *p_struct) {
|
||||||
{
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
/* get type of the struct */
|
/* get type of the struct */
|
||||||
@@ -152,8 +152,7 @@ void can_struct_para_init(can_struct_type_enum type, void* p_struct)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ErrStatus: SUCCESS or ERROR
|
\retval ErrStatus: SUCCESS or ERROR
|
||||||
*/
|
*/
|
||||||
ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init)
|
ErrStatus can_init(uint32_t can_periph, can_parameter_struct *can_parameter_init) {
|
||||||
{
|
|
||||||
uint32_t timeout = CAN_TIMEOUT;
|
uint32_t timeout = CAN_TIMEOUT;
|
||||||
ErrStatus flag = ERROR;
|
ErrStatus flag = ERROR;
|
||||||
|
|
||||||
@@ -170,11 +169,8 @@ ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init
|
|||||||
flag = ERROR;
|
flag = ERROR;
|
||||||
} else {
|
} else {
|
||||||
/* set the bit timing register */
|
/* set the bit timing register */
|
||||||
CAN_BT(can_periph) = (BT_MODE((uint32_t)can_parameter_init->working_mode) | \
|
CAN_BT(can_periph) = (BT_MODE((uint32_t)can_parameter_init->working_mode) | BT_SJW((uint32_t)can_parameter_init->resync_jump_width) | BT_BS1((uint32_t)can_parameter_init->time_segment_1)
|
||||||
BT_SJW((uint32_t)can_parameter_init->resync_jump_width) | \
|
| BT_BS2((uint32_t)can_parameter_init->time_segment_2) | BT_BAUDPSC(((uint32_t)(can_parameter_init->prescaler) - 1U)));
|
||||||
BT_BS1((uint32_t)can_parameter_init->time_segment_1) | \
|
|
||||||
BT_BS2((uint32_t)can_parameter_init->time_segment_2) | \
|
|
||||||
BT_BAUDPSC(((uint32_t)(can_parameter_init->prescaler) - 1U)));
|
|
||||||
|
|
||||||
/* time trigger communication mode */
|
/* time trigger communication mode */
|
||||||
if (ENABLE == can_parameter_init->time_triggered) {
|
if (ENABLE == can_parameter_init->time_triggered) {
|
||||||
@@ -255,8 +251,7 @@ ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
|
void can_filter_init(can_filter_parameter_struct *can_filter_parameter_init) {
|
||||||
{
|
|
||||||
uint32_t val = 0U;
|
uint32_t val = 0U;
|
||||||
|
|
||||||
val = ((uint32_t)1) << (can_filter_parameter_init->filter_number);
|
val = ((uint32_t)1) << (can_filter_parameter_init->filter_number);
|
||||||
@@ -270,26 +265,22 @@ void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
|
|||||||
/* set filter 16 bits */
|
/* set filter 16 bits */
|
||||||
CAN_FSCFG(CAN0) &= ~(uint32_t)val;
|
CAN_FSCFG(CAN0) &= ~(uint32_t)val;
|
||||||
/* first 16 bits list and first 16 bits mask or first 16 bits list and second 16 bits list */
|
/* first 16 bits list and first 16 bits mask or first 16 bits list and second 16 bits list */
|
||||||
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number) = \
|
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number)
|
||||||
FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS) | \
|
= FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS) | FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
|
||||||
FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
|
|
||||||
/* second 16 bits list and second 16 bits mask or third 16 bits list and fourth 16 bits list */
|
/* second 16 bits list and second 16 bits mask or third 16 bits list and fourth 16 bits list */
|
||||||
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number) = \
|
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number)
|
||||||
FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) | \
|
= FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) | FDATA_MASK_LOW((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS);
|
||||||
FDATA_MASK_LOW((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS);
|
|
||||||
}
|
}
|
||||||
/* filter 32 bits */
|
/* filter 32 bits */
|
||||||
if (CAN_FILTERBITS_32BIT == can_filter_parameter_init->filter_bits) {
|
if (CAN_FILTERBITS_32BIT == can_filter_parameter_init->filter_bits) {
|
||||||
/* set filter 32 bits */
|
/* set filter 32 bits */
|
||||||
CAN_FSCFG(CAN0) |= (uint32_t)val;
|
CAN_FSCFG(CAN0) |= (uint32_t)val;
|
||||||
/* 32 bits list or first 32 bits list */
|
/* 32 bits list or first 32 bits list */
|
||||||
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number) = \
|
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number)
|
||||||
FDATA_MASK_HIGH((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS) |
|
= FDATA_MASK_HIGH((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS) | FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
|
||||||
FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
|
|
||||||
/* 32 bits mask or second 32 bits list */
|
/* 32 bits mask or second 32 bits list */
|
||||||
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number) = \
|
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number)
|
||||||
FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) |
|
= FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) | FDATA_MASK_LOW((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS);
|
||||||
FDATA_MASK_LOW((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* filter mode */
|
/* filter mode */
|
||||||
@@ -328,8 +319,7 @@ void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can1_filter_start_bank(uint8_t start_bank)
|
void can1_filter_start_bank(uint8_t start_bank) {
|
||||||
{
|
|
||||||
/* filter lock disable */
|
/* filter lock disable */
|
||||||
CAN_FCTL(CAN0) |= CAN_FCTL_FLD;
|
CAN_FCTL(CAN0) |= CAN_FCTL_FLD;
|
||||||
/* set CAN1 filter start number */
|
/* set CAN1 filter start number */
|
||||||
@@ -346,8 +336,7 @@ void can1_filter_start_bank(uint8_t start_bank)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_debug_freeze_enable(uint32_t can_periph)
|
void can_debug_freeze_enable(uint32_t can_periph) {
|
||||||
{
|
|
||||||
/* set DFZ bit */
|
/* set DFZ bit */
|
||||||
CAN_CTL(can_periph) |= CAN_CTL_DFZ;
|
CAN_CTL(can_periph) |= CAN_CTL_DFZ;
|
||||||
if (CAN0 == can_periph) {
|
if (CAN0 == can_periph) {
|
||||||
@@ -364,8 +353,7 @@ void can_debug_freeze_enable(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_debug_freeze_disable(uint32_t can_periph)
|
void can_debug_freeze_disable(uint32_t can_periph) {
|
||||||
{
|
|
||||||
/* set DFZ bit */
|
/* set DFZ bit */
|
||||||
CAN_CTL(can_periph) &= ~CAN_CTL_DFZ;
|
CAN_CTL(can_periph) &= ~CAN_CTL_DFZ;
|
||||||
if (CAN0 == can_periph) {
|
if (CAN0 == can_periph) {
|
||||||
@@ -382,8 +370,7 @@ void can_debug_freeze_disable(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_time_trigger_mode_enable(uint32_t can_periph)
|
void can_time_trigger_mode_enable(uint32_t can_periph) {
|
||||||
{
|
|
||||||
uint8_t mailbox_number;
|
uint8_t mailbox_number;
|
||||||
|
|
||||||
/* enable the tcc mode */
|
/* enable the tcc mode */
|
||||||
@@ -401,8 +388,7 @@ void can_time_trigger_mode_enable(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_time_trigger_mode_disable(uint32_t can_periph)
|
void can_time_trigger_mode_disable(uint32_t can_periph) {
|
||||||
{
|
|
||||||
uint8_t mailbox_number;
|
uint8_t mailbox_number;
|
||||||
|
|
||||||
/* disable the TCC mode */
|
/* disable the TCC mode */
|
||||||
@@ -427,8 +413,7 @@ void can_time_trigger_mode_disable(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval mailbox_number
|
\retval mailbox_number
|
||||||
*/
|
*/
|
||||||
uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message)
|
uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct *transmit_message) {
|
||||||
{
|
|
||||||
uint8_t mailbox_number = CAN_MAILBOX0;
|
uint8_t mailbox_number = CAN_MAILBOX0;
|
||||||
|
|
||||||
/* select one empty mailbox */
|
/* select one empty mailbox */
|
||||||
@@ -449,26 +434,19 @@ uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* t
|
|||||||
CAN_TMI(can_periph, mailbox_number) &= CAN_TMI_TEN;
|
CAN_TMI(can_periph, mailbox_number) &= CAN_TMI_TEN;
|
||||||
if (CAN_FF_STANDARD == transmit_message->tx_ff) {
|
if (CAN_FF_STANDARD == transmit_message->tx_ff) {
|
||||||
/* set transmit mailbox standard identifier */
|
/* set transmit mailbox standard identifier */
|
||||||
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_SFID(transmit_message->tx_sfid) | \
|
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_SFID(transmit_message->tx_sfid) | transmit_message->tx_ft);
|
||||||
transmit_message->tx_ft);
|
|
||||||
} else {
|
} else {
|
||||||
/* set transmit mailbox extended identifier */
|
/* set transmit mailbox extended identifier */
|
||||||
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_EFID(transmit_message->tx_efid) | \
|
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_EFID(transmit_message->tx_efid) | transmit_message->tx_ff | transmit_message->tx_ft);
|
||||||
transmit_message->tx_ff | \
|
|
||||||
transmit_message->tx_ft);
|
|
||||||
}
|
}
|
||||||
/* set the data length */
|
/* set the data length */
|
||||||
CAN_TMP(can_periph, mailbox_number) &= ~CAN_TMP_DLENC;
|
CAN_TMP(can_periph, mailbox_number) &= ~CAN_TMP_DLENC;
|
||||||
CAN_TMP(can_periph, mailbox_number) |= transmit_message->tx_dlen;
|
CAN_TMP(can_periph, mailbox_number) |= transmit_message->tx_dlen;
|
||||||
/* set the data */
|
/* set the data */
|
||||||
CAN_TMDATA0(can_periph, mailbox_number) = TMDATA0_DB3(transmit_message->tx_data[3]) | \
|
CAN_TMDATA0(can_periph, mailbox_number)
|
||||||
TMDATA0_DB2(transmit_message->tx_data[2]) | \
|
= TMDATA0_DB3(transmit_message->tx_data[3]) | TMDATA0_DB2(transmit_message->tx_data[2]) | TMDATA0_DB1(transmit_message->tx_data[1]) | TMDATA0_DB0(transmit_message->tx_data[0]);
|
||||||
TMDATA0_DB1(transmit_message->tx_data[1]) | \
|
CAN_TMDATA1(can_periph, mailbox_number)
|
||||||
TMDATA0_DB0(transmit_message->tx_data[0]);
|
= TMDATA1_DB7(transmit_message->tx_data[7]) | TMDATA1_DB6(transmit_message->tx_data[6]) | TMDATA1_DB5(transmit_message->tx_data[5]) | TMDATA1_DB4(transmit_message->tx_data[4]);
|
||||||
CAN_TMDATA1(can_periph, mailbox_number) = TMDATA1_DB7(transmit_message->tx_data[7]) | \
|
|
||||||
TMDATA1_DB6(transmit_message->tx_data[6]) | \
|
|
||||||
TMDATA1_DB5(transmit_message->tx_data[5]) | \
|
|
||||||
TMDATA1_DB4(transmit_message->tx_data[4]);
|
|
||||||
/* enable transmission */
|
/* enable transmission */
|
||||||
CAN_TMI(can_periph, mailbox_number) |= CAN_TMI_TEN;
|
CAN_TMI(can_periph, mailbox_number) |= CAN_TMI_TEN;
|
||||||
|
|
||||||
@@ -485,8 +463,7 @@ uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval can_transmit_state_enum
|
\retval can_transmit_state_enum
|
||||||
*/
|
*/
|
||||||
can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox_number)
|
can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox_number) {
|
||||||
{
|
|
||||||
can_transmit_state_enum state = CAN_TRANSMIT_FAILED;
|
can_transmit_state_enum state = CAN_TRANSMIT_FAILED;
|
||||||
uint32_t val = 0U;
|
uint32_t val = 0U;
|
||||||
|
|
||||||
@@ -544,20 +521,16 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
|
void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number) {
|
||||||
{
|
|
||||||
if (CAN_MAILBOX0 == mailbox_number) {
|
if (CAN_MAILBOX0 == mailbox_number) {
|
||||||
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST0;
|
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST0;
|
||||||
while(CAN_TSTAT_MST0 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST0)){
|
while (CAN_TSTAT_MST0 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST0)) {}
|
||||||
}
|
|
||||||
} else if (CAN_MAILBOX1 == mailbox_number) {
|
} else if (CAN_MAILBOX1 == mailbox_number) {
|
||||||
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST1;
|
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST1;
|
||||||
while(CAN_TSTAT_MST1 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST1)){
|
while (CAN_TSTAT_MST1 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST1)) {}
|
||||||
}
|
|
||||||
} else if (CAN_MAILBOX2 == mailbox_number) {
|
} else if (CAN_MAILBOX2 == mailbox_number) {
|
||||||
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST2;
|
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST2;
|
||||||
while(CAN_TSTAT_MST2 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST2)){
|
while (CAN_TSTAT_MST2 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST2)) {}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* illegal parameters */
|
/* illegal parameters */
|
||||||
}
|
}
|
||||||
@@ -579,8 +552,7 @@ void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
|
|||||||
\arg rx_fi: 0 - 27
|
\arg rx_fi: 0 - 27
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct* receive_message)
|
void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct *receive_message) {
|
||||||
{
|
|
||||||
/* get the frame format */
|
/* get the frame format */
|
||||||
receive_message->rx_ff = (uint8_t)(CAN_RFIFOMI_FF & CAN_RFIFOMI(can_periph, fifo_number));
|
receive_message->rx_ff = (uint8_t)(CAN_RFIFOMI_FF & CAN_RFIFOMI(can_periph, fifo_number));
|
||||||
if (CAN_FF_STANDARD == receive_message->rx_ff) {
|
if (CAN_FF_STANDARD == receive_message->rx_ff) {
|
||||||
@@ -626,8 +598,7 @@ void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_m
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
|
void can_fifo_release(uint32_t can_periph, uint8_t fifo_number) {
|
||||||
{
|
|
||||||
if (CAN_FIFO0 == fifo_number) {
|
if (CAN_FIFO0 == fifo_number) {
|
||||||
CAN_RFIFO0(can_periph) |= CAN_RFIFO0_RFD0;
|
CAN_RFIFO0(can_periph) |= CAN_RFIFO0_RFD0;
|
||||||
} else if (CAN_FIFO1 == fifo_number) {
|
} else if (CAN_FIFO1 == fifo_number) {
|
||||||
@@ -648,8 +619,7 @@ void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval message length
|
\retval message length
|
||||||
*/
|
*/
|
||||||
uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number)
|
uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number) {
|
||||||
{
|
|
||||||
uint8_t val = 0U;
|
uint8_t val = 0U;
|
||||||
|
|
||||||
if (CAN_FIFO0 == fifo_number) {
|
if (CAN_FIFO0 == fifo_number) {
|
||||||
@@ -676,8 +646,7 @@ uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ErrStatus: SUCCESS or ERROR
|
\retval ErrStatus: SUCCESS or ERROR
|
||||||
*/
|
*/
|
||||||
ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
|
ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode) {
|
||||||
{
|
|
||||||
ErrStatus flag = ERROR;
|
ErrStatus flag = ERROR;
|
||||||
/* timeout for IWS or also for SLPWS bits */
|
/* timeout for IWS or also for SLPWS bits */
|
||||||
uint32_t timeout = CAN_TIMEOUT;
|
uint32_t timeout = CAN_TIMEOUT;
|
||||||
@@ -735,8 +704,7 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ErrStatus: SUCCESS or ERROR
|
\retval ErrStatus: SUCCESS or ERROR
|
||||||
*/
|
*/
|
||||||
ErrStatus can_wakeup(uint32_t can_periph)
|
ErrStatus can_wakeup(uint32_t can_periph) {
|
||||||
{
|
|
||||||
ErrStatus flag = ERROR;
|
ErrStatus flag = ERROR;
|
||||||
uint32_t timeout = CAN_TIMEOUT;
|
uint32_t timeout = CAN_TIMEOUT;
|
||||||
|
|
||||||
@@ -770,8 +738,7 @@ ErrStatus can_wakeup(uint32_t can_periph)
|
|||||||
\arg CAN_ERROR_CRC: CRC error
|
\arg CAN_ERROR_CRC: CRC error
|
||||||
\arg CAN_ERROR_SOFTWARECFG: software configure
|
\arg CAN_ERROR_SOFTWARECFG: software configure
|
||||||
*/
|
*/
|
||||||
can_error_enum can_error_get(uint32_t can_periph)
|
can_error_enum can_error_get(uint32_t can_periph) {
|
||||||
{
|
|
||||||
can_error_enum error;
|
can_error_enum error;
|
||||||
error = CAN_ERROR_NONE;
|
error = CAN_ERROR_NONE;
|
||||||
|
|
||||||
@@ -787,8 +754,7 @@ can_error_enum can_error_get(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval error number
|
\retval error number
|
||||||
*/
|
*/
|
||||||
uint8_t can_receive_error_number_get(uint32_t can_periph)
|
uint8_t can_receive_error_number_get(uint32_t can_periph) {
|
||||||
{
|
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
|
|
||||||
/* get error count */
|
/* get error count */
|
||||||
@@ -803,8 +769,7 @@ uint8_t can_receive_error_number_get(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval error number
|
\retval error number
|
||||||
*/
|
*/
|
||||||
uint8_t can_transmit_error_number_get(uint32_t can_periph)
|
uint8_t can_transmit_error_number_get(uint32_t can_periph) {
|
||||||
{
|
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
|
|
||||||
val = (uint8_t)(GET_ERR_TECNT(CAN_ERR(can_periph)));
|
val = (uint8_t)(GET_ERR_TECNT(CAN_ERR(can_periph)));
|
||||||
@@ -834,10 +799,7 @@ uint8_t can_transmit_error_number_get(uint32_t can_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt)
|
void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt) { CAN_INTEN(can_periph) |= interrupt; }
|
||||||
{
|
|
||||||
CAN_INTEN(can_periph) |= interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable CAN interrupt
|
\brief disable CAN interrupt
|
||||||
@@ -862,10 +824,7 @@ void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
|
void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt) { CAN_INTEN(can_periph) &= ~interrupt; }
|
||||||
{
|
|
||||||
CAN_INTEN(can_periph) &= ~interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get CAN flag state
|
\brief get CAN flag state
|
||||||
@@ -889,8 +848,7 @@ void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
|
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag) {
|
||||||
{
|
|
||||||
/* get flag and interrupt enable state */
|
/* get flag and interrupt enable state */
|
||||||
if (RESET != (CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)))) {
|
if (RESET != (CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
@@ -921,10 +879,7 @@ FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_flag_clear(uint32_t can_periph, can_flag_enum flag)
|
void can_flag_clear(uint32_t can_periph, can_flag_enum flag) { CAN_REG_VAL(can_periph, flag) = BIT(CAN_BIT_POS(flag)); }
|
||||||
{
|
|
||||||
CAN_REG_VAL(can_periph, flag) = BIT(CAN_BIT_POS(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get CAN interrupt flag state
|
\brief get CAN interrupt flag state
|
||||||
@@ -945,8 +900,7 @@ void can_flag_clear(uint32_t can_periph, can_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum flag)
|
FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum flag) {
|
||||||
{
|
|
||||||
uint32_t ret1 = RESET;
|
uint32_t ret1 = RESET;
|
||||||
uint32_t ret2 = RESET;
|
uint32_t ret2 = RESET;
|
||||||
|
|
||||||
@@ -983,7 +937,4 @@ FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum f
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void can_interrupt_flag_clear(uint32_t can_periph, can_interrupt_flag_enum flag)
|
void can_interrupt_flag_clear(uint32_t can_periph, can_interrupt_flag_enum flag) { CAN_REG_VALS(can_periph, flag) = BIT(CAN_BIT_POS0(flag)); }
|
||||||
{
|
|
||||||
CAN_REG_VALS(can_periph, flag) = BIT(CAN_BIT_POS0(flag));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void crc_deinit(void)
|
void crc_deinit(void) {
|
||||||
{
|
|
||||||
CRC_DATA = CRC_DATA_RESET_VALUE;
|
CRC_DATA = CRC_DATA_RESET_VALUE;
|
||||||
CRC_FDATA = CRC_FDATA_RESET_VALUE;
|
CRC_FDATA = CRC_FDATA_RESET_VALUE;
|
||||||
CRC_CTL = (uint32_t)CRC_CTL_RST;
|
CRC_CTL = (uint32_t)CRC_CTL_RST;
|
||||||
@@ -56,10 +55,7 @@ void crc_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void crc_data_register_reset(void)
|
void crc_data_register_reset(void) { CRC_CTL |= (uint32_t)CRC_CTL_RST; }
|
||||||
{
|
|
||||||
CRC_CTL |= (uint32_t)CRC_CTL_RST;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief read the value of the data register
|
\brief read the value of the data register
|
||||||
@@ -67,8 +63,7 @@ void crc_data_register_reset(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 32-bit value of the data register
|
\retval 32-bit value of the data register
|
||||||
*/
|
*/
|
||||||
uint32_t crc_data_register_read(void)
|
uint32_t crc_data_register_read(void) {
|
||||||
{
|
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
data = CRC_DATA;
|
data = CRC_DATA;
|
||||||
return (data);
|
return (data);
|
||||||
@@ -80,8 +75,7 @@ uint32_t crc_data_register_read(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 8-bit value of the free data register
|
\retval 8-bit value of the free data register
|
||||||
*/
|
*/
|
||||||
uint8_t crc_free_data_register_read(void)
|
uint8_t crc_free_data_register_read(void) {
|
||||||
{
|
|
||||||
uint8_t fdata;
|
uint8_t fdata;
|
||||||
fdata = (uint8_t)CRC_FDATA;
|
fdata = (uint8_t)CRC_FDATA;
|
||||||
return (fdata);
|
return (fdata);
|
||||||
@@ -93,10 +87,7 @@ uint8_t crc_free_data_register_read(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void crc_free_data_register_write(uint8_t free_data)
|
void crc_free_data_register_write(uint8_t free_data) { CRC_FDATA = (uint32_t)free_data; }
|
||||||
{
|
|
||||||
CRC_FDATA = (uint32_t)free_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief calculate the CRC value of a 32-bit data
|
\brief calculate the CRC value of a 32-bit data
|
||||||
@@ -104,8 +95,7 @@ void crc_free_data_register_write(uint8_t free_data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 32-bit value calculated by CRC
|
\retval 32-bit value calculated by CRC
|
||||||
*/
|
*/
|
||||||
uint32_t crc_single_data_calculate(uint32_t sdata)
|
uint32_t crc_single_data_calculate(uint32_t sdata) {
|
||||||
{
|
|
||||||
CRC_DATA = sdata;
|
CRC_DATA = sdata;
|
||||||
return (CRC_DATA);
|
return (CRC_DATA);
|
||||||
}
|
}
|
||||||
@@ -117,8 +107,7 @@ uint32_t crc_single_data_calculate(uint32_t sdata)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 32-bit value calculated by CRC
|
\retval 32-bit value calculated by CRC
|
||||||
*/
|
*/
|
||||||
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size)
|
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size) {
|
||||||
{
|
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
for (index = 0U; index < size; index++) {
|
for (index = 0U; index < size; index++) {
|
||||||
CRC_DATA = array[index];
|
CRC_DATA = array[index];
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_deinit(void)
|
void dac_deinit(void) {
|
||||||
{
|
|
||||||
rcu_periph_reset_enable(RCU_DACRST);
|
rcu_periph_reset_enable(RCU_DACRST);
|
||||||
rcu_periph_reset_disable(RCU_DACRST);
|
rcu_periph_reset_disable(RCU_DACRST);
|
||||||
}
|
}
|
||||||
@@ -57,8 +56,7 @@ void dac_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_enable(uint32_t dac_periph)
|
void dac_enable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL |= DAC_CTL_DEN0;
|
DAC_CTL |= DAC_CTL_DEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -72,8 +70,7 @@ void dac_enable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_disable(uint32_t dac_periph)
|
void dac_disable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL &= ~DAC_CTL_DEN0;
|
DAC_CTL &= ~DAC_CTL_DEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -87,8 +84,7 @@ void dac_disable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_dma_enable(uint32_t dac_periph)
|
void dac_dma_enable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL |= DAC_CTL_DDMAEN0;
|
DAC_CTL |= DAC_CTL_DDMAEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -102,8 +98,7 @@ void dac_dma_enable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_dma_disable(uint32_t dac_periph)
|
void dac_dma_disable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL &= ~DAC_CTL_DDMAEN0;
|
DAC_CTL &= ~DAC_CTL_DDMAEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -117,8 +112,7 @@ void dac_dma_disable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_output_buffer_enable(uint32_t dac_periph)
|
void dac_output_buffer_enable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL &= ~DAC_CTL_DBOFF0;
|
DAC_CTL &= ~DAC_CTL_DBOFF0;
|
||||||
} else {
|
} else {
|
||||||
@@ -132,8 +126,7 @@ void dac_output_buffer_enable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_output_buffer_disable(uint32_t dac_periph)
|
void dac_output_buffer_disable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL |= DAC_CTL_DBOFF0;
|
DAC_CTL |= DAC_CTL_DBOFF0;
|
||||||
} else {
|
} else {
|
||||||
@@ -147,8 +140,7 @@ void dac_output_buffer_disable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval DAC output data
|
\retval DAC output data
|
||||||
*/
|
*/
|
||||||
uint16_t dac_output_value_get(uint32_t dac_periph)
|
uint16_t dac_output_value_get(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
uint16_t data = 0U;
|
uint16_t data = 0U;
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* store the DAC0 output value */
|
/* store the DAC0 output value */
|
||||||
@@ -172,8 +164,7 @@ uint16_t dac_output_value_get(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
|
void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
switch (dac_align) {
|
switch (dac_align) {
|
||||||
/* data right 12 bit alignment */
|
/* data right 12 bit alignment */
|
||||||
@@ -217,8 +208,7 @@ void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_trigger_enable(uint32_t dac_periph)
|
void dac_trigger_enable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL |= DAC_CTL_DTEN0;
|
DAC_CTL |= DAC_CTL_DTEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -232,8 +222,7 @@ void dac_trigger_enable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_trigger_disable(uint32_t dac_periph)
|
void dac_trigger_disable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_CTL &= ~DAC_CTL_DTEN0;
|
DAC_CTL &= ~DAC_CTL_DTEN0;
|
||||||
} else {
|
} else {
|
||||||
@@ -257,8 +246,7 @@ void dac_trigger_disable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_trigger_source_config(uint32_t dac_periph,uint32_t triggersource)
|
void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* configure DAC0 trigger source */
|
/* configure DAC0 trigger source */
|
||||||
DAC_CTL &= ~DAC_CTL_DTSEL0;
|
DAC_CTL &= ~DAC_CTL_DTSEL0;
|
||||||
@@ -275,8 +263,7 @@ void dac_trigger_source_config(uint32_t dac_periph,uint32_t triggersource)
|
|||||||
\param[in] dac_periph: DACx(x = 0,1)
|
\param[in] dac_periph: DACx(x = 0,1)
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_software_trigger_enable(uint32_t dac_periph)
|
void dac_software_trigger_enable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_SWT |= DAC_SWT_SWTR0;
|
DAC_SWT |= DAC_SWT_SWTR0;
|
||||||
} else {
|
} else {
|
||||||
@@ -290,8 +277,7 @@ void dac_software_trigger_enable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_software_trigger_disable(uint32_t dac_periph)
|
void dac_software_trigger_disable(uint32_t dac_periph) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
DAC_SWT &= ~DAC_SWT_SWTR0;
|
DAC_SWT &= ~DAC_SWT_SWTR0;
|
||||||
} else {
|
} else {
|
||||||
@@ -310,8 +296,7 @@ void dac_software_trigger_disable(uint32_t dac_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
|
void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* configure DAC0 wave mode */
|
/* configure DAC0 wave mode */
|
||||||
DAC_CTL &= ~DAC_CTL_DWM0;
|
DAC_CTL &= ~DAC_CTL_DWM0;
|
||||||
@@ -343,8 +328,7 @@ void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
|
void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* configure DAC0 wave bit width */
|
/* configure DAC0 wave bit width */
|
||||||
DAC_CTL &= ~DAC_CTL_DWBW0;
|
DAC_CTL &= ~DAC_CTL_DWBW0;
|
||||||
@@ -376,8 +360,7 @@ void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
|
void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* configure DAC0 LFSR noise mode */
|
/* configure DAC0 LFSR noise mode */
|
||||||
DAC_CTL &= ~DAC_CTL_DWBW0;
|
DAC_CTL &= ~DAC_CTL_DWBW0;
|
||||||
@@ -409,8 +392,7 @@ void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude)
|
void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude) {
|
||||||
{
|
|
||||||
if (DAC0 == dac_periph) {
|
if (DAC0 == dac_periph) {
|
||||||
/* configure DAC0 triangle noise mode */
|
/* configure DAC0 triangle noise mode */
|
||||||
DAC_CTL &= ~DAC_CTL_DWBW0;
|
DAC_CTL &= ~DAC_CTL_DWBW0;
|
||||||
@@ -428,8 +410,7 @@ void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_enable(void)
|
void dac_concurrent_enable(void) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
ctl = DAC_CTL_DEN0 | DAC_CTL_DEN1;
|
ctl = DAC_CTL_DEN0 | DAC_CTL_DEN1;
|
||||||
DAC_CTL |= (ctl);
|
DAC_CTL |= (ctl);
|
||||||
@@ -441,8 +422,7 @@ void dac_concurrent_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_disable(void)
|
void dac_concurrent_disable(void) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
ctl = DAC_CTL_DEN0 | DAC_CTL_DEN1;
|
ctl = DAC_CTL_DEN0 | DAC_CTL_DEN1;
|
||||||
DAC_CTL &= (~ctl);
|
DAC_CTL &= (~ctl);
|
||||||
@@ -454,8 +434,7 @@ void dac_concurrent_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_software_trigger_enable(void)
|
void dac_concurrent_software_trigger_enable(void) {
|
||||||
{
|
|
||||||
uint32_t swt = 0U;
|
uint32_t swt = 0U;
|
||||||
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
|
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
|
||||||
DAC_SWT |= (swt);
|
DAC_SWT |= (swt);
|
||||||
@@ -467,8 +446,7 @@ void dac_concurrent_software_trigger_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_software_trigger_disable(void)
|
void dac_concurrent_software_trigger_disable(void) {
|
||||||
{
|
|
||||||
uint32_t swt = 0U;
|
uint32_t swt = 0U;
|
||||||
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
|
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
|
||||||
DAC_SWT &= (~swt);
|
DAC_SWT &= (~swt);
|
||||||
@@ -480,8 +458,7 @@ void dac_concurrent_software_trigger_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_output_buffer_enable(void)
|
void dac_concurrent_output_buffer_enable(void) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
ctl = DAC_CTL_DBOFF0 | DAC_CTL_DBOFF1;
|
ctl = DAC_CTL_DBOFF0 | DAC_CTL_DBOFF1;
|
||||||
DAC_CTL &= (~ctl);
|
DAC_CTL &= (~ctl);
|
||||||
@@ -493,8 +470,7 @@ void dac_concurrent_output_buffer_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_output_buffer_disable(void)
|
void dac_concurrent_output_buffer_disable(void) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
ctl = DAC_CTL_DBOFF0 | DAC_CTL_DBOFF1;
|
ctl = DAC_CTL_DBOFF0 | DAC_CTL_DBOFF1;
|
||||||
DAC_CTL |= (ctl);
|
DAC_CTL |= (ctl);
|
||||||
@@ -512,8 +488,7 @@ void dac_concurrent_output_buffer_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1)
|
void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1) {
|
||||||
{
|
|
||||||
uint32_t data = 0U;
|
uint32_t data = 0U;
|
||||||
switch (dac_align) {
|
switch (dac_align) {
|
||||||
/* data right 12b alignment */
|
/* data right 12b alignment */
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval DBG_ID code
|
\retval DBG_ID code
|
||||||
*/
|
*/
|
||||||
uint32_t dbg_id_get(void)
|
uint32_t dbg_id_get(void) { return DBG_ID; }
|
||||||
{
|
|
||||||
return DBG_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable low power behavior when the mcu is in debug mode
|
\brief enable low power behavior when the mcu is in debug mode
|
||||||
@@ -55,10 +52,7 @@ uint32_t dbg_id_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dbg_low_power_enable(uint32_t dbg_low_power)
|
void dbg_low_power_enable(uint32_t dbg_low_power) { DBG_CTL |= dbg_low_power; }
|
||||||
{
|
|
||||||
DBG_CTL |= dbg_low_power;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable low power behavior when the mcu is in debug mode
|
\brief disable low power behavior when the mcu is in debug mode
|
||||||
@@ -70,10 +64,7 @@ void dbg_low_power_enable(uint32_t dbg_low_power)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dbg_low_power_disable(uint32_t dbg_low_power)
|
void dbg_low_power_disable(uint32_t dbg_low_power) { DBG_CTL &= ~dbg_low_power; }
|
||||||
{
|
|
||||||
DBG_CTL &= ~dbg_low_power;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable peripheral behavior when the mcu is in debug mode
|
\brief enable peripheral behavior when the mcu is in debug mode
|
||||||
@@ -87,10 +78,7 @@ void dbg_low_power_disable(uint32_t dbg_low_power)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dbg_periph_enable(dbg_periph_enum dbg_periph)
|
void dbg_periph_enable(dbg_periph_enum dbg_periph) { DBG_CTL |= (uint32_t)dbg_periph; }
|
||||||
{
|
|
||||||
DBG_CTL |= (uint32_t)dbg_periph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable peripheral behavior when the mcu is in debug mode
|
\brief disable peripheral behavior when the mcu is in debug mode
|
||||||
@@ -104,7 +92,4 @@ void dbg_periph_enable(dbg_periph_enum dbg_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dbg_periph_disable(dbg_periph_enum dbg_periph)
|
void dbg_periph_disable(dbg_periph_enum dbg_periph) { DBG_CTL &= ~(uint32_t)dbg_periph; }
|
||||||
{
|
|
||||||
DBG_CTL &= ~(uint32_t)dbg_periph;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "gd32vf103_dma.h"
|
#include "gd32vf103_dma.h"
|
||||||
|
|
||||||
#define DMA_WRONG_HANDLE while(1){}
|
#define DMA_WRONG_HANDLE \
|
||||||
|
while (1) {}
|
||||||
|
|
||||||
/* check whether peripheral matches channels or not */
|
/* check whether peripheral matches channels or not */
|
||||||
static ErrStatus dma_periph_and_channel_check(uint32_t dma_periph, dma_channel_enum channelx);
|
static ErrStatus dma_periph_and_channel_check(uint32_t dma_periph, dma_channel_enum channelx);
|
||||||
@@ -49,8 +50,7 @@ static ErrStatus dma_periph_and_channel_check(uint32_t dma_periph, dma_channel_e
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -71,8 +71,7 @@ void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_struct_para_init(dma_parameter_struct* init_struct)
|
void dma_struct_para_init(dma_parameter_struct *init_struct) {
|
||||||
{
|
|
||||||
/* set the DMA struct with the default values */
|
/* set the DMA struct with the default values */
|
||||||
init_struct->periph_addr = 0U;
|
init_struct->periph_addr = 0U;
|
||||||
init_struct->periph_width = 0U;
|
init_struct->periph_width = 0U;
|
||||||
@@ -105,8 +104,7 @@ void dma_struct_para_init(dma_parameter_struct* init_struct)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_struct* init_struct)
|
void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_struct *init_struct) {
|
||||||
{
|
|
||||||
uint32_t ctl;
|
uint32_t ctl;
|
||||||
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
@@ -160,8 +158,7 @@ void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_stru
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -179,8 +176,7 @@ void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -198,8 +194,7 @@ void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_to_memory_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_memory_to_memory_enable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -217,8 +212,7 @@ void dma_memory_to_memory_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_to_memory_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_memory_to_memory_disable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -236,8 +230,7 @@ void dma_memory_to_memory_disable(uint32_t dma_periph, dma_channel_enum channelx
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -255,8 +248,7 @@ void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -275,8 +267,7 @@ void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address)
|
void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -295,8 +286,7 @@ void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address)
|
void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -315,8 +305,7 @@ void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t number)
|
void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t number) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -334,8 +323,7 @@ void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval uint32_t: the number of remaining data to be transferred by the DMA
|
\retval uint32_t: the number of remaining data to be transferred by the DMA
|
||||||
*/
|
*/
|
||||||
uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
|
uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -359,8 +347,7 @@ uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t priority)
|
void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t priority) {
|
||||||
{
|
|
||||||
uint32_t ctl;
|
uint32_t ctl;
|
||||||
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
@@ -390,8 +377,7 @@ void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_width_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t mwidth)
|
void dma_memory_width_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t mwidth) {
|
||||||
{
|
|
||||||
uint32_t ctl;
|
uint32_t ctl;
|
||||||
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
@@ -421,8 +407,7 @@ void dma_memory_width_config(uint32_t dma_periph, dma_channel_enum channelx, uin
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_periph_width_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t pwidth)
|
void dma_periph_width_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t pwidth) {
|
||||||
{
|
|
||||||
uint32_t ctl;
|
uint32_t ctl;
|
||||||
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
@@ -447,8 +432,7 @@ void dma_periph_width_config (uint32_t dma_periph, dma_channel_enum channelx, ui
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_memory_increase_enable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -466,8 +450,7 @@ void dma_memory_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_memory_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_memory_increase_disable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -485,8 +468,7 @@ void dma_memory_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_periph_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_periph_increase_enable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -504,8 +486,7 @@ void dma_periph_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -527,8 +508,7 @@ void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t direction)
|
void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t direction) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -556,8 +536,7 @@ void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channel
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
|
FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag) {
|
||||||
{
|
|
||||||
FlagStatus reval;
|
FlagStatus reval;
|
||||||
|
|
||||||
if (RESET != (DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx))) {
|
if (RESET != (DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx))) {
|
||||||
@@ -585,10 +564,7 @@ FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
|
void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag) { DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx); }
|
||||||
{
|
|
||||||
DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief check DMA flag and interrupt enable bit is set or not
|
\brief check DMA flag and interrupt enable bit is set or not
|
||||||
@@ -605,8 +581,7 @@ void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t fla
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
|
FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag) {
|
||||||
{
|
|
||||||
uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
|
uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
@@ -653,10 +628,7 @@ FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
|
void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag) { DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx); }
|
||||||
{
|
|
||||||
DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable DMA interrupt
|
\brief enable DMA interrupt
|
||||||
@@ -673,8 +645,7 @@ void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, ui
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source)
|
void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -697,8 +668,7 @@ void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source)
|
void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source) {
|
||||||
{
|
|
||||||
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
if (ERROR == dma_periph_and_channel_check(dma_periph, channelx)) {
|
||||||
DMA_WRONG_HANDLE
|
DMA_WRONG_HANDLE
|
||||||
}
|
}
|
||||||
@@ -716,8 +686,7 @@ void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint3
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static ErrStatus dma_periph_and_channel_check(uint32_t dma_periph, dma_channel_enum channelx)
|
static ErrStatus dma_periph_and_channel_check(uint32_t dma_periph, dma_channel_enum channelx) {
|
||||||
{
|
|
||||||
ErrStatus val = SUCCESS;
|
ErrStatus val = SUCCESS;
|
||||||
|
|
||||||
if (DMA1 == dma_periph) {
|
if (DMA1 == dma_periph) {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ OF SUCH DAMAGE.
|
|||||||
#define REG_DBGMCU2 ((uint32_t)0xE0042008)
|
#define REG_DBGMCU2 ((uint32_t)0xE0042008)
|
||||||
#define REG_DBGMCU2EN ((uint32_t)0xE004200C)
|
#define REG_DBGMCU2EN ((uint32_t)0xE004200C)
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set the priority group
|
\brief set the priority group
|
||||||
\param[in] prigroup: specify the priority group
|
\param[in] prigroup: specify the priority group
|
||||||
@@ -49,10 +48,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void eclic_priority_group_set(uint32_t prigroup) {
|
void eclic_priority_group_set(uint32_t prigroup) { ECLIC_SetCfgNlbits(prigroup); }
|
||||||
ECLIC_SetCfgNlbits(prigroup);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the interrupt request
|
\brief enable the interrupt request
|
||||||
@@ -74,9 +70,7 @@ void eclic_irq_enable(uint32_t source, uint8_t level, uint8_t priority) {
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void eclic_irq_disable(uint32_t source) {
|
void eclic_irq_disable(uint32_t source) { ECLIC_DisableIRQ(source); }
|
||||||
ECLIC_DisableIRQ(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief reset system
|
\brief reset system
|
||||||
@@ -88,4 +82,3 @@ void eclic_system_reset(void) {
|
|||||||
REG32(REG_DBGMCU2EN) = 0x4b5a6978;
|
REG32(REG_DBGMCU2EN) = 0x4b5a6978;
|
||||||
REG32(REG_DBGMCU2) = 0x1;
|
REG32(REG_DBGMCU2) = 0x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exmc_norsram_deinit(uint32_t norsram_region)
|
void exmc_norsram_deinit(uint32_t norsram_region) {
|
||||||
{
|
|
||||||
/* reset the registers */
|
/* reset the registers */
|
||||||
if (EXMC_BANK0_NORSRAM_REGION0 == norsram_region) {
|
if (EXMC_BANK0_NORSRAM_REGION0 == norsram_region) {
|
||||||
EXMC_SNCTL(norsram_region) = BANK0_SNCTL0_REGION_RESET;
|
EXMC_SNCTL(norsram_region) = BANK0_SNCTL0_REGION_RESET;
|
||||||
@@ -71,8 +70,7 @@ void exmc_norsram_deinit(uint32_t norsram_region)
|
|||||||
\param[out] exmc_norsram_init_struct: the initialized structure exmc_norsram_parameter_struct pointer
|
\param[out] exmc_norsram_init_struct: the initialized structure exmc_norsram_parameter_struct pointer
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
|
void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct) {
|
||||||
{
|
|
||||||
/* configure the structure with default value */
|
/* configure the structure with default value */
|
||||||
exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
|
exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
|
||||||
exmc_norsram_init_struct->address_data_mux = ENABLE;
|
exmc_norsram_init_struct->address_data_mux = ENABLE;
|
||||||
@@ -105,29 +103,23 @@ void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_i
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
|
void exmc_norsram_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct) {
|
||||||
{
|
|
||||||
uint32_t snctl = 0x00000000U, sntcfg = 0x00000000U;
|
uint32_t snctl = 0x00000000U, sntcfg = 0x00000000U;
|
||||||
|
|
||||||
/* get the register value */
|
/* get the register value */
|
||||||
snctl = EXMC_SNCTL(exmc_norsram_init_struct->norsram_region);
|
snctl = EXMC_SNCTL(exmc_norsram_init_struct->norsram_region);
|
||||||
|
|
||||||
/* clear relative bits */
|
/* clear relative bits */
|
||||||
snctl &= ((uint32_t)~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_NRWTPOL |
|
snctl &= ((uint32_t) ~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WREN | EXMC_SNCTL_NRWTEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_NRMUX));
|
||||||
EXMC_SNCTL_WREN | EXMC_SNCTL_NRWTEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_NRMUX));
|
|
||||||
|
|
||||||
snctl |= (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) |
|
snctl |= (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) | exmc_norsram_init_struct->memory_type | exmc_norsram_init_struct->databus_width
|
||||||
exmc_norsram_init_struct->memory_type |
|
| exmc_norsram_init_struct->nwait_polarity | (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) | (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET)
|
||||||
exmc_norsram_init_struct->databus_width |
|
| (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET);
|
||||||
exmc_norsram_init_struct->nwait_polarity |
|
|
||||||
(exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
|
|
||||||
(exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
|
|
||||||
(exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET);
|
|
||||||
|
|
||||||
sntcfg = (uint32_t)((exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime - 1U ) & EXMC_SNTCFG_ASET )|
|
sntcfg = (uint32_t)((exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime - 1U) & EXMC_SNTCFG_ASET)
|
||||||
(((exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime - 1U ) << SNTCFG_AHLD_OFFSET ) & EXMC_SNTCFG_AHLD ) |
|
| (((exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime - 1U) << SNTCFG_AHLD_OFFSET) & EXMC_SNTCFG_AHLD)
|
||||||
(((exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime - 1U ) << SNTCFG_DSET_OFFSET ) & EXMC_SNTCFG_DSET ) |
|
| (((exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime - 1U) << SNTCFG_DSET_OFFSET) & EXMC_SNTCFG_DSET)
|
||||||
(((exmc_norsram_init_struct->read_write_timing->bus_latency - 1U ) << SNTCFG_BUSLAT_OFFSET ) & EXMC_SNTCFG_BUSLAT );
|
| (((exmc_norsram_init_struct->read_write_timing->bus_latency - 1U) << SNTCFG_BUSLAT_OFFSET) & EXMC_SNTCFG_BUSLAT);
|
||||||
|
|
||||||
/* nor flash access enable */
|
/* nor flash access enable */
|
||||||
if (EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type) {
|
if (EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type) {
|
||||||
@@ -146,10 +138,7 @@ void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exmc_norsram_enable(uint32_t norsram_region)
|
void exmc_norsram_enable(uint32_t norsram_region) { EXMC_SNCTL(norsram_region) |= (uint32_t)EXMC_SNCTL_NRBKEN; }
|
||||||
{
|
|
||||||
EXMC_SNCTL(norsram_region) |= (uint32_t)EXMC_SNCTL_NRBKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable EXMC NOR/PSRAM bank region
|
\brief disable EXMC NOR/PSRAM bank region
|
||||||
@@ -158,7 +147,4 @@ void exmc_norsram_enable(uint32_t norsram_region)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exmc_norsram_disable(uint32_t norsram_region)
|
void exmc_norsram_disable(uint32_t norsram_region) { EXMC_SNCTL(norsram_region) &= ~(uint32_t)EXMC_SNCTL_NRBKEN; }
|
||||||
{
|
|
||||||
EXMC_SNCTL(norsram_region) &= ~(uint32_t)EXMC_SNCTL_NRBKEN;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_deinit(void)
|
void exti_deinit(void) {
|
||||||
{
|
|
||||||
/* reset the value of all the EXTI registers */
|
/* reset the value of all the EXTI registers */
|
||||||
EXTI_INTEN = EXTI_REG_RESET_VALUE;
|
EXTI_INTEN = EXTI_REG_RESET_VALUE;
|
||||||
EXTI_EVEN = EXTI_REG_RESET_VALUE;
|
EXTI_EVEN = EXTI_REG_RESET_VALUE;
|
||||||
@@ -70,8 +69,7 @@ void exti_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type)
|
void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type) {
|
||||||
{
|
|
||||||
/* reset the EXTI line x */
|
/* reset the EXTI line x */
|
||||||
EXTI_INTEN &= ~(uint32_t)linex;
|
EXTI_INTEN &= ~(uint32_t)linex;
|
||||||
EXTI_EVEN &= ~(uint32_t)linex;
|
EXTI_EVEN &= ~(uint32_t)linex;
|
||||||
@@ -118,10 +116,7 @@ void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum tr
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_interrupt_enable(exti_line_enum linex)
|
void exti_interrupt_enable(exti_line_enum linex) { EXTI_INTEN |= (uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_INTEN |= (uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the events from EXTI line x
|
\brief enable the events from EXTI line x
|
||||||
@@ -131,10 +126,7 @@ void exti_interrupt_enable(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_event_enable(exti_line_enum linex)
|
void exti_event_enable(exti_line_enum linex) { EXTI_EVEN |= (uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_EVEN |= (uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the interrupt from EXTI line x
|
\brief disable the interrupt from EXTI line x
|
||||||
@@ -144,10 +136,7 @@ void exti_event_enable(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_interrupt_disable(exti_line_enum linex)
|
void exti_interrupt_disable(exti_line_enum linex) { EXTI_INTEN &= ~(uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_INTEN &= ~(uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the events from EXTI line x
|
\brief disable the events from EXTI line x
|
||||||
@@ -157,10 +146,7 @@ void exti_interrupt_disable(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_event_disable(exti_line_enum linex)
|
void exti_event_disable(exti_line_enum linex) { EXTI_EVEN &= ~(uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_EVEN &= ~(uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get EXTI lines flag
|
\brief get EXTI lines flag
|
||||||
@@ -170,8 +156,7 @@ void exti_event_disable(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: status of flag (RESET or SET)
|
\retval FlagStatus: status of flag (RESET or SET)
|
||||||
*/
|
*/
|
||||||
FlagStatus exti_flag_get(exti_line_enum linex)
|
FlagStatus exti_flag_get(exti_line_enum linex) {
|
||||||
{
|
|
||||||
if (RESET != (EXTI_PD & (uint32_t)linex)) {
|
if (RESET != (EXTI_PD & (uint32_t)linex)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -187,10 +172,7 @@ FlagStatus exti_flag_get(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_flag_clear(exti_line_enum linex)
|
void exti_flag_clear(exti_line_enum linex) { EXTI_PD = (uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_PD = (uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get EXTI lines flag when the interrupt flag is set
|
\brief get EXTI lines flag when the interrupt flag is set
|
||||||
@@ -200,8 +182,7 @@ void exti_flag_clear(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: status of flag (RESET or SET)
|
\retval FlagStatus: status of flag (RESET or SET)
|
||||||
*/
|
*/
|
||||||
FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
|
FlagStatus exti_interrupt_flag_get(exti_line_enum linex) {
|
||||||
{
|
|
||||||
uint32_t flag_left, flag_right;
|
uint32_t flag_left, flag_right;
|
||||||
|
|
||||||
flag_left = EXTI_PD & (uint32_t)linex;
|
flag_left = EXTI_PD & (uint32_t)linex;
|
||||||
@@ -222,10 +203,7 @@ FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_interrupt_flag_clear(exti_line_enum linex)
|
void exti_interrupt_flag_clear(exti_line_enum linex) { EXTI_PD = (uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_PD = (uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable EXTI software interrupt event
|
\brief enable EXTI software interrupt event
|
||||||
@@ -235,10 +213,7 @@ void exti_interrupt_flag_clear(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_software_interrupt_enable(exti_line_enum linex)
|
void exti_software_interrupt_enable(exti_line_enum linex) { EXTI_SWIEV |= (uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_SWIEV |= (uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable EXTI software interrupt event
|
\brief disable EXTI software interrupt event
|
||||||
@@ -248,7 +223,4 @@ void exti_software_interrupt_enable(exti_line_enum linex)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void exti_software_interrupt_disable(exti_line_enum linex)
|
void exti_software_interrupt_disable(exti_line_enum linex) { EXTI_SWIEV &= ~(uint32_t)linex; }
|
||||||
{
|
|
||||||
EXTI_SWIEV &= ~(uint32_t) linex;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_wscnt_set(uint32_t wscnt)
|
void fmc_wscnt_set(uint32_t wscnt) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = FMC_WS;
|
reg = FMC_WS;
|
||||||
@@ -59,8 +58,7 @@ void fmc_wscnt_set(uint32_t wscnt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_unlock(void)
|
void fmc_unlock(void) {
|
||||||
{
|
|
||||||
if ((RESET != (FMC_CTL0 & FMC_CTL0_LK))) {
|
if ((RESET != (FMC_CTL0 & FMC_CTL0_LK))) {
|
||||||
/* write the FMC unlock key */
|
/* write the FMC unlock key */
|
||||||
FMC_KEY0 = UNLOCK_KEY0;
|
FMC_KEY0 = UNLOCK_KEY0;
|
||||||
@@ -74,21 +72,18 @@ void fmc_unlock(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_lock(void)
|
void fmc_lock(void) {
|
||||||
{
|
|
||||||
/* set the LK bit */
|
/* set the LK bit */
|
||||||
FMC_CTL0 |= FMC_CTL0_LK;
|
FMC_CTL0 |= FMC_CTL0_LK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief FMC erase page
|
\brief FMC erase page
|
||||||
\param[in] page_address: the page address to be erased.
|
\param[in] page_address: the page address to be erased.
|
||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_page_erase(uint32_t page_address)
|
fmc_state_enum fmc_page_erase(uint32_t page_address) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state;
|
fmc_state_enum fmc_state;
|
||||||
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
/* if the last operation is completed, start page erase */
|
/* if the last operation is completed, start page erase */
|
||||||
@@ -111,8 +106,7 @@ fmc_state_enum fmc_page_erase(uint32_t page_address)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_mass_erase(void)
|
fmc_state_enum fmc_mass_erase(void) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state;
|
fmc_state_enum fmc_state;
|
||||||
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
|
|
||||||
@@ -136,8 +130,7 @@ fmc_state_enum fmc_mass_erase(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
|
fmc_state_enum fmc_word_program(uint32_t address, uint32_t data) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = FMC_READY;
|
fmc_state_enum fmc_state = FMC_READY;
|
||||||
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
|
|
||||||
@@ -160,8 +153,7 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
|
fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = FMC_READY;
|
fmc_state_enum fmc_state = FMC_READY;
|
||||||
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
|
|
||||||
@@ -184,8 +176,7 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void ob_unlock(void)
|
void ob_unlock(void) {
|
||||||
{
|
|
||||||
if (RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {
|
if (RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {
|
||||||
/* write the FMC key */
|
/* write the FMC key */
|
||||||
FMC_OBKEY = UNLOCK_KEY0;
|
FMC_OBKEY = UNLOCK_KEY0;
|
||||||
@@ -193,8 +184,7 @@ void ob_unlock(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wait until OBWEN bit is set by hardware */
|
/* wait until OBWEN bit is set by hardware */
|
||||||
while (RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {
|
while (RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -203,8 +193,7 @@ void ob_unlock(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void ob_lock(void)
|
void ob_lock(void) {
|
||||||
{
|
|
||||||
/* reset the OBWEN bit */
|
/* reset the OBWEN bit */
|
||||||
FMC_CTL0 &= ~FMC_CTL0_OBWEN;
|
FMC_CTL0 &= ~FMC_CTL0_OBWEN;
|
||||||
}
|
}
|
||||||
@@ -216,8 +205,7 @@ void ob_lock(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum ob_erase(void)
|
fmc_state_enum ob_erase(void) {
|
||||||
{
|
|
||||||
uint16_t temp_spc = FMC_NSPC;
|
uint16_t temp_spc = FMC_NSPC;
|
||||||
|
|
||||||
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
@@ -271,8 +259,7 @@ fmc_state_enum ob_erase(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum ob_write_protection_enable(uint32_t ob_wp)
|
fmc_state_enum ob_write_protection_enable(uint32_t ob_wp) {
|
||||||
{
|
|
||||||
uint16_t temp_wp0, temp_wp1, temp_wp2, temp_wp3;
|
uint16_t temp_wp0, temp_wp1, temp_wp2, temp_wp3;
|
||||||
|
|
||||||
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
@@ -330,8 +317,7 @@ fmc_state_enum ob_write_protection_enable(uint32_t ob_wp)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum ob_security_protection_config(uint8_t ob_spc)
|
fmc_state_enum ob_security_protection_config(uint8_t ob_spc) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
fmc_state_enum fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
|
||||||
|
|
||||||
if (FMC_READY == fmc_state) {
|
if (FMC_READY == fmc_state) {
|
||||||
@@ -384,8 +370,7 @@ fmc_state_enum ob_security_protection_config(uint8_t ob_spc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep, uint8_t ob_stdby, uint8_t ob_boot)
|
fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep, uint8_t ob_stdby, uint8_t ob_boot) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = FMC_READY;
|
fmc_state_enum fmc_state = FMC_READY;
|
||||||
uint8_t temp;
|
uint8_t temp;
|
||||||
|
|
||||||
@@ -444,8 +429,7 @@ fmc_state_enum ob_data_program(uint32_t address, uint8_t data) {
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval the FMC user option byte values
|
\retval the FMC user option byte values
|
||||||
*/
|
*/
|
||||||
uint8_t ob_user_get(void)
|
uint8_t ob_user_get(void) {
|
||||||
{
|
|
||||||
/* return the FMC user option byte value */
|
/* return the FMC user option byte value */
|
||||||
return (uint8_t)(FMC_OBSTAT >> 2U);
|
return (uint8_t)(FMC_OBSTAT >> 2U);
|
||||||
}
|
}
|
||||||
@@ -456,10 +440,7 @@ uint8_t ob_user_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ob_data
|
\retval ob_data
|
||||||
*/
|
*/
|
||||||
uint16_t ob_data_get(void)
|
uint16_t ob_data_get(void) { return (uint16_t)(FMC_OBSTAT >> 10U); }
|
||||||
{
|
|
||||||
return (uint16_t) (FMC_OBSTAT >> 10U);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the FMC option byte write protection
|
\brief get the FMC option byte write protection
|
||||||
@@ -467,8 +448,7 @@ uint16_t ob_data_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval the FMC write protection option byte value
|
\retval the FMC write protection option byte value
|
||||||
*/
|
*/
|
||||||
uint32_t ob_write_protection_get(void)
|
uint32_t ob_write_protection_get(void) {
|
||||||
{
|
|
||||||
/* return the FMC write protection option byte value */
|
/* return the FMC write protection option byte value */
|
||||||
return FMC_WP;
|
return FMC_WP;
|
||||||
}
|
}
|
||||||
@@ -479,8 +459,7 @@ uint32_t ob_write_protection_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus ob_spc_get(void)
|
FlagStatus ob_spc_get(void) {
|
||||||
{
|
|
||||||
FlagStatus spc_state = RESET;
|
FlagStatus spc_state = RESET;
|
||||||
|
|
||||||
if (RESET != (FMC_OBSTAT & FMC_OBSTAT_SPC)) {
|
if (RESET != (FMC_OBSTAT & FMC_OBSTAT_SPC)) {
|
||||||
@@ -500,10 +479,7 @@ FlagStatus ob_spc_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_interrupt_enable(uint32_t interrupt)
|
void fmc_interrupt_enable(uint32_t interrupt) { FMC_REG_VAL(interrupt) |= BIT(FMC_BIT_POS(interrupt)); }
|
||||||
{
|
|
||||||
FMC_REG_VAL(interrupt) |= BIT(FMC_BIT_POS(interrupt));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable FMC interrupt
|
\brief disable FMC interrupt
|
||||||
@@ -514,10 +490,7 @@ void fmc_interrupt_enable(uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_interrupt_disable(uint32_t interrupt)
|
void fmc_interrupt_disable(uint32_t interrupt) { FMC_REG_VAL(interrupt) &= ~BIT(FMC_BIT_POS(interrupt)); }
|
||||||
{
|
|
||||||
FMC_REG_VAL(interrupt) &= ~BIT(FMC_BIT_POS(interrupt));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief check flag is set or not
|
\brief check flag is set or not
|
||||||
@@ -531,8 +504,7 @@ void fmc_interrupt_disable(uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus fmc_flag_get(uint32_t flag)
|
FlagStatus fmc_flag_get(uint32_t flag) {
|
||||||
{
|
|
||||||
if (RESET != (FMC_REG_VAL(flag) & BIT(FMC_BIT_POS(flag)))) {
|
if (RESET != (FMC_REG_VAL(flag) & BIT(FMC_BIT_POS(flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -550,10 +522,7 @@ FlagStatus fmc_flag_get(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_flag_clear(uint32_t flag)
|
void fmc_flag_clear(uint32_t flag) { FMC_REG_VAL(flag) = (!FMC_REG_VAL(flag)) | BIT(FMC_BIT_POS(flag)); }
|
||||||
{
|
|
||||||
FMC_REG_VAL(flag) = (!FMC_REG_VAL(flag)) | BIT(FMC_BIT_POS(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get FMC interrupt flag state
|
\brief get FMC interrupt flag state
|
||||||
@@ -565,8 +534,7 @@ void fmc_flag_clear(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag)
|
FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag) {
|
||||||
{
|
|
||||||
FlagStatus ret1 = RESET;
|
FlagStatus ret1 = RESET;
|
||||||
FlagStatus ret2 = RESET;
|
FlagStatus ret2 = RESET;
|
||||||
|
|
||||||
@@ -594,10 +562,7 @@ FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag)
|
void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag) { FMC_REG_VALS(flag) |= BIT(FMC_BIT_POS0(flag)); }
|
||||||
{
|
|
||||||
FMC_REG_VALS(flag) |= BIT(FMC_BIT_POS0(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the FMC state
|
\brief get the FMC state
|
||||||
@@ -605,8 +570,7 @@ void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_state_get(void)
|
fmc_state_enum fmc_state_get(void) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = FMC_READY;
|
fmc_state_enum fmc_state = FMC_READY;
|
||||||
|
|
||||||
if ((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_BUSY)) {
|
if ((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_BUSY)) {
|
||||||
@@ -630,8 +594,7 @@ fmc_state_enum fmc_state_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval state of FMC, refer to fmc_state_enum
|
\retval state of FMC, refer to fmc_state_enum
|
||||||
*/
|
*/
|
||||||
fmc_state_enum fmc_ready_wait(uint32_t timeout)
|
fmc_state_enum fmc_ready_wait(uint32_t timeout) {
|
||||||
{
|
|
||||||
fmc_state_enum fmc_state = FMC_BUSY;
|
fmc_state_enum fmc_state = FMC_BUSY;
|
||||||
|
|
||||||
/* wait for FMC ready */
|
/* wait for FMC ready */
|
||||||
|
|||||||
@@ -45,10 +45,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fwdgt_write_enable(void)
|
void fwdgt_write_enable(void) { FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE; }
|
||||||
{
|
|
||||||
FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable write access to FWDGT_PSC and FWDGT_RLD
|
\brief disable write access to FWDGT_PSC and FWDGT_RLD
|
||||||
@@ -56,10 +53,7 @@ void fwdgt_write_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fwdgt_write_disable(void)
|
void fwdgt_write_disable(void) { FWDGT_CTL = FWDGT_WRITEACCESS_DISABLE; }
|
||||||
{
|
|
||||||
FWDGT_CTL = FWDGT_WRITEACCESS_DISABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief start the free watchdog timer counter
|
\brief start the free watchdog timer counter
|
||||||
@@ -67,10 +61,7 @@ void fwdgt_write_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fwdgt_enable(void)
|
void fwdgt_enable(void) { FWDGT_CTL = FWDGT_KEY_ENABLE; }
|
||||||
{
|
|
||||||
FWDGT_CTL = FWDGT_KEY_ENABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief reload the counter of FWDGT
|
\brief reload the counter of FWDGT
|
||||||
@@ -78,10 +69,7 @@ void fwdgt_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void fwdgt_counter_reload(void)
|
void fwdgt_counter_reload(void) { FWDGT_CTL = FWDGT_KEY_RELOAD; }
|
||||||
{
|
|
||||||
FWDGT_CTL = FWDGT_KEY_RELOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure counter reload value, and prescaler divider value
|
\brief configure counter reload value, and prescaler divider value
|
||||||
@@ -98,8 +86,7 @@ void fwdgt_counter_reload(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ErrStatus: ERROR or SUCCESS
|
\retval ErrStatus: ERROR or SUCCESS
|
||||||
*/
|
*/
|
||||||
ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
|
ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div) {
|
||||||
{
|
|
||||||
uint32_t timeout = FWDGT_PSC_TIMEOUT;
|
uint32_t timeout = FWDGT_PSC_TIMEOUT;
|
||||||
uint32_t flag_status = RESET;
|
uint32_t flag_status = RESET;
|
||||||
|
|
||||||
@@ -141,8 +128,7 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus fwdgt_flag_get(uint16_t flag)
|
FlagStatus fwdgt_flag_get(uint16_t flag) {
|
||||||
{
|
|
||||||
if (FWDGT_STAT & flag) {
|
if (FWDGT_STAT & flag) {
|
||||||
return SET;
|
return SET;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_deinit(uint32_t gpio_periph)
|
void gpio_deinit(uint32_t gpio_periph) {
|
||||||
{
|
|
||||||
switch (gpio_periph) {
|
switch (gpio_periph) {
|
||||||
case GPIOA:
|
case GPIOA:
|
||||||
/* reset GPIOA */
|
/* reset GPIOA */
|
||||||
@@ -89,8 +88,7 @@ void gpio_deinit(uint32_t gpio_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_afio_deinit(void)
|
void gpio_afio_deinit(void) {
|
||||||
{
|
|
||||||
rcu_periph_reset_enable(RCU_AFRST);
|
rcu_periph_reset_enable(RCU_AFRST);
|
||||||
rcu_periph_reset_disable(RCU_AFRST);
|
rcu_periph_reset_disable(RCU_AFRST);
|
||||||
}
|
}
|
||||||
@@ -120,9 +118,7 @@ void gpio_afio_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed,
|
void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t pin) {
|
||||||
uint32_t pin)
|
|
||||||
{
|
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint32_t temp_mode = 0U;
|
uint32_t temp_mode = 0U;
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
@@ -195,10 +191,7 @@ void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_bit_set(uint32_t gpio_periph, uint32_t pin)
|
void gpio_bit_set(uint32_t gpio_periph, uint32_t pin) { GPIO_BOP(gpio_periph) = (uint32_t)pin; }
|
||||||
{
|
|
||||||
GPIO_BOP(gpio_periph) = (uint32_t) pin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief reset GPIO pin
|
\brief reset GPIO pin
|
||||||
@@ -209,10 +202,7 @@ void gpio_bit_set(uint32_t gpio_periph, uint32_t pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin)
|
void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin) { GPIO_BC(gpio_periph) = (uint32_t)pin; }
|
||||||
{
|
|
||||||
GPIO_BC(gpio_periph) = (uint32_t) pin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief write data to the specified GPIO pin
|
\brief write data to the specified GPIO pin
|
||||||
@@ -227,8 +217,7 @@ void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value)
|
void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value) {
|
||||||
{
|
|
||||||
if (RESET != bit_value) {
|
if (RESET != bit_value) {
|
||||||
GPIO_BOP(gpio_periph) = (uint32_t)pin;
|
GPIO_BOP(gpio_periph) = (uint32_t)pin;
|
||||||
} else {
|
} else {
|
||||||
@@ -243,10 +232,7 @@ void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_port_write(uint32_t gpio_periph, uint16_t data)
|
void gpio_port_write(uint32_t gpio_periph, uint16_t data) { GPIO_OCTL(gpio_periph) = (uint32_t)data; }
|
||||||
{
|
|
||||||
GPIO_OCTL(gpio_periph) = (uint32_t) data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get GPIO pin input status
|
\brief get GPIO pin input status
|
||||||
@@ -257,8 +243,7 @@ void gpio_port_write(uint32_t gpio_periph, uint16_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval input status of gpio pin: SET or RESET
|
\retval input status of gpio pin: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin)
|
FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin) {
|
||||||
{
|
|
||||||
if ((uint32_t)RESET != (GPIO_ISTAT(gpio_periph) & (pin))) {
|
if ((uint32_t)RESET != (GPIO_ISTAT(gpio_periph) & (pin))) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -272,10 +257,7 @@ FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval input status of gpio all pins
|
\retval input status of gpio all pins
|
||||||
*/
|
*/
|
||||||
uint16_t gpio_input_port_get(uint32_t gpio_periph)
|
uint16_t gpio_input_port_get(uint32_t gpio_periph) { return (uint16_t)(GPIO_ISTAT(gpio_periph)); }
|
||||||
{
|
|
||||||
return (uint16_t) (GPIO_ISTAT(gpio_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get GPIO pin output status
|
\brief get GPIO pin output status
|
||||||
@@ -286,8 +268,7 @@ uint16_t gpio_input_port_get(uint32_t gpio_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval output status of gpio pin: SET or RESET
|
\retval output status of gpio pin: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin)
|
FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin) {
|
||||||
{
|
|
||||||
if ((uint32_t)RESET != (GPIO_OCTL(gpio_periph) & (pin))) {
|
if ((uint32_t)RESET != (GPIO_OCTL(gpio_periph) & (pin))) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -301,10 +282,7 @@ FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval output status of gpio all pins
|
\retval output status of gpio all pins
|
||||||
*/
|
*/
|
||||||
uint16_t gpio_output_port_get(uint32_t gpio_periph)
|
uint16_t gpio_output_port_get(uint32_t gpio_periph) { return ((uint16_t)GPIO_OCTL(gpio_periph)); }
|
||||||
{
|
|
||||||
return ((uint16_t) GPIO_OCTL(gpio_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure GPIO pin remap
|
\brief configure GPIO pin remap
|
||||||
@@ -338,8 +316,7 @@ uint16_t gpio_output_port_get(uint32_t gpio_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue)
|
void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue) {
|
||||||
{
|
|
||||||
uint32_t remap1 = 0U, remap2 = 0U, temp_reg = 0U, temp_mask = 0U;
|
uint32_t remap1 = 0U, remap2 = 0U, temp_reg = 0U, temp_mask = 0U;
|
||||||
|
|
||||||
if (AFIO_PCF1_FIELDS == (remap & AFIO_PCF1_FIELDS)) {
|
if (AFIO_PCF1_FIELDS == (remap & AFIO_PCF1_FIELDS)) {
|
||||||
@@ -354,8 +331,7 @@ void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue)
|
|||||||
remap1 = remap & LSB_16BIT_MASK;
|
remap1 = remap & LSB_16BIT_MASK;
|
||||||
|
|
||||||
/* judge pin remap type */
|
/* judge pin remap type */
|
||||||
if ((PCF_LOCATION1_MASK | PCF_LOCATION2_MASK)
|
if ((PCF_LOCATION1_MASK | PCF_LOCATION2_MASK) == (remap & (PCF_LOCATION1_MASK | PCF_LOCATION2_MASK))) {
|
||||||
== (remap & (PCF_LOCATION1_MASK | PCF_LOCATION2_MASK))) {
|
|
||||||
temp_reg &= PCF_SWJCFG_MASK;
|
temp_reg &= PCF_SWJCFG_MASK;
|
||||||
AFIO_PCF0 &= PCF_SWJCFG_MASK;
|
AFIO_PCF0 &= PCF_SWJCFG_MASK;
|
||||||
} else if (PCF_LOCATION2_MASK == (remap & PCF_LOCATION2_MASK)) {
|
} else if (PCF_LOCATION2_MASK == (remap & PCF_LOCATION2_MASK)) {
|
||||||
@@ -394,37 +370,27 @@ void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin)
|
void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin) {
|
||||||
{
|
|
||||||
uint32_t source = 0U;
|
uint32_t source = 0U;
|
||||||
source = ((uint32_t) 0x0FU)
|
source = ((uint32_t)0x0FU) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK));
|
||||||
<< (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK));
|
|
||||||
|
|
||||||
/* select EXTI sources */
|
/* select EXTI sources */
|
||||||
if (GPIO_PIN_SOURCE_4 > output_pin) {
|
if (GPIO_PIN_SOURCE_4 > output_pin) {
|
||||||
/* select EXTI0/EXTI1/EXTI2/EXTI3 */
|
/* select EXTI0/EXTI1/EXTI2/EXTI3 */
|
||||||
AFIO_EXTISS0 &= ~source;
|
AFIO_EXTISS0 &= ~source;
|
||||||
AFIO_EXTISS0 |= (((uint32_t) output_port)
|
AFIO_EXTISS0 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
||||||
<< (AFIO_EXTI_SOURCE_FIELDS
|
|
||||||
* (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
|
||||||
} else if (GPIO_PIN_SOURCE_8 > output_pin) {
|
} else if (GPIO_PIN_SOURCE_8 > output_pin) {
|
||||||
/* select EXTI4/EXTI5/EXTI6/EXTI7 */
|
/* select EXTI4/EXTI5/EXTI6/EXTI7 */
|
||||||
AFIO_EXTISS1 &= ~source;
|
AFIO_EXTISS1 &= ~source;
|
||||||
AFIO_EXTISS1 |= (((uint32_t) output_port)
|
AFIO_EXTISS1 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
||||||
<< (AFIO_EXTI_SOURCE_FIELDS
|
|
||||||
* (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
|
||||||
} else if (GPIO_PIN_SOURCE_12 > output_pin) {
|
} else if (GPIO_PIN_SOURCE_12 > output_pin) {
|
||||||
/* select EXTI8/EXTI9/EXTI10/EXTI11 */
|
/* select EXTI8/EXTI9/EXTI10/EXTI11 */
|
||||||
AFIO_EXTISS2 &= ~source;
|
AFIO_EXTISS2 &= ~source;
|
||||||
AFIO_EXTISS2 |= (((uint32_t) output_port)
|
AFIO_EXTISS2 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
||||||
<< (AFIO_EXTI_SOURCE_FIELDS
|
|
||||||
* (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
|
||||||
} else {
|
} else {
|
||||||
/* select EXTI12/EXTI13/EXTI14/EXTI15 */
|
/* select EXTI12/EXTI13/EXTI14/EXTI15 */
|
||||||
AFIO_EXTISS3 &= ~source;
|
AFIO_EXTISS3 &= ~source;
|
||||||
AFIO_EXTISS3 |= (((uint32_t) output_port)
|
AFIO_EXTISS3 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
||||||
<< (AFIO_EXTI_SOURCE_FIELDS
|
|
||||||
* (output_pin & AFIO_EXTI_SOURCE_MASK)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,8 +409,7 @@ void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_event_output_config(uint8_t output_port, uint8_t output_pin)
|
void gpio_event_output_config(uint8_t output_port, uint8_t output_pin) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
reg = AFIO_EC;
|
reg = AFIO_EC;
|
||||||
|
|
||||||
@@ -463,10 +428,7 @@ void gpio_event_output_config(uint8_t output_port, uint8_t output_pin)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_event_output_enable(void)
|
void gpio_event_output_enable(void) { AFIO_EC |= AFIO_EC_EOE; }
|
||||||
{
|
|
||||||
AFIO_EC |= AFIO_EC_EOE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable GPIO pin event output
|
\brief disable GPIO pin event output
|
||||||
@@ -474,10 +436,7 @@ void gpio_event_output_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_event_output_disable(void)
|
void gpio_event_output_disable(void) { AFIO_EC &= (uint32_t)(~AFIO_EC_EOE); }
|
||||||
{
|
|
||||||
AFIO_EC &= (uint32_t) (~AFIO_EC_EOE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief lock GPIO pin
|
\brief lock GPIO pin
|
||||||
@@ -488,8 +447,7 @@ void gpio_event_output_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin)
|
void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin) {
|
||||||
{
|
|
||||||
uint32_t lock = 0x00010000U;
|
uint32_t lock = 0x00010000U;
|
||||||
lock |= pin;
|
lock |= pin;
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_deinit(uint32_t i2c_periph)
|
void i2c_deinit(uint32_t i2c_periph) {
|
||||||
{
|
|
||||||
switch (i2c_periph) {
|
switch (i2c_periph) {
|
||||||
case I2C0:
|
case I2C0:
|
||||||
/* reset I2C0 */
|
/* reset I2C0 */
|
||||||
@@ -79,8 +78,7 @@ void i2c_deinit(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc)
|
void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc) {
|
||||||
{
|
|
||||||
uint32_t pclk1, clkc, freq, risetime;
|
uint32_t pclk1, clkc, freq, risetime;
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
|
|
||||||
@@ -115,8 +113,7 @@ void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc)
|
|||||||
|
|
||||||
} else if (400000U >= clkspeed) {
|
} else if (400000U >= clkspeed) {
|
||||||
/* the maximum SCL rise time is 300ns in fast mode */
|
/* the maximum SCL rise time is 300ns in fast mode */
|
||||||
I2C_RT(i2c_periph) = (uint32_t) (((freq * (uint32_t) 300U)
|
I2C_RT(i2c_periph) = (uint32_t)(((freq * (uint32_t)300U) / (uint32_t)1000U) + (uint32_t)1U);
|
||||||
/ (uint32_t) 1000U) + (uint32_t) 1U);
|
|
||||||
if (I2C_DTCY_2 == dutycyc) {
|
if (I2C_DTCY_2 == dutycyc) {
|
||||||
/* I2C duty cycle is 2 */
|
/* I2C duty cycle is 2 */
|
||||||
clkc = (uint32_t)(pclk1 / (clkspeed * 3U));
|
clkc = (uint32_t)(pclk1 / (clkspeed * 3U));
|
||||||
@@ -151,8 +148,7 @@ void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode,uint32_t addformat, uint32_t addr)
|
void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t addformat, uint32_t addr) {
|
||||||
{
|
|
||||||
/* SMBus/I2C mode selected */
|
/* SMBus/I2C mode selected */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -175,8 +171,7 @@ void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode,uint32_t addformat,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type)
|
void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type) {
|
||||||
{
|
|
||||||
if (I2C_SMBUS_HOST == type) {
|
if (I2C_SMBUS_HOST == type) {
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_SMBSEL;
|
I2C_CTL0(i2c_periph) |= I2C_CTL0_SMBSEL;
|
||||||
} else {
|
} else {
|
||||||
@@ -194,8 +189,7 @@ void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_ack_config(uint32_t i2c_periph, uint32_t ack)
|
void i2c_ack_config(uint32_t i2c_periph, uint32_t ack) {
|
||||||
{
|
|
||||||
if (I2C_ACK_ENABLE == ack) {
|
if (I2C_ACK_ENABLE == ack) {
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_ACKEN;
|
I2C_CTL0(i2c_periph) |= I2C_CTL0_ACKEN;
|
||||||
} else {
|
} else {
|
||||||
@@ -213,8 +207,7 @@ void i2c_ack_config(uint32_t i2c_periph, uint32_t ack)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos)
|
void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos) {
|
||||||
{
|
|
||||||
/* configure I2C POAP position */
|
/* configure I2C POAP position */
|
||||||
if (I2C_ACKPOS_NEXT == pos) {
|
if (I2C_ACKPOS_NEXT == pos) {
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_POAP;
|
I2C_CTL0(i2c_periph) |= I2C_CTL0_POAP;
|
||||||
@@ -234,8 +227,7 @@ void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr,uint32_t trandirection)
|
void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t trandirection) {
|
||||||
{
|
|
||||||
/* master is a transmitter or a receiver */
|
/* master is a transmitter or a receiver */
|
||||||
if (I2C_TRANSMITTER == trandirection) {
|
if (I2C_TRANSMITTER == trandirection) {
|
||||||
addr = addr & I2C_TRANSMITTER;
|
addr = addr & I2C_TRANSMITTER;
|
||||||
@@ -253,8 +245,7 @@ void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr,uint32_t trandirec
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_saddr1_config(uint32_t i2c_periph,uint32_t addr)
|
void i2c_saddr1_config(uint32_t i2c_periph, uint32_t addr) {
|
||||||
{
|
|
||||||
/* configure saddress1 */
|
/* configure saddress1 */
|
||||||
I2C_SADDR1(i2c_periph) = (0xFE & addr);
|
I2C_SADDR1(i2c_periph) = (0xFE & addr);
|
||||||
}
|
}
|
||||||
@@ -266,8 +257,7 @@ void i2c_saddr1_config(uint32_t i2c_periph,uint32_t addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr)
|
void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr) {
|
||||||
{
|
|
||||||
/* configure address */
|
/* configure address */
|
||||||
addr = addr & I2C_ADDRESS2_MASK;
|
addr = addr & I2C_ADDRESS2_MASK;
|
||||||
I2C_SADDR1(i2c_periph) = (I2C_SADDR1_DUADEN | addr);
|
I2C_SADDR1(i2c_periph) = (I2C_SADDR1_DUADEN | addr);
|
||||||
@@ -279,10 +269,7 @@ void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_dualaddr_disable(uint32_t i2c_periph)
|
void i2c_dualaddr_disable(uint32_t i2c_periph) { I2C_SADDR1(i2c_periph) &= ~(I2C_SADDR1_DUADEN); }
|
||||||
{
|
|
||||||
I2C_SADDR1(i2c_periph) &= ~(I2C_SADDR1_DUADEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable I2C
|
\brief enable I2C
|
||||||
@@ -290,10 +277,7 @@ void i2c_dualaddr_disable(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_enable(uint32_t i2c_periph)
|
void i2c_enable(uint32_t i2c_periph) { I2C_CTL0(i2c_periph) |= I2C_CTL0_I2CEN; }
|
||||||
{
|
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_I2CEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable I2C
|
\brief disable I2C
|
||||||
@@ -301,10 +285,7 @@ void i2c_enable(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_disable(uint32_t i2c_periph)
|
void i2c_disable(uint32_t i2c_periph) { I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_I2CEN); }
|
||||||
{
|
|
||||||
I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_I2CEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief generate a START condition on I2C bus
|
\brief generate a START condition on I2C bus
|
||||||
@@ -312,10 +293,7 @@ void i2c_disable(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_start_on_bus(uint32_t i2c_periph)
|
void i2c_start_on_bus(uint32_t i2c_periph) { I2C_CTL0(i2c_periph) |= I2C_CTL0_START; }
|
||||||
{
|
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_START;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief generate a STOP condition on I2C bus
|
\brief generate a STOP condition on I2C bus
|
||||||
@@ -323,10 +301,7 @@ void i2c_start_on_bus(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_stop_on_bus(uint32_t i2c_periph)
|
void i2c_stop_on_bus(uint32_t i2c_periph) { I2C_CTL0(i2c_periph) |= I2C_CTL0_STOP; }
|
||||||
{
|
|
||||||
I2C_CTL0(i2c_periph) |= I2C_CTL0_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief I2C transmit data function
|
\brief I2C transmit data function
|
||||||
@@ -335,10 +310,7 @@ void i2c_stop_on_bus(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_data_transmit(uint32_t i2c_periph, uint8_t data)
|
void i2c_data_transmit(uint32_t i2c_periph, uint8_t data) { I2C_DATA(i2c_periph) = DATA_TRANS(data); }
|
||||||
{
|
|
||||||
I2C_DATA(i2c_periph) = DATA_TRANS(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief I2C receive data function
|
\brief I2C receive data function
|
||||||
@@ -346,10 +318,7 @@ void i2c_data_transmit(uint32_t i2c_periph, uint8_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval data of received
|
\retval data of received
|
||||||
*/
|
*/
|
||||||
uint8_t i2c_data_receive(uint32_t i2c_periph)
|
uint8_t i2c_data_receive(uint32_t i2c_periph) { return (uint8_t)DATA_RECV(I2C_DATA(i2c_periph)); }
|
||||||
{
|
|
||||||
return (uint8_t) DATA_RECV(I2C_DATA(i2c_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable I2C DMA mode
|
\brief enable I2C DMA mode
|
||||||
@@ -361,8 +330,7 @@ uint8_t i2c_data_receive(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate)
|
void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate) {
|
||||||
{
|
|
||||||
/* configure I2C DMA function */
|
/* configure I2C DMA function */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -382,8 +350,7 @@ void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast)
|
void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast) {
|
||||||
{
|
|
||||||
/* configure DMA last transfer */
|
/* configure DMA last transfer */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -403,8 +370,7 @@ void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara)
|
void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara) {
|
||||||
{
|
|
||||||
/* configure I2C SCL strerching enable or disable */
|
/* configure I2C SCL strerching enable or disable */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -424,8 +390,7 @@ void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara)
|
void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara) {
|
||||||
{
|
|
||||||
/* configure slave response to a general call enable or disable */
|
/* configure slave response to a general call enable or disable */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -445,8 +410,7 @@ void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset)
|
void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset) {
|
||||||
{
|
|
||||||
/* modify CTL0 and configure software reset I2C state */
|
/* modify CTL0 and configure software reset I2C state */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -466,8 +430,7 @@ void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate)
|
void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate) {
|
||||||
{
|
|
||||||
/* on/off PEC calculation */
|
/* on/off PEC calculation */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -487,8 +450,7 @@ void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara)
|
void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara) {
|
||||||
{
|
|
||||||
/* whether to transfer PEC */
|
/* whether to transfer PEC */
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -504,10 +466,7 @@ void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval PEC value
|
\retval PEC value
|
||||||
*/
|
*/
|
||||||
uint8_t i2c_pec_value_get(uint32_t i2c_periph)
|
uint8_t i2c_pec_value_get(uint32_t i2c_periph) { return (uint8_t)((I2C_STAT1(i2c_periph) & I2C_STAT1_PECV) >> STAT1_PECV_OFFSET); }
|
||||||
{
|
|
||||||
return (uint8_t) ((I2C_STAT1(i2c_periph) & I2C_STAT1_PECV)>> STAT1_PECV_OFFSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief I2C issue alert through SMBA pin
|
\brief I2C issue alert through SMBA pin
|
||||||
@@ -519,8 +478,7 @@ uint8_t i2c_pec_value_get(uint32_t i2c_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
|
void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara) {
|
||||||
{
|
|
||||||
/* issue alert through SMBA pin configure*/
|
/* issue alert through SMBA pin configure*/
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -540,8 +498,7 @@ void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate)
|
void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate) {
|
||||||
{
|
|
||||||
/* enable or disable I2C ARP protocol*/
|
/* enable or disable I2C ARP protocol*/
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
@@ -580,8 +537,7 @@ void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag)
|
FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag) {
|
||||||
{
|
|
||||||
if (RESET != (I2C_REG_VAL(i2c_periph, flag) & BIT(I2C_BIT_POS(flag)))) {
|
if (RESET != (I2C_REG_VAL(i2c_periph, flag) & BIT(I2C_BIT_POS(flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -605,8 +561,7 @@ FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag)
|
void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag) {
|
||||||
{
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
if (I2C_FLAG_ADDSEND == flag) {
|
if (I2C_FLAG_ADDSEND == flag) {
|
||||||
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
|
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
|
||||||
@@ -628,10 +583,7 @@ void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
|
void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt) { I2C_REG_VAL(i2c_periph, interrupt) |= BIT(I2C_BIT_POS(interrupt)); }
|
||||||
{
|
|
||||||
I2C_REG_VAL(i2c_periph, interrupt) |= BIT(I2C_BIT_POS(interrupt));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable I2C interrupt
|
\brief disable I2C interrupt
|
||||||
@@ -644,10 +596,7 @@ void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
|
void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt) { I2C_REG_VAL(i2c_periph, interrupt) &= ~BIT(I2C_BIT_POS(interrupt)); }
|
||||||
{
|
|
||||||
I2C_REG_VAL(i2c_periph, interrupt) &= ~BIT(I2C_BIT_POS(interrupt));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief check I2C interrupt flag
|
\brief check I2C interrupt flag
|
||||||
@@ -671,8 +620,7 @@ void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph,i2c_interrupt_flag_enum int_flag)
|
FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag) {
|
||||||
{
|
|
||||||
uint32_t intenable = 0U, flagstatus = 0U, bufie;
|
uint32_t intenable = 0U, flagstatus = 0U, bufie;
|
||||||
|
|
||||||
/* check BUFIE */
|
/* check BUFIE */
|
||||||
@@ -713,8 +661,7 @@ FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph,i2c_interrupt_flag_enum in
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2c_interrupt_flag_clear(uint32_t i2c_periph,i2c_interrupt_flag_enum int_flag)
|
void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag) {
|
||||||
{
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
if (I2C_INT_FLAG_ADDSEND == int_flag) {
|
if (I2C_INT_FLAG_ADDSEND == int_flag) {
|
||||||
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
|
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_deinit(void)
|
void pmu_deinit(void) {
|
||||||
{
|
|
||||||
/* reset PMU */
|
/* reset PMU */
|
||||||
rcu_periph_reset_enable(RCU_PMURST);
|
rcu_periph_reset_enable(RCU_PMURST);
|
||||||
rcu_periph_reset_disable(RCU_PMURST);
|
rcu_periph_reset_disable(RCU_PMURST);
|
||||||
@@ -62,8 +61,7 @@ void pmu_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_lvd_select(uint32_t lvdt_n)
|
void pmu_lvd_select(uint32_t lvdt_n) {
|
||||||
{
|
|
||||||
/* disable LVD */
|
/* disable LVD */
|
||||||
PMU_CTL &= ~PMU_CTL_LVDEN;
|
PMU_CTL &= ~PMU_CTL_LVDEN;
|
||||||
/* clear LVDT bits */
|
/* clear LVDT bits */
|
||||||
@@ -80,8 +78,7 @@ void pmu_lvd_select(uint32_t lvdt_n)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_lvd_disable(void)
|
void pmu_lvd_disable(void) {
|
||||||
{
|
|
||||||
/* disable LVD */
|
/* disable LVD */
|
||||||
PMU_CTL &= ~PMU_CTL_LVDEN;
|
PMU_CTL &= ~PMU_CTL_LVDEN;
|
||||||
}
|
}
|
||||||
@@ -95,8 +92,7 @@ void pmu_lvd_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_to_sleepmode(uint8_t sleepmodecmd)
|
void pmu_to_sleepmode(uint8_t sleepmodecmd) {
|
||||||
{
|
|
||||||
/* clear sleepdeep bit of RISC-V system control register */
|
/* clear sleepdeep bit of RISC-V system control register */
|
||||||
__RV_CSR_CLEAR(CSR_WFE, WFE_WFE);
|
__RV_CSR_CLEAR(CSR_WFE, WFE_WFE);
|
||||||
|
|
||||||
@@ -123,8 +119,7 @@ void pmu_to_sleepmode(uint8_t sleepmodecmd)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd)
|
void pmu_to_deepsleepmode(uint32_t ldo, uint8_t deepsleepmodecmd) {
|
||||||
{
|
|
||||||
/* clear stbmod and ldolp bits */
|
/* clear stbmod and ldolp bits */
|
||||||
PMU_CTL &= ~((uint32_t)(PMU_CTL_STBMOD | PMU_CTL_LDOLP));
|
PMU_CTL &= ~((uint32_t)(PMU_CTL_STBMOD | PMU_CTL_LDOLP));
|
||||||
/* set ldolp bit according to pmu_ldo */
|
/* set ldolp bit according to pmu_ldo */
|
||||||
@@ -152,8 +147,7 @@ void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_to_standbymode(uint8_t standbymodecmd)
|
void pmu_to_standbymode(uint8_t standbymodecmd) {
|
||||||
{
|
|
||||||
/* set CSR_SLEEPVALUE bit of RISC-V system control register */
|
/* set CSR_SLEEPVALUE bit of RISC-V system control register */
|
||||||
__RV_CSR_SET(CSR_WFE, WFE_WFE);
|
__RV_CSR_SET(CSR_WFE, WFE_WFE);
|
||||||
|
|
||||||
@@ -180,10 +174,7 @@ void pmu_to_standbymode(uint8_t standbymodecmd)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_wakeup_pin_enable(void)
|
void pmu_wakeup_pin_enable(void) { PMU_CS |= PMU_CS_WUPEN; }
|
||||||
{
|
|
||||||
PMU_CS |= PMU_CS_WUPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable wakeup pin
|
\brief disable wakeup pin
|
||||||
@@ -191,10 +182,7 @@ void pmu_wakeup_pin_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_wakeup_pin_disable(void)
|
void pmu_wakeup_pin_disable(void) { PMU_CS &= ~PMU_CS_WUPEN; }
|
||||||
{
|
|
||||||
PMU_CS &= ~PMU_CS_WUPEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable write access to the registers in backup domain
|
\brief enable write access to the registers in backup domain
|
||||||
@@ -202,10 +190,7 @@ void pmu_wakeup_pin_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_backup_write_enable(void)
|
void pmu_backup_write_enable(void) { PMU_CTL |= PMU_CTL_BKPWEN; }
|
||||||
{
|
|
||||||
PMU_CTL |= PMU_CTL_BKPWEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable write access to the registers in backup domain
|
\brief disable write access to the registers in backup domain
|
||||||
@@ -213,10 +198,7 @@ void pmu_backup_write_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_backup_write_disable(void)
|
void pmu_backup_write_disable(void) { PMU_CTL &= ~PMU_CTL_BKPWEN; }
|
||||||
{
|
|
||||||
PMU_CTL &= ~PMU_CTL_BKPWEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get flag state
|
\brief get flag state
|
||||||
@@ -228,8 +210,7 @@ void pmu_backup_write_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus SET or RESET
|
\retval FlagStatus SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus pmu_flag_get(uint32_t flag)
|
FlagStatus pmu_flag_get(uint32_t flag) {
|
||||||
{
|
|
||||||
if (PMU_CS & flag) {
|
if (PMU_CS & flag) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -246,8 +227,7 @@ FlagStatus pmu_flag_get(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void pmu_flag_clear(uint32_t flag_reset)
|
void pmu_flag_clear(uint32_t flag_reset) {
|
||||||
{
|
|
||||||
switch (flag_reset) {
|
switch (flag_reset) {
|
||||||
case PMU_FLAG_RESET_WAKEUP:
|
case PMU_FLAG_RESET_WAKEUP:
|
||||||
/* reset wakeup flag */
|
/* reset wakeup flag */
|
||||||
|
|||||||
@@ -34,31 +34,27 @@ OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "gd32vf103_rcu.h"
|
#include "gd32vf103_rcu.h"
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief deinitialize the RCU
|
\brief deinitialize the RCU
|
||||||
\param[in] none
|
\param[in] none
|
||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_deinit(void)
|
void rcu_deinit(void) {
|
||||||
{
|
|
||||||
/* enable IRC8M */
|
/* enable IRC8M */
|
||||||
RCU_CTL |= RCU_CTL_IRC8MEN;
|
RCU_CTL |= RCU_CTL_IRC8MEN;
|
||||||
rcu_osci_stab_wait(RCU_IRC8M);
|
rcu_osci_stab_wait(RCU_IRC8M);
|
||||||
|
|
||||||
/* reset CFG0 register */
|
/* reset CFG0 register */
|
||||||
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC |
|
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC | RCU_CFG0_ADCPSC | RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF | RCU_CFG0_USBFSPSC | RCU_CFG0_CKOUT0SEL
|
||||||
RCU_CFG0_ADCPSC | RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF |
|
| RCU_CFG0_ADCPSC_2 | RCU_CFG0_PLLMF_4);
|
||||||
RCU_CFG0_USBFSPSC | RCU_CFG0_CKOUT0SEL | RCU_CFG0_ADCPSC_2 | RCU_CFG0_PLLMF_4);
|
|
||||||
/* reset CTL register */
|
/* reset CTL register */
|
||||||
RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
|
RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
|
||||||
RCU_CTL &= ~RCU_CTL_HXTALBPS;
|
RCU_CTL &= ~RCU_CTL_HXTALBPS;
|
||||||
RCU_CTL &= ~(RCU_CTL_PLL1EN | RCU_CTL_PLL2EN);
|
RCU_CTL &= ~(RCU_CTL_PLL1EN | RCU_CTL_PLL2EN);
|
||||||
/* reset INT and CFG1 register */
|
/* reset INT and CFG1 register */
|
||||||
RCU_INT = 0x00ff0000U;
|
RCU_INT = 0x00ff0000U;
|
||||||
RCU_CFG1 &= ~(RCU_CFG1_PREDV0 | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF | RCU_CFG1_PLL2MF |
|
RCU_CFG1 &= ~(RCU_CFG1_PREDV0 | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF | RCU_CFG1_PLL2MF | RCU_CFG1_PREDV0SEL | RCU_CFG1_I2S1SEL | RCU_CFG1_I2S2SEL);
|
||||||
RCU_CFG1_PREDV0SEL | RCU_CFG1_I2S1SEL | RCU_CFG1_I2S2SEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -86,10 +82,7 @@ void rcu_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_clock_enable(rcu_periph_enum periph)
|
void rcu_periph_clock_enable(rcu_periph_enum periph) { RCU_REG_VAL(periph) |= BIT(RCU_BIT_POS(periph)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph) |= BIT(RCU_BIT_POS(periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the peripherals clock
|
\brief disable the peripherals clock
|
||||||
@@ -116,10 +109,7 @@ void rcu_periph_clock_enable(rcu_periph_enum periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_clock_disable(rcu_periph_enum periph)
|
void rcu_periph_clock_disable(rcu_periph_enum periph) { RCU_REG_VAL(periph) &= ~BIT(RCU_BIT_POS(periph)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph) &= ~BIT(RCU_BIT_POS(periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the peripherals clock when sleep mode
|
\brief enable the peripherals clock when sleep mode
|
||||||
@@ -130,10 +120,7 @@ void rcu_periph_clock_disable(rcu_periph_enum periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph)
|
void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph) { RCU_REG_VAL(periph) |= BIT(RCU_BIT_POS(periph)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph) |= BIT(RCU_BIT_POS(periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the peripherals clock when sleep mode
|
\brief disable the peripherals clock when sleep mode
|
||||||
@@ -144,10 +131,7 @@ void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph)
|
void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph) { RCU_REG_VAL(periph) &= ~BIT(RCU_BIT_POS(periph)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph) &= ~BIT(RCU_BIT_POS(periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief reset the peripherals
|
\brief reset the peripherals
|
||||||
@@ -170,10 +154,7 @@ void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset)
|
void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset) { RCU_REG_VAL(periph_reset) |= BIT(RCU_BIT_POS(periph_reset)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph_reset) |= BIT(RCU_BIT_POS(periph_reset));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable reset the peripheral
|
\brief disable reset the peripheral
|
||||||
@@ -196,10 +177,7 @@ void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset)
|
void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset) { RCU_REG_VAL(periph_reset) &= ~BIT(RCU_BIT_POS(periph_reset)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(periph_reset) &= ~BIT(RCU_BIT_POS(periph_reset));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief reset the BKP domain
|
\brief reset the BKP domain
|
||||||
@@ -207,10 +185,7 @@ void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_bkp_reset_enable(void)
|
void rcu_bkp_reset_enable(void) { RCU_BDCTL |= RCU_BDCTL_BKPRST; }
|
||||||
{
|
|
||||||
RCU_BDCTL |= RCU_BDCTL_BKPRST;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the BKP domain reset
|
\brief disable the BKP domain reset
|
||||||
@@ -218,10 +193,7 @@ void rcu_bkp_reset_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_bkp_reset_disable(void)
|
void rcu_bkp_reset_disable(void) { RCU_BDCTL &= ~RCU_BDCTL_BKPRST; }
|
||||||
{
|
|
||||||
RCU_BDCTL &= ~RCU_BDCTL_BKPRST;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure the system clock source
|
\brief configure the system clock source
|
||||||
@@ -233,8 +205,7 @@ void rcu_bkp_reset_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_system_clock_source_config(uint32_t ck_sys)
|
void rcu_system_clock_source_config(uint32_t ck_sys) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -252,10 +223,7 @@ void rcu_system_clock_source_config(uint32_t ck_sys)
|
|||||||
\arg RCU_SCSS_HXTAL: CK_HXTAL is selected as the CK_SYS source
|
\arg RCU_SCSS_HXTAL: CK_HXTAL is selected as the CK_SYS source
|
||||||
\arg RCU_SCSS_PLL: CK_PLL is selected as the CK_SYS source
|
\arg RCU_SCSS_PLL: CK_PLL is selected as the CK_SYS source
|
||||||
*/
|
*/
|
||||||
uint32_t rcu_system_clock_source_get(void)
|
uint32_t rcu_system_clock_source_get(void) { return (RCU_CFG0 & RCU_CFG0_SCSS); }
|
||||||
{
|
|
||||||
return (RCU_CFG0 & RCU_CFG0_SCSS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure the AHB clock prescaler selection
|
\brief configure the AHB clock prescaler selection
|
||||||
@@ -265,8 +233,7 @@ uint32_t rcu_system_clock_source_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_ahb_clock_config(uint32_t ck_ahb)
|
void rcu_ahb_clock_config(uint32_t ck_ahb) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -288,8 +255,7 @@ void rcu_ahb_clock_config(uint32_t ck_ahb)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_apb1_clock_config(uint32_t ck_apb1)
|
void rcu_apb1_clock_config(uint32_t ck_apb1) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -311,8 +277,7 @@ void rcu_apb1_clock_config(uint32_t ck_apb1)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_apb2_clock_config(uint32_t ck_apb2)
|
void rcu_apb2_clock_config(uint32_t ck_apb2) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -338,8 +303,7 @@ void rcu_apb2_clock_config(uint32_t ck_apb2)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_ckout0_config(uint32_t ckout0_src)
|
void rcu_ckout0_config(uint32_t ckout0_src) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -361,8 +325,7 @@ void rcu_ckout0_config(uint32_t ckout0_src)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul)
|
void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -386,8 +349,7 @@ void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div)
|
void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
|
|
||||||
reg = RCU_CFG1;
|
reg = RCU_CFG1;
|
||||||
@@ -407,8 +369,7 @@ void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_predv1_config(uint32_t predv1_div)
|
void rcu_predv1_config(uint32_t predv1_div) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
|
|
||||||
reg = RCU_CFG1;
|
reg = RCU_CFG1;
|
||||||
@@ -428,8 +389,7 @@ void rcu_predv1_config(uint32_t predv1_div)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_pll1_config(uint32_t pll_mul)
|
void rcu_pll1_config(uint32_t pll_mul) {
|
||||||
{
|
|
||||||
RCU_CFG1 &= ~RCU_CFG1_PLL1MF;
|
RCU_CFG1 &= ~RCU_CFG1_PLL1MF;
|
||||||
RCU_CFG1 |= pll_mul;
|
RCU_CFG1 |= pll_mul;
|
||||||
}
|
}
|
||||||
@@ -442,8 +402,7 @@ void rcu_pll1_config(uint32_t pll_mul)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_pll2_config(uint32_t pll_mul)
|
void rcu_pll2_config(uint32_t pll_mul) {
|
||||||
{
|
|
||||||
RCU_CFG1 &= ~RCU_CFG1_PLL2MF;
|
RCU_CFG1 &= ~RCU_CFG1_PLL2MF;
|
||||||
RCU_CFG1 |= pll_mul;
|
RCU_CFG1 |= pll_mul;
|
||||||
}
|
}
|
||||||
@@ -461,8 +420,7 @@ void rcu_pll2_config(uint32_t pll_mul)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_adc_clock_config(uint32_t adc_psc)
|
void rcu_adc_clock_config(uint32_t adc_psc) {
|
||||||
{
|
|
||||||
uint32_t reg0;
|
uint32_t reg0;
|
||||||
|
|
||||||
/* reset the ADCPSC bits */
|
/* reset the ADCPSC bits */
|
||||||
@@ -503,8 +461,7 @@ void rcu_adc_clock_config(uint32_t adc_psc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_usb_clock_config(uint32_t usb_psc)
|
void rcu_usb_clock_config(uint32_t usb_psc) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG0;
|
reg = RCU_CFG0;
|
||||||
@@ -525,8 +482,7 @@ void rcu_usb_clock_config(uint32_t usb_psc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_rtc_clock_config(uint32_t rtc_clock_source)
|
void rcu_rtc_clock_config(uint32_t rtc_clock_source) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_BDCTL;
|
reg = RCU_BDCTL;
|
||||||
@@ -544,8 +500,7 @@ void rcu_rtc_clock_config(uint32_t rtc_clock_source)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_i2s1_clock_config(uint32_t i2s_clock_source)
|
void rcu_i2s1_clock_config(uint32_t i2s_clock_source) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG1;
|
reg = RCU_CFG1;
|
||||||
@@ -563,8 +518,7 @@ void rcu_i2s1_clock_config(uint32_t i2s_clock_source)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_i2s2_clock_config(uint32_t i2s_clock_source)
|
void rcu_i2s2_clock_config(uint32_t i2s_clock_source) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CFG1;
|
reg = RCU_CFG1;
|
||||||
@@ -593,8 +547,7 @@ void rcu_i2s2_clock_config(uint32_t i2s_clock_source)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus rcu_flag_get(rcu_flag_enum flag)
|
FlagStatus rcu_flag_get(rcu_flag_enum flag) {
|
||||||
{
|
|
||||||
/* get the rcu flag */
|
/* get the rcu flag */
|
||||||
if (RESET != (RCU_REG_VAL(flag) & BIT(RCU_BIT_POS(flag)))) {
|
if (RESET != (RCU_REG_VAL(flag) & BIT(RCU_BIT_POS(flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
@@ -609,10 +562,7 @@ FlagStatus rcu_flag_get(rcu_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_all_reset_flag_clear(void)
|
void rcu_all_reset_flag_clear(void) { RCU_RSTSCK |= RCU_RSTSCK_RSTFC; }
|
||||||
{
|
|
||||||
RCU_RSTSCK |= RCU_RSTSCK_RSTFC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the clock stabilization interrupt and ckm flags
|
\brief get the clock stabilization interrupt and ckm flags
|
||||||
@@ -629,8 +579,7 @@ void rcu_all_reset_flag_clear(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
|
FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag) {
|
||||||
{
|
|
||||||
/* get the rcu interrupt flag */
|
/* get the rcu interrupt flag */
|
||||||
if (RESET != (RCU_REG_VAL(int_flag) & BIT(RCU_BIT_POS(int_flag)))) {
|
if (RESET != (RCU_REG_VAL(int_flag) & BIT(RCU_BIT_POS(int_flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
@@ -654,10 +603,7 @@ FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
|
void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear) { RCU_REG_VAL(int_flag_clear) |= BIT(RCU_BIT_POS(int_flag_clear)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(int_flag_clear) |= BIT(RCU_BIT_POS(int_flag_clear));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the stabilization interrupt
|
\brief enable the stabilization interrupt
|
||||||
@@ -673,10 +619,7 @@ void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_interrupt_enable(rcu_int_enum stab_int)
|
void rcu_interrupt_enable(rcu_int_enum stab_int) { RCU_REG_VAL(stab_int) |= BIT(RCU_BIT_POS(stab_int)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(stab_int) |= BIT(RCU_BIT_POS(stab_int));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the stabilization interrupt
|
\brief disable the stabilization interrupt
|
||||||
@@ -692,10 +635,7 @@ void rcu_interrupt_enable(rcu_int_enum stab_int)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_interrupt_disable(rcu_int_enum stab_int)
|
void rcu_interrupt_disable(rcu_int_enum stab_int) { RCU_REG_VAL(stab_int) &= ~BIT(RCU_BIT_POS(stab_int)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(stab_int) &= ~BIT(RCU_BIT_POS(stab_int));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief wait for oscillator stabilization flags is SET or oscillator startup is timeout
|
\brief wait for oscillator stabilization flags is SET or oscillator startup is timeout
|
||||||
@@ -711,8 +651,7 @@ void rcu_interrupt_disable(rcu_int_enum stab_int)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval ErrStatus: SUCCESS or ERROR
|
\retval ErrStatus: SUCCESS or ERROR
|
||||||
*/
|
*/
|
||||||
ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
|
ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci) {
|
||||||
{
|
|
||||||
uint32_t stb_cnt = 0U;
|
uint32_t stb_cnt = 0U;
|
||||||
ErrStatus reval = ERROR;
|
ErrStatus reval = ERROR;
|
||||||
FlagStatus osci_stat = RESET;
|
FlagStatus osci_stat = RESET;
|
||||||
@@ -829,10 +768,7 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_osci_on(rcu_osci_type_enum osci)
|
void rcu_osci_on(rcu_osci_type_enum osci) { RCU_REG_VAL(osci) |= BIT(RCU_BIT_POS(osci)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(osci) |= BIT(RCU_BIT_POS(osci));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief turn off the oscillator
|
\brief turn off the oscillator
|
||||||
@@ -848,10 +784,7 @@ void rcu_osci_on(rcu_osci_type_enum osci)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_osci_off(rcu_osci_type_enum osci)
|
void rcu_osci_off(rcu_osci_type_enum osci) { RCU_REG_VAL(osci) &= ~BIT(RCU_BIT_POS(osci)); }
|
||||||
{
|
|
||||||
RCU_REG_VAL(osci) &= ~BIT(RCU_BIT_POS(osci));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it
|
\brief enable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it
|
||||||
@@ -862,8 +795,7 @@ void rcu_osci_off(rcu_osci_type_enum osci)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
|
void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
switch (osci) {
|
switch (osci) {
|
||||||
@@ -899,8 +831,7 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
|
void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
switch (osci) {
|
switch (osci) {
|
||||||
@@ -934,10 +865,7 @@ void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
|
|||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void rcu_hxtal_clock_monitor_enable(void)
|
void rcu_hxtal_clock_monitor_enable(void) { RCU_CTL |= RCU_CTL_CKMEN; }
|
||||||
{
|
|
||||||
RCU_CTL |= RCU_CTL_CKMEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the HXTAL clock monitor
|
\brief disable the HXTAL clock monitor
|
||||||
@@ -945,10 +873,7 @@ void rcu_hxtal_clock_monitor_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_hxtal_clock_monitor_disable(void)
|
void rcu_hxtal_clock_monitor_disable(void) { RCU_CTL &= ~RCU_CTL_CKMEN; }
|
||||||
{
|
|
||||||
RCU_CTL &= ~RCU_CTL_CKMEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set the IRC8M adjust value
|
\brief set the IRC8M adjust value
|
||||||
@@ -956,8 +881,7 @@ void rcu_hxtal_clock_monitor_disable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_irc8m_adjust_value_set(uint32_t irc8m_adjval)
|
void rcu_irc8m_adjust_value_set(uint32_t irc8m_adjval) {
|
||||||
{
|
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = RCU_CTL;
|
reg = RCU_CTL;
|
||||||
@@ -977,8 +901,7 @@ void rcu_irc8m_adjust_value_set(uint32_t irc8m_adjval)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rcu_deepsleep_voltage_set(uint32_t dsvol)
|
void rcu_deepsleep_voltage_set(uint32_t dsvol) {
|
||||||
{
|
|
||||||
dsvol &= RCU_DSV_DSLPVS;
|
dsvol &= RCU_DSV_DSLPVS;
|
||||||
RCU_DSV = dsvol;
|
RCU_DSV = dsvol;
|
||||||
}
|
}
|
||||||
@@ -994,8 +917,7 @@ void rcu_deepsleep_voltage_set(uint32_t dsvol)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval clock frequency of system, AHB, APB1, APB2
|
\retval clock frequency of system, AHB, APB1, APB2
|
||||||
*/
|
*/
|
||||||
uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
|
uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock) {
|
||||||
{
|
|
||||||
uint32_t sws, ck_freq = 0U;
|
uint32_t sws, ck_freq = 0U;
|
||||||
uint32_t cksys_freq, ahb_freq, apb1_freq, apb2_freq;
|
uint32_t cksys_freq, ahb_freq, apb1_freq, apb2_freq;
|
||||||
uint32_t pllsel, predv0sel, pllmf, ck_src, idx, clk_exp;
|
uint32_t pllsel, predv0sel, pllmf, ck_src, idx, clk_exp;
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_configuration_mode_enter(void)
|
void rtc_configuration_mode_enter(void) { RTC_CTL |= RTC_CTL_CMF; }
|
||||||
{
|
|
||||||
RTC_CTL |= RTC_CTL_CMF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief exit RTC configuration mode
|
\brief exit RTC configuration mode
|
||||||
@@ -58,10 +55,7 @@ void rtc_configuration_mode_enter(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_configuration_mode_exit(void)
|
void rtc_configuration_mode_exit(void) { RTC_CTL &= ~RTC_CTL_CMF; }
|
||||||
{
|
|
||||||
RTC_CTL &= ~RTC_CTL_CMF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set RTC counter value
|
\brief set RTC counter value
|
||||||
@@ -69,8 +63,7 @@ void rtc_configuration_mode_exit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_counter_set(uint32_t cnt)
|
void rtc_counter_set(uint32_t cnt) {
|
||||||
{
|
|
||||||
rtc_configuration_mode_enter();
|
rtc_configuration_mode_enter();
|
||||||
/* set the RTC counter high bits */
|
/* set the RTC counter high bits */
|
||||||
RTC_CNTH = (cnt >> RTC_HIGH_BITS_OFFSET);
|
RTC_CNTH = (cnt >> RTC_HIGH_BITS_OFFSET);
|
||||||
@@ -85,8 +78,7 @@ void rtc_counter_set(uint32_t cnt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_prescaler_set(uint32_t psc)
|
void rtc_prescaler_set(uint32_t psc) {
|
||||||
{
|
|
||||||
rtc_configuration_mode_enter();
|
rtc_configuration_mode_enter();
|
||||||
/* set the RTC prescaler high bits */
|
/* set the RTC prescaler high bits */
|
||||||
RTC_PSCH = ((psc & RTC_HIGH_BITS_MASK) >> RTC_HIGH_BITS_OFFSET);
|
RTC_PSCH = ((psc & RTC_HIGH_BITS_MASK) >> RTC_HIGH_BITS_OFFSET);
|
||||||
@@ -101,11 +93,9 @@ void rtc_prescaler_set(uint32_t psc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_lwoff_wait(void)
|
void rtc_lwoff_wait(void) {
|
||||||
{
|
|
||||||
/* loop until LWOFF flag is set */
|
/* loop until LWOFF flag is set */
|
||||||
while(RESET == (RTC_CTL & RTC_CTL_LWOFF)){
|
while (RESET == (RTC_CTL & RTC_CTL_LWOFF)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -114,13 +104,11 @@ void rtc_lwoff_wait(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_register_sync_wait(void)
|
void rtc_register_sync_wait(void) {
|
||||||
{
|
|
||||||
/* clear RSYNF flag */
|
/* clear RSYNF flag */
|
||||||
RTC_CTL &= ~RTC_CTL_RSYNF;
|
RTC_CTL &= ~RTC_CTL_RSYNF;
|
||||||
/* loop until RSYNF flag is set */
|
/* loop until RSYNF flag is set */
|
||||||
while(RESET == (RTC_CTL & RTC_CTL_RSYNF)){
|
while (RESET == (RTC_CTL & RTC_CTL_RSYNF)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -129,8 +117,7 @@ void rtc_register_sync_wait(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_alarm_config(uint32_t alarm)
|
void rtc_alarm_config(uint32_t alarm) {
|
||||||
{
|
|
||||||
rtc_configuration_mode_enter();
|
rtc_configuration_mode_enter();
|
||||||
/* set the alarm high bits */
|
/* set the alarm high bits */
|
||||||
RTC_ALRMH = (alarm >> RTC_HIGH_BITS_OFFSET);
|
RTC_ALRMH = (alarm >> RTC_HIGH_BITS_OFFSET);
|
||||||
@@ -145,8 +132,7 @@ void rtc_alarm_config(uint32_t alarm)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval RTC counter value
|
\retval RTC counter value
|
||||||
*/
|
*/
|
||||||
uint32_t rtc_counter_get(void)
|
uint32_t rtc_counter_get(void) {
|
||||||
{
|
|
||||||
uint32_t temp = 0x0U;
|
uint32_t temp = 0x0U;
|
||||||
|
|
||||||
temp = RTC_CNTL;
|
temp = RTC_CNTL;
|
||||||
@@ -160,8 +146,7 @@ uint32_t rtc_counter_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval RTC divider value
|
\retval RTC divider value
|
||||||
*/
|
*/
|
||||||
uint32_t rtc_divider_get(void)
|
uint32_t rtc_divider_get(void) {
|
||||||
{
|
|
||||||
uint32_t temp = 0x00U;
|
uint32_t temp = 0x00U;
|
||||||
|
|
||||||
temp = ((RTC_DIVH & RTC_DIVH_DIV) << RTC_HIGH_BITS_OFFSET);
|
temp = ((RTC_DIVH & RTC_DIVH_DIV) << RTC_HIGH_BITS_OFFSET);
|
||||||
@@ -181,8 +166,7 @@ uint32_t rtc_divider_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval SET or RESET
|
\retval SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus rtc_flag_get(uint32_t flag)
|
FlagStatus rtc_flag_get(uint32_t flag) {
|
||||||
{
|
|
||||||
if (RESET != (RTC_CTL & flag)) {
|
if (RESET != (RTC_CTL & flag)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -201,8 +185,7 @@ FlagStatus rtc_flag_get(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_flag_clear(uint32_t flag)
|
void rtc_flag_clear(uint32_t flag) {
|
||||||
{
|
|
||||||
/* clear RTC flag */
|
/* clear RTC flag */
|
||||||
RTC_CTL &= ~flag;
|
RTC_CTL &= ~flag;
|
||||||
}
|
}
|
||||||
@@ -217,8 +200,7 @@ void rtc_flag_clear(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval SET or RESET
|
\retval SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus rtc_interrupt_flag_get(uint32_t flag)
|
FlagStatus rtc_interrupt_flag_get(uint32_t flag) {
|
||||||
{
|
|
||||||
if (RESET != (RTC_CTL & flag)) {
|
if (RESET != (RTC_CTL & flag)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -236,8 +218,7 @@ FlagStatus rtc_interrupt_flag_get(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_interrupt_flag_clear(uint32_t flag)
|
void rtc_interrupt_flag_clear(uint32_t flag) {
|
||||||
{
|
|
||||||
/* clear RTC interrupt flag */
|
/* clear RTC interrupt flag */
|
||||||
RTC_CTL &= ~flag;
|
RTC_CTL &= ~flag;
|
||||||
}
|
}
|
||||||
@@ -252,10 +233,7 @@ void rtc_interrupt_flag_clear(uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_interrupt_enable(uint32_t interrupt)
|
void rtc_interrupt_enable(uint32_t interrupt) { RTC_INTEN |= interrupt; }
|
||||||
{
|
|
||||||
RTC_INTEN |= interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable RTC interrupt
|
\brief disable RTC interrupt
|
||||||
@@ -267,7 +245,4 @@ void rtc_interrupt_enable(uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void rtc_interrupt_disable(uint32_t interrupt)
|
void rtc_interrupt_disable(uint32_t interrupt) { RTC_INTEN &= ~interrupt; }
|
||||||
{
|
|
||||||
RTC_INTEN &= ~interrupt;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_i2s_deinit(uint32_t spi_periph)
|
void spi_i2s_deinit(uint32_t spi_periph) {
|
||||||
{
|
|
||||||
switch (spi_periph) {
|
switch (spi_periph) {
|
||||||
case SPI0:
|
case SPI0:
|
||||||
/* reset SPI0 */
|
/* reset SPI0 */
|
||||||
@@ -84,8 +83,7 @@ void spi_i2s_deinit(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_struct_para_init(spi_parameter_struct* spi_struct)
|
void spi_struct_para_init(spi_parameter_struct *spi_struct) {
|
||||||
{
|
|
||||||
/* set the SPI struct with the default values */
|
/* set the SPI struct with the default values */
|
||||||
spi_struct->device_mode = SPI_SLAVE;
|
spi_struct->device_mode = SPI_SLAVE;
|
||||||
spi_struct->trans_mode = SPI_TRANSMODE_FULLDUPLEX;
|
spi_struct->trans_mode = SPI_TRANSMODE_FULLDUPLEX;
|
||||||
@@ -112,8 +110,7 @@ void spi_struct_para_init(spi_parameter_struct* spi_struct)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
|
void spi_init(uint32_t spi_periph, spi_parameter_struct *spi_struct) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
reg = SPI_CTL0(spi_periph);
|
reg = SPI_CTL0(spi_periph);
|
||||||
reg &= SPI_INIT_MASK;
|
reg &= SPI_INIT_MASK;
|
||||||
@@ -145,10 +142,7 @@ void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_enable(uint32_t spi_periph)
|
void spi_enable(uint32_t spi_periph) { SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_SPIEN; }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_SPIEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable SPI
|
\brief disable SPI
|
||||||
@@ -156,10 +150,7 @@ void spi_enable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_disable(uint32_t spi_periph)
|
void spi_disable(uint32_t spi_periph) { SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_SPIEN); }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_SPIEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief initialize I2S parameter
|
\brief initialize I2S parameter
|
||||||
@@ -184,8 +175,7 @@ void spi_disable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ckpl)
|
void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ckpl) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
reg = SPI_I2SCTL(spi_periph);
|
reg = SPI_I2SCTL(spi_periph);
|
||||||
reg &= I2S_INIT_MASK;
|
reg &= I2S_INIT_MASK;
|
||||||
@@ -230,8 +220,7 @@ void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ck
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout)
|
void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout) {
|
||||||
{
|
|
||||||
uint32_t i2sdiv = 2U, i2sof = 0U;
|
uint32_t i2sdiv = 2U, i2sof = 0U;
|
||||||
uint32_t clks = 0U;
|
uint32_t clks = 0U;
|
||||||
uint32_t i2sclock = 0U;
|
uint32_t i2sclock = 0U;
|
||||||
@@ -308,10 +297,7 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t framefor
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2s_enable(uint32_t spi_periph)
|
void i2s_enable(uint32_t spi_periph) { SPI_I2SCTL(spi_periph) |= (uint32_t)SPI_I2SCTL_I2SEN; }
|
||||||
{
|
|
||||||
SPI_I2SCTL(spi_periph) |= (uint32_t)SPI_I2SCTL_I2SEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable I2S
|
\brief disable I2S
|
||||||
@@ -319,10 +305,7 @@ void i2s_enable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void i2s_disable(uint32_t spi_periph)
|
void i2s_disable(uint32_t spi_periph) { SPI_I2SCTL(spi_periph) &= (uint32_t)(~SPI_I2SCTL_I2SEN); }
|
||||||
{
|
|
||||||
SPI_I2SCTL(spi_periph) &= (uint32_t)(~SPI_I2SCTL_I2SEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable SPI NSS output
|
\brief enable SPI NSS output
|
||||||
@@ -330,10 +313,7 @@ void i2s_disable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nss_output_enable(uint32_t spi_periph)
|
void spi_nss_output_enable(uint32_t spi_periph) { SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_NSSDRV; }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_NSSDRV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable SPI NSS output
|
\brief disable SPI NSS output
|
||||||
@@ -341,10 +321,7 @@ void spi_nss_output_enable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nss_output_disable(uint32_t spi_periph)
|
void spi_nss_output_disable(uint32_t spi_periph) { SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_NSSDRV); }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_NSSDRV);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI NSS pin high level in software mode
|
\brief SPI NSS pin high level in software mode
|
||||||
@@ -352,10 +329,7 @@ void spi_nss_output_disable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nss_internal_high(uint32_t spi_periph)
|
void spi_nss_internal_high(uint32_t spi_periph) { SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_SWNSS; }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_SWNSS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI NSS pin low level in software mode
|
\brief SPI NSS pin low level in software mode
|
||||||
@@ -363,10 +337,7 @@ void spi_nss_internal_high(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nss_internal_low(uint32_t spi_periph)
|
void spi_nss_internal_low(uint32_t spi_periph) { SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_SWNSS); }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_SWNSS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable SPI DMA send or receive
|
\brief enable SPI DMA send or receive
|
||||||
@@ -378,8 +349,7 @@ void spi_nss_internal_low(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_dma_enable(uint32_t spi_periph, uint8_t dma)
|
void spi_dma_enable(uint32_t spi_periph, uint8_t dma) {
|
||||||
{
|
|
||||||
if (SPI_DMA_TRANSMIT == dma) {
|
if (SPI_DMA_TRANSMIT == dma) {
|
||||||
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_DMATEN;
|
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_DMATEN;
|
||||||
} else {
|
} else {
|
||||||
@@ -397,8 +367,7 @@ void spi_dma_enable(uint32_t spi_periph, uint8_t dma)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_dma_disable(uint32_t spi_periph, uint8_t dma)
|
void spi_dma_disable(uint32_t spi_periph, uint8_t dma) {
|
||||||
{
|
|
||||||
if (SPI_DMA_TRANSMIT == dma) {
|
if (SPI_DMA_TRANSMIT == dma) {
|
||||||
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_DMATEN);
|
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_DMATEN);
|
||||||
} else {
|
} else {
|
||||||
@@ -416,8 +385,7 @@ void spi_dma_disable(uint32_t spi_periph, uint8_t dma)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format)
|
void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format) {
|
||||||
{
|
|
||||||
/* clear SPI_CTL0_FF16 bit */
|
/* clear SPI_CTL0_FF16 bit */
|
||||||
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_FF16);
|
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_FF16);
|
||||||
/* configure SPI_CTL0_FF16 bit */
|
/* configure SPI_CTL0_FF16 bit */
|
||||||
@@ -431,10 +399,7 @@ void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data)
|
void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data) { SPI_DATA(spi_periph) = (uint32_t)data; }
|
||||||
{
|
|
||||||
SPI_DATA(spi_periph) = (uint32_t)data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI receive data
|
\brief SPI receive data
|
||||||
@@ -442,10 +407,7 @@ void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 16-bit data
|
\retval 16-bit data
|
||||||
*/
|
*/
|
||||||
uint16_t spi_i2s_data_receive(uint32_t spi_periph)
|
uint16_t spi_i2s_data_receive(uint32_t spi_periph) { return ((uint16_t)SPI_DATA(spi_periph)); }
|
||||||
{
|
|
||||||
return ((uint16_t)SPI_DATA(spi_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure SPI bidirectional transfer direction
|
\brief configure SPI bidirectional transfer direction
|
||||||
@@ -457,8 +419,7 @@ uint16_t spi_i2s_data_receive(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction)
|
void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction) {
|
||||||
{
|
|
||||||
if (SPI_BIDIRECTIONAL_TRANSMIT == transfer_direction) {
|
if (SPI_BIDIRECTIONAL_TRANSMIT == transfer_direction) {
|
||||||
/* set the transmit-only mode */
|
/* set the transmit-only mode */
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TRANSMIT;
|
SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TRANSMIT;
|
||||||
@@ -475,8 +436,7 @@ void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_di
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_crc_polynomial_set(uint32_t spi_periph,uint16_t crc_poly)
|
void spi_crc_polynomial_set(uint32_t spi_periph, uint16_t crc_poly) {
|
||||||
{
|
|
||||||
/* enable SPI CRC */
|
/* enable SPI CRC */
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
|
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
|
||||||
|
|
||||||
@@ -490,10 +450,7 @@ void spi_crc_polynomial_set(uint32_t spi_periph,uint16_t crc_poly)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 16-bit CRC polynomial
|
\retval 16-bit CRC polynomial
|
||||||
*/
|
*/
|
||||||
uint16_t spi_crc_polynomial_get(uint32_t spi_periph)
|
uint16_t spi_crc_polynomial_get(uint32_t spi_periph) { return ((uint16_t)SPI_CRCPOLY(spi_periph)); }
|
||||||
{
|
|
||||||
return ((uint16_t)SPI_CRCPOLY(spi_periph));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief turn on CRC function
|
\brief turn on CRC function
|
||||||
@@ -501,10 +458,7 @@ uint16_t spi_crc_polynomial_get(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_crc_on(uint32_t spi_periph)
|
void spi_crc_on(uint32_t spi_periph) { SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN; }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief turn off CRC function
|
\brief turn off CRC function
|
||||||
@@ -512,10 +466,7 @@ void spi_crc_on(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_crc_off(uint32_t spi_periph)
|
void spi_crc_off(uint32_t spi_periph) { SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_CRCEN); }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_CRCEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI next data is CRC value
|
\brief SPI next data is CRC value
|
||||||
@@ -523,10 +474,7 @@ void spi_crc_off(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_crc_next(uint32_t spi_periph)
|
void spi_crc_next(uint32_t spi_periph) { SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCNT; }
|
||||||
{
|
|
||||||
SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get SPI CRC send value or receive value
|
\brief get SPI CRC send value or receive value
|
||||||
@@ -538,8 +486,7 @@ void spi_crc_next(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval 16-bit CRC value
|
\retval 16-bit CRC value
|
||||||
*/
|
*/
|
||||||
uint16_t spi_crc_get(uint32_t spi_periph,uint8_t crc)
|
uint16_t spi_crc_get(uint32_t spi_periph, uint8_t crc) {
|
||||||
{
|
|
||||||
if (SPI_CRC_TX == crc) {
|
if (SPI_CRC_TX == crc) {
|
||||||
return ((uint16_t)(SPI_TCRC(spi_periph)));
|
return ((uint16_t)(SPI_TCRC(spi_periph)));
|
||||||
} else {
|
} else {
|
||||||
@@ -553,10 +500,7 @@ uint16_t spi_crc_get(uint32_t spi_periph,uint8_t crc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_ti_mode_enable(uint32_t spi_periph)
|
void spi_ti_mode_enable(uint32_t spi_periph) { SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_TMOD; }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_TMOD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable SPI TI mode
|
\brief disable SPI TI mode
|
||||||
@@ -564,10 +508,7 @@ void spi_ti_mode_enable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_ti_mode_disable(uint32_t spi_periph)
|
void spi_ti_mode_disable(uint32_t spi_periph) { SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_TMOD); }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_TMOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable SPI NSS pulse mode
|
\brief enable SPI NSS pulse mode
|
||||||
@@ -575,10 +516,7 @@ void spi_ti_mode_disable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nssp_mode_enable(uint32_t spi_periph)
|
void spi_nssp_mode_enable(uint32_t spi_periph) { SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_NSSP; }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_NSSP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable SPI NSS pulse mode
|
\brief disable SPI NSS pulse mode
|
||||||
@@ -586,11 +524,7 @@ void spi_nssp_mode_enable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_nssp_mode_disable(uint32_t spi_periph)
|
void spi_nssp_mode_disable(uint32_t spi_periph) { SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_NSSP); }
|
||||||
{
|
|
||||||
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_NSSP);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable SPI and I2S interrupt
|
\brief enable SPI and I2S interrupt
|
||||||
@@ -604,8 +538,7 @@ void spi_nssp_mode_disable(uint32_t spi_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt)
|
void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt) {
|
||||||
{
|
|
||||||
switch (interrupt) {
|
switch (interrupt) {
|
||||||
/* SPI/I2S transmit buffer empty interrupt */
|
/* SPI/I2S transmit buffer empty interrupt */
|
||||||
case SPI_I2S_INT_TBE:
|
case SPI_I2S_INT_TBE:
|
||||||
@@ -636,8 +569,7 @@ void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt)
|
void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt) {
|
||||||
{
|
|
||||||
switch (interrupt) {
|
switch (interrupt) {
|
||||||
/* SPI/I2S transmit buffer empty interrupt */
|
/* SPI/I2S transmit buffer empty interrupt */
|
||||||
case SPI_I2S_INT_TBE:
|
case SPI_I2S_INT_TBE:
|
||||||
@@ -671,8 +603,7 @@ void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt)
|
FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt) {
|
||||||
{
|
|
||||||
uint32_t reg1 = SPI_STAT(spi_periph);
|
uint32_t reg1 = SPI_STAT(spi_periph);
|
||||||
uint32_t reg2 = SPI_CTL1(spi_periph);
|
uint32_t reg2 = SPI_CTL1(spi_periph);
|
||||||
|
|
||||||
@@ -745,8 +676,7 @@ FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag)
|
FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag) {
|
||||||
{
|
|
||||||
if (RESET != (SPI_STAT(spi_periph) & flag)) {
|
if (RESET != (SPI_STAT(spi_periph) & flag)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -760,7 +690,4 @@ FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void spi_crc_error_clear(uint32_t spi_periph)
|
void spi_crc_error_clear(uint32_t spi_periph) { SPI_STAT(spi_periph) &= (uint32_t)(~SPI_FLAG_CRCERR); }
|
||||||
{
|
|
||||||
SPI_STAT(spi_periph) &= (uint32_t)(~SPI_FLAG_CRCERR);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_deinit(uint32_t timer_periph)
|
void timer_deinit(uint32_t timer_periph) {
|
||||||
{
|
|
||||||
switch (timer_periph) {
|
switch (timer_periph) {
|
||||||
case TIMER0:
|
case TIMER0:
|
||||||
/* reset TIMER0 */
|
/* reset TIMER0 */
|
||||||
@@ -94,8 +93,7 @@ void timer_deinit(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_struct_para_init(timer_parameter_struct* initpara)
|
void timer_struct_para_init(timer_parameter_struct *initpara) {
|
||||||
{
|
|
||||||
/* initialize the init parameter struct member with the default value */
|
/* initialize the init parameter struct member with the default value */
|
||||||
initpara->prescaler = 0U;
|
initpara->prescaler = 0U;
|
||||||
initpara->alignedmode = TIMER_COUNTER_EDGE;
|
initpara->alignedmode = TIMER_COUNTER_EDGE;
|
||||||
@@ -119,14 +117,12 @@ void timer_struct_para_init(timer_parameter_struct* initpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
|
void timer_init(uint32_t timer_periph, timer_parameter_struct *initpara) {
|
||||||
{
|
|
||||||
/* configure the counter prescaler value */
|
/* configure the counter prescaler value */
|
||||||
TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
|
TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
|
||||||
|
|
||||||
/* configure the counter direction and aligned mode */
|
/* configure the counter direction and aligned mode */
|
||||||
if((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph)
|
if ((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph) || (TIMER3 == timer_periph) || (TIMER4 == timer_periph)) {
|
||||||
|| (TIMER3 == timer_periph) || (TIMER4 == timer_periph) ){
|
|
||||||
TIMER_CTL0(timer_periph) &= (~(uint32_t)(TIMER_CTL0_DIR | TIMER_CTL0_CAM));
|
TIMER_CTL0(timer_periph) &= (~(uint32_t)(TIMER_CTL0_DIR | TIMER_CTL0_CAM));
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->alignedmode & ALIGNEDMODE_MASK);
|
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->alignedmode & ALIGNEDMODE_MASK);
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->counterdirection & COUNTERDIRECTION_MASK);
|
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->counterdirection & COUNTERDIRECTION_MASK);
|
||||||
@@ -159,10 +155,7 @@ void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_enable(uint32_t timer_periph)
|
void timer_enable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_CEN; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_CEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable a timer
|
\brief disable a timer
|
||||||
@@ -170,10 +163,7 @@ void timer_enable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_disable(uint32_t timer_periph)
|
void timer_disable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CEN; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the auto reload shadow function
|
\brief enable the auto reload shadow function
|
||||||
@@ -181,10 +171,7 @@ void timer_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_auto_reload_shadow_enable(uint32_t timer_periph)
|
void timer_auto_reload_shadow_enable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_ARSE; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_ARSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the auto reload shadow function
|
\brief disable the auto reload shadow function
|
||||||
@@ -192,10 +179,7 @@ void timer_auto_reload_shadow_enable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_auto_reload_shadow_disable(uint32_t timer_periph)
|
void timer_auto_reload_shadow_disable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_ARSE; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_ARSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the update event
|
\brief enable the update event
|
||||||
@@ -203,10 +187,7 @@ void timer_auto_reload_shadow_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_update_event_enable(uint32_t timer_periph)
|
void timer_update_event_enable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPDIS; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPDIS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the update event
|
\brief disable the update event
|
||||||
@@ -214,10 +195,7 @@ void timer_update_event_enable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_update_event_disable(uint32_t timer_periph)
|
void timer_update_event_disable(uint32_t timer_periph) { TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPDIS; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t) TIMER_CTL0_UPDIS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set TIMER counter alignment mode
|
\brief set TIMER counter alignment mode
|
||||||
@@ -231,8 +209,7 @@ void timer_update_event_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
|
void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned) {
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) &= (uint32_t)(~TIMER_CTL0_CAM);
|
TIMER_CTL0(timer_periph) &= (uint32_t)(~TIMER_CTL0_CAM);
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
|
TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
|
||||||
}
|
}
|
||||||
@@ -243,10 +220,7 @@ void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_counter_up_direction(uint32_t timer_periph)
|
void timer_counter_up_direction(uint32_t timer_periph) { TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_DIR; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief set TIMER counter down direction
|
\brief set TIMER counter down direction
|
||||||
@@ -254,10 +228,7 @@ void timer_counter_up_direction(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_counter_down_direction(uint32_t timer_periph)
|
void timer_counter_down_direction(uint32_t timer_periph) { TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_DIR; }
|
||||||
{
|
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure TIMER prescaler
|
\brief configure TIMER prescaler
|
||||||
@@ -270,8 +241,7 @@ void timer_counter_down_direction(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t pscreload)
|
void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t pscreload) {
|
||||||
{
|
|
||||||
TIMER_PSC(timer_periph) = (uint32_t)prescaler;
|
TIMER_PSC(timer_periph) = (uint32_t)prescaler;
|
||||||
|
|
||||||
if (TIMER_PSC_RELOAD_NOW == pscreload) {
|
if (TIMER_PSC_RELOAD_NOW == pscreload) {
|
||||||
@@ -286,10 +256,7 @@ void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition)
|
void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition) { TIMER_CREP(timer_periph) = (uint32_t)repetition; }
|
||||||
{
|
|
||||||
TIMER_CREP(timer_periph) = (uint32_t)repetition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure TIMER autoreload register value
|
\brief configure TIMER autoreload register value
|
||||||
@@ -298,10 +265,7 @@ void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_autoreload_value_config(uint32_t timer_periph, uint16_t autoreload)
|
void timer_autoreload_value_config(uint32_t timer_periph, uint16_t autoreload) { TIMER_CAR(timer_periph) = (uint32_t)autoreload; }
|
||||||
{
|
|
||||||
TIMER_CAR(timer_periph) = (uint32_t)autoreload;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure TIMER counter register value
|
\brief configure TIMER counter register value
|
||||||
@@ -310,10 +274,7 @@ void timer_autoreload_value_config(uint32_t timer_periph, uint16_t autoreload)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_counter_value_config(uint32_t timer_periph, uint16_t counter)
|
void timer_counter_value_config(uint32_t timer_periph, uint16_t counter) { TIMER_CNT(timer_periph) = (uint32_t)counter; }
|
||||||
{
|
|
||||||
TIMER_CNT(timer_periph) = (uint32_t)counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief read TIMER counter value
|
\brief read TIMER counter value
|
||||||
@@ -321,8 +282,7 @@ void timer_counter_value_config(uint32_t timer_periph, uint16_t counter)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval counter value
|
\retval counter value
|
||||||
*/
|
*/
|
||||||
uint32_t timer_counter_read(uint32_t timer_periph)
|
uint32_t timer_counter_read(uint32_t timer_periph) {
|
||||||
{
|
|
||||||
uint32_t count_value = 0U;
|
uint32_t count_value = 0U;
|
||||||
count_value = TIMER_CNT(timer_periph);
|
count_value = TIMER_CNT(timer_periph);
|
||||||
return (count_value);
|
return (count_value);
|
||||||
@@ -334,8 +294,7 @@ uint32_t timer_counter_read(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval prescaler register value
|
\retval prescaler register value
|
||||||
*/
|
*/
|
||||||
uint16_t timer_prescaler_read(uint32_t timer_periph)
|
uint16_t timer_prescaler_read(uint32_t timer_periph) {
|
||||||
{
|
|
||||||
uint16_t prescaler_value = 0U;
|
uint16_t prescaler_value = 0U;
|
||||||
prescaler_value = (uint16_t)(TIMER_PSC(timer_periph));
|
prescaler_value = (uint16_t)(TIMER_PSC(timer_periph));
|
||||||
return (prescaler_value);
|
return (prescaler_value);
|
||||||
@@ -351,8 +310,7 @@ uint16_t timer_prescaler_read(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
|
void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode) {
|
||||||
{
|
|
||||||
if (TIMER_SP_MODE_SINGLE == spmode) {
|
if (TIMER_SP_MODE_SINGLE == spmode) {
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
|
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
|
||||||
} else if (TIMER_SP_MODE_REPETITIVE == spmode) {
|
} else if (TIMER_SP_MODE_REPETITIVE == spmode) {
|
||||||
@@ -373,8 +331,7 @@ void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_update_source_config(uint32_t timer_periph, uint32_t update)
|
void timer_update_source_config(uint32_t timer_periph, uint32_t update) {
|
||||||
{
|
|
||||||
if (TIMER_UPDATE_SRC_REGULAR == update) {
|
if (TIMER_UPDATE_SRC_REGULAR == update) {
|
||||||
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
|
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
|
||||||
} else if (TIMER_UPDATE_SRC_GLOBAL == update) {
|
} else if (TIMER_UPDATE_SRC_GLOBAL == update) {
|
||||||
@@ -399,10 +356,7 @@ void timer_update_source_config(uint32_t timer_periph, uint32_t update)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
|
void timer_dma_enable(uint32_t timer_periph, uint16_t dma) { TIMER_DMAINTEN(timer_periph) |= (uint32_t)dma; }
|
||||||
{
|
|
||||||
TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the TIMER DMA
|
\brief disable the TIMER DMA
|
||||||
@@ -419,10 +373,7 @@ void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
|
void timer_dma_disable(uint32_t timer_periph, uint16_t dma) { TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma)); }
|
||||||
{
|
|
||||||
TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief channel DMA request source selection
|
\brief channel DMA request source selection
|
||||||
@@ -434,8 +385,7 @@ void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma_request)
|
void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma_request) {
|
||||||
{
|
|
||||||
if (TIMER_DMAREQUEST_UPDATEEVENT == dma_request) {
|
if (TIMER_DMAREQUEST_UPDATEEVENT == dma_request) {
|
||||||
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
|
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
|
||||||
} else if (TIMER_DMAREQUEST_CHANNELEVENT == dma_request) {
|
} else if (TIMER_DMAREQUEST_CHANNELEVENT == dma_request) {
|
||||||
@@ -475,8 +425,7 @@ void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth)
|
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth) {
|
||||||
{
|
|
||||||
TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
|
TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
|
||||||
TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth);
|
TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth);
|
||||||
}
|
}
|
||||||
@@ -497,10 +446,7 @@ void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uin
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
|
void timer_event_software_generate(uint32_t timer_periph, uint16_t event) { TIMER_SWEVG(timer_periph) |= (uint32_t)event; }
|
||||||
{
|
|
||||||
TIMER_SWEVG(timer_periph) |= (uint32_t)event;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief initialize TIMER break parameter struct with a default value
|
\brief initialize TIMER break parameter struct with a default value
|
||||||
@@ -508,8 +454,7 @@ void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
|
void timer_break_struct_para_init(timer_break_parameter_struct *breakpara) {
|
||||||
{
|
|
||||||
/* initialize the break parameter struct member with the default value */
|
/* initialize the break parameter struct member with the default value */
|
||||||
breakpara->runoffstate = TIMER_ROS_STATE_DISABLE;
|
breakpara->runoffstate = TIMER_ROS_STATE_DISABLE;
|
||||||
breakpara->ideloffstate = TIMER_IOS_STATE_DISABLE;
|
breakpara->ideloffstate = TIMER_IOS_STATE_DISABLE;
|
||||||
@@ -534,15 +479,9 @@ void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara)
|
void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct *breakpara) {
|
||||||
{
|
TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(breakpara->runoffstate)) | ((uint32_t)(breakpara->ideloffstate)) | ((uint32_t)(breakpara->deadtime)) | ((uint32_t)(breakpara->breakpolarity))
|
||||||
TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(breakpara->runoffstate)) |
|
| ((uint32_t)(breakpara->outputautostate)) | ((uint32_t)(breakpara->protectmode)) | ((uint32_t)(breakpara->breakstate)));
|
||||||
((uint32_t)(breakpara->ideloffstate))|
|
|
||||||
((uint32_t)(breakpara->deadtime)) |
|
|
||||||
((uint32_t)(breakpara->breakpolarity)) |
|
|
||||||
((uint32_t)(breakpara->outputautostate)) |
|
|
||||||
((uint32_t)(breakpara->protectmode)) |
|
|
||||||
((uint32_t)(breakpara->breakstate)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -551,10 +490,7 @@ void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* bre
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_break_enable(uint32_t timer_periph)
|
void timer_break_enable(uint32_t timer_periph) { TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_BRKEN; }
|
||||||
{
|
|
||||||
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_BRKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable TIMER break function
|
\brief disable TIMER break function
|
||||||
@@ -562,10 +498,7 @@ void timer_break_enable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_break_disable(uint32_t timer_periph)
|
void timer_break_disable(uint32_t timer_periph) { TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_BRKEN; }
|
||||||
{
|
|
||||||
TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_BRKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable TIMER output automatic function
|
\brief enable TIMER output automatic function
|
||||||
@@ -573,10 +506,7 @@ void timer_break_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_automatic_output_enable(uint32_t timer_periph)
|
void timer_automatic_output_enable(uint32_t timer_periph) { TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_OAEN; }
|
||||||
{
|
|
||||||
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_OAEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable TIMER output automatic function
|
\brief disable TIMER output automatic function
|
||||||
@@ -584,10 +514,7 @@ void timer_automatic_output_enable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_automatic_output_disable(uint32_t timer_periph)
|
void timer_automatic_output_disable(uint32_t timer_periph) { TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_OAEN; }
|
||||||
{
|
|
||||||
TIMER_CCHP(timer_periph) &= ~(uint32_t)TIMER_CCHP_OAEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable or disable TIMER primary output function
|
\brief enable or disable TIMER primary output function
|
||||||
@@ -596,8 +523,7 @@ void timer_automatic_output_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue)
|
void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue) {
|
||||||
{
|
|
||||||
if (ENABLE == newvalue) {
|
if (ENABLE == newvalue) {
|
||||||
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_POEN;
|
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_POEN;
|
||||||
} else {
|
} else {
|
||||||
@@ -612,8 +538,7 @@ void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue)
|
void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue) {
|
||||||
{
|
|
||||||
if (ENABLE == newvalue) {
|
if (ENABLE == newvalue) {
|
||||||
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCSE;
|
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCSE;
|
||||||
} else {
|
} else {
|
||||||
@@ -631,8 +556,7 @@ void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus ne
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint32_t ccuctl)
|
void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint32_t ccuctl) {
|
||||||
{
|
|
||||||
if (TIMER_UPDATECTL_CCU == ccuctl) {
|
if (TIMER_UPDATECTL_CCU == ccuctl) {
|
||||||
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCUC);
|
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCUC);
|
||||||
} else if (TIMER_UPDATECTL_CCUTRI == ccuctl) {
|
} else if (TIMER_UPDATECTL_CCUTRI == ccuctl) {
|
||||||
@@ -648,8 +572,7 @@ void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint32_t
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
|
void timer_channel_output_struct_para_init(timer_oc_parameter_struct *ocpara) {
|
||||||
{
|
|
||||||
/* initialize the channel output parameter struct member with the default value */
|
/* initialize the channel output parameter struct member with the default value */
|
||||||
ocpara->outputstate = TIMER_CCX_DISABLE;
|
ocpara->outputstate = TIMER_CCX_DISABLE;
|
||||||
ocpara->outputnstate = TIMER_CCXN_DISABLE;
|
ocpara->outputnstate = TIMER_CCXN_DISABLE;
|
||||||
@@ -678,8 +601,7 @@ void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct* ocpara)
|
void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct *ocpara) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -820,8 +742,7 @@ void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode)
|
void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -861,8 +782,7 @@ void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse)
|
void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -901,8 +821,7 @@ void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t cha
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow)
|
void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -945,8 +864,7 @@ void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast)
|
void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -989,8 +907,7 @@ void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear)
|
void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1033,8 +950,7 @@ void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity)
|
void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1076,8 +992,7 @@ void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channe
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity)
|
void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1115,8 +1030,7 @@ void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, u
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state)
|
void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1158,8 +1072,7 @@ void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate)
|
void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1187,8 +1100,7 @@ void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
|
void timer_channel_input_struct_para_init(timer_ic_parameter_struct *icpara) {
|
||||||
{
|
|
||||||
/* initialize the channel input parameter struct member with the default value */
|
/* initialize the channel input parameter struct member with the default value */
|
||||||
icpara->icpolarity = TIMER_IC_POLARITY_RISING;
|
icpara->icpolarity = TIMER_IC_POLARITY_RISING;
|
||||||
icpara->icselection = TIMER_IC_SELECTION_DIRECTTI;
|
icpara->icselection = TIMER_IC_SELECTION_DIRECTTI;
|
||||||
@@ -1216,8 +1128,7 @@ void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpara)
|
void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpara) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1321,8 +1232,7 @@ void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_i
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler)
|
void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler) {
|
||||||
{
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
/* configure TIMER_CH_0 */
|
/* configure TIMER_CH_0 */
|
||||||
case TIMER_CH_0:
|
case TIMER_CH_0:
|
||||||
@@ -1361,8 +1271,7 @@ void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval channel capture compare register value
|
\retval channel capture compare register value
|
||||||
*/
|
*/
|
||||||
uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel)
|
uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel) {
|
||||||
{
|
|
||||||
uint32_t count_value = 0U;
|
uint32_t count_value = 0U;
|
||||||
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
@@ -1404,8 +1313,7 @@ uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm)
|
void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpwm) {
|
||||||
{
|
|
||||||
uint16_t icpolarity = 0x0U;
|
uint16_t icpolarity = 0x0U;
|
||||||
uint16_t icselection = 0x0U;
|
uint16_t icselection = 0x0U;
|
||||||
|
|
||||||
@@ -1511,8 +1419,7 @@ void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, tim
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
|
void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode) {
|
||||||
{
|
|
||||||
if (TIMER_HALLINTERFACE_ENABLE == hallmode) {
|
if (TIMER_HALLINTERFACE_ENABLE == hallmode) {
|
||||||
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
|
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
|
||||||
} else if (TIMER_HALLINTERFACE_DISABLE == hallmode) {
|
} else if (TIMER_HALLINTERFACE_DISABLE == hallmode) {
|
||||||
@@ -1538,8 +1445,7 @@ void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger)
|
void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger) {
|
||||||
{
|
|
||||||
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_TRGS);
|
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_TRGS);
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)intrigger;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)intrigger;
|
||||||
}
|
}
|
||||||
@@ -1560,8 +1466,7 @@ void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger)
|
void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger) {
|
||||||
{
|
|
||||||
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_MMC);
|
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_MMC);
|
||||||
TIMER_CTL1(timer_periph) |= (uint32_t)outrigger;
|
TIMER_CTL1(timer_periph) |= (uint32_t)outrigger;
|
||||||
}
|
}
|
||||||
@@ -1583,8 +1488,7 @@ void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t o
|
|||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
|
void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode) {
|
||||||
{
|
|
||||||
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
|
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)slavemode;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)slavemode;
|
||||||
}
|
}
|
||||||
@@ -1599,8 +1503,7 @@ void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
|
void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave) {
|
||||||
{
|
|
||||||
if (TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave) {
|
if (TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave) {
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
|
||||||
} else if (TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave) {
|
} else if (TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave) {
|
||||||
@@ -1627,8 +1530,7 @@ void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
|
void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter) {
|
||||||
{
|
|
||||||
TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
|
TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)(extprescaler | extpolarity);
|
TIMER_SMCFG(timer_periph) |= (uint32_t)(extprescaler | extpolarity);
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)(extfilter << 8U);
|
TIMER_SMCFG(timer_periph) |= (uint32_t)(extfilter << 8U);
|
||||||
@@ -1653,8 +1555,7 @@ void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler,
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity)
|
void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity) {
|
||||||
{
|
|
||||||
/* configure the quadrature decoder mode */
|
/* configure the quadrature decoder mode */
|
||||||
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
|
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)decomode;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)decomode;
|
||||||
@@ -1673,10 +1574,7 @@ void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomo
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_internal_clock_config(uint32_t timer_periph)
|
void timer_internal_clock_config(uint32_t timer_periph) { TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC; }
|
||||||
{
|
|
||||||
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure TIMER the internal trigger as external clock input
|
\brief configure TIMER the internal trigger as external clock input
|
||||||
@@ -1690,8 +1588,7 @@ void timer_internal_clock_config(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger)
|
void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger) {
|
||||||
{
|
|
||||||
timer_input_trigger_source_select(timer_periph, intrigger);
|
timer_input_trigger_source_select(timer_periph, intrigger);
|
||||||
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
|
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
|
||||||
@@ -1713,8 +1610,7 @@ void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint32_t extfilter)
|
void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint32_t extfilter) {
|
||||||
{
|
|
||||||
if (TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger) {
|
if (TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger) {
|
||||||
/* reset the CH1EN bit */
|
/* reset the CH1EN bit */
|
||||||
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
|
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
|
||||||
@@ -1775,8 +1671,7 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
|
void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter) {
|
||||||
{
|
|
||||||
/* configure TIMER external trigger input */
|
/* configure TIMER external trigger input */
|
||||||
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
|
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
|
||||||
/* reset the SMC bit,TRGS bit */
|
/* reset the SMC bit,TRGS bit */
|
||||||
@@ -1802,8 +1697,7 @@ void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extpresca
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
|
void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter) {
|
||||||
{
|
|
||||||
/* configure TIMER external trigger input */
|
/* configure TIMER external trigger input */
|
||||||
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
|
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
|
||||||
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_SMC1;
|
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_SMC1;
|
||||||
@@ -1815,10 +1709,7 @@ void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extpresca
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_external_clock_mode1_disable(uint32_t timer_periph)
|
void timer_external_clock_mode1_disable(uint32_t timer_periph) { TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC1; }
|
||||||
{
|
|
||||||
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable the TIMER interrupt
|
\brief enable the TIMER interrupt
|
||||||
@@ -1836,10 +1727,7 @@ void timer_external_clock_mode1_disable(uint32_t timer_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
|
void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt) { TIMER_DMAINTEN(timer_periph) |= (uint32_t)interrupt; }
|
||||||
{
|
|
||||||
TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable the TIMER interrupt
|
\brief disable the TIMER interrupt
|
||||||
@@ -1857,10 +1745,7 @@ void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
|
void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt) { TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt); }
|
||||||
{
|
|
||||||
TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get timer interrupt flag
|
\brief get timer interrupt flag
|
||||||
@@ -1878,8 +1763,7 @@ void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
|
FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt) {
|
||||||
{
|
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
val = (TIMER_DMAINTEN(timer_periph) & interrupt);
|
val = (TIMER_DMAINTEN(timer_periph) & interrupt);
|
||||||
if ((RESET != (TIMER_INTF(timer_periph) & interrupt)) && (RESET != val)) {
|
if ((RESET != (TIMER_INTF(timer_periph) & interrupt)) && (RESET != val)) {
|
||||||
@@ -1905,10 +1789,7 @@ FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt)
|
void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt) { TIMER_INTF(timer_periph) = (~(uint32_t)interrupt); }
|
||||||
{
|
|
||||||
TIMER_INTF(timer_periph) = (~(uint32_t)interrupt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get TIMER flags
|
\brief get TIMER flags
|
||||||
@@ -1930,8 +1811,7 @@ void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
|
FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag) {
|
||||||
{
|
|
||||||
if (RESET != (TIMER_INTF(timer_periph) & flag)) {
|
if (RESET != (TIMER_INTF(timer_periph) & flag)) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -1959,9 +1839,4 @@ FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
|
void timer_flag_clear(uint32_t timer_periph, uint32_t flag) { TIMER_INTF(timer_periph) = (~(uint32_t)flag); }
|
||||||
{
|
|
||||||
TIMER_INTF(timer_periph) = (~(uint32_t)flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_deinit(uint32_t usart_periph)
|
void usart_deinit(uint32_t usart_periph) {
|
||||||
{
|
|
||||||
switch (usart_periph) {
|
switch (usart_periph) {
|
||||||
case USART0:
|
case USART0:
|
||||||
/* reset USART0 */
|
/* reset USART0 */
|
||||||
@@ -80,8 +79,7 @@ void usart_deinit(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval)
|
void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval) {
|
||||||
{
|
|
||||||
uint32_t uclk = 0U, intdiv = 0U, fradiv = 0U, udiv = 0U;
|
uint32_t uclk = 0U, intdiv = 0U, fradiv = 0U, udiv = 0U;
|
||||||
switch (usart_periph) {
|
switch (usart_periph) {
|
||||||
/* get clock frequency */
|
/* get clock frequency */
|
||||||
@@ -126,8 +124,7 @@ void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg)
|
void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg) {
|
||||||
{
|
|
||||||
/* clear USART_CTL0 PM,PCEN bits */
|
/* clear USART_CTL0 PM,PCEN bits */
|
||||||
USART_CTL0(usart_periph) &= ~(USART_CTL0_PM | USART_CTL0_PCEN);
|
USART_CTL0(usart_periph) &= ~(USART_CTL0_PM | USART_CTL0_PCEN);
|
||||||
/* configure USART parity mode */
|
/* configure USART parity mode */
|
||||||
@@ -144,8 +141,7 @@ void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_word_length_set(uint32_t usart_periph, uint32_t wlen)
|
void usart_word_length_set(uint32_t usart_periph, uint32_t wlen) {
|
||||||
{
|
|
||||||
/* clear USART_CTL0 WL bit */
|
/* clear USART_CTL0 WL bit */
|
||||||
USART_CTL0(usart_periph) &= ~USART_CTL0_WL;
|
USART_CTL0(usart_periph) &= ~USART_CTL0_WL;
|
||||||
/* configure USART word length */
|
/* configure USART word length */
|
||||||
@@ -164,8 +160,7 @@ void usart_word_length_set(uint32_t usart_periph, uint32_t wlen)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen)
|
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen) {
|
||||||
{
|
|
||||||
/* clear USART_CTL1 STB bits */
|
/* clear USART_CTL1 STB bits */
|
||||||
USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
|
USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
|
||||||
/* configure USART stop bits */
|
/* configure USART stop bits */
|
||||||
@@ -178,10 +173,7 @@ void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_enable(uint32_t usart_periph)
|
void usart_enable(uint32_t usart_periph) { USART_CTL0(usart_periph) |= USART_CTL0_UEN; }
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) |= USART_CTL0_UEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable USART
|
\brief disable USART
|
||||||
@@ -189,10 +181,7 @@ void usart_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_disable(uint32_t usart_periph)
|
void usart_disable(uint32_t usart_periph) { USART_CTL0(usart_periph) &= ~(USART_CTL0_UEN); }
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) &= ~(USART_CTL0_UEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure USART transmitter
|
\brief configure USART transmitter
|
||||||
@@ -204,8 +193,7 @@ void usart_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
|
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL0(usart_periph);
|
ctl = USART_CTL0(usart_periph);
|
||||||
@@ -225,8 +213,7 @@ void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
|
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL0(usart_periph);
|
ctl = USART_CTL0(usart_periph);
|
||||||
@@ -243,10 +230,7 @@ void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_data_transmit(uint32_t usart_periph, uint32_t data)
|
void usart_data_transmit(uint32_t usart_periph, uint32_t data) { USART_DATA(usart_periph) = USART_DATA_DATA & data; }
|
||||||
{
|
|
||||||
USART_DATA(usart_periph) = USART_DATA_DATA & data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief USART receive data function
|
\brief USART receive data function
|
||||||
@@ -254,10 +238,7 @@ void usart_data_transmit(uint32_t usart_periph, uint32_t data)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval data of received
|
\retval data of received
|
||||||
*/
|
*/
|
||||||
uint16_t usart_data_receive(uint32_t usart_periph)
|
uint16_t usart_data_receive(uint32_t usart_periph) { return (uint16_t)(GET_BITS(USART_DATA(usart_periph), 0U, 8U)); }
|
||||||
{
|
|
||||||
return (uint16_t)(GET_BITS(USART_DATA(usart_periph), 0U, 8U));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure the address of the USART in wake up by address match mode
|
\brief configure the address of the USART in wake up by address match mode
|
||||||
@@ -266,8 +247,7 @@ uint16_t usart_data_receive(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_address_config(uint32_t usart_periph, uint8_t addr)
|
void usart_address_config(uint32_t usart_periph, uint8_t addr) {
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) &= ~(USART_CTL1_ADDR);
|
USART_CTL1(usart_periph) &= ~(USART_CTL1_ADDR);
|
||||||
USART_CTL1(usart_periph) |= (USART_CTL1_ADDR & addr);
|
USART_CTL1(usart_periph) |= (USART_CTL1_ADDR & addr);
|
||||||
}
|
}
|
||||||
@@ -278,10 +258,7 @@ void usart_address_config(uint32_t usart_periph, uint8_t addr)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_mute_mode_enable(uint32_t usart_periph)
|
void usart_mute_mode_enable(uint32_t usart_periph) { USART_CTL0(usart_periph) |= USART_CTL0_RWU; }
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) |= USART_CTL0_RWU;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief receiver in active mode
|
\brief receiver in active mode
|
||||||
@@ -289,10 +266,7 @@ void usart_mute_mode_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_mute_mode_disable(uint32_t usart_periph)
|
void usart_mute_mode_disable(uint32_t usart_periph) { USART_CTL0(usart_periph) &= ~(USART_CTL0_RWU); }
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) &= ~(USART_CTL0_RWU);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure wakeup method in mute mode
|
\brief configure wakeup method in mute mode
|
||||||
@@ -304,8 +278,7 @@ void usart_mute_mode_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod)
|
void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod) {
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) &= ~(USART_CTL0_WM);
|
USART_CTL0(usart_periph) &= ~(USART_CTL0_WM);
|
||||||
USART_CTL0(usart_periph) |= wmethod;
|
USART_CTL0(usart_periph) |= wmethod;
|
||||||
}
|
}
|
||||||
@@ -316,10 +289,7 @@ void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_lin_mode_enable(uint32_t usart_periph)
|
void usart_lin_mode_enable(uint32_t usart_periph) { USART_CTL1(usart_periph) |= USART_CTL1_LMEN; }
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) |= USART_CTL1_LMEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable LIN mode
|
\brief disable LIN mode
|
||||||
@@ -327,10 +297,7 @@ void usart_lin_mode_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_lin_mode_disable(uint32_t usart_periph)
|
void usart_lin_mode_disable(uint32_t usart_periph) { USART_CTL1(usart_periph) &= ~(USART_CTL1_LMEN); }
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) &= ~(USART_CTL1_LMEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure lin break frame length
|
\brief configure lin break frame length
|
||||||
@@ -342,8 +309,7 @@ void usart_lin_mode_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen)
|
void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen) {
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) &= ~(USART_CTL1_LBLEN);
|
USART_CTL1(usart_periph) &= ~(USART_CTL1_LBLEN);
|
||||||
USART_CTL1(usart_periph) |= (USART_CTL1_LBLEN & lblen);
|
USART_CTL1(usart_periph) |= (USART_CTL1_LBLEN & lblen);
|
||||||
}
|
}
|
||||||
@@ -354,10 +320,7 @@ void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lbl
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_send_break(uint32_t usart_periph)
|
void usart_send_break(uint32_t usart_periph) { USART_CTL0(usart_periph) |= USART_CTL0_SBKCMD; }
|
||||||
{
|
|
||||||
USART_CTL0(usart_periph) |= USART_CTL0_SBKCMD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable half duplex mode
|
\brief enable half duplex mode
|
||||||
@@ -365,10 +328,7 @@ void usart_send_break(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_halfduplex_enable(uint32_t usart_periph)
|
void usart_halfduplex_enable(uint32_t usart_periph) { USART_CTL2(usart_periph) |= USART_CTL2_HDEN; }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) |= USART_CTL2_HDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable half duplex mode
|
\brief disable half duplex mode
|
||||||
@@ -376,10 +336,7 @@ void usart_halfduplex_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_halfduplex_disable(uint32_t usart_periph)
|
void usart_halfduplex_disable(uint32_t usart_periph) { USART_CTL2(usart_periph) &= ~(USART_CTL2_HDEN); }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) &= ~(USART_CTL2_HDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable CK pin in synchronous mode
|
\brief enable CK pin in synchronous mode
|
||||||
@@ -387,10 +344,7 @@ void usart_halfduplex_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_synchronous_clock_enable(uint32_t usart_periph)
|
void usart_synchronous_clock_enable(uint32_t usart_periph) { USART_CTL1(usart_periph) |= USART_CTL1_CKEN; }
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) |= USART_CTL1_CKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable CK pin in synchronous mode
|
\brief disable CK pin in synchronous mode
|
||||||
@@ -398,10 +352,7 @@ void usart_synchronous_clock_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_synchronous_clock_disable(uint32_t usart_periph)
|
void usart_synchronous_clock_disable(uint32_t usart_periph) { USART_CTL1(usart_periph) &= ~(USART_CTL1_CKEN); }
|
||||||
{
|
|
||||||
USART_CTL1(usart_periph) &= ~(USART_CTL1_CKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure USART synchronous mode parameters
|
\brief configure USART synchronous mode parameters
|
||||||
@@ -421,8 +372,7 @@ void usart_synchronous_clock_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl)
|
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
/* read USART_CTL1 register */
|
/* read USART_CTL1 register */
|
||||||
@@ -441,8 +391,7 @@ void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut)
|
void usart_guard_time_config(uint32_t usart_periph, uint32_t gaut) {
|
||||||
{
|
|
||||||
USART_GP(usart_periph) &= ~(USART_GP_GUAT);
|
USART_GP(usart_periph) &= ~(USART_GP_GUAT);
|
||||||
USART_GP(usart_periph) |= (USART_GP_GUAT & ((gaut) << 8));
|
USART_GP(usart_periph) |= (USART_GP_GUAT & ((gaut) << 8));
|
||||||
}
|
}
|
||||||
@@ -453,10 +402,7 @@ void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_smartcard_mode_enable(uint32_t usart_periph)
|
void usart_smartcard_mode_enable(uint32_t usart_periph) { USART_CTL2(usart_periph) |= USART_CTL2_SCEN; }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) |= USART_CTL2_SCEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable smartcard mode
|
\brief disable smartcard mode
|
||||||
@@ -464,10 +410,7 @@ void usart_smartcard_mode_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_smartcard_mode_disable(uint32_t usart_periph)
|
void usart_smartcard_mode_disable(uint32_t usart_periph) { USART_CTL2(usart_periph) &= ~(USART_CTL2_SCEN); }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) &= ~(USART_CTL2_SCEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable NACK in smartcard mode
|
\brief enable NACK in smartcard mode
|
||||||
@@ -475,10 +418,7 @@ void usart_smartcard_mode_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_smartcard_mode_nack_enable(uint32_t usart_periph)
|
void usart_smartcard_mode_nack_enable(uint32_t usart_periph) { USART_CTL2(usart_periph) |= USART_CTL2_NKEN; }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) |= USART_CTL2_NKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable NACK in smartcard mode
|
\brief disable NACK in smartcard mode
|
||||||
@@ -486,10 +426,7 @@ void usart_smartcard_mode_nack_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_smartcard_mode_nack_disable(uint32_t usart_periph)
|
void usart_smartcard_mode_nack_disable(uint32_t usart_periph) { USART_CTL2(usart_periph) &= ~(USART_CTL2_NKEN); }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) &= ~(USART_CTL2_NKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable IrDA mode
|
\brief enable IrDA mode
|
||||||
@@ -497,10 +434,7 @@ void usart_smartcard_mode_nack_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_irda_mode_enable(uint32_t usart_periph)
|
void usart_irda_mode_enable(uint32_t usart_periph) { USART_CTL2(usart_periph) |= USART_CTL2_IREN; }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) |= USART_CTL2_IREN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable IrDA mode
|
\brief disable IrDA mode
|
||||||
@@ -508,10 +442,7 @@ void usart_irda_mode_enable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_irda_mode_disable(uint32_t usart_periph)
|
void usart_irda_mode_disable(uint32_t usart_periph) { USART_CTL2(usart_periph) &= ~(USART_CTL2_IREN); }
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) &= ~(USART_CTL2_IREN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure the peripheral clock prescaler in USART IrDA low-power mode
|
\brief configure the peripheral clock prescaler in USART IrDA low-power mode
|
||||||
@@ -520,8 +451,7 @@ void usart_irda_mode_disable(uint32_t usart_periph)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_prescaler_config(uint32_t usart_periph, uint8_t psc)
|
void usart_prescaler_config(uint32_t usart_periph, uint8_t psc) {
|
||||||
{
|
|
||||||
USART_GP(usart_periph) &= ~(USART_GP_PSC);
|
USART_GP(usart_periph) &= ~(USART_GP_PSC);
|
||||||
USART_GP(usart_periph) |= psc;
|
USART_GP(usart_periph) |= psc;
|
||||||
}
|
}
|
||||||
@@ -536,8 +466,7 @@ void usart_prescaler_config(uint32_t usart_periph, uint8_t psc)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
|
void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp) {
|
||||||
{
|
|
||||||
USART_CTL2(usart_periph) &= ~(USART_CTL2_IRLP);
|
USART_CTL2(usart_periph) &= ~(USART_CTL2_IRLP);
|
||||||
USART_CTL2(usart_periph) |= (USART_CTL2_IRLP & irlp);
|
USART_CTL2(usart_periph) |= (USART_CTL2_IRLP & irlp);
|
||||||
}
|
}
|
||||||
@@ -552,8 +481,7 @@ void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
|
void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL2(usart_periph);
|
ctl = USART_CTL2(usart_periph);
|
||||||
@@ -573,8 +501,7 @@ void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig)
|
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL2(usart_periph);
|
ctl = USART_CTL2(usart_periph);
|
||||||
@@ -594,8 +521,7 @@ void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
|
void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL2(usart_periph);
|
ctl = USART_CTL2(usart_periph);
|
||||||
@@ -615,8 +541,7 @@ void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
|
void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd) {
|
||||||
{
|
|
||||||
uint32_t ctl = 0U;
|
uint32_t ctl = 0U;
|
||||||
|
|
||||||
ctl = USART_CTL2(usart_periph);
|
ctl = USART_CTL2(usart_periph);
|
||||||
@@ -644,8 +569,7 @@ void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
|
FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag) {
|
||||||
{
|
|
||||||
if (RESET != (USART_REG_VAL(usart_periph, flag) & BIT(USART_BIT_POS(flag)))) {
|
if (RESET != (USART_REG_VAL(usart_periph, flag) & BIT(USART_BIT_POS(flag)))) {
|
||||||
return SET;
|
return SET;
|
||||||
} else {
|
} else {
|
||||||
@@ -665,10 +589,7 @@ FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag)
|
void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag) { USART_REG_VAL(usart_periph, flag) &= ~BIT(USART_BIT_POS(flag)); }
|
||||||
{
|
|
||||||
USART_REG_VAL(usart_periph, flag) &= ~BIT(USART_BIT_POS(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief enable USART interrupt
|
\brief enable USART interrupt
|
||||||
@@ -686,10 +607,7 @@ void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag)
|
void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag) { USART_REG_VAL(usart_periph, int_flag) |= BIT(USART_BIT_POS(int_flag)); }
|
||||||
{
|
|
||||||
USART_REG_VAL(usart_periph, int_flag) |= BIT(USART_BIT_POS(int_flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief disable USART interrupt
|
\brief disable USART interrupt
|
||||||
@@ -707,10 +625,7 @@ void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag)
|
void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag) { USART_REG_VAL(usart_periph, int_flag) &= ~BIT(USART_BIT_POS(int_flag)); }
|
||||||
{
|
|
||||||
USART_REG_VAL(usart_periph, int_flag) &= ~BIT(USART_BIT_POS(int_flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get USART interrupt and flag status
|
\brief get USART interrupt and flag status
|
||||||
@@ -731,8 +646,7 @@ void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag)
|
FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag) {
|
||||||
{
|
|
||||||
uint32_t intenable = 0U, flagstatus = 0U;
|
uint32_t intenable = 0U, flagstatus = 0U;
|
||||||
/* get the interrupt enable bit status */
|
/* get the interrupt enable bit status */
|
||||||
intenable = (USART_REG_VAL(usart_periph, int_flag) & BIT(USART_BIT_POS(int_flag)));
|
intenable = (USART_REG_VAL(usart_periph, int_flag) & BIT(USART_BIT_POS(int_flag)));
|
||||||
@@ -758,24 +672,18 @@ FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag)
|
void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag) { USART_REG_VAL2(usart_periph, flag) &= ~BIT(USART_BIT_POS2(flag)); }
|
||||||
{
|
|
||||||
USART_REG_VAL2(usart_periph, flag) &= ~BIT(USART_BIT_POS2(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
int usart_write(uint32_t usart_periph,int ch)
|
int usart_write(uint32_t usart_periph, int ch) {
|
||||||
{
|
|
||||||
usart_data_transmit(usart_periph, (uint8_t)ch);
|
usart_data_transmit(usart_periph, (uint8_t)ch);
|
||||||
while (usart_flag_get(usart_periph, USART_FLAG_TBE)== RESET){
|
while (usart_flag_get(usart_periph, USART_FLAG_TBE) == RESET) {}
|
||||||
}
|
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t usart_read(uint32_t usart_periph) {
|
||||||
uint8_t usart_read(uint32_t usart_periph)
|
|
||||||
{
|
|
||||||
/* loop until RBNE = 1 */
|
/* loop until RBNE = 1 */
|
||||||
while (usart_flag_get(usart_periph, USART_FLAG_RBNE) == RESET);
|
while (usart_flag_get(usart_periph, USART_FLAG_RBNE) == RESET)
|
||||||
|
;
|
||||||
return (usart_data_receive(usart_periph));
|
return (usart_data_receive(usart_periph));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ OF SUCH DAMAGE.
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_deinit(void)
|
void wwdgt_deinit(void) {
|
||||||
{
|
|
||||||
rcu_periph_reset_enable(RCU_WWDGTRST);
|
rcu_periph_reset_enable(RCU_WWDGTRST);
|
||||||
rcu_periph_reset_disable(RCU_WWDGTRST);
|
rcu_periph_reset_disable(RCU_WWDGTRST);
|
||||||
}
|
}
|
||||||
@@ -57,10 +56,7 @@ void wwdgt_deinit(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_enable(void)
|
void wwdgt_enable(void) { WWDGT_CTL |= WWDGT_CTL_WDGTEN; }
|
||||||
{
|
|
||||||
WWDGT_CTL |= WWDGT_CTL_WDGTEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief configure the window watchdog timer counter value
|
\brief configure the window watchdog timer counter value
|
||||||
@@ -68,8 +64,7 @@ void wwdgt_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_counter_update(uint16_t counter_value)
|
void wwdgt_counter_update(uint16_t counter_value) {
|
||||||
{
|
|
||||||
uint32_t reg = 0U;
|
uint32_t reg = 0U;
|
||||||
|
|
||||||
reg = (WWDGT_CTL & (~WWDGT_CTL_CNT));
|
reg = (WWDGT_CTL & (~WWDGT_CTL_CNT));
|
||||||
@@ -91,8 +86,7 @@ void wwdgt_counter_update(uint16_t counter_value)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler)
|
void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler) {
|
||||||
{
|
|
||||||
uint32_t reg_cfg = 0U, reg_ctl = 0U;
|
uint32_t reg_cfg = 0U, reg_ctl = 0U;
|
||||||
|
|
||||||
/* clear WIN and PSC bits, clear CNT bit */
|
/* clear WIN and PSC bits, clear CNT bit */
|
||||||
@@ -114,10 +108,7 @@ void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_interrupt_enable(void)
|
void wwdgt_interrupt_enable(void) { WWDGT_CFG |= WWDGT_CFG_EWIE; }
|
||||||
{
|
|
||||||
WWDGT_CFG |= WWDGT_CFG_EWIE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief check early wakeup interrupt state of WWDGT
|
\brief check early wakeup interrupt state of WWDGT
|
||||||
@@ -125,8 +116,7 @@ void wwdgt_interrupt_enable(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval FlagStatus: SET or RESET
|
\retval FlagStatus: SET or RESET
|
||||||
*/
|
*/
|
||||||
FlagStatus wwdgt_flag_get(void)
|
FlagStatus wwdgt_flag_get(void) {
|
||||||
{
|
|
||||||
if (WWDGT_STAT & WWDGT_STAT_EWIF) {
|
if (WWDGT_STAT & WWDGT_STAT_EWIF) {
|
||||||
return SET;
|
return SET;
|
||||||
}
|
}
|
||||||
@@ -140,7 +130,4 @@ FlagStatus wwdgt_flag_get(void)
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void wwdgt_flag_clear(void)
|
void wwdgt_flag_clear(void) { WWDGT_STAT &= (~WWDGT_STAT_EWIF); }
|
||||||
{
|
|
||||||
WWDGT_STAT &= (~WWDGT_STAT_EWIF);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
int _close(int fd)
|
int _close(int fd) { return _stub(EBADF); }
|
||||||
{
|
|
||||||
return _stub(EBADF);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int _fstat(int fd, struct stat* st)
|
int _fstat(int fd, struct stat *st) { return _stub(EBADF); }
|
||||||
{
|
|
||||||
return _stub(EBADF);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
#include "nuclei_sdk_soc.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "nuclei_sdk_soc.h"
|
|
||||||
|
|
||||||
int _gettimeofday(struct timeval *tp, void *tzp)
|
int _gettimeofday(struct timeval *tp, void *tzp) {
|
||||||
{
|
|
||||||
uint64_t cycles;
|
uint64_t cycles;
|
||||||
|
|
||||||
cycles = __get_rv_cycle();
|
cycles = __get_rv_cycle();
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int _isatty(int fd)
|
int _isatty(int fd) {
|
||||||
{
|
|
||||||
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
off_t _lseek(int fd, off_t ptr, int dir)
|
off_t _lseek(int fd, off_t ptr, int dir) { return _stub(EBADF); }
|
||||||
{
|
|
||||||
return _stub(EBADF);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "nuclei_sdk_hal.h"
|
|
||||||
#include "gd32vf103_usart.h"
|
#include "gd32vf103_usart.h"
|
||||||
|
#include "nuclei_sdk_hal.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
// #define UART_AUTO_ECHO
|
// #define UART_AUTO_ECHO
|
||||||
|
|
||||||
ssize_t _read(int fd, void* ptr, size_t len) {
|
ssize_t _read(int fd, void *ptr, size_t len) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
/* See LICENSE of license details. */
|
/* See LICENSE of license details. */
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void *_sbrk(ptrdiff_t incr)
|
void *_sbrk(ptrdiff_t incr) {
|
||||||
{
|
|
||||||
extern char _end[];
|
extern char _end[];
|
||||||
extern char _heap_end[];
|
extern char _heap_end[];
|
||||||
static char *curbrk = _end;
|
static char *curbrk = _end;
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
/* See LICENSE of license details. */
|
/* See LICENSE of license details. */
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <nuclei_sdk_hal.h>
|
|
||||||
#include "gd32vf103_usart.h"
|
#include "gd32vf103_usart.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <nuclei_sdk_hal.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
ssize_t _write(int fd, const void* ptr, size_t len) {
|
ssize_t _write(int fd, const void *ptr, size_t len) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
#include "nuclei_sdk_soc.h"
|
#include "nuclei_sdk_soc.h"
|
||||||
|
|
||||||
static uint32_t get_timer_freq()
|
static uint32_t get_timer_freq() { return SOC_TIMER_FREQ; }
|
||||||
{
|
|
||||||
return SOC_TIMER_FREQ;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t measure_cpu_freq(uint32_t n)
|
uint32_t measure_cpu_freq(uint32_t n) {
|
||||||
{
|
|
||||||
uint32_t start_mcycle, delta_mcycle;
|
uint32_t start_mcycle, delta_mcycle;
|
||||||
uint32_t start_mtime, delta_mtime;
|
uint32_t start_mtime, delta_mtime;
|
||||||
uint32_t mtime_freq = get_timer_freq();
|
uint32_t mtime_freq = get_timer_freq();
|
||||||
@@ -23,12 +19,10 @@ uint32_t measure_cpu_freq(uint32_t n)
|
|||||||
delta_mcycle = __RV_CSR_READ(CSR_MCYCLE) - start_mcycle;
|
delta_mcycle = __RV_CSR_READ(CSR_MCYCLE) - start_mcycle;
|
||||||
} while (delta_mtime < n);
|
} while (delta_mtime < n);
|
||||||
|
|
||||||
return (delta_mcycle / delta_mtime) * mtime_freq
|
return (delta_mcycle / delta_mtime) * mtime_freq + ((delta_mcycle % delta_mtime) * mtime_freq) / delta_mtime;
|
||||||
+ ((delta_mcycle % delta_mtime) * mtime_freq) / delta_mtime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_cpu_freq()
|
uint32_t get_cpu_freq() {
|
||||||
{
|
|
||||||
uint32_t cpu_freq;
|
uint32_t cpu_freq;
|
||||||
|
|
||||||
// warm up
|
// warm up
|
||||||
@@ -46,8 +40,7 @@ uint32_t get_cpu_freq()
|
|||||||
* \param[in] count: count in milliseconds
|
* \param[in] count: count in milliseconds
|
||||||
* \remarks
|
* \remarks
|
||||||
*/
|
*/
|
||||||
void delay_1ms(uint32_t count)
|
void delay_1ms(uint32_t count) {
|
||||||
{
|
|
||||||
uint64_t start_mtime, delta_mtime;
|
uint64_t start_mtime, delta_mtime;
|
||||||
uint64_t delay_ticks = (SOC_TIMER_FREQ * (uint64_t)count) / 1000;
|
uint64_t delay_ticks = (SOC_TIMER_FREQ * (uint64_t)count) / 1000;
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "nuclei_sdk_hal.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "nuclei_sdk_hal.h"
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
Define clocks
|
Define clocks
|
||||||
@@ -109,8 +109,7 @@ static void system_clock_108m_hxtal(void) {
|
|||||||
|
|
||||||
/* if fail */
|
/* if fail */
|
||||||
if (0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
|
if (0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
|
||||||
while (1) {
|
while (1) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HXTAL is stable */
|
/* HXTAL is stable */
|
||||||
@@ -127,54 +126,44 @@ static void system_clock_108m_hxtal(void) {
|
|||||||
|
|
||||||
if (HXTAL_VALUE == 25000000) {
|
if (HXTAL_VALUE == 25000000) {
|
||||||
/* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
|
/* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
|
||||||
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF |
|
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV0);
|
||||||
RCU_CFG1_PREDV0);
|
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PREDV1_DIV5 | RCU_PLL1_MUL8 | RCU_PREDV0_DIV10);
|
||||||
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PREDV1_DIV5 | RCU_PLL1_MUL8 |
|
|
||||||
RCU_PREDV0_DIV10);
|
|
||||||
|
|
||||||
/* enable PLL1 */
|
/* enable PLL1 */
|
||||||
RCU_CTL |= RCU_CTL_PLL1EN;
|
RCU_CTL |= RCU_CTL_PLL1EN;
|
||||||
/* wait till PLL1 is ready */
|
/* wait till PLL1 is ready */
|
||||||
while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {
|
while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {}
|
||||||
}
|
|
||||||
|
|
||||||
/* enable PLL1 */
|
/* enable PLL1 */
|
||||||
RCU_CTL |= RCU_CTL_PLL2EN;
|
RCU_CTL |= RCU_CTL_PLL2EN;
|
||||||
/* wait till PLL1 is ready */
|
/* wait till PLL1 is ready */
|
||||||
while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {
|
while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {}
|
||||||
}
|
|
||||||
} else if (HXTAL_VALUE == 8000000) {
|
} else if (HXTAL_VALUE == 8000000) {
|
||||||
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF |
|
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV0);
|
||||||
RCU_CFG1_PREDV0);
|
RCU_CFG1 |= (RCU_PREDV0SRC_HXTAL | RCU_PREDV0_DIV2 | RCU_PREDV1_DIV2 | RCU_PLL1_MUL20 | RCU_PLL2_MUL20);
|
||||||
RCU_CFG1 |= (RCU_PREDV0SRC_HXTAL | RCU_PREDV0_DIV2 | RCU_PREDV1_DIV2 |
|
|
||||||
RCU_PLL1_MUL20 | RCU_PLL2_MUL20);
|
|
||||||
|
|
||||||
/* enable PLL1 */
|
/* enable PLL1 */
|
||||||
RCU_CTL |= RCU_CTL_PLL1EN;
|
RCU_CTL |= RCU_CTL_PLL1EN;
|
||||||
/* wait till PLL1 is ready */
|
/* wait till PLL1 is ready */
|
||||||
while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {
|
while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {}
|
||||||
}
|
|
||||||
|
|
||||||
/* enable PLL2 */
|
/* enable PLL2 */
|
||||||
RCU_CTL |= RCU_CTL_PLL2EN;
|
RCU_CTL |= RCU_CTL_PLL2EN;
|
||||||
/* wait till PLL1 is ready */
|
/* wait till PLL1 is ready */
|
||||||
while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {
|
while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* enable PLL */
|
/* enable PLL */
|
||||||
RCU_CTL |= RCU_CTL_PLLEN;
|
RCU_CTL |= RCU_CTL_PLLEN;
|
||||||
|
|
||||||
/* wait until PLL is stable */
|
/* wait until PLL is stable */
|
||||||
while (0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
|
while (0U == (RCU_CTL & RCU_CTL_PLLSTB)) {}
|
||||||
}
|
|
||||||
|
|
||||||
/* select PLL as system clock */
|
/* select PLL as system clock */
|
||||||
RCU_CFG0 &= ~RCU_CFG0_SCS;
|
RCU_CFG0 &= ~RCU_CFG0_SCS;
|
||||||
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
|
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
|
||||||
|
|
||||||
/* wait until PLL is selected as system clock */
|
/* wait until PLL is selected as system clock */
|
||||||
while (0U == (RCU_CFG0 & RCU_SCSS_PLL)) {
|
while (0U == (RCU_CFG0 & RCU_SCSS_PLL)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -183,9 +172,7 @@ static void system_clock_108m_hxtal(void) {
|
|||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
static void system_clock_config(void) {
|
static void system_clock_config(void) { system_clock_108m_hxtal(); }
|
||||||
system_clock_108m_hxtal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Function to update the variable \ref SystemCoreClock
|
* \brief Function to update the variable \ref SystemCoreClock
|
||||||
@@ -292,9 +279,7 @@ void SystemInit(void) {
|
|||||||
RCU_CTL |= RCU_CTL_IRC8MEN;
|
RCU_CTL |= RCU_CTL_IRC8MEN;
|
||||||
|
|
||||||
/* reset SCS, AHBPSC, APB1PSC, APB2PSC, ADCPSC, CKOUT0SEL bits */
|
/* reset SCS, AHBPSC, APB1PSC, APB2PSC, ADCPSC, CKOUT0SEL bits */
|
||||||
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC
|
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC | RCU_CFG0_ADCPSC | RCU_CFG0_ADCPSC_2 | RCU_CFG0_CKOUT0SEL);
|
||||||
| RCU_CFG0_APB2PSC |
|
|
||||||
RCU_CFG0_ADCPSC | RCU_CFG0_ADCPSC_2 | RCU_CFG0_CKOUT0SEL);
|
|
||||||
|
|
||||||
/* reset HXTALEN, CKMEN, PLLEN bits */
|
/* reset HXTALEN, CKMEN, PLLEN bits */
|
||||||
RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
|
RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
|
||||||
@@ -304,13 +289,11 @@ void SystemInit(void) {
|
|||||||
|
|
||||||
/* reset PLLSEL, PREDV0_LSB, PLLMF, USBFSPSC bits */
|
/* reset PLLSEL, PREDV0_LSB, PLLMF, USBFSPSC bits */
|
||||||
|
|
||||||
RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF |
|
RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF | RCU_CFG0_USBFSPSC | RCU_CFG0_PLLMF_4);
|
||||||
RCU_CFG0_USBFSPSC | RCU_CFG0_PLLMF_4);
|
|
||||||
RCU_CFG1 = 0x00000000U;
|
RCU_CFG1 = 0x00000000U;
|
||||||
|
|
||||||
/* Reset HXTALEN, CKMEN, PLLEN, PLL1EN and PLL2EN bits */
|
/* Reset HXTALEN, CKMEN, PLLEN, PLL1EN and PLL2EN bits */
|
||||||
RCU_CTL &= ~(RCU_CTL_PLLEN | RCU_CTL_PLL1EN | RCU_CTL_PLL2EN | RCU_CTL_CKMEN
|
RCU_CTL &= ~(RCU_CTL_PLLEN | RCU_CTL_PLL1EN | RCU_CTL_PLL2EN | RCU_CTL_CKMEN | RCU_CTL_HXTALEN);
|
||||||
| RCU_CTL_HXTALEN);
|
|
||||||
/* disable all interrupts */
|
/* disable all interrupts */
|
||||||
RCU_INT = 0x00FF0000U;
|
RCU_INT = 0x00FF0000U;
|
||||||
|
|
||||||
@@ -354,8 +337,7 @@ typedef void (*EXC_HANDLER)(unsigned long mcause, unsigned long sp);
|
|||||||
* This function provided a default exception and NMI handling code for all exception ids.
|
* This function provided a default exception and NMI handling code for all exception ids.
|
||||||
* By default, It will just print some information for debug, Vendor can customize it according to its requirements.
|
* By default, It will just print some information for debug, Vendor can customize it according to its requirements.
|
||||||
*/
|
*/
|
||||||
static void system_default_exception_handler(unsigned long mcause,
|
static void system_default_exception_handler(unsigned long mcause, unsigned long sp) {
|
||||||
unsigned long sp) {
|
|
||||||
/* TODO: Uncomment this if you have implement printf function */
|
/* TODO: Uncomment this if you have implement printf function */
|
||||||
printf("MCAUSE: 0x%lx\r\n", mcause);
|
printf("MCAUSE: 0x%lx\r\n", mcause);
|
||||||
printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC));
|
printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC));
|
||||||
@@ -373,8 +355,7 @@ static void system_default_exception_handler(unsigned long mcause,
|
|||||||
*/
|
*/
|
||||||
static void Exception_Init(void) {
|
static void Exception_Init(void) {
|
||||||
for (int i = 0; i < MAX_SYSTEM_EXCEPTION_NUM + 1; i++) {
|
for (int i = 0; i < MAX_SYSTEM_EXCEPTION_NUM + 1; i++) {
|
||||||
SystemExceptionHandlers[i] =
|
SystemExceptionHandlers[i] = (unsigned long)system_default_exception_handler;
|
||||||
(unsigned long) system_default_exception_handler;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,8 +411,7 @@ uint32_t core_exception_handler(unsigned long mcause, unsigned long sp) {
|
|||||||
if ((EXCn < MAX_SYSTEM_EXCEPTION_NUM)) {
|
if ((EXCn < MAX_SYSTEM_EXCEPTION_NUM)) {
|
||||||
exc_handler = (EXC_HANDLER)SystemExceptionHandlers[EXCn];
|
exc_handler = (EXC_HANDLER)SystemExceptionHandlers[EXCn];
|
||||||
} else if (EXCn == NMI_EXCn) {
|
} else if (EXCn == NMI_EXCn) {
|
||||||
exc_handler =
|
exc_handler = (EXC_HANDLER)SystemExceptionHandlers[MAX_SYSTEM_EXCEPTION_NUM];
|
||||||
(EXC_HANDLER) SystemExceptionHandlers[MAX_SYSTEM_EXCEPTION_NUM];
|
|
||||||
} else {
|
} else {
|
||||||
exc_handler = (EXC_HANDLER)system_default_exception_handler;
|
exc_handler = (EXC_HANDLER)system_default_exception_handler;
|
||||||
}
|
}
|
||||||
@@ -482,11 +462,8 @@ void ECLIC_Init(void) {
|
|||||||
* - This function use to configure specific eclic interrupt and register its interrupt handler and enable its interrupt.
|
* - This function use to configure specific eclic interrupt and register its interrupt handler and enable its interrupt.
|
||||||
* - If the vector table is placed in read-only section(FLASHXIP mode), handler could not be installed
|
* - If the vector table is placed in read-only section(FLASHXIP mode), handler could not be installed
|
||||||
*/
|
*/
|
||||||
int32_t ECLIC_Register_IRQ(IRQn_Type IRQn, uint8_t shv,
|
int32_t ECLIC_Register_IRQ(IRQn_Type IRQn, uint8_t shv, ECLIC_TRIGGER_Type trig_mode, uint8_t lvl, uint8_t priority, void *handler) {
|
||||||
ECLIC_TRIGGER_Type trig_mode, uint8_t lvl, uint8_t priority,
|
if ((IRQn > SOC_INT_MAX) || (shv > ECLIC_VECTOR_INTERRUPT) || (trig_mode > ECLIC_NEGTIVE_EDGE_TRIGGER)) {
|
||||||
void *handler) {
|
|
||||||
if ((IRQn > SOC_INT_MAX) || (shv > ECLIC_VECTOR_INTERRUPT)
|
|
||||||
|| (trig_mode > ECLIC_NEGTIVE_EDGE_TRIGGER)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,9 +511,7 @@ void _premain_init(void) {
|
|||||||
* by __libc_fini_array function, so we defined a new function
|
* by __libc_fini_array function, so we defined a new function
|
||||||
* to do initialization
|
* to do initialization
|
||||||
*/
|
*/
|
||||||
void _postmain_fini(int status) {
|
void _postmain_fini(int status) { /* TODO: Add your own finishing code here, called after main */ }
|
||||||
/* TODO: Add your own finishing code here, called after main */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief _init function called in __libc_init_array()
|
* \brief _init function called in __libc_init_array()
|
||||||
@@ -547,9 +522,7 @@ void _postmain_fini(int status) {
|
|||||||
* \note
|
* \note
|
||||||
* Please use \ref _premain_init function now
|
* Please use \ref _premain_init function now
|
||||||
*/
|
*/
|
||||||
void _init(void) {
|
void _init(void) { /* Don't put any code here, please use _premain_init now */ }
|
||||||
/* Don't put any code here, please use _premain_init now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief _fini function called in __libc_fini_array()
|
* \brief _fini function called in __libc_fini_array()
|
||||||
@@ -560,8 +533,6 @@ void _init(void) {
|
|||||||
* \note
|
* \note
|
||||||
* Please use \ref _postmain_fini function now
|
* Please use \ref _postmain_fini function now
|
||||||
*/
|
*/
|
||||||
void _fini(void) {
|
void _fini(void) { /* Don't put any code here, please use _postmain_fini now */ }
|
||||||
/* Don't put any code here, please use _postmain_fini now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */ /* End of Doxygen Group NMSIS_Core_SystemAndClock */
|
/** @} */ /* End of Doxygen Group NMSIS_Core_SystemAndClock */
|
||||||
|
|||||||
@@ -43,5 +43,4 @@ void flash_read_buffer(uint8_t *buffer, const uint16_t length) {
|
|||||||
for (int i = 0; i < length / 4; i++) {
|
for (int i = 0; i < length / 4; i++) {
|
||||||
b[i] = b2[i];
|
b[i] = b2[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
#include "Model_Config.h"
|
#include "Model_Config.h"
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
#include "Setup.h"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "fusb302b.h"
|
|
||||||
#include "I2C_Wrapper.hpp"
|
#include "I2C_Wrapper.hpp"
|
||||||
#include <pd.h>
|
#include "Setup.h"
|
||||||
|
#include "fusb302b.h"
|
||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
|
#include <pd.h>
|
||||||
/*
|
/*
|
||||||
* Read a single byte from the FUSB302B
|
* Read a single byte from the FUSB302B
|
||||||
*
|
*
|
||||||
@@ -46,9 +46,7 @@ static uint8_t fusb_read_byte(uint8_t addr) {
|
|||||||
* size: The number of bytes to read
|
* size: The number of bytes to read
|
||||||
* buf: The buffer into which data will be read
|
* buf: The buffer into which data will be read
|
||||||
*/
|
*/
|
||||||
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) { return FRToSI2C::Mem_Read(FUSB302B_ADDR, addr, buf, size); }
|
||||||
return FRToSI2C::Mem_Read(FUSB302B_ADDR, addr, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a single byte to the FUSB302B
|
* Write a single byte to the FUSB302B
|
||||||
@@ -78,17 +76,8 @@ static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
|
|||||||
void fusb_send_message(const union pd_msg *msg) {
|
void fusb_send_message(const union pd_msg *msg) {
|
||||||
|
|
||||||
/* Token sequences for the FUSB302B */
|
/* Token sequences for the FUSB302B */
|
||||||
static uint8_t sop_seq[5] = {
|
static uint8_t sop_seq[5] = {FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM};
|
||||||
FUSB_FIFO_TX_SOP1,
|
static const uint8_t eop_seq[4] = {FUSB_FIFO_TX_JAM_CRC, FUSB_FIFO_TX_EOP, FUSB_FIFO_TX_TXOFF, FUSB_FIFO_TX_TXON};
|
||||||
FUSB_FIFO_TX_SOP1,
|
|
||||||
FUSB_FIFO_TX_SOP1,
|
|
||||||
FUSB_FIFO_TX_SOP2,
|
|
||||||
FUSB_FIFO_TX_PACKSYM };
|
|
||||||
static const uint8_t eop_seq[4] = {
|
|
||||||
FUSB_FIFO_TX_JAM_CRC,
|
|
||||||
FUSB_FIFO_TX_EOP,
|
|
||||||
FUSB_FIFO_TX_TXOFF,
|
|
||||||
FUSB_FIFO_TX_TXON };
|
|
||||||
|
|
||||||
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
||||||
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
||||||
@@ -102,7 +91,6 @@ void fusb_send_message(const union pd_msg *msg) {
|
|||||||
fusb_write_buf(FUSB_FIFOS, 5, sop_seq);
|
fusb_write_buf(FUSB_FIFOS, 5, sop_seq);
|
||||||
fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
|
fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
|
||||||
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t fusb_read_message(union pd_msg *msg) {
|
uint8_t fusb_read_message(union pd_msg *msg) {
|
||||||
@@ -131,7 +119,6 @@ void fusb_send_hardrst() {
|
|||||||
|
|
||||||
/* Send a hard reset */
|
/* Send a hard reset */
|
||||||
fusb_write_byte(FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
|
fusb_write_byte(FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fusb_setup() {
|
bool fusb_setup() {
|
||||||
@@ -165,8 +152,7 @@ bool fusb_setup() {
|
|||||||
// set defaults
|
// set defaults
|
||||||
fusb_write_byte(FUSB_CONTROL2, 0x00);
|
fusb_write_byte(FUSB_CONTROL2, 0x00);
|
||||||
/* Flush the RX buffer */
|
/* Flush the RX buffer */
|
||||||
fusb_write_byte( FUSB_CONTROL1,
|
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
||||||
FUSB_CONTROL1_RX_FLUSH);
|
|
||||||
|
|
||||||
/* Measure CC1 */
|
/* Measure CC1 */
|
||||||
fusb_write_byte(FUSB_SWITCHES0, 0x07);
|
fusb_write_byte(FUSB_SWITCHES0, 0x07);
|
||||||
@@ -196,14 +182,12 @@ void fusb_get_status(union fusb_status *status) {
|
|||||||
|
|
||||||
/* Read the interrupt and status flags into status */
|
/* Read the interrupt and status flags into status */
|
||||||
fusb_read_buf(FUSB_STATUS0A, 7, status->bytes);
|
fusb_read_buf(FUSB_STATUS0A, 7, status->bytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fusb_typec_current fusb_get_typec_current() {
|
enum fusb_typec_current fusb_get_typec_current() {
|
||||||
|
|
||||||
/* Read the BC_LVL into a variable */
|
/* Read the BC_LVL into a variable */
|
||||||
enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte(
|
enum fusb_typec_current bc_lvl = (enum fusb_typec_current)(fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
||||||
FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
|
||||||
|
|
||||||
return bc_lvl;
|
return bc_lvl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,3 @@ uint8_t showBootLogoIfavailable() {
|
|||||||
OLED::refresh();
|
OLED::refresh();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "I2C_Wrapper.hpp"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "Si7210.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "fusbpd.h"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include "power.hpp"
|
#include "power.hpp"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "I2C_Wrapper.hpp"
|
|
||||||
#include "fusbpd.h"
|
|
||||||
#include "Si7210.h"
|
|
||||||
|
|
||||||
bool hall_effect_present = false;
|
bool hall_effect_present = false;
|
||||||
void postRToSInit() {
|
void postRToSInit() {
|
||||||
@@ -23,16 +23,12 @@ void postRToSInit() {
|
|||||||
// Spawn all of the USB-C processors
|
// Spawn all of the USB-C processors
|
||||||
fusb302_start_processing();
|
fusb302_start_processing();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
int16_t getRawHallEffect() {
|
int16_t getRawHallEffect() {
|
||||||
if (hall_effect_present) {
|
if (hall_effect_present) {
|
||||||
return Si7210::read();
|
return Si7210::read();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getHallSensorFitted() {
|
bool getHallSensorFitted() { return hall_effect_present; }
|
||||||
return hall_effect_present;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gd32vf103_libopt.h"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#include "gd32vf103_libopt.h"
|
||||||
#include <I2C_Wrapper.hpp>
|
#include <I2C_Wrapper.hpp>
|
||||||
void preRToSInit() {
|
void preRToSInit() {
|
||||||
// Normal system bringup -- GPIO etc
|
// Normal system bringup -- GPIO etc
|
||||||
|
|||||||
Reference in New Issue
Block a user