make style
This commit is contained in:
1 parent
a0a3eb4bbf
commit
35c098d489
197 files changed
+30157
-35538
No files matched your search
@@ -44,9 +44,9 @@ bool FlashCodeEWriteMinUnit(uint32_t flash_address, const uint32_t *data, uint32
|
||||
|
||||
// Wait for operation to be completed
|
||||
*status = flash_operation_wait_for(ERASE_TIMEOUT);
|
||||
if((*status == FLASH_PROGRAM_ERROR) || (*status == FLASH_EPP_ERROR)) {
|
||||
if ((*status == FLASH_PROGRAM_ERROR) || (*status == FLASH_EPP_ERROR)) {
|
||||
flash_flag_clear(FLASH_PRGMERR_FLAG | FLASH_EPPERR_FLAG);
|
||||
} else if(*status == FLASH_OPERATE_TIMEOUT) {
|
||||
} else if (*status == FLASH_OPERATE_TIMEOUT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,15 +55,15 @@ bool FlashCodeEWriteMinUnit(uint32_t flash_address, const uint32_t *data, uint32
|
||||
|
||||
// Erase
|
||||
*status = flash_sector_erase(flash_address);
|
||||
if(*status != FLASH_OPERATE_DONE) {
|
||||
if (*status != FLASH_OPERATE_DONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write
|
||||
for(uint32_t i = 0; i < min_ew_unit_u32; i++) {
|
||||
for (uint32_t i = 0; i < min_ew_unit_u32; i++) {
|
||||
uint32_t w_addr = flash_address + i * sizeof(uint32_t);
|
||||
*status = flash_word_program(w_addr, data[i]);
|
||||
if(*status != FLASH_OPERATE_DONE) {
|
||||
if (*status != FLASH_OPERATE_DONE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
FlashStop();
|
||||
out:
|
||||
FlashStop();
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@@ -373,4 +373,4 @@ bool Flash_ReadStat2(uint8_t *status) {
|
||||
FlashSendByte(READSTAT2);
|
||||
*status = FlashSendLastByte(0xFF);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Enable(void);
|
||||
|
||||
// The buf address currently receiving and storing data (not the address of data that has already been received)
|
||||
// |done|done|done|working| <- you will get 'working' address.
|
||||
STATIC_FORCE_INLINE uint32_t* FPGA_SSC_DMA_RX_Current_Address(void);
|
||||
STATIC_FORCE_INLINE uint32_t *FPGA_SSC_DMA_RX_Current_Address(void);
|
||||
|
||||
// How much data still needs to be received?
|
||||
// After receiving an item each time, subtract 1 from this value.
|
||||
|
||||
@@ -736,7 +736,7 @@ void gowin_jtag_start_config(gowin_config_ctx_t *cctx) {
|
||||
cctx->status = gowin_jtag_init();
|
||||
if (cctx->status == GOWIN_JTAG_OK) {
|
||||
uint32_t idcode = gowin_jtag_get_idcode();
|
||||
const char* name = gowin_jtag_get_device_name();
|
||||
const char *name = gowin_jtag_get_device_name();
|
||||
dbg_printf("gowin_jtag OK: idcode = 0x%04lX, name = %s", idcode, name);
|
||||
// Read and print the detailed status register
|
||||
gowin_status_reg_t status_reg;
|
||||
@@ -767,7 +767,7 @@ void gowin_jtag_start_config(gowin_config_ctx_t *cctx) {
|
||||
}
|
||||
|
||||
// Print a message to indicate the startup is complete
|
||||
dbg_printf("gowin_jtag %s config started: %d", cctx->is_cfg_sram ? "sram" : "flash" , cctx->status);
|
||||
dbg_printf("gowin_jtag %s config started: %d", cctx->is_cfg_sram ? "sram" : "flash", cctx->status);
|
||||
}
|
||||
|
||||
void gowin_jtag_config_write(uint8_t *data, uint32_t data_length, gowin_config_ctx_t *cctx) {
|
||||
|
||||
@@ -153,15 +153,15 @@ typedef union {
|
||||
uint32_t program_spi_directly : 1; ///< Program SPI Directly flag. Common to all series.
|
||||
/* Bit 9 */
|
||||
uint32_t autoboot_state : 1; ///< AutoBoot State.
|
||||
///< - Table 7-13: this field exists (for models supporting AutoBoot)
|
||||
///< - Table 7-12: this bit is 0 (models that don't support AutoBoot, e.g. GW1N-1/4B)
|
||||
///< - Table 7-13: this field exists (for models supporting AutoBoot)
|
||||
///< - Table 7-12: this bit is 0 (models that don't support AutoBoot, e.g. GW1N-1/4B)
|
||||
/* Bit 10 */
|
||||
uint32_t non_jtag_active : 1; ///< Non-JTAG Active flag (e.g. active during MSPI/SSPI configuration). Common to all series.
|
||||
/* Bit 11 */
|
||||
uint32_t bypass_state : 1; ///< Bypass State flag. Common to all series.
|
||||
/* Bit 12 */
|
||||
uint32_t vld : 1; ///< Gowin VLD (1=normal, 0=abnormal). Internal Flash related parameter.
|
||||
///< Applies to all models with internal Flash (e.g. GW1NS, GW1NZ).
|
||||
///< Applies to all models with internal Flash (e.g. GW1NS, GW1NZ).
|
||||
/* Bit 13 */
|
||||
uint32_t done_final : 1; ///< Done Final (1=configuration completed successfully, 0=failed). Common to all series.
|
||||
/* Bit 14 */
|
||||
@@ -172,9 +172,9 @@ typedef union {
|
||||
uint32_t por : 1; ///< POR (Power-On Reset) status (1=normal, 0=abnormal). Common to all series.
|
||||
/* Bit 17 */
|
||||
uint32_t flash_lock : 1; ///< Flash Lock flag:
|
||||
///< - 1 = Flash locked (read-back disabled, but erase allowed)
|
||||
///< - Only present in the models listed in Table 7-13 (i.e. series with internal Flash, e.g. GW1NS/GW1NZ/GW1NSE)
|
||||
///< - On Table 7-12 models (e.g. GW1N-1/4B) this bit is 0 (no Flash Lock function)
|
||||
///< - 1 = Flash locked (read-back disabled, but erase allowed)
|
||||
///< - Only present in the models listed in Table 7-13 (i.e. series with internal Flash, e.g. GW1NS/GW1NZ/GW1NSE)
|
||||
///< - On Table 7-12 models (e.g. GW1N-1/4B) this bit is 0 (no Flash Lock function)
|
||||
/* Bits 18–31 */
|
||||
uint32_t reserved_18_31 : 14; ///< Reserved, always 0 (both tables state this explicitly).
|
||||
} bits;
|
||||
|
||||
@@ -138,7 +138,7 @@ void FpgaSetupSsc(uint16_t fpga_mode) {
|
||||
spi_i2s_reset(SPI_SSC); // full reset spi-ti_mode
|
||||
spi_init(SPI_SSC, &spi_init_struct);
|
||||
spi_ti_mode_enable(SPI_SSC, TRUE); // enable ti mode(Somewhat similar to SSC of AT91)
|
||||
spi_i2s_dma_receiver_enable(SPI_SSC,TRUE); // RX DMA enabled.
|
||||
spi_i2s_dma_receiver_enable(SPI_SSC, TRUE); // RX DMA enabled.
|
||||
spi_enable(SPI_SSC, TRUE);
|
||||
}
|
||||
|
||||
@@ -184,13 +184,13 @@ bool FpgaSetupSscRxDmaSingle(void *buf, uint16_t len) {
|
||||
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||
dma_init_struct.loop_mode_enable = FALSE; // loop disabled, only one time running.
|
||||
dma_init_struct.memory_base_addr = (uint32_t)buf;
|
||||
dma_init_struct.peripheral_base_addr = (uint32_t)&(SPI_SSC->dt);
|
||||
dma_init_struct.peripheral_base_addr = (uint32_t) & (SPI_SSC->dt);
|
||||
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY; // receive data from SPI-TI_MODE(SSC)
|
||||
dma_init(DMA_CHANNEL_SSC, &dma_init_struct);
|
||||
dmamux_init(DMA_CHANNEL_MUX_SSC, DMA_MUX_REQ_ID_SSC);
|
||||
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
((uint8_t*)buf)[0] = FPGA_SSC_RX_Value(); // Readout and discard old byte. It's important!
|
||||
((uint8_t *)buf)[0] = FPGA_SSC_RX_Value(); // Readout and discard old byte. It's important!
|
||||
}
|
||||
|
||||
FPGA_SSC_DMA_RX_Enable(); // Start rx channel
|
||||
@@ -265,9 +265,9 @@ void FpgaSendCommand(uint16_t cmd, uint16_t v) {
|
||||
spi_cmd_setup();
|
||||
// Send data
|
||||
gpio_bits_reset(AT32_GPIO_SPI_CS, AT32_GPIO_SPI_CS_PIN); // CS LOW
|
||||
while(spi_i2s_flag_get(SPI_CMD, SPI_I2S_TDBE_FLAG) == RESET) {}
|
||||
while (spi_i2s_flag_get(SPI_CMD, SPI_I2S_TDBE_FLAG) == RESET) {}
|
||||
spi_i2s_data_transmit(SPI_CMD, cmd | v);
|
||||
while(spi_i2s_flag_get(SPI_CMD, SPI_I2S_BF_FLAG) != RESET) {} // Waiting for SPI transmit finish.
|
||||
while (spi_i2s_flag_get(SPI_CMD, SPI_I2S_BF_FLAG) != RESET) {} // Waiting for SPI transmit finish.
|
||||
gpio_bits_set(AT32_GPIO_SPI_CS, AT32_GPIO_SPI_CS_PIN); // CS HIGH
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ STATIC_FORCE_INLINE bool FPGA_SSC_RX_Ready(void) {
|
||||
// Only when the ROERR flag is set, it is necessary to read DT, so the '&&' condition is very important.
|
||||
// If the former does not hold, the DT register will not be read.
|
||||
return ((SPI_SSC->sts & (SPI_I2S_RDBF_FLAG | SPI_I2S_ROERR_FLAG)) == SPI_I2S_RDBF_FLAG)
|
||||
|| (((SPI_SSC->sts & SPI_I2S_ROERR_FLAG) == SPI_I2S_ROERR_FLAG) && (SPI_SSC->dt & 0)); // Readout data for clear the ROERR flag. IMPORTANT!
|
||||
|| (((SPI_SSC->sts & SPI_I2S_ROERR_FLAG) == SPI_I2S_ROERR_FLAG) && (SPI_SSC->dt & 0)); // Readout data for clear the ROERR flag. IMPORTANT!
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE bool FPGA_SSC_TX_Ready(void) {
|
||||
@@ -107,7 +107,7 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Enable(void) {
|
||||
DMA_CHANNEL_SSC->ctrl_bit.chen = 1;
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE uint32_t* FPGA_SSC_DMA_RX_Current_Address(void) {
|
||||
STATIC_FORCE_INLINE uint32_t *FPGA_SSC_DMA_RX_Current_Address(void) {
|
||||
|
||||
// The DMA address of AT32 does not self increment. So reading the maddr register yields a fixed initial BUF starting address
|
||||
// We can calculate the current rx address: Starting address + Current rx count
|
||||
@@ -118,7 +118,7 @@ STATIC_FORCE_INLINE uint32_t* FPGA_SSC_DMA_RX_Current_Address(void) {
|
||||
|
||||
// Warn: Calc byte count first, last to convert to U32*
|
||||
|
||||
return (uint32_t*)((uint8_t*)DMA_CHANNEL_SSC->maddr + ((g_ssc_dma_rx_count - FPGA_SSC_DMA_RX_Remaining_Count()) * g_ssc_data_byte_width));
|
||||
return (uint32_t *)((uint8_t *)DMA_CHANNEL_SSC->maddr + ((g_ssc_dma_rx_count - FPGA_SSC_DMA_RX_Remaining_Count()) * g_ssc_data_byte_width));
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE uint16_t FPGA_SSC_DMA_RX_Remaining_Count(void) {
|
||||
@@ -168,4 +168,4 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Secondary(void *buf, uint16_t l
|
||||
FPGA_SSC_DMA_RX_Refresh_Single(buf, len);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -89,7 +89,7 @@ bool FpgaSetupSscRxDmaSingle(void *buf, uint16_t len) {
|
||||
FPGA_SSC_DMA_RX_Disable(); // Disable DMA Transfer
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // start transfer to this memory address
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = len; // transfer this many samples
|
||||
((uint8_t*)buf)[0] = (uint8_t)FPGA_SSC_RX_Value(); // clear receive register
|
||||
((uint8_t *)buf)[0] = (uint8_t)FPGA_SSC_RX_Value(); // clear receive register
|
||||
FPGA_SSC_DMA_RX_Enable(); // Start DMA transfer
|
||||
|
||||
return true;
|
||||
|
||||
@@ -45,8 +45,8 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Enable(void) {
|
||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE uint32_t* FPGA_SSC_DMA_RX_Current_Address(void) {
|
||||
return (uint32_t*)AT91C_BASE_PDC_SSC->PDC_RPR;
|
||||
STATIC_FORCE_INLINE uint32_t *FPGA_SSC_DMA_RX_Current_Address(void) {
|
||||
return (uint32_t *)AT91C_BASE_PDC_SSC->PDC_RPR;
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE uint16_t FPGA_SSC_DMA_RX_Remaining_Count(void) {
|
||||
@@ -103,4 +103,4 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Secondary(void *buf, uint16_t l
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = len; // next buffer count
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -409,6 +409,6 @@ void FpgaResetBitstream(void) {
|
||||
//----------------------------------------------------------------------------
|
||||
// The information of the bitstream of the FPGA that has been downloaded currently.
|
||||
//----------------------------------------------------------------------------
|
||||
const char* FpgaGetCurrentVersionString(void) {
|
||||
const char *FpgaGetCurrentVersionString(void) {
|
||||
return g_fpga_version_information[bitstream_target_to_index(downloaded_bitstream)].versionString;
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "fpga.h"
|
||||
|
||||
int FpgaGetCurrent(void);
|
||||
const char* FpgaGetCurrentVersionString(void);
|
||||
const char *FpgaGetCurrentVersionString(void);
|
||||
void FpgaDownloadAndGo(int bitstream_target);
|
||||
void FpgaDownloadAndGo_keep_EM(int bitstream_target);
|
||||
void FpgaResetBitstream(void);
|
||||
|
||||
@@ -9,10 +9,10 @@ void gpio_button_setup(void) {
|
||||
|
||||
void gpio_leds_setup(void) {
|
||||
AT91C_BASE_PIOA->PIO_PER = AT91C_BASE_PIOA->PIO_OER = // Chained assignment
|
||||
GPIO_LED_A |
|
||||
GPIO_LED_B |
|
||||
GPIO_LED_C |
|
||||
GPIO_LED_D;
|
||||
GPIO_LED_A |
|
||||
GPIO_LED_B |
|
||||
GPIO_LED_C |
|
||||
GPIO_LED_D;
|
||||
}
|
||||
|
||||
void gpio_arm_power_on_setup(void) {
|
||||
@@ -48,12 +48,12 @@ void gpio_fpga_switch_setup(void) {
|
||||
|
||||
void gpio_adc_mux_setup(void) {
|
||||
AT91C_BASE_PIOA->PIO_PER = AT91C_BASE_PIOA->PIO_OER = // Chained assignment
|
||||
GPIO_MUXSEL_HIPKD |
|
||||
GPIO_MUXSEL_HIPKD |
|
||||
#ifndef WITH_FPC_USART // FPC USART uses HIRAW/LOWRAW pins, so they are excluded here.
|
||||
GPIO_MUXSEL_LORAW |
|
||||
GPIO_MUXSEL_HIRAW |
|
||||
GPIO_MUXSEL_LORAW |
|
||||
GPIO_MUXSEL_HIRAW |
|
||||
#endif
|
||||
GPIO_MUXSEL_LOPKD;
|
||||
GPIO_MUXSEL_LOPKD;
|
||||
}
|
||||
|
||||
void gpio_fpga_download_setup(void) {
|
||||
|
||||
@@ -64,7 +64,7 @@ void AdcSetupRssiChannel(adc_rssi_ch_t ch) {
|
||||
// get vref value, ADC_CHANNEL_17 is fixed, don't change!!!
|
||||
adc_ordinary_channel_set(AT32_RSSI_ADC, ADC_CHANNEL_17, 1, ADC_SAMPLETIME_640_5);
|
||||
AdcRssiConversionStart();
|
||||
while(adc_flag_get(AT32_RSSI_ADC, ADC_OCCE_FLAG) == RESET); // Waiting for adc conversion done.
|
||||
while (adc_flag_get(AT32_RSSI_ADC, ADC_OCCE_FLAG) == RESET); // Waiting for adc conversion done.
|
||||
// printf("vref_value = %f V\r\n", ((double)1.2 * 4095) / adc1_ordinary_value);
|
||||
g_adc_vref_value = adc_ordinary_conversion_data_get(AT32_RSSI_ADC);
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ void AdcSetupRssiChannel(adc_rssi_ch_t ch) {
|
||||
}
|
||||
|
||||
AdcRssiConversionStart();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ STATIC_FORCE_INLINE uint32_t GetChipId(void);
|
||||
// size: the size of the unique ID in bytes, set to 0 if no unique id available(and return null ptr).
|
||||
// Note: Not all chips have a unique ID(Such as AT91SAM7S).
|
||||
//-----------------------------------------------------------------------------
|
||||
STATIC_FORCE_INLINE uint8_t* GetChipUniqueId(uint8_t *size);
|
||||
STATIC_FORCE_INLINE uint8_t *GetChipUniqueId(uint8_t *size);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reset the chip processor
|
||||
|
||||
@@ -377,18 +377,18 @@ void ConfigSystemClocks(void) {
|
||||
void system_simple_reset(void) {
|
||||
const uint32_t keep_gpiob_clock_mask = CRM_REG_BIT(AT32_GPIO_ARM_POWER_LOCK_CLK);
|
||||
uint32_t ahb1_reset_mask =
|
||||
CRM_REG_BIT(CRM_GPIOA_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOC_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOD_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOE_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOF_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOG_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOH_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_CRC_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_EDMA_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_DMA1_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_DMA2_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_OTGFS2_PERIPH_RESET);
|
||||
CRM_REG_BIT(CRM_GPIOA_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOC_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOD_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOE_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOF_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOG_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_GPIOH_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_CRC_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_EDMA_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_DMA1_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_DMA2_PERIPH_RESET) |
|
||||
CRM_REG_BIT(CRM_OTGFS2_PERIPH_RESET);
|
||||
#if defined(AT32F437xx)
|
||||
ahb1_reset_mask |= CRM_REG_BIT(CRM_EMAC_PERIPH_RESET);
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,7 @@ STATIC_FORCE_INLINE uint32_t GetChipId(void) {
|
||||
return *(AT91C_DBGU_CIDR);
|
||||
}
|
||||
|
||||
STATIC_FORCE_INLINE uint8_t* GetChipUniqueId(uint8_t *size) {
|
||||
STATIC_FORCE_INLINE uint8_t *GetChipUniqueId(uint8_t *size) {
|
||||
// !!! UNSUPPORTED !!!
|
||||
if (size) {
|
||||
*size = 0;
|
||||
@@ -64,9 +64,9 @@ STATIC_FORCE_INLINE uint32_t GetChipFlashSize(void) {
|
||||
|
||||
STATIC_FORCE_INLINE bool CheckRSTWithSRAMRetention(void) {
|
||||
if ((AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) == AT91C_RSTC_RSTTYP_WATCHDOG ||
|
||||
(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) == AT91C_RSTC_RSTTYP_SOFTWARE ||
|
||||
(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) == AT91C_RSTC_RSTTYP_USER) {
|
||||
return true;
|
||||
(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) == AT91C_RSTC_RSTTYP_SOFTWARE ||
|
||||
(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) == AT91C_RSTC_RSTTYP_USER) {
|
||||
return true;
|
||||
}
|
||||
/* Otherwise, initialize it from scratch */
|
||||
return false;
|
||||
|
||||
@@ -150,13 +150,13 @@ uint32_t RAMFUNC GetTickCount(void) {
|
||||
ertc_time_type time;
|
||||
ertc_calendar_get(&time);
|
||||
return mktime_utc_fast(
|
||||
// time.year is short length, not full, so 2025 is 25.
|
||||
time.year + 2000,
|
||||
// month & day & hour & min & sec is full length
|
||||
time.month, time.day, time.hour, time.min, time.sec,
|
||||
// this ms is from 0 -> 1000 of second, not timestamp value
|
||||
// ms = ((divb + 1) - subsecond * 1000) / (divb + 1)
|
||||
(3125 - ertc_sub_second_get()) * 1000 / 3125) - tick_start_val; // current - start = tick
|
||||
// time.year is short length, not full, so 2025 is 25.
|
||||
time.year + 2000,
|
||||
// month & day & hour & min & sec is full length
|
||||
time.month, time.day, time.hour, time.min, time.sec,
|
||||
// this ms is from 0 -> 1000 of second, not timestamp value
|
||||
// ms = ((divb + 1) - subsecond * 1000) / (divb + 1)
|
||||
(3125 - ertc_sub_second_get()) * 1000 / 3125) - tick_start_val; // current - start = tick
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -135,8 +135,7 @@ static usbd_desc_t *get_winusb_os_string(void) {
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
static usbd_desc_handler cdc_desc_handler =
|
||||
{
|
||||
static usbd_desc_handler cdc_desc_handler = {
|
||||
.get_device_descriptor = get_device_descriptor,
|
||||
.get_device_qualifier = get_device_qualifier,
|
||||
.get_device_configuration = get_device_configuration,
|
||||
@@ -173,11 +172,11 @@ static void usb_clock48m_select(usb_clk48_s clk_s) {
|
||||
acc_write_c1(7980);
|
||||
acc_write_c2(8000);
|
||||
acc_write_c3(8020);
|
||||
#if (USB_ID == 0)
|
||||
#if (USB_ID == 0)
|
||||
acc_sof_select(ACC_SOF_OTG1);
|
||||
#else
|
||||
#else
|
||||
acc_sof_select(ACC_SOF_OTG2);
|
||||
#endif
|
||||
#endif
|
||||
// open acc calibration
|
||||
acc_calibration_mode_enable(ACC_CAL_HICKTRIM, TRUE);
|
||||
|
||||
@@ -326,7 +325,7 @@ static bool usb_read_ng_link_ready(void) {
|
||||
|
||||
// Implemented for read_ng
|
||||
static bool usb_read_ng_data_ready(void) {
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
return pcdc->g_rx_completed;
|
||||
}
|
||||
|
||||
@@ -337,13 +336,13 @@ static uint16_t usb_read_ng_data_available(void) {
|
||||
|
||||
// Implemented for read_ng
|
||||
static uint8_t usb_read_ng_data_read(void) {
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
return pcdc->g_rx_buff[usb_read_ng_fifo_pos++];
|
||||
}
|
||||
|
||||
// Implemented for read_ng
|
||||
static void usb_read_ng_clear(void) {
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
// When receiving data from USB device is completed, the flag bit of receiving completion must be cleared,
|
||||
// otherwise, it will enter the endless cycle of receiving completion and may repeatedly execute an instruction.
|
||||
pcdc->g_rx_completed = 0;
|
||||
@@ -376,7 +375,7 @@ void usb_enable(void) {
|
||||
crm_periph_clock_enable(OTG_CLOCK, TRUE); // enable otgfs clock
|
||||
usb_clock48m_select(USB_CLK_HEXT); // select usb 48m clcok source
|
||||
nvic_irq_enable(OTG_IRQ, 0, 0); // enable otgfs irq
|
||||
usbd_init(&otg_core_struct, USB_FULL_SPEED_CORE_ID,USB_ID, &cdc_class_handler, &cdc_desc_handler); // init usb
|
||||
usbd_init(&otg_core_struct, USB_FULL_SPEED_CORE_ID, USB_ID, &cdc_class_handler, &cdc_desc_handler); // init usb
|
||||
|
||||
#ifndef AS_BOOTROM
|
||||
usb_read_ng_init(&g_usb_read_ng_config);
|
||||
@@ -409,7 +408,7 @@ bool usb_poll(void) {
|
||||
return false;
|
||||
}
|
||||
// g_rx_completed will set to 1 when irq event: USB_OTG_DOEPINT_XFERC_FLAG
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
return pcdc->g_rx_completed;
|
||||
}
|
||||
|
||||
@@ -418,7 +417,7 @@ bool usb_poll(void) {
|
||||
* @return data length, if no data received, return 0.
|
||||
*/
|
||||
uint16_t usb_available_length(void) {
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
// Only when g_rx_completed is set, the g_rxlen is valid, otherwise, it may be 0 or invalid.
|
||||
if (pcdc->g_rx_completed) {
|
||||
return pcdc->g_rxlen;
|
||||
@@ -500,7 +499,7 @@ int usb_write(const uint8_t *data, const size_t len) {
|
||||
}
|
||||
|
||||
// wait for send complete
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *) (udev->class_handler->pdata);
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)(udev->class_handler->pdata);
|
||||
while (pcdc->g_tx_completed != 1) {
|
||||
if (usb_check() == false) {
|
||||
return PM3_EIO;
|
||||
|
||||
@@ -895,4 +895,4 @@ void usb_get_ep_size(uint32_t *epCtl, uint32_t *epIn, uint32_t *epOut) {
|
||||
if (epCtl) *epCtl = AT91C_USB_EP_CONTROL_SIZE;
|
||||
if (epIn) *epIn = AT91C_USB_EP_IN_SIZE;
|
||||
if (epOut) *epOut = AT91C_USB_EP_OUT_SIZE;
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,10 @@ static size_t g_buf_offset = 0;
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
void usb_read_ng_init(const usb_read_ng_config_t *config)
|
||||
{
|
||||
void usb_read_ng_init(const usb_read_ng_config_t *config) {
|
||||
if (!config || !config->is_link_ready || !config->is_data_ready ||
|
||||
!config->get_byte_count || !config->read_fifo ||
|
||||
!config->clear_ready || !config->buffer || config->buffer_size == 0) {
|
||||
!config->get_byte_count || !config->read_fifo ||
|
||||
!config->clear_ready || !config->buffer || config->buffer_size == 0) {
|
||||
return;
|
||||
}
|
||||
g_config = config;
|
||||
@@ -21,13 +20,11 @@ void usb_read_ng_init(const usb_read_ng_config_t *config)
|
||||
g_buf_offset = 0;
|
||||
}
|
||||
|
||||
bool usb_read_ng_has_buffered_data(void)
|
||||
{
|
||||
bool usb_read_ng_has_buffered_data(void) {
|
||||
return g_buf_len > 0;
|
||||
}
|
||||
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len)
|
||||
{
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len) {
|
||||
if (!g_config || !data || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -79,8 +76,7 @@ uint32_t usb_read_ng(uint8_t *data, size_t len)
|
||||
// gc gc gc gc !!!
|
||||
g_config->clear_ready();
|
||||
time_out = 0; // Timeout reset.
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// usb link ready but no data. to check simple timeout.
|
||||
if (timeout_limit > 0) {
|
||||
time_out++;
|
||||
|
||||
@@ -13,40 +13,40 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Callbacks, implement functions on platform related.
|
||||
typedef bool (*usb_link_ready_cb_t)(void); // is usb link ready?
|
||||
typedef bool (*usb_data_ready_cb_t)(void); // is data received ready?
|
||||
typedef uint16_t (*usb_get_byte_count_cb_t)(void); // how length of data received?
|
||||
typedef uint8_t (*usb_read_fifo_cb_t)(void); // read byte from fifo
|
||||
typedef void (*usb_clear_rx_ready_cb_t)(void); // clear
|
||||
// Callbacks, implement functions on platform related.
|
||||
typedef bool (*usb_link_ready_cb_t)(void); // is usb link ready?
|
||||
typedef bool (*usb_data_ready_cb_t)(void); // is data received ready?
|
||||
typedef uint16_t (*usb_get_byte_count_cb_t)(void); // how length of data received?
|
||||
typedef uint8_t (*usb_read_fifo_cb_t)(void); // read byte from fifo
|
||||
typedef void (*usb_clear_rx_ready_cb_t)(void); // clear
|
||||
|
||||
// Configs, instance of platform.
|
||||
typedef struct {
|
||||
usb_link_ready_cb_t is_link_ready;
|
||||
usb_data_ready_cb_t is_data_ready;
|
||||
usb_get_byte_count_cb_t get_byte_count;
|
||||
usb_read_fifo_cb_t read_fifo;
|
||||
usb_clear_rx_ready_cb_t clear_ready;
|
||||
// Configs, instance of platform.
|
||||
typedef struct {
|
||||
usb_link_ready_cb_t is_link_ready;
|
||||
usb_data_ready_cb_t is_data_ready;
|
||||
usb_get_byte_count_cb_t get_byte_count;
|
||||
usb_read_fifo_cb_t read_fifo;
|
||||
usb_clear_rx_ready_cb_t clear_ready;
|
||||
|
||||
uint8_t *buffer; // buffer for read ng of platform.
|
||||
size_t buffer_size; // buffer size
|
||||
uint16_t timeout; // read timeout if no data ready.
|
||||
} usb_read_ng_config_t;
|
||||
uint8_t *buffer; // buffer for read ng of platform.
|
||||
size_t buffer_size; // buffer size
|
||||
uint16_t timeout; // read timeout if no data ready.
|
||||
} usb_read_ng_config_t;
|
||||
|
||||
// setup usb read ng, implement all usb related function for platform.
|
||||
// @param: config - the module will use this point on global, so don't instance in function stack!
|
||||
void usb_read_ng_init(const usb_read_ng_config_t *config);
|
||||
// setup usb read ng, implement all usb related function for platform.
|
||||
// @param: config - the module will use this point on global, so don't instance in function stack!
|
||||
void usb_read_ng_init(const usb_read_ng_config_t *config);
|
||||
|
||||
// exported api, not platform related, for check data available of local usb ng buffer(not usb ep buffer)
|
||||
// nonblocking api
|
||||
bool usb_read_ng_has_buffered_data(void);
|
||||
// exported api, not platform related, for check data available of local usb ng buffer(not usb ep buffer)
|
||||
// nonblocking api
|
||||
bool usb_read_ng_has_buffered_data(void);
|
||||
|
||||
// exported api, not platform related, for read data from local buffer or usb device online.
|
||||
// nonblocking api
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len);
|
||||
// exported api, not platform related, for read data from local buffer or usb device online.
|
||||
// nonblocking api
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -7,4 +7,4 @@ STATIC_FORCE_INLINE void WDT_HIT(void) {
|
||||
// TODO 待实现喂狗
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -8,4 +8,4 @@ STATIC_FORCE_INLINE void WDT_HIT(void) {
|
||||
AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Reference in new issue
Block a user